Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove redundant exports from v1 encoding #2485

Merged
merged 8 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/good-lobsters-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/abi-typegen": minor
"@fuel-ts/abi-coder": minor
"@fuel-ts/program": patch
---

feat!: remove redundant exports from `v1` encoding
17 changes: 0 additions & 17 deletions packages/abi-coder/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ export class Interface<TAbi extends JsonAbi = JsonAbi> {
);
}

decodeFunctionData(functionFragment: FunctionFragment | string, data: BytesLike): any {
const fragment =
typeof functionFragment === 'string' ? this.getFunction(functionFragment) : functionFragment;

return fragment.decodeArguments(data);
}

encodeFunctionData(
functionFragment: FunctionFragment | string,
values: Array<InputValue>
): Uint8Array {
const fragment =
typeof functionFragment === 'string' ? this.getFunction(functionFragment) : functionFragment;

return fragment.encodeArguments(values);
}

// Decode the result of a function call
decodeFunctionResult(functionFragment: FunctionFragment | string, data: BytesLike): any {
const fragment =
Expand Down
1 change: 0 additions & 1 deletion packages/abi-coder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export {
UTXO_ID_LEN,
BYTES_32,
calculateVmTxMemory,
type EncodingVersion,
ENCODING_V1,
} from './utils/constants';
export { AbiCoder } from './AbiCoder';
18 changes: 0 additions & 18 deletions packages/abi-coder/test/Interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,6 @@ describe('Abi interface', () => {
it('raises an error when function is not found', () => {
const fnName = 'doesnt_exist';
expect(() => exhaustiveExamplesInterface.getFunction(fnName)).toThrow();

expect(() => exhaustiveExamplesInterface.encodeFunctionData(fnName, [123])).toThrow();

expect(() =>
exhaustiveExamplesInterface.decodeFunctionData(fnName, new Uint8Array())
).toThrow();
});

it('raises an error if the arguments do not match the function input types', () => {
const values = [11, 11];

const errMsg = `Mismatch between provided arguments and expected ABI inputs.`
.concat(` Provided ${values.length} arguments,`)
.concat(` but expected 1 (excluding 0 optional inputs).`);

expect(() => exhaustiveExamplesInterface.encodeFunctionData('entry_one', values)).toThrow(
errMsg
);
});
});

Expand Down
8 changes: 0 additions & 8 deletions packages/abi-typegen/src/templates/contract/dts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ interface {{capitalizedName}}Interface extends Interface {
{{this}}: FunctionFragment;
{{/each}}
};

{{#each encoders}}
encodeFunctionData(functionFragment: '{{functionName}}', values: [{{input}}]): Uint8Array;
{{/each}}

{{#each decoders}}
decodeFunctionData(functionFragment: '{{functionName}}', data: BytesLike): DecodedValue;
{{/each}}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ interface MyContractAbiInterface extends Interface {
functions: {
main: FunctionFragment;
};

encodeFunctionData(functionFragment: 'main', values: [string, string]): Uint8Array;

decodeFunctionData(functionFragment: 'main', data: BytesLike): DecodedValue;
}

export class MyContractAbi extends Contract {
Expand Down
74 changes: 0 additions & 74 deletions packages/abi-typegen/test/fixtures/templates/contract/dts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -91,80 +91,6 @@ interface MyContractAbiInterface extends Interface {
types_vector_option: FunctionFragment;
types_vector_u8: FunctionFragment;
};

encodeFunctionData(functionFragment: 'type_address', values: [AddressInput]): Uint8Array;
encodeFunctionData(functionFragment: 'type_contract_id', values: [ContractIdInput]): Uint8Array;
encodeFunctionData(functionFragment: 'type_external_enum', values: [ExternalEnumInput]): Uint8Array;
encodeFunctionData(functionFragment: 'type_external_struct', values: [ExternalStructInput]): Uint8Array;
encodeFunctionData(functionFragment: 'type_identity', values: [IdentityInput]): Uint8Array;
encodeFunctionData(functionFragment: 'types_array', values: [[BigNumberish, BigNumberish, BigNumberish]]): Uint8Array;
encodeFunctionData(functionFragment: 'types_asset_id', values: [AssetIdInput]): Uint8Array;
encodeFunctionData(functionFragment: 'types_b256', values: [string]): Uint8Array;
encodeFunctionData(functionFragment: 'types_b512', values: [string]): Uint8Array;
encodeFunctionData(functionFragment: 'types_bool', values: [boolean]): Uint8Array;
encodeFunctionData(functionFragment: 'types_bytes', values: [Bytes]): Uint8Array;
encodeFunctionData(functionFragment: 'types_empty', values: []): Uint8Array;
encodeFunctionData(functionFragment: 'types_empty_then_value', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_enum', values: [MyEnumInput]): Uint8Array;
encodeFunctionData(functionFragment: 'types_enum_with_vector', values: [EnumWithVectorInput]): Uint8Array;
encodeFunctionData(functionFragment: 'types_evm_address', values: [EvmAddress]): Uint8Array;
encodeFunctionData(functionFragment: 'types_generic_enum', values: [GenericEnumInput<BigNumberish, BigNumberish>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_generic_struct', values: [GenericStructWithEnumInput<BigNumberish, BigNumberish>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_option', values: [Option<BigNumberish>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_option_geo', values: [Option<MyStructInput>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_raw_slice', values: [RawSlice]): Uint8Array;
encodeFunctionData(functionFragment: 'types_result', values: [Result<BigNumberish, BigNumberish>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_std_string', values: [StdString]): Uint8Array;
encodeFunctionData(functionFragment: 'types_str', values: [string]): Uint8Array;
encodeFunctionData(functionFragment: 'types_struct', values: [MyStructInput]): Uint8Array;
encodeFunctionData(functionFragment: 'types_tuple', values: [[BigNumberish, BigNumberish, BigNumberish]]): Uint8Array;
encodeFunctionData(functionFragment: 'types_u16', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_u256', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_u32', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_u64', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_u8', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_value_then_empty', values: [BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_value_then_empty_then_value', values: [BigNumberish, BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'types_vector_geo', values: [Vec<MyStructInput>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_vector_option', values: [Vec<StructWithMultiOptionInput>]): Uint8Array;
encodeFunctionData(functionFragment: 'types_vector_u8', values: [Vec<BigNumberish>]): Uint8Array;

decodeFunctionData(functionFragment: 'type_address', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'type_contract_id', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'type_external_enum', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'type_external_struct', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'type_identity', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_array', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_asset_id', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_b256', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_b512', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_bool', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_bytes', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_empty', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_empty_then_value', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_enum', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_enum_with_vector', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_evm_address', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_generic_enum', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_generic_struct', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_option', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_option_geo', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_raw_slice', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_result', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_std_string', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_str', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_struct', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_tuple', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_u16', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_u256', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_u32', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_u64', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_u8', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_value_then_empty', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_value_then_empty_then_value', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_vector_geo', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_vector_option', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'types_vector_u8', data: BytesLike): DecodedValue;
}

export class MyContractAbi extends Contract {
Expand Down
2 changes: 0 additions & 2 deletions packages/program/src/functions/base-invocation-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ function createContractCall(funcScope: InvocationScopeLike): ContractCall {

return {
contractId: (program as AbstractContract).id,
fnSelector: func.selector,
fnSelectorBytes: func.selectorBytes,
encoding: func.encoding,
danielbate marked this conversation as resolved.
Show resolved Hide resolved
data,
assetId: forward?.assetId,
amount: forward?.amount,
Expand Down
4 changes: 1 addition & 3 deletions packages/program/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FunctionFragment, JsonAbi, EncodingVersion } from '@fuel-ts/abi-coder';
import type { FunctionFragment, JsonAbi } from '@fuel-ts/abi-coder';
import type { CoinQuantity, CoinQuantityLike } from '@fuel-ts/account';
import type { AbstractProgram, AbstractAddress, BytesLike } from '@fuel-ts/interfaces';
import type { BigNumberish } from '@fuel-ts/math';
Expand All @@ -11,9 +11,7 @@ import type { FunctionInvocationScope } from './functions/invocation-scope';
export type ContractCall = {
contractId: AbstractAddress;
data: BytesLike;
fnSelector: string;
fnSelectorBytes: Uint8Array;
encoding?: EncodingVersion;
amount?: BigNumberish;
assetId?: BytesLike;
gas?: BigNumberish;
Expand Down
Loading