Skip to content

Commit 4358f90

Browse files
authored
Merge pull request #6937 from BitGo/COIN-5586-make-abi-mandatory-customtx
feat(sdk-coin-apt): making abi mandatory for custom transactions
2 parents aa22b51 + fc3e879 commit 4358f90

File tree

3 files changed

+425
-30
lines changed

3 files changed

+425
-30
lines changed

modules/sdk-coin-apt/src/lib/iface.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ export interface RecipientsValidationResult {
6363
* ```
6464
*
6565
* @remarks
66-
* - The `abi` field is optional but provides type validation when present
66+
* - The `abi` field is required to ensure type safety
6767
* - Invalid ABI will cause transaction building to fail
68-
* - Without ABI, the Aptos SDK performs basic validation
69-
* - All Aptos transactions use the same payload structure regardless of complexity
68+
* - ABI must match the exact function signature of the target entry function
7069
*/
7170
export interface CustomTransactionParams {
7271
/**
@@ -106,18 +105,16 @@ export interface CustomTransactionParams {
106105
functionArguments?: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>;
107106

108107
/**
109-
* Entry function ABI for type validation and safety (optional)
108+
* Entry function ABI for type validation and safety (required)
110109
*
111-
* When provided:
110+
* Provides:
112111
* - Validates argument count matches expected parameters
113112
* - Performs type checking during transaction building
114113
* - Improves error messages for invalid calls
115114
*
116-
* When omitted:
117-
* - Transaction building relies on Aptos SDK basic validation
118-
* - Function signature errors detected at build/simulation time
119-
*
120-
* @remarks Providing incorrect ABI will cause transaction building to fail
115+
* @remarks
116+
* - Providing incorrect ABI will cause transaction building to fail
117+
* - Must match the exact function signature of the target entry function
121118
*/
122-
abi?: EntryFunctionABI;
119+
abi: EntryFunctionABI;
123120
}

modules/sdk-coin-apt/src/lib/transaction/customTransaction.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class CustomTransaction extends Transaction {
1919
private _functionName: string;
2020
private _typeArguments: string[] = [];
2121
private _functionArguments: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes> = [];
22-
private _entryFunctionAbi?: EntryFunctionABI;
22+
private _entryFunctionAbi: EntryFunctionABI;
2323

2424
constructor(coinConfig: Readonly<CoinConfig>) {
2525
super(coinConfig);
@@ -34,11 +34,13 @@ export class CustomTransaction extends Transaction {
3434
setCustomTransactionParams(params: CustomTransactionParams): void {
3535
this.validateModuleName(params.moduleName);
3636
this.validateFunctionName(params.functionName);
37+
this.validateAbi(params.abi);
3738

3839
this._moduleName = params.moduleName;
3940
this._functionName = params.functionName;
4041
this._typeArguments = params.typeArguments || [];
4142
this._functionArguments = params.functionArguments || [];
43+
this._entryFunctionAbi = params.abi;
4244
}
4345

4446
/**
@@ -122,6 +124,7 @@ export class CustomTransaction extends Transaction {
122124
functionName: this._functionName || '',
123125
typeArguments: this._typeArguments,
124126
functionArguments: this._functionArguments,
127+
abi: this._entryFunctionAbi,
125128
};
126129
}
127130

@@ -207,4 +210,24 @@ export class CustomTransaction extends Transaction {
207210

208211
return fullName as `${string}::${string}::${string}`;
209212
}
213+
214+
/**
215+
* Validate ABI structure and provide helpful error messages
216+
*
217+
* @param {EntryFunctionABI} abi - The ABI to validate
218+
* @throws {Error} If ABI format is invalid
219+
*/
220+
private validateAbi(abi: EntryFunctionABI): void {
221+
if (!abi || typeof abi !== 'object') {
222+
throw new Error('ABI must be a valid EntryFunctionABI object');
223+
}
224+
225+
if (!Array.isArray(abi.typeParameters)) {
226+
throw new Error('ABI must have a typeParameters array. Use [] if the function has no type parameters');
227+
}
228+
229+
if (!Array.isArray(abi.parameters)) {
230+
throw new Error('ABI must have a parameters array containing TypeTag objects for each function parameter');
231+
}
232+
}
210233
}

0 commit comments

Comments
 (0)