Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Oct 9, 2024
1 parent 23a1a79 commit 5fc34d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
3 changes: 1 addition & 2 deletions examples/typescript-esm/multisig_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ const createMultiSigTransferTransaction = async () => {
aptosConfig: config,
});

// The simulation enhancement feature is not enabled on the devnet yet.
const isSimulationEnhancementFeatureEnabled = false;
const isSimulationEnhancementFeatureEnabled = true;
if (!isSimulationEnhancementFeatureEnabled) {
// Simulate the transfer transaction to make sure it passes
const transactionToSimulate = await generateRawTransaction({
Expand Down
44 changes: 19 additions & 25 deletions src/transactions/transactionBuilder/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,11 @@ export function generateSignedTransactionForSimulation(args: InputSimulateTransa
transaction.secondarySignerAddresses ?? [],
transaction.feePayerAddress,
);
let secondaryAccountAuthenticators: Array<AccountAuthenticator> = [];
if (transaction.secondarySignerAddresses) {
if (secondarySignersPublicKeys) {
secondaryAccountAuthenticators = secondarySignersPublicKeys.map((publicKey) =>
getAuthenticatorForSimulation(publicKey),
);
} else {
secondaryAccountAuthenticators = new Array(transaction.secondarySignerAddresses.length)
.fill(undefined)
.map((publicKey) => getAuthenticatorForSimulation(publicKey));
}
}

const feePayerAuthenticator = getAuthenticatorForSimulation(feePayerPublicKey);
const secondaryAccountAuthenticators: Array<AccountAuthenticator> = secondaryAccountAuthenticatorsForSimulation(
secondarySignersPublicKeys,
transaction.secondarySignerAddresses?.length ?? 0,
);
const feePayerAuthenticator = getAuthenticatorForSimulation(feePayerPublicKey!);

const transactionAuthenticator = new TransactionAuthenticatorFeePayer(
accountAuthenticator,
Expand All @@ -429,17 +420,10 @@ export function generateSignedTransactionForSimulation(args: InputSimulateTransa
transaction.secondarySignerAddresses,
);

let secondaryAccountAuthenticators: Array<AccountAuthenticator> = [];

if (secondarySignersPublicKeys) {
secondaryAccountAuthenticators = secondarySignersPublicKeys.map((publicKey) =>
getAuthenticatorForSimulation(publicKey),
);
} else {
secondaryAccountAuthenticators = new Array(transaction.secondarySignerAddresses.length)
.fill(undefined)
.map((publicKey) => getAuthenticatorForSimulation(publicKey));
}
const secondaryAccountAuthenticators: Array<AccountAuthenticator> = secondaryAccountAuthenticatorsForSimulation(
secondarySignersPublicKeys,
transaction.secondarySignerAddresses.length,
);

const transactionAuthenticator = new TransactionAuthenticatorMultiAgent(
accountAuthenticator,
Expand Down Expand Up @@ -467,6 +451,16 @@ export function generateSignedTransactionForSimulation(args: InputSimulateTransa
return new SignedTransaction(transaction.rawTransaction, transactionAuthenticator).bcsToBytes();
}

function secondaryAccountAuthenticatorsForSimulation(
secondarySignersPublicKeys: Array<PublicKey | undefined> | undefined,
numSecondarySigners: number,
): Array<AccountAuthenticatorNoAccountAuthenticator | AccountAuthenticatorEd25519 | AccountAuthenticatorSingleKey> {
if (secondarySignersPublicKeys) {
return secondarySignersPublicKeys.map((publicKey) => getAuthenticatorForSimulation(publicKey));
}
return new Array(numSecondarySigners).fill(undefined).map((publicKey) => getAuthenticatorForSimulation(publicKey));
}

export function getAuthenticatorForSimulation(publicKey?: PublicKey) {
if (!publicKey) {
return new AccountAuthenticatorNoAccountAuthenticator();
Expand Down

0 comments on commit 5fc34d5

Please sign in to comment.