diff --git a/app/app.go b/app/app.go index 63b926c39..3bf4fcd22 100644 --- a/app/app.go +++ b/app/app.go @@ -3,6 +3,7 @@ package app import ( "fmt" "io" + "math/big" "net/http" "os" "path/filepath" @@ -185,6 +186,8 @@ func init() { } DefaultNodeHome = filepath.Join(userHomeDir, "."+ShortName) + + sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)) } // App extends an ABCI application, but with most of its parameters exported. @@ -617,9 +620,6 @@ func New( app.MountMemoryStores(memKeys) // initialize BaseApp - app.SetInitChainer(app.InitChainer) - app.SetBeginBlocker(app.BeginBlocker) - anteHandler, err := ante.NewAnteHandler( ante.HandlerOptions{ AccountKeeper: app.AccountKeeper, @@ -638,6 +638,9 @@ func New( app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) app.SetUpgradeChecker(app.UpgradeKeeper.IsUpgraded) + + ms := app.CommitMultiStore() + ctx := sdk.NewContext(ms, tmproto.Header{ChainID: app.ChainID(), Height: app.LastBlockHeight()}, true, app.UpgradeKeeper.IsUpgraded, app.Logger()) if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) @@ -646,27 +649,24 @@ func New( // Execute the upgraded register, such as the newly added Msg type // ex. // app.GovKeeper.Router().RegisterService(...) - ms := app.CommitMultiStore() - ctx := sdk.NewContext(ms, tmproto.Header{ChainID: app.ChainID(), Height: app.LastBlockHeight()}, true, app.UpgradeKeeper.IsUpgraded, app.Logger()) - if loadLatest { - err = app.UpgradeKeeper.InitUpgraded(ctx) - if err != nil { - panic(err) - } + err = app.UpgradeKeeper.InitUpgraded(ctx) + if err != nil { + panic(err) } } // this line is used by starport scaffolding # stargate/app/beforeInitReturn - app.initModules() + app.initModules(ctx) return app } -func (app *App) initModules() { +func (app *App) initModules(ctx sdk.Context) { app.initBridge() - app.initCrossChain() + + app.initGashub(ctx) } func (app *App) initCrossChain() { @@ -678,6 +678,12 @@ func (app *App) initBridge() { bridgemodulekeeper.RegisterCrossApps(app.BridgeKeeper) } +func (app *App) initGashub(ctx sdk.Context) { + if app.LastBlockHeight() > 0 { + app.GashubKeeper.RegisterGasCalculators(ctx) + } +} + // Name returns the name of the App func (app *App) Name() string { return app.BaseApp.Name() } diff --git a/app/config.go b/app/config.go index 55fea15db..1baff19eb 100644 --- a/app/config.go +++ b/app/config.go @@ -41,7 +41,7 @@ func NewDefaultAppConfig() *AppConfig { // own app.toml to override, or use this default value. // // In simapp, we set the min gas prices to 0. - srvCfg.MinGasPrices = "0stake" + srvCfg.MinGasPrices = "1000000000BNB" return &AppConfig{ Config: *srvCfg, diff --git a/cmd/gnfd/cmd/root.go b/cmd/gnfd/cmd/root.go index fe787274f..e6bfec62a 100644 --- a/cmd/gnfd/cmd/root.go +++ b/cmd/gnfd/cmd/root.go @@ -97,6 +97,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) { flags.FlagChainID: app.Name + "_" + app.EIP155ChainID + "-" + app.Epoch, flags.FlagKeyringBackend: "test", flags.FlagSignMode: flags.SignModeEIP712, + flags.FlagGas: "auto", }) return rootCmd, encodingConfig diff --git a/deployment/localup/.env b/deployment/localup/.env index bfce671e5..93caf3acc 100644 --- a/deployment/localup/.env +++ b/deployment/localup/.env @@ -1,18 +1,18 @@ ## BASIC CONFIG CHAIN_ID=greenfield_9000-121 -STAKING_BOND_DENOM=bnb -BASIC_DENOM=bnb -STAKING_BOND_AMOUNT=10000000000 +STAKING_BOND_DENOM=BNB +BASIC_DENOM=BNB +STAKING_BOND_AMOUNT=10000000000000000000000000 SNAPSHOT_INTERVAL=10 SNAPSHOT_KEEP_RECENT=0 KPASS=12345678 -GENESIS_ACCOUNT_BALANCE=100000000000 +GENESIS_ACCOUNT_BALANCE=100000000000000000000000000 COMMISSION_MAX_CHANGE_RATE=0.01 COMMISSION_MAX_RATE=1.0 COMMISSION_RATE=0.07 -NATIVE_COIN_DESC='{"description":"The native staking token of the Greenfield.","denom_units":[{"denom":"weibnb","exponent":0,"aliases":["ether"]},{"denom":"gweibnb","exponent":9,"aliases":["gwei"]},{"denom":"bnb","exponent":18 }],"base":"wei","display":"bnb"}' +NATIVE_COIN_DESC='{"description":"The native staking token of the Greenfield.","denom_units":[{"denom":"BNB","exponent":0,"aliases":["wei"]}],"base":"BNB","display":"BNB"}' DEPOSIT_VOTE_PERIOD=300s -MIN_DEPOSIT_AMOUNT=100 +GOV_MIN_DEPOSIT_AMOUNT=1000000000000000000 ## CROSS CHAIN SRC_CHAIN_ID=18 diff --git a/deployment/localup/create_sp.json b/deployment/localup/create_sp.json index e6b2cded7..c870e8890 100644 --- a/deployment/localup/create_sp.json +++ b/deployment/localup/create_sp.json @@ -15,13 +15,13 @@ "approval_address": "0x78FeF615b06251ecfA9Ba01B7DB2BFA892722dDC", "endpoint": "sp0.greenfield.io", "deposit":{ - "denom":"bnb", - "amount":"10000" + "denom":"BNB", + "amount":"10000000000000000000000" }, "creator":"0x7b5Fe22B5446f7C62Ea27B8BD71CeF94e03f3dF2" } ], "metadata": "4pIMOgIGx1vZGU=", - "deposit": "1bnb" + "deposit": "1000000000000000000BNB" } diff --git a/deployment/localup/localup.sh b/deployment/localup/localup.sh index d0cd6d17c..fe1dfc887 100755 --- a/deployment/localup/localup.sh +++ b/deployment/localup/localup.sh @@ -52,9 +52,9 @@ function generate_genesis() { spfund_addr=("$(${bin} keys show sp${i}_fund -a --keyring-backend test --home ${workspace}/.local/sp${i})") spseal_addr=("$(${bin} keys show sp${i}_seal -a --keyring-backend test --home ${workspace}/.local/sp${i})") spapproval_addr=("$(${bin} keys show sp${i}_approval -a --keyring-backend test --home ${workspace}/.local/sp${i})") - ${bin} add-genesis-account $sp_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0 + ${bin} add-genesis-account $sp_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0 ${bin} add-genesis-account $spfund_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0 - ${bin} add-genesis-account $spseal_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0 + ${bin} add-genesis-account $spseal_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0 ${bin} add-genesis-account $spapproval_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0 done @@ -100,9 +100,10 @@ function generate_genesis() { --commission-rate=${COMMISSION_RATE} \ --details="validator${i}" \ --website="http://website" \ - --node tcp://localhost:$((${VALIDATOR_P2P_PORT_START}+${i})) \ + --node tcp://localhost:$((${VALIDATOR_RPC_PORT_START}+${i})) \ --node-id "validator${i}" \ - --ip 127.0.0.1 + --ip 127.0.0.1 \ + --gas "" cp ${workspace}/.local/validator${i}/config/gentx/gentx-validator${i}.json ${workspace}/.local/gentx/ done @@ -133,8 +134,7 @@ function generate_genesis() { sed -i -e "s/\"reserve_time\": \"15552000\"/\"reserve_time\": \"600\"/g" ${workspace}/.local/validator${i}/config/genesis.json sed -i -e "s/\"forced_settle_time\": \"86400\"/\"forced_settle_time\": \"100\"/g" ${workspace}/.local/validator${i}/config/genesis.json sed -i -e "s/172800s/${DEPOSIT_VOTE_PERIOD}/g" ${workspace}/.local/validator${i}/config/genesis.json - sed -i -e "s/\"10000000\"/\"${MIN_DEPOSIT_AMOUNT}\"/g" ${workspace}/.local/validator${i}/config/genesis.json - + sed -i -e "s/\"10000000\"/\"${GOV_MIN_DEPOSIT_AMOUNT}\"/g" ${workspace}/.local/validator${i}/config/genesis.json done # enable swagger API for validator0 @@ -182,12 +182,12 @@ function sp_join() { sp_addr=("$(${bin} keys show sp${i} -a --keyring-backend test --home ${workspace}/.local/sp${i})") sleep 6 ${bin} tx sp grant 0x7b5Fe22B5446f7C62Ea27B8BD71CeF94e03f3dF2 \ - --spend-limit 1000000bnb \ + --spend-limit 10000000000000000000000BNB \ --SPAddress "${sp_addr}" \ --from sp${i}_fund \ --home "${workspace}/.local/sp${i}" \ --keyring-backend test \ - --node http://localhost:26750 \ + --node http://localhost:${VALIDATOR_RPC_PORT_START} \ --yes done @@ -213,17 +213,17 @@ function sp_join() { --from sp${i} \ --keyring-backend test \ --home ${workspace}/.local/sp${i} \ - --node http://localhost:26750 \ + --node http://localhost:${VALIDATOR_RPC_PORT_START} \ --broadcast-mode block \ --yes sleep 6 # deposit the proposal - ${bin} tx gov deposit $((${PROPOSAL_ID_START} + ${i})) 10000bnb \ + ${bin} tx gov deposit $((${PROPOSAL_ID_START} + ${i})) 1000000000000000000BNB \ --from sp${i} \ --keyring-backend test \ --home ${workspace}/.local/sp${i} \ - --node http://localhost:26750 \ + --node http://localhost:${VALIDATOR_RPC_PORT_START} \ --broadcast-mode block \ --yes @@ -233,7 +233,7 @@ function sp_join() { --from validator0 \ --keyring-backend test \ --home ${workspace}/.local/validator0 \ - --node http://localhost:26750 \ + --node http://localhost:${VALIDATOR_RPC_PORT_START} \ --broadcast-mode block \ --yes sleep 1 @@ -248,7 +248,7 @@ function sp_check() { # wait 360s , and then check the sp if ready n=0 while [ $n -le 360 ]; do - cnt=("$(${bin} query sp storage-providers --node http://localhost:26750 | grep approval_address | wc -l)") + cnt=("$(${bin} query sp storage-providers --node http://localhost:${VALIDATOR_RPC_PORT_START} | grep approval_address | wc -l)") ((n++)) sleep 1 if [ "$cnt" -eq "$sp_size" ]; then @@ -274,12 +274,12 @@ fi case ${CMD} in init) echo "===== init ====" - init $SIZE + init $SIZE $SP_SIZE echo "===== end ====" ;; generate) echo "===== generate genesis ====" - generate_genesis $SIZE + generate_genesis $SIZE $SP_SIZE echo "===== end ====" ;; start) @@ -320,4 +320,4 @@ all) # TODO: implement create sp in genesis use genesis transaction like validator. echo "Usage: localup.sh all | init | generate | start | sp_join | sp_check | stop" ;; -esac \ No newline at end of file +esac diff --git a/deployment/readme.md b/deployment/readme.md index f1d793e5e..dcaf55f57 100644 --- a/deployment/readme.md +++ b/deployment/readme.md @@ -8,7 +8,7 @@ make build 2. Creates all the configuration files ```bash # The argument is the custom username of your node, it should be human-readable. -./build/bin/gnfd init --chain-id greenfield_9000-01 --staking-bond-denom bnb +./build/bin/gnfd init --chain-id greenfield_9000-01 --staking-bond-denom BNB ``` All these configuration files are in ~/.gnfd by default, but you can overwrite the location of this folder by passing the --home flag. @@ -46,13 +46,13 @@ Before starting the chain, you need to populate the state with at least one acco VALIDATOR=$(./build/bin/gnfd keys show validator -a --keyring-backend test) RELAYER=$(./build/bin/gnfd keys show relayer -a --keyring-backend test) RELAYER_BLS=$(./build/bin/gnfd keys show relayer --keyring-backend test --output json | jq -r .pubkey_hex) -./build/bin/gnfd add-genesis-account $VALIDATOR 100000000000bnb +./build/bin/gnfd add-genesis-account $VALIDATOR 100000000000000000000000000BNB ``` 5. Create validator in genesis state ```bash # create a gentx. -./build/bin/gnfd gentx validator 1000000000bnb $VALIDATOR $RELAYER $RELAYER_BLS --keyring-backend=test --chain-id=greenfield_9000-121 \ +./build/bin/gnfd gentx validator 10000000000000000000000000BNB $VALIDATOR $RELAYER $RELAYER_BLS --keyring-backend=test --chain-id=greenfield_9000-121 \ --moniker="validator" \ --commission-max-change-rate=0.01 \ --commission-max-rate=1.0 \ @@ -81,7 +81,7 @@ bash ./deployment/localup/localup.sh stop 3. Send Tx ```bash -./build/bin/gnfd tx bank send validator0 0x32Ff14Fa1547314b95991976DB432F9Aa648A423 500bnb --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block +./build/bin/gnfd tx bank send validator0 0x32Ff14Fa1547314b95991976DB432F9Aa648A423 500000000000000000000BNB --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block ``` 4. Restart the chain without state initialization diff --git a/docs/tutorial/05-bank.md b/docs/tutorial/05-bank.md index 1fe2274ec..f95e5299d 100644 --- a/docs/tutorial/05-bank.md +++ b/docs/tutorial/05-bank.md @@ -16,19 +16,19 @@ $ alias gnfd="./build/bin/gnfd" $ receiver=0x32Ff14Fa1547314b95991976DB432F9Aa648A423 ## query the balance of receiver $ gnfd q bank balances $receiver --node tcp://127.0.0.1:26750 -## send 500bnb to the receiver (note the decimal of BNB is 18) -$ gnfd tx bank send validator0 $receiver 500bnb --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block -y +## send 500BNB to the receiver (note the decimal of BNB is 18) +$ gnfd tx bank send validator0 $receiver 500000000000000000000BNB --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block -y ## query the balance of receiver again $ gnfd q bank balances $receiver --node tcp://127.0.0.1:26750 ## try send some token that does not exit, error is expected. -$ gnfd tx bank send validator0 $receiver 500bnb --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block -y -## try multi send, send each 500bnb to both receiver and receiver2 +$ gnfd tx bank send validator0 $receiver 500000000000000000000ETH --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block -y +## try multi send, send each 500BNB to both receiver and receiver2 $ receiver2=0x6d6247501b822fd4eaa76fcb64baea360279497f -$ gnfd tx bank multi-send validator0 $receiver $receiver2 500bnb --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block -y --gas 500000 +$ gnfd tx bank multi-send validator0 $receiver $receiver2 500000000000000000000BNB --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block -y --gas 500000 ## query the metadata of BNB $ gnfd q bank denom-metadata --node tcp://127.0.0.1:26750 ## query the total supply of BNB -$ gnfd q bank total --denom bnb --node tcp://127.0.0.1:26750 +$ gnfd q bank total --denom BNB --node tcp://127.0.0.1:26750 ``` ## Detailed CLI @@ -54,15 +54,15 @@ gnfd query bank balances [address] [flags] Example: ```sh -gnfd query bank balances bnb.. +gnfd query bank balances 0x73a4Cf67b46D7E4efbb95Fc6F59D64129299c2E3 ``` Example Output: ```yml balances: -- amount: "1000000000" - denom: bnb +- amount: "10000000000000000000000" + denom: BNB pagination: next_key: null total: "0" @@ -79,32 +79,25 @@ gnfd query bank denom-metadata [flags] Example: ```sh -gnfd query bank denom-metadata --denom bnb +gnfd query bank denom-metadata --denom BNB ``` Example Output: ```yml -metadatas: - - base: wei - denom_units: - - aliases: - - ether - denom: weibnb - exponent: 0 - - aliases: - - gwei - denom: gweibnb - exponent: 9 - - aliases: [] - denom: bnb - exponent: 18 - description: The native staking token of the Greenfield. - display: bnb - name: "" - symbol: "" - uri: "" - uri_hash: "" +metadata: + base: BNB + denom_units: + - aliases: + - wei + denom: BNB + exponent: 0 + description: The native staking token of the Greenfield. + display: BNB + name: "" + symbol: "" + uri: "" + uri_hash: "" ``` #### total @@ -118,14 +111,14 @@ gnfd query bank total [flags] Example: ```sh -gnfd query bank total --denom bnb +gnfd query bank total --denom BNB ``` Example Output: ```yml amount: "1000000000000000800000000000" -denom: bnb +denom: BNB ``` ### Transactions @@ -147,5 +140,5 @@ gnfd tx bank send [from_key_or_address] [to_address] [amount] [flags] Example: ```sh -gnfd tx bank send addr1.. addr2.. 100bnb +gnfd tx bank send addr1.. addr2.. 100000000000000000000BNB ``` \ No newline at end of file diff --git a/e2e/core/basesuite.go b/e2e/core/basesuite.go index 38c36f4cd..2a4fa97e4 100644 --- a/e2e/core/basesuite.go +++ b/e2e/core/basesuite.go @@ -1,25 +1,29 @@ package core import ( - "github.com/bnb-chain/greenfield/sdk/client" - "github.com/bnb-chain/greenfield/sdk/keys" - "github.com/bnb-chain/greenfield/sdk/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/suite" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/bnb-chain/greenfield/sdk/client" + "github.com/bnb-chain/greenfield/sdk/keys" + "github.com/bnb-chain/greenfield/sdk/types" ) type BaseSuite struct { suite.Suite config *Config - Client client.GreenfieldClient + Client *client.GreenfieldClient TestAccount keys.KeyManager } func (s *BaseSuite) SetupSuite() { s.config = InitConfig() - s.Client = client.NewGreenfieldClient(s.config.GrpcAddr, s.config.ChainId) + s.Client = client.NewGreenfieldClient(s.config.GrpcAddr, s.config.ChainId, + client.WithGrpcDialOption(grpc.WithTransportCredentials(insecure.NewCredentials()))) var err error s.TestAccount, err = keys.NewMnemonicKeyManager(s.config.Mnemonic) s.Require().NoError(err) @@ -31,7 +35,7 @@ func (s *BaseSuite) SendTxBlock(msg sdk.Msg, from keys.KeyManager) (txRes *sdk.T Mode: &mode, GasLimit: 1000000, Memo: "", - FeeAmount: sdk.Coins{{Denom: s.config.Denom, Amount: sdk.NewInt(1)}}, + FeeAmount: sdk.Coins{{Denom: s.config.Denom, Amount: sdk.NewInt(1e9 * 1e6)}}, } s.Client.SetKeyManager(from) response, err := s.Client.BroadcastTx([]sdk.Msg{msg}, txOpt) @@ -49,7 +53,7 @@ func (s *BaseSuite) GenAndChargeAccounts(n int, balance int64) (accounts []keys. accounts = append(accounts, km) outputs = append(outputs, banktypes.Output{ Address: km.GetAddr().String(), - Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance)}}, + Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance * 1e18)}}, }) } if balance == 0 { @@ -57,7 +61,7 @@ func (s *BaseSuite) GenAndChargeAccounts(n int, balance int64) (accounts []keys. } in := banktypes.Input{ Address: s.TestAccount.GetAddr().String(), - Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance * int64(n))}}, + Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance * 1e18 * int64(n))}}, } msg := banktypes.MsgMultiSend{ Inputs: []banktypes.Input{in}, diff --git a/e2e/core/config.go b/e2e/core/config.go index e3a953d09..ba762edd5 100644 --- a/e2e/core/config.go +++ b/e2e/core/config.go @@ -14,7 +14,7 @@ type Config struct { } func InitConfig() *Config { - // todo: support qa and testnet config + // TODO: support qa and testnet config return InitE2eConfig() } @@ -22,7 +22,7 @@ func InitE2eConfig() *Config { return &Config{ GrpcAddr: "localhost:9090", ChainId: "greenfield_9000-121", - Denom: "bnb", + Denom: "BNB", Mnemonic: ParseValidatorMnemonic(0), } } diff --git a/e2e/core/utils.go b/e2e/core/utils.go index 134e8e510..5b4bdd93c 100644 --- a/e2e/core/utils.go +++ b/e2e/core/utils.go @@ -4,9 +4,10 @@ import ( "fmt" "math/rand" - "github.com/bnb-chain/greenfield/sdk/keys" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/crypto" + + "github.com/bnb-chain/greenfield/sdk/keys" ) func GenRandomAddr() sdk.AccAddress { diff --git a/e2e/tests/payment_test.go b/e2e/tests/payment_test.go index f7519f75e..71955699b 100644 --- a/e2e/tests/payment_test.go +++ b/e2e/tests/payment_test.go @@ -5,9 +5,10 @@ import ( "context" "testing" + "github.com/stretchr/testify/suite" + "github.com/bnb-chain/greenfield/e2e/core" paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" - "github.com/stretchr/testify/suite" ) type PaymentTestSuite struct { @@ -18,8 +19,7 @@ func (s *PaymentTestSuite) SetupSuite() { s.BaseSuite.SetupSuite() } -func (s *PaymentTestSuite) SetupTest() { -} +func (s *PaymentTestSuite) SetupTest() {} func (s *PaymentTestSuite) TestPaymentAccount() { user := s.GenAndChargeAccounts(1, 100)[0] diff --git a/readme.md b/readme.md index 30ff71532..18140b787 100644 --- a/readme.md +++ b/readme.md @@ -64,7 +64,7 @@ $ addr=`./build/bin/gnfd keys list --home $(pwd)/deployment/localup/.local/val $ ./build/bin/gnfd q bank balances $addr --node tcp://127.0.0.1:26750 ## send BNB -$ ./build/bin/gnfd tx bank send validator0 0x73a4Cf67b46D7E4efbb95Fc6F59D64129299c2E3 100bnb --from validator0 -y --node tcp://127.0.0.1:26750 --home $(pwd)/deployment/localup/.local/validator0 -keyring-backend test --broadcast-mode block +$ ./build/bin/gnfd tx bank send validator0 0x73a4Cf67b46D7E4efbb95Fc6F59D64129299c2E3 100000000000000000000BNB --from validator0 -y --node tcp://127.0.0.1:26750 --home $(pwd)/deployment/localup/.local/validator0 -keyring-backend test --broadcast-mode block ## create a storage bucket $ ./build/bin/gnfd tx storage create-bucket bucketname 0x73a4Cf67b46D7E4efbb95Fc6F59D64129299c2E3 --from validator0 -y --node tcp://127.0.0.1:26750 --home $(pwd)/deployment/localup/.local/validator0 --keyring-backend test --broadcast-mode block diff --git a/sdk/client/gnfd_client.go b/sdk/client/gnfd_client.go index 248b85046..35b3f1dc2 100644 --- a/sdk/client/gnfd_client.go +++ b/sdk/client/gnfd_client.go @@ -25,56 +25,118 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" ) +// AuthQueryClient is a type to define the auth types Query Client type AuthQueryClient = authtypes.QueryClient + +// AuthzQueryClient is a type to define the authz types Query Client type AuthzQueryClient = authztypes.QueryClient + +// BankQueryClient is a type to define the bank types Query Client type BankQueryClient = banktypes.QueryClient + +// CrosschainQueryClient is a type to define the crosschain types Query Client type CrosschainQueryClient = crosschaintypes.QueryClient + +// DistrQueryClient is a type to define the distribution types Query Client type DistrQueryClient = distrtypes.QueryClient + +// FeegrantQueryClient is a type to define the feegrant types Query Client type FeegrantQueryClient = feegranttypes.QueryClient + +// GashubQueryClient is a type to define the gashub types Query Client type GashubQueryClient = gashubtypes.QueryClient + +// PaymentQueryClient is a type to define the payment types Query Client type PaymentQueryClient = paymenttypes.QueryClient + +// SpQueryClient is a type to define the sp types Query Client type SpQueryClient = sptypes.QueryClient + +// BridgeQueryClient is a type to define the bridge types Query Client type BridgeQueryClient = bridgetypes.QueryClient + +// StorageQueryClient is a type to define the storage types Query Client type StorageQueryClient = storagetypes.QueryClient + +// GovQueryClientV1 is a type to define the governance types Query Client V1 type GovQueryClientV1 = govv1.QueryClient + +// OracleQueryClient is a type to define the oracle types Query Client type OracleQueryClient = oracletypes.QueryClient + +// ParamsQueryClient is a type to define the parameters proposal types Query Client type ParamsQueryClient = paramstypes.QueryClient + +// SlashingQueryClient is a type to define the slashing types Query Client type SlashingQueryClient = slashingtypes.QueryClient + +// StakingQueryClient is a type to define the staking types Query Client type StakingQueryClient = stakingtypes.QueryClient + +// TxClient is a type to define the tx Service Client type TxClient = tx.ServiceClient + +// UpgradeQueryClient is a type to define the upgrade types Query Client type UpgradeQueryClient = upgradetypes.QueryClient +// GreenfieldClient holds all necessary information for creating/querying transactions. type GreenfieldClient struct { + // AuthQueryClient holds the auth query client. AuthQueryClient + // AuthzQueryClient holds the authz query client. AuthzQueryClient + // BankQueryClient holds the bank query client. BankQueryClient + // CrosschainQueryClient holds the crosschain query client. CrosschainQueryClient + // DistrQueryClient holds the distr query client. DistrQueryClient + // FeegrantQueryClient holds the feegrant query client. FeegrantQueryClient + // GashubQueryClient holds the gashub query client. GashubQueryClient + // PaymentQueryClient holds the payment query client. PaymentQueryClient + // SpQueryClient holds the sp query client. SpQueryClient + // BridgeQueryClient holds the bridge query client. BridgeQueryClient + // StorageQueryClient holds the storage query client. StorageQueryClient + // GovQueryClientV1 holds the gov query client V1. GovQueryClientV1 + // OracleQueryClient holds the oracle query client. OracleQueryClient + // ParamsQueryClient holds the params query client. ParamsQueryClient + // SlashingQueryClient holds the slashing query client. SlashingQueryClient + // StakingQueryClient holds the staking query client. StakingQueryClient - TxClient + // UpgradeQueryClient holds the upgrade query client. UpgradeQueryClient + // TxClient holds the tx service client. + TxClient + + // keyManager is the manager used for generating and managing keys. keyManager keys.KeyManager - chainId string - codec *codec.ProtoCodec + // chainId is the id of the chain. + chainId string + // codec is the ProtoCodec used for encoding and decoding messages. + codec *codec.ProtoCodec + + // option fields + // grpcDialOption is the list of grpc dial options. + grpcDialOption []grpc.DialOption } -func grpcConn(addr string) *grpc.ClientConn { +// grpcConn is used to establish a connection with a given address and dial options. +func grpcConn(addr string, opts ...grpc.DialOption) *grpc.ClientConn { conn, err := grpc.Dial( addr, - grpc.WithTransportCredentials(insecure.NewCredentials()), + opts..., ) if err != nil { panic(err) @@ -82,40 +144,44 @@ func grpcConn(addr string) *grpc.ClientConn { return conn } -func NewGreenfieldClient(grpcAddr, chainId string) GreenfieldClient { - conn := grpcConn(grpcAddr) - cdc := types.Cdc() - return GreenfieldClient{ - authtypes.NewQueryClient(conn), - authztypes.NewQueryClient(conn), - banktypes.NewQueryClient(conn), - crosschaintypes.NewQueryClient(conn), - distrtypes.NewQueryClient(conn), - feegranttypes.NewQueryClient(conn), - gashubtypes.NewQueryClient(conn), - paymenttypes.NewQueryClient(conn), - sptypes.NewQueryClient(conn), - bridgetypes.NewQueryClient(conn), - storagetypes.NewQueryClient(conn), - govv1.NewQueryClient(conn), - oracletypes.NewQueryClient(conn), - paramstypes.NewQueryClient(conn), - slashingtypes.NewQueryClient(conn), - stakingtypes.NewQueryClient(conn), - tx.NewServiceClient(conn), - upgradetypes.NewQueryClient(conn), - nil, - chainId, - cdc, +// NewGreenfieldClient is used to create a new GreenfieldClient structure. +func NewGreenfieldClient(grpcAddr, chainId string, opts ...GreenfieldClientOption) *GreenfieldClient { + client := &GreenfieldClient{ + chainId: chainId, + codec: types.Cdc(), + } + for _, opt := range opts { + opt.Apply(client) } + + conn := grpcConn(grpcAddr, client.grpcDialOption...) + client.AuthQueryClient = authtypes.NewQueryClient(conn) + client.AuthzQueryClient = authztypes.NewQueryClient(conn) + client.BankQueryClient = banktypes.NewQueryClient(conn) + client.CrosschainQueryClient = crosschaintypes.NewQueryClient(conn) + client.DistrQueryClient = distrtypes.NewQueryClient(conn) + client.FeegrantQueryClient = feegranttypes.NewQueryClient(conn) + client.GashubQueryClient = gashubtypes.NewQueryClient(conn) + client.PaymentQueryClient = paymenttypes.NewQueryClient(conn) + client.SpQueryClient = sptypes.NewQueryClient(conn) + client.BridgeQueryClient = bridgetypes.NewQueryClient(conn) + client.StorageQueryClient = storagetypes.NewQueryClient(conn) + client.GovQueryClientV1 = govv1.NewQueryClient(conn) + client.OracleQueryClient = oracletypes.NewQueryClient(conn) + client.ParamsQueryClient = paramstypes.NewQueryClient(conn) + client.SlashingQueryClient = slashingtypes.NewQueryClient(conn) + client.StakingQueryClient = stakingtypes.NewQueryClient(conn) + client.UpgradeQueryClient = upgradetypes.NewQueryClient(conn) + client.TxClient = tx.NewServiceClient(conn) + return client } -func NewGreenfieldClientWithKeyManager(grpcAddr, chainId string, keyManager keys.KeyManager) GreenfieldClient { - gnfdClient := NewGreenfieldClient(grpcAddr, chainId) - gnfdClient.keyManager = keyManager - return gnfdClient +// SetKeyManager sets a key manager in the GreenfieldClient structure. +func (c *GreenfieldClient) SetKeyManager(keyManager keys.KeyManager) { + c.keyManager = keyManager } +// GetKeyManager returns the key manager set in the GreenfieldClient structure. func (c *GreenfieldClient) GetKeyManager() (keys.KeyManager, error) { if c.keyManager == nil { return nil, types.KeyManagerNotInitError @@ -123,14 +189,12 @@ func (c *GreenfieldClient) GetKeyManager() (keys.KeyManager, error) { return c.keyManager, nil } -func (c *GreenfieldClient) SetKeyManager(keyManager keys.KeyManager) { - c.keyManager = keyManager -} - +// SetChainId sets the chain ID in the GreenfieldClient structure. func (c *GreenfieldClient) SetChainId(id string) { c.chainId = id } +// GetChainId returns the chain ID set in the GreenfieldClient structure. func (c *GreenfieldClient) GetChainId() (string, error) { if c.chainId == "" { return "", types.ChainIdNotSetError diff --git a/sdk/client/gnfd_client_option.go b/sdk/client/gnfd_client_option.go new file mode 100644 index 000000000..94f5e768c --- /dev/null +++ b/sdk/client/gnfd_client_option.go @@ -0,0 +1,33 @@ +package client + +import ( + "github.com/bnb-chain/greenfield/sdk/keys" + "google.golang.org/grpc" +) + +// GreenfieldClientOption configures how we set up the greenfield client. +type GreenfieldClientOption interface { + Apply(*GreenfieldClient) +} + +// GreenfieldClientOptionFunc defines an applied function for setting the greenfield client. +type GreenfieldClientOptionFunc func(*GreenfieldClient) + +// Apply set up the option field to the client instance. +func (f GreenfieldClientOptionFunc) Apply(client *GreenfieldClient) { + f(client) +} + +// WithKeyManager returns a GreenfieldClientOption which configures a client key manager option. +func WithKeyManager(km keys.KeyManager) GreenfieldClientOption { + return GreenfieldClientOptionFunc(func(client *GreenfieldClient) { + client.keyManager = km + }) +} + +// WithGrpcDialOption returns a GreenfieldClientOption which configures a grpc client connection options. +func WithGrpcDialOption(opts ...grpc.DialOption) GreenfieldClientOption { + return GreenfieldClientOptionFunc(func(client *GreenfieldClient) { + client.grpcDialOption = opts + }) +} diff --git a/sdk/client/test/config.go b/sdk/client/test/config.go index 2fa68f033..af023ef6f 100644 --- a/sdk/client/test/config.go +++ b/sdk/client/test/config.go @@ -10,4 +10,5 @@ const ( TEST_GRPC_ADDR = "localhost:9090" TEST_RPC_ADDR = "http://0.0.0.0:26750" TEST_CHAIN_ID = "greenfield_9000-121" + TEST_TOKEN_NAME = "bnb" ) diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index 041d1a9b3..d7e0a7842 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -10,15 +10,19 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/assert" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) func TestSendTokenSucceedWithSimulatedGas(t *testing.T) { km, err := keys.NewPrivateKeyManager(test.TEST_PRIVATE_KEY) assert.NoError(t, err) - gnfdCli := NewGreenfieldClientWithKeyManager(test.TEST_GRPC_ADDR, test.TEST_CHAIN_ID, km) + gnfdCli := NewGreenfieldClient(test.TEST_GRPC_ADDR, test.TEST_CHAIN_ID, + WithKeyManager(km), + WithGrpcDialOption(grpc.WithTransportCredentials(insecure.NewCredentials()))) to, err := sdk.AccAddressFromHexUnsafe(test.TEST_ADDR) assert.NoError(t, err) - transfer := banktypes.NewMsgSend(km.GetAddr(), to, sdk.NewCoins(sdk.NewInt64Coin("bnb", 12))) + transfer := banktypes.NewMsgSend(km.GetAddr(), to, sdk.NewCoins(sdk.NewInt64Coin(test.TEST_TOKEN_NAME, 12))) response, err := gnfdCli.BroadcastTx([]sdk.Msg{transfer}, nil) assert.NoError(t, err) assert.Equal(t, uint32(0), response.TxResponse.Code) @@ -28,18 +32,20 @@ func TestSendTokenSucceedWithSimulatedGas(t *testing.T) { func TestSendTokenWithTxOptionSucceed(t *testing.T) { km, err := keys.NewPrivateKeyManager(test.TEST_PRIVATE_KEY) assert.NoError(t, err) - gnfdCli := NewGreenfieldClientWithKeyManager(test.TEST_GRPC_ADDR, test.TEST_CHAIN_ID, km) + gnfdCli := NewGreenfieldClient(test.TEST_GRPC_ADDR, test.TEST_CHAIN_ID, + WithKeyManager(km), + WithGrpcDialOption(grpc.WithTransportCredentials(insecure.NewCredentials()))) to, err := sdk.AccAddressFromHexUnsafe(test.TEST_ADDR) assert.NoError(t, err) - transfer := banktypes.NewMsgSend(km.GetAddr(), to, sdk.NewCoins(sdk.NewInt64Coin("bnb", 100))) + transfer := banktypes.NewMsgSend(km.GetAddr(), to, sdk.NewCoins(sdk.NewInt64Coin(test.TEST_TOKEN_NAME, 100))) payerAddr, err := sdk.AccAddressFromHexUnsafe(km.GetAddr().String()) assert.NoError(t, err) - mode := tx.BroadcastMode_BROADCAST_MODE_ASYNC + mode := tx.BroadcastMode_BROADCAST_MODE_BLOCK txOpt := &types.TxOption{ Mode: &mode, GasLimit: 123456, Memo: "test", - FeeAmount: sdk.Coins{{Denom: "bnb", Amount: sdk.NewInt(1)}}, + FeeAmount: sdk.NewCoins(sdk.NewInt64Coin(test.TEST_TOKEN_NAME, 1)), FeePayer: payerAddr, } response, err := gnfdCli.BroadcastTx([]sdk.Msg{transfer}, txOpt) @@ -51,10 +57,12 @@ func TestSendTokenWithTxOptionSucceed(t *testing.T) { func TestSimulateTx(t *testing.T) { km, err := keys.NewPrivateKeyManager(test.TEST_PRIVATE_KEY) assert.NoError(t, err) - gnfdCli := NewGreenfieldClientWithKeyManager(test.TEST_GRPC_ADDR, test.TEST_CHAIN_ID, km) + gnfdCli := NewGreenfieldClient(test.TEST_GRPC_ADDR, test.TEST_CHAIN_ID, + WithKeyManager(km), + WithGrpcDialOption(grpc.WithTransportCredentials(insecure.NewCredentials()))) to, err := sdk.AccAddressFromHexUnsafe(test.TEST_ADDR) assert.NoError(t, err) - transfer := banktypes.NewMsgSend(km.GetAddr(), to, sdk.NewCoins(sdk.NewInt64Coin("bnb", 100))) + transfer := banktypes.NewMsgSend(km.GetAddr(), to, sdk.NewCoins(sdk.NewInt64Coin(test.TEST_TOKEN_NAME, 100))) simulateRes, err := gnfdCli.SimulateTx([]sdk.Msg{transfer}, nil) assert.NoError(t, err) t.Log(simulateRes.GasInfo.String()) diff --git a/x/payment/types/params.go b/x/payment/types/params.go index 2883b453e..45e42e7a8 100644 --- a/x/payment/types/params.go +++ b/x/payment/types/params.go @@ -20,7 +20,7 @@ var ( DefaultForcedSettleTime uint64 = 24 * 60 * 60 // 1 day DefaultPaymentAccountCountLimit uint64 = 200 DefaultMaxAutoForceSettleNum uint64 = 100 - DefaultFeeDenom string = "bnb" + DefaultFeeDenom string = "BNB" ) // ParamKeyTable the param key table for launch module diff --git a/x/sp/types/params.go b/x/sp/types/params.go index 4c14c2621..8c8619c23 100644 --- a/x/sp/types/params.go +++ b/x/sp/types/params.go @@ -3,6 +3,7 @@ package types import ( "errors" fmt "fmt" + "math/big" "strings" "cosmossdk.io/math" @@ -16,11 +17,11 @@ const ( // Default maximum number of SP DefaultMaxStorageProviders uint32 = 100 // Dafault deposit denom - DefaultDepositDenom = "bnb" + DefaultDepositDenom = "BNB" ) // DefaultMinDeposit defines the minimum deposit amount for all storage provider -var DefaulMinDeposit math.Int = math.NewInt(10000) +var DefaulMinDeposit = math.NewIntFromBigInt(new(big.Int).Mul(big.NewInt(10000), big.NewInt(1e18))) var ( KeyMaxStorageProviders = []byte("MaxStorageProviders")