Skip to content

Commit

Permalink
Generate the encodeFields function for the contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Apr 25, 2024
1 parent 3151e35 commit 8fb0645
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 41 deletions.
10 changes: 10 additions & 0 deletions artifacts/ts/Add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as AddContractJson } from "../add/Add.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -63,6 +65,14 @@ export namespace AddTypes {
}

class Factory extends ContractFactory<AddInstance, AddTypes.Fields> {
encodeFields(fields: AddTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as AddTypes.Fields;
}
Expand Down
6 changes: 6 additions & 0 deletions artifacts/ts/Assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as AssertContractJson } from "../test/Assert.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand All @@ -36,6 +38,10 @@ export namespace AssertTypes {
}

class Factory extends ContractFactory<AssertInstance, {}> {
encodeFields() {
return encodeContractFields({}, this.contract.fieldsSig, AllStructs);
}

consts = {
Error: BigInt(3),
A: BigInt(-3),
Expand Down
6 changes: 6 additions & 0 deletions artifacts/ts/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DebugContractJson } from "../test/Debug.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand All @@ -36,6 +38,10 @@ export namespace DebugTypes {
}

class Factory extends ContractFactory<DebugInstance, {}> {
encodeFields() {
return encodeContractFields({}, this.contract.fieldsSig, AllStructs);
}

at(address: string): DebugInstance {
return new DebugInstance(address);
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest1ContractJson } from "../nft/DeprecatedNFTTest1.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -63,6 +65,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest1Instance,
DeprecatedNFTTest1Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest1Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest1Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest2ContractJson } from "../nft/DeprecatedNFTTest2.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -67,6 +69,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest2Instance,
DeprecatedNFTTest2Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest2Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest2Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest3ContractJson } from "../nft/DeprecatedNFTTest3.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -63,6 +65,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest3Instance,
DeprecatedNFTTest3Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest3Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest3Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest4ContractJson } from "../nft/DeprecatedNFTTest4.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -67,6 +69,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest4Instance,
DeprecatedNFTTest4Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest4Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest4Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest5ContractJson } from "../nft/DeprecatedNFTTest5.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -67,6 +69,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest5Instance,
DeprecatedNFTTest5Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest5Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest5Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest6ContractJson } from "../nft/DeprecatedNFTTest6.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -67,6 +69,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest6Instance,
DeprecatedNFTTest6Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest6Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest6Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/DeprecatedNFTTest7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as DeprecatedNFTTest7ContractJson } from "../nft/DeprecatedNFTTest7.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -67,6 +69,14 @@ class Factory extends ContractFactory<
DeprecatedNFTTest7Instance,
DeprecatedNFTTest7Types.Fields
> {
encodeFields(fields: DeprecatedNFTTest7Types.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as DeprecatedNFTTest7Types.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/FakeTokenTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as FakeTokenTestContractJson } from "../token/FakeTokenTest.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -74,6 +76,14 @@ class Factory extends ContractFactory<
FakeTokenTestInstance,
FakeTokenTestTypes.Fields
> {
encodeFields(fields: FakeTokenTestTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as FakeTokenTestTypes.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/Greeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as GreeterContractJson } from "../greeter/Greeter.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -67,6 +69,14 @@ export namespace GreeterTypes {
}

class Factory extends ContractFactory<GreeterInstance, GreeterTypes.Fields> {
encodeFields(fields: GreeterTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as GreeterTypes.Fields;
}
Expand Down
6 changes: 6 additions & 0 deletions artifacts/ts/MapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as MapTestContractJson } from "../test/MapTest.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -59,6 +61,10 @@ export namespace MapTestTypes {
}

class Factory extends ContractFactory<MapTestInstance, {}> {
encodeFields() {
return encodeContractFields({}, this.contract.fieldsSig, AllStructs);
}

at(address: string): MapTestInstance {
return new MapTestInstance(address);
}
Expand Down
6 changes: 6 additions & 0 deletions artifacts/ts/MetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as MetaDataContractJson } from "../test/MetaData.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand All @@ -36,6 +38,10 @@ export namespace MetaDataTypes {
}

class Factory extends ContractFactory<MetaDataInstance, {}> {
encodeFields() {
return encodeContractFields({}, this.contract.fieldsSig, AllStructs);
}

at(address: string): MetaDataInstance {
return new MetaDataInstance(address);
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/NFTCollectionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as NFTCollectionTestContractJson } from "../nft/NFTCollectionTest.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -76,6 +78,14 @@ class Factory extends ContractFactory<
NFTCollectionTestInstance,
NFTCollectionTestTypes.Fields
> {
encodeFields(fields: NFTCollectionTestTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as NFTCollectionTestTypes.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/NFTCollectionWithRoyaltyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as NFTCollectionWithRoyaltyTestContractJson } from "../nft/NFTCollectionWithRoyaltyTest.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -82,6 +84,14 @@ class Factory extends ContractFactory<
NFTCollectionWithRoyaltyTestInstance,
NFTCollectionWithRoyaltyTestTypes.Fields
> {
encodeFields(fields: NFTCollectionWithRoyaltyTestTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as NFTCollectionWithRoyaltyTestTypes.Fields;
}
Expand Down
10 changes: 10 additions & 0 deletions artifacts/ts/NFTTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as NFTTestContractJson } from "../nft/NFTTest.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -65,6 +67,14 @@ export namespace NFTTestTypes {
}

class Factory extends ContractFactory<NFTTestInstance, NFTTestTypes.Fields> {
encodeFields(fields: NFTTestTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
AllStructs
);
}

getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as NFTTestTypes.Fields;
}
Expand Down
Loading

0 comments on commit 8fb0645

Please sign in to comment.