accounts/abi/bind/backends: return errors instead of panic (#24242)

This commit is contained in:
Pantelis Peslis 2022-01-18 11:17:37 +02:00 committed by GitHub
parent b1f09596e6
commit f80ce141a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -639,7 +639,6 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
} }
// SendTransaction updates the pending block to include the given transaction. // SendTransaction updates the pending block to include the given transaction.
// It panics if the transaction is invalid.
func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error { func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
@ -647,17 +646,17 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
// Get the last block // Get the last block
block, err := b.blockByHash(ctx, b.pendingBlock.ParentHash()) block, err := b.blockByHash(ctx, b.pendingBlock.ParentHash())
if err != nil { if err != nil {
panic("could not fetch parent") return fmt.Errorf("could not fetch parent")
} }
// Check transaction validity // Check transaction validity
signer := types.MakeSigner(b.blockchain.Config(), block.Number()) signer := types.MakeSigner(b.blockchain.Config(), block.Number())
sender, err := types.Sender(signer, tx) sender, err := types.Sender(signer, tx)
if err != nil { if err != nil {
panic(fmt.Errorf("invalid transaction: %v", err)) return fmt.Errorf("invalid transaction: %v", err)
} }
nonce := b.pendingState.GetNonce(sender) nonce := b.pendingState.GetNonce(sender)
if tx.Nonce() != nonce { if tx.Nonce() != nonce {
panic(fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)) return fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)
} }
// Include tx in chain // Include tx in chain
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) { blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {