Commit 813dbbe5 authored by suyanlong's avatar suyanlong

Fixed bug and update README.md

parent bddbbcfa
...@@ -10,9 +10,17 @@ Use the following command to build ...@@ -10,9 +10,17 @@ Use the following command to build
make chain33 make chain33
``` ```
This will create a `build` directory under the project path and generate a `chain33-client.so` inside the `build`.
This `.so` file will be used by [sidecar](https://gitlab.33.cn/link33/sidecar/wikis/sidecar%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3).
## Usage ## 业务流程
### 锁币(铸币)
用户公链发起锁币 => 铸币
### 销毁(提币)
用户联盟链发起销毁 => 提币
备注:使用以上流程,其它流程不允许。如不允许在公链发起提币,不允许在联盟链发起锁币。针对程序来说。
### 在用户层来说,怎么发起由前端决定。
# Details about how to use this plugin can be found in [here](https://gitlab.33.cn/link33/sidecar/wikis/chain33%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE)
package evmxgo package evmxgo
import ( import (
"encoding/hex"
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
"testing" "testing"
"gitlab.33.cn/link33/sidecar-client-chain33/util" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/db" "github.com/33cn/chain33/common/db"
types33 "github.com/33cn/chain33/types"
evmxgotypes "github.com/33cn/plugin/plugin/dapp/evmxgo/types"
"github.com/stretchr/testify/assert"
"gitlab.33.cn/link33/sidecar-client-chain33/util"
) )
func bytesPrefix(prefix []byte) []byte { func bytesPrefix(prefix []byte) []byte {
...@@ -54,3 +58,35 @@ func TestDB(t *testing.T) { ...@@ -54,3 +58,35 @@ func TestDB(t *testing.T) {
// https://github.com/Pallinder/go-randomdata:产生随机数据,用于单元测试 // https://github.com/Pallinder/go-randomdata:产生随机数据,用于单元测试
// https://github.com/spf13/cast 类型转化 // https://github.com/spf13/cast 类型转化
func TestTx(t *testing.T) {
// data := "0a05746f6b656e1212380c4a0e0a04544553541080e4bbffcac50120a08d0630d5e5e484c9b1a8da4d3a22313268704a4248796268316d537943696a51324d514a506b377a376b5a376a6e5161"
data := "0a0665766d78676f120e300c220a0a03444f471080ade20420a08d0630c7f8ecc9effcd2ae1b3a2231365542505734757836484e6451444a7051416570746d454c7070414d3936423167"
td, err := hex.DecodeString(data)
assert.Nil(t, err)
tx := &types33.Transaction{}
err = types33.Decode(td, tx)
assert.Nil(t, err)
t.Log(tx)
params := &evmxgotypes.EvmxgoAction{
Value: &evmxgotypes.EvmxgoAction_Mint{},
}
// payload := &types33.CreateTxIn{}
// t.Log(hex.EncodeToString(tx.Payload))
err = types33.Decode(tx.Payload, params)
t.Log(err)
assert.Nil(t, err)
t.Log(params.Ty)
t.Log(params.Value)
// t.Log(params.Recipient)
// t.Log(params.Extra)
// t.Log(params.BridgeToken)
// t.Log(payload.ActionName)
// t.Log(payload.Execer)
// t.Log(payload.Payload)
execerAddress := address.ExecAddress(execer)
t.Log(execerAddress)
assert.Equal(t, "16UBPW4ux6HNdQDJpQAeptmELppAM96B1g", execerAddress)
}
...@@ -34,10 +34,10 @@ var ActionMap = map[string]func(){ ...@@ -34,10 +34,10 @@ var ActionMap = map[string]func(){
}, },
} }
const ( var (
PluginName = "evmxgo" PluginName = evmxgotypes.EvmxgoX
ID = "evmxgo" ID = evmxgotypes.EvmxgoX
execer = "evmxgo" execer = evmxgotypes.EvmxgoX
) )
var logger = hclog.New(&hclog.LoggerOptions{ var logger = hclog.New(&hclog.LoggerOptions{
...@@ -179,93 +179,100 @@ func (e *Evmxgo) pollAppChain() chan *typess.Event { ...@@ -179,93 +179,100 @@ func (e *Evmxgo) pollAppChain() chan *typess.Event {
if tx.Execer == execer { if tx.Execer == execer {
switch item.Receipts[i].Ty { switch item.Receipts[i].Ty {
case types33.ExecOk: // OK case types33.ExecOk: // OK
if item.Receipts[i].TyName == evmxgotypes.NameMintMapAction { for _, log := range item.Receipts[i].Logs {
var mintEvent evmxgotypes.EvmxgoMintMap if log.Ty == evmxgotypes.TyLogEvmxgoMintMap {
tool.ErrorCheck(types33.Decode(tx.Payload, &mintEvent)) var mintEvent evmxgotypes.EvmxgoMintMap
if len(mintEvent.Extra) > 0 { // 存在关联的数据 tool.ErrorCheck(types33.Decode(tx.Payload, &mintEvent))
event := &typess.Event{ if len(mintEvent.Extra) > 0 { // 存在关联的数据
TxID: tx.Hash, event := &typess.Event{
BlockNumber: uint64(item.Block.Height), TxID: tx.Hash,
Contract: &typess.Contract{ BlockNumber: uint64(item.Block.Height),
ChainID: e.appChainID, Contract: &typess.Contract{
ExecName: ID, ChainID: e.appChainID,
Address: "", // TODO 合约地址 ExecName: ID,
CallMethod: evmxgotypes.NameMintMapAction, Address: "", // TODO 合约地址
}, CallMethod: evmxgotypes.NameMintMapAction,
Payload: &typess.MapAssetInfo{ },
EventType: typess.EventType_Mint, Payload: &typess.MapAssetInfo{
MintAddress: mintEvent.Recipient, EventType: typess.EventType_Mint,
MintAmount: mintEvent.Amount, MintAddress: mintEvent.Recipient,
Symbol: mintEvent.Symbol, MintAmount: mintEvent.Amount,
Extra: mintEvent.Extra, Symbol: mintEvent.Symbol,
}, Extra: mintEvent.Extra,
},
}
srcEvent := &typess.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)
//}
e.saveMint(event)
e.updateLockMint(srcEvent, event)
ch <- event
} }
break
srcEvent := &typess.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)
//}
e.saveMint(event)
e.updateLockMint(srcEvent, event)
ch <- event
} }
} if log.Ty == evmxgotypes.TyLogEvmxgoBurnMap {
if item.Receipts[i].TyName == evmxgotypes.NameBurnMapAction { var mintEvent evmxgotypes.EvmxgoBurnMap
var mintEvent evmxgotypes.EvmxgoBurnMap tool.ErrorCheck(types33.Decode(tx.Payload, &mintEvent))
tool.ErrorCheck(types33.Decode(tx.Payload, &mintEvent)) if len(mintEvent.Extra) > 0 {
if len(mintEvent.Extra) > 0 { // 已销毁
// 已销毁 event := &typess.Event{
event := &typess.Event{ TxID: tx.Hash,
TxID: tx.Hash, BlockNumber: uint64(item.Block.Height),
BlockNumber: uint64(item.Block.Height), Contract: &typess.Contract{
Contract: &typess.Contract{ ChainID: e.appChainID,
ChainID: e.appChainID, ExecName: ID,
ExecName: ID, Address: "", // TODO 合约地址
Address: "", // TODO 合约地址 CallMethod: evmxgotypes.NameBurnMapAction,
CallMethod: evmxgotypes.NameBurnMapAction, },
}, Payload: &typess.MapAssetInfo{
Payload: &typess.MapAssetInfo{ EventType: typess.EventType_Burn,
EventType: typess.EventType_Burn, BurnAddress: tx.From, // 用户地址
BurnAddress: tx.From, // 用户地址 BurnAmount: mintEvent.Amount,
BurnAmount: mintEvent.Amount, Symbol: mintEvent.Symbol,
Symbol: mintEvent.Symbol, Extra: mintEvent.Extra, // TODO
Extra: mintEvent.Extra, // TODO },
}, }
e.saveBurn(event)
e.saveUndoneEvent(event)
ch <- event // 需要保存这个事件,用于确认销毁成功。
} else {
// TODO 在公链一侧,用户发起注销,余额不够,交易失败.
// e.deleteUndoneEvent(srcEvent.TxID)
} }
e.saveBurn(event) break
e.saveUndoneEvent(event)
ch <- event // 需要保存这个事件,用于确认销毁成功。
} else {
// TODO 在公链一侧,用户发起注销,余额不够,交易失败.
// e.deleteUndoneEvent(srcEvent.TxID)
} }
} }
case types33.ExecPack: // 打包:交易
logger.Error("exec error!",
"tx:", tx,
"height:", item.Block.Height,
)
case types33.ExecErr: // Error case types33.ExecErr: // Error
logger.Error("transaction error ", logger.Error("transaction error ",
"tx:", tx, "tx:", tx,
"height:", item.Block.Height, "height:", item.Block.Height,
) )
default:
case types33.ExecPack: logger.Error("exec type error!",
logger.Error("exec error!",
"tx:", tx, "tx:", tx,
"height:", item.Block.Height, "height:", item.Block.Height,
) )
// 打包:交易
} }
} }
} }
...@@ -444,7 +451,7 @@ func (e *Evmxgo) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -444,7 +451,7 @@ func (e *Evmxgo) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
Recipient: event.Payload.LockAddress, Recipient: event.Payload.LockAddress,
Extra: ibtp.Payload, // TODO 附加已经完成的事件 Extra: ibtp.Payload, // TODO 附加已经完成的事件
} }
tx.Payload = types33.Encode(mint) tx.Payload = types33.Encode(mint) // TODO
e.saveLock(event) e.saveLock(event)
} else if event.Payload.EventType == typess.EventType_UnLock { } else if event.Payload.EventType == typess.EventType_UnLock {
......
...@@ -59,7 +59,7 @@ require ( ...@@ -59,7 +59,7 @@ require (
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/huandu/xstrings v1.3.2 // indirect github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect github.com/imdario/mergo v0.3.12 // indirect
github.com/jinzhu/copier v0.3.2 // indirect github.com/jinzhu/copier v0.3.6-0.20220210061904-7948fe2be217 // indirect
github.com/jinzhu/now v1.1.2 // indirect github.com/jinzhu/now v1.1.2 // indirect
github.com/joho/godotenv v1.3.0 // indirect github.com/joho/godotenv v1.3.0 // indirect
github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff // indirect github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff // indirect
......
...@@ -920,6 +920,8 @@ github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4 ...@@ -920,6 +920,8 @@ github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4
github.com/jhump/protoreflect v1.8.2/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg= github.com/jhump/protoreflect v1.8.2/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg=
github.com/jinzhu/copier v0.3.2 h1:QdBOCbaouLDYaIPFfi1bKv5F5tPpeTwXe4sD0jqtz5w= github.com/jinzhu/copier v0.3.2 h1:QdBOCbaouLDYaIPFfi1bKv5F5tPpeTwXe4sD0jqtz5w=
github.com/jinzhu/copier v0.3.2/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro= github.com/jinzhu/copier v0.3.2/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro=
github.com/jinzhu/copier v0.3.6-0.20220210061904-7948fe2be217 h1:Uy9RZ3MW1z8PUZ4NE+bybs4teJbzt62EKZ3/j42jSFw=
github.com/jinzhu/copier v0.3.6-0.20220210061904-7948fe2be217/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI= github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
......
...@@ -568,6 +568,7 @@ func (p *Paracross) getNodeStatus(tx *types33.Transaction) (*paracorssTypes.Para ...@@ -568,6 +568,7 @@ func (p *Paracross) getNodeStatus(tx *types33.Transaction) (*paracorssTypes.Para
if err != nil { if err != nil {
return nil, err return nil, err
} }
// TODO fix bug
return &paracorssTypes.ParacrossNodeStatus{ return &paracorssTypes.ParacrossNodeStatus{
MainBlockHash: blockDetail.Block.MainHash, // 跨链交易在主链时高度的hash MainBlockHash: blockDetail.Block.MainHash, // 跨链交易在主链时高度的hash
MainBlockHeight: blockDetail.Block.MainHeight, // 跨链交易在主链时的高度 MainBlockHeight: blockDetail.Block.MainHeight, // 跨链交易在主链时的高度
......
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