feat: add register pubkey
Now appchain registration need upload public key.
This commit is contained in:
parent
58696975ae
commit
5796919e82
|
@ -35,6 +35,7 @@ type appchain struct {
|
|||
ChainType string `json:"chain_type"`
|
||||
Desc string `json:"desc"`
|
||||
Version string `json:"version"`
|
||||
PublicKey string `json:"public_key"`
|
||||
InterchainCounter map[string]uint64 `json:"interchain_counter,omitempty"`
|
||||
ReceiptCounter map[string]uint64 `json:"receipt_counter,omitempty"`
|
||||
SourceReceiptCounter map[string]uint64 `json:"source_receipt_counter,omitempty"`
|
||||
|
@ -71,7 +72,7 @@ func (chain *appchain) UnmarshalJSON(data []byte) error {
|
|||
|
||||
// Register appchain manager registers appchain info caller is the appchain
|
||||
// manager address return appchain id and error
|
||||
func (x *Interchain) Register(validators string, consensusType int32, chainType, name, desc, version string) *boltvm.Response {
|
||||
func (x *Interchain) Register(validators string, consensusType int32, chainType, name, desc, version, pubkey string) *boltvm.Response {
|
||||
chain := &appchain{
|
||||
ID: x.Caller(),
|
||||
Name: name,
|
||||
|
@ -80,6 +81,7 @@ func (x *Interchain) Register(validators string, consensusType int32, chainType,
|
|||
ChainType: chainType,
|
||||
Desc: desc,
|
||||
Version: version,
|
||||
PublicKey: pubkey,
|
||||
}
|
||||
|
||||
ok := x.Has(x.appchainKey(x.Caller()))
|
||||
|
@ -103,7 +105,7 @@ func (x *Interchain) Register(validators string, consensusType int32, chainType,
|
|||
return boltvm.Success(body)
|
||||
}
|
||||
|
||||
func (x *Interchain) UpdateAppchain(validators string, consensusType int32, chainType, name, desc, version string) *boltvm.Response {
|
||||
func (x *Interchain) UpdateAppchain(validators string, consensusType int32, chainType, name, desc, version, pubkey string) *boltvm.Response {
|
||||
ok := x.Has(x.appchainKey(x.Caller()))
|
||||
if !ok {
|
||||
return boltvm.Error("register appchain firstly")
|
||||
|
@ -124,6 +126,7 @@ func (x *Interchain) UpdateAppchain(validators string, consensusType int32, chai
|
|||
ChainType: chainType,
|
||||
Desc: desc,
|
||||
Version: version,
|
||||
PublicKey: pubkey,
|
||||
}
|
||||
|
||||
x.SetObject(x.appchainKey(x.Caller()), chain)
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
type RegisterAppchain struct {
|
||||
suite.Suite
|
||||
privKey crypto.PrivateKey
|
||||
pubKey crypto.PublicKey
|
||||
client rpcx.Client
|
||||
}
|
||||
|
||||
|
@ -23,6 +24,8 @@ func (suite *RegisterAppchain) SetupSuite() {
|
|||
suite.privKey, err = ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
suite.pubKey = suite.privKey.PublicKey()
|
||||
|
||||
suite.client, err = rpcx.New(
|
||||
rpcx.WithPrivateKey(suite.privKey),
|
||||
rpcx.WithAddrs(grpcAddresses()),
|
||||
|
@ -33,6 +36,8 @@ func (suite *RegisterAppchain) SetupSuite() {
|
|||
// Appchain registers in bitxhub
|
||||
func (suite *RegisterAppchain) TestRegisterAppchain() {
|
||||
suite.client.SetPrivateKey(suite.privKey)
|
||||
pubKey, err := suite.pubKey.Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
args := []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -40,6 +45,7 @@ func (suite *RegisterAppchain) TestRegisterAppchain() {
|
|||
rpcx.String("税务链"),
|
||||
rpcx.String("趣链税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pubKey)),
|
||||
}
|
||||
ret, err := suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
suite.Assert().Nil(err)
|
||||
|
@ -53,6 +59,8 @@ func (suite *RegisterAppchain) TestFetchAppchains() {
|
|||
suite.Assert().Nil(err)
|
||||
|
||||
suite.client.SetPrivateKey(k1)
|
||||
pk1, err := k1.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
args := []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -60,11 +68,14 @@ func (suite *RegisterAppchain) TestFetchAppchains() {
|
|||
rpcx.String("税务链"),
|
||||
rpcx.String("趣链税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk1)),
|
||||
}
|
||||
_, err = suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
suite.client.SetPrivateKey(k2)
|
||||
pk2, err := k2.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
args = []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -72,6 +83,7 @@ func (suite *RegisterAppchain) TestFetchAppchains() {
|
|||
rpcx.String("政务链"),
|
||||
rpcx.String("fabric政务"),
|
||||
rpcx.String("1.4"),
|
||||
rpcx.String(string(pk2)),
|
||||
}
|
||||
_, err = suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
pk1, err := k1.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -59,8 +61,11 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
rpcx.String("婚姻链"),
|
||||
rpcx.String("趣链婚姻链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk1)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
pk2, err := k2.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c2.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -68,6 +73,7 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
rpcx.String("税务链"),
|
||||
rpcx.String("fabric婚姻链"),
|
||||
rpcx.String("1.4"),
|
||||
rpcx.String(string(pk2)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
|
@ -110,6 +116,8 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
|
||||
confByte, err := ioutil.ReadFile("./test_data/validator")
|
||||
suite.Assert().Nil(err)
|
||||
pk1, err := k1.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(rpcx.InterchainContractAddr, "Register",
|
||||
rpcx.String(string(confByte)),
|
||||
rpcx.Int32(0),
|
||||
|
@ -117,8 +125,11 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
rpcx.String("婚姻链"),
|
||||
rpcx.String("趣链婚姻链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk1)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
pk2, err := k2.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c2.InvokeBVMContract(rpcx.InterchainContractAddr, "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -126,6 +137,7 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
rpcx.String("税务链"),
|
||||
rpcx.String("fabric税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk2)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
type Role struct {
|
||||
suite.Suite
|
||||
privKey crypto.PrivateKey
|
||||
pubKey crypto.PublicKey
|
||||
client rpcx.Client
|
||||
}
|
||||
|
||||
|
@ -23,6 +24,8 @@ func (suite *Role) SetupSuite() {
|
|||
suite.privKey, err = ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
suite.pubKey = suite.privKey.PublicKey()
|
||||
|
||||
suite.client, err = rpcx.New(
|
||||
rpcx.WithPrivateKey(suite.privKey),
|
||||
rpcx.WithAddrs([]string{
|
||||
|
@ -36,13 +39,16 @@ func (suite *Role) SetupSuite() {
|
|||
}
|
||||
|
||||
func (suite *Role) TestGetRole() {
|
||||
_, err := suite.client.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
pubKey, err := suite.pubKey.Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = suite.client.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("婚姻链"),
|
||||
rpcx.String("趣链婚姻链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pubKey)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
type Pier struct {
|
||||
suite.Suite
|
||||
privKey crypto.PrivateKey
|
||||
pubKey crypto.PublicKey
|
||||
address types.Address
|
||||
client rpcx.Client // bitxhub admin
|
||||
}
|
||||
|
@ -38,6 +39,7 @@ func (suite *Pier) SetupSuite() {
|
|||
suite.Require().Nil(err)
|
||||
|
||||
suite.privKey = privKey
|
||||
suite.pubKey = suite.privKey.PublicKey()
|
||||
suite.address = address
|
||||
suite.client = client
|
||||
}
|
||||
|
@ -55,6 +57,8 @@ func (suite *Pier) TestSyncMerkleWrapper() {
|
|||
)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
pubKey, err := privKey.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
args := []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
|
@ -62,6 +66,7 @@ func (suite *Pier) TestSyncMerkleWrapper() {
|
|||
rpcx.String("税务链"),
|
||||
rpcx.String("趣链税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pubKey)),
|
||||
}
|
||||
|
||||
ret, err := client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
|
|
Loading…
Reference in New Issue