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

fix: contract class splitArgsAndOptions #1253

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/contract/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ProviderInterface, defaultProvider } from '../provider';
import {
Abi,
AbiEvents,
AbiStruct,
ArgsOrCalldata,
ArgsOrCalldataWithOptions,
AsyncContractFunction,
Expand All @@ -21,16 +22,15 @@ import {
ParsedEvents,
RawArgs,
Result,
AbiStruct,
ValidateType,
} from '../types';
import assert from '../utils/assert';
import { CallData, cairo } from '../utils/calldata';
import { createAbiParser } from '../utils/calldata/parser';
import { getAbiEvents, parseEvents as parseRawEvents } from '../utils/events/index';
import { cleanHex } from '../utils/num';
import { ContractInterface } from './interface';
import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt';
import { ContractInterface } from './interface';

export type TypedContractV2<TAbi extends AbiKanabi> = AbiWanTypedContract<TAbi> & Contract;

Expand Down Expand Up @@ -70,7 +70,7 @@ function buildCall(contract: Contract, functionAbi: FunctionAbi): AsyncContractF
* Adds invoke methods to the contract
*/
function buildInvoke(contract: Contract, functionAbi: FunctionAbi): AsyncContractFunction {
return async function (...args: Array<any>): Promise<any> {
return async function (...args: ArgsOrCalldataWithOptions): Promise<any> {
const params = splitArgsAndOptions(args);
return contract.invoke(functionAbi.name, params.args, {
parseRequest: true,
Expand Down
33 changes: 31 additions & 2 deletions src/types/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,37 @@ export type Result =
| boolean
| CairoEnum;

export type ArgsOrCalldata = RawArgsArray | [Calldata] | Calldata;
export type ArgsOrCalldataWithOptions = ArgsOrCalldata & ContractOptions;
// export type ArgsOrCalldata = RawArgsArray | [Calldata] | Calldata;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only q I have is if these are left intentionally here commented out?

// export type ArgsOrCalldataWithOptions = ArgsOrCalldata & ContractOptions;

// RawParamsOrCalldata as args
export type ArgsOrCalldata =
// params like (va,vb,vc,vd...) as args is [va,vb,vc,vd...]
// params like (x) where x = {a:va,b:vb,c:vc...} as args is [x]
// params like (x) where x = [va,vb,vc...] as args is [[x]]
| RawArgsArray // recursive definition cover all this cases
// [calldata] is [['0x','0x'...]]
| [Calldata]
// calldata is ['0x','0x'...]
| Calldata;

// RawParamsOrCalldata where each can have an option
export type ArgsOrCalldataWithOptions =
// params like (va,vb,vc,vd..., option) as args is [va,vb,vc,vd..., option]
// params like (x, option) where x = {a:va,b:vb,c:vc...} as args is [x, option]
// params like (x, option) where x = [va,vb,vc...] as args is [[x], option]
// recursive definition cover all this cases
| [...RawArgsArray]
| [...RawArgsArray, ContractOptions]
// used when called compile that return array of calldata
// (calldata, options) as args is [['0x','0x'...], options]
| [Calldata]
| [Calldata, ContractOptions]
// used when separate params compilations
// (c,a,l,l,d,a,t,a, options) as args is ['0x','0x'..., options]
| [...Calldata]
| [...Calldata, ContractOptions];

export type ContractOptions = {
blockIdentifier?: BlockIdentifier;
parseRequest?: boolean;
Expand Down