From c95775f6f5c15e06c5e382b38db7b69d2cedc577 Mon Sep 17 00:00:00 2001 From: MetaB0y Date: Tue, 16 Aug 2022 15:02:05 +0800 Subject: [PATCH 1/2] fix: add 'Assets' and 'Applications' to InnerTx --- packages/runtime/src/lib/itxn.ts | 13 +++++++++++-- .../inner-transaction/assets/approval-payment.py | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/lib/itxn.ts b/packages/runtime/src/lib/itxn.ts index e588d5ccf..82fb142dc 100644 --- a/packages/runtime/src/lib/itxn.ts +++ b/packages/runtime/src/lib/itxn.ts @@ -27,13 +27,21 @@ const TxnTypeMap: { [key: string]: { version: number; field: string | number } } 6: { version: 6, field: "appl" }, }; +// each value here is number but they come in array +const arrayNumberFields = new Set(["Assets", "Applications"]); // requires their type as number const numberTxnFields: { [key: number]: Set } = { 1: new Set(), 2: new Set(), 3: new Set(), 4: new Set(), - 5: new Set(["Fee", "FreezeAssetFrozen", "ConfigAssetDecimals", "ConfigAssetDefaultFrozen"]), + 5: new Set([ + "Fee", + "FreezeAssetFrozen", + "ConfigAssetDecimals", + "ConfigAssetDefaultFrozen", + ...arrayNumberFields, + ]), }; numberTxnFields[6] = cloneDeep(numberTxnFields[5]); ["VoteFirst", "VoteLast", "VoteKeyDilution", "Nonparticipation", "ApplicationID"].forEach( @@ -217,6 +225,7 @@ export function setInnerTxField( } break; } + case "ConfigAssetDecimals": { const assetDecimals = txValue as bigint; if (assetDecimals > 19n || assetDecimals < 0n) { @@ -297,7 +306,7 @@ export function setInnerTxField( (subTxn as any).apar = (subTxn as any).apar ?? {}; (subTxn as any).apar[encodedField] = txValue; } else { - if (field === "ApplicationArgs") { + if (field === "ApplicationArgs" || arrayNumberFields.has(field)) { if ((subTxn as any)[encodedField] === undefined) { (subTxn as any)[encodedField] = []; } diff --git a/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py b/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py index 89c82b608..ac5dc3f21 100644 --- a/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py +++ b/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py @@ -15,7 +15,10 @@ def approval_program(): TxnField.type_enum: TxnType.Payment, TxnField.receiver: Txn.sender(), TxnField.amount: Int(1000000), - } + TxnField.assets: [ + Int(1) + ], + }, ), InnerTxnBuilder.Submit(), @@ -26,6 +29,9 @@ def approval_program(): TxnField.type_enum: TxnType.Payment, TxnField.receiver: Txn.accounts[1], TxnField.amount: Int(2000000), + TxnField.applications: [ + Int(1) + ], } ), InnerTxnBuilder.Submit(), From 0c930835d902be00c33d44c1ff639720b4ae5d8f Mon Sep 17 00:00:00 2001 From: MetaB0y Date: Tue, 16 Aug 2022 15:19:25 +0800 Subject: [PATCH 2/2] fix: add 'Accounts' to InnerTx --- packages/runtime/src/lib/itxn.ts | 9 ++++++++- .../inner-transaction/assets/approval-payment.py | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/lib/itxn.ts b/packages/runtime/src/lib/itxn.ts index 82fb142dc..e81aacb84 100644 --- a/packages/runtime/src/lib/itxn.ts +++ b/packages/runtime/src/lib/itxn.ts @@ -112,6 +112,8 @@ const acfgAddrTxnFields: { [key: number]: Set } = { acfgAddrTxnFields[6] = cloneDeep(acfgAddrTxnFields[5]); +// each value here is Addr but they come in array +const arrayAddrFields = new Set(["Accounts"]); const otherAddrTxnFields: { [key: number]: Set } = { 5: new Set([ "Sender", @@ -121,6 +123,7 @@ const otherAddrTxnFields: { [key: number]: Set } = { "AssetCloseTo", "AssetReceiver", "FreezeAssetAccount", + ...arrayAddrFields, ]), }; @@ -306,7 +309,11 @@ export function setInnerTxField( (subTxn as any).apar = (subTxn as any).apar ?? {}; (subTxn as any).apar[encodedField] = txValue; } else { - if (field === "ApplicationArgs" || arrayNumberFields.has(field)) { + if ( + field === "ApplicationArgs" || + arrayNumberFields.has(field) || + arrayAddrFields.has(field) + ) { if ((subTxn as any)[encodedField] === undefined) { (subTxn as any)[encodedField] = []; } diff --git a/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py b/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py index ac5dc3f21..df5fba307 100644 --- a/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py +++ b/packages/runtime/test/fixtures/inner-transaction/assets/approval-payment.py @@ -32,6 +32,9 @@ def approval_program(): TxnField.applications: [ Int(1) ], + TxnField.accounts: [ + Global.current_application_address() + ], } ), InnerTxnBuilder.Submit(),