Skip to content

Commit

Permalink
Update ContractError to have the expected data field
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Oct 3, 2023
1 parent 0912efb commit e660f69
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,21 @@ func (h *Handler) Call(call FunctionCall, id BlockID) ([]*felt.Felt, *jsonrpc.Er

res, err := h.vm.Call(&call.ContractAddress, &call.EntryPointSelector, call.Calldata, blockNumber, header.Timestamp, state, h.network)
if err != nil {
contractErr := *ErrContractError
contractErr.Data = err.Error()
return nil, &contractErr
return nil, makeContractError(err)
}
return res, nil
}

func makeContractError(err error) *jsonrpc.Error {
contractErr := *ErrContractError
contractErr.Data = struct {
RevertError string `json:"revert_error"`
}{
RevertError: err.Error(),
}
return &contractErr
}

func (h *Handler) TransactionStatus(ctx context.Context, hash felt.Felt) (*TransactionStatus, *jsonrpc.Error) {
var status *TransactionStatus

Expand Down Expand Up @@ -1279,9 +1287,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
overallFees, traces, err := h.vm.Execute(txns, classes, blockNumber, header.Timestamp, sequencerAddress,
state, h.network, paidFeesOnL1, skipFeeCharge, header.GasPrice, legacyTraceJSON)
if err != nil {
rpcErr := *ErrContractError
rpcErr.Data = err.Error()
return nil, &rpcErr
return nil, makeContractError(err)
}

var result []SimulatedTransaction
Expand Down Expand Up @@ -1378,9 +1384,7 @@ func (h *Handler) traceBlockTransactions(block *core.Block, numTxns int, legacyT
_, traces, err := h.vm.Execute(transactions, classes, blockNumber, header.Timestamp,
sequencerAddress, state, h.network, paidFeesOnL1, false, header.GasPrice, legacyTraceJSON)
if err != nil {
rpcErr := *ErrContractError
rpcErr.Data = err.Error()
return nil, &rpcErr
return nil, makeContractError(err)
}

var result []TracedBlockTransaction
Expand Down

0 comments on commit e660f69

Please sign in to comment.