From 7a463853efb9a2f952e14c5cade7020fd2d4683f Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Tue, 3 Dec 2024 11:50:39 +1100 Subject: [PATCH 1/7] pass concrete keeper --- x/babylon/keeper/keeper.go | 5 +++-- x/babylon/keeper/keeper_test.go | 2 +- x/babylon/keeper/options.go | 4 ++-- x/babylon/keeper/wasm.go | 4 ++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/x/babylon/keeper/keeper.go b/x/babylon/keeper/keeper.go index 188c3d0..3fff6b3 100644 --- a/x/babylon/keeper/keeper.go +++ b/x/babylon/keeper/keeper.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -21,7 +22,7 @@ type Keeper struct { cdc codec.Codec bank types.BankKeeper Staking types.StakingKeeper - wasm types.WasmKeeper + wasm *wasmkeeper.Keeper // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string @@ -34,7 +35,7 @@ func NewKeeper( memoryStoreKey storetypes.StoreKey, bank types.BankKeeper, staking types.StakingKeeper, - wasm types.WasmKeeper, + wasm *wasmkeeper.Keeper, authority string, opts ...Option, ) *Keeper { diff --git a/x/babylon/keeper/keeper_test.go b/x/babylon/keeper/keeper_test.go index 3bb2123..e69bd37 100644 --- a/x/babylon/keeper/keeper_test.go +++ b/x/babylon/keeper/keeper_test.go @@ -279,7 +279,7 @@ func NewTestKeepers(t testing.TB, opts ...keeper.Option) TestKeepers { memKeys[types.MemStoreKey], bankKeeper, stakingKeeper, - wasmKeeper, + &wasmKeeper, authority, opts..., ) diff --git a/x/babylon/keeper/options.go b/x/babylon/keeper/options.go index 322f869..0b6f151 100644 --- a/x/babylon/keeper/options.go +++ b/x/babylon/keeper/options.go @@ -1,6 +1,6 @@ package keeper -import "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" +import wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" // option that is applied after keeper is setup with the VM. Used for decorators mainly. type postOptsFn func(*Keeper) @@ -10,7 +10,7 @@ func (f postOptsFn) apply(keeper *Keeper) { } // WithWasmKeeperDecorated can set a decorator to the wasm keeper -func WithWasmKeeperDecorated(cb func(types.WasmKeeper) types.WasmKeeper) Option { +func WithWasmKeeperDecorated(cb func(*wasmkeeper.Keeper) *wasmkeeper.Keeper) Option { return postOptsFn(func(keeper *Keeper) { keeper.wasm = cb(keeper.wasm) }) diff --git a/x/babylon/keeper/wasm.go b/x/babylon/keeper/wasm.go index 60bad02..3e316d9 100644 --- a/x/babylon/keeper/wasm.go +++ b/x/babylon/keeper/wasm.go @@ -11,6 +11,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +func (k Keeper) StoreBabylonContracts(ctx sdk.Context) error { + return nil +} + func (k Keeper) getBTCStakingContractAddr(ctx sdk.Context) sdk.AccAddress { // get address of the BTC staking contract addrStr := k.GetParams(ctx).BtcStakingContractAddress From 51dbbbbba71d623a808a010b0b9ddea0e07d3dc6 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Tue, 3 Dec 2024 15:07:20 +1100 Subject: [PATCH 2/7] msg formats --- docs/proto/proto-docs.md | 67 ++ .../babylonlabs/babylon/v1beta1/babylon.proto | 16 +- proto/babylonlabs/babylon/v1beta1/tx.proto | 47 + x/babylon/keeper/msg_server.go | 54 + x/babylon/keeper/wasm.go | 84 +- x/babylon/types/babylon.go | 55 ++ x/babylon/types/babylon.pb.go | 167 +++- x/babylon/types/params.go | 13 + x/babylon/types/tx.pb.go | 926 +++++++++++++++++- 9 files changed, 1355 insertions(+), 74 deletions(-) create mode 100644 x/babylon/types/babylon.go diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 0a9d8e6..37d5886 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -17,6 +17,10 @@ - [Query](#babylonlabs.babylon.v1beta1.Query) - [babylonlabs/babylon/v1beta1/tx.proto](#babylonlabs/babylon/v1beta1/tx.proto) + - [MsgInstantiateBabylonContracts](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts) + - [MsgInstantiateBabylonContractsResponse](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContractsResponse) + - [MsgStoreBabylonContractCodes](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodes) + - [MsgStoreBabylonContractCodesResponse](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodesResponse) - [MsgUpdateParams](#babylonlabs.babylon.v1beta1.MsgUpdateParams) - [MsgUpdateParamsResponse](#babylonlabs.babylon.v1beta1.MsgUpdateParamsResponse) @@ -41,6 +45,9 @@ Params defines the parameters for the x/babylon module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | +| `babylon_contract_code_id` | [uint64](#uint64) | | babylon_contract_code_id is the code ID of the Babylon contract | +| `btc_staking_contract_code_id` | [uint64](#uint64) | | btc_staking_contract_code_id is the code ID of the BTC staking contract | +| `btc_finality_contract_code_id` | [uint64](#uint64) | | btc_finality_contract_code_id is the code ID of the BTC finality contract | | `babylon_contract_address` | [string](#string) | | babylon_contract_address is the address of the Babylon contract | | `btc_staking_contract_address` | [string](#string) | | btc_staking_contract_address is the address of the BTC staking contract | | `btc_finality_contract_address` | [string](#string) | | btc_finality_contract_address is the address of the BTC finality contract | @@ -151,6 +158,64 @@ Query provides defines the gRPC querier service + + +### MsgInstantiateBabylonContracts +MsgInstantiateBabylonContracts is the Msg/InstantiateBabylonContracts request +type. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `signer` | [string](#string) | | signer is the address who submits the message. | +| `init_msg` | [bytes](#bytes) | | init_msg is the instantiation message for the Babylon contract. | + + + + + + + + +### MsgInstantiateBabylonContractsResponse +MsgInstantiateBabylonContractsResponse is the Msg/InstantiateBabylonContracts +response type. + + + + + + + + +### MsgStoreBabylonContractCodes +MsgStoreBabylonContractCodes is the Msg/StoreBabylonContractCodes request +type. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `signer` | [string](#string) | | signer is the address who submits the message. | +| `babylon_contract_code` | [bytes](#bytes) | | babylon_contract_code is the bytecode for the Babylon contract. WASMByteCode can be raw or gzip compressed | +| `btc_staking_contract_code` | [bytes](#bytes) | | btc_staking_contract_code is the bytecode for the BTC staking contract. WASMByteCode can be raw or gzip compressed | +| `btc_finality_contract_code` | [bytes](#bytes) | | btc_finality_contract_code is the bytecode for the BTC finality contract. WASMByteCode can be raw or gzip compressed | + + + + + + + + +### MsgStoreBabylonContractCodesResponse +MsgStoreBabylonContractCodesResponse is the Msg/StoreBabylonContractCodes +response type. + + + + + + ### MsgUpdateParams @@ -193,6 +258,8 @@ Msg defines the wasm Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `StoreBabylonContractCodes` | [MsgStoreBabylonContractCodes](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodes) | [MsgStoreBabylonContractCodesResponse](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodesResponse) | StoreBabylonContractCodes defines an operation for storing the Babylon contract codes. | | +| `InstantiateBabylonContracts` | [MsgInstantiateBabylonContracts](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts) | [MsgInstantiateBabylonContractsResponse](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContractsResponse) | InstantiateBabylonContracts defines an operation for instantiating the Babylon contracts. | | | `UpdateParams` | [MsgUpdateParams](#babylonlabs.babylon.v1beta1.MsgUpdateParams) | [MsgUpdateParamsResponse](#babylonlabs.babylon.v1beta1.MsgUpdateParamsResponse) | UpdateParams defines a (governance) operation for updating the x/auth module parameters. The authority defaults to the x/gov module account. | | diff --git a/proto/babylonlabs/babylon/v1beta1/babylon.proto b/proto/babylonlabs/babylon/v1beta1/babylon.proto index 37cdeb3..640bf2e 100644 --- a/proto/babylonlabs/babylon/v1beta1/babylon.proto +++ b/proto/babylonlabs/babylon/v1beta1/babylon.proto @@ -12,16 +12,22 @@ option (gogoproto.equal_all) = false; message Params { option (gogoproto.equal) = true; + // babylon_contract_code_id is the code ID of the Babylon contract + uint64 babylon_contract_code_id = 1; + // btc_staking_contract_code_id is the code ID of the BTC staking contract + uint64 btc_staking_contract_code_id = 2; + // btc_finality_contract_code_id is the code ID of the BTC finality contract + uint64 btc_finality_contract_code_id = 3; // babylon_contract_address is the address of the Babylon contract - string babylon_contract_address = 1 + string babylon_contract_address = 4 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; // btc_staking_contract_address is the address of the BTC staking contract - string btc_staking_contract_address = 2 + string btc_staking_contract_address = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; // btc_finality_contract_address is the address of the BTC finality contract - string btc_finality_contract_address = 3 - [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string btc_finality_contract_address = 6 + [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; // max_gas_begin_blocker defines the maximum gas that can be spent in a // contract sudo callback - uint32 max_gas_begin_blocker = 4; + uint32 max_gas_begin_blocker = 7; } diff --git a/proto/babylonlabs/babylon/v1beta1/tx.proto b/proto/babylonlabs/babylon/v1beta1/tx.proto index 7d6a7da..77fe22f 100644 --- a/proto/babylonlabs/babylon/v1beta1/tx.proto +++ b/proto/babylonlabs/babylon/v1beta1/tx.proto @@ -13,11 +13,58 @@ option (gogoproto.goproto_getters_all) = false; service Msg { option (cosmos.msg.v1.service) = true; + // StoreBabylonContractCodes defines an operation for storing the Babylon + // contract codes. + rpc StoreBabylonContractCodes(MsgStoreBabylonContractCodes) + returns (MsgStoreBabylonContractCodesResponse); + + // InstantiateBabylonContracts defines an operation for instantiating the + // Babylon contracts. + rpc InstantiateBabylonContracts(MsgInstantiateBabylonContracts) + returns (MsgInstantiateBabylonContractsResponse); + // UpdateParams defines a (governance) operation for updating the x/auth // module parameters. The authority defaults to the x/gov module account. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } +// MsgStoreBabylonContractCodes is the Msg/StoreBabylonContractCodes request +// type. +message MsgStoreBabylonContractCodes { + option (cosmos.msg.v1.signer) = "signer"; + + // signer is the address who submits the message. + string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // babylon_contract_code is the bytecode for the Babylon contract. + // WASMByteCode can be raw or gzip compressed + bytes babylon_contract_code = 2; + // btc_staking_contract_code is the bytecode for the BTC staking contract. + // WASMByteCode can be raw or gzip compressed + bytes btc_staking_contract_code = 3; + // btc_finality_contract_code is the bytecode for the BTC finality contract. + // WASMByteCode can be raw or gzip compressed + bytes btc_finality_contract_code = 4; +} + +// MsgStoreBabylonContractCodesResponse is the Msg/StoreBabylonContractCodes +// response type. +message MsgStoreBabylonContractCodesResponse {} + +// MsgInstantiateBabylonContracts is the Msg/InstantiateBabylonContracts request +// type. +message MsgInstantiateBabylonContracts { + option (cosmos.msg.v1.signer) = "signer"; + + // signer is the address who submits the message. + string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // init_msg is the instantiation message for the Babylon contract. + bytes init_msg = 2; +} + +// MsgInstantiateBabylonContractsResponse is the Msg/InstantiateBabylonContracts +// response type. +message MsgInstantiateBabylonContractsResponse {} + // MsgUpdateParams is the Msg/UpdateParams request type. message MsgUpdateParams { option (cosmos.msg.v1.signer) = "authority"; diff --git a/x/babylon/keeper/msg_server.go b/x/babylon/keeper/msg_server.go index 7e34f5f..c7e280a 100644 --- a/x/babylon/keeper/msg_server.go +++ b/x/babylon/keeper/msg_server.go @@ -20,6 +20,60 @@ func NewMsgServer(k *Keeper) *msgServer { return &msgServer{k: k} } +func (ms msgServer) StoreBabylonContractCodes(goCtx context.Context, req *types.MsgStoreBabylonContractCodes) (*types.MsgStoreBabylonContractCodesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + params := ms.k.GetParams(ctx) + + // only the authority can override the contract codes + if params.IsCodeStored() && req.Signer != ms.k.authority { + return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "only authority can override stored codes; expected %s, got %s", ms.k.authority, req.Signer) + } + + // store the contract codes + babylonContractCodeID, btcStakingContractCodeID, btcFinalityContractCodeID, err := ms.k.StoreBabylonContractCodes(ctx, req.BabylonContractCode, req.BtcStakingContractCode, req.BtcFinalityContractCode) + if err != nil { + return nil, err + } + + // update params + params.BabylonContractCodeId = babylonContractCodeID + params.BtcStakingContractCodeId = btcStakingContractCodeID + params.BtcFinalityContractCodeId = btcFinalityContractCodeID + if err := ms.k.SetParams(ctx, params); err != nil { + panic(err) + } + + return &types.MsgStoreBabylonContractCodesResponse{}, nil +} + +func (ms msgServer) InstantiateBabylonContracts(goCtx context.Context, req *types.MsgInstantiateBabylonContracts) (*types.MsgInstantiateBabylonContractsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + params := ms.k.GetParams(ctx) + + // only the authority can override the instantiated contracts + if params.IsContractInstantiated() && req.Signer != ms.k.authority { + return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "only authority can override instantiated contracts; expected %s, got %s", ms.k.authority, req.Signer) + } + + // instantiate the contracts + babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, req.InitMsg) + if err != nil { + return nil, err + } + + // update params + params.BabylonContractAddress = babylonContractAddr + params.BtcStakingContractAddress = btcStakingContractAddr + params.BtcFinalityContractAddress = btcFinalityContractAddr + if err := ms.k.SetParams(ctx, params); err != nil { + panic(err) + } + + return &types.MsgInstantiateBabylonContractsResponse{}, nil +} + // UpdateParams updates the params. func (ms msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if ms.k.authority != req.Authority { diff --git a/x/babylon/keeper/wasm.go b/x/babylon/keeper/wasm.go index 3e316d9..6b5aa0d 100644 --- a/x/babylon/keeper/wasm.go +++ b/x/babylon/keeper/wasm.go @@ -7,12 +7,92 @@ import ( "fmt" errorsmod "cosmossdk.io/errors" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/babylonlabs-io/babylon-sdk/x/babylon/contract" + types "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" sdk "github.com/cosmos/cosmos-sdk/types" ) -func (k Keeper) StoreBabylonContracts(ctx sdk.Context) error { - return nil +// StoreBabylonContractCodes stores the Babylon contract codes +func (k Keeper) StoreBabylonContractCodes( + ctx sdk.Context, + babylonContractCode []byte, + btcStakingContractCode []byte, + btcFinalityContractCode []byte, +) (uint64, uint64, uint64, error) { + contractKeeper := wasmkeeper.NewGovPermissionKeeper(k.wasm) + instantiateConfig := wasmtypes.AccessConfig{ + Permission: wasmtypes.AccessTypeAnyOfAddresses, + Addresses: []string{k.authority}, + } + + // gov address + govAddr, err := sdk.AccAddressFromBech32(k.authority) + if err != nil { + panic(err) + } + + // store Babylon contract + babylonContractCodeID, _, err := contractKeeper.Create(ctx, govAddr, babylonContractCode, &instantiateConfig) + if err != nil { + return 0, 0, 0, err + } + // store BTC staking contract + btcStakingContractCodeID, _, err := contractKeeper.Create(ctx, govAddr, btcStakingContractCode, &instantiateConfig) + if err != nil { + return 0, 0, 0, err + } + // store BTC finality contract + btcFinalityContractCodeID, _, err := contractKeeper.Create(ctx, govAddr, btcFinalityContractCode, &instantiateConfig) + if err != nil { + return 0, 0, 0, err + } + + return babylonContractCodeID, btcStakingContractCodeID, btcFinalityContractCodeID, nil +} + +func (k Keeper) InstantiateBabylonContracts(ctx sdk.Context, initMsg []byte) (string, string, string, error) { + contractKeeper := wasmkeeper.NewGovPermissionKeeper(k.wasm) + + // get params + params := k.GetParams(ctx) + + // check that the contract codes are stored + if !params.IsCodeStored() { + return "", "", "", types.ErrInvalid.Wrapf("Babylon contract code ID is not set") + } + + // gov address + govAddr, err := sdk.AccAddressFromBech32(k.authority) + if err != nil { + panic(err) + } + + // instantiate Babylon contract + babylonContractAddr, _, err := contractKeeper.Instantiate(ctx, params.BabylonContractCodeId, govAddr, govAddr, initMsg, "Babylon contract", nil) + if err != nil { + return "", "", "", err + } + + // get contract addresses + res, err := k.wasm.QuerySmart(ctx, babylonContractAddr, []byte(`"config":{}`)) + if err != nil { + return "", "", "", err + } + var config types.BabylonContractConfig + err = json.Unmarshal(res, &config) + if err != nil { + return "", "", "", err + } + if len(config.BTCStaking) == 0 { + return "", "", "", errorsmod.Wrap(types.ErrInvalid, "failed to instantiate BTC staking contract") + } + if len(config.BTCFinality) == 0 { + return "", "", "", errorsmod.Wrap(types.ErrInvalid, "failed to instantiate BTC finality contract") + } + + return babylonContractAddr.String(), config.BTCStaking, config.BTCFinality, nil } func (k Keeper) getBTCStakingContractAddr(ctx sdk.Context) sdk.AccAddress { diff --git a/x/babylon/types/babylon.go b/x/babylon/types/babylon.go new file mode 100644 index 0000000..45cd09b --- /dev/null +++ b/x/babylon/types/babylon.go @@ -0,0 +1,55 @@ +package types + +// Config represents the configuration for the Babylon contract +type BabylonContractConfig struct { + Network string `json:"network"` + BabylonTag []byte `json:"babylon_tag"` + BTCConfirmationDepth uint32 `json:"btc_confirmation_depth"` + CheckpointFinalizationTimeout uint32 `json:"checkpoint_finalization_timeout"` + // NotifyCosmosZone indicates whether to send Cosmos zone messages notifying BTC-finalised headers. + // NOTE: if set to true, then the Cosmos zone needs to integrate the corresponding message + // handler as well + NotifyCosmosZone bool `json:"notify_cosmos_zone"` + // BTCStaking stores a BTC staking contract used for BTC re-staking if set + BTCStaking string `json:"btc_staking,omitempty"` + // BTCFinality stores a BTC finality contract used for BTC finality on the Consumer if set + BTCFinality string `json:"btc_finality,omitempty"` + // ConsumerName represents the name of the Consumer + ConsumerName string `json:"consumer_name,omitempty"` + // ConsumerDescription represents the description of the Consumer + ConsumerDescription string `json:"consumer_description,omitempty"` +} + +type BabylonContractInitMsg struct { + // Network represents the Bitcoin network (mainnet, testnet, etc.) + Network string `json:"network"` + // BabylonTag is a string encoding four bytes used for identification / tagging of the Babylon zone. + // NOTE: this is a hex string, not raw bytes + BabylonTag string `json:"babylon_tag"` + // BTCConfirmationDepth is the number of confirmations required for BTC headers + BTCConfirmationDepth uint32 `json:"btc_confirmation_depth"` + // CheckpointFinalizationTimeout is the timeout period for checkpoint finalization + CheckpointFinalizationTimeout uint32 `json:"checkpoint_finalization_timeout"` + // NotifyCosmosZone indicates whether to send Cosmos zone messages notifying BTC-finalised headers. + // NOTE: If set to true, then the Cosmos zone needs to integrate the corresponding message handler + // as well + NotifyCosmosZone bool `json:"notify_cosmos_zone"` + // BTCStakingCodeID is the code ID for the BTC staking contract, if set + BTCStakingCodeID *uint64 `json:"btc_staking_code_id,omitempty"` + // BTCStakingMsg is the instantiation message for the BTC staking contract. + // This message is opaque to the Babylon contract, and depends on the specific staking contract + // being instantiated + BTCStakingMsg []byte `json:"btc_staking_msg,omitempty"` + // BTCFinalityCodeID is the code ID for the BTC finality contract, if set + BTCFinalityCodeID *uint64 `json:"btc_finality_code_id,omitempty"` + // BTCFinalityMsg is the instantiation message for the BTC finality contract. + // This message is opaque to the Babylon contract, and depends on the specific finality contract + // being instantiated + BTCFinalityMsg []byte `json:"btc_finality_msg,omitempty"` + // Admin is the Wasm migration / upgrade admin of the BTC staking contract and the BTC finality contract + Admin string `json:"admin,omitempty"` + // ConsumerName represents the name of the Consumer + ConsumerName string `json:"consumer_name,omitempty"` + // ConsumerDescription represents the description of the Consumer + ConsumerDescription string `json:"consumer_description,omitempty"` +} diff --git a/x/babylon/types/babylon.pb.go b/x/babylon/types/babylon.pb.go index a9ee6a8..02c6ec7 100644 --- a/x/babylon/types/babylon.pb.go +++ b/x/babylon/types/babylon.pb.go @@ -26,15 +26,21 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the x/babylon module. type Params struct { + // babylon_contract_code_id is the code ID of the Babylon contract + BabylonContractCodeId uint64 `protobuf:"varint,1,opt,name=babylon_contract_code_id,json=babylonContractCodeId,proto3" json:"babylon_contract_code_id,omitempty"` + // btc_staking_contract_code_id is the code ID of the BTC staking contract + BtcStakingContractCodeId uint64 `protobuf:"varint,2,opt,name=btc_staking_contract_code_id,json=btcStakingContractCodeId,proto3" json:"btc_staking_contract_code_id,omitempty"` + // btc_finality_contract_code_id is the code ID of the BTC finality contract + BtcFinalityContractCodeId uint64 `protobuf:"varint,3,opt,name=btc_finality_contract_code_id,json=btcFinalityContractCodeId,proto3" json:"btc_finality_contract_code_id,omitempty"` // babylon_contract_address is the address of the Babylon contract - BabylonContractAddress string `protobuf:"bytes,1,opt,name=babylon_contract_address,json=babylonContractAddress,proto3" json:"babylon_contract_address,omitempty"` + BabylonContractAddress string `protobuf:"bytes,4,opt,name=babylon_contract_address,json=babylonContractAddress,proto3" json:"babylon_contract_address,omitempty"` // btc_staking_contract_address is the address of the BTC staking contract - BtcStakingContractAddress string `protobuf:"bytes,2,opt,name=btc_staking_contract_address,json=btcStakingContractAddress,proto3" json:"btc_staking_contract_address,omitempty"` + BtcStakingContractAddress string `protobuf:"bytes,5,opt,name=btc_staking_contract_address,json=btcStakingContractAddress,proto3" json:"btc_staking_contract_address,omitempty"` // btc_finality_contract_address is the address of the BTC finality contract - BtcFinalityContractAddress string `protobuf:"bytes,3,opt,name=btc_finality_contract_address,json=btcFinalityContractAddress,proto3" json:"btc_finality_contract_address,omitempty"` + BtcFinalityContractAddress string `protobuf:"bytes,6,opt,name=btc_finality_contract_address,json=btcFinalityContractAddress,proto3" json:"btc_finality_contract_address,omitempty"` // max_gas_begin_blocker defines the maximum gas that can be spent in a // contract sudo callback - MaxGasBeginBlocker uint32 `protobuf:"varint,4,opt,name=max_gas_begin_blocker,json=maxGasBeginBlocker,proto3" json:"max_gas_begin_blocker,omitempty"` + MaxGasBeginBlocker uint32 `protobuf:"varint,7,opt,name=max_gas_begin_blocker,json=maxGasBeginBlocker,proto3" json:"max_gas_begin_blocker,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -79,29 +85,32 @@ func init() { } var fileDescriptor_9eb75d1c9a41f85f = []byte{ - // 339 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xb1, 0x4e, 0x32, 0x41, - 0x14, 0x85, 0x77, 0xf8, 0x09, 0xc9, 0xbf, 0x89, 0xcd, 0x06, 0xcd, 0x82, 0x3a, 0x12, 0x2b, 0x2c, - 0x60, 0x43, 0x8c, 0x8d, 0x9d, 0x6b, 0xa2, 0xad, 0x81, 0xc2, 0xa8, 0xc5, 0xe4, 0xce, 0xb0, 0x8e, - 0x13, 0x76, 0x77, 0xc8, 0xce, 0x68, 0xe0, 0x2d, 0x7c, 0x04, 0x4b, 0x1f, 0xc0, 0x87, 0xa0, 0x31, - 0x21, 0x56, 0x96, 0xba, 0x34, 0x3e, 0x86, 0x81, 0x99, 0x35, 0x04, 0x0a, 0xba, 0x7b, 0xee, 0x39, - 0xe7, 0x6b, 0xee, 0x75, 0x8f, 0x28, 0xd0, 0x71, 0x2c, 0xd3, 0x18, 0xa8, 0x0a, 0xec, 0x1c, 0x3c, - 0x75, 0x68, 0xa4, 0xa1, 0x53, 0xe8, 0xf6, 0x30, 0x93, 0x5a, 0x7a, 0xbb, 0x4b, 0xd1, 0x76, 0x61, - 0xd9, 0x68, 0xbd, 0xc6, 0xa4, 0x4a, 0xa4, 0x22, 0x8b, 0x68, 0x60, 0x84, 0xe9, 0xd5, 0xab, 0x5c, - 0x72, 0x69, 0xf6, 0xf3, 0xc9, 0x6c, 0x0f, 0xdf, 0x4b, 0x6e, 0xe5, 0x0a, 0x32, 0x48, 0x94, 0xd7, - 0x75, 0x7d, 0x8b, 0x23, 0x4c, 0xa6, 0x3a, 0x03, 0xa6, 0x09, 0xf4, 0xfb, 0x59, 0xa4, 0x94, 0x8f, - 0x1a, 0xa8, 0xf9, 0x3f, 0xf4, 0x3f, 0xde, 0x5a, 0x55, 0x0b, 0x3d, 0x33, 0x4e, 0x4f, 0x67, 0x22, - 0xe5, 0xdd, 0x1d, 0xdb, 0x3c, 0xb7, 0x45, 0xeb, 0x7a, 0x37, 0xee, 0x1e, 0xd5, 0x8c, 0x28, 0x0d, - 0x03, 0x91, 0xf2, 0x75, 0x6e, 0x69, 0x03, 0xb7, 0x46, 0x35, 0xeb, 0x99, 0xf2, 0x2a, 0xfa, 0xce, - 0xdd, 0x9f, 0xa3, 0xef, 0x45, 0x0a, 0xb1, 0xd0, 0xe3, 0x75, 0xf6, 0xbf, 0x0d, 0xec, 0x3a, 0xd5, - 0xec, 0xc2, 0xb6, 0x57, 0xe1, 0x1d, 0x77, 0x3b, 0x81, 0x11, 0xe1, 0xa0, 0x08, 0x8d, 0xb8, 0x48, - 0x09, 0x8d, 0x25, 0x1b, 0x44, 0x99, 0x5f, 0x6e, 0xa0, 0xe6, 0x56, 0xd7, 0x4b, 0x60, 0x74, 0x09, - 0x2a, 0x9c, 0x5b, 0xa1, 0x71, 0x4e, 0xcb, 0x3f, 0x2f, 0x07, 0x28, 0xbc, 0x9e, 0x7c, 0x63, 0xe7, - 0x35, 0xc7, 0xce, 0x24, 0xc7, 0x68, 0x9a, 0x63, 0xf4, 0x95, 0x63, 0xf4, 0x3c, 0xc3, 0xce, 0x74, - 0x86, 0x9d, 0xcf, 0x19, 0x76, 0x6e, 0x4f, 0xb8, 0xd0, 0x0f, 0x8f, 0xb4, 0xcd, 0x64, 0x12, 0x2c, - 0x9d, 0xb2, 0x25, 0x64, 0x21, 0x5b, 0xaa, 0x3f, 0x08, 0x46, 0x7f, 0x6f, 0xa0, 0xc7, 0xc3, 0x48, - 0xd1, 0xca, 0xe2, 0x5e, 0xc7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xfb, 0xe1, 0x4c, 0x30, 0x2a, - 0x02, 0x00, 0x00, + // 395 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x4a, 0xeb, 0x40, + 0x18, 0xc5, 0x33, 0xf7, 0xe6, 0xf6, 0x72, 0x03, 0x77, 0x13, 0xda, 0x4b, 0xda, 0xab, 0x63, 0x71, + 0x55, 0x17, 0x6d, 0x28, 0x22, 0x82, 0x0b, 0xd1, 0x14, 0x14, 0x77, 0x92, 0x2e, 0x44, 0x5d, 0x0c, + 0x33, 0x93, 0x18, 0x87, 0x26, 0x99, 0x92, 0x19, 0xa5, 0x7d, 0x03, 0x97, 0x3e, 0x82, 0x4b, 0x1f, + 0xc0, 0x87, 0xe8, 0xb2, 0xb8, 0x72, 0xa9, 0xe9, 0xc6, 0xc7, 0x90, 0x26, 0x13, 0x29, 0xfd, 0x43, + 0x77, 0xf3, 0xcd, 0x39, 0xe7, 0xc7, 0x9c, 0xe1, 0x33, 0x76, 0x08, 0x26, 0xc3, 0x90, 0xc7, 0x21, + 0x26, 0xc2, 0x56, 0x67, 0xfb, 0xbe, 0x4d, 0x7c, 0x89, 0xdb, 0xc5, 0xdc, 0xea, 0x27, 0x5c, 0x72, + 0xf3, 0xff, 0x8c, 0xb5, 0x55, 0x48, 0xca, 0x5a, 0xab, 0x52, 0x2e, 0x22, 0x2e, 0x50, 0x66, 0xb5, + 0xf3, 0x21, 0xcf, 0xd5, 0xca, 0x01, 0x0f, 0x78, 0x7e, 0x3f, 0x3d, 0xe5, 0xb7, 0xdb, 0x0f, 0xba, + 0x51, 0x3a, 0xc7, 0x09, 0x8e, 0x84, 0xb9, 0x6f, 0x58, 0x0a, 0x87, 0x28, 0x8f, 0x65, 0x82, 0xa9, + 0x44, 0x94, 0x7b, 0x3e, 0x62, 0x9e, 0x05, 0xea, 0xa0, 0xa1, 0xbb, 0x15, 0xa5, 0x77, 0x94, 0xdc, + 0xe1, 0x9e, 0x7f, 0xe6, 0x99, 0x87, 0xc6, 0x06, 0x91, 0x14, 0x09, 0x89, 0x7b, 0x2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0x1b, 0x2c, 0x87, 0x7d, 0x5f, 0x90, 0x52, 0xb6, 0x6a, 0xbb, 0x5f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0xdf, 0x0d, 0xd0, 0x9d, 0xe5, 0x02, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -123,6 +132,15 @@ func (this *Params) Equal(that interface{}) bool { } else if this == nil { return false } + if this.BabylonContractCodeId != that1.BabylonContractCodeId { + return false + } + if this.BtcStakingContractCodeId != that1.BtcStakingContractCodeId { + return false + } + if this.BtcFinalityContractCodeId != that1.BtcFinalityContractCodeId { + return false + } if this.BabylonContractAddress != that1.BabylonContractAddress { return false } @@ -160,28 +178,43 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.MaxGasBeginBlocker != 0 { i = encodeVarintBabylon(dAtA, i, uint64(m.MaxGasBeginBlocker)) i-- - dAtA[i] = 0x20 + dAtA[i] = 0x38 } if len(m.BtcFinalityContractAddress) > 0 { i -= len(m.BtcFinalityContractAddress) copy(dAtA[i:], m.BtcFinalityContractAddress) i = encodeVarintBabylon(dAtA, i, uint64(len(m.BtcFinalityContractAddress))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x32 } if len(m.BtcStakingContractAddress) > 0 { i -= len(m.BtcStakingContractAddress) copy(dAtA[i:], m.BtcStakingContractAddress) i = encodeVarintBabylon(dAtA, i, uint64(len(m.BtcStakingContractAddress))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x2a } if len(m.BabylonContractAddress) > 0 { i -= len(m.BabylonContractAddress) copy(dAtA[i:], m.BabylonContractAddress) i = encodeVarintBabylon(dAtA, i, uint64(len(m.BabylonContractAddress))) i-- - dAtA[i] = 0xa + dAtA[i] = 0x22 + } + if m.BtcFinalityContractCodeId != 0 { + i = encodeVarintBabylon(dAtA, i, uint64(m.BtcFinalityContractCodeId)) + i-- + dAtA[i] = 0x18 + } + if m.BtcStakingContractCodeId != 0 { + i = encodeVarintBabylon(dAtA, i, uint64(m.BtcStakingContractCodeId)) + i-- + dAtA[i] = 0x10 + } + if m.BabylonContractCodeId != 0 { + i = encodeVarintBabylon(dAtA, i, uint64(m.BabylonContractCodeId)) + i-- + dAtA[i] = 0x8 } return len(dAtA) - i, nil } @@ -203,6 +236,15 @@ func (m *Params) Size() (n int) { } var l int _ = l + if m.BabylonContractCodeId != 0 { + n += 1 + sovBabylon(uint64(m.BabylonContractCodeId)) + } + if m.BtcStakingContractCodeId != 0 { + n += 1 + sovBabylon(uint64(m.BtcStakingContractCodeId)) + } + if m.BtcFinalityContractCodeId != 0 { + n += 1 + sovBabylon(uint64(m.BtcFinalityContractCodeId)) + } l = len(m.BabylonContractAddress) if l > 0 { n += 1 + l + sovBabylon(uint64(l)) @@ -257,6 +299,63 @@ func (m *Params) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BabylonContractCodeId", wireType) + } + m.BabylonContractCodeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBabylon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BabylonContractCodeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingContractCodeId", wireType) + } + m.BtcStakingContractCodeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBabylon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BtcStakingContractCodeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityContractCodeId", wireType) + } + m.BtcFinalityContractCodeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBabylon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BtcFinalityContractCodeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BabylonContractAddress", wireType) } @@ -288,7 +387,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.BabylonContractAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingContractAddress", wireType) } @@ -320,7 +419,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.BtcStakingContractAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityContractAddress", wireType) } @@ -352,7 +451,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.BtcFinalityContractAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 7: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field MaxGasBeginBlocker", wireType) } diff --git a/x/babylon/types/params.go b/x/babylon/types/params.go index db35b2c..51faf32 100644 --- a/x/babylon/types/params.go +++ b/x/babylon/types/params.go @@ -14,3 +14,16 @@ func (p Params) ValidateBasic() error { } return nil } + +func (p Params) IsCodeStored() bool { + return p.BabylonContractCodeId != 0 && + p.BtcStakingContractCodeId != 0 && + p.BtcFinalityContractCodeId != 0 +} + +func (p Params) IsContractInstantiated() bool { + return p.IsCodeStored() && + len(p.BabylonContractAddress) > 0 && + len(p.BtcStakingContractAddress) > 0 && + len(p.BtcFinalityContractAddress) > 0 +} diff --git a/x/babylon/types/tx.pb.go b/x/babylon/types/tx.pb.go index 54d9cac..78b525a 100644 --- a/x/babylon/types/tx.pb.go +++ b/x/babylon/types/tx.pb.go @@ -30,6 +30,175 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgStoreBabylonContractCodes is the Msg/StoreBabylonContractCodes request +// type. +type MsgStoreBabylonContractCodes struct { + // signer is the address who submits the message. + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + // babylon_contract_code is the bytecode for the Babylon contract. + // WASMByteCode can be raw or gzip compressed + BabylonContractCode []byte `protobuf:"bytes,2,opt,name=babylon_contract_code,json=babylonContractCode,proto3" json:"babylon_contract_code,omitempty"` + // btc_staking_contract_code is the bytecode for the BTC staking contract. + // WASMByteCode can be raw or gzip compressed + BtcStakingContractCode []byte `protobuf:"bytes,3,opt,name=btc_staking_contract_code,json=btcStakingContractCode,proto3" json:"btc_staking_contract_code,omitempty"` + // btc_finality_contract_code is the bytecode for the BTC finality contract. + // WASMByteCode can be raw or gzip compressed + BtcFinalityContractCode []byte `protobuf:"bytes,4,opt,name=btc_finality_contract_code,json=btcFinalityContractCode,proto3" json:"btc_finality_contract_code,omitempty"` +} + +func (m *MsgStoreBabylonContractCodes) Reset() { *m = MsgStoreBabylonContractCodes{} } +func (m *MsgStoreBabylonContractCodes) String() string { return proto.CompactTextString(m) } +func (*MsgStoreBabylonContractCodes) ProtoMessage() {} +func (*MsgStoreBabylonContractCodes) Descriptor() ([]byte, []int) { + return fileDescriptor_406c9f025b2f9448, []int{0} +} +func (m *MsgStoreBabylonContractCodes) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgStoreBabylonContractCodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStoreBabylonContractCodes.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgStoreBabylonContractCodes) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStoreBabylonContractCodes.Merge(m, src) +} +func (m *MsgStoreBabylonContractCodes) XXX_Size() int { + return m.Size() +} +func (m *MsgStoreBabylonContractCodes) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStoreBabylonContractCodes.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStoreBabylonContractCodes proto.InternalMessageInfo + +// MsgStoreBabylonContractCodesResponse is the Msg/StoreBabylonContractCodes +// response type. +type MsgStoreBabylonContractCodesResponse struct { +} + +func (m *MsgStoreBabylonContractCodesResponse) Reset() { *m = MsgStoreBabylonContractCodesResponse{} } +func (m *MsgStoreBabylonContractCodesResponse) String() string { return proto.CompactTextString(m) } +func (*MsgStoreBabylonContractCodesResponse) ProtoMessage() {} +func (*MsgStoreBabylonContractCodesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_406c9f025b2f9448, []int{1} +} +func (m *MsgStoreBabylonContractCodesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgStoreBabylonContractCodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStoreBabylonContractCodesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgStoreBabylonContractCodesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStoreBabylonContractCodesResponse.Merge(m, src) +} +func (m *MsgStoreBabylonContractCodesResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgStoreBabylonContractCodesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStoreBabylonContractCodesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStoreBabylonContractCodesResponse proto.InternalMessageInfo + +// MsgInstantiateBabylonContracts is the Msg/InstantiateBabylonContracts request +// type. +type MsgInstantiateBabylonContracts struct { + // signer is the address who submits the message. + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + // init_msg is the instantiation message for the Babylon contract. + InitMsg []byte `protobuf:"bytes,2,opt,name=init_msg,json=initMsg,proto3" json:"init_msg,omitempty"` +} + +func (m *MsgInstantiateBabylonContracts) Reset() { *m = MsgInstantiateBabylonContracts{} } +func (m *MsgInstantiateBabylonContracts) String() string { return proto.CompactTextString(m) } +func (*MsgInstantiateBabylonContracts) ProtoMessage() {} +func (*MsgInstantiateBabylonContracts) Descriptor() ([]byte, []int) { + return fileDescriptor_406c9f025b2f9448, []int{2} +} +func (m *MsgInstantiateBabylonContracts) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgInstantiateBabylonContracts) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgInstantiateBabylonContracts.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgInstantiateBabylonContracts) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgInstantiateBabylonContracts.Merge(m, src) +} +func (m *MsgInstantiateBabylonContracts) XXX_Size() int { + return m.Size() +} +func (m *MsgInstantiateBabylonContracts) XXX_DiscardUnknown() { + xxx_messageInfo_MsgInstantiateBabylonContracts.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgInstantiateBabylonContracts proto.InternalMessageInfo + +// MsgInstantiateBabylonContractsResponse is the Msg/InstantiateBabylonContracts +// response type. +type MsgInstantiateBabylonContractsResponse struct { +} + +func (m *MsgInstantiateBabylonContractsResponse) Reset() { + *m = MsgInstantiateBabylonContractsResponse{} +} +func (m *MsgInstantiateBabylonContractsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgInstantiateBabylonContractsResponse) ProtoMessage() {} +func (*MsgInstantiateBabylonContractsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_406c9f025b2f9448, []int{3} +} +func (m *MsgInstantiateBabylonContractsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgInstantiateBabylonContractsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgInstantiateBabylonContractsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgInstantiateBabylonContractsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgInstantiateBabylonContractsResponse.Merge(m, src) +} +func (m *MsgInstantiateBabylonContractsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgInstantiateBabylonContractsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgInstantiateBabylonContractsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgInstantiateBabylonContractsResponse proto.InternalMessageInfo + // MsgUpdateParams is the Msg/UpdateParams request type. type MsgUpdateParams struct { // authority is the address that controls the module (defaults to x/gov unless @@ -45,7 +214,7 @@ func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParams) ProtoMessage() {} func (*MsgUpdateParams) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{0} + return fileDescriptor_406c9f025b2f9448, []int{4} } func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -83,7 +252,7 @@ func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParamsResponse) ProtoMessage() {} func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{1} + return fileDescriptor_406c9f025b2f9448, []int{5} } func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -113,6 +282,10 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgStoreBabylonContractCodes)(nil), "babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodes") + proto.RegisterType((*MsgStoreBabylonContractCodesResponse)(nil), "babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodesResponse") + proto.RegisterType((*MsgInstantiateBabylonContracts)(nil), "babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts") + proto.RegisterType((*MsgInstantiateBabylonContractsResponse)(nil), "babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContractsResponse") proto.RegisterType((*MsgUpdateParams)(nil), "babylonlabs.babylon.v1beta1.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "babylonlabs.babylon.v1beta1.MsgUpdateParamsResponse") } @@ -122,29 +295,42 @@ func init() { } var fileDescriptor_406c9f025b2f9448 = []byte{ - // 337 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0x4a, 0x4c, 0xaa, - 0xcc, 0xc9, 0xcf, 0xcb, 0x49, 0x4c, 0x2a, 0xd6, 0x87, 0xb2, 0xf5, 0xcb, 0x0c, 0x93, 0x52, 0x4b, - 0x12, 0x0d, 0xf5, 0x4b, 0x2a, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x91, 0x54, 0xe9, - 0x41, 0xd9, 0x7a, 0x50, 0x55, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x75, 0xfa, 0x20, 0x16, - 0x44, 0x8b, 0x94, 0x78, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0xb1, 0x7e, 0x6e, 0x71, 0xba, 0x7e, 0x99, - 0x21, 0x88, 0x82, 0x4a, 0x48, 0x42, 0x24, 0xe2, 0x21, 0x3a, 0x20, 0x1c, 0xa8, 0x94, 0x26, 0x3e, - 0xc7, 0xc0, 0xac, 0x05, 0x2b, 0x55, 0x9a, 0xc3, 0xc8, 0xc5, 0xef, 0x5b, 0x9c, 0x1e, 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0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x91, 0x2c, 0xd1, 0xcd, 0xcc, 0x87, 0x71, - 0x75, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xe0, 0x31, 0x54, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, - 0x8e, 0x18, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xcd, 0x42, 0xc9, 0x7e, 0x52, 0x02, 0x00, - 0x00, + // 551 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xcf, 0x6b, 0x13, 0x41, + 0x14, 0xc7, 0xb3, 0x4d, 0x8d, 0x76, 0x5a, 0x14, 0xd6, 0x6a, 0x92, 0xad, 0xac, 0x25, 0x96, 0x12, + 0x8b, 0xd9, 0x35, 0xf1, 0x07, 0xb4, 0x3d, 0x25, 0x01, 0xc1, 0x43, 0x40, 0x12, 0xbc, 0x78, 0x09, + 0xb3, 0x3f, 0x9c, 0x0e, 0x4d, 0x66, 0xc2, 0xbe, 0xd7, 0xd2, 0x78, 0x12, 0x6f, 0xde, 0xbc, 0x0a, + 0x82, 0xff, 0x42, 0x0f, 0x9e, 0x3d, 0xe7, 0x58, 0x3c, 0x79, 0x12, 0x4d, 0x0e, 0xfd, 0x37, 0x24, + 0xbb, 0xb3, 0x69, 0x12, 0x71, 0x83, 0xf5, 0xb4, 0x33, 0xbc, 0xef, 0xe7, 0x7d, 0xbf, 0x3b, 0xf3, + 0x18, 0xb2, 0xe5, 0x50, 0xa7, 0xdf, 0x91, 0xa2, 0x43, 0x1d, 0xb0, 0xd5, 0xda, 0x3e, 0x2e, 0x3b, + 0x3e, 0xd2, 0xb2, 0x8d, 0x27, 0x56, 0x2f, 0x90, 0x28, 0xf5, 0x8d, 0x29, 0x95, 0xa5, 0xd6, 0x96, + 0x52, 0x19, 0xeb, 0x4c, 0x32, 0x19, 0xea,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 0x32, 0x53, 0xdf, 0x47, 0x66, 0xea, 0xd5, 0x13, 0xc6, 0xf1, 0xe0, 0xc8, 0xb1, + 0x5c, 0xd9, 0xb5, 0xa7, 0x4c, 0x4a, 0x5c, 0xc6, 0xdb, 0x12, 0x78, 0x87, 0xf6, 0xc9, 0xe4, 0xe5, + 0xc2, 0x7e, 0xcf, 0x07, 0x27, 0x13, 0x3e, 0x58, 0x8f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x53, + 0x29, 0x66, 0x64, 0x6a, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -159,6 +345,12 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + // StoreBabylonContractCodes defines an operation for storing the Babylon + // contract codes. + StoreBabylonContractCodes(ctx context.Context, in *MsgStoreBabylonContractCodes, opts ...grpc.CallOption) (*MsgStoreBabylonContractCodesResponse, error) + // InstantiateBabylonContracts defines an operation for instantiating the + // Babylon contracts. + InstantiateBabylonContracts(ctx context.Context, in *MsgInstantiateBabylonContracts, opts ...grpc.CallOption) (*MsgInstantiateBabylonContractsResponse, error) // UpdateParams defines a (governance) operation for updating the x/auth // module parameters. The authority defaults to the x/gov module account. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) @@ -172,6 +364,24 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) StoreBabylonContractCodes(ctx context.Context, in *MsgStoreBabylonContractCodes, opts ...grpc.CallOption) (*MsgStoreBabylonContractCodesResponse, error) { + out := new(MsgStoreBabylonContractCodesResponse) + err := c.cc.Invoke(ctx, "/babylonlabs.babylon.v1beta1.Msg/StoreBabylonContractCodes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) InstantiateBabylonContracts(ctx context.Context, in *MsgInstantiateBabylonContracts, opts ...grpc.CallOption) (*MsgInstantiateBabylonContractsResponse, error) { + out := new(MsgInstantiateBabylonContractsResponse) + err := c.cc.Invoke(ctx, "/babylonlabs.babylon.v1beta1.Msg/InstantiateBabylonContracts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { out := new(MsgUpdateParamsResponse) err := c.cc.Invoke(ctx, "/babylonlabs.babylon.v1beta1.Msg/UpdateParams", in, out, opts...) @@ -183,6 +393,12 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts // MsgServer is the server API for Msg service. type MsgServer interface { + // StoreBabylonContractCodes defines an operation for storing the Babylon + // contract codes. + StoreBabylonContractCodes(context.Context, *MsgStoreBabylonContractCodes) (*MsgStoreBabylonContractCodesResponse, error) + // InstantiateBabylonContracts defines an operation for instantiating the + // Babylon contracts. + InstantiateBabylonContracts(context.Context, *MsgInstantiateBabylonContracts) (*MsgInstantiateBabylonContractsResponse, error) // UpdateParams defines a (governance) operation for updating the x/auth // module parameters. The authority defaults to the x/gov module account. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) @@ -192,6 +408,12 @@ type MsgServer interface { type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) StoreBabylonContractCodes(ctx context.Context, req *MsgStoreBabylonContractCodes) (*MsgStoreBabylonContractCodesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method StoreBabylonContractCodes not implemented") +} +func (*UnimplementedMsgServer) InstantiateBabylonContracts(ctx context.Context, req *MsgInstantiateBabylonContracts) (*MsgInstantiateBabylonContractsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method InstantiateBabylonContracts not implemented") +} func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } @@ -200,6 +422,42 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_StoreBabylonContractCodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgStoreBabylonContractCodes) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).StoreBabylonContractCodes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/babylonlabs.babylon.v1beta1.Msg/StoreBabylonContractCodes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).StoreBabylonContractCodes(ctx, req.(*MsgStoreBabylonContractCodes)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_InstantiateBabylonContracts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgInstantiateBabylonContracts) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).InstantiateBabylonContracts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/babylonlabs.babylon.v1beta1.Msg/InstantiateBabylonContracts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).InstantiateBabylonContracts(ctx, req.(*MsgInstantiateBabylonContracts)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgUpdateParams) if err := dec(in); err != nil { @@ -222,6 +480,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "babylonlabs.babylon.v1beta1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "StoreBabylonContractCodes", + Handler: _Msg_StoreBabylonContractCodes_Handler, + }, + { + MethodName: "InstantiateBabylonContracts", + Handler: _Msg_InstantiateBabylonContracts_Handler, + }, { MethodName: "UpdateParams", Handler: _Msg_UpdateParams_Handler, @@ -231,6 +497,140 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "babylonlabs/babylon/v1beta1/tx.proto", } +func (m *MsgStoreBabylonContractCodes) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgStoreBabylonContractCodes) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgStoreBabylonContractCodes) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BtcFinalityContractCode) > 0 { + i -= len(m.BtcFinalityContractCode) + copy(dAtA[i:], m.BtcFinalityContractCode) + i = encodeVarintTx(dAtA, i, uint64(len(m.BtcFinalityContractCode))) + i-- + dAtA[i] = 0x22 + } + if len(m.BtcStakingContractCode) > 0 { + i -= len(m.BtcStakingContractCode) + copy(dAtA[i:], m.BtcStakingContractCode) + i = encodeVarintTx(dAtA, i, uint64(len(m.BtcStakingContractCode))) + i-- + dAtA[i] = 0x1a + } + if len(m.BabylonContractCode) > 0 { + i -= len(m.BabylonContractCode) + copy(dAtA[i:], m.BabylonContractCode) + i = encodeVarintTx(dAtA, i, uint64(len(m.BabylonContractCode))) + i-- + dAtA[i] = 0x12 + } + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgStoreBabylonContractCodesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgStoreBabylonContractCodesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgStoreBabylonContractCodesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgInstantiateBabylonContracts) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgInstantiateBabylonContracts) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgInstantiateBabylonContracts) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.InitMsg) > 0 { + i -= len(m.InitMsg) + copy(dAtA[i:], m.InitMsg) + i = encodeVarintTx(dAtA, i, uint64(len(m.InitMsg))) + i-- + dAtA[i] = 0x12 + } + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgInstantiateBabylonContractsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgInstantiateBabylonContractsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgInstantiateBabylonContractsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -305,22 +705,32 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgUpdateParams) Size() (n int) { +func (m *MsgStoreBabylonContractCodes) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Authority) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BabylonContractCode) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BtcStakingContractCode) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BtcFinalityContractCode) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.Params.Size() - n += 1 + l + sovTx(uint64(l)) return n } -func (m *MsgUpdateParamsResponse) Size() (n int) { +func (m *MsgStoreBabylonContractCodesResponse) Size() (n int) { if m == nil { return 0 } @@ -329,12 +739,462 @@ func (m *MsgUpdateParamsResponse) Size() (n int) { return n } -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 +func (m *MsgInstantiateBabylonContracts) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.InitMsg) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n } -func sozTx(x uint64) (n int) { + +func (m *MsgInstantiateBabylonContractsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *MsgStoreBabylonContractCodes) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStoreBabylonContractCodes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStoreBabylonContractCodes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BabylonContractCode", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BabylonContractCode = append(m.BabylonContractCode[:0], dAtA[iNdEx:postIndex]...) + if m.BabylonContractCode == nil { + m.BabylonContractCode = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingContractCode", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BtcStakingContractCode = append(m.BtcStakingContractCode[:0], dAtA[iNdEx:postIndex]...) + if m.BtcStakingContractCode == nil { + m.BtcStakingContractCode = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityContractCode", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BtcFinalityContractCode = append(m.BtcFinalityContractCode[:0], dAtA[iNdEx:postIndex]...) + if m.BtcFinalityContractCode == nil { + m.BtcFinalityContractCode = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgStoreBabylonContractCodesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStoreBabylonContractCodesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStoreBabylonContractCodesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgInstantiateBabylonContracts: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgInstantiateBabylonContracts: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InitMsg", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InitMsg = append(m.InitMsg[:0], dAtA[iNdEx:postIndex]...) + if m.InitMsg == nil { + m.InitMsg = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgInstantiateBabylonContractsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgInstantiateBabylonContractsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgInstantiateBabylonContractsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From c8d957a37ab3cd8f9cfc90065d2a1b157f9dd32e Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Tue, 3 Dec 2024 16:14:23 +1100 Subject: [PATCH 3/7] some test cases --- docs/proto/proto-docs.md | 10 +- proto/babylonlabs/babylon/v1beta1/tx.proto | 25 +- x/babylon/keeper/keeper_test.go | 116 ++++-- x/babylon/keeper/msg_server.go | 20 +- x/babylon/keeper/msg_server_test.go | 90 ++++- x/babylon/types/babylon.go | 67 ++-- x/babylon/types/codec.go | 6 + x/babylon/types/tx.pb.go | 430 ++++++++++++++++++--- 8 files changed, 657 insertions(+), 107 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 37d5886..776dafb 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -168,7 +168,15 @@ type. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `signer` | [string](#string) | | signer is the address who submits the message. | -| `init_msg` | [bytes](#bytes) | | init_msg is the instantiation message for the Babylon contract. | +| `network` | [string](#string) | | network is the Bitcoin network to connect to (e.g. "regtest", "testnet", "mainnet") | +| `babylon_tag` | [string](#string) | | babylon_tag is a unique identifier for this Babylon instance | +| `btc_confirmation_depth` | [uint32](#uint32) | | btc_confirmation_depth is the number of confirmations required for Bitcoin transactions | +| `checkpoint_finalization_timeout` | [uint32](#uint32) | | checkpoint_finalization_timeout is the timeout in blocks for checkpoint finalization | +| `notify_cosmos_zone` | [bool](#bool) | | notify_cosmos_zone indicates whether to notify the Cosmos zone of events | +| `btc_staking_msg` | [bytes](#bytes) | | btc_staking_msg is the initialization message for the BTC staking contract | +| `btc_finality_msg` | [bytes](#bytes) | | btc_finality_msg is the initialization message for the BTC finality contract | +| `consumer_name` | [string](#string) | | consumer_name is the name of this consumer chain | +| `consumer_description` | [string](#string) | | consumer_description is a description of this consumer chain | diff --git a/proto/babylonlabs/babylon/v1beta1/tx.proto b/proto/babylonlabs/babylon/v1beta1/tx.proto index 77fe22f..a6cc386 100644 --- a/proto/babylonlabs/babylon/v1beta1/tx.proto +++ b/proto/babylonlabs/babylon/v1beta1/tx.proto @@ -57,8 +57,29 @@ message MsgInstantiateBabylonContracts { // signer is the address who submits the message. string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; - // init_msg is the instantiation message for the Babylon contract. - bytes init_msg = 2; + + // network is the Bitcoin network to connect to (e.g. "regtest", "testnet", + // "mainnet") + string network = 2; + // babylon_tag is a unique identifier for this Babylon instance + string babylon_tag = 3; + // btc_confirmation_depth is the number of confirmations required for Bitcoin + // transactions + uint32 btc_confirmation_depth = 4; + // checkpoint_finalization_timeout is the timeout in blocks for checkpoint + // finalization + uint32 checkpoint_finalization_timeout = 5; + // notify_cosmos_zone indicates whether to notify the Cosmos zone of events + bool notify_cosmos_zone = 6; + // btc_staking_msg is the initialization message for the BTC staking contract + bytes btc_staking_msg = 7; + // btc_finality_msg is the initialization message for the BTC finality + // contract + bytes btc_finality_msg = 8; + // consumer_name is the name of this consumer chain + string consumer_name = 9; + // consumer_description is a description of this consumer chain + string consumer_description = 10; } // MsgInstantiateBabylonContractsResponse is the Msg/InstantiateBabylonContracts diff --git a/x/babylon/keeper/keeper_test.go b/x/babylon/keeper/keeper_test.go index e69bd37..52ea498 100644 --- a/x/babylon/keeper/keeper_test.go +++ b/x/babylon/keeper/keeper_test.go @@ -1,6 +1,8 @@ package keeper_test import ( + "fmt" + "os" "testing" "time" @@ -8,10 +10,13 @@ import ( "cosmossdk.io/store" storemetrics "cosmossdk.io/store/metrics" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/evidence" evidencetypes "cosmossdk.io/x/evidence/types" "cosmossdk.io/x/feegrant" + "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/CosmWasm/wasmd/x/wasm/ioutils" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -30,10 +35,13 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + "github.com/cosmos/cosmos-sdk/x/distribution" distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/gov" @@ -41,17 +49,21 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/mint" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/ibc-go/modules/capability" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v8/modules/core" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" "github.com/stretchr/testify/require" @@ -70,11 +82,20 @@ type encodingConfig struct { var moduleBasics = module.NewBasicManager( auth.AppModuleBasic{}, bank.AppModuleBasic{}, + capability.AppModuleBasic{}, staking.AppModuleBasic{}, mint.AppModuleBasic{}, + distribution.AppModuleBasic{}, gov.NewAppModuleBasic([]govclient.ProposalHandler{ paramsclient.ProposalHandler, }), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + ibc.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + vesting.AppModuleBasic{}, ) func makeEncodingConfig(_ testing.TB) encodingConfig { @@ -86,6 +107,9 @@ func makeEncodingConfig(_ testing.TB) encodingConfig { moduleBasics.RegisterLegacyAminoCodec(amino) moduleBasics.RegisterInterfaces(interfaceRegistry) + // add wasm types + wasmtypes.RegisterInterfaces(interfaceRegistry) + wasmtypes.RegisterLegacyAminoCodec(amino) // add babylon types types.RegisterInterfaces(interfaceRegistry) types.RegisterLegacyAminoCodec(amino) @@ -99,17 +123,18 @@ func makeEncodingConfig(_ testing.TB) encodingConfig { } type TestKeepers struct { - Ctx sdk.Context - StakingKeeper *stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - BankKeeper bankkeeper.Keeper - StoreKey *storetypes.KVStoreKey - EncodingConfig encodingConfig - BabylonKeeper *keeper.Keeper - AccountKeeper authkeeper.AccountKeeper - WasmKeeper *wasmkeeper.Keeper - WasmMsgServer wasmtypes.MsgServer - Faucet *wasmkeeper.TestFaucet + Ctx sdk.Context + StakingKeeper *stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + BankKeeper bankkeeper.Keeper + StoreKey *storetypes.KVStoreKey + EncodingConfig encodingConfig + BabylonKeeper *keeper.Keeper + BabylonMsgServer types.MsgServer + AccountKeeper authkeeper.AccountKeeper + WasmKeeper *wasmkeeper.Keeper + WasmMsgServer wasmtypes.MsgServer + Faucet *wasmkeeper.TestFaucet } func NewTestKeepers(t testing.TB, opts ...keeper.Option) TestKeepers { @@ -267,7 +292,7 @@ func NewTestKeepers(t testing.TB, opts ...keeper.Option) TestKeepers { querier, t.TempDir(), wasmtypes.DefaultWasmConfig(), - []string{"iterator", "staking", "stargate", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "virtual_staking"}, + []string{"iterator", "staking", "stargate", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "virtual_staking"}, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) require.NoError(t, wasmKeeper.SetParams(ctx, wasmtypes.DefaultParams())) @@ -284,19 +309,64 @@ func NewTestKeepers(t testing.TB, opts ...keeper.Option) TestKeepers { opts..., ) require.NoError(t, babylonKeeper.SetParams(ctx, types.DefaultParams(sdk.DefaultBondDenom))) + babylonMsgServer := keeper.NewMsgServer(babylonKeeper) faucet := wasmkeeper.NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1_000_000_000_000)) return TestKeepers{ - Ctx: ctx, - AccountKeeper: accountKeeper, - StakingKeeper: stakingKeeper, - SlashingKeeper: slashingKeeper, - BankKeeper: bankKeeper, - StoreKey: keys[types.StoreKey], - EncodingConfig: encConfig, - BabylonKeeper: babylonKeeper, - WasmKeeper: &wasmKeeper, - WasmMsgServer: wasmMsgServer, - Faucet: faucet, + Ctx: ctx, + AccountKeeper: accountKeeper, + StakingKeeper: stakingKeeper, + SlashingKeeper: slashingKeeper, + BankKeeper: bankKeeper, + StoreKey: keys[types.StoreKey], + EncodingConfig: encConfig, + BabylonKeeper: babylonKeeper, + BabylonMsgServer: babylonMsgServer, + WasmKeeper: &wasmKeeper, + WasmMsgServer: wasmMsgServer, + Faucet: faucet, } } + +const ( + TestDataPath = "../../../tests/testdata" + BabylonContractCodePath = TestDataPath + "/babylon_contract.wasm" + BtcStakingContractCodePath = TestDataPath + "/btc_staking.wasm" + BtcFinalityContractCodePath = TestDataPath + "/btc_finality.wasm" +) + +func GetGZippedContractCode(path string) ([]byte, error) { + wasm, err := os.ReadFile(path) + if err != nil { + return nil, err + } + // gzip the wasm file + if ioutils.IsWasm(wasm) { + wasm, err = ioutils.GzipIt(wasm) + + if err != nil { + return nil, err + } + } else if !ioutils.IsGzip(wasm) { + return nil, fmt.Errorf("invalid input file. Use wasm binary or gzip") + } + + return wasm, nil +} + +func GetGZippedContractCodes() ([]byte, []byte, []byte) { + babylonContractCode, err := GetGZippedContractCode(BabylonContractCodePath) + if err != nil { + panic(err) + } + btcStakingContractCode, err := GetGZippedContractCode(BtcStakingContractCodePath) + if err != nil { + panic(err) + } + btcFinalityContractCode, err := GetGZippedContractCode(BtcFinalityContractCodePath) + if err != nil { + panic(err) + } + + return babylonContractCode, btcStakingContractCode, btcFinalityContractCode +} diff --git a/x/babylon/keeper/msg_server.go b/x/babylon/keeper/msg_server.go index c7e280a..01cbee8 100644 --- a/x/babylon/keeper/msg_server.go +++ b/x/babylon/keeper/msg_server.go @@ -57,8 +57,26 @@ func (ms msgServer) InstantiateBabylonContracts(goCtx context.Context, req *type return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "only authority can override instantiated contracts; expected %s, got %s", ms.k.authority, req.Signer) } + // construct the init message + initMsg, err := types.NewInitMsg( + ms.k.authority, + ¶ms, + req.Network, + req.BabylonTag, + req.BtcConfirmationDepth, + req.CheckpointFinalizationTimeout, + req.NotifyCosmosZone, + req.BtcStakingMsg, + req.BtcFinalityMsg, + req.ConsumerName, + req.ConsumerDescription, + ) + if err != nil { + return nil, err + } + // instantiate the contracts - babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, req.InitMsg) + babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, initMsg) if err != nil { return nil, err } diff --git a/x/babylon/keeper/msg_server_test.go b/x/babylon/keeper/msg_server_test.go index b55569d..52b9400 100644 --- a/x/babylon/keeper/msg_server_test.go +++ b/x/babylon/keeper/msg_server_test.go @@ -1 +1,89 @@ -package keeper +package keeper_test + +import ( + "encoding/json" + "testing" + + "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" + "github.com/stretchr/testify/require" +) + +func TestStoreBabylonContractCodes(t *testing.T) { + keepers := NewTestKeepers(t) + msgServer := keepers.BabylonMsgServer + + babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() + + // store Babylon contract codes + _, err := msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ + BabylonContractCode: babylonContractCode, + BtcStakingContractCode: btcStakingContractCode, + BtcFinalityContractCode: btcFinalityContractCode, + }) + require.NoError(t, err) + + // ensure params are set + params := keepers.BabylonKeeper.GetParams(keepers.Ctx) + require.Positive(t, params.BabylonContractCodeId) + require.Positive(t, params.BtcStakingContractCodeId) + require.Positive(t, params.BtcFinalityContractCodeId) + + // ensure non-gov account cannot override + _, err = msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ + BabylonContractCode: babylonContractCode, + BtcStakingContractCode: btcStakingContractCode, + BtcFinalityContractCode: btcFinalityContractCode, + }) + require.Error(t, err) + + // gov can override + _, err = msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ + Signer: keepers.BabylonKeeper.GetAuthority(), + BabylonContractCode: babylonContractCode, + BtcStakingContractCode: btcStakingContractCode, + BtcFinalityContractCode: btcFinalityContractCode, + }) + require.NoError(t, err) +} + +// TODO: fix this test +func TestInstantiateBabylonContracts(t *testing.T) { + keepers := NewTestKeepers(t) + msgServer := keepers.BabylonMsgServer + + // store Babylon contract codes + babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() + _, err := msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ + BabylonContractCode: babylonContractCode, + BtcStakingContractCode: btcStakingContractCode, + BtcFinalityContractCode: btcFinalityContractCode, + }) + require.NoError(t, err) + + // BTC staking init message + btcStakingInitMsg := map[string]interface{}{ + "admin": keepers.BabylonKeeper.GetAuthority(), + } + btcStakingInitMsgBytes, err := json.Marshal(btcStakingInitMsg) + require.NoError(t, err) + // BTC finality init message + btcFinalityInitMsg := map[string]interface{}{ + "admin": keepers.BabylonKeeper.GetAuthority(), + } + btcFinalityInitMsgBytes, err := json.Marshal(btcFinalityInitMsg) + require.NoError(t, err) + + // instantiate Babylon contract + _, err = msgServer.InstantiateBabylonContracts(keepers.Ctx, &types.MsgInstantiateBabylonContracts{ + Network: "regtest", + BabylonTag: "01020304", + BtcConfirmationDepth: 1, + CheckpointFinalizationTimeout: 2, + NotifyCosmosZone: false, + BtcStakingMsg: btcStakingInitMsgBytes, + BtcFinalityMsg: btcFinalityInitMsgBytes, + ConsumerName: "test-consumer", + ConsumerDescription: "test-consumer-description", + }) + require.NoError(t, err) +} diff --git a/x/babylon/types/babylon.go b/x/babylon/types/babylon.go index 45cd09b..bc83cd3 100644 --- a/x/babylon/types/babylon.go +++ b/x/babylon/types/babylon.go @@ -1,5 +1,7 @@ package types +import "encoding/json" + // Config represents the configuration for the Babylon contract type BabylonContractConfig struct { Network string `json:"network"` @@ -20,36 +22,37 @@ type BabylonContractConfig struct { ConsumerDescription string `json:"consumer_description,omitempty"` } -type BabylonContractInitMsg struct { - // Network represents the Bitcoin network (mainnet, testnet, etc.) - Network string `json:"network"` - // BabylonTag is a string encoding four bytes used for identification / tagging of the Babylon zone. - // NOTE: this is a hex string, not raw bytes - BabylonTag string `json:"babylon_tag"` - // BTCConfirmationDepth is the number of confirmations required for BTC headers - BTCConfirmationDepth uint32 `json:"btc_confirmation_depth"` - // CheckpointFinalizationTimeout is the timeout period for checkpoint finalization - CheckpointFinalizationTimeout uint32 `json:"checkpoint_finalization_timeout"` - // NotifyCosmosZone indicates whether to send Cosmos zone messages notifying BTC-finalised headers. - // NOTE: If set to true, then the Cosmos zone needs to integrate the corresponding message handler - // as well - NotifyCosmosZone bool `json:"notify_cosmos_zone"` - // BTCStakingCodeID is the code ID for the BTC staking contract, if set - BTCStakingCodeID *uint64 `json:"btc_staking_code_id,omitempty"` - // BTCStakingMsg is the instantiation message for the BTC staking contract. - // This message is opaque to the Babylon contract, and depends on the specific staking contract - // being instantiated - BTCStakingMsg []byte `json:"btc_staking_msg,omitempty"` - // BTCFinalityCodeID is the code ID for the BTC finality contract, if set - BTCFinalityCodeID *uint64 `json:"btc_finality_code_id,omitempty"` - // BTCFinalityMsg is the instantiation message for the BTC finality contract. - // This message is opaque to the Babylon contract, and depends on the specific finality contract - // being instantiated - BTCFinalityMsg []byte `json:"btc_finality_msg,omitempty"` - // Admin is the Wasm migration / upgrade admin of the BTC staking contract and the BTC finality contract - Admin string `json:"admin,omitempty"` - // ConsumerName represents the name of the Consumer - ConsumerName string `json:"consumer_name,omitempty"` - // ConsumerDescription represents the description of the Consumer - ConsumerDescription string `json:"consumer_description,omitempty"` +// NewInitMsg creates the init message for the Babylon contract +func NewInitMsg( + govAccount string, + params *Params, + network string, + babylonTag string, + btcConfirmationDepth uint32, + checkpointFinalizationTimeout uint32, + notifyCosmosZone bool, + btcStakingInitMsgBytes []byte, + btcFinalityInitMsgBytes []byte, + consumerName string, + consumerDescription string, +) ([]byte, error) { + initMsg := map[string]interface{}{ + "network": network, + "babylon_tag": babylonTag, + "btc_confirmation_depth": btcConfirmationDepth, + "checkpoint_finalization_timeout": checkpointFinalizationTimeout, + "notify_cosmos_zone": notifyCosmosZone, + "btc_staking_code_id": params.BtcStakingContractCodeId, + "btc_staking_msg": btcStakingInitMsgBytes, + "consumer_name": consumerName, + "consumer_description": consumerDescription, + "btc_finality_code_id": params.BtcFinalityContractCodeId, + "btc_finality_msg": btcFinalityInitMsgBytes, + "admin": govAccount, + } + initMsgBytes, err := json.Marshal(initMsg) + if err != nil { + return nil, err + } + return initMsgBytes, nil } diff --git a/x/babylon/types/codec.go b/x/babylon/types/codec.go index ff8e82c..63ef3c6 100644 --- a/x/babylon/types/codec.go +++ b/x/babylon/types/codec.go @@ -10,12 +10,18 @@ import ( // RegisterLegacyAminoCodec register types with legacy amino func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgStoreBabylonContractCodes{}, "babylon/MsgStoreBabylonContractCodes", nil) + cdc.RegisterConcrete(&MsgInstantiateBabylonContracts{}, "babylon/MsgInstantiateBabylonContracts", nil) + cdc.RegisterConcrete(&MsgUpdateParams{}, "babylon/MsgUpdateParams", nil) } // RegisterInterfaces register types with interface registry func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), + &MsgStoreBabylonContractCodes{}, + &MsgInstantiateBabylonContracts{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/babylon/types/tx.pb.go b/x/babylon/types/tx.pb.go index 78b525a..8fd3627 100644 --- a/x/babylon/types/tx.pb.go +++ b/x/babylon/types/tx.pb.go @@ -122,8 +122,28 @@ var xxx_messageInfo_MsgStoreBabylonContractCodesResponse proto.InternalMessageIn type MsgInstantiateBabylonContracts struct { // signer is the address who submits the message. Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` - // init_msg is the instantiation message for the Babylon contract. - InitMsg []byte `protobuf:"bytes,2,opt,name=init_msg,json=initMsg,proto3" json:"init_msg,omitempty"` + // network is the Bitcoin network to connect to (e.g. "regtest", "testnet", + // "mainnet") + Network string `protobuf:"bytes,2,opt,name=network,proto3" json:"network,omitempty"` + // babylon_tag is a unique identifier for this Babylon instance + BabylonTag string `protobuf:"bytes,3,opt,name=babylon_tag,json=babylonTag,proto3" json:"babylon_tag,omitempty"` + // btc_confirmation_depth is the number of confirmations required for Bitcoin + // transactions + BtcConfirmationDepth uint32 `protobuf:"varint,4,opt,name=btc_confirmation_depth,json=btcConfirmationDepth,proto3" json:"btc_confirmation_depth,omitempty"` + // checkpoint_finalization_timeout is the timeout in blocks for checkpoint + // finalization + CheckpointFinalizationTimeout uint32 `protobuf:"varint,5,opt,name=checkpoint_finalization_timeout,json=checkpointFinalizationTimeout,proto3" json:"checkpoint_finalization_timeout,omitempty"` + // notify_cosmos_zone indicates whether to notify the Cosmos zone of events + NotifyCosmosZone bool `protobuf:"varint,6,opt,name=notify_cosmos_zone,json=notifyCosmosZone,proto3" json:"notify_cosmos_zone,omitempty"` + // btc_staking_msg is the initialization message for the BTC staking contract + BtcStakingMsg []byte `protobuf:"bytes,7,opt,name=btc_staking_msg,json=btcStakingMsg,proto3" json:"btc_staking_msg,omitempty"` + // btc_finality_msg is the initialization message for the BTC finality + // contract + BtcFinalityMsg []byte `protobuf:"bytes,8,opt,name=btc_finality_msg,json=btcFinalityMsg,proto3" json:"btc_finality_msg,omitempty"` + // consumer_name is the name of this consumer chain + ConsumerName string `protobuf:"bytes,9,opt,name=consumer_name,json=consumerName,proto3" json:"consumer_name,omitempty"` + // consumer_description is a description of this consumer chain + ConsumerDescription string `protobuf:"bytes,10,opt,name=consumer_description,json=consumerDescription,proto3" json:"consumer_description,omitempty"` } func (m *MsgInstantiateBabylonContracts) Reset() { *m = MsgInstantiateBabylonContracts{} } @@ -295,42 +315,54 @@ func init() { } var fileDescriptor_406c9f025b2f9448 = []byte{ - // 551 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xcf, 0x6b, 0x13, 0x41, - 0x14, 0xc7, 0xb3, 0x4d, 0x8d, 0x76, 0x5a, 0x14, 0xd6, 0x6a, 0x92, 0xad, 0xac, 0x25, 0x96, 0x12, - 0x8b, 0xd9, 0x35, 0xf1, 0x07, 0xb4, 0x3d, 0x25, 0x01, 0xc1, 0x43, 0x40, 0x12, 0xbc, 0x78, 0x09, - 0xb3, 0x3f, 0x9c, 0x0e, 0x4d, 0x66, 0xc2, 0xbe, 0xd7, 0xd2, 0x78, 0x12, 0x6f, 0xde, 0xbc, 0x0a, - 0x82, 0xff, 0x42, 0x0f, 0x9e, 0x3d, 0xe7, 0x58, 0x3c, 0x79, 0x12, 0x4d, 0x0e, 0xfd, 0x37, 0x24, - 0xbb, 0xb3, 0x69, 0x12, 0x71, 0x83, 0xf5, 0xb4, 0x33, 0xbc, 0xef, 0xe7, 0x7d, 0xbf, 0x3b, 0xf3, - 0x18, 0xb2, 0xe5, 0x50, 0xa7, 0xdf, 0x91, 0xa2, 0x43, 0x1d, 0xb0, 0xd5, 0xda, 0x3e, 0x2e, 0x3b, - 0x3e, 0xd2, 0xb2, 0x8d, 0x27, 0x56, 0x2f, 0x90, 0x28, 0xf5, 0x8d, 0x29, 0x95, 0xa5, 0xd6, 0x96, - 0x52, 0x19, 0xeb, 0x4c, 0x32, 0x19, 0xea, 0xec, 0xf1, 0x2a, 0x42, 0x8c, 0xac, 0x2b, 0xa1, 0x2b, - 0xc1, 0xee, 0x02, 0xb3, 0x8f, 0xcb, 0xe3, 0x8f, 0x2a, 0xe4, 0xa3, 0x42, 0x3b, 0x22, 0xa2, 0x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, 0xf6, 0xc9, 0xe4, 0xe5, - 0xc2, 0x7e, 0xcf, 0x07, 0x27, 0x13, 0x3e, 0x58, 0x8f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x53, - 0x29, 0x66, 0x64, 0x6a, 0x05, 0x00, 0x00, + // 739 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcf, 0x4f, 0xdb, 0x48, + 0x14, 0x8e, 0x09, 0x04, 0x32, 0xfc, 0x94, 0xc9, 0x2e, 0x4e, 0xd8, 0x35, 0x28, 0x20, 0x94, 0x45, + 0x10, 0x6f, 0x58, 0xb6, 0x12, 0x70, 0x22, 0x41, 0x48, 0x3d, 0xa4, 0xaa, 0x1c, 0x7a, 0xe1, 0x12, + 0x8d, 0xed, 0xc1, 0x19, 0x05, 0xcf, 0x58, 0x9e, 0x09, 0x25, 0x9c, 0xaa, 0xde, 0x7a, 0xeb, 0xb5, + 0x52, 0xa5, 0xfe, 0x0b, 0x1c, 0x7a, 0xee, 0x99, 0x23, 0xea, 0xa9, 0xa7, 0xaa, 0x85, 0x03, 0xd7, + 0xfe, 0x09, 0x95, 0xc7, 0x76, 0xe2, 0xa4, 0xaa, 0x51, 0xe9, 0xc9, 0x33, 0xfe, 0xbe, 0x6f, 0xde, + 0x7b, 0xdf, 0x7b, 0xf6, 0x80, 0x55, 0x03, 0x1a, 0xdd, 0x53, 0x4a, 0x4e, 0xa1, 0xc1, 0xb4, 0x70, + 0xad, 0x9d, 0x55, 0x0c, 0xc4, 0x61, 0x45, 0xe3, 0xe7, 0x65, 0xd7, 0xa3, 0x9c, 0xca, 0x8b, 0x31, + 0x56, 0x39, 0x5c, 0x97, 0x43, 0x56, 0x21, 0x67, 0x53, 0x9b, 0x0a, 0x9e, 0xe6, 0xaf, 0x02, 0x49, + 0x61, 0xc1, 0xa4, 0xcc, 0xa1, 0x4c, 0x73, 0x98, 0x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2, + 0xcf, 0xa9, 0xd7, 0x16, 0x3e, 0x65, 0xf5, 0x68, 0x2b, 0x2f, 0x81, 0xc9, 0xc8, 0x4f, 0x0e, 0x6d, + 0xe1, 0x46, 0x56, 0x07, 0xe1, 0xab, 0x23, 0x68, 0xcb, 0xdb, 0xc0, 0xf7, 0xc6, 0x2f, 0xfc, 0x04, + 0x7b, 0x0e, 0xe4, 0x98, 0x92, 0xa6, 0x85, 0x5c, 0xde, 0x12, 0xd5, 0x4f, 0xeb, 0x39, 0x83, 0x9b, + 0xb5, 0x18, 0x78, 0xe0, 0x63, 0xf2, 0x21, 0x58, 0x32, 0x5b, 0xc8, 0x6c, 0xbb, 0x14, 0x13, 0x1e, + 0xda, 0x77, 0x11, 0x88, 0x39, 0x76, 0x10, 0xed, 0x70, 0x65, 0x4c, 0xc8, 0xff, 0xee, 0xd3, 0x0e, + 0x63, 0xac, 0xa3, 0x80, 0x24, 0x6f, 0x00, 0x99, 0x50, 0x8e, 0x4f, 0x7c, 0xe7, 0xc5, 0x40, 0x5e, + 0x50, 0x82, 0x94, 0xcc, 0xb2, 0x54, 0x9a, 0xd0, 0xe7, 0x02, 0xa4, 0x26, 0x80, 0x63, 0x4a, 0x90, + 0xbc, 0x06, 0x66, 0xe3, 0x8d, 0x76, 0x98, 0xad, 0x8c, 0x8b, 0x16, 0x4d, 0xf7, 0xdb, 0x5b, 0x67, + 0xb6, 0x5c, 0x02, 0x73, 0x03, 0x5d, 0xf5, 0x89, 0x13, 0x82, 0x38, 0x13, 0xeb, 0xa5, 0xcf, 0x5c, + 0x01, 0xd3, 0x26, 0x25, 0xac, 0xe3, 0x20, 0xaf, 0x49, 0xa0, 0x83, 0x94, 0xac, 0x30, 0x68, 0x2a, + 0x7a, 0xf9, 0x04, 0x3a, 0x48, 0xae, 0x80, 0x5c, 0x8f, 0x64, 0x21, 0x66, 0x7a, 0xd8, 0xf5, 0x6b, + 0x50, 0x80, 0xe0, 0xce, 0x47, 0xd8, 0x41, 0x1f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0xd1, 0x62, + 0x41, 0x36, 0x31, 0x8d, 0xb6, 0x9b, 0xcc, 0x6a, 0x6b, 0xe7, 0xbd, 0x0b, 0x83, 0x77, 0x5d, 0xc4, + 0x8c, 0x8c, 0xb8, 0x27, 0xfe, 0xfb, 0x1e, 0x00, 0x00, 0xff, 0xff, 0x43, 0xc9, 0xb7, 0x23, 0xe1, + 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -591,10 +623,65 @@ func (m *MsgInstantiateBabylonContracts) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l - if len(m.InitMsg) > 0 { - i -= len(m.InitMsg) - copy(dAtA[i:], m.InitMsg) - i = encodeVarintTx(dAtA, i, uint64(len(m.InitMsg))) + if len(m.ConsumerDescription) > 0 { + i -= len(m.ConsumerDescription) + copy(dAtA[i:], m.ConsumerDescription) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConsumerDescription))) + i-- + dAtA[i] = 0x52 + } + if len(m.ConsumerName) > 0 { + i -= len(m.ConsumerName) + copy(dAtA[i:], m.ConsumerName) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConsumerName))) + i-- + dAtA[i] = 0x4a + } + if len(m.BtcFinalityMsg) > 0 { + i -= len(m.BtcFinalityMsg) + copy(dAtA[i:], m.BtcFinalityMsg) + i = encodeVarintTx(dAtA, i, uint64(len(m.BtcFinalityMsg))) + i-- + dAtA[i] = 0x42 + } + if len(m.BtcStakingMsg) > 0 { + i -= len(m.BtcStakingMsg) + copy(dAtA[i:], m.BtcStakingMsg) + i = encodeVarintTx(dAtA, i, uint64(len(m.BtcStakingMsg))) + i-- + dAtA[i] = 0x3a + } + if m.NotifyCosmosZone { + i-- + if m.NotifyCosmosZone { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x30 + } + if m.CheckpointFinalizationTimeout != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.CheckpointFinalizationTimeout)) + i-- + dAtA[i] = 0x28 + } + if m.BtcConfirmationDepth != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.BtcConfirmationDepth)) + i-- + dAtA[i] = 0x20 + } + if len(m.BabylonTag) > 0 { + i -= len(m.BabylonTag) + copy(dAtA[i:], m.BabylonTag) + i = encodeVarintTx(dAtA, i, uint64(len(m.BabylonTag))) + i-- + dAtA[i] = 0x1a + } + if len(m.Network) > 0 { + i -= len(m.Network) + copy(dAtA[i:], m.Network) + i = encodeVarintTx(dAtA, i, uint64(len(m.Network))) i-- dAtA[i] = 0x12 } @@ -749,7 +836,36 @@ func (m *MsgInstantiateBabylonContracts) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.InitMsg) + l = len(m.Network) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BabylonTag) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.BtcConfirmationDepth != 0 { + n += 1 + sovTx(uint64(m.BtcConfirmationDepth)) + } + if m.CheckpointFinalizationTimeout != 0 { + n += 1 + sovTx(uint64(m.CheckpointFinalizationTimeout)) + } + if m.NotifyCosmosZone { + n += 2 + } + l = len(m.BtcStakingMsg) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BtcFinalityMsg) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ConsumerName) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ConsumerDescription) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -1092,7 +1208,129 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InitMsg", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Network", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Network = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BabylonTag", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BabylonTag = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcConfirmationDepth", wireType) + } + m.BtcConfirmationDepth = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BtcConfirmationDepth |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CheckpointFinalizationTimeout", wireType) + } + m.CheckpointFinalizationTimeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CheckpointFinalizationTimeout |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NotifyCosmosZone", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.NotifyCosmosZone = bool(v != 0) + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingMsg", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1119,10 +1357,108 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.InitMsg = append(m.InitMsg[:0], dAtA[iNdEx:postIndex]...) - if m.InitMsg == nil { - m.InitMsg = []byte{} + m.BtcStakingMsg = append(m.BtcStakingMsg[:0], dAtA[iNdEx:postIndex]...) + if m.BtcStakingMsg == nil { + m.BtcStakingMsg = []byte{} + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityMsg", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BtcFinalityMsg = append(m.BtcFinalityMsg[:0], dAtA[iNdEx:postIndex]...) + if m.BtcFinalityMsg == nil { + m.BtcFinalityMsg = []byte{} + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsumerName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsumerName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsumerDescription", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF } + m.ConsumerDescription = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex From 7ba5c63bef0e1d232e632b0df7ef2e6427e6eac4 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Tue, 3 Dec 2024 16:59:13 +1100 Subject: [PATCH 4/7] e2e --- docs/proto/proto-docs.md | 37 +- proto/babylonlabs/babylon/v1beta1/tx.proto | 54 +- tests/e2e/test_client.go | 51 +- x/babylon/keeper/keeper_test.go | 28 +- x/babylon/keeper/msg_server.go | 37 +- x/babylon/keeper/msg_server_test.go | 62 +- x/babylon/keeper/wasm.go | 56 +- x/babylon/types/babylon.go | 11 +- x/babylon/types/codec.go | 2 - x/babylon/types/params.go | 27 + x/babylon/types/tx.pb.go | 671 +++++---------------- x/babylon/types/types.go | 33 +- 12 files changed, 306 insertions(+), 763 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 776dafb..00ff66d 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -19,8 +19,6 @@ - [babylonlabs/babylon/v1beta1/tx.proto](#babylonlabs/babylon/v1beta1/tx.proto) - [MsgInstantiateBabylonContracts](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts) - [MsgInstantiateBabylonContractsResponse](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContractsResponse) - - [MsgStoreBabylonContractCodes](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodes) - - [MsgStoreBabylonContractCodesResponse](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodesResponse) - [MsgUpdateParams](#babylonlabs.babylon.v1beta1.MsgUpdateParams) - [MsgUpdateParamsResponse](#babylonlabs.babylon.v1beta1.MsgUpdateParamsResponse) @@ -168,6 +166,9 @@ type. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `signer` | [string](#string) | | signer is the address who submits the message. | +| `babylon_contract_code_id` | [uint64](#uint64) | | babylon_contract_code_id is the code ID for the Babylon contract. | +| `btc_staking_contract_code_id` | [uint64](#uint64) | | btc_staking_contract_code_id is the code ID for the BTC staking contract. | +| `btc_finality_contract_code_id` | [uint64](#uint64) | | btc_finality_contract_code_id is the code ID for the BTC finality contract. | | `network` | [string](#string) | | network is the Bitcoin network to connect to (e.g. "regtest", "testnet", "mainnet") | | `babylon_tag` | [string](#string) | | babylon_tag is a unique identifier for this Babylon instance | | `btc_confirmation_depth` | [uint32](#uint32) | | btc_confirmation_depth is the number of confirmations required for Bitcoin transactions | @@ -177,6 +178,7 @@ type. | `btc_finality_msg` | [bytes](#bytes) | | btc_finality_msg is the initialization message for the BTC finality contract | | `consumer_name` | [string](#string) | | consumer_name is the name of this consumer chain | | `consumer_description` | [string](#string) | | consumer_description is a description of this consumer chain | +| `admin` | [string](#string) | | admin is the address that controls the Babylon module | @@ -194,36 +196,6 @@ response type. - - -### MsgStoreBabylonContractCodes -MsgStoreBabylonContractCodes is the Msg/StoreBabylonContractCodes request -type. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `signer` | [string](#string) | | signer is the address who submits the message. | -| `babylon_contract_code` | [bytes](#bytes) | | babylon_contract_code is the bytecode for the Babylon contract. WASMByteCode can be raw or gzip compressed | -| `btc_staking_contract_code` | [bytes](#bytes) | | btc_staking_contract_code is the bytecode for the BTC staking contract. WASMByteCode can be raw or gzip compressed | -| `btc_finality_contract_code` | [bytes](#bytes) | | btc_finality_contract_code is the bytecode for the BTC finality contract. WASMByteCode can be raw or gzip compressed | - - - - - - - - -### MsgStoreBabylonContractCodesResponse -MsgStoreBabylonContractCodesResponse is the Msg/StoreBabylonContractCodes -response type. - - - - - - ### MsgUpdateParams @@ -266,7 +238,6 @@ Msg defines the wasm Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `StoreBabylonContractCodes` | [MsgStoreBabylonContractCodes](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodes) | [MsgStoreBabylonContractCodesResponse](#babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodesResponse) | StoreBabylonContractCodes defines an operation for storing the Babylon contract codes. | | | `InstantiateBabylonContracts` | [MsgInstantiateBabylonContracts](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts) | [MsgInstantiateBabylonContractsResponse](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContractsResponse) | InstantiateBabylonContracts defines an operation for instantiating the Babylon contracts. | | | `UpdateParams` | [MsgUpdateParams](#babylonlabs.babylon.v1beta1.MsgUpdateParams) | [MsgUpdateParamsResponse](#babylonlabs.babylon.v1beta1.MsgUpdateParamsResponse) | UpdateParams defines a (governance) operation for updating the x/auth module parameters. The authority defaults to the x/gov module account. | | diff --git a/proto/babylonlabs/babylon/v1beta1/tx.proto b/proto/babylonlabs/babylon/v1beta1/tx.proto index a6cc386..af2ca6d 100644 --- a/proto/babylonlabs/babylon/v1beta1/tx.proto +++ b/proto/babylonlabs/babylon/v1beta1/tx.proto @@ -13,11 +13,6 @@ option (gogoproto.goproto_getters_all) = false; service Msg { option (cosmos.msg.v1.service) = true; - // StoreBabylonContractCodes defines an operation for storing the Babylon - // contract codes. - rpc StoreBabylonContractCodes(MsgStoreBabylonContractCodes) - returns (MsgStoreBabylonContractCodesResponse); - // InstantiateBabylonContracts defines an operation for instantiating the // Babylon contracts. rpc InstantiateBabylonContracts(MsgInstantiateBabylonContracts) @@ -28,28 +23,6 @@ service Msg { rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } -// MsgStoreBabylonContractCodes is the Msg/StoreBabylonContractCodes request -// type. -message MsgStoreBabylonContractCodes { - option (cosmos.msg.v1.signer) = "signer"; - - // signer is the address who submits the message. - string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; - // babylon_contract_code is the bytecode for the Babylon contract. - // WASMByteCode can be raw or gzip compressed - bytes babylon_contract_code = 2; - // btc_staking_contract_code is the bytecode for the BTC staking contract. - // WASMByteCode can be raw or gzip compressed - bytes btc_staking_contract_code = 3; - // btc_finality_contract_code is the bytecode for the BTC finality contract. - // WASMByteCode can be raw or gzip compressed - bytes btc_finality_contract_code = 4; -} - -// MsgStoreBabylonContractCodesResponse is the Msg/StoreBabylonContractCodes -// response type. -message MsgStoreBabylonContractCodesResponse {} - // MsgInstantiateBabylonContracts is the Msg/InstantiateBabylonContracts request // type. message MsgInstantiateBabylonContracts { @@ -58,28 +31,37 @@ message MsgInstantiateBabylonContracts { // signer is the address who submits the message. string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // babylon_contract_code_id is the code ID for the Babylon contract. + uint64 babylon_contract_code_id = 2; + // btc_staking_contract_code_id is the code ID for the BTC staking contract. + uint64 btc_staking_contract_code_id = 3; + // btc_finality_contract_code_id is the code ID for the BTC finality contract. + uint64 btc_finality_contract_code_id = 4; + // network is the Bitcoin network to connect to (e.g. "regtest", "testnet", // "mainnet") - string network = 2; + string network = 5; // babylon_tag is a unique identifier for this Babylon instance - string babylon_tag = 3; + string babylon_tag = 6; // btc_confirmation_depth is the number of confirmations required for Bitcoin // transactions - uint32 btc_confirmation_depth = 4; + uint32 btc_confirmation_depth = 7; // checkpoint_finalization_timeout is the timeout in blocks for checkpoint // finalization - uint32 checkpoint_finalization_timeout = 5; + uint32 checkpoint_finalization_timeout = 8; // notify_cosmos_zone indicates whether to notify the Cosmos zone of events - bool notify_cosmos_zone = 6; + bool notify_cosmos_zone = 9; // btc_staking_msg is the initialization message for the BTC staking contract - bytes btc_staking_msg = 7; + bytes btc_staking_msg = 10; // btc_finality_msg is the initialization message for the BTC finality // contract - bytes btc_finality_msg = 8; + bytes btc_finality_msg = 11; // consumer_name is the name of this consumer chain - string consumer_name = 9; + string consumer_name = 12; // consumer_description is a description of this consumer chain - string consumer_description = 10; + string consumer_description = 13; + // admin is the address that controls the Babylon module + string admin = 14 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; } // MsgInstantiateBabylonContractsResponse is the Msg/InstantiateBabylonContracts diff --git a/tests/e2e/test_client.go b/tests/e2e/test_client.go index 087d644..d636af5 100644 --- a/tests/e2e/test_client.go +++ b/tests/e2e/test_client.go @@ -8,6 +8,7 @@ import ( "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/babylonlabs-io/babylon-sdk/demo/app" + "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" bbntypes "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -120,43 +121,39 @@ func (p *TestConsumerClient) BootstrapContracts() (*ConsumerContract, error) { if err != nil { return nil, err } - initMsg := map[string]interface{}{ - "network": "regtest", - "babylon_tag": "01020304", - "btc_confirmation_depth": 1, - "checkpoint_finalization_timeout": 2, - "notify_cosmos_zone": false, - "btc_staking_code_id": btcStakingContractWasmId, - "btc_staking_msg": btcStakingInitMsgBytes, - "consumer_name": "test-consumer", - "consumer_description": "test-consumer-description", - "btc_finality_code_id": btcFinalityContractWasmId, - "btc_finality_msg": btcFinalityInitMsgBytes, - "admin": p.GetSender().String(), + + // instantiate Babylon contract + msgInstantiate := types.MsgInstantiateBabylonContracts{ + Signer: p.GetSender().String(), + BabylonContractCodeId: babylonContractWasmId, + BtcStakingContractCodeId: btcStakingContractWasmId, + BtcFinalityContractCodeId: btcFinalityContractWasmId, + Network: "regtest", + BabylonTag: "01020304", + BtcConfirmationDepth: 1, + CheckpointFinalizationTimeout: 2, + NotifyCosmosZone: false, + BtcStakingMsg: btcStakingInitMsgBytes, + BtcFinalityMsg: btcFinalityInitMsgBytes, + ConsumerName: "test-consumer", + ConsumerDescription: "test-consumer-description", + Admin: p.GetSender().String(), } - initMsgBytes, err := json.Marshal(initMsg) + _, err = p.Chain.SendMsgs(&msgInstantiate) if err != nil { return nil, err } - babylonContractAddr := InstantiateContract(p.t, p.Chain, babylonContractWasmId, initMsgBytes) - res, err := p.Query(babylonContractAddr, Query{"config": {}}) + params := p.App.BabylonKeeper.GetParams(p.Chain.GetContext()) + babylonAddr, btcStakingAddr, btcFinalityAddr, err := params.GetContractAddresses() if err != nil { return nil, err } - btcStakingContractAddr, ok := res["btc_staking"] - if !ok { - return nil, fmt.Errorf("failed to instantiate BTC staking contract") - } - btcFinalityContractAddr, ok := res["btc_finality"] - if !ok { - return nil, fmt.Errorf("failed to instantiate BTC finality contract") - } r := ConsumerContract{ - Babylon: babylonContractAddr, - BTCStaking: sdk.MustAccAddressFromBech32(btcStakingContractAddr.(string)), - BTCFinality: sdk.MustAccAddressFromBech32(btcFinalityContractAddr.(string)), + Babylon: babylonAddr, + BTCStaking: btcStakingAddr, + BTCFinality: btcFinalityAddr, } p.Contracts = r return &r, nil diff --git a/x/babylon/keeper/keeper_test.go b/x/babylon/keeper/keeper_test.go index 52ea498..9f71474 100644 --- a/x/babylon/keeper/keeper_test.go +++ b/x/babylon/keeper/keeper_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "fmt" - "os" "testing" "time" @@ -16,7 +14,6 @@ import ( "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/CosmWasm/wasmd/x/wasm/ioutils" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -335,35 +332,16 @@ const ( BtcFinalityContractCodePath = TestDataPath + "/btc_finality.wasm" ) -func GetGZippedContractCode(path string) ([]byte, error) { - wasm, err := os.ReadFile(path) - if err != nil { - return nil, err - } - // gzip the wasm file - if ioutils.IsWasm(wasm) { - wasm, err = ioutils.GzipIt(wasm) - - if err != nil { - return nil, err - } - } else if !ioutils.IsGzip(wasm) { - return nil, fmt.Errorf("invalid input file. Use wasm binary or gzip") - } - - return wasm, nil -} - func GetGZippedContractCodes() ([]byte, []byte, []byte) { - babylonContractCode, err := GetGZippedContractCode(BabylonContractCodePath) + babylonContractCode, err := types.GetGZippedContractCode(BabylonContractCodePath) if err != nil { panic(err) } - btcStakingContractCode, err := GetGZippedContractCode(BtcStakingContractCodePath) + btcStakingContractCode, err := types.GetGZippedContractCode(BtcStakingContractCodePath) if err != nil { panic(err) } - btcFinalityContractCode, err := GetGZippedContractCode(BtcFinalityContractCodePath) + btcFinalityContractCode, err := types.GetGZippedContractCode(BtcFinalityContractCodePath) if err != nil { panic(err) } diff --git a/x/babylon/keeper/msg_server.go b/x/babylon/keeper/msg_server.go index 01cbee8..6b2d81f 100644 --- a/x/babylon/keeper/msg_server.go +++ b/x/babylon/keeper/msg_server.go @@ -20,33 +20,6 @@ func NewMsgServer(k *Keeper) *msgServer { return &msgServer{k: k} } -func (ms msgServer) StoreBabylonContractCodes(goCtx context.Context, req *types.MsgStoreBabylonContractCodes) (*types.MsgStoreBabylonContractCodesResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - params := ms.k.GetParams(ctx) - - // only the authority can override the contract codes - if params.IsCodeStored() && req.Signer != ms.k.authority { - return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "only authority can override stored codes; expected %s, got %s", ms.k.authority, req.Signer) - } - - // store the contract codes - babylonContractCodeID, btcStakingContractCodeID, btcFinalityContractCodeID, err := ms.k.StoreBabylonContractCodes(ctx, req.BabylonContractCode, req.BtcStakingContractCode, req.BtcFinalityContractCode) - if err != nil { - return nil, err - } - - // update params - params.BabylonContractCodeId = babylonContractCodeID - params.BtcStakingContractCodeId = btcStakingContractCodeID - params.BtcFinalityContractCodeId = btcFinalityContractCodeID - if err := ms.k.SetParams(ctx, params); err != nil { - panic(err) - } - - return &types.MsgStoreBabylonContractCodesResponse{}, nil -} - func (ms msgServer) InstantiateBabylonContracts(goCtx context.Context, req *types.MsgInstantiateBabylonContracts) (*types.MsgInstantiateBabylonContractsResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -59,29 +32,33 @@ func (ms msgServer) InstantiateBabylonContracts(goCtx context.Context, req *type // construct the init message initMsg, err := types.NewInitMsg( - ms.k.authority, - ¶ms, req.Network, req.BabylonTag, req.BtcConfirmationDepth, req.CheckpointFinalizationTimeout, req.NotifyCosmosZone, + req.BtcStakingContractCodeId, req.BtcStakingMsg, + req.BtcFinalityContractCodeId, req.BtcFinalityMsg, req.ConsumerName, req.ConsumerDescription, + req.Admin, ) if err != nil { return nil, err } // instantiate the contracts - babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, initMsg) + babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, req.BabylonContractCodeId, initMsg) if err != nil { return nil, err } // update params + params.BabylonContractCodeId = req.BabylonContractCodeId + params.BtcStakingContractCodeId = req.BtcStakingContractCodeId + params.BtcFinalityContractCodeId = req.BtcFinalityContractCodeId params.BabylonContractAddress = babylonContractAddr params.BtcStakingContractAddress = btcStakingContractAddr params.BtcFinalityContractAddress = btcFinalityContractAddr diff --git a/x/babylon/keeper/msg_server_test.go b/x/babylon/keeper/msg_server_test.go index 52b9400..f14faae 100644 --- a/x/babylon/keeper/msg_server_test.go +++ b/x/babylon/keeper/msg_server_test.go @@ -4,60 +4,36 @@ import ( "encoding/json" "testing" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" "github.com/stretchr/testify/require" ) -func TestStoreBabylonContractCodes(t *testing.T) { +// TODO: fix this test +func TestInstantiateBabylonContracts(t *testing.T) { keepers := NewTestKeepers(t) msgServer := keepers.BabylonMsgServer - - babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() + wasmMsgServer := keepers.WasmMsgServer // store Babylon contract codes - _, err := msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ - BabylonContractCode: babylonContractCode, - BtcStakingContractCode: btcStakingContractCode, - BtcFinalityContractCode: btcFinalityContractCode, + babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() + resp, err := wasmMsgServer.StoreCode(keepers.Ctx, &wasmtypes.MsgStoreCode{ + Sender: keepers.BabylonKeeper.GetAuthority(), + WASMByteCode: babylonContractCode, }) + babylonContractCodeID := resp.CodeID require.NoError(t, err) - - // ensure params are set - params := keepers.BabylonKeeper.GetParams(keepers.Ctx) - require.Positive(t, params.BabylonContractCodeId) - require.Positive(t, params.BtcStakingContractCodeId) - require.Positive(t, params.BtcFinalityContractCodeId) - - // ensure non-gov account cannot override - _, err = msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ - BabylonContractCode: babylonContractCode, - BtcStakingContractCode: btcStakingContractCode, - BtcFinalityContractCode: btcFinalityContractCode, - }) - require.Error(t, err) - - // gov can override - _, err = msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ - Signer: keepers.BabylonKeeper.GetAuthority(), - BabylonContractCode: babylonContractCode, - BtcStakingContractCode: btcStakingContractCode, - BtcFinalityContractCode: btcFinalityContractCode, + resp, err = wasmMsgServer.StoreCode(keepers.Ctx, &wasmtypes.MsgStoreCode{ + Sender: keepers.BabylonKeeper.GetAuthority(), + WASMByteCode: btcStakingContractCode, }) + btcStakingContractCodeID := resp.CodeID require.NoError(t, err) -} - -// TODO: fix this test -func TestInstantiateBabylonContracts(t *testing.T) { - keepers := NewTestKeepers(t) - msgServer := keepers.BabylonMsgServer - - // store Babylon contract codes - babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() - _, err := msgServer.StoreBabylonContractCodes(keepers.Ctx, &types.MsgStoreBabylonContractCodes{ - BabylonContractCode: babylonContractCode, - BtcStakingContractCode: btcStakingContractCode, - BtcFinalityContractCode: btcFinalityContractCode, + resp, err = wasmMsgServer.StoreCode(keepers.Ctx, &wasmtypes.MsgStoreCode{ + Sender: keepers.BabylonKeeper.GetAuthority(), + WASMByteCode: btcFinalityContractCode, }) + btcFinalityContractCodeID := resp.CodeID require.NoError(t, err) // BTC staking init message @@ -76,6 +52,9 @@ func TestInstantiateBabylonContracts(t *testing.T) { // instantiate Babylon contract _, err = msgServer.InstantiateBabylonContracts(keepers.Ctx, &types.MsgInstantiateBabylonContracts{ Network: "regtest", + BabylonContractCodeId: babylonContractCodeID, + BtcStakingContractCodeId: btcStakingContractCodeID, + BtcFinalityContractCodeId: btcFinalityContractCodeID, BabylonTag: "01020304", BtcConfirmationDepth: 1, CheckpointFinalizationTimeout: 2, @@ -84,6 +63,7 @@ func TestInstantiateBabylonContracts(t *testing.T) { BtcFinalityMsg: btcFinalityInitMsgBytes, ConsumerName: "test-consumer", ConsumerDescription: "test-consumer-description", + Admin: keepers.BabylonKeeper.GetAuthority(), }) require.NoError(t, err) } diff --git a/x/babylon/keeper/wasm.go b/x/babylon/keeper/wasm.go index 6b5aa0d..0bc4af1 100644 --- a/x/babylon/keeper/wasm.go +++ b/x/babylon/keeper/wasm.go @@ -8,60 +8,17 @@ import ( errorsmod "cosmossdk.io/errors" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/babylonlabs-io/babylon-sdk/x/babylon/contract" types "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" sdk "github.com/cosmos/cosmos-sdk/types" ) -// StoreBabylonContractCodes stores the Babylon contract codes -func (k Keeper) StoreBabylonContractCodes( +func (k Keeper) InstantiateBabylonContracts( ctx sdk.Context, - babylonContractCode []byte, - btcStakingContractCode []byte, - btcFinalityContractCode []byte, -) (uint64, uint64, uint64, error) { + babylonContractCodeId uint64, + initMsg []byte, +) (string, string, string, error) { contractKeeper := wasmkeeper.NewGovPermissionKeeper(k.wasm) - instantiateConfig := wasmtypes.AccessConfig{ - Permission: wasmtypes.AccessTypeAnyOfAddresses, - Addresses: []string{k.authority}, - } - - // gov address - govAddr, err := sdk.AccAddressFromBech32(k.authority) - if err != nil { - panic(err) - } - - // store Babylon contract - babylonContractCodeID, _, err := contractKeeper.Create(ctx, govAddr, babylonContractCode, &instantiateConfig) - if err != nil { - return 0, 0, 0, err - } - // store BTC staking contract - btcStakingContractCodeID, _, err := contractKeeper.Create(ctx, govAddr, btcStakingContractCode, &instantiateConfig) - if err != nil { - return 0, 0, 0, err - } - // store BTC finality contract - btcFinalityContractCodeID, _, err := contractKeeper.Create(ctx, govAddr, btcFinalityContractCode, &instantiateConfig) - if err != nil { - return 0, 0, 0, err - } - - return babylonContractCodeID, btcStakingContractCodeID, btcFinalityContractCodeID, nil -} - -func (k Keeper) InstantiateBabylonContracts(ctx sdk.Context, initMsg []byte) (string, string, string, error) { - contractKeeper := wasmkeeper.NewGovPermissionKeeper(k.wasm) - - // get params - params := k.GetParams(ctx) - - // check that the contract codes are stored - if !params.IsCodeStored() { - return "", "", "", types.ErrInvalid.Wrapf("Babylon contract code ID is not set") - } // gov address govAddr, err := sdk.AccAddressFromBech32(k.authority) @@ -70,13 +27,14 @@ func (k Keeper) InstantiateBabylonContracts(ctx sdk.Context, initMsg []byte) (st } // instantiate Babylon contract - babylonContractAddr, _, err := contractKeeper.Instantiate(ctx, params.BabylonContractCodeId, govAddr, govAddr, initMsg, "Babylon contract", nil) + babylonContractAddr, _, err := contractKeeper.Instantiate(ctx, babylonContractCodeId, govAddr, govAddr, initMsg, "Babylon contract", nil) if err != nil { return "", "", "", err } // get contract addresses - res, err := k.wasm.QuerySmart(ctx, babylonContractAddr, []byte(`"config":{}`)) + configQuery := []byte(`{"config":{}}`) + res, err := k.wasm.QuerySmart(ctx, babylonContractAddr, configQuery) if err != nil { return "", "", "", err } diff --git a/x/babylon/types/babylon.go b/x/babylon/types/babylon.go index bc83cd3..38de66f 100644 --- a/x/babylon/types/babylon.go +++ b/x/babylon/types/babylon.go @@ -24,17 +24,18 @@ type BabylonContractConfig struct { // NewInitMsg creates the init message for the Babylon contract func NewInitMsg( - govAccount string, - params *Params, network string, babylonTag string, btcConfirmationDepth uint32, checkpointFinalizationTimeout uint32, notifyCosmosZone bool, + btcStakingCodeId uint64, btcStakingInitMsgBytes []byte, + btcFinalityCodeId uint64, btcFinalityInitMsgBytes []byte, consumerName string, consumerDescription string, + admin string, ) ([]byte, error) { initMsg := map[string]interface{}{ "network": network, @@ -42,13 +43,13 @@ func NewInitMsg( "btc_confirmation_depth": btcConfirmationDepth, "checkpoint_finalization_timeout": checkpointFinalizationTimeout, "notify_cosmos_zone": notifyCosmosZone, - "btc_staking_code_id": params.BtcStakingContractCodeId, + "btc_staking_code_id": btcStakingCodeId, "btc_staking_msg": btcStakingInitMsgBytes, "consumer_name": consumerName, "consumer_description": consumerDescription, - "btc_finality_code_id": params.BtcFinalityContractCodeId, + "btc_finality_code_id": btcFinalityCodeId, "btc_finality_msg": btcFinalityInitMsgBytes, - "admin": govAccount, + "admin": admin, } initMsgBytes, err := json.Marshal(initMsg) if err != nil { diff --git a/x/babylon/types/codec.go b/x/babylon/types/codec.go index 63ef3c6..de5d811 100644 --- a/x/babylon/types/codec.go +++ b/x/babylon/types/codec.go @@ -10,7 +10,6 @@ import ( // RegisterLegacyAminoCodec register types with legacy amino func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgStoreBabylonContractCodes{}, "babylon/MsgStoreBabylonContractCodes", nil) cdc.RegisterConcrete(&MsgInstantiateBabylonContracts{}, "babylon/MsgInstantiateBabylonContracts", nil) cdc.RegisterConcrete(&MsgUpdateParams{}, "babylon/MsgUpdateParams", nil) } @@ -19,7 +18,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), - &MsgStoreBabylonContractCodes{}, &MsgInstantiateBabylonContracts{}, &MsgUpdateParams{}, ) diff --git a/x/babylon/types/params.go b/x/babylon/types/params.go index 51faf32..cf18a3c 100644 --- a/x/babylon/types/params.go +++ b/x/babylon/types/params.go @@ -1,5 +1,11 @@ package types +import ( + "errors" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + // DefaultParams returns default babylon parameters func DefaultParams(denom string) Params { return Params{ @@ -15,6 +21,27 @@ func (p Params) ValidateBasic() error { return nil } +func (p Params) GetContractAddresses() (sdk.AccAddress, sdk.AccAddress, sdk.AccAddress, error) { + if !p.IsCodeStored() { + return nil, nil, nil, errors.New("contracts are not instantiated") + } + + babylonAddr, err := sdk.AccAddressFromBech32(p.BabylonContractAddress) + if err != nil { + return nil, nil, nil, err + } + btcStakingAddr, err := sdk.AccAddressFromBech32(p.BtcStakingContractAddress) + if err != nil { + return nil, nil, nil, err + } + btcFinalityAddr, err := sdk.AccAddressFromBech32(p.BtcFinalityContractAddress) + if err != nil { + return nil, nil, nil, err + } + + return babylonAddr, btcStakingAddr, btcFinalityAddr, nil +} + func (p Params) IsCodeStored() bool { return p.BabylonContractCodeId != 0 && p.BtcStakingContractCodeId != 0 && diff --git a/x/babylon/types/tx.pb.go b/x/babylon/types/tx.pb.go index 8fd3627..a8507c5 100644 --- a/x/babylon/types/tx.pb.go +++ b/x/babylon/types/tx.pb.go @@ -30,127 +30,48 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgStoreBabylonContractCodes is the Msg/StoreBabylonContractCodes request -// type. -type MsgStoreBabylonContractCodes struct { - // signer is the address who submits the message. - Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` - // babylon_contract_code is the bytecode for the Babylon contract. - // WASMByteCode can be raw or gzip compressed - BabylonContractCode []byte `protobuf:"bytes,2,opt,name=babylon_contract_code,json=babylonContractCode,proto3" json:"babylon_contract_code,omitempty"` - // btc_staking_contract_code is the bytecode for the BTC staking contract. - // WASMByteCode can be raw or gzip compressed - BtcStakingContractCode []byte `protobuf:"bytes,3,opt,name=btc_staking_contract_code,json=btcStakingContractCode,proto3" json:"btc_staking_contract_code,omitempty"` - // btc_finality_contract_code is the bytecode for the BTC finality contract. - // WASMByteCode can be raw or gzip compressed - BtcFinalityContractCode []byte `protobuf:"bytes,4,opt,name=btc_finality_contract_code,json=btcFinalityContractCode,proto3" json:"btc_finality_contract_code,omitempty"` -} - -func (m *MsgStoreBabylonContractCodes) Reset() { *m = MsgStoreBabylonContractCodes{} } -func (m *MsgStoreBabylonContractCodes) String() string { return proto.CompactTextString(m) } -func (*MsgStoreBabylonContractCodes) ProtoMessage() {} -func (*MsgStoreBabylonContractCodes) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{0} -} -func (m *MsgStoreBabylonContractCodes) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgStoreBabylonContractCodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgStoreBabylonContractCodes.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgStoreBabylonContractCodes) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgStoreBabylonContractCodes.Merge(m, src) -} -func (m *MsgStoreBabylonContractCodes) XXX_Size() int { - return m.Size() -} -func (m *MsgStoreBabylonContractCodes) XXX_DiscardUnknown() { - xxx_messageInfo_MsgStoreBabylonContractCodes.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgStoreBabylonContractCodes proto.InternalMessageInfo - -// MsgStoreBabylonContractCodesResponse is the Msg/StoreBabylonContractCodes -// response type. -type MsgStoreBabylonContractCodesResponse struct { -} - -func (m *MsgStoreBabylonContractCodesResponse) Reset() { *m = MsgStoreBabylonContractCodesResponse{} } -func (m *MsgStoreBabylonContractCodesResponse) String() string { return proto.CompactTextString(m) } -func (*MsgStoreBabylonContractCodesResponse) ProtoMessage() {} -func (*MsgStoreBabylonContractCodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{1} -} -func (m *MsgStoreBabylonContractCodesResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgStoreBabylonContractCodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgStoreBabylonContractCodesResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgStoreBabylonContractCodesResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgStoreBabylonContractCodesResponse.Merge(m, src) -} -func (m *MsgStoreBabylonContractCodesResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgStoreBabylonContractCodesResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgStoreBabylonContractCodesResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgStoreBabylonContractCodesResponse proto.InternalMessageInfo - // MsgInstantiateBabylonContracts is the Msg/InstantiateBabylonContracts request // type. type MsgInstantiateBabylonContracts struct { // signer is the address who submits the message. Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + // babylon_contract_code_id is the code ID for the Babylon contract. + BabylonContractCodeId uint64 `protobuf:"varint,2,opt,name=babylon_contract_code_id,json=babylonContractCodeId,proto3" json:"babylon_contract_code_id,omitempty"` + // btc_staking_contract_code_id is the code ID for the BTC staking contract. + BtcStakingContractCodeId uint64 `protobuf:"varint,3,opt,name=btc_staking_contract_code_id,json=btcStakingContractCodeId,proto3" json:"btc_staking_contract_code_id,omitempty"` + // btc_finality_contract_code_id is the code ID for the BTC finality contract. + BtcFinalityContractCodeId uint64 `protobuf:"varint,4,opt,name=btc_finality_contract_code_id,json=btcFinalityContractCodeId,proto3" json:"btc_finality_contract_code_id,omitempty"` // network is the Bitcoin network to connect to (e.g. "regtest", "testnet", // "mainnet") - Network string `protobuf:"bytes,2,opt,name=network,proto3" json:"network,omitempty"` + Network string `protobuf:"bytes,5,opt,name=network,proto3" json:"network,omitempty"` // babylon_tag is a unique identifier for this Babylon instance - BabylonTag string `protobuf:"bytes,3,opt,name=babylon_tag,json=babylonTag,proto3" json:"babylon_tag,omitempty"` + BabylonTag string `protobuf:"bytes,6,opt,name=babylon_tag,json=babylonTag,proto3" json:"babylon_tag,omitempty"` // btc_confirmation_depth is the number of confirmations required for Bitcoin // transactions - BtcConfirmationDepth uint32 `protobuf:"varint,4,opt,name=btc_confirmation_depth,json=btcConfirmationDepth,proto3" json:"btc_confirmation_depth,omitempty"` + BtcConfirmationDepth uint32 `protobuf:"varint,7,opt,name=btc_confirmation_depth,json=btcConfirmationDepth,proto3" json:"btc_confirmation_depth,omitempty"` // checkpoint_finalization_timeout is the timeout in blocks for checkpoint // finalization - CheckpointFinalizationTimeout uint32 `protobuf:"varint,5,opt,name=checkpoint_finalization_timeout,json=checkpointFinalizationTimeout,proto3" json:"checkpoint_finalization_timeout,omitempty"` + CheckpointFinalizationTimeout uint32 `protobuf:"varint,8,opt,name=checkpoint_finalization_timeout,json=checkpointFinalizationTimeout,proto3" json:"checkpoint_finalization_timeout,omitempty"` // notify_cosmos_zone indicates whether to notify the Cosmos zone of events - NotifyCosmosZone bool `protobuf:"varint,6,opt,name=notify_cosmos_zone,json=notifyCosmosZone,proto3" json:"notify_cosmos_zone,omitempty"` + NotifyCosmosZone bool `protobuf:"varint,9,opt,name=notify_cosmos_zone,json=notifyCosmosZone,proto3" json:"notify_cosmos_zone,omitempty"` // btc_staking_msg is the initialization message for the BTC staking contract - BtcStakingMsg []byte `protobuf:"bytes,7,opt,name=btc_staking_msg,json=btcStakingMsg,proto3" json:"btc_staking_msg,omitempty"` + BtcStakingMsg []byte `protobuf:"bytes,10,opt,name=btc_staking_msg,json=btcStakingMsg,proto3" json:"btc_staking_msg,omitempty"` // btc_finality_msg is the initialization message for the BTC finality // contract - BtcFinalityMsg []byte `protobuf:"bytes,8,opt,name=btc_finality_msg,json=btcFinalityMsg,proto3" json:"btc_finality_msg,omitempty"` + BtcFinalityMsg []byte `protobuf:"bytes,11,opt,name=btc_finality_msg,json=btcFinalityMsg,proto3" json:"btc_finality_msg,omitempty"` // consumer_name is the name of this consumer chain - ConsumerName string `protobuf:"bytes,9,opt,name=consumer_name,json=consumerName,proto3" json:"consumer_name,omitempty"` + ConsumerName string `protobuf:"bytes,12,opt,name=consumer_name,json=consumerName,proto3" json:"consumer_name,omitempty"` // consumer_description is a description of this consumer chain - ConsumerDescription string `protobuf:"bytes,10,opt,name=consumer_description,json=consumerDescription,proto3" json:"consumer_description,omitempty"` + ConsumerDescription string `protobuf:"bytes,13,opt,name=consumer_description,json=consumerDescription,proto3" json:"consumer_description,omitempty"` + // admin is the address that controls the Babylon module + Admin string `protobuf:"bytes,14,opt,name=admin,proto3" json:"admin,omitempty"` } func (m *MsgInstantiateBabylonContracts) Reset() { *m = MsgInstantiateBabylonContracts{} } func (m *MsgInstantiateBabylonContracts) String() string { return proto.CompactTextString(m) } func (*MsgInstantiateBabylonContracts) ProtoMessage() {} func (*MsgInstantiateBabylonContracts) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{2} + return fileDescriptor_406c9f025b2f9448, []int{0} } func (m *MsgInstantiateBabylonContracts) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -190,7 +111,7 @@ func (m *MsgInstantiateBabylonContractsResponse) Reset() { func (m *MsgInstantiateBabylonContractsResponse) String() string { return proto.CompactTextString(m) } func (*MsgInstantiateBabylonContractsResponse) ProtoMessage() {} func (*MsgInstantiateBabylonContractsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{3} + return fileDescriptor_406c9f025b2f9448, []int{1} } func (m *MsgInstantiateBabylonContractsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -234,7 +155,7 @@ func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParams) ProtoMessage() {} func (*MsgUpdateParams) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{4} + return fileDescriptor_406c9f025b2f9448, []int{2} } func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -272,7 +193,7 @@ func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParamsResponse) ProtoMessage() {} func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_406c9f025b2f9448, []int{5} + return fileDescriptor_406c9f025b2f9448, []int{3} } func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -302,8 +223,6 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgStoreBabylonContractCodes)(nil), "babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodes") - proto.RegisterType((*MsgStoreBabylonContractCodesResponse)(nil), "babylonlabs.babylon.v1beta1.MsgStoreBabylonContractCodesResponse") proto.RegisterType((*MsgInstantiateBabylonContracts)(nil), "babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts") proto.RegisterType((*MsgInstantiateBabylonContractsResponse)(nil), "babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContractsResponse") proto.RegisterType((*MsgUpdateParams)(nil), "babylonlabs.babylon.v1beta1.MsgUpdateParams") @@ -315,54 +234,52 @@ func init() { } var fileDescriptor_406c9f025b2f9448 = []byte{ - // 739 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcf, 0x4f, 0xdb, 0x48, - 0x14, 0x8e, 0x09, 0x04, 0x32, 0xfc, 0x94, 0xc9, 0x2e, 0x4e, 0xd8, 0x35, 0x28, 0x20, 0x94, 0x45, - 0x10, 0x6f, 0x58, 0xb6, 0x12, 0x70, 0x22, 0x41, 0x48, 0x3d, 0xa4, 0xaa, 0x1c, 0x7a, 0xe1, 0x12, - 0x8d, 0xed, 0xc1, 0x19, 0x05, 0xcf, 0x58, 0x9e, 0x09, 0x25, 0x9c, 0xaa, 0xde, 0x7a, 0xeb, 0xb5, - 0x52, 0xa5, 0xfe, 0x0b, 0x1c, 0x7a, 0xee, 0x99, 0x23, 0xea, 0xa9, 0xa7, 0xaa, 0x85, 0x03, 0xd7, - 0xfe, 0x09, 0x95, 0xc7, 0x76, 0xe2, 0xa4, 0xaa, 0x51, 0xe9, 0xc9, 0x33, 0xfe, 0xbe, 0x6f, 0xde, - 0x7b, 0xdf, 0x7b, 0xf6, 0x80, 0x55, 0x03, 0x1a, 0xdd, 0x53, 0x4a, 0x4e, 0xa1, 0xc1, 0xb4, 0x70, - 0xad, 0x9d, 0x55, 0x0c, 0xc4, 0x61, 0x45, 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 0xa9, 0xab, - 0x1b, 0x55, 0xba, 0xbe, 0x51, 0xa5, 0x2f, 0x37, 0xaa, 0xf4, 0xfa, 0x56, 0x4d, 0x5d, 0xdf, 0xaa, - 0xa9, 0x4f, 0xb7, 0x6a, 0xea, 0xf8, 0x7f, 0x1b, 0xf3, 0x56, 0xc7, 0x28, 0x9b, 0xd4, 0xd1, 0x62, - 0x41, 0x36, 0x31, 0x8d, 0xb6, 0x9b, 0xcc, 0x6a, 0x6b, 0xe7, 0xbd, 0x0b, 0x83, 0x77, 0x5d, 0xc4, - 0x8c, 0x8c, 0xb8, 0x27, 0xfe, 0xfb, 0x1e, 0x00, 0x00, 0xff, 0xff, 0x43, 0xc9, 0xb7, 0x23, 0xe1, - 0x06, 0x00, 0x00, + // 716 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x4f, 0x4b, 0x1b, 0x4d, + 0x1c, 0xc7, 0xb3, 0x6a, 0xa2, 0x4e, 0x12, 0x95, 0x79, 0xf2, 0x3c, 0x8e, 0xf1, 0x71, 0x0d, 0xb1, + 0x48, 0x2a, 0x9a, 0x6d, 0xac, 0x6d, 0xc1, 0x42, 0xa9, 0x89, 0x08, 0x1e, 0x2c, 0x65, 0xb5, 0x17, + 0x2f, 0x61, 0x76, 0x77, 0xdc, 0x0c, 0x71, 0x67, 0x96, 0x9d, 0x89, 0x35, 0x9e, 0x4a, 0x5f, 0x41, + 0x5f, 0x40, 0xa1, 0xd0, 0x57, 0xe0, 0xa1, 0x2f, 0xc2, 0xa3, 0xf4, 0x54, 0x28, 0x94, 0x56, 0x0f, + 0xbe, 0x8d, 0xb2, 0xbb, 0xb3, 0x26, 0x2a, 0x44, 0x4a, 0x4f, 0x99, 0xd9, 0xef, 0xe7, 0xfb, 0xfb, + 0x97, 0xdf, 0x2e, 0x78, 0x60, 0x61, 0xab, 0x7b, 0xc8, 0xd9, 0x21, 0xb6, 0x84, 0xa1, 0xce, 0xc6, + 0x51, 0xcd, 0x22, 0x12, 0xd7, 0x0c, 0x79, 0x5c, 0xf5, 0x03, 0x2e, 0x39, 0x9c, 0xed, 0xa3, 0xaa, + 0xea, 0x5c, 0x55, 0x54, 0xb1, 0xe0, 0x72, 0x97, 0x47, 0x9c, 0x11, 0x9e, 0x62, 0x4b, 0x71, 0xda, + 0xe6, 0xc2, 0xe3, 0xc2, 0xf0, 0x84, 0x6b, 0x1c, 0xd5, 0xc2, 0x1f, 0x25, 0xcc, 0xc4, 0x42, 0x33, + 0x76, 0xc4, 0x17, 0x25, 0x3d, 0x1c, 0x54, 0x4c, 0x92, 0x36, 0x42, 0xcb, 0xdf, 0xd3, 0x40, 0xdf, + 0x11, 0xee, 0x36, 0x13, 0x12, 0x33, 0x49, 0xb1, 0x24, 0xf5, 0x58, 0x6f, 0x70, 0x26, 0x03, 0x6c, + 0x4b, 0x01, 0x1f, 0x81, 0x8c, 0xa0, 0x2e, 0x23, 0x01, 0xd2, 0x4a, 0x5a, 0x65, 0xbc, 0x8e, 0xbe, + 0x7e, 0x59, 0x29, 0xa8, 0x7c, 0x1b, 0x8e, 0x13, 0x10, 0x21, 0x76, 0x65, 0x40, 0x99, 0x6b, 0x2a, + 0x0e, 0x3e, 0x03, 0x48, 0x65, 0x69, 0xda, 0x2a, 0x4c, 0xd3, 0xe6, 0x0e, 0x69, 0x52, 0x07, 0x0d, + 0x95, 0xb4, 0xca, 0x88, 0xf9, 0xaf, 0x75, 0x33, 0x4b, 0x83, 0x3b, 0x64, 0xdb, 0x81, 0x2f, 0xc0, + 0xff, 0x96, 0xb4, 0x9b, 0x42, 0xe2, 0x36, 0x65, 0xee, 0x5d, 0xf3, 0x70, 0x64, 0x46, 0x96, 0xb4, + 0x77, 0x63, 0xe4, 0x96, 0xff, 0x25, 0x98, 0x0b, 0xfd, 0x07, 0x94, 0xe1, 0x43, 0x2a, 0xbb, 0x77, + 0x03, 0x8c, 0x44, 0x01, 0x66, 0x2c, 0x69, 0x6f, 0x29, 0xe6, 0x56, 0x04, 0x04, 0x46, 0x19, 0x91, + 0x6f, 0x79, 0xd0, 0x46, 0xe9, 0xb0, 0x5b, 0x33, 0xb9, 0xc2, 0x79, 0x90, 0x4d, 0x9a, 0x92, 0xd8, + 0x45, 0x99, 0x48, 0x05, 0xea, 0xd1, 0x1e, 0x76, 0xe1, 0x1a, 0xf8, 0x2f, 0x4c, 0x6e, 0x73, 0x76, + 0x40, 0x03, 0x0f, 0x4b, 0xca, 0x59, 0xd3, 0x21, 0xbe, 0x6c, 0xa1, 0xd1, 0x92, 0x56, 0xc9, 0x9b, + 0x05, 0x4b, 0xda, 0x8d, 0x3e, 0x71, 0x33, 0xd4, 0xe0, 0x16, 0x98, 0xb7, 0x5b, 0xc4, 0x6e, 0xfb, + 0x9c, 0x32, 0xa9, 0x2a, 0x3f, 0x89, 0xcd, 0x92, 0x7a, 0x84, 0x77, 0x24, 0x1a, 0x8b, 0xec, 0x73, + 0x3d, 0x6c, 0xab, 0x8f, 0xda, 0x8b, 0x21, 0xb8, 0x0c, 0x20, 0xe3, 0x92, 0x1e, 0x84, 0x4d, 0x47, + 0x7b, 0x71, 0xc2, 0x19, 0x41, 0xe3, 0x25, 0xad, 0x32, 0x66, 0x4e, 0xc5, 0x4a, 0x23, 0x12, 0xf6, + 0x39, 0x23, 0x70, 0x11, 0x4c, 0xf6, 0x0f, 0xda, 0x13, 0x2e, 0x02, 0x25, 0xad, 0x92, 0x33, 0xf3, + 0xbd, 0xd9, 0xee, 0x08, 0x17, 0x56, 0xc0, 0xd4, 0x8d, 0x81, 0x86, 0x60, 0x36, 0x02, 0x27, 0xfa, + 0x66, 0x18, 0x92, 0x0b, 0x20, 0x6f, 0x73, 0x26, 0x3a, 0x1e, 0x09, 0x9a, 0x0c, 0x7b, 0x04, 0xe5, + 0xa2, 0x01, 0xe5, 0x92, 0x87, 0xaf, 0xb0, 0x47, 0x60, 0x0d, 0x14, 0xae, 0x21, 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xb8, 0xd4, 0x53, 0xe7, 0x97, 0x7a, 0xea, 0xdb, 0xa5, 0x9e, 0xda, 0x7f, 0xe2, + 0x52, 0xd9, 0xea, 0x58, 0x55, 0x9b, 0x7b, 0x46, 0x5f, 0x92, 0x15, 0xca, 0x93, 0xeb, 0x8a, 0x70, + 0xda, 0xc6, 0xf1, 0xf5, 0xb7, 0x54, 0x76, 0x7d, 0x22, 0xac, 0x4c, 0xf4, 0x09, 0x7d, 0xfc, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0x2b, 0x2a, 0x0c, 0x4d, 0xfc, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -377,9 +294,6 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - // StoreBabylonContractCodes defines an operation for storing the Babylon - // contract codes. - StoreBabylonContractCodes(ctx context.Context, in *MsgStoreBabylonContractCodes, opts ...grpc.CallOption) (*MsgStoreBabylonContractCodesResponse, error) // InstantiateBabylonContracts defines an operation for instantiating the // Babylon contracts. InstantiateBabylonContracts(ctx context.Context, in *MsgInstantiateBabylonContracts, opts ...grpc.CallOption) (*MsgInstantiateBabylonContractsResponse, error) @@ -396,15 +310,6 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) StoreBabylonContractCodes(ctx context.Context, in *MsgStoreBabylonContractCodes, opts ...grpc.CallOption) (*MsgStoreBabylonContractCodesResponse, error) { - out := new(MsgStoreBabylonContractCodesResponse) - err := c.cc.Invoke(ctx, "/babylonlabs.babylon.v1beta1.Msg/StoreBabylonContractCodes", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *msgClient) InstantiateBabylonContracts(ctx context.Context, in *MsgInstantiateBabylonContracts, opts ...grpc.CallOption) (*MsgInstantiateBabylonContractsResponse, error) { out := new(MsgInstantiateBabylonContractsResponse) err := c.cc.Invoke(ctx, "/babylonlabs.babylon.v1beta1.Msg/InstantiateBabylonContracts", in, out, opts...) @@ -425,9 +330,6 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts // MsgServer is the server API for Msg service. type MsgServer interface { - // StoreBabylonContractCodes defines an operation for storing the Babylon - // contract codes. - StoreBabylonContractCodes(context.Context, *MsgStoreBabylonContractCodes) (*MsgStoreBabylonContractCodesResponse, error) // InstantiateBabylonContracts defines an operation for instantiating the // Babylon contracts. InstantiateBabylonContracts(context.Context, *MsgInstantiateBabylonContracts) (*MsgInstantiateBabylonContractsResponse, error) @@ -440,9 +342,6 @@ type MsgServer interface { type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) StoreBabylonContractCodes(ctx context.Context, req *MsgStoreBabylonContractCodes) (*MsgStoreBabylonContractCodesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method StoreBabylonContractCodes not implemented") -} func (*UnimplementedMsgServer) InstantiateBabylonContracts(ctx context.Context, req *MsgInstantiateBabylonContracts) (*MsgInstantiateBabylonContractsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method InstantiateBabylonContracts not implemented") } @@ -454,24 +353,6 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_StoreBabylonContractCodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgStoreBabylonContractCodes) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).StoreBabylonContractCodes(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/babylonlabs.babylon.v1beta1.Msg/StoreBabylonContractCodes", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).StoreBabylonContractCodes(ctx, req.(*MsgStoreBabylonContractCodes)) - } - return interceptor(ctx, in, info, handler) -} - func _Msg_InstantiateBabylonContracts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgInstantiateBabylonContracts) if err := dec(in); err != nil { @@ -512,10 +393,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "babylonlabs.babylon.v1beta1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "StoreBabylonContractCodes", - Handler: _Msg_StoreBabylonContractCodes_Handler, - }, { MethodName: "InstantiateBabylonContracts", Handler: _Msg_InstantiateBabylonContracts_Handler, @@ -529,80 +406,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "babylonlabs/babylon/v1beta1/tx.proto", } -func (m *MsgStoreBabylonContractCodes) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgStoreBabylonContractCodes) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgStoreBabylonContractCodes) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.BtcFinalityContractCode) > 0 { - i -= len(m.BtcFinalityContractCode) - copy(dAtA[i:], m.BtcFinalityContractCode) - i = encodeVarintTx(dAtA, i, uint64(len(m.BtcFinalityContractCode))) - i-- - dAtA[i] = 0x22 - } - if len(m.BtcStakingContractCode) > 0 { - i -= len(m.BtcStakingContractCode) - copy(dAtA[i:], m.BtcStakingContractCode) - i = encodeVarintTx(dAtA, i, uint64(len(m.BtcStakingContractCode))) - i-- - dAtA[i] = 0x1a - } - if len(m.BabylonContractCode) > 0 { - i -= len(m.BabylonContractCode) - copy(dAtA[i:], m.BabylonContractCode) - i = encodeVarintTx(dAtA, i, uint64(len(m.BabylonContractCode))) - i-- - dAtA[i] = 0x12 - } - if len(m.Signer) > 0 { - i -= len(m.Signer) - copy(dAtA[i:], m.Signer) - i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgStoreBabylonContractCodesResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgStoreBabylonContractCodesResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgStoreBabylonContractCodesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func (m *MsgInstantiateBabylonContracts) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -623,33 +426,40 @@ func (m *MsgInstantiateBabylonContracts) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintTx(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0x72 + } if len(m.ConsumerDescription) > 0 { i -= len(m.ConsumerDescription) copy(dAtA[i:], m.ConsumerDescription) i = encodeVarintTx(dAtA, i, uint64(len(m.ConsumerDescription))) i-- - dAtA[i] = 0x52 + dAtA[i] = 0x6a } if len(m.ConsumerName) > 0 { i -= len(m.ConsumerName) copy(dAtA[i:], m.ConsumerName) i = encodeVarintTx(dAtA, i, uint64(len(m.ConsumerName))) i-- - dAtA[i] = 0x4a + dAtA[i] = 0x62 } if len(m.BtcFinalityMsg) > 0 { i -= len(m.BtcFinalityMsg) copy(dAtA[i:], m.BtcFinalityMsg) i = encodeVarintTx(dAtA, i, uint64(len(m.BtcFinalityMsg))) i-- - dAtA[i] = 0x42 + dAtA[i] = 0x5a } if len(m.BtcStakingMsg) > 0 { i -= len(m.BtcStakingMsg) copy(dAtA[i:], m.BtcStakingMsg) i = encodeVarintTx(dAtA, i, uint64(len(m.BtcStakingMsg))) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x52 } if m.NotifyCosmosZone { i-- @@ -659,31 +469,46 @@ func (m *MsgInstantiateBabylonContracts) MarshalToSizedBuffer(dAtA []byte) (int, dAtA[i] = 0 } i-- - dAtA[i] = 0x30 + dAtA[i] = 0x48 } if m.CheckpointFinalizationTimeout != 0 { i = encodeVarintTx(dAtA, i, uint64(m.CheckpointFinalizationTimeout)) i-- - dAtA[i] = 0x28 + dAtA[i] = 0x40 } if m.BtcConfirmationDepth != 0 { i = encodeVarintTx(dAtA, i, uint64(m.BtcConfirmationDepth)) i-- - dAtA[i] = 0x20 + dAtA[i] = 0x38 } if len(m.BabylonTag) > 0 { i -= len(m.BabylonTag) copy(dAtA[i:], m.BabylonTag) i = encodeVarintTx(dAtA, i, uint64(len(m.BabylonTag))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x32 } if len(m.Network) > 0 { i -= len(m.Network) copy(dAtA[i:], m.Network) i = encodeVarintTx(dAtA, i, uint64(len(m.Network))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x2a + } + if m.BtcFinalityContractCodeId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.BtcFinalityContractCodeId)) + i-- + dAtA[i] = 0x20 + } + if m.BtcStakingContractCodeId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.BtcStakingContractCodeId)) + i-- + dAtA[i] = 0x18 + } + if m.BabylonContractCodeId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.BabylonContractCodeId)) + i-- + dAtA[i] = 0x10 } if len(m.Signer) > 0 { i -= len(m.Signer) @@ -792,7 +617,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgStoreBabylonContractCodes) Size() (n int) { +func (m *MsgInstantiateBabylonContracts) Size() (n int) { if m == nil { return 0 } @@ -802,39 +627,14 @@ func (m *MsgStoreBabylonContractCodes) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.BabylonContractCode) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + if m.BabylonContractCodeId != 0 { + n += 1 + sovTx(uint64(m.BabylonContractCodeId)) } - l = len(m.BtcStakingContractCode) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + if m.BtcStakingContractCodeId != 0 { + n += 1 + sovTx(uint64(m.BtcStakingContractCodeId)) } - l = len(m.BtcFinalityContractCode) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgStoreBabylonContractCodesResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *MsgInstantiateBabylonContracts) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Signer) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + if m.BtcFinalityContractCodeId != 0 { + n += 1 + sovTx(uint64(m.BtcFinalityContractCodeId)) } l = len(m.Network) if l > 0 { @@ -869,6 +669,10 @@ func (m *MsgInstantiateBabylonContracts) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -911,7 +715,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgStoreBabylonContractCodes) Unmarshal(dAtA []byte) error { +func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -934,10 +738,10 @@ func (m *MsgStoreBabylonContractCodes) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgStoreBabylonContractCodes: wiretype end group for non-group") + return fmt.Errorf("proto: MsgInstantiateBabylonContracts: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgStoreBabylonContractCodes: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgInstantiateBabylonContracts: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -973,10 +777,10 @@ func (m *MsgStoreBabylonContractCodes) Unmarshal(dAtA []byte) error { m.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BabylonContractCode", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BabylonContractCodeId", wireType) } - var byteLen int + m.BabylonContractCodeId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -986,31 +790,16 @@ func (m *MsgStoreBabylonContractCodes) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + m.BabylonContractCodeId |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BabylonContractCode = append(m.BabylonContractCode[:0], dAtA[iNdEx:postIndex]...) - if m.BabylonContractCode == nil { - m.BabylonContractCode = []byte{} - } - iNdEx = postIndex case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingContractCode", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingContractCodeId", wireType) } - var byteLen int + m.BtcStakingContractCodeId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1020,165 +809,16 @@ func (m *MsgStoreBabylonContractCodes) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + m.BtcStakingContractCodeId |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BtcStakingContractCode = append(m.BtcStakingContractCode[:0], dAtA[iNdEx:postIndex]...) - if m.BtcStakingContractCode == nil { - m.BtcStakingContractCode = []byte{} - } - iNdEx = postIndex case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityContractCode", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BtcFinalityContractCode = append(m.BtcFinalityContractCode[:0], dAtA[iNdEx:postIndex]...) - if m.BtcFinalityContractCode == nil { - m.BtcFinalityContractCode = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgStoreBabylonContractCodesResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgStoreBabylonContractCodesResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgStoreBabylonContractCodesResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgInstantiateBabylonContracts: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgInstantiateBabylonContracts: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityContractCodeId", wireType) } - var stringLen uint64 + m.BtcFinalityContractCodeId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1188,25 +828,12 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + m.BtcFinalityContractCodeId |= uint64(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signer = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Network", wireType) } @@ -1238,7 +865,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { } m.Network = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BabylonTag", wireType) } @@ -1270,7 +897,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { } m.BabylonTag = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 7: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field BtcConfirmationDepth", wireType) } @@ -1289,7 +916,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { break } } - case 5: + case 8: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field CheckpointFinalizationTimeout", wireType) } @@ -1308,7 +935,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { break } } - case 6: + case 9: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field NotifyCosmosZone", wireType) } @@ -1328,7 +955,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { } } m.NotifyCosmosZone = bool(v != 0) - case 7: + case 10: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BtcStakingMsg", wireType) } @@ -1362,7 +989,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { m.BtcStakingMsg = []byte{} } iNdEx = postIndex - case 8: + case 11: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BtcFinalityMsg", wireType) } @@ -1396,7 +1023,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { m.BtcFinalityMsg = []byte{} } iNdEx = postIndex - case 9: + case 12: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ConsumerName", wireType) } @@ -1428,7 +1055,7 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { } m.ConsumerName = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 10: + case 13: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ConsumerDescription", wireType) } @@ -1460,6 +1087,38 @@ func (m *MsgInstantiateBabylonContracts) Unmarshal(dAtA []byte) error { } m.ConsumerDescription = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 14: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/babylon/types/types.go b/x/babylon/types/types.go index f829d46..18723b4 100644 --- a/x/babylon/types/types.go +++ b/x/babylon/types/types.go @@ -1,12 +1,27 @@ package types -type SchedulerTaskType byte - -const ( - // SchedulerTaskUndefined null value - SchedulerTaskUndefined SchedulerTaskType = 0 - // SchedulerTaskHandleEpoch triggered by updates to the virtual staking max cap or by end of epoch - SchedulerTaskHandleEpoch = 1 - // SchedulerTaskValsetUpdate triggered by any update on the active set. This includes add, remove, validator modifications, slashing, tombstone - SchedulerTaskValsetUpdate = 2 +import ( + fmt "fmt" + "os" + + "github.com/CosmWasm/wasmd/x/wasm/ioutils" ) + +func GetGZippedContractCode(path string) ([]byte, error) { + wasm, err := os.ReadFile(path) + if err != nil { + return nil, err + } + // gzip the wasm file + if ioutils.IsWasm(wasm) { + wasm, err = ioutils.GzipIt(wasm) + + if err != nil { + return nil, err + } + } else if !ioutils.IsGzip(wasm) { + return nil, fmt.Errorf("invalid input file. Use wasm binary or gzip") + } + + return wasm, nil +} From a8fcc34ddbed1aea0c97c489e2752b317b0f8bc8 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Wed, 4 Dec 2024 15:21:44 +1100 Subject: [PATCH 5/7] unit tests --- demo/app/app_test.go | 96 ++++++++++++++++++++++++++++- x/babylon/keeper/msg_server_test.go | 69 --------------------- 2 files changed, 94 insertions(+), 71 deletions(-) delete mode 100644 x/babylon/keeper/msg_server_test.go diff --git a/demo/app/app_test.go b/demo/app/app_test.go index 7c8f4b1..58a4ddb 100644 --- a/demo/app/app_test.go +++ b/demo/app/app_test.go @@ -1,17 +1,23 @@ package app import ( + "encoding/json" "fmt" "testing" + "time" "cosmossdk.io/log" "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + babylonkeeper "github.com/babylonlabs-io/babylon-sdk/x/babylon/keeper" + "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" abci "github.com/cometbft/cometbft/abci/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" - "github.com/stretchr/testify/require" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" ) var emptyWasmOpts []wasm.Option @@ -61,3 +67,89 @@ func TestGetMaccPerms(t *testing.T) { dup := GetMaccPerms() require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions") } + +const ( + TestDataPath = "../../tests/testdata" + BabylonContractCodePath = TestDataPath + "/babylon_contract.wasm" + BtcStakingContractCodePath = TestDataPath + "/btc_staking.wasm" + BtcFinalityContractCodePath = TestDataPath + "/btc_finality.wasm" +) + +func GetGZippedContractCodes() ([]byte, []byte, []byte) { + babylonContractCode, err := types.GetGZippedContractCode(BabylonContractCodePath) + if err != nil { + panic(err) + } + btcStakingContractCode, err := types.GetGZippedContractCode(BtcStakingContractCodePath) + if err != nil { + panic(err) + } + btcFinalityContractCode, err := types.GetGZippedContractCode(BtcFinalityContractCodePath) + if err != nil { + panic(err) + } + + return babylonContractCode, btcStakingContractCode, btcFinalityContractCode +} + +func TestInstantiateBabylonContracts(t *testing.T) { + consumerApp := Setup(t) + ctx := consumerApp.NewContext(false) + ctx = ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + babylonKeeper := consumerApp.BabylonKeeper + babylonMsgServer := babylonkeeper.NewMsgServer(babylonKeeper) + wasmKeeper := consumerApp.WasmKeeper + wasmMsgServer := wasmkeeper.NewMsgServerImpl(&wasmKeeper) + + // store Babylon contract codes + babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() + resp, err := wasmMsgServer.StoreCode(ctx, &wasmtypes.MsgStoreCode{ + Sender: consumerApp.BabylonKeeper.GetAuthority(), + WASMByteCode: babylonContractCode, + }) + babylonContractCodeID := resp.CodeID + require.NoError(t, err) + resp, err = wasmMsgServer.StoreCode(ctx, &wasmtypes.MsgStoreCode{ + Sender: consumerApp.BabylonKeeper.GetAuthority(), + WASMByteCode: btcStakingContractCode, + }) + btcStakingContractCodeID := resp.CodeID + require.NoError(t, err) + resp, err = wasmMsgServer.StoreCode(ctx, &wasmtypes.MsgStoreCode{ + Sender: consumerApp.BabylonKeeper.GetAuthority(), + WASMByteCode: btcFinalityContractCode, + }) + btcFinalityContractCodeID := resp.CodeID + require.NoError(t, err) + + // BTC staking init message + btcStakingInitMsg := map[string]interface{}{ + "admin": consumerApp.BabylonKeeper.GetAuthority(), + } + btcStakingInitMsgBytes, err := json.Marshal(btcStakingInitMsg) + require.NoError(t, err) + // BTC finality init message + btcFinalityInitMsg := map[string]interface{}{ + "admin": consumerApp.BabylonKeeper.GetAuthority(), + } + btcFinalityInitMsgBytes, err := json.Marshal(btcFinalityInitMsg) + require.NoError(t, err) + + // instantiate Babylon contract + _, err = babylonMsgServer.InstantiateBabylonContracts(ctx, &types.MsgInstantiateBabylonContracts{ + Network: "regtest", + BabylonContractCodeId: babylonContractCodeID, + BtcStakingContractCodeId: btcStakingContractCodeID, + BtcFinalityContractCodeId: btcFinalityContractCodeID, + BabylonTag: "01020304", + BtcConfirmationDepth: 1, + CheckpointFinalizationTimeout: 2, + NotifyCosmosZone: false, + BtcStakingMsg: btcStakingInitMsgBytes, + BtcFinalityMsg: btcFinalityInitMsgBytes, + ConsumerName: "test-consumer", + ConsumerDescription: "test-consumer-description", + Admin: babylonKeeper.GetAuthority(), + }) + require.NoError(t, err) +} diff --git a/x/babylon/keeper/msg_server_test.go b/x/babylon/keeper/msg_server_test.go deleted file mode 100644 index f14faae..0000000 --- a/x/babylon/keeper/msg_server_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package keeper_test - -import ( - "encoding/json" - "testing" - - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" - "github.com/stretchr/testify/require" -) - -// TODO: fix this test -func TestInstantiateBabylonContracts(t *testing.T) { - keepers := NewTestKeepers(t) - msgServer := keepers.BabylonMsgServer - wasmMsgServer := keepers.WasmMsgServer - - // store Babylon contract codes - babylonContractCode, btcStakingContractCode, btcFinalityContractCode := GetGZippedContractCodes() - resp, err := wasmMsgServer.StoreCode(keepers.Ctx, &wasmtypes.MsgStoreCode{ - Sender: keepers.BabylonKeeper.GetAuthority(), - WASMByteCode: babylonContractCode, - }) - babylonContractCodeID := resp.CodeID - require.NoError(t, err) - resp, err = wasmMsgServer.StoreCode(keepers.Ctx, &wasmtypes.MsgStoreCode{ - Sender: keepers.BabylonKeeper.GetAuthority(), - WASMByteCode: btcStakingContractCode, - }) - btcStakingContractCodeID := resp.CodeID - require.NoError(t, err) - resp, err = wasmMsgServer.StoreCode(keepers.Ctx, &wasmtypes.MsgStoreCode{ - Sender: keepers.BabylonKeeper.GetAuthority(), - WASMByteCode: btcFinalityContractCode, - }) - btcFinalityContractCodeID := resp.CodeID - require.NoError(t, err) - - // BTC staking init message - btcStakingInitMsg := map[string]interface{}{ - "admin": keepers.BabylonKeeper.GetAuthority(), - } - btcStakingInitMsgBytes, err := json.Marshal(btcStakingInitMsg) - require.NoError(t, err) - // BTC finality init message - btcFinalityInitMsg := map[string]interface{}{ - "admin": keepers.BabylonKeeper.GetAuthority(), - } - btcFinalityInitMsgBytes, err := json.Marshal(btcFinalityInitMsg) - require.NoError(t, err) - - // instantiate Babylon contract - _, err = msgServer.InstantiateBabylonContracts(keepers.Ctx, &types.MsgInstantiateBabylonContracts{ - Network: "regtest", - BabylonContractCodeId: babylonContractCodeID, - BtcStakingContractCodeId: btcStakingContractCodeID, - BtcFinalityContractCodeId: btcFinalityContractCodeID, - BabylonTag: "01020304", - BtcConfirmationDepth: 1, - CheckpointFinalizationTimeout: 2, - NotifyCosmosZone: false, - BtcStakingMsg: btcStakingInitMsgBytes, - BtcFinalityMsg: btcFinalityInitMsgBytes, - ConsumerName: "test-consumer", - ConsumerDescription: "test-consumer-description", - Admin: keepers.BabylonKeeper.GetAuthority(), - }) - require.NoError(t, err) -} From d2008ce683277daadf2d764f7e908b1a13bd979d Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Wed, 4 Dec 2024 15:34:19 +1100 Subject: [PATCH 6/7] cli --- x/babylon/client/cli/tx.go | 97 +++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/x/babylon/client/cli/tx.go b/x/babylon/client/cli/tx.go index 78d50c2..50a542f 100644 --- a/x/babylon/client/cli/tx.go +++ b/x/babylon/client/cli/tx.go @@ -1,9 +1,13 @@ package cli import ( - "github.com/spf13/cobra" + "encoding/hex" + "strconv" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" ) @@ -20,6 +24,95 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, SilenceUsage: true, } - txCmd.AddCommand() + txCmd.AddCommand( + NewInstantiateBabylonContractsCmd(), + ) return txCmd } + +// [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-hex] [btc-finality-init-msg-hex] [consumer-name] [consumer-description] [admin] +func parseInstantiateArgs(args []string, sender string) (*types.MsgInstantiateBabylonContracts, error) { + // get the id of the code to instantiate + babylonContractCodeID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return nil, err + } + btcStakingContractCodeID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return nil, err + } + btcFinalityContractCodeID, err := strconv.ParseUint(args[2], 10, 64) + if err != nil { + return nil, err + } + + btcNetwork := args[3] + babylonTag := args[4] + btcConfirmationDepth, err := strconv.ParseUint(args[5], 10, 32) + if err != nil { + return nil, err + } + checkpointFinalizationTimeout, err := strconv.ParseUint(args[6], 10, 32) + if err != nil { + return nil, err + } + notifyCosmosZone, err := strconv.ParseBool(args[7]) + if err != nil { + return nil, err + } + btcStakingInitMsg, err := hex.DecodeString(args[8]) + if err != nil { + return nil, err + } + btcFinalityInitMsg, err := hex.DecodeString(args[9]) + if err != nil { + return nil, err + } + consumerName := args[10] + consumerDescription := args[11] + adminStr := args[12] + + // build and sign the transaction, then broadcast to Tendermint + msg := types.MsgInstantiateBabylonContracts{ + Signer: sender, + BabylonContractCodeId: babylonContractCodeID, + BtcStakingContractCodeId: btcStakingContractCodeID, + BtcFinalityContractCodeId: btcFinalityContractCodeID, + Network: btcNetwork, + BabylonTag: babylonTag, + BtcConfirmationDepth: uint32(btcConfirmationDepth), + CheckpointFinalizationTimeout: uint32(checkpointFinalizationTimeout), + NotifyCosmosZone: notifyCosmosZone, + BtcStakingMsg: btcStakingInitMsg, + BtcFinalityMsg: btcFinalityInitMsg, + ConsumerName: consumerName, + ConsumerDescription: consumerDescription, + Admin: adminStr, + } + return &msg, nil +} + +func NewInstantiateBabylonContractsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "instantiate-babylon-contracts [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-hex] [btc-finality-init-msg-hex] [consumer-name] [consumer-description] [admin]", + Short: "Instantiate Babylon contracts", + Long: "Instantiate Babylon contracts", + Aliases: []string{"i"}, + Args: cobra.ExactArgs(11), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + msg, err := parseInstantiateArgs(args, clientCtx.GetFromAddress().String()) + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + SilenceUsage: true, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} From 8e147fca43e030f1134c638a9b82499ff7929b4a Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Wed, 4 Dec 2024 15:36:28 +1100 Subject: [PATCH 7/7] fix docker build ci --- .github/workflows/ci.yml | 2 +- .github/workflows/publish.yml | 2 +- Makefile | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea84439..6bd40ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,5 +20,5 @@ jobs: secrets: inherit with: publish: false - dockerfile: ./Dockerfile + dockerfile: ./contrib/images/local-bcd/Dockerfile repoName: babylon-sdk \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1e10a37..0905b11 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,5 +23,5 @@ jobs: secrets: inherit with: publish: true - dockerfile: ./Dockerfile + dockerfile: ./contrib/images/local-bcd/Dockerfile repoName: babylon-sdk \ No newline at end of file diff --git a/Makefile b/Makefile index 1851306..f7b1cf5 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,7 @@ build-linux-static: $(MAKE) -C demo build-linux-static build-docker: - $(DOCKER) build --tag babylonlabs-io/bcd -f contrib/images/bcd/Dockerfile . - -# A local bcd image with users and funds for testing / development / integration purposes -build-bcd: - $(DOCKER) build --tag babylonlabs-io/local-bcd -f contrib/images/local-bcd/Dockerfile . + $(DOCKER) build --tag babylonlabs-io/bcd -f contrib/images/local-bcd/Dockerfile . ######################################## ### Testing