├── assets └── banner.png ├── app ├── helpers │ └── test_helpers.go ├── params │ ├── params.go │ ├── encoding.go │ ├── doc.go │ ├── proto.go │ ├── weights.go │ └── config.go ├── encoding.go ├── genesis.go ├── wasm_config.go ├── vesting.go ├── genesis_account.go ├── test_helpers.go ├── sim_test.go ├── ante_handler.go └── export.go ├── config.yml ├── x ├── nftstaking │ ├── types │ │ ├── genesis.go │ │ ├── errors.go │ │ ├── keys.go │ │ ├── expected_keepers.go │ │ ├── msgs.go │ │ ├── codec.go │ │ ├── query.pb.gw.go │ │ ├── genesis.pb.go │ │ └── nftstaking.pb.go │ ├── keeper │ │ ├── grpc_query.go │ │ ├── keeper.go │ │ ├── msg_server.go │ │ └── nftstaking.go │ ├── spec │ │ └── README.md │ ├── handler.go │ ├── abci.go │ ├── client │ │ └── cli │ │ │ ├── query.go │ │ │ └── tx.go │ └── module.go └── airdrop │ ├── types │ ├── params.go │ ├── events.go │ ├── keys.go │ ├── msgs_test.go │ ├── expected_keepers.go │ ├── errors.go │ ├── codec.go │ ├── genesis.go │ ├── msgs.go │ ├── query.pb.gw.go │ ├── params.pb.go │ └── genesis.pb.go │ ├── abci.go │ ├── keeper │ ├── params.go │ ├── grpc_query.go │ ├── querier.go │ ├── keeper_test.go │ ├── keeper.go │ ├── msg_server.go │ ├── signature_test.go │ ├── allocation_test.go │ ├── signature.go │ └── allocation.go │ ├── genesis.go │ ├── handler.go │ ├── client │ └── cli │ │ ├── query.go │ │ └── tx.go │ ├── spec │ └── README.md │ └── module.go ├── proto └── teritori │ ├── nftstaking │ └── v1beta1 │ │ ├── nftstaking.proto │ │ ├── genesis.proto │ │ ├── tx.proto │ │ └── query.proto │ └── airdrop │ └── v1beta1 │ ├── params.proto │ ├── genesis.proto │ ├── allocation.proto │ ├── query.proto │ └── tx.proto ├── scripts ├── examples │ ├── nftstaking.sh │ └── airdrop.sh └── protocgen.sh ├── cmd └── teritorid │ ├── cmd │ ├── root_test.go │ ├── genaccounts.go │ └── root.go │ └── main.go ├── README.md ├── start.sh ├── docker-compose.yml ├── CW20.md ├── sims.mk ├── testnet ├── teritori-testnet-v1 │ └── README.md └── teritori-testnet-v2 │ └── README.md ├── go.mod └── Makefile /assets/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NodesBlocks/teritori-chain/HEAD/assets/banner.png -------------------------------------------------------------------------------- /app/helpers/test_helpers.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | // SimAppChainID hardcoded chainID for simulation 4 | const ( 5 | SimAppChainID = "teritori-app" 6 | ) 7 | -------------------------------------------------------------------------------- /app/params/params.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | // Simulation parameter constants 4 | const ( 5 | StakePerAccount = "stake_per_account" 6 | InitiallyBondedValidators = "initially_bonded_validators" 7 | ) 8 | -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | version: 1 2 | accounts: 3 | - name: alice 4 | coins: ["1000token", "100000000stake"] 5 | - name: bob 6 | coins: ["500token"] 7 | validator: 8 | name: alice 9 | staked: "100000000stake" 10 | -------------------------------------------------------------------------------- /x/nftstaking/types/genesis.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // DefaultGenesis returns the default CustomGo genesis state 4 | func DefaultGenesis() *GenesisState { 5 | return &GenesisState{ 6 | NftStakings: []NftStaking{}, 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /x/airdrop/types/params.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | var ( 8 | DefaultClaimDenom = "uosmo" 9 | DefaultDurationUntilDecay = time.Hour 10 | DefaultDurationOfDecay = time.Hour * 5 11 | ) 12 | -------------------------------------------------------------------------------- /x/airdrop/types/events.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | const ( 4 | EventTypeClaimAllocation = "claim_allocation" 5 | 6 | AttributeKeyAddress = "address" 7 | AttributeKeyAmount = "amount" 8 | AttributeKeyRewardAddress = "reward_address" 9 | ) 10 | -------------------------------------------------------------------------------- /x/nftstaking/types/errors.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import "github.com/cosmos/cosmos-sdk/types/errors" 4 | 5 | var ( 6 | ErrEmptySender = errors.Register(ModuleName, 1, "empty sender") 7 | ErrEmptyRewardAddress = errors.Register(ModuleName, 2, "empty reward address") 8 | ) 9 | -------------------------------------------------------------------------------- /x/nftstaking/types/keys.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // constants 4 | var ( 5 | ModuleName = "nftstaking" 6 | 7 | // RouterKey to be used for routing msgs 8 | RouterKey = ModuleName 9 | QuerierRoute = ModuleName 10 | StoreKey = ModuleName 11 | 12 | PrefixKeyNftStaking = []byte{0x0} 13 | ) 14 | -------------------------------------------------------------------------------- /x/airdrop/abci.go: -------------------------------------------------------------------------------- 1 | package airdrop 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/airdrop/keeper" 5 | sdk "github.com/cosmos/cosmos-sdk/types" 6 | ) 7 | 8 | // EndBlocker called every block, process inflation, update validator set. 9 | func EndBlocker(ctx sdk.Context, k keeper.Keeper) { 10 | } 11 | -------------------------------------------------------------------------------- /proto/teritori/nftstaking/v1beta1/nftstaking.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.nftstaking.v1beta1; 3 | 4 | option go_package = "github.com/NXTPOP/teritori-chain/x/nftstaking/types"; 5 | 6 | message NftStaking { 7 | string nft_identifier = 1; 8 | string nft_metadata = 2; 9 | string reward_address = 3; 10 | uint64 reward_weight = 4; 11 | } 12 | -------------------------------------------------------------------------------- /proto/teritori/airdrop/v1beta1/params.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.airdrop.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/duration.proto"; 6 | import "google/protobuf/timestamp.proto"; 7 | 8 | option go_package = "github.com/NXTPOP/teritori-chain/x/airdrop/types"; 9 | 10 | // Params defines the module's parameters. 11 | message Params { 12 | } 13 | -------------------------------------------------------------------------------- /scripts/examples/nftstaking.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | teritorid tx nftstaking register-nft-staking --from validator --nft-identifier "identifier3" --nft-metadata "metadata" --reward-address "pop1snktzg6rrncqtct3acx2vz60aak2a6fke3ny3c" --reward-weight 1000 --chain-id=testing --home=$HOME/.teritorid --keyring-backend=test --broadcast-mode=block --yes 4 | 5 | teritorid query bank balances pop1uef5c6tx7vhjyhfumhzdhvwkepshcmljyv4wh4 6 | -------------------------------------------------------------------------------- /proto/teritori/nftstaking/v1beta1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.nftstaking.v1beta1; 3 | 4 | option go_package = "github.com/NXTPOP/teritori-chain/x/nftstaking/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "teritori/nftstaking/v1beta1/nftstaking.proto"; 8 | 9 | message GenesisState { 10 | repeated teritori.nftstaking.v1beta1.NftStaking nft_stakings = 1 11 | [ (gogoproto.nullable) = false ]; 12 | } 13 | -------------------------------------------------------------------------------- /x/airdrop/keeper/params.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 5 | sdk "github.com/cosmos/cosmos-sdk/types" 6 | ) 7 | 8 | // GetParams get params 9 | func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { 10 | return types.Params{}, nil 11 | } 12 | 13 | // SetParams set params 14 | func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /x/airdrop/types/keys.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | const ( 4 | // ModuleName defines the module name 5 | ModuleName = "airdrop" 6 | 7 | // StoreKey defines the primary module store key 8 | StoreKey = ModuleName 9 | 10 | // RouterKey is the message route for slashing 11 | RouterKey = ModuleName 12 | 13 | // QuerierRoute defines the module's query routing key 14 | QuerierRoute = ModuleName 15 | ) 16 | 17 | var ( 18 | KeyPrefixAirdropAllocation = []byte{0x01} 19 | ) 20 | -------------------------------------------------------------------------------- /x/nftstaking/types/expected_keepers.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | ) 6 | 7 | type BankKeeper interface { 8 | MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error 9 | BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error 10 | SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error 11 | SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error 12 | } 13 | -------------------------------------------------------------------------------- /app/params/encoding.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/client" 5 | "github.com/cosmos/cosmos-sdk/codec" 6 | "github.com/cosmos/cosmos-sdk/codec/types" 7 | ) 8 | 9 | // EncodingConfig specifies the concrete encoding types to use for a given app. 10 | // This is provided for compatibility between protobuf and amino implementations. 11 | type EncodingConfig struct { 12 | InterfaceRegistry types.InterfaceRegistry 13 | Marshaler codec.Codec 14 | TxConfig client.TxConfig 15 | Amino *codec.LegacyAmino 16 | } 17 | -------------------------------------------------------------------------------- /proto/teritori/airdrop/v1beta1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.airdrop.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "cosmos/base/v1beta1/coin.proto"; 6 | import "cosmos/bank/v1beta1/genesis.proto"; 7 | import "google/protobuf/duration.proto"; 8 | import "google/protobuf/timestamp.proto"; 9 | import "teritori/airdrop/v1beta1/allocation.proto"; 10 | 11 | option go_package = "github.com/NXTPOP/teritori-chain/x/airdrop/types"; 12 | 13 | // GenesisState defines the module's genesis state. 14 | message GenesisState { 15 | repeated AirdropAllocation allocations = 1; 16 | } 17 | -------------------------------------------------------------------------------- /app/encoding.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/app/params" 5 | 6 | "github.com/cosmos/cosmos-sdk/std" 7 | ) 8 | 9 | // MakeEncodingConfig creates an EncodingConfig for testing 10 | func MakeEncodingConfig() params.EncodingConfig { 11 | encodingConfig := params.MakeEncodingConfig() 12 | std.RegisterLegacyAminoCodec(encodingConfig.Amino) 13 | std.RegisterInterfaces(encodingConfig.InterfaceRegistry) 14 | ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) 15 | ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) 16 | return encodingConfig 17 | } 18 | -------------------------------------------------------------------------------- /cmd/teritorid/cmd/root_test.go: -------------------------------------------------------------------------------- 1 | package cmd_test 2 | 3 | import ( 4 | "testing" 5 | 6 | svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" 7 | 8 | app "github.com/NXTPOP/teritori-chain/app" 9 | "github.com/NXTPOP/teritori-chain/cmd/teritorid/cmd" 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestRootCmdConfig(t *testing.T) { 14 | 15 | rootCmd, _ := cmd.NewRootCmd() 16 | rootCmd.SetArgs([]string{ 17 | "config", // Test the config cmd 18 | "keyring-backend", // key 19 | "test", // value 20 | }) 21 | 22 | require.NoError(t, svrcmd.Execute(rootCmd, app.DefaultNodeHome)) 23 | } 24 | -------------------------------------------------------------------------------- /x/airdrop/types/msgs_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | fmt "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestMsgCreatePool(t *testing.T) { 11 | msg := MsgClaimAllocation{ 12 | Address: "0x9d967594Cc61453aFEfD657313e5F05be7c6F88F", 13 | RewardAddress: "pop18mu5hhgy64390q56msql8pfwps0uesn0gf0elf", 14 | Signature: "0xb89733c05568385a861fa20f5c4abe53c23a13962515bf5510638b4e3947b1236963b53de549ae762bbd45427dbd3712ae7d169a935d21e44e7da86b1c552f471b", 15 | } 16 | 17 | fmt.Println("sign_bytes", string(msg.GetSignBytes())) 18 | 19 | require.NoError(t, msg.ValidateBasic()) 20 | } 21 | -------------------------------------------------------------------------------- /cmd/teritorid/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/cosmos/cosmos-sdk/server" 7 | svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" 8 | 9 | app "github.com/NXTPOP/teritori-chain/app" 10 | appparams "github.com/NXTPOP/teritori-chain/app/params" 11 | "github.com/NXTPOP/teritori-chain/cmd/teritorid/cmd" 12 | ) 13 | 14 | func main() { 15 | appparams.SetAddressPrefixes() 16 | 17 | rootCmd, _ := cmd.NewRootCmd() 18 | if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil { 19 | switch e := err.(type) { 20 | case server.ErrorCode: 21 | os.Exit(e.Code) 22 | 23 | default: 24 | os.Exit(1) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/params/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package params defines the simulation parameters in the teritori. 3 | 4 | It contains the default weights used for each transaction used on the module's 5 | simulation. These weights define the chance for a transaction to be simulated at 6 | any gived operation. 7 | 8 | You can repace the default values for the weights by providing a params.json 9 | file with the weights defined for each of the transaction operations: 10 | 11 | { 12 | "op_weight_msg_send": 60, 13 | "op_weight_msg_delegate": 100, 14 | } 15 | 16 | In the example above, the `MsgSend` has 60% chance to be simulated, while the 17 | `MsgDelegate` will always be simulated. 18 | */ 19 | package params 20 | -------------------------------------------------------------------------------- /proto/teritori/nftstaking/v1beta1/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.nftstaking.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/timestamp.proto"; 6 | import "teritori/nftstaking/v1beta1/nftstaking.proto"; 7 | 8 | option go_package = "github.com/NXTPOP/teritori-chain/x/nftstaking/types"; 9 | 10 | // Msg defines the ubi Msg service. 11 | service Msg { 12 | rpc RegisterNftStaking(MsgRegisterNftStaking) returns (MsgRegisterNftStakingResponse); 13 | } 14 | 15 | message MsgRegisterNftStaking { 16 | string sender = 1; 17 | teritori.nftstaking.v1beta1.NftStaking nft_staking = 2 [ (gogoproto.nullable) = false ]; 18 | } 19 | message MsgRegisterNftStakingResponse {} 20 | -------------------------------------------------------------------------------- /x/airdrop/keeper/grpc_query.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | "google.golang.org/grpc/codes" 9 | "google.golang.org/grpc/status" 10 | ) 11 | 12 | var _ types.QueryServer = Keeper{} 13 | 14 | func (k Keeper) Allocation(c context.Context, req *types.QueryAllocationRequest) (*types.QueryAllocationResponse, error) { 15 | if req == nil { 16 | return nil, status.Error(codes.InvalidArgument, "invalid request") 17 | } 18 | 19 | ctx := sdk.UnwrapSDKContext(c) 20 | 21 | return &types.QueryAllocationResponse{ 22 | Allocation: k.GetAllocation(ctx, req.Address), 23 | }, nil 24 | } 25 | -------------------------------------------------------------------------------- /x/airdrop/genesis.go: -------------------------------------------------------------------------------- 1 | package airdrop 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/airdrop/keeper" 7 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 8 | ) 9 | 10 | // InitGenesis initializes the capability module's state from a provided genesis 11 | // state. 12 | func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { 13 | for _, allocation := range genState.Allocations { 14 | k.SetAllocation(ctx, *allocation) 15 | } 16 | } 17 | 18 | // ExportGenesis returns the capability module's exported genesis. 19 | func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { 20 | return &types.GenesisState{} 21 | } 22 | -------------------------------------------------------------------------------- /x/nftstaking/keeper/grpc_query.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | ) 9 | 10 | type Querier struct { 11 | keeper Keeper 12 | } 13 | 14 | func NewQuerier(keeper Keeper) types.QueryServer { 15 | return &Querier{keeper: keeper} 16 | } 17 | 18 | var _ types.QueryServer = Querier{} 19 | 20 | func (q Querier) QueryNftStakings(goCtx context.Context, request *types.QueryNftStakingsRequest) (*types.QueryNftStakingsResponse, error) { 21 | ctx := sdk.UnwrapSDKContext(goCtx) 22 | 23 | return &types.QueryNftStakingsResponse{ 24 | Nftstakings: q.keeper.GetAllNftStakings(ctx), 25 | }, nil 26 | } 27 | -------------------------------------------------------------------------------- /proto/teritori/airdrop/v1beta1/allocation.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.airdrop.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "cosmos_proto/cosmos.proto"; 6 | 7 | option go_package = "github.com/NXTPOP/teritori-chain/x/airdrop/types"; 8 | 9 | // AirdropAllocation defines the user's airdrop allocation. 10 | message AirdropAllocation { 11 | string chain = 1; 12 | string address = 2; 13 | string amount = 3 [ 14 | (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", 15 | (gogoproto.nullable) = false 16 | ]; 17 | string claimed_amount = 4 [ 18 | (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", 19 | (gogoproto.nullable) = false 20 | ]; 21 | } 22 | -------------------------------------------------------------------------------- /app/params/proto.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | "github.com/cosmos/cosmos-sdk/codec/types" 6 | "github.com/cosmos/cosmos-sdk/x/auth/tx" 7 | ) 8 | 9 | // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. 10 | func MakeEncodingConfig() EncodingConfig { 11 | amino := codec.NewLegacyAmino() 12 | interfaceRegistry := types.NewInterfaceRegistry() 13 | marshaler := codec.NewProtoCodec(interfaceRegistry) 14 | txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) 15 | 16 | return EncodingConfig{ 17 | InterfaceRegistry: interfaceRegistry, 18 | Marshaler: marshaler, 19 | TxConfig: txCfg, 20 | Amino: amino, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /x/airdrop/keeper/querier.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | abci "github.com/tendermint/tendermint/abci/types" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 7 | "github.com/cosmos/cosmos-sdk/codec" 8 | sdk "github.com/cosmos/cosmos-sdk/types" 9 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 10 | ) 11 | 12 | // NewQuerier returns a new sdk.Keeper instance. 13 | func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { 14 | return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { 15 | switch path[0] { 16 | default: 17 | return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /x/nftstaking/keeper/keeper.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 5 | "github.com/cosmos/cosmos-sdk/codec" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | ) 8 | 9 | // Keeper is for managing token module 10 | type Keeper struct { 11 | cdc codec.BinaryCodec 12 | storeKey sdk.StoreKey 13 | bk types.BankKeeper 14 | } 15 | 16 | // NewKeeper returns instance of a keeper 17 | func NewKeeper(storeKey sdk.StoreKey, cdc codec.BinaryCodec, bk types.BankKeeper) Keeper { 18 | return Keeper{ 19 | cdc: cdc, 20 | storeKey: storeKey, 21 | bk: bk, 22 | } 23 | } 24 | 25 | // BondDenom returns the denom that is basically used for fee payment 26 | func (k Keeper) BondDenom(ctx sdk.Context) string { 27 | return "utori" 28 | } 29 | -------------------------------------------------------------------------------- /app/genesis.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // The genesis state of the blockchain is represented here as a map of raw json 8 | // messages key'd by a identifier string. 9 | // The identifier is used to determine which module genesis information belongs 10 | // to so it may be appropriately routed during init chain. 11 | // Within this application default genesis information is retrieved from 12 | // the ModuleBasicManager which populates json from each BasicModule 13 | // object provided to it during init. 14 | type GenesisState map[string]json.RawMessage 15 | 16 | // NewDefaultGenesisState generates the default state for the application. 17 | func NewDefaultGenesisState() GenesisState { 18 | encCfg := MakeEncodingConfig() 19 | return ModuleBasics.DefaultGenesis(encCfg.Marshaler) 20 | } 21 | -------------------------------------------------------------------------------- /app/wasm_config.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" 5 | ) 6 | 7 | const ( 8 | // DefaultJunoInstanceCost is initially set the same as in wasmd 9 | DefaultJunoInstanceCost uint64 = 60_000 10 | // DefaultJunoCompileCost set to a large number for testing 11 | DefaultJunoCompileCost uint64 = 100 12 | ) 13 | 14 | // JunoGasRegisterConfig is defaults plus a custom compile amount 15 | func JunoGasRegisterConfig() wasmkeeper.WasmGasRegisterConfig { 16 | gasConfig := wasmkeeper.DefaultGasRegisterConfig() 17 | gasConfig.InstanceCost = DefaultJunoInstanceCost 18 | gasConfig.CompileCost = DefaultJunoCompileCost 19 | 20 | return gasConfig 21 | } 22 | 23 | func NewPoppWasmGasRegister() wasmkeeper.WasmGasRegister { 24 | return wasmkeeper.NewWasmGasRegister(JunoGasRegisterConfig()) 25 | } 26 | -------------------------------------------------------------------------------- /proto/teritori/nftstaking/v1beta1/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.nftstaking.v1beta1; 3 | 4 | import "cosmos/base/query/v1beta1/pagination.proto"; 5 | import "gogoproto/gogo.proto"; 6 | import "google/api/annotations.proto"; 7 | import "teritori/nftstaking/v1beta1/nftstaking.proto"; 8 | 9 | option go_package = "github.com/NXTPOP/teritori-chain/x/nftstaking/types"; 10 | 11 | // Query defines the gRPC querier service 12 | service Query { 13 | rpc QueryNftStakings(QueryNftStakingsRequest) returns (QueryNftStakingsResponse) { 14 | option (google.api.http).get = "/teritori/nftstaking/v1beta1/nftstakings"; 15 | } 16 | } 17 | 18 | message QueryNftStakingsRequest {} 19 | message QueryNftStakingsResponse { 20 | repeated teritori.nftstaking.v1beta1.NftStaking nftstakings = 1 21 | [ (gogoproto.nullable) = false ]; 22 | } 23 | -------------------------------------------------------------------------------- /x/airdrop/types/expected_keepers.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" 6 | ) 7 | 8 | type BankKeeper interface { 9 | SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error 10 | SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error 11 | GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin 12 | MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error 13 | } 14 | 15 | type StakingKeeper interface { 16 | // BondDenom - Bondable coin denomination 17 | BondDenom(sdk.Context) string 18 | } 19 | 20 | type AccountKeeper interface { 21 | GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI 22 | } 23 | -------------------------------------------------------------------------------- /x/nftstaking/keeper/msg_server.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | ) 9 | 10 | type msgServer struct { 11 | keeper Keeper 12 | } 13 | 14 | // NewMsgServerImpl returns an implementation of the bank MsgServer interface 15 | // for the provided Keeper. 16 | func NewMsgServerImpl(keeper Keeper) types.MsgServer { 17 | return &msgServer{ 18 | keeper: keeper, 19 | } 20 | } 21 | 22 | var _ types.MsgServer = msgServer{} 23 | 24 | func (k msgServer) RegisterNftStaking(goCtx context.Context, msg *types.MsgRegisterNftStaking) (*types.MsgRegisterNftStakingResponse, error) { 25 | ctx := sdk.UnwrapSDKContext(goCtx) 26 | 27 | k.keeper.SetNftStaking(ctx, msg.NftStaking) 28 | return &types.MsgRegisterNftStakingResponse{}, nil 29 | } 30 | -------------------------------------------------------------------------------- /x/airdrop/types/errors.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/types/errors" 5 | ) 6 | 7 | // errors 8 | var ( 9 | ErrEmptyRewardAddress = errors.Register(ModuleName, 1, "empty reward address") 10 | ErrEmptyOnChainAllocationAddress = errors.Register(ModuleName, 2, "empty on-chain allocation address") 11 | ErrAirdropAllocationDoesNotExists = errors.Register(ModuleName, 3, "airdrop allocation does not exists for the address") 12 | ErrAirdropAllocationAlreadyClaimed = errors.Register(ModuleName, 4, "airdrop allocation is already claimed for the address") 13 | ErrNativeChainAccountSigVerificationFailure = errors.Register(ModuleName, 5, "native chain account signature verification failure") 14 | ErrEmptyAddress = errors.Register(ModuleName, 6, "empty address") 15 | ) 16 | -------------------------------------------------------------------------------- /x/nftstaking/spec/README.md: -------------------------------------------------------------------------------- 1 | # `x/nftstaking` 2 | 3 | ## Abstract 4 | 5 | `nftstaking` module is provide rewards to nft stakers on different networks. 6 | 7 | The owner registers nft stakers on the module. 8 | 9 | Part of inflation rewards are allocated to registered nft stakers and broadcasted on everyblock. 10 | 11 | ## State 12 | 13 | `nftstaking` module keeps the information of `NftStaking` that shows nft information and reward address with weights. 14 | 15 | ```go 16 | type NftStaking struct { 17 | NftIdentifier string 18 | NftMetadata string 19 | RewardAddress string 20 | RewardWeight uint64 21 | } 22 | ``` 23 | 24 | ## Messages 25 | 26 | ### MsgRegisterNftStaking 27 | 28 | `MsgRegisterNftStaking` describes the message to register staked nfts by admin. 29 | 30 | ```go 31 | type MsgRegisterNftStaking struct { 32 | Sender string 33 | NftStaking NftStaking 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /x/airdrop/keeper/keeper_test.go: -------------------------------------------------------------------------------- 1 | package keeper_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/suite" 7 | 8 | tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 9 | 10 | "github.com/cosmos/cosmos-sdk/codec" 11 | sdk "github.com/cosmos/cosmos-sdk/types" 12 | 13 | simapp "github.com/NXTPOP/teritori-chain/app" 14 | ) 15 | 16 | const ( 17 | isCheckTx = false 18 | ) 19 | 20 | type KeeperTestSuite struct { 21 | suite.Suite 22 | 23 | legacyAmino *codec.LegacyAmino 24 | ctx sdk.Context 25 | app *simapp.TeritoriApp 26 | } 27 | 28 | func (suite *KeeperTestSuite) SetupTest() { 29 | app := simapp.Setup(isCheckTx) 30 | 31 | suite.legacyAmino = app.LegacyAmino() 32 | suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) 33 | suite.app = app 34 | } 35 | 36 | func TestKeeperSuite(t *testing.T) { 37 | suite.Run(t, new(KeeperTestSuite)) 38 | } 39 | -------------------------------------------------------------------------------- /x/nftstaking/handler.go: -------------------------------------------------------------------------------- 1 | package nftstaking 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/nftstaking/keeper" 5 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | "github.com/cosmos/cosmos-sdk/types/errors" 8 | ) 9 | 10 | // NewHandler returns new instance of handler 11 | func NewHandler(k keeper.Keeper) sdk.Handler { 12 | msgServer := keeper.NewMsgServerImpl(k) 13 | 14 | return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { 15 | ctx = ctx.WithEventManager(sdk.NewEventManager()) 16 | 17 | switch msg := msg.(type) { 18 | 19 | case *types.MsgRegisterNftStaking: 20 | res, err := msgServer.RegisterNftStaking(sdk.WrapSDKContext(ctx), msg) 21 | return sdk.WrapServiceResult(ctx, res, err) 22 | 23 | default: 24 | return nil, errors.Wrapf(errors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /proto/teritori/airdrop/v1beta1/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.airdrop.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/api/annotations.proto"; 6 | import "cosmos/base/v1beta1/coin.proto"; 7 | import "teritori/airdrop/v1beta1/allocation.proto"; 8 | 9 | option go_package = "github.com/NXTPOP/teritori-chain/x/airdrop/types"; 10 | 11 | // Query defines the gRPC querier service. 12 | service Query { 13 | rpc Allocation(QueryAllocationRequest) returns (QueryAllocationResponse) { 14 | option (google.api.http).get = 15 | "/teritori/airdrop/v1beta1/allocation/{address}"; 16 | } 17 | } 18 | 19 | message QueryAllocationRequest { 20 | option (gogoproto.equal) = false; 21 | option (gogoproto.goproto_getters) = false; 22 | 23 | // address is the address to query allocation for. 24 | string address = 1; 25 | } 26 | 27 | message QueryAllocationResponse { 28 | AirdropAllocation allocation = 1; 29 | } 30 | -------------------------------------------------------------------------------- /x/nftstaking/abci.go: -------------------------------------------------------------------------------- 1 | package nftstaking 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/nftstaking/keeper" 5 | sdk "github.com/cosmos/cosmos-sdk/types" 6 | ) 7 | 8 | func EndBlocker(ctx sdk.Context, k keeper.Keeper) { 9 | stakings := k.GetAllNftStakings(ctx) 10 | 11 | totalInflation := sdk.NewInt(1000_000_000) 12 | totalStakingPower := uint64(0) 13 | 14 | for _, staking := range stakings { 15 | totalStakingPower += staking.RewardWeight 16 | } 17 | 18 | for _, staking := range stakings { 19 | reward := totalInflation.Mul(sdk.NewInt(int64(staking.RewardWeight))).Quo(sdk.NewInt(int64(totalStakingPower))) 20 | 21 | rewardAddr, err := sdk.AccAddressFromBech32(staking.RewardAddress) 22 | if err != nil { 23 | continue 24 | } 25 | cachedCtx, write := ctx.CacheContext() 26 | err = k.AllocateTokensToRewardAddress(cachedCtx, rewardAddr, sdk.NewCoin(k.BondDenom(ctx), reward)) 27 | if err == nil { 28 | write() 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /x/airdrop/keeper/keeper.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/tendermint/tendermint/libs/log" 7 | 8 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 9 | "github.com/cosmos/cosmos-sdk/codec" 10 | sdk "github.com/cosmos/cosmos-sdk/types" 11 | ) 12 | 13 | // Keeper struct 14 | type Keeper struct { 15 | cdc codec.Codec 16 | storeKey sdk.StoreKey 17 | bankKeeper types.BankKeeper 18 | stakingKeeper types.StakingKeeper 19 | acountKeeper types.AccountKeeper 20 | } 21 | 22 | // NewKeeper returns keeper 23 | func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, bk types.BankKeeper, sk types.StakingKeeper, ak types.AccountKeeper) *Keeper { 24 | return &Keeper{ 25 | cdc: cdc, 26 | storeKey: storeKey, 27 | bankKeeper: bk, 28 | stakingKeeper: sk, 29 | acountKeeper: ak, 30 | } 31 | } 32 | 33 | // Logger returns logger 34 | func (k Keeper) Logger(ctx sdk.Context) log.Logger { 35 | return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) 36 | } 37 | -------------------------------------------------------------------------------- /app/params/weights.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | // Default simulation operation weights for messages and gov proposals 4 | const ( 5 | DefaultWeightMsgSend int = 100 6 | DefaultWeightMsgMultiSend int = 10 7 | DefaultWeightMsgSetWithdrawAddress int = 50 8 | DefaultWeightMsgWithdrawDelegationReward int = 50 9 | DefaultWeightMsgWithdrawValidatorCommission int = 50 10 | DefaultWeightMsgFundCommunityPool int = 50 11 | DefaultWeightMsgDeposit int = 100 12 | DefaultWeightMsgVote int = 67 13 | DefaultWeightMsgUnjail int = 100 14 | DefaultWeightMsgCreateValidator int = 100 15 | DefaultWeightMsgEditValidator int = 5 16 | DefaultWeightMsgDelegate int = 100 17 | DefaultWeightMsgUndelegate int = 100 18 | DefaultWeightMsgBeginRedelegate int = 100 19 | 20 | DefaultWeightCommunitySpendProposal int = 5 21 | DefaultWeightTextProposal int = 5 22 | DefaultWeightParamChangeProposal int = 5 23 | ) 24 | -------------------------------------------------------------------------------- /x/airdrop/handler.go: -------------------------------------------------------------------------------- 1 | package airdrop 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/airdrop/keeper" 7 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 8 | sdk "github.com/cosmos/cosmos-sdk/types" 9 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 10 | ) 11 | 12 | // NewHandler returns airdrop module messages 13 | func NewHandler(k keeper.Keeper) sdk.Handler { 14 | msgServer := keeper.NewMsgServerImpl(k) 15 | 16 | return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { 17 | ctx = ctx.WithEventManager(sdk.NewEventManager()) 18 | 19 | switch msg := msg.(type) { 20 | case *types.MsgClaimAllocation: 21 | res, err := msgServer.ClaimAllocation(sdk.WrapSDKContext(ctx), msg) 22 | return sdk.WrapServiceResult(ctx, res, err) 23 | 24 | case *types.MsgSetAllocation: 25 | res, err := msgServer.SetAllocation(sdk.WrapSDKContext(ctx), msg) 26 | return sdk.WrapServiceResult(ctx, res, err) 27 | 28 | default: 29 | errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) 30 | return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /x/nftstaking/client/cli/query.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/spf13/cobra" 7 | 8 | "github.com/cosmos/cosmos-sdk/client" 9 | "github.com/cosmos/cosmos-sdk/client/flags" 10 | 11 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 12 | ) 13 | 14 | func NewQueryCmd() *cobra.Command { 15 | queryCmd := &cobra.Command{ 16 | Use: types.RouterKey, 17 | Short: "query commands for the nftstaking module", 18 | } 19 | queryCmd.AddCommand( 20 | GetCmdQueryNftStakings(), 21 | ) 22 | 23 | return queryCmd 24 | } 25 | 26 | func GetCmdQueryNftStakings() *cobra.Command { 27 | cmd := &cobra.Command{ 28 | Use: "stakings", 29 | Short: "Get all nft stakings", 30 | RunE: func(cmd *cobra.Command, args []string) error { 31 | clientCtx := client.GetClientContextFromCmd(cmd) 32 | 33 | queryClient := types.NewQueryClient(clientCtx) 34 | res, err := queryClient.QueryNftStakings(context.Background(), &types.QueryNftStakingsRequest{}) 35 | if err != nil { 36 | return err 37 | } 38 | 39 | return clientCtx.PrintProto(res) 40 | }, 41 | } 42 | 43 | flags.AddQueryFlagsToCmd(cmd) 44 | 45 | return cmd 46 | } 47 | -------------------------------------------------------------------------------- /x/airdrop/keeper/msg_server.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | ) 9 | 10 | type msgServer struct { 11 | keeper Keeper 12 | } 13 | 14 | // NewMsgServerImpl returns an implementation of the bank MsgServer interface 15 | // for the provided Keeper. 16 | func NewMsgServerImpl(keeper Keeper) types.MsgServer { 17 | return &msgServer{ 18 | keeper: keeper, 19 | } 20 | } 21 | 22 | var _ types.MsgServer = msgServer{} 23 | 24 | func (k msgServer) ClaimAllocation(goCtx context.Context, msg *types.MsgClaimAllocation) (*types.MsgClaimAllocationResponse, error) { 25 | ctx := sdk.UnwrapSDKContext(goCtx) 26 | 27 | err := k.keeper.ClaimAllocation(ctx, msg.Address, msg.PubKey, msg.RewardAddress, msg.Signature) 28 | return &types.MsgClaimAllocationResponse{}, err 29 | } 30 | 31 | func (k msgServer) SetAllocation(goCtx context.Context, msg *types.MsgSetAllocation) (*types.MsgSetAllocationResponse, error) { 32 | ctx := sdk.UnwrapSDKContext(goCtx) 33 | 34 | k.keeper.SetAllocation(ctx, msg.Allocation) 35 | return &types.MsgSetAllocationResponse{}, nil 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Teritori 2 | 3 | ![Banner!](assets/banner.png) 4 | 5 | [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/teritori) 6 | [![Go Report 7 | Card](https://goreportcard.com/badge/github.com/TERITORI/teritori-chain?style=flat-square)](https://goreportcard.com/report/github.com/TERITORI/teritori-chain) 8 | [![Version](https://img.shields.io/github/tag/TERITORI/teritori-chain.svg?style=flat-square)](https://github.com/TERITORI/teritori-chain/releases/latest) 9 | [![Lines Of 10 | Code](https://img.shields.io/tokei/lines/github/TERITORI/teritori-chain?style=flat-square)](https://github.com/TERITORI/teritori-chain) 11 | 12 | Teritori is a Cosmos SDK based blockchain here to enhance Web3 individuals, communities & builders experience through an all-in-one hub of dApps. 13 | 14 | # Testnet 15 | 16 | ## All the testnet chains: 17 | [*DEPRECIATED*] - [teritori-testnet-v1](https://github.com/TERITORI/teritori-chain/tree/main/testnet/teritori-testnet-v1) 18 | [__ACTIVE__] - [teritori-testnet-v2](https://github.com/TERITORI/teritori-chain/tree/main/testnet/teritori-testnet-v2) 19 | 20 | # Mainnet 21 | 22 | ## All the mainnet chains: 23 | -------------------------------------------------------------------------------- /scripts/protocgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | # get protoc executions 6 | go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null 7 | # get cosmos sdk from github 8 | go get github.com/cosmos/cosmos-sdk 2>/dev/null 9 | 10 | # Get the path of the cosmos-sdk repo from go/pkg/mod 11 | cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk) 12 | proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) 13 | for dir in $proto_dirs; do 14 | # generate protobuf bind 15 | buf protoc \ 16 | -I "proto" \ 17 | -I "$cosmos_sdk_dir/third_party/proto" \ 18 | -I "$cosmos_sdk_dir/proto" \ 19 | --gocosmos_out=plugins=interfacetype+grpc,\ 20 | Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ 21 | $(find "${dir}" -name '*.proto') 22 | 23 | # generate grpc gateway 24 | buf protoc \ 25 | -I "proto" \ 26 | -I "$cosmos_sdk_dir/third_party/proto" \ 27 | -I "$cosmos_sdk_dir/proto" \ 28 | --grpc-gateway_out=logtostderr=true:. \ 29 | $(find "${dir}" -maxdepth 1 -name '*.proto') 30 | done 31 | 32 | cp -r ./github.com/NXTPOP/teritori-chain/x/* x/ 33 | rm -rf ./github.com -------------------------------------------------------------------------------- /x/nftstaking/types/msgs.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | ) 6 | 7 | var _ sdk.Msg = &MsgRegisterNftStaking{} 8 | 9 | var MsgTypeClaimAllocation = "claim_allocation" 10 | 11 | func NewMsgRegisterNftStaking( 12 | sender string, 13 | nftStaking NftStaking, 14 | ) *MsgRegisterNftStaking { 15 | return &MsgRegisterNftStaking{ 16 | Sender: sender, 17 | NftStaking: nftStaking, 18 | } 19 | } 20 | 21 | func (m *MsgRegisterNftStaking) Route() string { 22 | return ModuleName 23 | } 24 | 25 | func (m *MsgRegisterNftStaking) Type() string { 26 | return MsgTypeClaimAllocation 27 | } 28 | 29 | func (m *MsgRegisterNftStaking) ValidateBasic() error { 30 | if m.Sender == "" { 31 | return ErrEmptySender 32 | } 33 | 34 | if m.NftStaking.RewardAddress == "" { 35 | return ErrEmptyRewardAddress 36 | } 37 | 38 | return nil 39 | } 40 | 41 | func (m *MsgRegisterNftStaking) GetSignBytes() []byte { 42 | bz := ModuleCdc.MustMarshalJSON(m) 43 | return sdk.MustSortJSON(bz) 44 | } 45 | 46 | func (m *MsgRegisterNftStaking) GetSigners() []sdk.AccAddress { 47 | sender, err := sdk.AccAddressFromBech32(m.Sender) 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | return []sdk.AccAddress{ 53 | sender, 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /x/airdrop/types/codec.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | "github.com/cosmos/cosmos-sdk/codec/types" 6 | cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | "github.com/cosmos/cosmos-sdk/types/msgservice" 9 | ) 10 | 11 | func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { 12 | cdc.RegisterConcrete(&MsgClaimAllocation{}, "teritori/airdrop/ClaimAllocation", nil) 13 | } 14 | 15 | func RegisterInterfaces(registry types.InterfaceRegistry) { 16 | registry.RegisterImplementations((*sdk.Msg)(nil), 17 | &MsgClaimAllocation{}, 18 | ) 19 | 20 | msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) 21 | } 22 | 23 | var ( 24 | amino = codec.NewLegacyAmino() 25 | 26 | // ModuleCdc references the global x/staking module codec. Note, the codec should 27 | // ONLY be used in certain instances of tests and for JSON encoding as Amino is 28 | // still used for that purpose. 29 | // 30 | // The actual codec used for serialization should be provided to x/staking and 31 | // defined at the application level. 32 | ModuleCdc = codec.NewAminoCodec(amino) 33 | ) 34 | 35 | func init() { 36 | RegisterLegacyAminoCodec(amino) 37 | cryptocodec.RegisterCrypto(amino) 38 | amino.Seal() 39 | } 40 | -------------------------------------------------------------------------------- /x/nftstaking/types/codec.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | "github.com/cosmos/cosmos-sdk/codec/types" 6 | cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | "github.com/cosmos/cosmos-sdk/types/msgservice" 9 | ) 10 | 11 | func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { 12 | cdc.RegisterConcrete(&MsgRegisterNftStaking{}, "teritori/nftstaking/RegisterNftStaking", nil) 13 | } 14 | 15 | func RegisterInterfaces(registry types.InterfaceRegistry) { 16 | registry.RegisterImplementations((*sdk.Msg)(nil), 17 | &MsgRegisterNftStaking{}, 18 | ) 19 | 20 | msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) 21 | } 22 | 23 | var ( 24 | amino = codec.NewLegacyAmino() 25 | 26 | // ModuleCdc references the global x/staking module codec. Note, the codec should 27 | // ONLY be used in certain instances of tests and for JSON encoding as Amino is 28 | // still used for that purpose. 29 | // 30 | // The actual codec used for serialization should be provided to x/staking and 31 | // defined at the application level. 32 | ModuleCdc = codec.NewAminoCodec(amino) 33 | ) 34 | 35 | func init() { 36 | RegisterLegacyAminoCodec(amino) 37 | cryptocodec.RegisterCrypto(amino) 38 | amino.Seal() 39 | } 40 | -------------------------------------------------------------------------------- /x/nftstaking/keeper/nftstaking.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 5 | "github.com/cosmos/cosmos-sdk/store/prefix" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | ) 8 | 9 | func (k Keeper) GetAllNftStakings(ctx sdk.Context) []types.NftStaking { 10 | stakings := []types.NftStaking{} 11 | store := ctx.KVStore(k.storeKey) 12 | iterator := sdk.KVStorePrefixIterator(store, types.PrefixKeyNftStaking) 13 | defer iterator.Close() 14 | 15 | for ; iterator.Valid(); iterator.Next() { 16 | staking := types.NftStaking{} 17 | k.cdc.MustUnmarshal(iterator.Value(), &staking) 18 | stakings = append(stakings, staking) 19 | } 20 | 21 | return stakings 22 | } 23 | 24 | func (k Keeper) SetNftStaking(ctx sdk.Context, staking types.NftStaking) { 25 | prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.PrefixKeyNftStaking) 26 | bz := k.cdc.MustMarshal(&staking) 27 | prefixStore.Set([]byte(staking.NftIdentifier), bz) 28 | } 29 | 30 | func (k Keeper) AllocateTokensToRewardAddress(ctx sdk.Context, addr sdk.AccAddress, amount sdk.Coin) error { 31 | err := k.bk.MintCoins(ctx, types.ModuleName, sdk.Coins{amount}) 32 | if err != nil { 33 | return err 34 | } 35 | return k.bk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, sdk.Coins{amount}) 36 | } 37 | -------------------------------------------------------------------------------- /x/airdrop/keeper/signature_test.go: -------------------------------------------------------------------------------- 1 | package keeper_test 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/airdrop/keeper" 5 | ) 6 | 7 | func (suite *KeeperTestSuite) TestVerifySignature() { 8 | tests := []struct { 9 | testCase string 10 | chain string 11 | address string 12 | pubKey string 13 | rewardAddr string 14 | signature string 15 | expectPass bool 16 | }{ 17 | { 18 | "evm invalid signature verification", 19 | "evm", 20 | "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", 21 | "", 22 | "tori1665x2fj8xyez0vqxs5pjhc6e7ktmmrx9dz864d", 23 | "0xed41b43ee89d28652b34f0e5c769753ba3b4f0cb6b85bc63f29ba6680cedbf89688d66145b5326c1afb811117a196f0f14b73989b062dde980ce13cd06f1ad801b", 24 | false, 25 | }, 26 | { 27 | "evm successful verification", 28 | "evm", 29 | "0x583e8DD54b7C3F5Ea23862E0E852f0e6914475D5", 30 | "", 31 | "tori1pkmvlnstq8q7djns3w882pcu92xh4c9x4ukhcd", 32 | "0xf2cde652dbe26e73e508782d673850ac10880fafef4f7cd2599fd434736ef0ca2d8a2bd65c7f8b67abc1a837f95a23e3c34789dd0ac230cb9b04000641d62b521c", 33 | true, 34 | }, 35 | } 36 | 37 | for _, tc := range tests { 38 | passed := keeper.VerifySignature(tc.chain, tc.address, tc.pubKey, tc.rewardAddr, tc.signature) 39 | if tc.expectPass { 40 | suite.Require().True(passed) 41 | } else { 42 | suite.Require().False(passed) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf $HOME/.teritorid/ 4 | 5 | cd $HOME 6 | 7 | teritorid init --chain-id=testing testing --home=$HOME/.teritorid 8 | teritorid keys add validator --keyring-backend=test --home=$HOME/.teritorid 9 | teritorid add-genesis-account $(teritorid keys show validator -a --keyring-backend=test --home=$HOME/.teritorid) 100000000000utori,100000000000stake --home=$HOME/.teritorid 10 | teritorid gentx validator 500000000stake --keyring-backend=test --home=$HOME/.teritorid --chain-id=testing 11 | teritorid collect-gentxs --home=$HOME/.teritorid 12 | 13 | sed -i '' -e 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' $HOME/.teritorid/config/app.toml 14 | sed -i '' -e 's/enable = false/enable = true/g' $HOME/.teritorid/config/app.toml 15 | sed -i '' -e 's/cors_allowed_origins = \[\]/cors_allowed_origins = ["*"]/g' $HOME/.teritorid/config/config.toml 16 | 17 | teritorid start --home=$HOME/.teritorid 18 | 19 | # teritorid tx bank send validator pop18mu5hhgy64390q56msql8pfwps0uesn0gf0elf 10000000utori --keyring-backend=test --chain-id=testing --home=$HOME/.teritorid/ --yes --broadcast-mode=block 20 | # teritorid tx airdrop claim-allocation 0x9d967594Cc61453aFEfD657313e5F05be7c6F88F 0xb89733c05568385a861fa20f5c4abe53c23a13962515bf5510638b4e3947b1236963b53de549ae762bbd45427dbd3712ae7d169a935d21e44e7da86b1c552f471b --from=validator --keyring-backend=test --chain-id=testing --home=$HOME/.teritorid/ --yes --broadcast-mode=block 21 | -------------------------------------------------------------------------------- /proto/teritori/airdrop/v1beta1/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package teritori.airdrop.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/any.proto"; 6 | import "teritori/airdrop/v1beta1/allocation.proto"; 7 | 8 | option go_package = "github.com/NXTPOP/teritori-chain/x/airdrop/types"; 9 | 10 | // Msg defines the staking Msg service. 11 | service Msg { 12 | // ClaimAllocation defines a method to claim allocation 13 | rpc ClaimAllocation(MsgClaimAllocation) returns (MsgClaimAllocationResponse); 14 | // SetAllocation defines a method to set allocation 15 | rpc SetAllocation(MsgSetAllocation) returns (MsgSetAllocationResponse); 16 | } 17 | 18 | // MsgSetAllocation defines an sdk.Msg type that set airdrop allocation 19 | message MsgSetAllocation { 20 | string sender = 1; 21 | AirdropAllocation allocation = 2 [(gogoproto.nullable) = false]; 22 | } 23 | // MsgSetAllocationResponse defines the Msg/SetAllocation response type. 24 | message MsgSetAllocationResponse {} 25 | 26 | // MsgClaimAllocation defines an sdk.Msg type that claims airdrop allocation 27 | message MsgClaimAllocation { 28 | option (gogoproto.equal) = false; 29 | option (gogoproto.goproto_getters) = false; 30 | 31 | string address = 1; 32 | string pub_key = 2; 33 | string reward_address = 3; 34 | string signature = 4; 35 | } 36 | 37 | // MsgClaimAllocationResponse defines the Msg/ClaimAllocation response type. 38 | message MsgClaimAllocationResponse { 39 | } -------------------------------------------------------------------------------- /x/airdrop/client/cli/query.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 8 | "github.com/cosmos/cosmos-sdk/client" 9 | "github.com/cosmos/cosmos-sdk/client/flags" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | // GetQueryCmd returns the cli query commands for this module 14 | func GetQueryCmd() *cobra.Command { 15 | queryCmd := &cobra.Command{ 16 | Use: types.ModuleName, 17 | Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), 18 | DisableFlagParsing: true, 19 | SuggestionsMinimumDistance: 2, 20 | RunE: client.ValidateCmd, 21 | } 22 | 23 | queryCmd.AddCommand( 24 | GetCmdQueryAllocation(), 25 | ) 26 | 27 | return queryCmd 28 | } 29 | 30 | func GetCmdQueryAllocation() *cobra.Command { 31 | cmd := &cobra.Command{ 32 | Use: "allocation [addr]", 33 | Short: "Query allocations of an address", 34 | RunE: func(cmd *cobra.Command, args []string) error { 35 | clientCtx := client.GetClientContextFromCmd(cmd) 36 | 37 | params := &types.QueryAllocationRequest{Address: args[0]} 38 | 39 | queryClient := types.NewQueryClient(clientCtx) 40 | res, err := queryClient.Allocation(context.Background(), params) 41 | if err != nil { 42 | return err 43 | } 44 | 45 | return clientCtx.PrintProto(res.Allocation) 46 | }, 47 | } 48 | 49 | flags.AddQueryFlagsToCmd(cmd) 50 | 51 | return cmd 52 | } 53 | -------------------------------------------------------------------------------- /x/airdrop/spec/README.md: -------------------------------------------------------------------------------- 1 | # `x/airdrop` 2 | 3 | ## Abstract 4 | 5 | `airdrop` module is to allocate airdrop to different network addresses. 6 | 7 | The target networks available to allocate airdrops are 8 | 9 | - solana 10 | - evm 11 | - cosmos 12 | - osmosis 13 | - juno 14 | - terra 15 | 16 | Airdrop allocation can be set from genesis or admin can set the allocation for different network addresses. 17 | The user with airdrop allocation can send address ownership verification signature to receive airdrop. 18 | 19 | ## State 20 | 21 | Airdrop module keeps the information of `AirdropAllocation` that shows allocation and claimed amounts for an address on different network. 22 | 23 | ```go 24 | type AirdropAllocation struct { 25 | Chain string 26 | Address string 27 | Amount sdk.Coin 28 | ClaimedAmount sdk.Coin 29 | } 30 | ``` 31 | 32 | ## Messages 33 | 34 | ### MsgSetAllocation 35 | 36 | `MsgSetAllocation` describes the message to set allocation for an account by admin. 37 | 38 | ```go 39 | type MsgSetAllocation struct { 40 | Sender string 41 | Allocation AirdropAllocation 42 | } 43 | ``` 44 | 45 | ### MsgClaimAllocation 46 | 47 | `MsgClaimAllocation` describes the message to claim airdrop allocation allocated to different network address. 48 | RewardAddress is the teritori chain address that receives allocation. 49 | 50 | ```go 51 | type MsgClaimAllocation struct { 52 | Address string 53 | PubKey string 54 | RewardAddress string 55 | Signature string 56 | } 57 | ``` 58 | -------------------------------------------------------------------------------- /x/airdrop/keeper/allocation_test.go: -------------------------------------------------------------------------------- 1 | package keeper_test 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 5 | sdk "github.com/cosmos/cosmos-sdk/types" 6 | ) 7 | 8 | func (suite *KeeperTestSuite) TestAllocationGetSet() { 9 | // get allocation for an address before set 10 | allocation := suite.app.AirdropKeeper.GetAllocation(suite.ctx, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9") 11 | suite.Require().Nil(allocation) 12 | 13 | allocations := suite.app.AirdropKeeper.GetAllAllocations(suite.ctx) 14 | suite.Require().Len(allocations, 6) 15 | 16 | // set allocation 17 | evmAllocation := types.AirdropAllocation{ 18 | Chain: "evm", 19 | Address: "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", 20 | Amount: sdk.NewInt64Coin("utori", 1000000), 21 | ClaimedAmount: sdk.NewInt64Coin("utori", 0), 22 | } 23 | suite.app.AirdropKeeper.SetAllocation(suite.ctx, evmAllocation) 24 | 25 | // check allocation after set 26 | allocation = suite.app.AirdropKeeper.GetAllocation(suite.ctx, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9") 27 | suite.Require().Equal(*allocation, evmAllocation) 28 | 29 | allocations = suite.app.AirdropKeeper.GetAllAllocations(suite.ctx) 30 | suite.Require().Len(allocations, 7) 31 | 32 | // check allocation after delete 33 | suite.app.AirdropKeeper.DeleteAllocation(suite.ctx, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9") 34 | 35 | allocation = suite.app.AirdropKeeper.GetAllocation(suite.ctx, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9") 36 | suite.Require().Nil(allocation) 37 | 38 | allocations = suite.app.AirdropKeeper.GetAllAllocations(suite.ctx) 39 | suite.Require().Len(allocations, 6) 40 | } 41 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | teritoridnode0: 5 | container_name: teritoridnode0 6 | image: "tendermint/teritoridnode" 7 | ports: 8 | - "26656-26657:26656-26657" 9 | environment: 10 | - ID=0 11 | - LOG=${LOG:-teritorid.log} 12 | volumes: 13 | - ./build:/teritorid:Z 14 | networks: 15 | localnet: 16 | ipv4_address: 192.168.10.2 17 | 18 | teritoridnode1: 19 | container_name: teritoridnode1 20 | image: "tendermint/teritoridnode" 21 | ports: 22 | - "26659-26660:26656-26657" 23 | environment: 24 | - ID=1 25 | - LOG=${LOG:-teritorid.log} 26 | volumes: 27 | - ./build:/teritorid:Z 28 | networks: 29 | localnet: 30 | ipv4_address: 192.168.10.3 31 | 32 | teritoridnode2: 33 | container_name: teritoridnode2 34 | image: "tendermint/teritoridnode" 35 | environment: 36 | - ID=2 37 | - LOG=${LOG:-teritorid.log} 38 | ports: 39 | - "26661-26662:26656-26657" 40 | volumes: 41 | - ./build:/teritorid:Z 42 | networks: 43 | localnet: 44 | ipv4_address: 192.168.10.4 45 | 46 | teritoridnode3: 47 | container_name: teritoridnode3 48 | image: "tendermint/teritoridnode" 49 | environment: 50 | - ID=3 51 | - LOG=${LOG:-teritorid.log} 52 | ports: 53 | - "26663-26664:26656-26657" 54 | volumes: 55 | - ./build:/teritorid:Z 56 | networks: 57 | localnet: 58 | ipv4_address: 192.168.10.5 59 | 60 | networks: 61 | localnet: 62 | driver: bridge 63 | ipam: 64 | driver: default 65 | config: 66 | - subnet: 192.168.10.0/16 67 | -------------------------------------------------------------------------------- /app/vesting.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | 6 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 7 | "github.com/cosmos/cosmos-sdk/x/auth/ante" 8 | vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" 9 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" 10 | ) 11 | 12 | // VestingTransactionDecorator prevents staking from vesting accounts 13 | type VestingTransactionDecorator struct { 14 | ak ante.AccountKeeper 15 | } 16 | 17 | func NewVestingTransactionDecorator(ak ante.AccountKeeper) VestingTransactionDecorator { 18 | return VestingTransactionDecorator{ 19 | ak: ak, 20 | } 21 | } 22 | 23 | // AnteHandle prevents staking from vesting accounts 24 | func (vtd VestingTransactionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { 25 | for _, msg := range tx.GetMsgs() { 26 | delegateMsg, ok := msg.(*stakingtypes.MsgDelegate) 27 | if !ok { 28 | continue 29 | } 30 | 31 | sender, err := sdk.AccAddressFromBech32(delegateMsg.DelegatorAddress) 32 | if err != nil { 33 | return ctx, err 34 | } 35 | 36 | acc := vtd.ak.GetAccount(ctx, sender) 37 | if acc == nil { 38 | return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, 39 | "account %s does not exist", acc) 40 | } 41 | 42 | // Check if vesting account 43 | _, isVesting := acc.(vesting.VestingAccount) 44 | if !isVesting { 45 | return next(ctx, tx, simulate) 46 | } 47 | 48 | return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, 49 | "cannot perform delegation on vesting account: %s", delegateMsg.DelegatorAddress, 50 | ) 51 | } 52 | 53 | return next(ctx, tx, simulate) 54 | } 55 | -------------------------------------------------------------------------------- /app/params/config.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | ) 6 | 7 | const ( 8 | HumanCoinUnit = "TORI" 9 | BaseCoinUnit = "utori" 10 | 11 | DefaultBondDenom = BaseCoinUnit 12 | 13 | // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address 14 | Bech32PrefixAccAddr = "tori" 15 | ) 16 | 17 | var ( 18 | // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key 19 | Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub" 20 | // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address 21 | Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper" 22 | // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key 23 | Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub" 24 | // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address 25 | Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons" 26 | // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key 27 | Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub" 28 | ) 29 | 30 | func init() { 31 | SetAddressPrefixes() 32 | RegisterDenoms() 33 | } 34 | 35 | func RegisterDenoms() { 36 | err := sdk.RegisterDenom(HumanCoinUnit, sdk.OneDec()) 37 | if err != nil { 38 | panic(err) 39 | } 40 | err = sdk.RegisterDenom(BaseCoinUnit, sdk.NewDecWithPrec(1, 6)) 41 | if err != nil { 42 | panic(err) 43 | } 44 | } 45 | 46 | func SetAddressPrefixes() { 47 | config := sdk.GetConfig() 48 | config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) 49 | config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) 50 | config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) 51 | } 52 | -------------------------------------------------------------------------------- /x/airdrop/types/genesis.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import "github.com/cosmos/cosmos-sdk/types" 4 | 5 | // DefaultGenesis returns the default Capability genesis state 6 | func DefaultGenesis() *GenesisState { 7 | return &GenesisState{ 8 | Allocations: []*AirdropAllocation{ 9 | { 10 | Chain: "evm", 11 | Address: "0x--", 12 | Amount: types.NewCoin("utori", types.NewIntWithDecimal(100, 6)), 13 | ClaimedAmount: types.NewCoin("utori", types.NewIntWithDecimal(0, 6)), 14 | }, 15 | { 16 | Chain: "solana", 17 | Address: "--", 18 | Amount: types.NewCoin("utori", types.NewIntWithDecimal(100, 6)), 19 | ClaimedAmount: types.NewCoin("utori", types.NewIntWithDecimal(0, 10)), 20 | }, 21 | { 22 | Chain: "terra", 23 | Address: "terra--", 24 | Amount: types.NewCoin("utori", types.NewIntWithDecimal(100, 6)), 25 | ClaimedAmount: types.NewCoin("utori", types.NewIntWithDecimal(0, 10)), 26 | }, 27 | { 28 | Chain: "cosmos", 29 | Address: "cosmos--", 30 | Amount: types.NewCoin("utori", types.NewIntWithDecimal(100, 6)), 31 | ClaimedAmount: types.NewCoin("utori", types.NewIntWithDecimal(0, 10)), 32 | }, 33 | { 34 | Chain: "juno", 35 | Address: "juno--", 36 | Amount: types.NewCoin("utori", types.NewIntWithDecimal(100, 6)), 37 | ClaimedAmount: types.NewCoin("utori", types.NewIntWithDecimal(0, 10)), 38 | }, 39 | { 40 | Chain: "osmosis", 41 | Address: "osmo--", 42 | Amount: types.NewCoin("utori", types.NewIntWithDecimal(100, 6)), 43 | ClaimedAmount: types.NewCoin("utori", types.NewIntWithDecimal(0, 10)), 44 | }, 45 | }, 46 | } 47 | } 48 | 49 | // Validate performs basic genesis state validation returning an error upon any 50 | // failure. 51 | func (gs GenesisState) Validate() error { 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /app/genesis_account.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | "errors" 5 | 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" 8 | ) 9 | 10 | var _ authtypes.GenesisAccount = (*SimGenesisAccount)(nil) 11 | 12 | // SimGenesisAccount defines a type that implements the GenesisAccount interface 13 | // to be used for simulation accounts in the genesis state. 14 | type SimGenesisAccount struct { 15 | *authtypes.BaseAccount 16 | 17 | // vesting account fields 18 | OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"` // total vesting coins upon initialization 19 | DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"` // delegated vested coins at time of delegation 20 | DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` // delegated vesting coins at time of delegation 21 | StartTime int64 `json:"start_time" yaml:"start_time"` // vesting start time (UNIX Epoch time) 22 | EndTime int64 `json:"end_time" yaml:"end_time"` // vesting end time (UNIX Epoch time) 23 | 24 | // module account fields 25 | ModuleName string `json:"module_name" yaml:"module_name"` // name of the module account 26 | ModulePermissions []string `json:"module_permissions" yaml:"module_permissions"` // permissions of module account 27 | } 28 | 29 | // Validate checks for errors on the vesting and module account parameters 30 | func (sga SimGenesisAccount) Validate() error { 31 | if !sga.OriginalVesting.IsZero() { 32 | if sga.StartTime >= sga.EndTime { 33 | return errors.New("vesting start-time cannot be before end-time") 34 | } 35 | } 36 | 37 | if sga.ModuleName != "" { 38 | ma := authtypes.ModuleAccount{ 39 | BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions, 40 | } 41 | if err := ma.Validate(); err != nil { 42 | return err 43 | } 44 | } 45 | 46 | return sga.BaseAccount.Validate() 47 | } 48 | -------------------------------------------------------------------------------- /app/test_helpers.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | bam "github.com/cosmos/cosmos-sdk/baseapp" 7 | servertypes "github.com/cosmos/cosmos-sdk/server/types" 8 | "github.com/cosmos/cosmos-sdk/simapp" 9 | storetypes "github.com/cosmos/cosmos-sdk/store/types" 10 | "github.com/cosmos/cosmos-sdk/testutil/network" 11 | abci "github.com/tendermint/tendermint/abci/types" 12 | "github.com/tendermint/tendermint/libs/log" 13 | dbm "github.com/tendermint/tm-db" 14 | ) 15 | 16 | func setup(withGenesis bool, invCheckPeriod uint) (*TeritoriApp, GenesisState) { 17 | db := dbm.NewMemDB() 18 | encCdc := MakeEncodingConfig() 19 | app := NewTeritoriApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, simapp.EmptyAppOptions{}) 20 | if withGenesis { 21 | return app, NewDefaultGenesisState() 22 | } 23 | return app, GenesisState{} 24 | } 25 | 26 | // Setup initializes a new SimApp. A Nop logger is set in SimApp. 27 | func Setup(isCheckTx bool) *TeritoriApp { 28 | app, genesisState := setup(!isCheckTx, 5) 29 | if !isCheckTx { 30 | // init chain must be called to stop deliverState from being nil 31 | stateBytes, err := json.MarshalIndent(genesisState, "", " ") 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | // Initialize the chain 37 | app.InitChain( 38 | abci.RequestInitChain{ 39 | Validators: []abci.ValidatorUpdate{}, 40 | ConsensusParams: simapp.DefaultConsensusParams, 41 | AppStateBytes: stateBytes, 42 | }, 43 | ) 44 | } 45 | 46 | return app 47 | } 48 | 49 | func SimAppConstructor(val network.Validator) servertypes.Application { 50 | return NewTeritoriApp( 51 | val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), 52 | val.Ctx.Config.RootDir, 0, MakeEncodingConfig(), simapp.EmptyAppOptions{}, 53 | bam.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), 54 | bam.SetMinGasPrices(val.AppConfig.MinGasPrices), 55 | ) 56 | } 57 | 58 | func NewConfig() network.Config { 59 | cfg := network.DefaultConfig() 60 | encCfg := MakeEncodingConfig() 61 | cfg.Codec = encCfg.Marshaler 62 | cfg.TxConfig = encCfg.TxConfig 63 | cfg.LegacyAmino = encCfg.Amino 64 | cfg.InterfaceRegistry = encCfg.InterfaceRegistry 65 | cfg.AppConstructor = SimAppConstructor 66 | cfg.GenesisState = NewDefaultGenesisState() 67 | return cfg 68 | } 69 | -------------------------------------------------------------------------------- /x/airdrop/types/msgs.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | ) 6 | 7 | var _ sdk.Msg = &MsgClaimAllocation{} 8 | 9 | var MsgTypeClaimAllocation = "claim_allocation" 10 | 11 | func NewMsgClaimAllocation( 12 | address string, 13 | rewardAddress sdk.AccAddress, 14 | signature string, 15 | ) *MsgClaimAllocation { 16 | return &MsgClaimAllocation{ 17 | Address: address, 18 | RewardAddress: rewardAddress.String(), 19 | Signature: signature, 20 | } 21 | } 22 | 23 | func (m *MsgClaimAllocation) Route() string { 24 | return ModuleName 25 | } 26 | 27 | func (m *MsgClaimAllocation) Type() string { 28 | return MsgTypeClaimAllocation 29 | } 30 | 31 | func (m *MsgClaimAllocation) ValidateBasic() error { 32 | if m.RewardAddress == "" { 33 | return ErrEmptyRewardAddress 34 | } 35 | 36 | if m.Address == "" { 37 | return ErrEmptyOnChainAllocationAddress 38 | } 39 | 40 | return nil 41 | } 42 | 43 | func (m *MsgClaimAllocation) GetSignBytes() []byte { 44 | bz := ModuleCdc.MustMarshalJSON(m) 45 | return sdk.MustSortJSON(bz) 46 | } 47 | 48 | func (m *MsgClaimAllocation) GetSigners() []sdk.AccAddress { 49 | rewardAddr, err := sdk.AccAddressFromBech32(m.RewardAddress) 50 | if err != nil { 51 | panic(err) 52 | } 53 | return []sdk.AccAddress{ 54 | rewardAddr, 55 | } 56 | } 57 | 58 | var _ sdk.Msg = &MsgSetAllocation{} 59 | 60 | var MsgTypeSetAllocation = "set_allocation" 61 | 62 | func NewMsgSetAllocation( 63 | sender string, 64 | allocation AirdropAllocation, 65 | ) *MsgSetAllocation { 66 | return &MsgSetAllocation{ 67 | Sender: sender, 68 | Allocation: allocation, 69 | } 70 | } 71 | 72 | func (m *MsgSetAllocation) Route() string { 73 | return ModuleName 74 | } 75 | 76 | func (m *MsgSetAllocation) Type() string { 77 | return MsgTypeSetAllocation 78 | } 79 | 80 | func (m *MsgSetAllocation) ValidateBasic() error { 81 | if m.Sender == "" { 82 | return ErrEmptyAddress 83 | } 84 | 85 | return nil 86 | } 87 | 88 | func (m *MsgSetAllocation) GetSignBytes() []byte { 89 | bz := ModuleCdc.MustMarshalJSON(m) 90 | return sdk.MustSortJSON(bz) 91 | } 92 | 93 | func (m *MsgSetAllocation) GetSigners() []sdk.AccAddress { 94 | addr, err := sdk.AccAddressFromBech32(m.Sender) 95 | if err != nil { 96 | panic(err) 97 | } 98 | return []sdk.AccAddress{ 99 | addr, 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /scripts/examples/airdrop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # query allocation for XXX address 4 | teritorid query airdrop allocation XXX --home=/Users/admin/.teritorid 5 | 6 | # set allocation for XXX address 7 | teritorid tx airdrop set-allocation evm 0x583e8DD54b7C3F5Ea23862E0E852f0e6914475D5 10000000utori 0utori --from=validator --keyring-backend=test --home=$HOME/.teritorid --chain-id=testing --broadcast-mode=block --yes 8 | 9 | # claim allocation for XXX address 10 | teritorid tx airdrop claim-allocation XXX "" --from=validator --keyring-backend=test --home=$HOME/.teritorid --chain-id=testing --broadcast-mode=block 11 | 12 | teritorid tx airdrop set-allocation evm 0x441D470F996D049B698A442e6DDb9dC3cb78AB68 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 13 | teritorid tx airdrop set-allocation solana BW5D1Dv7pydTYZ8rSByEqNXYVRnGpm4qcEhkfHEGqBM 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 14 | teritorid tx airdrop set-allocation terra BW5D1Dv7pydTYZ8rSByEqNXYVRnGpm4qcEhkfHEGqBM 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 15 | teritorid tx airdrop set-allocation cosmos cosmos19ftk3lkfupgtnh38d7enc8c6jp7aljj3s0p6gt 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 16 | teritorid tx airdrop set-allocation osmosis osmo19ftk3lkfupgtnh38d7enc8c6jp7aljj3c5j27e 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 17 | teritorid tx airdrop set-allocation juno juno19ftk3lkfupgtnh38d7enc8c6jp7aljj3xazp0h 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 18 | 19 | teritorid tx bank send node0 pop19ftk3lkfupgtnh38d7enc8c6jp7aljj3qspa84 1stake --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 20 | teritorid tx bank send node0 pop1hwf62gw7h39xmd69st3p487r8x3sphm29dftfh 1stake --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 21 | 22 | teritorid keys add node0 --keyring-backend=test --home=nodehome 23 | teritorid tx airdrop set-allocation evm 0x0bEE910D7CFD039DD24178E2CE8C781f749A4791 100000000utori 0utori --from=node0 --keyring-backend=test --home=nodehome --chain-id=chain-JskdwJ --broadcast-mode=block --yes 24 | -------------------------------------------------------------------------------- /x/nftstaking/client/cli/tx.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 7 | "github.com/cosmos/cosmos-sdk/client" 8 | "github.com/cosmos/cosmos-sdk/client/flags" 9 | "github.com/cosmos/cosmos-sdk/client/tx" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | const ( 14 | FlagNftIdentifier = "nft-identifier" 15 | FlagNftMetadata = "nft-metadata" 16 | FlagRewardAddress = "reward-address" 17 | FlagRewardWeight = "reward-weight" 18 | ) 19 | 20 | // NewTxCmd returns a root CLI command handler for all x/bank transaction commands. 21 | func NewTxCmd() *cobra.Command { 22 | txCmd := &cobra.Command{ 23 | Use: types.ModuleName, 24 | Short: "nftstaking sub commands", 25 | DisableFlagParsing: true, 26 | SuggestionsMinimumDistance: 2, 27 | RunE: client.ValidateCmd, 28 | } 29 | 30 | txCmd.AddCommand( 31 | GetTxRegisterNftStakingCmd(), 32 | ) 33 | 34 | return txCmd 35 | } 36 | 37 | func GetTxRegisterNftStakingCmd() *cobra.Command { 38 | cmd := &cobra.Command{ 39 | Use: "register-nft-staking [flags]", 40 | Short: "Register a nft staking with nft identifier and reward address", 41 | RunE: func(cmd *cobra.Command, args []string) error { 42 | clientCtx, err := client.GetClientTxContext(cmd) 43 | 44 | nftIdentifier, err := cmd.Flags().GetString(FlagNftIdentifier) 45 | if err != nil { 46 | return fmt.Errorf("invalid nft identifier: %w", err) 47 | } 48 | 49 | nftMetadata, err := cmd.Flags().GetString(FlagNftMetadata) 50 | if err != nil { 51 | return fmt.Errorf("invalid nft metadata: %w", err) 52 | } 53 | 54 | rewardAddr, err := cmd.Flags().GetString(FlagRewardAddress) 55 | if err != nil { 56 | return fmt.Errorf("invalid reward address: %w", err) 57 | } 58 | 59 | rewardWeight, err := cmd.Flags().GetUint64(FlagRewardWeight) 60 | if err != nil { 61 | return fmt.Errorf("invalid reward address: %w", err) 62 | } 63 | 64 | msg := types.NewMsgRegisterNftStaking(clientCtx.FromAddress.String(), types.NftStaking{ 65 | NftIdentifier: nftIdentifier, 66 | NftMetadata: nftMetadata, 67 | RewardAddress: rewardAddr, 68 | RewardWeight: rewardWeight, 69 | }) 70 | if err != nil { 71 | return err 72 | } 73 | 74 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) 75 | }, 76 | } 77 | 78 | cmd.Flags().String(FlagNftIdentifier, "", "nft identifier.") 79 | cmd.Flags().String(FlagNftMetadata, "", "nft metadata.") 80 | cmd.Flags().String(FlagRewardAddress, "", "Reward address to receive staking rewards.") 81 | cmd.Flags().Uint64(FlagRewardWeight, 0, "Reward weight for the nft") 82 | 83 | flags.AddTxFlagsToCmd(cmd) 84 | _ = cmd.MarkFlagRequired(flags.FlagFrom) 85 | 86 | return cmd 87 | } 88 | -------------------------------------------------------------------------------- /CW20.md: -------------------------------------------------------------------------------- 1 | This steps are based on https://docs.junonetwork.io/smart-contracts-and-junod-development/tutorial-erc-20 2 | 3 | 1. Compile wasm 4 | 5 | Clone erc20 contract in RUST and compile it. The result is `.wasm` file. 6 | Take an example of erc20 contract from here - https://github.com/InterWasm/cw-contracts/tree/main/contracts/erc20 7 | 8 | 2. Upload wasm 9 | 10 | Upload compile wasm contract to the chain. 11 | 12 | ``` 13 | teritorid tx wasm store cw_erc20.wasm --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ -y 14 | ``` 15 | 16 | This command will return a code number which starts from `1`. 17 | 18 | 3. instantiate 19 | 20 | Create a contract from uploaded wasm. This will use the code number generated at upload step. 21 | 22 | ``` 23 | teritorid tx wasm instantiate 1 'instantiate message' --amount 50000utori --label "teritori erc20" --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ --no-admin -y 24 | 25 | teritorid tx wasm instantiate 1 '{"name":"Nxtpop Coin","symbol":"NPOP","decimals":6,"initial_balances":[{"address":"pop1...","amount":"12345678000"}]}' --amount 50000utori --label "teritori erc20" --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ --no-admin -y 26 | ``` 27 | 28 | This command will return a contract address. 29 | 30 | 4. query contract 31 | 32 | Query contract info by address. Use above generated contract address to check contract info. 33 | 34 | ``` 35 | teritorid query wasm contract "contract address" 36 | 37 | teritorid query wasm contract pop1..... 38 | ``` 39 | 40 | 5. query balance 41 | 42 | Query balance of an address. At first, try to check the address with initial balances. 43 | 44 | ``` 45 | teritorid query wasm contract-state smart "contract address" '{"balance":{"address":"user address"}}' 46 | 47 | teritorid query wasm contract-state smart pop1... '{"balance":{"address":"pop1..."}}' 48 | ``` 49 | 50 | 6. transfer cw20 token 51 | 52 | Transfer cw20 token to an address. 53 | 54 | ``` 55 | teritorid tx wasm execute "contract address" 'transfer message' --from initial --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ -y 56 | 57 | teritorid tx wasm execute "contract address" '{"transfer":{"amount":"amount","owner":"from address","recipient":"receiver address"}}' --from initial --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ -y 58 | 59 | teritorid tx wasm execute pop1... '{"transfer":{"amount":"200","owner":"pop1...","recipient":"pop1..."}}' --from initial --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ -y 60 | ``` 61 | 62 | Try to test balance changes after transfer using `teritorid query wasm contract-state smart` command in step `5`. 63 | -------------------------------------------------------------------------------- /x/airdrop/client/cli/tx.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 7 | "github.com/cosmos/cosmos-sdk/client" 8 | "github.com/cosmos/cosmos-sdk/client/flags" 9 | "github.com/cosmos/cosmos-sdk/client/tx" 10 | sdk "github.com/cosmos/cosmos-sdk/types" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | // GetTxCmd returns the transaction commands for this module 15 | func GetTxCmd() *cobra.Command { 16 | txCmd := &cobra.Command{ 17 | Use: types.ModuleName, 18 | Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), 19 | DisableFlagParsing: true, 20 | SuggestionsMinimumDistance: 2, 21 | RunE: client.ValidateCmd, 22 | } 23 | 24 | txCmd.AddCommand( 25 | GetTxClaimAllocationCmd(), 26 | GetTxSetAllocationCmd(), 27 | ) 28 | 29 | return txCmd 30 | } 31 | 32 | // GetTxClaimAllocationCmd implement cli command for MsgClaimAllocation 33 | func GetTxClaimAllocationCmd() *cobra.Command { 34 | cmd := &cobra.Command{ 35 | Use: "claim-allocation [native_chain_address] [signature]", 36 | Short: "Claim reward allocation", 37 | Args: cobra.ExactArgs(2), 38 | RunE: func(cmd *cobra.Command, args []string) error { 39 | clientCtx, err := client.GetClientTxContext(cmd) 40 | 41 | msg := types.NewMsgClaimAllocation( 42 | args[0], 43 | clientCtx.FromAddress, 44 | args[1], 45 | ) 46 | 47 | err = msg.ValidateBasic() 48 | if err != nil { 49 | return err 50 | } 51 | 52 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) 53 | }, 54 | } 55 | 56 | flags.AddTxFlagsToCmd(cmd) 57 | _ = cmd.MarkFlagRequired(flags.FlagFrom) 58 | 59 | return cmd 60 | } 61 | 62 | // GetTxSetAllocationCmd implement cli command for MsgSetAllocation 63 | func GetTxSetAllocationCmd() *cobra.Command { 64 | cmd := &cobra.Command{ 65 | Use: "set-allocation [chain] [native_chain_address] [amount] [claimed_amount]", 66 | Short: "Set allocation", 67 | Args: cobra.ExactArgs(4), 68 | RunE: func(cmd *cobra.Command, args []string) error { 69 | clientCtx, err := client.GetClientTxContext(cmd) 70 | 71 | amount, err := sdk.ParseCoinNormalized(args[2]) 72 | if err != nil { 73 | return err 74 | } 75 | 76 | claimedAmount, err := sdk.ParseCoinNormalized(args[3]) 77 | if err != nil { 78 | return err 79 | } 80 | 81 | msg := types.NewMsgSetAllocation( 82 | clientCtx.FromAddress.String(), 83 | types.AirdropAllocation{ 84 | Chain: args[0], 85 | Address: args[1], 86 | Amount: amount, 87 | ClaimedAmount: claimedAmount, 88 | }, 89 | ) 90 | 91 | err = msg.ValidateBasic() 92 | if err != nil { 93 | return err 94 | } 95 | 96 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) 97 | }, 98 | } 99 | 100 | flags.AddTxFlagsToCmd(cmd) 101 | _ = cmd.MarkFlagRequired(flags.FlagFrom) 102 | 103 | return cmd 104 | } 105 | -------------------------------------------------------------------------------- /x/airdrop/keeper/signature.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "encoding/hex" 5 | "encoding/json" 6 | 7 | appparams "github.com/NXTPOP/teritori-chain/app/params" 8 | "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" 9 | "github.com/cosmos/cosmos-sdk/types/bech32" 10 | "github.com/ethereum/go-ethereum/accounts" 11 | "github.com/ethereum/go-ethereum/common/hexutil" 12 | "github.com/ethereum/go-ethereum/crypto" 13 | solana "github.com/gagliardetto/solana-go" 14 | ) 15 | 16 | type SignMessage struct { 17 | Chain string `json:"chain"` 18 | Address string `json:"address"` 19 | RewardAddr string `json:"rewardAddr"` 20 | } 21 | 22 | func VerifySignature(chain string, address string, pubKey string, rewardAddr string, signatureBytes string) bool { 23 | signMsg := SignMessage{ 24 | Chain: chain, 25 | Address: address, 26 | RewardAddr: rewardAddr, 27 | } 28 | signBytes, err := json.Marshal(signMsg) 29 | 30 | if err != nil { 31 | return false 32 | } 33 | 34 | switch chain { 35 | case "solana": 36 | pubkey := solana.MustPublicKeyFromBase58(address) 37 | signatureData, err := hex.DecodeString(signatureBytes[2:]) 38 | if err != nil { 39 | return false 40 | } 41 | signature := solana.SignatureFromBytes(signatureData) 42 | return signature.Verify(pubkey, signBytes) 43 | case "evm": 44 | signatureData := hexutil.MustDecode(signatureBytes) 45 | signatureData[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1 46 | recovered, err := crypto.SigToPub(accounts.TextHash(signBytes), signatureData) 47 | if err != nil { 48 | return false 49 | } 50 | recoveredAddr := crypto.PubkeyToAddress(*recovered) 51 | return recoveredAddr.String() == address 52 | case "terra": 53 | pubKeyBytes := hexutil.MustDecode(pubKey) 54 | secp256k1PubKey := secp256k1.PubKey{Key: pubKeyBytes} 55 | terraAddr, err := bech32.ConvertAndEncode("terra", secp256k1PubKey.Address()) 56 | if err != nil { 57 | return false 58 | } 59 | if terraAddr != address { 60 | return false 61 | } 62 | 63 | signatureData := hexutil.MustDecode(signatureBytes) 64 | return secp256k1PubKey.VerifySignature(signBytes, signatureData) 65 | case "osmosis": 66 | _, bz, err := bech32.DecodeAndConvert(address) 67 | if err != nil { 68 | return false 69 | } 70 | 71 | bech32Addr, err := bech32.ConvertAndEncode(appparams.Bech32PrefixAccAddr, bz) 72 | if err != nil { 73 | return false 74 | } 75 | 76 | return bech32Addr == rewardAddr 77 | case "juno": 78 | _, bz, err := bech32.DecodeAndConvert(address) 79 | if err != nil { 80 | return false 81 | } 82 | 83 | bech32Addr, err := bech32.ConvertAndEncode(appparams.Bech32PrefixAccAddr, bz) 84 | if err != nil { 85 | return false 86 | } 87 | 88 | return bech32Addr == rewardAddr 89 | case "cosmos": 90 | _, bz, err := bech32.DecodeAndConvert(address) 91 | if err != nil { 92 | return false 93 | } 94 | 95 | bech32Addr, err := bech32.ConvertAndEncode(appparams.Bech32PrefixAccAddr, bz) 96 | if err != nil { 97 | return false 98 | } 99 | 100 | return bech32Addr == rewardAddr 101 | default: // unsupported chain 102 | return false 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /sims.mk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | ######################################## 4 | ### Simulations 5 | 6 | BINDIR ?= $(GOPATH)/bin 7 | SIMAPP = ./app 8 | test-sim-nondeterminism: 9 | @echo "Running non-determinism test..." 10 | @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ 11 | -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h 12 | 13 | test-sim-custom-genesis-fast: 14 | @echo "Running custom genesis simulation..." 15 | @echo "By default, ${HOME}/.teritori/config/genesis.json will be used." 16 | @go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.teritori/config/genesis.json \ 17 | -Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h 18 | 19 | test-sim-import-export: runsim 20 | @echo "Running application import/export simulation. This may take several minutes..." 21 | @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppImportExport 22 | 23 | test-sim-after-import: runsim 24 | @echo "Running application simulation-after-import. This may take several minutes..." 25 | @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppSimulationAfterImport 26 | 27 | test-sim-custom-genesis-multi-seed: runsim 28 | @echo "Running multi-seed custom genesis simulation..." 29 | @echo "By default, ${HOME}/.teritori/config/genesis.json will be used." 30 | @$(BINDIR)/runsim -Genesis=${HOME}/.teritori/config/genesis.json -SimAppPkg=$(SIMAPP) -ExitOnFail 400 5 TestFullAppSimulation 31 | 32 | test-sim-multi-seed-long: runsim 33 | @echo "Running long multi-seed application simulation. This may take awhile!" 34 | @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestFullAppSimulation 35 | 36 | test-sim-multi-seed-short: runsim 37 | @echo "Running short multi-seed application simulation. This may take awhile!" 38 | @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation 39 | 40 | test-sim-benchmark-invariants: 41 | @echo "Running simulation invariant benchmarks..." 42 | @go test -mod=readonly $(SIMAPP) -benchmem -bench=BenchmarkInvariants -run=^$ \ 43 | -Enabled=true -NumBlocks=1000 -BlockSize=200 \ 44 | -Period=1 -Commit=true -Seed=57 -v -timeout 24h 45 | 46 | .PHONY: \ 47 | test-sim-nondeterminism \ 48 | test-sim-custom-genesis-fast \ 49 | test-sim-import-export \ 50 | test-sim-after-import \ 51 | test-sim-custom-genesis-multi-seed \ 52 | test-sim-multi-seed-short \ 53 | test-sim-multi-seed-long \ 54 | test-sim-benchmark-invariants 55 | 56 | SIM_NUM_BLOCKS ?= 500 57 | SIM_BLOCK_SIZE ?= 200 58 | SIM_COMMIT ?= true 59 | 60 | test-sim-benchmark: 61 | @echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!" 62 | @go test -mod=readonly -benchmem -run=^$$ $(SIMAPP) -bench ^BenchmarkFullAppSimulation$$ \ 63 | -Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h 64 | 65 | test-sim-profile: 66 | @echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!" 67 | @go test -mod=readonly -benchmem -run=^$$ $(SIMAPP) -bench ^BenchmarkFullAppSimulation$$ \ 68 | -Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out 69 | 70 | .PHONY: test-sim-profile test-sim-benchmark -------------------------------------------------------------------------------- /x/airdrop/keeper/allocation.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 5 | "github.com/cosmos/cosmos-sdk/store/prefix" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | ) 8 | 9 | func (k Keeper) GetAllocation(ctx sdk.Context, address string) *types.AirdropAllocation { 10 | allocation := types.AirdropAllocation{} 11 | 12 | prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAirdropAllocation) 13 | bz := prefixStore.Get([]byte(address)) 14 | if bz == nil { 15 | return nil 16 | } 17 | k.cdc.MustUnmarshal(bz, &allocation) 18 | return &allocation 19 | } 20 | 21 | func (k Keeper) GetAllAllocations(ctx sdk.Context) []types.AirdropAllocation { 22 | allocations := []types.AirdropAllocation{} 23 | store := ctx.KVStore(k.storeKey) 24 | iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixAirdropAllocation) 25 | defer iterator.Close() 26 | 27 | for ; iterator.Valid(); iterator.Next() { 28 | allocation := types.AirdropAllocation{} 29 | k.cdc.MustUnmarshal(iterator.Value(), &allocation) 30 | allocations = append(allocations, allocation) 31 | } 32 | 33 | return allocations 34 | } 35 | 36 | func (k Keeper) SetAllocation(ctx sdk.Context, allocation types.AirdropAllocation) { 37 | prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAirdropAllocation) 38 | bz := k.cdc.MustMarshal(&allocation) 39 | prefixStore.Set([]byte(allocation.Address), bz) 40 | } 41 | 42 | func (k Keeper) DeleteAllocation(ctx sdk.Context, address string) { 43 | prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAirdropAllocation) 44 | prefixStore.Delete([]byte(address)) 45 | } 46 | 47 | func (k Keeper) ClaimAllocation(ctx sdk.Context, address string, pubKey string, rewardAddress string, signature string) error { 48 | // ensure allocation exists for the address 49 | allocation := k.GetAllocation(ctx, address) 50 | if allocation == nil { 51 | return types.ErrAirdropAllocationDoesNotExists 52 | } 53 | 54 | // ensure allocation is not claimed already 55 | unclaimed := allocation.Amount.Sub(allocation.ClaimedAmount) 56 | if unclaimed.IsZero() { 57 | return types.ErrAirdropAllocationAlreadyClaimed 58 | } 59 | 60 | // verify native chain account with signature 61 | sigOk := VerifySignature(allocation.Chain, allocation.Address, pubKey, rewardAddress, signature) 62 | if !sigOk { 63 | return types.ErrNativeChainAccountSigVerificationFailure 64 | } 65 | 66 | // send coins from airdrop module account to beneficiary address 67 | sdkAddr, err := sdk.AccAddressFromBech32(rewardAddress) 68 | if err != nil { 69 | return err 70 | } 71 | 72 | err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.Coins{unclaimed}) 73 | if err != nil { 74 | return err 75 | } 76 | err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sdkAddr, sdk.Coins{unclaimed}) 77 | if err != nil { 78 | return err 79 | } 80 | 81 | // update claimed amount and set the record on-chain 82 | allocation.ClaimedAmount = allocation.Amount 83 | k.SetAllocation(ctx, *allocation) 84 | 85 | ctx.EventManager().EmitEvent( 86 | sdk.NewEvent( 87 | types.EventTypeClaimAllocation, 88 | sdk.NewAttribute(types.AttributeKeyAddress, address), 89 | sdk.NewAttribute(types.AttributeKeyAmount, unclaimed.String()), 90 | sdk.NewAttribute(types.AttributeKeyRewardAddress, rewardAddress), 91 | ), 92 | ) 93 | 94 | return nil 95 | } 96 | -------------------------------------------------------------------------------- /testnet/teritori-testnet-v1/README.md: -------------------------------------------------------------------------------- 1 | # [DEPRECIATED] 2 | 3 | ## Setup your machine 4 | 5 | If you already have go 1.18+ and packages up to date, you can skip this part and jump to the second section: [Setup the chain](https://github.com/TERITORI/teritori-chain/edit/main/testnet/testnet-teritori-v1/README.md#setup-the-chain) 6 | Make sure your machine is up to date: 7 | ```shell 8 | apt update && apt upgrade -y 9 | ``` 10 | 11 | Install few packages: 12 | ```shell 13 | apt install build-essential git curl gcc make jq -y 14 | ``` 15 | 16 | Install Go 1.18+: 17 | ```shell 18 | wget -c https://go.dev/dl/go1.18.3.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz && rm -rf go1.18.3.linux-amd64.tar.gz 19 | ``` 20 | 21 | Setup your environnement (you can skip this part if you already had go installed before): 22 | ```shell 23 | echo 'export GOROOT=/usr/local/go' >> $HOME/.bash_profile 24 | echo 'export GOPATH=$HOME/go' >> $HOME/.bash_profile 25 | echo 'export GO111MODULE=on' >> $HOME/.bash_profile 26 | echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile && . $HOME/.bash_profile 27 | ``` 28 | 29 | Verify the installation: 30 | ```shell 31 | go version 32 | #Should return go version go1.18.3 linux/amd64 33 | ``` 34 | 35 | ## Setup the chain 36 | 37 | Clone the Teritori repository and install the v1 of testnet: 38 | ```shell 39 | git clone https://github.com/TERITORI/teritori-chain && cd teritori-chain && git checkout teritori-testnet-v1 && make install 40 | ``` 41 | 42 | Verify the installation: 43 | ```shell 44 | teritorid version 45 | #Should return teritori-testnet-v1-9f1943df9cff63ca5e4ec10d0e31521e13c2fc13 46 | ``` 47 | 48 | Init the chain: 49 | ```shell 50 | teritorid init --chain-id teritori-testnet-v1 51 | ``` 52 | 53 | Add peers in the config file: 54 | ```shell 55 | sed -i.bak 's/persistent_peers =.*/persistent_peers = "0dde2ae55624d822eeea57d1b5e1223b6019a531@176.9.149.15:26656,4d2ea61e6195ee4e449c1e6132cabce98f7d94e1@5.9.40.222:26656,bceb776975aab62bcfd501969c0e1a2734ed7c2e@176.9.19.162:26656"/' $HOME/.teritorid/config/config.toml 56 | ``` 57 | 58 | Download the genesis file: 59 | ```shell 60 | wget -O ~/.teritorid/config/genesis.json https://raw.githubusercontent.com/TERITORI/teritori-chain/main/testnet/teritori-testnet-v1/genesis.json 61 | ``` 62 | 63 | Launch the node: 64 | ```shell 65 | teritorid start 66 | ``` 67 | 68 | Wait for the chain to synchronize with the current block... 69 | 70 | ## Setup your account 71 | 72 | Create an account: 73 | ```shell 74 | teritorid keys add 75 | ``` 76 | 77 | You can also you `--recover` flag to use an already existed key (but we recommend for security reason to use one key per chain to avoid total loss of funds in case one key is missing) 78 | 79 | Join our [Discord](https://discord.gg/teritori) and request fund on the `Faucet` channel using this command: 80 | ```shell 81 | $request 82 | ``` 83 | 84 | You can check if you have received fund once your node will be synched using this CLI command: 85 | ```shell 86 | teritorid query bank balances --chain-id teritori-testnet-v1 87 | ``` 88 | 89 | Once the fund are received, you can create your validator: 90 | ```shell 91 | teritorid tx staking create-validator \ 92 | --commission-max-change-rate=0.01 \ 93 | --commission-max-rate=0.2 \ 94 | --commission-rate=0.05 \ 95 | --amount 10000stake \ 96 | --pubkey=$(teritorid tendermint show-validator) \ 97 | --moniker= \ 98 | --chain-id=teritori-testnet-v1 \ 99 | --details="" \ 100 | --security-contact=" 105 | ``` -------------------------------------------------------------------------------- /app/sim_test.go: -------------------------------------------------------------------------------- 1 | package teritori_test 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os" 7 | "testing" 8 | 9 | teritori "github.com/NXTPOP/teritori-chain/app" 10 | 11 | "github.com/NXTPOP/teritori-chain/app/helpers" 12 | "github.com/stretchr/testify/require" 13 | "github.com/tendermint/tendermint/libs/log" 14 | "github.com/tendermint/tendermint/libs/rand" 15 | dbm "github.com/tendermint/tm-db" 16 | 17 | "github.com/cosmos/cosmos-sdk/baseapp" 18 | "github.com/cosmos/cosmos-sdk/simapp" 19 | "github.com/cosmos/cosmos-sdk/store" 20 | simulation2 "github.com/cosmos/cosmos-sdk/types/simulation" 21 | "github.com/cosmos/cosmos-sdk/x/simulation" 22 | ) 23 | 24 | func init() { 25 | simapp.GetSimulatorFlags() 26 | } 27 | 28 | // Profile with: 29 | // /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/TeritoriApp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out 30 | func BenchmarkFullAppSimulation(b *testing.B) { 31 | config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation") 32 | if err != nil { 33 | b.Fatalf("simulation setup failed: %s", err.Error()) 34 | } 35 | 36 | defer func() { 37 | db.Close() 38 | err = os.RemoveAll(dir) 39 | if err != nil { 40 | b.Fatal(err) 41 | } 42 | }() 43 | 44 | app := teritori.NewTeritoriApp(logger, db, nil, true, map[int64]bool{}, teritori.DefaultNodeHome, simapp.FlagPeriodValue, teritori.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt()) 45 | 46 | // Run randomized simulation:w 47 | _, simParams, simErr := simulation.SimulateFromSeed( 48 | b, 49 | os.Stdout, 50 | app.BaseApp, 51 | simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), 52 | simulation2.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 53 | simapp.SimulationOperations(app, app.AppCodec(), config), 54 | app.ModuleAccountAddrs(), 55 | config, 56 | app.AppCodec(), 57 | ) 58 | 59 | // export state and simParams before the simulation error is checked 60 | if err = simapp.CheckExportSimulation(app, config, simParams); err != nil { 61 | b.Fatal(err) 62 | } 63 | 64 | if simErr != nil { 65 | b.Fatal(simErr) 66 | } 67 | 68 | if config.Commit { 69 | simapp.PrintStats(db) 70 | } 71 | } 72 | 73 | // interBlockCacheOpt returns a BaseApp option function that sets the persistent 74 | // inter-block write-through cache. 75 | func interBlockCacheOpt() func(*baseapp.BaseApp) { 76 | return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager()) 77 | } 78 | 79 | //// TODO: Make another test for the fuzzer itself, which just has noOp txs 80 | //// and doesn't depend on the application. 81 | func TestAppStateDeterminism(t *testing.T) { 82 | if !simapp.FlagEnabledValue { 83 | t.Skip("skipping application simulation") 84 | } 85 | 86 | config := simapp.NewConfigFromFlags() 87 | config.InitialBlockHeight = 1 88 | config.ExportParamsPath = "" 89 | config.OnOperation = false 90 | config.AllInvariants = false 91 | config.ChainID = helpers.SimAppChainID 92 | 93 | numSeeds := 3 94 | numTimesToRunPerSeed := 5 95 | appHashList := make([]json.RawMessage, numTimesToRunPerSeed) 96 | 97 | for i := 0; i < numSeeds; i++ { 98 | config.Seed = rand.Int63() 99 | 100 | for j := 0; j < numTimesToRunPerSeed; j++ { 101 | var logger log.Logger 102 | if simapp.FlagVerboseValue { 103 | logger = log.TestingLogger() 104 | } else { 105 | logger = log.NewNopLogger() 106 | } 107 | 108 | db := dbm.NewMemDB() 109 | app := teritori.NewTeritoriApp(logger, db, nil, true, map[int64]bool{}, teritori.DefaultNodeHome, simapp.FlagPeriodValue, teritori.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt()) 110 | 111 | fmt.Printf( 112 | "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", 113 | config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, 114 | ) 115 | 116 | _, _, err := simulation.SimulateFromSeed( 117 | t, 118 | os.Stdout, 119 | app.BaseApp, 120 | simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), 121 | simulation2.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 122 | simapp.SimulationOperations(app, app.AppCodec(), config), 123 | app.ModuleAccountAddrs(), 124 | config, 125 | app.AppCodec(), 126 | ) 127 | require.NoError(t, err) 128 | 129 | if config.Commit { 130 | simapp.PrintStats(db) 131 | } 132 | 133 | appHash := app.LastCommitID().Hash 134 | appHashList[j] = appHash 135 | 136 | if j != 0 { 137 | require.Equal( 138 | t, string(appHashList[0]), string(appHashList[j]), 139 | "non-determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, 140 | ) 141 | } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /app/ante_handler.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | sdk "github.com/cosmos/cosmos-sdk/types" 6 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 7 | "github.com/cosmos/cosmos-sdk/x/auth/ante" 8 | "github.com/cosmos/cosmos-sdk/x/authz" 9 | ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante" 10 | ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" 11 | 12 | wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" 13 | wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" 14 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" 15 | ) 16 | 17 | // HandlerOptions extends the SDK's AnteHandler options by requiring the IBC 18 | // channel keeper. 19 | type HandlerOptions struct { 20 | ante.HandlerOptions 21 | 22 | IBCKeeper *ibckeeper.Keeper 23 | TxCounterStoreKey sdk.StoreKey 24 | WasmConfig wasmTypes.WasmConfig 25 | Cdc codec.BinaryCodec 26 | } 27 | 28 | type MinCommissionDecorator struct { 29 | cdc codec.BinaryCodec 30 | } 31 | 32 | func NewMinCommissionDecorator(cdc codec.BinaryCodec) MinCommissionDecorator { 33 | return MinCommissionDecorator{cdc} 34 | } 35 | 36 | func (min MinCommissionDecorator) AnteHandle( 37 | ctx sdk.Context, tx sdk.Tx, 38 | simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { 39 | msgs := tx.GetMsgs() 40 | minCommissionRate := sdk.NewDecWithPrec(5, 2) 41 | 42 | validMsg := func(m sdk.Msg) error { 43 | switch msg := m.(type) { 44 | case *stakingtypes.MsgCreateValidator: 45 | // prevent new validators joining the set with 46 | // commission set below 5% 47 | c := msg.Commission 48 | if c.Rate.LT(minCommissionRate) { 49 | return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%") 50 | } 51 | case *stakingtypes.MsgEditValidator: 52 | // if commission rate is nil, it means only 53 | // other fields are affected - skip 54 | if msg.CommissionRate == nil { 55 | break 56 | } 57 | if msg.CommissionRate.LT(minCommissionRate) { 58 | return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%") 59 | } 60 | } 61 | 62 | return nil 63 | } 64 | 65 | validAuthz := func(execMsg *authz.MsgExec) error { 66 | for _, v := range execMsg.Msgs { 67 | var innerMsg sdk.Msg 68 | err := min.cdc.UnpackAny(v, &innerMsg) 69 | if err != nil { 70 | return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs") 71 | } 72 | 73 | err = validMsg(innerMsg) 74 | if err != nil { 75 | return err 76 | } 77 | } 78 | 79 | return nil 80 | } 81 | 82 | for _, m := range msgs { 83 | if msg, ok := m.(*authz.MsgExec); ok { 84 | if err := validAuthz(msg); err != nil { 85 | return ctx, err 86 | } 87 | continue 88 | } 89 | 90 | // validate normal msgs 91 | err = validMsg(m) 92 | if err != nil { 93 | return ctx, err 94 | } 95 | } 96 | 97 | return next(ctx, tx, simulate) 98 | } 99 | 100 | // NewAnteHandler returns an AnteHandler that checks and increments sequence 101 | // numbers, checks signatures & account numbers, and deducts fees from the first 102 | // signer. 103 | func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { 104 | if options.AccountKeeper == nil { 105 | return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") 106 | } 107 | 108 | if options.BankKeeper == nil { 109 | return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") 110 | } 111 | 112 | if options.SignModeHandler == nil { 113 | return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") 114 | } 115 | 116 | var sigGasConsumer = options.SigGasConsumer 117 | if sigGasConsumer == nil { 118 | sigGasConsumer = ante.DefaultSigVerificationGasConsumer 119 | } 120 | 121 | anteDecorators := []sdk.AnteDecorator{ 122 | ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first 123 | NewMinCommissionDecorator(options.Cdc), 124 | NewVestingTransactionDecorator(options.AccountKeeper), 125 | wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), 126 | wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), 127 | ante.NewRejectExtensionOptionsDecorator(), 128 | ante.NewMempoolFeeDecorator(), 129 | ante.NewValidateBasicDecorator(), 130 | ante.NewTxTimeoutHeightDecorator(), 131 | ante.NewValidateMemoDecorator(options.AccountKeeper), 132 | ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), 133 | ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), 134 | // SetPubKeyDecorator must be called before all signature verification decorators 135 | ante.NewSetPubKeyDecorator(options.AccountKeeper), 136 | ante.NewValidateSigCountDecorator(options.AccountKeeper), 137 | ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), 138 | ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), 139 | ante.NewIncrementSequenceDecorator(options.AccountKeeper), 140 | ibcante.NewAnteDecorator(options.IBCKeeper), 141 | } 142 | 143 | return sdk.ChainAnteDecorators(anteDecorators...), nil 144 | } 145 | -------------------------------------------------------------------------------- /x/nftstaking/module.go: -------------------------------------------------------------------------------- 1 | package nftstaking 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "math/rand" 7 | 8 | "github.com/grpc-ecosystem/grpc-gateway/runtime" 9 | 10 | "github.com/NXTPOP/teritori-chain/x/nftstaking/client/cli" 11 | "github.com/NXTPOP/teritori-chain/x/nftstaking/keeper" 12 | "github.com/NXTPOP/teritori-chain/x/nftstaking/types" 13 | 14 | "github.com/cosmos/cosmos-sdk/client" 15 | "github.com/cosmos/cosmos-sdk/codec" 16 | codectypes "github.com/cosmos/cosmos-sdk/codec/types" 17 | sdk "github.com/cosmos/cosmos-sdk/types" 18 | "github.com/cosmos/cosmos-sdk/types/module" 19 | simtypes "github.com/cosmos/cosmos-sdk/types/simulation" 20 | "github.com/cosmos/cosmos-sdk/x/gov/simulation" 21 | "github.com/gorilla/mux" 22 | "github.com/spf13/cobra" 23 | abci "github.com/tendermint/tendermint/abci/types" 24 | ) 25 | 26 | var ( 27 | _ module.AppModule = AppModule{} 28 | _ module.AppModuleBasic = AppModuleBasic{} 29 | ) 30 | 31 | type AppModuleBasic struct { 32 | cdc codec.Codec 33 | } 34 | 35 | func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { 36 | return AppModuleBasic{cdc: cdc} 37 | } 38 | 39 | // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the staking module. 40 | func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { 41 | } 42 | 43 | func (b AppModuleBasic) Name() string { 44 | return types.ModuleName 45 | } 46 | 47 | func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { 48 | types.RegisterInterfaces(registry) 49 | } 50 | 51 | func (b AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { 52 | return cdc.MustMarshalJSON(types.DefaultGenesis()) 53 | } 54 | 55 | func (b AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error { 56 | return nil 57 | } 58 | 59 | func (b AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, router *mux.Router) { 60 | } 61 | 62 | func (b AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, serveMux *runtime.ServeMux) { 63 | types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(clientCtx)) 64 | } 65 | 66 | func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { 67 | } 68 | 69 | func (b AppModuleBasic) GetTxCmd() *cobra.Command { 70 | return cli.NewTxCmd() 71 | } 72 | 73 | // GetQueryCmd implement query commands for this module 74 | func (b AppModuleBasic) GetQueryCmd() *cobra.Command { 75 | return cli.NewQueryCmd() 76 | } 77 | 78 | type AppModule struct { 79 | AppModuleBasic 80 | keeper keeper.Keeper 81 | } 82 | 83 | func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { 84 | return AppModule{ 85 | AppModuleBasic: NewAppModuleBasic(cdc), 86 | keeper: keeper, 87 | } 88 | } 89 | 90 | // RegisterQueryService registers a GRPC query service to respond to the 91 | // module-specific GRPC queries. 92 | func (am AppModule) RegisterServices(cfg module.Configurator) { 93 | types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) 94 | querier := keeper.NewQuerier(am.keeper) 95 | types.RegisterQueryServer(cfg.QueryServer(), querier) 96 | } 97 | 98 | func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { 99 | types.RegisterInterfaces(registry) 100 | } 101 | 102 | func (am AppModule) InitGenesis( 103 | ctx sdk.Context, 104 | cdc codec.JSONCodec, 105 | data json.RawMessage, 106 | ) []abci.ValidatorUpdate { 107 | var genesisState types.GenesisState 108 | cdc.MustUnmarshalJSON(data, &genesisState) 109 | 110 | for _, staking := range genesisState.NftStakings { 111 | am.keeper.SetNftStaking(ctx, staking) 112 | } 113 | 114 | return nil 115 | } 116 | 117 | func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { 118 | var genesisState types.GenesisState 119 | genesisState.NftStakings = am.keeper.GetAllNftStakings(ctx) 120 | return cdc.MustMarshalJSON(&genesisState) 121 | } 122 | 123 | // ConsensusVersion implements AppModule/ConsensusVersion. 124 | func (AppModule) ConsensusVersion() uint64 { return 1 } 125 | 126 | func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {} 127 | 128 | func (am AppModule) QuerierRoute() string { 129 | return types.QuerierRoute 130 | } 131 | 132 | // LegacyQuerierHandler returns the staking module sdk.Querier. 133 | func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { 134 | return nil 135 | } 136 | 137 | func (am AppModule) BeginBlock(clientCtx sdk.Context, block abci.RequestBeginBlock) {} 138 | 139 | func (am AppModule) EndBlock(ctx sdk.Context, block abci.RequestEndBlock) []abci.ValidatorUpdate { 140 | EndBlocker(ctx, am.keeper) 141 | 142 | return nil 143 | } 144 | 145 | func (am AppModule) Name() string { 146 | return types.ModuleName 147 | } 148 | 149 | // Route returns the message routing key for the staking module. 150 | func (am AppModule) Route() sdk.Route { 151 | return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) 152 | } 153 | 154 | // GenerateGenesisState creates a randomized GenState of the gov module. 155 | func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 156 | } 157 | 158 | // ProposalContents returns all the gov content functions used to 159 | // simulate governance proposals. 160 | func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { 161 | return nil 162 | } 163 | 164 | // RandomizedParams creates randomized gov param changes for the simulator. 165 | func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { 166 | return nil 167 | } 168 | 169 | // RegisterStoreDecoder registers a decoder for gov module's types 170 | func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 171 | sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) 172 | } 173 | 174 | // WeightedOperations returns the all the gov module operations with their respective weights. 175 | func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { 176 | return nil 177 | } 178 | -------------------------------------------------------------------------------- /x/nftstaking/types/query.pb.gw.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. 2 | // source: teritori/nftstaking/v1beta1/query.proto 3 | 4 | /* 5 | Package types is a reverse proxy. 6 | 7 | It translates gRPC into RESTful JSON APIs. 8 | */ 9 | package types 10 | 11 | import ( 12 | "context" 13 | "io" 14 | "net/http" 15 | 16 | "github.com/golang/protobuf/descriptor" 17 | "github.com/golang/protobuf/proto" 18 | "github.com/grpc-ecosystem/grpc-gateway/runtime" 19 | "github.com/grpc-ecosystem/grpc-gateway/utilities" 20 | "google.golang.org/grpc" 21 | "google.golang.org/grpc/codes" 22 | "google.golang.org/grpc/grpclog" 23 | "google.golang.org/grpc/status" 24 | ) 25 | 26 | // Suppress "imported and not used" errors 27 | var _ codes.Code 28 | var _ io.Reader 29 | var _ status.Status 30 | var _ = runtime.String 31 | var _ = utilities.NewDoubleArray 32 | var _ = descriptor.ForMessage 33 | 34 | func request_Query_QueryNftStakings_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 35 | var protoReq QueryNftStakingsRequest 36 | var metadata runtime.ServerMetadata 37 | 38 | msg, err := client.QueryNftStakings(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) 39 | return msg, metadata, err 40 | 41 | } 42 | 43 | func local_request_Query_QueryNftStakings_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 44 | var protoReq QueryNftStakingsRequest 45 | var metadata runtime.ServerMetadata 46 | 47 | msg, err := server.QueryNftStakings(ctx, &protoReq) 48 | return msg, metadata, err 49 | 50 | } 51 | 52 | // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". 53 | // UnaryRPC :call QueryServer directly. 54 | // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. 55 | // Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. 56 | func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { 57 | 58 | mux.Handle("GET", pattern_Query_QueryNftStakings_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 59 | ctx, cancel := context.WithCancel(req.Context()) 60 | defer cancel() 61 | inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 62 | rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) 63 | if err != nil { 64 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 65 | return 66 | } 67 | resp, md, err := local_request_Query_QueryNftStakings_0(rctx, inboundMarshaler, server, req, pathParams) 68 | ctx = runtime.NewServerMetadataContext(ctx, md) 69 | if err != nil { 70 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 71 | return 72 | } 73 | 74 | forward_Query_QueryNftStakings_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 75 | 76 | }) 77 | 78 | return nil 79 | } 80 | 81 | // RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but 82 | // automatically dials to "endpoint" and closes the connection when "ctx" gets done. 83 | func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { 84 | conn, err := grpc.Dial(endpoint, opts...) 85 | if err != nil { 86 | return err 87 | } 88 | defer func() { 89 | if err != nil { 90 | if cerr := conn.Close(); cerr != nil { 91 | grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 92 | } 93 | return 94 | } 95 | go func() { 96 | <-ctx.Done() 97 | if cerr := conn.Close(); cerr != nil { 98 | grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 99 | } 100 | }() 101 | }() 102 | 103 | return RegisterQueryHandler(ctx, mux, conn) 104 | } 105 | 106 | // RegisterQueryHandler registers the http handlers for service Query to "mux". 107 | // The handlers forward requests to the grpc endpoint over "conn". 108 | func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { 109 | return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) 110 | } 111 | 112 | // RegisterQueryHandlerClient registers the http handlers for service Query 113 | // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". 114 | // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" 115 | // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in 116 | // "QueryClient" to call the correct interceptors. 117 | func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { 118 | 119 | mux.Handle("GET", pattern_Query_QueryNftStakings_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 120 | ctx, cancel := context.WithCancel(req.Context()) 121 | defer cancel() 122 | inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 123 | rctx, err := runtime.AnnotateContext(ctx, mux, req) 124 | if err != nil { 125 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 126 | return 127 | } 128 | resp, md, err := request_Query_QueryNftStakings_0(rctx, inboundMarshaler, client, req, pathParams) 129 | ctx = runtime.NewServerMetadataContext(ctx, md) 130 | if err != nil { 131 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 132 | return 133 | } 134 | 135 | forward_Query_QueryNftStakings_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 136 | 137 | }) 138 | 139 | return nil 140 | } 141 | 142 | var ( 143 | pattern_Query_QueryNftStakings_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"teritori", "nftstaking", "v1beta1", "nftstakings"}, "", runtime.AssumeColonVerbOpt(true))) 144 | ) 145 | 146 | var ( 147 | forward_Query_QueryNftStakings_0 = runtime.ForwardResponseMessage 148 | ) 149 | -------------------------------------------------------------------------------- /app/export.go: -------------------------------------------------------------------------------- 1 | package teritori 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | 7 | tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 8 | 9 | servertypes "github.com/cosmos/cosmos-sdk/server/types" 10 | sdk "github.com/cosmos/cosmos-sdk/types" 11 | slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" 12 | "github.com/cosmos/cosmos-sdk/x/staking" 13 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" 14 | ) 15 | 16 | // ExportAppStateAndValidators exports the state of the application for a genesis 17 | // file. 18 | func (app *TeritoriApp) ExportAppStateAndValidators( 19 | forZeroHeight bool, jailAllowedAddrs []string, 20 | ) (servertypes.ExportedApp, error) { 21 | // as if they could withdraw from the start of the next block 22 | ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) 23 | 24 | // We export at last height + 1, because that's the height at which 25 | // Tendermint will start InitChain. 26 | height := app.LastBlockHeight() + 1 27 | if forZeroHeight { 28 | height = 0 29 | app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) 30 | } 31 | 32 | genState := app.mm.ExportGenesis(ctx, app.appCodec) 33 | appState, err := json.MarshalIndent(genState, "", " ") 34 | if err != nil { 35 | return servertypes.ExportedApp{}, err 36 | } 37 | 38 | validators, err := staking.WriteValidators(ctx, app.StakingKeeper) 39 | return servertypes.ExportedApp{ 40 | AppState: appState, 41 | Validators: validators, 42 | Height: height, 43 | ConsensusParams: app.BaseApp.GetConsensusParams(ctx), 44 | }, err 45 | } 46 | 47 | // prepare for fresh start at zero height 48 | // NOTE zero height genesis is a temporary feature which will be deprecated 49 | // in favour of export at a block height 50 | func (app *TeritoriApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { 51 | applyAllowedAddrs := false 52 | 53 | // check if there is a allowed address list 54 | if len(jailAllowedAddrs) > 0 { 55 | applyAllowedAddrs = true 56 | } 57 | 58 | allowedAddrsMap := make(map[string]bool) 59 | 60 | for _, addr := range jailAllowedAddrs { 61 | _, err := sdk.ValAddressFromBech32(addr) 62 | if err != nil { 63 | log.Fatal(err) 64 | } 65 | allowedAddrsMap[addr] = true 66 | } 67 | 68 | /* Just to be safe, assert the invariants on current state. */ 69 | app.CrisisKeeper.AssertInvariants(ctx) 70 | 71 | /* Handle fee distribution state. */ 72 | 73 | // withdraw all validator commission 74 | app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { 75 | _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) 76 | return false 77 | }) 78 | 79 | // withdraw all delegator rewards 80 | dels := app.StakingKeeper.GetAllDelegations(ctx) 81 | for _, delegation := range dels { 82 | valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) 83 | if err != nil { 84 | panic(err) 85 | } 86 | 87 | delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress) 88 | if err != nil { 89 | panic(err) 90 | } 91 | _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) 92 | } 93 | 94 | // clear validator slash events 95 | app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx) 96 | 97 | // clear validator historical rewards 98 | app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) 99 | 100 | // set context height to zero 101 | height := ctx.BlockHeight() 102 | ctx = ctx.WithBlockHeight(0) 103 | 104 | // reinitialize all validators 105 | app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { 106 | // donate any unwithdrawn outstanding reward fraction tokens to the community pool 107 | scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) 108 | feePool := app.DistrKeeper.GetFeePool(ctx) 109 | feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) 110 | app.DistrKeeper.SetFeePool(ctx, feePool) 111 | 112 | app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) 113 | return false 114 | }) 115 | 116 | // reinitialize all delegations 117 | for _, del := range dels { 118 | valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) 119 | if err != nil { 120 | panic(err) 121 | } 122 | delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress) 123 | if err != nil { 124 | panic(err) 125 | } 126 | app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr) 127 | app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr) 128 | } 129 | 130 | // reset context height 131 | ctx = ctx.WithBlockHeight(height) 132 | 133 | /* Handle staking state. */ 134 | 135 | // iterate through redelegations, reset creation height 136 | app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { 137 | for i := range red.Entries { 138 | red.Entries[i].CreationHeight = 0 139 | } 140 | app.StakingKeeper.SetRedelegation(ctx, red) 141 | return false 142 | }) 143 | 144 | // iterate through unbonding delegations, reset creation height 145 | app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { 146 | for i := range ubd.Entries { 147 | ubd.Entries[i].CreationHeight = 0 148 | } 149 | app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) 150 | return false 151 | }) 152 | 153 | // Iterate through validators by power descending, reset bond heights, and 154 | // update bond intra-tx counters. 155 | store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) 156 | iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) 157 | counter := int16(0) 158 | 159 | for ; iter.Valid(); iter.Next() { 160 | addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) 161 | validator, found := app.StakingKeeper.GetValidator(ctx, addr) 162 | if !found { 163 | panic("expected validator, not found") 164 | } 165 | 166 | validator.UnbondingHeight = 0 167 | if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { 168 | validator.Jailed = true 169 | } 170 | 171 | app.StakingKeeper.SetValidator(ctx, validator) 172 | counter++ 173 | } 174 | 175 | iter.Close() 176 | 177 | _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) 178 | if err != nil { 179 | log.Fatal(err) 180 | } 181 | 182 | /* Handle slashing state. */ 183 | 184 | // reset start height on signing infos 185 | app.SlashingKeeper.IterateValidatorSigningInfos( 186 | ctx, 187 | func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { 188 | info.StartHeight = 0 189 | app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) 190 | return false 191 | }, 192 | ) 193 | } 194 | -------------------------------------------------------------------------------- /x/airdrop/types/query.pb.gw.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. 2 | // source: teritori/airdrop/v1beta1/query.proto 3 | 4 | /* 5 | Package types is a reverse proxy. 6 | 7 | It translates gRPC into RESTful JSON APIs. 8 | */ 9 | package types 10 | 11 | import ( 12 | "context" 13 | "io" 14 | "net/http" 15 | 16 | "github.com/golang/protobuf/descriptor" 17 | "github.com/golang/protobuf/proto" 18 | "github.com/grpc-ecosystem/grpc-gateway/runtime" 19 | "github.com/grpc-ecosystem/grpc-gateway/utilities" 20 | "google.golang.org/grpc" 21 | "google.golang.org/grpc/codes" 22 | "google.golang.org/grpc/grpclog" 23 | "google.golang.org/grpc/status" 24 | ) 25 | 26 | // Suppress "imported and not used" errors 27 | var _ codes.Code 28 | var _ io.Reader 29 | var _ status.Status 30 | var _ = runtime.String 31 | var _ = utilities.NewDoubleArray 32 | var _ = descriptor.ForMessage 33 | 34 | func request_Query_Allocation_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 35 | var protoReq QueryAllocationRequest 36 | var metadata runtime.ServerMetadata 37 | 38 | var ( 39 | val string 40 | ok bool 41 | err error 42 | _ = err 43 | ) 44 | 45 | val, ok = pathParams["address"] 46 | if !ok { 47 | return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") 48 | } 49 | 50 | protoReq.Address, err = runtime.String(val) 51 | 52 | if err != nil { 53 | return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) 54 | } 55 | 56 | msg, err := client.Allocation(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) 57 | return msg, metadata, err 58 | 59 | } 60 | 61 | func local_request_Query_Allocation_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 62 | var protoReq QueryAllocationRequest 63 | var metadata runtime.ServerMetadata 64 | 65 | var ( 66 | val string 67 | ok bool 68 | err error 69 | _ = err 70 | ) 71 | 72 | val, ok = pathParams["address"] 73 | if !ok { 74 | return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") 75 | } 76 | 77 | protoReq.Address, err = runtime.String(val) 78 | 79 | if err != nil { 80 | return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) 81 | } 82 | 83 | msg, err := server.Allocation(ctx, &protoReq) 84 | return msg, metadata, err 85 | 86 | } 87 | 88 | // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". 89 | // UnaryRPC :call QueryServer directly. 90 | // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. 91 | // Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. 92 | func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { 93 | 94 | mux.Handle("GET", pattern_Query_Allocation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 95 | ctx, cancel := context.WithCancel(req.Context()) 96 | defer cancel() 97 | inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 98 | rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) 99 | if err != nil { 100 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 101 | return 102 | } 103 | resp, md, err := local_request_Query_Allocation_0(rctx, inboundMarshaler, server, req, pathParams) 104 | ctx = runtime.NewServerMetadataContext(ctx, md) 105 | if err != nil { 106 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 107 | return 108 | } 109 | 110 | forward_Query_Allocation_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 111 | 112 | }) 113 | 114 | return nil 115 | } 116 | 117 | // RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but 118 | // automatically dials to "endpoint" and closes the connection when "ctx" gets done. 119 | func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { 120 | conn, err := grpc.Dial(endpoint, opts...) 121 | if err != nil { 122 | return err 123 | } 124 | defer func() { 125 | if err != nil { 126 | if cerr := conn.Close(); cerr != nil { 127 | grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 128 | } 129 | return 130 | } 131 | go func() { 132 | <-ctx.Done() 133 | if cerr := conn.Close(); cerr != nil { 134 | grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 135 | } 136 | }() 137 | }() 138 | 139 | return RegisterQueryHandler(ctx, mux, conn) 140 | } 141 | 142 | // RegisterQueryHandler registers the http handlers for service Query to "mux". 143 | // The handlers forward requests to the grpc endpoint over "conn". 144 | func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { 145 | return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) 146 | } 147 | 148 | // RegisterQueryHandlerClient registers the http handlers for service Query 149 | // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". 150 | // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" 151 | // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in 152 | // "QueryClient" to call the correct interceptors. 153 | func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { 154 | 155 | mux.Handle("GET", pattern_Query_Allocation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 156 | ctx, cancel := context.WithCancel(req.Context()) 157 | defer cancel() 158 | inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 159 | rctx, err := runtime.AnnotateContext(ctx, mux, req) 160 | if err != nil { 161 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 162 | return 163 | } 164 | resp, md, err := request_Query_Allocation_0(rctx, inboundMarshaler, client, req, pathParams) 165 | ctx = runtime.NewServerMetadataContext(ctx, md) 166 | if err != nil { 167 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 168 | return 169 | } 170 | 171 | forward_Query_Allocation_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 172 | 173 | }) 174 | 175 | return nil 176 | } 177 | 178 | var ( 179 | pattern_Query_Allocation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"teritori", "airdrop", "v1beta1", "allocation", "address"}, "", runtime.AssumeColonVerbOpt(true))) 180 | ) 181 | 182 | var ( 183 | forward_Query_Allocation_0 = runtime.ForwardResponseMessage 184 | ) 185 | -------------------------------------------------------------------------------- /cmd/teritorid/cmd/genaccounts.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bufio" 5 | "encoding/json" 6 | "errors" 7 | "fmt" 8 | 9 | "github.com/spf13/cobra" 10 | 11 | "github.com/cosmos/cosmos-sdk/client" 12 | "github.com/cosmos/cosmos-sdk/client/flags" 13 | "github.com/cosmos/cosmos-sdk/crypto/keyring" 14 | "github.com/cosmos/cosmos-sdk/server" 15 | sdk "github.com/cosmos/cosmos-sdk/types" 16 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" 17 | authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" 18 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" 19 | "github.com/cosmos/cosmos-sdk/x/genutil" 20 | genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" 21 | ) 22 | 23 | const ( 24 | flagVestingStart = "vesting-start-time" 25 | flagVestingEnd = "vesting-end-time" 26 | flagVestingAmt = "vesting-amount" 27 | ) 28 | 29 | // AddGenesisAccountCmd returns add-genesis-account cobra Command. 30 | func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command { 31 | cmd := &cobra.Command{ 32 | Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]", 33 | Short: "Add a genesis account to genesis.json", 34 | Long: `Add a genesis account to genesis.json. The provided account must specify 35 | the account address or key name and a list of initial coins. If a key name is given, 36 | the address will be looked up in the local Keybase. The list of initial tokens must 37 | contain valid denominations. Accounts may optionally be supplied with vesting parameters. 38 | `, 39 | Args: cobra.ExactArgs(2), 40 | RunE: func(cmd *cobra.Command, args []string) error { 41 | clientCtx := client.GetClientContextFromCmd(cmd) 42 | serverCtx := server.GetServerContextFromCmd(cmd) 43 | config := serverCtx.Config 44 | 45 | config.SetRoot(clientCtx.HomeDir) 46 | 47 | addr, err := sdk.AccAddressFromBech32(args[0]) 48 | if err != nil { 49 | inBuf := bufio.NewReader(cmd.InOrStdin()) 50 | keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | // attempt to lookup address from Keybase if no address was provided 56 | kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf) 57 | if err != nil { 58 | return err 59 | } 60 | 61 | info, err := kb.Key(args[0]) 62 | if err != nil { 63 | return fmt.Errorf("failed to get address from Keybase: %w", err) 64 | } 65 | 66 | addr = info.GetAddress() 67 | } 68 | 69 | coins, err := sdk.ParseCoinsNormalized(args[1]) 70 | if err != nil { 71 | return fmt.Errorf("failed to parse coins: %w", err) 72 | } 73 | 74 | vestingStart, err := cmd.Flags().GetInt64(flagVestingStart) 75 | if err != nil { 76 | return err 77 | } 78 | vestingEnd, err := cmd.Flags().GetInt64(flagVestingEnd) 79 | if err != nil { 80 | return err 81 | } 82 | vestingAmtStr, err := cmd.Flags().GetString(flagVestingAmt) 83 | if err != nil { 84 | return err 85 | } 86 | 87 | vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr) 88 | if err != nil { 89 | return fmt.Errorf("failed to parse vesting amount: %w", err) 90 | } 91 | 92 | // create concrete account type based on input parameters 93 | var genAccount authtypes.GenesisAccount 94 | 95 | balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()} 96 | baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0) 97 | 98 | if !vestingAmt.IsZero() { 99 | baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd) 100 | 101 | if (balances.Coins.IsZero() && !baseVestingAccount.OriginalVesting.IsZero()) || 102 | baseVestingAccount.OriginalVesting.IsAnyGT(balances.Coins) { 103 | return errors.New("vesting amount cannot be greater than total amount") 104 | } 105 | 106 | switch { 107 | case vestingStart != 0 && vestingEnd != 0: 108 | genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart) 109 | 110 | case vestingEnd != 0: 111 | genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount) 112 | 113 | default: 114 | return errors.New("invalid vesting parameters; must supply start and end time or end time") 115 | } 116 | } else { 117 | genAccount = baseAccount 118 | } 119 | 120 | if err := genAccount.Validate(); err != nil { 121 | return fmt.Errorf("failed to validate new genesis account: %w", err) 122 | } 123 | 124 | genFile := config.GenesisFile() 125 | appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile) 126 | if err != nil { 127 | return fmt.Errorf("failed to unmarshal genesis state: %w", err) 128 | } 129 | 130 | authGenState := authtypes.GetGenesisStateFromAppState(clientCtx.Codec, appState) 131 | 132 | accs, err := authtypes.UnpackAccounts(authGenState.Accounts) 133 | if err != nil { 134 | return fmt.Errorf("failed to get accounts from any: %w", err) 135 | } 136 | 137 | if accs.Contains(addr) { 138 | return fmt.Errorf("cannot add account at existing address %s", addr) 139 | } 140 | 141 | // Add the new account to the set of genesis accounts and sanitize the 142 | // accounts afterwards. 143 | accs = append(accs, genAccount) 144 | accs = authtypes.SanitizeGenesisAccounts(accs) 145 | 146 | genAccs, err := authtypes.PackAccounts(accs) 147 | if err != nil { 148 | return fmt.Errorf("failed to convert accounts into any's: %w", err) 149 | } 150 | authGenState.Accounts = genAccs 151 | 152 | authGenStateBz, err := clientCtx.Codec.MarshalJSON(&authGenState) 153 | if err != nil { 154 | return fmt.Errorf("failed to marshal auth genesis state: %w", err) 155 | } 156 | 157 | appState[authtypes.ModuleName] = authGenStateBz 158 | 159 | bankGenState := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState) 160 | bankGenState.Balances = append(bankGenState.Balances, balances) 161 | bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances) 162 | bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...) 163 | 164 | bankGenStateBz, err := clientCtx.Codec.MarshalJSON(bankGenState) 165 | if err != nil { 166 | return fmt.Errorf("failed to marshal bank genesis state: %w", err) 167 | } 168 | 169 | appState[banktypes.ModuleName] = bankGenStateBz 170 | 171 | appStateJSON, err := json.Marshal(appState) 172 | if err != nil { 173 | return fmt.Errorf("failed to marshal application genesis state: %w", err) 174 | } 175 | 176 | genDoc.AppState = appStateJSON 177 | return genutil.ExportGenesisFile(genDoc, genFile) 178 | }, 179 | } 180 | 181 | cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") 182 | cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") 183 | cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") 184 | cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") 185 | cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") 186 | flags.AddQueryFlagsToCmd(cmd) 187 | 188 | return cmd 189 | } 190 | -------------------------------------------------------------------------------- /x/airdrop/module.go: -------------------------------------------------------------------------------- 1 | package airdrop 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "math/rand" 8 | 9 | "github.com/NXTPOP/teritori-chain/x/airdrop/client/cli" 10 | "github.com/NXTPOP/teritori-chain/x/airdrop/keeper" 11 | "github.com/NXTPOP/teritori-chain/x/airdrop/types" 12 | "github.com/cosmos/cosmos-sdk/client" 13 | "github.com/cosmos/cosmos-sdk/codec" 14 | cdctypes "github.com/cosmos/cosmos-sdk/codec/types" 15 | sdk "github.com/cosmos/cosmos-sdk/types" 16 | "github.com/cosmos/cosmos-sdk/types/module" 17 | simtypes "github.com/cosmos/cosmos-sdk/types/simulation" 18 | "github.com/cosmos/cosmos-sdk/x/gov/simulation" 19 | "github.com/gorilla/mux" 20 | "github.com/grpc-ecosystem/grpc-gateway/runtime" 21 | "github.com/spf13/cobra" 22 | abci "github.com/tendermint/tendermint/abci/types" 23 | ) 24 | 25 | var ( 26 | _ module.AppModule = AppModule{} 27 | _ module.AppModuleBasic = AppModuleBasic{} 28 | ) 29 | 30 | // ---------------------------------------------------------------------------- 31 | // AppModuleBasic 32 | // ---------------------------------------------------------------------------- 33 | 34 | // AppModuleBasic implements the AppModuleBasic interface for the capability module. 35 | type AppModuleBasic struct { 36 | cdc codec.Codec 37 | } 38 | 39 | func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { 40 | return AppModuleBasic{cdc: cdc} 41 | } 42 | 43 | // Name returns the capability module's name. 44 | func (AppModuleBasic) Name() string { 45 | return types.ModuleName 46 | } 47 | 48 | func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { 49 | } 50 | 51 | // RegisterInterfaces registers the module's interface types 52 | func (a AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { 53 | types.RegisterInterfaces(registry) 54 | } 55 | 56 | // DefaultGenesis returns the capability module's default genesis state. 57 | func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { 58 | return cdc.MustMarshalJSON(types.DefaultGenesis()) 59 | } 60 | 61 | // ValidateGenesis performs genesis state validation for the capability module. 62 | func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { 63 | var genState types.GenesisState 64 | if err := cdc.UnmarshalJSON(bz, &genState); err != nil { 65 | return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) 66 | } 67 | return genState.Validate() 68 | } 69 | 70 | // RegisterRESTRoutes registers the capability module's REST service handlers. 71 | func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { 72 | } 73 | 74 | // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. 75 | func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { 76 | types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck 77 | } 78 | 79 | // GetTxCmd returns the capability module's root tx command. 80 | func (a AppModuleBasic) GetTxCmd() *cobra.Command { 81 | return cli.GetTxCmd() 82 | } 83 | 84 | // GetQueryCmd returns the capability module's root query command. 85 | func (AppModuleBasic) GetQueryCmd() *cobra.Command { 86 | return cli.GetQueryCmd() 87 | } 88 | 89 | // ---------------------------------------------------------------------------- 90 | // AppModule 91 | // ---------------------------------------------------------------------------- 92 | 93 | // AppModule implements the AppModule interface for the capability module. 94 | type AppModule struct { 95 | AppModuleBasic 96 | 97 | keeper keeper.Keeper 98 | } 99 | 100 | func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { 101 | return AppModule{ 102 | AppModuleBasic: NewAppModuleBasic(cdc), 103 | keeper: keeper, 104 | } 105 | } 106 | 107 | // Name returns the capability module's name. 108 | func (am AppModule) Name() string { 109 | return am.AppModuleBasic.Name() 110 | } 111 | 112 | // Route returns the capability module's message routing key. 113 | func (am AppModule) Route() sdk.Route { 114 | return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) 115 | } 116 | 117 | // QuerierRoute returns the capability module's query routing key. 118 | func (AppModule) QuerierRoute() string { return types.QuerierRoute } 119 | 120 | // LegacyQuerierHandler returns the capability module's Querier. 121 | func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { 122 | return keeper.NewQuerier(am.keeper, legacyQuerierCdc) 123 | } 124 | 125 | // RegisterServices registers a GRPC query service to respond to the 126 | // module-specific GRPC queries. 127 | func (am AppModule) RegisterServices(cfg module.Configurator) { 128 | types.RegisterQueryServer(cfg.QueryServer(), am.keeper) 129 | } 130 | 131 | // RegisterInvariants registers the capability module's invariants. 132 | func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} 133 | 134 | // InitGenesis performs the capability module's genesis initialization It returns 135 | // no validator updates. 136 | func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { 137 | var genState types.GenesisState 138 | // Initialize global index to index in genesis state 139 | cdc.MustUnmarshalJSON(gs, &genState) 140 | 141 | InitGenesis(ctx, am.keeper, genState) 142 | 143 | return []abci.ValidatorUpdate{} 144 | } 145 | 146 | // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. 147 | func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { 148 | genState := ExportGenesis(ctx, am.keeper) 149 | return cdc.MustMarshalJSON(genState) 150 | } 151 | 152 | // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. 153 | func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} 154 | 155 | // EndBlock executes all ABCI EndBlock logic respective to the capability module. It 156 | // returns no validator updates. 157 | func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { 158 | EndBlocker(ctx, am.keeper) 159 | return []abci.ValidatorUpdate{} 160 | } 161 | 162 | // GenerateGenesisState creates a randomized GenState of the gov module. 163 | func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 164 | } 165 | 166 | // ProposalContents returns all the gov content functions used to 167 | // simulate governance proposals. 168 | func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { 169 | return nil 170 | } 171 | 172 | // RandomizedParams creates randomized gov param changes for the simulator. 173 | func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { 174 | return nil 175 | } 176 | 177 | // RegisterStoreDecoder registers a decoder for gov module's types 178 | func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 179 | sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) 180 | } 181 | 182 | // WeightedOperations returns the all the gov module operations with their respective weights. 183 | func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { 184 | return nil 185 | } 186 | 187 | // ConsensusVersion implements AppModule/ConsensusVersion. 188 | func (AppModule) ConsensusVersion() uint64 { return 1 } 189 | -------------------------------------------------------------------------------- /testnet/teritori-testnet-v2/README.md: -------------------------------------------------------------------------------- 1 | # [ACTIVE] 2 | 3 | ## Server Configuration 4 | 5 | Here is the configuration of the server we are using: 6 | - No. of CPUs: 2 7 | - Memory: 2GB 8 | - Disk: 80GB SSD 9 | - OS: Ubuntu 18.04 LTS 10 | 11 | Allow all incoming connections from TCP port 26656 and 26657 12 | 13 | Notes on the configurations. 14 | 1. Multicore is important, regardless the less CPU time usage 15 | 2. teritorid uses less than 1GB memory and 2GB should be enough for now. 16 | Once your new server is running, login to the server and upgrade your packages. 17 | 18 | 19 | 20 | ## Setup your machine 21 | 22 | If you already have go 1.18+ and packages up to date, you can skip this part and jump to the second section: [Setup the chain](#setup-the-chain) 23 | Make sure your machine is up to date: 24 | ```shell 25 | apt update && apt upgrade -y 26 | ``` 27 | 28 | Install few packages: 29 | ```shell 30 | apt install build-essential git curl gcc make jq -y 31 | ``` 32 | 33 | Install Go 1.18+: 34 | ```shell 35 | wget -c https://go.dev/dl/go1.18.3.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz && rm -rf go1.18.3.linux-amd64.tar.gz 36 | ``` 37 | 38 | Setup your environnement (you can skip this part if you already had go installed before): 39 | ```shell 40 | echo 'export GOROOT=/usr/local/go' >> $HOME/.bash_profile 41 | echo 'export GOPATH=$HOME/go' >> $HOME/.bash_profile 42 | echo 'export GO111MODULE=on' >> $HOME/.bash_profile 43 | echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile && . $HOME/.bash_profile 44 | ``` 45 | 46 | Verify the installation: 47 | ```shell 48 | go version 49 | #Should return go version go1.18.3 linux/amd64 50 | ``` 51 | 52 | ## Setup the chain 53 | 54 | Clone the Teritori repository and install the v2 of testnet: 55 | ```shell 56 | git clone https://github.com/TERITORI/teritori-chain && cd teritori-chain && git checkout teritori-testnet-v2 && make install 57 | ``` 58 | 59 | Verify the installation: 60 | ```shell 61 | teritorid version 62 | #Should return teritori-testnet-v2-0f4e5cb1d529fa18971664891a9e8e4c114456c6 63 | ``` 64 | 65 | Init the chain: 66 | ```shell 67 | teritorid init --chain-id teritori-testnet-v2 68 | ``` 69 | 70 | Add peers in the config file: 71 | ```shell 72 | sed -i.bak 's/persistent_peers =.*/persistent_peers = "0b42fd287d3bb0a20230e30d54b4b8facc412c53@176.9.149.15:26656,2371b28f366a61637ac76c2577264f79f0965447@176.9.19.162:26656,2f394edda96be07bf92b0b503d8be13d1b9cc39f@5.9.40.222:26656"/' $HOME/.teritorid/config/config.toml 73 | ``` 74 | 75 | Download the genesis file: 76 | ```shell 77 | wget -O ~/.teritorid/config/genesis.json https://raw.githubusercontent.com/TERITORI/teritori-chain/main/testnet/teritori-testnet-v2/genesis.json 78 | ``` 79 | 80 | 81 | ## Launch the node 82 | 83 | You have multiple choice for launching the chain, choose the one that you prefer in the below list: 84 | - [Manual](https://github.com/TERITORI/teritori-chain/tree/main/testnet/teritori-testnet-v2#Manual) 85 | - [Systemctl](https://github.com/TERITORI/teritori-chain/tree/main/testnet/teritori-testnet-v2#Systemctl) 86 | - [Cosmovisor](https://github.com/TERITORI/teritori-chain/tree/main/testnet/teritori-testnet-v2#Cosmovisor) 87 | 88 | ### __Manual__ 89 | - Create a screen and setup limit of files 90 | - Launch the chain 91 | ```shell 92 | screen -S teritori 93 | ulimit -n 4096 94 | teritorid start 95 | ``` 96 | You can escape the screen pressing `CTRL + AD` and enter it again using: 97 | ```shell 98 | screen -r teritori 99 | ``` 100 | ### __Systemctl__ 101 | - Create service file 102 | - Enable and launch the service file 103 | - Setup the logs 104 | 105 | ```shell 106 | tee </dev/null /etc/systemd/system/teritorid.service 107 | [Unit] 108 | Description=Teritori Cosmos daemon 109 | After=network-online.target 110 | 111 | [Service] 112 | User=$USER 113 | ExecStart=/home/$USER/go/bin/teritorid start 114 | Restart=on-failure 115 | RestartSec=3 116 | LimitNOFILE=4096 117 | 118 | [Install] 119 | WantedBy=multi-user.target 120 | EOF 121 | ``` 122 | 123 | ```shell 124 | systemctl enable teritorid 125 | systemctl daemon-reload 126 | systemctl restart teritorid 127 | ``` 128 | 129 | To check the logs: 130 | ```shell 131 | journalctl -u teritorid.service -f -n 100 132 | ``` 133 | 134 | 135 | ### __Cosmovisor__ 136 | - Install cosmovisor 137 | - Setup environment variables 138 | - Create folders needed for upgrades 139 | - Copy binaries to cosmovisor bin 140 | - Create service file 141 | - Enable and launch the service file 142 | - Setup the logs 143 | 144 | ```shell 145 | go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest 146 | ``` 147 | 148 | ```shell 149 | export DAEMON_NAME=teritorid 150 | export DAEMON_HOME=$HOME/.teritori 151 | source ~/.profile 152 | ``` 153 | 154 | ```shell 155 | mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin 156 | mkdir -p $DAEMON_HOME/cosmovisor/upgrades 157 | ``` 158 | 159 | ```shell 160 | cp $HOME/go/bin/teritorid $DAEMON_HOME/cosmovisor/genesis/bin 161 | ``` 162 | 163 | ```shell 164 | tee </dev/null /etc/systemd/system/teritorid.service 165 | [Unit] 166 | Description=Teritori Daemon (cosmovisor) 167 | 168 | After=network-online.target 169 | 170 | [Service] 171 | User=$USER 172 | ExecStart=/home/$USER/go/bin/cosmovisor start 173 | Restart=always 174 | RestartSec=3 175 | LimitNOFILE=4096 176 | Environment="DAEMON_NAME=teritorid" 177 | Environment="DAEMON_HOME=/home/$USER/.teritori" 178 | Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false" 179 | Environment="DAEMON_RESTART_AFTER_UPGRADE=true" 180 | Environment="DAEMON_LOG_BUFFER_SIZE=512" 181 | 182 | [Install] 183 | WantedBy=multi-user.target 184 | EOF 185 | ``` 186 | 187 | ```shell 188 | systemctl enable teritorid 189 | systemctl daemon-reload 190 | systemctl restart teritorid 191 | ``` 192 | 193 | To check the logs: 194 | ```shell 195 | journalctl -u teritorid.service -f -n 100 196 | ``` 197 | 198 | Wait for the chain to synchronize with the current block... you can do the next step during this time 199 | 200 | ## Setup your account 201 | 202 | Create an account: 203 | ```shell 204 | teritorid keys add 205 | ``` 206 | 207 | You can also you `--recover` flag to use an already existed key (but we recommend for security reason to use one key per chain to avoid total loss of funds in case one key is missing) 208 | 209 | Join our [Discord](https://discord.gg/teritori) and request fund on the `Faucet` channel using this command: 210 | ```shell 211 | $request 212 | ``` 213 | 214 | You can check if you have received fund once your node will be synched using this CLI command: 215 | ```shell 216 | teritorid query bank balances --chain-id teritori-testnet-v2 217 | ``` 218 | 219 | Once the fund are received and chain is synchronized you can create your validator: 220 | ```shell 221 | teritorid tx staking create-validator \ 222 | --commission-max-change-rate=0.01 \ 223 | --commission-max-rate=0.2 \ 224 | --commission-rate=0.05 \ 225 | --amount 1000000utori \ 226 | --pubkey=$(teritorid tendermint show-validator) \ 227 | --moniker= \ 228 | --chain-id=teritori-testnet-v2 \ 229 | --details="" \ 230 | --security-contact=" 235 | ``` 236 | 237 | 238 | FAQ: Coming soon. 239 | 240 | Join us on [Discord](https://discord.gg/teritori) for Testnet v2 Village discussions. 241 | -------------------------------------------------------------------------------- /x/airdrop/types/params.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: teritori/airdrop/v1beta1/params.proto 3 | 4 | package types 5 | 6 | import ( 7 | fmt "fmt" 8 | _ "github.com/gogo/protobuf/gogoproto" 9 | proto "github.com/gogo/protobuf/proto" 10 | _ "google.golang.org/protobuf/types/known/durationpb" 11 | _ "google.golang.org/protobuf/types/known/timestamppb" 12 | io "io" 13 | math "math" 14 | math_bits "math/bits" 15 | ) 16 | 17 | // Reference imports to suppress errors if they are not otherwise used. 18 | var _ = proto.Marshal 19 | var _ = fmt.Errorf 20 | var _ = math.Inf 21 | 22 | // This is a compile-time assertion to ensure that this generated file 23 | // is compatible with the proto package it is being compiled against. 24 | // A compilation error at this line likely means your copy of the 25 | // proto package needs to be updated. 26 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 27 | 28 | // Params defines the module's parameters. 29 | type Params struct { 30 | } 31 | 32 | func (m *Params) Reset() { *m = Params{} } 33 | func (m *Params) String() string { return proto.CompactTextString(m) } 34 | func (*Params) ProtoMessage() {} 35 | func (*Params) Descriptor() ([]byte, []int) { 36 | return fileDescriptor_a2c3d8a029e35b4d, []int{0} 37 | } 38 | func (m *Params) XXX_Unmarshal(b []byte) error { 39 | return m.Unmarshal(b) 40 | } 41 | func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 42 | if deterministic { 43 | return xxx_messageInfo_Params.Marshal(b, m, deterministic) 44 | } else { 45 | b = b[:cap(b)] 46 | n, err := m.MarshalToSizedBuffer(b) 47 | if err != nil { 48 | return nil, err 49 | } 50 | return b[:n], nil 51 | } 52 | } 53 | func (m *Params) XXX_Merge(src proto.Message) { 54 | xxx_messageInfo_Params.Merge(m, src) 55 | } 56 | func (m *Params) XXX_Size() int { 57 | return m.Size() 58 | } 59 | func (m *Params) XXX_DiscardUnknown() { 60 | xxx_messageInfo_Params.DiscardUnknown(m) 61 | } 62 | 63 | var xxx_messageInfo_Params proto.InternalMessageInfo 64 | 65 | func init() { 66 | proto.RegisterType((*Params)(nil), "teritori.airdrop.v1beta1.Params") 67 | } 68 | 69 | func init() { 70 | proto.RegisterFile("teritori/airdrop/v1beta1/params.proto", fileDescriptor_a2c3d8a029e35b4d) 71 | } 72 | 73 | var fileDescriptor_a2c3d8a029e35b4d = []byte{ 74 | // 202 bytes of a gzipped FileDescriptorProto 75 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x49, 0x2d, 0xca, 76 | 0x2c, 0xc9, 0x2f, 0xca, 0xd4, 0x4f, 0xcc, 0x2c, 0x4a, 0x29, 0xca, 0x2f, 0xd0, 0x2f, 0x33, 0x4c, 77 | 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 78 | 0xc9, 0x17, 0x92, 0x80, 0x29, 0xd3, 0x83, 0x2a, 0xd3, 0x83, 0x2a, 0x93, 0x12, 0x49, 0xcf, 0x4f, 79 | 0xcf, 0x07, 0x2b, 0xd2, 0x07, 0xb1, 0x20, 0xea, 0xa5, 0xe4, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 80 | 0xf5, 0xc1, 0xbc, 0xa4, 0xd2, 0x34, 0xfd, 0x94, 0xd2, 0xa2, 0xc4, 0x92, 0xcc, 0xfc, 0x3c, 0xa8, 81 | 0xbc, 0x3c, 0xba, 0x7c, 0x49, 0x66, 0x6e, 0x6a, 0x71, 0x49, 0x62, 0x6e, 0x01, 0x44, 0x81, 0x12, 82 | 0x07, 0x17, 0x5b, 0x00, 0xd8, 0x01, 0x4e, 0x5e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 83 | 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 84 | 0xc7, 0x10, 0x65, 0x90, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0xef, 0x17, 85 | 0x11, 0x12, 0xe0, 0x1f, 0xa0, 0x0f, 0x73, 0xa6, 0x6e, 0x72, 0x46, 0x62, 0x66, 0x9e, 0x7e, 0x05, 86 | 0xdc, 0x57, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0xc3, 0x8d, 0x01, 0x01, 0x00, 0x00, 87 | 0xff, 0xff, 0x46, 0xf9, 0x8b, 0xef, 0xf6, 0x00, 0x00, 0x00, 88 | } 89 | 90 | func (m *Params) Marshal() (dAtA []byte, err error) { 91 | size := m.Size() 92 | dAtA = make([]byte, size) 93 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 94 | if err != nil { 95 | return nil, err 96 | } 97 | return dAtA[:n], nil 98 | } 99 | 100 | func (m *Params) MarshalTo(dAtA []byte) (int, error) { 101 | size := m.Size() 102 | return m.MarshalToSizedBuffer(dAtA[:size]) 103 | } 104 | 105 | func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { 106 | i := len(dAtA) 107 | _ = i 108 | var l int 109 | _ = l 110 | return len(dAtA) - i, nil 111 | } 112 | 113 | func encodeVarintParams(dAtA []byte, offset int, v uint64) int { 114 | offset -= sovParams(v) 115 | base := offset 116 | for v >= 1<<7 { 117 | dAtA[offset] = uint8(v&0x7f | 0x80) 118 | v >>= 7 119 | offset++ 120 | } 121 | dAtA[offset] = uint8(v) 122 | return base 123 | } 124 | func (m *Params) Size() (n int) { 125 | if m == nil { 126 | return 0 127 | } 128 | var l int 129 | _ = l 130 | return n 131 | } 132 | 133 | func sovParams(x uint64) (n int) { 134 | return (math_bits.Len64(x|1) + 6) / 7 135 | } 136 | func sozParams(x uint64) (n int) { 137 | return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) 138 | } 139 | func (m *Params) Unmarshal(dAtA []byte) error { 140 | l := len(dAtA) 141 | iNdEx := 0 142 | for iNdEx < l { 143 | preIndex := iNdEx 144 | var wire uint64 145 | for shift := uint(0); ; shift += 7 { 146 | if shift >= 64 { 147 | return ErrIntOverflowParams 148 | } 149 | if iNdEx >= l { 150 | return io.ErrUnexpectedEOF 151 | } 152 | b := dAtA[iNdEx] 153 | iNdEx++ 154 | wire |= uint64(b&0x7F) << shift 155 | if b < 0x80 { 156 | break 157 | } 158 | } 159 | fieldNum := int32(wire >> 3) 160 | wireType := int(wire & 0x7) 161 | if wireType == 4 { 162 | return fmt.Errorf("proto: Params: wiretype end group for non-group") 163 | } 164 | if fieldNum <= 0 { 165 | return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) 166 | } 167 | switch fieldNum { 168 | default: 169 | iNdEx = preIndex 170 | skippy, err := skipParams(dAtA[iNdEx:]) 171 | if err != nil { 172 | return err 173 | } 174 | if (skippy < 0) || (iNdEx+skippy) < 0 { 175 | return ErrInvalidLengthParams 176 | } 177 | if (iNdEx + skippy) > l { 178 | return io.ErrUnexpectedEOF 179 | } 180 | iNdEx += skippy 181 | } 182 | } 183 | 184 | if iNdEx > l { 185 | return io.ErrUnexpectedEOF 186 | } 187 | return nil 188 | } 189 | func skipParams(dAtA []byte) (n int, err error) { 190 | l := len(dAtA) 191 | iNdEx := 0 192 | depth := 0 193 | for iNdEx < l { 194 | var wire uint64 195 | for shift := uint(0); ; shift += 7 { 196 | if shift >= 64 { 197 | return 0, ErrIntOverflowParams 198 | } 199 | if iNdEx >= l { 200 | return 0, io.ErrUnexpectedEOF 201 | } 202 | b := dAtA[iNdEx] 203 | iNdEx++ 204 | wire |= (uint64(b) & 0x7F) << shift 205 | if b < 0x80 { 206 | break 207 | } 208 | } 209 | wireType := int(wire & 0x7) 210 | switch wireType { 211 | case 0: 212 | for shift := uint(0); ; shift += 7 { 213 | if shift >= 64 { 214 | return 0, ErrIntOverflowParams 215 | } 216 | if iNdEx >= l { 217 | return 0, io.ErrUnexpectedEOF 218 | } 219 | iNdEx++ 220 | if dAtA[iNdEx-1] < 0x80 { 221 | break 222 | } 223 | } 224 | case 1: 225 | iNdEx += 8 226 | case 2: 227 | var length int 228 | for shift := uint(0); ; shift += 7 { 229 | if shift >= 64 { 230 | return 0, ErrIntOverflowParams 231 | } 232 | if iNdEx >= l { 233 | return 0, io.ErrUnexpectedEOF 234 | } 235 | b := dAtA[iNdEx] 236 | iNdEx++ 237 | length |= (int(b) & 0x7F) << shift 238 | if b < 0x80 { 239 | break 240 | } 241 | } 242 | if length < 0 { 243 | return 0, ErrInvalidLengthParams 244 | } 245 | iNdEx += length 246 | case 3: 247 | depth++ 248 | case 4: 249 | if depth == 0 { 250 | return 0, ErrUnexpectedEndOfGroupParams 251 | } 252 | depth-- 253 | case 5: 254 | iNdEx += 4 255 | default: 256 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType) 257 | } 258 | if iNdEx < 0 { 259 | return 0, ErrInvalidLengthParams 260 | } 261 | if depth == 0 { 262 | return iNdEx, nil 263 | } 264 | } 265 | return 0, io.ErrUnexpectedEOF 266 | } 267 | 268 | var ( 269 | ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") 270 | ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") 271 | ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") 272 | ) 273 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/NXTPOP/teritori-chain 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/CosmWasm/wasmd v0.27.0 7 | github.com/cosmos/cosmos-sdk v0.45.4 8 | github.com/cosmos/ibc-go/v3 v3.0.0 9 | github.com/ethereum/go-ethereum v1.10.16 10 | github.com/gagliardetto/solana-go v1.2.0 11 | github.com/gogo/protobuf v1.3.3 12 | github.com/golang/protobuf v1.5.2 13 | github.com/gorilla/mux v1.8.0 14 | github.com/gravity-devs/liquidity v1.4.4 15 | github.com/grpc-ecosystem/grpc-gateway v1.16.0 16 | github.com/prometheus/client_golang v1.12.1 17 | github.com/rakyll/statik v0.1.7 18 | github.com/regen-network/cosmos-proto v0.3.1 19 | github.com/spf13/cast v1.4.1 20 | github.com/spf13/cobra v1.4.0 21 | github.com/stretchr/testify v1.7.1 22 | github.com/tendermint/tendermint v0.34.19 23 | github.com/tendermint/tm-db v0.6.7 24 | google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac 25 | google.golang.org/grpc v1.45.0 26 | google.golang.org/protobuf v1.28.0 27 | ) 28 | 29 | require ( 30 | contrib.go.opencensus.io/exporter/stackdriver v0.13.4 // indirect 31 | filippo.io/edwards25519 v1.0.0-rc.1 // indirect 32 | github.com/99designs/keyring v1.1.6 // indirect 33 | github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect 34 | github.com/CosmWasm/wasmvm v1.0.0 // indirect 35 | github.com/DataDog/zstd v1.4.5 // indirect 36 | github.com/Workiva/go-datastructures v1.0.53 // indirect 37 | github.com/armon/go-metrics v0.3.10 // indirect 38 | github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59 // indirect 39 | github.com/beorn7/perks v1.0.1 // indirect 40 | github.com/bgentry/speakeasy v0.1.0 // indirect 41 | github.com/blendle/zapdriver v1.3.1 // indirect 42 | github.com/btcsuite/btcd v0.22.0-beta // indirect 43 | github.com/cespare/xxhash v1.1.0 // indirect 44 | github.com/cespare/xxhash/v2 v2.1.2 // indirect 45 | github.com/coinbase/rosetta-sdk-go v0.7.0 // indirect 46 | github.com/confio/ics23/go v0.7.0 // indirect 47 | github.com/cosmos/btcutil v1.0.4 // indirect 48 | github.com/cosmos/go-bip39 v1.0.0 // indirect 49 | github.com/cosmos/gorocksdb v1.2.0 // indirect 50 | github.com/cosmos/iavl v0.17.3 // indirect 51 | github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect 52 | github.com/cosmos/ledger-go v0.9.2 // indirect 53 | github.com/danieljoos/wincred v1.0.2 // indirect 54 | github.com/davecgh/go-spew v1.1.1 // indirect 55 | github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect 56 | github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 // indirect 57 | github.com/dgraph-io/badger/v2 v2.2007.2 // indirect 58 | github.com/dgraph-io/ristretto v0.0.3 // indirect 59 | github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect 60 | github.com/dustin/go-humanize v1.0.0 // indirect 61 | github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect 62 | github.com/fatih/color v1.13.0 // indirect 63 | github.com/felixge/httpsnoop v1.0.1 // indirect 64 | github.com/fsnotify/fsnotify v1.5.1 // indirect 65 | github.com/gagliardetto/binary v0.6.1 // indirect 66 | github.com/gagliardetto/treeout v0.1.4 // indirect 67 | github.com/go-kit/kit v0.12.0 // indirect 68 | github.com/go-kit/log v0.2.0 // indirect 69 | github.com/go-logfmt/logfmt v0.5.1 // indirect 70 | github.com/go-playground/validator/v10 v10.4.1 // indirect 71 | github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect 72 | github.com/gogo/gateway v1.1.0 // indirect 73 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 74 | github.com/golang/snappy v0.0.4 // indirect 75 | github.com/google/btree v1.0.0 // indirect 76 | github.com/google/gofuzz v1.2.0 // indirect 77 | github.com/google/orderedcode v0.0.1 // indirect 78 | github.com/gorilla/handlers v1.5.1 // indirect 79 | github.com/gorilla/websocket v1.5.0 // indirect 80 | github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect 81 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.1 // indirect 82 | github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect 83 | github.com/gtank/merlin v0.1.1 // indirect 84 | github.com/gtank/ristretto255 v0.1.2 // indirect 85 | github.com/hashicorp/go-immutable-radix v1.3.1 // indirect 86 | github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect 87 | github.com/hashicorp/hcl v1.0.0 // indirect 88 | github.com/improbable-eng/grpc-web v0.14.1 // indirect 89 | github.com/inconshreveable/mousetrap v1.0.0 // indirect 90 | github.com/jmhodges/levigo v1.0.0 // indirect 91 | github.com/json-iterator/go v1.1.12 // indirect 92 | github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect 93 | github.com/klauspost/compress v1.13.6 // indirect 94 | github.com/lib/pq v1.10.4 // indirect 95 | github.com/libp2p/go-buffer-pool v0.0.2 // indirect 96 | github.com/logrusorgru/aurora v2.0.3+incompatible // indirect 97 | github.com/magiconair/properties v1.8.6 // indirect 98 | github.com/mattn/go-colorable v0.1.12 // indirect 99 | github.com/mattn/go-isatty v0.0.14 // indirect 100 | github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect 101 | github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect 102 | github.com/minio/highwayhash v1.0.2 // indirect 103 | github.com/mitchellh/go-homedir v1.1.0 // indirect 104 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect 105 | github.com/mitchellh/mapstructure v1.4.3 // indirect 106 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 107 | github.com/modern-go/reflect2 v1.0.2 // indirect 108 | github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1 // indirect 109 | github.com/mr-tron/base58 v1.2.0 // indirect 110 | github.com/mtibben/percent v0.2.1 // indirect 111 | github.com/pelletier/go-toml v1.9.4 // indirect 112 | github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect 113 | github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect 114 | github.com/pkg/errors v0.9.1 // indirect 115 | github.com/pmezard/go-difflib v1.0.0 // indirect 116 | github.com/prometheus/client_model v0.2.0 // indirect 117 | github.com/prometheus/common v0.32.1 // indirect 118 | github.com/prometheus/procfs v0.7.3 // indirect 119 | github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect 120 | github.com/rs/cors v1.8.2 // indirect 121 | github.com/rs/zerolog v1.26.0 // indirect 122 | github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect 123 | github.com/spf13/afero v1.8.2 // indirect 124 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 125 | github.com/spf13/pflag v1.0.5 // indirect 126 | github.com/spf13/viper v1.11.0 // indirect 127 | github.com/subosito/gotenv v1.2.0 // indirect 128 | github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect 129 | github.com/tendermint/btcd v0.1.1 // indirect 130 | github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect 131 | github.com/tendermint/go-amino v0.16.0 // indirect 132 | github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 // indirect 133 | github.com/tidwall/gjson v1.9.3 // indirect 134 | github.com/tidwall/match v1.1.1 // indirect 135 | github.com/tidwall/pretty v1.2.0 // indirect 136 | github.com/zondax/hid v0.9.0 // indirect 137 | go.etcd.io/bbolt v1.3.6 // indirect 138 | go.opencensus.io v0.23.0 // indirect 139 | go.uber.org/atomic v1.9.0 // indirect 140 | go.uber.org/multierr v1.7.0 // indirect 141 | go.uber.org/zap v1.19.1 // indirect 142 | golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect 143 | golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect 144 | golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect 145 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect 146 | golang.org/x/text v0.3.7 // indirect 147 | gopkg.in/ini.v1 v1.66.4 // indirect 148 | gopkg.in/yaml.v2 v2.4.0 // indirect 149 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect 150 | nhooyr.io/websocket v1.8.6 // indirect 151 | ) 152 | 153 | require ( 154 | github.com/cosmos/ibc-go/v2 v2.0.0 155 | github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect 156 | github.com/strangelove-ventures/packet-forward-middleware/v2 v2.1.1 157 | ) 158 | 159 | replace ( 160 | github.com/cosmos/iavl => github.com/cosmos/iavl v0.17.3 161 | github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 162 | google.golang.org/grpc => google.golang.org/grpc v1.33.2 163 | ) 164 | -------------------------------------------------------------------------------- /cmd/teritorid/cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | "os" 7 | "path/filepath" 8 | 9 | "github.com/cosmos/cosmos-sdk/baseapp" 10 | "github.com/cosmos/cosmos-sdk/client" 11 | "github.com/cosmos/cosmos-sdk/client/config" 12 | "github.com/cosmos/cosmos-sdk/client/debug" 13 | "github.com/cosmos/cosmos-sdk/client/flags" 14 | "github.com/cosmos/cosmos-sdk/client/keys" 15 | "github.com/cosmos/cosmos-sdk/client/rpc" 16 | "github.com/cosmos/cosmos-sdk/server" 17 | serverconfig "github.com/cosmos/cosmos-sdk/server/config" 18 | servertypes "github.com/cosmos/cosmos-sdk/server/types" 19 | "github.com/cosmos/cosmos-sdk/snapshots" 20 | "github.com/cosmos/cosmos-sdk/store" 21 | sdk "github.com/cosmos/cosmos-sdk/types" 22 | authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" 23 | "github.com/cosmos/cosmos-sdk/x/auth/types" 24 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" 25 | "github.com/cosmos/cosmos-sdk/x/crisis" 26 | genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" 27 | "github.com/spf13/cast" 28 | "github.com/spf13/cobra" 29 | tmcli "github.com/tendermint/tendermint/libs/cli" 30 | "github.com/tendermint/tendermint/libs/log" 31 | dbm "github.com/tendermint/tm-db" 32 | 33 | teritori "github.com/NXTPOP/teritori-chain/app" 34 | "github.com/NXTPOP/teritori-chain/app/params" 35 | ) 36 | 37 | // NewRootCmd creates a new root command for simd. It is called once in the 38 | // main function. 39 | func NewRootCmd() (*cobra.Command, params.EncodingConfig) { 40 | encodingConfig := teritori.MakeEncodingConfig() 41 | initClientCtx := client.Context{}. 42 | WithCodec(encodingConfig.Marshaler). 43 | WithInterfaceRegistry(encodingConfig.InterfaceRegistry). 44 | WithTxConfig(encodingConfig.TxConfig). 45 | WithLegacyAmino(encodingConfig.Amino). 46 | WithInput(os.Stdin). 47 | WithAccountRetriever(types.AccountRetriever{}). 48 | WithHomeDir(teritori.DefaultNodeHome). 49 | WithViper("") 50 | 51 | rootCmd := &cobra.Command{ 52 | Use: "teritorid", 53 | Short: "Stargate Cosmos Hub App", 54 | PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { 55 | initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) 56 | if err != nil { 57 | return err 58 | } 59 | 60 | initClientCtx, err = config.ReadFromClientConfig(initClientCtx) 61 | if err != nil { 62 | return err 63 | } 64 | 65 | if err = client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { 66 | return err 67 | } 68 | 69 | customTemplate, customNxtPopConfig := initAppConfig() 70 | return server.InterceptConfigsPreRunHandler(cmd, customTemplate, customNxtPopConfig) 71 | }, 72 | } 73 | 74 | initRootCmd(rootCmd, encodingConfig) 75 | 76 | return rootCmd, encodingConfig 77 | } 78 | 79 | func initAppConfig() (string, interface{}) { 80 | 81 | type CustomAppConfig struct { 82 | serverconfig.Config 83 | } 84 | 85 | // Allow overrides to the SDK default server config 86 | srvCfg := serverconfig.DefaultConfig() 87 | srvCfg.StateSync.SnapshotInterval = 1000 88 | srvCfg.StateSync.SnapshotKeepRecent = 10 89 | 90 | appCfg := CustomAppConfig{Config: *srvCfg} 91 | 92 | appTemplate := serverconfig.DefaultConfigTemplate 93 | 94 | return appTemplate, appCfg 95 | } 96 | 97 | func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { 98 | cfg := sdk.GetConfig() 99 | 100 | cfg.Seal() 101 | 102 | rootCmd.AddCommand( 103 | genutilcli.InitCmd(teritori.ModuleBasics, teritori.DefaultNodeHome), 104 | genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, teritori.DefaultNodeHome), 105 | genutilcli.GenTxCmd(teritori.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, teritori.DefaultNodeHome), 106 | genutilcli.ValidateGenesisCmd(teritori.ModuleBasics), 107 | AddGenesisAccountCmd(teritori.DefaultNodeHome), 108 | tmcli.NewCompletionCmd(rootCmd, true), 109 | testnetCmd(teritori.ModuleBasics, banktypes.GenesisBalancesIterator{}), 110 | debug.Cmd(), 111 | config.Cmd(), 112 | ) 113 | 114 | ac := appCreator{ 115 | encCfg: encodingConfig, 116 | } 117 | server.AddCommands(rootCmd, teritori.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags) 118 | 119 | // add keybase, auxiliary RPC, query, and tx child commands 120 | rootCmd.AddCommand( 121 | rpc.StatusCommand(), 122 | queryCommand(), 123 | txCommand(), 124 | keys.Commands(teritori.DefaultNodeHome), 125 | ) 126 | } 127 | 128 | func addModuleInitFlags(startCmd *cobra.Command) { 129 | crisis.AddModuleInitFlags(startCmd) 130 | } 131 | 132 | func queryCommand() *cobra.Command { 133 | cmd := &cobra.Command{ 134 | Use: "query", 135 | Aliases: []string{"q"}, 136 | Short: "Querying subcommands", 137 | DisableFlagParsing: true, 138 | SuggestionsMinimumDistance: 2, 139 | RunE: client.ValidateCmd, 140 | } 141 | 142 | cmd.AddCommand( 143 | authcmd.GetAccountCmd(), 144 | rpc.ValidatorCommand(), 145 | rpc.BlockCommand(), 146 | authcmd.QueryTxsByEventsCmd(), 147 | authcmd.QueryTxCmd(), 148 | ) 149 | 150 | teritori.ModuleBasics.AddQueryCommands(cmd) 151 | cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") 152 | 153 | return cmd 154 | } 155 | 156 | func txCommand() *cobra.Command { 157 | cmd := &cobra.Command{ 158 | Use: "tx", 159 | Short: "Transactions subcommands", 160 | DisableFlagParsing: true, 161 | SuggestionsMinimumDistance: 2, 162 | RunE: client.ValidateCmd, 163 | } 164 | 165 | cmd.AddCommand( 166 | authcmd.GetSignCommand(), 167 | authcmd.GetSignBatchCommand(), 168 | authcmd.GetMultiSignCommand(), 169 | authcmd.GetMultiSignBatchCmd(), 170 | authcmd.GetValidateSignaturesCommand(), 171 | flags.LineBreak, 172 | authcmd.GetBroadcastCommand(), 173 | authcmd.GetEncodeCommand(), 174 | authcmd.GetDecodeCommand(), 175 | ) 176 | 177 | teritori.ModuleBasics.AddTxCommands(cmd) 178 | cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") 179 | 180 | return cmd 181 | } 182 | 183 | type appCreator struct { 184 | encCfg params.EncodingConfig 185 | } 186 | 187 | func (ac appCreator) newApp( 188 | logger log.Logger, 189 | db dbm.DB, 190 | traceStore io.Writer, 191 | appOpts servertypes.AppOptions, 192 | ) servertypes.Application { 193 | 194 | var cache sdk.MultiStorePersistentCache 195 | 196 | if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { 197 | cache = store.NewCommitKVStoreCacheManager() 198 | } 199 | 200 | skipUpgradeHeights := make(map[int64]bool) 201 | for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { 202 | skipUpgradeHeights[int64(h)] = true 203 | } 204 | 205 | pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts) 206 | if err != nil { 207 | panic(err) 208 | } 209 | 210 | snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") 211 | snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir) 212 | if err != nil { 213 | panic(err) 214 | } 215 | snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) 216 | if err != nil { 217 | panic(err) 218 | } 219 | 220 | return teritori.NewTeritoriApp( 221 | logger, db, traceStore, true, skipUpgradeHeights, 222 | cast.ToString(appOpts.Get(flags.FlagHome)), 223 | cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), 224 | ac.encCfg, 225 | appOpts, 226 | baseapp.SetPruning(pruningOpts), 227 | baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), 228 | baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), 229 | baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))), 230 | baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))), 231 | baseapp.SetInterBlockCache(cache), 232 | baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))), 233 | baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))), 234 | baseapp.SetSnapshotStore(snapshotStore), 235 | baseapp.SetSnapshotInterval(cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval))), 236 | baseapp.SetSnapshotKeepRecent(cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent))), 237 | ) 238 | } 239 | 240 | func (ac appCreator) appExport( 241 | logger log.Logger, 242 | db dbm.DB, 243 | traceStore io.Writer, 244 | height int64, 245 | forZeroHeight bool, 246 | jailAllowedAddrs []string, 247 | appOpts servertypes.AppOptions, 248 | ) (servertypes.ExportedApp, error) { 249 | 250 | homePath, ok := appOpts.Get(flags.FlagHome).(string) 251 | if !ok || homePath == "" { 252 | return servertypes.ExportedApp{}, errors.New("application home is not set") 253 | } 254 | 255 | var loadLatest bool 256 | if height == -1 { 257 | loadLatest = true 258 | } 259 | 260 | teritoriApp := teritori.NewTeritoriApp( 261 | logger, 262 | db, 263 | traceStore, 264 | loadLatest, 265 | map[int64]bool{}, 266 | homePath, 267 | cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), 268 | ac.encCfg, 269 | appOpts, 270 | ) 271 | 272 | if height != -1 { 273 | if err := teritoriApp.LoadHeight(height); err != nil { 274 | return servertypes.ExportedApp{}, err 275 | } 276 | } 277 | 278 | return teritoriApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) 279 | } 280 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | BRANCH := $(shell git rev-parse --abbrev-ref HEAD) 4 | COMMIT := $(shell git log -1 --format='%H') 5 | 6 | # don't override user values 7 | ifeq (,$(VERSION)) 8 | VERSION := $(shell git describe --exact-match 2>/dev/null) 9 | # if VERSION is empty, then populate it with branch's name and raw commit hash 10 | ifeq (,$(VERSION)) 11 | VERSION := $(BRANCH)-$(COMMIT) 12 | endif 13 | endif 14 | 15 | PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') 16 | LEDGER_ENABLED ?= true 17 | SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') 18 | TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7" 19 | DOCKER := $(shell which docker) 20 | BUILDDIR ?= $(CURDIR)/build 21 | TEST_DOCKER_REPO=jackzampolin/teritoritest 22 | 23 | export GO111MODULE = on 24 | 25 | # process build tags 26 | 27 | build_tags = netgo 28 | ifeq ($(LEDGER_ENABLED),true) 29 | ifeq ($(OS),Windows_NT) 30 | GCCEXE = $(shell where gcc.exe 2> NUL) 31 | ifeq ($(GCCEXE),) 32 | $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) 33 | else 34 | build_tags += ledger 35 | endif 36 | else 37 | UNAME_S = $(shell uname -s) 38 | ifeq ($(UNAME_S),OpenBSD) 39 | $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) 40 | else 41 | GCC = $(shell command -v gcc 2> /dev/null) 42 | ifeq ($(GCC),) 43 | $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) 44 | else 45 | build_tags += ledger 46 | endif 47 | endif 48 | endif 49 | endif 50 | 51 | ifeq (cleveldb,$(findstring cleveldb,$(NXTPOP_BUILD_OPTIONS))) 52 | build_tags += gcc cleveldb 53 | endif 54 | build_tags += $(BUILD_TAGS) 55 | build_tags := $(strip $(build_tags)) 56 | 57 | whitespace := 58 | whitespace += $(whitespace) 59 | comma := , 60 | build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) 61 | 62 | # process linker flags 63 | 64 | ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=teritori \ 65 | -X github.com/cosmos/cosmos-sdk/version.AppName=teritorid \ 66 | -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ 67 | -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ 68 | -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ 69 | -X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION) 70 | 71 | ifeq (cleveldb,$(findstring cleveldb,$(NXTPOP_BUILD_OPTIONS))) 72 | ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb 73 | endif 74 | ifeq (,$(findstring nostrip,$(NXTPOP_BUILD_OPTIONS))) 75 | ldflags += -w -s 76 | endif 77 | ldflags += $(LDFLAGS) 78 | ldflags := $(strip $(ldflags)) 79 | 80 | BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' 81 | # check for nostrip option 82 | ifeq (,$(findstring nostrip,$(NXTPOP_BUILD_OPTIONS))) 83 | BUILD_FLAGS += -trimpath 84 | endif 85 | 86 | #$(info $$BUILD_FLAGS is [$(BUILD_FLAGS)]) 87 | 88 | # The below include contains the tools target. 89 | 90 | ############################################################################### 91 | ### Documentation ### 92 | ############################################################################### 93 | 94 | all: install lint test 95 | 96 | BUILD_TARGETS := build install 97 | 98 | build: BUILD_ARGS=-o $(BUILDDIR)/ 99 | 100 | $(BUILD_TARGETS): go.sum $(BUILDDIR)/ 101 | go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... 102 | 103 | $(BUILDDIR)/: 104 | mkdir -p $(BUILDDIR)/ 105 | 106 | build-reproducible: go.sum 107 | $(DOCKER) rm latest-build || true 108 | $(DOCKER) run --volume=$(CURDIR):/sources:ro \ 109 | --env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64 windows/amd64' \ 110 | --env APP=teritorid \ 111 | --env VERSION=$(VERSION) \ 112 | --env COMMIT=$(COMMIT) \ 113 | --env LEDGER_ENABLED=$(LEDGER_ENABLED) \ 114 | --name latest-build cosmossdk/rbuilder:latest 115 | $(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/ 116 | 117 | build-linux: go.sum 118 | LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build 119 | 120 | build-contract-tests-hooks: 121 | mkdir -p $(BUILDDIR) 122 | go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./cmd/contract_tests 123 | 124 | go-mod-cache: go.sum 125 | @echo "--> Download go modules to local cache" 126 | @go mod download 127 | 128 | go.sum: go.mod 129 | @echo "--> Ensure dependencies have not been modified" 130 | @go mod verify 131 | 132 | draw-deps: 133 | @# requires brew install graphviz or apt-get install graphviz 134 | go get github.com/RobotsAndPencils/goviz 135 | @goviz -i ./cmd/teritorid -d 2 | dot -Tpng -o dependency-graph.png 136 | 137 | clean: 138 | rm -rf $(BUILDDIR)/ artifacts/ 139 | 140 | distclean: clean 141 | rm -rf vendor/ 142 | 143 | ############################################################################### 144 | ### Devdoc ### 145 | ############################################################################### 146 | 147 | build-docs: 148 | @cd docs && \ 149 | while read p; do \ 150 | (git checkout $${p} && npm install && VUEPRESS_BASE="/$${p}/" npm run build) ; \ 151 | mkdir -p ~/output/$${p} ; \ 152 | cp -r .vuepress/dist/* ~/output/$${p}/ ; \ 153 | cp ~/output/$${p}/index.html ~/output ; \ 154 | done < versions ; 155 | .PHONY: build-docs 156 | 157 | sync-docs: 158 | cd ~/output && \ 159 | echo "role_arn = ${DEPLOYMENT_ROLE_ARN}" >> /root/.aws/config ; \ 160 | echo "CI job = ${CIRCLE_BUILD_URL}" >> version.html ; \ 161 | aws s3 sync . s3://${WEBSITE_BUCKET} --profile terraform --delete ; \ 162 | aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ; 163 | .PHONY: sync-docs 164 | 165 | 166 | ############################################################################### 167 | ### Tests & Simulation ### 168 | ############################################################################### 169 | 170 | include sims.mk 171 | 172 | test: test-unit test-build 173 | 174 | test-all: check test-race test-cover 175 | 176 | test-unit: 177 | @VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./... 178 | 179 | test-race: 180 | @VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' ./... 181 | 182 | test-cover: 183 | @go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./... 184 | 185 | benchmark: 186 | @go test -mod=readonly -bench=. ./... 187 | 188 | 189 | ############################################################################### 190 | ### Linting ### 191 | ############################################################################### 192 | 193 | lint: 194 | golangci-lint run 195 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s 196 | 197 | format: 198 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s 199 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w 200 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk 201 | 202 | ############################################################################### 203 | ### Localnet ### 204 | ############################################################################### 205 | 206 | build-docker-teritoridnode: 207 | $(MAKE) -C networks/local 208 | 209 | # Run a 4-node testnet locally 210 | localnet-start: build-linux localnet-stop 211 | @if ! [ -f build/node0/teritorid/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/teritorid:Z tendermint/teritoridnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi 212 | docker-compose up -d 213 | 214 | # Stop testnet 215 | localnet-stop: 216 | docker-compose down 217 | 218 | test-docker: 219 | @docker build -f contrib/Dockerfile.test -t ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) . 220 | @docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g') 221 | @docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:latest 222 | 223 | test-docker-push: test-docker 224 | @docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) 225 | @docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g') 226 | @docker push ${TEST_DOCKER_REPO}:latest 227 | 228 | .PHONY: all build-linux install format lint \ 229 | go-mod-cache draw-deps clean build \ 230 | setup-transactions setup-contract-tests-data start-teritori run-lcd-contract-tests contract-tests \ 231 | test test-all test-build test-cover test-unit test-race \ 232 | benchmark \ 233 | build-docker-teritoridnode localnet-start localnet-stop \ 234 | docker-single-node 235 | 236 | protoVer=v0.2 237 | protoImageName=tendermintdev/sdk-proto-gen:$(protoVer) 238 | containerProtoGen=teritori-proto-gen-$(protoVer) 239 | 240 | proto-gen: 241 | @echo "Generating Protobuf files" 242 | @if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \ 243 | sh ./scripts/protocgen.sh; fi 244 | -------------------------------------------------------------------------------- /x/nftstaking/types/genesis.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: teritori/nftstaking/v1beta1/genesis.proto 3 | 4 | package types 5 | 6 | import ( 7 | fmt "fmt" 8 | _ "github.com/gogo/protobuf/gogoproto" 9 | proto "github.com/gogo/protobuf/proto" 10 | io "io" 11 | math "math" 12 | math_bits "math/bits" 13 | ) 14 | 15 | // Reference imports to suppress errors if they are not otherwise used. 16 | var _ = proto.Marshal 17 | var _ = fmt.Errorf 18 | var _ = math.Inf 19 | 20 | // This is a compile-time assertion to ensure that this generated file 21 | // is compatible with the proto package it is being compiled against. 22 | // A compilation error at this line likely means your copy of the 23 | // proto package needs to be updated. 24 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 25 | 26 | type GenesisState struct { 27 | NftStakings []NftStaking `protobuf:"bytes,1,rep,name=nft_stakings,json=nftStakings,proto3" json:"nft_stakings"` 28 | } 29 | 30 | func (m *GenesisState) Reset() { *m = GenesisState{} } 31 | func (m *GenesisState) String() string { return proto.CompactTextString(m) } 32 | func (*GenesisState) ProtoMessage() {} 33 | func (*GenesisState) Descriptor() ([]byte, []int) { 34 | return fileDescriptor_f3bdd74a405c00b8, []int{0} 35 | } 36 | func (m *GenesisState) XXX_Unmarshal(b []byte) error { 37 | return m.Unmarshal(b) 38 | } 39 | func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 40 | if deterministic { 41 | return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) 42 | } else { 43 | b = b[:cap(b)] 44 | n, err := m.MarshalToSizedBuffer(b) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return b[:n], nil 49 | } 50 | } 51 | func (m *GenesisState) XXX_Merge(src proto.Message) { 52 | xxx_messageInfo_GenesisState.Merge(m, src) 53 | } 54 | func (m *GenesisState) XXX_Size() int { 55 | return m.Size() 56 | } 57 | func (m *GenesisState) XXX_DiscardUnknown() { 58 | xxx_messageInfo_GenesisState.DiscardUnknown(m) 59 | } 60 | 61 | var xxx_messageInfo_GenesisState proto.InternalMessageInfo 62 | 63 | func (m *GenesisState) GetNftStakings() []NftStaking { 64 | if m != nil { 65 | return m.NftStakings 66 | } 67 | return nil 68 | } 69 | 70 | func init() { 71 | proto.RegisterType((*GenesisState)(nil), "teritori.nftstaking.v1beta1.GenesisState") 72 | } 73 | 74 | func init() { 75 | proto.RegisterFile("teritori/nftstaking/v1beta1/genesis.proto", fileDescriptor_f3bdd74a405c00b8) 76 | } 77 | 78 | var fileDescriptor_f3bdd74a405c00b8 = []byte{ 79 | // 222 bytes of a gzipped FileDescriptorProto 80 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x49, 0x2d, 0xca, 81 | 0x2c, 0xc9, 0x2f, 0xca, 0xd4, 0xcf, 0x4b, 0x2b, 0x29, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xd7, 82 | 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 83 | 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x86, 0x29, 0xd5, 0x43, 0x28, 0xd5, 0x83, 0x2a, 0x95, 84 | 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd3, 0x07, 0xb1, 0x20, 0x5a, 0xa4, 0x74, 0xf0, 0x99, 85 | 0x8e, 0x64, 0x0a, 0x58, 0xb5, 0x52, 0x02, 0x17, 0x8f, 0x3b, 0xc4, 0xc6, 0xe0, 0x92, 0xc4, 0x92, 86 | 0x54, 0xa1, 0x00, 0x2e, 0x9e, 0xbc, 0xb4, 0x92, 0x78, 0xa8, 0xa2, 0x62, 0x09, 0x46, 0x05, 0x66, 87 | 0x0d, 0x6e, 0x23, 0x75, 0x3d, 0x3c, 0xee, 0xd0, 0xf3, 0x4b, 0x2b, 0x09, 0x86, 0x08, 0x39, 0xb1, 88 | 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0xc4, 0x9d, 0x07, 0x17, 0x29, 0x76, 0xf2, 0x3d, 0xf1, 0x48, 0x8e, 89 | 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 90 | 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xe3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 91 | 0xfc, 0x5c, 0x7d, 0xbf, 0x88, 0x90, 0x00, 0xff, 0x00, 0x7d, 0x98, 0x35, 0xba, 0xc9, 0x19, 0x89, 92 | 0x99, 0x79, 0xfa, 0x15, 0xc8, 0x7e, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xbb, 0xdb, 93 | 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x2c, 0x49, 0x17, 0xfa, 0x45, 0x01, 0x00, 0x00, 94 | } 95 | 96 | func (m *GenesisState) Marshal() (dAtA []byte, err error) { 97 | size := m.Size() 98 | dAtA = make([]byte, size) 99 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 100 | if err != nil { 101 | return nil, err 102 | } 103 | return dAtA[:n], nil 104 | } 105 | 106 | func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { 107 | size := m.Size() 108 | return m.MarshalToSizedBuffer(dAtA[:size]) 109 | } 110 | 111 | func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { 112 | i := len(dAtA) 113 | _ = i 114 | var l int 115 | _ = l 116 | if len(m.NftStakings) > 0 { 117 | for iNdEx := len(m.NftStakings) - 1; iNdEx >= 0; iNdEx-- { 118 | { 119 | size, err := m.NftStakings[iNdEx].MarshalToSizedBuffer(dAtA[:i]) 120 | if err != nil { 121 | return 0, err 122 | } 123 | i -= size 124 | i = encodeVarintGenesis(dAtA, i, uint64(size)) 125 | } 126 | i-- 127 | dAtA[i] = 0xa 128 | } 129 | } 130 | return len(dAtA) - i, nil 131 | } 132 | 133 | func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { 134 | offset -= sovGenesis(v) 135 | base := offset 136 | for v >= 1<<7 { 137 | dAtA[offset] = uint8(v&0x7f | 0x80) 138 | v >>= 7 139 | offset++ 140 | } 141 | dAtA[offset] = uint8(v) 142 | return base 143 | } 144 | func (m *GenesisState) Size() (n int) { 145 | if m == nil { 146 | return 0 147 | } 148 | var l int 149 | _ = l 150 | if len(m.NftStakings) > 0 { 151 | for _, e := range m.NftStakings { 152 | l = e.Size() 153 | n += 1 + l + sovGenesis(uint64(l)) 154 | } 155 | } 156 | return n 157 | } 158 | 159 | func sovGenesis(x uint64) (n int) { 160 | return (math_bits.Len64(x|1) + 6) / 7 161 | } 162 | func sozGenesis(x uint64) (n int) { 163 | return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) 164 | } 165 | func (m *GenesisState) Unmarshal(dAtA []byte) error { 166 | l := len(dAtA) 167 | iNdEx := 0 168 | for iNdEx < l { 169 | preIndex := iNdEx 170 | var wire uint64 171 | for shift := uint(0); ; shift += 7 { 172 | if shift >= 64 { 173 | return ErrIntOverflowGenesis 174 | } 175 | if iNdEx >= l { 176 | return io.ErrUnexpectedEOF 177 | } 178 | b := dAtA[iNdEx] 179 | iNdEx++ 180 | wire |= uint64(b&0x7F) << shift 181 | if b < 0x80 { 182 | break 183 | } 184 | } 185 | fieldNum := int32(wire >> 3) 186 | wireType := int(wire & 0x7) 187 | if wireType == 4 { 188 | return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") 189 | } 190 | if fieldNum <= 0 { 191 | return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) 192 | } 193 | switch fieldNum { 194 | case 1: 195 | if wireType != 2 { 196 | return fmt.Errorf("proto: wrong wireType = %d for field NftStakings", wireType) 197 | } 198 | var msglen int 199 | for shift := uint(0); ; shift += 7 { 200 | if shift >= 64 { 201 | return ErrIntOverflowGenesis 202 | } 203 | if iNdEx >= l { 204 | return io.ErrUnexpectedEOF 205 | } 206 | b := dAtA[iNdEx] 207 | iNdEx++ 208 | msglen |= int(b&0x7F) << shift 209 | if b < 0x80 { 210 | break 211 | } 212 | } 213 | if msglen < 0 { 214 | return ErrInvalidLengthGenesis 215 | } 216 | postIndex := iNdEx + msglen 217 | if postIndex < 0 { 218 | return ErrInvalidLengthGenesis 219 | } 220 | if postIndex > l { 221 | return io.ErrUnexpectedEOF 222 | } 223 | m.NftStakings = append(m.NftStakings, NftStaking{}) 224 | if err := m.NftStakings[len(m.NftStakings)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 225 | return err 226 | } 227 | iNdEx = postIndex 228 | default: 229 | iNdEx = preIndex 230 | skippy, err := skipGenesis(dAtA[iNdEx:]) 231 | if err != nil { 232 | return err 233 | } 234 | if (skippy < 0) || (iNdEx+skippy) < 0 { 235 | return ErrInvalidLengthGenesis 236 | } 237 | if (iNdEx + skippy) > l { 238 | return io.ErrUnexpectedEOF 239 | } 240 | iNdEx += skippy 241 | } 242 | } 243 | 244 | if iNdEx > l { 245 | return io.ErrUnexpectedEOF 246 | } 247 | return nil 248 | } 249 | func skipGenesis(dAtA []byte) (n int, err error) { 250 | l := len(dAtA) 251 | iNdEx := 0 252 | depth := 0 253 | for iNdEx < l { 254 | var wire uint64 255 | for shift := uint(0); ; shift += 7 { 256 | if shift >= 64 { 257 | return 0, ErrIntOverflowGenesis 258 | } 259 | if iNdEx >= l { 260 | return 0, io.ErrUnexpectedEOF 261 | } 262 | b := dAtA[iNdEx] 263 | iNdEx++ 264 | wire |= (uint64(b) & 0x7F) << shift 265 | if b < 0x80 { 266 | break 267 | } 268 | } 269 | wireType := int(wire & 0x7) 270 | switch wireType { 271 | case 0: 272 | for shift := uint(0); ; shift += 7 { 273 | if shift >= 64 { 274 | return 0, ErrIntOverflowGenesis 275 | } 276 | if iNdEx >= l { 277 | return 0, io.ErrUnexpectedEOF 278 | } 279 | iNdEx++ 280 | if dAtA[iNdEx-1] < 0x80 { 281 | break 282 | } 283 | } 284 | case 1: 285 | iNdEx += 8 286 | case 2: 287 | var length int 288 | for shift := uint(0); ; shift += 7 { 289 | if shift >= 64 { 290 | return 0, ErrIntOverflowGenesis 291 | } 292 | if iNdEx >= l { 293 | return 0, io.ErrUnexpectedEOF 294 | } 295 | b := dAtA[iNdEx] 296 | iNdEx++ 297 | length |= (int(b) & 0x7F) << shift 298 | if b < 0x80 { 299 | break 300 | } 301 | } 302 | if length < 0 { 303 | return 0, ErrInvalidLengthGenesis 304 | } 305 | iNdEx += length 306 | case 3: 307 | depth++ 308 | case 4: 309 | if depth == 0 { 310 | return 0, ErrUnexpectedEndOfGroupGenesis 311 | } 312 | depth-- 313 | case 5: 314 | iNdEx += 4 315 | default: 316 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType) 317 | } 318 | if iNdEx < 0 { 319 | return 0, ErrInvalidLengthGenesis 320 | } 321 | if depth == 0 { 322 | return iNdEx, nil 323 | } 324 | } 325 | return 0, io.ErrUnexpectedEOF 326 | } 327 | 328 | var ( 329 | ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") 330 | ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") 331 | ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") 332 | ) 333 | -------------------------------------------------------------------------------- /x/airdrop/types/genesis.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: teritori/airdrop/v1beta1/genesis.proto 3 | 4 | package types 5 | 6 | import ( 7 | fmt "fmt" 8 | _ "github.com/cosmos/cosmos-sdk/types" 9 | _ "github.com/cosmos/cosmos-sdk/x/bank/types" 10 | _ "github.com/gogo/protobuf/gogoproto" 11 | proto "github.com/gogo/protobuf/proto" 12 | _ "google.golang.org/protobuf/types/known/durationpb" 13 | _ "google.golang.org/protobuf/types/known/timestamppb" 14 | io "io" 15 | math "math" 16 | math_bits "math/bits" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // This is a compile-time assertion to ensure that this generated file 25 | // is compatible with the proto package it is being compiled against. 26 | // A compilation error at this line likely means your copy of the 27 | // proto package needs to be updated. 28 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 29 | 30 | // GenesisState defines the module's genesis state. 31 | type GenesisState struct { 32 | Allocations []*AirdropAllocation `protobuf:"bytes,1,rep,name=allocations,proto3" json:"allocations,omitempty"` 33 | } 34 | 35 | func (m *GenesisState) Reset() { *m = GenesisState{} } 36 | func (m *GenesisState) String() string { return proto.CompactTextString(m) } 37 | func (*GenesisState) ProtoMessage() {} 38 | func (*GenesisState) Descriptor() ([]byte, []int) { 39 | return fileDescriptor_70ea57bcfeb0bccc, []int{0} 40 | } 41 | func (m *GenesisState) XXX_Unmarshal(b []byte) error { 42 | return m.Unmarshal(b) 43 | } 44 | func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 45 | if deterministic { 46 | return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) 47 | } else { 48 | b = b[:cap(b)] 49 | n, err := m.MarshalToSizedBuffer(b) 50 | if err != nil { 51 | return nil, err 52 | } 53 | return b[:n], nil 54 | } 55 | } 56 | func (m *GenesisState) XXX_Merge(src proto.Message) { 57 | xxx_messageInfo_GenesisState.Merge(m, src) 58 | } 59 | func (m *GenesisState) XXX_Size() int { 60 | return m.Size() 61 | } 62 | func (m *GenesisState) XXX_DiscardUnknown() { 63 | xxx_messageInfo_GenesisState.DiscardUnknown(m) 64 | } 65 | 66 | var xxx_messageInfo_GenesisState proto.InternalMessageInfo 67 | 68 | func (m *GenesisState) GetAllocations() []*AirdropAllocation { 69 | if m != nil { 70 | return m.Allocations 71 | } 72 | return nil 73 | } 74 | 75 | func init() { 76 | proto.RegisterType((*GenesisState)(nil), "teritori.airdrop.v1beta1.GenesisState") 77 | } 78 | 79 | func init() { 80 | proto.RegisterFile("teritori/airdrop/v1beta1/genesis.proto", fileDescriptor_70ea57bcfeb0bccc) 81 | } 82 | 83 | var fileDescriptor_70ea57bcfeb0bccc = []byte{ 84 | // 274 bytes of a gzipped FileDescriptorProto 85 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xbd, 0x4a, 0xc4, 0x40, 86 | 0x14, 0x85, 0x13, 0x04, 0x8b, 0xac, 0xd5, 0x62, 0xb1, 0xa4, 0x18, 0x7f, 0x0a, 0x51, 0xc4, 0xb9, 87 | 0xae, 0x3e, 0xc1, 0xda, 0x08, 0x82, 0xba, 0xa8, 0x85, 0x08, 0x16, 0x33, 0xb3, 0xe3, 0xec, 0x60, 88 | 0x92, 0x1b, 0x66, 0x6e, 0x44, 0xdf, 0xc2, 0xc7, 0xb2, 0xdc, 0xd2, 0x52, 0x92, 0x17, 0x11, 0xf3, 89 | 0xe7, 0x22, 0x6e, 0x37, 0x97, 0xf3, 0xdd, 0x73, 0xce, 0xdc, 0x68, 0x8f, 0xb4, 0xb3, 0x84, 0xce, 90 | 0x82, 0xb0, 0x6e, 0xe6, 0x30, 0x87, 0x97, 0xb1, 0xd4, 0x24, 0xc6, 0x60, 0x74, 0xa6, 0xbd, 0xf5, 91 | 0x3c, 0x77, 0x48, 0x38, 0x1c, 0x75, 0x1c, 0x6f, 0x39, 0xde, 0x72, 0xf1, 0xa6, 0x41, 0x83, 0x35, 92 | 0x04, 0x3f, 0xaf, 0x86, 0x8f, 0x99, 0x42, 0x9f, 0xa2, 0x07, 0x29, 0xbc, 0xee, 0x2d, 0x15, 0xda, 93 | 0xac, 0xd5, 0x77, 0x7a, 0x3d, 0x7b, 0xfe, 0x3f, 0x32, 0x66, 0x06, 0xd1, 0x24, 0x1a, 0xea, 0x49, 94 | 0x16, 0x4f, 0x30, 0x2b, 0x9c, 0x20, 0x8b, 0x9d, 0xc5, 0xd6, 0x5f, 0x9d, 0x6c, 0xaa, 0x3d, 0x89, 95 | 0x34, 0x6f, 0x81, 0x83, 0x95, 0x7f, 0x13, 0x49, 0x82, 0x6a, 0xc9, 0x6b, 0xf7, 0x31, 0xda, 0x38, 96 | 0x6f, 0xc2, 0x6f, 0x49, 0x90, 0x1e, 0x5e, 0x46, 0x83, 0x5f, 0xc6, 0x8f, 0xc2, 0xed, 0xb5, 0xfd, 97 | 0xc1, 0xc9, 0x21, 0x5f, 0x75, 0x04, 0x3e, 0x69, 0xe6, 0x49, 0xbf, 0x73, 0xb3, 0xbc, 0x7f, 0x76, 98 | 0xf1, 0x51, 0xb2, 0x70, 0x51, 0xb2, 0xf0, 0xab, 0x64, 0xe1, 0x7b, 0xc5, 0x82, 0x45, 0xc5, 0x82, 99 | 0xcf, 0x8a, 0x05, 0x0f, 0xc7, 0xc6, 0xd2, 0xbc, 0x90, 0x5c, 0x61, 0x0a, 0x57, 0xf7, 0x77, 0xd3, 100 | 0xeb, 0x29, 0x74, 0x21, 0x47, 0x6a, 0x2e, 0x6c, 0x06, 0xaf, 0x7d, 0x7b, 0x7a, 0xcb, 0xb5, 0x97, 101 | 0xeb, 0x75, 0xe3, 0xd3, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x99, 0xd4, 0x09, 0xba, 0x01, 102 | 0x00, 0x00, 103 | } 104 | 105 | func (m *GenesisState) Marshal() (dAtA []byte, err error) { 106 | size := m.Size() 107 | dAtA = make([]byte, size) 108 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 109 | if err != nil { 110 | return nil, err 111 | } 112 | return dAtA[:n], nil 113 | } 114 | 115 | func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { 116 | size := m.Size() 117 | return m.MarshalToSizedBuffer(dAtA[:size]) 118 | } 119 | 120 | func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { 121 | i := len(dAtA) 122 | _ = i 123 | var l int 124 | _ = l 125 | if len(m.Allocations) > 0 { 126 | for iNdEx := len(m.Allocations) - 1; iNdEx >= 0; iNdEx-- { 127 | { 128 | size, err := m.Allocations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) 129 | if err != nil { 130 | return 0, err 131 | } 132 | i -= size 133 | i = encodeVarintGenesis(dAtA, i, uint64(size)) 134 | } 135 | i-- 136 | dAtA[i] = 0xa 137 | } 138 | } 139 | return len(dAtA) - i, nil 140 | } 141 | 142 | func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { 143 | offset -= sovGenesis(v) 144 | base := offset 145 | for v >= 1<<7 { 146 | dAtA[offset] = uint8(v&0x7f | 0x80) 147 | v >>= 7 148 | offset++ 149 | } 150 | dAtA[offset] = uint8(v) 151 | return base 152 | } 153 | func (m *GenesisState) Size() (n int) { 154 | if m == nil { 155 | return 0 156 | } 157 | var l int 158 | _ = l 159 | if len(m.Allocations) > 0 { 160 | for _, e := range m.Allocations { 161 | l = e.Size() 162 | n += 1 + l + sovGenesis(uint64(l)) 163 | } 164 | } 165 | return n 166 | } 167 | 168 | func sovGenesis(x uint64) (n int) { 169 | return (math_bits.Len64(x|1) + 6) / 7 170 | } 171 | func sozGenesis(x uint64) (n int) { 172 | return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) 173 | } 174 | func (m *GenesisState) Unmarshal(dAtA []byte) error { 175 | l := len(dAtA) 176 | iNdEx := 0 177 | for iNdEx < l { 178 | preIndex := iNdEx 179 | var wire uint64 180 | for shift := uint(0); ; shift += 7 { 181 | if shift >= 64 { 182 | return ErrIntOverflowGenesis 183 | } 184 | if iNdEx >= l { 185 | return io.ErrUnexpectedEOF 186 | } 187 | b := dAtA[iNdEx] 188 | iNdEx++ 189 | wire |= uint64(b&0x7F) << shift 190 | if b < 0x80 { 191 | break 192 | } 193 | } 194 | fieldNum := int32(wire >> 3) 195 | wireType := int(wire & 0x7) 196 | if wireType == 4 { 197 | return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") 198 | } 199 | if fieldNum <= 0 { 200 | return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) 201 | } 202 | switch fieldNum { 203 | case 1: 204 | if wireType != 2 { 205 | return fmt.Errorf("proto: wrong wireType = %d for field Allocations", wireType) 206 | } 207 | var msglen int 208 | for shift := uint(0); ; shift += 7 { 209 | if shift >= 64 { 210 | return ErrIntOverflowGenesis 211 | } 212 | if iNdEx >= l { 213 | return io.ErrUnexpectedEOF 214 | } 215 | b := dAtA[iNdEx] 216 | iNdEx++ 217 | msglen |= int(b&0x7F) << shift 218 | if b < 0x80 { 219 | break 220 | } 221 | } 222 | if msglen < 0 { 223 | return ErrInvalidLengthGenesis 224 | } 225 | postIndex := iNdEx + msglen 226 | if postIndex < 0 { 227 | return ErrInvalidLengthGenesis 228 | } 229 | if postIndex > l { 230 | return io.ErrUnexpectedEOF 231 | } 232 | m.Allocations = append(m.Allocations, &AirdropAllocation{}) 233 | if err := m.Allocations[len(m.Allocations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 234 | return err 235 | } 236 | iNdEx = postIndex 237 | default: 238 | iNdEx = preIndex 239 | skippy, err := skipGenesis(dAtA[iNdEx:]) 240 | if err != nil { 241 | return err 242 | } 243 | if (skippy < 0) || (iNdEx+skippy) < 0 { 244 | return ErrInvalidLengthGenesis 245 | } 246 | if (iNdEx + skippy) > l { 247 | return io.ErrUnexpectedEOF 248 | } 249 | iNdEx += skippy 250 | } 251 | } 252 | 253 | if iNdEx > l { 254 | return io.ErrUnexpectedEOF 255 | } 256 | return nil 257 | } 258 | func skipGenesis(dAtA []byte) (n int, err error) { 259 | l := len(dAtA) 260 | iNdEx := 0 261 | depth := 0 262 | for iNdEx < l { 263 | var wire uint64 264 | for shift := uint(0); ; shift += 7 { 265 | if shift >= 64 { 266 | return 0, ErrIntOverflowGenesis 267 | } 268 | if iNdEx >= l { 269 | return 0, io.ErrUnexpectedEOF 270 | } 271 | b := dAtA[iNdEx] 272 | iNdEx++ 273 | wire |= (uint64(b) & 0x7F) << shift 274 | if b < 0x80 { 275 | break 276 | } 277 | } 278 | wireType := int(wire & 0x7) 279 | switch wireType { 280 | case 0: 281 | for shift := uint(0); ; shift += 7 { 282 | if shift >= 64 { 283 | return 0, ErrIntOverflowGenesis 284 | } 285 | if iNdEx >= l { 286 | return 0, io.ErrUnexpectedEOF 287 | } 288 | iNdEx++ 289 | if dAtA[iNdEx-1] < 0x80 { 290 | break 291 | } 292 | } 293 | case 1: 294 | iNdEx += 8 295 | case 2: 296 | var length int 297 | for shift := uint(0); ; shift += 7 { 298 | if shift >= 64 { 299 | return 0, ErrIntOverflowGenesis 300 | } 301 | if iNdEx >= l { 302 | return 0, io.ErrUnexpectedEOF 303 | } 304 | b := dAtA[iNdEx] 305 | iNdEx++ 306 | length |= (int(b) & 0x7F) << shift 307 | if b < 0x80 { 308 | break 309 | } 310 | } 311 | if length < 0 { 312 | return 0, ErrInvalidLengthGenesis 313 | } 314 | iNdEx += length 315 | case 3: 316 | depth++ 317 | case 4: 318 | if depth == 0 { 319 | return 0, ErrUnexpectedEndOfGroupGenesis 320 | } 321 | depth-- 322 | case 5: 323 | iNdEx += 4 324 | default: 325 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType) 326 | } 327 | if iNdEx < 0 { 328 | return 0, ErrInvalidLengthGenesis 329 | } 330 | if depth == 0 { 331 | return iNdEx, nil 332 | } 333 | } 334 | return 0, io.ErrUnexpectedEOF 335 | } 336 | 337 | var ( 338 | ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") 339 | ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") 340 | ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") 341 | ) 342 | -------------------------------------------------------------------------------- /x/nftstaking/types/nftstaking.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: teritori/nftstaking/v1beta1/nftstaking.proto 3 | 4 | package types 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "github.com/gogo/protobuf/proto" 9 | io "io" 10 | math "math" 11 | math_bits "math/bits" 12 | ) 13 | 14 | // Reference imports to suppress errors if they are not otherwise used. 15 | var _ = proto.Marshal 16 | var _ = fmt.Errorf 17 | var _ = math.Inf 18 | 19 | // This is a compile-time assertion to ensure that this generated file 20 | // is compatible with the proto package it is being compiled against. 21 | // A compilation error at this line likely means your copy of the 22 | // proto package needs to be updated. 23 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 24 | 25 | type NftStaking struct { 26 | NftIdentifier string `protobuf:"bytes,1,opt,name=nft_identifier,json=nftIdentifier,proto3" json:"nft_identifier,omitempty"` 27 | NftMetadata string `protobuf:"bytes,2,opt,name=nft_metadata,json=nftMetadata,proto3" json:"nft_metadata,omitempty"` 28 | RewardAddress string `protobuf:"bytes,3,opt,name=reward_address,json=rewardAddress,proto3" json:"reward_address,omitempty"` 29 | RewardWeight uint64 `protobuf:"varint,4,opt,name=reward_weight,json=rewardWeight,proto3" json:"reward_weight,omitempty"` 30 | } 31 | 32 | func (m *NftStaking) Reset() { *m = NftStaking{} } 33 | func (m *NftStaking) String() string { return proto.CompactTextString(m) } 34 | func (*NftStaking) ProtoMessage() {} 35 | func (*NftStaking) Descriptor() ([]byte, []int) { 36 | return fileDescriptor_d4f464c8317ea07c, []int{0} 37 | } 38 | func (m *NftStaking) XXX_Unmarshal(b []byte) error { 39 | return m.Unmarshal(b) 40 | } 41 | func (m *NftStaking) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 42 | if deterministic { 43 | return xxx_messageInfo_NftStaking.Marshal(b, m, deterministic) 44 | } else { 45 | b = b[:cap(b)] 46 | n, err := m.MarshalToSizedBuffer(b) 47 | if err != nil { 48 | return nil, err 49 | } 50 | return b[:n], nil 51 | } 52 | } 53 | func (m *NftStaking) XXX_Merge(src proto.Message) { 54 | xxx_messageInfo_NftStaking.Merge(m, src) 55 | } 56 | func (m *NftStaking) XXX_Size() int { 57 | return m.Size() 58 | } 59 | func (m *NftStaking) XXX_DiscardUnknown() { 60 | xxx_messageInfo_NftStaking.DiscardUnknown(m) 61 | } 62 | 63 | var xxx_messageInfo_NftStaking proto.InternalMessageInfo 64 | 65 | func (m *NftStaking) GetNftIdentifier() string { 66 | if m != nil { 67 | return m.NftIdentifier 68 | } 69 | return "" 70 | } 71 | 72 | func (m *NftStaking) GetNftMetadata() string { 73 | if m != nil { 74 | return m.NftMetadata 75 | } 76 | return "" 77 | } 78 | 79 | func (m *NftStaking) GetRewardAddress() string { 80 | if m != nil { 81 | return m.RewardAddress 82 | } 83 | return "" 84 | } 85 | 86 | func (m *NftStaking) GetRewardWeight() uint64 { 87 | if m != nil { 88 | return m.RewardWeight 89 | } 90 | return 0 91 | } 92 | 93 | func init() { 94 | proto.RegisterType((*NftStaking)(nil), "teritori.nftstaking.v1beta1.NftStaking") 95 | } 96 | 97 | func init() { 98 | proto.RegisterFile("teritori/nftstaking/v1beta1/nftstaking.proto", fileDescriptor_d4f464c8317ea07c) 99 | } 100 | 101 | var fileDescriptor_d4f464c8317ea07c = []byte{ 102 | // 258 bytes of a gzipped FileDescriptorProto 103 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x29, 0x49, 0x2d, 0xca, 104 | 0x2c, 0xc9, 0x2f, 0xca, 0xd4, 0xcf, 0x4b, 0x2b, 0x29, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xd7, 105 | 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x44, 0x12, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 106 | 0x92, 0x86, 0xa9, 0xd6, 0x43, 0x92, 0x82, 0xaa, 0x56, 0x5a, 0xc4, 0xc8, 0xc5, 0xe5, 0x97, 0x56, 107 | 0x12, 0x0c, 0x11, 0x16, 0x52, 0xe5, 0xe2, 0xcb, 0x4b, 0x2b, 0x89, 0xcf, 0x4c, 0x49, 0xcd, 0x2b, 108 | 0xc9, 0x4c, 0xcb, 0x4c, 0x2d, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0xcd, 0x4b, 0x2b, 109 | 0xf1, 0x84, 0x0b, 0x0a, 0x29, 0x72, 0xf1, 0x80, 0x94, 0xe5, 0xa6, 0x96, 0x24, 0xa6, 0x24, 0x96, 110 | 0x24, 0x4a, 0x30, 0x81, 0x15, 0x71, 0xe7, 0xa5, 0x95, 0xf8, 0x42, 0x85, 0x40, 0x26, 0x15, 0xa5, 111 | 0x96, 0x27, 0x16, 0xa5, 0xc4, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x43, 0x4c, 112 | 0x82, 0x88, 0x3a, 0x42, 0x04, 0x85, 0x94, 0xb9, 0xa0, 0x02, 0xf1, 0xe5, 0xa9, 0x99, 0xe9, 0x19, 113 | 0x25, 0x12, 0x2c, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x3c, 0x10, 0xc1, 0x70, 0xb0, 0x98, 0x93, 0xef, 114 | 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 115 | 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa7, 0x67, 0x96, 0x64, 0x94, 116 | 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xfb, 0x45, 0x84, 0x04, 0xf8, 0x07, 0xe8, 0xc3, 0x7c, 0xab, 117 | 0x9b, 0x9c, 0x91, 0x98, 0x99, 0xa7, 0x5f, 0x81, 0x1c, 0x46, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 118 | 0x6c, 0xe0, 0x70, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x81, 0x62, 0xd9, 0x47, 0x01, 119 | 0x00, 0x00, 120 | } 121 | 122 | func (m *NftStaking) Marshal() (dAtA []byte, err error) { 123 | size := m.Size() 124 | dAtA = make([]byte, size) 125 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 126 | if err != nil { 127 | return nil, err 128 | } 129 | return dAtA[:n], nil 130 | } 131 | 132 | func (m *NftStaking) MarshalTo(dAtA []byte) (int, error) { 133 | size := m.Size() 134 | return m.MarshalToSizedBuffer(dAtA[:size]) 135 | } 136 | 137 | func (m *NftStaking) MarshalToSizedBuffer(dAtA []byte) (int, error) { 138 | i := len(dAtA) 139 | _ = i 140 | var l int 141 | _ = l 142 | if m.RewardWeight != 0 { 143 | i = encodeVarintNftstaking(dAtA, i, uint64(m.RewardWeight)) 144 | i-- 145 | dAtA[i] = 0x20 146 | } 147 | if len(m.RewardAddress) > 0 { 148 | i -= len(m.RewardAddress) 149 | copy(dAtA[i:], m.RewardAddress) 150 | i = encodeVarintNftstaking(dAtA, i, uint64(len(m.RewardAddress))) 151 | i-- 152 | dAtA[i] = 0x1a 153 | } 154 | if len(m.NftMetadata) > 0 { 155 | i -= len(m.NftMetadata) 156 | copy(dAtA[i:], m.NftMetadata) 157 | i = encodeVarintNftstaking(dAtA, i, uint64(len(m.NftMetadata))) 158 | i-- 159 | dAtA[i] = 0x12 160 | } 161 | if len(m.NftIdentifier) > 0 { 162 | i -= len(m.NftIdentifier) 163 | copy(dAtA[i:], m.NftIdentifier) 164 | i = encodeVarintNftstaking(dAtA, i, uint64(len(m.NftIdentifier))) 165 | i-- 166 | dAtA[i] = 0xa 167 | } 168 | return len(dAtA) - i, nil 169 | } 170 | 171 | func encodeVarintNftstaking(dAtA []byte, offset int, v uint64) int { 172 | offset -= sovNftstaking(v) 173 | base := offset 174 | for v >= 1<<7 { 175 | dAtA[offset] = uint8(v&0x7f | 0x80) 176 | v >>= 7 177 | offset++ 178 | } 179 | dAtA[offset] = uint8(v) 180 | return base 181 | } 182 | func (m *NftStaking) Size() (n int) { 183 | if m == nil { 184 | return 0 185 | } 186 | var l int 187 | _ = l 188 | l = len(m.NftIdentifier) 189 | if l > 0 { 190 | n += 1 + l + sovNftstaking(uint64(l)) 191 | } 192 | l = len(m.NftMetadata) 193 | if l > 0 { 194 | n += 1 + l + sovNftstaking(uint64(l)) 195 | } 196 | l = len(m.RewardAddress) 197 | if l > 0 { 198 | n += 1 + l + sovNftstaking(uint64(l)) 199 | } 200 | if m.RewardWeight != 0 { 201 | n += 1 + sovNftstaking(uint64(m.RewardWeight)) 202 | } 203 | return n 204 | } 205 | 206 | func sovNftstaking(x uint64) (n int) { 207 | return (math_bits.Len64(x|1) + 6) / 7 208 | } 209 | func sozNftstaking(x uint64) (n int) { 210 | return sovNftstaking(uint64((x << 1) ^ uint64((int64(x) >> 63)))) 211 | } 212 | func (m *NftStaking) Unmarshal(dAtA []byte) error { 213 | l := len(dAtA) 214 | iNdEx := 0 215 | for iNdEx < l { 216 | preIndex := iNdEx 217 | var wire uint64 218 | for shift := uint(0); ; shift += 7 { 219 | if shift >= 64 { 220 | return ErrIntOverflowNftstaking 221 | } 222 | if iNdEx >= l { 223 | return io.ErrUnexpectedEOF 224 | } 225 | b := dAtA[iNdEx] 226 | iNdEx++ 227 | wire |= uint64(b&0x7F) << shift 228 | if b < 0x80 { 229 | break 230 | } 231 | } 232 | fieldNum := int32(wire >> 3) 233 | wireType := int(wire & 0x7) 234 | if wireType == 4 { 235 | return fmt.Errorf("proto: NftStaking: wiretype end group for non-group") 236 | } 237 | if fieldNum <= 0 { 238 | return fmt.Errorf("proto: NftStaking: illegal tag %d (wire type %d)", fieldNum, wire) 239 | } 240 | switch fieldNum { 241 | case 1: 242 | if wireType != 2 { 243 | return fmt.Errorf("proto: wrong wireType = %d for field NftIdentifier", wireType) 244 | } 245 | var stringLen uint64 246 | for shift := uint(0); ; shift += 7 { 247 | if shift >= 64 { 248 | return ErrIntOverflowNftstaking 249 | } 250 | if iNdEx >= l { 251 | return io.ErrUnexpectedEOF 252 | } 253 | b := dAtA[iNdEx] 254 | iNdEx++ 255 | stringLen |= uint64(b&0x7F) << shift 256 | if b < 0x80 { 257 | break 258 | } 259 | } 260 | intStringLen := int(stringLen) 261 | if intStringLen < 0 { 262 | return ErrInvalidLengthNftstaking 263 | } 264 | postIndex := iNdEx + intStringLen 265 | if postIndex < 0 { 266 | return ErrInvalidLengthNftstaking 267 | } 268 | if postIndex > l { 269 | return io.ErrUnexpectedEOF 270 | } 271 | m.NftIdentifier = string(dAtA[iNdEx:postIndex]) 272 | iNdEx = postIndex 273 | case 2: 274 | if wireType != 2 { 275 | return fmt.Errorf("proto: wrong wireType = %d for field NftMetadata", wireType) 276 | } 277 | var stringLen uint64 278 | for shift := uint(0); ; shift += 7 { 279 | if shift >= 64 { 280 | return ErrIntOverflowNftstaking 281 | } 282 | if iNdEx >= l { 283 | return io.ErrUnexpectedEOF 284 | } 285 | b := dAtA[iNdEx] 286 | iNdEx++ 287 | stringLen |= uint64(b&0x7F) << shift 288 | if b < 0x80 { 289 | break 290 | } 291 | } 292 | intStringLen := int(stringLen) 293 | if intStringLen < 0 { 294 | return ErrInvalidLengthNftstaking 295 | } 296 | postIndex := iNdEx + intStringLen 297 | if postIndex < 0 { 298 | return ErrInvalidLengthNftstaking 299 | } 300 | if postIndex > l { 301 | return io.ErrUnexpectedEOF 302 | } 303 | m.NftMetadata = string(dAtA[iNdEx:postIndex]) 304 | iNdEx = postIndex 305 | case 3: 306 | if wireType != 2 { 307 | return fmt.Errorf("proto: wrong wireType = %d for field RewardAddress", wireType) 308 | } 309 | var stringLen uint64 310 | for shift := uint(0); ; shift += 7 { 311 | if shift >= 64 { 312 | return ErrIntOverflowNftstaking 313 | } 314 | if iNdEx >= l { 315 | return io.ErrUnexpectedEOF 316 | } 317 | b := dAtA[iNdEx] 318 | iNdEx++ 319 | stringLen |= uint64(b&0x7F) << shift 320 | if b < 0x80 { 321 | break 322 | } 323 | } 324 | intStringLen := int(stringLen) 325 | if intStringLen < 0 { 326 | return ErrInvalidLengthNftstaking 327 | } 328 | postIndex := iNdEx + intStringLen 329 | if postIndex < 0 { 330 | return ErrInvalidLengthNftstaking 331 | } 332 | if postIndex > l { 333 | return io.ErrUnexpectedEOF 334 | } 335 | m.RewardAddress = string(dAtA[iNdEx:postIndex]) 336 | iNdEx = postIndex 337 | case 4: 338 | if wireType != 0 { 339 | return fmt.Errorf("proto: wrong wireType = %d for field RewardWeight", wireType) 340 | } 341 | m.RewardWeight = 0 342 | for shift := uint(0); ; shift += 7 { 343 | if shift >= 64 { 344 | return ErrIntOverflowNftstaking 345 | } 346 | if iNdEx >= l { 347 | return io.ErrUnexpectedEOF 348 | } 349 | b := dAtA[iNdEx] 350 | iNdEx++ 351 | m.RewardWeight |= uint64(b&0x7F) << shift 352 | if b < 0x80 { 353 | break 354 | } 355 | } 356 | default: 357 | iNdEx = preIndex 358 | skippy, err := skipNftstaking(dAtA[iNdEx:]) 359 | if err != nil { 360 | return err 361 | } 362 | if (skippy < 0) || (iNdEx+skippy) < 0 { 363 | return ErrInvalidLengthNftstaking 364 | } 365 | if (iNdEx + skippy) > l { 366 | return io.ErrUnexpectedEOF 367 | } 368 | iNdEx += skippy 369 | } 370 | } 371 | 372 | if iNdEx > l { 373 | return io.ErrUnexpectedEOF 374 | } 375 | return nil 376 | } 377 | func skipNftstaking(dAtA []byte) (n int, err error) { 378 | l := len(dAtA) 379 | iNdEx := 0 380 | depth := 0 381 | for iNdEx < l { 382 | var wire uint64 383 | for shift := uint(0); ; shift += 7 { 384 | if shift >= 64 { 385 | return 0, ErrIntOverflowNftstaking 386 | } 387 | if iNdEx >= l { 388 | return 0, io.ErrUnexpectedEOF 389 | } 390 | b := dAtA[iNdEx] 391 | iNdEx++ 392 | wire |= (uint64(b) & 0x7F) << shift 393 | if b < 0x80 { 394 | break 395 | } 396 | } 397 | wireType := int(wire & 0x7) 398 | switch wireType { 399 | case 0: 400 | for shift := uint(0); ; shift += 7 { 401 | if shift >= 64 { 402 | return 0, ErrIntOverflowNftstaking 403 | } 404 | if iNdEx >= l { 405 | return 0, io.ErrUnexpectedEOF 406 | } 407 | iNdEx++ 408 | if dAtA[iNdEx-1] < 0x80 { 409 | break 410 | } 411 | } 412 | case 1: 413 | iNdEx += 8 414 | case 2: 415 | var length int 416 | for shift := uint(0); ; shift += 7 { 417 | if shift >= 64 { 418 | return 0, ErrIntOverflowNftstaking 419 | } 420 | if iNdEx >= l { 421 | return 0, io.ErrUnexpectedEOF 422 | } 423 | b := dAtA[iNdEx] 424 | iNdEx++ 425 | length |= (int(b) & 0x7F) << shift 426 | if b < 0x80 { 427 | break 428 | } 429 | } 430 | if length < 0 { 431 | return 0, ErrInvalidLengthNftstaking 432 | } 433 | iNdEx += length 434 | case 3: 435 | depth++ 436 | case 4: 437 | if depth == 0 { 438 | return 0, ErrUnexpectedEndOfGroupNftstaking 439 | } 440 | depth-- 441 | case 5: 442 | iNdEx += 4 443 | default: 444 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType) 445 | } 446 | if iNdEx < 0 { 447 | return 0, ErrInvalidLengthNftstaking 448 | } 449 | if depth == 0 { 450 | return iNdEx, nil 451 | } 452 | } 453 | return 0, io.ErrUnexpectedEOF 454 | } 455 | 456 | var ( 457 | ErrInvalidLengthNftstaking = fmt.Errorf("proto: negative length found during unmarshaling") 458 | ErrIntOverflowNftstaking = fmt.Errorf("proto: integer overflow") 459 | ErrUnexpectedEndOfGroupNftstaking = fmt.Errorf("proto: unexpected end of group") 460 | ) 461 | --------------------------------------------------------------------------------