Skip to content

Commit

Permalink
Merge pull request #10 from binance-chain/gas_price
Browse files Browse the repository at this point in the history
R4R: add gas price to config
  • Loading branch information
unclezoro authored Aug 29, 2020
2 parents 696e7f0 + 0b283c9 commit 88d9bcb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type BSCConfig struct {
PrivateKey string `json:"private_key"`
Provider string `json:"provider"`
GasLimit uint64 `json:"gas_limit"`
GasPrice uint64 `json:"gas_price"`
MonitorDataSeedList []string `json:"monitor_data_seed_list"`
}

Expand All @@ -113,7 +114,7 @@ func (cfg *BSCConfig) Validate() {
if cfg.KeyType != KeyTypeAWSPrivateKey && cfg.PrivateKey == "" {
panic(fmt.Sprintf("privateKey of Binance Smart Chain should not be empty"))
}
if cfg.GasLimit <= 0 {
if cfg.GasLimit == 0 {
panic(fmt.Sprintf("gas_limit of Binance Smart Chain should be larger than 0"))
}
}
Expand Down
1 change: 1 addition & 0 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"private_key": "",
"provider": "https://data-seed-prebsc-1-s1.binance.org:8545",
"gas_limit": 4700000,
"gas_price": 20000000000,
"monitor_data_seed_list": []
},
"log_config": {
Expand Down
11 changes: 5 additions & 6 deletions executor/bsc_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ func (executor *BSCExecutor) getTransactor() (*bind.TransactOpts, error) {
return nil, err
}

gasPrice, err := executor.bscClient.SuggestGasPrice(context.Background())
if err != nil {
return nil, err
}

txOpts := bind.NewKeyedTransactor(executor.privateKey)
txOpts.Nonce = big.NewInt(int64(nonce))
txOpts.Value = big.NewInt(0)
txOpts.GasLimit = executor.bscConfig.GasLimit
txOpts.GasPrice = gasPrice
if executor.bscConfig.GasPrice == 0 {
txOpts.GasPrice = big.NewInt(DefaultGasPrice)
} else {
txOpts.GasPrice = big.NewInt(int64(executor.bscConfig.GasPrice))
}
return txOpts, nil
}

Expand Down
12 changes: 6 additions & 6 deletions executor/bsc_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ import (
)

const (
BBCRpc = "http://dex-qa-s1-bsc-dev-validator-alb-501442930.ap-northeast-1.elb.amazonaws.com:27147"
provider = "http://dex-qa-s1-bsc-dev-validator-alb-501442930.ap-northeast-1.elb.amazonaws.com:8545"
BBCRpc = "tcp://seed-pre-s3.binance.org:80"
provider = "http://data-seed-prebsc-1-s1.binance.org:8545"
privateKey = "EB19E69C9EBF9737FCB41AFFF5D6E3B3711E15579E5FA89F03DC4656EEC34E4D"
)

var (
cfg = &config.Config{
CrossChainConfig: &config.CrossChainConfig{
CrossChainConfig: config.CrossChainConfig{
SourceChainID: 1,
DestChainID: 96,
DestChainID: 97,
},
BBCConfig: &config.BBCConfig{
BBCConfig: config.BBCConfig{
RpcAddr: BBCRpc,
},
BSCConfig: &config.BSCConfig{
BSCConfig: config.BSCConfig{
GasLimit: 4700000,
Provider: provider,
PrivateKey: privateKey,
Expand Down
2 changes: 2 additions & 0 deletions executor/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
CrossChainPackageEventType = "IBCPackage"
CorssChainPackageInfoAttributeKey = "IBCPackageInfo"
CorssChainPackageInfoAttributeValue = "%d" + separator + "%d" + separator + "%d" // destChainID channelID sequence

DefaultGasPrice = 20000000000 // 20 GWei
)

var (
Expand Down

0 comments on commit 88d9bcb

Please sign in to comment.