Skip to content

Commit

Permalink
Merge pull request #390 from alephium/call-tx-script
Browse files Browse the repository at this point in the history
Add support for calling TxScript
  • Loading branch information
polarker committed Jul 5, 2024
2 parents 8f3c62c + 14ece73 commit f2b593f
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 58 deletions.
30 changes: 22 additions & 8 deletions .project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"fullNodeVersion": "v3.2.0",
"fullNodeVersion": "v3.3.0",
"compilerOptionsUsed": {
"ignoreUnusedConstantsWarnings": false,
"ignoreUnusedVariablesWarnings": false,
Expand Down Expand Up @@ -63,6 +63,20 @@
"codeHashDebug": "",
"warnings": []
},
"CallScript0": {
"sourceFile": "test/call_scripts.ral",
"sourceCodeHash": "71ecb0e86393e15d1b284326c92ac9b0d15e8fdad75cd5dc197cd34679ca83f1",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
},
"CallScript1": {
"sourceFile": "test/call_scripts.ral",
"sourceCodeHash": "71ecb0e86393e15d1b284326c92ac9b0d15e8fdad75cd5dc197cd34679ca83f1",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
},
"Debug": {
"sourceFile": "test/debug.ral",
"sourceCodeHash": "0d7cdfad264cf2009dd8907b716ba0d79cc4cf722b35773129645c5415bcb4dc",
Expand Down Expand Up @@ -193,16 +207,16 @@
},
"InsertIntoMap": {
"sourceFile": "test/map.ral",
"sourceCodeHash": "997a7ecabb3c68882a1c28b4889c252258493c1bcb1877d4afe992a872420d38",
"sourceCodeHash": "f797013ab9c7bf780bb8f452c0724703e877bbd9d71a60b400ed5009eb0f08e8",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
},
"MapTest": {
"sourceFile": "test/map.ral",
"sourceCodeHash": "997a7ecabb3c68882a1c28b4889c252258493c1bcb1877d4afe992a872420d38",
"bytecodeDebugPatch": "=6-2+a8=1-3+128=2-2+ea=10-2+4025=50+7a7e0214696e73657274206174206d617020706174683a2000=56+7a7e0214696e73657274206174206d617020706174683a2000=54+7a7e0214696e73657274206174206d617020706174683a2000=280-2+33=124+7a7e021472656d6f7665206174206d617020706174683a2000=46+7a7e021472656d6f7665206174206d617020706174683a2000=48+7a7e021472656d6f7665206174206d617020706174683a2000=6",
"codeHashDebug": "8666d70738c42748551e987c3eb46a2d7b1db5d82f5f6b2fdfc95b3906ff7477",
"sourceCodeHash": "f797013ab9c7bf780bb8f452c0724703e877bbd9d71a60b400ed5009eb0f08e8",
"bytecodeDebugPatch": "=6-2+a8=1-3+128=2-2+ea=1+2=1-2+7=10-2+4025=50+7a7e0214696e73657274206174206d617020706174683a2000=56+7a7e0214696e73657274206174206d617020706174683a2000=54+7a7e0214696e73657274206174206d617020706174683a2000=280-2+33=124+7a7e021472656d6f7665206174206d617020706174683a2000=46+7a7e021472656d6f7665206174206d617020706174683a2000=48+7a7e021472656d6f7665206174206d617020706174683a2000=96",
"codeHashDebug": "31aed0ff7b29f2cbc2d8360a83f31af4e9db00f0084a7406bd84b7745181373d",
"warnings": [
"No external caller check for function \"MapTest.remove\". Please use \"checkCaller!(...)\" in the function or its callees, or disable it with \"@using(checkExternalCaller = false)\".",
"No external caller check for function \"MapTest.update\". Please use \"checkCaller!(...)\" in the function or its callees, or disable it with \"@using(checkExternalCaller = false)\".",
Expand All @@ -211,7 +225,7 @@
},
"MapValue": {
"sourceFile": "test/map.ral",
"sourceCodeHash": "997a7ecabb3c68882a1c28b4889c252258493c1bcb1877d4afe992a872420d38",
"sourceCodeHash": "f797013ab9c7bf780bb8f452c0724703e877bbd9d71a60b400ed5009eb0f08e8",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
Expand Down Expand Up @@ -278,7 +292,7 @@
},
"RemoveFromMap": {
"sourceFile": "test/map.ral",
"sourceCodeHash": "997a7ecabb3c68882a1c28b4889c252258493c1bcb1877d4afe992a872420d38",
"sourceCodeHash": "f797013ab9c7bf780bb8f452c0724703e877bbd9d71a60b400ed5009eb0f08e8",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
Expand Down Expand Up @@ -320,7 +334,7 @@
},
"UpdateMapValue": {
"sourceFile": "test/map.ral",
"sourceCodeHash": "997a7ecabb3c68882a1c28b4889c252258493c1bcb1877d4afe992a872420d38",
"sourceCodeHash": "f797013ab9c7bf780bb8f452c0724703e877bbd9d71a60b400ed5009eb0f08e8",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
Expand Down
30 changes: 30 additions & 0 deletions artifacts/test/CallScript0.ral.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "v3.2.0",
"name": "CallScript0",
"bytecodeTemplate": "01010000000206{1}0d0e{0}010302",
"fieldsSig": {
"names": [
"mapTest",
"key"
],
"types": [
"MapTest",
"Address"
],
"isMutable": [
false,
false
]
},
"functions": [
{
"name": "main",
"paramNames": [],
"paramTypes": [],
"paramIsMutable": [],
"returnTypes": [
"MapValue"
]
}
]
}
34 changes: 34 additions & 0 deletions artifacts/test/CallScript1.ral.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "v3.2.0",
"name": "CallScript1",
"bytecodeTemplate": "0101000000070a{1}0d0e{0}01030c11{2}010202",
"fieldsSig": {
"names": [
"mapTest",
"key",
"userAccount"
],
"types": [
"MapTest",
"Address",
"UserAccount"
],
"isMutable": [
false,
false,
false
]
},
"functions": [
{
"name": "main",
"paramNames": [],
"paramTypes": [],
"paramIsMutable": [],
"returnTypes": [
"MapValue",
"Balances"
]
}
]
}
2 changes: 1 addition & 1 deletion artifacts/test/InsertIntoMap.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v3.1.4",
"version": "v3.2.0",
"name": "InsertIntoMap",
"bytecodeTemplate": "01010300020010{2}{3}17011700{1}d10f2ca2{1}160016010f0c{0}0100",
"fieldsSig": {
Expand Down
21 changes: 18 additions & 3 deletions artifacts/test/MapTest.ral.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": "v3.1.4",
"version": "v3.2.0",
"name": "MapTest",
"bytecode": "0003405c40dc415301030303001fd3a9cdcc691600d1a2140a5f5f6d61705f5f305f5f160047441601b11602d202011600d1a2140a5f5f6d61705f5f315f5f16014044b11602d201011600d1a2140a5f5f6d61705f5f325f5f1402001144b11602d2010101000104004036d3c50ed2bb0c0d0d140a5f5f6d61705f5f305f5f16004744cb1703160301000c0d0d160301011702170116020d2a0c0e0c140a5f5f6d61705f5f305f5f16004744cb010216020d2a0c0e0c140a5f5f6d61705f5f315f5f16014044cb010216020d2a0c0e0c140a5f5f6d61705f5f325f5f1402001144cb01020100010400402dd392ac08660c0d0d140a5f5f6d61705f5f305f5f16004744cb1703160301000c0d0d160301011702170116000d0c140a5f5f6d61705f5f305f5f16004744cb010316000d0c140a5f5f6d61705f5f315f5f16014044cb010316000d0c140a5f5f6d61705f5f325f5f1402001144cb0103",
"codeHash": "6ce8563011315ab1834d01457eb638c0a081c689b0daf1a59f8d914330a8673d",
"bytecode": "0004405c40dc4153418001030303001fd3a9cdcc691600d1a2140a5f5f6d61705f5f305f5f160047441601b11602d202011600d1a2140a5f5f6d61705f5f315f5f16014044b11602d201011600d1a2140a5f5f6d61705f5f325f5f1402001144b11602d2010101000104004036d3c50ed2bb0c0d0d140a5f5f6d61705f5f305f5f16004744cb1703160301000c0d0d160301011702170116020d2a0c0e0c140a5f5f6d61705f5f305f5f16004744cb010216020d2a0c0e0c140a5f5f6d61705f5f315f5f16014044cb010216020d2a0c0e0c140a5f5f6d61705f5f325f5f1402001144cb01020100010400402dd392ac08660c0d0d140a5f5f6d61705f5f305f5f16004744cb1703160301000c0d0d160301011702170116000d0c140a5f5f6d61705f5f305f5f16004744cb010316000d0c140a5f5f6d61705f5f315f5f16014044cb010316000d0c140a5f5f6d61705f5f325f5f1402001144cb0103010001020212d3143f7dc50c0d0d140a5f5f6d61705f5f305f5f16004744cb1701160101000c0d0d1601010102",
"codeHash": "9c0dad73dd47255270a366794f84539f06816e30c68b1f1cca767707fa8db596",
"fieldsSig": {
"names": [],
"types": [],
Expand Down Expand Up @@ -51,6 +51,21 @@
false
],
"returnTypes": []
},
{
"name": "getValue",
"paramNames": [
"key"
],
"paramTypes": [
"Address"
],
"paramIsMutable": [
false
],
"returnTypes": [
"MapValue"
]
}
],
"constants": [],
Expand Down
2 changes: 1 addition & 1 deletion artifacts/test/RemoveFromMap.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v3.1.4",
"version": "v3.2.0",
"name": "RemoveFromMap",
"bytecodeTemplate": "01010300000005{1}0d0c{0}0102",
"fieldsSig": {
Expand Down
2 changes: 1 addition & 1 deletion artifacts/test/UpdateMapValue.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v3.1.4",
"version": "v3.2.0",
"name": "UpdateMapValue",
"bytecodeTemplate": "01010300000005{1}0d0c{0}0101",
"fieldsSig": {
Expand Down
64 changes: 62 additions & 2 deletions artifacts/ts/MapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export namespace MapTestTypes {
params: CallContractParams<{ key: Address }>;
result: CallContractResult<null>;
};
getValue: {
params: CallContractParams<{ key: Address }>;
result: CallContractResult<MapValue>;
};
}
export type CallMethodParams<T extends keyof CallMethodTable> =
CallMethodTable[T]["params"];
Expand Down Expand Up @@ -90,6 +94,10 @@ export namespace MapTestTypes {
params: SignExecuteContractMethodParams<{ key: Address }>;
result: SignExecuteScriptTxResult;
};
getValue: {
params: SignExecuteContractMethodParams<{ key: Address }>;
result: SignExecuteScriptTxResult;
};
}
export type SignExecuteMethodParams<T extends keyof SignExecuteMethodTable> =
SignExecuteMethodTable[T]["params"];
Expand Down Expand Up @@ -182,15 +190,40 @@ class Factory extends ContractFactory<MapTestInstance, {}> {
> => {
return testMethod(this, "remove", params, getContractByCodeHash);
},
getValue: async (
params: Omit<
TestContractParams<
never,
{ key: Address },
{
map0?: Map<Address, MapValue>;
map1?: Map<bigint, bigint>;
map2?: Map<HexString, bigint>;
}
>,
"initialFields"
>
): Promise<
TestContractResult<
MapValue,
{
map0?: Map<Address, MapValue>;
map1?: Map<bigint, bigint>;
map2?: Map<HexString, bigint>;
}
>
> => {
return testMethod(this, "getValue", params, getContractByCodeHash);
},
};
}

