Skip to content

Commit

Permalink
[refactor] Merge ABI into transaction data
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Feb 12, 2024
1 parent 9ff4837 commit c8f9842
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 54 deletions.
8 changes: 4 additions & 4 deletions examples/typescript-esm/performance_optimization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ const example = async () => {
function: "0x1::coin::transfer",
typeArguments: [APTOS_COIN_TYPE],
functionArguments: [bobAddressString, TRANSFER_AMOUNT],
abi: transferAbi,
},
abi: transferAbi,
});

const committedTxn = await aptos.signAndSubmitTransaction({ signer: alice, transaction: txn });
Expand All @@ -159,8 +159,8 @@ const example = async () => {
function: "0x1::coin::transfer",
typeArguments: [APTOS_COIN_TYPE],
functionArguments: [bob.accountAddress, new U64(TRANSFER_AMOUNT)],
abi: transferAbi,
},
abi: transferAbi,
});

const committedTxn = await aptos.signAndSubmitTransaction({ signer: alice, transaction: txn });
Expand All @@ -178,11 +178,11 @@ const example = async () => {
function: "0x1::coin::transfer",
typeArguments: [APTOS_COIN_TYPE],
functionArguments: [bob.accountAddress, new U64(TRANSFER_AMOUNT)],
abi: transferAbi,
},
options: {
accountSequenceNumber: sequenceNumber,
},
abi: transferAbi,
});

const committedTxn = await aptos.signAndSubmitTransaction({ signer: alice, transaction: txn });
Expand All @@ -198,13 +198,13 @@ const example = async () => {
function: "0x1::coin::transfer",
typeArguments: [APTOS_COIN_TYPE],
functionArguments: [bob.accountAddress, new U64(TRANSFER_AMOUNT)],
abi: transferAbi,
},
options: {
accountSequenceNumber: sequenceNumber + 1n,
gasUnitPrice: 100,
maxGasAmount: 1000,
},
abi: transferAbi,
});

const committedTxn = await aptos.signAndSubmitTransaction({ signer: alice, transaction: txn });
Expand Down
2 changes: 1 addition & 1 deletion src/internal/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export async function transferCoinTransaction(args: {
function: "0x1::aptos_account::transfer_coins",
typeArguments: [coinStructType],
functionArguments: [recipient, amount],
abi: coinTransferAbi,
},
abi: coinTransferAbi,
options,
});
}
30 changes: 15 additions & 15 deletions src/internal/digitalAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ export async function createCollectionTransaction(
new U64(args.royaltyNumerator ?? 0),
new U64(args.royaltyDenominator ?? 1),
],
abi: createCollectionAbi,
},
abi: createCollectionAbi,
options,
});
}
Expand Down Expand Up @@ -365,9 +365,9 @@ export async function mintDigitalAssetTransaction(args: {
MoveVector.MoveString(convertedPropertyType ?? []),
getPropertyValueRaw(propertyValues ?? [], convertedPropertyType ?? []),
],
abi: mintDigitalAssetAbi,
},
options,
abi: mintDigitalAssetAbi,
});
}

Expand All @@ -392,9 +392,9 @@ export async function transferDigitalAssetTransaction(args: {
function: "0x1::object::transfer",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [AccountAddress.from(digitalAssetAddress), AccountAddress.from(recipient)],
abi: transferDigitalAssetAbi,
},
options,
abi: transferDigitalAssetAbi,
});
}

Expand Down Expand Up @@ -460,9 +460,9 @@ export async function mintSoulBoundTransaction(args: {
getPropertyValueRaw(propertyValues ?? [], convertedPropertyType ?? []),
recipient,
],
abi: mintSoulBoundAbi,
},
options,
abi: mintSoulBoundAbi,
});
}

Expand All @@ -486,9 +486,9 @@ export async function burnDigitalAssetTransaction(args: {
function: "0x4::aptos_token::burn",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [AccountAddress.from(digitalAssetAddress)],
abi: burnDigitalAssetAbi,
},
options,
abi: burnDigitalAssetAbi,
});
}

Expand All @@ -512,9 +512,9 @@ export async function freezeDigitalAssetTransferTransaction(args: {
function: "0x4::aptos_token::freeze_transfer",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [digitalAssetAddress],
abi: freezeDigitalAssetAbi,
},
options,
abi: freezeDigitalAssetAbi,
});
}

Expand All @@ -538,9 +538,9 @@ export async function unfreezeDigitalAssetTransferTransaction(args: {
function: "0x4::aptos_token::unfreeze_transfer",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [digitalAssetAddress],
abi: unfreezeDigitalAssetAbi,
},
options,
abi: unfreezeDigitalAssetAbi,
});
}

Expand All @@ -565,9 +565,9 @@ export async function setDigitalAssetDescriptionTransaction(args: {
function: "0x4::aptos_token::set_description",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [AccountAddress.from(digitalAssetAddress), new MoveString(description)],
abi: setDigitalAssetDescriptionAbi,
},
options,
abi: setDigitalAssetDescriptionAbi,
});
}

