feat:support erc20 interchain

This commit is contained in:
jzhe 2021-04-29 10:15:53 +08:00
parent 49aa2a5545
commit 000f8ebeeb
12 changed files with 5284 additions and 171 deletions

2
go.mod
View File

@ -28,7 +28,7 @@ require (
github.com/magiconair/properties v1.8.4
github.com/meshplus/bitxhub-core v1.3.0
github.com/meshplus/bitxhub-kit v1.2.0
github.com/meshplus/bitxhub-model v1.2.0
github.com/meshplus/bitxhub-model v1.2.1-0.20210429021628-d64a34d749b4
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a
github.com/meshplus/did-registry v0.0.0-20210413035015-509c6c3a0bae
github.com/meshplus/go-libp2p-cert v0.0.0-20210125063330-7c25fd5b7a49

25
go.sum
View File

@ -126,6 +126,7 @@ github.com/cbergoon/merkletree v0.2.0 h1:Bttqr3OuoiZEo4ed1L7fTasHka9II+BF9fhBfbN
github.com/cbergoon/merkletree v0.2.0/go.mod h1:5c15eckUgiucMGDOCanvalj/yJnD+KAZj1qyJtRW5aM=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
@ -192,6 +193,7 @@ github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUn
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf h1:sh8rkQZavChcmakYiSlqu2425CHyFXLZZnvm7PDpU8M=
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
@ -221,6 +223,7 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc h1:jtW8jbpkO4YirRSyepBOH8E+2HEw6/hKkBvFPwhUN8c=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
@ -553,6 +556,7 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0=
@ -817,10 +821,6 @@ github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpe
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210318102029-494ee3060b0c/go.mod h1:G19Wrz1u66UmwaES/iLM19jmlv3APAZ5qfYOlNnIIZw=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210423140028-7c7e2fd80a46 h1:ZX6J+BcLFuxzCmC8yf7DC5ah9MVJ+birGL5xd5SMdgY=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210423140028-7c7e2fd80a46/go.mod h1:ijf/8xybq2lGz86VKSTghDQGrKhx7GHavDQpCJWcsDs=
github.com/meshplus/bitxhub-core v1.2.0 h1:tSOIN3Fg89UJwu0XhlCIP+oCLwhg/TP4JQehTFp4Las=
github.com/meshplus/bitxhub-core v1.2.0/go.mod h1:2ksSKEiox4B06gSPT6h4+GcdWnh92/FDPUUImX/dI04=
github.com/meshplus/bitxhub-core v1.3.0 h1:bv4iAQMk7tg0Gz6WfoC3q1/ssLhE0czNnUcLglWrltM=
github.com/meshplus/bitxhub-core v1.3.0/go.mod h1:2ksSKEiox4B06gSPT6h4+GcdWnh92/FDPUUImX/dI04=
github.com/meshplus/bitxhub-kit v1.1.1 h1:vkPO88oA3+Kpc0N8lIgfj/U52KBuI+633hPbMYt1xm8=
@ -831,25 +831,15 @@ github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d h1:J9tzTNf2
github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d/go.mod h1:KR7ZlXhII9n0Bu8viaZTScvXCYn0MCQnYlsTvHPp0XA=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210112075018-319e668d6359 h1:GdgS14bnCF4b/a5zhQi2wlu92pHc9cfl6A1HcbO7zmE=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210112075018-319e668d6359/go.mod h1:KR7ZlXhII9n0Bu8viaZTScvXCYn0MCQnYlsTvHPp0XA=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210423082909-97edee705d22 h1:4PguI96NAg5IFHTnUi0YGQ9HgSiV3K0b/PkxaWRmUrg=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210423082909-97edee705d22/go.mod h1:ltiaMnupw2mzE1gENiV6LF6C8UYu0bF7w1NrG3QDvFQ=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210425013549-7a642723d279/go.mod h1:ltiaMnupw2mzE1gENiV6LF6C8UYu0bF7w1NrG3QDvFQ=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210425020456-3e87ac09c707 h1:xkeoue4sog72PnVVmPrcGgGiQDjaougHallr4RjDTEk=
github.com/meshplus/bitxhub-kit v1.1.2-0.20210425020456-3e87ac09c707/go.mod h1:Zs4eZnVtI0uX6aIMN7DnqXCJTthQ0WNrjF1/h6KkGRc=
github.com/meshplus/bitxhub-kit v1.2.0 h1:lG6vyRD14bPoQFNU8ygmgzMXAy4xDlEueJyM6vShndo=
github.com/meshplus/bitxhub-kit v1.2.0/go.mod h1:vGTKDkCAU7/IlirT6tlq6BMnCpY9UbfrrwGDy6foQIg=
github.com/meshplus/bitxhub-model v1.1.1/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
github.com/meshplus/bitxhub-model v1.1.2-0.20210409090411-de23bd385c5f/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
github.com/meshplus/bitxhub-model v1.1.2-0.20210423135747-9546174eabb0/go.mod h1:rW2Sd4ZFdBoch0h4i1lSuyHNFIOg/3t8loQ+LV5rvNc=
github.com/meshplus/bitxhub-model v1.1.2-0.20210425021723-411f67ad49be h1:SGCgDzpMEu/cpjlewBrotZmGujB9tPOEL614CrJxlLk=
github.com/meshplus/bitxhub-model v1.1.2-0.20210425021723-411f67ad49be/go.mod h1:XIfxB6AAi0D5Qd7jmOykijSvI0GSKQZRR0OG0cp23iU=
github.com/meshplus/bitxhub-model v1.1.2-0.20210426012554-bb170814ec11 h1:rdevlFfnfLNvoSfnJx/pdJkfUHAQGoJfyqxDxWOyhJw=
github.com/meshplus/bitxhub-model v1.1.2-0.20210426012554-bb170814ec11/go.mod h1:XIfxB6AAi0D5Qd7jmOykijSvI0GSKQZRR0OG0cp23iU=
github.com/meshplus/bitxhub-model v1.1.2-0.20210426065438-954f4d830abc h1:Xdr93A4XsYXzI0Sxcmrvsl9aDt0QGnaXfs8i1vbGmhk=
github.com/meshplus/bitxhub-model v1.1.2-0.20210426065438-954f4d830abc/go.mod h1:XIfxB6AAi0D5Qd7jmOykijSvI0GSKQZRR0OG0cp23iU=
github.com/meshplus/bitxhub-model v1.2.0 h1:Ac8ol1HZNLIegyZkU/DZGYkPeeAWp3ZgYsbJGNF2GV0=
github.com/meshplus/bitxhub-model v1.2.0/go.mod h1:QCYJy8fUQex0cvxqAZtGHJn31F5mwuXnE3Lyri15zUc=
github.com/meshplus/bitxhub-model v1.2.1-0.20210429021628-d64a34d749b4 h1:qfn8eq0RJyIsTbUkoXPKYsGIvW29pZl/bsWjGB6bLDE=
github.com/meshplus/bitxhub-model v1.2.1-0.20210429021628-d64a34d749b4/go.mod h1:2zFpbwQ/2y7JiTCsnLYSa3XTF1jTz0ElsQJhUksj2EE=
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a h1:c4ESPDa60Jd4zfzZIGGTyzhfaVM3vKN+xV2G9BwIDGQ=
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a/go.mod h1:vAldSRfDe2Qo7exsSTbchVmZWXPY7fhWQrRw18QJHho=
github.com/meshplus/did-registry v0.0.0-20210413035015-509c6c3a0bae h1:E4iaFwHAg1ScyiU9Bz3RY0wjfXNZzPH3O43DBTl9iWg=
@ -1433,6 +1423,7 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@ -1543,6 +1534,7 @@ gopkg.in/src-d/go-cli.v0 v0.0.0-20181105080154-d492247bbc0d/go.mod h1:z+K8VcOYVY
gopkg.in/src-d/go-log.v1 v1.0.1/go.mod h1:GN34hKP0g305ysm2/hctJ0Y8nWP3zxXXJ8GFabTyABE=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
@ -1559,6 +1551,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2 h1:VEmvx0P+GVTgkNu2EdTN988YCZPcD3lo9AoczZpucwc=
gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -128,12 +128,12 @@ func GenerateBitXHubWithoutOrder(rep *repo.Repo) (*BitXHub, error) {
}
// 1. create executor and view executor
txExec, err := executor.New(rwLdg, loggers.Logger(loggers.Executor), rep.Config.Executor.Type, rep.Config.GasLimit)
txExec, err := executor.New(rwLdg, loggers.Logger(loggers.Executor), *rep.Config)
if err != nil {
return nil, fmt.Errorf("create BlockExecutor: %w", err)
}
viewExec, err := executor.New(viewLdg, loggers.Logger(loggers.Executor), rep.Config.Executor.Type, rep.Config.GasLimit)
viewExec, err := executor.New(viewLdg, loggers.Logger(loggers.Executor), *rep.Config)
if err != nil {
return nil, fmt.Errorf("create ViewExecutor: %w", err)
}

View File

@ -162,6 +162,8 @@ func (b *BrokerAPI) FetchSignsFromOtherPeers(id string, typ pb.GetMultiSignsRequ
address, sign, err = b.requestIBTPSignPeer(pid, id)
case pb.GetMultiSignsRequest_BLOCK_HEADER:
address, sign, err = b.requestBlockHeaderSignFromPeer(pid, id)
case pb.GetMultiSignsRequest_MINT:
address, sign, err = b.requestMintSignFromPeer(pid, id)
}
if err != nil {
@ -250,6 +252,29 @@ func (b *BrokerAPI) requestBlockHeaderSignFromPeer(pid uint64, height string) (s
return data.Address, data.Signature, nil
}
func (b *BrokerAPI) requestMintSignFromPeer(pid uint64, height string) (string, []byte, error) {
req := pb.Message{
Type: pb.Message_FETCH_MINT_SIGN,
Data: []byte(height),
}
resp, err := b.bxh.PeerMgr.Send(pid, &req)
if err != nil {
return "", nil, err
}
if resp == nil || resp.Type != pb.Message_FETCH_MINT_SIGN_ACK {
return "", nil, fmt.Errorf("invalid fetch minter sign resp")
}
data := model.MerkleWrapperSign{}
if err := data.Unmarshal(resp.Data); err != nil {
return "", nil, err
}
return data.Address, data.Signature, nil
}
func (b *BrokerAPI) GetSign(content string, typ pb.GetMultiSignsRequest_Type) (string, []byte, error) {
switch typ {
case pb.GetMultiSignsRequest_ASSET_EXCHANGE:

View File

@ -0,0 +1,164 @@
package contracts
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/meshplus/bitxhub-core/boltvm"
"github.com/meshplus/bitxhub/internal/executor/oracle/appchain"
"github.com/sirupsen/logrus"
)
const (
EscrowsAddrKey = "escrows_addr_key"
MINT_HASH_PREFIX = "mint"
)
type EscrowsAddr struct {
EscrowsAddr string `json:"addr"`
}
type EthHeaderManager struct {
boltvm.Stub
oracle *appchain.EthLightChainOracle
}
func NewEthHeaderManager(path string, logger logrus.FieldLogger) *EthHeaderManager {
ropstenOracle, err := appchain.NewRopstenOracle(path, logger)
if err != nil {
panic(err)
}
return &EthHeaderManager{oracle: ropstenOracle}
}
func (ehm *EthHeaderManager) SetEscrowAddr(addr string) *boltvm.Response {
//TODO:add governance
ok := common.IsHexAddress(addr)
if ok {
escrowsAddr := EscrowsAddr{addr}
ehm.SetObject(EscrowsAddrKey, escrowsAddr)
}
return boltvm.Success([]byte(addr))
}
func (ehm *EthHeaderManager) GetEscrowAddr() *boltvm.Response {
var escrowsAddr EscrowsAddr
ok := ehm.GetObject(EscrowsAddrKey, escrowsAddr)
if ok {
return boltvm.Success([]byte(escrowsAddr.EscrowsAddr))
}
return boltvm.Error("not found")
}
func (ehm *EthHeaderManager) InsertBlockHeaders(headersData []byte) *boltvm.Response {
headers := make([]*types.Header, 0)
err := json.Unmarshal(headersData, &headers)
if err != nil {
return boltvm.Error(err.Error())
}
num, err := ehm.oracle.InsertBlockHeaders(headers)
if err != nil {
return boltvm.Error(err.Error())
}
return boltvm.Success([]byte(strconv.Itoa(num)))
}
func (ehm *EthHeaderManager) CurrentBlockHeader() *boltvm.Response {
header := ehm.oracle.CurrentHeader()
if header == nil {
return boltvm.Error("not found")
}
data, err := header.MarshalJSON()
if err != nil {
return boltvm.Error(err.Error())
}
return boltvm.Success(data)
}
func (ehm *EthHeaderManager) GetBlockHeader(hash string) *boltvm.Response {
header := ehm.oracle.GetHeader(common.HexToHash(hash))
if header == nil {
return boltvm.Error("not found")
}
data, err := header.MarshalJSON()
if err != nil {
return boltvm.Error(err.Error())
}
return boltvm.Success(data)
}
func (ehm *EthHeaderManager) PreMint(receiptData []byte, proofData []byte) *boltvm.Response {
var receipt types.Receipt
err := receipt.UnmarshalJSON(receiptData)
if err != nil {
return boltvm.Error(err.Error())
}
err = ehm.oracle.VerifyProof(&receipt, proofData)
if err != nil {
return boltvm.Error(err.Error())
}
escrowsLockEvent, err := ehm.unpackEscrowsLock(&receipt)
if err != nil {
return boltvm.Error(err.Error())
}
//abi.encodePacked
hash := crypto.Keccak256Hash(
escrowsLockEvent.EthToken.Bytes(),
escrowsLockEvent.RelayToken.Bytes(),
escrowsLockEvent.Locker.Bytes(),
escrowsLockEvent.Recipient.Bytes(),
common.LeftPadBytes(escrowsLockEvent.Amount.Bytes(), 32),
)
prefixedHash := crypto.Keccak256Hash(
[]byte(fmt.Sprintf("\x19Ethereum Signed Message:\n%v", len(hash))),
hash.Bytes(),
)
ehm.SetObject(MintKey(prefixedHash.String()), escrowsLockEvent)
return boltvm.Success(prefixedHash.Bytes())
}
func (ehm *EthHeaderManager) unpackEscrowsLock(receipt *types.Receipt) (*appchain.EscrowsLock, error) {
escrowsAbi, err := abi.JSON(bytes.NewReader([]byte(appchain.EscrowsABI)))
if err != nil {
return nil, err
}
var escrowsAddr EscrowsAddr
ok := ehm.GetObject(EscrowsAddrKey, escrowsAddr)
if !ok {
return nil, fmt.Errorf("not found the escrows contract address")
}
var lock *appchain.EscrowsLock
for _, log := range receipt.Logs {
if !strings.EqualFold(log.Address.String(), escrowsAddr.EscrowsAddr) {
continue
}
if log.Removed {
continue
}
for _, topic := range log.Topics {
if strings.EqualFold(topic.String(), escrowsAbi.Events["Lock"].ID.String()) {
if err := escrowsAbi.UnpackIntoInterface(&lock, "Lock", log.Data); err != nil {
continue
}
}
}
}
if lock == nil {
return nil, fmt.Errorf("not found the escrow lock event")
}
return lock, nil
}
func MintKey(hash string) string {
return fmt.Sprintf("%s-%s", MINT_HASH_PREFIX, hash)
}

View File

@ -17,6 +17,7 @@ import (
"github.com/meshplus/bitxhub/internal/executor/contracts"
"github.com/meshplus/bitxhub/internal/ledger"
"github.com/meshplus/bitxhub/internal/model/events"
"github.com/meshplus/bitxhub/internal/repo"
"github.com/meshplus/bitxhub/pkg/proof"
"github.com/meshplus/bitxhub/pkg/vm/boltvm"
"github.com/sirupsen/logrus"
@ -51,13 +52,14 @@ type BlockExecutor struct {
evm *vm.EVM
evmChainCfg *params.ChainConfig
gasLimit uint64
config repo.Config
}
// New creates executor instance
func New(chainLedger ledger.Ledger, logger logrus.FieldLogger, typ string, gasLimit uint64) (*BlockExecutor, error) {
ibtpVerify := proof.New(chainLedger, logger)
func New(chainLedger ledger.Ledger, logger logrus.FieldLogger, config repo.Config) (*BlockExecutor, error) {
txsExecutor, err := agency.GetExecutorConstructor(typ)
ibtpVerify := proof.New(chainLedger, logger)
txsExecutor, err := agency.GetExecutorConstructor(config.Executor.Type)
if err != nil {
return nil, err
}
@ -78,12 +80,13 @@ func New(chainLedger ledger.Ledger, logger logrus.FieldLogger, typ string, gasLi
currentBlockHash: chainLedger.GetChainMeta().BlockHash,
wasmInstances: make(map[string]wasmer.Instance),
evmChainCfg: newEVMChainCfg(),
gasLimit: gasLimit,
config: config,
gasLimit: config.GasLimit,
}
blockExecutor.evm = newEvm(1, uint64(0), blockExecutor.evmChainCfg, blockExecutor.ledger.StateDB())
blockExecutor.txsExecutor = txsExecutor(blockExecutor.applyTx, registerBoltContracts, logger)
blockExecutor.txsExecutor = txsExecutor(blockExecutor.applyTx, blockExecutor.registerBoltContracts, logger)
return blockExecutor, nil
}
@ -222,7 +225,7 @@ func (exec *BlockExecutor) persistData() {
}
}
func registerBoltContracts() map[string]agency.Contract {
func (exec *BlockExecutor) registerBoltContracts() map[string]agency.Contract {
boltContracts := []*boltvm.BoltContract{
{
Enabled: true,
@ -278,6 +281,12 @@ func registerBoltContracts() map[string]agency.Contract {
Address: constant.GovernanceContractAddr.Address().String(),
Contract: &contracts.Governance{},
},
{
Enabled: true,
Name: "ethereum header service",
Address: constant.EthHeaderMgrContractAddr.Address().String(),
Contract: contracts.NewEthHeaderManager(exec.config.RepoRoot, exec.logger),
},
}
ContractsInfo := agency.GetRegisteredContractInfo()

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,147 @@
package appchain
import (
"bytes"
"fmt"
"path/filepath"
"sort"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/sirupsen/logrus"
)
type EthLightChainOracle struct {
lc *light.LightChain
logger logrus.FieldLogger
}
const (
MinConfirmNum = 15
// block 10105112
RopstenHeader = "{\"parentHash\":\"0x4672d904ca88bdb365f83bc6050344fdcb672ce8e639e727f8c69247634e73f0\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"miner\":\"0x1cdb00d07b721b98da52532db9a7d82d2a4bf2e0\",\"stateRoot\":\"0x823fbc8d2cf2d9c32832c6c1bd451ea84acdd79e39e88a7061215746a0794f40\",\"transactionsRoot\":\"0x65abe72faaaa113cf0a9374cefde93bc64cd264e2931ba95ee27c8d62499e63d\",\"receiptsRoot\":\"0xfac424a8e1a45789a5456fe1bc58228d93c28871df42dd789434e4de65f7e2e9\",\"logsBloom\":\"0x00200000000000000000000080000000000000000000000080010000000000000000000000000000020000000000000000000000000000000000000000200000000000000008000000000008000000200000000800000000000000020002000000000000080000000000000000000000000000000000000000000010000000000800000000000000014000000000000000000000000000080000004000000000020000000000000140000000000000000000001000000000001000000000000000000002000000200004000000002200000000000000003000000000020020000010000000000000000000000201000000000080000000000000000400000000\",\"difficulty\":\"0x729df1d\",\"number\":\"0x9a3118\",\"gasLimit\":\"0x98f36f\",\"gasUsed\":\"0x2fd96\",\"timestamp\":\"0x608506bf\",\"extraData\":\"0xd683010a01846765746886676f312e3136856c696e7578\",\"mixHash\":\"0x62c65e608f10001004171345c230a231afed11dad637b93545f600b71adb0f5d\",\"nonce\":\"0x7ea6f1aedb5ea8c1\",\"hash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\"}\n"
)
// TODO: need to start with special header height
func NewRinkebyOracle(storagePath string, logger logrus.FieldLogger) (*EthLightChainOracle, error) {
appchainBlockHeaderPath := filepath.Join(storagePath, "eth_rinkeby")
db, err := leveldb.New(appchainBlockHeaderPath, 256, 0, "", false)
if err != nil {
return nil, err
}
database := rawdb.NewDatabase(db)
core.DefaultRinkebyGenesisBlock().MustCommit(database)
lc, err := light.NewLightChain(les.NewLesOdr(database, light.DefaultServerIndexerConfig, nil, nil),
core.DefaultRinkebyGenesisBlock().Config, clique.New(params.RinkebyChainConfig.Clique, database), params.RinkebyTrustedCheckpoint)
if err != nil {
return nil, err
}
return &EthLightChainOracle{lc: lc, logger: logger}, nil
}
// NewRopstenOracle inits with ropsten block 10105112, receives above the 10105112 headers
func NewRopstenOracle(storagePath string, logger logrus.FieldLogger) (*EthLightChainOracle, error) {
appchainBlockHeaderPath := filepath.Join(storagePath, "eth_ropsten")
db, err := leveldb.New(appchainBlockHeaderPath, 256, 0, "", false)
if err != nil {
return nil, err
}
database := rawdb.NewDatabase(db)
// block 10105112
header := types.Header{}
err = header.UnmarshalJSON([]byte(RopstenHeader))
if head := rawdb.ReadHeadHeaderHash(database); head == (common.Hash{}) {
core.DefaultRopstenGenesisBlock().MustCommit(database)
rawdb.WriteHeader(database, &header)
rawdb.WriteTd(database, header.Hash(), header.Number.Uint64(), header.Difficulty)
rawdb.WriteCanonicalHash(database, header.Hash(), header.Number.Uint64())
rawdb.WriteHeadBlockHash(database, header.Hash())
rawdb.WriteHeadFastBlockHash(database, header.Hash())
rawdb.WriteHeadHeaderHash(database, header.Hash())
}
lc, err := light.NewLightChain(les.NewLesOdr(database, light.DefaultServerIndexerConfig, nil, nil),
core.DefaultRopstenGenesisBlock().Config, ethash.New(ethash.Config{}, nil, false), params.RopstenTrustedCheckpoint)
if err != nil {
return nil, err
}
return &EthLightChainOracle{lc: lc, logger: logger}, nil
}
// InsertBlockHeaders attempts to insert the given header chain in to the local
// chain, possibly creating a reorg. If an error is returned, it will return the
// index number of the failing header as well an error describing what went wrong.
// Ropsten receives the block header after the height of 10105112
func (oracle *EthLightChainOracle) InsertBlockHeaders(headers []*types.Header) (int, error) {
if len(headers) == 0 {
return 0, fmt.Errorf("insert empty headers")
}
sort.Slice(headers, func(i, j int) bool {
return headers[i].Number.Cmp(headers[j].Number) < 0
})
oracle.logger.WithFields(logrus.Fields{
"start": headers[0].Number.Uint64(),
"end": headers[len(headers)-1].Number.Uint64(),
}).Debugf("insert ethereum block headers")
return oracle.lc.InsertHeaderChain(headers, 0)
}
// CurrentHeader retrieves the current head header of the canonical chain.
func (oracle *EthLightChainOracle) CurrentHeader() *types.Header {
return oracle.lc.CurrentHeader()
}
// GetHeader retrieves a block header by hash
func (oracle *EthLightChainOracle) GetHeader(hash common.Hash) *types.Header {
return oracle.lc.GetHeaderByHash(hash)
}
func (oracle *EthLightChainOracle) VerifyProof(receipt *types.Receipt, proof []byte) error {
if receipt.Status == 0 {
return fmt.Errorf("receipt status is fail, hash is:%v", receipt.TxHash.String())
}
header := oracle.GetHeader(receipt.BlockHash)
if header == nil {
return fmt.Errorf("not found header:%v", receipt.BlockHash.String())
}
currentHeader := oracle.CurrentHeader()
if currentHeader.Number.Uint64()-header.Number.Uint64() < MinConfirmNum {
return fmt.Errorf("not enough confirmed")
}
keyBuf := bytes.Buffer{}
keyBuf.Reset()
if err := rlp.Encode(&keyBuf, receipt.TransactionIndex); err != nil {
return err
}
nodeList := &light.NodeList{}
if err := rlp.DecodeBytes(proof, nodeList); err != nil {
return err
}
value, err := trie.VerifyProof(header.ReceiptHash, keyBuf.Bytes(), nodeList.NodeSet())
if err != nil {
return err
}
receiptData, err := rlp.EncodeToBytes(receipt)
if err != nil {
return err
}
if !bytes.Equal(receiptData, value) {
return fmt.Errorf("invaild receipt:%v", receipt.TxHash.String())
}
return nil
}

View File

@ -0,0 +1,124 @@
package appchain
import (
"bytes"
"io/ioutil"
"os"
"testing"
"github.com/meshplus/bitxhub-kit/log"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
)
// block headers from infura api server
const (
RinkebyHeader1 = "{\"parentHash\":\"0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"stateRoot\":\"0x53580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2d\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"difficulty\":\"0x2\",\"number\":\"0x1\",\"gasLimit\":\"0x47c94c\",\"gasUsed\":\"0x0\",\"timestamp\":\"0x58ee45da\",\"extraData\":\"0xd783010600846765746887676f312e372e33856c696e757800000000000000009f1efa1efa72af138c915966c639544a0255e6288e188c22ce9168c10dbe46da3d88b4aa065930119fb886210bf01a084fde5d3bc48d8aa38bca92e4fcc5215100\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"nonce\":\"0x0000000000000000\",\"hash\":\"0xa7684ac44d48494670b2e0d9085b7750e7341620f0a271db146ed5e70c1db854\"}\n"
RinkebyHeader2 = "{\"parentHash\":\"0xa7684ac44d48494670b2e0d9085b7750e7341620f0a271db146ed5e70c1db854\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"stateRoot\":\"0x53580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2d\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"difficulty\":\"0x2\",\"number\":\"0x2\",\"gasLimit\":\"0x47db3d\",\"gasUsed\":\"0x0\",\"timestamp\":\"0x58ee45ea\",\"extraData\":\"0xd783010600846765746887676f312e372e33856c696e75780000000000000000b5a4a624d2e19fdab62ff7f4d2f2b80dfab4c518761beb56c2319c4224dd156f698bb1a2750c7edf12d61c4022079622062039637f40fb817e2cce0f0a4dae9c01\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"nonce\":\"0x0000000000000000\",\"hash\":\"0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9\"}\n"
RinkebyHeader3 = "{\"parentHash\":\"0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"stateRoot\":\"0x53580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2d\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"difficulty\":\"0x2\",\"number\":\"0x3\",\"gasLimit\":\"0x47e7c4\",\"gasUsed\":\"0x0\",\"timestamp\":\"0x58ee45f9\",\"extraData\":\"0xd783010600846765746887676f312e372e33856c696e757800000000000000004e10f96536e45ceca7e34cc1bdda71db3f3bb029eb69afd28b57eb0202c0ec0859d383a99f63503c4df9ab6c1dc63bf6b9db77be952f47d86d2d7b208e77397301\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"nonce\":\"0x0000000000000000\",\"hash\":\"0x9eb9db9c3ec72918c7db73ae44e520139e95319c421ed6f9fc11fa8dd0cddc56\"}\n"
RopstenHeader1 = "{\"parentHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"miner\":\"0x033ef6db9fbd0ee60e2931906b987fe0280471a0\",\"stateRoot\":\"0xfc22ae06eb79345da19322573c740ccaf4e224e32c916226c0adf7223c881bc5\",\"transactionsRoot\":\"0x792fa9b9b95e586cd5757922f5f06adff5333bd5fb77059d95debcde4a4d5e0d\",\"receiptsRoot\":\"0x23f3951c0cede08fa61c20c77f36c8d7853d0f205f5053ee9a39f4cf68833546\",\"logsBloom\":\"0x00004000000000200000400000008000000010000000020000000000001004000000001000010000000000000000001040100000001000000010091010200000000000000000000000000008000004000000000000108400000100040000000000100000020000080000000020001880000200800000002000000010000018000000000240000000000000008000000000000020000000102020000000800000420004000000000000000000000020000000000000000014000200200000000000000102000000040000080000100000000060000000008000000200000020000010000000000000000000040000080004000000000000000000000000000000\",\"difficulty\":\"0x72ac658\",\"number\":\"0x9a3119\",\"gasLimit\":\"0x98cd34\",\"gasUsed\":\"0x1d58f8\",\"timestamp\":\"0x608506c2\",\"extraData\":\"0xd683010a01846765746886676f312e3136856c696e7578\",\"mixHash\":\"0xdbca2ed1c216550ef4d7f63d1c223da0530fc196f14960e70ac8f384cd0f8d63\",\"nonce\":\"0x2293d516a92c2912\",\"hash\":\"0x6a04391a825d6a5a7a247c6e5134f020abec8f8073b1eb1fc778bd9e1502b852\"}\n"
RopstenHeader2 = "{\"parentHash\":\"0x6a04391a825d6a5a7a247c6e5134f020abec8f8073b1eb1fc778bd9e1502b852\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"miner\":\"0x773b556e7f3222f3b93d6519484cef0c443b9d7e\",\"stateRoot\":\"0xc45bd719ef83edd7f6afbaa7afb43a3422ef9ca0faf6853565dbd04671a0736f\",\"transactionsRoot\":\"0xf2a97635c98b8c96c6977e5e16418f9b480c0bd6f4922d15a34dffac2a2b23de\",\"receiptsRoot\":\"0x400c370ac70c3031022c8fd923fbff191f5dcfa6b4454e90ef8c5de8d9475af3\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000020000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000\",\"difficulty\":\"0x72ac858\",\"number\":\"0x9a311a\",\"gasLimit\":\"0x98a702\",\"gasUsed\":\"0xd09e6\",\"timestamp\":\"0x608506cb\",\"extraData\":\"0xd683010a01846765746886676f312e3136856c696e7578\",\"mixHash\":\"0xc7d603705499308d968e7e4687325bc227fbe104d62f0bd53eeff154e2749223\",\"nonce\":\"0x3733ef9174a63f69\",\"hash\":\"0x91c4c53daae0fc7fec3310c2c60597349f84183322b1bdaec9faf9a602627151\"}\n"
)
func TestRinkebyLightClient(t *testing.T) {
repoRoot, err := ioutil.TempDir("", "TestRinkebyLightClient")
require.Nil(t, err)
defer os.RemoveAll(repoRoot)
oracle, err := NewRinkebyOracle(repoRoot, log.NewWithModule("test"))
require.Nil(t, err)
header1 := types.Header{}
err = header1.UnmarshalJSON([]byte(RinkebyHeader1))
require.Nil(t, err)
header2 := types.Header{}
err = header2.UnmarshalJSON([]byte(RinkebyHeader2))
require.Nil(t, err)
header3 := types.Header{}
err = header3.UnmarshalJSON([]byte(RinkebyHeader3))
require.Nil(t, err)
num, err := oracle.InsertBlockHeaders([]*types.Header{&header1, &header2})
require.Nil(t, err)
require.Equal(t, num, 0)
}
func TestRopstenLightClient(t *testing.T) {
repoRoot, err := ioutil.TempDir("", "TestRopstenLightClient")
require.Nil(t, err)
defer os.RemoveAll(repoRoot)
oracle, err := NewRopstenOracle(repoRoot, log.NewWithModule("test"))
require.Nil(t, err)
currentHeader := oracle.CurrentHeader()
header1 := &types.Header{}
err = header1.UnmarshalJSON([]byte(RopstenHeader1))
require.Nil(t, err)
require.Equal(t, currentHeader.Number.Uint64(), header1.Number.Uint64()-1)
header2 := &types.Header{}
err = header2.UnmarshalJSON([]byte(RopstenHeader2))
require.Nil(t, err)
require.Equal(t, currentHeader.Number.Uint64(), header2.Number.Uint64()-2)
num, err := oracle.InsertBlockHeaders([]*types.Header{header1, header2})
require.Nil(t, err)
require.Equal(t, 0, num)
}
func TestVerifyProof(t *testing.T) {
repoRoot, err := ioutil.TempDir("", "TestRopstenLightClient")
require.Nil(t, err)
defer os.RemoveAll(repoRoot)
var (
receipt0 = "{\"root\":\"0x\",\"status\":\"0x1\",\"cumulativeGasUsed\":\"0x11336\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000008000000000008000000000000000000000000000000020002000000000000000000000000000000000000000000000000000000000010000000000800000000000000010000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000002000000000004000000000200000000000000002000000000000000000010000000000000000000000001000000000000000000000000000000000000\",\"logs\":[{\"address\":\"0x7a9a60a43edd1d885f9e672dd498c829b101dd07\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x0000000000000000000000002266463a8b23ddfc606670a06b0ce2e66011f1bf\",\"0x0000000000000000000000000de52d48482bf7f8a4c94bfdbdedd2319e99e92f\"],\"data\":\"0x00000000000000000000000000000000000000000000043c33c1937564800000\",\"blockNumber\":\"0x9a3118\",\"transactionHash\":\"0xba4d94730e0e76992538f19597cc41669d154c103b2ad77fb53ce18c4c0fc3cd\",\"transactionIndex\":\"0x0\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"logIndex\":\"0x0\",\"removed\":false},{\"address\":\"0x7a9a60a43edd1d885f9e672dd498c829b101dd07\",\"topics\":[\"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925\",\"0x0000000000000000000000002266463a8b23ddfc606670a06b0ce2e66011f1bf\",\"0x0000000000000000000000000de52d48482bf7f8a4c94bfdbdedd2319e99e92f\"],\"data\":\"0xfffffffffffffffffffffffffffffffffffffffffffffbc3cc3e6c8a9b7fffff\",\"blockNumber\":\"0x9a3118\",\"transactionHash\":\"0xba4d94730e0e76992538f19597cc41669d154c103b2ad77fb53ce18c4c0fc3cd\",\"transactionIndex\":\"0x0\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"logIndex\":\"0x1\",\"removed\":false}],\"transactionHash\":\"0xba4d94730e0e76992538f19597cc41669d154c103b2ad77fb53ce18c4c0fc3cd\",\"contractAddress\":\"0x0000000000000000000000000000000000000000\",\"gasUsed\":\"0x11336\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"blockNumber\":\"0x9a3118\",\"transactionIndex\":\"0x0\"}\n"
receipt1 = "{\"root\":\"0x\",\"status\":\"0x1\",\"cumulativeGasUsed\":\"0x1653e\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"logs\":[],\"transactionHash\":\"0xcb158ce1be4b6648dcdc69dedbe7ddda8e3aa284db7dacdb5b22401e9a454845\",\"contractAddress\":\"0x0000000000000000000000000000000000000000\",\"gasUsed\":\"0x5208\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"blockNumber\":\"0x9a3118\",\"transactionIndex\":\"0x1\"}\n"
receipt2 = "{\"root\":\"0x\",\"status\":\"0x1\",\"cumulativeGasUsed\":\"0x2fd96\",\"logsBloom\":\"0x00200000000000000000000080000000000000000000000080010000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000008000000200000000800000000000000000000000000000000080000000000000000000000000000000000000000000010000000000000000000000000004000000000000000000000000000080000004000000000000000000000000140000000000000000000001000000000001000000000000000000002000000200000000000002000000000000000001000000000020020000000000000000000000000000200000000000080000000000000000400000000\",\"logs\":[{\"address\":\"0x2d80502854fc7304c3e3457084de549f5016b73f\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x0000000000000000000000004183d62963434056e75e9854bc4ba92aa43a2d08\",\"0x000000000000000000000000dc914190feeb16d6f7c5d9a22826d515be5c5857\"],\"data\":\"0x00000000000000000000000000000000000000000000000000000000000b4cc6\",\"blockNumber\":\"0x9a3118\",\"transactionHash\":\"0x37fc9bf0e945443c862efe5405d9a179dced048c3baed58751f00d84ba64701c\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"logIndex\":\"0x2\",\"removed\":false},{\"address\":\"0x0d9c8723b343a8368bebe0b5e89273ff8d712e3c\",\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\",\"0x000000000000000000000000dc914190feeb16d6f7c5d9a22826d515be5c5857\",\"0x0000000000000000000000004183d62963434056e75e9854bc4ba92aa43a2d08\"],\"data\":\"0x0000000000000000000000000000000000000000000000000000000015ee0375\",\"blockNumber\":\"0x9a3118\",\"transactionHash\":\"0x37fc9bf0e945443c862efe5405d9a179dced048c3baed58751f00d84ba64701c\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"logIndex\":\"0x3\",\"removed\":false},{\"address\":\"0xdc914190feeb16d6f7c5d9a22826d515be5c5857\",\"topics\":[\"0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1\"],\"data\":\"0x00000000000000000000000000000000000000000000000000001a4f9e78bc5e0000000000000000000000000000000000000000000000000000000d8457df78\",\"blockNumber\":\"0x9a3118\",\"transactionHash\":\"0x37fc9bf0e945443c862efe5405d9a179dced048c3baed58751f00d84ba64701c\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"logIndex\":\"0x4\",\"removed\":false},{\"address\":\"0xdc914190feeb16d6f7c5d9a22826d515be5c5857\",\"topics\":[\"0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822\",\"0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d\",\"0x0000000000000000000000004183d62963434056e75e9854bc4ba92aa43a2d08\"],\"data\":\"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b4cc60000000000000000000000000000000000000000000000000000000015ee03750000000000000000000000000000000000000000000000000000000000000000\",\"blockNumber\":\"0x9a3118\",\"transactionHash\":\"0x37fc9bf0e945443c862efe5405d9a179dced048c3baed58751f00d84ba64701c\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"logIndex\":\"0x5\",\"removed\":false}],\"transactionHash\":\"0x37fc9bf0e945443c862efe5405d9a179dced048c3baed58751f00d84ba64701c\",\"contractAddress\":\"0x0000000000000000000000000000000000000000\",\"gasUsed\":\"0x19858\",\"blockHash\":\"0x0d37ff8f4a8f1adcfd16add9cf8726e17a8097baa9a50d3b5fd51849476f7ec3\",\"blockNumber\":\"0x9a3118\",\"transactionIndex\":\"0x2\"}\n"
)
receiptList := []string{receipt0, receipt1, receipt2}
oracle, err := NewRopstenOracle(repoRoot, log.NewWithModule("test"))
require.Nil(t, err)
receipts := make([]*types.Receipt, 0, len(receiptList))
for _, r := range receiptList {
var receipt types.Receipt
err := receipt.UnmarshalJSON([]byte(r))
require.Nil(t, err)
receipts = append(receipts, &receipt)
}
tReceipts := types.Receipts(receipts)
keybuf := new(bytes.Buffer)
receiptsTrie := new(trie.Trie)
index := uint64(2)
header := oracle.lc.GetHeaderByHash(receipts[index].BlockHash)
deriveSha := types.DeriveSha(tReceipts, receiptsTrie)
require.Equal(t, header.ReceiptHash, deriveSha)
err = rlp.Encode(keybuf, index)
require.Nil(t, err)
nodeSet := light.NewNodeSet()
err = receiptsTrie.Prove(keybuf.Bytes(), 0, nodeSet)
require.Nil(t, err)
proof, err := rlp.EncodeToBytes(nodeSet.NodeList())
require.Nil(t, err)
err = VerifyProof(receipts[index], header, proof)
require.Nil(t, err)
}

View File

@ -40,6 +40,8 @@ func (swarm *Swarm) handleMessage(s network.Stream, data []byte) {
swarm.handleFetchAssetExchangeSignMessage(s, m.Data)
case pb.Message_FETCH_IBTP_SIGN:
swarm.handleFetchIBTPSignMessage(s, m.Data)
case pb.Message_FETCH_MINT_SIGN:
swarm.handleFetchMinterSignMessage(s, m.Data)
case pb.Message_CHECK_MASTER_PIER:
swarm.handleAskPierMaster(s, m.Data)
case pb.Message_CHECK_MASTER_PIER_ACK:
@ -278,6 +280,52 @@ func (swarm *Swarm) handleFetchIBTPSignMessage(s network.Stream, data []byte) {
}
}
func (swarm *Swarm) handleFetchMinterSignMessage(s network.Stream, data []byte) {
handle := func(id string) (string, []byte, error) {
swarm.logger.WithField("mint id", id).Debug("Handle fetching minter sign message")
ok, _ := swarm.ledger.GetState(constant.EthHeaderMgrContractAddr.Address(), []byte(contracts.MintKey(id)))
if !ok {
return "", nil, fmt.Errorf("cannot find minter record with id %s", id)
}
hash := sha256.Sum256([]byte(fmt.Sprintf("%s", id)))
key := swarm.repo.Key
sign, err := key.PrivKey.Sign(hash[:])
if err != nil {
return "", nil, fmt.Errorf("fetch minter sign: %w", err)
}
return key.Address, sign, nil
}
address, signed, err := handle(string(data))
if err != nil {
swarm.logger.Errorf("handle fetch-minter-sign: %s", err)
return
}
m := model.MerkleWrapperSign{
Address: address,
Signature: signed,
}
body, err := m.Marshal()
if err != nil {
swarm.logger.Errorf("marshal merkle wrapper sign: %s", err)
return
}
msg := &pb.Message{
Type: pb.Message_FETCH_MINT_SIGN_ACK,
Data: body,
}
if err := swarm.SendWithStream(s, msg); err != nil {
swarm.logger.Errorf("send minter sign back: %s", err)
}
}
func (swarm *Swarm) handleGetBlocksPack(s network.Stream, msg *pb.Message) error {
req := &pb.GetBlocksRequest{}
if err := req.Unmarshal(msg.Data); err != nil {

View File

@ -5,8 +5,6 @@
package mock_peermgr
import (
reflect "reflect"
event "github.com/ethereum/go-ethereum/event"
gomock "github.com/golang/mock/gomock"
peer "github.com/libp2p/go-libp2p-core/peer"
@ -14,44 +12,61 @@ import (
events "github.com/meshplus/bitxhub/internal/model/events"
peermgr "github.com/meshplus/bitxhub/pkg/peermgr"
network "github.com/meshplus/go-lightp2p"
reflect "reflect"
)
// MockPeerManager is a mock of PeerManager interface.
// MockPeerManager is a mock of PeerManager interface
type MockPeerManager struct {
ctrl *gomock.Controller
recorder *MockPeerManagerMockRecorder
}
// MockPeerManagerMockRecorder is the mock recorder for MockPeerManager.
// MockPeerManagerMockRecorder is the mock recorder for MockPeerManager
type MockPeerManagerMockRecorder struct {
mock *MockPeerManager
}
// NewMockPeerManager creates a new mock instance.
// NewMockPeerManager creates a new mock instance
func NewMockPeerManager(ctrl *gomock.Controller) *MockPeerManager {
mock := &MockPeerManager{ctrl: ctrl}
mock.recorder = &MockPeerManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockPeerManager) EXPECT() *MockPeerManagerMockRecorder {
return m.recorder
}
// AddNode mocks base method.
func (m *MockPeerManager) AddNode(newNodeID uint64, vpInfo *pb.VpInfo) {
// Start mocks base method
func (m *MockPeerManager) Start() error {
m.ctrl.T.Helper()
m.ctrl.Call(m, "AddNode", newNodeID, vpInfo)
ret := m.ctrl.Call(m, "Start")
ret0, _ := ret[0].(error)
return ret0
}
// AddNode indicates an expected call of AddNode.
func (mr *MockPeerManagerMockRecorder) AddNode(newNodeID, vpInfo interface{}) *gomock.Call {
// Start indicates an expected call of Start
func (mr *MockPeerManagerMockRecorder) Start() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNode", reflect.TypeOf((*MockPeerManager)(nil).AddNode), newNodeID, vpInfo)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockPeerManager)(nil).Start))
}
// AsyncSend mocks base method.
// Stop mocks base method
func (m *MockPeerManager) Stop() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Stop")
ret0, _ := ret[0].(error)
return ret0
}
// Stop indicates an expected call of Stop
func (mr *MockPeerManagerMockRecorder) Stop() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockPeerManager)(nil).Stop))
}
// AsyncSend mocks base method
func (m *MockPeerManager) AsyncSend(arg0 uint64, arg1 *pb.Message) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AsyncSend", arg0, arg1)
@ -59,107 +74,27 @@ func (m *MockPeerManager) AsyncSend(arg0 uint64, arg1 *pb.Message) error {
return ret0
}
// AsyncSend indicates an expected call of AsyncSend.
// AsyncSend indicates an expected call of AsyncSend
func (mr *MockPeerManagerMockRecorder) AsyncSend(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AsyncSend", reflect.TypeOf((*MockPeerManager)(nil).AsyncSend), arg0, arg1)
}
// Broadcast mocks base method.
func (m *MockPeerManager) Broadcast(arg0 *pb.Message) error {
// SendWithStream mocks base method
func (m *MockPeerManager) SendWithStream(arg0 network.Stream, arg1 *pb.Message) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Broadcast", arg0)
ret := m.ctrl.Call(m, "SendWithStream", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Broadcast indicates an expected call of Broadcast.
func (mr *MockPeerManagerMockRecorder) Broadcast(arg0 interface{}) *gomock.Call {
// SendWithStream indicates an expected call of SendWithStream
func (mr *MockPeerManagerMockRecorder) SendWithStream(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Broadcast", reflect.TypeOf((*MockPeerManager)(nil).Broadcast), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendWithStream", reflect.TypeOf((*MockPeerManager)(nil).SendWithStream), arg0, arg1)
}
// CountConnectedPeers mocks base method.
func (m *MockPeerManager) CountConnectedPeers() uint64 {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CountConnectedPeers")
ret0, _ := ret[0].(uint64)
return ret0
}
// CountConnectedPeers indicates an expected call of CountConnectedPeers.
func (mr *MockPeerManagerMockRecorder) CountConnectedPeers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountConnectedPeers", reflect.TypeOf((*MockPeerManager)(nil).CountConnectedPeers))
}
// DelNode mocks base method.
func (m *MockPeerManager) DelNode(delID uint64) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "DelNode", delID)
}
// DelNode indicates an expected call of DelNode.
func (mr *MockPeerManagerMockRecorder) DelNode(delID interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelNode", reflect.TypeOf((*MockPeerManager)(nil).DelNode), delID)
}
// Disconnect mocks base method.
func (m *MockPeerManager) Disconnect(vpInfos map[uint64]*pb.VpInfo) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Disconnect", vpInfos)
}
// Disconnect indicates an expected call of Disconnect.
func (mr *MockPeerManagerMockRecorder) Disconnect(vpInfos interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Disconnect", reflect.TypeOf((*MockPeerManager)(nil).Disconnect), vpInfos)
}
// OtherPeers mocks base method.
func (m *MockPeerManager) OtherPeers() map[uint64]*peer.AddrInfo {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "OtherPeers")
ret0, _ := ret[0].(map[uint64]*peer.AddrInfo)
return ret0
}
// OtherPeers indicates an expected call of OtherPeers.
func (mr *MockPeerManagerMockRecorder) OtherPeers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OtherPeers", reflect.TypeOf((*MockPeerManager)(nil).OtherPeers))
}
// Peers mocks base method.
func (m *MockPeerManager) Peers() map[uint64]*pb.VpInfo {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Peers")
ret0, _ := ret[0].(map[uint64]*pb.VpInfo)
return ret0
}
// Peers indicates an expected call of Peers.
func (mr *MockPeerManagerMockRecorder) Peers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Peers", reflect.TypeOf((*MockPeerManager)(nil).Peers))
}
// PierManager mocks base method.
func (m *MockPeerManager) PierManager() peermgr.PierManager {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PierManager")
ret0, _ := ret[0].(peermgr.PierManager)
return ret0
}
// PierManager indicates an expected call of PierManager.
func (mr *MockPeerManagerMockRecorder) PierManager() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PierManager", reflect.TypeOf((*MockPeerManager)(nil).PierManager))
}
// Send mocks base method.
// Send mocks base method
func (m *MockPeerManager) Send(arg0 uint64, arg1 *pb.Message) (*pb.Message, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Send", arg0, arg1)
@ -168,55 +103,69 @@ func (m *MockPeerManager) Send(arg0 uint64, arg1 *pb.Message) (*pb.Message, erro
return ret0, ret1
}
// Send indicates an expected call of Send.
// Send indicates an expected call of Send
func (mr *MockPeerManagerMockRecorder) Send(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockPeerManager)(nil).Send), arg0, arg1)
}
// SendWithStream mocks base method.
func (m *MockPeerManager) SendWithStream(arg0 network.Stream, arg1 *pb.Message) error {
// Broadcast mocks base method
func (m *MockPeerManager) Broadcast(arg0 *pb.Message) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendWithStream", arg0, arg1)
ret := m.ctrl.Call(m, "Broadcast", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// SendWithStream indicates an expected call of SendWithStream.
func (mr *MockPeerManagerMockRecorder) SendWithStream(arg0, arg1 interface{}) *gomock.Call {
// Broadcast indicates an expected call of Broadcast
func (mr *MockPeerManagerMockRecorder) Broadcast(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendWithStream", reflect.TypeOf((*MockPeerManager)(nil).SendWithStream), arg0, arg1)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Broadcast", reflect.TypeOf((*MockPeerManager)(nil).Broadcast), arg0)
}
// Start mocks base method.
func (m *MockPeerManager) Start() error {
// CountConnectedPeers mocks base method
func (m *MockPeerManager) CountConnectedPeers() uint64 {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Start")
ret0, _ := ret[0].(error)
ret := m.ctrl.Call(m, "CountConnectedPeers")
ret0, _ := ret[0].(uint64)
return ret0
}
// Start indicates an expected call of Start.
func (mr *MockPeerManagerMockRecorder) Start() *gomock.Call {
// CountConnectedPeers indicates an expected call of CountConnectedPeers
func (mr *MockPeerManagerMockRecorder) CountConnectedPeers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockPeerManager)(nil).Start))
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountConnectedPeers", reflect.TypeOf((*MockPeerManager)(nil).CountConnectedPeers))
}
// Stop mocks base method.
func (m *MockPeerManager) Stop() error {
// Peers mocks base method
func (m *MockPeerManager) Peers() map[uint64]*pb.VpInfo {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Stop")
ret0, _ := ret[0].(error)
ret := m.ctrl.Call(m, "Peers")
ret0, _ := ret[0].(map[uint64]*pb.VpInfo)
return ret0
}
// Stop indicates an expected call of Stop.
func (mr *MockPeerManagerMockRecorder) Stop() *gomock.Call {
// Peers indicates an expected call of Peers
func (mr *MockPeerManagerMockRecorder) Peers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockPeerManager)(nil).Stop))
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Peers", reflect.TypeOf((*MockPeerManager)(nil).Peers))
}
// SubscribeOrderMessage mocks base method.
// OtherPeers mocks base method
func (m *MockPeerManager) OtherPeers() map[uint64]*peer.AddrInfo {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "OtherPeers")
ret0, _ := ret[0].(map[uint64]*peer.AddrInfo)
return ret0
}
// OtherPeers indicates an expected call of OtherPeers
func (mr *MockPeerManagerMockRecorder) OtherPeers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OtherPeers", reflect.TypeOf((*MockPeerManager)(nil).OtherPeers))
}
// SubscribeOrderMessage mocks base method
func (m *MockPeerManager) SubscribeOrderMessage(ch chan<- events.OrderMessageEvent) event.Subscription {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SubscribeOrderMessage", ch)
@ -224,13 +173,37 @@ func (m *MockPeerManager) SubscribeOrderMessage(ch chan<- events.OrderMessageEve
return ret0
}
// SubscribeOrderMessage indicates an expected call of SubscribeOrderMessage.
// SubscribeOrderMessage indicates an expected call of SubscribeOrderMessage
func (mr *MockPeerManagerMockRecorder) SubscribeOrderMessage(ch interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeOrderMessage", reflect.TypeOf((*MockPeerManager)(nil).SubscribeOrderMessage), ch)
}
// UpdateRouter mocks base method.
// AddNode mocks base method
func (m *MockPeerManager) AddNode(newNodeID uint64, vpInfo *pb.VpInfo) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "AddNode", newNodeID, vpInfo)
}
// AddNode indicates an expected call of AddNode
func (mr *MockPeerManagerMockRecorder) AddNode(newNodeID, vpInfo interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNode", reflect.TypeOf((*MockPeerManager)(nil).AddNode), newNodeID, vpInfo)
}
// DelNode mocks base method
func (m *MockPeerManager) DelNode(delID uint64) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "DelNode", delID)
}
// DelNode indicates an expected call of DelNode
func (mr *MockPeerManagerMockRecorder) DelNode(delID interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelNode", reflect.TypeOf((*MockPeerManager)(nil).DelNode), delID)
}
// UpdateRouter mocks base method
func (m *MockPeerManager) UpdateRouter(vpInfos map[uint64]*pb.VpInfo, isNew bool) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UpdateRouter", vpInfos, isNew)
@ -238,36 +211,76 @@ func (m *MockPeerManager) UpdateRouter(vpInfos map[uint64]*pb.VpInfo, isNew bool
return ret0
}
// UpdateRouter indicates an expected call of UpdateRouter.
// UpdateRouter indicates an expected call of UpdateRouter
func (mr *MockPeerManagerMockRecorder) UpdateRouter(vpInfos, isNew interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRouter", reflect.TypeOf((*MockPeerManager)(nil).UpdateRouter), vpInfos, isNew)
}
// MockPierManager is a mock of PierManager interface.
// Disconnect mocks base method
func (m *MockPeerManager) Disconnect(vpInfos map[uint64]*pb.VpInfo) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Disconnect", vpInfos)
}
// Disconnect indicates an expected call of Disconnect
func (mr *MockPeerManagerMockRecorder) Disconnect(vpInfos interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Disconnect", reflect.TypeOf((*MockPeerManager)(nil).Disconnect), vpInfos)
}
// PierManager mocks base method
func (m *MockPeerManager) PierManager() peermgr.PierManager {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PierManager")
ret0, _ := ret[0].(peermgr.PierManager)
return ret0
}
// PierManager indicates an expected call of PierManager
func (mr *MockPeerManagerMockRecorder) PierManager() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PierManager", reflect.TypeOf((*MockPeerManager)(nil).PierManager))
}
// MockPierManager is a mock of PierManager interface
type MockPierManager struct {
ctrl *gomock.Controller
recorder *MockPierManagerMockRecorder
}
// MockPierManagerMockRecorder is the mock recorder for MockPierManager.
// MockPierManagerMockRecorder is the mock recorder for MockPierManager
type MockPierManagerMockRecorder struct {
mock *MockPierManager
}
// NewMockPierManager creates a new mock instance.
// NewMockPierManager creates a new mock instance
func NewMockPierManager(ctrl *gomock.Controller) *MockPierManager {
mock := &MockPierManager{ctrl: ctrl}
mock.recorder = &MockPierManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockPierManager) EXPECT() *MockPierManagerMockRecorder {
return m.recorder
}
// AskPierMaster mocks base method.
// Piers mocks base method
func (m *MockPierManager) Piers() *peermgr.Piers {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Piers")
ret0, _ := ret[0].(*peermgr.Piers)
return ret0
}
// Piers indicates an expected call of Piers
func (mr *MockPierManagerMockRecorder) Piers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Piers", reflect.TypeOf((*MockPierManager)(nil).Piers))
}
// AskPierMaster mocks base method
func (m *MockPierManager) AskPierMaster(arg0 string) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AskPierMaster", arg0)
@ -276,22 +289,8 @@ func (m *MockPierManager) AskPierMaster(arg0 string) (bool, error) {
return ret0, ret1
}
// AskPierMaster indicates an expected call of AskPierMaster.
// AskPierMaster indicates an expected call of AskPierMaster
func (mr *MockPierManagerMockRecorder) AskPierMaster(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AskPierMaster", reflect.TypeOf((*MockPierManager)(nil).AskPierMaster), arg0)
}
// Piers mocks base method.
func (m *MockPierManager) Piers() *peermgr.Piers {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Piers")
ret0, _ := ret[0].(*peermgr.Piers)
return ret0
}
// Piers indicates an expected call of Piers.
func (mr *MockPierManagerMockRecorder) Piers() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Piers", reflect.TypeOf((*MockPierManager)(nil).Piers))
}

View File

@ -5,6 +5,7 @@ import (
"github.com/meshplus/bitxhub-core/boltvm"
"github.com/meshplus/bitxhub-core/validator"
evm "github.com/meshplus/bitxhub-kit/evm"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/bitxhub/pkg/vm"
@ -15,6 +16,7 @@ var _ boltvm.Stub = (*BoltStubImpl)(nil)
type BoltStubImpl struct {
bvm *BoltVM
evm *evm.EVM
ctx *vm.Context
ve validator.Engine
}