// Use this object to test and deploy the contract
export const MapTest = new Factory(
Contract.fromJson(
MapTestContractJson,
"=6-2+a8=1-3+128=2-2+ea=10-2+4025=50+7a7e0214696e73657274206174206d617020706174683a2000=56+7a7e0214696e73657274206174206d617020706174683a2000=54+7a7e0214696e73657274206174206d617020706174683a2000=280-2+33=124+7a7e021472656d6f7665206174206d617020706174683a2000=46+7a7e021472656d6f7665206174206d617020706174683a2000=48+7a7e021472656d6f7665206174206d617020706174683a2000=6",
"8666d70738c42748551e987c3eb46a2d7b1db5d82f5f6b2fdfc95b3906ff7477",
"=6-2+a8=1-3+128=2-2+ea=1+2=1-2+7=10-2+4025=50+7a7e0214696e73657274206174206d617020706174683a2000=56+7a7e0214696e73657274206174206d617020706174683a2000=54+7a7e0214696e73657274206174206d617020706174683a2000=280-2+33=124+7a7e021472656d6f7665206174206d617020706174683a2000=46+7a7e021472656d6f7665206174206d617020706174683a2000=48+7a7e021472656d6f7665206174206d617020706174683a2000=96",
"31aed0ff7b29f2cbc2d8360a83f31af4e9db00f0084a7406bd84b7745181373d",
AllStructs
)
);
Expand Down Expand Up @@ -239,6 +272,17 @@ export class MapTestInstance extends ContractInstance {
): Promise<MapTestTypes.CallMethodResult<"remove">> => {
return callMethod(MapTest, this, "remove", params, getContractByCodeHash);
},
getValue: async (
params: MapTestTypes.CallMethodParams<"getValue">
): Promise<MapTestTypes.CallMethodResult<"getValue">> => {
return callMethod(
MapTest,
this,
"getValue",
params,
getContractByCodeHash
);
},
};

transact = {
Expand All @@ -257,5 +301,21 @@ export class MapTestInstance extends ContractInstance {
): Promise<MapTestTypes.SignExecuteMethodResult<"remove">> => {
return signExecuteMethod(MapTest, this, "remove", params);
},
getValue: async (
params: MapTestTypes.SignExecuteMethodParams<"getValue">
): Promise<MapTestTypes.SignExecuteMethodResult<"getValue">> => {
return signExecuteMethod(MapTest, this, "getValue", params);
},
};

async multicall<Calls extends MapTestTypes.MultiCallParams>(
calls: Calls
): Promise<MapTestTypes.MultiCallResults<Calls>> {
return (await multicallMethods(
MapTest,
this,
calls,
getContractByCodeHash
)) as MapTestTypes.MultiCallResults<Calls>;
}
}
Loading

0 comments on commit f2b593f

Please sign in to comment.