diff --git a/.changeset/yellow-trees-talk.md b/.changeset/yellow-trees-talk.md new file mode 100644 index 00000000000..8556e240630 --- /dev/null +++ b/.changeset/yellow-trees-talk.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/transactions": patch +"@fuel-ts/account": patch +--- + +chore: fix receipts properties and deprecate incorrect ones diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index f8791c58505..226c6642e00 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -365,6 +365,10 @@ describe('Provider', () => { val1: bn(186), val2: bn(0), val3: bn(0), + ra: bn(202), + rb: bn(186), + rc: bn(0), + rd: bn(0), pc: bn(0x2888), is: bn(0x2880), }, diff --git a/packages/account/src/providers/transaction-summary/operations.test.ts b/packages/account/src/providers/transaction-summary/operations.test.ts index 9a00406afc2..b6d7cae9b70 100644 --- a/packages/account/src/providers/transaction-summary/operations.test.ts +++ b/packages/account/src/providers/transaction-summary/operations.test.ts @@ -882,6 +882,7 @@ describe('operations', () => { amount: bn('0x5f5e100'), assetId: '0x0000000000000000000000000000000000000000000000000000000000000000', from: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', + id: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', is: bn('0x4370'), pc: bn('0x57dc'), to: '0x3e7ddda4d0d3f8307ae5f1aed87623992c1c4decefec684936960775181b2302', diff --git a/packages/account/src/providers/utils/receipts.ts b/packages/account/src/providers/utils/receipts.ts index bfc1ec9b85f..f2cd9deacf7 100644 --- a/packages/account/src/providers/utils/receipts.ts +++ b/packages/account/src/providers/utils/receipts.ts @@ -66,9 +66,11 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { switch (receiptType) { case GqlReceiptType.Call: { + const id = hexOrZero(receipt.id || receipt.contractId); const callReceipt: ReceiptCall = { type: ReceiptType.Call, - from: hexOrZero(receipt.id || receipt.contractId), + id, + from: id, to: hexOrZero(receipt?.to), amount: bn(receipt.amount), assetId: hexOrZero(receipt.assetId), @@ -134,13 +136,22 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.Log: { + const ra = bn(receipt.ra); + const rb = bn(receipt.rb); + const rc = bn(receipt.rc); + const rd = bn(receipt.rd); + const logReceipt: ReceiptLog = { type: ReceiptType.Log, id: hexOrZero(receipt.id || receipt.contractId), - val0: bn(receipt.ra), - val1: bn(receipt.rb), - val2: bn(receipt.rc), - val3: bn(receipt.rd), + ra, + rb, + rc, + rd, + val0: ra, + val1: rb, + val2: rc, + val3: rd, pc: bn(receipt.pc), is: bn(receipt.is), }; @@ -149,11 +160,15 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.LogData: { + const ra = bn(receipt.ra); + const rb = bn(receipt.rb); const logDataReceipt: ReceiptLogData = { type: ReceiptType.LogData, id: hexOrZero(receipt.id || receipt.contractId), - val0: bn(receipt.ra), - val1: bn(receipt.rb), + ra, + rb, + val0: ra, + val1: rb, ptr: bn(receipt.ptr), len: bn(receipt.len), digest: hexOrZero(receipt.digest), @@ -165,9 +180,11 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.Transfer: { + const id = hexOrZero(receipt.id || receipt.contractId); const transferReceipt: ReceiptTransfer = { type: ReceiptType.Transfer, - from: hexOrZero(receipt.id || receipt.contractId), + id, + from: id, to: hexOrZero(receipt.toAddress || receipt?.to), amount: bn(receipt.amount), assetId: hexOrZero(receipt.assetId), @@ -179,9 +196,11 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.TransferOut: { + const id = hexOrZero(receipt.id || receipt.contractId); const transferOutReceipt: ReceiptTransferOut = { type: ReceiptType.TransferOut, - from: hexOrZero(receipt.id || receipt.contractId), + id, + from: id, to: hexOrZero(receipt.toAddress || receipt.to), amount: bn(receipt.amount), assetId: hexOrZero(receipt.assetId), diff --git a/packages/account/test/fixtures/transaction-summary.ts b/packages/account/test/fixtures/transaction-summary.ts index 10054eef528..9ed7e2bd689 100644 --- a/packages/account/test/fixtures/transaction-summary.ts +++ b/packages/account/test/fixtures/transaction-summary.ts @@ -109,6 +109,7 @@ export const MOCK_OUTPUT_CONTRACT_CREATED: OutputContractCreated = { export const MOCK_RECEIPT_CALL: TransactionResultCallReceipt = { type: ReceiptType.Call, from: '0x0000000000000000000000000000000000000000000000000000000000000000', + id: '0x0000000000000000000000000000000000000000000000000000000000000000', to: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', amount: bn(100000000), assetId: '0x0000000000000000000000000000000000000000000000000000000000000000', @@ -129,6 +130,7 @@ export const MOCK_RECEIPT_RETURN: TransactionResultReturnReceipt = { export const MOCK_RECEIPT_TRANSFER: TransactionResultTransferReceipt = { type: ReceiptType.Transfer, + id: '0x0000000000000000000000000000000000000000000000000000000000000000', from: '0x0000000000000000000000000000000000000000000000000000000000000000', to: '0xaab4884920fa4d3a35fc2977cc442b0caddf87e001ef62321b6c02f5ab0f4115', amount: bn(988), @@ -139,6 +141,7 @@ export const MOCK_RECEIPT_TRANSFER: TransactionResultTransferReceipt = { export const MOCK_RECEIPT_TRANSFER_OUT: TransactionResultTransferOutReceipt = { type: ReceiptType.TransferOut, + id: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', from: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', to: '0x3e7ddda4d0d3f8307ae5f1aed87623992c1c4decefec684936960775181b2302', amount: bn(100000000), diff --git a/packages/transactions/src/coders/receipt.test.ts b/packages/transactions/src/coders/receipt.test.ts index 77b185c1957..7199104f06e 100644 --- a/packages/transactions/src/coders/receipt.test.ts +++ b/packages/transactions/src/coders/receipt.test.ts @@ -19,6 +19,7 @@ describe('ReceiptCoder', () => { it('Can encode Call', () => { const receipt: Receipt = { type: ReceiptType.Call, + id: B256, from: B256, to: B256, amount: bn(0), @@ -134,6 +135,10 @@ describe('ReceiptCoder', () => { const receipt: Receipt = { type: ReceiptType.Log, id: B256, + ra: bn(0), + rb: bn(0), + rc: bn(0), + rd: bn(0), val0: bn(0), val1: bn(0), val2: bn(0), @@ -158,6 +163,8 @@ describe('ReceiptCoder', () => { const receipt: Receipt = { type: ReceiptType.LogData, id: B256, + ra: bn(0), + rb: bn(0), val0: bn(0), val1: bn(0), ptr: bn(0), @@ -183,6 +190,7 @@ describe('ReceiptCoder', () => { it('Can encode Transfer', () => { const receipt: Receipt = { type: ReceiptType.Transfer, + id: B256, from: B256, to: B256, amount: bn(0), @@ -206,6 +214,7 @@ describe('ReceiptCoder', () => { it('Can encode TransferOut', () => { const receipt: Receipt = { type: ReceiptType.TransferOut, + id: B256, from: B256, to: B256, amount: bn(0), diff --git a/packages/transactions/src/coders/receipt.ts b/packages/transactions/src/coders/receipt.ts index f5ce228dd69..722cc1ad92c 100644 --- a/packages/transactions/src/coders/receipt.ts +++ b/packages/transactions/src/coders/receipt.ts @@ -26,8 +26,12 @@ export enum ReceiptType /* u8 */ { export type ReceiptCall = { type: ReceiptType.Call; - /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `id` instead. + */ from: string; + /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + id: string; /** Contract ID of called contract (b256) */ to: string; /** Amount of coins to forward, i.e. $rB (u64) */ @@ -77,7 +81,7 @@ export class ReceiptCallCoder extends Coder { let o = offset; [decoded, o] = new B256Coder().decode(data, o); - const from = decoded; + const id = decoded; [decoded, o] = new B256Coder().decode(data, o); const to = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); @@ -98,7 +102,8 @@ export class ReceiptCallCoder extends Coder { return [ { type: ReceiptType.Call, - from, + id, + from: id, to, amount, assetId, @@ -377,14 +382,30 @@ export type ReceiptLog = { type: ReceiptType.Log; /** Contract ID of current context if in an internal context, zero otherwise (b256) */ id: string; - /** Value of register $rA (u64) */ + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `ra` instead. + */ val0: BN; - /** Value of register $rB (u64) */ + /** Value of register $rA (u64) */ + ra: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rb` instead. + */ val1: BN; - /** Value of register $rC (u64) */ + /** Value of register $rB (u64) */ + rb: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rc` instead. + */ val2: BN; - /** Value of register $rD (u64) */ + /** Value of register $rC (u64) */ + rc: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rd` instead. + */ val3: BN; + /** Value of register $rD (u64) */ + rd: BN; /** Value of register $pc (u64) */ pc: BN; /** Value of register $is (u64) */ @@ -422,13 +443,13 @@ export class ReceiptLogCoder extends Coder { [decoded, o] = new B256Coder().decode(data, o); const id = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val0 = decoded; + const ra = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val1 = decoded; + const rb = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val2 = decoded; + const rc = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val3 = decoded; + const rd = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); const pc = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); @@ -438,10 +459,14 @@ export class ReceiptLogCoder extends Coder { { type: ReceiptType.Log, id, - val0, - val1, - val2, - val3, + ra, + rb, + rc, + rd, + val0: ra, + val1: rb, + val2: rc, + val3: rd, pc, is, }, @@ -455,8 +480,16 @@ export type ReceiptLogData = { /** Contract ID of current context if in an internal context, zero otherwise (b256) */ id: string; /** Value of register $rA (u64) */ + ra: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `ra` instead. + */ val0: BN; /** Value of register $rB (u64) */ + rb: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rb` instead. + */ val1: BN; /** Value of register $rC (u64) */ ptr: BN; @@ -505,9 +538,9 @@ export class ReceiptLogDataCoder extends Coder { [decoded, o] = new B256Coder().decode(data, o); const id = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val0 = decoded; + const ra = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val1 = decoded; + const rb = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); const ptr = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); @@ -525,8 +558,10 @@ export class ReceiptLogDataCoder extends Coder { { type: ReceiptType.LogData, id, - val0, - val1, + ra, + rb, + val0: ra, + val1: rb, ptr, len, digest, @@ -541,8 +576,12 @@ export class ReceiptLogDataCoder extends Coder { export type ReceiptTransfer = { type: ReceiptType.Transfer; - /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `id` instead. + */ from: string; + /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + id: string; /** Contract ID of contract to transfer coins to (b256) */ to: string; /** Amount of coins transferred (u64) */ @@ -583,7 +622,7 @@ export class ReceiptTransferCoder extends Coder