Skip to content

Commit

Permalink
Allow errors in the middle of eth_callBundle
Browse files Browse the repository at this point in the history
Change the return object to be a map, with result/error keys. Also add
txHash
  • Loading branch information
jparyani committed Jan 22, 2021
1 parent 9199d2e commit a99dfc1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ func NewBundleAPI(b Backend) *BundleAPI {

// CallBundle will simulate a bundle of transactions at the top of a block.
// The sender is responsible for signing the transactions and using the correct nonce and ensuring validity
func (s *BundleAPI) CallBundle(ctx context.Context, encodedTxs []hexutil.Bytes, blockNrOrHash rpc.BlockNumberOrHash, blockTimestamp *uint64) ([]hexutil.Bytes, error) {
func (s *BundleAPI) CallBundle(ctx context.Context, encodedTxs []hexutil.Bytes, blockNrOrHash rpc.BlockNumberOrHash, blockTimestamp *uint64) ([]map[string]interface{}, error) {
if len(encodedTxs) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -2034,7 +2034,7 @@ func (s *BundleAPI) CallBundle(ctx context.Context, encodedTxs []hexutil.Bytes,
// and apply the message.
gp := new(core.GasPool).AddGas(math.MaxUint64)

results := []hexutil.Bytes{}
results := []map[string]interface{}{}
for _, tx := range txs {
msg, err := tx.AsMessage(signer)
if err != nil {
Expand All @@ -2051,10 +2051,16 @@ func (s *BundleAPI) CallBundle(ctx context.Context, encodedTxs []hexutil.Bytes,
if err != nil {
return nil, fmt.Errorf("err: %w; supplied gas %d; txhash %s", err, msg.Gas(), tx.Hash())
}
jsonResult := map[string]interface{}{
"txHash": tx.Hash().String(),
}

if result.Err != nil {
return nil, fmt.Errorf("err in tx: %w; supplied gas %d; txhash %s", result.Err, msg.Gas(), tx.Hash())
jsonResult["error"] = result.Err.Error()
} else {
jsonResult["value"] = common.BytesToHash(result.Return())
}
results = append(results, result.Return())
results = append(results, jsonResult)
}
return results, nil
}

0 comments on commit a99dfc1

Please sign in to comment.