From e323559660071eb96125c340a5e9fa064a1a336a Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 13 Mar 2024 19:24:25 +0800 Subject: [PATCH] fix: remove all duplicate resources in resource population (#243) * fix: double addr in resource population * fix: remove all duplicate resources * docs --------- Co-authored-by: Joe Polny --- docs/code/modules/index.md | 16 ++++++++-------- src/transaction/transaction.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index 1a3a06b3..1fdeb2fa 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -349,7 +349,7 @@ the estimated rate. #### Defined in -[src/transaction/transaction.ts:667](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L667) +[src/transaction/transaction.ts:675](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L675) ___ @@ -405,7 +405,7 @@ Allows for control of fees on a `Transaction` or `SuggestedParams` object #### Defined in -[src/transaction/transaction.ts:690](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L690) +[src/transaction/transaction.ts:698](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L698) ___ @@ -1477,7 +1477,7 @@ The array of transactions with signers #### Defined in -[src/transaction/transaction.ts:722](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L722) +[src/transaction/transaction.ts:730](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L730) ___ @@ -1810,7 +1810,7 @@ The suggested transaction parameters #### Defined in -[src/transaction/transaction.ts:713](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L713) +[src/transaction/transaction.ts:721](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L721) ___ @@ -2145,7 +2145,7 @@ The dryrun result #### Defined in -[src/transaction/transaction.ts:547](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L547) +[src/transaction/transaction.ts:555](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L555) ___ @@ -2436,7 +2436,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa #### Defined in -[src/transaction/transaction.ts:419](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L419) +[src/transaction/transaction.ts:427](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L427) ___ @@ -2461,7 +2461,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa #### Defined in -[src/transaction/transaction.ts:565](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L565) +[src/transaction/transaction.ts:573](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L573) ___ @@ -2740,4 +2740,4 @@ Throws an error if the transaction is not confirmed or rejected in the next `tim #### Defined in -[src/transaction/transaction.ts:610](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L610) +[src/transaction/transaction.ts:618](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L618) diff --git a/src/transaction/transaction.ts b/src/transaction/transaction.ts index 2728b226..12887789 100644 --- a/src/transaction/transaction.ts +++ b/src/transaction/transaction.ts @@ -359,12 +359,20 @@ export async function populateAppCallResources(atc: algosdk.AtomicTransactionCom const txnIndex = findTxnBelowRefLimit(group, 'appLocal') group[txnIndex].txn.appForeignApps?.push(Number(a.app)) group[txnIndex].txn.appAccounts?.push(algosdk.decodeAddress(a.account)) + + // Remove resources from the group if we're adding them here + g.accounts = g.accounts?.filter((acc) => acc !== a.account) + g.apps = g.apps?.filter((app) => BigInt(app) !== BigInt(a.app)) }) g.assetHoldings?.forEach((a) => { const txnIndex = findTxnBelowRefLimit(group, 'assetHolding') group[txnIndex].txn.appForeignAssets?.push(Number(a.asset)) group[txnIndex].txn.appAccounts?.push(algosdk.decodeAddress(a.account)) + + // Remove resources from the group if we're adding them here + g.accounts = g.accounts?.filter((acc) => acc !== a.account) + g.assets = g.assets?.filter((asset) => BigInt(asset) !== BigInt(a.asset)) }) // Do accounts next because the account limit is 4