Skip to content

Commit

Permalink
api: Add Consensus transaction failure details
Browse files Browse the repository at this point in the history
  • Loading branch information
aefhm committed Mar 9, 2023
1 parent 477aac1 commit 2645798
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
9 changes: 9 additions & 0 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,15 @@ components:
success:
type: boolean
description: Whether this transaction successfully executed.
code:
type: integer
description: The status code of a failed call.
module:
type: string
description: The module of a failed call.
message:
type: string
description: The message of a failed call.
description: |
A consensus transaction.
Expand Down
24 changes: 18 additions & 6 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ func (c *StorageClient) Transactions(ctx context.Context, p apiTypes.GetConsensu
}
for res.rows.Next() {
var t Transaction
var code uint64
var module string
var message string
if err := res.rows.Scan(
&t.Block,
&t.Index,
Expand All @@ -271,13 +272,18 @@ func (c *StorageClient) Transactions(ctx context.Context, p apiTypes.GetConsensu
&t.Fee,
&t.Method,
&t.Body,
&code,
&t.Code,
&module,
&message,
&t.Timestamp,
); err != nil {
return nil, wrapError(err)
}
if code == oasisErrors.CodeNoError {
if *t.Code == oasisErrors.CodeNoError {
t.Success = true
} else {
t.Module = &module
t.Message = &message
}

ts.Transactions = append(ts.Transactions, t)
Expand All @@ -295,7 +301,8 @@ func (c *StorageClient) Transaction(ctx context.Context, txHash string) (*Transa
}

var t Transaction
var code uint64
var module string
var message string
if err := c.db.QueryRow(
ctx,
queries.Transaction,
Expand All @@ -309,13 +316,18 @@ func (c *StorageClient) Transaction(ctx context.Context, txHash string) (*Transa
&t.Fee,
&t.Method,
&t.Body,
&code,
&t.Code,
&module,
&message,
&t.Timestamp,
); err != nil {
return nil, wrapError(err)
}
if code == oasisErrors.CodeNoError {
if *t.Code == oasisErrors.CodeNoError {
t.Success = true
} else {
t.Module = &module
t.Message = &message
}

c.cacheTx(&t)
Expand Down
4 changes: 3 additions & 1 deletion storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
chain.transactions.method as method,
chain.transactions.body as body,
chain.transactions.code as code,
chain.transactions.module as module,
chain.transactions.message as message,
chain.blocks.time as time
FROM chain.transactions
JOIN chain.blocks ON chain.transactions.block = chain.blocks.height
Expand All @@ -64,7 +66,7 @@ const (
OFFSET $9::bigint`

Transaction = `
SELECT block, tx_index, tx_hash, sender, nonce, fee_amount, method, body, code, chain.blocks.time
SELECT block, tx_index, tx_hash, sender, nonce, fee_amount, method, body, code, module, message, chain.blocks.time
FROM chain.transactions
JOIN chain.blocks ON chain.transactions.block = chain.blocks.height
WHERE tx_hash = $1::text`
Expand Down

0 comments on commit 2645798

Please sign in to comment.