Skip to content

Commit

Permalink
feat: support fixSigners in simulate
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell committed Nov 6, 2024
1 parent 4edb822 commit 8d7e4d0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/code/classes/types_composer.default.md
Original file line number Diff line number Diff line change
Expand Up @@ -1209,4 +1209,4 @@ The binary encoded transaction note

#### Defined in

[src/types/composer.ts:1365](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L1365)
[src/types/composer.ts:1367](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L1367)
20 changes: 10 additions & 10 deletions docs/code/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ the estimated rate.

#### Defined in

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

___

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

#### Defined in

[src/transaction/transaction.ts:904](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L904)
[src/transaction/transaction.ts:887](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L887)

___

Expand Down Expand Up @@ -948,7 +948,7 @@ Converts `bigint`'s for Uint's < 64 to `number` for easier use.

#### Defined in

[src/transaction/transaction.ts:729](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L729)
[src/transaction/transaction.ts:712](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L712)

___

Expand Down Expand Up @@ -1931,7 +1931,7 @@ Returns the array of transactions currently present in the given `AtomicTransact

#### Defined in

[src/transaction/transaction.ts:940](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L940)
[src/transaction/transaction.ts:923](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L923)

___

Expand Down Expand Up @@ -2318,7 +2318,7 @@ Returns suggested transaction parameters from algod unless some are already prov

#### Defined in

[src/transaction/transaction.ts:929](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L929)
[src/transaction/transaction.ts:912](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L912)

___

Expand Down Expand Up @@ -2635,7 +2635,7 @@ Performs a dry run of the transactions loaded into the given AtomicTransactionCo

#### Defined in

[src/transaction/transaction.ts:755](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L755)
[src/transaction/transaction.ts:738](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L738)

___

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

#### Defined in

[src/transaction/transaction.ts:329](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L329)
[src/transaction/transaction.ts:312](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L312)

___

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

#### Defined in

[src/transaction/transaction.ts:580](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L580)
[src/transaction/transaction.ts:563](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L563)

___

Expand Down Expand Up @@ -2957,7 +2957,7 @@ Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-de

#### Defined in

[src/transaction/transaction.ts:775](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L775)
[src/transaction/transaction.ts:758](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L758)

___

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

#### Defined in

[src/transaction/transaction.ts:820](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L820)
[src/transaction/transaction.ts:803](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L803)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function performAtomicTransactionComposerSimulate(atc: AtomicTransa

const simulateRequest = new modelsv2.SimulateRequest({
allowEmptySignatures: true,
fixSigners: true,
allowMoreLogging: true,
execTraceConfig: new modelsv2.SimulateTraceConfig({
enable: true,
Expand Down
27 changes: 5 additions & 22 deletions src/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,38 +261,21 @@ export const sendTransaction = async function (
* @returns The unnamed resources accessed by the group and by each transaction in the group
*/
async function getUnnamedAppCallResourcesAccessed(atc: algosdk.AtomicTransactionComposer, algod: algosdk.Algodv2) {
const simReq = new algosdk.modelsv2.SimulateRequest({
const simulateRequest = new algosdk.modelsv2.SimulateRequest({
txnGroups: [],
allowUnnamedResources: true,
allowEmptySignatures: true,
fixSigners: 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 nullSigner = algosdk.makeEmptyTransactionSigner()

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

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

const groupResponse = result.simulateResponse.txnGroups[0]

Expand Down
2 changes: 2 additions & 0 deletions src/types/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ export default class TransactionComposer {
// Build the transactions
if (options?.skipSignatures) {
options.allowEmptySignatures = true
options.fixSigners = true
// Build transactions uses empty signers
const transactions = await this.buildTransactions()
for (const txn of transactions.transactions) {
Expand All @@ -1314,6 +1315,7 @@ export default class TransactionComposer {
...(Config.debug
? {
allowEmptySignatures: true,
fixSigners: true,
allowMoreLogging: true,
execTraceConfig: new modelsv2.SimulateTraceConfig({
enable: true,
Expand Down

0 comments on commit 8d7e4d0

Please sign in to comment.