Expand All @@ -592,9 +592,9 @@ export async function setDigitalAssetNameTransaction(args: {
function: "0x4::aptos_token::set_name",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [AccountAddress.from(digitalAssetAddress), new MoveString(name)],
abi: setDigitalAssetNameAbi,
},
options,
abi: setDigitalAssetNameAbi,
});
}

Expand All @@ -619,9 +619,9 @@ export async function setDigitalAssetURITransaction(args: {
function: "0x4::aptos_token::set_uri",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [AccountAddress.from(digitalAssetAddress), new MoveString(uri)],
abi: setDigitalAssetURIAbi,
},
options,
abi: setDigitalAssetURIAbi,
});
}

Expand Down Expand Up @@ -667,9 +667,9 @@ export async function addDigitalAssetPropertyTransaction(args: {
new MoveString(PropertyTypeMap[propertyType]),
MoveVector.U8(getSinglePropertyValueRaw(propertyValue, PropertyTypeMap[propertyType])),
],
abi: addDigitalAssetPropertyAbi,
},
options,
abi: addDigitalAssetPropertyAbi,
});
}

Expand All @@ -694,9 +694,9 @@ export async function removeDigitalAssetPropertyTransaction(args: {
function: "0x4::aptos_token::remove_property",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType],
functionArguments: [AccountAddress.from(digitalAssetAddress), new MoveString(propertyKey)],
abi: removeDigitalAssetPropertyAbi,
},
options,
abi: removeDigitalAssetPropertyAbi,
});
}

Expand Down Expand Up @@ -742,9 +742,9 @@ export async function updateDigitalAssetPropertyTransaction(args: {
new MoveString(PropertyTypeMap[propertyType]),
getSinglePropertyValueRaw(propertyValue, PropertyTypeMap[propertyType]),
],
abi: updateDigitalAssetPropertyAbi,
},
options,
abi: updateDigitalAssetPropertyAbi,
});
}

Expand Down Expand Up @@ -784,9 +784,9 @@ export async function addDigitalAssetTypedPropertyTransaction(args: {
function: "0x4::aptos_token::add_typed_property",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType, PropertyTypeMap[propertyType]],
functionArguments: [AccountAddress.from(digitalAssetAddress), new MoveString(propertyKey), propertyValue],
abi: addDigitalAssetTypedPropertyAbi,
},
options,
abi: addDigitalAssetTypedPropertyAbi,
});
}

