Skip to content

Commit

Permalink
feat: fix signers during resource population (#284)
Browse files Browse the repository at this point in the history
* feat: fix signers during resource population

* chore: doc regen

* remove extra line of code

Co-authored-by: Neil Campbell <[email protected]>

---------

Co-authored-by: Neil Campbell <[email protected]>
  • Loading branch information
joe-p and neilcampbell authored May 29, 2024
1 parent 794c04a commit 6083190
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
18 changes: 9 additions & 9 deletions docs/code/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ the estimated rate.

#### Defined in

[src/transaction/transaction.ts:796](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L796)
[src/transaction/transaction.ts:816](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L816)

___

Expand Down Expand Up @@ -426,7 +426,7 @@ Allows for control of fees on a `Transaction` or `SuggestedParams` object

#### Defined in

[src/transaction/transaction.ts:819](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L819)
[src/transaction/transaction.ts:839](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L839)

___

Expand Down Expand Up @@ -1605,7 +1605,7 @@ The array of transactions with signers

#### Defined in

[src/transaction/transaction.ts:851](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L851)
[src/transaction/transaction.ts:871](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L871)

___

Expand Down Expand Up @@ -1938,7 +1938,7 @@ The suggested transaction parameters

#### Defined in

[src/transaction/transaction.ts:842](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L842)
[src/transaction/transaction.ts:862](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L862)

___

Expand Down Expand Up @@ -2300,7 +2300,7 @@ The dryrun result

#### Defined in

[src/transaction/transaction.ts:676](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L676)
[src/transaction/transaction.ts:696](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L696)

___

Expand Down Expand Up @@ -2431,7 +2431,7 @@ A new ATC with the resources packed into the transactions

#### Defined in

[src/transaction/transaction.ts:288](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L288)
[src/transaction/transaction.ts:308](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L308)

___

Expand Down Expand Up @@ -2591,7 +2591,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa

#### Defined in

[src/transaction/transaction.ts:541](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L541)
[src/transaction/transaction.ts:561](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L561)

___

Expand All @@ -2616,7 +2616,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa

#### Defined in

[src/transaction/transaction.ts:694](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L694)
[src/transaction/transaction.ts:714](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L714)

___

Expand Down Expand Up @@ -2895,4 +2895,4 @@ Throws an error if the transaction is not confirmed or rejected in the next `tim

#### Defined in

[src/transaction/transaction.ts:739](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L739)
[src/transaction/transaction.ts:759](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L759)
31 changes: 31 additions & 0 deletions src/transaction/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,4 +783,35 @@ describe('Resource Packer: meta', () => {

expect(res.transaction.appAccounts?.length || 0).toBe(0)
})

test('rekeyed account', async () => {
const { testAccount } = fixture.context
const { algorand } = fixture

const authAddr = algorand.account.random().account


Check warning on line 793 in src/transaction/transaction.spec.ts

View workflow job for this annotation

GitHub Actions / Continuous Integration / node-ci

Delete `⏎`
await algorand.send.payment({
sender: testAccount.addr,
receiver: testAccount.addr,
rekeyTo: authAddr.addr,
amount: algokit.microAlgos(0),
})

await externalClient.fundAppAccount(algokit.microAlgos(200_000))

await externalClient.call({
method: 'createAsset',
methodArgs: [],
sendParams: { fee: algokit.microAlgos(2_000) },
sender: { addr: testAccount.addr, signer: algosdk.makeBasicAccountTransactionSigner(authAddr) },
})
const res = await externalClient.call({
method: 'senderAssetBalance',
methodArgs: [],
sender: { addr: testAccount.addr, signer: algosdk.makeBasicAccountTransactionSigner(authAddr) },
})

expect(res.transaction.appAccounts?.length || 0).toBe(0)
})
})
22 changes: 21 additions & 1 deletion src/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,29 @@ async function getUnnamedAppCallResourcesAccessed(atc: algosdk.AtomicTransaction
allowEmptySignatures: true,
})

const signerWithFixedSgnr: algosdk.TransactionSigner = async (txns: algosdk.Transaction[], indexes: number[]) => {
const stxns = await algosdk.makeEmptyTransactionSigner()(txns, indexes)
return Promise.all(
stxns.map(async (stxn) => {
const decodedStxn = algosdk.decodeSignedTransaction(stxn)
const sender = algosdk.encodeAddress(decodedStxn.txn.from.publicKey)

const authAddr = (await algod.accountInformation(sender).do())['auth-addr']

const stxnObj: { txn: algosdk.EncodedTransaction; sgnr?: Buffer } = { txn: decodedStxn.txn.get_obj_for_encoding() }

if (authAddr !== undefined) {
stxnObj.sgnr = Buffer.from(algosdk.decodeAddress(authAddr).publicKey)
}

return algosdk.encodeObj(stxnObj)
}),
)
}

const emptySignerAtc = atc.clone()
emptySignerAtc['transactions'].forEach((t: algosdk.TransactionWithSigner) => {
t.signer = algosdk.makeEmptyTransactionSigner()
t.signer = signerWithFixedSgnr
})

const result = await emptySignerAtc.simulate(algod, simReq)
Expand Down

0 comments on commit 6083190

Please sign in to comment.