Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar-client-chain33
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar-client-chain33
Commits
813dbbe5
Commit
813dbbe5
authored
Mar 31, 2022
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug and update README.md
parent
bddbbcfa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
85 deletions
+139
-85
README.md
README.md
+12
-4
db_test.go
evmxgo/db_test.go
+38
-2
evmxgo.go
evmxgo/evmxgo.go
+85
-78
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-0
paracross.go
paracross/paracross.go
+1
-0
No files found.
README.md
View file @
813dbbe5
...
...
@@ -10,9 +10,17 @@ Use the following command to build
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)
evmxgo/db_test.go
View file @
813dbbe5
package
evmxgo
import
(
"encoding/hex"
"fmt"
"math/rand"
"os"
"testing"
"gitlab.33.cn/link33/sidecar-client-chain33/util"
"github.com/33cn/chain33/common/address"
"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
{
...
...
@@ -54,3 +58,35 @@ func TestDB(t *testing.T) {
// https://github.com/Pallinder/go-randomdata:产生随机数据,用于单元测试
// 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
)
}
evmxgo/evmxgo.go
View file @
813dbbe5
...
...
@@ -34,10 +34,10 @@ var ActionMap = map[string]func(){
},
}
const
(
PluginName
=
"evmxgo"
ID
=
"evmxgo"
execer
=
"evmxgo"
var
(
PluginName
=
evmxgotypes
.
EvmxgoX
ID
=
evmxgotypes
.
EvmxgoX
execer
=
evmxgotypes
.
EvmxgoX
)
var
logger
=
hclog
.
New
(
&
hclog
.
LoggerOptions
{
...
...
@@ -179,93 +179,100 @@ func (e *Evmxgo) pollAppChain() chan *typess.Event {
if
tx
.
Execer
==
execer
{
switch
item
.
Receipts
[
i
]
.
Ty
{
case
types33
.
ExecOk
:
// OK
if
item
.
Receipts
[
i
]
.
TyName
==
evmxgotypes
.
NameMintMapAction
{
var
mintEvent
evmxgotypes
.
EvmxgoMintMap
tool
.
ErrorCheck
(
types33
.
Decode
(
tx
.
Payload
,
&
mintEvent
))
if
len
(
mintEvent
.
Extra
)
>
0
{
// 存在关联的数据
event
:=
&
typess
.
Event
{
TxID
:
tx
.
Hash
,
BlockNumber
:
uint64
(
item
.
Block
.
Height
),
Contract
:
&
typess
.
Contract
{
ChainID
:
e
.
appChainID
,
ExecName
:
ID
,
Address
:
""
,
// TODO 合约地址
CallMethod
:
evmxgotypes
.
NameMintMapAction
,
},
Payload
:
&
typess
.
MapAssetInfo
{
EventType
:
typess
.
EventType_Mint
,
MintAddress
:
mintEvent
.
Recipient
,
MintAmount
:
mintEvent
.
Amount
,
Symbol
:
mintEvent
.
Symbol
,
Extra
:
mintEvent
.
Extra
,
},
for
_
,
log
:=
range
item
.
Receipts
[
i
]
.
Logs
{
if
log
.
Ty
==
evmxgotypes
.
TyLogEvmxgoMintMap
{
var
mintEvent
evmxgotypes
.
EvmxgoMintMap
tool
.
ErrorCheck
(
types33
.
Decode
(
tx
.
Payload
,
&
mintEvent
))
if
len
(
mintEvent
.
Extra
)
>
0
{
// 存在关联的数据
event
:=
&
typess
.
Event
{
TxID
:
tx
.
Hash
,
BlockNumber
:
uint64
(
item
.
Block
.
Height
),
Contract
:
&
typess
.
Contract
{
ChainID
:
e
.
appChainID
,
ExecName
:
ID
,
Address
:
""
,
// TODO 合约地址
CallMethod
:
evmxgotypes
.
NameMintMapAction
,
},
Payload
:
&
typess
.
MapAssetInfo
{
EventType
:
typess
.
EventType_Mint
,
MintAddress
:
mintEvent
.
Recipient
,
MintAmount
:
mintEvent
.
Amount
,
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
}
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
}
}
if
item
.
Receipts
[
i
]
.
TyName
==
evmxgotypes
.
NameBurnMapAction
{
var
mintEvent
evmxgotypes
.
EvmxgoBurnMap
tool
.
ErrorCheck
(
types33
.
Decode
(
tx
.
Payload
,
&
mintEvent
))
if
len
(
mintEvent
.
Extra
)
>
0
{
// 已销毁
event
:=
&
typess
.
Event
{
TxID
:
tx
.
Hash
,
BlockNumber
:
uint64
(
item
.
Block
.
Height
),
Contract
:
&
typess
.
Contract
{
ChainID
:
e
.
appChainID
,
ExecName
:
ID
,
Address
:
""
,
// TODO 合约地址
CallMethod
:
evmxgotypes
.
NameBurnMapAction
,
},
Payload
:
&
typess
.
MapAssetInfo
{
EventType
:
typess
.
EventType_Burn
,
BurnAddress
:
tx
.
From
,
// 用户地址
BurnAmount
:
mintEvent
.
Amount
,
Symbol
:
mintEvent
.
Symbol
,
Extra
:
mintEvent
.
Extra
,
// TODO
},
if
log
.
Ty
==
evmxgotypes
.
TyLogEvmxgoBurnMap
{
var
mintEvent
evmxgotypes
.
EvmxgoBurnMap
tool
.
ErrorCheck
(
types33
.
Decode
(
tx
.
Payload
,
&
mintEvent
))
if
len
(
mintEvent
.
Extra
)
>
0
{
// 已销毁
event
:=
&
typess
.
Event
{
TxID
:
tx
.
Hash
,
BlockNumber
:
uint64
(
item
.
Block
.
Height
),
Contract
:
&
typess
.
Contract
{
ChainID
:
e
.
appChainID
,
ExecName
:
ID
,
Address
:
""
,
// TODO 合约地址
CallMethod
:
evmxgotypes
.
NameBurnMapAction
,
},
Payload
:
&
typess
.
MapAssetInfo
{
EventType
:
typess
.
EventType_Burn
,
BurnAddress
:
tx
.
From
,
// 用户地址
BurnAmount
:
mintEvent
.
Amount
,
Symbol
:
mintEvent
.
Symbol
,
Extra
:
mintEvent
.
Extra
,
// TODO
},
}
e
.
saveBurn
(
event
)
e
.
saveUndoneEvent
(
event
)
ch
<-
event
// 需要保存这个事件,用于确认销毁成功。
}
else
{
// TODO 在公链一侧,用户发起注销,余额不够,交易失败.
// e.deleteUndoneEvent(srcEvent.TxID)
}
e
.
saveBurn
(
event
)
e
.
saveUndoneEvent
(
event
)
ch
<-
event
// 需要保存这个事件,用于确认销毁成功。
}
else
{
// TODO 在公链一侧,用户发起注销,余额不够,交易失败.
// e.deleteUndoneEvent(srcEvent.TxID)
break
}
}
case
types33
.
ExecPack
:
// 打包:交易
logger
.
Error
(
"exec error!"
,
"tx:"
,
tx
,
"height:"
,
item
.
Block
.
Height
,
)
case
types33
.
ExecErr
:
// Error
logger
.
Error
(
"transaction error "
,
"tx:"
,
tx
,
"height:"
,
item
.
Block
.
Height
,
)
case
types33
.
ExecPack
:
logger
.
Error
(
"exec error!"
,
default
:
logger
.
Error
(
"exec type error!"
,
"tx:"
,
tx
,
"height:"
,
item
.
Block
.
Height
,
)
// 打包:交易
}
}
}
...
...
@@ -444,7 +451,7 @@ func (e *Evmxgo) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
Recipient
:
event
.
Payload
.
LockAddress
,
Extra
:
ibtp
.
Payload
,
// TODO 附加已经完成的事件
}
tx
.
Payload
=
types33
.
Encode
(
mint
)
tx
.
Payload
=
types33
.
Encode
(
mint
)
// TODO
e
.
saveLock
(
event
)
}
else
if
event
.
Payload
.
EventType
==
typess
.
EventType_UnLock
{
...
...
go.mod
View file @
813dbbe5
...
...
@@ -59,7 +59,7 @@ require (
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/huandu/xstrings v1.3.2 // 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/joho/godotenv v1.3.0 // indirect
github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff // indirect
...
...
go.sum
View file @
813dbbe5
...
...
@@ -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/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.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/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
...
...
paracross/paracross.go
View file @
813dbbe5
...
...
@@ -568,6 +568,7 @@ func (p *Paracross) getNodeStatus(tx *types33.Transaction) (*paracorssTypes.Para
if
err
!=
nil
{
return
nil
,
err
}
// TODO fix bug
return
&
paracorssTypes
.
ParacrossNodeStatus
{
MainBlockHash
:
blockDetail
.
Block
.
MainHash
,
// 跨链交易在主链时高度的hash
MainBlockHeight
:
blockDetail
.
Block
.
MainHeight
,
// 跨链交易在主链时的高度
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment