quantumcoin 7.0.2 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npmjs.yaml +22 -22
- package/.gitignore +15 -15
- package/LICENSE +21 -21
- package/README-SDK.md +756 -756
- package/README.md +165 -152
- package/SPEC.md +3845 -3845
- package/config.d.ts +50 -50
- package/config.js +115 -115
- package/examples/AllSolidityTypes.sol +184 -184
- package/examples/SimpleIERC20.sol +74 -74
- package/examples/events.js +41 -35
- package/examples/events.ts +35 -0
- package/examples/example-generator-sdk-js.js +100 -95
- package/examples/example-generator-sdk-js.ts +77 -0
- package/examples/example-generator-sdk-ts.js +100 -95
- package/examples/example-generator-sdk-ts.ts +77 -0
- package/examples/example.js +72 -61
- package/examples/example.ts +61 -0
- package/examples/offline-signing.js +79 -0
- package/examples/offline-signing.ts +66 -0
- package/examples/package-lock.json +48 -57
- package/examples/package.json +32 -16
- package/examples/read-operations.js +32 -27
- package/examples/read-operations.ts +31 -0
- package/examples/sdk-generator-erc20.inline.json +251 -251
- package/examples/solidity-types.ts +43 -43
- package/examples/wallet-offline.js +35 -29
- package/examples/wallet-offline.ts +34 -0
- package/generate-sdk.js +1824 -1383
- package/index.js +12 -12
- package/package.json +95 -75
- package/scripts/copy-declarations.js +31 -0
- package/scripts/run-all-one-by-one.js +151 -0
- package/src/abi/fragments.d.ts +42 -42
- package/src/abi/fragments.js +63 -63
- package/src/abi/index.d.ts +13 -13
- package/src/abi/index.js +9 -9
- package/src/abi/interface.d.ts +128 -132
- package/src/abi/interface.js +590 -590
- package/src/abi/js-abi-coder.d.ts +8 -0
- package/src/abi/js-abi-coder.js +474 -474
- package/src/constants.d.ts +66 -61
- package/src/constants.js +101 -94
- package/src/contract/contract-factory.d.ts +28 -28
- package/src/contract/contract-factory.js +105 -105
- package/src/contract/contract.d.ts +113 -105
- package/src/contract/contract.js +354 -312
- package/src/contract/index.d.ts +9 -9
- package/src/contract/index.js +9 -9
- package/src/errors/index.d.ts +92 -92
- package/src/errors/index.js +188 -188
- package/src/generator/index.d.ts +74 -0
- package/src/generator/index.js +1404 -1201
- package/src/index.d.ts +125 -127
- package/src/index.js +41 -41
- package/src/internal/hex.d.ts +61 -61
- package/src/internal/hex.js +144 -144
- package/src/providers/extra-providers.d.ts +139 -128
- package/src/providers/extra-providers.js +600 -575
- package/src/providers/index.d.ts +17 -16
- package/src/providers/index.js +10 -10
- package/src/providers/json-rpc-provider.d.ts +12 -12
- package/src/providers/json-rpc-provider.js +79 -79
- package/src/providers/provider.d.ts +207 -196
- package/src/providers/provider.js +392 -359
- package/src/types/index.d.ts +214 -462
- package/src/types/index.js +9 -9
- package/src/utils/address.d.ts +72 -72
- package/src/utils/address.js +181 -182
- package/src/utils/encoding.d.ts +120 -120
- package/src/utils/encoding.js +306 -306
- package/src/utils/hashing.d.ts +82 -76
- package/src/utils/hashing.js +313 -298
- package/src/utils/index.d.ts +65 -55
- package/src/utils/index.js +13 -13
- package/src/utils/result.d.ts +57 -57
- package/src/utils/result.js +128 -128
- package/src/utils/rlp.d.ts +12 -12
- package/src/utils/rlp.js +200 -200
- package/src/utils/units.d.ts +29 -29
- package/src/utils/units.js +107 -107
- package/src/wallet/index.d.ts +10 -10
- package/src/wallet/index.js +8 -8
- package/src/wallet/wallet.d.ts +160 -160
- package/src/wallet/wallet.js +483 -489
- package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
- package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
- package/test/e2e/all-solidity-types.fixtures.js +231 -231
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -361
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
- package/test/e2e/helpers.js +59 -47
- package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
- package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -144
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
- package/test/e2e/transactional.test.js +245 -191
- package/test/e2e/transactional.test.ts +208 -0
- package/test/e2e/typed-generator.e2e.test.js +407 -402
- package/test/e2e/typed-generator.e2e.test.ts +337 -0
- package/test/fixtures/ConstructorParam.sol +23 -23
- package/test/fixtures/MultiContracts.sol +37 -37
- package/test/fixtures/SimpleStorage.sol +18 -18
- package/test/fixtures/StakingContract.abi.json +1 -1
- package/test/integration/ipc-provider.test.js +49 -44
- package/test/integration/ipc-provider.test.ts +44 -0
- package/test/integration/provider.test.js +88 -72
- package/test/integration/provider.test.ts +85 -0
- package/test/integration/ws-provider.test.js +41 -33
- package/test/integration/ws-provider.test.ts +38 -0
- package/test/security/malformed-input.test.js +37 -31
- package/test/security/malformed-input.test.ts +35 -0
- package/test/unit/_encrypted-output.txt +6 -0
- package/test/unit/_log-encrypted-jsons.js +45 -0
- package/test/unit/_write-keystore-fixture.js +16 -0
- package/test/unit/abi-interface.test.js +103 -98
- package/test/unit/abi-interface.test.ts +102 -0
- package/test/unit/address-wallet.test.js +355 -257
- package/test/unit/address-wallet.test.ts +342 -0
- package/test/unit/browser-provider.test.js +85 -82
- package/test/unit/browser-provider.test.ts +79 -0
- package/test/unit/contract.test.js +85 -82
- package/test/unit/contract.test.ts +83 -0
- package/test/unit/encoding-units-rlp.test.js +92 -89
- package/test/unit/encoding-units-rlp.test.ts +91 -0
- package/test/unit/errors.test.js +77 -74
- package/test/unit/errors.test.ts +76 -0
- package/test/unit/filter-by-blockhash.test.js +55 -52
- package/test/unit/filter-by-blockhash.test.ts +54 -0
- package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
- package/test/unit/generate-contract-cli.test.js +42 -39
- package/test/unit/generate-contract-cli.test.ts +41 -0
- package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
- package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
- package/test/unit/generator.test.js +102 -98
- package/test/unit/generator.test.ts +101 -0
- package/test/unit/hashing.test.js +68 -54
- package/test/unit/hashing.test.ts +67 -0
- package/test/unit/init.test.js +39 -36
- package/test/unit/init.test.ts +38 -0
- package/test/unit/interface.test.js +56 -53
- package/test/unit/interface.test.ts +54 -0
- package/test/unit/internal-hex.test.js +50 -47
- package/test/unit/internal-hex.test.ts +49 -0
- package/test/unit/populate-transaction.test.js +65 -0
- package/test/unit/populate-transaction.test.ts +64 -0
- package/test/unit/providers.test.js +200 -144
- package/test/unit/providers.test.ts +196 -0
- package/test/unit/result.test.js +80 -77
- package/test/unit/result.test.ts +79 -0
- package/test/unit/solidity-types.test.js +49 -46
- package/test/unit/solidity-types.test.ts +39 -0
- package/test/unit/utils.test.js +57 -54
- package/test/unit/utils.test.ts +56 -0
- package/test/verbose-logger.js +74 -0
- package/tsconfig.build.json +14 -0
package/src/constants.d.ts
CHANGED
|
@@ -1,61 +1,66 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The current version of the QuantumCoin.js library.
|
|
3
|
-
* @type {string}
|
|
4
|
-
*/
|
|
5
|
-
export const version: string;
|
|
6
|
-
/**
|
|
7
|
-
* The zero address (32 bytes).
|
|
8
|
-
* @type {string}
|
|
9
|
-
*/
|
|
10
|
-
export const ZeroAddress: string;
|
|
11
|
-
/**
|
|
12
|
-
* The zero hash (32 bytes).
|
|
13
|
-
* @type {string}
|
|
14
|
-
*/
|
|
15
|
-
export const ZeroHash: string;
|
|
16
|
-
/**
|
|
17
|
-
* The maximum value for a uint256.
|
|
18
|
-
* @type {bigint}
|
|
19
|
-
*/
|
|
20
|
-
export const MaxUint256: bigint;
|
|
21
|
-
/**
|
|
22
|
-
* The maximum value for a uint160.
|
|
23
|
-
* @type {bigint}
|
|
24
|
-
*/
|
|
25
|
-
export const MaxUint160: bigint;
|
|
26
|
-
/**
|
|
27
|
-
* The minimum value for an int256.
|
|
28
|
-
* @type {bigint}
|
|
29
|
-
*/
|
|
30
|
-
export const MinInt256: bigint;
|
|
31
|
-
/**
|
|
32
|
-
* The maximum value for an int256.
|
|
33
|
-
* @type {bigint}
|
|
34
|
-
*/
|
|
35
|
-
export const MaxInt256: bigint;
|
|
36
|
-
/**
|
|
37
|
-
* Error code for numeric faults.
|
|
38
|
-
* @type {string}
|
|
39
|
-
*/
|
|
40
|
-
export const NumericFault: string;
|
|
41
|
-
/**
|
|
42
|
-
* Error code for numeric faults (alias).
|
|
43
|
-
* @type {string}
|
|
44
|
-
*/
|
|
45
|
-
export const NumericFaultCode: string;
|
|
46
|
-
/**
|
|
47
|
-
* Wei per coin (1e18).
|
|
48
|
-
* @type {bigint}
|
|
49
|
-
*/
|
|
50
|
-
export const WeiPerEther: bigint;
|
|
51
|
-
/**
|
|
52
|
-
* Currency symbol (compat with ethers.js v6).
|
|
53
|
-
* @type {string}
|
|
54
|
-
*/
|
|
55
|
-
export const EtherSymbol: string;
|
|
56
|
-
/**
|
|
57
|
-
* BigNumber constant (exported as `N` in ethers.js v6).
|
|
58
|
-
* In QuantumCoin.js, this is a bigint constant.
|
|
59
|
-
* @type {bigint}
|
|
60
|
-
*/
|
|
61
|
-
export const N: bigint;
|
|
1
|
+
/**
|
|
2
|
+
* The current version of the QuantumCoin.js library.
|
|
3
|
+
* @type {string}
|
|
4
|
+
*/
|
|
5
|
+
export const version: string;
|
|
6
|
+
/**
|
|
7
|
+
* The zero address (32 bytes).
|
|
8
|
+
* @type {string}
|
|
9
|
+
*/
|
|
10
|
+
export const ZeroAddress: string;
|
|
11
|
+
/**
|
|
12
|
+
* The zero hash (32 bytes).
|
|
13
|
+
* @type {string}
|
|
14
|
+
*/
|
|
15
|
+
export const ZeroHash: string;
|
|
16
|
+
/**
|
|
17
|
+
* The maximum value for a uint256.
|
|
18
|
+
* @type {bigint}
|
|
19
|
+
*/
|
|
20
|
+
export const MaxUint256: bigint;
|
|
21
|
+
/**
|
|
22
|
+
* The maximum value for a uint160.
|
|
23
|
+
* @type {bigint}
|
|
24
|
+
*/
|
|
25
|
+
export const MaxUint160: bigint;
|
|
26
|
+
/**
|
|
27
|
+
* The minimum value for an int256.
|
|
28
|
+
* @type {bigint}
|
|
29
|
+
*/
|
|
30
|
+
export const MinInt256: bigint;
|
|
31
|
+
/**
|
|
32
|
+
* The maximum value for an int256.
|
|
33
|
+
* @type {bigint}
|
|
34
|
+
*/
|
|
35
|
+
export const MaxInt256: bigint;
|
|
36
|
+
/**
|
|
37
|
+
* Error code for numeric faults.
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
export const NumericFault: string;
|
|
41
|
+
/**
|
|
42
|
+
* Error code for numeric faults (alias).
|
|
43
|
+
* @type {string}
|
|
44
|
+
*/
|
|
45
|
+
export const NumericFaultCode: string;
|
|
46
|
+
/**
|
|
47
|
+
* Wei per coin (1e18).
|
|
48
|
+
* @type {bigint}
|
|
49
|
+
*/
|
|
50
|
+
export const WeiPerEther: bigint;
|
|
51
|
+
/**
|
|
52
|
+
* Currency symbol (compat with ethers.js v6).
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
55
|
+
export const EtherSymbol: string;
|
|
56
|
+
/**
|
|
57
|
+
* BigNumber constant (exported as `N` in ethers.js v6).
|
|
58
|
+
* In QuantumCoin.js, this is a bigint constant.
|
|
59
|
+
* @type {bigint}
|
|
60
|
+
*/
|
|
61
|
+
export const N: bigint;
|
|
62
|
+
/**
|
|
63
|
+
* EIP-191 personal sign message prefix (ethers.js compatible).
|
|
64
|
+
* @type {string}
|
|
65
|
+
*/
|
|
66
|
+
export const MessagePrefix: string;
|
package/src/constants.js
CHANGED
|
@@ -1,94 +1,101 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Public constants matching ethers.js v6 naming.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const pkg = require("../package.json");
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The current version of the QuantumCoin.js library.
|
|
9
|
-
* @type {string}
|
|
10
|
-
*/
|
|
11
|
-
const version = pkg.version || "0.0.0";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The zero address (32 bytes).
|
|
15
|
-
* @type {string}
|
|
16
|
-
*/
|
|
17
|
-
const ZeroAddress = "0x" + "00".repeat(32);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The zero hash (32 bytes).
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
const ZeroHash = "0x" + "00".repeat(32);
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The maximum value for a uint256.
|
|
27
|
-
* @type {bigint}
|
|
28
|
-
*/
|
|
29
|
-
const MaxUint256 = (2n ** 256n) - 1n;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The maximum value for a uint160.
|
|
33
|
-
* @type {bigint}
|
|
34
|
-
*/
|
|
35
|
-
const MaxUint160 = (2n ** 160n) - 1n;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The minimum value for an int256.
|
|
39
|
-
* @type {bigint}
|
|
40
|
-
*/
|
|
41
|
-
const MinInt256 = -(2n ** 255n);
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The maximum value for an int256.
|
|
45
|
-
* @type {bigint}
|
|
46
|
-
*/
|
|
47
|
-
const MaxInt256 = (2n ** 255n) - 1n;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Error code for numeric faults.
|
|
51
|
-
* @type {string}
|
|
52
|
-
*/
|
|
53
|
-
const NumericFault = "NUMERIC_FAULT";
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Error code for numeric faults (alias).
|
|
57
|
-
* @type {string}
|
|
58
|
-
*/
|
|
59
|
-
const NumericFaultCode = "NUMERIC_FAULT";
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Wei per coin (1e18).
|
|
63
|
-
* @type {bigint}
|
|
64
|
-
*/
|
|
65
|
-
const WeiPerEther = 1000000000000000000n;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Currency symbol (compat with ethers.js v6).
|
|
69
|
-
* @type {string}
|
|
70
|
-
*/
|
|
71
|
-
const EtherSymbol = "Ξ";
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* BigNumber constant (exported as `N` in ethers.js v6).
|
|
75
|
-
* In QuantumCoin.js, this is a bigint constant.
|
|
76
|
-
* @type {bigint}
|
|
77
|
-
*/
|
|
78
|
-
const N = 0n;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public constants matching ethers.js v6 naming.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const pkg = require("../package.json");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The current version of the QuantumCoin.js library.
|
|
9
|
+
* @type {string}
|
|
10
|
+
*/
|
|
11
|
+
const version = pkg.version || "0.0.0";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The zero address (32 bytes).
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
const ZeroAddress = "0x" + "00".repeat(32);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The zero hash (32 bytes).
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
const ZeroHash = "0x" + "00".repeat(32);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The maximum value for a uint256.
|
|
27
|
+
* @type {bigint}
|
|
28
|
+
*/
|
|
29
|
+
const MaxUint256 = (2n ** 256n) - 1n;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The maximum value for a uint160.
|
|
33
|
+
* @type {bigint}
|
|
34
|
+
*/
|
|
35
|
+
const MaxUint160 = (2n ** 160n) - 1n;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The minimum value for an int256.
|
|
39
|
+
* @type {bigint}
|
|
40
|
+
*/
|
|
41
|
+
const MinInt256 = -(2n ** 255n);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The maximum value for an int256.
|
|
45
|
+
* @type {bigint}
|
|
46
|
+
*/
|
|
47
|
+
const MaxInt256 = (2n ** 255n) - 1n;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Error code for numeric faults.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
const NumericFault = "NUMERIC_FAULT";
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Error code for numeric faults (alias).
|
|
57
|
+
* @type {string}
|
|
58
|
+
*/
|
|
59
|
+
const NumericFaultCode = "NUMERIC_FAULT";
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Wei per coin (1e18).
|
|
63
|
+
* @type {bigint}
|
|
64
|
+
*/
|
|
65
|
+
const WeiPerEther = 1000000000000000000n;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Currency symbol (compat with ethers.js v6).
|
|
69
|
+
* @type {string}
|
|
70
|
+
*/
|
|
71
|
+
const EtherSymbol = "Ξ";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* BigNumber constant (exported as `N` in ethers.js v6).
|
|
75
|
+
* In QuantumCoin.js, this is a bigint constant.
|
|
76
|
+
* @type {bigint}
|
|
77
|
+
*/
|
|
78
|
+
const N = 0n;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* EIP-191 personal sign message prefix (ethers.js compatible).
|
|
82
|
+
* @type {string}
|
|
83
|
+
*/
|
|
84
|
+
const MessagePrefix = "\x19Ethereum Signed Message:\n";
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
version,
|
|
88
|
+
ZeroAddress,
|
|
89
|
+
ZeroHash,
|
|
90
|
+
MaxUint256,
|
|
91
|
+
MaxUint160,
|
|
92
|
+
MinInt256,
|
|
93
|
+
MaxInt256,
|
|
94
|
+
NumericFault,
|
|
95
|
+
NumericFaultCode,
|
|
96
|
+
WeiPerEther,
|
|
97
|
+
EtherSymbol,
|
|
98
|
+
N,
|
|
99
|
+
MessagePrefix,
|
|
100
|
+
};
|
|
101
|
+
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
export class ContractFactory {
|
|
2
|
-
/**
|
|
3
|
-
* @param {any[]|Interface} abi
|
|
4
|
-
* @param {string} bytecode
|
|
5
|
-
* @param {any} signer
|
|
6
|
-
*/
|
|
7
|
-
constructor(abi: any[] | Interface, bytecode: string, signer: any);
|
|
8
|
-
abi: any;
|
|
9
|
-
interface: Interface;
|
|
10
|
-
bytecode: string;
|
|
11
|
-
signer: any;
|
|
12
|
-
/**
|
|
13
|
-
* Compute deploy transaction request.
|
|
14
|
-
* @param {...any} args
|
|
15
|
-
* @returns {import("../providers/provider").TransactionRequest}
|
|
16
|
-
*/
|
|
17
|
-
getDeployTransaction(...args: any[]): import("../providers/provider").TransactionRequest;
|
|
18
|
-
/**
|
|
19
|
-
* Deploy contract.
|
|
20
|
-
* @param {...any} args
|
|
21
|
-
* @returns {Promise<Contract>}
|
|
22
|
-
*/
|
|
23
|
-
deploy(...args: any[]): Promise<Contract>;
|
|
24
|
-
attach(address:
|
|
25
|
-
connect(signer: any): ContractFactory;
|
|
26
|
-
}
|
|
27
|
-
import { Interface } from "../abi/interface";
|
|
28
|
-
import { Contract } from "./contract";
|
|
1
|
+
export class ContractFactory {
|
|
2
|
+
/**
|
|
3
|
+
* @param {any[]|Interface} abi
|
|
4
|
+
* @param {string} bytecode
|
|
5
|
+
* @param {any} signer
|
|
6
|
+
*/
|
|
7
|
+
constructor(abi: any[] | Interface, bytecode: string, signer: any);
|
|
8
|
+
abi: any;
|
|
9
|
+
interface: Interface;
|
|
10
|
+
bytecode: string;
|
|
11
|
+
signer: any;
|
|
12
|
+
/**
|
|
13
|
+
* Compute deploy transaction request.
|
|
14
|
+
* @param {...any} args
|
|
15
|
+
* @returns {import("../providers/provider").TransactionRequest}
|
|
16
|
+
*/
|
|
17
|
+
getDeployTransaction(...args: any[]): import("../providers/provider").TransactionRequest;
|
|
18
|
+
/**
|
|
19
|
+
* Deploy contract.
|
|
20
|
+
* @param {...any} args
|
|
21
|
+
* @returns {Promise<Contract>}
|
|
22
|
+
*/
|
|
23
|
+
deploy(...args: any[]): Promise<Contract>;
|
|
24
|
+
attach(address: any): Contract;
|
|
25
|
+
connect(signer: any): ContractFactory;
|
|
26
|
+
}
|
|
27
|
+
import { Interface } from "../abi/interface";
|
|
28
|
+
import { Contract } from "./contract";
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview ContractFactory implementation.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const qcsdk = require("quantum-coin-js-sdk");
|
|
6
|
-
const { Interface } = require("../abi/interface");
|
|
7
|
-
const jsAbi = require("../abi/js-abi-coder");
|
|
8
|
-
const { Contract } = require("./contract");
|
|
9
|
-
const { makeError, assertArgument } = require("../errors");
|
|
10
|
-
const { normalizeHex, strip0x, bytesToHex } = require("../internal/hex");
|
|
11
|
-
const { getCreateAddress } = require("../utils/address");
|
|
12
|
-
|
|
13
|
-
function _requireInitialized() {
|
|
14
|
-
// eslint-disable-next-line global-require
|
|
15
|
-
const { isInitialized } = require("../../config");
|
|
16
|
-
if (!isInitialized()) {
|
|
17
|
-
throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", { operation: "contract-factory" });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class ContractFactory {
|
|
22
|
-
/**
|
|
23
|
-
* @param {any[]|Interface} abi
|
|
24
|
-
* @param {string} bytecode
|
|
25
|
-
* @param {any} signer
|
|
26
|
-
*/
|
|
27
|
-
constructor(abi, bytecode, signer) {
|
|
28
|
-
_requireInitialized();
|
|
29
|
-
this.abi = abi instanceof Interface ? JSON.parse(abi.formatJson()) : abi;
|
|
30
|
-
this.interface = abi instanceof Interface ? abi : new Interface(abi);
|
|
31
|
-
this.bytecode = normalizeHex(bytecode);
|
|
32
|
-
this.signer = signer;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Compute deploy transaction request.
|
|
37
|
-
* @param {...any} args
|
|
38
|
-
* @returns {import("../providers/provider").TransactionRequest}
|
|
39
|
-
*/
|
|
40
|
-
getDeployTransaction(...args) {
|
|
41
|
-
_requireInitialized();
|
|
42
|
-
const ctor = this.interface.getConstructor();
|
|
43
|
-
const ctorInputs = ctor ? ctor.inputs : [];
|
|
44
|
-
|
|
45
|
-
// If the constructor includes tuples/structs, use the JS ABI encoder fallback.
|
|
46
|
-
if (jsAbi.hasTuple(ctorInputs)) {
|
|
47
|
-
const enc = jsAbi.encodeTupleLike(ctorInputs, args);
|
|
48
|
-
const data = normalizeHex(this.bytecode + strip0x(bytesToHex(enc)));
|
|
49
|
-
return { to: null, data, value: 0n };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const normArgs = this.interface._qcsdkNormalizeValues(ctorInputs, args);
|
|
53
|
-
const res = qcsdk.packCreateContractData(this.interface._qcsdkFormatJson(), this.bytecode, ...normArgs);
|
|
54
|
-
if (!res || typeof res.error !== "string") throw makeError("packCreateContractData failed", "UNKNOWN_ERROR", {});
|
|
55
|
-
if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "packCreateContractData" });
|
|
56
|
-
return { to: null, data: normalizeHex(res.result), value: 0n };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Deploy contract.
|
|
61
|
-
* @param {...any} args
|
|
62
|
-
* @returns {Promise<Contract>}
|
|
63
|
-
*/
|
|
64
|
-
async deploy(...args) {
|
|
65
|
-
if (!this.signer) throw makeError("missing signer", "UNKNOWN_ERROR", { operation: "deploy" });
|
|
66
|
-
const tx = this.getDeployTransaction(...args);
|
|
67
|
-
|
|
68
|
-
// Compute deterministic address from (from, nonce)
|
|
69
|
-
const from =
|
|
70
|
-
typeof this.signer.getAddress === "function"
|
|
71
|
-
? await this.signer.getAddress()
|
|
72
|
-
: this.signer.address;
|
|
73
|
-
if (typeof from !== "string") throw makeError("unable to resolve deployer address", "UNKNOWN_ERROR", {});
|
|
74
|
-
|
|
75
|
-
const provider = this.signer.provider || null;
|
|
76
|
-
if (!provider || typeof provider.getTransactionCount !== "function") {
|
|
77
|
-
throw makeError("missing provider for deploy", "UNKNOWN_ERROR", { operation: "deploy" });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Prefer pending nonce to avoid collisions with in-flight transactions.
|
|
81
|
-
let nonce;
|
|
82
|
-
try {
|
|
83
|
-
nonce = await provider.getTransactionCount(from, "pending");
|
|
84
|
-
} catch {
|
|
85
|
-
nonce = await provider.getTransactionCount(from, "latest");
|
|
86
|
-
}
|
|
87
|
-
const address = getCreateAddress({ from, nonce });
|
|
88
|
-
|
|
89
|
-
const resp = await this.signer.sendTransaction({ ...tx, nonce });
|
|
90
|
-
const contract = new Contract(address, this.interface, this.signer, this.bytecode);
|
|
91
|
-
contract._deployTx = resp;
|
|
92
|
-
return contract;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
attach(address) {
|
|
96
|
-
return new Contract(address, this.interface, this.signer, this.bytecode);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
connect(signer) {
|
|
100
|
-
return new ContractFactory(this.interface, this.bytecode, signer);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = { ContractFactory };
|
|
105
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ContractFactory implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const qcsdk = require("quantum-coin-js-sdk");
|
|
6
|
+
const { Interface } = require("../abi/interface");
|
|
7
|
+
const jsAbi = require("../abi/js-abi-coder");
|
|
8
|
+
const { Contract } = require("./contract");
|
|
9
|
+
const { makeError, assertArgument } = require("../errors");
|
|
10
|
+
const { normalizeHex, strip0x, bytesToHex } = require("../internal/hex");
|
|
11
|
+
const { getCreateAddress } = require("../utils/address");
|
|
12
|
+
|
|
13
|
+
function _requireInitialized() {
|
|
14
|
+
// eslint-disable-next-line global-require
|
|
15
|
+
const { isInitialized } = require("../../config");
|
|
16
|
+
if (!isInitialized()) {
|
|
17
|
+
throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", { operation: "contract-factory" });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class ContractFactory {
|
|
22
|
+
/**
|
|
23
|
+
* @param {any[]|Interface} abi
|
|
24
|
+
* @param {string} bytecode
|
|
25
|
+
* @param {any} signer
|
|
26
|
+
*/
|
|
27
|
+
constructor(abi, bytecode, signer) {
|
|
28
|
+
_requireInitialized();
|
|
29
|
+
this.abi = abi instanceof Interface ? JSON.parse(abi.formatJson()) : abi;
|
|
30
|
+
this.interface = abi instanceof Interface ? abi : new Interface(abi);
|
|
31
|
+
this.bytecode = normalizeHex(bytecode);
|
|
32
|
+
this.signer = signer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Compute deploy transaction request.
|
|
37
|
+
* @param {...any} args
|
|
38
|
+
* @returns {import("../providers/provider").TransactionRequest}
|
|
39
|
+
*/
|
|
40
|
+
getDeployTransaction(...args) {
|
|
41
|
+
_requireInitialized();
|
|
42
|
+
const ctor = this.interface.getConstructor();
|
|
43
|
+
const ctorInputs = ctor ? ctor.inputs : [];
|
|
44
|
+
|
|
45
|
+
// If the constructor includes tuples/structs, use the JS ABI encoder fallback.
|
|
46
|
+
if (jsAbi.hasTuple(ctorInputs)) {
|
|
47
|
+
const enc = jsAbi.encodeTupleLike(ctorInputs, args);
|
|
48
|
+
const data = normalizeHex(this.bytecode + strip0x(bytesToHex(enc)));
|
|
49
|
+
return { to: null, data, value: 0n };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const normArgs = this.interface._qcsdkNormalizeValues(ctorInputs, args);
|
|
53
|
+
const res = qcsdk.packCreateContractData(this.interface._qcsdkFormatJson(), this.bytecode, ...normArgs);
|
|
54
|
+
if (!res || typeof res.error !== "string") throw makeError("packCreateContractData failed", "UNKNOWN_ERROR", {});
|
|
55
|
+
if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "packCreateContractData" });
|
|
56
|
+
return { to: null, data: normalizeHex(res.result), value: 0n };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Deploy contract.
|
|
61
|
+
* @param {...any} args
|
|
62
|
+
* @returns {Promise<Contract>}
|
|
63
|
+
*/
|
|
64
|
+
async deploy(...args) {
|
|
65
|
+
if (!this.signer) throw makeError("missing signer", "UNKNOWN_ERROR", { operation: "deploy" });
|
|
66
|
+
const tx = this.getDeployTransaction(...args);
|
|
67
|
+
|
|
68
|
+
// Compute deterministic address from (from, nonce)
|
|
69
|
+
const from =
|
|
70
|
+
typeof this.signer.getAddress === "function"
|
|
71
|
+
? await this.signer.getAddress()
|
|
72
|
+
: this.signer.address;
|
|
73
|
+
if (typeof from !== "string") throw makeError("unable to resolve deployer address", "UNKNOWN_ERROR", {});
|
|
74
|
+
|
|
75
|
+
const provider = this.signer.provider || null;
|
|
76
|
+
if (!provider || typeof provider.getTransactionCount !== "function") {
|
|
77
|
+
throw makeError("missing provider for deploy", "UNKNOWN_ERROR", { operation: "deploy" });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Prefer pending nonce to avoid collisions with in-flight transactions.
|
|
81
|
+
let nonce;
|
|
82
|
+
try {
|
|
83
|
+
nonce = await provider.getTransactionCount(from, "pending");
|
|
84
|
+
} catch {
|
|
85
|
+
nonce = await provider.getTransactionCount(from, "latest");
|
|
86
|
+
}
|
|
87
|
+
const address = getCreateAddress({ from, nonce });
|
|
88
|
+
|
|
89
|
+
const resp = await this.signer.sendTransaction({ ...tx, nonce });
|
|
90
|
+
const contract = new Contract(address, this.interface, this.signer, this.bytecode);
|
|
91
|
+
contract._deployTx = resp;
|
|
92
|
+
return contract;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
attach(address) {
|
|
96
|
+
return new Contract(address, this.interface, this.signer, this.bytecode);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
connect(signer) {
|
|
100
|
+
return new ContractFactory(this.interface, this.bytecode, signer);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { ContractFactory };
|
|
105
|
+
|