aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark.lin <mark@maicoin.com>2018-01-29 18:47:08 +0800
committermark.lin <mark@maicoin.com>2018-01-29 18:47:08 +0800
commitc1d70ea97082145f5ba04cf4feb9792136b51507 (patch)
treef98e0d133397c2ef837c12d46cde274c504c9f69
parent05ade19302357eba6a24348f31df140ce0eca326 (diff)
downloaddexon-c1d70ea97082145f5ba04cf4feb9792136b51507.tar.gz
dexon-c1d70ea97082145f5ba04cf4feb9792136b51507.tar.zst
dexon-c1d70ea97082145f5ba04cf4feb9792136b51507.zip
accounts/abi, core: add AddTxWithChain in BlockGen for simulation
-rw-r--r--accounts/abi/bind/backends/simulated.go4
-rw-r--r--core/chain_makers.go14
2 files changed, 15 insertions, 3 deletions
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go
index 81c32e421..5d8aa48a4 100644
--- a/accounts/abi/bind/backends/simulated.go
+++ b/accounts/abi/bind/backends/simulated.go
@@ -293,9 +293,9 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
for _, tx := range b.pendingBlock.Transactions() {
- block.AddTx(tx)
+ block.AddTxWithChain(b.blockchain, tx)
}
- block.AddTx(tx)
+ block.AddTxWithChain(b.blockchain, tx)
})
b.pendingBlock = blocks[0]
b.pendingState, _ = state.New(b.pendingBlock.Root(), state.NewDatabase(b.database))
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 5e264a994..9bd3b2aee 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -82,11 +82,23 @@ func (b *BlockGen) SetExtra(data []byte) {
// added. Notably, contract code relying on the BLOCKHASH instruction
// will panic during execution.
func (b *BlockGen) AddTx(tx *types.Transaction) {
+ b.AddTxWithChain(nil, tx)
+}
+
+// AddTxWithChain adds a transaction to the generated block. If no coinbase has
+// been set, the block's coinbase is set to the zero address.
+//
+// AddTxWithChain panics if the transaction cannot be executed. In addition to
+// the protocol-imposed limitations (gas limit, etc.), there are some
+// further limitations on the content of transactions that can be
+// added. If contract code relies on the BLOCKHASH instruction,
+// the block in chain will be returned.
+func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
if b.gasPool == nil {
b.SetCoinbase(common.Address{})
}
b.statedb.Prepare(tx.Hash(), common.Hash{}, len(b.txs))
- receipt, _, err := ApplyTransaction(b.config, nil, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
+ receipt, _, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
if err != nil {
panic(err)
}