Expand Down Expand Up @@ -826,9 +826,9 @@ export async function updateDigitalAssetTypedPropertyTransaction(args: {
function: "0x4::aptos_token::update_typed_property",
typeArguments: [digitalAssetType ?? defaultDigitalAssetType, PropertyTypeMap[propertyType]],
functionArguments: [AccountAddress.from(digitalAssetAddress), new MoveString(propertyKey), propertyValue],
abi: updateDigitalAssetTypedPropertyAbi,
},
options,
abi: updateDigitalAssetTypedPropertyAbi,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/fungibleAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export async function transferFungibleAsset(args: {
function: "0x1::primary_fungible_store::transfer",
typeArguments: ["0x1::fungible_asset::Metadata"],
functionArguments: [fungibleAssetMetadataAddress, recipient, amount],
abi: faTransferAbi,
},
abi: faTransferAbi,
options,
});
}
14 changes: 7 additions & 7 deletions src/internal/transactionSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function generateTransaction(
export async function buildTransactionPayload(
args: { aptosConfig: AptosConfig } & InputGenerateTransactionData,
): Promise<AnyTransactionPayloadInstance> {
const { aptosConfig, data, abi } = args;
const { aptosConfig, data } = args;

// Merge in aptosConfig for remote ABI on non-script payloads
let generateTransactionPayloadData: InputGenerateTransactionPayloadDataWithRemoteABI;
Expand All @@ -111,8 +111,8 @@ export async function buildTransactionPayload(
// TODO: Add ABI checking later
payload = await generateTransactionPayload(data);
} else if ("multisigAddress" in data) {
if (abi) {
payload = generateTransactionPayloadWithABI(data, abi);
if (data.abi) {
payload = generateTransactionPayloadWithABI(data);
} else {
generateTransactionPayloadData = {
aptosConfig,
Expand All @@ -123,8 +123,8 @@ export async function buildTransactionPayload(
};
payload = await generateTransactionPayload(generateTransactionPayloadData);
}
} else if (abi) {
payload = generateTransactionPayloadWithABI(data, abi);
} else if (data.abi) {
payload = generateTransactionPayloadWithABI(data);
} else {
generateTransactionPayloadData = {
aptosConfig,
Expand Down Expand Up @@ -312,9 +312,9 @@ export async function publicPackageTransaction(args: {
data: {
function: "0x1::code::publish_package_txn",
functionArguments: [MoveVector.U8(metadataBytes), new MoveVector(totalByteCode)],
abi: packagePublishAbi,
},
options,
abi: packagePublishAbi,
});
}

Expand Down Expand Up @@ -372,8 +372,8 @@ export async function rotateAuthKey(args: {
MoveVector.U8(proofSignedByCurrentPrivateKey.toUint8Array()),
MoveVector.U8(proofSignedByNewPrivateKey.toUint8Array()),
],
abi: rotateAuthKeyAbi,
},
abi: rotateAuthKeyAbi,
});
return signAndSubmitTransaction({
aptosConfig,
Expand Down
17 changes: 5 additions & 12 deletions src/transactions/management/transactionWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { Account } from "../../core";
import { waitForTransaction } from "../../internal/transaction";
import { generateTransaction, signAndSubmitTransaction } from "../../internal/transactionSubmission";
import { PendingTransactionResponse, TransactionResponse } from "../../types";
import {
EntryFunctionABI,
InputGenerateTransactionOptions,
InputGenerateTransactionPayloadData,
SimpleTransaction,
} from "../types";
import { InputGenerateTransactionOptions, InputGenerateTransactionPayloadData, SimpleTransaction } from "../types";
import { AccountSequenceNumber } from "./accountSequenceNumber";
import { AsyncQueue, AsyncQueueCancelledError } from "./asyncQueue";

Expand Down Expand Up @@ -89,7 +84,7 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
* TODO support entry function payload from ABI builder
*/
transactionsQueue = new AsyncQueue<
[InputGenerateTransactionPayloadData, InputGenerateTransactionOptions | undefined, EntryFunctionABI | undefined]
[InputGenerateTransactionPayloadData, InputGenerateTransactionOptions | undefined]
>();

/**
Expand Down Expand Up @@ -267,18 +262,17 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
* Push transaction to the transactions queue
*
* @param transactionData Transaction payload
* @param transactionData.abi For all entry function payloads, the ABI to skip remote ABI lookups
* @param options.maxGasAmount Maximum gas amount for the transaction
* @param options.gasUnitPrice Gas unit price for the transaction
* @param options.expireTimestamp expiration timestamp on the transaction
* @param options.accountSequenceNumber the sequence number for the transaction
* @param abi Entry function ABI to skip remote ABI lookups
*/
async push(
transactionData: InputGenerateTransactionPayloadData,
options?: InputGenerateTransactionOptions,
abi?: EntryFunctionABI,
): Promise<void> {
this.transactionsQueue.enqueue([transactionData, options, abi]);
this.transactionsQueue.enqueue([transactionData, options]);
}

/**
Expand All @@ -289,13 +283,12 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
*/
async generateNextTransaction(account: Account, sequenceNumber: bigint): Promise<SimpleTransaction | undefined> {
if (this.transactionsQueue.isEmpty()) return undefined;
const [transactionData, options, abi] = await this.transactionsQueue.dequeue();
const [transactionData, options] = await this.transactionsQueue.dequeue();
return generateTransaction({
aptosConfig: this.aptosConfig,
sender: account.accountAddress,
data: transactionData,
options: { ...options, accountSequenceNumber: sequenceNumber },
abi,
});
}

Expand Down
17 changes: 5 additions & 12 deletions src/transactions/transactionBuilder/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import {
AnyTransactionPayloadInstance,
AnyRawTransactionInstance,
EntryFunctionArgumentTypes,
EntryFunctionABI,
InputGenerateMultiAgentRawTransactionArgs,
InputGenerateRawTransactionArgs,
InputGenerateSingleSignerRawTransactionArgs,
Expand Down Expand Up @@ -117,25 +116,19 @@ export async function generateTransactionPayload(
1000 * 60 * 5, // 5 minutes
)();

return generateTransactionPayloadWithABI(args, functionAbi);
// Fill in the ABI
return generateTransactionPayloadWithABI({ abi: functionAbi, ...args });
}

export function generateTransactionPayloadWithABI(
args: InputEntryFunctionData,
functionAbi: EntryFunctionABI,
): TransactionPayloadEntryFunction;
export function generateTransactionPayloadWithABI(
args: InputMultiSigData,
functionAbi: EntryFunctionABI,
): TransactionPayloadMultiSig;
export function generateTransactionPayloadWithABI(args: InputEntryFunctionData): TransactionPayloadEntryFunction;
export function generateTransactionPayloadWithABI(args: InputMultiSigData): TransactionPayloadMultiSig;
export function generateTransactionPayloadWithABI(
args: InputGenerateTransactionPayloadData,
functionAbi: EntryFunctionABI,
): AnyTransactionPayloadInstance {
if (isScriptDataInput(args)) {
return generateTransactionPayloadScript(args);
}

const functionAbi = args.abi!;
const { moduleAddress, moduleName, functionName } = getFunctionParts(args.function);

// Ensure that all type arguments are typed properly
Expand Down
Loading

0 comments on commit c8f9842

Please sign in to comment.