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 600cc13
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .changeset/hip-plums-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@ckb-ccc/core": patch
---

feat(core): extra infos in the response of getTransaction

- blockNumber
- blockHash
- cycles
- reason (When failed)
- txIndex (After CKB 0.118)
22 changes: 22 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"@ckb-ccc/ccc": "0.0.12",
"ckb-ccc": "0.0.12",
"@ckb-ccc/connector": "0.0.12",
"@ckb-ccc/connector-react": "0.0.12",
"@ckb-ccc/core": "0.0.12",
"@ckb-ccc/ccc-demo": "0.0.1",
"@ckb-ccc/eip6963": "0.0.12",
"@ckb-ccc/faucet": "0.0.1",
"@ckb-ccc/joy-id": "0.0.12",
"@ckb-ccc/lumos-patches": "0.0.12",
"@ckb-ccc/nip07": "0.0.12",
"@ckb-ccc/okx": "0.0.12",
"@ckb-ccc/rei": "0.0.12",
"@ckb-ccc/uni-sat": "0.0.12",
"@ckb-ccc/utxo-global": "0.0.12"
},
"changesets": []
}
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 600cc13

Please sign in to comment.