Commit 2afe8a07 authored by suyanlong's avatar suyanlong

fix config info bug

parent c528d06b
......@@ -10,7 +10,12 @@ default:
mkdir -p build
$(GO) build -o build/chain33-client-evmxgo ./cmd/evmxgo/*.go
$(GO) build -o build/chain33-client-paracross ./cmd/paracross/*.go
cp build/chain33-client-* build/plugins/
mkdir -p build/plugins
mkdir -p build/evmxgo
cp build/chain33-client-* build/plugins/
cp paracross/paracross.toml build/plugins/paracross/
cp evmxgo/evmxgo.toml build/plugins/evmxgo/
cp config/sidecar.toml build/
help: Makefile
@echo "Choose a command run:"
......
......@@ -21,6 +21,6 @@ make chain33
备注:只能使用以上流程,其它流程不允许。如不允许在公链发起提币,不允许在联盟链发起锁币。针对程序来说。
### 在用户层来说,怎么发起由前端决定。
### 在用户层来说,如何发起由前端决定。
......@@ -7,6 +7,7 @@ chain_id = "3"
start_height = 1
height_diff = 0
fee = 100000
is_test = true
[log]
level = "debug"
......
......@@ -37,12 +37,13 @@ type Chain33 struct {
Addr string `toml:"addr" json:"addr"`
Name string `toml:"name" json:"name"`
PrivateKey string `mapstructure:"private_key" toml:"private_key" json:"private_key"`
ChainID string `mapstructure:"chain_id" json:"chain_id"`
ChainID int32 `mapstructure:"chain_id" json:"chain_id"`
StartHeight int64 `mapstructure:"start_height" json:"start_height"` // 起始高度
HeightDiff int64 `mapstructure:"height_diff" json:"height_diff"` // 高度差
Fee int64 `mapstructure:"Fee" json:"Fee"` // 单笔交易的手续费
EventFilter string `mapstructure:"event_filter" toml:"event_filter" json:"event_filter"`
TimeoutHeight int64 `mapstructure:"timeout_height" json:"timeout_height"`
IsTest bool `mapstructure:"is_test" json:"is_test"`
}
type Service struct {
......@@ -57,7 +58,7 @@ func DefaultConfig() *Config {
Addr: "40.125.164.122:8801",
Name: "chain33",
PrivateKey: "",
ChainID: "1",
ChainID: 1,
StartHeight: 3,
HeightDiff: 6,
Fee: 1e5,
......@@ -69,8 +70,8 @@ func DefaultConfig() *Config {
DbCache: 100,
},
Router: Router{
FromChain: "1",
ToChain: "3",
FromChain: "paracross",
ToChain: "evmxgo",
},
Log: Log{
Level: "info",
......
......@@ -26,17 +26,18 @@ rule = "info"
[[appchains]]
enable = true
type = "appchain"
did = "3"
did = "paracross"
config = "paracross/paracross.toml"
plugin = "chain33-client-paracross"
plugin_id = "paracross"
[[appchains]]
enable = true
type = "appchain"
did = "1"
did = "evmxgo"
config = "evmxgo/evmxgo.toml"
plugin = "chain33-client-evmxgo"
plugin_id = "evmxgo"
[router]
enable = false
......
......@@ -45,16 +45,17 @@ var (
)
type Evmxgo struct {
eventC chan *pb.IBTP // 发送给sidecar
appChainID string
toChainID string
ticker *time.Ticker
done chan bool
client *rpc.Client
pk string // 签名,仅仅是和当前链挂钩的私钥。
height *atomic.Int64 // 已经解析的高度。1、初始化时设置; 2、服务每次重启后设置
db *util.KVDBList // 记录已完成的hashID、高度等信息。
fee int64
eventC chan *pb.IBTP // 发送给sidecar
chainID int32
fromID string
toID string
ticker *time.Ticker
done chan bool
client *rpc.Client
pk string // 签名,仅仅是和当前链挂钩的私钥。
height *atomic.Int64 // 已经解析的高度。1、初始化时设置; 2、服务每次重启后设置
db *util.KVDBList // 记录已完成的hashID、高度等信息。
fee int64
}
func (e *Evmxgo) incHeight() int64 {
......@@ -95,7 +96,7 @@ func (e *Evmxgo) Type() string {
}
func (e *Evmxgo) ID() string {
return e.appChainID
return e.fromID
}
// configPath 完整路径
......@@ -111,10 +112,11 @@ func (e *Evmxgo) Initialize(configPath string, ID string, extra []byte) error {
logger.Info("print chain33Config", "chain33Config", util.Sprint(chain33Config))
logger.Info("print privateKey", "privateKey", chain33Config.Chain33.PrivateKey)
e.pk = chain33Config.Chain33.PrivateKey
e.appChainID = chain33Config.Chain33.ChainID
e.toChainID = chain33Config.Router.ToChain
e.chainID = chain33Config.Chain33.ChainID
e.fromID = chain33Config.Router.FromChain
e.toID = chain33Config.Router.ToChain
e.fee = chain33Config.Chain33.Fee
logger.SetLevel(hclog.LevelFromString(chain33Config.Log.Level))
// logger.SetLevel(hclog.LevelFromString(chain33Config.Log.Level))
// 初始化chain33 client rpc
client, err := rpc.NewClient("", chain33Config.Chain33.Addr)
......@@ -187,7 +189,7 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
time.Sleep(2 * time.Second)
} else {
height1 := height + 1
blockInfo, err := e.client.QueryBlockInfo(height1, height1, true) // TODO 分组获取
blockInfo, err := e.client.QueryBlockInfo(height1, height1, true)
if err != nil {
logger.Error("call QueryBlockInfo", "error", err)
} else {
......@@ -210,7 +212,7 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
Amount string `json:"amount,omitempty"`
BridgeToken string `json:"bridgeToken,omitempty"`
Recipient string `json:"recipient,omitempty"`
Extra []byte `json:"extra,omitempty"`
// Extra []byte `json:"extra,omitempty"` TODO?
}
Action struct {
MintMap *MintMap `json:"mintMap,omitempty"`
......@@ -219,8 +221,10 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
)
action := &Action{}
err := json.Unmarshal(tx.Payload, &action)
// action := &evmxgotypes.EvmxgoAction{}
// err := types33.Decode(tx.Payload, action)
if err != nil {
logger.Error("Unmarshal payload",
logger.Error("MintMap Unmarshal tx.payload to action",
"height:", item.Block.Height,
"tx:", util.FormatJSON(tx),
"error", err,
......@@ -234,7 +238,7 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
TxID: tx.Hash,
BlockNumber: uint64(item.Block.Height),
Contract: &types.Contract{
ChainID: e.appChainID,
ChainID: e.fromID,
ExecName: ID,
Address: address.ExecAddress(ID), // TODO 合约地址
CallMethod: evmxgotypes.NameMintMapAction,
......@@ -246,24 +250,14 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
Symbol: types.Symbol(mintEvent.Symbol),
Height: height1,
Nonce: tx.Nonce,
Extra: mintEvent.Extra,
// Extra: mintEvent.Extra,
},
}
srcEvent := &types.Event{}
err = types33.Decode(mintEvent.Extra, srcEvent)
if err != nil {
logger.Error("types33.Decode(mintEvent.Extra, &srcEvent)", "error", err)
continue
}
// 铸币成功,置换DB中的状态。
// 1、发送交易时返回的hash; 2、日志解析
//bindHash, _ := e.db.Get([]byte(tx.Hash))
//if bindHash != nil {
// e.deleteUndoneEvent(string(bindHash))
// _ = e.db.Delete([]byte(tx.Hash))
// _ = e.db.Delete(bindHash)
// // key := fmt.Sprintf("%s-%s-%d-%s", "lock", event.TxID)
//err = types33.Decode(mintEvent.Extra, srcEvent)
//if err != nil {
// logger.Error("types33.Decode(mintEvent.Extra, &srcEvent)", "error", err)
// continue
//}
e.saveMint(event)
e.updateLockMint(srcEvent, event)
......@@ -285,7 +279,7 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
action := &Action{}
err := json.Unmarshal(tx.Payload, &action)
if err != nil {
logger.Error("Unmarshal payload",
logger.Error("BurnMap Unmarshal tx.payload to action",
"height:", item.Block.Height,
"tx:", util.FormatJSON(tx),
"error", err,
......@@ -300,7 +294,7 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
TxID: tx.Hash,
BlockNumber: uint64(item.Block.Height),
Contract: &types.Contract{
ChainID: e.appChainID,
ChainID: cast.ToString(e.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // TODO 合约地址
CallMethod: evmxgotypes.NameBurnMapAction,
......@@ -455,8 +449,8 @@ func (e *Evmxgo) loop() {
data, _ := payload.Marshal()
tmp := time.Now().UnixNano()
ibtp := &pb.IBTP{
From: e.appChainID,
To: e.toChainID,
From: e.fromID,
To: e.toID,
Nonce: uint64(event.Payload.Nonce), // TODO 唯一标识。随机nonce
Type: pb.IBTP_INTERCHAIN,
Timestamp: tmp,
......@@ -574,14 +568,14 @@ func (e *Evmxgo) CreateTx(execName, action string, param types33.Message) (*type
}
// 填写nonce,execer,to, fee 等信息, 后面会增加一个修改transaction的函数,会加上execer fee 等的修改
tx.Nonce = rand.Int63()
tx.ChainID = cast.ToInt32(e.appChainID)
tx.ChainID = e.chainID
tx.Execer = []byte(execName)
// 平行链,所有的to地址都是合约地址
if tx.To == "" {
tx.To = address.ExecAddress(string(tx.Execer))
}
if tx.Fee == 0 {
tx.Fee, err = tx.GetRealFee(e.fee) // TODO 手续费可配置
tx.Fee, err = tx.GetRealFee(e.fee)
if err != nil {
return nil, err
}
......
......@@ -3,13 +3,13 @@
addr = "http://192.168.0.15:8801"
#用于跨链交易签名的私钥
private_key = "0xb9135831281bb9a09e2610680258270faecbeb4a73e0cec261ef0970c32cca5a"
chain_id = "1"
chain_id = 0
start_height = 1
height_diff = 0
fee = 100000
[log]
level = "debug"
level = "trace"
[db]
name = "evmxgo"
......@@ -18,4 +18,5 @@ db_path = "./evmxgo"
db_cache = 100
[router]
to_chain = "3"
from_chain = "evmxgo"
to_chain = "paracross"
......@@ -3,6 +3,7 @@ package paracross
import (
"bytes"
"context"
"errors"
"fmt"
"math/rand"
"os"
......@@ -40,14 +41,14 @@ var (
)
type Paracross struct {
eventC chan *pb.IBTP // 发送给sidecar
chainID int32
appChainID string
toChainID string
ticker *time.Ticker
done chan bool
height *atomic.Int64 // 已经解析的高度。1、初始化时设置; 2、服务每次重启后设置
db *util.KVDBList // 记录已完成的hashID、高度等信息。
eventC chan *pb.IBTP // 发送给sidecar
chainID int32
fromID string
toID string
ticker *time.Ticker
done chan bool
height *atomic.Int64 // 已经解析的高度。1、初始化时设置; 2、服务每次重启后设置
db *util.KVDBList // 记录已完成的hashID、高度等信息。
// 模拟平行链节点
paraHeight *atomic.Uint64 // paraHeightHash = Hash(paraHeight)
......@@ -63,6 +64,8 @@ type Paracross struct {
// 分类块中的交易为:已完成、未完成的交易。
notify chan int64 // 高度完成提醒
heightDiff int64 // 高度差
isTest bool
}
func (p *Paracross) incParaHeight() uint64 {
......@@ -109,7 +112,7 @@ func (p *Paracross) Type() string {
}
func (p *Paracross) ID() string {
return p.appChainID
return p.fromID
}
func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error {
......@@ -124,12 +127,13 @@ func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error
logger.Info("print chain33Config", "chain33Config", util.Sprint(chain33Config))
logger.Info("print privateKey", "privateKey", chain33Config.Chain33.PrivateKey)
p.privateKey = util33.HexToPrivkey(chain33Config.Chain33.PrivateKey)
p.appChainID = chain33Config.Chain33.ChainID
p.chainID = cast.ToInt32(p.appChainID)
p.toChainID = chain33Config.Router.ToChain
p.chainID = chain33Config.Chain33.ChainID
p.toID = chain33Config.Router.ToChain
p.fromID = chain33Config.Router.FromChain
p.title = chain33Config.Chain33.Title
p.MinTxFeeRate = chain33Config.Chain33.Fee
logger.SetLevel(hclog.LevelFromString(chain33Config.Log.Level))
p.isTest = chain33Config.Chain33.IsTest
// logger.SetLevel(hclog.LevelFromString(chain33Config.Log.Level))
config33 = fmt.Sprintf(config33, p.title, chain33Config.Chain33.Addr)
logger.Info(config33)
......@@ -251,7 +255,7 @@ func (p *Paracross) pollAppchain() chan *types.Event {
TxID: string(tx.Hash()),
BlockNumber: uint64(height1),
Contract: &types.Contract{
ChainID: p.appChainID,
ChainID: cast.ToString(p.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // TODO 合约地址
CallMethod: "AssetsWithdraw",
......@@ -275,7 +279,7 @@ func (p *Paracross) pollAppchain() chan *types.Event {
TxID: util.ToHex(tx.Hash()),
BlockNumber: uint64(height1),
Contract: &types.Contract{
ChainID: p.appChainID,
ChainID: cast.ToString(p.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // TODO 合约地址
CallMethod: "AssetTransfer",
......@@ -309,7 +313,7 @@ func (p *Paracross) pollAppchain() chan *types.Event {
TxID: util.ToHex(tx.Hash()),
BlockNumber: uint64(height1),
Contract: &types.Contract{
ChainID: p.appChainID,
ChainID: cast.ToString(p.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // TODO 合约地址
CallMethod: "AssetsWithdraw",
......@@ -508,8 +512,8 @@ func (p *Paracross) loop() {
data, _ := payload.Marshal()
tmp := time.Now().UnixNano()
ibtp := &pb.IBTP{
From: p.appChainID,
To: p.toChainID,
From: p.fromID,
To: p.toID,
Nonce: uint64(event.Payload.Nonce), // TODO 唯一标识。随机nonce
Type: pb.IBTP_INTERCHAIN,
Timestamp: tmp,
......@@ -523,7 +527,6 @@ func (p *Paracross) loop() {
func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
logger.Debug("SubmitIBTP recv ibtp", "ibtp", util.FormatJSON(ibtp))
ibtpRes := &pb.SubmitIBTPResponse{}
ibtpRes = nil
switch ibtp.Type {
case pb.IBTP_INTERCHAIN:
// 上链之前,先查询,是否存在
......@@ -573,26 +576,44 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
tx.Sign(types33.SECP256K1, p.privateKey)
ret, err := p.grpcClient.SendTransaction(p.ctx, tx)
if err != nil {
logger.Error("SendTransaction ", "error", err)
return nil, err
}
ibtpRes.Result = ibtp
if ret.IsOk {
p.saveBurn(event)
logger.Info("SendTransaction tx ok", "hash", string(ret.Msg))
ibtpRes.Status = true
} else {
ibtpRes.Status = false
logger.Error("SendTransaction error", "msg", string(ret.Msg))
}
return ibtpRes, nil
}
default:
logger.Error("ibtp.Type error: ", "type", ibtp.Type)
}
return ibtpRes, nil
// ibtpRes.Status = false
// ibtpRes.Result = ibtp
// return ibtpRes, nil
return nil, errors.New("ibtp.Type error")
}
// 模拟status
func (p *Paracross) getNodeStatus(curTxHashs [][]byte, blockDetail *types33.BlockDetail) (*paracorssTypes.ParacrossNodeStatus, error) {
txs := blockDetail.Block.Txs[1:]
receipts := blockDetail.Receipts[1:]
var (
txs []*types33.Transaction
receipts []*types33.ReceiptData
)
if p.isTest {
txs = blockDetail.Block.Txs
receipts = blockDetail.Receipts
} else {
txs = blockDetail.Block.Txs[1:]
receipts = blockDetail.Receipts[1:]
}
isCommitTx := make(map[string]bool)
// 包含我的平行链交易,
var paraTxHashs [][]byte
......
......@@ -4,13 +4,14 @@ Title = "user.p.test."
addr = "192.168.0.15:8802"
#用于跨链交易签名的私钥
private_key = "0xb9135831281bb9a09e2610680258270faecbeb4a73e0cec261ef0970c32cca5a"
chain_id = "3"
chain_id = 0
start_height = 10
height_diff = 0
fee = 100000
is_test = true
[log]
level = "debug"
level = "trace"
[db]
name = "paracross"
......@@ -19,4 +20,5 @@ db_path = "./paracross"
db_cache = 100
[router]
to_chain = "1"
from_chain = "paracross"
to_chain = "evmxgo"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment