Skip to content

Commit

Permalink
fix: add missing receipts properties (#3156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored and nedsalk committed Sep 17, 2024
1 parent dc0db20 commit e6b6af9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .changeset/three-hairs-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/transactions": patch
"@fuel-ts/account": patch
---

fix: add missing receipts properties
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ describe('operations', () => {
nonce: '0x66c4d70c08ff30cd2d9dae0b6fd05972997579328529bb0605dd604afedfdf93',
recipient: '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
sender: '0x4aec2335430f52d0314a03b244d285c675d790dfbf0bc853fd31e39548ad8b7d',
len: 0,
type: 10,
};

Expand Down
22 changes: 2 additions & 20 deletions packages/account/src/providers/transaction-summary/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,8 @@ import { assembleReceiptByType } from '../utils';

import type { BurnedAsset, MintedAsset } from './types';

export const processGqlReceipt = (gqlReceipt: GqlReceiptFragment): TransactionResultReceipt => {
const receipt = assembleReceiptByType(gqlReceipt);

switch (receipt.type) {
case ReceiptType.ReturnData: {
return {
...receipt,
data: gqlReceipt.data || '0x',
};
}
case ReceiptType.LogData: {
return {
...receipt,
data: gqlReceipt.data || '0x',
};
}
default:
return receipt;
}
};
export const processGqlReceipt = (gqlReceipt: GqlReceiptFragment): TransactionResultReceipt =>
assembleReceiptByType(gqlReceipt);

export const extractMintedAssetsFromReceipts = (
receipts: Array<TransactionResultReceipt>
Expand Down
4 changes: 4 additions & 0 deletions packages/account/src/providers/utils/receipts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('assembleReceiptByType', () => {
expect(receipt.len).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.len));
expect(receipt.is).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.is));
expect(receipt.pc).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.pc));
expect(receipt.data).toStrictEqual(MOCK_GQL_RECEIPT_FRAGMENT.data);
expect(receipt.ptr).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.ptr));
});

Expand Down Expand Up @@ -133,6 +134,7 @@ describe('assembleReceiptByType', () => {
expect(receipt.len).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.len));
expect(receipt.val0).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.ra));
expect(receipt.val1).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.rb));
expect(receipt.data).toStrictEqual(MOCK_GQL_RECEIPT_FRAGMENT.data);
});

