Skip to content

Commit

Permalink
Change TraceTransaction error code on txn hash not found case
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Nov 28, 2023
1 parent fff569c commit 4e0b623
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,13 +1340,17 @@ func (h *Handler) TraceTransaction(ctx context.Context, hash felt.Felt) (json.Ra
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/1ae810e0137cc5d175ace4554892a4f43052be56/api/starknet_trace_api_openrpc.json#L11
func (h *Handler) LegacyTraceTransaction(ctx context.Context, hash felt.Felt) (json.RawMessage, *jsonrpc.Error) {
return h.traceTransaction(ctx, &hash, true)
trace, err := h.traceTransaction(ctx, &hash, true)
if err.Code == ErrTxnHashNotFound.Code {
err = ErrInvalidTxHash
}
return trace, err
}

func (h *Handler) traceTransaction(ctx context.Context, hash *felt.Felt, legacyTraceJSON bool) (json.RawMessage, *jsonrpc.Error) {
_, _, blockNumber, err := h.bcReader.Receipt(hash)
if err != nil {
return nil, ErrInvalidTxHash
return nil, ErrTxnHashNotFound
}

block, err := h.bcReader.BlockByNumber(blockNumber)
Expand Down
2 changes: 1 addition & 1 deletion rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,7 @@ func TestTraceTransaction(t *testing.T) {

trace, err := handler.TraceTransaction(context.Background(), *hash)
assert.Nil(t, trace)
assert.Equal(t, rpc.ErrInvalidTxHash, err)
assert.Equal(t, rpc.ErrTxnHashNotFound, err)
})
t.Run("ok", func(t *testing.T) {
hash := utils.HexToFelt(t, "0x37b244ea7dc6b3f9735fba02d183ef0d6807a572dd91a63cc1b14b923c1ac0")
Expand Down

0 comments on commit 4e0b623

Please sign in to comment.