From 0ea20188cf31c752ba5a27419971dfdb8a28c772 Mon Sep 17 00:00:00 2001 From: Sang Heon Lee Date: Mon, 29 Apr 2024 13:54:28 +0900 Subject: [PATCH] Verifying NFT ownership through oracle voting (#160) --- app/ante/settlement_fee_checker.go | 5 +- app/app.go | 52 +- contracts/erc721.go | 2 +- evmos/x/erc20/types/erc20.pb.go | 3 +- go.mod | 5 +- go.sum | 2 + proto/settlus/nftownership/genesis.proto | 10 - proto/settlus/nftownership/params.proto | 13 - proto/settlus/nftownership/query.proto | 43 - proto/settlus/oracle/v1alpha1/event.proto | 2 +- proto/settlus/oracle/v1alpha1/oracle.proto | 35 +- proto/settlus/oracle/v1alpha1/tx.proto | 3 +- .../settlement/{ => v1alpha1}/event.proto | 25 +- .../settlement/{ => v1alpha1}/genesis.proto | 4 +- .../settlement/{ => v1alpha1}/query.proto | 16 +- .../{ => v1alpha1}/settlement.proto | 17 +- .../settlement/{ => v1alpha1}/tx.proto | 7 +- tests/e2e/e2e_settlement_test.go | 11 +- tests/e2e/e2e_setup_test.go | 6 +- testutil/keeper/nftownership.go | 54 - tools/interop-node/feeder/block_feeder.go | 229 ---- tools/interop-node/feeder/feeder.go | 303 ++++- .../{block_feeder_test.go => feeder_test.go} | 13 +- tools/interop-node/feeder/hash.go | 15 +- tools/interop-node/feeder/hash_test.go | 18 +- tools/interop-node/repository/leveldb.go | 141 --- tools/interop-node/repository/types.go | 17 - tools/interop-node/server/server.go | 37 +- tools/interop-node/subscriber/cache.go | 45 + tools/interop-node/subscriber/cache_test.go | 46 + .../interop-node/subscriber/ethereum_fill.go | 5 - .../subscriber/ethereum_subscriber.go | 283 +---- tools/interop-node/subscriber/subscriber.go | 8 +- tools/interop-node/types/ethereum.go | 6 +- tools/interop-node/types/util.go | 3 + types/hex_address.go | 15 +- types/hex_address_test.go | 31 +- x/nftownership/README.md | 68 -- x/nftownership/client/cli/query.go | 101 -- x/nftownership/genesis.go | 25 - x/nftownership/genesis_test.go | 85 -- x/nftownership/keeper/genesis.go | 21 - x/nftownership/keeper/integration_test.go | 60 - x/nftownership/keeper/keeper.go | 106 -- x/nftownership/keeper/keeper_test.go | 228 ---- x/nftownership/keeper/mock_test.go | 70 -- x/nftownership/keeper/params.go | 23 - x/nftownership/keeper/params_test.go | 19 - x/nftownership/keeper/query.go | 42 - x/nftownership/keeper/query_test.go | 41 - x/nftownership/module.go | 160 --- x/nftownership/types/codec.go | 19 - x/nftownership/types/errors.go | 14 - x/nftownership/types/expected_keepers.go | 43 - x/nftownership/types/genesis.go | 20 - x/nftownership/types/genesis.pb.go | 323 ------ x/nftownership/types/genesis_test.go | 41 - x/nftownership/types/keys.go | 27 - x/nftownership/types/params.go | 72 -- x/nftownership/types/params.pb.go | 321 ----- x/nftownership/types/params_test.go | 25 - x/nftownership/types/query.pb.go | 1028 ----------------- x/nftownership/types/query.pb.gw.go | 298 ----- x/oracle/abci.go | 91 +- x/oracle/client/cli/tx.go | 34 +- x/oracle/keeper/feeder.go | 387 +++++++ x/oracle/keeper/integration_test.go | 44 +- x/oracle/keeper/keeper.go | 452 +------- x/oracle/keeper/keeper_test.go | 182 +-- x/oracle/keeper/msg_server.go | 35 +- x/oracle/keeper/msg_server_test.go | 157 ++- x/oracle/keeper/query_test.go | 50 +- x/oracle/types/event.pb.go | 70 +- x/oracle/types/expected_keepers.go | 6 + x/oracle/types/messages.go | 23 +- x/oracle/types/nft.go | 26 + x/oracle/types/oracle.pb.go | 935 +++++++++++++-- x/oracle/types/params.go | 4 + x/oracle/types/tx.pb.go | 119 +- x/oracle/types/vote.go | 119 +- x/oracle/types/vote_data.go | 111 ++ x/oracle/types/vote_data_test.go | 134 +++ x/oracle/types/vote_test.go | 386 ------- x/oracle/voteprocessor/factory.go | 52 + x/oracle/voteprocessor/types.go | 16 + x/oracle/voteprocessor/voteprocessor.go | 116 ++ x/oracle/voteprocessor/voteprocessor_test.go | 166 +++ x/settlement/genesis.go | 2 + x/settlement/genesis_test.go | 9 +- x/settlement/keeper/grpc_query_test.go | 33 +- x/settlement/keeper/keeper.go | 57 +- x/settlement/keeper/keeper_test.go | 5 - x/settlement/keeper/msg_server.go | 50 +- x/settlement/keeper/msg_server_test.go | 27 +- x/settlement/keeper/settle.go | 76 +- x/settlement/keeper/settle_test.go | 25 +- x/settlement/keeper/utxr.go | 72 +- x/settlement/keeper/utxr_test.go | 93 +- x/settlement/types/event.pb.go | 661 +++++------ x/settlement/types/expected_keepers.go | 6 - x/settlement/types/genesis.pb.go | 59 +- x/settlement/types/keys.go | 9 + x/settlement/types/query.pb.go | 181 +-- x/settlement/types/query.pb.gw.go | 12 +- x/settlement/types/recipient.go | 14 + x/settlement/types/settlement.pb.go | 426 +++++-- x/settlement/types/tx.pb.go | 271 ++--- 107 files changed, 4103 insertions(+), 6510 deletions(-) delete mode 100644 proto/settlus/nftownership/genesis.proto delete mode 100644 proto/settlus/nftownership/params.proto delete mode 100644 proto/settlus/nftownership/query.proto rename proto/settlus/settlement/{ => v1alpha1}/event.proto (64%) rename proto/settlus/settlement/{ => v1alpha1}/genesis.proto (85%) rename proto/settlus/settlement/{ => v1alpha1}/query.proto (84%) rename proto/settlus/settlement/{ => v1alpha1}/settlement.proto (78%) rename proto/settlus/settlement/{ => v1alpha1}/tx.proto (97%) delete mode 100644 testutil/keeper/nftownership.go delete mode 100644 tools/interop-node/feeder/block_feeder.go rename tools/interop-node/feeder/{block_feeder_test.go => feeder_test.go} (67%) delete mode 100644 tools/interop-node/repository/leveldb.go delete mode 100644 tools/interop-node/repository/types.go create mode 100644 tools/interop-node/subscriber/cache.go create mode 100644 tools/interop-node/subscriber/cache_test.go delete mode 100644 tools/interop-node/subscriber/ethereum_fill.go delete mode 100644 x/nftownership/README.md delete mode 100644 x/nftownership/client/cli/query.go delete mode 100644 x/nftownership/genesis.go delete mode 100644 x/nftownership/genesis_test.go delete mode 100644 x/nftownership/keeper/genesis.go delete mode 100644 x/nftownership/keeper/integration_test.go delete mode 100644 x/nftownership/keeper/keeper.go delete mode 100644 x/nftownership/keeper/keeper_test.go delete mode 100644 x/nftownership/keeper/mock_test.go delete mode 100644 x/nftownership/keeper/params.go delete mode 100644 x/nftownership/keeper/params_test.go delete mode 100644 x/nftownership/keeper/query.go delete mode 100644 x/nftownership/keeper/query_test.go delete mode 100644 x/nftownership/module.go delete mode 100644 x/nftownership/types/codec.go delete mode 100644 x/nftownership/types/errors.go delete mode 100644 x/nftownership/types/expected_keepers.go delete mode 100644 x/nftownership/types/genesis.go delete mode 100644 x/nftownership/types/genesis.pb.go delete mode 100644 x/nftownership/types/genesis_test.go delete mode 100644 x/nftownership/types/keys.go delete mode 100644 x/nftownership/types/params.go delete mode 100644 x/nftownership/types/params.pb.go delete mode 100644 x/nftownership/types/params_test.go delete mode 100644 x/nftownership/types/query.pb.go delete mode 100644 x/nftownership/types/query.pb.gw.go create mode 100644 x/oracle/keeper/feeder.go create mode 100644 x/oracle/types/nft.go create mode 100644 x/oracle/types/vote_data.go create mode 100644 x/oracle/types/vote_data_test.go delete mode 100644 x/oracle/types/vote_test.go create mode 100644 x/oracle/voteprocessor/factory.go create mode 100644 x/oracle/voteprocessor/types.go create mode 100644 x/oracle/voteprocessor/voteprocessor.go create mode 100644 x/oracle/voteprocessor/voteprocessor_test.go create mode 100644 x/settlement/types/recipient.go diff --git a/app/ante/settlement_fee_checker.go b/app/ante/settlement_fee_checker.go index 696d521c..070bfc70 100644 --- a/app/ante/settlement_fee_checker.go +++ b/app/ante/settlement_fee_checker.go @@ -1,6 +1,8 @@ package ante import ( + "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -36,7 +38,8 @@ func newSettlementFeeChecker(k SettlementKeeper) ante.TxFeeChecker { func calculateGasCost(tx sdk.Tx) (gas uint64) { for _, msg := range tx.GetMsgs() { gas += SettlementBasicGasCost - if sdk.MsgTypeURL(msg) == "/settlus.settlement.MsgCreateTenant" { + url := sdk.MsgTypeURL(msg) + if strings.HasPrefix(url, "/settlus.settlement") && strings.HasSuffix(url, "MsgCreateTenant") { gas += SettlementCreateTenantGasCost } } diff --git a/app/app.go b/app/app.go index 3f595840..50f55f17 100644 --- a/app/app.go +++ b/app/app.go @@ -125,9 +125,7 @@ import ( "github.com/settlus/chain/app/ante" "github.com/settlus/chain/swagger" - nftownershipmodule "github.com/settlus/chain/x/nftownership" - nftownershipmodulekeeper "github.com/settlus/chain/x/nftownership/keeper" - nftownershipmoduletypes "github.com/settlus/chain/x/nftownership/types" + oraclemodule "github.com/settlus/chain/x/oracle" oraclemodulekeeper "github.com/settlus/chain/x/oracle/keeper" oraclemoduletypes "github.com/settlus/chain/x/oracle/types" @@ -184,7 +182,6 @@ var ( // Settlus modules settlementmodule.AppModuleBasic{}, - nftownershipmodule.AppModuleBasic{}, oraclemodule.AppModuleBasic{}, ) @@ -203,9 +200,8 @@ var ( erc20types.ModuleName: {authtypes.Minter, authtypes.Burner}, // settlus modules - settlementmoduletypes.ModuleName: nil, - nftownershipmoduletypes.ModuleName: nil, - oraclemoduletypes.ModuleName: nil, + settlementmoduletypes.ModuleName: nil, + oraclemoduletypes.ModuleName: nil, } ) @@ -273,9 +269,8 @@ type App struct { Erc20Keeper erc20keeper.Keeper // Settlus keepers - SettlementKeeper *settlementmodulekeeper.SettlementKeeper - NftOwnershipKeeper *nftownershipmodulekeeper.Keeper - OracleKeeper *oraclemodulekeeper.Keeper + SettlementKeeper *settlementmodulekeeper.SettlementKeeper + OracleKeeper *oraclemodulekeeper.Keeper // mm is the module manager mm *module.Manager @@ -329,7 +324,6 @@ func New( erc20types.StoreKey, // Settlus keys settlementmoduletypes.StoreKey, - nftownershipmoduletypes.StoreKey, oraclemoduletypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey) @@ -527,35 +521,26 @@ func New( ) // Settlus Keeper - app.OracleKeeper = oraclemodulekeeper.NewKeeper( + app.SettlementKeeper = settlementmodulekeeper.NewKeeper( appCodec, - keys[oraclemoduletypes.StoreKey], - app.GetSubspace(oraclemoduletypes.ModuleName), + keys[settlementmoduletypes.StoreKey], + app.GetSubspace(settlementmoduletypes.ModuleName), app.AccountKeeper, app.BankKeeper, - app.DistrKeeper, - &stakingKeeper, - distrtypes.ModuleName, - ) - - app.NftOwnershipKeeper = nftownershipmodulekeeper.NewKeeper( - appCodec, - keys[nftownershipmoduletypes.StoreKey], - app.GetSubspace(nftownershipmoduletypes.ModuleName), - app.AccountKeeper, + app.Erc20Keeper, app.EvmKeeper, - app.OracleKeeper, ) - app.SettlementKeeper = settlementmodulekeeper.NewKeeper( + app.OracleKeeper = oraclemodulekeeper.NewKeeper( appCodec, - keys[settlementmoduletypes.StoreKey], - app.GetSubspace(settlementmoduletypes.ModuleName), + keys[oraclemoduletypes.StoreKey], + app.GetSubspace(oraclemoduletypes.ModuleName), app.AccountKeeper, app.BankKeeper, - app.Erc20Keeper, - app.EvmKeeper, - app.NftOwnershipKeeper, + app.DistrKeeper, + &stakingKeeper, + app.SettlementKeeper, + distrtypes.ModuleName, ) // NOTE: app.Erc20Keeper is already initialized elsewhere @@ -660,7 +645,6 @@ func New( // Settlus app modules settlementmodule.NewAppModule(appCodec, app.SettlementKeeper, app.AccountKeeper, app.BankKeeper), - nftownershipmodule.NewAppModule(appCodec, *app.NftOwnershipKeeper, app.AccountKeeper, app.EvmKeeper), oraclemodule.NewAppModule(appCodec, *app.OracleKeeper, app.AccountKeeper, app.BankKeeper), ) @@ -697,7 +681,6 @@ func New( // Settlus modules settlementmoduletypes.ModuleName, - nftownershipmoduletypes.ModuleName, oraclemoduletypes.ModuleName, ) @@ -729,7 +712,6 @@ func New( // Settlus modules settlementmoduletypes.ModuleName, - nftownershipmoduletypes.ModuleName, oraclemoduletypes.ModuleName, ) @@ -767,7 +749,6 @@ func New( // Settlus modules settlementmoduletypes.ModuleName, - nftownershipmoduletypes.ModuleName, oraclemoduletypes.ModuleName, // NOTE: crisis module must go at the end to check for invariants on each module @@ -1067,7 +1048,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino // Settlus modules paramsKeeper.Subspace(settlementmoduletypes.ModuleName) - paramsKeeper.Subspace(nftownershipmoduletypes.ModuleName) paramsKeeper.Subspace(oraclemoduletypes.ModuleName) return paramsKeeper diff --git a/contracts/erc721.go b/contracts/erc721.go index 73f0b2cb..b4a8c613 100644 --- a/contracts/erc721.go +++ b/contracts/erc721.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" evmtypes "github.com/settlus/chain/evmos/x/evm/types" - "github.com/settlus/chain/x/nftownership/types" + "github.com/settlus/chain/x/settlement/types" ) var ( diff --git a/evmos/x/erc20/types/erc20.pb.go b/evmos/x/erc20/types/erc20.pb.go index c6b346ea..2b0a321b 100644 --- a/evmos/x/erc20/types/erc20.pb.go +++ b/evmos/x/erc20/types/erc20.pb.go @@ -57,8 +57,7 @@ func (Owner) EnumDescriptor() ([]byte, []int) { } // TokenPair defines an instance that records a pairing consisting of a native -// -// Cosmos Coin and an ERC20 token address. +// Cosmos Coin and an ERC20 token address. type TokenPair struct { // erc20_address is the hex address of ERC20 contract token Erc20Address string `protobuf:"bytes,1,opt,name=erc20_address,json=erc20Address,proto3" json:"erc20_address,omitempty"` diff --git a/go.mod b/go.mod index e3b75e1c..88c2380f 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/ibc-go/v6 v6.2.1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc + github.com/emirpasic/gods v1.18.1 github.com/ethereum/go-ethereum v1.11.6 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.4 @@ -33,7 +34,6 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 - github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d github.com/tendermint/tendermint v0.34.28 github.com/tendermint/tm-db v0.6.7 github.com/tidwall/gjson v1.17.1 @@ -41,7 +41,6 @@ require ( github.com/tyler-smith/go-bip39 v1.1.0 github.com/zondax/hid v0.9.2 go.opencensus.io v0.24.0 - golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa golang.org/x/net v0.24.0 golang.org/x/text v0.14.0 google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de @@ -199,6 +198,7 @@ require ( github.com/status-im/keycard-go v0.2.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.5.0 // indirect @@ -217,6 +217,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/crypto v0.22.0 // indirect + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/oauth2 v0.17.0 // indirect golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.19.0 // indirect diff --git a/go.sum b/go.sum index 7a0d785b..439206c1 100644 --- a/go.sum +++ b/go.sum @@ -510,6 +510,8 @@ github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7j github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/proto/settlus/nftownership/genesis.proto b/proto/settlus/nftownership/genesis.proto deleted file mode 100644 index 68b2a6bf..00000000 --- a/proto/settlus/nftownership/genesis.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; -package settlus.nftownership; - -import "gogoproto/gogo.proto"; -import "settlus/nftownership/params.proto"; - -option go_package = "github.com/settlus/chain/x/nftownership/types"; - -// GenesisState defines the nftownership module's genesis state. -message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/proto/settlus/nftownership/params.proto b/proto/settlus/nftownership/params.proto deleted file mode 100644 index 616ef7ec..00000000 --- a/proto/settlus/nftownership/params.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; -package settlus.nftownership; - -import "gogoproto/gogo.proto"; - -option go_package = "github.com/settlus/chain/x/nftownership/types"; - -// Params defines the parameters for the module. -message Params { - option (gogoproto.goproto_stringer) = false; - - repeated string allowed_chain_ids = 1; -} diff --git a/proto/settlus/nftownership/query.proto b/proto/settlus/nftownership/query.proto deleted file mode 100644 index 5f1b8141..00000000 --- a/proto/settlus/nftownership/query.proto +++ /dev/null @@ -1,43 +0,0 @@ -syntax = "proto3"; -package settlus.nftownership; - -import "gogoproto/gogo.proto"; -import "google/api/annotations.proto"; -import "settlus/nftownership/params.proto"; - -option go_package = "github.com/settlus/chain/x/nftownership/types"; - -// Query defines the gRPC querier service. -service Query { - // Parameters queries the parameters of the module. - rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/settlus/nftownership/params"; - } - - // Queries a list of GetNftOwner items. - rpc GetNftOwner(QueryGetNftOwnerRequest) returns (QueryGetNftOwnerResponse) { - option (google.api.http).get = - "/settlus/nftownership/get_nft_owner/" - "{chain_id}/{contract_address}/{token_id_hex}"; - } -} - -// QueryParamsRequest is request type for the Query/Params RPC method. -message QueryParamsRequest {} - -// QueryParamsResponse is response type for the Query/Params RPC method. -message QueryParamsResponse { - // params holds all the parameters of this module. - Params params = 1 [ (gogoproto.nullable) = false ]; -} - -// QueryGetNftOwnerRequest is request type for the Query/GetNftOwner RPC method. -message QueryGetNftOwnerRequest { - string chain_id = 1; - string contract_address = 2; - string token_id_hex = 3; -} - -// QueryGetNftOwnerResponse is response type for the Query/GetNftOwner RPC -// method. -message QueryGetNftOwnerResponse { string owner_address = 1; } diff --git a/proto/settlus/oracle/v1alpha1/event.proto b/proto/settlus/oracle/v1alpha1/event.proto index db5765ad..78da7dcf 100644 --- a/proto/settlus/oracle/v1alpha1/event.proto +++ b/proto/settlus/oracle/v1alpha1/event.proto @@ -14,7 +14,7 @@ message EventPrevote { message EventVote { string feeder = 1; string validator = 2; - repeated BlockData block_data = 3; + repeated VoteData vote_data = 3; } message EventFeederDelegationConsent { diff --git a/proto/settlus/oracle/v1alpha1/oracle.proto b/proto/settlus/oracle/v1alpha1/oracle.proto index 606e7c79..178995da 100644 --- a/proto/settlus/oracle/v1alpha1/oracle.proto +++ b/proto/settlus/oracle/v1alpha1/oracle.proto @@ -31,14 +31,28 @@ message Chain { string chain_url = 3; } +enum OralceTopic { + BLOCK = 0; + OWNERSHIP = 1; +} + +message OracleData { + OralceTopic topic = 1; + repeated string sources = 2; +} + +message VoteData { + OralceTopic topic = 1; + repeated string data = 2; +} + message AggregatePrevote { string hash = 1; string voter = 2; - uint64 submit_block = 3; } message AggregateVote { - repeated BlockData block_data = 1; + repeated VoteData vote_data = 1; string voter = 2; } @@ -62,8 +76,19 @@ message RoundInfo { uint64 id = 1; int64 prevote_end = 2; int64 vote_end = 3; - - repeated string chain_ids = 4; + repeated OracleData oracle_data = 4; // UNIX time in milliseconds int64 timestamp = 5; -} \ No newline at end of file +} + +message Nft { + string chain_id = 1; + string contract_addr = 2 [ + (gogoproto.customtype) = "github.com/settlus/chain/types.HexAddressString", + (gogoproto.nullable) = false + ]; + string token_id = 3 [ + (gogoproto.customtype) = "github.com/settlus/chain/types.HexAddressString", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/settlus/oracle/v1alpha1/tx.proto b/proto/settlus/oracle/v1alpha1/tx.proto index 46ea157b..49a5c100 100644 --- a/proto/settlus/oracle/v1alpha1/tx.proto +++ b/proto/settlus/oracle/v1alpha1/tx.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package settlus.oracle.v1alpha1; import "cosmos/msg/v1/msg.proto"; +import "settlus/oracle/v1alpha1/oracle.proto"; option go_package = "github.com/settlus/chain/x/oracle/types"; @@ -35,7 +36,7 @@ message MsgVote { string feeder = 1; string validator = 2; - string block_data_string = 3; + repeated VoteData vote_data = 3; string salt = 4; uint64 round_id = 5; } diff --git a/proto/settlus/settlement/event.proto b/proto/settlus/settlement/v1alpha1/event.proto similarity index 64% rename from proto/settlus/settlement/event.proto rename to proto/settlus/settlement/v1alpha1/event.proto index cbf42788..2494e6c3 100644 --- a/proto/settlus/settlement/event.proto +++ b/proto/settlus/settlement/v1alpha1/event.proto @@ -1,7 +1,10 @@ syntax = "proto3"; -package settlus.settlement; +package settlus.settlement.v1alpha1; import "cosmos/base/v1beta1/coin.proto"; +import "settlus/oracle/v1alpha1/oracle.proto"; +import "settlus/settlement/v1alpha1/settlement.proto"; + import "gogoproto/gogo.proto"; option go_package = "github.com/settlus/chain/x/settlement/types"; @@ -9,9 +12,12 @@ option go_package = "github.com/settlus/chain/x/settlement/types"; message EventSettled { uint64 tenant = 1; uint64 utxr_id = 2; - string request_id = 3; - cosmos.base.v1beta1.Coin amount = 4 [ (gogoproto.nullable) = false ]; - string recipient = 5; +} + +message EventSetRecipients { + uint64 tenant = 1; + uint64 utxr_id = 2; + repeated Recipient recipients = 3; } message EventRecord { @@ -20,18 +26,15 @@ message EventRecord { uint64 utxr_id = 3; string request_id = 4; cosmos.base.v1beta1.Coin amount = 5 [ (gogoproto.nullable) = false ]; - string chain_id = 6; - string contract_address = 7; - string token_id_hex = 8; - string recipient = 9; - string metadata = 10; - uint64 payout_block = 11; + settlus.oracle.v1alpha1.Nft nft = 6; + repeated Recipient recipients = 7; + string metadata = 8; + uint64 created_at = 9; } message EventCancel { uint64 tenant = 1; uint64 utxr_id = 2; - string request_id = 3; } message EventSettlementFailed { diff --git a/proto/settlus/settlement/genesis.proto b/proto/settlus/settlement/v1alpha1/genesis.proto similarity index 85% rename from proto/settlus/settlement/genesis.proto rename to proto/settlus/settlement/v1alpha1/genesis.proto index 411351db..6f774ba8 100644 --- a/proto/settlus/settlement/genesis.proto +++ b/proto/settlus/settlement/v1alpha1/genesis.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package settlus.settlement; +package settlus.settlement.v1alpha1; import "gogoproto/gogo.proto"; -import "settlus/settlement/settlement.proto"; +import "settlus/settlement/v1alpha1/settlement.proto"; option go_package = "github.com/settlus/chain/x/settlement/types"; diff --git a/proto/settlus/settlement/query.proto b/proto/settlus/settlement/v1alpha1/query.proto similarity index 84% rename from proto/settlus/settlement/query.proto rename to proto/settlus/settlement/v1alpha1/query.proto index dd048117..19be3e02 100644 --- a/proto/settlus/settlement/query.proto +++ b/proto/settlus/settlement/v1alpha1/query.proto @@ -1,12 +1,12 @@ syntax = "proto3"; -package settlus.settlement; +package settlus.settlement.v1alpha1; import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; -import "settlus/settlement/settlement.proto"; +import "settlus/settlement/v1alpha1/settlement.proto"; option go_package = "github.com/settlus/chain/x/settlement/types"; @@ -14,28 +14,30 @@ option go_package = "github.com/settlus/chain/x/settlement/types"; service Query { // Parameters queries the parameters of the module. rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/settlus/settlement/params"; + option (google.api.http).get = "/settlus/settlement/v1alpha1/params"; } // Queries a UTXR by tenant_id and request_id. rpc UTXR(QueryUTXRRRequest) returns (QueryUTXRResponse) { option (google.api.http).get = - "/settlus/settlement/utxr/{tenant_id}/{request_id}"; + "/settlus/settlement/v1alpha1/utxr/{tenant_id}/{request_id}"; } // Queries a list of TxRecord items. rpc UTXRs(QueryUTXRsRequest) returns (QueryUTXRsResponse) { - option (google.api.http).get = "/settlus/settlement/utxrs/{tenant_id}"; + option (google.api.http).get = + "/settlus/settlement/v1alpha1/utxrs/{tenant_id}"; } // Queries a tenant by tenant_id. rpc Tenant(QueryTenantRequest) returns (QueryTenantResponse) { - option (google.api.http).get = "/settlus/settlement/tenant/{tenant_id}"; + option (google.api.http).get = + "/settlus/settlement/v1alpha1/tenant/{tenant_id}"; } // Queries a all tenants. rpc Tenants(QueryTenantsRequest) returns (QueryTenantsResponse) { - option (google.api.http).get = "/settlus/settlement/tenants"; + option (google.api.http).get = "/settlus/settlement/v1alpha1/tenants"; } } diff --git a/proto/settlus/settlement/settlement.proto b/proto/settlus/settlement/v1alpha1/settlement.proto similarity index 78% rename from proto/settlus/settlement/settlement.proto rename to proto/settlus/settlement/v1alpha1/settlement.proto index 0912b9dd..0200653c 100644 --- a/proto/settlus/settlement/settlement.proto +++ b/proto/settlus/settlement/v1alpha1/settlement.proto @@ -1,7 +1,8 @@ syntax = "proto3"; -package settlus.settlement; +package settlus.settlement.v1alpha1; import "cosmos/base/v1beta1/coin.proto"; +import "settlus/oracle/v1alpha1/oracle.proto"; import "gogoproto/gogo.proto"; option go_package = "github.com/settlus/chain/x/settlement/types"; @@ -33,10 +34,16 @@ message Tenant { // UTXR defines the unspent transaction record. message UTXR { string request_id = 1; - string recipient = 2 [ + repeated Recipient recipients = 2; + cosmos.base.v1beta1.Coin amount = 3 [ (gogoproto.nullable) = false ]; + uint64 created_at = 4; // block number of the utxr creation + settlus.oracle.v1alpha1.Nft nft = 5; +} + +message Recipient { + string address = 1 [ (gogoproto.customtype) = "github.com/settlus/chain/types.HexAddressString", (gogoproto.nullable) = false ]; - cosmos.base.v1beta1.Coin amount = 3 [ (gogoproto.nullable) = false ]; - uint64 payout_block = 4; -} + uint32 weight = 2; +} \ No newline at end of file diff --git a/proto/settlus/settlement/tx.proto b/proto/settlus/settlement/v1alpha1/tx.proto similarity index 97% rename from proto/settlus/settlement/tx.proto rename to proto/settlus/settlement/v1alpha1/tx.proto index f6343c73..1870004f 100644 --- a/proto/settlus/settlement/tx.proto +++ b/proto/settlus/settlement/v1alpha1/tx.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package settlus.settlement; +package settlus.settlement.v1alpha1; import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; @@ -55,10 +55,7 @@ message MsgRecord { // MsgRecordResponse defines the response structure for executing a MsgRecord // message. -message MsgRecordResponse { - uint64 utxr_id = 1; - string recipient = 2; -} +message MsgRecordResponse { uint64 utxr_id = 1; } // MsgCancel is the Cancel request type. message MsgCancel { diff --git a/tests/e2e/e2e_settlement_test.go b/tests/e2e/e2e_settlement_test.go index a7dfd5e8..0877eb08 100644 --- a/tests/e2e/e2e_settlement_test.go +++ b/tests/e2e/e2e_settlement_test.go @@ -3,10 +3,10 @@ package e2e import ( "math/rand" "strconv" - "strings" "time" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/settlus/chain/x/settlement/types" ) @@ -33,6 +33,7 @@ func (s *IntegrationTestSuite) SetupSettlementTestSuite() { contractAddr, err := mintNFTContract(ethClient) s.Require().NoError(err) s.internalNftAddr = contractAddr + s.T().Log("NFT:", contractAddr) err = mintNFT(ethClient, contractAddr, internalNftOwner) s.Require().NoError(err) @@ -84,7 +85,7 @@ func (s *IntegrationTestSuite) TestNativeTenant() { time.Minute, 2*time.Second, ) - s.Require().Equal(internalNftOwner, strings.ToLower(utxr.Recipient.String())) + s.Require().Equal(common.FromHex(internalNftOwner), utxr.Recipients[0].Address.Bytes()) s.Require().Equal(revenue, utxr.Amount) }) s.Require().True(pass) @@ -102,7 +103,7 @@ func (s *IntegrationTestSuite) TestNativeTenant() { time.Minute, 2*time.Second, ) - s.Require().Equal(extNftOwner, strings.ToLower(utxr.Recipient.String())) + s.Require().Equal(common.FromHex(extNftOwner), utxr.Recipients[0].Address.Bytes()) s.Require().Equal(revenue, utxr.Amount) }) s.Require().True(pass) @@ -192,7 +193,7 @@ func (s *IntegrationTestSuite) TestMintableContractTenant() { time.Minute, 2*time.Second, ) - s.Require().Equal(internalNftOwner, strings.ToLower(utxr.Recipient.String())) + s.Require().Equal(common.FromHex(internalNftOwner), utxr.Recipients[0].Address.Bytes()) s.Require().Equal(revenue, utxr.Amount) beforeBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, internalNftOwner) @@ -223,7 +224,7 @@ func (s *IntegrationTestSuite) TestMintableContractTenant() { time.Minute, 2*time.Second, ) - s.Require().Equal(extNftOwner, strings.ToLower(utxr.Recipient.String())) + s.Require().Equal(common.FromHex(extNftOwner), utxr.Recipients[0].Address.Bytes()) s.Require().Equal(revenue, utxr.Amount) beforeBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, extNftOwner) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index c96cfde5..bd9a19a3 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -10,9 +10,9 @@ import ( const ( settlusdBinary = "settlusd" - txCommand = "txs" - queryCommand = "quesry" - keysCommand = "keyfs" + txCommand = "tx" + queryCommand = "query" + keysCommand = "keys" setlDenom = "setl" asetlDenom = "asetl" ) diff --git a/testutil/keeper/nftownership.go b/testutil/keeper/nftownership.go deleted file mode 100644 index a3efc6ab..00000000 --- a/testutil/keeper/nftownership.go +++ /dev/null @@ -1,54 +0,0 @@ -package keeper - -import ( - "testing" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/store" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - typesparams "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/settlus/chain/x/nftownership/keeper" - "github.com/settlus/chain/x/nftownership/types" - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmdb "github.com/tendermint/tm-db" -) - -func NftOwnershipKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { - storeKey := sdk.NewKVStoreKey(types.StoreKey) - memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) - - db := tmdb.NewMemDB() - stateStore := store.NewCommitMultiStore(db) - stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) - stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) - - registry := codectypes.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(registry) - - paramsSubspace := typesparams.NewSubspace(cdc, - types.Amino, - storeKey, - memStoreKey, - "NftOwnershipParams", - ) - k := keeper.NewKeeper( - cdc, - storeKey, - paramsSubspace, - nil, - nil, - nil, - ) - - ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - - // Initialize params - k.SetParams(ctx, types.DefaultParams()) - - return k, ctx -} diff --git a/tools/interop-node/feeder/block_feeder.go b/tools/interop-node/feeder/block_feeder.go deleted file mode 100644 index 027f3d92..00000000 --- a/tools/interop-node/feeder/block_feeder.go +++ /dev/null @@ -1,229 +0,0 @@ -package feeder - -import ( - "context" - "fmt" - "strings" - - "github.com/tendermint/tendermint/libs/log" - - "github.com/settlus/chain/tools/interop-node/client" - "github.com/settlus/chain/tools/interop-node/config" - "github.com/settlus/chain/tools/interop-node/subscriber" - oracletypes "github.com/settlus/chain/x/oracle/types" -) - -const BlockTopic = "block" - -type BlockVoteInfo struct { - RoundId uint64 - Salt string - BlockDataString string -} - -type BlockFeeder struct { - BaseFeeder - - lastPreVote *BlockVoteInfo - lastVote *BlockVoteInfo - subscribers map[string]subscriber.Subscriber -} - -var _ Feeder = (*BlockFeeder)(nil) - -func NewBlockFeeder( - config *config.Config, - sc *client.SettlusClient, - subscribers []subscriber.Subscriber, - logger log.Logger, -) (*BlockFeeder, error) { - BaseFeeder := BaseFeeder{ - logger: logger.With("topic", "block"), - validatorAddress: config.Feeder.ValidatorAddress, - address: config.Feeder.Address, - sc: sc, - } - - subscribersMap := make(map[string]subscriber.Subscriber) - for _, cc := range subscribers { - subscribersMap[cc.Id()] = cc - } - - return &BlockFeeder{ - BaseFeeder: BaseFeeder, - subscribers: subscribersMap, - }, nil -} - -// HandleVote Handles a vote period -func (feeder *BlockFeeder) HandleVote(ctx context.Context) error { - roundId := feeder.currentRound.Id - if feeder.lastPreVote == nil { - return nil - } - - if feeder.lastVote != nil && roundId == feeder.lastVote.RoundId { - feeder.logger.Debug("already sent a vote for this height, skipping this vote period...") - return nil - } - - if err := feeder.sendVote(ctx); err != nil { - feeder.logger.Error(fmt.Sprintf("failed to send vote: %v", err)) - return fmt.Errorf("failed to send vote: %w", err) - } - - feeder.lastVote = &BlockVoteInfo{ - RoundId: roundId, - Salt: feeder.lastPreVote.Salt, - BlockDataString: feeder.lastPreVote.BlockDataString, - } - - return nil -} - -// HandlePrevote Handles a prevote period -func (feeder *BlockFeeder) HandlePrevote(ctx context.Context) error { - round := feeder.currentRound - if feeder.lastPreVote != nil && round.Id == feeder.lastPreVote.RoundId { - feeder.logger.Debug("already prevote, skipping this period...") - return nil - } - - blockDataStr, err := feeder.gatherBlockDataString(round) - if err != nil { - feeder.abstainRoundId = round.Id - return err - } - - salt, err := GenerateSalt() - if err != nil { - return fmt.Errorf("failed to generate salt: %w", err) - } - - if err := feeder.sendPrevote(ctx, blockDataStr, salt, round.Id); err != nil { - return fmt.Errorf("failed to send prevote: %w", err) - } - - feeder.lastPreVote = &BlockVoteInfo{ - RoundId: round.Id, - Salt: salt, - BlockDataString: blockDataStr, - } - - return nil -} - -// HandleAbstain Handles a prevote period when block data string cannot be gathered -func (feeder *BlockFeeder) HandleAbstain(ctx context.Context) error { - round := feeder.currentRound - if feeder.lastPreVote != nil && round.Id == feeder.lastPreVote.RoundId { - feeder.logger.Debug("already prevote, skipping this period...") - return nil - } - - feeder.logger.Info("failed to gather block data string, abstaining from this vote period") - - salt, err := GenerateSalt() - if err != nil { - return fmt.Errorf("failed to generate salt: %w", err) - } - - // abstain from voting - abstainString := GenerateAbstainString(round.ChainIds) - if err := feeder.sendPrevote(ctx, abstainString, salt, round.Id); err != nil { - return fmt.Errorf("failed to send abstain prevote: %w", err) - } - - feeder.lastPreVote = &BlockVoteInfo{ - RoundId: round.Id, - Salt: salt, - BlockDataString: abstainString, - } - - return nil -} - -func (feeder *BlockFeeder) gatherBlockDataString(round oracletypes.RoundInfo) (string, error) { - blockDataList := make([]oracletypes.BlockData, len(round.ChainIds)) - for idx, cid := range round.ChainIds { - cc, ok := feeder.subscribers[cid] - if !ok { - return "", fmt.Errorf("chain client not found for chain id: %s", cc) - } - bd, err := cc.GetOldestBlock(uint64(round.Timestamp)) - if err != nil { - return "", err - } - - blockDataList[idx] = bd - } - - return BlockDataListToBlockDataString(blockDataList), nil -} - -// sendVote sends a vote to the Settlus node -func (feeder *BlockFeeder) sendVote(ctx context.Context) error { - if feeder.lastPreVote.Salt == "" || feeder.lastPreVote.BlockDataString == "" { - // we skip if salt is empty, which means no previous prevote was sent. - feeder.logger.Info("salt or blockDataString is empty, skipping this vote period...") - return nil - } - - msg := oracletypes.NewMsgVote( - feeder.address, - feeder.validatorAddress, - feeder.lastPreVote.BlockDataString, - feeder.lastPreVote.Salt, - feeder.lastPreVote.RoundId, - ) - - feeder.logger.Debug("try to send vote", "msg", msg.String()) - if err := feeder.sc.BuildAndSendTxWithRetry(ctx, msg); err != nil { - return fmt.Errorf("failed to send vote tx: %w", err) - } - feeder.logger.Info("vote sent successfully", "msg", msg.String()) - - return nil -} - -// sendPrevote sends a prevote to the Settlus node -func (feeder *BlockFeeder) sendPrevote(ctx context.Context, bd, salt string, roundId uint64) error { - hash := GeneratePrevoteHash(bd, salt) - - msg := oracletypes.NewMsgPrevote( - feeder.address, - feeder.validatorAddress, - hash, - roundId, - ) - - feeder.logger.Debug("try to send prevote", "msg", msg.String(), "blockDataString", bd) - if err := feeder.sc.BuildAndSendTxWithRetry(ctx, msg); err != nil { - return fmt.Errorf("failed to send prevote tx: %w", err) - } - feeder.logger.Info("prevote sent successfully", "msg", msg.String(), "blockDataString", bd) - - return nil -} - -// GenerateAbstainString generates an abstain string from a list of chains -// To abstain from voting, we send a prevote with a negative blocknumber -1 -func GenerateAbstainString(chainIds []string) string { - var builder strings.Builder - for _, chainId := range chainIds { - builder.WriteString(fmt.Sprintf("%s:%d:%s", chainId, -1, "")) - } - return builder.String() -} - -// BlockDataListToBlockDataString converts a list of BlockData to a string -func BlockDataListToBlockDataString(bdList []oracletypes.BlockData) string { - var builder strings.Builder - for i, bd := range bdList { - builder.WriteString(fmt.Sprintf("%s:%d:%s", bd.ChainId, bd.BlockNumber, bd.BlockHash)) - if i != len(bdList)-1 { - builder.WriteString(",") - } - } - return builder.String() -} diff --git a/tools/interop-node/feeder/feeder.go b/tools/interop-node/feeder/feeder.go index 8c76f96e..6f1a9ed5 100644 --- a/tools/interop-node/feeder/feeder.go +++ b/tools/interop-node/feeder/feeder.go @@ -3,67 +3,31 @@ package feeder import ( "context" "fmt" - "strings" "github.com/tendermint/tendermint/libs/log" "github.com/settlus/chain/tools/interop-node/client" "github.com/settlus/chain/tools/interop-node/config" "github.com/settlus/chain/tools/interop-node/subscriber" + "github.com/settlus/chain/tools/interop-node/types" oracletypes "github.com/settlus/chain/x/oracle/types" ) -type Feeder interface { - IsPreVotingPeriod(height int64) bool - IsVotingPeriod(height int64) bool - WantAbstain(height int64) bool - - HandlePrevote(ctx context.Context) error - HandleVote(ctx context.Context) error - HandleAbstain(ctx context.Context) error - FetchNewRoundInfo(ctx context.Context) -} - -func InitFeeders(config *config.Config, sc *client.SettlusClient, chainClients []subscriber.Subscriber, logger log.Logger) ([]Feeder, error) { - var feeders []Feeder - - feederTypes := strings.Split(config.Feeder.Topics, ",") - for _, feederType := range feederTypes { - feeder, err := NewFeeder(feederType, config, sc, chainClients, logger) - if err != nil { - return nil, err - } - - if feeder == nil { - return nil, fmt.Errorf("failed to create feeder without error: %s", feederType) - } - - feeders = append(feeders, feeder) - } - - return feeders, nil -} - -func NewFeeder(feederType string, config *config.Config, sc *client.SettlusClient, chainClients []subscriber.Subscriber, logger log.Logger) (Feeder, error) { - switch feederType { - case BlockTopic: - return NewBlockFeeder(config, sc, chainClients, logger) - default: - return nil, fmt.Errorf("unsupported feeder type: %s", feederType) - } -} - -type BaseFeeder struct { +type Feeder struct { logger log.Logger validatorAddress string address string currentRound oracletypes.RoundInfo abstainRoundId uint64 sc *client.SettlusClient + + lastPreVote *BlockVoteInfo + lastVote *BlockVoteInfo + subscribers map[string]subscriber.Subscriber } -func (feeder *BaseFeeder) FetchNewRoundInfo(ctx context.Context) { +func (feeder *Feeder) FetchNewRoundInfo(ctx context.Context) { roundInfo, err := feeder.sc.FetchNewRoundInfo(ctx) if err != nil { feeder.logger.Error(fmt.Sprintf("failed to fetch round info: %v", err)) @@ -74,16 +38,263 @@ func (feeder *BaseFeeder) FetchNewRoundInfo(ctx context.Context) { } // IsVotingPeriod returns true if the current height is a voting period -func (feeder *BaseFeeder) IsVotingPeriod(height int64) bool { +func (feeder *Feeder) IsVotingPeriod(height int64) bool { return height > int64(feeder.currentRound.PrevoteEnd) && height <= int64(feeder.currentRound.VoteEnd) } // IsPreVotingPeriod returns true if the current height is a prevoting period -func (feeder *BaseFeeder) IsPreVotingPeriod(height int64) bool { +func (feeder *Feeder) IsPreVotingPeriod(height int64) bool { return height <= int64(feeder.currentRound.PrevoteEnd) } // WantAbstain returns true if the feeder wants to abstain from voting -func (feeder *BaseFeeder) WantAbstain(height int64) bool { +func (feeder *Feeder) WantAbstain(height int64) bool { return feeder.IsPreVotingPeriod(height) && feeder.currentRound.Id == feeder.abstainRoundId } + +type BlockVoteInfo struct { + RoundId uint64 + Salt string + VoteData types.VoteDataArr +} + +func NewFeeder( + config *config.Config, + sc *client.SettlusClient, + subscribers []subscriber.Subscriber, + logger log.Logger, +) (*Feeder, error) { + subscribersMap := make(map[string]subscriber.Subscriber) + for _, cc := range subscribers { + subscribersMap[cc.Id()] = cc + } + + return &Feeder{ + logger: logger.With("topic", "block"), + validatorAddress: config.Feeder.ValidatorAddress, + address: config.Feeder.Address, + sc: sc, + subscribers: subscribersMap, + }, nil +} + +// HandleVote Handles a vote period +func (feeder *Feeder) HandleVote(ctx context.Context) error { + roundId := feeder.currentRound.Id + if feeder.lastPreVote == nil { + return nil + } + + if feeder.lastVote != nil && roundId == feeder.lastVote.RoundId { + feeder.logger.Debug("already sent a vote for this height, skipping this vote period...") + return nil + } + + if err := feeder.sendVote(ctx); err != nil { + feeder.logger.Error(fmt.Sprintf("failed to send vote: %v", err)) + return fmt.Errorf("failed to send vote: %w", err) + } + + feeder.lastVote = &BlockVoteInfo{ + RoundId: roundId, + Salt: feeder.lastPreVote.Salt, + VoteData: feeder.lastPreVote.VoteData, + } + + return nil +} + +// HandlePrevote Handles a prevote period +func (feeder *Feeder) HandlePrevote(ctx context.Context) error { + round := feeder.currentRound + if feeder.lastPreVote != nil && round.Id == feeder.lastPreVote.RoundId { + feeder.logger.Debug("already prevote, skipping this period...") + return nil + } + + voteData := types.VoteDataArr{} + for _, od := range round.OracleData { + switch od.Topic { + case oracletypes.OralceTopic_BLOCK: + blockDataStr, err := feeder.gatherBlockDataString(od.Sources, uint64(round.Timestamp)) + if err != nil { + feeder.abstainRoundId = round.Id + return err + } + + voteData = append(voteData, &oracletypes.VoteData{ + Topic: oracletypes.OralceTopic_BLOCK, + Data: blockDataStr, + }) + + case oracletypes.OralceTopic_OWNERSHIP: + nftDataStr, err := feeder.gatherNftOwnerDataString(od.Sources, uint64(round.Timestamp)) + if err != nil { + feeder.abstainRoundId = round.Id + return err + } + voteData = append(voteData, &oracletypes.VoteData{ + Topic: oracletypes.OralceTopic_OWNERSHIP, + Data: nftDataStr, + }) + } + } + + salt, err := GenerateSalt() + if err != nil { + return fmt.Errorf("failed to generate salt: %w", err) + } + + if err := feeder.sendPrevote(ctx, voteData, salt, round.Id); err != nil { + return fmt.Errorf("failed to send prevote: %w", err) + } + + feeder.lastPreVote = &BlockVoteInfo{ + RoundId: round.Id, + Salt: salt, + VoteData: voteData, + } + + return nil +} + +// HandleAbstain Handles a prevote period when block data string cannot be gathered +func (feeder *Feeder) HandleAbstain(ctx context.Context) error { + round := feeder.currentRound + if feeder.lastPreVote != nil && round.Id == feeder.lastPreVote.RoundId { + feeder.logger.Debug("already prevote, skipping this period...") + return nil + } + + feeder.logger.Info("failed to gather block data string, abstaining from this vote period") + + salt, err := GenerateSalt() + if err != nil { + return fmt.Errorf("failed to generate salt: %w", err) + } + + // abstain from voting + abstainData := []*oracletypes.VoteData{} + if err := feeder.sendPrevote(ctx, abstainData, salt, round.Id); err != nil { + return fmt.Errorf("failed to send abstain prevote: %w", err) + } + + feeder.lastPreVote = &BlockVoteInfo{ + RoundId: round.Id, + Salt: salt, + VoteData: abstainData, + } + + return nil +} + +func (feeder *Feeder) gatherBlockDataString(chainIds []string, timestamp uint64) ([]string, error) { + blockDataList := make([]oracletypes.BlockData, len(chainIds)) + for idx, cid := range chainIds { + bd, err := feeder.getOldestBlock(cid, timestamp) + if err != nil { + return nil, err + } + + blockDataList[idx] = bd + } + + return blockDataListToBlockDataString(blockDataList), nil +} + +func (feeder *Feeder) getOldestBlock(chainId string, timestamp uint64) (oracletypes.BlockData, error) { + sub, ok := feeder.subscribers[chainId] + if !ok { + return oracletypes.BlockData{}, fmt.Errorf("chain client not found for chain id: %s", chainId) + } + + bd, err := sub.GetOldestBlock(timestamp) + return oracletypes.BlockData{ + ChainId: chainId, + BlockNumber: bd.BlockNumber, + BlockHash: bd.BlockHash, + }, err +} + +func (feeder *Feeder) gatherNftOwnerDataString(nftIds []string, timestamp uint64) ([]string, error) { + s := make([]string, len(nftIds)) + for i, nftId := range nftIds { + nft, err := oracletypes.ParseNftId(nftId) + if err != nil { + return nil, err + } + + bd, err := feeder.getOldestBlock(nft.ChainId, timestamp) + if err != nil { + return nil, err + } + + sub, ok := feeder.subscribers[nft.ChainId] + if !ok { + return nil, fmt.Errorf("chain client not found for chain id: %s", nft.ChainId) + } + + owner, err := sub.OwnerOf(context.TODO(), nft.ContractAddr.String(), nft.TokenId.String(), bd.BlockHash) + if err != nil { + return nil, err + } + + s[i] = fmt.Sprintf("%s:%s", nftId, owner) + } + + return s, nil +} + +// sendVote sends a vote to the Settlus node +func (feeder *Feeder) sendVote(ctx context.Context) error { + if feeder.lastPreVote.Salt == "" { + // we skip if salt is empty, which means no previous prevote was sent. + feeder.logger.Info("salt or blockDataString is empty, skipping this vote period...") + return nil + } + + msg := oracletypes.NewMsgVote( + feeder.address, + feeder.validatorAddress, + feeder.lastPreVote.VoteData, + feeder.lastPreVote.Salt, + feeder.lastPreVote.RoundId, + ) + + feeder.logger.Debug("try to send vote", "msg", msg.String()) + if err := feeder.sc.BuildAndSendTxWithRetry(ctx, msg); err != nil { + return fmt.Errorf("failed to send vote tx: %w", err) + } + feeder.logger.Info("vote sent successfully", "msg", msg.String()) + + return nil +} + +// sendPrevote sends a prevote to the Settlus node +func (feeder *Feeder) sendPrevote(ctx context.Context, vda types.VoteDataArr, salt string, roundId uint64) error { + hash := GeneratePrevoteHash(vda, salt) + + msg := oracletypes.NewMsgPrevote( + feeder.address, + feeder.validatorAddress, + hash, + roundId, + ) + + feeder.logger.Debug("try to send prevote", "msg", msg.String(), "vote data", vda) + if err := feeder.sc.BuildAndSendTxWithRetry(ctx, msg); err != nil { + return fmt.Errorf("failed to send prevote tx: %w", err) + } + feeder.logger.Info("prevote sent successfully", "msg", msg.String(), "vote data", vda) + + return nil +} + +// BlockDataListToBlockDataString converts a list of BlockData to a string +func blockDataListToBlockDataString(bdList []oracletypes.BlockData) []string { + s := make([]string, len(bdList)) + for i, bd := range bdList { + s[i] = fmt.Sprintf("%s:%d/%s", bd.ChainId, bd.BlockNumber, bd.BlockHash) + } + return s +} diff --git a/tools/interop-node/feeder/block_feeder_test.go b/tools/interop-node/feeder/feeder_test.go similarity index 67% rename from tools/interop-node/feeder/block_feeder_test.go rename to tools/interop-node/feeder/feeder_test.go index 35575bce..72dab4e1 100644 --- a/tools/interop-node/feeder/block_feeder_test.go +++ b/tools/interop-node/feeder/feeder_test.go @@ -1,10 +1,10 @@ -package feeder_test +package feeder import ( "testing" - "github.com/settlus/chain/tools/interop-node/feeder" oracletypes "github.com/settlus/chain/x/oracle/types" + "github.com/stretchr/testify/require" ) func Test_BlockDataListToBlockDataString(t *testing.T) { @@ -14,7 +14,7 @@ func Test_BlockDataListToBlockDataString(t *testing.T) { tests := []struct { name string args args - want string + want []string }{ { name: "test", @@ -32,14 +32,13 @@ func Test_BlockDataListToBlockDataString(t *testing.T) { }, }, }, - want: "1:123:0x123,2:456:0x456", + want: []string{"1:123/0x123", "2:456/0x456"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := feeder.BlockDataListToBlockDataString(tt.args.bdList); got != tt.want { - t.Errorf("BlockDataListToBlockDataString() = %v, want %v", got, tt.want) - } + got := blockDataListToBlockDataString(tt.args.bdList) + require.EqualValues(t, tt.want, got) }) } } diff --git a/tools/interop-node/feeder/hash.go b/tools/interop-node/feeder/hash.go index 20d987d7..66a3d26d 100644 --- a/tools/interop-node/feeder/hash.go +++ b/tools/interop-node/feeder/hash.go @@ -4,6 +4,9 @@ import ( "crypto/rand" "crypto/sha256" "fmt" + "strings" + + "github.com/settlus/chain/tools/interop-node/types" ) const SaltLength = 4 @@ -18,10 +21,16 @@ func GenerateSalt() (string, error) { } // GeneratePrevoteHash generates a prevote hash from a block data string and a salt -func GeneratePrevoteHash(bd, salt string) string { - sourceStr := fmt.Sprintf("%s%s", salt, bd) +func GeneratePrevoteHash(vda types.VoteDataArr, salt string) string { + var sb strings.Builder + sb.WriteString(salt) + for _, vd := range vda { + for _, d := range vd.Data { + sb.WriteString(d) + } + } h := sha256.New() - h.Write([]byte(sourceStr)) + h.Write([]byte(sb.String())) bs := h.Sum(nil) return fmt.Sprintf("%X", bs) } diff --git a/tools/interop-node/feeder/hash_test.go b/tools/interop-node/feeder/hash_test.go index 9fa2224a..2e541ff5 100644 --- a/tools/interop-node/feeder/hash_test.go +++ b/tools/interop-node/feeder/hash_test.go @@ -4,6 +4,8 @@ import ( "testing" "github.com/settlus/chain/tools/interop-node/feeder" + "github.com/settlus/chain/tools/interop-node/types" + oracletypes "github.com/settlus/chain/x/oracle/types" ) func Test_GenerateSalt(t *testing.T) { @@ -22,7 +24,7 @@ func Test_GenerateSalt(t *testing.T) { func Test_GeneratePrevoteHash(t *testing.T) { type args struct { - blockDataString string + blockDataString []string salt string } tests := []struct { @@ -33,23 +35,29 @@ func Test_GeneratePrevoteHash(t *testing.T) { { name: "single chain", args: args{ - blockDataString: "1:123:0x123", + blockDataString: []string{"1:123:0x123"}, salt: "foo", }, want: "01A164031A468DE61267F23A6BD7642AA33422C983D0E298085AEE1244A51F40", }, { name: "multiple chains", args: args{ - blockDataString: "1:123:0x123,2:456:0x456", + blockDataString: []string{"1:123:0x123", "2:456:0x456"}, salt: "bar", }, - want: "701589DAB7F4883BFD8CCC3AE2A4A90D30C5AE3C21486BB0C346D47A02B4FE05", + want: "1776F5F1BCACEFC9E75DA6623C9C9B1AA6DDF9831DBDEC3453D0C69B380FBE97", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := feeder.GeneratePrevoteHash(tt.args.blockDataString, tt.args.salt); got != tt.want { + voteData := types.VoteDataArr{ + { + Topic: oracletypes.OralceTopic_BLOCK, + Data: tt.args.blockDataString, + }, + } + if got := feeder.GeneratePrevoteHash(voteData, tt.args.salt); got != tt.want { t.Errorf("GeneratePrevoteHash() = %v, want %v", got, tt.want) } }) diff --git a/tools/interop-node/repository/leveldb.go b/tools/interop-node/repository/leveldb.go deleted file mode 100644 index dffb7df5..00000000 --- a/tools/interop-node/repository/leveldb.go +++ /dev/null @@ -1,141 +0,0 @@ -package repository - -import ( - "bytes" - "encoding/binary" - "errors" - "fmt" - "path/filepath" - - sdkmath "cosmossdk.io/math" - "github.com/ethereum/go-ethereum/common" - "github.com/syndtr/goleveldb/leveldb" - - "github.com/settlus/chain/tools/interop-node/types" -) - -const ( - BLOCK_HASH_PREFIX = "BH" - BLOCK_NUMBER_PREFIX = "BN" - BLOCK_TIMESTAMP_PREFIX = "BT" - NFT_OWNERSHIP_PREFIX = "NO" -) - -type LevelDbRepository struct { - db *leveldb.DB -} - -var _ Repository = (*LevelDbRepository)(nil) - -func NewLevelDbRepostiory(path string, chainId string) *LevelDbRepository { - db, err := leveldb.OpenFile(filepath.Join(path, chainId), nil) - if err != nil { - panic(err) - } - - return &LevelDbRepository{db: db} -} - -// GetBlockNumber implements Repository. -func (repo *LevelDbRepository) GetBlockNumber(blockHash string) (string, error) { - blockHashBytes := common.FromHex(blockHash) - value, err := repo.db.Get(hashKey(blockHashBytes), nil) - if err != nil { - return "", err - } - return common.Bytes2Hex(value), nil -} - -// GetBlockHash implements Repository. -func (repo *LevelDbRepository) GetBlockHash(blockNumber string) (string, error) { - blockNumberBytes := common.FromHex(blockNumber) - value, err := repo.db.Get(numberKey(blockNumberBytes), nil) - if err != nil { - return "", err - } - return common.Bytes2Hex(value), nil -} - -// GetNftOwnership implements Repository. -func (repo *LevelDbRepository) GetNftOwnership(nftAddessHex string, tokenIdHex string, blockNumberHex string) (string, error) { - nftAddessBytes := common.FromHex(nftAddessHex) - tokenIdBytes := common.FromHex(tokenIdHex) - blockNumberBytes := common.FromHex(blockNumberHex) - - key := nftKey(nftAddessBytes, tokenIdBytes, blockNumberBytes) - iter := repo.db.NewIterator(nil, nil) - if ok := iter.Seek(key); ok && bytes.Equal(iter.Key(), key) { - return common.Bytes2Hex(iter.Value()), nil - } - - if ok := iter.Prev(); ok && bytes.HasPrefix(iter.Key(), nftKeyPrefix(nftAddessBytes, tokenIdBytes)) { - return common.Bytes2Hex(iter.Value()), nil - } - - return "", types.NewNotFoundError(fmt.Sprintf("NFT(%s/%s) not found at %s from DB", nftAddessHex, tokenIdBytes, blockNumberHex)) - -} - -// GetOldestBlock implements Repository. -func (repo *LevelDbRepository) GetOldestBlock(timestamp uint64) (BlockData, error) { - iter := repo.db.NewIterator(nil, nil) - if ok := iter.Seek(timestampKey(timestamp)); ok && bytes.HasPrefix(iter.Key(), []byte(BLOCK_TIMESTAMP_PREFIX)) { - defer iter.Release() - blockData := iter.Value() - - return BlockData{ - Number: blockData[:32], - Hash: blockData[32:], - }, nil - } - - return BlockData{}, errors.New("not found") -} - -// PutBlockData implements Repository. -func (repo *LevelDbRepository) PutBlockData(hash []byte, number []byte, timestamp uint64, ownershipData []*types.OwnershipTransferEvent) error { - batch := new(leveldb.Batch) - defer batch.Reset() - - batch.Put(hashKey(hash), number) - batch.Put(numberKey(number), hash) - batch.Put(timestampKey(timestamp), append(types.PadBytes(32, number), types.PadBytes(32, hash)...)) - - for _, v := range ownershipData { - blockNumber := sdkmath.NewIntFromUint64(v.BlockNumber).BigInt().Bytes() - batch.Put(nftKey(v.ContractAddr, v.TokenId.Bytes(), blockNumber), v.To) - } - - if err := repo.db.Write(batch, nil); err != nil { - return err - } - - return nil -} - -func hashKey(blockHash []byte) []byte { - return append([]byte(BLOCK_HASH_PREFIX), types.PadBytes(32, blockHash)...) -} - -func numberKey(blockNumber []byte) []byte { - return append([]byte(BLOCK_NUMBER_PREFIX), types.PadBytes(32, blockNumber)...) -} - -func nftKey(nftAddr []byte, tokenId []byte, blockNumber []byte) []byte { - return append(nftKeyPrefix(nftAddr, tokenId), types.PadBytes(32, blockNumber)...) -} - -func nftKeyPrefix(nftAddr []byte, tokenId []byte) []byte { - combined := append(types.PadBytes(20, nftAddr), types.PadBytes(32, tokenId)...) - return append([]byte(NFT_OWNERSHIP_PREFIX), combined...) -} - -func timestampKey(timestamp uint64) []byte { - b := make([]byte, 8) - binary.BigEndian.PutUint64(b, timestamp) - return append([]byte(BLOCK_TIMESTAMP_PREFIX), b...) -} - -func (repo *LevelDbRepository) Close() { - repo.db.Close() -} diff --git a/tools/interop-node/repository/types.go b/tools/interop-node/repository/types.go deleted file mode 100644 index 2b6da72b..00000000 --- a/tools/interop-node/repository/types.go +++ /dev/null @@ -1,17 +0,0 @@ -package repository - -import "github.com/settlus/chain/tools/interop-node/types" - -type BlockData struct { - Number []byte - Hash []byte -} - -type Repository interface { - PutBlockData(hash []byte, number []byte, timestamp uint64, ownershipData []*types.OwnershipTransferEvent) error - - GetOldestBlock(timestamp uint64) (BlockData, error) - GetBlockNumber(blockHash string) (string, error) - GetBlockHash(blockNumber string) (string, error) - GetNftOwnership(nftAddessHex string, tokenIdHex string, blockNumberHex string) (string, error) -} diff --git a/tools/interop-node/server/server.go b/tools/interop-node/server/server.go index 84329749..391ca129 100644 --- a/tools/interop-node/server/server.go +++ b/tools/interop-node/server/server.go @@ -28,7 +28,7 @@ type Server struct { sc *client.SettlusClient subscribers map[string]subscriber.Subscriber - feeders []feeder.Feeder + feeder *feeder.Feeder } // NewServer creates a new interop server @@ -60,7 +60,7 @@ func NewServer( subscribersMap[ss.Id()] = ss } - feeders, err := feeder.InitFeeders(config, sc, subscribers, logger) + feeder, err := feeder.NewFeeder(config, sc, subscribers, logger) if err != nil { return nil, fmt.Errorf("failed to create block feeder: %w", err) } @@ -71,7 +71,7 @@ func NewServer( config: config, sc: sc, subscribers: subscribersMap, - feeders: feeders, + feeder: feeder, }, nil } @@ -109,23 +109,22 @@ func (s *Server) handleIteration() { } nextHeight := latestHeight + 1 - for _, f := range s.feeders { - switch { - case f.WantAbstain(nextHeight): - if err := f.HandleAbstain(s.ctx); err != nil { - s.logger.Error(fmt.Sprintf("failed to handle abstain: %v", err)) - } - case f.IsVotingPeriod(nextHeight): - if err := f.HandleVote(s.ctx); err != nil { - s.logger.Error(fmt.Sprintf("failed to handle vote: %v", err)) - } - case f.IsPreVotingPeriod(nextHeight): - if err := f.HandlePrevote(s.ctx); err != nil { - s.logger.Error(fmt.Sprintf("failed to handle prevote: %v", err)) - } - default: - f.FetchNewRoundInfo(s.ctx) + f := s.feeder + switch { + case f.WantAbstain(nextHeight): + if err := f.HandleAbstain(s.ctx); err != nil { + s.logger.Error(fmt.Sprintf("failed to handle abstain: %v", err)) } + case f.IsVotingPeriod(nextHeight): + if err := f.HandleVote(s.ctx); err != nil { + s.logger.Error(fmt.Sprintf("failed to handle vote: %v", err)) + } + case f.IsPreVotingPeriod(nextHeight): + if err := f.HandlePrevote(s.ctx); err != nil { + s.logger.Error(fmt.Sprintf("failed to handle prevote: %v", err)) + } + default: + f.FetchNewRoundInfo(s.ctx) } } diff --git a/tools/interop-node/subscriber/cache.go b/tools/interop-node/subscriber/cache.go new file mode 100644 index 00000000..407f77d0 --- /dev/null +++ b/tools/interop-node/subscriber/cache.go @@ -0,0 +1,45 @@ +package subscriber + +import ( + "github.com/emirpasic/gods/maps/treemap" + "github.com/emirpasic/gods/utils" +) + +type BlockCache struct { + data *treemap.Map + size int +} + +type BlockData struct { + Hash string + Number int64 +} + +func NewBlockCache(size int) *BlockCache { + return &BlockCache{ + data: treemap.NewWith(utils.UInt64Comparator), + size: size, + } +} + +func (c BlockCache) PutBlockData(hash string, number int64, timestamp uint64) { + c.data.Put(timestamp, BlockData{ + Hash: hash, + Number: number, + }) + + if c.data.Size() > c.size { + key, _ := c.data.Min() + c.data.Remove(key) + } +} + +func (c BlockCache) GetOldestBlock(timetsamp uint64) (string, int64) { + key, value := c.data.Ceiling(timetsamp) + if key == nil { + return "", 0 + } + + bd := value.(BlockData) + return bd.Hash, bd.Number +} diff --git a/tools/interop-node/subscriber/cache_test.go b/tools/interop-node/subscriber/cache_test.go new file mode 100644 index 00000000..add4a9fa --- /dev/null +++ b/tools/interop-node/subscriber/cache_test.go @@ -0,0 +1,46 @@ +package subscriber + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestBlockCache_PutBlockData(t *testing.T) { + c := NewBlockCache(2) + + // Add some initial data to the cache + c.PutBlockData("hash1", 1, 123456789) + c.PutBlockData("hash2", 2, 123456790) + + // Add a new block data + c.PutBlockData("hash3", 3, 123456791) + + require.Equal(t, 2, c.data.Size()) + + _, ok := c.data.Get(uint64(123456789)) + require.False(t, ok) + + _, ok = c.data.Get(uint64(123456790)) + require.True(t, ok) + + _, ok = c.data.Get(uint64(123456791)) + require.True(t, ok) +} + +func TestBlockCache_GetOldestBlock(t *testing.T) { + c := NewBlockCache(2) + + // Add some initial data to the cache + c.PutBlockData("hash1", 1, 123456789) + c.PutBlockData("hash2", 2, 123456790) + + hash, _ := c.GetOldestBlock(123456788) + require.Equal(t, "hash1", hash) + + hash, _ = c.GetOldestBlock(123456790) + require.Equal(t, "hash2", hash) + + hash, _ = c.GetOldestBlock(123456791) + require.Equal(t, "", hash) +} diff --git a/tools/interop-node/subscriber/ethereum_fill.go b/tools/interop-node/subscriber/ethereum_fill.go deleted file mode 100644 index 62bcc69d..00000000 --- a/tools/interop-node/subscriber/ethereum_fill.go +++ /dev/null @@ -1,5 +0,0 @@ -package subscriber - -func (sub *EthereumSubscriber) fillDB() { - //TODO: Fill all block and nft data which is not processed yet -} diff --git a/tools/interop-node/subscriber/ethereum_subscriber.go b/tools/interop-node/subscriber/ethereum_subscriber.go index 6f4aaef6..443c8f66 100644 --- a/tools/interop-node/subscriber/ethereum_subscriber.go +++ b/tools/interop-node/subscriber/ethereum_subscriber.go @@ -8,46 +8,40 @@ import ( "io" "math/big" "net/http" + "strings" "time" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rpc" "github.com/tendermint/tendermint/libs/log" "github.com/ethereum/go-ethereum/common" - oracletypes "github.com/settlus/chain/x/oracle/types" - - "github.com/settlus/chain/tools/interop-node/repository" "github.com/settlus/chain/tools/interop-node/types" + oracletypes "github.com/settlus/chain/x/oracle/types" ) type EthereumSubscriber struct { chainId string - repo repository.Repository + cache *BlockCache client *http.Client rpcUrl string logger log.Logger - dbCh chan *types.BlockEventData } var _ Subscriber = (*EthereumSubscriber)(nil) -func NewEthereumSubscriber(chainId string, rpcUrl string, logger log.Logger, repo repository.Repository) (*EthereumSubscriber, error) { +func NewEthereumSubscriber(chainId string, rpcUrl string, logger log.Logger) (*EthereumSubscriber, error) { client := &http.Client{ Timeout: 10 * time.Second, } - dbCh := make(chan *types.BlockEventData) - return &EthereumSubscriber{ chainId: chainId, - repo: repo, + cache: NewBlockCache(100), client: client, rpcUrl: rpcUrl, logger: logger, - dbCh: dbCh, }, nil } @@ -56,9 +50,7 @@ func (sub *EthereumSubscriber) Id() string { } func (sub *EthereumSubscriber) Start(ctx context.Context) { - go sub.dbLoop(ctx) go sub.fetchLoop(ctx) - go sub.fillDB() } func (sub *EthereumSubscriber) Stop() { @@ -67,69 +59,39 @@ func (sub *EthereumSubscriber) Stop() { // OwnerOf returns the owner of the given NFT func (sub *EthereumSubscriber) OwnerOf(_ context.Context, nftAddressHex string, tokenIdHex string, blockHash string) (string, error) { - ownerHex, err := sub.findOwnerFromDb(nftAddressHex, tokenIdHex, blockHash) - - switch err.(type) { - case *types.NotFoundError: - sub.logger.Info("Not found in db, try to find from network", "error", err) - ownerHex, err := sub.findOwnerFromNetwork(nftAddressHex, tokenIdHex, blockHash) - if err == nil { - // lazily register ownership data to db - go func() { - blockNumber, blockTime, err := sub.blockByHash(blockHash) - if err != nil { - sub.logger.Error("Failed to get block", "error", err) - return - } - - events := []*types.OwnershipTransferEvent{{ - ContractAddr: common.HexToAddress(nftAddressHex).Bytes(), - To: common.HexToAddress(ownerHex).Bytes(), - TokenId: common.HexToHash(tokenIdHex).Big(), - }} - - if err := sub.repo.PutBlockData([]byte(blockHash), blockNumber.Bytes(), blockTime, events); err != nil { - sub.logger.Error("Failed to putBlockData", "error", err) - } else { - sub.logger.Info("put new block", "number", blockNumber, "hash", blockHash, "timestamp", blockTime) - } - }() - return ownerHex, nil - } - default: - return ownerHex, err - } - - return ownerHex, err + return sub.findOwnerFromNetwork(nftAddressHex, tokenIdHex, blockHash) } -// GetOldestBlock returns the latest block data -func (sub *EthereumSubscriber) GetOldestBlock(timestamp uint64) (oracletypes.BlockData, error) { - block, err := sub.repo.GetOldestBlock(timestamp) - if err != nil { - return oracletypes.BlockData{}, err +func (sub *EthereumSubscriber) findOwnerFromNetwork(nftAddressHex string, tokenIdHex string, blockHash string) (string, error) { + if !strings.HasPrefix(nftAddressHex, "0x") { + nftAddressHex = "0x" + nftAddressHex } - return oracletypes.BlockData{ - ChainId: sub.chainId, - BlockNumber: common.BytesToHash(block.Number).Big().Int64(), - BlockHash: common.Bytes2Hex(block.Hash), - }, nil -} + if !strings.HasPrefix(blockHash, "0x") { + blockHash = "0x" + blockHash + } -func (sub *EthereumSubscriber) findOwnerFromNetwork(nftAddressHex string, tokenIdHex string, blockHash string) (string, error) { - addr := common.HexToAddress(nftAddressHex) - data := common.Hex2Bytes(fmt.Sprintf("6352211e%064x", common.HexToHash(tokenIdHex))) // ownerOf = 0x6352211e - msg := ethereum.CallMsg{ - To: &addr, - Data: data, + data := fmt.Sprintf("0x6352211e%064x", common.HexToHash(tokenIdHex)) + + type CallMsg struct { + To string `json:"to"` + Data string `json:"data"` + } + + type BlockHash struct { + BlockHash string `json:"blockHash"` } body, err := json.Marshal(types.EthRpcInput{ JsonRpc: "2.0", Method: "eth_call", - Params: []interface{}{msg, blockHash}, - Id: "1", + Params: []interface{}{CallMsg{ + To: nftAddressHex, + Data: data, + }, BlockHash{ + BlockHash: blockHash, + }}, + Id: "1", }) if err != nil { return "failed to marshal json", err @@ -151,47 +113,15 @@ func (sub *EthereumSubscriber) findOwnerFromNetwork(nftAddressHex string, tokenI return "failed to unmarshal json", err } - return owner.Result, nil -} + if owner.Error != nil { + if owner.Error.Code == 3 { //Tranasction Reverted + return "0x00", nil + } -func (sub *EthereumSubscriber) findOwnerFromDb(nftAddressHex string, tokenIdHex string, blockHash string) (string, error) { - blockNumberHex, err := sub.repo.GetBlockNumber(blockHash) - if err != nil { - return "", types.NewNotFoundError(fmt.Sprintf("block(%s) data not found", blockHash)) + return "", fmt.Errorf("failed to get ownerOf: %s code: %d", owner.Error.Message, owner.Error.Code) } - return sub.repo.GetNftOwnership(nftAddressHex, tokenIdHex, blockNumberHex) -} - -func (sub *EthereumSubscriber) dbLoop(ctx context.Context) { - for { - select { - case event := <-sub.dbCh: - // if channel closed - if event == nil { - return - } - - // check whether block data already exists - if hash, err := sub.repo.GetBlockHash(common.Bytes2Hex(event.BlockNumber.Bytes())); err == nil { - if hash != "" && hash != common.Bytes2Hex(event.BlockHash) { - sub.logger.Error("BlockHash mismatch", "db", hash, "new", common.Bytes2Hex(event.BlockHash)) - } - continue - } - - if err := sub.repo.PutBlockData(event.BlockHash, event.BlockNumber.Bytes(), event.Timestamp, event.NftTransferred); err != nil { - sub.logger.Error("Failed to putBlockData", "error", err) - continue - } - - sub.logger.Info("put new block", "number", event.BlockNumber.Int64(), "hash", common.Bytes2Hex(event.BlockHash), "timestamp", event.Timestamp) - - case <-ctx.Done(): - close(sub.dbCh) - return - } - } + return owner.Result, nil } const fetchInterval = 5 * time.Second @@ -212,13 +142,8 @@ func (sub *EthereumSubscriber) fetchLoop(ctx context.Context) { sub.logger.Error(err.Error(), "from", "block fetch", "hash", blockHash) continue } - event, err := sub.parseBlock(blockNumber, blockHash, blockTime) - if err != nil { - sub.logger.Error(err.Error(), "from", "parse block", "number", blockNumber) - continue - } - sub.dbCh <- event + sub.cache.PutBlockData(blockHash, blockNumber.Int64(), blockTime) case <-ctx.Done(): sub.logger.Info("fetchLoop stopped") return @@ -226,99 +151,20 @@ func (sub *EthereumSubscriber) fetchLoop(ctx context.Context) { } } -// parseBlock parses the block and returns the block event data -func (sub *EthereumSubscriber) parseBlock(blockNumber *big.Int, blockHash string, blockTime uint64) (*types.BlockEventData, error) { - erc721Transferred, err := sub.getTransferEventsFromBlock(blockNumber) - if err != nil { - return nil, err +// GetOldestBlock returns the latest block data +func (sub *EthereumSubscriber) GetOldestBlock(timestamp uint64) (oracletypes.BlockData, error) { + hash, number := sub.cache.GetOldestBlock(timestamp) + if hash == "" || number == 0 { + return oracletypes.BlockData{}, fmt.Errorf("failed to get oldest block") } - return &types.BlockEventData{ - BlockNumber: blockNumber, - BlockHash: []byte(blockHash), - Timestamp: blockTime, - NftTransferred: erc721Transferred, + return oracletypes.BlockData{ + ChainId: sub.chainId, + BlockNumber: number, + BlockHash: hash, }, nil } -// toFilterArg converts ethereum.FilterQuery to a filter argument for eth_getFilterLogs JSON RPC -func toFilterArg(q ethereum.FilterQuery) (interface{}, error) { - arg := map[string]interface{}{ - "address": q.Addresses, - "topics": q.Topics, - } - if q.BlockHash != nil { - arg["blockHash"] = *q.BlockHash - if q.FromBlock != nil || q.ToBlock != nil { - return nil, fmt.Errorf("cannot specify both BlockHash and FromBlock/ToBlock") - } - } else { - if q.FromBlock == nil { - arg["fromBlock"] = "0x0" - } else { - arg["fromBlock"] = hexutil.EncodeBig(q.FromBlock) - } - arg["toBlock"] = hexutil.EncodeBig(q.ToBlock) - } - return arg, nil -} - -// getTransferEventsFromBlock returns all transfer events from a block -func (sub *EthereumSubscriber) getTransferEventsFromBlock(blockNumber *big.Int) ([]*types.OwnershipTransferEvent, error) { - filterArgs, err := toFilterArg(ethereum.FilterQuery{ - FromBlock: blockNumber, - ToBlock: blockNumber, - Topics: [][]common.Hash{{common.HexToHash(types.EventTransferSignature)}}, - }) - if err != nil { - return nil, fmt.Errorf("failed to create filter args: %w", err) - } - - body, err := json.Marshal(types.EthRpcInput{ - JsonRpc: "2.0", - Method: "eth_getFilterLogs", - Params: []interface{}{filterArgs}, - Id: "1", - }) - if err != nil { - return nil, fmt.Errorf("failed to marshal json: %w", err) - } - - res, err := sub.client.Post(sub.rpcUrl, "application/json", bytes.NewBuffer(body)) - if err != nil { - return nil, fmt.Errorf("failed to get filter logs: %w", err) - } - defer res.Body.Close() - - respBody, err := io.ReadAll(res.Body) - if err != nil { - return nil, fmt.Errorf("failed to read response body: %w", err) - } - - var logs types.FilterLogOutput - - if err := json.Unmarshal(respBody, &logs); err != nil { - return nil, fmt.Errorf("failed to unmarshal json: %w", err) - } - - erc721events := make([]*types.OwnershipTransferEvent, 0) - for _, vLog := range logs.Result { - if len(vLog.Topics) != 4 || vLog.Topics[0].Hex() != types.EventTransferSignature { - continue - } - - erc721events = append(erc721events, &types.OwnershipTransferEvent{ - TxId: vLog.TxHash.Hex(), - ContractAddr: vLog.Address.Bytes(), - To: vLog.Topics[2].Bytes(), - TokenId: vLog.Topics[3].Big(), - BlockNumber: vLog.BlockNumber, - }) - } - - return erc721events, nil -} - // blockNumber returns the latest block number func (sub *EthereumSubscriber) blockNumber() (*big.Int, error) { res, err := sub.client.Post(sub.rpcUrl, "application/json", bytes.NewBuffer([]byte(`{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}`))) @@ -340,47 +186,6 @@ func (sub *EthereumSubscriber) blockNumber() (*big.Int, error) { return common.HexToHash(blockNumber.Result).Big(), nil } -// blockByHash returns the block by hash -func (sub *EthereumSubscriber) blockByHash(blockHash string) (*big.Int, uint64, error) { - body, err := json.Marshal(types.EthRpcInput{ - JsonRpc: "2.0", - Method: "eth_getBlockByHash", - Params: []interface{}{common.HexToHash(blockHash), false}, - Id: "1", - }) - if err != nil { - return nil, 0, fmt.Errorf("failed to marshal json: %w", err) - } - - res, err := sub.client.Post(sub.rpcUrl, "application/json", bytes.NewBuffer(body)) - if err != nil { - return nil, 0, fmt.Errorf("failed to get block: %w", err) - } - defer res.Body.Close() - - respBody, err := io.ReadAll(res.Body) - if err != nil { - return nil, 0, fmt.Errorf("failed to read response body: %w", err) - } - - var block types.BlockByHashOutput - if err := json.Unmarshal(respBody, &block); err != nil { - return nil, 0, fmt.Errorf("failed to unmarshal json: %w", err) - } - - timestamp, err := hexutil.DecodeUint64(block.Result.Timestamp) - if err != nil { - return nil, 0, fmt.Errorf("failed to decode timestamp: %w", err) - } - - blockNumber, err := hexutil.DecodeBig(block.Result.Number) - if err != nil { - return nil, 0, fmt.Errorf("failed to decode block number: %w", err) - } - - return blockNumber, timestamp * 1000, nil -} - func toBlockNumArg(number *big.Int) string { if number == nil { return "latest" diff --git a/tools/interop-node/subscriber/subscriber.go b/tools/interop-node/subscriber/subscriber.go index a543581a..9dc1032d 100644 --- a/tools/interop-node/subscriber/subscriber.go +++ b/tools/interop-node/subscriber/subscriber.go @@ -7,7 +7,6 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/settlus/chain/tools/interop-node/config" - "github.com/settlus/chain/tools/interop-node/repository" "github.com/settlus/chain/tools/interop-node/types" oracletypes "github.com/settlus/chain/x/oracle/types" ) @@ -23,8 +22,7 @@ type Subscriber interface { func InitSubscribers(config *config.Config, logger log.Logger) (subscribers []Subscriber, err error) { subscribers = make([]Subscriber, len(config.Chains)) for i, chain := range config.Chains { - repo := repository.NewLevelDbRepostiory(config.DBHome, chain.ChainID) - subscriber, err := NewSubscriber(chain, logger, repo) + subscriber, err := NewSubscriber(chain, logger) if err != nil { return nil, err } @@ -34,9 +32,9 @@ func InitSubscribers(config *config.Config, logger log.Logger) (subscribers []Su return subscribers, err } -func NewSubscriber(config config.ChainConfig, logger log.Logger, repo repository.Repository) (Subscriber, error) { +func NewSubscriber(config config.ChainConfig, logger log.Logger) (Subscriber, error) { if config.ChainType == types.CHAINTYPE_ETHEREUM { - return NewEthereumSubscriber(config.ChainID, config.RpcUrl, logger, repo) + return NewEthereumSubscriber(config.ChainID, config.RpcUrl, logger) } return nil, fmt.Errorf("unsupported chain type: %s", config.ChainType) diff --git a/tools/interop-node/types/ethereum.go b/tools/interop-node/types/ethereum.go index dc37a7cb..873837fe 100644 --- a/tools/interop-node/types/ethereum.go +++ b/tools/interop-node/types/ethereum.go @@ -44,8 +44,12 @@ type EthRpcInput struct { type OwnerOfOutput struct { JsonRpc string `json:"jsonrpc"` - Id int `json:"id"` + Id string `json:"id"` Result string `json:"result"` + Error *struct { + Code int `json:"code"` + Message string `json:"message"` + } `json:"error"` } type FilterLogOutput struct { diff --git a/tools/interop-node/types/util.go b/tools/interop-node/types/util.go index fd340fa3..be5c3171 100644 --- a/tools/interop-node/types/util.go +++ b/tools/interop-node/types/util.go @@ -7,8 +7,11 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + oracletypes "github.com/settlus/chain/x/oracle/types" ) +type VoteDataArr []*oracletypes.VoteData + func PadBytes(pad int, b []byte) []byte { if len(b) == pad { return b diff --git a/types/hex_address.go b/types/hex_address.go index a0e3ca81..7f747867 100644 --- a/types/hex_address.go +++ b/types/hex_address.go @@ -1,6 +1,8 @@ package types import ( + "strings" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" ) @@ -9,12 +11,12 @@ const AccAddressByteSize = 20 type HexAddressString string -func NewHexAddressString(addr sdk.AccAddress) HexAddressString { +func NewHexAddrFromAccAddr(addr sdk.AccAddress) HexAddressString { return HexAddressString(common.BytesToAddress(addr.Bytes()).Hex()) } func (a HexAddressString) Marshal() ([]byte, error) { - return common.FromHex(string(a)), nil + return a.Bytes(), nil } func (a HexAddressString) MarshalTo(data []byte) (int, error) { @@ -39,3 +41,12 @@ func (a HexAddressString) Size() int { func (a HexAddressString) String() string { return string(a) } + +func (a HexAddressString) Bytes() []byte { + aStr := strings.TrimPrefix(string(a), "0x") + if len(aStr)%2 == 1 { + aStr = "0" + aStr + } + + return common.Hex2BytesFixed(aStr, AccAddressByteSize) +} diff --git a/types/hex_address_test.go b/types/hex_address_test.go index b0fdfa5e..cf2e5a76 100644 --- a/types/hex_address_test.go +++ b/types/hex_address_test.go @@ -26,7 +26,7 @@ func Test_NewHexAddressString(t *testing.T) { for _, testCase := range testCases { _, bytes, err := bech32.DecodeAndConvert(testCase.Bech32) require.NoError(t, err) - address := types.NewHexAddressString(bytes) + address := types.NewHexAddrFromAccAddr(bytes) require.Equal(t, testCase.Hex, address.String()) } } @@ -64,3 +64,32 @@ func TestHexAddressString_Unmarshal(t *testing.T) { require.Equal(t, expectedAddress, address) } } + +func TestHexAddressString_Normalize(t *testing.T) { + cases := []struct { + before string + after string + }{ + { + before: "0x1", + after: "0x0000000000000000000000000000000000000001", + }, + { + before: "a8", + after: "0x00000000000000000000000000000000000000a8", + }, + } + + for _, tc := range cases { + hexAddr := types.HexAddressString(tc.before) + temp := make([]byte, hexAddr.Size()) + size, err := hexAddr.MarshalTo(temp) + require.NoError(t, err) + require.Equal(t, 20, size) + + var normHexAddr types.HexAddressString + err = (&normHexAddr).Unmarshal(temp) + require.NoError(t, err) + require.Equal(t, tc.after, normHexAddr.String()) + } +} diff --git a/x/nftownership/README.md b/x/nftownership/README.md deleted file mode 100644 index fb0a736b..00000000 --- a/x/nftownership/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Abstract - -The `x/nftownership` module enables the Settlus blockchain to easily get the owner of an NFT regardless of the chain the NFT is on. - -# Contents -1. **[Concepts](#concepts)** -2. **[Queries](#queries)** -3. **[Events](#events)** -4. **[Parameters](#parameters)** - -# Concepts - -Nft ownership module allows users to easily query the owner of an NFT. -This module can query not only the NFTs on the Settlus chain, but also the NFTs on other chains by utilizing the [`x/oracle`](../../oracle/) module. - -## Allowed Chain IDs -NFT ownership module has a set of allowed chain IDs. -Governance can modify the `allowed_chain_ids` parameter to add or remove chain IDs. - -## Querying NFT Owner -Process for querying the owner of an NFT is different depending on the chain the NFT is on. - -#### NFTs on Settlus Chain -`x/nftownership` module simply calls ERC721 contract's `ownerOf` function to query the owner of an NFT. - -#### NFTs on Other Chains -`x/nftownership` module queries the owner of an NFT on other chains by utilizing the [`x/oracle`](../oracle/README.md) module. -[`x/oracle`](../oracle/README.md) module keeps track of the latest block number of the other chains. - -# Queries - -## Get NFT Owner -`/nftownership/get_nft_owner/{chain_id}/{contract_address}/{token_id}` - -Request -```protobuf -message QueryGetNftOwnerRequest { - string chain_id = 1; - string contract_address = 2; - uint64 token_id = 3; -} -``` - -Response - -Returns hex address (e.g. `0xfoobar`) of the owner of the NFT. -```protobuf -message QueryGetNftOwnerResponse { - string owner_address = 1; -} -``` - -# Events - -TODO - -The `x/nftownership` module emits the following events: - -# Parameters - -The `x/nftownership` module contains the following parameters: - -| Key | Type | Example | -|-------------------|----------|-------------------------------------| -| allowed_chain_ids | []string | ["settlus_5371-1", "ethereum", ...] | - -## Validations -- `allowed_chain_ids` can't have an empty string or duplicate chain IDs. diff --git a/x/nftownership/client/cli/query.go b/x/nftownership/client/cli/query.go deleted file mode 100644 index abcd86bf..00000000 --- a/x/nftownership/client/cli/query.go +++ /dev/null @@ -1,101 +0,0 @@ -package cli - -import ( - "context" - "fmt" - "strconv" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/ethereum/go-ethereum/common" - "github.com/spf13/cobra" - - "github.com/settlus/chain/x/nftownership/types" -) - -var _ = strconv.Itoa(0) - -// GetQueryCmd returns the cli query commands for this module -func GetQueryCmd(queryRoute string) *cobra.Command { - // Group nftownership queries under a subcommand - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand(CmdQueryParams()) - cmd.AddCommand(CmdGetNFTOwner()) - - // this line is used by starport scaffolding # 1 - - return cmd -} - -func CmdQueryParams() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "shows the parameters of the module", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func CmdGetNFTOwner() *cobra.Command { - cmd := &cobra.Command{ - Use: "get-nft-owner [chain-id] [contract-address] [token-id-hex]", - Short: "get nft owner", - Args: cobra.ExactArgs(3), - RunE: func(cmd *cobra.Command, args []string) error { - reqChainId := args[0] - reqContractAddress := args[1] - reqTokenId := args[2] - - contractAddress := common.HexToAddress(reqContractAddress) - if contractAddress == common.HexToAddress("") { - return fmt.Errorf("invalid contract address") - } - - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryGetNftOwnerRequest{ - ChainId: reqChainId, - ContractAddress: contractAddress.String(), - TokenIdHex: reqTokenId, - } - - res, err := queryClient.GetNftOwner(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/nftownership/genesis.go b/x/nftownership/genesis.go deleted file mode 100644 index e3b26958..00000000 --- a/x/nftownership/genesis.go +++ /dev/null @@ -1,25 +0,0 @@ -package nftownership - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/settlus/chain/x/nftownership/keeper" - "github.com/settlus/chain/x/nftownership/types" -) - -// InitGenesis initializes the module's state from a provided genesis state. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - // this line is used by starport scaffolding # genesis/module/init - k.SetParams(ctx, genState.Params) - k.InitGenesis(ctx) -} - -// ExportGenesis returns the module's exported genesis -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { - genesis := types.DefaultGenesis() - genesis.Params = k.GetParams(ctx) - - // this line is used by starport scaffolding # genesis/module/export - - return genesis -} diff --git a/x/nftownership/genesis_test.go b/x/nftownership/genesis_test.go deleted file mode 100644 index 59f7f58c..00000000 --- a/x/nftownership/genesis_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package nftownership_test - -import ( - "testing" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/crypto/tmhash" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" - "github.com/tendermint/tendermint/version" - - "github.com/settlus/chain/app" - feemarkettypes "github.com/settlus/chain/evmos/x/feemarket/types" - utiltx "github.com/settlus/chain/testutil/tx" - - "github.com/settlus/chain/x/nftownership" - "github.com/settlus/chain/x/nftownership/types" -) - -type GenesisTestSuite struct { - suite.Suite - ctx sdk.Context - app *app.App - genesis types.GenesisState -} - -func TestGenesisTestSuite(t *testing.T) { - suite.Run(t, new(GenesisTestSuite)) -} - -func (suite *GenesisTestSuite) SetupTest() { - // consensus key - consAddress := sdk.ConsAddress(utiltx.GenerateAddress().Bytes()) - - suite.app = app.Setup(false, feemarkettypes.DefaultGenesisState()) - suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{ - Height: 1, - ChainID: "settlus_5371-1", - Time: time.Now().UTC(), - ProposerAddress: consAddress.Bytes(), - - Version: tmversion.Consensus{ - Block: version.BlockProtocol, - }, - LastBlockId: tmproto.BlockID{ - Hash: tmhash.Sum([]byte("block_id")), - PartSetHeader: tmproto.PartSetHeader{ - Total: 11, - Hash: tmhash.Sum([]byte("partset_header")), - }, - }, - AppHash: tmhash.Sum([]byte("app")), - DataHash: tmhash.Sum([]byte("data")), - EvidenceHash: tmhash.Sum([]byte("evidence")), - ValidatorsHash: tmhash.Sum([]byte("validators")), - NextValidatorsHash: tmhash.Sum([]byte("next_validators")), - ConsensusHash: tmhash.Sum([]byte("consensus")), - LastResultsHash: tmhash.Sum([]byte("last_result")), - }) - - suite.genesis = *types.DefaultGenesis() -} - -func (suite *GenesisTestSuite) TestNftOwnershipInitGenesis() { - testCases := []struct { - name string - genesisState types.GenesisState - }{ - { - "default genesis", - *types.DefaultGenesis(), - }, - } - - for _, tc := range testCases { - suite.Require().NotPanics(func() { - nftownership.InitGenesis(suite.ctx, *suite.app.NftOwnershipKeeper, tc.genesisState) - }) - params := suite.app.NftOwnershipKeeper.GetParams(suite.ctx) - - suite.Require().Equal(tc.genesisState.Params, params) - } -} diff --git a/x/nftownership/keeper/genesis.go b/x/nftownership/keeper/genesis.go deleted file mode 100644 index 90bbd397..00000000 --- a/x/nftownership/keeper/genesis.go +++ /dev/null @@ -1,21 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - "github.com/settlus/chain/x/nftownership/types" -) - -/* -InitGenesis initializes the module's state from a provided genesis state. -If we do not set the module account here, we cannot query the EVM state with nftownership's module account. -*/ -func (k Keeper) InitGenesis(ctx sdk.Context) { - baseAcc := authtypes.NewBaseAccountWithAddress(authtypes.NewModuleAddress(types.ModuleName)) - accountName := fmt.Sprintf("%s-module-account", types.ModuleName) - acc := authtypes.NewModuleAccount(baseAcc, accountName) - k.accountKeeper.SetModuleAccount(ctx, acc) -} diff --git a/x/nftownership/keeper/integration_test.go b/x/nftownership/keeper/integration_test.go deleted file mode 100644 index 6f8502a4..00000000 --- a/x/nftownership/keeper/integration_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package keeper_test - -import ( - "math/big" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/ethereum/go-ethereum/common" - - utiltx "github.com/settlus/chain/testutil/tx" -) - -var _ = Describe("Nft license module integration tests", Ordered, func() { - BeforeEach(func() { - s.SetupTest() - }) - - var contractAddress common.Address - ownerAddress := utiltx.GenerateAddress() - - Context("with deployed NFT contracts", func() { - BeforeEach(func() { - // Deploy NFT contracts - addr, err := s.DeployContract("Bored Ape Yatch Club", "BAYC") - Expect(err).To(BeNil()) - contractAddress = addr - - err = s.MintNFT(contractAddress, ownerAddress) - Expect(err).To(BeNil()) - }) - It("can get correct owner of NFT", func() { - exists, err := s.CheckNFTExists(contractAddress, big.NewInt(0)) - Expect(err).To(BeNil()) - Expect(exists).To(BeTrue()) - - owner, err := s.app.NftOwnershipKeeper.FindInternalOwner( - s.ctx, - contractAddress.Hex(), - "0x0", - ) - Expect(err).To(BeNil()) - Expect(owner.Hex()).To(Equal(ownerAddress.Hex())) - }) - It("fails to get owner of non-existent NFT", func() { - randomContractAddress := utiltx.GenerateAddress() - exists, err := s.CheckNFTExists(randomContractAddress, big.NewInt(0)) - Expect(err).To(BeNil()) - Expect(exists).To(BeFalse()) - - owner, err := s.app.NftOwnershipKeeper.FindInternalOwner( - s.ctx, - randomContractAddress.Hex(), - "0x0", - ) - Expect(err).ToNot(BeNil()) - Expect(owner).To(BeNil()) - }) - }) -}) diff --git a/x/nftownership/keeper/keeper.go b/x/nftownership/keeper/keeper.go deleted file mode 100644 index dd293ed3..00000000 --- a/x/nftownership/keeper/keeper.go +++ /dev/null @@ -1,106 +0,0 @@ -package keeper - -import ( - "fmt" - - errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - errortypes "github.com/cosmos/cosmos-sdk/types/errors" - sdkerrorstypes "github.com/cosmos/cosmos-sdk/types/errors" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - "github.com/ethereum/go-ethereum/common" - "github.com/settlus/chain/contracts" - "github.com/settlus/chain/x/nftownership/types" - "github.com/tendermint/tendermint/libs/log" -) - -type Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - paramstore paramtypes.Subspace - - accountKeeper types.AccountKeeper - evmKeeper types.EVMKeeper - oracleKeeper types.OracleKeeper -} - -func NewKeeper( - cdc codec.BinaryCodec, - storeKey storetypes.StoreKey, - ps paramtypes.Subspace, - - accountKeeper types.AccountKeeper, - evmKeeper types.EVMKeeper, - oracleKeeper types.OracleKeeper, -) *Keeper { - // set KeyTable if it has not already been set - if !ps.HasKeyTable() { - ps = ps.WithKeyTable(types.ParamKeyTable()) - } - - return &Keeper{ - cdc: cdc, - storeKey: storeKey, - paramstore: ps, - - accountKeeper: accountKeeper, - evmKeeper: evmKeeper, - oracleKeeper: oracleKeeper, - } -} - -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) -} - -func (k Keeper) CheckValidChainId(ctx sdk.Context, chainId string) bool { - params := k.GetParams(ctx) - for _, allowedChainId := range params.AllowedChainIds { - if allowedChainId == chainId { - return true - } - } - return false -} - -func (k Keeper) OwnerOf(ctx sdk.Context, chainId string, contractAddr string, tokenIdHex string) (*common.Address, error) { - if ctx.ChainID() == chainId { - address, err := k.FindInternalOwner(ctx, contractAddr, tokenIdHex) - if err != nil { - return nil, types.ErrEVMCallFailed - } - return address, nil - } else if k.CheckValidChainId(ctx, chainId) { - return k.FindExternalOwner(ctx, chainId, contractAddr, tokenIdHex) - } else { - return &common.Address{}, types.ErrInvalidChainId - } -} - -// FindInternalOwner returns the owner of the given NFT on current chain -func (k Keeper) FindInternalOwner( - ctx sdk.Context, contractAddr string, tokenIdHex string, -) (*common.Address, error) { - erc721 := contracts.ERC721Contract.ABI - tokenId := common.HexToHash(tokenIdHex) - contract := common.HexToAddress(contractAddr) - res, err := k.evmKeeper.CallEVM(ctx, erc721, types.ModuleAddress, contract, false, "ownerOf", tokenId.Big()) - if err != nil { - return nil, fmt.Errorf("call evm failed: %w", err) - } - - owner := common.BytesToAddress(res.Ret) - if owner == common.HexToAddress("") { - return nil, errorsmod.Wrapf(sdkerrorstypes.ErrInvalidAddress, "contract '%s', token '%s', owner '%s'", contract, tokenId, owner.String()) - } - - return &owner, nil -} - -func (k Keeper) FindExternalOwner(ctx sdk.Context, chainId string, contractAddr string, tokenIdHex string) (*common.Address, error) { - // Not implemented yet - return nil, errortypes.ErrNotSupported -} diff --git a/x/nftownership/keeper/keeper_test.go b/x/nftownership/keeper/keeper_test.go deleted file mode 100644 index efb36f73..00000000 --- a/x/nftownership/keeper/keeper_test.go +++ /dev/null @@ -1,228 +0,0 @@ -package keeper_test - -import ( - "math" - "math/big" - "testing" - "time" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "github.com/settlus/chain/evmos/crypto/ethsecp256k1" - evmtypes "github.com/settlus/chain/evmos/x/evm/types" - feemarkettypes "github.com/settlus/chain/evmos/x/feemarket/types" - - "github.com/settlus/chain/app" - "github.com/settlus/chain/cmd/settlusd/config" - "github.com/settlus/chain/contracts" - "github.com/settlus/chain/testutil" - utiltx "github.com/settlus/chain/testutil/tx" - "github.com/settlus/chain/x/nftownership/types" -) - -type NftOwnershipTestSuite struct { - suite.Suite - - ctx sdk.Context - app *app.App - queryClient types.QueryClient - queryClientEvm evmtypes.QueryClient - - creator common.Address - address common.Address - consAddress sdk.ConsAddress - clientCtx client.Context //nolint:unused - ethSigner ethtypes.Signer - priv cryptotypes.PrivKey - validator stakingtypes.Validator - - signer keyring.Signer -} - -var ( - s *NftOwnershipTestSuite -) - -func TestKeeperTestSuite(t *testing.T) { - s = new(NftOwnershipTestSuite) - suite.Run(t, s) - - // Run Ginkgo integration tests - RegisterFailHandler(Fail) - RunSpecs(t, "Keeper Suite") -} - -func (suite *NftOwnershipTestSuite) SetupTest() { - suite.DoSetupTest(suite.T()) -} - -func (suite *NftOwnershipTestSuite) DoSetupTest(t require.TestingT) { - // account key - priv, err := ethsecp256k1.GenerateKey() - require.NoError(t, err) - suite.priv = priv - suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes()) - suite.signer = utiltx.NewSigner(priv) - - // consensus key - privCons, err := ethsecp256k1.GenerateKey() - require.NoError(t, err) - consAddress := sdk.ConsAddress(privCons.PubKey().Address()) - suite.consAddress = consAddress - - // init app - suite.app = app.Setup(false, feemarkettypes.DefaultGenesisState()) - header := testutil.NewHeader( - 1, time.Now().UTC(), "settlus_5371-1", consAddress, nil, nil, - ) - suite.ctx = suite.app.BaseApp.NewContext(false, header) - - // query clients - queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, suite.app.NftOwnershipKeeper) - suite.queryClient = types.NewQueryClient(queryHelper) - queryHelperEvm := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) - evmtypes.RegisterQueryServer(queryHelperEvm, suite.app.EvmKeeper) - suite.queryClientEvm = evmtypes.NewQueryClient(queryHelperEvm) - - // bond denom - stakingParams := suite.app.StakingKeeper.GetParams(suite.ctx) - stakingParams.BondDenom = config.BaseDenom - suite.app.StakingKeeper.SetParams(suite.ctx, stakingParams) - - evmParams := suite.app.EvmKeeper.GetParams(suite.ctx) - evmParams.EvmDenom = config.BaseDenom - err = suite.app.EvmKeeper.SetParams(suite.ctx, evmParams) - require.NoError(t, err) - - // nft ownership module params - nftownershipParams := suite.app.NftOwnershipKeeper.GetParams(suite.ctx) - nftownershipParams.AllowedChainIds = []string{"settlus_5371-1"} - suite.app.NftOwnershipKeeper.SetParams(suite.ctx, nftownershipParams) - - creator := utiltx.GenerateAddress() - suite.creator = creator - creatorCosmosAddress := sdk.AccAddress(creator.Bytes()) - err = testutil.FundAccount(suite.ctx, suite.app.BankKeeper, creatorCosmosAddress, sdk.NewCoins(testutil.NewSetl(1000000000000000000), testutil.NewMicroUSDC(10000))) - require.NoError(t, err) - - addressCosmosAddress := sdk.AccAddress(suite.address.Bytes()) - err = testutil.FundAccount(suite.ctx, suite.app.BankKeeper, addressCosmosAddress, sdk.NewCoins(testutil.NewSetl(1000000000000000000), testutil.NewMicroUSDC(10000))) - require.NoError(t, err) - - // Set Validator - valAddr := sdk.ValAddress(suite.address.Bytes()) - validator, err := stakingtypes.NewValidator(valAddr, privCons.PubKey(), stakingtypes.Description{}) - require.NoError(t, err) - validator = stakingkeeper.TestingUpdateValidator(suite.app.StakingKeeper, suite.ctx, validator, true) - err = suite.app.StakingKeeper.AfterValidatorCreated(suite.ctx, validator.GetOperator()) - require.NoError(t, err) - err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) - require.NoError(t, err) - - // fund signer acc to pay for tx fees - amt := sdk.NewInt(int64(math.Pow10(18) * 2)) - err = testutil.FundAccount( - suite.ctx, - suite.app.BankKeeper, - suite.priv.PubKey().Address().Bytes(), - sdk.NewCoins(sdk.NewCoin(config.BaseDenom, amt)), - ) - suite.Require().NoError(err) - - // fund nft license module account - err = testutil.FundModuleAccount( - suite.ctx, - suite.app.BankKeeper, - types.ModuleName, - sdk.NewCoins(sdk.NewCoin(config.BaseDenom, amt)), - ) - suite.Require().NoError(err) - - // TODO change to setup with 1 validator - validators := s.app.StakingKeeper.GetValidators(s.ctx, 2) - // set a bonded validator that takes part in consensus - if validators[0].Status == stakingtypes.Bonded { - suite.validator = validators[0] - } else { - suite.validator = validators[1] - } - - suite.ethSigner = ethtypes.LatestSignerForChainID(s.app.EvmKeeper.ChainID()) -} - -// Commit commits and starts a new block with an updated context. -func (suite *NftOwnershipTestSuite) Commit() { - suite.CommitAndBeginBlockAfter(time.Hour * 1) -} - -// Commit commits a block at a given time. Reminder: At the end of each -// Tendermint Consensus round the following methods are run -// 1. BeginBlock -// 2. DeliverTx -// 3. EndBlock -// 4. Commit -func (suite *NftOwnershipTestSuite) CommitAndBeginBlockAfter(t time.Duration) { - var err error - suite.ctx, err = testutil.Commit(suite.ctx, suite.app, t, nil) - suite.Require().NoError(err) - - queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) - evmtypes.RegisterQueryServer(queryHelper, suite.app.EvmKeeper) - suite.queryClientEvm = evmtypes.NewQueryClient(queryHelper) -} - -// DeployContract deploys the ERC721 contract with the provided name and symbol -func (suite *NftOwnershipTestSuite) DeployContract(name, symbol string) (common.Address, error) { - suite.Commit() - addr, err := testutil.DeployContract( - suite.ctx, - suite.app, - suite.priv, - suite.queryClientEvm, - contracts.ERC721Contract, - name, symbol, - ) - suite.Commit() - return addr, err -} - -func (suite *NftOwnershipTestSuite) MintNFT(contractAddress, ownerAddress common.Address) error { - suite.Commit() - err := testutil.MintNFT( - suite.ctx, - suite.app, - suite.priv, - contracts.ERC721Contract, - contractAddress, - ownerAddress, - ) - suite.Commit() - return err -} - -func (suite *NftOwnershipTestSuite) CheckNFTExists(contractAddress common.Address, tokenId *big.Int) (bool, error) { - exists, err := testutil.CheckNFTExists( - suite.ctx, - suite.app, - suite.priv, - contracts.ERC721Contract, - contractAddress, - tokenId, - ) - - return exists, err -} diff --git a/x/nftownership/keeper/mock_test.go b/x/nftownership/keeper/mock_test.go deleted file mode 100644 index 2e254df6..00000000 --- a/x/nftownership/keeper/mock_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package keeper_test - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/vm" - "github.com/stretchr/testify/mock" - - "github.com/settlus/chain/evmos/x/evm/statedb" - evm "github.com/settlus/chain/evmos/x/evm/types" - "github.com/settlus/chain/x/nftownership/types" -) - -var _ types.EVMKeeper = &MockEVMKeeper{} - -type MockEVMKeeper struct { - mock.Mock -} - -func (m *MockEVMKeeper) GetParams(_ sdk.Context) evm.Params { - args := m.Called(mock.Anything) - return args.Get(0).(evm.Params) -} - -func (m *MockEVMKeeper) GetAccountWithoutBalance(_ sdk.Context, _ common.Address) *statedb.Account { - args := m.Called(mock.Anything, mock.Anything) - if args.Get(0) == nil { - return nil - } - return args.Get(0).(*statedb.Account) -} - -func (m *MockEVMKeeper) EstimateGas(_ context.Context, _ *evm.EthCallRequest) (*evm.EstimateGasResponse, error) { - args := m.Called(mock.Anything, mock.Anything) - if args.Get(0) == nil { - return nil, args.Error(1) - } - return args.Get(0).(*evm.EstimateGasResponse), args.Error(1) -} - -func (m *MockEVMKeeper) ApplyMessage(_ sdk.Context, _ core.Message, _ vm.EVMLogger, _ bool) (*evm.MsgEthereumTxResponse, error) { - args := m.Called(mock.Anything, mock.Anything, mock.Anything, mock.Anything) - - if args.Get(0) == nil { - return nil, args.Error(1) - } - return args.Get(0).(*evm.MsgEthereumTxResponse), args.Error(1) -} - -// CallEVM implements types.EVMKeeper. -func (m *MockEVMKeeper) CallEVM(ctx sdk.Context, abi abi.ABI, from common.Address, contract common.Address, commit bool, method string, arg ...interface{}) (*evm.MsgEthereumTxResponse, error) { - args := m.Called(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) - if args.Get(0) == nil { - return nil, args.Error(1) - } - return args.Get(0).(*evm.MsgEthereumTxResponse), args.Error(1) -} - -// CallEVMWithData implements types.EVMKeeper. -func (m *MockEVMKeeper) CallEVMWithData(ctx sdk.Context, from common.Address, contract *common.Address, data []byte, commit bool) (*evm.MsgEthereumTxResponse, error) { - args := m.Called(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) - if args.Get(0) == nil { - return nil, args.Error(1) - } - return args.Get(0).(*evm.MsgEthereumTxResponse), args.Error(1) -} diff --git a/x/nftownership/keeper/params.go b/x/nftownership/keeper/params.go deleted file mode 100644 index fbe83560..00000000 --- a/x/nftownership/keeper/params.go +++ /dev/null @@ -1,23 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/settlus/chain/x/nftownership/types" -) - -// GetParams get all parameters as types.Params -func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - k.paramstore.GetParamSet(ctx, ¶ms) - - if params.AllowedChainIds == nil { - return types.DefaultParams() - } - - return params -} - -// SetParams set the params -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramstore.SetParamSet(ctx, ¶ms) -} diff --git a/x/nftownership/keeper/params_test.go b/x/nftownership/keeper/params_test.go deleted file mode 100644 index 2aea772b..00000000 --- a/x/nftownership/keeper/params_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - testkeeper "github.com/settlus/chain/testutil/keeper" - "github.com/settlus/chain/x/nftownership/types" -) - -func TestGetParams(t *testing.T) { - k, ctx := testkeeper.NftOwnershipKeeper(t) - params := types.DefaultParams() - - k.SetParams(ctx, params) - - require.EqualValues(t, params, k.GetParams(ctx)) -} diff --git a/x/nftownership/keeper/query.go b/x/nftownership/keeper/query.go deleted file mode 100644 index 09a47b55..00000000 --- a/x/nftownership/keeper/query.go +++ /dev/null @@ -1,42 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrorstypes "github.com/cosmos/cosmos-sdk/types/errors" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "github.com/settlus/chain/x/nftownership/types" -) - -func (k Keeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - wctx := sdk.UnwrapSDKContext(ctx) - - return &types.QueryParamsResponse{Params: k.GetParams(wctx)}, nil -} - -func (k Keeper) GetNftOwner(goCtx context.Context, req *types.QueryGetNftOwnerRequest) (*types.QueryGetNftOwnerResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - ctx := sdk.UnwrapSDKContext(goCtx) - - ownerAddress, err := k.OwnerOf(ctx, req.ChainId, req.ContractAddress, req.TokenIdHex) - if err != nil { - if sdkerrorstypes.ErrInvalidAddress.Is(err) { - return nil, sdkerrorstypes.ErrInvalidAddress - } - - // Note: we shouldn't return the EVM error log directly to the client - return nil, err - } - return &types.QueryGetNftOwnerResponse{ - OwnerAddress: ownerAddress.String(), - }, nil -} diff --git a/x/nftownership/keeper/query_test.go b/x/nftownership/keeper/query_test.go deleted file mode 100644 index 1689e4fe..00000000 --- a/x/nftownership/keeper/query_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package keeper_test - -import ( - "math/big" - - utiltx "github.com/settlus/chain/testutil/tx" - "github.com/settlus/chain/x/nftownership/types" -) - -func (suite *NftOwnershipTestSuite) TestKeeper_Params() { - params := types.DefaultParams() - params.AllowedChainIds = []string{"chain1", "chain2"} - suite.app.NftOwnershipKeeper.SetParams(suite.ctx, params) - - response, err := suite.app.NftOwnershipKeeper.Params(suite.ctx, &types.QueryParamsRequest{}) - suite.Require().NoError(err) - suite.Require().Equal(params, response.Params) -} - -func (suite *NftOwnershipTestSuite) TestKeeper_GetNftOwner() { - addr, err := s.DeployContract("Bored Ape Yatch Club", "BAYC") - suite.Require().NoError(err) - contractAddress := addr - ownerAddress := utiltx.GenerateAddress() - - err = s.MintNFT(contractAddress, ownerAddress) - suite.Require().NoError(err) - - exists, err := s.CheckNFTExists(contractAddress, big.NewInt(0)) - suite.Require().NoError(err) - suite.Require().True(exists) - - response, err := suite.app.NftOwnershipKeeper.GetNftOwner(suite.ctx, &types.QueryGetNftOwnerRequest{ - ChainId: suite.ctx.ChainID(), - ContractAddress: contractAddress.Hex(), - TokenIdHex: "0x0", - }) - - suite.Require().NoError(err) - suite.Require().Equal(ownerAddress.Hex(), response.OwnerAddress) -} diff --git a/x/nftownership/module.go b/x/nftownership/module.go deleted file mode 100644 index a3baafd1..00000000 --- a/x/nftownership/module.go +++ /dev/null @@ -1,160 +0,0 @@ -package nftownership - -import ( - "context" - "encoding/json" - "fmt" - - // this line is used by starport scaffolding # 1 - - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/settlus/chain/x/nftownership/client/cli" - "github.com/settlus/chain/x/nftownership/keeper" - "github.com/settlus/chain/x/nftownership/types" -) - -var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} -) - -// ---------------------------------------------------------------------------- -// AppModuleBasic -// ---------------------------------------------------------------------------- - -// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. -type AppModuleBasic struct { - cdc codec.BinaryCodec -} - -func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { - return AppModuleBasic{cdc: cdc} -} - -// Name returns the name of the module as a string -func (AppModuleBasic) Name() string { - return types.ModuleName -} - -// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} - -// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message -func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(reg) -} - -// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesis()) -} - -// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - var genState types.GenesisState - if err := cdc.UnmarshalJSON(bz, &genState); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - } - return genState.Validate() -} - -// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - _ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) -} - -// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module -func (a AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(types.StoreKey) -} - -// ---------------------------------------------------------------------------- -// AppModule -// ---------------------------------------------------------------------------- - -// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement -type AppModule struct { - AppModuleBasic - - keeper keeper.Keeper - accountKeeper types.AccountKeeper - evmKeeper types.EVMKeeper -} - -func NewAppModule( - cdc codec.Codec, - keeper keeper.Keeper, - accountKeeper types.AccountKeeper, - evmKeeper types.EVMKeeper, -) AppModule { - return AppModule{ - AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, - accountKeeper: accountKeeper, - evmKeeper: evmKeeper, - } -} - -// Deprecated: use RegisterServices -func (am AppModule) Route() sdk.Route { return sdk.Route{} } - -// Deprecated: use RegisterServices -func (AppModule) QuerierRoute() string { return types.RouterKey } - -// Deprecated: use RegisterServices -func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { - return nil -} - -// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries -func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) -} - -// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// InitGenesis performs the module's genesis initialization. It returns no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { - var genState types.GenesisState - // Initialize global index to index in genesis state - cdc.MustUnmarshalJSON(gs, &genState) - - InitGenesis(ctx, am.keeper, genState) - - return []abci.ValidatorUpdate{} -} - -// ExportGenesis returns the module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) - return cdc.MustMarshalJSON(genState) -} - -// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 -func (AppModule) ConsensusVersion() uint64 { return 1 } - -// BeginBlock contains the logic that is automatically triggered at the beginning of each block -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock contains the logic that is automatically triggered at the end of each block -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} diff --git a/x/nftownership/types/codec.go b/x/nftownership/types/codec.go deleted file mode 100644 index 24b7f62e..00000000 --- a/x/nftownership/types/codec.go +++ /dev/null @@ -1,19 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" -) - -func RegisterCodec(_ *codec.LegacyAmino) { - // this line is used by starport scaffolding # 2 -} - -func RegisterInterfaces(_ cdctypes.InterfaceRegistry) { - // this line is used by starport scaffolding # 3 -} - -var ( - Amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/nftownership/types/errors.go b/x/nftownership/types/errors.go deleted file mode 100644 index ea7bca40..00000000 --- a/x/nftownership/types/errors.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -// DONTCOVER - -import ( - errorsmod "cosmossdk.io/errors" -) - -// ErrABIPack x/nftownership module sentinel errors -var ( - ErrABIPack = errorsmod.Register(ModuleName, 9, "contract ABI pack failed") - ErrInvalidChainId = errorsmod.Register(ModuleName, 10, "invalid chain id") - ErrEVMCallFailed = errorsmod.Register(ModuleName, 11, "evm call failed") -) diff --git a/x/nftownership/types/expected_keepers.go b/x/nftownership/types/expected_keepers.go deleted file mode 100644 index b50167a2..00000000 --- a/x/nftownership/types/expected_keepers.go +++ /dev/null @@ -1,43 +0,0 @@ -package types - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/vm" - - "github.com/settlus/chain/evmos/x/evm/statedb" - evmtypes "github.com/settlus/chain/evmos/x/evm/types" - oracletypes "github.com/settlus/chain/x/oracle/types" -) - -// AccountKeeper defines the expected account keeper used for simulations (noalias) -type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI - GetSequence(sdk.Context, sdk.AccAddress) (uint64, error) - SetModuleAccount(sdk.Context, authtypes.ModuleAccountI) -} - -// 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 -} - -// EVMKeeper defines the expected EVM keeper interface used on erc20 -type EVMKeeper interface { - GetParams(ctx sdk.Context) evmtypes.Params - GetAccountWithoutBalance(ctx sdk.Context, addr common.Address) *statedb.Account - EstimateGas(c context.Context, req *evmtypes.EthCallRequest) (*evmtypes.EstimateGasResponse, error) - ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*evmtypes.MsgEthereumTxResponse, error) - CallEVM(ctx sdk.Context, abi abi.ABI, from, contract common.Address, commit bool, method string, args ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) - CallEVMWithData(ctx sdk.Context, from common.Address, contract *common.Address, data []byte, commit bool) (*evmtypes.MsgEthereumTxResponse, error) -} - -type OracleKeeper interface { - GetBlockData(ctx sdk.Context, chainId string) (*oracletypes.BlockData, error) -} diff --git a/x/nftownership/types/genesis.go b/x/nftownership/types/genesis.go deleted file mode 100644 index f2689b73..00000000 --- a/x/nftownership/types/genesis.go +++ /dev/null @@ -1,20 +0,0 @@ -package types - -// DefaultIndex is the default global index -const DefaultIndex uint64 = 1 - -// DefaultGenesis returns the default genesis state -func DefaultGenesis() *GenesisState { - return &GenesisState{ - // this line is used by starport scaffolding # genesis/types/default - Params: DefaultParams(), - } -} - -// Validate performs basic genesis state validation returning an error upon any -// failure. -func (gs GenesisState) Validate() error { - // this line is used by starport scaffolding # genesis/types/validate - - return gs.Params.Validate() -} diff --git a/x/nftownership/types/genesis.pb.go b/x/nftownership/types/genesis.pb.go deleted file mode 100644 index 1c55e284..00000000 --- a/x/nftownership/types/genesis.pb.go +++ /dev/null @@ -1,323 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/nftownership/genesis.proto - -package types - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// GenesisState defines the nftownership module's genesis state. -type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` -} - -func (m *GenesisState) Reset() { *m = GenesisState{} } -func (m *GenesisState) String() string { return proto.CompactTextString(m) } -func (*GenesisState) ProtoMessage() {} -func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_637a918d49bc5895, []int{0} -} -func (m *GenesisState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { - xxx_messageInfo_GenesisState.Merge(m, src) -} -func (m *GenesisState) XXX_Size() int { - return m.Size() -} -func (m *GenesisState) XXX_DiscardUnknown() { - xxx_messageInfo_GenesisState.DiscardUnknown(m) -} - -var xxx_messageInfo_GenesisState proto.InternalMessageInfo - -func (m *GenesisState) GetParams() Params { - if m != nil { - return m.Params - } - return Params{} -} - -func init() { - proto.RegisterType((*GenesisState)(nil), "settlus.nftownership.GenesisState") -} - -func init() { - proto.RegisterFile("settlus/nftownership/genesis.proto", fileDescriptor_637a918d49bc5895) -} - -var fileDescriptor_637a918d49bc5895 = []byte{ - // 196 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2a, 0x4e, 0x2d, 0x29, - 0xc9, 0x29, 0x2d, 0xd6, 0xcf, 0x4b, 0x2b, 0xc9, 0x2f, 0xcf, 0x4b, 0x2d, 0x2a, 0xce, 0xc8, 0x2c, - 0xd0, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, - 0x81, 0xaa, 0xd1, 0x43, 0x56, 0x23, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa0, 0x0f, 0x62, - 0x41, 0xd4, 0x4a, 0x29, 0x62, 0x35, 0xaf, 0x20, 0xb1, 0x28, 0x31, 0x17, 0x6a, 0x9c, 0x92, 0x17, - 0x17, 0x8f, 0x3b, 0xc4, 0xfc, 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, 0x2b, 0x2e, 0x36, 0x88, 0xbc, - 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x8c, 0x1e, 0x36, 0xfb, 0xf4, 0x02, 0xc0, 0x6a, 0x9c, - 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xea, 0x70, 0x72, 0x3f, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, - 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, - 0xc6, 0x63, 0x39, 0x86, 0x28, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, - 0x7d, 0x98, 0x9b, 0x92, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x2b, 0x50, 0xdd, 0x56, 0x52, 0x59, 0x90, - 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0x9b, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xab, 0x43, 0x79, 0x4b, - 0x10, 0x01, 0x00, 0x00, -} - -func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { - offset -= sovGenesis(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *GenesisState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Params.Size() - n += 1 + l + sovGenesis(uint64(l)) - return n -} - -func sovGenesis(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGenesis(x uint64) (n int) { - return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *GenesisState) 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 ErrIntOverflowGenesis - } - 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: GenesisState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipGenesis(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthGenesis - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGenesis - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthGenesis - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/nftownership/types/genesis_test.go b/x/nftownership/types/genesis_test.go deleted file mode 100644 index 845a9bf0..00000000 --- a/x/nftownership/types/genesis_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package types_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/settlus/chain/x/nftownership/types" -) - -func TestGenesisState_Validate(t *testing.T) { - for _, tc := range []struct { - desc string - genState *types.GenesisState - valid bool - }{ - { - desc: "default is valid", - genState: types.DefaultGenesis(), - valid: true, - }, - { - desc: "valid genesis state", - genState: &types.GenesisState{ - - // this line is used by starport scaffolding # types/genesis/validField - }, - valid: true, - }, - // this line is used by starport scaffolding # types/genesis/testcase - } { - t.Run(tc.desc, func(t *testing.T) { - err := tc.genState.Validate() - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } -} diff --git a/x/nftownership/types/keys.go b/x/nftownership/types/keys.go deleted file mode 100644 index f97b75a9..00000000 --- a/x/nftownership/types/keys.go +++ /dev/null @@ -1,27 +0,0 @@ -package types - -import ( - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/ethereum/go-ethereum/common" -) - -const ( - // ModuleName defines the module name - ModuleName = "nftownership" - - // StoreKey defines the primary module store key - StoreKey = ModuleName - - // RouterKey defines the module's message routing key - RouterKey = ModuleName - - // MemStoreKey defines the in-memory store key - MemStoreKey = "mem_nftownership" -) - -// ModuleAddress is the native module address for EVM -var ModuleAddress common.Address - -func init() { - ModuleAddress = common.BytesToAddress(authtypes.NewModuleAddress(ModuleName).Bytes()) -} diff --git a/x/nftownership/types/params.go b/x/nftownership/types/params.go deleted file mode 100644 index f001c415..00000000 --- a/x/nftownership/types/params.go +++ /dev/null @@ -1,72 +0,0 @@ -package types - -import ( - "fmt" - - errorsmod "cosmossdk.io/errors" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "gopkg.in/yaml.v2" -) - -var ( - KeyAllowedChainIds = []byte("AllowedChainIds") -) - -var _ paramtypes.ParamSet = (*Params)(nil) - -// ParamKeyTable the param key table for launch module -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// DefaultParams returns a default set of parameters -func DefaultParams() Params { - return Params{ - AllowedChainIds: []string{}, - } -} - -// ParamSetPairs get the params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyAllowedChainIds, &p.AllowedChainIds, validateAllowedChainIds), - } -} - -func validateAllowedChainIds(i interface{}) error { - v, ok := i.([]string) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - for _, chainId := range v { - if chainId == "" { - return errorsmod.Wrapf(ErrInvalidChainId, "empty chain id") - } - } - - return nil -} - -// Validate validates the set of params -func (p Params) Validate() error { - chainIds := make(map[string]bool) - for _, chainId := range p.AllowedChainIds { - if chainId == "" { - return errorsmod.Wrapf(ErrInvalidChainId, "empty chain id") - } - - if _, ok := chainIds[chainId]; ok { - return errorsmod.Wrapf(ErrInvalidChainId, fmt.Sprintf("duplicate chain id: %s", chainId)) - } - chainIds[chainId] = true - } - - return nil -} - -// String implements the Stringer interface. -func (p Params) String() string { - out, _ := yaml.Marshal(p) - return string(out) -} diff --git a/x/nftownership/types/params.pb.go b/x/nftownership/types/params.pb.go deleted file mode 100644 index 1b9eadde..00000000 --- a/x/nftownership/types/params.pb.go +++ /dev/null @@ -1,321 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/nftownership/params.proto - -package types - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Params defines the parameters for the module. -type Params struct { - AllowedChainIds []string `protobuf:"bytes,1,rep,name=allowed_chain_ids,json=allowedChainIds,proto3" json:"allowed_chain_ids,omitempty"` -} - -func (m *Params) Reset() { *m = Params{} } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_f1478a27f8c9ce63, []int{0} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func (m *Params) GetAllowedChainIds() []string { - if m != nil { - return m.AllowedChainIds - } - return nil -} - -func init() { - proto.RegisterType((*Params)(nil), "settlus.nftownership.Params") -} - -func init() { proto.RegisterFile("settlus/nftownership/params.proto", fileDescriptor_f1478a27f8c9ce63) } - -var fileDescriptor_f1478a27f8c9ce63 = []byte{ - // 188 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2c, 0x4e, 0x2d, 0x29, - 0xc9, 0x29, 0x2d, 0xd6, 0xcf, 0x4b, 0x2b, 0xc9, 0x2f, 0xcf, 0x4b, 0x2d, 0x2a, 0xce, 0xc8, 0x2c, - 0xd0, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x81, - 0x2a, 0xd1, 0x43, 0x56, 0x22, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa0, 0x0f, 0x62, 0x41, - 0xd4, 0x2a, 0x59, 0x71, 0xb1, 0x05, 0x80, 0xf5, 0x0a, 0x69, 0x71, 0x09, 0x26, 0xe6, 0xe4, 0xe4, - 0x97, 0xa7, 0xa6, 0xc4, 0x27, 0x67, 0x24, 0x66, 0xe6, 0xc5, 0x67, 0xa6, 0x14, 0x4b, 0x30, 0x2a, - 0x30, 0x6b, 0x70, 0x06, 0xf1, 0x43, 0x25, 0x9c, 0x41, 0xe2, 0x9e, 0x29, 0xc5, 0x56, 0x2c, 0x33, - 0x16, 0xc8, 0x33, 0x38, 0xb9, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, - 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, - 0x6e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xcc, 0xbd, 0x60, 0x43, - 0xf5, 0x2b, 0x50, 0xdd, 0x5d, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0x8b, 0x31, 0x20, - 0x00, 0x00, 0xff, 0xff, 0x4e, 0x73, 0xd9, 0x39, 0xdc, 0x00, 0x00, 0x00, -} - -func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.AllowedChainIds) > 0 { - for iNdEx := len(m.AllowedChainIds) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.AllowedChainIds[iNdEx]) - copy(dAtA[i:], m.AllowedChainIds[iNdEx]) - i = encodeVarintParams(dAtA, i, uint64(len(m.AllowedChainIds[iNdEx]))) - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func encodeVarintParams(dAtA []byte, offset int, v uint64) int { - offset -= sovParams(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.AllowedChainIds) > 0 { - for _, s := range m.AllowedChainIds { - l = len(s) - n += 1 + l + sovParams(uint64(l)) - } - } - return n -} - -func sovParams(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozParams(x uint64) (n int) { - return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) 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 ErrIntOverflowParams - } - 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: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AllowedChainIds", 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.AllowedChainIds = append(m.AllowedChainIds, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipParams(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipParams(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthParams - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupParams - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthParams - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/nftownership/types/params_test.go b/x/nftownership/types/params_test.go deleted file mode 100644 index 11a3adaa..00000000 --- a/x/nftownership/types/params_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package types - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestParams(t *testing.T) { - p1 := DefaultParams() - err := p1.Validate() - require.NoError(t, err) - - // empty string as chain id - p2 := DefaultParams() - p2.AllowedChainIds = []string{""} - err = p2.Validate() - require.Error(t, err) - - // duplicate chain id - p3 := DefaultParams() - p3.AllowedChainIds = []string{"chain1", "chain1"} - err = p3.Validate() - require.Error(t, err) -} diff --git a/x/nftownership/types/query.pb.go b/x/nftownership/types/query.pb.go deleted file mode 100644 index d7c68fe2..00000000 --- a/x/nftownership/types/query.pb.go +++ /dev/null @@ -1,1028 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/nftownership/query.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - grpc1 "github.com/gogo/protobuf/grpc" - proto "github.com/gogo/protobuf/proto" - _ "google.golang.org/genproto/googleapis/api/annotations" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// QueryParamsRequest is request type for the Query/Params RPC method. -type QueryParamsRequest struct { -} - -func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } -func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryParamsRequest) ProtoMessage() {} -func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b1059a197ab5bd20, []int{0} -} -func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryParamsRequest.Merge(m, src) -} -func (m *QueryParamsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryParamsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo - -// QueryParamsResponse is response type for the Query/Params RPC method. -type QueryParamsResponse struct { - // params holds all the parameters of this module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` -} - -func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } -func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryParamsResponse) ProtoMessage() {} -func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b1059a197ab5bd20, []int{1} -} -func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryParamsResponse.Merge(m, src) -} -func (m *QueryParamsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryParamsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo - -func (m *QueryParamsResponse) GetParams() Params { - if m != nil { - return m.Params - } - return Params{} -} - -// QueryGetNftOwnerRequest is request type for the Query/GetNftOwner RPC method. -type QueryGetNftOwnerRequest struct { - ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - ContractAddress string `protobuf:"bytes,2,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` - TokenIdHex string `protobuf:"bytes,3,opt,name=token_id_hex,json=tokenIdHex,proto3" json:"token_id_hex,omitempty"` -} - -func (m *QueryGetNftOwnerRequest) Reset() { *m = QueryGetNftOwnerRequest{} } -func (m *QueryGetNftOwnerRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetNftOwnerRequest) ProtoMessage() {} -func (*QueryGetNftOwnerRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b1059a197ab5bd20, []int{2} -} -func (m *QueryGetNftOwnerRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetNftOwnerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetNftOwnerRequest.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 *QueryGetNftOwnerRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetNftOwnerRequest.Merge(m, src) -} -func (m *QueryGetNftOwnerRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryGetNftOwnerRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetNftOwnerRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetNftOwnerRequest proto.InternalMessageInfo - -func (m *QueryGetNftOwnerRequest) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" -} - -func (m *QueryGetNftOwnerRequest) GetContractAddress() string { - if m != nil { - return m.ContractAddress - } - return "" -} - -func (m *QueryGetNftOwnerRequest) GetTokenIdHex() string { - if m != nil { - return m.TokenIdHex - } - return "" -} - -// QueryGetNftOwnerResponse is response type for the Query/GetNftOwner RPC -// method. -type QueryGetNftOwnerResponse struct { - OwnerAddress string `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"` -} - -func (m *QueryGetNftOwnerResponse) Reset() { *m = QueryGetNftOwnerResponse{} } -func (m *QueryGetNftOwnerResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetNftOwnerResponse) ProtoMessage() {} -func (*QueryGetNftOwnerResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b1059a197ab5bd20, []int{3} -} -func (m *QueryGetNftOwnerResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryGetNftOwnerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryGetNftOwnerResponse.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 *QueryGetNftOwnerResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetNftOwnerResponse.Merge(m, src) -} -func (m *QueryGetNftOwnerResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryGetNftOwnerResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetNftOwnerResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryGetNftOwnerResponse proto.InternalMessageInfo - -func (m *QueryGetNftOwnerResponse) GetOwnerAddress() string { - if m != nil { - return m.OwnerAddress - } - return "" -} - -func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "settlus.nftownership.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "settlus.nftownership.QueryParamsResponse") - proto.RegisterType((*QueryGetNftOwnerRequest)(nil), "settlus.nftownership.QueryGetNftOwnerRequest") - proto.RegisterType((*QueryGetNftOwnerResponse)(nil), "settlus.nftownership.QueryGetNftOwnerResponse") -} - -func init() { proto.RegisterFile("settlus/nftownership/query.proto", fileDescriptor_b1059a197ab5bd20) } - -var fileDescriptor_b1059a197ab5bd20 = []byte{ - // 440 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x86, 0xbd, 0x01, 0x02, 0x6c, 0x8b, 0x40, 0x4b, 0x24, 0x8c, 0x15, 0x99, 0x60, 0x38, 0xb4, - 0x87, 0x7a, 0xa5, 0x72, 0xe3, 0x82, 0xe8, 0xa5, 0xf4, 0x02, 0xad, 0x4f, 0x88, 0x8b, 0xb5, 0xb5, - 0x37, 0xb6, 0x45, 0xbb, 0xeb, 0x7a, 0xc7, 0x22, 0x55, 0x94, 0x03, 0xf0, 0x02, 0x48, 0xbc, 0x13, - 0xea, 0x31, 0x12, 0x12, 0xe2, 0x84, 0x50, 0xc2, 0x83, 0x20, 0xaf, 0x37, 0x51, 0xd2, 0x58, 0x51, - 0x6e, 0xf6, 0xef, 0x6f, 0xe6, 0xff, 0x67, 0xc6, 0xb8, 0xa7, 0x38, 0xc0, 0x59, 0xa9, 0xa8, 0xe8, - 0x83, 0xfc, 0x24, 0x78, 0xa1, 0xd2, 0x2c, 0xa7, 0x17, 0x25, 0x2f, 0x2e, 0xfd, 0xbc, 0x90, 0x20, - 0x49, 0xc7, 0x10, 0xfe, 0x22, 0xe1, 0x74, 0x12, 0x99, 0x48, 0x0d, 0xd0, 0xea, 0xa9, 0x66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 0x4e, 0xf3, 0x16, 0x56, 0xd7, 0xea, 0xec, 0x6e, 0x40, 0xd6, 0x71, - 0xbc, 0xe7, 0x5f, 0x7e, 0xfe, 0xfb, 0xde, 0x72, 0x49, 0x97, 0xae, 0xb9, 0x21, 0xf9, 0x81, 0xf0, - 0xd6, 0xc2, 0x30, 0x64, 0x6f, 0x8d, 0xc1, 0xea, 0xde, 0x1d, 0x7f, 0x53, 0xdc, 0x84, 0x7a, 0xaf, - 0x43, 0x05, 0xe4, 0xb8, 0x39, 0x54, 0xc2, 0x21, 0x14, 0x7d, 0x08, 0xb5, 0x42, 0x87, 0xb3, 0x93, - 0x8e, 0xe8, 0xf0, 0xfa, 0x09, 0x47, 0x74, 0xb8, 0x78, 0xaa, 0xd1, 0xc1, 0xe1, 0xd5, 0xc4, 0x45, - 0xe3, 0x89, 0x8b, 0xfe, 0x4e, 0x5c, 0xf4, 0x6d, 0xea, 0x5a, 0xe3, 0xa9, 0x6b, 0xfd, 0x9e, 0xba, - 0xd6, 0x87, 0xbd, 0x24, 0x83, 0xb4, 0x3c, 0xf5, 0x23, 0x79, 0x3e, 0x77, 0xd5, 0x9d, 0xe9, 0x60, - 0xd9, 0x1d, 0x2e, 0x73, 0xae, 0x4e, 0xdb, 0xfa, 0xb7, 0x7e, 0xf1, 0x3f, 0x00, 0x00, 0xff, 0xff, - 0x0e, 0x63, 0xdd, 0x7e, 0x67, 0x03, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// QueryClient is the client API for Query service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type QueryClient interface { - // Parameters queries the parameters of the module. - Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // Queries a list of GetNftOwner items. - GetNftOwner(ctx context.Context, in *QueryGetNftOwnerRequest, opts ...grpc.CallOption) (*QueryGetNftOwnerResponse, error) -} - -type queryClient struct { - cc grpc1.ClientConn -} - -func NewQueryClient(cc grpc1.ClientConn) QueryClient { - return &queryClient{cc} -} - -func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { - out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/settlus.nftownership.Query/Params", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) GetNftOwner(ctx context.Context, in *QueryGetNftOwnerRequest, opts ...grpc.CallOption) (*QueryGetNftOwnerResponse, error) { - out := new(QueryGetNftOwnerResponse) - err := c.cc.Invoke(ctx, "/settlus.nftownership.Query/GetNftOwner", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// QueryServer is the server API for Query service. -type QueryServer interface { - // Parameters queries the parameters of the module. - Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // Queries a list of GetNftOwner items. - GetNftOwner(context.Context, *QueryGetNftOwnerRequest) (*QueryGetNftOwnerResponse, error) -} - -// UnimplementedQueryServer can be embedded to have forward compatible implementations. -type UnimplementedQueryServer struct { -} - -func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") -} -func (*UnimplementedQueryServer) GetNftOwner(ctx context.Context, req *QueryGetNftOwnerRequest) (*QueryGetNftOwnerResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetNftOwner not implemented") -} - -func RegisterQueryServer(s grpc1.Server, srv QueryServer) { - s.RegisterService(&_Query_serviceDesc, srv) -} - -func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryParamsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Params(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/settlus.nftownership.Query/Params", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_GetNftOwner_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetNftOwnerRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).GetNftOwner(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/settlus.nftownership.Query/GetNftOwner", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetNftOwner(ctx, req.(*QueryGetNftOwnerRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "settlus.nftownership.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Params", - Handler: _Query_Params_Handler, - }, - { - MethodName: "GetNftOwner", - Handler: _Query_GetNftOwner_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "settlus/nftownership/query.proto", -} - -func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *QueryGetNftOwnerRequest) 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 *QueryGetNftOwnerRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetNftOwnerRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.TokenIdHex) > 0 { - i -= len(m.TokenIdHex) - copy(dAtA[i:], m.TokenIdHex) - i = encodeVarintQuery(dAtA, i, uint64(len(m.TokenIdHex))) - i-- - dAtA[i] = 0x1a - } - if len(m.ContractAddress) > 0 { - i -= len(m.ContractAddress) - copy(dAtA[i:], m.ContractAddress) - i = encodeVarintQuery(dAtA, i, uint64(len(m.ContractAddress))) - i-- - dAtA[i] = 0x12 - } - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintQuery(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryGetNftOwnerResponse) 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 *QueryGetNftOwnerResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetNftOwnerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.OwnerAddress) > 0 { - i -= len(m.OwnerAddress) - copy(dAtA[i:], m.OwnerAddress) - i = encodeVarintQuery(dAtA, i, uint64(len(m.OwnerAddress))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *QueryParamsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryParamsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Params.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - -func (m *QueryGetNftOwnerRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.ContractAddress) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.TokenIdHex) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryGetNftOwnerResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.OwnerAddress) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozQuery(x uint64) (n int) { - return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *QueryParamsRequest) 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 ErrIntOverflowQuery - } - 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: QueryParamsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryParamsResponse) 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 ErrIntOverflowQuery - } - 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: QueryParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetNftOwnerRequest) 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 ErrIntOverflowQuery - } - 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: QueryGetNftOwnerRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetNftOwnerRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ContractAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ContractAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TokenIdHex", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TokenIdHex = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetNftOwnerResponse) 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 ErrIntOverflowQuery - } - 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: QueryGetNftOwnerResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetNftOwnerResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OwnerAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.OwnerAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipQuery(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthQuery - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupQuery - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthQuery - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/nftownership/types/query.pb.gw.go b/x/nftownership/types/query.pb.gw.go deleted file mode 100644 index 103ee313..00000000 --- a/x/nftownership/types/query.pb.gw.go +++ /dev/null @@ -1,298 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: settlus/nftownership/query.proto - -/* -Package types is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package types - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage -var _ = metadata.Join - -func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryParamsRequest - var metadata runtime.ServerMetadata - - msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryParamsRequest - var metadata runtime.ServerMetadata - - msg, err := server.Params(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_GetNftOwner_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetNftOwnerRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["chain_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") - } - - protoReq.ChainId, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) - } - - val, ok = pathParams["contract_address"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contract_address") - } - - protoReq.ContractAddress, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contract_address", err) - } - - val, ok = pathParams["token_id_hex"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "token_id_hex") - } - - protoReq.TokenIdHex, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "token_id_hex", err) - } - - msg, err := client.GetNftOwner(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_GetNftOwner_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetNftOwnerRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["chain_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_id") - } - - protoReq.ChainId, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_id", err) - } - - val, ok = pathParams["contract_address"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contract_address") - } - - protoReq.ContractAddress, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contract_address", err) - } - - val, ok = pathParams["token_id_hex"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "token_id_hex") - } - - protoReq.TokenIdHex, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "token_id_hex", err) - } - - msg, err := server.GetNftOwner(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". -// UnaryRPC :call QueryServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. -func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetNftOwner_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_GetNftOwner_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetNftOwner_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterQueryHandler(ctx, mux, conn) -} - -// RegisterQueryHandler registers the http handlers for service Query to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) -} - -// RegisterQueryHandlerClient registers the http handlers for service Query -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "QueryClient" to call the correct interceptors. -func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_GetNftOwner_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_GetNftOwner_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_GetNftOwner_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"settlus", "nftownership", "params"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_GetNftOwner_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"settlus", "nftownership", "get_nft_owner", "chain_id", "contract_address", "token_id_hex"}, "", runtime.AssumeColonVerbOpt(false))) -) - -var ( - forward_Query_Params_0 = runtime.ForwardResponseMessage - - forward_Query_GetNftOwner_0 = runtime.ForwardResponseMessage -) diff --git a/x/oracle/abci.go b/x/oracle/abci.go index 4e298d68..91262b8c 100644 --- a/x/oracle/abci.go +++ b/x/oracle/abci.go @@ -8,6 +8,7 @@ import ( "github.com/settlus/chain/x/oracle/keeper" "github.com/settlus/chain/x/oracle/types" + "github.com/settlus/chain/x/oracle/voteprocessor" ) // EndBlocker runs at the end of every block @@ -24,16 +25,14 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { logger := k.Logger(ctx) - // Build claim map over all validators in active set - validatorClaimMap := make(map[string]types.Claim) - - whitelistChainCount := len(params.Whitelist) maxValidators := k.StakingKeeper.MaxValidators(ctx) iterator := k.StakingKeeper.ValidatorsPowerStoreIterator(ctx) defer iterator.Close() // Add all active validators to the claim map i := 0 + // Build claim map over all validators in active set + validatorClaimMap := make(map[string]types.Claim) for ; iterator.Valid() && i < int(maxValidators); iterator.Next() { validator, found := k.StakingKeeper.GetValidator(ctx, iterator.Value()) if !found { @@ -44,10 +43,9 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { if validator.IsBonded() && !validator.IsJailed() { valAddr := validator.GetOperator() validatorClaimMap[valAddr.String()] = types.Claim{ - Weight: validator.GetConsensusPower(k.StakingKeeper.PowerReduction(ctx)), - MissCount: int64(whitelistChainCount), - Recipient: valAddr, - Abstain: false, + Weight: validator.GetConsensusPower(k.StakingKeeper.PowerReduction(ctx)), + Miss: false, + Abstain: false, } i++ } @@ -59,72 +57,32 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { voteThreshold := params.VoteThreshold thresholdVotes := voteThreshold.MulInt64(totalBondedPower).RoundInt() - // Organize votes by chain IDs - votesByChainId := k.GroupVotesByChainId(ctx) - voteResults := types.TallyVotes(votesByChainId, validatorClaimMap, thresholdVotes) - - // set block data - for chainId, blockData := range voteResults { - if blockData == nil { - logger.Debug("consensus failed") - if err := ctx.EventManager().EmitTypedEvent(&types.EventOracleConsensusFailed{ - ChainId: chainId, - BlockHeight: ctx.BlockHeight(), - }); err != nil { - logger.Error("failed to emit event", "error", err) - } + // Get all aggregate votes + aggregateVotes := k.GetAggregateVotes(ctx) - continue + // Check abstain + for _, vote := range aggregateVotes { + if len(vote.VoteData) == 0 { + claim := validatorClaimMap[vote.Voter] + claim.Abstain = true } - k.SetBlockData(ctx, *blockData) } - // increase win count for validators who voted for the winning block data - for chainId, vote := range votesByChainId { - correctBlockData := voteResults[chainId] - - if correctBlockData == nil { - continue - } - - for _, voteData := range vote { - claim, ok := validatorClaimMap[voteData.Voter.String()] - if !ok { - // if the validator is not in the active set or is jailed, skip - logger.Info("validator not found in active set", "validator", voteData.Voter.String()) - continue - } - - // if abstain flag is set, continue - if claim.Abstain { - continue - } - - // if the validator voted abstain, set abstain flag to true and continue - if voteData.BlockData.BlockNumber < 0 { - claim.Abstain = true - validatorClaimMap[voteData.Voter.String()] = claim - continue - } - - // if the validator did not abstain and voted for the block number outside the tolerated error band, increase miss count - if *voteData.BlockData == *correctBlockData { - claim.MissCount-- - validatorClaimMap[voteData.Voter.String()] = claim - } - } + vps := voteprocessor.NewSettlusVoteProcessors(k, aggregateVotes, thresholdVotes) + for _, vp := range vps { + vp.TallyVotes(ctx, validatorClaimMap) } // do miss counting - for _, claim := range validatorClaimMap { - if claim.MissCount > 0 { + for addr, claim := range validatorClaimMap { + if claim.Miss { // get miss count and increase it by 1 - k.SetMissCount(ctx, claim.Recipient.String(), k.GetMissCount(ctx, claim.Recipient.String())+1) + k.SetMissCount(ctx, addr, k.GetMissCount(ctx, addr)+1) } } // distribute rewards to winners - if err := k.RewardBallotWinners(ctx, &validatorClaimMap); err != nil { + if err := k.RewardBallotWinners(ctx, validatorClaimMap); err != nil { logger.Error("failed to distribute rewards", "error", err) } @@ -136,12 +94,3 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { k.SlashValidatorsAndResetMissCount(ctx) } } - -// Abs returns the absolute value of x. -// (How is this not included in the Go standard library? Math.abs() is only for float64.) -func Abs(x int64) int64 { - if x < 0 { - return -x - } - return x -} diff --git a/x/oracle/client/cli/tx.go b/x/oracle/client/cli/tx.go index d531c439..b6c6175c 100644 --- a/x/oracle/client/cli/tx.go +++ b/x/oracle/client/cli/tx.go @@ -74,14 +74,15 @@ func CmdPrevote() *cobra.Command { // CmdVote is the CLI command for sending a Vote message func CmdVote() *cobra.Command { cmd := &cobra.Command{ - Use: "vote [validator] [blockData] [salt] [roundId]", + Use: "vote [validator] [topic] [data] [salt] [roundId]", Short: "Broadcast message vote", - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(5), RunE: func(cmd *cobra.Command, args []string) (err error) { argValidator := args[0] - argBlockDataStr := args[1] - argSalt := args[2] - argRoundId := args[3] + argTopic := args[1] + argData := args[2] + argSalt := args[3] + argRoundId := args[4] roundId, err := cast.ToUint64E(argRoundId) if err != nil { return err @@ -92,12 +93,22 @@ func CmdVote() *cobra.Command { return err } + topic, err := TopicStringToEnum(argTopic) + if err != nil { + return err + } + feeder := clientCtx.GetFromAddress().String() msg := types.NewMsgVote( feeder, argValidator, - argBlockDataStr, + []*types.VoteData{ + { + Topic: topic, + Data: []string{argData}, + }, + }, argSalt, roundId, ) @@ -144,3 +155,14 @@ func CmdFeederDelegationConsent() *cobra.Command { return cmd } + +func TopicStringToEnum(topic string) (types.OralceTopic, error) { + switch topic { + case "block": + return types.OralceTopic_BLOCK, nil + case "nft": + return types.OralceTopic_OWNERSHIP, nil + default: + return 0, fmt.Errorf("invalid topic: %s", topic) + } +} diff --git a/x/oracle/keeper/feeder.go b/x/oracle/keeper/feeder.go new file mode 100644 index 00000000..9d63d5f9 --- /dev/null +++ b/x/oracle/keeper/feeder.go @@ -0,0 +1,387 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/settlus/chain/x/oracle/types" +) + +// GetFeederDelegation returns feeder delegation of a validator +func (k Keeper) GetFeederDelegation(ctx sdk.Context, validatorAddr string) sdk.AccAddress { + store := ctx.KVStore(k.storeKey) + fd := store.Get(types.FeederDelegationKey(validatorAddr)) + if fd == nil { + // By default, validator is its own feeder + validator, _ := sdk.ValAddressFromBech32(validatorAddr) + return sdk.AccAddress(validator.Bytes()) + } + return fd +} + +// GetFeederDelegations returns feeder delegations of all validators +func (k Keeper) GetFeederDelegations(ctx sdk.Context) []types.FeederDelegation { + store := ctx.KVStore(k.storeKey) + var feederDelegations []types.FeederDelegation + iterator := sdk.KVStorePrefixIterator(store, types.FeederDelegationKeyPrefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + validatorAddr := string(iterator.Key()[1:]) + feederAddr := string(iterator.Value()) + feederDelegations = append(feederDelegations, types.FeederDelegation{ + ValidatorAddress: validatorAddr, + FeederAddress: feederAddr, + }) + } + + return feederDelegations +} + +// SetFeederDelegation sets feeder delegation of a validator +func (k Keeper) SetFeederDelegation(ctx sdk.Context, validatorAddr string, feederAddr string) error { + feeder, err := sdk.AccAddressFromBech32(feederAddr) + if err != nil { + return errorsmod.Wrapf(types.ErrInvalidFeeder, "feeder address %s is invalid", feederAddr) + } + + store := ctx.KVStore(k.storeKey) + store.Set(types.FeederDelegationKey(validatorAddr), feeder.Bytes()) + return nil +} + +// ValidateFeeder validates if the feeder has permission to vote for the validator +func (k Keeper) ValidateFeeder(ctx sdk.Context, feederAddr string, validatorAddr string) (bool, error) { + validator, err := sdk.ValAddressFromBech32(validatorAddr) + if err != nil { + return false, errorsmod.Wrapf(types.ErrInvalidValidator, "validator address %s is invalid", validatorAddr) + } + + if val, found := k.StakingKeeper.GetValidator(ctx, validator); !found || !val.IsBonded() { + return false, errorsmod.Wrapf(types.ErrValidatorNotFound, "validator %s is not active", validator.String()) + } + + feeder, err := sdk.AccAddressFromBech32(feederAddr) + if err != nil { + return false, errorsmod.Wrapf(types.ErrInvalidFeeder, "feeder address %s is invalid", feederAddr) + } + + if !feeder.Equals(validator) { + delegation := k.GetFeederDelegation(ctx, validatorAddr) + if !delegation.Equals(feeder) { + return false, errorsmod.Wrapf(types.ErrNoVotingPermission, "feeder %s has no permission to vote for validator %s", feeder, validator) + } + } + + return true, nil +} + +// GetMissCount returns miss count of a validator +func (k Keeper) GetMissCount(ctx sdk.Context, validatorAddr string) uint64 { + store := ctx.KVStore(k.storeKey) + mc := store.Get(types.MissCountKey(validatorAddr)) + if mc == nil { + return 0 + } + return sdk.BigEndianToUint64(mc) +} + +// GetMissCounts returns miss counts of all validators +func (k Keeper) GetMissCounts(ctx sdk.Context) []types.MissCount { + var missCounts []types.MissCount + k.IterateMissCount(ctx, func(validatorAddr string, missCount uint64) (stop bool) { + missCounts = append(missCounts, types.MissCount{ + ValidatorAddress: validatorAddr, + MissCount: missCount, + }) + return false + }) + return missCounts +} + +// SetMissCount sets miss count of a validator +func (k Keeper) SetMissCount(ctx sdk.Context, validatorAddr string, missCount uint64) { + store := ctx.KVStore(k.storeKey) + store.Set(types.MissCountKey(validatorAddr), sdk.Uint64ToBigEndian(missCount)) +} + +func (k Keeper) DeleteMissCount(ctx sdk.Context, validatorAddr string) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.MissCountKey(validatorAddr)) +} + +func (k Keeper) IterateMissCount(ctx sdk.Context, handler func(validatorAddr string, missCount uint64) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.MissCountKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + validatorAddr := string(iter.Key()[1:]) + missCount := sdk.BigEndianToUint64(iter.Value()) + + if handler(validatorAddr, missCount) { + break + } + } +} + +// GetRewardPool returns the current reward pool balance +func (k Keeper) GetRewardPool(ctx sdk.Context) sdk.Coins { + addr := k.AccountKeeper.GetModuleAddress(types.ModuleName) + if addr == nil { + panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) + } + + return k.BankKeeper.GetAllBalances(ctx, addr) +} + +/********************* Prevote *********************/ + +// GetAggregatePrevote returns aggregate prevote of a validator +func (k Keeper) GetAggregatePrevote(ctx sdk.Context, validatorAddr string) *types.AggregatePrevote { + store := ctx.KVStore(k.storeKey) + ap := store.Get(types.AggregatePrevoteKey(validatorAddr)) + if ap == nil { + return nil + } + var aggregatePrevote types.AggregatePrevote + k.cdc.MustUnmarshal(ap, &aggregatePrevote) + return &aggregatePrevote +} + +// GetAggregatePrevotes returns aggregate prevotes of all validators +func (k Keeper) GetAggregatePrevotes(ctx sdk.Context) []types.AggregatePrevote { + store := ctx.KVStore(k.storeKey) + var aggregatePrevotes []types.AggregatePrevote + iterator := sdk.KVStorePrefixIterator(store, types.AggregatePrevoteKeyPrefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var ap types.AggregatePrevote + k.cdc.MustUnmarshal(iterator.Value(), &ap) + aggregatePrevotes = append(aggregatePrevotes, ap) + } + return aggregatePrevotes +} + +// GetAggregatePrevoteStore returns a new KV store from aggregate prevote prefix +func (k Keeper) GetAggregatePrevoteStore(ctx sdk.Context) sdk.KVStore { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.AggregatePrevoteKeyPrefix) +} + +// SetAggregatePrevote sets aggregate prevote of a validator +func (k Keeper) SetAggregatePrevote(ctx sdk.Context, aggregatePrevote types.AggregatePrevote) { + store := ctx.KVStore(k.storeKey) + ap := k.cdc.MustMarshal(&aggregatePrevote) + store.Set(types.AggregatePrevoteKey(aggregatePrevote.Voter), ap) +} + +// DeleteAggregatePrevote deletes aggregate prevote of a validator +func (k Keeper) DeleteAggregatePrevote(ctx sdk.Context, validatorAddress string) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.AggregatePrevoteKey(validatorAddress)) +} + +// IterateAggregatePrevotes iterates over prevotes in the store +func (k Keeper) IterateAggregatePrevotes(ctx sdk.Context, handler func(voterAddr string, aggregatePrevote types.AggregatePrevote) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.AggregatePrevoteKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + voterAddr := string(iter.Key()[1:]) + var aggregatePrevote types.AggregatePrevote + k.cdc.MustUnmarshal(iter.Value(), &aggregatePrevote) + + if handler(voterAddr, aggregatePrevote) { + break + } + } +} + +/********************* Vote *********************/ + +// GetAggregateVote returns aggregate vote of a validator +func (k Keeper) GetAggregateVote(ctx sdk.Context, validatorAddr string) *types.AggregateVote { + store := ctx.KVStore(k.storeKey) + av := store.Get(types.AggregateVoteKey(validatorAddr)) + if av == nil { + return nil + } + var aggregateVote types.AggregateVote + k.cdc.MustUnmarshal(av, &aggregateVote) + return &aggregateVote +} + +// GetAggregateVotes returns aggregate votes of all validators +func (k Keeper) GetAggregateVotes(ctx sdk.Context) []types.AggregateVote { + store := ctx.KVStore(k.storeKey) + var aggregateVotes []types.AggregateVote + iterator := sdk.KVStorePrefixIterator(store, types.AggregateVoteKeyPrefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var av types.AggregateVote + k.cdc.MustUnmarshal(iterator.Value(), &av) + aggregateVotes = append(aggregateVotes, av) + } + return aggregateVotes +} + +// GetAggregateVoteStore returns a new KV store from aggregate vote prefix +func (k Keeper) GetAggregateVoteStore(ctx sdk.Context) sdk.KVStore { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.AggregateVoteKeyPrefix) +} + +// SetAggregateVote sets aggregate vote of a validator +func (k Keeper) SetAggregateVote(ctx sdk.Context, aggregateVote types.AggregateVote) { + store := ctx.KVStore(k.storeKey) + av := k.cdc.MustMarshal(&aggregateVote) + store.Set(types.AggregateVoteKey(aggregateVote.Voter), av) +} + +// DeleteAggregateVote deletes aggregate vote of a validator +func (k Keeper) DeleteAggregateVote(ctx sdk.Context, validator string) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.AggregateVoteKey(validator)) +} + +// IterateAggregateVotes iterates rate over votes in the store +func (k Keeper) IterateAggregateVotes(ctx sdk.Context, handler func(voterAddr string, aggregateVote types.AggregateVote) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.AggregateVoteKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + voterAddr := string(iter.Key()[1:]) + var aggregateVote types.AggregateVote + k.cdc.MustUnmarshal(iter.Value(), &aggregateVote) + + if handler(voterAddr, aggregateVote) { + break + } + } +} + +/********************* Ballots & Validators *********************/ + +// RewardBallotWinners distributes rewards to validators who voted for the winning block data +func (k Keeper) RewardBallotWinners(ctx sdk.Context, validatorClaimMap map[string]types.Claim) error { + weightSum := int64(0) + for _, claim := range validatorClaimMap { + if !claim.Miss && !claim.Abstain { + weightSum += claim.Weight + } + } + + if weightSum == 0 { + return nil + } + + // distribute rewards in proportion to the voting power + rewards := sdk.NewDecCoinsFromCoins(k.GetRewardPool(ctx)...) + if rewards.IsZero() { + return nil + } + + logger := k.Logger(ctx) + logger.Debug("RewardBallotWinner", "rewards", rewards) + + var distributedReward sdk.Coins + + for addr, voter := range validatorClaimMap { + // skip if the validator abstained or missed the vote + if voter.Abstain || voter.Miss { + logger.Debug(fmt.Sprintf("no reward %s(%s)", + addr, + addr), + "miss count in the current ballot", voter.Miss, + "abstain", voter.Abstain, + ) + continue + } + + // multiply the reward by the weight of the validator + // rewardCoins = rewards * (weight / weightSum) + rewardCoins, _ := rewards.MulDec(sdk.NewDec(voter.Weight).QuoInt64(weightSum)).TruncateDecimal() + + // distribute reward to the validator + valAddr, _ := sdk.ValAddressFromBech32(addr) + receiverVal, ok := k.StakingKeeper.GetValidator(ctx, valAddr) + if !ok { + return fmt.Errorf("validator not found: %s", valAddr) + } + + if !rewardCoins.IsZero() { + k.DistributionKeeper.AllocateTokensToValidator(ctx, receiverVal, sdk.NewDecCoinsFromCoins(rewardCoins...)) + distributedReward = distributedReward.Add(rewardCoins...) + } else { + logger.Debug(fmt.Sprintf("no reward %s(%s)", + receiverVal.GetMoniker(), + receiverVal.GetOperator().String()), + "weight", voter.Weight, + ) + } + } + + // Move distributed reward to distribution module + if err := k.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.distributionName, distributedReward); err != nil { + return fmt.Errorf("failed to move distributed reward to distribution module: %w", err) + } + + return nil +} + +func (k Keeper) ClearBallots(ctx sdk.Context) { + // Clear all aggregate prevotes + k.IterateAggregatePrevotes(ctx, func(validatorAddress string, aggregatePrevote types.AggregatePrevote) (stop bool) { + k.DeleteAggregatePrevote(ctx, validatorAddress) + return false + }) + + // Clear all aggregate votes + k.IterateAggregateVotes(ctx, func(validatorAddress string, aggregateVote types.AggregateVote) (stop bool) { + k.DeleteAggregateVote(ctx, validatorAddress) + return false + }) +} + +// SlashValidatorsAndResetMissCount slashes validators who missed the vote more than MaxMissCountPerSlashWindow +// and resets miss count of all validators +func (k Keeper) SlashValidatorsAndResetMissCount(ctx sdk.Context) { + logger := k.Logger(ctx) + height := ctx.BlockHeight() + distributionHeight := height - sdk.ValidatorUpdateDelay - 1 + powerReduction := k.StakingKeeper.PowerReduction(ctx) + params := k.GetParams(ctx) + MaxMissCountPerSlashWindow := params.MaxMissCountPerSlashWindow + slashFraction := params.SlashFraction + + k.IterateMissCount(ctx, func(operatorAddress string, missCount uint64) (stop bool) { + if missCount > MaxMissCountPerSlashWindow { + // slash validator if the validator missed the vote more than MaxMissCountPerSlashWindow + validatorAddress, err := sdk.ValAddressFromBech32(operatorAddress) + if err != nil { + panic(fmt.Errorf("failed to parse validator address from store: %w", err)) + } + validator, ok := k.StakingKeeper.GetValidator(ctx, validatorAddress) + if !ok { + logger.Debug(fmt.Sprintf("validator not found: %s", operatorAddress)) + } + + if validator.IsBonded() && !validator.IsJailed() { + consAddr, err := validator.GetConsAddr() + if err != nil { + panic(fmt.Errorf("failed to get consensus address from validator: %w", err)) + } + + k.StakingKeeper.Slash( + ctx, consAddr, + distributionHeight, validator.GetConsensusPower(powerReduction), slashFraction, + ) + k.StakingKeeper.Jail(ctx, consAddr) + } + } + + k.DeleteMissCount(ctx, operatorAddress) + return false + }) +} diff --git a/x/oracle/keeper/integration_test.go b/x/oracle/keeper/integration_test.go index 72bdcdcd..951d2f90 100644 --- a/x/oracle/keeper/integration_test.go +++ b/x/oracle/keeper/integration_test.go @@ -25,7 +25,7 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { }) blockHash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" - blockDataStr := types.BlockDataToString(&types.BlockData{ChainId: "1", BlockNumber: 100, BlockHash: blockHash}) + voteData := types.BlockDataToVoteData(&types.BlockData{ChainId: "1", BlockNumber: 100, BlockHash: blockHash}) Context("Test oracle consensus threshold", func() { BeforeEach(func() { @@ -33,7 +33,7 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { It("Less than the threshold signs, block data consensus fails", func() { salt := "1" validator := s.validators[0] - SendPrevoteAndVote(validator, blockDataStr, salt, 0) + SendPrevoteAndVote(validator, voteData, salt, 0) oracle.EndBlocker(s.ctx, *s.app.OracleKeeper) @@ -45,7 +45,7 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { // All validators sign for i, validator := range s.validators { salt := fmt.Sprintf("%d", i) - SendPrevoteAndVote(validator, blockDataStr, salt, 0) + SendPrevoteAndVote(validator, voteData, salt, 0) } _, voteEnd := types.CalculateVotePeriod(s.ctx.BlockHeight(), DefaultVotePeriod) @@ -59,14 +59,14 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { // Two validators sign block number 100 for i, validator := range s.validators[:2] { salt := fmt.Sprintf("%d", i) - SendPrevoteAndVote(validator, blockDataStr, salt, 0) + SendPrevoteAndVote(validator, voteData, salt, 0) } // Two validators sign block number 99 - blockDataStr2 := types.BlockDataToString(&types.BlockData{ChainId: "1", BlockNumber: 99, BlockHash: blockHash}) + voteData2 := types.BlockDataToVoteData(&types.BlockData{ChainId: "1", BlockNumber: 99, BlockHash: blockHash}) for i, validator := range s.validators[2:] { salt := fmt.Sprintf("%d", i+2) - SendPrevoteAndVote(validator, blockDataStr2, salt, 0) + SendPrevoteAndVote(validator, voteData2, salt, 0) } oracle.EndBlocker(s.ctx.WithBlockHeight(DefaultVotePeriod), *s.app.OracleKeeper) @@ -78,14 +78,14 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { It("Abstain validator's power is majority, block data consensus fails", func() { // One validator abstains abstainValidator := s.validators[0] - blockDataStr := types.BlockDataToString(&types.BlockData{ChainId: "1", BlockNumber: -1, BlockHash: blockHash}) + voteData := types.BlockDataToVoteData(&types.BlockData{ChainId: "1", BlockNumber: -1, BlockHash: blockHash}) salt := "abstain" - SendPrevoteAndVote(abstainValidator, blockDataStr, salt, 0) + SendPrevoteAndVote(abstainValidator, voteData, salt, 0) // One validator signs block number 100 validator := s.validators[1] salt = "1" - SendPrevoteAndVote(validator, blockDataStr, salt, 0) + SendPrevoteAndVote(validator, voteData, salt, 0) oracle.EndBlocker(s.ctx.WithBlockHeight(2), *s.app.OracleKeeper) @@ -99,14 +99,14 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { BeforeEach(func() { for i, validator := range s.validators { salt := fmt.Sprintf("%d", i) - SendPrevote(s.ctx.WithBlockHeight(1), validator, blockDataStr, salt, 0) + SendPrevote(s.ctx.WithBlockHeight(1), validator, voteData, salt, 0) } oracle.EndBlocker(s.ctx.WithBlockHeight(1), *s.app.OracleKeeper) }) It("Vote period is 10, prevote is submitted at block 1, vote is submitted at block 10, block data is updated at block 19", func() { for i, validator := range s.validators { salt := fmt.Sprintf("%d", i) - SendVote(s.ctx.WithBlockHeight(DefaultVotePeriod), validator, blockDataStr, salt, 0) + SendVote(s.ctx.WithBlockHeight(DefaultVotePeriod), validator, voteData, salt, 0) } _, voteEnd := types.CalculateVotePeriod(s.ctx.BlockHeight(), DefaultVotePeriod) @@ -119,7 +119,7 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { It("Vote period is 10, prevote is submitted at block 1, vote is submitted at block 11, block data is not updated at block 12", func() { for i, validator := range s.validators { salt := fmt.Sprintf("%d", i) - SendVote(s.ctx.WithBlockHeight(DefaultVotePeriod+1), validator, blockDataStr, salt, 0) + SendVote(s.ctx.WithBlockHeight(DefaultVotePeriod+1), validator, voteData, salt, 0) } oracle.EndBlocker(s.ctx.WithBlockHeight(DefaultVotePeriod+1), *s.app.OracleKeeper) @@ -136,17 +136,17 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { Expect(prevotes.AggregatePrevotes).To(BeNil()) }) It("Vote period is 10, send prevote at block 1 and another at block 2. Send vote at block 10. Block data is updated at block 19", func() { - blockDataStr := types.BlockDataToString(&types.BlockData{ChainId: "1", BlockNumber: 101, BlockHash: blockHash}) + voteData := types.BlockDataToVoteData(&types.BlockData{ChainId: "1", BlockNumber: 101, BlockHash: blockHash}) for i, validator := range s.validators { salt := fmt.Sprintf("%d", i) - SendPrevote(s.ctx.WithBlockHeight(2), validator, blockDataStr, salt, 0) + SendPrevote(s.ctx.WithBlockHeight(2), validator, voteData, salt, 0) } oracle.EndBlocker(s.ctx.WithBlockHeight(2), *s.app.OracleKeeper) for i, validator := range s.validators { salt := fmt.Sprintf("%d", i) - SendVote(s.ctx.WithBlockHeight(DefaultVotePeriod), validator, blockDataStr, salt, 0) + SendVote(s.ctx.WithBlockHeight(DefaultVotePeriod), validator, voteData, salt, 0) } _, voteEnd := types.CalculateVotePeriod(s.ctx.BlockHeight(), DefaultVotePeriod) oracle.EndBlocker(s.ctx.WithBlockHeight(voteEnd), *s.app.OracleKeeper) @@ -159,26 +159,26 @@ var _ = Describe("Oracle module integration tests", Ordered, func() { }) -func SendPrevote(ctx sdk.Context, validator stakingtypes.Validator, blockDataStr, salt string, roundId uint64) { - hash, _ := types.GetAggregateVoteHash(blockDataStr, salt) +func SendPrevote(ctx sdk.Context, validator stakingtypes.Validator, voteData []*types.VoteData, salt string, roundId uint64) { + hash, _ := types.GetAggregateVoteHash(voteData, salt) prevoteMsg := types.NewMsgPrevote(validator.OperatorAddress, validator.OperatorAddress, hash, roundId) oracleMsgSvr := oraclekeeper.NewMsgServerImpl(*s.app.OracleKeeper) _, err := oracleMsgSvr.Prevote(ctx, prevoteMsg) Expect(err).To(BeNil()) } -func SendVote(ctx sdk.Context, validator stakingtypes.Validator, blockDataStr, salt string, roundId uint64) { - voteMsg := types.NewMsgVote(validator.OperatorAddress, validator.OperatorAddress, blockDataStr, salt, roundId) +func SendVote(ctx sdk.Context, validator stakingtypes.Validator, voteData []*types.VoteData, salt string, roundId uint64) { + voteMsg := types.NewMsgVote(validator.OperatorAddress, validator.OperatorAddress, voteData, salt, roundId) oracleMsgSvr := oraclekeeper.NewMsgServerImpl(*s.app.OracleKeeper) _, err := oracleMsgSvr.Vote(ctx, voteMsg) Expect(err).To(BeNil()) } // SendPrevoteAndVote sends prevote and vote messages to the oracle module -func SendPrevoteAndVote(validator stakingtypes.Validator, blockDataStr, salt string, roundId uint64) { - hash, _ := types.GetAggregateVoteHash(blockDataStr, salt) +func SendPrevoteAndVote(validator stakingtypes.Validator, voteData []*types.VoteData, salt string, roundId uint64) { + hash, _ := types.GetAggregateVoteHash(voteData, salt) prevoteMsg := types.NewMsgPrevote(validator.OperatorAddress, validator.OperatorAddress, hash, roundId) - voteMsg := types.NewMsgVote(validator.OperatorAddress, validator.OperatorAddress, blockDataStr, salt, roundId) + voteMsg := types.NewMsgVote(validator.OperatorAddress, validator.OperatorAddress, voteData, salt, roundId) oracleMsgSvr := oraclekeeper.NewMsgServerImpl(*s.app.OracleKeeper) _, err := oracleMsgSvr.Prevote(s.ctx.WithBlockHeight(1), prevoteMsg) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index e4edccc0..3eaf8f22 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -4,18 +4,17 @@ import ( "fmt" "time" - errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" + ctypes "github.com/settlus/chain/types" "github.com/settlus/chain/x/oracle/types" ) -const BlockTimestampMargin = 60 * time.Second +const BlockTimestampMargin = 15 * time.Second type ( Keeper struct { @@ -27,6 +26,7 @@ type ( BankKeeper types.BankKeeper DistributionKeeper types.DistributionKeeper StakingKeeper types.StakingKeeper + SettlementKeeper types.SettlementKeeper distributionName string } @@ -41,6 +41,7 @@ func NewKeeper( bankKeeper types.BankKeeper, distributionKeeper types.DistributionKeeper, stakingKeeper types.StakingKeeper, + settlementKeeper types.SettlementKeeper, distributionName string, ) *Keeper { @@ -63,6 +64,7 @@ func NewKeeper( BankKeeper: bankKeeper, DistributionKeeper: distributionKeeper, StakingKeeper: stakingKeeper, + SettlementKeeper: settlementKeeper, distributionName: distributionName, } @@ -77,18 +79,49 @@ func (k Keeper) GetCurrentRoundInfo(ctx sdk.Context) *types.RoundInfo { blockHeight := ctx.BlockHeight() prevoteEnd, voteEnd := types.CalculateVotePeriod(blockHeight, params.VotePeriod) + oracleData := []*types.OracleData{} + oracleData = appendIfValid(oracleData, k.blockOracleData(params.Whitelist)) + oracleData = appendIfValid(oracleData, k.ownershipOracleData(ctx, params.VotePeriod)) + roundInfo := types.RoundInfo{ Id: types.CalculateRoundId(blockHeight, params.VotePeriod), PrevoteEnd: prevoteEnd, VoteEnd: voteEnd, - - ChainIds: params.GetWhitelistChainIds(), - Timestamp: ctx.BlockHeader().Time.Add(-BlockTimestampMargin).UnixMilli(), + OracleData: oracleData, + Timestamp: ctx.BlockHeader().Time.Add(-BlockTimestampMargin).UnixMilli(), } return &roundInfo } +func (k Keeper) blockOracleData(whitelist []*types.Chain) *types.OracleData { + source := make([]string, len(whitelist)) + for idx, chain := range whitelist { + source[idx] = chain.ChainId + } + + return &types.OracleData{ + Topic: types.OralceTopic_BLOCK, + Sources: source, + } +} + +func (k Keeper) ownershipOracleData(ctx sdk.Context, votePeriod uint64) *types.OracleData { + // We will retrieve all NFTs that need to be verified collected until the last round. + // Because list of nfts in the current round can be increased as the round progresses + startHeight := types.CalculateRoundStartHeight(ctx.BlockHeight(), votePeriod) + nfts := k.SettlementKeeper.GetAllUniqueNftToVerify(ctx, startHeight-1) + sources := make([]string, len(nfts)) + for i, nft := range nfts { + sources[i] = nft.FormatString() + } + + return &types.OracleData{ + Topic: types.OralceTopic_OWNERSHIP, + Sources: sources, + } +} + // GetBlockData returns block data of a chain func (k Keeper) GetBlockData(ctx sdk.Context, chainId string) (*types.BlockData, error) { store := ctx.KVStore(k.storeKey) @@ -127,408 +160,15 @@ func (k Keeper) SetBlockData(ctx sdk.Context, blockData types.BlockData) { store.Set(types.BlockDataKey(blockData.ChainId), bd) } -// GetFeederDelegation returns feeder delegation of a validator -func (k Keeper) GetFeederDelegation(ctx sdk.Context, validatorAddr string) sdk.AccAddress { - store := ctx.KVStore(k.storeKey) - fd := store.Get(types.FeederDelegationKey(validatorAddr)) - if fd == nil { - // By default, validator is its own feeder - validator, _ := sdk.ValAddressFromBech32(validatorAddr) - return sdk.AccAddress(validator.Bytes()) - } - return fd -} - -// GetFeederDelegations returns feeder delegations of all validators -func (k Keeper) GetFeederDelegations(ctx sdk.Context) []types.FeederDelegation { - store := ctx.KVStore(k.storeKey) - var feederDelegations []types.FeederDelegation - iterator := sdk.KVStorePrefixIterator(store, types.FeederDelegationKeyPrefix) - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - validatorAddr := string(iterator.Key()[1:]) - feederAddr := string(iterator.Value()) - feederDelegations = append(feederDelegations, types.FeederDelegation{ - ValidatorAddress: validatorAddr, - FeederAddress: feederAddr, - }) - } - - return feederDelegations -} - -// SetFeederDelegation sets feeder delegation of a validator -func (k Keeper) SetFeederDelegation(ctx sdk.Context, validatorAddr string, feederAddr string) error { - feeder, err := sdk.AccAddressFromBech32(feederAddr) - if err != nil { - return errorsmod.Wrapf(types.ErrInvalidFeeder, "feeder address %s is invalid", feederAddr) - } - - store := ctx.KVStore(k.storeKey) - store.Set(types.FeederDelegationKey(validatorAddr), feeder.Bytes()) - return nil -} - -// ValidateFeeder validates if the feeder has permission to vote for the validator -func (k Keeper) ValidateFeeder(ctx sdk.Context, feederAddr string, validatorAddr string) (bool, error) { - validator, err := sdk.ValAddressFromBech32(validatorAddr) - if err != nil { - return false, errorsmod.Wrapf(types.ErrInvalidValidator, "validator address %s is invalid", validatorAddr) - } - - if val, found := k.StakingKeeper.GetValidator(ctx, validator); !found || !val.IsBonded() { - return false, errorsmod.Wrapf(types.ErrValidatorNotFound, "validator %s is not active", validator.String()) - } - - feeder, err := sdk.AccAddressFromBech32(feederAddr) - if err != nil { - return false, errorsmod.Wrapf(types.ErrInvalidFeeder, "feeder address %s is invalid", feederAddr) - } - - if !feeder.Equals(validator) { - delegation := k.GetFeederDelegation(ctx, validatorAddr) - if !delegation.Equals(feeder) { - return false, errorsmod.Wrapf(types.ErrNoVotingPermission, "feeder %s has no permission to vote for validator %s", feeder, validator) - } - } - - return true, nil -} - -// GetMissCount returns miss count of a validator -func (k Keeper) GetMissCount(ctx sdk.Context, validatorAddr string) uint64 { - store := ctx.KVStore(k.storeKey) - mc := store.Get(types.MissCountKey(validatorAddr)) - if mc == nil { - return 0 - } - return sdk.BigEndianToUint64(mc) -} - -// GetMissCounts returns miss counts of all validators -func (k Keeper) GetMissCounts(ctx sdk.Context) []types.MissCount { - var missCounts []types.MissCount - k.IterateMissCount(ctx, func(validatorAddr string, missCount uint64) (stop bool) { - missCounts = append(missCounts, types.MissCount{ - ValidatorAddress: validatorAddr, - MissCount: missCount, - }) - return false - }) - return missCounts -} - -// SetMissCount sets miss count of a validator -func (k Keeper) SetMissCount(ctx sdk.Context, validatorAddr string, missCount uint64) { - store := ctx.KVStore(k.storeKey) - store.Set(types.MissCountKey(validatorAddr), sdk.Uint64ToBigEndian(missCount)) -} - -func (k Keeper) DeleteMissCount(ctx sdk.Context, validatorAddr string) { - store := ctx.KVStore(k.storeKey) - store.Delete(types.MissCountKey(validatorAddr)) -} - -func (k Keeper) IterateMissCount(ctx sdk.Context, handler func(validatorAddr string, missCount uint64) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.MissCountKeyPrefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - validatorAddr := string(iter.Key()[1:]) - missCount := sdk.BigEndianToUint64(iter.Value()) - - if handler(validatorAddr, missCount) { - break - } - } -} - -// GetRewardPool returns the current reward pool balance -func (k Keeper) GetRewardPool(ctx sdk.Context) sdk.Coins { - addr := k.AccountKeeper.GetModuleAddress(types.ModuleName) - if addr == nil { - panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) - } - - return k.BankKeeper.GetAllBalances(ctx, addr) -} - -/********************* Prevote *********************/ - -// GetAggregatePrevote returns aggregate prevote of a validator -func (k Keeper) GetAggregatePrevote(ctx sdk.Context, validatorAddr string) *types.AggregatePrevote { - store := ctx.KVStore(k.storeKey) - ap := store.Get(types.AggregatePrevoteKey(validatorAddr)) - if ap == nil { - return nil - } - var aggregatePrevote types.AggregatePrevote - k.cdc.MustUnmarshal(ap, &aggregatePrevote) - return &aggregatePrevote -} - -// GetAggregatePrevotes returns aggregate prevotes of all validators -func (k Keeper) GetAggregatePrevotes(ctx sdk.Context) []types.AggregatePrevote { - store := ctx.KVStore(k.storeKey) - var aggregatePrevotes []types.AggregatePrevote - iterator := sdk.KVStorePrefixIterator(store, types.AggregatePrevoteKeyPrefix) - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - var ap types.AggregatePrevote - k.cdc.MustUnmarshal(iterator.Value(), &ap) - aggregatePrevotes = append(aggregatePrevotes, ap) - } - return aggregatePrevotes -} - -// GetAggregatePrevoteStore returns a new KV store from aggregate prevote prefix -func (k Keeper) GetAggregatePrevoteStore(ctx sdk.Context) sdk.KVStore { - store := ctx.KVStore(k.storeKey) - return prefix.NewStore(store, types.AggregatePrevoteKeyPrefix) -} - -// SetAggregatePrevote sets aggregate prevote of a validator -func (k Keeper) SetAggregatePrevote(ctx sdk.Context, aggregatePrevote types.AggregatePrevote) { - store := ctx.KVStore(k.storeKey) - ap := k.cdc.MustMarshal(&aggregatePrevote) - store.Set(types.AggregatePrevoteKey(aggregatePrevote.Voter), ap) -} - -// DeleteAggregatePrevote deletes aggregate prevote of a validator -func (k Keeper) DeleteAggregatePrevote(ctx sdk.Context, validatorAddress string) { - store := ctx.KVStore(k.storeKey) - store.Delete(types.AggregatePrevoteKey(validatorAddress)) -} - -// IterateAggregatePrevotes iterates over prevotes in the store -func (k Keeper) IterateAggregatePrevotes(ctx sdk.Context, handler func(voterAddr string, aggregatePrevote types.AggregatePrevote) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.AggregatePrevoteKeyPrefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - voterAddr := string(iter.Key()[1:]) - var aggregatePrevote types.AggregatePrevote - k.cdc.MustUnmarshal(iter.Value(), &aggregatePrevote) - - if handler(voterAddr, aggregatePrevote) { - break - } - } -} - -/********************* Vote *********************/ - -// GetAggregateVote returns aggregate vote of a validator -func (k Keeper) GetAggregateVote(ctx sdk.Context, validatorAddr string) *types.AggregateVote { - store := ctx.KVStore(k.storeKey) - av := store.Get(types.AggregateVoteKey(validatorAddr)) - if av == nil { - return nil - } - var aggregateVote types.AggregateVote - k.cdc.MustUnmarshal(av, &aggregateVote) - return &aggregateVote -} - -// GetAggregateVotes returns aggregate votes of all validators -func (k Keeper) GetAggregateVotes(ctx sdk.Context) []types.AggregateVote { - store := ctx.KVStore(k.storeKey) - var aggregateVotes []types.AggregateVote - iterator := sdk.KVStorePrefixIterator(store, types.AggregateVoteKeyPrefix) - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - var av types.AggregateVote - k.cdc.MustUnmarshal(iterator.Value(), &av) - aggregateVotes = append(aggregateVotes, av) - } - return aggregateVotes -} - -// GetAggregateVoteStore returns a new KV store from aggregate vote prefix -func (k Keeper) GetAggregateVoteStore(ctx sdk.Context) sdk.KVStore { - store := ctx.KVStore(k.storeKey) - return prefix.NewStore(store, types.AggregateVoteKeyPrefix) -} - -// GroupVotesByChainId groups votes by chain ID -func (k Keeper) GroupVotesByChainId(ctx sdk.Context) map[string][]*types.BlockDataAndVoter { - // Get all aggregate votes - var aggregateVotes []types.AggregateVote - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.AggregateVoteKeyPrefix) - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - var av types.AggregateVote - k.cdc.MustUnmarshal(iterator.Value(), &av) - aggregateVotes = append(aggregateVotes, av) - } - - // Group votes by chain ID - groupedVotes := make(map[string][]*types.BlockDataAndVoter) - for _, vote := range aggregateVotes { - for _, bd := range vote.BlockData { - voter, _ := sdk.ValAddressFromBech32(vote.Voter) - groupedVotes[bd.ChainId] = append(groupedVotes[bd.ChainId], &types.BlockDataAndVoter{ - BlockData: bd, - Voter: voter, - }) - } - } - return groupedVotes -} - -// SetAggregateVote sets aggregate vote of a validator -func (k Keeper) SetAggregateVote(ctx sdk.Context, aggregateVote types.AggregateVote) { - store := ctx.KVStore(k.storeKey) - av := k.cdc.MustMarshal(&aggregateVote) - store.Set(types.AggregateVoteKey(aggregateVote.Voter), av) -} - -// DeleteAggregateVote deletes aggregate vote of a validator -func (k Keeper) DeleteAggregateVote(ctx sdk.Context, validator string) { - store := ctx.KVStore(k.storeKey) - store.Delete(types.AggregateVoteKey(validator)) -} - -// IterateAggregateVotes iterates rate over votes in the store -func (k Keeper) IterateAggregateVotes(ctx sdk.Context, handler func(voterAddr string, aggregateVote types.AggregateVote) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.AggregateVoteKeyPrefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - voterAddr := string(iter.Key()[1:]) - var aggregateVote types.AggregateVote - k.cdc.MustUnmarshal(iter.Value(), &aggregateVote) - - if handler(voterAddr, aggregateVote) { - break - } - } +func (k Keeper) FillSettlementRecipients(ctx sdk.Context, nftOwnership map[types.Nft]ctypes.HexAddressString) { + startHeight := types.CalculateRoundStartHeight(ctx.BlockHeight(), k.GetParams(ctx).VotePeriod) + k.SettlementKeeper.SetRecipients(ctx, nftOwnership, startHeight-1) } -/********************* Ballots & Validators *********************/ - -// RewardBallotWinners distributes rewards to validators who voted for the winning block data -func (k Keeper) RewardBallotWinners(ctx sdk.Context, validatorClaimMap *map[string]types.Claim) error { - weightSum := int64(0) - for _, claim := range *validatorClaimMap { - if claim.MissCount == 0 && !claim.Abstain { - weightSum += claim.Weight - } - } - - if weightSum == 0 { - return nil - } - - // distribute rewards in proportion to the voting power - rewards := sdk.NewDecCoinsFromCoins(k.GetRewardPool(ctx)...) - if rewards.IsZero() { - return nil - } - - logger := k.Logger(ctx) - logger.Debug("RewardBallotWinner", "rewards", rewards) - - var distributedReward sdk.Coins - - for _, voter := range *validatorClaimMap { - // skip if the validator abstained or missed the vote - if voter.Abstain || voter.MissCount > 0 { - logger.Debug(fmt.Sprintf("no reward %s(%s)", - voter.Recipient.String(), - voter.Recipient.String()), - "miss count in the current ballot", voter.MissCount, - "abstain", voter.Abstain, - ) - continue - } - - // multiply the reward by the weight of the validator - // rewardCoins = rewards * (weight / weightSum) - rewardCoins, _ := rewards.MulDec(sdk.NewDec(voter.Weight).QuoInt64(weightSum)).TruncateDecimal() - - // distribute reward to the validator - receiverVal, ok := k.StakingKeeper.GetValidator(ctx, voter.Recipient) - if !ok { - return fmt.Errorf("validator not found: %s", voter.Recipient) - } - - if !rewardCoins.IsZero() { - k.DistributionKeeper.AllocateTokensToValidator(ctx, receiverVal, sdk.NewDecCoinsFromCoins(rewardCoins...)) - distributedReward = distributedReward.Add(rewardCoins...) - } else { - logger.Debug(fmt.Sprintf("no reward %s(%s)", - receiverVal.GetMoniker(), - receiverVal.GetOperator().String()), - "weight", voter.Weight, - ) - } +func appendIfValid(slice []*types.OracleData, elem *types.OracleData) []*types.OracleData { + if len(elem.Sources) == 0 { + return slice } - // Move distributed reward to distribution module - if err := k.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.distributionName, distributedReward); err != nil { - return fmt.Errorf("failed to move distributed reward to distribution module: %w", err) - } - - return nil -} - -func (k Keeper) ClearBallots(ctx sdk.Context) { - // Clear all aggregate prevotes that are older than the current block height - k.IterateAggregatePrevotes(ctx, func(validatorAddress string, aggregatePrevote types.AggregatePrevote) (stop bool) { - if ctx.BlockHeight() >= int64(aggregatePrevote.SubmitBlock) { - k.DeleteAggregatePrevote(ctx, validatorAddress) - } - - return false - }) - - // Clear all aggregate votes - k.IterateAggregateVotes(ctx, func(validatorAddress string, aggregateVote types.AggregateVote) (stop bool) { - k.DeleteAggregateVote(ctx, validatorAddress) - return false - }) -} - -// SlashValidatorsAndResetMissCount slashes validators who missed the vote more than MaxMissCountPerSlashWindow -// and resets miss count of all validators -func (k Keeper) SlashValidatorsAndResetMissCount(ctx sdk.Context) { - logger := k.Logger(ctx) - height := ctx.BlockHeight() - distributionHeight := height - sdk.ValidatorUpdateDelay - 1 - powerReduction := k.StakingKeeper.PowerReduction(ctx) - params := k.GetParams(ctx) - MaxMissCountPerSlashWindow := params.MaxMissCountPerSlashWindow - slashFraction := params.SlashFraction - - k.IterateMissCount(ctx, func(operatorAddress string, missCount uint64) (stop bool) { - if missCount > MaxMissCountPerSlashWindow { - // slash validator if the validator missed the vote more than MaxMissCountPerSlashWindow - validatorAddress, err := sdk.ValAddressFromBech32(operatorAddress) - if err != nil { - panic(fmt.Errorf("failed to parse validator address from store: %w", err)) - } - validator, ok := k.StakingKeeper.GetValidator(ctx, validatorAddress) - if !ok { - logger.Debug(fmt.Sprintf("validator not found: %s", operatorAddress)) - } - - if validator.IsBonded() && !validator.IsJailed() { - consAddr, err := validator.GetConsAddr() - if err != nil { - panic(fmt.Errorf("failed to get consensus address from validator: %w", err)) - } - - k.StakingKeeper.Slash( - ctx, consAddr, - distributionHeight, validator.GetConsensusPower(powerReduction), slashFraction, - ) - k.StakingKeeper.Jail(ctx, consAddr) - } - } - - k.DeleteMissCount(ctx, operatorAddress) - return false - }) + return append(slice, elem) } diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index e0898ae6..d54e21a4 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -241,9 +241,8 @@ func (suite *OracleTestSuite) TestKeeper_GetRewardPool() { func (suite *OracleTestSuite) TestKeeper_GetSetDeletePrevote() { validator := s.validators[0] prevote := types.AggregatePrevote{ - Hash: "foobar", - Voter: validator.GetOperator().String(), - SubmitBlock: uint64(100), + Hash: "foobar", + Voter: validator.GetOperator().String(), } s.app.OracleKeeper.SetAggregatePrevote(s.ctx, prevote) @@ -262,11 +261,10 @@ func (suite *OracleTestSuite) TestKeeper_GetSetDeletePrevote() { func (suite *OracleTestSuite) TestKeeper_GetSetDeleteVote() { validator := s.validators[0] vote := types.AggregateVote{ - BlockData: []*types.BlockData{ + VoteData: []*types.VoteData{ { - ChainId: "1", - BlockNumber: 100, - BlockHash: "foobar", + Topic: types.OralceTopic_BLOCK, + Data: []string{"1:100:foobar"}, }, }, Voter: validator.GetOperator().String(), @@ -305,28 +303,24 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners() { name: "all validators with same weight get reward", vcm: map[string]types.Claim{ s.validators[0].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[0].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, s.validators[1].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[1].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, s.validators[2].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[2].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, s.validators[3].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[3].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, }, totalCoin: sdk.NewCoins(sdk.NewInt64Coin("asetl", 4000000)), @@ -341,28 +335,24 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners() { name: "all validators with different weights get reward", vcm: map[string]types.Claim{ s.validators[0].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[0].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, s.validators[1].GetOperator().String(): { - Weight: 200, - MissCount: 0, - Recipient: s.validators[1].GetOperator(), - Abstain: false, + Weight: 200, + Miss: false, + Abstain: false, }, s.validators[2].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[2].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, s.validators[3].GetOperator().String(): { - Weight: 200, - MissCount: 0, - Recipient: s.validators[3].GetOperator(), - Abstain: false, + Weight: 200, + Miss: false, + Abstain: false, }, }, totalCoin: sdk.NewCoins(sdk.NewInt64Coin("asetl", 4000000)), @@ -377,28 +367,24 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners() { name: "2 validators get reward, 2 validators do not", vcm: map[string]types.Claim{ s.validators[0].GetOperator().String(): { - Weight: 100, - MissCount: 0, - Recipient: s.validators[0].GetOperator(), - Abstain: false, + Weight: 100, + Miss: false, + Abstain: false, }, s.validators[1].GetOperator().String(): { - Weight: 200, - MissCount: 0, - Recipient: s.validators[1].GetOperator(), - Abstain: false, + Weight: 200, + Miss: false, + Abstain: false, }, s.validators[2].GetOperator().String(): { - Weight: 100, - MissCount: 1, - Recipient: s.validators[2].GetOperator(), - Abstain: false, + Weight: 100, + Miss: true, + Abstain: false, }, s.validators[3].GetOperator().String(): { - Weight: 200, - MissCount: 0, - Recipient: s.validators[3].GetOperator(), - Abstain: true, + Weight: 200, + Miss: false, + Abstain: true, }, }, totalCoin: sdk.NewCoins(sdk.NewInt64Coin("asetl", 3000000)), @@ -413,28 +399,24 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners() { name: "no validators get reward", vcm: map[string]types.Claim{ s.validators[0].GetOperator().String(): { - Weight: 100, - MissCount: 1, - Recipient: s.validators[0].GetOperator(), - Abstain: false, + Weight: 100, + Miss: true, + Abstain: false, }, s.validators[1].GetOperator().String(): { - Weight: 200, - MissCount: 1, - Recipient: s.validators[1].GetOperator(), - Abstain: false, + Weight: 200, + Miss: true, + Abstain: false, }, s.validators[2].GetOperator().String(): { - Weight: 100, - MissCount: 1, - Recipient: s.validators[2].GetOperator(), - Abstain: false, + Weight: 100, + Miss: true, + Abstain: false, }, s.validators[3].GetOperator().String(): { - Weight: 200, - MissCount: 1, - Recipient: s.validators[3].GetOperator(), - Abstain: false, + Weight: 200, + Miss: true, + Abstain: false, }, }, totalCoin: sdk.NewCoins(sdk.NewInt64Coin("asetl", 1000000)), @@ -455,7 +437,7 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners() { err = s.app.BankKeeper.SendCoinsFromAccountToModule(s.ctx, s.address, types.ModuleName, tt.totalCoin) s.NoError(err) - err = s.app.OracleKeeper.RewardBallotWinners(s.ctx, &tt.vcm) + err = s.app.OracleKeeper.RewardBallotWinners(s.ctx, tt.vcm) s.NoError(err) for _, validator := range s.validators { @@ -481,65 +463,23 @@ func (suite *OracleTestSuite) TestKeeper_ClearBallots() { name: "all prevotes and votes need to be cleared", setupPrevotesAndVotes: func() { s.app.OracleKeeper.SetAggregatePrevote(s.ctx, types.AggregatePrevote{ - Hash: "foobar", - Voter: s.validators[0].GetOperator().String(), - SubmitBlock: uint64(1), + Hash: "foobar", + Voter: s.validators[0].GetOperator().String(), }) s.app.OracleKeeper.SetAggregatePrevote(s.ctx, types.AggregatePrevote{ - Hash: "foobar", - Voter: s.validators[1].GetOperator().String(), - SubmitBlock: uint64(1), + Hash: "foobar", + Voter: s.validators[1].GetOperator().String(), }) s.app.OracleKeeper.SetAggregateVote(s.ctx, types.AggregateVote{ - BlockData: []*types.BlockData{ - { - ChainId: "1", - BlockNumber: 100, - BlockHash: "foobar", - }, + VoteData: []*types.VoteData{ { - ChainId: "2", - BlockNumber: 200, - BlockHash: "foobar", + Topic: types.OralceTopic_BLOCK, + Data: []string{"1:100:foobar"}, }, }, }) }, wantLength: 0, - }, { - name: "only some prevotes need to be cleared", - setupPrevotesAndVotes: func() { - s.app.OracleKeeper.SetAggregatePrevote(s.ctx, types.AggregatePrevote{ - Hash: "foobar", - Voter: s.validators[0].GetOperator().String(), - SubmitBlock: uint64(1), - }) - s.app.OracleKeeper.SetAggregatePrevote(s.ctx, types.AggregatePrevote{ - Hash: "foobar", - Voter: s.validators[1].GetOperator().String(), - SubmitBlock: uint64(1), - }) - s.app.OracleKeeper.SetAggregatePrevote(s.ctx, types.AggregatePrevote{ - Hash: "foobar", - Voter: s.validators[2].GetOperator().String(), - SubmitBlock: uint64(4), - }) - s.app.OracleKeeper.SetAggregateVote(s.ctx.WithBlockHeight(2), types.AggregateVote{ - BlockData: []*types.BlockData{ - { - ChainId: "1", - BlockNumber: 100, - BlockHash: "foobar", - }, - { - ChainId: "2", - BlockNumber: 200, - BlockHash: "foobar", - }, - }, - }) - }, - wantLength: 1, }, } diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index 1d4f313a..6cd67d5a 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -6,8 +6,6 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "golang.org/x/exp/slices" - "github.com/settlus/chain/x/oracle/types" ) @@ -42,9 +40,8 @@ func (m msgServer) Prevote(goCtx context.Context, prevote *types.MsgPrevote) (*t } aggregatePrevote := types.AggregatePrevote{ - Hash: prevote.Hash, - Voter: prevote.Validator, - SubmitBlock: uint64(ctx.BlockHeight()), + Hash: prevote.Hash, + Voter: prevote.Validator, } m.SetAggregatePrevote(ctx, aggregatePrevote) @@ -71,6 +68,10 @@ func (m msgServer) Vote(goCtx context.Context, vote *types.MsgVote) (*types.MsgV return nil, errorsmod.Wrapf(types.ErrPrevotesNotAccepted, "vote period is over") } + if !types.ValidateVoteData(vote.VoteData, m.GetParams(ctx).GetWhitelistChainIds()) { + return nil, errorsmod.Wrapf(types.ErrInvalidVote, "invalid vote data") + } + // validator and feeder addresses are validated in the ValidateBasic() if v, err := m.ValidateFeeder(ctx, vote.Feeder, vote.Validator); err != nil && v { return nil, err @@ -83,7 +84,7 @@ func (m msgServer) Vote(goCtx context.Context, vote *types.MsgVote) (*types.MsgV } // Check if the vote matches the aggregate prevote hash - hash, err := types.GetAggregateVoteHash(vote.BlockDataString, vote.Salt) + hash, err := types.GetAggregateVoteHash(vote.VoteData, vote.Salt) if err != nil { return nil, fmt.Errorf("failed to get aggregate vote hash (%s)", err) } @@ -91,25 +92,9 @@ func (m msgServer) Vote(goCtx context.Context, vote *types.MsgVote) (*types.MsgV return nil, errorsmod.Wrapf(types.ErrInvalidVote, "hash submitted in prevote (%s) does not match the hash of the vote (%s)", aggregatePrevote.Hash, hash) } - // Check if all whitelisted chains are included in the vote - blockData, err := types.ParseBlockDataString(vote.BlockDataString) - if err != nil { - return nil, errorsmod.Wrapf(types.ErrInvalidVote, "failed to parse block data string (%s)", err) - } - - var voteChainIds []string - for _, chain := range blockData { - voteChainIds = append(voteChainIds, chain.ChainId) - } - - chainIds := m.GetCurrentRoundInfo(ctx).ChainIds - if !slices.Equal(chainIds, voteChainIds) { - return nil, errorsmod.Wrapf(types.ErrInvalidVote, "chain ids are not matched with the whitelist") - } - aggregateVote := types.AggregateVote{ - BlockData: blockData, - Voter: vote.Validator, + VoteData: vote.VoteData, + Voter: vote.Validator, } m.SetAggregateVote(ctx, aggregateVote) @@ -118,7 +103,7 @@ func (m msgServer) Vote(goCtx context.Context, vote *types.MsgVote) (*types.MsgV err = ctx.EventManager().EmitTypedEvent(&types.EventVote{ Feeder: vote.Feeder, Validator: vote.Validator, - BlockData: blockData, + VoteData: vote.VoteData, }) if err != nil { return nil, fmt.Errorf("failed to emit event (%s)", err) diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index 91b45989..9eaa05ac 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -9,13 +9,7 @@ import ( func (suite *OracleTestSuite) TestMsgServer_Prevote() { msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) - blockHash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" - blockDataStr := types.BlockDataToString(&types.BlockData{ - ChainId: "1", BlockNumber: 100, BlockHash: blockHash, - }) - salt := "TestMsgServer_Prevote" - hash, _ := types.GetAggregateVoteHash(blockDataStr, salt) - + hash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" response, err := msgSvr.Prevote(s.ctx.WithBlockHeight(1), &types.MsgPrevote{ Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), Validator: s.validators[0].GetOperator().String(), @@ -30,12 +24,7 @@ func (suite *OracleTestSuite) TestMsgServer_Prevote() { func (suite *OracleTestSuite) TestMsgServer_Prevote_should_be_failed_with_different_round_id() { msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) - blockHash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" - blockDataStr := types.BlockDataToString(&types.BlockData{ - ChainId: "1", BlockNumber: 100, BlockHash: blockHash, - }) - salt := "TestMsgServer_Prevote" - hash, _ := types.GetAggregateVoteHash(blockDataStr, salt) + hash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" _, err := msgSvr.Prevote(s.ctx.WithBlockHeight(20), &types.MsgPrevote{ Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), @@ -48,12 +37,7 @@ func (suite *OracleTestSuite) TestMsgServer_Prevote_should_be_failed_with_differ func (suite *OracleTestSuite) TestMsgServer_Prevote_should_be_failed_if_exceed_prevote_period() { msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) - blockHash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" - blockDataStr := types.BlockDataToString(&types.BlockData{ - ChainId: "1", BlockNumber: 100, BlockHash: blockHash, - }) - salt := "TestMsgServer_Prevote" - hash, _ := types.GetAggregateVoteHash(blockDataStr, salt) + hash := "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3" _, err := msgSvr.Prevote(s.ctx.WithBlockHeight(10), &types.MsgPrevote{ Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), @@ -67,37 +51,57 @@ func (suite *OracleTestSuite) TestMsgServer_Prevote_should_be_failed_if_exceed_p func (suite *OracleTestSuite) TestMsgServer_Vote() { msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) salt := "TestMsgServer_Vote" - blockData := &types.BlockData{ - ChainId: "1", BlockNumber: 100, BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + blockStr := []string{"1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"} + ownershipStr := []string{"1/0x1234567890abcdef/0x1234567890abcdef:0x77791"} + voteData := []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: blockStr, + }, + { + Topic: types.OralceTopic_OWNERSHIP, + Data: ownershipStr, + }, } - blockDataStr := suite.doPrevote(msgSvr, blockData, salt, 1) + suite.doPrevote(msgSvr, voteData, salt, 1) _, err := msgSvr.Vote(s.ctx.WithBlockHeight(10), &types.MsgVote{ - Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), - Validator: s.validators[0].GetOperator().String(), - BlockDataString: blockDataStr, - Salt: salt, + Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), + Validator: s.validators[0].GetOperator().String(), + VoteData: voteData, + Salt: salt, }) suite.NoError(err) vote := s.app.OracleKeeper.GetAggregateVote(s.ctx, s.validators[0].GetOperator().String()) - suite.Equal(vote.BlockData[0], blockData) + suite.Equal(vote.VoteData[0].Data, blockStr) + suite.Equal(vote.VoteData[1].Data, ownershipStr) } func (suite *OracleTestSuite) TestMsgServer_Vote_should_be_failed_with_different_round_id() { msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) salt := "TestMsgServer_Vote" - blockData := &types.BlockData{ - ChainId: "1", BlockNumber: 100, BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + blockStr := []string{"1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"} + ownershipStr := []string{"1/0x1234567890abcdef/0x1234567890abcdef:0x77791"} + voteData := []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: blockStr, + }, + { + Topic: types.OralceTopic_OWNERSHIP, + Data: ownershipStr, + }, } - blockDataStr := suite.doPrevote(msgSvr, blockData, salt, 1) + + suite.doPrevote(msgSvr, voteData, salt, 1) _, err := msgSvr.Vote(s.ctx.WithBlockHeight(39), &types.MsgVote{ - Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), - Validator: s.validators[0].GetOperator().String(), - BlockDataString: blockDataStr, - Salt: salt, - RoundId: 1, + Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), + Validator: s.validators[0].GetOperator().String(), + VoteData: voteData, + Salt: salt, + RoundId: 1, }) suite.Error(err) } @@ -105,17 +109,63 @@ func (suite *OracleTestSuite) TestMsgServer_Vote_should_be_failed_with_different func (suite *OracleTestSuite) TestMsgServer_Vote_should_be_failed_if_exceed_vote_period() { msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) salt := "TestMsgServer_Vote" - blockData := &types.BlockData{ - ChainId: "1", BlockNumber: 100, BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + blockStr := []string{"1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"} + ownershipStr := []string{"1/0x1234567890abcdef/0x1234567890abcdef:0x77791"} + voteData := []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: blockStr, + }, + { + Topic: types.OralceTopic_OWNERSHIP, + Data: ownershipStr, + }, } - blockDataStr := suite.doPrevote(msgSvr, blockData, salt, 1) + + suite.doPrevote(msgSvr, voteData, salt, 1) _, err := msgSvr.Vote(s.ctx.WithBlockHeight(20), &types.MsgVote{ - Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), - Validator: s.validators[0].GetOperator().String(), - BlockDataString: blockDataStr, - Salt: salt, - RoundId: 0, + Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), + Validator: s.validators[0].GetOperator().String(), + VoteData: voteData, + Salt: salt, + RoundId: 0, + }) + suite.Error(err) +} + +func (suite *OracleTestSuite) TestMsgServer_vote_should_fail_if_block_str_is_invalid() { + msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) + salt := "TestMsgServer_Vote" + voteData := buildVoteData( + "1100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + "1/0x1234567890abcdef/0x1234567890abcdef:0x77791") + suite.doPrevote(msgSvr, voteData, salt, 1) + + _, err := msgSvr.Vote(s.ctx.WithBlockHeight(10), &types.MsgVote{ + Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), + Validator: s.validators[0].GetOperator().String(), + VoteData: voteData, + Salt: salt, + RoundId: 0, + }) + suite.Error(err) +} + +func (suite *OracleTestSuite) TestMsgServer_vote_should_fail_if_nft_str_is_invalid() { + msgSvr := keeper.NewMsgServerImpl(*suite.app.OracleKeeper) + salt := "TestMsgServer_Vote" + voteData := buildVoteData( + "1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + "10x1234567890abcdef/0x1234567890abcdef:0x77791") + suite.doPrevote(msgSvr, voteData, salt, 1) + + _, err := msgSvr.Vote(s.ctx.WithBlockHeight(10), &types.MsgVote{ + Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), + Validator: s.validators[0].GetOperator().String(), + VoteData: voteData, + Salt: salt, + RoundId: 0, }) suite.Error(err) } @@ -133,15 +183,26 @@ func (suite *OracleTestSuite) TestMsgServer_FeederDelegationConsent() { suite.Equal(feeder, s.address) } -func (suite *OracleTestSuite) doPrevote(msgSvr types.MsgServer, blockData *types.BlockData, salt string, height int64) string { - blockDataStr := types.BlockDataToString(blockData) - hash, _ := types.GetAggregateVoteHash(blockDataStr, salt) - +func (suite *OracleTestSuite) doPrevote(msgSvr types.MsgServer, voteData []*types.VoteData, salt string, height int64) []string { + hash, _ := types.GetAggregateVoteHash(voteData, salt) _, _ = msgSvr.Prevote(s.ctx.WithBlockHeight(height), &types.MsgPrevote{ Feeder: sdk.AccAddress(s.validators[0].GetOperator().Bytes()).String(), Validator: s.validators[0].GetOperator().String(), Hash: hash, }) - return blockDataStr + return voteData[0].Data +} + +func buildVoteData(blockStr, ownershipStr string) []*types.VoteData { + return []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: []string{blockStr}, + }, + { + Topic: types.OralceTopic_OWNERSHIP, + Data: []string{ownershipStr}, + }, + } } diff --git a/x/oracle/keeper/query_test.go b/x/oracle/keeper/query_test.go index 8a038c66..60761798 100644 --- a/x/oracle/keeper/query_test.go +++ b/x/oracle/keeper/query_test.go @@ -53,9 +53,8 @@ func (suite *OracleTestSuite) TestKeeper_AllBlockData() { func (suite *OracleTestSuite) TestKeeper_AggregatePrevote() { expectedAggregatePrevote := types.AggregatePrevote{ - Hash: "foobar", - Voter: s.validators[0].GetOperator().String(), - SubmitBlock: 100, + Hash: "foobar", + Voter: s.validators[0].GetOperator().String(), } s.app.OracleKeeper.SetAggregatePrevote(s.ctx, expectedAggregatePrevote) @@ -69,14 +68,12 @@ func (suite *OracleTestSuite) TestKeeper_AggregatePrevote() { func (suite *OracleTestSuite) TestKeeper_AggregatePrevotes() { expectedAggregatePrevotes := []types.AggregatePrevote{ { - Hash: "foobar", - Voter: s.validators[0].GetOperator().String(), - SubmitBlock: 100, + Hash: "foobar", + Voter: s.validators[0].GetOperator().String(), }, { - Hash: "barbaz", - Voter: s.validators[1].GetOperator().String(), - SubmitBlock: 200, + Hash: "barbaz", + Voter: s.validators[1].GetOperator().String(), }, } for _, aggregatePrevote := range expectedAggregatePrevotes { @@ -90,13 +87,11 @@ func (suite *OracleTestSuite) TestKeeper_AggregatePrevotes() { func (suite *OracleTestSuite) TestKeeper_AggregateVote() { expectedAggregateVote := types.AggregateVote{ - BlockData: []*types.BlockData{ - { - ChainId: "1", - BlockNumber: 100, - BlockHash: "foobar", - }, - }, + VoteData: types.BlockDataToVoteData(&types.BlockData{ + ChainId: "1", + BlockNumber: 100, + BlockHash: "foobar", + }), Voter: s.validators[0].GetOperator().String(), } s.app.OracleKeeper.SetAggregateVote(s.ctx, expectedAggregateVote) @@ -110,23 +105,22 @@ func (suite *OracleTestSuite) TestKeeper_AggregateVote() { func (suite *OracleTestSuite) TestKeeper_AggregateVotes() { expectedAggregateVotes := []types.AggregateVote{ { - BlockData: []*types.BlockData{ - { - ChainId: "1", - BlockNumber: 100, - BlockHash: "foobar", - }, + VoteData: types.BlockDataToVoteData(&types.BlockData{ + ChainId: "1", + BlockNumber: 100, + BlockHash: "foobar", }, + ), Voter: s.validators[0].GetOperator().String(), }, { - BlockData: []*types.BlockData{ - { - ChainId: "2", - BlockNumber: 200, - BlockHash: "barbaz", - }, + VoteData: types.BlockDataToVoteData(&types.BlockData{ + + ChainId: "2", + BlockNumber: 200, + BlockHash: "barbaz", }, + ), Voter: s.validators[1].GetOperator().String(), }, } diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index dc7bd408..d7e61226 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -83,9 +83,9 @@ func (m *EventPrevote) GetHash() string { } type EventVote struct { - Feeder string `protobuf:"bytes,1,opt,name=feeder,proto3" json:"feeder,omitempty"` - Validator string `protobuf:"bytes,2,opt,name=validator,proto3" json:"validator,omitempty"` - BlockData []*BlockData `protobuf:"bytes,3,rep,name=block_data,json=blockData,proto3" json:"block_data,omitempty"` + Feeder string `protobuf:"bytes,1,opt,name=feeder,proto3" json:"feeder,omitempty"` + Validator string `protobuf:"bytes,2,opt,name=validator,proto3" json:"validator,omitempty"` + VoteData []*VoteData `protobuf:"bytes,3,rep,name=vote_data,json=voteData,proto3" json:"vote_data,omitempty"` } func (m *EventVote) Reset() { *m = EventVote{} } @@ -135,9 +135,9 @@ func (m *EventVote) GetValidator() string { return "" } -func (m *EventVote) GetBlockData() []*BlockData { +func (m *EventVote) GetVoteData() []*VoteData { if m != nil { - return m.BlockData + return m.VoteData } return nil } @@ -258,28 +258,28 @@ func init() { } var fileDescriptor_19e458172dc6362a = []byte{ - // 331 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xc1, 0x4e, 0xc2, 0x40, - 0x10, 0x86, 0xa9, 0x35, 0x68, 0x17, 0x4e, 0x7b, 0xd0, 0x4a, 0x48, 0x83, 0xd5, 0x44, 0x4e, 0x6d, - 0xd0, 0x27, 0x00, 0x91, 0xe8, 0x49, 0x43, 0x8c, 0x31, 0x5c, 0xc8, 0xb6, 0x1d, 0xd9, 0x8d, 0x6b, - 0x97, 0x74, 0x97, 0x46, 0xef, 0x3e, 0x80, 0x8f, 0xe5, 0x91, 0xa3, 0x47, 0x03, 0x2f, 0x62, 0x98, - 0xb6, 0xf1, 0xc4, 0x85, 0xdb, 0xce, 0xcc, 0x3f, 0xdf, 0xfe, 0x93, 0x9f, 0x9c, 0x69, 0x30, 0x46, - 0x2e, 0x74, 0xa8, 0x32, 0x16, 0x4b, 0x08, 0xf3, 0x1e, 0x93, 0x73, 0xce, 0x7a, 0x21, 0xe4, 0x90, - 0x9a, 0x60, 0x9e, 0x29, 0xa3, 0xe8, 0x71, 0x29, 0x0a, 0x0a, 0x51, 0x50, 0x89, 0x5a, 0xe7, 0xdb, - 0xb6, 0x4b, 0x21, 0xae, 0xfb, 0xcf, 0xa4, 0x79, 0xb3, 0xa1, 0x3d, 0x64, 0x90, 0x2b, 0x03, 0xf4, - 0x88, 0xd4, 0x5f, 0x00, 0x12, 0xc8, 0x5c, 0xab, 0x63, 0x75, 0x9d, 0x71, 0x59, 0xd1, 0x36, 0x71, - 0x72, 0x26, 0x45, 0xc2, 0x8c, 0xca, 0xdc, 0x3d, 0x1c, 0xfd, 0x37, 0x28, 0x25, 0xfb, 0x9c, 0x69, - 0xee, 0xda, 0x38, 0xc0, 0xb7, 0xff, 0x69, 0x11, 0x07, 0xd1, 0x4f, 0xbb, 0x73, 0xfb, 0x84, 0x44, - 0x52, 0xc5, 0xaf, 0xd3, 0x84, 0x19, 0xe6, 0xda, 0x1d, 0xbb, 0xdb, 0xb8, 0xf4, 0x83, 0x2d, 0x17, - 0x07, 0x83, 0x8d, 0x74, 0xc8, 0x0c, 0x1b, 0x3b, 0x51, 0xf5, 0xf4, 0x1f, 0x49, 0x1b, 0x5d, 0x8c, - 0xf0, 0xbf, 0x21, 0x48, 0x98, 0x31, 0x23, 0x54, 0x7a, 0xad, 0x52, 0x0d, 0xa9, 0xd9, 0xcd, 0x98, - 0x3f, 0x21, 0x2d, 0xa4, 0xde, 0xa3, 0x85, 0x82, 0xa5, 0x17, 0x7a, 0xc4, 0x84, 0x84, 0x84, 0x9e, - 0x90, 0xc3, 0x98, 0x33, 0x91, 0x4e, 0x45, 0x52, 0x52, 0x0f, 0xb0, 0xbe, 0x4b, 0xe8, 0x29, 0x69, - 0x16, 0x17, 0x71, 0x10, 0x33, 0x6e, 0x90, 0x6c, 0x8f, 0x1b, 0xd8, 0xbb, 0xc5, 0xd6, 0xa0, 0xff, - 0xbd, 0xf2, 0xac, 0xe5, 0xca, 0xb3, 0x7e, 0x57, 0x9e, 0xf5, 0xb5, 0xf6, 0x6a, 0xcb, 0xb5, 0x57, - 0xfb, 0x59, 0x7b, 0xb5, 0xc9, 0xc5, 0x4c, 0x18, 0xbe, 0x88, 0x82, 0x58, 0xbd, 0x85, 0x55, 0xba, - 0x08, 0x0e, 0xdf, 0xab, 0x94, 0xcd, 0xc7, 0x1c, 0x74, 0x54, 0xc7, 0x70, 0xaf, 0xfe, 0x02, 0x00, - 0x00, 0xff, 0xff, 0xe2, 0xdd, 0x7a, 0x5b, 0x42, 0x02, 0x00, 0x00, + // 335 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0x41, 0x4f, 0xea, 0x40, + 0x10, 0xc7, 0xe9, 0xeb, 0x0b, 0x8f, 0x2e, 0x9c, 0xf6, 0xf0, 0x5e, 0x1f, 0x21, 0x0d, 0x54, 0x13, + 0x39, 0xb5, 0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x26, 0xbb, 0x30, 0x99, 0x85, 0x0c, 0xf7, 0x73, + 0x15, 0x8e, 0x58, 0x93, 0xa8, 0x37, 0x64, 0x60, 0xc3, 0xb2, 0x73, 0x3b, 0x10, 0x4a, 0x43, 0xca, + 0xff, 0xb3, 0x5a, 0x22, 0x85, 0xca, 0xc6, 0x2a, 0x2d, 0xa9, 0x7f, 0xa8, 0xbe, 0x4e, 0x79, 0x87, + 0x35, 0x26, 0xda, 0x24, 0x4f, 0x63, 0x09, 0x6a, 0x2a, 0x91, 0xc8, 0xee, 0xb0, 0x4e, 0xbd, 0x2b, + 0x6a, 0x9d, 0x9f, 0x7d, 0x2c, 0x03, 0x67, 0xb1, 0x0c, 0x9c, 0xaf, 0x65, 0xe0, 0xbc, 0xaf, 0x82, + 0xca, 0x62, 0x15, 0x54, 0x3e, 0x57, 0x41, 0x65, 0x74, 0x34, 0x55, 0x28, 0xe7, 0x93, 0x28, 0x31, + 0xcf, 0xf1, 0x36, 0x5a, 0x02, 0xc7, 0x2f, 0xdb, 0x88, 0xf1, 0x75, 0x06, 0x76, 0x52, 0xa5, 0x64, + 0x4f, 0xbe, 0x03, 0x00, 0x00, 0xff, 0xff, 0x10, 0x4b, 0xfa, 0x62, 0x3f, 0x02, 0x00, 0x00, } func (m *EventPrevote) Marshal() (dAtA []byte, err error) { @@ -346,10 +346,10 @@ func (m *EventVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.BlockData) > 0 { - for iNdEx := len(m.BlockData) - 1; iNdEx >= 0; iNdEx-- { + if len(m.VoteData) > 0 { + for iNdEx := len(m.VoteData) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.BlockData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.VoteData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -495,8 +495,8 @@ func (m *EventVote) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - if len(m.BlockData) > 0 { - for _, e := range m.BlockData { + if len(m.VoteData) > 0 { + for _, e := range m.VoteData { l = e.Size() n += 1 + l + sovEvent(uint64(l)) } @@ -784,7 +784,7 @@ func (m *EventVote) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockData", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field VoteData", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -811,8 +811,8 @@ func (m *EventVote) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BlockData = append(m.BlockData, &BlockData{}) - if err := m.BlockData[len(m.BlockData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.VoteData = append(m.VoteData, &VoteData{}) + if err := m.VoteData[len(m.VoteData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/oracle/types/expected_keepers.go b/x/oracle/types/expected_keepers.go index c19722b7..a0dfc42a 100644 --- a/x/oracle/types/expected_keepers.go +++ b/x/oracle/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ctypes "github.com/settlus/chain/types" ) type StakingKeeper interface { @@ -64,3 +65,8 @@ type DistributionKeeper interface { // splitting according to commission. AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) } + +type SettlementKeeper interface { + GetAllUniqueNftToVerify(ctx sdk.Context, height uint64) (list []Nft) + SetRecipients(ctx sdk.Context, nfts map[Nft]ctypes.HexAddressString, height uint64) +} diff --git a/x/oracle/types/messages.go b/x/oracle/types/messages.go index b6ad73c0..82afa1d9 100644 --- a/x/oracle/types/messages.go +++ b/x/oracle/types/messages.go @@ -18,13 +18,13 @@ var ( _ sdk.Msg = &MsgFeederDelegationConsent{} ) -func NewMsgVote(feeder, validator, blockDataString, salt string, roundId uint64) *MsgVote { +func NewMsgVote(feeder, validator string, voteData []*VoteData, salt string, roundId uint64) *MsgVote { return &MsgVote{ - Feeder: feeder, - Validator: validator, - BlockDataString: blockDataString, - Salt: salt, - RoundId: roundId, + Feeder: feeder, + Validator: validator, + VoteData: voteData, + Salt: salt, + RoundId: roundId, } } @@ -60,10 +60,13 @@ func (msg *MsgVote) ValidateBasic() error { return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address (%s)", err) } - _, err = ParseBlockDataString(msg.BlockDataString) - if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block data string (%s)", err) - } + //TODO: Validate VoteData + /* + _, err = ParseBlockDataString(msg.BlockDataString) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block data string (%s)", err) + } + */ return nil } diff --git a/x/oracle/types/nft.go b/x/oracle/types/nft.go new file mode 100644 index 00000000..272be0dc --- /dev/null +++ b/x/oracle/types/nft.go @@ -0,0 +1,26 @@ +package types + +import ( + fmt "fmt" + "strings" + + settlustypes "github.com/settlus/chain/types" +) + +func ParseNftId(nftId string) (Nft, error) { + // split the nftId into its components + data := strings.Split(nftId, "/") + if len(data) != 3 { + return Nft{}, fmt.Errorf("invalid nftId: %s", nftId) + } + + return Nft{ + ChainId: data[0], + ContractAddr: settlustypes.HexAddressString(data[1]), + TokenId: settlustypes.HexAddressString(data[2]), + }, nil +} + +func (nft Nft) FormatString() string { + return fmt.Sprintf("%s/%s/%s", nft.ChainId, nft.ContractAddr, nft.TokenId) +} diff --git a/x/oracle/types/oracle.pb.go b/x/oracle/types/oracle.pb.go index 759d70ff..104edaae 100644 --- a/x/oracle/types/oracle.pb.go +++ b/x/oracle/types/oracle.pb.go @@ -8,6 +8,7 @@ import ( github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + github_com_settlus_chain_types "github.com/settlus/chain/types" io "io" math "math" math_bits "math/bits" @@ -24,6 +25,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type OralceTopic int32 + +const ( + OralceTopic_BLOCK OralceTopic = 0 + OralceTopic_OWNERSHIP OralceTopic = 1 +) + +var OralceTopic_name = map[int32]string{ + 0: "BLOCK", + 1: "OWNERSHIP", +} + +var OralceTopic_value = map[string]int32{ + "BLOCK": 0, + "OWNERSHIP": 1, +} + +func (x OralceTopic) String() string { + return proto.EnumName(OralceTopic_name, int32(x)) +} + +func (OralceTopic) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_787227b110a6eeb7, []int{0} +} + // Params defines the parameters for the module. type Params struct { VotePeriod uint64 `protobuf:"varint,1,opt,name=vote_period,json=votePeriod,proto3" json:"vote_period,omitempty"` @@ -163,17 +189,120 @@ func (m *Chain) GetChainUrl() string { return "" } +type OracleData struct { + Topic OralceTopic `protobuf:"varint,1,opt,name=topic,proto3,enum=settlus.oracle.v1alpha1.OralceTopic" json:"topic,omitempty"` + Sources []string `protobuf:"bytes,2,rep,name=sources,proto3" json:"sources,omitempty"` +} + +func (m *OracleData) Reset() { *m = OracleData{} } +func (m *OracleData) String() string { return proto.CompactTextString(m) } +func (*OracleData) ProtoMessage() {} +func (*OracleData) Descriptor() ([]byte, []int) { + return fileDescriptor_787227b110a6eeb7, []int{2} +} +func (m *OracleData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OracleData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OracleData.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 *OracleData) XXX_Merge(src proto.Message) { + xxx_messageInfo_OracleData.Merge(m, src) +} +func (m *OracleData) XXX_Size() int { + return m.Size() +} +func (m *OracleData) XXX_DiscardUnknown() { + xxx_messageInfo_OracleData.DiscardUnknown(m) +} + +var xxx_messageInfo_OracleData proto.InternalMessageInfo + +func (m *OracleData) GetTopic() OralceTopic { + if m != nil { + return m.Topic + } + return OralceTopic_BLOCK +} + +func (m *OracleData) GetSources() []string { + if m != nil { + return m.Sources + } + return nil +} + +type VoteData struct { + Topic OralceTopic `protobuf:"varint,1,opt,name=topic,proto3,enum=settlus.oracle.v1alpha1.OralceTopic" json:"topic,omitempty"` + Data []string `protobuf:"bytes,2,rep,name=data,proto3" json:"data,omitempty"` +} + +func (m *VoteData) Reset() { *m = VoteData{} } +func (m *VoteData) String() string { return proto.CompactTextString(m) } +func (*VoteData) ProtoMessage() {} +func (*VoteData) Descriptor() ([]byte, []int) { + return fileDescriptor_787227b110a6eeb7, []int{3} +} +func (m *VoteData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VoteData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VoteData.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 *VoteData) XXX_Merge(src proto.Message) { + xxx_messageInfo_VoteData.Merge(m, src) +} +func (m *VoteData) XXX_Size() int { + return m.Size() +} +func (m *VoteData) XXX_DiscardUnknown() { + xxx_messageInfo_VoteData.DiscardUnknown(m) +} + +var xxx_messageInfo_VoteData proto.InternalMessageInfo + +func (m *VoteData) GetTopic() OralceTopic { + if m != nil { + return m.Topic + } + return OralceTopic_BLOCK +} + +func (m *VoteData) GetData() []string { + if m != nil { + return m.Data + } + return nil +} + type AggregatePrevote struct { - Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` - Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` - SubmitBlock uint64 `protobuf:"varint,3,opt,name=submit_block,json=submitBlock,proto3" json:"submit_block,omitempty"` + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` } func (m *AggregatePrevote) Reset() { *m = AggregatePrevote{} } func (m *AggregatePrevote) String() string { return proto.CompactTextString(m) } func (*AggregatePrevote) ProtoMessage() {} func (*AggregatePrevote) Descriptor() ([]byte, []int) { - return fileDescriptor_787227b110a6eeb7, []int{2} + return fileDescriptor_787227b110a6eeb7, []int{4} } func (m *AggregatePrevote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -216,23 +345,16 @@ func (m *AggregatePrevote) GetVoter() string { return "" } -func (m *AggregatePrevote) GetSubmitBlock() uint64 { - if m != nil { - return m.SubmitBlock - } - return 0 -} - type AggregateVote struct { - BlockData []*BlockData `protobuf:"bytes,1,rep,name=block_data,json=blockData,proto3" json:"block_data,omitempty"` - Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` + VoteData []*VoteData `protobuf:"bytes,1,rep,name=vote_data,json=voteData,proto3" json:"vote_data,omitempty"` + Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` } func (m *AggregateVote) Reset() { *m = AggregateVote{} } func (m *AggregateVote) String() string { return proto.CompactTextString(m) } func (*AggregateVote) ProtoMessage() {} func (*AggregateVote) Descriptor() ([]byte, []int) { - return fileDescriptor_787227b110a6eeb7, []int{3} + return fileDescriptor_787227b110a6eeb7, []int{5} } func (m *AggregateVote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -261,9 +383,9 @@ func (m *AggregateVote) XXX_DiscardUnknown() { var xxx_messageInfo_AggregateVote proto.InternalMessageInfo -func (m *AggregateVote) GetBlockData() []*BlockData { +func (m *AggregateVote) GetVoteData() []*VoteData { if m != nil { - return m.BlockData + return m.VoteData } return nil } @@ -285,7 +407,7 @@ func (m *BlockData) Reset() { *m = BlockData{} } func (m *BlockData) String() string { return proto.CompactTextString(m) } func (*BlockData) ProtoMessage() {} func (*BlockData) Descriptor() ([]byte, []int) { - return fileDescriptor_787227b110a6eeb7, []int{4} + return fileDescriptor_787227b110a6eeb7, []int{6} } func (m *BlockData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -344,7 +466,7 @@ func (m *FeederDelegation) Reset() { *m = FeederDelegation{} } func (m *FeederDelegation) String() string { return proto.CompactTextString(m) } func (*FeederDelegation) ProtoMessage() {} func (*FeederDelegation) Descriptor() ([]byte, []int) { - return fileDescriptor_787227b110a6eeb7, []int{5} + return fileDescriptor_787227b110a6eeb7, []int{7} } func (m *FeederDelegation) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -396,7 +518,7 @@ func (m *MissCount) Reset() { *m = MissCount{} } func (m *MissCount) String() string { return proto.CompactTextString(m) } func (*MissCount) ProtoMessage() {} func (*MissCount) Descriptor() ([]byte, []int) { - return fileDescriptor_787227b110a6eeb7, []int{6} + return fileDescriptor_787227b110a6eeb7, []int{8} } func (m *MissCount) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -440,10 +562,10 @@ func (m *MissCount) GetMissCount() uint64 { } type RoundInfo struct { - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - PrevoteEnd int64 `protobuf:"varint,2,opt,name=prevote_end,json=prevoteEnd,proto3" json:"prevote_end,omitempty"` - VoteEnd int64 `protobuf:"varint,3,opt,name=vote_end,json=voteEnd,proto3" json:"vote_end,omitempty"` - ChainIds []string `protobuf:"bytes,4,rep,name=chain_ids,json=chainIds,proto3" json:"chain_ids,omitempty"` + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + PrevoteEnd int64 `protobuf:"varint,2,opt,name=prevote_end,json=prevoteEnd,proto3" json:"prevote_end,omitempty"` + VoteEnd int64 `protobuf:"varint,3,opt,name=vote_end,json=voteEnd,proto3" json:"vote_end,omitempty"` + OracleData []*OracleData `protobuf:"bytes,4,rep,name=oracle_data,json=oracleData,proto3" json:"oracle_data,omitempty"` // UNIX time in milliseconds Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` } @@ -452,7 +574,7 @@ func (m *RoundInfo) Reset() { *m = RoundInfo{} } func (m *RoundInfo) String() string { return proto.CompactTextString(m) } func (*RoundInfo) ProtoMessage() {} func (*RoundInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_787227b110a6eeb7, []int{7} + return fileDescriptor_787227b110a6eeb7, []int{9} } func (m *RoundInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -502,9 +624,9 @@ func (m *RoundInfo) GetVoteEnd() int64 { return 0 } -func (m *RoundInfo) GetChainIds() []string { +func (m *RoundInfo) GetOracleData() []*OracleData { if m != nil { - return m.ChainIds + return m.OracleData } return nil } @@ -516,15 +638,65 @@ func (m *RoundInfo) GetTimestamp() int64 { return 0 } +type Nft struct { + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + ContractAddr github_com_settlus_chain_types.HexAddressString `protobuf:"bytes,2,opt,name=contract_addr,json=contractAddr,proto3,customtype=github.com/settlus/chain/types.HexAddressString" json:"contract_addr"` + TokenId github_com_settlus_chain_types.HexAddressString `protobuf:"bytes,3,opt,name=token_id,json=tokenId,proto3,customtype=github.com/settlus/chain/types.HexAddressString" json:"token_id"` +} + +func (m *Nft) Reset() { *m = Nft{} } +func (m *Nft) String() string { return proto.CompactTextString(m) } +func (*Nft) ProtoMessage() {} +func (*Nft) Descriptor() ([]byte, []int) { + return fileDescriptor_787227b110a6eeb7, []int{10} +} +func (m *Nft) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Nft) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Nft.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 *Nft) XXX_Merge(src proto.Message) { + xxx_messageInfo_Nft.Merge(m, src) +} +func (m *Nft) XXX_Size() int { + return m.Size() +} +func (m *Nft) XXX_DiscardUnknown() { + xxx_messageInfo_Nft.DiscardUnknown(m) +} + +var xxx_messageInfo_Nft proto.InternalMessageInfo + +func (m *Nft) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + func init() { + proto.RegisterEnum("settlus.oracle.v1alpha1.OralceTopic", OralceTopic_name, OralceTopic_value) proto.RegisterType((*Params)(nil), "settlus.oracle.v1alpha1.Params") proto.RegisterType((*Chain)(nil), "settlus.oracle.v1alpha1.Chain") + proto.RegisterType((*OracleData)(nil), "settlus.oracle.v1alpha1.OracleData") + proto.RegisterType((*VoteData)(nil), "settlus.oracle.v1alpha1.VoteData") proto.RegisterType((*AggregatePrevote)(nil), "settlus.oracle.v1alpha1.AggregatePrevote") proto.RegisterType((*AggregateVote)(nil), "settlus.oracle.v1alpha1.AggregateVote") proto.RegisterType((*BlockData)(nil), "settlus.oracle.v1alpha1.BlockData") proto.RegisterType((*FeederDelegation)(nil), "settlus.oracle.v1alpha1.FeederDelegation") proto.RegisterType((*MissCount)(nil), "settlus.oracle.v1alpha1.MissCount") proto.RegisterType((*RoundInfo)(nil), "settlus.oracle.v1alpha1.RoundInfo") + proto.RegisterType((*Nft)(nil), "settlus.oracle.v1alpha1.Nft") } func init() { @@ -532,52 +704,62 @@ func init() { } var fileDescriptor_787227b110a6eeb7 = []byte{ - // 716 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4f, 0x4f, 0x1b, 0x39, - 0x14, 0xcf, 0x90, 0x00, 0x3b, 0x2f, 0x80, 0x58, 0x0b, 0x69, 0xb3, 0xec, 0x6e, 0x02, 0xa3, 0xdd, - 0x2d, 0x52, 0xd5, 0xa4, 0xb4, 0xb7, 0xaa, 0x97, 0x84, 0x3f, 0x2a, 0x87, 0xa2, 0x68, 0x5a, 0x8a, - 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d9, 0x41, 0x3e, 0x94, 0x64, 0x05, 0xe6, 0x44, 0x39, 0x07, 0xe6, 0x04, - 0xb3, 0x03, 0x62, 0xec, 0x5a, 0x21, 0xe2, 0x39, 0x2b, 0xf2, 0x03, 0x05, 0xb4, 0x97, 0x33, 0x9b, - 0xdc, 0xa9, 0xb5, 0x8a, 0xd6, 0xc5, 0xd2, 0x34, 0x6d, 0x36, 0xc1, 0x34, 0x7e, 0xd9, 0xb2, 0xd9, - 0x0e, 0x98, 0x26, 0x7f, 0x83, 0x6f, 0x44, 0xc6, 0xb5, 0xa1, 0xd9, 0x18, 0x3f, 0x63, 0x35, 0x9c, - 0x01, 0xbd, 0xee, 0xc5, 0x75, 0xd3, 0xbb, 0xbc, 0x6e, 0x7a, 0x5f, 0xaf, 0x9b, 0xde, 0xbb, 0x9b, - 0x66, 0xe5, 0xf2, 0xa6, 0x59, 0xf9, 0x7c, 0xd3, 0xac, 0xbc, 0xbe, 0xf7, 0xdd, 0x4f, 0x2d, 0x87, - 0x23, 0x8a, 0x76, 0xce, 0xcb, 0x21, 0x89, 0xdf, 0x75, 0xb0, 0x80, 0xc3, 0xee, 0xf1, 0xb7, 0x00, - 0x00, 0x00, 0xff, 0xff, 0xb4, 0x82, 0xd3, 0x34, 0x43, 0x05, 0x00, 0x00, + // 867 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x41, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0xc6, 0x71, 0x9c, 0x7d, 0x8e, 0x23, 0x33, 0x8a, 0x84, 0x29, 0x60, 0x27, 0x4b, 0xa1, + 0x11, 0x08, 0x9b, 0x96, 0x03, 0x52, 0x55, 0x21, 0xc5, 0x49, 0xaa, 0x44, 0x40, 0x62, 0x6d, 0x5a, + 0x22, 0x55, 0x88, 0xd5, 0x78, 0x67, 0xec, 0x5d, 0x65, 0x77, 0xc7, 0x9a, 0x19,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, 0x8c, 0xc4, 0x87, 0xda, 0xe0, 0xfb, 0xe3, 0xdd, 0xef, 0x5a, 0x15, 0xd2, + 0x04, 0xff, 0xf8, 0xf4, 0x68, 0x3f, 0x3c, 0x39, 0x38, 0x1c, 0xb6, 0xbc, 0xc1, 0xce, 0xcb, 0xab, + 0x8e, 0xf7, 0xea, 0xaa, 0xe3, 0xfd, 0x7b, 0xd5, 0xf1, 0x7e, 0xbd, 0xee, 0x54, 0x5e, 0x5d, 0x77, + 0x2a, 0x7f, 0x5f, 0x77, 0x2a, 0x2f, 0x1e, 0xdc, 0x1a, 0xfc, 0xb2, 0xfc, 0xcb, 0xe1, 0x29, 0x46, + 0x2b, 0xf8, 0xb7, 0xfa, 0xfa, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5c, 0x78, 0xea, 0xdb, 0x04, + 0x07, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -701,6 +883,80 @@ func (m *Chain) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *OracleData) 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 *OracleData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OracleData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Sources) > 0 { + for iNdEx := len(m.Sources) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Sources[iNdEx]) + copy(dAtA[i:], m.Sources[iNdEx]) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Sources[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if m.Topic != 0 { + i = encodeVarintOracle(dAtA, i, uint64(m.Topic)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *VoteData) 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 *VoteData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VoteData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + for iNdEx := len(m.Data) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Data[iNdEx]) + copy(dAtA[i:], m.Data[iNdEx]) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Data[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if m.Topic != 0 { + i = encodeVarintOracle(dAtA, i, uint64(m.Topic)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *AggregatePrevote) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -721,11 +977,6 @@ func (m *AggregatePrevote) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.SubmitBlock != 0 { - i = encodeVarintOracle(dAtA, i, uint64(m.SubmitBlock)) - i-- - dAtA[i] = 0x18 - } if len(m.Voter) > 0 { i -= len(m.Voter) copy(dAtA[i:], m.Voter) @@ -770,10 +1021,10 @@ func (m *AggregateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.BlockData) > 0 { - for iNdEx := len(m.BlockData) - 1; iNdEx >= 0; iNdEx-- { + if len(m.VoteData) > 0 { + for iNdEx := len(m.VoteData) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.BlockData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.VoteData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -926,11 +1177,16 @@ func (m *RoundInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x28 } - if len(m.ChainIds) > 0 { - for iNdEx := len(m.ChainIds) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.ChainIds[iNdEx]) - copy(dAtA[i:], m.ChainIds[iNdEx]) - i = encodeVarintOracle(dAtA, i, uint64(len(m.ChainIds[iNdEx]))) + if len(m.OracleData) > 0 { + for iNdEx := len(m.OracleData) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.OracleData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintOracle(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x22 } @@ -953,6 +1209,56 @@ func (m *RoundInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Nft) 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 *Nft) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Nft) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.TokenId.Size() + i -= size + if _, err := m.TokenId.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.ContractAddr.Size() + i -= size + if _, err := m.ContractAddr.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintOracle(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintOracle(dAtA []byte, offset int, v uint64) int { offset -= sovOracle(v) base := offset @@ -1016,6 +1322,42 @@ func (m *Chain) Size() (n int) { return n } +func (m *OracleData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Topic != 0 { + n += 1 + sovOracle(uint64(m.Topic)) + } + if len(m.Sources) > 0 { + for _, s := range m.Sources { + l = len(s) + n += 1 + l + sovOracle(uint64(l)) + } + } + return n +} + +func (m *VoteData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Topic != 0 { + n += 1 + sovOracle(uint64(m.Topic)) + } + if len(m.Data) > 0 { + for _, s := range m.Data { + l = len(s) + n += 1 + l + sovOracle(uint64(l)) + } + } + return n +} + func (m *AggregatePrevote) Size() (n int) { if m == nil { return 0 @@ -1030,9 +1372,6 @@ func (m *AggregatePrevote) Size() (n int) { if l > 0 { n += 1 + l + sovOracle(uint64(l)) } - if m.SubmitBlock != 0 { - n += 1 + sovOracle(uint64(m.SubmitBlock)) - } return n } @@ -1042,8 +1381,8 @@ func (m *AggregateVote) Size() (n int) { } var l int _ = l - if len(m.BlockData) > 0 { - for _, e := range m.BlockData { + if len(m.VoteData) > 0 { + for _, e := range m.VoteData { l = e.Size() n += 1 + l + sovOracle(uint64(l)) } @@ -1123,9 +1462,9 @@ func (m *RoundInfo) Size() (n int) { if m.VoteEnd != 0 { n += 1 + sovOracle(uint64(m.VoteEnd)) } - if len(m.ChainIds) > 0 { - for _, s := range m.ChainIds { - l = len(s) + if len(m.OracleData) > 0 { + for _, e := range m.OracleData { + l = e.Size() n += 1 + l + sovOracle(uint64(l)) } } @@ -1135,13 +1474,30 @@ func (m *RoundInfo) Size() (n int) { return n } -func sovOracle(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozOracle(x uint64) (n int) { - return sovOracle(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) Unmarshal(dAtA []byte) error { +func (m *Nft) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovOracle(uint64(l)) + } + l = m.ContractAddr.Size() + n += 1 + l + sovOracle(uint64(l)) + l = m.TokenId.Size() + n += 1 + l + sovOracle(uint64(l)) + return n +} + +func sovOracle(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozOracle(x uint64) (n int) { + return sovOracle(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1515,7 +1871,7 @@ func (m *Chain) Unmarshal(dAtA []byte) error { } return nil } -func (m *AggregatePrevote) Unmarshal(dAtA []byte) error { +func (m *OracleData) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1538,15 +1894,34 @@ func (m *AggregatePrevote) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: AggregatePrevote: wiretype end group for non-group") + return fmt.Errorf("proto: OracleData: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: AggregatePrevote: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: OracleData: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Topic", wireType) + } + m.Topic = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Topic |= OralceTopic(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Sources", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1574,11 +1949,80 @@ func (m *AggregatePrevote) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Hash = string(dAtA[iNdEx:postIndex]) + m.Sources = append(m.Sources, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipOracle(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthOracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *VoteData) 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 ErrIntOverflowOracle + } + 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: VoteData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VoteData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Topic", wireType) + } + m.Topic = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Topic |= OralceTopic(b&0x7F) << shift + if b < 0x80 { + break + } + } case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Voter", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1606,13 +2050,63 @@ func (m *AggregatePrevote) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Voter = string(dAtA[iNdEx:postIndex]) + m.Data = append(m.Data, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SubmitBlock", wireType) + default: + iNdEx = preIndex + skippy, err := skipOracle(dAtA[iNdEx:]) + if err != nil { + return err } - m.SubmitBlock = 0 + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthOracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AggregatePrevote) 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 ErrIntOverflowOracle + } + 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: AggregatePrevote: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AggregatePrevote: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowOracle @@ -1622,11 +2116,56 @@ func (m *AggregatePrevote) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.SubmitBlock |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Voter", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Voter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipOracle(dAtA[iNdEx:]) @@ -1679,7 +2218,7 @@ func (m *AggregateVote) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockData", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field VoteData", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1706,8 +2245,8 @@ func (m *AggregateVote) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BlockData = append(m.BlockData, &BlockData{}) - if err := m.BlockData[len(m.BlockData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.VoteData = append(m.VoteData, &VoteData{}) + if err := m.VoteData[len(m.VoteData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -2200,9 +2739,9 @@ func (m *RoundInfo) Unmarshal(dAtA []byte) error { } case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainIds", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field OracleData", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowOracle @@ -2212,23 +2751,25 @@ func (m *RoundInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthOracle } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF } - m.ChainIds = append(m.ChainIds, string(dAtA[iNdEx:postIndex])) + m.OracleData = append(m.OracleData, &OracleData{}) + if err := m.OracleData[len(m.OracleData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 5: if wireType != 0 { @@ -2270,6 +2811,156 @@ func (m *RoundInfo) Unmarshal(dAtA []byte) error { } return nil } +func (m *Nft) 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 ErrIntOverflowOracle + } + 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: Nft: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Nft: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ContractAddr.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TokenId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TokenId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipOracle(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthOracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipOracle(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index dac102cf..2d7bbbc2 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -269,6 +269,10 @@ func (p Params) GetWhitelistChainIds() []string { } func CalculateRoundId(blockHeight int64, votePeriod uint64) uint64 { + return CalculateRoundStartHeight(blockHeight, votePeriod) +} + +func CalculateRoundStartHeight(blockHeight int64, votePeriod uint64) uint64 { uBlockHeight := uint64(blockHeight) return uBlockHeight - uBlockHeight%(votePeriod*2) } diff --git a/x/oracle/types/tx.pb.go b/x/oracle/types/tx.pb.go index 96dda14e..a112ed77 100644 --- a/x/oracle/types/tx.pb.go +++ b/x/oracle/types/tx.pb.go @@ -133,11 +133,11 @@ func (m *MsgPrevoteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPrevoteResponse proto.InternalMessageInfo type MsgVote struct { - Feeder string `protobuf:"bytes,1,opt,name=feeder,proto3" json:"feeder,omitempty"` - Validator string `protobuf:"bytes,2,opt,name=validator,proto3" json:"validator,omitempty"` - BlockDataString string `protobuf:"bytes,3,opt,name=block_data_string,json=blockDataString,proto3" json:"block_data_string,omitempty"` - Salt string `protobuf:"bytes,4,opt,name=salt,proto3" json:"salt,omitempty"` - RoundId uint64 `protobuf:"varint,5,opt,name=round_id,json=roundId,proto3" json:"round_id,omitempty"` + Feeder string `protobuf:"bytes,1,opt,name=feeder,proto3" json:"feeder,omitempty"` + Validator string `protobuf:"bytes,2,opt,name=validator,proto3" json:"validator,omitempty"` + VoteData []*VoteData `protobuf:"bytes,3,rep,name=vote_data,json=voteData,proto3" json:"vote_data,omitempty"` + Salt string `protobuf:"bytes,4,opt,name=salt,proto3" json:"salt,omitempty"` + RoundId uint64 `protobuf:"varint,5,opt,name=round_id,json=roundId,proto3" json:"round_id,omitempty"` } func (m *MsgVote) Reset() { *m = MsgVote{} } @@ -187,11 +187,11 @@ func (m *MsgVote) GetValidator() string { return "" } -func (m *MsgVote) GetBlockDataString() string { +func (m *MsgVote) GetVoteData() []*VoteData { if m != nil { - return m.BlockDataString + return m.VoteData } - return "" + return nil } func (m *MsgVote) GetSalt() string { @@ -344,36 +344,36 @@ func init() { func init() { proto.RegisterFile("settlus/oracle/v1alpha1/tx.proto", fileDescriptor_c427dfd05f1e9c25) } var fileDescriptor_c427dfd05f1e9c25 = []byte{ - // 455 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x73, 0x6d, 0x68, 0xc8, 0x43, 0xb4, 0xea, 0x09, 0x91, 0x60, 0x21, 0x2b, 0x32, 0x20, - 0xa2, 0x22, 0xd9, 0x0a, 0xdd, 0xca, 0x54, 0xa8, 0x90, 0x18, 0x22, 0x21, 0x23, 0x31, 0xc0, 0x10, - 0x5d, 0x7c, 0xc7, 0xd9, 0xc2, 0xf1, 0x85, 0x7b, 0x97, 0xa8, 0x2c, 0x0c, 0xac, 0x2c, 0x7c, 0x0b, - 0x56, 0x3e, 0x04, 0x03, 0x63, 0x47, 0x46, 0x94, 0x0c, 0x7c, 0x0d, 0xe4, 0xb3, 0x5d, 0xab, 0x48, - 0x0e, 0x55, 0x27, 0xdf, 0xbd, 0xf7, 0xff, 0xbf, 0xf7, 0xb3, 0x9f, 0x1f, 0x0c, 0x50, 0x18, 0x93, - 0x2e, 0x30, 0x50, 0x9a, 0x45, 0xa9, 0x08, 0x96, 0x23, 0x96, 0xce, 0x63, 0x36, 0x0a, 0xcc, 0xa9, - 0x3f, 0xd7, 0xca, 0x28, 0xda, 0x2b, 0x15, 0x7e, 0xa1, 0xf0, 0x2b, 0x85, 0xd3, 0x8b, 0x14, 0xce, - 0x14, 0x06, 0x33, 0x94, 0xc1, 0x72, 0x94, 0x3f, 0x0a, 0x87, 0xf7, 0x09, 0x60, 0x8c, 0xf2, 0xa5, - 0x16, 0x4b, 0x65, 0x04, 0xbd, 0x0d, 0x3b, 0xef, 0x84, 0xe0, 0x42, 0xf7, 0xc9, 0x80, 0x0c, 0xb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x54, 0x03, 0xbf, 0xe7, 0x37, 0xfc, 0x31, 0x7e, 0x3d, 0x15, 0xe7, - 0xd1, 0x25, 0x44, 0x55, 0x13, 0x1a, 0x42, 0xdb, 0x8e, 0x6d, 0xb0, 0xc9, 0x94, 0x2b, 0x9c, 0xe1, - 0xff, 0x14, 0xe7, 0x35, 0xbf, 0x10, 0xe8, 0x35, 0x7d, 0xcf, 0xc3, 0x4d, 0x55, 0x1a, 0x4c, 0xce, - 0x93, 0x2b, 0x98, 0x2a, 0x9a, 0xa7, 0xc7, 0x3f, 0x57, 0x2e, 0x39, 0x5b, 0xb9, 0xe4, 0xf7, 0xca, - 0x25, 0x5f, 0xd7, 0x6e, 0xeb, 0x6c, 0xed, 0xb6, 0x7e, 0xad, 0xdd, 0xd6, 0x9b, 0x87, 0x32, 0x31, - 0xf1, 0x62, 0xea, 0x47, 0x6a, 0x16, 0x54, 0xbb, 0x1a, 0xc5, 0x2c, 0xc9, 0x82, 0xd3, 0x6a, 0x67, - 0xcd, 0xc7, 0xb9, 0xc0, 0xe9, 0x8e, 0x5d, 0xbe, 0xc3, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x17, - 0xf8, 0xe2, 0xdd, 0xd2, 0x03, 0x00, 0x00, + // 463 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x31, 0x8b, 0xd4, 0x40, + 0x14, 0xde, 0xb9, 0x5d, 0x6f, 0x6f, 0xdf, 0xe1, 0x89, 0x83, 0xb8, 0x31, 0x48, 0x88, 0xf1, 0xc4, + 0x45, 0x21, 0x61, 0xef, 0xba, 0x13, 0x84, 0xd3, 0x43, 0xb0, 0x58, 0x90, 0x14, 0x16, 0x5a, 0x2c, + 0x73, 0x99, 0x31, 0x09, 0x64, 0x33, 0x31, 0x6f, 0x36, 0x9c, 0x8d, 0x85, 0xad, 0x8d, 0x3f, 0xc5, + 0xde, 0x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2e, 0xbc, 0x66, + 0x23, 0x83, 0x88, 0xc5, 0xa9, 0x77, 0xd6, 0x6c, 0xa6, 0xfa, 0x90, 0x09, 0x3c, 0xdd, 0xd6, 0x0b, + 0x79, 0xf8, 0x27, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x50, 0xe8, 0xed, 0x0c, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -638,12 +638,19 @@ func (m *MsgVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x22 } - if len(m.BlockDataString) > 0 { - i -= len(m.BlockDataString) - copy(dAtA[i:], m.BlockDataString) - i = encodeVarintTx(dAtA, i, uint64(len(m.BlockDataString))) - i-- - dAtA[i] = 0x1a + if len(m.VoteData) > 0 { + for iNdEx := len(m.VoteData) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VoteData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Validator) > 0 { i -= len(m.Validator) @@ -803,9 +810,11 @@ func (m *MsgVote) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.BlockDataString) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + if len(m.VoteData) > 0 { + for _, e := range m.VoteData { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } } l = len(m.Salt) if l > 0 { @@ -1168,9 +1177,9 @@ func (m *MsgVote) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlockDataString", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field VoteData", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1180,23 +1189,25 @@ func (m *MsgVote) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.BlockDataString = string(dAtA[iNdEx:postIndex]) + m.VoteData = append(m.VoteData, &VoteData{}) + if err := m.VoteData[len(m.VoteData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 4: if wireType != 2 { diff --git a/x/oracle/types/vote.go b/x/oracle/types/vote.go index 6f309c09..68b974d0 100644 --- a/x/oracle/types/vote.go +++ b/x/oracle/types/vote.go @@ -3,70 +3,42 @@ package types import ( "crypto/sha256" "fmt" - "strconv" "strings" - sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ) // Claim is an interface that directs its rewards to an attached bank account. type Claim struct { - Weight int64 - MissCount int64 - Recipient sdk.ValAddress - Abstain bool + Weight int64 + Miss bool + Abstain bool } -type BlockDataAndVoter struct { - BlockData *BlockData - Voter sdk.ValAddress -} - -type BlockDataAndWeight struct { - BlockData *BlockData - Weight int64 -} - -// ParseBlockDataString parses a string of block data into a slice of BlockData. -// The string must be in the format of "{chain-id}:{height}:{hash},{chain-id}:{height}:{hash},..." -func ParseBlockDataString(blockDataStr string) ([]*BlockData, error) { - var blockData []*BlockData - for _, blockDataStr := range strings.Split(blockDataStr, ",") { - if blockDataStr == "" { - continue - } - blockDataFields := strings.Split(blockDataStr, ":") - if len(blockDataFields) != 3 { - return nil, fmt.Errorf("invalid block data string: %s", blockDataStr) - } - chainID := blockDataFields[0] - height, err := strconv.ParseInt(blockDataFields[1], 10, 64) - if err != nil { - return nil, fmt.Errorf("invalid block data string: %s", blockDataStr) +// GetAggregateVoteHash returns the hash of the aggregate vote from the block data string and salt +func GetAggregateVoteHash(voteData []*VoteData, salt string) (string, error) { + var sb strings.Builder + sb.WriteString(salt) + for _, vd := range voteData { + for _, d := range vd.Data { + sb.WriteString(d) } - hash := blockDataFields[2] - blockData = append(blockData, &BlockData{ - ChainId: chainID, - BlockNumber: height, - BlockHash: hash, - }) } - return blockData, nil -} - -// GetAggregateVoteHash returns the hash of the aggregate vote from the block data string and salt -func GetAggregateVoteHash(blockDataString, salt string) (string, error) { - sourceStr := fmt.Sprintf("%s%s", salt, blockDataString) h := sha256.New() - h.Write([]byte(sourceStr)) + if _, err := h.Write([]byte(sb.String())); err != nil { + return "", err + } bs := h.Sum(nil) return fmt.Sprintf("%X", bs), nil } -// BlockDataToString returns a string representation of the given block data -func BlockDataToString(bd *BlockData) string { - return fmt.Sprintf("%s:%d:%s", bd.ChainId, bd.BlockNumber, bd.BlockHash) +func BlockDataToVoteData(bd *BlockData) []*VoteData { + return []*VoteData{ + { + Topic: OralceTopic_BLOCK, + Data: []string{fmt.Sprintf("%s:%d/%s", bd.ChainId, bd.BlockNumber, bd.BlockHash)}, + }, + } } // IsLastBlockOfSlashWindow returns true if we are at the last block of the slash slashWindow @@ -77,54 +49,3 @@ func IsLastBlockOfSlashWindow(ctx sdk.Context, slashWindow uint64) bool { return (uint64)(ctx.BlockHeight())%slashWindow == 0 } - -// TallyVotes tallies votes by chain ID and picks the most voted block data -func TallyVotes(votesByChainId map[string][]*BlockDataAndVoter, validatorClaimMap map[string]Claim, thresholdVotes sdkmath.Int) map[string]*BlockData { - blockData := make(map[string]*BlockData) - for chainId, votes := range votesByChainId { - var bds []*BlockDataAndWeight - for _, vote := range votes { - // Skip abstain votes - if vote.BlockData.BlockNumber < 0 { - continue - } - bds = append(bds, &BlockDataAndWeight{ - BlockData: vote.BlockData, - Weight: validatorClaimMap[vote.Voter.String()].Weight, - }) - } - - blockData[chainId] = PicMostVotedBlockData(bds, thresholdVotes) - } - return blockData -} - -// PicMostVotedBlockData picks the most voted block data from the given slice of block data -func PicMostVotedBlockData(votes []*BlockDataAndWeight, thresholdVotes sdkmath.Int) *BlockData { - // Count votes - voteCount := make(map[BlockData]int64) - for _, vote := range votes { - voteCount[*vote.BlockData] += vote.Weight - } - - // Filter out votes that are below the threshold - voteCountAboveThreshold := make(map[BlockData]int64) - for bd, count := range voteCount { - if sdkmath.NewInt(count).GTE(thresholdVotes) { - voteCountAboveThreshold[bd] = count - } - } - - // Assuming the threshold is at least 50%, if there are more than one votes above the threshold, return nil - if len(voteCountAboveThreshold) > 1 { - return nil - } - - // If there is only one vote above the threshold, return it - for bd := range voteCountAboveThreshold { - return &bd - } - - // If there are no votes above the threshold, return nil - return nil -} diff --git a/x/oracle/types/vote_data.go b/x/oracle/types/vote_data.go new file mode 100644 index 00000000..81f081f4 --- /dev/null +++ b/x/oracle/types/vote_data.go @@ -0,0 +1,111 @@ +package types + +import ( + fmt "fmt" + "strconv" + "strings" + + ctypes "github.com/settlus/chain/types" +) + +func ValidateVoteData(voteData []*VoteData, chainList []string) bool { + chainMap := make(map[string]struct{}) + for _, chainId := range chainList { + chainMap[chainId] = struct{}{} + } + + for _, vd := range voteData { + switch vd.Topic { + case OralceTopic_BLOCK: + for _, data := range vd.Data { + chainId, _, err := StringToBlockData(data) + if err != nil { + return false + } + if _, ok := chainMap[chainId]; !ok { + return false + } + } + + case OralceTopic_OWNERSHIP: + for _, data := range vd.Data { + nft, _, err := StringToOwnershipData(data) + if err != nil { + return false + } + if _, ok := chainMap[nft.ChainId]; !ok { + return false + } + } + default: + return false + } + } + + return true +} + +func StringToBlockData(voteString string) (string, BlockData, error) { + // voteString = chainId:blockNumber/blockHash + + data := strings.Split(voteString, ":") + if len(data) != 2 { + return "", BlockData{}, fmt.Errorf("invalid block data string: %s", voteString) + } + + chainId := data[0] + blockDataFields := strings.Split(data[1], "/") + if len(blockDataFields) != 2 { + return "", BlockData{}, fmt.Errorf("invalid block data string: %s", voteString) + } + + blockNumber, err := strconv.ParseInt(blockDataFields[0], 10, 64) + if err != nil { + return "", BlockData{}, fmt.Errorf("invalid block data string: %s", voteString) + } + + blockHash := blockDataFields[1] + if !isValidHex(blockHash) { + return "", BlockData{}, fmt.Errorf("invalid block data string: %s", voteString) + } + + blockData := BlockData{ + ChainId: chainId, + BlockNumber: blockNumber, + BlockHash: blockHash, + } + + return chainId, blockData, err +} + +func StringToOwnershipData(voteString string) (Nft, ctypes.HexAddressString, error) { + // voteString = chainId/contractAddr/tokenId:owner + + data := strings.Split(voteString, ":") + nft, err := ParseNftId(data[0]) + + if !isValidHex(nft.ContractAddr.String()) || !isValidHex(nft.TokenId.String()) { + return Nft{}, "", fmt.Errorf("invalid nftId: %s", data[0]) + } + + owner := ctypes.HexAddressString(data[1]) + + return nft, owner, err +} + +func isValidHex(s string) bool { + if len(s) == 0 { + return false + } + + if len(s) > 2 && s[:2] == "0x" { + s = s[2:] + } + + for _, r := range s { + if !(r >= '0' && r <= '9' || r >= 'a' && r <= 'f' || r >= 'A' && r <= 'F') { + return false + } + } + return true +} diff --git a/x/oracle/types/vote_data_test.go b/x/oracle/types/vote_data_test.go new file mode 100644 index 00000000..80555cd4 --- /dev/null +++ b/x/oracle/types/vote_data_test.go @@ -0,0 +1,134 @@ +package types + +import ( + "testing" + + ctypes "github.com/settlus/chain/types" + "github.com/stretchr/testify/require" +) + +func TestParseBlockDataString(t *testing.T) { + tests := []struct { + name string + blockData BlockData + blockDatastr string + wantErr bool + }{ + { + name: "valid block data string", + blockData: BlockData{ + ChainId: "1", + BlockNumber: 100, + BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + }, + blockDatastr: "1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + wantErr: false, + }, { + name: "invalid block data string: no colon", + blockData: BlockData{}, + blockDatastr: "1100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd32", + wantErr: true, + }, + { + name: "invalid block data string: no slash", + blockData: BlockData{}, + blockDatastr: "1:100315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd32", + wantErr: true, + }, + { + name: "invalid block data string: non-integer block number", + blockData: BlockData{}, + blockDatastr: "1:abc:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, bd, err := StringToBlockData(tt.blockDatastr) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.blockData, bd) + } + }) + } +} + +func TestStringToOwnershipData(t *testing.T) { + type Result struct { + nft Nft + owner ctypes.HexAddressString + err bool + } + + testCases := []struct { + name string + voteString string + expected struct { + nft Nft + owner ctypes.HexAddressString + err bool + } + }{ + { + name: "Valid vote string", + voteString: "1/0x123/0x0:0x777", + expected: Result{ + nft: Nft{ + ChainId: "1", + ContractAddr: "0x123", + TokenId: "0x0", + }, + owner: ctypes.HexAddressString("0x777"), + err: false, + }, + }, + { + name: "Valid vote string", + voteString: "1/123/0a:777", + expected: Result{ + nft: Nft{ + ChainId: "1", + ContractAddr: "123", + TokenId: "0a", + }, + owner: ctypes.HexAddressString("777"), + err: false, + }, + }, + { + name: "Invalid nftId - no colone", + voteString: "1/0x123/0x0/0x777", + expected: Result{ + nft: Nft{}, + owner: ctypes.HexAddressString(""), + err: true, + }, + }, + { + name: "Invalid nftId - no slash", + voteString: "10x123/0x0:0x777", + expected: Result{ + nft: Nft{}, + owner: ctypes.HexAddressString(""), + err: true, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + nft, owner, err := StringToOwnershipData(tc.voteString) + + if tc.expected.err { + require.NotNil(t, err) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected.nft, nft) + require.Equal(t, tc.expected.owner, owner) + } + }) + } +} diff --git a/x/oracle/types/vote_test.go b/x/oracle/types/vote_test.go deleted file mode 100644 index c77490b4..00000000 --- a/x/oracle/types/vote_test.go +++ /dev/null @@ -1,386 +0,0 @@ -package types_test - -import ( - "context" - "strings" - "testing" - - sdkmath "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - - "github.com/settlus/chain/x/oracle/types" -) - -func TestParseBlockDataString(t *testing.T) { - tests := []struct { - name string - blockData []*types.BlockData - blockDatastr string - wantErr bool - }{ - { - name: "valid block data string", - blockData: []*types.BlockData{ - { - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - { - ChainId: "2", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - }, - blockDatastr: "1:100:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3,2:200:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - wantErr: false, - }, { - name: "invalid block data string: no comma", - blockData: nil, - blockDatastr: "1:100:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd32:200:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - wantErr: true, - }, { - name: "invalid block data string: non-integer block number", - blockData: nil, - blockDatastr: "1:100.5:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3,2:200.1:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - wantErr: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - bd, err := types.ParseBlockDataString(tt.blockDatastr) - if tt.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - require.Equal(t, tt.blockData, bd) - } - }) - } -} - -func TestGetAggregateVoteHash(t *testing.T) { - tests := []struct { - name string - blockDataStr string - salt string - wantHash string - }{ - { - name: "valid block data string", - salt: "1", - blockDataStr: "1:100:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3,2:200:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - wantHash: "f54d660a42b63a4eb17bbea8337b108509ae70348b08e1dbd7e64f2d02bb13b4", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - hash, err := types.GetAggregateVoteHash(tt.blockDataStr, tt.salt) - require.NoError(t, err) - require.Equal(t, hash, strings.ToUpper(tt.wantHash)) - }) - } -} - -func TestBlockDataToString(t *testing.T) { - tests := []struct { - name string - bd *types.BlockData - want string - }{ - { - name: "valid block data", - bd: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - want: "1:100:315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.want, types.BlockDataToString(tt.bd)) - }) - } -} -func TestIsLastBlockOfSlashWindow(t *testing.T) { - tests := []struct { - name string - blockNumber uint64 - slashWindow uint64 - want bool - }{ - { - name: "block number is last block of slashWindow", - blockNumber: 1000, - slashWindow: 100, - want: true, - }, { - name: "block number is not last block of slashWindow", - blockNumber: 1001, - slashWindow: 100, - want: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ctx := sdk.Context{}.WithContext(context.Background()).WithBlockHeight(int64(tt.blockNumber)) - require.Equal(t, tt.want, types.IsLastBlockOfSlashWindow(ctx, tt.slashWindow)) - }) - } -} - -func TestPickMostVotedBlockData(t *testing.T) { - tests := []struct { - name string - votes []*types.BlockDataAndWeight - thresholdVotes sdkmath.Int - want *types.BlockData - }{ - { - name: "default case", - votes: []*types.BlockDataAndWeight{ - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - Weight: 100, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894eddd", - }, - Weight: 200, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894eddd", - }, - Weight: 100, - }, - }, - thresholdVotes: sdkmath.NewInt(200), - want: &types.BlockData{ - ChainId: "1", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894eddd", - }, - }, { - name: "tie should return nil", - votes: []*types.BlockDataAndWeight{ - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - Weight: 100, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894eddd", - }, - Weight: 100, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 10, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edde", - }, - Weight: 100, - }, - }, - thresholdVotes: sdkmath.NewInt(100), - want: nil, - }, { - name: "check block number as well as block hash", - votes: []*types.BlockDataAndWeight{ - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "1111111111111111", - }, - Weight: 100, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "1111111111111111", - }, - Weight: 100, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "2222222222222222", - }, - Weight: 100, - }, - }, - thresholdVotes: sdkmath.NewInt(150), - want: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "1111111111111111", - }, - }, { - name: "same block number, different hash", - votes: []*types.BlockDataAndWeight{ - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "1111111111111111", - }, - Weight: 100, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "2222222222222222", - }, - Weight: 100, - }, - }, - thresholdVotes: sdkmath.NewInt(100), - want: nil, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - bd := types.PicMostVotedBlockData(tt.votes, tt.thresholdVotes) - require.Equal(t, tt.want, bd) - }) - } -} - -func TestTallyVotes(t *testing.T) { - validator1 := sdk.ValAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) - validator2 := sdk.ValAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) - validatorAbstain := sdk.ValAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) - tests := []struct { - name string - votesByChainId map[string][]*types.BlockDataAndVoter - validatorClaimMap map[string]types.Claim - thresholdVotes sdkmath.Int - want map[string]*types.BlockData - }{ - { - name: "valid block data string", - votesByChainId: map[string][]*types.BlockDataAndVoter{ - "1": { - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - Voter: validator1, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - Voter: validator2, - }, - { - BlockData: &types.BlockData{ - ChainId: "1", - BlockNumber: -1, - BlockHash: "", - }, - Voter: validatorAbstain, - }, - }, - "2": { - { - BlockData: &types.BlockData{ - ChainId: "2", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - Voter: validator1, - }, - { - BlockData: &types.BlockData{ - ChainId: "2", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - Voter: validator2, - }, - { - BlockData: &types.BlockData{ - ChainId: "2", - BlockNumber: -1, - BlockHash: "", - }, - Voter: validatorAbstain, - }, - }, - }, - validatorClaimMap: map[string]types.Claim{ - validator1.String(): { - Weight: 100, - MissCount: 0, - Recipient: validator1, - Abstain: false, - }, - validator2.String(): { - Weight: 200, - MissCount: 0, - Recipient: validator2, - Abstain: false, - }, - validatorAbstain.String(): { - Weight: 100, - MissCount: 0, - Recipient: validatorAbstain, - Abstain: true, - }, - }, - thresholdVotes: sdkmath.NewInt(300), - want: map[string]*types.BlockData{ - "1": { - ChainId: "1", - BlockNumber: 100, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - "2": { - ChainId: "2", - BlockNumber: 200, - BlockHash: "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.want, types.TallyVotes(tt.votesByChainId, tt.validatorClaimMap, tt.thresholdVotes)) - }) - } -} diff --git a/x/oracle/voteprocessor/factory.go b/x/oracle/voteprocessor/factory.go new file mode 100644 index 00000000..d09ee62d --- /dev/null +++ b/x/oracle/voteprocessor/factory.go @@ -0,0 +1,52 @@ +package voteprocessor + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + ctypes "github.com/settlus/chain/types" + "github.com/settlus/chain/x/oracle/keeper" + "github.com/settlus/chain/x/oracle/types" +) + +func NewSettlusVoteProcessors(keeper keeper.Keeper, aggregateVotes []types.AggregateVote, thresholdVotes math.Int) []IVoteProcessor { + blockConsensus := func(ctx sdk.Context, voteData map[string]types.BlockData) { + for _, block := range voteData { + keeper.SetBlockData(ctx, block) + } + } + + ownershipConsensus := func(ctx sdk.Context, voteData map[types.Nft]ctypes.HexAddressString) { + keeper.FillSettlementRecipients(ctx, voteData) + } + + return []IVoteProcessor{ + NewBlockVoteProcessor(blockConsensus, aggregateVotes, thresholdVotes), + NewOwnershipVoteProcessor(ownershipConsensus, aggregateVotes, thresholdVotes), + } +} + +func NewBlockVoteProcessor( + onConsensus func(ctx sdk.Context, voteData map[string]types.BlockData), + aggregateVotes []types.AggregateVote, + thresholdVotes math.Int) *VoteProcessor[string, types.BlockData] { + + return &VoteProcessor[string, types.BlockData]{ + aggregateVotes: aggregateVotes, + thresholdVotes: thresholdVotes, + dataConverter: types.StringToBlockData, + onConsensus: onConsensus, + } +} + +func NewOwnershipVoteProcessor( + onConsensus func(ctx sdk.Context, voteData map[types.Nft]ctypes.HexAddressString), + aggregateVotes []types.AggregateVote, + thresholdVotes math.Int) *VoteProcessor[types.Nft, ctypes.HexAddressString] { + + return &VoteProcessor[types.Nft, ctypes.HexAddressString]{ + aggregateVotes: aggregateVotes, + thresholdVotes: thresholdVotes, + dataConverter: types.StringToOwnershipData, + onConsensus: onConsensus, + } +} diff --git a/x/oracle/voteprocessor/types.go b/x/oracle/voteprocessor/types.go new file mode 100644 index 00000000..0b41e5ed --- /dev/null +++ b/x/oracle/voteprocessor/types.go @@ -0,0 +1,16 @@ +package voteprocessor + +import sdk "github.com/cosmos/cosmos-sdk/types" + +type DataWithVoter[T any] struct { + Data T + Voter sdk.ValAddress +} + +type DataWithWeight[T any] struct { + Data T + Weight int64 +} + +type ConsensusHook[Source comparable, Data comparable] func(sdk.Context, map[Source]Data) +type DataConverter[Source comparable, Data comparable] func(string) (Source, Data, error) diff --git a/x/oracle/voteprocessor/voteprocessor.go b/x/oracle/voteprocessor/voteprocessor.go new file mode 100644 index 00000000..9571a680 --- /dev/null +++ b/x/oracle/voteprocessor/voteprocessor.go @@ -0,0 +1,116 @@ +package voteprocessor + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/settlus/chain/x/oracle/types" +) + +type IVoteProcessor interface { + TallyVotes(ctx sdk.Context, validatorClaimMap map[string]types.Claim) +} + +type VoteProcessor[Source comparable, Data comparable] struct { + aggregateVotes []types.AggregateVote + thresholdVotes math.Int + dataConverter DataConverter[Source, Data] + onConsensus ConsensusHook[Source, Data] +} + +func (vp *VoteProcessor[Source, Data]) TallyVotes(ctx sdk.Context, validatorClaimMap map[string]types.Claim) { + logger := ctx.Logger() + votes := vp.groupVotes(vp.aggregateVotes) + voteResults := make(map[Source]Data) + for source, votes := range votes { + var dwwList []DataWithWeight[Data] + for _, vote := range votes { + dwwList = append(dwwList, DataWithWeight[Data]{ + Data: vote.Data, + Weight: validatorClaimMap[vote.Voter.String()].Weight, + }) + } + + voteResults[source] = vp.pickMostVoted(dwwList) + } + + vp.onConsensus(ctx, voteResults) + + // increase win count for validators who voted for the winning data + for source, vote := range votes { + majorData := voteResults[source] + for _, voteData := range vote { + claim, ok := validatorClaimMap[voteData.Voter.String()] + if !ok { + // if the validator is not in the active set or is jailed, skip + logger.Info("validator not found in active set", "validator", voteData.Voter.String()) + continue + } + + // if abstain flag is set, continue + if claim.Abstain { + continue + } + + if voteData.Data != majorData { + claim.Miss = claim.Miss || true + } + + validatorClaimMap[voteData.Voter.String()] = claim + } + } +} + +func (vp *VoteProcessor[Source, Data]) groupVotes(aggregateVotes []types.AggregateVote) map[Source][]DataWithVoter[Data] { + groupedVotes := make(map[Source][]DataWithVoter[Data]) + for _, vote := range aggregateVotes { + for _, vd := range vote.VoteData { + voter, err := sdk.ValAddressFromBech32(vote.Voter) + if err != nil { + continue + } + + for _, strData := range vd.Data { + source, data, err := vp.dataConverter(strData) + if err != nil { + continue + } + + groupedVotes[source] = append(groupedVotes[source], DataWithVoter[Data]{ + Data: data, + Voter: voter, + }) + } + } + } + return groupedVotes +} + +// pickMostVotedData picks the most voted data from the given slice of data +func (vp *VoteProcessor[Source, Data]) pickMostVoted(dwwList []DataWithWeight[Data]) (ret Data) { + // Count votes + voteCount := make(map[Data]int64) + for _, dww := range dwwList { + voteCount[dww.Data] += dww.Weight + } + + // Filter out votes that are below the threshold + voteCountAboveThreshold := make(map[Data]int64) + for data, count := range voteCount { + if math.NewInt(count).GTE(vp.thresholdVotes) { + voteCountAboveThreshold[data] = count + } + } + + // Assuming the threshold is at least 50%, if there are more than one votes above the threshold, return nil + if len(voteCountAboveThreshold) > 1 { + return ret + } + + // If there is only one vote above the threshold, return it + for data := range voteCountAboveThreshold { + return data + } + + // If there are no votes above the threshold, return nil + return ret +} diff --git a/x/oracle/voteprocessor/voteprocessor_test.go b/x/oracle/voteprocessor/voteprocessor_test.go new file mode 100644 index 00000000..f180117a --- /dev/null +++ b/x/oracle/voteprocessor/voteprocessor_test.go @@ -0,0 +1,166 @@ +package voteprocessor + +import ( + "testing" + + "github.com/tendermint/tendermint/crypto/ed25519" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + ctypes "github.com/settlus/chain/types" + "github.com/settlus/chain/x/oracle/types" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" +) + +func genValAddrs(num int) []sdk.ValAddress { + valAddrs := make([]sdk.ValAddress, num) + for i := 0; i < num; i++ { + pk := ed25519.GenPrivKey().PubKey() + valAddrs[i] = sdk.ValAddress(pk.Address()) + } + return valAddrs +} + +func TestBlockVoteProcessor(t *testing.T) { + thresholdVotes := math.NewInt(2) + addrs := genValAddrs(3) + + aggregateVotes := []types.AggregateVote{ + { + Voter: addrs[0].String(), + VoteData: []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: []string{"1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"}, + }, + }, + }, + { + Voter: addrs[1].String(), + VoteData: []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: []string{"1:100/315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"}, + }, + }, + }, + { + Voter: addrs[2].String(), + VoteData: []*types.VoteData{ + { + Topic: types.OralceTopic_BLOCK, + Data: []string{"1:101/415f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"}, + }, + }, + }, + } + + validatorClaimMap := map[string]types.Claim{ + addrs[0].String(): { + Weight: 1, + Miss: false, + Abstain: false, + }, + addrs[1].String(): { + Weight: 1, + Miss: false, + Abstain: false, + }, + addrs[2].String(): { + Weight: 1, + Miss: false, + Abstain: false, + }, + } + + result := make(map[string]types.BlockData) + onConsensus := func(ctx sdk.Context, voteData map[string]types.BlockData) { + for chainId, block := range voteData { + result[chainId] = block + } + } + vp := NewBlockVoteProcessor(onConsensus, aggregateVotes, thresholdVotes) + ctx := sdk.NewContext(nil, tmproto.Header{Height: 1}, false, log.NewNopLogger()) + + vp.TallyVotes(ctx, validatorClaimMap) + + require.Equal(t, "1", result["1"].ChainId) + require.Equal(t, int64(100), result["1"].BlockNumber) + require.Equal(t, "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", result["1"].BlockHash) + + require.False(t, validatorClaimMap[addrs[0].String()].Miss) + require.False(t, validatorClaimMap[addrs[1].String()].Miss) + require.True(t, validatorClaimMap[addrs[2].String()].Miss) +} + +func TestOwnershipVoteProcessor(t *testing.T) { + thresholdVotes := math.NewInt(2) + addrs := genValAddrs(3) + + aggregateVotes := []types.AggregateVote{ + { + Voter: addrs[0].String(), + VoteData: []*types.VoteData{ + { + Topic: types.OralceTopic_OWNERSHIP, + Data: []string{"1/0x123/0x0:0x777"}, + }, + }, + }, + { + Voter: addrs[1].String(), + VoteData: []*types.VoteData{ + { + Topic: types.OralceTopic_OWNERSHIP, + Data: []string{"1/0x123/0x0:0x777"}, + }, + }, + }, + { + Voter: addrs[2].String(), + VoteData: []*types.VoteData{ + { + Topic: types.OralceTopic_OWNERSHIP, + Data: []string{"1/0x123/0x0:0x666"}, + }, + }, + }, + } + + validatorClaimMap := map[string]types.Claim{ + addrs[0].String(): { + Weight: 1, + Miss: false, + Abstain: false, + }, + addrs[1].String(): { + Weight: 1, + Miss: false, + Abstain: false, + }, + addrs[2].String(): { + Weight: 1, + Miss: false, + Abstain: false, + }, + } + + result := make(map[string]ctypes.HexAddressString) + onConsensus := func(ctx sdk.Context, voteData map[types.Nft]ctypes.HexAddressString) { + for nft, owner := range voteData { + result[nft.FormatString()] = owner + } + } + vp := NewOwnershipVoteProcessor(onConsensus, aggregateVotes, thresholdVotes) + ctx := sdk.NewContext(nil, tmproto.Header{Height: 1}, false, log.NewNopLogger()) + + vp.TallyVotes(ctx, validatorClaimMap) + + require.Equal(t, ctypes.HexAddressString("0x777"), result["1/0x123/0x0"]) + + require.False(t, validatorClaimMap[addrs[0].String()].Miss) + require.False(t, validatorClaimMap[addrs[1].String()].Miss) + require.True(t, validatorClaimMap[addrs[2].String()].Miss) +} diff --git a/x/settlement/genesis.go b/x/settlement/genesis.go index b7cc02ff..fc3fb672 100644 --- a/x/settlement/genesis.go +++ b/x/settlement/genesis.go @@ -24,6 +24,8 @@ func InitGenesis(ctx sdk.Context, k *keeper.SettlementKeeper, genState types.Gen k.CreateTreasuryAccount(ctx, tenant.Id) k.SetTenant(ctx, &tenant) } + + k.InitAccountModule(ctx) } // ExportGenesis returns the module's exported genesis diff --git a/x/settlement/genesis_test.go b/x/settlement/genesis_test.go index 78250378..de28bbb3 100644 --- a/x/settlement/genesis_test.go +++ b/x/settlement/genesis_test.go @@ -13,7 +13,6 @@ import ( feemarkettypes "github.com/settlus/chain/evmos/x/feemarket/types" "github.com/settlus/chain/testutil/sample" - settlustypes "github.com/settlus/chain/types" "github.com/settlus/chain/app" utiltx "github.com/settlus/chain/testutil/tx" @@ -98,10 +97,10 @@ func (suite *GenesisTestSuite) TestGenesis_ExportGenesis() { Id: 1, TenantId: 1, Utxr: types.UTXR{ - RequestId: "request-0", - Recipient: settlustypes.NewHexAddressString(sdk.MustAccAddressFromBech32(suite.creator)), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: 101, + RequestId: "request-0", + Recipients: types.SingleRecipients(sdk.MustAccAddressFromBech32(suite.creator)), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: 101, }, }, }, diff --git a/x/settlement/keeper/grpc_query_test.go b/x/settlement/keeper/grpc_query_test.go index 2accf578..50583811 100644 --- a/x/settlement/keeper/grpc_query_test.go +++ b/x/settlement/keeper/grpc_query_test.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - settlustypes "github.com/settlus/chain/types" "github.com/settlus/chain/x/settlement/types" ) @@ -21,19 +20,19 @@ func (suite *SettlementTestSuite) TestKeeper_UTXR() { // Create UTXRs for i := 1; i < 4; i++ { utxrId, err := s.keeper.CreateUTXR(s.ctx, uint64(1), &types.UTXR{ - RequestId: fmt.Sprintf("request-%d", i), - Recipient: settlustypes.NewHexAddressString(s.creator), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), - PayoutBlock: 100, + RequestId: fmt.Sprintf("request-%d", i), + Recipients: types.SingleRecipients(s.creator), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), + CreatedAt: 100, }) s.NoError(err) s.Equal(uint64(i), utxrId) utxrId, err = s.keeper.CreateUTXR(s.ctx, uint64(2), &types.UTXR{ - RequestId: fmt.Sprintf("request-%d", i), - Recipient: settlustypes.NewHexAddressString(s.creator), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), - PayoutBlock: 100, + RequestId: fmt.Sprintf("request-%d", i), + Recipients: types.SingleRecipients(s.creator), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), + CreatedAt: 100, }) s.NoError(err) s.Equal(uint64(i), utxrId) @@ -62,19 +61,19 @@ func (suite *SettlementTestSuite) TestKeeper_UTXRs() { // Create UTXRs for i := 1; i < 4; i++ { utxrId, err := s.keeper.CreateUTXR(s.ctx, 1, &types.UTXR{ - RequestId: fmt.Sprintf("request-%d", i), - Recipient: settlustypes.NewHexAddressString(s.creator), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), - PayoutBlock: 100, + RequestId: fmt.Sprintf("request-%d", i), + Recipients: types.SingleRecipients(s.creator), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), + CreatedAt: 100, }) s.NoError(err) s.Equal(uint64(i), utxrId) utxrId, err = s.keeper.CreateUTXR(s.ctx, 2, &types.UTXR{ - RequestId: fmt.Sprintf("request-%d", i), - Recipient: settlustypes.NewHexAddressString(s.creator), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), - PayoutBlock: 100, + RequestId: fmt.Sprintf("request-%d", i), + Recipients: types.SingleRecipients(s.creator), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), + CreatedAt: 100, }) s.NoError(err) s.Equal(uint64(i), utxrId) diff --git a/x/settlement/keeper/keeper.go b/x/settlement/keeper/keeper.go index ce049143..06a8b0d1 100644 --- a/x/settlement/keeper/keeper.go +++ b/x/settlement/keeper/keeper.go @@ -5,7 +5,11 @@ import ( errorsmod "cosmossdk.io/errors" sdkerrorstypes "github.com/cosmos/cosmos-sdk/types/errors" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/ethereum/go-ethereum/common" + "github.com/settlus/chain/contracts" + ctypes "github.com/settlus/chain/types" "github.com/settlus/chain/x/settlement/types" "github.com/cosmos/cosmos-sdk/codec" @@ -23,7 +27,6 @@ type SettlementKeeper struct { bk types.BankKeeper erc20k types.Erc20Keeper evmk types.EvmKeeper - nk types.NftOwnershipKeeper } func NewKeeper( @@ -34,7 +37,6 @@ func NewKeeper( bk types.BankKeeper, erc20k types.Erc20Keeper, evmk types.EvmKeeper, - nk types.NftOwnershipKeeper, ) *SettlementKeeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -49,25 +51,64 @@ func NewKeeper( bk: bk, erc20k: erc20k, evmk: evmk, - nk: nk, } } +func (k SettlementKeeper) InitAccountModule(ctx sdk.Context) { + baseAcc := authtypes.NewBaseAccountWithAddress(authtypes.NewModuleAddress(types.ModuleName)) + accountName := fmt.Sprintf("%s-module-account", types.ModuleName) + acc := authtypes.NewModuleAccount(baseAcc, accountName) + k.ak.SetModuleAccount(ctx, acc) +} + func (k SettlementKeeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } +//NFT + // GetRecipient returns the owner of the given NFT from x/nftownership module -func (k SettlementKeeper) GetRecipient(ctx sdk.Context, chainId string, contractAddr string, tokenIdHex string) (string, error) { - ownerAddress, err := k.nk.OwnerOf(ctx, chainId, contractAddr, tokenIdHex) +func (k SettlementKeeper) GetRecipients(ctx sdk.Context, chainId string, contractAddr string, tokenIdHex string) ([]*types.Recipient, error) { + recipients := make([]*types.Recipient, 0) + if ctx.ChainID() != chainId { + // length 0 recipients means that owner of NFT will be determined by voting + return recipients, nil + } + + address, err := k.FindInternalOwner(ctx, contractAddr, tokenIdHex) if err != nil { if sdkerrorstypes.ErrInvalidAddress.Is(err) { - return "", err + return nil, err } // Note: we shouldn't return the EVM error log directly to the client - return "", errorsmod.Wrapf(types.ErrEVMCallFailed, "failed to get the owner of the given NFT") + return nil, errorsmod.Wrapf(types.ErrEVMCallFailed, "failed to get the owner of the given NFT") + } + + // TODO: suupport multi-owner + recipient := &types.Recipient{ + Address: ctypes.HexAddressString(address.Hex()), + } + + return append(recipients, recipient), nil +} + +// FindInternalOwner returns the owner of the given NFT on current chain +func (k SettlementKeeper) FindInternalOwner( + ctx sdk.Context, contractAddr string, tokenIdHex string, +) (*common.Address, error) { + erc721 := contracts.ERC721Contract.ABI + tokenId := common.HexToHash(tokenIdHex) + contract := common.HexToAddress(contractAddr) + res, err := k.evmk.CallEVM(ctx, erc721, types.ModuleAddress, contract, false, "ownerOf", tokenId.Big()) + if err != nil { + return nil, fmt.Errorf("call evm failed: %w", err) + } + + owner := common.BytesToAddress(res.Ret) + if owner == common.HexToAddress("") { + return nil, errorsmod.Wrapf(sdkerrorstypes.ErrInvalidAddress, "contract '%s', token '%s', owner '%s'", contract, tokenId, owner.String()) } - return ownerAddress.Hex(), nil + return &owner, nil } diff --git a/x/settlement/keeper/keeper_test.go b/x/settlement/keeper/keeper_test.go index 725db5f7..597d7895 100644 --- a/x/settlement/keeper/keeper_test.go +++ b/x/settlement/keeper/keeper_test.go @@ -114,11 +114,6 @@ func (suite *SettlementTestSuite) DoSetupTest(t require.TestingT) { err = suite.app.EvmKeeper.SetParams(suite.ctx, evmParams) require.NoError(t, err) - // nft ownership module params - nftownershipParams := suite.app.NftOwnershipKeeper.GetParams(suite.ctx) - nftownershipParams.AllowedChainIds = []string{"settlus_5371-1"} - suite.app.NftOwnershipKeeper.SetParams(suite.ctx, nftownershipParams) - // keeper suite.keeper = suite.app.SettlementKeeper diff --git a/x/settlement/keeper/msg_server.go b/x/settlement/keeper/msg_server.go index 2f930930..0f210c6d 100644 --- a/x/settlement/keeper/msg_server.go +++ b/x/settlement/keeper/msg_server.go @@ -12,6 +12,7 @@ import ( "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" + oracletypes "github.com/settlus/chain/x/oracle/types" ) type msgServer struct { @@ -47,21 +48,26 @@ func (k msgServer) Record(goCtx context.Context, msg *types.MsgRecord) (*types.M return nil, types.ErrInvalidTenant } - recipient, err := k.GetRecipient(ctx, msg.ChainId, msg.ContractAddress, msg.TokenIdHex) + recipients, err := k.GetRecipients(ctx, msg.ChainId, msg.ContractAddress, msg.TokenIdHex) if err != nil { return nil, err } - payoutBlock := uint64(ctx.BlockHeight()) + tenant.PayoutPeriod + payoutBlock := uint64(ctx.BlockHeight()) utxrId, err := k.CreateUTXR( ctx, msg.TenantId, &types.UTXR{ - RequestId: msg.RequestId, - Recipient: settlustypes.HexAddressString(recipient), - Amount: msg.Amount, - PayoutBlock: payoutBlock, + RequestId: msg.RequestId, + Recipients: recipients, + Amount: msg.Amount, + Nft: &oracletypes.Nft{ + ChainId: msg.ChainId, + ContractAddr: settlustypes.HexAddressString(msg.ContractAddress), + TokenId: settlustypes.HexAddressString(msg.TokenIdHex), + }, + CreatedAt: payoutBlock, }, ) if err != nil { @@ -69,17 +75,19 @@ func (k msgServer) Record(goCtx context.Context, msg *types.MsgRecord) (*types.M } if err := ctx.EventManager().EmitTypedEvents(&types.EventRecord{ - Sender: msg.Sender, - Tenant: msg.TenantId, - UtxrId: utxrId, - RequestId: msg.RequestId, - Amount: msg.Amount, - ChainId: msg.ChainId, - ContractAddress: msg.ContractAddress, - TokenIdHex: msg.TokenIdHex, - Recipient: recipient, - Metadata: msg.Metadata, - PayoutBlock: payoutBlock, + Sender: msg.Sender, + Tenant: msg.TenantId, + UtxrId: utxrId, + RequestId: msg.RequestId, + Amount: msg.Amount, + Nft: &oracletypes.Nft{ + ChainId: msg.ChainId, + ContractAddr: settlustypes.HexAddressString(msg.ContractAddress), + TokenId: settlustypes.HexAddressString(msg.TokenIdHex), + }, + Recipients: recipients, + Metadata: msg.Metadata, + CreatedAt: uint64(ctx.BlockHeight()), }); err != nil { return nil, errorsmod.Wrapf(types.ErrEventCreationFailed, "EventRecord event creation failed") } @@ -93,8 +101,7 @@ func (k msgServer) Record(goCtx context.Context, msg *types.MsgRecord) (*types.M ) return &types.MsgRecordResponse{ - UtxrId: utxrId, - Recipient: recipient, + UtxrId: utxrId, }, nil } @@ -118,9 +125,8 @@ func (k msgServer) Cancel(goCtx context.Context, msg *types.MsgCancel) (*types.M } if err := ctx.EventManager().EmitTypedEvents(&types.EventCancel{ - Tenant: msg.TenantId, - UtxrId: utxrId, - RequestId: msg.RequestId, + Tenant: msg.TenantId, + UtxrId: utxrId, }); err != nil { return nil, errorsmod.Wrapf(types.ErrEventCreationFailed, "EventCancel event creation failed") } diff --git a/x/settlement/keeper/msg_server_test.go b/x/settlement/keeper/msg_server_test.go index c4ba089f..e4e9b933 100644 --- a/x/settlement/keeper/msg_server_test.go +++ b/x/settlement/keeper/msg_server_test.go @@ -8,7 +8,6 @@ import ( "github.com/settlus/chain/testutil/sample" utiltx "github.com/settlus/chain/testutil/tx" - settlustypes "github.com/settlus/chain/types" "github.com/settlus/chain/x/settlement/types" ) @@ -31,7 +30,7 @@ func (suite *SettlementTestSuite) TestMsgServer_Record() { utxr := suite.keeper.GetUTXRByRequestId(suite.ctx, 1, "request-1") suite.NotNil(utxr) suite.EqualValues(utxr.Amount.Amount.Int64(), 10) - suite.EqualValues(utxr.Recipient, suite.nftOwner) + suite.EqualValues(utxr.Recipients[0].Address, suite.nftOwner) } func (suite *SettlementTestSuite) TestMsgServer_Record_CreateAccount() { @@ -380,10 +379,10 @@ func (suite *SettlementTestSuite) TestMsgServer_DepositToTreasury_MultipleTenant func (suite *SettlementTestSuite) TestMsgServer_Cancel() { requestId := "request-cancel" _, err := suite.keeper.CreateUTXR(suite.ctx, 1, &types.UTXR{ - RequestId: requestId, - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", math.NewInt(10)), - PayoutBlock: uint64(100), + RequestId: requestId, + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", math.NewInt(10)), + CreatedAt: uint64(100), }) suite.NoError(err) @@ -404,10 +403,10 @@ func (suite *SettlementTestSuite) TestMsgServer_Cancel() { func (suite *SettlementTestSuite) TestMsgServer_Cancel_InvalidTenant() { requestId := "request-cancel" _, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: requestId, - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", math.NewInt(10)), - PayoutBlock: uint64(100), + RequestId: requestId, + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", math.NewInt(10)), + CreatedAt: uint64(100), }) suite.NoError(err) @@ -429,10 +428,10 @@ func (suite *SettlementTestSuite) TestMsgServer_Cancel_InvalidTenant() { func (suite *SettlementTestSuite) TestMsgServer_Cancel_NonAdmin() { requestId := "request-cancel" _, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: requestId, - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", math.NewInt(10)), - PayoutBlock: uint64(100), + RequestId: requestId, + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", math.NewInt(10)), + CreatedAt: uint64(100), }) suite.NoError(err) diff --git a/x/settlement/keeper/settle.go b/x/settlement/keeper/settle.go index b9d0abe0..19758d0a 100644 --- a/x/settlement/keeper/settle.go +++ b/x/settlement/keeper/settle.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" @@ -32,29 +33,30 @@ func (k SettlementKeeper) settleUTXRs(ctx sdk.Context, tenantId uint64) error { iterator := store.Iterator(nil, nil) defer iterator.Close() + period := k.GetPayoutPeriod(ctx, tenantId) for ; iterator.Valid(); iterator.Next() { var utxr types.UTXR k.cdc.MustUnmarshal(iterator.Value(), &utxr) utxrId := sdk.BigEndianToUint64(iterator.Key()) - - if utxr.PayoutBlock > uint64(ctx.BlockHeight()) { - logger.Debug("skip payout", "tenant", tenantId, "payoutBlock", utxr.PayoutBlock, "currentBlock", ctx.BlockHeight()) + payoutBlock := utxr.CreatedAt + period + if payoutBlock > uint64(ctx.BlockHeight()) { + logger.Debug("skip payout", "tenant", tenantId, "payoutBlock", payoutBlock, "currentBlock", ctx.BlockHeight()) break } + if len(utxr.Recipients) == 0 { + continue + } + if err := k.tryPayout(ctx, tenantId, &utxr); err != nil { - logger.Error("failed to payout", "tenant", tenantId, "recipient", utxr.Recipient, "amount", utxr.Amount.String(), "error", err) + logger.Error("failed to payout", "tenant", tenantId, "recipient", utxr.Recipients, "amount", utxr.Amount.String(), "error", err) break } - recipientCosmosAddr := sdk.AccAddress(common.FromHex(utxr.Recipient.String())) if err := ctx.EventManager().EmitTypedEvents(&types.EventSettled{ - Tenant: tenantId, - UtxrId: utxrId, - RequestId: utxr.RequestId, - Amount: utxr.Amount, - Recipient: recipientCosmosAddr.String(), + Tenant: tenantId, + UtxrId: utxrId, }); err != nil { logger.Error("failed to emit EventSettled event", "tenant", tenantId, "error", err) } @@ -69,29 +71,53 @@ func (k SettlementKeeper) settleUTXRs(ctx sdk.Context, tenantId uint64) error { return nil } -func (k SettlementKeeper) tryPayout(ctx sdk.Context, tenantId uint64, utxr *types.UTXR) (err error) { +func (k SettlementKeeper) tryPayout(ctx sdk.Context, tenantId uint64, utxr *types.UTXR) error { treasuryAddr := types.GetTenantTreasuryAccount(tenantId) - recipientCosmosAddr := sdk.AccAddress(common.FromHex(utxr.Recipient.String())) tenant := k.GetTenant(ctx, tenantId) if tenant == nil { return fmt.Errorf("tenant [%d] not found", tenantId) } - switch payoutMethod := tenant.PayoutMethod; { - case payoutMethod == types.PayoutMethod_Native: - if k.erc20k.IsDenomRegistered(ctx, utxr.Amount.Denom) { - msg := erc20types.NewMsgConvertCoin(utxr.Amount, common.BytesToAddress(recipientCosmosAddr), treasuryAddr) - _, err = k.erc20k.ConvertCoin(ctx, msg) + var totalWeight uint32 = 0 + for _, recipient := range utxr.Recipients { + totalWeight += recipient.Weight + } + + for _, recipient := range utxr.Recipients { + recipientCosmosAddr := sdk.AccAddress(common.FromHex(recipient.Address.String())) + + // if total weight is 0, payout should be distributed equally + // otherwise it will be distributed based on the weight + amount := sdk.Coin{ + Denom: utxr.Amount.Denom, + Amount: math.ZeroInt(), + } + + if totalWeight == 0 { + amount.Amount = utxr.Amount.Amount.Quo(sdk.NewInt(int64(len(utxr.Recipients)))) } else { - err = k.bk.SendCoins(ctx, treasuryAddr, recipientCosmosAddr, sdk.NewCoins(utxr.Amount)) + amount.Amount = utxr.Amount.Amount.Mul(sdk.NewInt(int64(recipient.Weight))).Quo(sdk.NewInt(int64(totalWeight))) + } + + var err error + switch payoutMethod := tenant.PayoutMethod; { + case payoutMethod == types.PayoutMethod_Native: + if k.erc20k.IsDenomRegistered(ctx, amount.Denom) { + _, err = k.erc20k.ConvertCoin(ctx, erc20types.NewMsgConvertCoin(amount, common.BytesToAddress(recipientCosmosAddr), treasuryAddr)) + } else { + err = k.bk.SendCoins(ctx, treasuryAddr, recipientCosmosAddr, sdk.NewCoins(amount)) + } + case payoutMethod == types.PayoutMethod_MintContract: + contractAddr := tenant.GetContractAddress() + _, err = k.evmk.CallEVM(ctx, contracts.SBTContract.ABI, common.BytesToAddress(treasuryAddr), common.HexToAddress(contractAddr), + true, "mint", common.BytesToAddress(recipientCosmosAddr), amount.Amount.BigInt()) + default: + return fmt.Errorf("invalid payout method: %s", payoutMethod) + } + if err != nil { + return err } - case payoutMethod == types.PayoutMethod_MintContract: - contractAddr := tenant.GetContractAddress() - _, err = k.evmk.CallEVM(ctx, contracts.SBTContract.ABI, common.BytesToAddress(treasuryAddr), common.HexToAddress(contractAddr), - true, "mint", common.BytesToAddress(recipientCosmosAddr), utxr.Amount.Amount.BigInt()) - default: - return fmt.Errorf("invalid payout method: %s", payoutMethod) } - return err + return nil } diff --git a/x/settlement/keeper/settle_test.go b/x/settlement/keeper/settle_test.go index f851daef..a5ac49c1 100644 --- a/x/settlement/keeper/settle_test.go +++ b/x/settlement/keeper/settle_test.go @@ -11,7 +11,6 @@ import ( "github.com/settlus/chain/contracts" "github.com/settlus/chain/testutil/sample" utiltx "github.com/settlus/chain/testutil/tx" - settlustypes "github.com/settlus/chain/types" "github.com/settlus/chain/x/settlement/types" ) @@ -26,10 +25,10 @@ func (suite *SettlementTestSuite) TestSettle_Settle() { requestId := "request-1" recipient := sdk.MustAccAddressFromBech32(sample.AccAddress()) _, err = suite.keeper.CreateUTXR(suite.ctx, 1, &types.UTXR{ - RequestId: requestId, - Recipient: settlustypes.NewHexAddressString(recipient), - Amount: sdk.NewCoin("uusdc", math.NewInt(10)), - PayoutBlock: 10, + RequestId: requestId, + Recipients: types.SingleRecipients(recipient), + Amount: sdk.NewCoin("uusdc", math.NewInt(10)), + CreatedAt: 10, }) suite.NoError(err) @@ -63,10 +62,10 @@ func (suite *SettlementTestSuite) TestSettle_Settle_InsufficientTreasuryBalance( // total amount to settle is 100 for i := 0; i < 10; i++ { res, err := suite.keeper.CreateUTXR(suite.ctx, 1, &types.UTXR{ - RequestId: fmt.Sprintf("request-%d", i), - Recipient: settlustypes.NewHexAddressString(recipient), - Amount: sdk.NewCoin("uusdc", math.NewInt(10)), - PayoutBlock: uint64(suite.ctx.BlockHeight()) + 10, + RequestId: fmt.Sprintf("request-%d", i), + Recipients: types.SingleRecipients(recipient), + Amount: sdk.NewCoin("uusdc", math.NewInt(10)), + CreatedAt: uint64(suite.ctx.BlockHeight()), }) suite.NoError(err) @@ -104,10 +103,10 @@ func (suite *SettlementTestSuite) TestSettle_Settle_TopUpTreasuryBalance() { recipient := sdk.AccAddress(utiltx.GenerateAddress().Bytes()) _, err = suite.keeper.CreateUTXR(suite.ctx, 1, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(recipient), - Amount: sdk.NewCoin("uusdc", math.NewInt(100)), - PayoutBlock: uint64(suite.ctx.BlockHeight()) + 10, + RequestId: "request-1", + Recipients: types.SingleRecipients(recipient), + Amount: sdk.NewCoin("uusdc", math.NewInt(100)), + CreatedAt: uint64(suite.ctx.BlockHeight()), }) suite.NoError(err) diff --git a/x/settlement/keeper/utxr.go b/x/settlement/keeper/utxr.go index 8cfed887..afe1f513 100644 --- a/x/settlement/keeper/utxr.go +++ b/x/settlement/keeper/utxr.go @@ -8,6 +8,8 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + ctypes "github.com/settlus/chain/types" + oracletypes "github.com/settlus/chain/x/oracle/types" ) // GetUTXRStore returns the UTXR store for the given tenantId @@ -43,13 +45,15 @@ func (k SettlementKeeper) CreateUTXR(ctx sdk.Context, tenantId uint64, utxr *typ return 0, sdkerrors.Wrapf(types.ErrDuplicateRequestId, "UTXR with [request ID: %s] [tenant ID: %d] already exists.", utxr.RequestId, tenantId) } - if !common.IsHexAddress(utxr.Recipient.String()) { - return 0, sdkerrors.Wrapf(types.ErrInvalidAccount, "Invalid recipient address: %s", utxr.Recipient) - } + for _, recipient := range utxr.Recipients { + if !common.IsHexAddress(recipient.Address.String()) { + return 0, sdkerrors.Wrapf(types.ErrInvalidAccount, "Invalid recipient address: %s", recipient.Address) + } - recipient := common.HexToAddress(utxr.Recipient.String()).Bytes() - if !k.ak.HasAccount(ctx, recipient) { - k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, recipient)) + accAddr := sdk.AccAddress(recipient.Address.Bytes()) + if !k.ak.HasAccount(ctx, accAddr) { + k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, accAddr)) + } } utxrId := k.GetLargestUTXRId(ctx, tenantId) + 1 @@ -137,3 +141,59 @@ func (k SettlementKeeper) GetAllUTXRWithTenantAndID(ctx sdk.Context) (list []typ return list } + +func (k SettlementKeeper) GetAllUniqueNftToVerify(ctx sdk.Context, until uint64) (list []oracletypes.Nft) { + nfts := make(map[oracletypes.Nft]struct{}) + + store := ctx.KVStore(k.storeKey) + utxrStore := prefix.NewStore(store, types.UTXRPrefix) + iterator := utxrStore.Iterator(nil, nil) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var utxr types.UTXR + k.cdc.MustUnmarshal(iterator.Value(), &utxr) + if len(utxr.Recipients) == 0 && until >= utxr.CreatedAt { + nfts[*utxr.Nft] = struct{}{} + } + } + + for nft := range nfts { + list = append(list, nft) + } + + return list +} + +func (k SettlementKeeper) SetRecipients(ctx sdk.Context, nfts map[oracletypes.Nft]ctypes.HexAddressString, until uint64) { + store := ctx.KVStore(k.storeKey) + utxrStore := prefix.NewStore(store, types.UTXRPrefix) + iterator := utxrStore.Iterator(nil, nil) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var utxr types.UTXR + k.cdc.MustUnmarshal(iterator.Value(), &utxr) + if len(utxr.Recipients) == 0 && until >= utxr.CreatedAt { + owner, ok := nfts[*utxr.Nft] + if !ok { + continue + } + utxr.Recipients = []*types.Recipient{{ + Address: owner, + }} + bz := k.cdc.MustMarshal(&utxr) + key := iterator.Key() + utxrStore.Set(key, bz) + + err := ctx.EventManager().EmitTypedEvents(&types.EventSetRecipients{ + Tenant: sdk.BigEndianToUint64(key[0:8]), + UtxrId: sdk.BigEndianToUint64(key[8:]), + Recipients: utxr.Recipients, + }) + if err != nil { + k.Logger(ctx).Error("failed to emit EventSetRecipients", "error", err) + } + } + } +} diff --git a/x/settlement/keeper/utxr_test.go b/x/settlement/keeper/utxr_test.go index d04b9dde..9e251eb1 100644 --- a/x/settlement/keeper/utxr_test.go +++ b/x/settlement/keeper/utxr_test.go @@ -4,16 +4,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - settlustypes "github.com/settlus/chain/types" "github.com/settlus/chain/x/settlement/types" ) func (suite *SettlementTestSuite) TestKeeper_HasUTXRByRequestId() { utxrId, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(1), utxrId) @@ -30,10 +29,10 @@ func (suite *SettlementTestSuite) TestKeeper_GetLatestUTXR() { suite.Equal(uint64(0), id) utxrId, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(1), utxrId) @@ -45,10 +44,10 @@ func (suite *SettlementTestSuite) TestKeeper_GetLatestUTXR() { suite.Equal(uint64(1), id) utxrId, err = suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-2", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-2", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(2), utxrId) @@ -78,10 +77,10 @@ func (suite *SettlementTestSuite) TestKeeper_GetLatestUTXR_MultipleTenants() { suite.Equal(uint64(0), t1Id) utxrId, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(1), utxrId) @@ -93,10 +92,10 @@ func (suite *SettlementTestSuite) TestKeeper_GetLatestUTXR_MultipleTenants() { suite.Equal(uint64(1), t0Id) utxrId, err = suite.keeper.CreateUTXR(suite.ctx, 1, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(1), utxrId) @@ -108,10 +107,10 @@ func (suite *SettlementTestSuite) TestKeeper_GetLatestUTXR_MultipleTenants() { suite.Equal(uint64(1), t1Id) utxrId, err = suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-2", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-2", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(2), utxrId) @@ -128,10 +127,10 @@ func (suite *SettlementTestSuite) TestKeeper_GetLatestUTXR_MultipleTenants() { func (suite *SettlementTestSuite) TestKeeper_CreateUTXR() { utxrId, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(1), utxrId) @@ -142,25 +141,25 @@ func (suite *SettlementTestSuite) TestKeeper_CreateUTXR() { func (suite *SettlementTestSuite) TestKeeper_GetUTXRByRequestId() { _, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.creator), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.creator), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), + CreatedAt: uint64(100), }) suite.NoError(err) utxr := suite.keeper.GetUTXRByRequestId(suite.ctx, 0, "request-1") suite.NotNil(utxr) suite.EqualValues(10, utxr.Amount.Amount.Int64()) - suite.EqualValues(suite.creator, common.FromHex(utxr.Recipient.String())) + suite.EqualValues(suite.creator, utxr.Recipients[0].Address.Bytes()) } func (suite *SettlementTestSuite) TestKeeper_DeleteUTXRByRequestId() { _, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.creator), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.creator), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(10)), + CreatedAt: uint64(100), }) suite.NoError(err) @@ -169,7 +168,7 @@ func (suite *SettlementTestSuite) TestKeeper_DeleteUTXRByRequestId() { utxr := suite.keeper.GetUTXRByRequestId(suite.ctx, 0, "request-1") suite.NotNil(utxr) suite.EqualValues(10, utxr.Amount.Amount.Int64()) - suite.EqualValues(suite.creator, common.FromHex(utxr.Recipient.String())) + suite.EqualValues(suite.creator, common.FromHex(utxr.Recipients[0].Address.String())) utxrId, err := suite.keeper.DeleteUTXRByRequestId(suite.ctx, 0, "request-1") suite.NoError(err) @@ -181,19 +180,19 @@ func (suite *SettlementTestSuite) TestKeeper_DeleteUTXRByRequestId() { func (suite *SettlementTestSuite) TestKeeper_GetAllUTXRWithTenantAndID() { utxrId, err := suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-1", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-1", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(1), utxrId) utxrId, err = suite.keeper.CreateUTXR(suite.ctx, 0, &types.UTXR{ - RequestId: "request-2", - Recipient: settlustypes.NewHexAddressString(suite.appAdmin), - Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), - PayoutBlock: uint64(100), + RequestId: "request-2", + Recipients: types.SingleRecipients(suite.appAdmin), + Amount: sdk.NewCoin("uusdc", sdk.NewInt(100)), + CreatedAt: uint64(100), }) suite.NoError(err) suite.Equal(uint64(2), utxrId) diff --git a/x/settlement/types/event.pb.go b/x/settlement/types/event.pb.go index 7b3577bb..453725e4 100644 --- a/x/settlement/types/event.pb.go +++ b/x/settlement/types/event.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/settlement/event.proto +// source: settlus/settlement/v1alpha1/event.proto package types @@ -8,6 +8,7 @@ import ( types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + types1 "github.com/settlus/chain/x/oracle/types" io "io" math "math" math_bits "math/bits" @@ -25,18 +26,15 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type EventSettled struct { - Tenant uint64 `protobuf:"varint,1,opt,name=tenant,proto3" json:"tenant,omitempty"` - UtxrId uint64 `protobuf:"varint,2,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` - RequestId string `protobuf:"bytes,3,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` - Amount types.Coin `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount"` - Recipient string `protobuf:"bytes,5,opt,name=recipient,proto3" json:"recipient,omitempty"` + Tenant uint64 `protobuf:"varint,1,opt,name=tenant,proto3" json:"tenant,omitempty"` + UtxrId uint64 `protobuf:"varint,2,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` } func (m *EventSettled) Reset() { *m = EventSettled{} } func (m *EventSettled) String() string { return proto.CompactTextString(m) } func (*EventSettled) ProtoMessage() {} func (*EventSettled) Descriptor() ([]byte, []int) { - return fileDescriptor_c944366c474aba71, []int{0} + return fileDescriptor_318f5afc0de44f41, []int{0} } func (m *EventSettled) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,46 +77,83 @@ func (m *EventSettled) GetUtxrId() uint64 { return 0 } -func (m *EventSettled) GetRequestId() string { +type EventSetRecipients struct { + Tenant uint64 `protobuf:"varint,1,opt,name=tenant,proto3" json:"tenant,omitempty"` + UtxrId uint64 `protobuf:"varint,2,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` + Recipients []*Recipient `protobuf:"bytes,3,rep,name=recipients,proto3" json:"recipients,omitempty"` +} + +func (m *EventSetRecipients) Reset() { *m = EventSetRecipients{} } +func (m *EventSetRecipients) String() string { return proto.CompactTextString(m) } +func (*EventSetRecipients) ProtoMessage() {} +func (*EventSetRecipients) Descriptor() ([]byte, []int) { + return fileDescriptor_318f5afc0de44f41, []int{1} +} +func (m *EventSetRecipients) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventSetRecipients) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventSetRecipients.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 *EventSetRecipients) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventSetRecipients.Merge(m, src) +} +func (m *EventSetRecipients) XXX_Size() int { + return m.Size() +} +func (m *EventSetRecipients) XXX_DiscardUnknown() { + xxx_messageInfo_EventSetRecipients.DiscardUnknown(m) +} + +var xxx_messageInfo_EventSetRecipients proto.InternalMessageInfo + +func (m *EventSetRecipients) GetTenant() uint64 { if m != nil { - return m.RequestId + return m.Tenant } - return "" + return 0 } -func (m *EventSettled) GetAmount() types.Coin { +func (m *EventSetRecipients) GetUtxrId() uint64 { if m != nil { - return m.Amount + return m.UtxrId } - return types.Coin{} + return 0 } -func (m *EventSettled) GetRecipient() string { +func (m *EventSetRecipients) GetRecipients() []*Recipient { if m != nil { - return m.Recipient + return m.Recipients } - return "" + return nil } type EventRecord struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - Tenant uint64 `protobuf:"varint,2,opt,name=tenant,proto3" json:"tenant,omitempty"` - UtxrId uint64 `protobuf:"varint,3,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` - RequestId string `protobuf:"bytes,4,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` - Amount types.Coin `protobuf:"bytes,5,opt,name=amount,proto3" json:"amount"` - ChainId string `protobuf:"bytes,6,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - ContractAddress string `protobuf:"bytes,7,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` - TokenIdHex string `protobuf:"bytes,8,opt,name=token_id_hex,json=tokenIdHex,proto3" json:"token_id_hex,omitempty"` - Recipient string `protobuf:"bytes,9,opt,name=recipient,proto3" json:"recipient,omitempty"` - Metadata string `protobuf:"bytes,10,opt,name=metadata,proto3" json:"metadata,omitempty"` - PayoutBlock uint64 `protobuf:"varint,11,opt,name=payout_block,json=payoutBlock,proto3" json:"payout_block,omitempty"` + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + Tenant uint64 `protobuf:"varint,2,opt,name=tenant,proto3" json:"tenant,omitempty"` + UtxrId uint64 `protobuf:"varint,3,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` + RequestId string `protobuf:"bytes,4,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + Amount types.Coin `protobuf:"bytes,5,opt,name=amount,proto3" json:"amount"` + Nft *types1.Nft `protobuf:"bytes,6,opt,name=nft,proto3" json:"nft,omitempty"` + Recipients []*Recipient `protobuf:"bytes,7,rep,name=recipients,proto3" json:"recipients,omitempty"` + Metadata string `protobuf:"bytes,8,opt,name=metadata,proto3" json:"metadata,omitempty"` + CreatedAt uint64 `protobuf:"varint,9,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` } func (m *EventRecord) Reset() { *m = EventRecord{} } func (m *EventRecord) String() string { return proto.CompactTextString(m) } func (*EventRecord) ProtoMessage() {} func (*EventRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_c944366c474aba71, []int{1} + return fileDescriptor_318f5afc0de44f41, []int{2} } func (m *EventRecord) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -182,32 +217,18 @@ func (m *EventRecord) GetAmount() types.Coin { return types.Coin{} } -func (m *EventRecord) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" -} - -func (m *EventRecord) GetContractAddress() string { - if m != nil { - return m.ContractAddress - } - return "" -} - -func (m *EventRecord) GetTokenIdHex() string { +func (m *EventRecord) GetNft() *types1.Nft { if m != nil { - return m.TokenIdHex + return m.Nft } - return "" + return nil } -func (m *EventRecord) GetRecipient() string { +func (m *EventRecord) GetRecipients() []*Recipient { if m != nil { - return m.Recipient + return m.Recipients } - return "" + return nil } func (m *EventRecord) GetMetadata() string { @@ -217,24 +238,23 @@ func (m *EventRecord) GetMetadata() string { return "" } -func (m *EventRecord) GetPayoutBlock() uint64 { +func (m *EventRecord) GetCreatedAt() uint64 { if m != nil { - return m.PayoutBlock + return m.CreatedAt } return 0 } type EventCancel struct { - Tenant uint64 `protobuf:"varint,1,opt,name=tenant,proto3" json:"tenant,omitempty"` - UtxrId uint64 `protobuf:"varint,2,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` - RequestId string `protobuf:"bytes,3,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + Tenant uint64 `protobuf:"varint,1,opt,name=tenant,proto3" json:"tenant,omitempty"` + UtxrId uint64 `protobuf:"varint,2,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` } func (m *EventCancel) Reset() { *m = EventCancel{} } func (m *EventCancel) String() string { return proto.CompactTextString(m) } func (*EventCancel) ProtoMessage() {} func (*EventCancel) Descriptor() ([]byte, []int) { - return fileDescriptor_c944366c474aba71, []int{2} + return fileDescriptor_318f5afc0de44f41, []int{3} } func (m *EventCancel) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -277,13 +297,6 @@ func (m *EventCancel) GetUtxrId() uint64 { return 0 } -func (m *EventCancel) GetRequestId() string { - if m != nil { - return m.RequestId - } - return "" -} - type EventSettlementFailed struct { Tenant uint64 `protobuf:"varint,1,opt,name=tenant,proto3" json:"tenant,omitempty"` Reason string `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"` @@ -293,7 +306,7 @@ func (m *EventSettlementFailed) Reset() { *m = EventSettlementFailed{} } func (m *EventSettlementFailed) String() string { return proto.CompactTextString(m) } func (*EventSettlementFailed) ProtoMessage() {} func (*EventSettlementFailed) Descriptor() ([]byte, []int) { - return fileDescriptor_c944366c474aba71, []int{3} + return fileDescriptor_318f5afc0de44f41, []int{4} } func (m *EventSettlementFailed) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -347,7 +360,7 @@ func (m *EventDeployContract) Reset() { *m = EventDeployContract{} } func (m *EventDeployContract) String() string { return proto.CompactTextString(m) } func (*EventDeployContract) ProtoMessage() {} func (*EventDeployContract) Descriptor() ([]byte, []int) { - return fileDescriptor_c944366c474aba71, []int{4} + return fileDescriptor_318f5afc0de44f41, []int{5} } func (m *EventDeployContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -405,51 +418,55 @@ func (m *EventDeployContract) GetContractAdmin() string { } func init() { - proto.RegisterType((*EventSettled)(nil), "settlus.settlement.EventSettled") - proto.RegisterType((*EventRecord)(nil), "settlus.settlement.EventRecord") - proto.RegisterType((*EventCancel)(nil), "settlus.settlement.EventCancel") - proto.RegisterType((*EventSettlementFailed)(nil), "settlus.settlement.EventSettlementFailed") - proto.RegisterType((*EventDeployContract)(nil), "settlus.settlement.EventDeployContract") -} - -func init() { proto.RegisterFile("settlus/settlement/event.proto", fileDescriptor_c944366c474aba71) } - -var fileDescriptor_c944366c474aba71 = []byte{ - // 529 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4d, 0x6e, 0xd3, 0x40, - 0x14, 0x8e, 0xd3, 0x34, 0x89, 0x5f, 0xc2, 0x8f, 0x06, 0x28, 0x6e, 0x44, 0x4d, 0x88, 0x84, 0x14, - 0x84, 0x64, 0xab, 0xb0, 0x60, 0x4d, 0x42, 0x81, 0x6c, 0x58, 0x98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86, 0x5c, 0x49, 0xa1, 0xbf, 0x63, 0x07, 0xa6, 0xea, 0x7d, - 0xb1, 0xe0, 0x8e, 0x66, 0x7a, 0x85, 0xe9, 0x5c, 0x2e, 0x87, 0xc6, 0xc5, 0x9d, 0x3c, 0x57, 0x9d, - 0x40, 0xf5, 0xea, 0x13, 0x38, 0x82, 0xd2, 0xed, 0xb1, 0xe0, 0x09, 0x6e, 0x24, 0x68, 0xe4, 0x1d, - 0x4f, 0x90, 0x3d, 0x86, 0x9b, 0x5b, 0x4c, 0x49, 0x2c, 0x4c, 0x84, 0x6e, 0x5c, 0xf2, 0x24, 0xb1, - 0x18, 0x9c, 0x9c, 0xaf, 0x5c, 0xeb, 0x62, 0xe5, 0x5a, 0x3f, 0x56, 0xae, 0xf5, 0x79, 0xed, 0x56, - 0x2e, 0xd6, 0x6e, 0xe5, 0xdb, 0xda, 0xad, 0x7c, 0x78, 0x3a, 0x8d, 0x69, 0x96, 0x4f, 0xbc, 0x50, - 0x26, 0xfe, 0xe6, 0x16, 0xd0, 0x41, 0xf1, 0x17, 0xdb, 0xb7, 0x01, 0x2d, 0x53, 0x54, 0x93, 0xba, - 0xfe, 0x89, 0x9f, 0xff, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x69, 0x11, 0x2e, 0xd9, 0x30, 0x04, 0x00, - 0x00, + proto.RegisterType((*EventSettled)(nil), "settlus.settlement.v1alpha1.EventSettled") + proto.RegisterType((*EventSetRecipients)(nil), "settlus.settlement.v1alpha1.EventSetRecipients") + proto.RegisterType((*EventRecord)(nil), "settlus.settlement.v1alpha1.EventRecord") + proto.RegisterType((*EventCancel)(nil), "settlus.settlement.v1alpha1.EventCancel") + proto.RegisterType((*EventSettlementFailed)(nil), "settlus.settlement.v1alpha1.EventSettlementFailed") + proto.RegisterType((*EventDeployContract)(nil), "settlus.settlement.v1alpha1.EventDeployContract") +} + +func init() { + proto.RegisterFile("settlus/settlement/v1alpha1/event.proto", fileDescriptor_318f5afc0de44f41) +} + +var fileDescriptor_318f5afc0de44f41 = []byte{ + // 546 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x6f, 0xd3, 0x4c, + 0x10, 0x8e, 0x93, 0xbc, 0x69, 0xbd, 0x79, 0xf9, 0x90, 0x81, 0x62, 0x02, 0x98, 0x28, 0xe2, 0x23, + 0x08, 0xb4, 0x56, 0xca, 0x81, 0x1b, 0xa8, 0x0d, 0x2d, 0xea, 0xa5, 0x07, 0x73, 0xe3, 0x12, 0x6d, + 0xd6, 0xd3, 0xc4, 0x22, 0xde, 0x0d, 0xde, 0x49, 0xd4, 0xfe, 0x08, 0x24, 0x7e, 0x01, 0xbf, 0xa7, + 0xc7, 0x1e, 0x39, 0x21, 0x48, 0xfe, 0x08, 0xda, 0xf5, 0xc6, 0x31, 0x48, 0x8d, 0x54, 0x4e, 0xf6, + 0xcc, 0x3e, 0xf3, 0xcc, 0x33, 0x5f, 0xe4, 0x99, 0x02, 0xc4, 0xc9, 0x4c, 0x85, 0xe6, 0x0b, 0x29, + 0x08, 0x0c, 0xe7, 0x3d, 0x36, 0x99, 0x8e, 0x59, 0x2f, 0x84, 0x39, 0x08, 0xa4, 0xd3, 0x4c, 0xa2, + 0xf4, 0xee, 0x5b, 0x20, 0x5d, 0x03, 0xe9, 0x0a, 0xd8, 0x0a, 0xb8, 0x54, 0xa9, 0x54, 0xe1, 0x90, + 0x29, 0x08, 0xe7, 0xbd, 0x21, 0x20, 0xeb, 0x85, 0x5c, 0x26, 0x22, 0x0f, 0x6e, 0x3d, 0x5e, 0x65, + 0x91, 0x19, 0xe3, 0x13, 0x58, 0x67, 0xc8, 0x6d, 0x8b, 0x7a, 0xb9, 0x49, 0x4b, 0x29, 0x6d, 0x8e, + 0xbe, 0x3d, 0x92, 0x23, 0x69, 0x7e, 0x43, 0xfd, 0x97, 0x7b, 0x3b, 0x6f, 0xc9, 0xff, 0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f, 0x72, 0x72, 0xb8, 0x7e, 0x04, + 0x00, 0x00, } func (m *EventSettled) Marshal() (dAtA []byte, err error) { @@ -472,29 +489,52 @@ func (m *EventSettled) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Recipient) > 0 { - i -= len(m.Recipient) - copy(dAtA[i:], m.Recipient) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Recipient))) + if m.UtxrId != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.UtxrId)) i-- - dAtA[i] = 0x2a - } - { - size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintEvent(dAtA, i, uint64(size)) + dAtA[i] = 0x10 } - i-- - dAtA[i] = 0x22 - if len(m.RequestId) > 0 { - i -= len(m.RequestId) - copy(dAtA[i:], m.RequestId) - i = encodeVarintEvent(dAtA, i, uint64(len(m.RequestId))) + if m.Tenant != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.Tenant)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *EventSetRecipients) 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 *EventSetRecipients) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventSetRecipients) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Recipients) > 0 { + for iNdEx := len(m.Recipients) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Recipients[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvent(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if m.UtxrId != 0 { i = encodeVarintEvent(dAtA, i, uint64(m.UtxrId)) @@ -529,43 +569,41 @@ func (m *EventRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.PayoutBlock != 0 { - i = encodeVarintEvent(dAtA, i, uint64(m.PayoutBlock)) + if m.CreatedAt != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.CreatedAt)) i-- - dAtA[i] = 0x58 + dAtA[i] = 0x48 } if len(m.Metadata) > 0 { i -= len(m.Metadata) copy(dAtA[i:], m.Metadata) i = encodeVarintEvent(dAtA, i, uint64(len(m.Metadata))) i-- - dAtA[i] = 0x52 - } - if len(m.Recipient) > 0 { - i -= len(m.Recipient) - copy(dAtA[i:], m.Recipient) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Recipient))) - i-- - dAtA[i] = 0x4a - } - if len(m.TokenIdHex) > 0 { - i -= len(m.TokenIdHex) - copy(dAtA[i:], m.TokenIdHex) - i = encodeVarintEvent(dAtA, i, uint64(len(m.TokenIdHex))) - i-- dAtA[i] = 0x42 } - if len(m.ContractAddress) > 0 { - i -= len(m.ContractAddress) - copy(dAtA[i:], m.ContractAddress) - i = encodeVarintEvent(dAtA, i, uint64(len(m.ContractAddress))) - i-- - dAtA[i] = 0x3a + if len(m.Recipients) > 0 { + for iNdEx := len(m.Recipients) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Recipients[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvent(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } } - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintEvent(dAtA, i, uint64(len(m.ChainId))) + if m.Nft != nil { + { + size, err := m.Nft.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvent(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x32 } @@ -626,13 +664,6 @@ func (m *EventCancel) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.RequestId) > 0 { - i -= len(m.RequestId) - copy(dAtA[i:], m.RequestId) - i = encodeVarintEvent(dAtA, i, uint64(len(m.RequestId))) - i-- - dAtA[i] = 0x1a - } if m.UtxrId != 0 { i = encodeVarintEvent(dAtA, i, uint64(m.UtxrId)) i-- @@ -753,15 +784,26 @@ func (m *EventSettled) Size() (n int) { if m.UtxrId != 0 { n += 1 + sovEvent(uint64(m.UtxrId)) } - l = len(m.RequestId) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) + return n +} + +func (m *EventSetRecipients) Size() (n int) { + if m == nil { + return 0 } - l = m.Amount.Size() - n += 1 + l + sovEvent(uint64(l)) - l = len(m.Recipient) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) + var l int + _ = l + if m.Tenant != 0 { + n += 1 + sovEvent(uint64(m.Tenant)) + } + if m.UtxrId != 0 { + n += 1 + sovEvent(uint64(m.UtxrId)) + } + if len(m.Recipients) > 0 { + for _, e := range m.Recipients { + l = e.Size() + n += 1 + l + sovEvent(uint64(l)) + } } return n } @@ -788,28 +830,22 @@ func (m *EventRecord) Size() (n int) { } l = m.Amount.Size() n += 1 + l + sovEvent(uint64(l)) - l = len(m.ChainId) - if l > 0 { + if m.Nft != nil { + l = m.Nft.Size() n += 1 + l + sovEvent(uint64(l)) } - l = len(m.ContractAddress) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) - } - l = len(m.TokenIdHex) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) - } - l = len(m.Recipient) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) + if len(m.Recipients) > 0 { + for _, e := range m.Recipients { + l = e.Size() + n += 1 + l + sovEvent(uint64(l)) + } } l = len(m.Metadata) if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - if m.PayoutBlock != 0 { - n += 1 + sovEvent(uint64(m.PayoutBlock)) + if m.CreatedAt != 0 { + n += 1 + sovEvent(uint64(m.CreatedAt)) } return n } @@ -826,10 +862,6 @@ func (m *EventCancel) Size() (n int) { if m.UtxrId != 0 { n += 1 + sovEvent(uint64(m.UtxrId)) } - l = len(m.RequestId) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) - } return n } @@ -946,11 +978,61 @@ func (m *EventSettled) Unmarshal(dAtA []byte) error { break } } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestId", wireType) + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err } - var stringLen uint64 + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EventSetRecipients) 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 ErrIntOverflowEvent + } + 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: EventSetRecipients: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventSetRecipients: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Tenant", wireType) + } + m.Tenant = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -960,29 +1042,16 @@ func (m *EventSettled) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + m.Tenant |= uint64(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RequestId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UtxrId", wireType) } - var msglen int + m.UtxrId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -992,30 +1061,16 @@ func (m *EventSettled) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.UtxrId |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthEvent - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Recipients", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -1025,23 +1080,25 @@ func (m *EventSettled) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthEvent } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthEvent } if postIndex > l { return io.ErrUnexpectedEOF } - m.Recipient = string(dAtA[iNdEx:postIndex]) + m.Recipients = append(m.Recipients, &Recipient{}) + if err := m.Recipients[len(m.Recipients)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -1230,9 +1287,9 @@ func (m *EventRecord) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Nft", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -1242,61 +1299,33 @@ func (m *EventRecord) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthEvent } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthEvent } if postIndex > l { return io.ErrUnexpectedEOF } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ContractAddress", wireType) + if m.Nft == nil { + m.Nft = &types1.Nft{} } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEvent - } - 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 ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF + if err := m.Nft.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - m.ContractAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 8: + case 7: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TokenIdHex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Recipients", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -1306,57 +1335,27 @@ func (m *EventRecord) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthEvent } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthEvent } if postIndex > l { return io.ErrUnexpectedEOF } - m.TokenIdHex = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEvent - } - 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 ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF + m.Recipients = append(m.Recipients, &Recipient{}) + if err := m.Recipients[len(m.Recipients)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - m.Recipient = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 10: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) } @@ -1388,11 +1387,11 @@ func (m *EventRecord) Unmarshal(dAtA []byte) error { } m.Metadata = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 11: + case 9: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PayoutBlock", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) } - m.PayoutBlock = 0 + m.CreatedAt = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -1402,7 +1401,7 @@ func (m *EventRecord) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.PayoutBlock |= uint64(b&0x7F) << shift + m.CreatedAt |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1495,38 +1494,6 @@ func (m *EventCancel) Unmarshal(dAtA []byte) error { break } } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RequestId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEvent - } - 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 ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RequestId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvent(dAtA[iNdEx:]) diff --git a/x/settlement/types/expected_keepers.go b/x/settlement/types/expected_keepers.go index eb2b9d56..0c5225c6 100644 --- a/x/settlement/types/expected_keepers.go +++ b/x/settlement/types/expected_keepers.go @@ -40,9 +40,3 @@ type EvmKeeper interface { CallEVM(ctx sdk.Context, abi abi.ABI, from, contract common.Address, commit bool, method string, args ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) CallEVMWithData(ctx sdk.Context, from common.Address, contract *common.Address, data []byte, commit bool) (*evmtypes.MsgEthereumTxResponse, error) } - -// NftOwnershipKeeper defines the expected interface needed to retrieve owner of NFT. -type NftOwnershipKeeper interface { - CheckValidChainId(ctx sdk.Context, chainId string) bool - OwnerOf(ctx sdk.Context, chainId string, contractAddr string, tokenIdHex string) (*common.Address, error) -} diff --git a/x/settlement/types/genesis.pb.go b/x/settlement/types/genesis.pb.go index b7dad175..962e9371 100644 --- a/x/settlement/types/genesis.pb.go +++ b/x/settlement/types/genesis.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/settlement/genesis.proto +// source: settlus/settlement/v1alpha1/genesis.proto package types @@ -34,7 +34,7 @@ func (m *GenesisState) Reset() { *m = GenesisState{} } func (m *GenesisState) String() string { return proto.CompactTextString(m) } func (*GenesisState) ProtoMessage() {} func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_50b4d7b20b5c1163, []int{0} + return fileDescriptor_6c14fe82f6650cc5, []int{0} } func (m *GenesisState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -94,7 +94,7 @@ func (m *UTXRWithTenantAndId) Reset() { *m = UTXRWithTenantAndId{} } func (m *UTXRWithTenantAndId) String() string { return proto.CompactTextString(m) } func (*UTXRWithTenantAndId) ProtoMessage() {} func (*UTXRWithTenantAndId) Descriptor() ([]byte, []int) { - return fileDescriptor_50b4d7b20b5c1163, []int{1} + return fileDescriptor_6c14fe82f6650cc5, []int{1} } func (m *UTXRWithTenantAndId) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -145,34 +145,37 @@ func (m *UTXRWithTenantAndId) GetUtxr() UTXR { } func init() { - proto.RegisterType((*GenesisState)(nil), "settlus.settlement.GenesisState") - proto.RegisterType((*UTXRWithTenantAndId)(nil), "settlus.settlement.UTXRWithTenantAndId") + proto.RegisterType((*GenesisState)(nil), "settlus.settlement.v1alpha1.GenesisState") + proto.RegisterType((*UTXRWithTenantAndId)(nil), "settlus.settlement.v1alpha1.UTXRWithTenantAndId") } -func init() { proto.RegisterFile("settlus/settlement/genesis.proto", fileDescriptor_50b4d7b20b5c1163) } +func init() { + proto.RegisterFile("settlus/settlement/v1alpha1/genesis.proto", fileDescriptor_6c14fe82f6650cc5) +} -var fileDescriptor_50b4d7b20b5c1163 = []byte{ - // 308 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x28, 0x4e, 0x2d, 0x29, - 0xc9, 0x29, 0x2d, 0xd6, 0x07, 0xd3, 0xa9, 0xb9, 0xa9, 0x79, 0x25, 0xfa, 0xe9, 0xa9, 0x79, 0xa9, - 0xc5, 0x99, 0xc5, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x42, 0x50, 0x15, 0x7a, 0x08, 0x15, - 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x69, 0x7d, 0x10, 0x0b, 0xa2, 0x52, 0x4a, 0x19, 0x8b, - 0x59, 0x08, 0x26, 0x44, 0x91, 0xd2, 0x49, 0x46, 0x2e, 0x1e, 0x77, 0x88, 0x05, 0xc1, 0x25, 0x89, - 0x25, 0xa9, 0x42, 0x16, 0x5c, 0x6c, 0x05, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x12, 0x8c, 0x0a, 0x8c, - 0x1a, 0xdc, 0x46, 0x52, 0x7a, 0x98, 0x16, 0xea, 0x05, 0x80, 0x55, 0x38, 0xb1, 0x9c, 0xb8, 0x27, - 0xcf, 0x10, 0x04, 0x55, 0x2f, 0x64, 0xc5, 0xc5, 0x5e, 0x92, 0x9a, 0x97, 0x98, 0x57, 0x52, 0x2c, - 0xc1, 0xa4, 0xc0, 0x8c, 0x4b, 0x6b, 0x08, 0x58, 0x09, 0x54, 0x2b, 0x4c, 0x83, 0x90, 0x33, 0x17, - 0x6b, 0x69, 0x49, 0x45, 0x51, 0xb1, 0x04, 0x33, 0x58, 0xa7, 0x3a, 0x36, 0x9d, 0xa1, 0x21, 0x11, - 0x41, 0xe1, 0x99, 0x25, 0x19, 0x10, 0x13, 0x1c, 0xf3, 0x52, 0x3c, 0x53, 0xa0, 0xc6, 0x40, 0xf4, - 0x2a, 0x95, 0x71, 0x09, 0x63, 0x51, 0x23, 0x24, 0xcd, 0xc5, 0x09, 0xb1, 0x26, 0x3e, 0x33, 0x05, - 0xec, 0x29, 0x96, 0x20, 0x0e, 0x88, 0x80, 0x67, 0x8a, 0x10, 0x1f, 0x17, 0x53, 0x66, 0x8a, 0x04, - 0x13, 0x58, 0x94, 0x29, 0x33, 0x45, 0xc8, 0x88, 0x8b, 0x05, 0x64, 0x98, 0x04, 0x33, 0xd8, 0xf3, - 0x12, 0xb8, 0xdc, 0x01, 0xb5, 0x18, 0xac, 0xd6, 0xc9, 0xf5, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, - 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, - 0x8f, 0xe5, 0x18, 0xa2, 0xb4, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, - 0x61, 0xb1, 0x91, 0x9c, 0x91, 0x98, 0x99, 0xa7, 0x5f, 0x81, 0x1c, 0x2b, 0x25, 0x95, 0x05, 0xa9, - 0xc5, 0x49, 0x6c, 0xe0, 0x18, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xca, 0x5f, 0xd7, - 0x04, 0x02, 0x00, 0x00, +var fileDescriptor_6c14fe82f6650cc5 = []byte{ + // 322 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x4e, 0x2d, 0x29, + 0xc9, 0x29, 0x2d, 0xd6, 0x07, 0xd3, 0xa9, 0xb9, 0xa9, 0x79, 0x25, 0xfa, 0x65, 0x86, 0x89, 0x39, + 0x05, 0x19, 0x89, 0x86, 0xfa, 0xe9, 0xa9, 0x79, 0xa9, 0xc5, 0x99, 0xc5, 0x7a, 0x05, 0x45, 0xf9, + 0x25, 0xf9, 0x42, 0xd2, 0x50, 0xa5, 0x7a, 0x08, 0xa5, 0x7a, 0x30, 0xa5, 0x52, 0x22, 0xe9, 0xf9, + 0xe9, 0xf9, 0x60, 0x75, 0xfa, 0x20, 0x16, 0x44, 0x8b, 0x94, 0x0e, 0x3e, 0xd3, 0x91, 0x8c, 0x01, + 0xab, 0x56, 0x7a, 0xc2, 0xc8, 0xc5, 0xe3, 0x0e, 0xb1, 0x32, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0xc8, + 0x91, 0x8b, 0xad, 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, + 0x59, 0x0f, 0x8f, 0x13, 0xf4, 0x02, 0xc0, 0x4a, 0x9d, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, + 0x6a, 0x14, 0x72, 0xe6, 0x62, 0x2f, 0x49, 0xcd, 0x4b, 0xcc, 0x2b, 0x29, 0x96, 0x60, 0x52, 0x60, + 0x26, 0x68, 0x46, 0x08, 0x58, 0x2d, 0xd4, 0x0c, 0x98, 0x4e, 0x21, 0x1f, 0x2e, 0xd6, 0xd2, 0x92, + 0x8a, 0xa2, 0x62, 0x09, 0x66, 0xb0, 0x11, 0x06, 0x78, 0x8d, 0x08, 0x0d, 0x89, 0x08, 0x0a, 0xcf, + 0x2c, 0xc9, 0x80, 0x18, 0xe5, 0x98, 0x97, 0xe2, 0x99, 0x02, 0x35, 0x0f, 0x62, 0x88, 0x52, 0x3d, + 0x97, 0x30, 0x16, 0x35, 0x42, 0xd2, 0x5c, 0x9c, 0x10, 0xfb, 0xe2, 0x33, 0x53, 0xc0, 0xfe, 0x65, + 0x09, 0xe2, 0x80, 0x08, 0x78, 0xa6, 0x08, 0xf1, 0x71, 0x31, 0x65, 0xa6, 0x48, 0x30, 0x81, 0x45, + 0x99, 0x32, 0x53, 0x84, 0xac, 0xb9, 0x58, 0x40, 0x86, 0x49, 0x30, 0x83, 0xc3, 0x45, 0x91, 0xa0, + 0x83, 0xa0, 0x2e, 0x00, 0x6b, 0x72, 0x72, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, + 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, + 0x86, 0x28, 0xed, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x58, 0xd4, + 0x25, 0x67, 0x24, 0x66, 0xe6, 0xe9, 0x57, 0x20, 0x47, 0x61, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, + 0x1b, 0x38, 0xd6, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x2a, 0x47, 0x51, 0x43, 0x02, + 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/settlement/types/keys.go b/x/settlement/types/keys.go index 4f6fc247..e842608e 100644 --- a/x/settlement/types/keys.go +++ b/x/settlement/types/keys.go @@ -2,6 +2,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/ethereum/go-ethereum/common" ) const ( @@ -18,6 +20,13 @@ const ( MemStoreKey = "mem_settlement" ) +// ModuleAddress is the native module address for EVM +var ModuleAddress common.Address + +func init() { + ModuleAddress = common.BytesToAddress(authtypes.NewModuleAddress(ModuleName).Bytes()) +} + var ( UTXRPrefix = []byte{0x00} UTXRRequestIdPrefix = []byte{0x01} diff --git a/x/settlement/types/query.pb.go b/x/settlement/types/query.pb.go index 54268ebe..723fbc30 100644 --- a/x/settlement/types/query.pb.go +++ b/x/settlement/types/query.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/settlement/query.proto +// source: settlus/settlement/v1alpha1/query.proto package types @@ -39,7 +39,7 @@ func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryParamsRequest) ProtoMessage() {} func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{0} + return fileDescriptor_c9a196576cc7b35c, []int{0} } func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -78,7 +78,7 @@ func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryParamsResponse) ProtoMessage() {} func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{1} + return fileDescriptor_c9a196576cc7b35c, []int{1} } func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -124,7 +124,7 @@ func (m *QueryUTXRRRequest) Reset() { *m = QueryUTXRRRequest{} } func (m *QueryUTXRRRequest) String() string { return proto.CompactTextString(m) } func (*QueryUTXRRRequest) ProtoMessage() {} func (*QueryUTXRRRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{2} + return fileDescriptor_c9a196576cc7b35c, []int{2} } func (m *QueryUTXRRRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -176,7 +176,7 @@ func (m *QueryUTXRResponse) Reset() { *m = QueryUTXRResponse{} } func (m *QueryUTXRResponse) String() string { return proto.CompactTextString(m) } func (*QueryUTXRResponse) ProtoMessage() {} func (*QueryUTXRResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{3} + return fileDescriptor_c9a196576cc7b35c, []int{3} } func (m *QueryUTXRResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -222,7 +222,7 @@ func (m *QueryUTXRsRequest) Reset() { *m = QueryUTXRsRequest{} } func (m *QueryUTXRsRequest) String() string { return proto.CompactTextString(m) } func (*QueryUTXRsRequest) ProtoMessage() {} func (*QueryUTXRsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{4} + return fileDescriptor_c9a196576cc7b35c, []int{4} } func (m *QueryUTXRsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -275,7 +275,7 @@ func (m *QueryUTXRsResponse) Reset() { *m = QueryUTXRsResponse{} } func (m *QueryUTXRsResponse) String() string { return proto.CompactTextString(m) } func (*QueryUTXRsResponse) ProtoMessage() {} func (*QueryUTXRsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{5} + return fileDescriptor_c9a196576cc7b35c, []int{5} } func (m *QueryUTXRsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -327,7 +327,7 @@ func (m *QueryTenantRequest) Reset() { *m = QueryTenantRequest{} } func (m *QueryTenantRequest) String() string { return proto.CompactTextString(m) } func (*QueryTenantRequest) ProtoMessage() {} func (*QueryTenantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{6} + return fileDescriptor_c9a196576cc7b35c, []int{6} } func (m *QueryTenantRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -372,7 +372,7 @@ func (m *QueryTenantResponse) Reset() { *m = QueryTenantResponse{} } func (m *QueryTenantResponse) String() string { return proto.CompactTextString(m) } func (*QueryTenantResponse) ProtoMessage() {} func (*QueryTenantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{7} + return fileDescriptor_c9a196576cc7b35c, []int{7} } func (m *QueryTenantResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -417,7 +417,7 @@ func (m *TenantWithTreasury) Reset() { *m = TenantWithTreasury{} } func (m *TenantWithTreasury) String() string { return proto.CompactTextString(m) } func (*TenantWithTreasury) ProtoMessage() {} func (*TenantWithTreasury) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{8} + return fileDescriptor_c9a196576cc7b35c, []int{8} } func (m *TenantWithTreasury) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -469,7 +469,7 @@ func (m *Treasury) Reset() { *m = Treasury{} } func (m *Treasury) String() string { return proto.CompactTextString(m) } func (*Treasury) ProtoMessage() {} func (*Treasury) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{9} + return fileDescriptor_c9a196576cc7b35c, []int{9} } func (m *Treasury) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -521,7 +521,7 @@ func (m *QueryTenantsRequest) Reset() { *m = QueryTenantsRequest{} } func (m *QueryTenantsRequest) String() string { return proto.CompactTextString(m) } func (*QueryTenantsRequest) ProtoMessage() {} func (*QueryTenantsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{10} + return fileDescriptor_c9a196576cc7b35c, []int{10} } func (m *QueryTenantsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -567,7 +567,7 @@ func (m *QueryTenantsResponse) Reset() { *m = QueryTenantsResponse{} } func (m *QueryTenantsResponse) String() string { return proto.CompactTextString(m) } func (*QueryTenantsResponse) ProtoMessage() {} func (*QueryTenantsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_76bdf01f1ca7a637, []int{11} + return fileDescriptor_c9a196576cc7b35c, []int{11} } func (m *QueryTenantsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -611,70 +611,73 @@ func (m *QueryTenantsResponse) GetPagination() *query.PageResponse { } func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "settlus.settlement.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "settlus.settlement.QueryParamsResponse") - proto.RegisterType((*QueryUTXRRRequest)(nil), "settlus.settlement.QueryUTXRRRequest") - proto.RegisterType((*QueryUTXRResponse)(nil), "settlus.settlement.QueryUTXRResponse") - proto.RegisterType((*QueryUTXRsRequest)(nil), "settlus.settlement.QueryUTXRsRequest") - proto.RegisterType((*QueryUTXRsResponse)(nil), "settlus.settlement.QueryUTXRsResponse") - proto.RegisterType((*QueryTenantRequest)(nil), "settlus.settlement.QueryTenantRequest") - proto.RegisterType((*QueryTenantResponse)(nil), "settlus.settlement.QueryTenantResponse") - proto.RegisterType((*TenantWithTreasury)(nil), "settlus.settlement.TenantWithTreasury") - proto.RegisterType((*Treasury)(nil), "settlus.settlement.Treasury") - proto.RegisterType((*QueryTenantsRequest)(nil), "settlus.settlement.QueryTenantsRequest") - proto.RegisterType((*QueryTenantsResponse)(nil), "settlus.settlement.QueryTenantsResponse") -} - -func init() { proto.RegisterFile("settlus/settlement/query.proto", fileDescriptor_76bdf01f1ca7a637) } - -var fileDescriptor_76bdf01f1ca7a637 = []byte{ - // 731 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x4f, 0x4f, 0xdb, 0x4c, - 0x10, 0xc6, 0xb3, 0xbc, 0xf9, 0x43, 0x96, 0xd3, 0xbb, 0xe5, 0x40, 0x0d, 0xb8, 0xc8, 0x88, 0x10, - 0xb5, 0xaa, 0xad, 0x84, 0x1e, 0xe0, 0x4a, 0x5b, 0x10, 0x27, 0xa8, 0x45, 0xd5, 0xaa, 0x55, 0x85, - 0x36, 0xc9, 0xca, 0x58, 0x22, 0xde, 0xe0, 0xdd, 0x54, 0x20, 0xc4, 0xa1, 0x48, 0x3d, 0xf4, 0xd4, - 0x4a, 0x7c, 0x88, 0x5e, 0xfb, 0x31, 0x38, 0x22, 0xf5, 0xd2, 0x53, 0x55, 0x41, 0x3f, 0x48, 0xe5, - 0xdd, 0xb1, 0x13, 0x17, 0x07, 0xa7, 0x55, 0x4f, 0x98, 0xf5, 0x33, 0xcf, 0xfc, 0x76, 0x66, 0x3c, - 0xc1, 0xa6, 0x60, 0x52, 0x1e, 0xf4, 0x85, 0xa3, 0xfe, 0xb2, 0x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x75, 0xa9, 0xe7, 0x0b, - 0x01, 0x67, 0x51, 0xe1, 0xcc, 0x93, 0xd9, 0xd1, 0x38, 0x62, 0xfd, 0xe9, 0xc5, 0x95, 0x89, 0x2e, - 0xaf, 0x4c, 0xf4, 0xe3, 0xca, 0x44, 0x9f, 0xae, 0xcd, 0xc2, 0xe5, 0xb5, 0x59, 0xf8, 0x76, 0x6d, - 0x16, 0x5e, 0x3d, 0xf0, 0x7c, 0xb9, 0xdf, 0x6f, 0xd9, 0x6d, 0xde, 0x4d, 0x0c, 0xda, 0xfb, 0xd4, - 0x0f, 0x9c, 0xa3, 0x94, 0xd1, 0x71, 0x8f, 0x89, 0x56, 0x59, 0xfd, 0x20, 0xaf, 0xfc, 0x0a, 0x00, - 0x00, 0xff, 0xff, 0xfc, 0xe0, 0x74, 0xff, 0x6b, 0x08, 0x00, 0x00, + proto.RegisterType((*QueryParamsRequest)(nil), "settlus.settlement.v1alpha1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "settlus.settlement.v1alpha1.QueryParamsResponse") + proto.RegisterType((*QueryUTXRRRequest)(nil), "settlus.settlement.v1alpha1.QueryUTXRRRequest") + proto.RegisterType((*QueryUTXRResponse)(nil), "settlus.settlement.v1alpha1.QueryUTXRResponse") + proto.RegisterType((*QueryUTXRsRequest)(nil), "settlus.settlement.v1alpha1.QueryUTXRsRequest") + proto.RegisterType((*QueryUTXRsResponse)(nil), "settlus.settlement.v1alpha1.QueryUTXRsResponse") + proto.RegisterType((*QueryTenantRequest)(nil), "settlus.settlement.v1alpha1.QueryTenantRequest") + proto.RegisterType((*QueryTenantResponse)(nil), "settlus.settlement.v1alpha1.QueryTenantResponse") + proto.RegisterType((*TenantWithTreasury)(nil), "settlus.settlement.v1alpha1.TenantWithTreasury") + proto.RegisterType((*Treasury)(nil), "settlus.settlement.v1alpha1.Treasury") + proto.RegisterType((*QueryTenantsRequest)(nil), "settlus.settlement.v1alpha1.QueryTenantsRequest") + proto.RegisterType((*QueryTenantsResponse)(nil), "settlus.settlement.v1alpha1.QueryTenantsResponse") +} + +func init() { + proto.RegisterFile("settlus/settlement/v1alpha1/query.proto", fileDescriptor_c9a196576cc7b35c) +} + +var fileDescriptor_c9a196576cc7b35c = []byte{ + // 749 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0xcf, 0x4f, 0xd4, 0x40, + 0x14, 0xc7, 0x77, 0x70, 0xd9, 0x65, 0x87, 0x93, 0x23, 0x07, 0x5c, 0xb4, 0x62, 0x91, 0x1f, 0x11, + 0xd2, 0xa1, 0x98, 0x68, 0x14, 0x3d, 0x80, 0x51, 0xc3, 0xc1, 0x80, 0x0d, 0x46, 0x62, 0x62, 0xc8, + 0xec, 0xee, 0xa4, 0xdb, 0x64, 0xb7, 0x53, 0x3a, 0xb3, 0x04, 0x42, 0xb8, 0xf8, 0x17, 0x98, 0xe8, + 0xc1, 0x03, 0x07, 0x0f, 0x9e, 0x3c, 0x79, 0xf4, 0x4f, 0xe0, 0x48, 0xe2, 0xc5, 0x93, 0x31, 0xe0, + 0x1f, 0x62, 0x3a, 0x33, 0x2d, 0xad, 0x98, 0x6e, 0x21, 0x9e, 0xb6, 0x3b, 0x7d, 0xef, 0xfb, 0x3e, + 0xef, 0xc7, 0xbc, 0x14, 0x4e, 0x73, 0x2a, 0x44, 0xa7, 0xc7, 0xb1, 0xfc, 0xa5, 0x5d, 0xea, 0x0b, + 0xbc, 0x6d, 0x93, 0x4e, 0xd0, 0x26, 0x36, 0xde, 0xea, 0xd1, 0x70, 0xd7, 0x0a, 0x42, 0x26, 0x18, + 0x1a, 0xd3, 0x86, 0xd6, 0xa9, 0xa1, 0x15, 0x1b, 0xd6, 0x8d, 0x26, 0xe3, 0x5d, 0xc6, 0x71, 0x83, + 0x70, 0x8a, 0xb7, 0xed, 0x06, 0x15, 0xc4, 0xc6, 0x4d, 0xe6, 0xf9, 0xca,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 0xfd, + 0x38, 0x31, 0x4a, 0xaf, 0x67, 0x5d, 0x4f, 0xb4, 0x7b, 0x0d, 0xab, 0xc9, 0xba, 0x89, 0x52, 0xb3, + 0x4d, 0x3c, 0x1f, 0xef, 0xa4, 0x15, 0xc5, 0x6e, 0x40, 0x79, 0xa3, 0x22, 0xbf, 0x2b, 0xee, 0xfc, + 0x09, 0x00, 0x00, 0xff, 0xff, 0x6a, 0x3c, 0x82, 0xe4, 0x4d, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -711,7 +714,7 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Query/Params", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Query/Params", in, out, opts...) if err != nil { return nil, err } @@ -720,7 +723,7 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . func (c *queryClient) UTXR(ctx context.Context, in *QueryUTXRRRequest, opts ...grpc.CallOption) (*QueryUTXRResponse, error) { out := new(QueryUTXRResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Query/UTXR", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Query/UTXR", in, out, opts...) if err != nil { return nil, err } @@ -729,7 +732,7 @@ func (c *queryClient) UTXR(ctx context.Context, in *QueryUTXRRRequest, opts ...g func (c *queryClient) UTXRs(ctx context.Context, in *QueryUTXRsRequest, opts ...grpc.CallOption) (*QueryUTXRsResponse, error) { out := new(QueryUTXRsResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Query/UTXRs", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Query/UTXRs", in, out, opts...) if err != nil { return nil, err } @@ -738,7 +741,7 @@ func (c *queryClient) UTXRs(ctx context.Context, in *QueryUTXRsRequest, opts ... func (c *queryClient) Tenant(ctx context.Context, in *QueryTenantRequest, opts ...grpc.CallOption) (*QueryTenantResponse, error) { out := new(QueryTenantResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Query/Tenant", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Query/Tenant", in, out, opts...) if err != nil { return nil, err } @@ -747,7 +750,7 @@ func (c *queryClient) Tenant(ctx context.Context, in *QueryTenantRequest, opts . func (c *queryClient) Tenants(ctx context.Context, in *QueryTenantsRequest, opts ...grpc.CallOption) (*QueryTenantsResponse, error) { out := new(QueryTenantsResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Query/Tenants", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Query/Tenants", in, out, opts...) if err != nil { return nil, err } @@ -802,7 +805,7 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Query/Params", + FullMethod: "/settlus.settlement.v1alpha1.Query/Params", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) @@ -820,7 +823,7 @@ func _Query_UTXR_Handler(srv interface{}, ctx context.Context, dec func(interfac } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Query/UTXR", + FullMethod: "/settlus.settlement.v1alpha1.Query/UTXR", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).UTXR(ctx, req.(*QueryUTXRRRequest)) @@ -838,7 +841,7 @@ func _Query_UTXRs_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Query/UTXRs", + FullMethod: "/settlus.settlement.v1alpha1.Query/UTXRs", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).UTXRs(ctx, req.(*QueryUTXRsRequest)) @@ -856,7 +859,7 @@ func _Query_Tenant_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Query/Tenant", + FullMethod: "/settlus.settlement.v1alpha1.Query/Tenant", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).Tenant(ctx, req.(*QueryTenantRequest)) @@ -874,7 +877,7 @@ func _Query_Tenants_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Query/Tenants", + FullMethod: "/settlus.settlement.v1alpha1.Query/Tenants", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).Tenants(ctx, req.(*QueryTenantsRequest)) @@ -883,7 +886,7 @@ func _Query_Tenants_Handler(srv interface{}, ctx context.Context, dec func(inter } var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "settlus.settlement.Query", + ServiceName: "settlus.settlement.v1alpha1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { @@ -908,7 +911,7 @@ var _Query_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "settlus/settlement/query.proto", + Metadata: "settlus/settlement/v1alpha1/query.proto", } func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { diff --git a/x/settlement/types/query.pb.gw.go b/x/settlement/types/query.pb.gw.go index 598deccc..ffa5e357 100644 --- a/x/settlement/types/query.pb.gw.go +++ b/x/settlement/types/query.pb.gw.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: settlus/settlement/query.proto +// source: settlus/settlement/v1alpha1/query.proto /* Package types is a reverse proxy. @@ -555,15 +555,15 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"settlus", "settlement", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"settlus", "settlement", "v1alpha1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_UTXR_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"settlus", "settlement", "utxr", "tenant_id", "request_id"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_UTXR_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"settlus", "settlement", "v1alpha1", "utxr", "tenant_id", "request_id"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_UTXRs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"settlus", "settlement", "utxrs", "tenant_id"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_UTXRs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"settlus", "settlement", "v1alpha1", "utxrs", "tenant_id"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Tenant_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"settlus", "settlement", "tenant", "tenant_id"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Tenant_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"settlus", "settlement", "v1alpha1", "tenant", "tenant_id"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Tenants_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"settlus", "settlement", "tenants"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Tenants_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"settlus", "settlement", "v1alpha1", "tenants"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/settlement/types/recipient.go b/x/settlement/types/recipient.go new file mode 100644 index 00000000..dac47731 --- /dev/null +++ b/x/settlement/types/recipient.go @@ -0,0 +1,14 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + ctypes "github.com/settlus/chain/types" +) + +func SingleRecipients(creator sdk.AccAddress) []*Recipient { + return []*Recipient{ + { + Address: ctypes.NewHexAddrFromAccAddr(creator), + }, + } +} diff --git a/x/settlement/types/settlement.pb.go b/x/settlement/types/settlement.pb.go index 737fcf42..64ff5269 100644 --- a/x/settlement/types/settlement.pb.go +++ b/x/settlement/types/settlement.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/settlement/settlement.proto +// source: settlus/settlement/v1alpha1/settlement.proto package types @@ -10,6 +10,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_settlus_chain_types "github.com/settlus/chain/types" + types1 "github.com/settlus/chain/x/oracle/types" io "io" math "math" math_bits "math/bits" @@ -35,7 +36,7 @@ type Params struct { func (m *Params) Reset() { *m = Params{} } func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_e83090d94702b861, []int{0} + return fileDescriptor_c8003d389c9288b3, []int{0} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -84,7 +85,7 @@ type Tenant struct { func (m *Tenant) Reset() { *m = Tenant{} } func (*Tenant) ProtoMessage() {} func (*Tenant) Descriptor() ([]byte, []int) { - return fileDescriptor_e83090d94702b861, []int{1} + return fileDescriptor_c8003d389c9288b3, []int{1} } func (m *Tenant) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -157,17 +158,18 @@ func (m *Tenant) GetContractAddress() string { // UTXR defines the unspent transaction record. type UTXR struct { - RequestId string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` - Recipient github_com_settlus_chain_types.HexAddressString `protobuf:"bytes,2,opt,name=recipient,proto3,customtype=github.com/settlus/chain/types.HexAddressString" json:"recipient"` - Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` - PayoutBlock uint64 `protobuf:"varint,4,opt,name=payout_block,json=payoutBlock,proto3" json:"payout_block,omitempty"` + RequestId string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + Recipients []*Recipient `protobuf:"bytes,2,rep,name=recipients,proto3" json:"recipients,omitempty"` + Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` + CreatedAt uint64 `protobuf:"varint,4,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + Nft *types1.Nft `protobuf:"bytes,5,opt,name=nft,proto3" json:"nft,omitempty"` } func (m *UTXR) Reset() { *m = UTXR{} } func (m *UTXR) String() string { return proto.CompactTextString(m) } func (*UTXR) ProtoMessage() {} func (*UTXR) Descriptor() ([]byte, []int) { - return fileDescriptor_e83090d94702b861, []int{2} + return fileDescriptor_c8003d389c9288b3, []int{2} } func (m *UTXR) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -203,6 +205,13 @@ func (m *UTXR) GetRequestId() string { return "" } +func (m *UTXR) GetRecipients() []*Recipient { + if m != nil { + return m.Recipients + } + return nil +} + func (m *UTXR) GetAmount() types.Coin { if m != nil { return m.Amount @@ -210,57 +219,115 @@ func (m *UTXR) GetAmount() types.Coin { return types.Coin{} } -func (m *UTXR) GetPayoutBlock() uint64 { +func (m *UTXR) GetCreatedAt() uint64 { if m != nil { - return m.PayoutBlock + return m.CreatedAt + } + return 0 +} + +func (m *UTXR) GetNft() *types1.Nft { + if m != nil { + return m.Nft + } + return nil +} + +type Recipient struct { + Address github_com_settlus_chain_types.HexAddressString `protobuf:"bytes,1,opt,name=address,proto3,customtype=github.com/settlus/chain/types.HexAddressString" json:"address"` + Weight uint32 `protobuf:"varint,2,opt,name=weight,proto3" json:"weight,omitempty"` +} + +func (m *Recipient) Reset() { *m = Recipient{} } +func (m *Recipient) String() string { return proto.CompactTextString(m) } +func (*Recipient) ProtoMessage() {} +func (*Recipient) Descriptor() ([]byte, []int) { + return fileDescriptor_c8003d389c9288b3, []int{3} +} +func (m *Recipient) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Recipient) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Recipient.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 *Recipient) XXX_Merge(src proto.Message) { + xxx_messageInfo_Recipient.Merge(m, src) +} +func (m *Recipient) XXX_Size() int { + return m.Size() +} +func (m *Recipient) XXX_DiscardUnknown() { + xxx_messageInfo_Recipient.DiscardUnknown(m) +} + +var xxx_messageInfo_Recipient proto.InternalMessageInfo + +func (m *Recipient) GetWeight() uint32 { + if m != nil { + return m.Weight } return 0 } func init() { - proto.RegisterType((*Params)(nil), "settlus.settlement.Params") - proto.RegisterType((*Tenant)(nil), "settlus.settlement.Tenant") - proto.RegisterType((*UTXR)(nil), "settlus.settlement.UTXR") + proto.RegisterType((*Params)(nil), "settlus.settlement.v1alpha1.Params") + proto.RegisterType((*Tenant)(nil), "settlus.settlement.v1alpha1.Tenant") + proto.RegisterType((*UTXR)(nil), "settlus.settlement.v1alpha1.UTXR") + proto.RegisterType((*Recipient)(nil), "settlus.settlement.v1alpha1.Recipient") } func init() { - proto.RegisterFile("settlus/settlement/settlement.proto", fileDescriptor_e83090d94702b861) + proto.RegisterFile("settlus/settlement/v1alpha1/settlement.proto", fileDescriptor_c8003d389c9288b3) } -var fileDescriptor_e83090d94702b861 = []byte{ - // 504 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4d, 0x6b, 0xd4, 0x40, - 0x18, 0xde, 0x6c, 0xb7, 0xa1, 0x99, 0xfa, 0xc5, 0x58, 0x25, 0x16, 0xcc, 0xae, 0x5b, 0x90, 0x15, - 0x31, 0xa1, 0x7a, 0x28, 0x14, 0x2f, 0xae, 0x1f, 0xe8, 0x41, 0x58, 0x62, 0x0b, 0xe2, 0x25, 0x4c, - 0x26, 0xaf, 0xd9, 0xa1, 0x9b, 0x99, 0x38, 0x33, 0x91, 0xf6, 0x5f, 0x78, 0xf4, 0xd8, 0x9f, 0xe0, - 0x9f, 0x10, 0x7a, 0xec, 0xb1, 0x78, 0x28, 0xb2, 0x7b, 0xf1, 0x67, 0x48, 0x66, 0xa6, 0x76, 0x2f, - 0x42, 0x4f, 0xf3, 0xce, 0x93, 0xe7, 0x7d, 0xf2, 0xbc, 0xcf, 0xbc, 0x68, 0x4b, 0x81, 0xd6, 0xb3, - 0x46, 0x25, 0xe6, 0x84, 0x0a, 0xb8, 0x5e, 0x2a, 0xe3, 0x5a, 0x0a, 0x2d, 0x30, 0x76, 0xa4, 0xf8, - 0xf2, 0xcb, 0x66, 0x44, 0x85, 0xaa, 0x84, 0x4a, 0x72, 0xa2, 0x20, 0xf9, 0xba, 0x9d, 0x83, 0x26, - 0xdb, 0x09, 0x15, 0x8c, 0xdb, 0x9e, 0xcd, 0x8d, 0x52, 0x94, 0xc2, 0x94, 0x49, 0x5b, 0x59, 0x74, - 0xf8, 0xc3, 0x43, 0xfe, 0x84, 0x48, 0x52, 0x29, 0xfc, 0x1c, 0x05, 0x25, 0x51, 0x59, 0x2d, 0x19, - 0x85, 0xd0, 0x1b, 0x78, 0xa3, 0xf5, 0xa7, 0xf7, 0x62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x81, - 0xbf, 0xb0, 0xf0, 0xee, 0x5a, 0x3b, 0xc3, 0x9f, 0xe3, 0xbe, 0x37, 0x3c, 0xf3, 0x50, 0x6f, 0x7f, - 0xef, 0x63, 0x8a, 0xef, 0x23, 0x24, 0xe1, 0x4b, 0x03, 0x4a, 0x67, 0x6e, 0x9a, 0x20, 0x0d, 0x1c, - 0xf2, 0xae, 0xc0, 0xfb, 0x28, 0x90, 0x40, 0x59, 0xcd, 0x80, 0xeb, 0xb0, 0x6b, 0xd2, 0xdc, 0x71, - 0x69, 0x26, 0x4b, 0x69, 0x5e, 0xec, 0x0d, 0x9d, 0x12, 0xc6, 0x5d, 0x92, 0x6f, 0xe1, 0xd0, 0xfd, - 0xf7, 0x83, 0x96, 0x8c, 0x97, 0xe9, 0xa5, 0x12, 0xde, 0x41, 0x3e, 0xa9, 0x44, 0xc3, 0xb5, 0x09, - 0xe5, 0x0a, 0x6f, 0xed, 0xe8, 0xf8, 0x01, 0x72, 0xc3, 0x67, 0xf9, 0x4c, 0xd0, 0x03, 0x97, 0xda, - 0xba, 0xc5, 0xc6, 0x2d, 0x34, 0x7e, 0x7d, 0x32, 0x8f, 0xbc, 0xd3, 0x79, 0xe4, 0xfd, 0x9e, 0x47, - 0xde, 0xb7, 0x45, 0xd4, 0x39, 0x5d, 0x44, 0x9d, 0xb3, 0x45, 0xd4, 0xf9, 0xf4, 0xf8, 0xbf, 0x8e, - 0x0f, 0x97, 0x37, 0xde, 0xd8, 0xcf, 0x7d, 0xb3, 0xa3, 0xcf, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, - 0xff, 0x88, 0x35, 0xa2, 0x14, 0x03, 0x00, 0x00, +var fileDescriptor_c8003d389c9288b3 = []byte{ + // 586 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xc1, 0x6e, 0xd3, 0x4a, + 0x14, 0x8d, 0xd3, 0x34, 0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 0x1e, 0x35, 0xcd, 0xc5, 0x79, 0xf0, 0x2b, 0x00, 0x00, + 0xff, 0xff, 0xab, 0xb3, 0xf7, 0x73, 0xe1, 0x03, 0x00, 0x00, } func (this *Tenant) Equal(that interface{}) bool { @@ -433,8 +500,20 @@ func (m *UTXR) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.PayoutBlock != 0 { - i = encodeVarintSettlement(dAtA, i, uint64(m.PayoutBlock)) + if m.Nft != nil { + { + size, err := m.Nft.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSettlement(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.CreatedAt != 0 { + i = encodeVarintSettlement(dAtA, i, uint64(m.CreatedAt)) i-- dAtA[i] = 0x20 } @@ -448,16 +527,20 @@ func (m *UTXR) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x1a - { - size := m.Recipient.Size() - i -= size - if _, err := m.Recipient.MarshalTo(dAtA[i:]); err != nil { - return 0, err + if len(m.Recipients) > 0 { + for iNdEx := len(m.Recipients) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Recipients[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSettlement(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - i = encodeVarintSettlement(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x12 if len(m.RequestId) > 0 { i -= len(m.RequestId) copy(dAtA[i:], m.RequestId) @@ -468,6 +551,44 @@ func (m *UTXR) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Recipient) 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 *Recipient) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Recipient) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Weight != 0 { + i = encodeVarintSettlement(dAtA, i, uint64(m.Weight)) + i-- + dAtA[i] = 0x10 + } + { + size := m.Address.Size() + i -= size + if _, err := m.Address.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintSettlement(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintSettlement(dAtA []byte, offset int, v uint64) int { offset -= sovSettlement(v) base := offset @@ -535,12 +656,34 @@ func (m *UTXR) Size() (n int) { if l > 0 { n += 1 + l + sovSettlement(uint64(l)) } - l = m.Recipient.Size() - n += 1 + l + sovSettlement(uint64(l)) + if len(m.Recipients) > 0 { + for _, e := range m.Recipients { + l = e.Size() + n += 1 + l + sovSettlement(uint64(l)) + } + } l = m.Amount.Size() n += 1 + l + sovSettlement(uint64(l)) - if m.PayoutBlock != 0 { - n += 1 + sovSettlement(uint64(m.PayoutBlock)) + if m.CreatedAt != 0 { + n += 1 + sovSettlement(uint64(m.CreatedAt)) + } + if m.Nft != nil { + l = m.Nft.Size() + n += 1 + l + sovSettlement(uint64(l)) + } + return n +} + +func (m *Recipient) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Address.Size() + n += 1 + l + sovSettlement(uint64(l)) + if m.Weight != 0 { + n += 1 + sovSettlement(uint64(m.Weight)) } return n } @@ -947,9 +1090,9 @@ func (m *UTXR) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Recipients", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowSettlement @@ -959,23 +1102,23 @@ func (m *UTXR) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthSettlement } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthSettlement } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Recipient.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Recipients = append(m.Recipients, &Recipient{}) + if err := m.Recipients[len(m.Recipients)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1014,9 +1157,148 @@ func (m *UTXR) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PayoutBlock", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + m.CreatedAt = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSettlement + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreatedAt |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Nft", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSettlement + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSettlement + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSettlement + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Nft == nil { + m.Nft = &types1.Nft{} + } + if err := m.Nft.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSettlement(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSettlement + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Recipient) 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 ErrIntOverflowSettlement + } + 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: Recipient: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Recipient: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSettlement + } + 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 ErrInvalidLengthSettlement + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSettlement + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Address.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Weight", wireType) } - m.PayoutBlock = 0 + m.Weight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowSettlement @@ -1026,7 +1308,7 @@ func (m *UTXR) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.PayoutBlock |= uint64(b&0x7F) << shift + m.Weight |= uint32(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/settlement/types/tx.pb.go b/x/settlement/types/tx.pb.go index dde6c633..d4d34ae5 100644 --- a/x/settlement/types/tx.pb.go +++ b/x/settlement/types/tx.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settlus/settlement/tx.proto +// source: settlus/settlement/v1alpha1/tx.proto package types @@ -46,7 +46,7 @@ func (m *MsgRecord) Reset() { *m = MsgRecord{} } func (m *MsgRecord) String() string { return proto.CompactTextString(m) } func (*MsgRecord) ProtoMessage() {} func (*MsgRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{0} + return fileDescriptor_34b846958bde2029, []int{0} } func (m *MsgRecord) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -134,15 +134,14 @@ func (m *MsgRecord) GetMetadata() string { // MsgRecordResponse defines the response structure for executing a MsgRecord // message. type MsgRecordResponse struct { - UtxrId uint64 `protobuf:"varint,1,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` - Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` + UtxrId uint64 `protobuf:"varint,1,opt,name=utxr_id,json=utxrId,proto3" json:"utxr_id,omitempty"` } func (m *MsgRecordResponse) Reset() { *m = MsgRecordResponse{} } func (m *MsgRecordResponse) String() string { return proto.CompactTextString(m) } func (*MsgRecordResponse) ProtoMessage() {} func (*MsgRecordResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{1} + return fileDescriptor_34b846958bde2029, []int{1} } func (m *MsgRecordResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -178,13 +177,6 @@ func (m *MsgRecordResponse) GetUtxrId() uint64 { return 0 } -func (m *MsgRecordResponse) GetRecipient() string { - if m != nil { - return m.Recipient - } - return "" -} - // MsgCancel is the Cancel request type. type MsgCancel struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` @@ -196,7 +188,7 @@ func (m *MsgCancel) Reset() { *m = MsgCancel{} } func (m *MsgCancel) String() string { return proto.CompactTextString(m) } func (*MsgCancel) ProtoMessage() {} func (*MsgCancel) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{2} + return fileDescriptor_34b846958bde2029, []int{2} } func (m *MsgCancel) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -255,7 +247,7 @@ func (m *MsgCancelResponse) Reset() { *m = MsgCancelResponse{} } func (m *MsgCancelResponse) String() string { return proto.CompactTextString(m) } func (*MsgCancelResponse) ProtoMessage() {} func (*MsgCancelResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{3} + return fileDescriptor_34b846958bde2029, []int{3} } func (m *MsgCancelResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -295,7 +287,7 @@ func (m *MsgCreateTenant) Reset() { *m = MsgCreateTenant{} } func (m *MsgCreateTenant) String() string { return proto.CompactTextString(m) } func (*MsgCreateTenant) ProtoMessage() {} func (*MsgCreateTenant) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{4} + return fileDescriptor_34b846958bde2029, []int{4} } func (m *MsgCreateTenant) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -355,7 +347,7 @@ func (m *MsgCreateTenantResponse) Reset() { *m = MsgCreateTenantResponse func (m *MsgCreateTenantResponse) String() string { return proto.CompactTextString(m) } func (*MsgCreateTenantResponse) ProtoMessage() {} func (*MsgCreateTenantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{5} + return fileDescriptor_34b846958bde2029, []int{5} } func (m *MsgCreateTenantResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -406,7 +398,7 @@ func (m *MsgCreateTenantWithMintableContract) Reset() { *m = MsgCreateTe func (m *MsgCreateTenantWithMintableContract) String() string { return proto.CompactTextString(m) } func (*MsgCreateTenantWithMintableContract) ProtoMessage() {} func (*MsgCreateTenantWithMintableContract) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{6} + return fileDescriptor_34b846958bde2029, []int{6} } func (m *MsgCreateTenantWithMintableContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -501,7 +493,7 @@ func (m *MsgAddTenantAdmin) Reset() { *m = MsgAddTenantAdmin{} } func (m *MsgAddTenantAdmin) String() string { return proto.CompactTextString(m) } func (*MsgAddTenantAdmin) ProtoMessage() {} func (*MsgAddTenantAdmin) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{7} + return fileDescriptor_34b846958bde2029, []int{7} } func (m *MsgAddTenantAdmin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -560,7 +552,7 @@ func (m *MsgAddTenantAdminResponse) Reset() { *m = MsgAddTenantAdminResp func (m *MsgAddTenantAdminResponse) String() string { return proto.CompactTextString(m) } func (*MsgAddTenantAdminResponse) ProtoMessage() {} func (*MsgAddTenantAdminResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{8} + return fileDescriptor_34b846958bde2029, []int{8} } func (m *MsgAddTenantAdminResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -600,7 +592,7 @@ func (m *MsgRemoveTenantAdmin) Reset() { *m = MsgRemoveTenantAdmin{} } func (m *MsgRemoveTenantAdmin) String() string { return proto.CompactTextString(m) } func (*MsgRemoveTenantAdmin) ProtoMessage() {} func (*MsgRemoveTenantAdmin) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{9} + return fileDescriptor_34b846958bde2029, []int{9} } func (m *MsgRemoveTenantAdmin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -659,7 +651,7 @@ func (m *MsgRemoveTenantAdminResponse) Reset() { *m = MsgRemoveTenantAdm func (m *MsgRemoveTenantAdminResponse) String() string { return proto.CompactTextString(m) } func (*MsgRemoveTenantAdminResponse) ProtoMessage() {} func (*MsgRemoveTenantAdminResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{10} + return fileDescriptor_34b846958bde2029, []int{10} } func (m *MsgRemoveTenantAdminResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -699,7 +691,7 @@ func (m *MsgUpdateTenantPayoutPeriod) Reset() { *m = MsgUpdateTenantPayo func (m *MsgUpdateTenantPayoutPeriod) String() string { return proto.CompactTextString(m) } func (*MsgUpdateTenantPayoutPeriod) ProtoMessage() {} func (*MsgUpdateTenantPayoutPeriod) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{11} + return fileDescriptor_34b846958bde2029, []int{11} } func (m *MsgUpdateTenantPayoutPeriod) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -758,7 +750,7 @@ func (m *MsgUpdateTenantPayoutPeriodResponse) Reset() { *m = MsgUpdateTe func (m *MsgUpdateTenantPayoutPeriodResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateTenantPayoutPeriodResponse) ProtoMessage() {} func (*MsgUpdateTenantPayoutPeriodResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{12} + return fileDescriptor_34b846958bde2029, []int{12} } func (m *MsgUpdateTenantPayoutPeriodResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -798,7 +790,7 @@ func (m *MsgDepositToTreasury) Reset() { *m = MsgDepositToTreasury{} } func (m *MsgDepositToTreasury) String() string { return proto.CompactTextString(m) } func (*MsgDepositToTreasury) ProtoMessage() {} func (*MsgDepositToTreasury) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{13} + return fileDescriptor_34b846958bde2029, []int{13} } func (m *MsgDepositToTreasury) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -857,7 +849,7 @@ func (m *MsgDepositToTreasuryResponse) Reset() { *m = MsgDepositToTreasu func (m *MsgDepositToTreasuryResponse) String() string { return proto.CompactTextString(m) } func (*MsgDepositToTreasuryResponse) ProtoMessage() {} func (*MsgDepositToTreasuryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2217e74226b1f19d, []int{14} + return fileDescriptor_34b846958bde2029, []int{14} } func (m *MsgDepositToTreasuryResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -887,80 +879,82 @@ func (m *MsgDepositToTreasuryResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgDepositToTreasuryResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgRecord)(nil), "settlus.settlement.MsgRecord") - proto.RegisterType((*MsgRecordResponse)(nil), "settlus.settlement.MsgRecordResponse") - proto.RegisterType((*MsgCancel)(nil), "settlus.settlement.MsgCancel") - proto.RegisterType((*MsgCancelResponse)(nil), "settlus.settlement.MsgCancelResponse") - proto.RegisterType((*MsgCreateTenant)(nil), "settlus.settlement.MsgCreateTenant") - proto.RegisterType((*MsgCreateTenantResponse)(nil), "settlus.settlement.MsgCreateTenantResponse") - proto.RegisterType((*MsgCreateTenantWithMintableContract)(nil), "settlus.settlement.MsgCreateTenantWithMintableContract") - proto.RegisterType((*MsgAddTenantAdmin)(nil), "settlus.settlement.MsgAddTenantAdmin") - proto.RegisterType((*MsgAddTenantAdminResponse)(nil), "settlus.settlement.MsgAddTenantAdminResponse") - proto.RegisterType((*MsgRemoveTenantAdmin)(nil), "settlus.settlement.MsgRemoveTenantAdmin") - proto.RegisterType((*MsgRemoveTenantAdminResponse)(nil), "settlus.settlement.MsgRemoveTenantAdminResponse") - proto.RegisterType((*MsgUpdateTenantPayoutPeriod)(nil), "settlus.settlement.MsgUpdateTenantPayoutPeriod") - proto.RegisterType((*MsgUpdateTenantPayoutPeriodResponse)(nil), "settlus.settlement.MsgUpdateTenantPayoutPeriodResponse") - proto.RegisterType((*MsgDepositToTreasury)(nil), "settlus.settlement.MsgDepositToTreasury") - proto.RegisterType((*MsgDepositToTreasuryResponse)(nil), "settlus.settlement.MsgDepositToTreasuryResponse") -} - -func init() { proto.RegisterFile("settlus/settlement/tx.proto", fileDescriptor_2217e74226b1f19d) } - -var fileDescriptor_2217e74226b1f19d = []byte{ - // 837 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xf7, 0x34, 0xe9, 0xc6, 0x7e, 0x4d, 0x09, 0x99, 0x46, 0xc4, 0xb1, 0xdb, 0xc5, 0x72, 0x54, - 0x14, 0xa8, 0xd8, 0x25, 0x45, 0x22, 0x12, 0xb7, 0x24, 0x20, 0xd5, 0x48, 0xa9, 0x2a, 0x2b, 0x08, - 0x89, 0xcb, 0x32, 0xde, 0x79, 0x38, 0x2b, 0xbc, 0x33, 0xdb, 0x9d, 0x71, 0xea, 0xdc, 0x10, 0xea, - 0xa1, 0x47, 0xf8, 0x24, 0xf0, 0x31, 0x2a, 0x4e, 0x3d, 0x72, 0x42, 0x28, 0x3e, 0xf0, 0x35, 0xd0, - 0xce, 0xae, 0xb7, 0x59, 0xdb, 0x0b, 0x76, 0x50, 0x4e, 0xbb, 0xf3, 0xfe, 0xfe, 0xde, 0x6f, 0xde, - 0xbc, 0x19, 0x68, 0x2a, 0xd4, 0x7a, 0x30, 0x54, 0xae, 0xf9, 0x62, 0x88, 0x42, 0xbb, 0x7a, 0xe4, - 0x44, 0xb1, 0xd4, 0x92, 0xd2, 0x4c, 0xe9, 0xbc, 0x55, 0x36, 0x6c, 0x5f, 0xaa, 0x50, 0x2a, 0xb7, - 0xc7, 0x14, 0xba, 0xe7, 0xfb, 0x3d, 0xd4, 0x6c, 0xdf, 0xf5, 0x65, 0x20, 0x52, 0x9f, 0xc6, 0x56, - 0x5f, 0xf6, 0xa5, 0xf9, 0x75, 0x93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0xd6, 0x7f, 0x4e, 0x9a, 0x83, 0x05, 0x22, - 0xce, 0x73, 0x5c, 0x0e, 0xca, 0xf7, 0xf0, 0xce, 0xd4, 0x9c, 0x28, 0x63, 0xa9, 0x68, 0xd6, 0xf8, - 0x78, 0x21, 0xb3, 0x3c, 0x8f, 0x84, 0xcd, 0xd9, 0xd3, 0xbf, 0x57, 0xba, 0xc1, 0x53, 0x96, 0x8d, - 0x4f, 0x16, 0xb5, 0xcc, 0x13, 0xbe, 0x24, 0x50, 0x2f, 0x3d, 0xcc, 0x6e, 0x49, 0xb8, 0x32, 0x87, - 0xc6, 0xc1, 0x92, 0x0e, 0x57, 0xeb, 0x9e, 0x3d, 0xa4, 0x65, 0x75, 0xcf, 0x58, 0x96, 0xd6, 0x5d, - 0x7a, 0xca, 0x8e, 0xbe, 0x7c, 0x7d, 0x69, 0x93, 0x37, 0x97, 0x36, 0xf9, 0xeb, 0xd2, 0x26, 0x3f, - 0x8f, 0xed, 0xca, 0x9b, 0xb1, 0x5d, 0xf9, 0x63, 0x6c, 0x57, 0xbe, 0x7d, 0xd4, 0x0f, 0xf4, 0xd9, - 0xb0, 0xe7, 0xf8, 0x32, 0x74, 0x27, 0x2f, 0x43, 0xf3, 0xe8, 0x71, 0x47, 0x85, 0x17, 0xe2, 0x45, - 0x84, 0xaa, 0x67, 0x99, 0x27, 0xdc, 0xa7, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x58, 0x32, 0xd9, - 0x24, 0x44, 0x0a, 0x00, 0x00, + proto.RegisterType((*MsgRecord)(nil), "settlus.settlement.v1alpha1.MsgRecord") + proto.RegisterType((*MsgRecordResponse)(nil), "settlus.settlement.v1alpha1.MsgRecordResponse") + proto.RegisterType((*MsgCancel)(nil), "settlus.settlement.v1alpha1.MsgCancel") + proto.RegisterType((*MsgCancelResponse)(nil), "settlus.settlement.v1alpha1.MsgCancelResponse") + proto.RegisterType((*MsgCreateTenant)(nil), "settlus.settlement.v1alpha1.MsgCreateTenant") + proto.RegisterType((*MsgCreateTenantResponse)(nil), "settlus.settlement.v1alpha1.MsgCreateTenantResponse") + proto.RegisterType((*MsgCreateTenantWithMintableContract)(nil), "settlus.settlement.v1alpha1.MsgCreateTenantWithMintableContract") + proto.RegisterType((*MsgAddTenantAdmin)(nil), "settlus.settlement.v1alpha1.MsgAddTenantAdmin") + proto.RegisterType((*MsgAddTenantAdminResponse)(nil), "settlus.settlement.v1alpha1.MsgAddTenantAdminResponse") + proto.RegisterType((*MsgRemoveTenantAdmin)(nil), "settlus.settlement.v1alpha1.MsgRemoveTenantAdmin") + proto.RegisterType((*MsgRemoveTenantAdminResponse)(nil), "settlus.settlement.v1alpha1.MsgRemoveTenantAdminResponse") + proto.RegisterType((*MsgUpdateTenantPayoutPeriod)(nil), "settlus.settlement.v1alpha1.MsgUpdateTenantPayoutPeriod") + proto.RegisterType((*MsgUpdateTenantPayoutPeriodResponse)(nil), "settlus.settlement.v1alpha1.MsgUpdateTenantPayoutPeriodResponse") + proto.RegisterType((*MsgDepositToTreasury)(nil), "settlus.settlement.v1alpha1.MsgDepositToTreasury") + proto.RegisterType((*MsgDepositToTreasuryResponse)(nil), "settlus.settlement.v1alpha1.MsgDepositToTreasuryResponse") +} + +func init() { + proto.RegisterFile("settlus/settlement/v1alpha1/tx.proto", fileDescriptor_34b846958bde2029) +} + +var fileDescriptor_34b846958bde2029 = []byte{ + // 840 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x96, 0x4b, 0x6f, 0xeb, 0x44, + 0x14, 0xc7, 0x33, 0xb7, 0xb9, 0x79, 0x9c, 0xdb, 0x4b, 0xa9, 0x6f, 0x45, 0xd3, 0x04, 0x4c, 0x94, + 0x0b, 0x57, 0x05, 0xae, 0x6c, 0xa5, 0xa0, 0xf2, 0x58, 0xf5, 0x01, 0x52, 0xb3, 0x88, 0x54, 0x59, + 0x41, 0x48, 0x6c, 0xd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xfe, 0xbc, 0xd1, + 0xd1, 0x0f, 0xb7, 0x7a, 0xee, 0xfa, 0x56, 0xcf, 0xfd, 0x7e, 0xab, 0xe7, 0xbe, 0x7c, 0xaf, 0xe7, + 0xca, 0xfe, 0xb0, 0x6b, 0x38, 0xdc, 0x33, 0x27, 0xf7, 0x53, 0x75, 0xd1, 0x32, 0xc7, 0xf7, 0xef, + 0xa9, 0xf2, 0xd2, 0xa7, 0xa2, 0x5b, 0x50, 0xd7, 0xc6, 0xf7, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, + 0xd5, 0x8c, 0x75, 0x7e, 0xca, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1004,7 +998,7 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { func (c *msgClient) Record(ctx context.Context, in *MsgRecord, opts ...grpc.CallOption) (*MsgRecordResponse, error) { out := new(MsgRecordResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/Record", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/Record", in, out, opts...) if err != nil { return nil, err } @@ -1013,7 +1007,7 @@ func (c *msgClient) Record(ctx context.Context, in *MsgRecord, opts ...grpc.Call func (c *msgClient) Cancel(ctx context.Context, in *MsgCancel, opts ...grpc.CallOption) (*MsgCancelResponse, error) { out := new(MsgCancelResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/Cancel", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/Cancel", in, out, opts...) if err != nil { return nil, err } @@ -1022,7 +1016,7 @@ func (c *msgClient) Cancel(ctx context.Context, in *MsgCancel, opts ...grpc.Call func (c *msgClient) CreateTenant(ctx context.Context, in *MsgCreateTenant, opts ...grpc.CallOption) (*MsgCreateTenantResponse, error) { out := new(MsgCreateTenantResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/CreateTenant", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/CreateTenant", in, out, opts...) if err != nil { return nil, err } @@ -1031,7 +1025,7 @@ func (c *msgClient) CreateTenant(ctx context.Context, in *MsgCreateTenant, opts func (c *msgClient) CreateTenantWithMintableContract(ctx context.Context, in *MsgCreateTenantWithMintableContract, opts ...grpc.CallOption) (*MsgCreateTenantResponse, error) { out := new(MsgCreateTenantResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/CreateTenantWithMintableContract", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/CreateTenantWithMintableContract", in, out, opts...) if err != nil { return nil, err } @@ -1040,7 +1034,7 @@ func (c *msgClient) CreateTenantWithMintableContract(ctx context.Context, in *Ms func (c *msgClient) AddTenantAdmin(ctx context.Context, in *MsgAddTenantAdmin, opts ...grpc.CallOption) (*MsgAddTenantAdminResponse, error) { out := new(MsgAddTenantAdminResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/AddTenantAdmin", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/AddTenantAdmin", in, out, opts...) if err != nil { return nil, err } @@ -1049,7 +1043,7 @@ func (c *msgClient) AddTenantAdmin(ctx context.Context, in *MsgAddTenantAdmin, o func (c *msgClient) RemoveTenantAdmin(ctx context.Context, in *MsgRemoveTenantAdmin, opts ...grpc.CallOption) (*MsgRemoveTenantAdminResponse, error) { out := new(MsgRemoveTenantAdminResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/RemoveTenantAdmin", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/RemoveTenantAdmin", in, out, opts...) if err != nil { return nil, err } @@ -1058,7 +1052,7 @@ func (c *msgClient) RemoveTenantAdmin(ctx context.Context, in *MsgRemoveTenantAd func (c *msgClient) UpdateTenantPayoutPeriod(ctx context.Context, in *MsgUpdateTenantPayoutPeriod, opts ...grpc.CallOption) (*MsgUpdateTenantPayoutPeriodResponse, error) { out := new(MsgUpdateTenantPayoutPeriodResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/UpdateTenantPayoutPeriod", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/UpdateTenantPayoutPeriod", in, out, opts...) if err != nil { return nil, err } @@ -1067,7 +1061,7 @@ func (c *msgClient) UpdateTenantPayoutPeriod(ctx context.Context, in *MsgUpdateT func (c *msgClient) DepositToTreasury(ctx context.Context, in *MsgDepositToTreasury, opts ...grpc.CallOption) (*MsgDepositToTreasuryResponse, error) { out := new(MsgDepositToTreasuryResponse) - err := c.cc.Invoke(ctx, "/settlus.settlement.Msg/DepositToTreasury", in, out, opts...) + err := c.cc.Invoke(ctx, "/settlus.settlement.v1alpha1.Msg/DepositToTreasury", in, out, opts...) if err != nil { return nil, err } @@ -1138,7 +1132,7 @@ func _Msg_Record_Handler(srv interface{}, ctx context.Context, dec func(interfac } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/Record", + FullMethod: "/settlus.settlement.v1alpha1.Msg/Record", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).Record(ctx, req.(*MsgRecord)) @@ -1156,7 +1150,7 @@ func _Msg_Cancel_Handler(srv interface{}, ctx context.Context, dec func(interfac } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/Cancel", + FullMethod: "/settlus.settlement.v1alpha1.Msg/Cancel", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).Cancel(ctx, req.(*MsgCancel)) @@ -1174,7 +1168,7 @@ func _Msg_CreateTenant_Handler(srv interface{}, ctx context.Context, dec func(in } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/CreateTenant", + FullMethod: "/settlus.settlement.v1alpha1.Msg/CreateTenant", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).CreateTenant(ctx, req.(*MsgCreateTenant)) @@ -1192,7 +1186,7 @@ func _Msg_CreateTenantWithMintableContract_Handler(srv interface{}, ctx context. } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/CreateTenantWithMintableContract", + FullMethod: "/settlus.settlement.v1alpha1.Msg/CreateTenantWithMintableContract", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).CreateTenantWithMintableContract(ctx, req.(*MsgCreateTenantWithMintableContract)) @@ -1210,7 +1204,7 @@ func _Msg_AddTenantAdmin_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/AddTenantAdmin", + FullMethod: "/settlus.settlement.v1alpha1.Msg/AddTenantAdmin", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).AddTenantAdmin(ctx, req.(*MsgAddTenantAdmin)) @@ -1228,7 +1222,7 @@ func _Msg_RemoveTenantAdmin_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/RemoveTenantAdmin", + FullMethod: "/settlus.settlement.v1alpha1.Msg/RemoveTenantAdmin", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).RemoveTenantAdmin(ctx, req.(*MsgRemoveTenantAdmin)) @@ -1246,7 +1240,7 @@ func _Msg_UpdateTenantPayoutPeriod_Handler(srv interface{}, ctx context.Context, } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/UpdateTenantPayoutPeriod", + FullMethod: "/settlus.settlement.v1alpha1.Msg/UpdateTenantPayoutPeriod", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).UpdateTenantPayoutPeriod(ctx, req.(*MsgUpdateTenantPayoutPeriod)) @@ -1264,7 +1258,7 @@ func _Msg_DepositToTreasury_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/settlus.settlement.Msg/DepositToTreasury", + FullMethod: "/settlus.settlement.v1alpha1.Msg/DepositToTreasury", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).DepositToTreasury(ctx, req.(*MsgDepositToTreasury)) @@ -1273,7 +1267,7 @@ func _Msg_DepositToTreasury_Handler(srv interface{}, ctx context.Context, dec fu } var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "settlus.settlement.Msg", + ServiceName: "settlus.settlement.v1alpha1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { @@ -1310,7 +1304,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "settlus/settlement/tx.proto", + Metadata: "settlus/settlement/v1alpha1/tx.proto", } func (m *MsgRecord) Marshal() (dAtA []byte, err error) { @@ -1413,13 +1407,6 @@ func (m *MsgRecordResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Recipient) > 0 { - i -= len(m.Recipient) - copy(dAtA[i:], m.Recipient) - i = encodeVarintTx(dAtA, i, uint64(len(m.Recipient))) - i-- - dAtA[i] = 0x12 - } if m.UtxrId != 0 { i = encodeVarintTx(dAtA, i, uint64(m.UtxrId)) i-- @@ -1947,10 +1934,6 @@ func (m *MsgRecordResponse) Size() (n int) { if m.UtxrId != 0 { n += 1 + sovTx(uint64(m.UtxrId)) } - l = len(m.Recipient) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } return n } @@ -2509,38 +2492,6 @@ func (m *MsgRecordResponse) Unmarshal(dAtA []byte) error { break } } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Recipient", 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.Recipient = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:])