From 3062f2b201f2c0f3c5393385491eda39a4373f0e Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 24 May 2024 09:33:29 +0800 Subject: [PATCH] completed mint --- app/app.go | 7 +- app/keepers/keepers.go | 1 + cmd/sided/cmd/config.go | 12 +- go.mod | 6 +- go.sum | 2 - local_node.sh | 16 +- proto/side/btclightclient/params.proto | 2 + proto/side/btclightclient/tx.proto | 9 +- testutil/keeper/btc_light_client.go | 6 +- x/btclightclient/client/cli/query.go | 6 +- x/btclightclient/keeper/keeper.go | 122 +++++++++-- x/btclightclient/keeper/msg_server.go | 6 +- x/btclightclient/types/codec.go | 6 +- x/btclightclient/types/errors.go | 2 + x/btclightclient/types/expected_keepers.go | 20 ++ x/btclightclient/types/keys.go | 3 + x/btclightclient/types/merkle_proof.go | 39 ++++ .../types/message_submit_transaction.go | 20 +- x/btclightclient/types/params.pb.go | 111 +++++++--- x/btclightclient/types/tx.pb.go | 202 ++++++++++++++---- 20 files changed, 477 insertions(+), 121 deletions(-) create mode 100644 x/btclightclient/types/merkle_proof.go diff --git a/app/app.go b/app/app.go index d14095ce..59fecd38 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "github.com/btcsuite/btcd/chaincfg" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" @@ -85,8 +86,8 @@ import ( ) const ( - AccountAddressPrefix = "bc" - Name = "side" + // AccountAddressPrefix = "bc" + Name = "side" ) var Upgrades = []upgrades.Upgrade{v1.Upgrade, v2.Upgrade} @@ -102,6 +103,8 @@ var ( // and genesis verification. ModuleBasics = keepers.AppModuleBasics + BitcoinChainCfg = chaincfg.MainNetParams + // module account permissions ) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 44a73be6..4ed09599 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -397,6 +397,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appCodec, appKeepers.keys[btclightclienttypes.StoreKey], appKeepers.keys[btclightclienttypes.StoreKey], + appKeepers.BankKeeper, ) // The last arguments can contain custom message handlers, and custom query handlers, diff --git a/cmd/sided/cmd/config.go b/cmd/sided/cmd/config.go index aba94a3a..14f80879 100644 --- a/cmd/sided/cmd/config.go +++ b/cmd/sided/cmd/config.go @@ -8,15 +8,15 @@ import ( func initSDKConfig() { // Set prefixes - accountPubKeyPrefix := app.AccountAddressPrefix + "pub" - validatorAddressPrefix := app.AccountAddressPrefix + "valoper" - validatorPubKeyPrefix := app.AccountAddressPrefix + "valoperpub" - consNodeAddressPrefix := app.AccountAddressPrefix + "valcons" - consNodePubKeyPrefix := app.AccountAddressPrefix + "valconspub" + accountPubKeyPrefix := app.BitcoinChainCfg.Bech32HRPSegwit + "pub" + validatorAddressPrefix := app.BitcoinChainCfg.Bech32HRPSegwit + "valoper" + validatorPubKeyPrefix := app.BitcoinChainCfg.Bech32HRPSegwit + "valoperpub" + consNodeAddressPrefix := app.BitcoinChainCfg.Bech32HRPSegwit + "valcons" + consNodePubKeyPrefix := app.BitcoinChainCfg.Bech32HRPSegwit + "valconspub" // Set and seal config config := sdk.GetConfig() - config.SetBech32PrefixForAccount(app.AccountAddressPrefix, accountPubKeyPrefix) + config.SetBech32PrefixForAccount(app.BitcoinChainCfg.Bech32HRPSegwit, accountPubKeyPrefix) config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix) config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix) diff --git a/go.mod b/go.mod index 96b995bc..0da0cb9e 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,6 @@ require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect - github.com/btcsuite/btcd/btcutil v1.1.5 // indirect github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect github.com/bufbuild/connect-go v1.0.0 // indirect github.com/bufbuild/protocompile v0.8.0 // indirect @@ -215,6 +214,7 @@ require ( github.com/CosmWasm/wasmvm v1.5.2 github.com/Stride-Labs/stride/v16 v16.0.0 github.com/btcsuite/btcd v0.24.1-0.20240318151728-2fc99e0496d2 + github.com/btcsuite/btcd/btcutil v1.1.5 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/bufbuild/buf v1.7.0 github.com/cosmos/cosmos-proto v1.0.0-beta.4 @@ -230,8 +230,8 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sideprotocol/cosmos-sdk v0.47.116 - // github.com/cosmos/cosmos-sdk => ../cosmos-sdk + // github.com/cosmos/cosmos-sdk => github.com/sideprotocol/cosmos-sdk v0.47.116 + github.com/cosmos/cosmos-sdk => ../cosmos-sdk github.com/cosmos/interchain-security/v3 => github.com/Stride-Labs/interchain-security/v3 v3.1.0-remove-validation-bug-7d3d9d github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 diff --git a/go.sum b/go.sum index f8f4e1b5..fdac66a0 100644 --- a/go.sum +++ b/go.sum @@ -973,8 +973,6 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sideprotocol/cosmos-sdk v0.47.116 h1:9qXEko5qj+RVHR5a01dheCjqzw5MlnYqxu36fqJm5MU= -github.com/sideprotocol/cosmos-sdk v0.47.116/go.mod h1:Ql8d4j8oRXssuNQfVIaa6LRo7VsFMJgSy2Qckd/dcr0= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= diff --git a/local_node.sh b/local_node.sh index 520198e3..0ac139e5 100755 --- a/local_node.sh +++ b/local_node.sh @@ -5,14 +5,14 @@ CHAINID="S2-testnet-1" MONIKER="Side Labs" BINARY="$HOME/go/bin/sided" DENOM_STR="uside,ubtct,uusdc,uusdc.axl,uusdc.noble,uusdt,uusdt.kava,uusdt.axl,uwbtc.axl,uwbtc.osmo,uwbtc" - +INITIAL_ACCOUNT_STR="bc1q4h88d5xg2cxxcm2kaej32lx6gkdfrxslfaxm8n" set -f IFS=, DENOMS=($DENOM_STR) +INITIAL_ACCOUNTS=($INITIAL_ACCOUNT_STR) IFS=";" - INITIAL_SUPPLY="500000000000000" BLOCK_GAS=10000000 MAX_GAS=10000000000 @@ -103,6 +103,18 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then $BINARY add-genesis-account "$KEY" ${BALANCES:1} --keyring-backend $KEYRING --home "$HOMEDIR" done + # Allocate genesis accounts (cosmos formatted addresses) + for ADDR in "${INITIAL_ACCOUNTS[@]}"; do + BALANCES="" + for key in "${!DENOMS[@]}"; do + BALANCES+=",${INITIAL_SUPPLY}${DENOMS[$key]}" + done + echo ${BALANCES:1} + $BINARY add-genesis-account "$ADDR" ${BALANCES:1} --home "$HOMEDIR" + done + + + # Sign genesis transaction echo $INITIAL_SUPPLY${DENOMS[0]} $BINARY gentx "${KEYS[0]}" $INITIAL_SUPPLY${DENOMS[0]} --keyring-backend $KEYRING --chain-id $CHAINID --identity "666AC57CC678BEC4" --website="https://side.one" --home "$HOMEDIR" diff --git a/proto/side/btclightclient/params.proto b/proto/side/btclightclient/params.proto index 4433e1fa..2ec5f322 100644 --- a/proto/side/btclightclient/params.proto +++ b/proto/side/btclightclient/params.proto @@ -15,6 +15,8 @@ message Params { uint64 max_acceptable_block_depth = 3; // the denomanation of the voucher string btc_voucher_denom = 4; + // the address to which the voucher is sent + repeated string btc_voucher_address = 5; } // Bitcoin Block Header diff --git a/proto/side/btclightclient/tx.proto b/proto/side/btclightclient/tx.proto index 5113f98e..8a57b832 100644 --- a/proto/side/btclightclient/tx.proto +++ b/proto/side/btclightclient/tx.proto @@ -30,8 +30,13 @@ message MsgSubmitBlockHeadersResponse { // MsgSubmitTransactionRequest defines the Msg/SubmitTransaction request type. message MsgSubmitTransactionRequest { string sender = 1; - string tx = 2; - string proof = 3; + string blockhash = 2; + // the tx bytes in base64 format + // used for parsing the sender of the transaction + string prev_tx_bytes = 3; + // the tx bytes in base64 format + string tx_bytes = 4; + repeated string proof = 5; } // MsgSubmitTransactionResponse defines the Msg/SubmitTransaction response type. diff --git a/testutil/keeper/btc_light_client.go b/testutil/keeper/btc_light_client.go index 5b5e5a6a..fb57d765 100644 --- a/testutil/keeper/btc_light_client.go +++ b/testutil/keeper/btc_light_client.go @@ -11,16 +11,17 @@ import ( "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sideprotocol/side/app" "github.com/sideprotocol/side/x/btclightclient/keeper" "github.com/sideprotocol/side/x/btclightclient/types" "github.com/stretchr/testify/require" ) func BtcLightClientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { - // app := app.InitSideTestApp(false) + app := app.InitSideTestApp(false) storeKey := sdk.NewKVStoreKey(types.StoreKey) - memStoreKey := storetypes.NewMemoryStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.ModuleName) db := tmdb.NewMemDB() stateStore := store.NewCommitMultiStore(db) @@ -35,6 +36,7 @@ func BtcLightClientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { cdc, storeKey, memStoreKey, + app.BankKeeper, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/btclightclient/client/cli/query.go b/x/btclightclient/client/cli/query.go index 63f48604..e831815c 100644 --- a/x/btclightclient/client/cli/query.go +++ b/x/btclightclient/client/cli/query.go @@ -4,15 +4,11 @@ import ( "fmt" // "strings" + "github.com/sideprotocol/side/x/btclightclient/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sideprotocol/side/x/btclightclient/types" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/btclightclient/keeper/keeper.go b/x/btclightclient/keeper/keeper.go index 941b0276..cb9d9dbb 100644 --- a/x/btclightclient/keeper/keeper.go +++ b/x/btclightclient/keeper/keeper.go @@ -2,11 +2,15 @@ package keeper import ( "bytes" - "encoding/hex" + "encoding/base64" "fmt" + "slices" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/chaincfg/chainhash" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -20,6 +24,8 @@ type ( cdc codec.BinaryCodec storeKey storetypes.StoreKey memKey storetypes.StoreKey + + bankKeeper types.BankKeeper } ) @@ -27,11 +33,14 @@ func NewKeeper( cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey, + + bankKeeper types.BankKeeper, ) *Keeper { return &Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + bankKeeper: bankKeeper, } } @@ -127,13 +136,32 @@ func (k Keeper) SetBlockHeaders(ctx sdk.Context, blockHeader []*types.BlockHeade return nil } -// Process Bitcoin Transaction -func (k Keeper) ProcessBitcoinTransaction(ctx sdk.Context, txHexByte, proof string) error { +// Process Bitcoin Deposit Transaction +func (k Keeper) ProcessBitcoinDepositTransaction(ctx sdk.Context, msg *types.MsgSubmitTransactionRequest) error { + + ctx.Logger().Debug("Processing Transaction in block: ", msg.Blockhash) + + param := k.GetParams(ctx) + header := k.GetBlockHeader(ctx, msg.Blockhash) + // Check if block confirmed + if header == nil { + return types.ErrBlockNotFound + } + + best := k.GetBestBlockHeader(ctx) + // Check if the block is confirmed + if best.Height-header.Height < uint64(param.Confirmations) { + return types.ErrNotConfirmed + } + // Check if the block is within the acceptable depth + if best.Height-header.Height > param.MaxAcceptableBlockDepth { + return types.ErrExceedMaxAcceptanceDepth + } - // Decode the hexadecimal transaction - txBytes, err := hex.DecodeString(txHexByte) + // Decode the base64 transaction + txBytes, err := base64.StdEncoding.DecodeString(msg.TxBytes) if err != nil { - fmt.Println("Error decoding hex:", err) + fmt.Println("Error decoding transaction from base64:", err) return err } @@ -144,20 +172,88 @@ func (k Keeper) ProcessBitcoinTransaction(ctx sdk.Context, txHexByte, proof stri fmt.Println("Error deserializing transaction:", err) return err } + uTx := btcutil.NewTx(&tx) + if len(uTx.MsgTx().TxIn) < 1 { + return types.ErrInvalidBtcTransaction + } // Validate the transaction - // cfg := &chaincfg.MainNetParams // Use MainNetParams or TestNet3Params as per your network - if err := blockchain.CheckTransactionSanity(&tx); err != nil { + if err := blockchain.CheckTransactionSanity(uTx); err != nil { fmt.Println("Transaction is not valid:", err) return err } + + // extract senders from the previous transaction + prevTxBytes, err := base64.StdEncoding.DecodeString(msg.PrevTxBytes) if err != nil { + fmt.Println("Error decoding transaction from base64:", err) return err } - ctx.Logger().Debug("Processing Transaction", tx) + // Create a new transaction + var prevMsgTx wire.MsgTx + err = prevMsgTx.Deserialize(bytes.NewReader(prevTxBytes)) + if err != nil { + fmt.Println("Error deserializing transaction:", err) + return err + } - // transaction.MsgTx(). + prevTx := btcutil.NewTx(&prevMsgTx) + if len(prevTx.MsgTx().TxOut) < 1 { + return types.ErrInvalidBtcTransaction + } + // Validate the transaction + if err := blockchain.CheckTransactionSanity(prevTx); err != nil { + fmt.Println("Transaction is not valid:", err) + return err + } + + // check if the output is a valid address + // if there are multiple inputs, then the first input is considered as the sender + // assumpe all inputs are from the same sender + out := prevTx.MsgTx().TxOut[tx.TxIn[0].PreviousOutPoint.Index] + // check if the output is a valid address + pk, err := txscript.ParsePkScript(out.PkScript) + if err != nil { + return err + } + sender, err := pk.Address(types.ChainCfg) + if err != nil { + return err + } + + // check if the proof is valid + root, err := chainhash.NewHashFromStr(header.MerkleRoot) + if err != nil { + return err + } + if !types.VerifyMerkleProof(msg.Proof, uTx.Hash(), root) { + return types.ErrTransactionNotIncluded + } + + for _, out := range uTx.MsgTx().TxOut { + // check if the output is a valid address + pk, err := txscript.ParsePkScript(out.PkScript) + if err != nil { + return err + } + addr, err := pk.Address(types.ChainCfg) + if err != nil { + return err + } + + if slices.Contains(param.BtcVoucherAddress, addr.EncodeAddress()) { + // mint the voucher token + coins := sdk.NewCoins(sdk.NewCoin(param.BtcVoucherDenom, sdk.NewInt(int64(out.Value)))) + senderAddr, err := sdk.AccAddressFromBech32(sender.EncodeAddress()) + if err != nil { + return err + } + k.bankKeeper.MintCoins(ctx, types.ModuleName, coins) + k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, senderAddr, coins) + } + + } return nil } diff --git a/x/btclightclient/keeper/msg_server.go b/x/btclightclient/keeper/msg_server.go index ba05da68..e8801693 100644 --- a/x/btclightclient/keeper/msg_server.go +++ b/x/btclightclient/keeper/msg_server.go @@ -42,18 +42,18 @@ func (m msgServer) SubmitBlockHeaders(goCtx context.Context, msg *types.MsgSubmi return &types.MsgSubmitBlockHeadersResponse{}, nil } -// SubmitBtcTransaction implements types.MsgServer. +// SubmitTransaction implements types.MsgServer. // No Permission check required for this message // Since everyone can submit a transaction to mint voucher tokens // This message is usually sent by relayers -func (m msgServer) SubmitBtcTransaction(goCtx context.Context, msg *types.MsgSubmitTransactionRequest) (*types.MsgSubmitTransactionResponse, error) { +func (m msgServer) SubmitTransaction(goCtx context.Context, msg *types.MsgSubmitTransactionRequest) (*types.MsgSubmitTransactionResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) if err := msg.ValidateBasic(); err != nil { return nil, err } - if err := m.ProcessBitcoinTransaction(ctx, msg.Tx, msg.Proof); err != nil { + if err := m.ProcessBitcoinDepositTransaction(ctx, msg); err != nil { return nil, err } diff --git a/x/btclightclient/types/codec.go b/x/btclightclient/types/codec.go index 3fb14daa..7c4cfced 100644 --- a/x/btclightclient/types/codec.go +++ b/x/btclightclient/types/codec.go @@ -9,17 +9,15 @@ import ( func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgSubmitBlockHeaderRequest{}, "btclightclient/MsgSubmitBlockHeaderRequest", nil) - // cdc.RegisterConcrete(&MsgSubmitBlockHeadersResponse{}, "btclightclient/MsgSubmitBlockHeadersResponse", nil) cdc.RegisterConcrete(&MsgUpdateSendersRequest{}, "btclightclient/MsgUpdateSendersRequest", nil) - // cdc.RegisterConcrete(&MsgUpdateSendersResponse{}, "btclightclient/MsgUpdateSendersResponse", nil) + cdc.RegisterConcrete(&MsgSubmitTransactionRequest{}, "btclightclient/MsgSubmitTransactionRequest", nil) // this line is used by starport scaffolding # 2 } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitBlockHeaderRequest{}) - // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitBlockHeadersResponse{}) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUpdateSendersRequest{}) - // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUpdateSendersResponse{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitTransactionRequest{}) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/btclightclient/types/errors.go b/x/btclightclient/types/errors.go index fe2f825a..9f751bea 100644 --- a/x/btclightclient/types/errors.go +++ b/x/btclightclient/types/errors.go @@ -16,6 +16,8 @@ var ( ErrInvalidSenders = errorsmod.Register(ModuleName, 2100, "invalid allowed senders") ErrInvalidBtcTransaction = errorsmod.Register(ModuleName, 3100, "invalid bitcoin transaction") + ErrBlockNotFound = errorsmod.Register(ModuleName, 3101, "block not found") + ErrTransactionNotIncluded = errorsmod.Register(ModuleName, 3101, "transaction not included in block") ErrNotConfirmed = errorsmod.Register(ModuleName, 3200, "transaction not confirmed") ErrExceedMaxAcceptanceDepth = errorsmod.Register(ModuleName, 3201, "exceed max acceptance block depth") ) diff --git a/x/btclightclient/types/expected_keepers.go b/x/btclightclient/types/expected_keepers.go index 20eea16d..c3387102 100644 --- a/x/btclightclient/types/expected_keepers.go +++ b/x/btclightclient/types/expected_keepers.go @@ -3,6 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" + banktype "github.com/cosmos/cosmos-sdk/x/bank/types" ) // AccountKeeper defines the expected account keeper used for simulations (noalias) @@ -10,3 +11,22 @@ type AccountKeeper interface { GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI // Methods imported from account should be defined here } + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here + + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + SetDenomMetaData(ctx sdk.Context, denomMetaData banktype.Metadata) + + MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error + BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error + + HasSupply(ctx sdk.Context, denom string) bool + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin +} diff --git a/x/btclightclient/types/keys.go b/x/btclightclient/types/keys.go index 94adc542..cde6daa9 100644 --- a/x/btclightclient/types/keys.go +++ b/x/btclightclient/types/keys.go @@ -2,6 +2,8 @@ package types import ( "math/big" + + "github.com/btcsuite/btcd/chaincfg" ) const ( @@ -26,6 +28,7 @@ var ( BtcBlockHeaderHeightPrefix = []byte{0x12} // prefix for each key to a block hash, for a height BtcBestBlockHeaderKey = []byte{0x13} // key for the best block height + ChainCfg = &chaincfg.MainNetParams ) func Int64ToBytes(number uint64) []byte { diff --git a/x/btclightclient/types/merkle_proof.go b/x/btclightclient/types/merkle_proof.go new file mode 100644 index 00000000..26f6c8ef --- /dev/null +++ b/x/btclightclient/types/merkle_proof.go @@ -0,0 +1,39 @@ +package types + +import ( + "encoding/base64" + + "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg/chainhash" +) + +// VerifyMerkleProof verifies a Merkle proof +func VerifyMerkleProof(proofs []string, hn, root *chainhash.Hash) bool { + current := hn + for _, proof := range proofs { + + bytes, err := base64.StdEncoding.DecodeString(proof) + if err != nil { + return false + } + position := bytes[0] + p := current + if len(bytes) > 1 { + p, err = chainhash.NewHash(bytes[1:]) + if err != nil { + return false + } + } + + var temp chainhash.Hash + if position == 0 { + temp = blockchain.HashMerkleBranches(current, p) + } else { + temp = blockchain.HashMerkleBranches(p, current) + } + current = &temp + } + + return current.IsEqual(root) + +} diff --git a/x/btclightclient/types/message_submit_transaction.go b/x/btclightclient/types/message_submit_transaction.go index 6173e524..7bd5ca3f 100644 --- a/x/btclightclient/types/message_submit_transaction.go +++ b/x/btclightclient/types/message_submit_transaction.go @@ -9,13 +9,15 @@ const TypeMsgSubmitTransaction = "submit_transaction" func NewMsgSubmitTransactionRequest( sender string, + blockhash string, transaction string, - proof string, + proof []string, ) *MsgSubmitTransactionRequest { return &MsgSubmitTransactionRequest{ - Sender: sender, - Tx: transaction, - Proof: proof, + Sender: sender, + Blockhash: blockhash, + TxBytes: transaction, + Proof: proof, } } @@ -46,7 +48,15 @@ func (msg *MsgSubmitTransactionRequest) ValidateBasic() error { return sdkerrors.Wrapf(err, "invalid Sender address (%s)", err) } - if len(msg.Tx) == 0 { + if len(msg.Blockhash) == 0 { + return sdkerrors.Wrap(ErrInvalidBtcTransaction, "blockhash cannot be empty") + } + + if len(msg.PrevTxBytes) == 0 { + return sdkerrors.Wrap(ErrInvalidBtcTransaction, "transaction cannot be empty") + } + + if len(msg.TxBytes) == 0 { return sdkerrors.Wrap(ErrInvalidBtcTransaction, "transaction cannot be empty") } diff --git a/x/btclightclient/types/params.pb.go b/x/btclightclient/types/params.pb.go index 51f8e801..3600bb94 100644 --- a/x/btclightclient/types/params.pb.go +++ b/x/btclightclient/types/params.pb.go @@ -33,6 +33,8 @@ type Params struct { MaxAcceptableBlockDepth uint64 `protobuf:"varint,3,opt,name=max_acceptable_block_depth,json=maxAcceptableBlockDepth,proto3" json:"max_acceptable_block_depth,omitempty"` // the denomanation of the voucher BtcVoucherDenom string `protobuf:"bytes,4,opt,name=btc_voucher_denom,json=btcVoucherDenom,proto3" json:"btc_voucher_denom,omitempty"` + // the address to which the voucher is sent + BtcVoucherAddress []string `protobuf:"bytes,5,rep,name=btc_voucher_address,json=btcVoucherAddress,proto3" json:"btc_voucher_address,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -96,6 +98,13 @@ func (m *Params) GetBtcVoucherDenom() string { return "" } +func (m *Params) GetBtcVoucherAddress() []string { + if m != nil { + return m.BtcVoucherAddress + } + return nil +} + // Bitcoin Block Header type BlockHeader struct { Version uint64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` @@ -213,33 +222,34 @@ func init() { func init() { proto.RegisterFile("side/btclightclient/params.proto", fileDescriptor_3b47f8b78acf6f6e) } var fileDescriptor_3b47f8b78acf6f6e = []byte{ - // 404 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x3d, 0x8e, 0xd4, 0x30, - 0x14, 0x1e, 0x33, 0x3f, 0xcb, 0x78, 0x85, 0x60, 0xbd, 0x2b, 0xb0, 0xb6, 0x08, 0xd1, 0x8a, 0x62, - 0x44, 0x31, 0x29, 0xb6, 0xa4, 0x62, 0xb5, 0x05, 0x0d, 0x12, 0x4a, 0x41, 0x41, 0x13, 0xd9, 0xce, - 0x23, 0xb1, 0x36, 0xf6, 0x8b, 0x6c, 0xcf, 0x28, 0xdc, 0x82, 0xab, 0x70, 0x0b, 0xca, 0x2d, 0x29, - 0xd1, 0xcc, 0x15, 0x38, 0x00, 0xb2, 0x33, 0x83, 0x34, 0x34, 0xd1, 0xf7, 0xf7, 0xf2, 0x3e, 0xe5, - 0x85, 0xe6, 0x5e, 0xd7, 0x50, 0xc8, 0xa0, 0x3a, 0xdd, 0xb4, 0xf1, 0x09, 0x36, 0x14, 0xbd, 0x70, - 0xc2, 0xf8, 0x75, 0xef, 0x30, 0x20, 0xbb, 0x8c, 0x89, 0xf5, 0x69, 0xe2, 0xfa, 0xaa, 0xc1, 0x06, - 0x93, 0x5f, 0x44, 0x34, 0x46, 0x6f, 0x7e, 0x10, 0xba, 0xf8, 0x94, 0x66, 0x19, 0xa7, 0x67, 0x1e, - 0x6c, 0x0d, 0xce, 0x73, 0x92, 0x4f, 0x57, 0xcb, 0xf2, 0x48, 0xd9, 0x1b, 0xfa, 0x4c, 0xa1, 0xfd, - 0xaa, 0x9d, 0x11, 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9, 0x0b, 0x3a, 0xb5, 0x61, 0xe0, 0xcb, - 0x24, 0x45, 0x78, 0xf7, 0xf1, 0xe7, 0x2e, 0x23, 0x8f, 0xbb, 0x8c, 0xfc, 0xde, 0x65, 0xe4, 0xfb, - 0x3e, 0x9b, 0x3c, 0xee, 0xb3, 0xc9, 0xaf, 0x7d, 0x36, 0xf9, 0x72, 0xdb, 0xe8, 0xd0, 0x6e, 0xe4, - 0x5a, 0xa1, 0x29, 0xe2, 0xe9, 0xd3, 0x69, 0x15, 0x76, 0x89, 0x14, 0xc3, 0xff, 0xff, 0x4a, 0xf8, - 0xd6, 0x83, 0x97, 0x8b, 0x94, 0xba, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x08, 0x42, 0x8d, 0x83, - 0x4f, 0x02, 0x00, 0x00, + // 421 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x3f, 0x6f, 0xd3, 0x40, + 0x14, 0xcf, 0x91, 0x3f, 0x25, 0x57, 0x21, 0xc8, 0xb5, 0x82, 0x53, 0x07, 0x63, 0x55, 0x0c, 0x11, + 0x43, 0x3c, 0x74, 0x64, 0x6a, 0xd5, 0x81, 0x05, 0x09, 0x79, 0x60, 0x60, 0xb1, 0xce, 0xe7, 0x47, + 0x7c, 0xaa, 0x7d, 0xcf, 0xba, 0xbb, 0x44, 0xe6, 0x5b, 0xf0, 0xb1, 0x18, 0x3b, 0x32, 0x42, 0xf2, + 0x15, 0xf8, 0x00, 0xe8, 0x9e, 0x13, 0xa0, 0x5d, 0xa2, 0xdf, 0xbf, 0xcb, 0xfb, 0x3d, 0xeb, 0xf1, + 0xd4, 0x9b, 0x0a, 0xb2, 0x32, 0xe8, 0xc6, 0xac, 0xeb, 0xf8, 0x0b, 0x36, 0x64, 0x9d, 0x72, 0xaa, + 0xf5, 0xab, 0xce, 0x61, 0x40, 0x71, 0x16, 0x13, 0x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7, 0x60, 0x6b, 0x70, + 0xe3, 0x0f, 0x8b, 0xd2, 0xd3, 0xa1, 0xf3, 0xe2, 0x68, 0x0d, 0x73, 0xe3, 0xff, 0xbc, 0xe6, 0xa7, + 0x2d, 0xb8, 0xbb, 0x06, 0x0a, 0x87, 0x18, 0xe4, 0x94, 0x72, 0x7c, 0x90, 0x72, 0xc4, 0x20, 0xce, + 0xf9, 0xd4, 0xa2, 0xd5, 0x20, 0x67, 0x34, 0x67, 0x20, 0xb1, 0x52, 0x69, 0x82, 0x97, 0x27, 0x43, + 0xa5, 0x88, 0xa3, 0x16, 0x4c, 0x0b, 0xf2, 0x29, 0x05, 0x09, 0x8b, 0x17, 0x7c, 0x6c, 0x43, 0x2f, + 0xe7, 0x24, 0x45, 0x78, 0xf3, 0xe1, 0xfb, 0x2e, 0x61, 0xf7, 0xbb, 0x84, 0xfd, 0xdc, 0x25, 0xec, + 0xdb, 0x3e, 0x19, 0xdd, 0xef, 0x93, 0xd1, 0x8f, 0x7d, 0x32, 0xfa, 0x7c, 0xb5, 0x36, 0xa1, 0xde, + 0x94, 0x2b, 0x8d, 0x6d, 0x16, 0x4f, 0x85, 0x4e, 0x41, 0x63, 0x43, 0x24, 0xeb, 0x1f, 0xdf, 0x56, + 0xf8, 0xda, 0x81, 0x2f, 0x67, 0x94, 0xba, 0xfa, 0x13, 0x00, 0x00, 0xff, 0xff, 0x68, 0x1a, 0xad, + 0x49, 0x7f, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -262,6 +272,15 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.BtcVoucherAddress) > 0 { + for iNdEx := len(m.BtcVoucherAddress) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.BtcVoucherAddress[iNdEx]) + copy(dAtA[i:], m.BtcVoucherAddress[iNdEx]) + i = encodeVarintParams(dAtA, i, uint64(len(m.BtcVoucherAddress[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } if len(m.BtcVoucherDenom) > 0 { i -= len(m.BtcVoucherDenom) copy(dAtA[i:], m.BtcVoucherDenom) @@ -400,6 +419,12 @@ func (m *Params) Size() (n int) { if l > 0 { n += 1 + l + sovParams(uint64(l)) } + if len(m.BtcVoucherAddress) > 0 { + for _, s := range m.BtcVoucherAddress { + l = len(s) + n += 1 + l + sovParams(uint64(l)) + } + } return n } @@ -580,6 +605,38 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.BtcVoucherDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BtcVoucherAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BtcVoucherAddress = append(m.BtcVoucherAddress, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/btclightclient/types/tx.pb.go b/x/btclightclient/types/tx.pb.go index 7c3c3971..8da3a195 100644 --- a/x/btclightclient/types/tx.pb.go +++ b/x/btclightclient/types/tx.pb.go @@ -120,9 +120,14 @@ var xxx_messageInfo_MsgSubmitBlockHeadersResponse proto.InternalMessageInfo // MsgSubmitTransactionRequest defines the Msg/SubmitTransaction request type. type MsgSubmitTransactionRequest struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - Tx string `protobuf:"bytes,2,opt,name=tx,proto3" json:"tx,omitempty"` - Proof string `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + Blockhash string `protobuf:"bytes,2,opt,name=blockhash,proto3" json:"blockhash,omitempty"` + // the tx bytes in base64 format + // used for parsing the sender of the transaction + PrevTxBytes string `protobuf:"bytes,3,opt,name=prev_tx_bytes,json=prevTxBytes,proto3" json:"prev_tx_bytes,omitempty"` + // the tx bytes in base64 format + TxBytes string `protobuf:"bytes,4,opt,name=tx_bytes,json=txBytes,proto3" json:"tx_bytes,omitempty"` + Proof []string `protobuf:"bytes,5,rep,name=proof,proto3" json:"proof,omitempty"` } func (m *MsgSubmitTransactionRequest) Reset() { *m = MsgSubmitTransactionRequest{} } @@ -165,20 +170,34 @@ func (m *MsgSubmitTransactionRequest) GetSender() string { return "" } -func (m *MsgSubmitTransactionRequest) GetTx() string { +func (m *MsgSubmitTransactionRequest) GetBlockhash() string { if m != nil { - return m.Tx + return m.Blockhash } return "" } -func (m *MsgSubmitTransactionRequest) GetProof() string { +func (m *MsgSubmitTransactionRequest) GetPrevTxBytes() string { if m != nil { - return m.Proof + return m.PrevTxBytes } return "" } +func (m *MsgSubmitTransactionRequest) GetTxBytes() string { + if m != nil { + return m.TxBytes + } + return "" +} + +func (m *MsgSubmitTransactionRequest) GetProof() []string { + if m != nil { + return m.Proof + } + return nil +} + // MsgSubmitTransactionResponse defines the Msg/SubmitTransaction response type. type MsgSubmitTransactionResponse struct { } @@ -319,32 +338,35 @@ func init() { func init() { proto.RegisterFile("side/btclightclient/tx.proto", fileDescriptor_4df07798138ba91c) } var fileDescriptor_4df07798138ba91c = []byte{ - // 389 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x4d, 0x4b, 0xc3, 0x40, - 0x10, 0x6d, 0x52, 0xac, 0x74, 0xb5, 0x82, 0x6b, 0xd1, 0x10, 0x6b, 0x0c, 0x39, 0xf5, 0xa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0xc8, 0x52, 0x49, 0xe4, 0x6f, 0x22, 0x4b, 0x71, 0x13, 0xad, - 0xc5, 0x09, 0xa5, 0x77, 0x52, 0x95, 0x3f, 0xe5, 0x40, 0x53, 0x50, 0xab, 0x5c, 0x7c, 0x66, 0x7e, - 0x81, 0xf6, 0x4c, 0xf0, 0xaf, 0x62, 0xcf, 0x66, 0xa4, 0xcf, 0x85, 0x61, 0x99, 0xb1, 0x84, 0xd6, - 0xf3, 0x5b, 0x9e, 0x48, 0xdd, 0xfa, 0x82, 0x9a, 0x8c, 0xa4, 0xa2, 0x58, 0x6e, 0xd4, 0xf9, 0x10, - 0x51, 0xd5, 0x04, 0x1f, 0x3f, 0x21, 0x5c, 0xcc, 0x02, 0x9f, 0x94, 0x86, 0xfa, 0xc7, 0xd4, 0xe4, - 0xce, 0xca, 0x3f, 0xbe, 0x7b, 0xc0, 0x29, 0xda, 0x2e, 0x24, 0xb1, 0xcc, 0xba, 0x38, 0x11, 0xf9, - 0xf4, 0x1f, 0x3f, 0x66, 0xce, 0x21, 0x6a, 0x2c, 0xc4, 0x82, 0x8f, 0x7e, 0xd3, 0x28, 0x1b, 0x85, - 0x7c, 0xbc, 0x22, 0x3b, 0x77, 0xeb, 0x99, 0xaf, 0x13, 0x45, 0x18, 0x4f, 0x14, 0xe1, 0x7d, 0xa2, - 0x08, 0x2f, 0x53, 0xa5, 0x32, 0x9e, 0x2a, 0x95, 0xb7, 0xa9, 0x52, 0xb9, 0xee, 0xfa, 0x01, 0x1b, - 0x8c, 0x1c, 0xdd, 0xa5, 0x43, 0x23, 0x93, 0xe4, 0x0b, 0xe2, 0xd2, 0x90, 0x03, 0x23, 0x2d, 0xec, - 0xe3, 0x63, 0x4c, 0xc0, 0xa9, 0x71, 0x56, 0xf7, 0x33, 0x00, 0x00, 0xff, 0xff, 0x08, 0x0a, 0x8e, - 0x18, 0xb3, 0x03, 0x00, 0x00, + // 435 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xcd, 0xae, 0x93, 0x40, + 0x14, 0x2e, 0xc5, 0x7b, 0xaf, 0x9c, 0x6b, 0x17, 0x8e, 0x37, 0x8a, 0x58, 0x91, 0xb0, 0xea, 0x42, + 0x41, 0x7b, 0xdf, 0xa0, 0x89, 0x89, 0x89, 0x61, 0xc3, 0xad, 0x1b, 0x37, 0x0d, 0x3f, 0x23, 0x10, + 0x29, 0x83, 0x9c, 0xa9, 0xa1, 0xc6, 0x87, 0xf0, 0x31, 0x7c, 0x14, 0x97, 0x5d, 0xba, 0x34, 0xed, + 0xca, 0xb7, 0x30, 0x0c, 0xd8, 0x9f, 0x80, 0xb6, 0x77, 0x43, 0xe6, 0xcc, 0xf7, 0xcd, 0xf7, 0x7d, + 0x73, 0x0e, 0x03, 0x43, 0x4c, 0x42, 0x6a, 0xfb, 0x3c, 0x48, 0x93, 0x28, 0xae, 0xbe, 0x34, 0xe3, + 0x36, 0x2f, 0xad, 0xbc, 0x60, 0x9c, 0x91, 0x07, 0x15, 0x6a, 0x1d, 0xa2, 0xda, 0x55, 0xc4, 0x22, + 0x26, 0x70, 0xbb, 0x5a, 0xd5, 0x54, 0xcd, 0xe8, 0x12, 0xca, 0xbd, 0xc2, 0x9b, 0x63, 0xcd, 0x30, + 0xbf, 0xc2, 0x13, 0x07, 0xa3, 0x9b, 0x85, 0x3f, 0x4f, 0xf8, 0x24, 0x65, 0xc1, 0xc7, 0x37, 0xd4, + 0x0b, 0x69, 0xe1, 0xd2, 0x4f, 0x0b, 0x8a, 0x9c, 0x3c, 0x84, 0x73, 0xa4, 0x59, 0x48, 0x0b, 0x55, + 0x32, 0xa4, 0x91, 0xe2, 0x36, 0x15, 0x79, 0x0d, 0x03, 0xbf, 0x62, 0xcf, 0x62, 0x41, 0x47, 0xb5, + 0x6f, 0xc8, 0xa3, 0xcb, 0xb1, 0x61, 0x75, 0x64, 0xb3, 0xf6, 0x75, 0xef,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0xc8, + 0xae, 0xdd, 0x26, 0xce, 0x8f, 0xb5, 0x2e, 0xad, 0xd6, 0xba, 0xf4, 0x6b, 0xad, 0x4b, 0xdf, 0x36, + 0x7a, 0x6f, 0xb5, 0xd1, 0x7b, 0x3f, 0x37, 0x7a, 0xef, 0xfd, 0x75, 0x94, 0xf0, 0x78, 0xe1, 0x5b, + 0x01, 0x9b, 0xdb, 0x95, 0xa4, 0x78, 0x6e, 0x01, 0x4b, 0x45, 0x61, 0x97, 0xad, 0xd7, 0xbd, 0xcc, + 0x29, 0xfa, 0xe7, 0x82, 0x75, 0xfd, 0x27, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xe7, 0x80, 0xd3, 0x01, + 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -593,16 +615,32 @@ func (m *MsgSubmitTransactionRequest) MarshalToSizedBuffer(dAtA []byte) (int, er var l int _ = l if len(m.Proof) > 0 { - i -= len(m.Proof) - copy(dAtA[i:], m.Proof) - i = encodeVarintTx(dAtA, i, uint64(len(m.Proof))) + for iNdEx := len(m.Proof) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Proof[iNdEx]) + copy(dAtA[i:], m.Proof[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Proof[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.TxBytes) > 0 { + i -= len(m.TxBytes) + copy(dAtA[i:], m.TxBytes) + i = encodeVarintTx(dAtA, i, uint64(len(m.TxBytes))) + i-- + dAtA[i] = 0x22 + } + if len(m.PrevTxBytes) > 0 { + i -= len(m.PrevTxBytes) + copy(dAtA[i:], m.PrevTxBytes) + i = encodeVarintTx(dAtA, i, uint64(len(m.PrevTxBytes))) i-- dAtA[i] = 0x1a } - if len(m.Tx) > 0 { - i -= len(m.Tx) - copy(dAtA[i:], m.Tx) - i = encodeVarintTx(dAtA, i, uint64(len(m.Tx))) + if len(m.Blockhash) > 0 { + i -= len(m.Blockhash) + copy(dAtA[i:], m.Blockhash) + i = encodeVarintTx(dAtA, i, uint64(len(m.Blockhash))) i-- dAtA[i] = 0x12 } @@ -750,14 +788,24 @@ func (m *MsgSubmitTransactionRequest) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Tx) + l = len(m.Blockhash) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Proof) + l = len(m.PrevTxBytes) if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.TxBytes) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Proof) > 0 { + for _, s := range m.Proof { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } return n } @@ -1033,7 +1081,7 @@ func (m *MsgSubmitTransactionRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Tx", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Blockhash", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1061,9 +1109,73 @@ func (m *MsgSubmitTransactionRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Tx = string(dAtA[iNdEx:postIndex]) + m.Blockhash = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrevTxBytes", 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.PrevTxBytes = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxBytes", 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.TxBytes = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) } @@ -1093,7 +1205,7 @@ func (m *MsgSubmitTransactionRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Proof = string(dAtA[iNdEx:postIndex]) + m.Proof = append(m.Proof, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex default: iNdEx = preIndex