Skip to content

Commit

Permalink
feat(core): extra infos in the response of getTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanssen0 committed Aug 26, 2024
1 parent 8ff3fca commit e161e31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/client/clientTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export type TransactionStatus =
export type ClientTransactionResponse = {
transaction: Transaction;
status: TransactionStatus;
cycles?: Num;
blockHash?: Hex;
blockNumber?: Num;
txIndex?: Num;
reason?: string;
};

/**
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/client/jsonRpc/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
depTypeFrom,
hashTypeFrom,
} from "../../ckb/index.js";
import { Hex } from "../../hex/index.js";
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
import { NumLike, numFrom, numToHex } from "../../num/index.js";
import { apply } from "../../utils/index.js";
import {
Expand Down Expand Up @@ -172,10 +172,18 @@ export class JsonRpcTransformers {
});
}
static transactionResponseTo({
tx_status: { status },
cycles,
tx_status: { status, block_number, block_hash, tx_index, reason },
transaction,
}: {
tx_status: { status: TransactionStatus };
cycles?: NumLike;
tx_status: {
status: TransactionStatus;
block_hash?: HexLike;
tx_index?: NumLike;
block_number?: NumLike;
reason?: string;
};
transaction: JsonRpcTransaction | null;
}): ClientTransactionResponse | undefined {
if (transaction == null) {
Expand All @@ -185,6 +193,11 @@ export class JsonRpcTransformers {
return {
transaction: JsonRpcTransformers.transactionTo(transaction),
status,
cycles: apply(numFrom, cycles),
blockHash: apply(hexFrom, block_hash),
blockNumber: apply(numFrom, block_number),
txIndex: apply(numFrom, tx_index),
reason,
};
}
static blockHeaderTo(header: JsonRpcBlockHeader): ClientBlockHeader {
Expand Down

0 comments on commit e161e31

Please sign in to comment.