Skip to content

Commit

Permalink
Support calling method multiple times in milticall
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Jul 23, 2024
1 parent 34fd181 commit 35ede59
Show file tree
Hide file tree
Showing 32 changed files with 604 additions and 24 deletions.
12 changes: 6 additions & 6 deletions .project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"infos": {
"Add": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "e53e74ff98c352525e856abd4311868176d45c61c957791c3d42eae274088df0",
"bytecodeDebugPatch": "=12-2+5c=2-2+81=3-1+e=2-2+bc=83-1+97e010a61646450726976617465=266",
"codeHashDebug": "c46db1ae7bae8b332c115869126eb1402bc71574925608a2adcea3cf7b9f8e7e",
"sourceCodeHash": "6b4446c131ebdde7662571313e51887d9edb809f64e40d91a4b39cdcd750654a",
"bytecodeDebugPatch": "=12-2+5c=2-5+8=4-1+e=3-1+c40ca=83-1+97e010a61646450726976617465=294",
"codeHashDebug": "f33fc76b0c24f4cad3809b504f064346033dc25d2ed78a643cd7e61417521fdd",
"warnings": [
"Found unused variables in Add: add2.addS, add2.address, add2.array2",
"The return values of the function \"Add.copyCreateSubContract\" are not used. If this is intentional, consider using anonymous variables to suppress this warning.",
Expand All @@ -26,7 +26,7 @@
},
"AddMain": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "e53e74ff98c352525e856abd4311868176d45c61c957791c3d42eae274088df0",
"sourceCodeHash": "6b4446c131ebdde7662571313e51887d9edb809f64e40d91a4b39cdcd750654a",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": [
Expand All @@ -35,14 +35,14 @@
},
"AddStruct1": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "e53e74ff98c352525e856abd4311868176d45c61c957791c3d42eae274088df0",
"sourceCodeHash": "6b4446c131ebdde7662571313e51887d9edb809f64e40d91a4b39cdcd750654a",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
},
"AddStruct2": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "e53e74ff98c352525e856abd4311868176d45c61c957791c3d42eae274088df0",
"sourceCodeHash": "6b4446c131ebdde7662571313e51887d9edb809f64e40d91a4b39cdcd750654a",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
Expand Down
15 changes: 12 additions & 3 deletions artifacts/add/Add.ral.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": "v3.2.0",
"version": "v3.3.0",
"name": "Add",
"bytecode": "0206124024404f407440a140af010002100205d34fbb20db1600160100020201000c0c0205d36a51f82d1600160100020200000202021805160016015f06160016015f075da00016002a16012aa100a000160016010e0dce000100020103040c0011d319adf50e1300641600130164170517041603d1a21601160216041605c118010104060015d3f6ce55a6130064160013016417051704160316021340c8ac1603d1a21601160216041605c118010201010003d320f98f621600b0",
"codeHash": "6a1f1415a68d55365e205b39e5418cd1f6fc8c2c7926d3662c77d69b55c92681",
"bytecode": "0207124024404f407440a140af40bd010002100205d34fbb20db1600160100020201000c0c0205d36a51f82d1600160100020200000202021805160016015f06160016015f075da00016002a16012aa100a000160016010e0dce000100020103040c0011d319adf50e1300641600130164170517041603d1a21601160216041605c118010104060015d3f6ce55a6130064160013016417051704160316021340c8ac1603d1a21601160216041605c118010201010003d320f98f621600b0010000000103d3fb40c983a00002",
"codeHash": "7c3b1b6ea587ea7b796a69e9db8efc4b763be9473ffb95642be042849a45ab24",
"fieldsSig": {
"names": [
"sub",
Expand Down Expand Up @@ -157,6 +157,15 @@
false
],
"returnTypes": []
},
{
"name": "getResult",
"paramNames": [],
"paramTypes": [],
"paramIsMutable": [],
"returnTypes": [
"U256"
]
}
],
"constants": [],
Expand Down
2 changes: 1 addition & 1 deletion artifacts/add/AddMain.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v3.2.0",
"version": "v3.3.0",
"name": "AddMain",
"bytecodeTemplate": "0101030002000c{1}{2}17011700160016010e0e{0}01001818",
"fieldsSig": {
Expand Down
57 changes: 55 additions & 2 deletions artifacts/ts/Add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testMethod,
callMethod,
multicallMethods,
multicall,
fetchContractState,
ContractInstance,
getContractEventsCurrentCount,
Expand Down Expand Up @@ -91,6 +92,10 @@ export namespace AddTypes {
params: CallContractParams<{ caller: Address }>;
result: CallContractResult<null>;
};
getResult: {
params: Omit<CallContractParams<{}>, "args">;
result: CallContractResult<bigint>;
};
}
export type CallMethodParams<T extends keyof CallMethodTable> =
CallMethodTable[T]["params"];
Expand All @@ -104,6 +109,15 @@ export namespace AddTypes {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MultiCallByMethodParams = {
[Name in keyof CallMethodTable]: {
method: Name;
params: CallMethodTable[Name]["params"];
};
}[keyof CallMethodTable][];
export type MultiCallByMethodResults<T extends MultiCallByMethodParams> = {
[I in keyof T]: CallMethodTable[T[I]["method"]]["result"];
};

export interface SignExecuteMethodTable {
add: {
Expand Down Expand Up @@ -141,6 +155,10 @@ export namespace AddTypes {
params: SignExecuteContractMethodParams<{ caller: Address }>;
result: SignExecuteScriptTxResult;
};
getResult: {
params: Omit<SignExecuteContractMethodParams<{}>, "args">;
result: SignExecuteScriptTxResult;
};
}
export type SignExecuteMethodParams<T extends keyof SignExecuteMethodTable> =
SignExecuteMethodTable[T]["params"];
Expand Down Expand Up @@ -231,15 +249,23 @@ class Factory extends ContractFactory<AddInstance, AddTypes.Fields> {
): Promise<TestContractResultWithoutMaps<null>> => {
return testMethod(this, "destroy", params, getContractByCodeHash);
},
getResult: async (
params: Omit<
TestContractParamsWithoutMaps<AddTypes.Fields, never>,
"testArgs"
>
): Promise<TestContractResultWithoutMaps<bigint>> => {
return testMethod(this, "getResult", params, getContractByCodeHash);
},
};
}

// Use this object to test and deploy the contract
export const Add = new Factory(
Contract.fromJson(
AddContractJson,
"=12-2+5c=2-2+81=3-1+e=2-2+bc=83-1+97e010a61646450726976617465=266",
"c46db1ae7bae8b332c115869126eb1402bc71574925608a2adcea3cf7b9f8e7e",
"=12-2+5c=2-5+8=4-1+e=3-1+c40ca=83-1+97e010a61646450726976617465=294",
"f33fc76b0c24f4cad3809b504f064346033dc25d2ed78a643cd7e61417521fdd",
AllStructs
)
);
Expand Down Expand Up @@ -344,6 +370,17 @@ export class AddInstance extends ContractInstance {
): Promise<AddTypes.CallMethodResult<"destroy">> => {
return callMethod(Add, this, "destroy", params, getContractByCodeHash);
},
getResult: async (
params?: AddTypes.CallMethodParams<"getResult">
): Promise<AddTypes.CallMethodResult<"getResult">> => {
return callMethod(
Add,
this,
"getResult",
params === undefined ? {} : params,
getContractByCodeHash
);
},
};

transact = {
Expand Down Expand Up @@ -379,6 +416,11 @@ export class AddInstance extends ContractInstance {
): Promise<AddTypes.SignExecuteMethodResult<"destroy">> => {
return signExecuteMethod(Add, this, "destroy", params);
},
getResult: async (
params: AddTypes.SignExecuteMethodParams<"getResult">
): Promise<AddTypes.SignExecuteMethodResult<"getResult">> => {
return signExecuteMethod(Add, this, "getResult", params);
},
};

async multicall<Calls extends AddTypes.MultiCallParams>(
Expand All @@ -391,4 +433,15 @@ export class AddInstance extends ContractInstance {
getContractByCodeHash
)) as AddTypes.MultiCallResults<Calls>;
}

