forked from cerc-io/laconicd-deprecated
Add support for miner_setGasPrice API (#1237)
This commit is contained in:
parent
66e8cdbe02
commit
989192028f
@ -49,6 +49,7 @@ type EVMBackend interface {
|
|||||||
Accounts() ([]common.Address, error)
|
Accounts() ([]common.Address, error)
|
||||||
Syncing() (interface{}, error)
|
Syncing() (interface{}, error)
|
||||||
SetEtherbase(etherbase common.Address) bool
|
SetEtherbase(etherbase common.Address) bool
|
||||||
|
SetGasPrice(gasPrice hexutil.Big) bool
|
||||||
ImportRawKey(privkey, password string) (common.Address, error)
|
ImportRawKey(privkey, password string) (common.Address, error)
|
||||||
ListAccounts() ([]common.Address, error)
|
ListAccounts() ([]common.Address, error)
|
||||||
NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (*keyring.Record, error)
|
NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (*keyring.Record, error)
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||||
sdkcrypto "github.com/cosmos/cosmos-sdk/crypto"
|
sdkcrypto "github.com/cosmos/cosmos-sdk/crypto"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
|
sdkconfig "github.com/cosmos/cosmos-sdk/server/config"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
||||||
rpctypes "github.com/evmos/ethermint/rpc/types"
|
rpctypes "github.com/evmos/ethermint/rpc/types"
|
||||||
|
"github.com/evmos/ethermint/server/config"
|
||||||
ethermint "github.com/evmos/ethermint/types"
|
ethermint "github.com/evmos/ethermint/types"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
@ -239,6 +241,35 @@ func (b *Backend) NewMnemonic(uid string, language keyring.Language, hdPath, bip
|
|||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGasPrice sets the minimum accepted gas price for the miner.
|
||||||
|
// NOTE: this function accepts only integers to have the same interface than go-eth
|
||||||
|
// to use float values, the gas prices must be configured using the configuration file
|
||||||
|
func (b *Backend) SetGasPrice(gasPrice hexutil.Big) bool {
|
||||||
|
appConf := config.GetConfig(b.clientCtx.Viper)
|
||||||
|
|
||||||
|
var unit string
|
||||||
|
minGasPrices := appConf.GetMinGasPrices()
|
||||||
|
|
||||||
|
// fetch the base denom from the sdk Config in case it's not currently defined on the node config
|
||||||
|
if len(minGasPrices) == 0 || minGasPrices.Empty() {
|
||||||
|
var err error
|
||||||
|
unit, err = sdk.GetBaseDenom()
|
||||||
|
if err != nil {
|
||||||
|
b.logger.Debug("could not get the denom of smallest unit registered", "error", err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unit = minGasPrices[0].Denom
|
||||||
|
}
|
||||||
|
|
||||||
|
c := sdk.NewDecCoin(unit, sdk.NewIntFromBigInt(gasPrice.ToInt()))
|
||||||
|
|
||||||
|
appConf.SetMinGasPrices(sdk.DecCoins{c})
|
||||||
|
sdkconfig.WriteConfigFile(b.clientCtx.Viper.ConfigFileUsed(), appConf)
|
||||||
|
b.logger.Info("Your configuration file was modified. Please RESTART your node.", "gas-price", c.String())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// UnprotectedAllowed returns the node configuration value for allowing
|
// UnprotectedAllowed returns the node configuration value for allowing
|
||||||
// unprotected transactions (i.e not replay-protected)
|
// unprotected transactions (i.e not replay-protected)
|
||||||
func (b Backend) UnprotectedAllowed() bool {
|
func (b Backend) UnprotectedAllowed() bool {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -34,3 +35,9 @@ func (api *API) SetEtherbase(etherbase common.Address) bool {
|
|||||||
api.logger.Debug("miner_setEtherbase")
|
api.logger.Debug("miner_setEtherbase")
|
||||||
return api.backend.SetEtherbase(etherbase)
|
return api.backend.SetEtherbase(etherbase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGasPrice sets the minimum accepted gas price for the miner.
|
||||||
|
func (api *API) SetGasPrice(gasPrice hexutil.Big) bool {
|
||||||
|
api.logger.Info(api.ctx.Viper.ConfigFileUsed())
|
||||||
|
return api.backend.SetGasPrice(gasPrice)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user