Skip to content

Commit

Permalink
chore: fix receipts properties and deprecate incorrect ones (#3385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Nov 13, 2024
1 parent 2b624a1 commit 1226ac3
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/yellow-trees-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/transactions": patch
"@fuel-ts/account": patch
---

chore: fix receipts properties and deprecate incorrect ones
4 changes: 4 additions & 0 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ describe('operations', () => {
amount: bn('0x5f5e100'),
assetId: '0x0000000000000000000000000000000000000000000000000000000000000000',
from: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1',
id: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1',
is: bn('0x4370'),
pc: bn('0x57dc'),
to: '0x3e7ddda4d0d3f8307ae5f1aed87623992c1c4decefec684936960775181b2302',
Expand Down
37 changes: 28 additions & 9 deletions packages/account/src/providers/utils/receipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
};
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions packages/account/test/fixtures/transaction-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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),
Expand All @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions packages/transactions/src/coders/receipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
95 changes: 70 additions & 25 deletions packages/transactions/src/coders/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -77,7 +81,7 @@ export class ReceiptCallCoder extends Coder<ReceiptCall, ReceiptCall> {
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);
Expand All @@ -98,7 +102,8 @@ export class ReceiptCallCoder extends Coder<ReceiptCall, ReceiptCall> {
return [
{
type: ReceiptType.Call,
from,
id,
from: id,
to,
amount,
assetId,
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -422,13 +443,13 @@ export class ReceiptLogCoder extends Coder<ReceiptLog, ReceiptLog> {
[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);
Expand All @@ -438,10 +459,14 @@ export class ReceiptLogCoder extends Coder<ReceiptLog, ReceiptLog> {
{
type: ReceiptType.Log,
id,
val0,
val1,
val2,
val3,
ra,
rb,
rc,
rd,
val0: ra,
val1: rb,
val2: rc,
val3: rd,
pc,
is,
},
Expand All @@ -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;
Expand Down Expand Up @@ -505,9 +538,9 @@ export class ReceiptLogDataCoder extends Coder<ReceiptLogData, ReceiptLogData> {
[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);
Expand All @@ -525,8 +558,10 @@ export class ReceiptLogDataCoder extends Coder<ReceiptLogData, ReceiptLogData> {
{
type: ReceiptType.LogData,
id,
val0,
val1,
ra,
rb,
val0: ra,
val1: rb,
ptr,
len,
digest,
Expand All @@ -541,8 +576,12 @@ export class ReceiptLogDataCoder extends Coder<ReceiptLogData, ReceiptLogData> {

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) */
Expand Down Expand Up @@ -583,7 +622,7 @@ export class ReceiptTransferCoder extends Coder<ReceiptTransfer, ReceiptTransfer
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);
Expand All @@ -598,7 +637,8 @@ export class ReceiptTransferCoder extends Coder<ReceiptTransfer, ReceiptTransfer
return [
{
type: ReceiptType.Transfer,
from,
id,
from: id,
to,
amount,
assetId,
Expand All @@ -612,8 +652,12 @@ export class ReceiptTransferCoder extends Coder<ReceiptTransfer, ReceiptTransfer

export type ReceiptTransferOut = {
type: ReceiptType.TransferOut;
/** 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;
/** Address to transfer coins to (b256) */
to: string;
/** Amount of coins transferred (u64) */
Expand Down Expand Up @@ -654,7 +698,7 @@ export class ReceiptTransferOutCoder extends Coder<ReceiptTransferOut, ReceiptTr
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);
Expand All @@ -669,7 +713,8 @@ export class ReceiptTransferOutCoder extends Coder<ReceiptTransferOut, ReceiptTr
return [
{
type: ReceiptType.TransferOut,
from,
id,
from: id,
to,
amount,
assetId,
Expand Down

0 comments on commit 1226ac3

Please sign in to comment.