Skip to content

Commit

Permalink
Support array and struct types
Browse files Browse the repository at this point in the history
  • Loading branch information
h0ngcha0 committed Apr 18, 2024
1 parent e918560 commit 0415502
Show file tree
Hide file tree
Showing 33 changed files with 491 additions and 55 deletions.
26 changes: 21 additions & 5 deletions .project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,40 @@
"infos": {
"Add": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "1aefef4f21ebee078768df8158bd43d5008e640e443f9b41f0cdbfc8e43eccdd",
"bytecodeDebugPatch": "=8+4=1-1=2-1=1+3=2-2+6c=37+77e010a=1+1646450726976617465=152",
"codeHashDebug": "6d87d293224fce4601a8e315e6a384aca46fdd1adab1402ffae8cc454b94a66e",
"sourceCodeHash": "ff387b4feef2fd71654165255dd2eb872b8e7366f976419693f9124ed60a7ab2",
"bytecodeDebugPatch": "=10-2+50=2-2+70=2-2+79=63+77e010a=1+1646450726976617465=152",
"codeHashDebug": "9a4cf22e444db365cc62468b22db303401e6942409e193055e7f5f0318b389ca",
"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.",
"No external caller check for function \"Add.createSubContract\". Please use \"checkCaller!(...)\" in the function or its callees, or disable it with \"@using(checkExternalCaller = false)\".",
"No external caller check for function \"Add.add\". Please use \"checkCaller!(...)\" in the function or its callees, or disable it with \"@using(checkExternalCaller = false)\"."
"No external caller check for function \"Add.add\". Please use \"checkCaller!(...)\" in the function or its callees, or disable it with \"@using(checkExternalCaller = false)\".",
"No external caller check for function \"Add.add2\". Please use \"checkCaller!(...)\" in the function or its callees, or disable it with \"@using(checkExternalCaller = false)\"."
]
},
"AddMain": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "1aefef4f21ebee078768df8158bd43d5008e640e443f9b41f0cdbfc8e43eccdd",
"sourceCodeHash": "ff387b4feef2fd71654165255dd2eb872b8e7366f976419693f9124ed60a7ab2",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": [
"The return values of the function \"Add.add\" are not used. If this is intentional, consider using anonymous variables to suppress this warning."
]
},
"AddStruct1": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "ff387b4feef2fd71654165255dd2eb872b8e7366f976419693f9124ed60a7ab2",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
},
"AddStruct2": {
"sourceFile": "add/add.ral",
"sourceCodeHash": "ff387b4feef2fd71654165255dd2eb872b8e7366f976419693f9124ed60a7ab2",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
},
"Assert": {
"sourceFile": "test/assert.ral",
"sourceCodeHash": "65f8387941a38e88ef555f5d0b4992dab390d97ff97b2473fdea45b8d58a74a5",
Expand Down
31 changes: 29 additions & 2 deletions artifacts/add/Add.ral.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": "v2.11.0",
"name": "Add",
"bytecode": "02040d40364056405f0100020402041600160100010200000202021605160016015f06160016015fa00016002a16012aa100a000160016010e0dce000100020103040600101300641600130164170517041603d1a21601160216041605c1180102010100021600b0",
"codeHash": "97dbb799a710b8cf8dd878e3892333657c26020014bd2f0099850a26bd39668a",
"bytecode": "02050d1a40434063406c0100021002041600160100020201000c0c02041600160100020200000202021605160016015f06160016015fa00016002a16012aa100a000160016010e0dce000100020103040600101300641600130164170517041603d1a21601160216041605c1180102010100021600b0",
"codeHash": "cb9bcf12cd42167de9cd08cbb974d03263bf8fd12fae62340a72029f35497b04",
"fieldsSig": {
"names": [
"sub",
Expand Down Expand Up @@ -60,6 +60,33 @@
"[U256;2]"
]
},
{
"name": "add2",
"usePreapprovedAssets": false,
"useAssetsInContract": false,
"isPublic": true,
"paramNames": [
"array1",
"address",
"array2",
"addS"
],
"paramTypes": [
"[U256;2]",
"Address",
"[U256;2]",
"AddStruct1"
],
"paramIsMutable": [
false,
false,
false,
false
],
"returnTypes": [
"[U256;2]"
]
},
{
"name": "addPrivate",
"usePreapprovedAssets": false,
Expand Down
2 changes: 1 addition & 1 deletion artifacts/add/DestroyAdd.ral.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "v2.11.0",
"name": "DestroyAdd",
"bytecodeTemplate": "01010300000005{1}0d0c{0}0103",
"bytecodeTemplate": "01010300000005{1}0d0c{0}0104",
"fieldsSig": {
"names": [
"add",
Expand Down
30 changes: 30 additions & 0 deletions artifacts/structs.ral.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
[
{
"name": "AddStruct1",
"fieldNames": [
"a",
"b"
],
"fieldTypes": [
"U256",
"[AddStruct2;2]"
],
"isMutable": [
false,
false
]
},
{
"name": "AddStruct2",
"fieldNames": [
"a",
"b"
],
"fieldTypes": [
"U256",
"[U256;2]"
],
"isMutable": [
false,
false
]
},
{
"name": "MapValue",
"fieldNames": [
Expand Down
54 changes: 51 additions & 3 deletions artifacts/ts/Add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as AddContractJson } from "../add/Add.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace AddTypes {
Expand All @@ -50,6 +57,15 @@ export namespace AddTypes {
params: CallContractParams<{ array: [bigint, bigint] }>;
result: CallContractResult<[bigint, bigint]>;
};
add2: {
params: CallContractParams<{
array1: [bigint, bigint];
address: Address;
array2: [bigint, bigint];
addS: AddStruct1;
}>;
result: CallContractResult<[bigint, bigint]>;
};
createSubContract: {
params: CallContractParams<{
a: bigint;
Expand Down Expand Up @@ -82,6 +98,15 @@ export namespace AddTypes {
params: SignExecuteContractMethodParams<{ array: [bigint, bigint] }>;
result: SignExecuteScriptTxResult;
};
add2: {
params: SignExecuteContractMethodParams<{
array1: [bigint, bigint];
address: Address;
array2: [bigint, bigint];
addS: AddStruct1;
}>;
result: SignExecuteScriptTxResult;
};
createSubContract: {
params: SignExecuteContractMethodParams<{
a: bigint;
Expand Down Expand Up @@ -122,6 +147,19 @@ class Factory extends ContractFactory<AddInstance, AddTypes.Fields> {
): Promise<TestContractResultWithoutMaps<[bigint, bigint]>> => {
return testMethod(this, "add", params);
},
add2: async (
params: TestContractParamsWithoutMaps<
AddTypes.Fields,
{
array1: [bigint, bigint];
address: Address;
array2: [bigint, bigint];
addS: AddStruct1;
}
>
): Promise<TestContractResultWithoutMaps<[bigint, bigint]>> => {
return testMethod(this, "add2", params);
},
addPrivate: async (
params: TestContractParamsWithoutMaps<
AddTypes.Fields,
Expand Down Expand Up @@ -153,8 +191,8 @@ class Factory extends ContractFactory<AddInstance, AddTypes.Fields> {
export const Add = new Factory(
Contract.fromJson(
AddContractJson,
"=8+4=1-1=2-1=1+3=2-2+6c=37+77e010a=1+1646450726976617465=152",
"6d87d293224fce4601a8e315e6a384aca46fdd1adab1402ffae8cc454b94a66e",
"=10-2+50=2-2+70=2-2+79=63+77e010a=1+1646450726976617465=152",
"9a4cf22e444db365cc62468b22db303401e6942409e193055e7f5f0318b389ca",
AllStructs
)
);
Expand Down Expand Up @@ -212,6 +250,11 @@ export class AddInstance extends ContractInstance {
): Promise<AddTypes.CallMethodResult<"add">> => {
return callMethod(Add, this, "add", params, getContractByCodeHash);
},
add2: async (
params: AddTypes.CallMethodParams<"add2">
): Promise<AddTypes.CallMethodResult<"add2">> => {
return callMethod(Add, this, "add2", params, getContractByCodeHash);
},
createSubContract: async (
params: AddTypes.CallMethodParams<"createSubContract">
): Promise<AddTypes.CallMethodResult<"createSubContract">> => {
Expand All @@ -238,6 +281,11 @@ export class AddInstance extends ContractInstance {
): Promise<AddTypes.SignExecuteMethodResult<"add">> => {
return signExecuteMethod(Add, this, "add", params);
},
add2: async (
params: AddTypes.SignExecuteMethodParams<"add2">
): Promise<AddTypes.SignExecuteMethodResult<"add2">> => {
return signExecuteMethod(Add, this, "add2", params);
},
createSubContract: async (
params: AddTypes.SignExecuteMethodParams<"createSubContract">
): Promise<AddTypes.SignExecuteMethodResult<"createSubContract">> => {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/Assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as AssertContractJson } from "../test/Assert.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace AssertTypes {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DebugContractJson } from "../test/Debug.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DebugTypes {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest1ContractJson } from "../nft/DeprecatedNFTTest1.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest1Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest2ContractJson } from "../nft/DeprecatedNFTTest2.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest2Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest3ContractJson } from "../nft/DeprecatedNFTTest3.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest3Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest4ContractJson } from "../nft/DeprecatedNFTTest4.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest4Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest5ContractJson } from "../nft/DeprecatedNFTTest5.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest5Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest6ContractJson } from "../nft/DeprecatedNFTTest6.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest6Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/DeprecatedNFTTest7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as DeprecatedNFTTest7ContractJson } from "../nft/DeprecatedNFTTest7.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace DeprecatedNFTTest7Types {
Expand Down
9 changes: 8 additions & 1 deletion artifacts/ts/FakeTokenTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
} from "@alephium/web3";
import { default as FakeTokenTestContractJson } from "../token/FakeTokenTest.ral.json";
import { getContractByCodeHash } from "./contracts";
import { Balances, MapValue, TokenBalance, AllStructs } from "./types";
import {
AddStruct1,
AddStruct2,
Balances,
MapValue,
TokenBalance,
AllStructs,
} from "./types";

// Custom types for the contract
export namespace FakeTokenTestTypes {
Expand Down
Loading

0 comments on commit 0415502

Please sign in to comment.