Skip to content

Commit

Permalink
[refactor] Merge OptionalABI with existing types
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Feb 12, 2024
1 parent caef3e3 commit 9ff4837
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
15 changes: 6 additions & 9 deletions src/api/transactionSubmission/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
InputGenerateTransactionOptions,
SimpleTransaction,
MultiAgentTransaction,
OptionalAbi,
} from "../../transactions";
import { AptosConfig } from "../aptosConfig";

Expand All @@ -32,14 +31,12 @@ export class Build {
*
* @returns SimpleTransaction
*/
async simple(
args: {
sender: AccountAddressInput;
data: InputGenerateTransactionPayloadData;
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
} & OptionalAbi,
): Promise<SimpleTransaction> {
async simple(args: {
sender: AccountAddressInput;
data: InputGenerateTransactionPayloadData;
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
}): Promise<SimpleTransaction> {
return generateTransaction({ aptosConfig: this.config, ...args });
}

Expand Down
13 changes: 6 additions & 7 deletions src/internal/transactionSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
InputGenerateSingleSignerRawTransactionData,
MultiAgentTransaction,
AnyTransactionPayloadInstance,
OptionalAbi,
EntryFunctionABI,
} from "../transactions/types";
import { getInfo } from "./account";
Expand All @@ -48,10 +47,10 @@ import { TypeTagU8, TypeTagVector } from "../transactions";
* Typescript can infer the return type based on the appropriate function overload.
*/
export async function generateTransaction(
args: { aptosConfig: AptosConfig } & InputGenerateSingleSignerRawTransactionData & OptionalAbi,
args: { aptosConfig: AptosConfig } & InputGenerateSingleSignerRawTransactionData,
): Promise<SimpleTransaction>;
export async function generateTransaction(
args: { aptosConfig: AptosConfig } & InputGenerateMultiAgentRawTransactionData & OptionalAbi,
args: { aptosConfig: AptosConfig } & InputGenerateMultiAgentRawTransactionData,
): Promise<MultiAgentTransaction>;
/**
* Generates any transaction by passing in the required arguments
Expand Down Expand Up @@ -94,14 +93,14 @@ export async function generateTransaction(
* ```
*/
export async function generateTransaction(
args: { aptosConfig: AptosConfig } & InputGenerateTransactionData & OptionalAbi,
args: { aptosConfig: AptosConfig } & InputGenerateTransactionData,
): Promise<AnyRawTransaction> {
const payload = await buildTransactionPayload(args);
return buildRawTransaction(args, payload);
}

export async function buildTransactionPayload(
args: { aptosConfig: AptosConfig } & InputGenerateTransactionData & OptionalAbi,
args: { aptosConfig: AptosConfig } & InputGenerateTransactionData,
): Promise<AnyTransactionPayloadInstance> {
const { aptosConfig, data, abi } = args;

Expand All @@ -112,7 +111,7 @@ export async function buildTransactionPayload(
// TODO: Add ABI checking later
payload = await generateTransactionPayload(data);
} else if ("multisigAddress" in data) {
if (abi !== undefined) {
if (abi) {
payload = generateTransactionPayloadWithABI(data, abi);
} else {
generateTransactionPayloadData = {
Expand All @@ -124,7 +123,7 @@ export async function buildTransactionPayload(
};
payload = await generateTransactionPayload(generateTransactionPayloadData);
}
} else if (abi !== undefined) {
} else if (abi) {
payload = generateTransactionPayloadWithABI(data, abi);
} else {
generateTransactionPayloadData = {
Expand Down
4 changes: 1 addition & 3 deletions src/transactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export interface InputGenerateSingleSignerRawTransactionData {
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
secondarySignerAddresses?: undefined;
abi?: EntryFunctionABI;
}

/**
Expand All @@ -255,9 +256,6 @@ export interface InputGenerateMultiAgentRawTransactionData {
secondarySignerAddresses: AccountAddressInput[];
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
}

export interface OptionalAbi {
abi?: EntryFunctionABI;
}

Expand Down

0 comments on commit 9ff4837

Please sign in to comment.