it('should return a ReceiptTransfer receipt when GqlReceiptType.Transfer is provided', () => {
Expand Down Expand Up @@ -218,6 +220,7 @@ describe('assembleReceiptByType', () => {
const amount = bn(MOCK_GQL_RECEIPT_FRAGMENT.amount);
const data = arrayify(MOCK_GQL_RECEIPT_FRAGMENT.data || '');
const digest = MOCK_GQL_RECEIPT_FRAGMENT.digest;
const len = Number(MOCK_GQL_RECEIPT_FRAGMENT.len);

const messageId = ReceiptMessageOutCoder.getMessageId({
sender,
Expand All @@ -234,6 +237,7 @@ describe('assembleReceiptByType', () => {
expect(receipt.nonce).toStrictEqual(nonce);
expect(receipt.recipient).toStrictEqual(recipient);
expect(receipt.sender).toStrictEqual(sender);
expect(receipt.len).toStrictEqual(len);
expect(receipt.data).toStrictEqual(data);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/account/src/providers/utils/receipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) {
len: bn(receipt.len),
digest: hexOrZero(receipt.digest),
pc: bn(receipt.pc),
data: hexOrZero(receipt.data),
is: bn(receipt.is),
};

Expand Down Expand Up @@ -157,6 +158,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) {
len: bn(receipt.len),
digest: hexOrZero(receipt.digest),
pc: bn(receipt.pc),
data: hexOrZero(receipt.data),
is: bn(receipt.is),
};
return logDataReceipt;
Expand Down Expand Up @@ -206,6 +208,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) {
const amount = bn(receipt.amount);
const data = receipt.data ? arrayify(receipt.data) : Uint8Array.from([]);
const digest = hexOrZero(receipt.digest);
const len = bn(receipt.len).toNumber();

const messageId = InputMessageCoder.getMessageId({
sender,
Expand All @@ -221,6 +224,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) {
recipient,
amount,
nonce,
len,
data,
digest,
messageId,
Expand Down
1 change: 1 addition & 0 deletions packages/account/test/fixtures/transaction-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const MOCK_RECEIPT_MESSAGE_OUT: TransactionResultMessageOutReceipt = {
amount: bn.parseUnits('0.001'),
nonce: '0x66c4d70c08ff30cd2d9dae0b6fd05972997579328529bb0605dd604afedfdf93',
digest: '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
len: 0,
data: new Uint8Array(),
};

Expand Down
3 changes: 3 additions & 0 deletions packages/transactions/src/coders/receipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('ReceiptCoder', () => {
digest: B256,
pc: bn(0),
is: bn(0),
data: '0x',
};

const encoded = hexlify(new ReceiptCoder().encode(receipt));
Expand Down Expand Up @@ -164,6 +165,7 @@ describe('ReceiptCoder', () => {
digest: B256,
pc: bn(0),
is: bn(0),
data: '0x',
};

const encoded = hexlify(new ReceiptCoder().encode(receipt));
Expand Down Expand Up @@ -232,6 +234,7 @@ describe('ReceiptCoder', () => {
recipient: B256_ALT2,
amount: bn(4000),
nonce: B256_ALT3,
len: 12,
digest: B256_ALT4,
data: Uint8Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
};
Expand Down
15 changes: 15 additions & 0 deletions packages/transactions/src/coders/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ export type ReceiptReturnData = {
digest: string;
/** Value of register $pc (u64) */
pc: BN;
/** Value of the memory range MEM[$rA, $rB]. */
data: string;
/** Value of register $is (u64) */
is: BN;
};
Expand All @@ -207,6 +209,7 @@ export class ReceiptReturnDataCoder extends Coder<ReceiptReturnData, ReceiptRetu
parts.push(new B256Coder().encode(value.digest));
parts.push(new BigNumberCoder('u64').encode(value.pc));
parts.push(new BigNumberCoder('u64').encode(value.is));
parts.push(new ByteArrayCoder(value.len.toNumber()).encode(value.data));

return concat(parts);
}
Expand All @@ -227,6 +230,8 @@ export class ReceiptReturnDataCoder extends Coder<ReceiptReturnData, ReceiptRetu
const pc = decoded;
[decoded, o] = new BigNumberCoder('u64').decode(data, o);
const is = decoded;
[decoded, o] = new ByteArrayCoder(len.toNumber()).decode(data, o);
const returnData = decoded;

return [
{
Expand All @@ -237,6 +242,7 @@ export class ReceiptReturnDataCoder extends Coder<ReceiptReturnData, ReceiptRetu
digest,
pc,
is,
data: returnData,
},
o,
];
Expand Down Expand Up @@ -458,6 +464,8 @@ export type ReceiptLogData = {
len: BN;
/** Hash of MEM[$rC, $rD] (b256) */
digest: string;
/** Value of the memory range MEM[$rC, $rD]. */
data: string;
/** Value of register $pc (u64) */
pc: BN;
/** Value of register $is (u64) */
Expand Down Expand Up @@ -485,6 +493,7 @@ export class ReceiptLogDataCoder extends Coder<ReceiptLogData, ReceiptLogData> {
parts.push(new B256Coder().encode(value.digest));
parts.push(new BigNumberCoder('u64').encode(value.pc));
parts.push(new BigNumberCoder('u64').encode(value.is));
parts.push(new ByteArrayCoder(value.len.toNumber()).encode(value.data));

return concat(parts);
}
Expand All @@ -509,6 +518,8 @@ export class ReceiptLogDataCoder extends Coder<ReceiptLogData, ReceiptLogData> {
const pc = decoded;
[decoded, o] = new BigNumberCoder('u64').decode(data, o);
const is = decoded;
[decoded, o] = new ByteArrayCoder(len.toNumber()).decode(data, o);
const logData = decoded;

return [
{
Expand All @@ -521,6 +532,7 @@ export class ReceiptLogDataCoder extends Coder<ReceiptLogData, ReceiptLogData> {
digest,
pc,
is,
data: logData,
},
o,
];
Expand Down Expand Up @@ -728,6 +740,8 @@ export type ReceiptMessageOut = {
amount: BN;
/** Hexadecimal string representation of the 256-bit (32-byte) message nonce */
nonce: string;
/** Decimal string representation of a 16-bit unsigned integer; value of register $rC. */
len: number;
/** Hexadecimal string representation of 256-bit (32-byte), hash of MEM[$rA + 32, $rB] */
digest: string;
/** Hexadecimal string representation of the value of the memory range MEM[$rA + 32, $rB] */
Expand Down Expand Up @@ -802,6 +816,7 @@ export class ReceiptMessageOutCoder extends Coder<ReceiptMessageOut, ReceiptMess
recipient,
amount,
nonce,
len,
digest,
data: messageData,
};
Expand Down

0 comments on commit e6b6af9

Please sign in to comment.