diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-15 23:44:25 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-15 23:44:25 +0800 |
commit | f2a2164184a9397d8e6100c370595ccdcd00ca0b (patch) | |
tree | be5f43c0255c6351b2c1b9a6db191318974fe664 /xeth | |
parent | f475a013264b5036dfe9fcc04e21c4112845b9a2 (diff) | |
parent | 1e3f4877c0e9ebf58ffa06b0b119fdf3bab21658 (diff) | |
download | go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.tar go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.tar.gz go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.tar.bz2 go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.tar.lz go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.tar.xz go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.tar.zst go-tangerine-f2a2164184a9397d8e6100c370595ccdcd00ca0b.zip |
Merge pull request #990 from zsfelfoldi/gasprice
eth: add GasPriceOracle
Diffstat (limited to 'xeth')
-rw-r--r-- | xeth/xeth.go | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/xeth/xeth.go b/xeth/xeth.go index d2f992084..71753d6bd 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -39,8 +39,14 @@ const ( LogFilterTy ) -func DefaultGas() *big.Int { return new(big.Int).Set(defaultGas) } -func DefaultGasPrice() *big.Int { return new(big.Int).Set(defaultGasPrice) } +func DefaultGas() *big.Int { return new(big.Int).Set(defaultGas) } + +func (self *XEth) DefaultGasPrice() *big.Int { + if self.gpo == nil { + self.gpo = eth.NewGasPriceOracle(self.backend) + } + return self.gpo.SuggestPrice() +} type XEth struct { backend *eth.Ethereum @@ -68,6 +74,8 @@ type XEth struct { // register map[string][]*interface{} // TODO improve return type agent *miner.RemoteAgent + + gpo *eth.GasPriceOracle } func NewTest(eth *eth.Ethereum, frontend Frontend) *XEth { @@ -80,22 +88,22 @@ func NewTest(eth *eth.Ethereum, frontend Frontend) *XEth { // New creates an XEth that uses the given frontend. // If a nil Frontend is provided, a default frontend which // confirms all transactions will be used. -func New(eth *eth.Ethereum, frontend Frontend) *XEth { +func New(ethereum *eth.Ethereum, frontend Frontend) *XEth { xeth := &XEth{ - backend: eth, + backend: ethereum, frontend: frontend, quit: make(chan struct{}), - filterManager: filter.NewFilterManager(eth.EventMux()), + filterManager: filter.NewFilterManager(ethereum.EventMux()), logQueue: make(map[int]*logQueue), blockQueue: make(map[int]*hashQueue), transactionQueue: make(map[int]*hashQueue), messages: make(map[int]*whisperFilter), agent: miner.NewRemoteAgent(), } - if eth.Whisper() != nil { - xeth.whisper = NewWhisper(eth.Whisper()) + if ethereum.Whisper() != nil { + xeth.whisper = NewWhisper(ethereum.Whisper()) } - eth.Miner().Register(xeth.agent) + ethereum.Miner().Register(xeth.agent) if frontend == nil { xeth.frontend = dummyFrontend{} } @@ -227,6 +235,7 @@ func (self *XEth) WithState(statedb *state.StateDB) *XEth { xeth := &XEth{ backend: self.backend, frontend: self.frontend, + gpo: self.gpo, } xeth.state = NewState(xeth, statedb) @@ -829,7 +838,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st } if msg.gasPrice.Cmp(big.NewInt(0)) == 0 { - msg.gasPrice = DefaultGasPrice() + msg.gasPrice = self.DefaultGasPrice() } block := self.CurrentBlock() @@ -898,7 +907,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS } if len(gasPriceStr) == 0 { - price = DefaultGasPrice() + price = self.DefaultGasPrice() } else { price = common.Big(gasPriceStr) } |