Skip to content

Commit 69c4dbe

Browse files
authored
Merge pull request #181 from meshplus/feat/adapt-to-bitxhub-governance
feat(*): adapt to bitxhub governance
2 parents fd12e76 + 0dde77d commit 69c4dbe

File tree

14 files changed

+496
-537
lines changed

14 files changed

+496
-537
lines changed

cmd/pier/appchain_bxh.go

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313
"github.com/urfave/cli"
1414
)
1515

16+
type RegisterResult struct {
17+
ChainID string `json:"chain_id"`
18+
ProposalID string `json:"proposal_id"`
19+
}
20+
1621
var appchainBxhCMD = cli.Command{
1722
Name: "appchain",
1823
Usage: "Command about appchain in bitxhub",
@@ -54,18 +59,6 @@ var appchainBxhCMD = cli.Command{
5459
},
5560
Action: registerAppchain,
5661
},
57-
{
58-
Name: "audit",
59-
Usage: "Audit appchain in bitxhub",
60-
Flags: []cli.Flag{
61-
cli.StringFlag{
62-
Name: "id",
63-
Usage: "Specific appchain id",
64-
Required: true,
65-
},
66-
},
67-
Action: auditAppchain,
68-
},
6962
{
7063
Name: "get",
7164
Usage: "Get appchain info",
@@ -136,51 +129,12 @@ func registerAppchain(ctx *cli.Context) error {
136129
return fmt.Errorf("invoke register: %s", receipt.Ret)
137130
}
138131

139-
appchain := &rpcx.Appchain{}
140-
if err := json.Unmarshal(receipt.Ret, appchain); err != nil {
132+
ret := &RegisterResult{}
133+
if err := json.Unmarshal(receipt.Ret, ret); err != nil {
141134
return err
142135
}
143136

144-
fmt.Printf("appchain register successfully, id is %s\n", appchain.ID)
145-
146-
return nil
147-
}
148-
149-
func auditAppchain(ctx *cli.Context) error {
150-
id := ctx.String("id")
151-
152-
repoRoot, err := repo.PathRootWithDefault(ctx.GlobalString("repo"))
153-
if err != nil {
154-
return err
155-
}
156-
157-
config, err := repo.UnmarshalConfig(repoRoot)
158-
if err != nil {
159-
return fmt.Errorf("init config error: %s", err)
160-
}
161-
162-
client, err := loadClient(repo.KeyPath(repoRoot), config.Mode.Relay.Addrs, ctx)
163-
if err != nil {
164-
return fmt.Errorf("load client: %w", err)
165-
}
166-
167-
receipt, err := client.InvokeBVMContract(
168-
constant.AppchainMgrContractAddr.Address(),
169-
"Audit", nil,
170-
rpcx.String(id),
171-
rpcx.Int32(1),
172-
rpcx.String("Audit passed"),
173-
)
174-
175-
if err != nil {
176-
return err
177-
}
178-
179-
if !receipt.IsSuccess() {
180-
return fmt.Errorf("invoke audit: %s", receipt.Ret)
181-
}
182-
183-
fmt.Printf("audit appchain %s successfully\n", id)
137+
fmt.Printf("appchain register successfully, chain id is %s, proposal id is %s\n", ret.ChainID, ret.ProposalID)
184138

185139
return nil
186140
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ require (
1818
github.com/ipfs/go-cid v0.0.7
1919
github.com/lestrrat-go/strftime v1.0.3 // indirect
2020
github.com/libp2p/go-libp2p-core v0.6.1
21-
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210204062242-16739cd5ee9a
21+
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210323012328-bf23a08fd3e4
2222
github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d
2323
github.com/meshplus/bitxhub-model v1.1.2-0.20210312014622-c3ad532b64ad
24-
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210301024916-b7461066a067
24+
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210319081343-102b2061fe4e
2525
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54
2626
github.com/mitchellh/go-homedir v1.1.0
2727
github.com/multiformats/go-multiaddr v0.3.0
@@ -30,7 +30,7 @@ require (
3030
github.com/spf13/viper v1.6.1
3131
github.com/stretchr/objx v0.2.0 // indirect
3232
github.com/stretchr/testify v1.6.0
33-
github.com/tidwall/gjson v1.6.0
33+
github.com/tidwall/gjson v1.6.8
3434
github.com/urfave/cli v1.22.1
3535
github.com/wonderivan/logger v1.0.0
3636
go.uber.org/atomic v1.6.0

go.sum

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
7070
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
7171
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
7272
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
73-
github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo=
74-
github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
7573
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
7674
github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q=
7775
github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
@@ -135,8 +133,6 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er
135133
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
136134
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
137135
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
138-
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
139-
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
140136
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
141137
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
142138
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -509,6 +505,8 @@ github.com/libp2p/go-yamux v1.3.3/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZ
509505
github.com/libp2p/go-yamux v1.3.5/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow=
510506
github.com/libp2p/go-yamux v1.3.6 h1:O5qcBXRcfqecvQ/My9NqDNHB3/5t58yuJYqthcKhhgE=
511507
github.com/libp2p/go-yamux v1.3.6/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow=
508+
github.com/looplab/fsm v0.2.0 h1:M8hf5EF4AYLcT1FNKVUX8nu7D0xfp291iGeuigSxfrw=
509+
github.com/looplab/fsm v0.2.0/go.mod h1:p+IElwgCnAByqr2DWMuNbPjgMwqcHvTRZZn3dvKEke0=
512510
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
513511
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
514512
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
@@ -524,8 +522,10 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA
524522
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
525523
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
526524
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
527-
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210204062242-16739cd5ee9a h1:9xxE5M9tYlmImTlLF1sMYqA9mBjwooHUk6EK1lDjiJE=
528-
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210204062242-16739cd5ee9a/go.mod h1:MHf0waxqnW4Qwfpq66jqvJP+FritN5OTs/8wlQcNlJY=
525+
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210318102029-494ee3060b0c h1:78bm/wsSv0IORdGw6xdoeFVsILn/hwG6vk4eAg3rgLE=
526+
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210318102029-494ee3060b0c/go.mod h1:G19Wrz1u66UmwaES/iLM19jmlv3APAZ5qfYOlNnIIZw=
527+
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210323012328-bf23a08fd3e4 h1:cFfK+rWt/OjD0wGgbAa/CDChfkLdEjIcWA80Y0GNr7g=
528+
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210323012328-bf23a08fd3e4/go.mod h1:G19Wrz1u66UmwaES/iLM19jmlv3APAZ5qfYOlNnIIZw=
529529
github.com/meshplus/bitxhub-kit v1.0.0-rc1 h1:gNi8IFU5CMHT3KE2I4ACj5alMW9h/4cV8xOxn7wSmtA=
530530
github.com/meshplus/bitxhub-kit v1.0.0-rc1/go.mod h1:ra/AhOkPvpElI+wXrB9G6DjdcrdxFU3vMwA5MYKr9D0=
531531
github.com/meshplus/bitxhub-kit v1.0.0 h1:+RHGTqW50CLZlEQAUm89fQHicYcjqkdYa+QMAktxGd4=
@@ -538,14 +538,10 @@ github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d/go.mod h1:K
538538
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
539539
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23 h1:ys+2VjPrt6nr5xEVgRsVxowipkF425IOcI5HV53M5bA=
540540
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
541-
github.com/meshplus/bitxhub-model v1.1.2-0.20210107045700-cee670a2e117 h1:q1FT1DYWg2Ntf6A6wWiEx2WIEaEGBVgaIE1gAIVJKeI=
542-
github.com/meshplus/bitxhub-model v1.1.2-0.20210107045700-cee670a2e117/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
543-
github.com/meshplus/bitxhub-model v1.1.2-0.20210120083349-c7a006b03fcb h1:PxGQL22OVxozkvEgVvxHol9WDqCZlhyvnd0Bu0HBX1Y=
544-
github.com/meshplus/bitxhub-model v1.1.2-0.20210120083349-c7a006b03fcb/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
545541
github.com/meshplus/bitxhub-model v1.1.2-0.20210312014622-c3ad532b64ad h1:aTK2R7ATKdfAQe96xaXM91r6I1GPGvqFkHmum57G+G8=
546542
github.com/meshplus/bitxhub-model v1.1.2-0.20210312014622-c3ad532b64ad/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
547-
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210301024916-b7461066a067 h1:zSUf3BJYzYK2v4WtXytghutLmJhreA0HtslOqPIwRWc=
548-
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210301024916-b7461066a067/go.mod h1:ZWklYGrAMQcknmMMyxZtRU1IiBRuoYy570QNTp3WJbI=
543+
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210319081343-102b2061fe4e h1:OGzfCqMOUx5Qu3q6fdbFGlpDIBPaV+/n7KfGAqfaCL4=
544+
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210319081343-102b2061fe4e/go.mod h1:tSvmN8oF7YqBDtYl+Apu/oMLGfX5tIQF8hMOdzF35mU=
549545
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54 h1:5Ip5AB7SxxQHg5SRtf2cCOI2wy1p75MQB12soPtPyf8=
550546
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54/go.mod h1:G89UJaeqCQFxFdp8wzy1AdKfMtDEhpySau0pjDNeeaw=
551547
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
@@ -761,12 +757,12 @@ github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+
761757
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
762758
github.com/tebeka/strftime v0.1.3 h1:5HQXOqWKYRFfNyBMNVc9z5+QzuBtIXy03psIhtdJYto=
763759
github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ=
764-
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
765-
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
766-
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
767-
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
768-
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
769-
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
760+
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
761+
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
762+
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
763+
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
764+
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
765+
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
770766
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
771767
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
772768
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=

internal/checker/checker_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ func getIBTP(t *testing.T, index uint64, typ pb.IBTP_Type, fid, tid, proofPath s
156156
type MockAppchainMgr struct {
157157
}
158158

159+
func (m MockAppchainMgr) ChangeStatus(id, trigger string) (bool, []byte) {
160+
return true, nil
161+
}
162+
163+
func (m MockAppchainMgr) CountAvailableAppchains() (bool, []byte) {
164+
return true, nil
165+
}
166+
159167
func (m MockAppchainMgr) Register(id, validators string, consensusType int32, chainType, name, desc, version, pubkey string) (bool, []byte) {
160168
return true, nil
161169
}

internal/exchanger/exchanger_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/golang/mock/gomock"
1212
crypto2 "github.com/libp2p/go-libp2p-core/crypto"
1313
peer2 "github.com/libp2p/go-libp2p-core/peer"
14+
appchainmgr "github.com/meshplus/bitxhub-core/appchain-mgr"
1415
"github.com/meshplus/bitxhub-kit/crypto"
1516
"github.com/meshplus/bitxhub-kit/crypto/asym"
1617
ecdsa2 "github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
@@ -552,7 +553,7 @@ func testUnionMode(pierID string, t *testing.T) {
552553
ID: pierID,
553554
Name: "hpc",
554555
Validators: "validator for hpc",
555-
Status: 0,
556+
Status: appchainmgr.AppchainAvailable,
556557
ChainType: "hyperchain",
557558
Desc: "appchain for test",
558559
PublicKey: "",

internal/executor/mock_executor/mock_executor.go

Lines changed: 43 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)