async multicallByMethod<Calls extends AddTypes.MultiCallByMethodParams>(
calls: Calls
): Promise<AddTypes.MultiCallByMethodResults<Calls>> {
return (await multicall(
Add,
this,
calls,
getContractByCodeHash
)) as AddTypes.MultiCallByMethodResults<Calls>;
}
}
10 changes: 10 additions & 0 deletions artifacts/ts/Assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testMethod,
callMethod,
multicallMethods,
multicall,
fetchContractState,
ContractInstance,
getContractEventsCurrentCount,
Expand Down Expand Up @@ -64,6 +65,15 @@ export namespace AssertTypes {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MultiCallByMethodParams = {
[Name in keyof CallMethodTable]: {
method: Name;
params: CallMethodTable[Name]["params"];
};
}[keyof CallMethodTable][];
export type MultiCallByMethodResults<T extends MultiCallByMethodParams> = {
[I in keyof T]: CallMethodTable[T[I]["method"]]["result"];
};

export interface SignExecuteMethodTable {
test: {
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testMethod,
callMethod,
multicallMethods,
multicall,
fetchContractState,
ContractInstance,
getContractEventsCurrentCount,
Expand Down Expand Up @@ -64,6 +65,15 @@ export namespace DebugTypes {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MultiCallByMethodParams = {
[Name in keyof CallMethodTable]: {
method: Name;
params: CallMethodTable[Name]["params"];
};
}[keyof CallMethodTable][];
export type MultiCallByMethodResults<T extends MultiCallByMethodParams> = {
[I in keyof T]: CallMethodTable[T[I]["method"]]["result"];
};

export interface SignExecuteMethodTable {
debug: {
Expand Down
23 changes: 23 additions & 0 deletions artifacts/ts/DeprecatedNFTTest1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testMethod,
callMethod,
multicallMethods,
multicall,
fetchContractState,
ContractInstance,
getContractEventsCurrentCount,
Expand Down Expand Up @@ -69,6 +70,15 @@ export namespace DeprecatedNFTTest1Types {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MultiCallByMethodParams = {
[Name in keyof CallMethodTable]: {
method: Name;
params: CallMethodTable[Name]["params"];
};
}[keyof CallMethodTable][];
export type MultiCallByMethodResults<T extends MultiCallByMethodParams> = {
[I in keyof T]: CallMethodTable[T[I]["method"]]["result"];
};

export interface SignExecuteMethodTable {
getTokenUri: {
Expand Down Expand Up @@ -168,4 +178,17 @@ export class DeprecatedNFTTest1Instance extends ContractInstance {
getContractByCodeHash
)) as DeprecatedNFTTest1Types.MultiCallResults<Calls>;
}

async multicallByMethod<
Calls extends DeprecatedNFTTest1Types.MultiCallByMethodParams
>(
calls: Calls
): Promise<DeprecatedNFTTest1Types.MultiCallByMethodResults<Calls>> {
return (await multicall(
DeprecatedNFTTest1,
this,
calls,
getContractByCodeHash
)) as DeprecatedNFTTest1Types.MultiCallByMethodResults<Calls>;
}
}
23 changes: 23 additions & 0 deletions artifacts/ts/DeprecatedNFTTest2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testMethod,
callMethod,
multicallMethods,
multicall,
fetchContractState,
ContractInstance,
getContractEventsCurrentCount,
Expand Down Expand Up @@ -73,6 +74,15 @@ export namespace DeprecatedNFTTest2Types {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MultiCallByMethodParams = {
[Name in keyof CallMethodTable]: {
method: Name;
params: CallMethodTable[Name]["params"];
};
}[keyof CallMethodTable][];
export type MultiCallByMethodResults<T extends MultiCallByMethodParams> = {
[I in keyof T]: CallMethodTable[T[I]["method"]]["result"];
};

export interface SignExecuteMethodTable {
getTokenUri: {
Expand Down Expand Up @@ -207,4 +217,17 @@ export class DeprecatedNFTTest2Instance extends ContractInstance {
getContractByCodeHash
)) as DeprecatedNFTTest2Types.MultiCallResults<Calls>;
}

async multicallByMethod<
Calls extends DeprecatedNFTTest2Types.MultiCallByMethodParams
>(
calls: Calls
): Promise<DeprecatedNFTTest2Types.MultiCallByMethodResults<Calls>> {
return (await multicall(
DeprecatedNFTTest2,
this,
calls,
getContractByCodeHash
)) as DeprecatedNFTTest2Types.MultiCallByMethodResults<Calls>;
}
}
23 changes: 23 additions & 0 deletions artifacts/ts/DeprecatedNFTTest3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testMethod,
callMethod,
multicallMethods,
multicall,
fetchContractState,
ContractInstance,
getContractEventsCurrentCount,
Expand Down Expand Up @@ -73,6 +74,15 @@ export namespace DeprecatedNFTTest3Types {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MultiCallByMethodParams = {
[Name in keyof CallMethodTable]: {
method: Name;
params: CallMethodTable[Name]["params"];
};
}[keyof CallMethodTable][];
export type MultiCallByMethodResults<T extends MultiCallByMethodParams> = {
[I in keyof T]: CallMethodTable[T[I]["method"]]["result"];
};

export interface SignExecuteMethodTable {
getTokenUri: {
Expand Down Expand Up @@ -207,4 +217,17 @@ export class DeprecatedNFTTest3Instance extends ContractInstance {
getContractByCodeHash
)) as DeprecatedNFTTest3Types.MultiCallResults<Calls>;
}

async multicallByMethod<
Calls extends DeprecatedNFTTest3Types.MultiCallByMethodParams
>(
calls: Calls
): Promise<DeprecatedNFTTest3Types.MultiCallByMethodResults<Calls>> {
return (await multicall(
DeprecatedNFTTest3,
this,
calls,
getContractByCodeHash
)) as DeprecatedNFTTest3Types.MultiCallByMethodResults<Calls>;
}
}
Loading

0 comments on commit 35ede59

Please sign in to comment.