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
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.7.6;
|
|
3
|
-
pragma experimental ABIEncoderV2;
|
|
4
|
-
|
|
5
|
-
/// @title AllSolidityTypes
|
|
6
|
-
/// @notice A Solidity 0.7.6 contract that exercises a wide surface of ABI-encodable types.
|
|
7
|
-
/// @dev
|
|
8
|
-
/// - Includes: bool, all int/uint widths, address/address payable, string, bytes, bytes1..bytes32
|
|
9
|
-
/// - Includes: enums, nested structs, fixed/dynamic arrays, arrays of structs, structs of structs
|
|
10
|
-
/// - Excludes: fixed-point types and function types (by request)
|
|
11
|
-
/// - Note: mappings are not ABI-encodable, so they are shown only as a storage type.
|
|
12
|
-
contract AllSolidityTypes {
|
|
13
|
-
enum Choice { None, One, Two }
|
|
14
|
-
|
|
15
|
-
// Mapping example (not ABI-encodable as param/return)
|
|
16
|
-
mapping(address => uint256) private _balances;
|
|
17
|
-
|
|
18
|
-
// --------------------------------------------------------------------------
|
|
19
|
-
// All integer widths
|
|
20
|
-
// --------------------------------------------------------------------------
|
|
21
|
-
struct AllUints {
|
|
22
|
-
uint8 u8; uint16 u16; uint24 u24; uint32 u32; uint40 u40; uint48 u48; uint56 u56; uint64 u64;
|
|
23
|
-
uint72 u72; uint80 u80; uint88 u88; uint96 u96; uint104 u104; uint112 u112; uint120 u120; uint128 u128;
|
|
24
|
-
uint136 u136; uint144 u144; uint152 u152; uint160 u160; uint168 u168; uint176 u176; uint184 u184; uint192 u192;
|
|
25
|
-
uint200 u200; uint208 u208; uint216 u216; uint224 u224; uint232 u232; uint240 u240; uint248 u248; uint256 u256;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
struct AllInts {
|
|
29
|
-
int8 i8; int16 i16; int24 i24; int32 i32; int40 i40; int48 i48; int56 i56; int64 i64;
|
|
30
|
-
int72 i72; int80 i80; int88 i88; int96 i96; int104 i104; int112 i112; int120 i120; int128 i128;
|
|
31
|
-
int136 i136; int144 i144; int152 i152; int160 i160; int168 i168; int176 i176; int184 i184; int192 i192;
|
|
32
|
-
int200 i200; int208 i208; int216 i216; int224 i224; int232 i232; int240 i240; int248 i248; int256 i256;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// --------------------------------------------------------------------------
|
|
36
|
-
// All fixed-size bytes
|
|
37
|
-
// --------------------------------------------------------------------------
|
|
38
|
-
struct AllFixedBytes {
|
|
39
|
-
bytes1 b1; bytes2 b2; bytes3 b3; bytes4 b4; bytes5 b5; bytes6 b6; bytes7 b7; bytes8 b8;
|
|
40
|
-
bytes9 b9; bytes10 b10; bytes11 b11; bytes12 b12; bytes13 b13; bytes14 b14; bytes15 b15; bytes16 b16;
|
|
41
|
-
bytes17 b17; bytes18 b18; bytes19 b19; bytes20 b20; bytes21 b21; bytes22 b22; bytes23 b23; bytes24 b24;
|
|
42
|
-
bytes25 b25; bytes26 b26; bytes27 b27; bytes28 b28; bytes29 b29; bytes30 b30; bytes31 b31; bytes32 b32;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// --------------------------------------------------------------------------
|
|
46
|
-
// Misc ABI value types (plus arrays)
|
|
47
|
-
// --------------------------------------------------------------------------
|
|
48
|
-
struct AllMisc {
|
|
49
|
-
bool bo;
|
|
50
|
-
address addr;
|
|
51
|
-
address payable payableAddr;
|
|
52
|
-
string str;
|
|
53
|
-
bytes dynBytes;
|
|
54
|
-
Choice choice;
|
|
55
|
-
// Arrays of elementary types
|
|
56
|
-
uint256[] u256s;
|
|
57
|
-
int256[] i256s;
|
|
58
|
-
bytes32[] b32s;
|
|
59
|
-
address[] addrs;
|
|
60
|
-
bool[] bools;
|
|
61
|
-
string[] strings;
|
|
62
|
-
bytes[] bytesArr;
|
|
63
|
-
// Fixed arrays
|
|
64
|
-
uint16[3] fixedU16;
|
|
65
|
-
bytes32[2] fixedB32;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Nested struct that contains structs and arrays of structs
|
|
69
|
-
struct Inner {
|
|
70
|
-
AllUints u;
|
|
71
|
-
AllInts i;
|
|
72
|
-
AllFixedBytes fb;
|
|
73
|
-
AllMisc misc;
|
|
74
|
-
// Array of structs
|
|
75
|
-
AllUints[] uStructs;
|
|
76
|
-
// Struct of structs
|
|
77
|
-
AllFixedBytes[2] fixedFb;
|
|
78
|
-
// Nested arrays
|
|
79
|
-
uint256[][] matrix;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
struct Outer {
|
|
83
|
-
Inner inner;
|
|
84
|
-
Inner[] inners; // dynamic array of structs
|
|
85
|
-
Inner[2] fixedInners; // fixed array of structs
|
|
86
|
-
bytes32[][] b32Matrix;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
AllUints private _storedU;
|
|
90
|
-
AllInts private _storedI;
|
|
91
|
-
AllFixedBytes private _storedFb;
|
|
92
|
-
AllMisc private _storedMisc;
|
|
93
|
-
|
|
94
|
-
/// @notice Constructor with multiple parameters (including structs and arrays).
|
|
95
|
-
constructor(
|
|
96
|
-
bool bo,
|
|
97
|
-
address payable payableAddr,
|
|
98
|
-
string memory str,
|
|
99
|
-
bytes memory dynBytes,
|
|
100
|
-
Choice choice,
|
|
101
|
-
AllUints memory u,
|
|
102
|
-
AllInts memory i,
|
|
103
|
-
AllFixedBytes memory fb,
|
|
104
|
-
AllMisc memory misc,
|
|
105
|
-
uint256[] memory seedU256s,
|
|
106
|
-
bytes32[2] memory seedB32
|
|
107
|
-
) {
|
|
108
|
-
_storedU = u;
|
|
109
|
-
_storedI = i;
|
|
110
|
-
_storedFb = fb;
|
|
111
|
-
|
|
112
|
-
// Store some misc fields (keep it simple; not all array fields are persisted).
|
|
113
|
-
_storedMisc.bo = bo;
|
|
114
|
-
_storedMisc.addr = msg.sender;
|
|
115
|
-
_storedMisc.payableAddr = payableAddr;
|
|
116
|
-
_storedMisc.str = str;
|
|
117
|
-
_storedMisc.dynBytes = dynBytes;
|
|
118
|
-
_storedMisc.choice = choice;
|
|
119
|
-
_storedMisc.u256s = seedU256s;
|
|
120
|
-
_storedMisc.fixedB32 = seedB32;
|
|
121
|
-
|
|
122
|
-
// Touch mapping to demonstrate mapping existence.
|
|
123
|
-
_balances[msg.sender] = seedU256s.length;
|
|
124
|
-
|
|
125
|
-
// Use "misc" parameter to avoid unused warnings and ensure ABIEncoderV2 path is exercised.
|
|
126
|
-
if (misc.fixedU16.length > 0) {
|
|
127
|
-
_balances[misc.addr] = uint256(misc.fixedU16[0]);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// --------------------------------------------------------------------------
|
|
132
|
-
// Echo / roundtrip helpers (ABI-encodable inputs and outputs)
|
|
133
|
-
// --------------------------------------------------------------------------
|
|
134
|
-
|
|
135
|
-
function echoAllUints(AllUints memory x) external pure returns (AllUints memory) { return x; }
|
|
136
|
-
function echoAllInts(AllInts memory x) external pure returns (AllInts memory) { return x; }
|
|
137
|
-
function echoAllFixedBytes(AllFixedBytes memory x) external pure returns (AllFixedBytes memory) { return x; }
|
|
138
|
-
function echoAllMisc(AllMisc memory x) external pure returns (AllMisc memory) { return x; }
|
|
139
|
-
|
|
140
|
-
function echoInner(Inner memory x) external pure returns (Inner memory) { return x; }
|
|
141
|
-
function echoOuter(Outer memory x) external pure returns (Outer memory) { return x; }
|
|
142
|
-
|
|
143
|
-
// Arrays of structs and nested arrays
|
|
144
|
-
function echoAllUintsArray(AllUints[] memory xs) external pure returns (AllUints[] memory) { return xs; }
|
|
145
|
-
function echoInnerArray(Inner[] memory xs) external pure returns (Inner[] memory) { return xs; }
|
|
146
|
-
function echoMatrix(uint256[][] memory m) external pure returns (uint256[][] memory) { return m; }
|
|
147
|
-
|
|
148
|
-
// Multiple input params + multiple return params
|
|
149
|
-
function multiReturn(
|
|
150
|
-
bool bo,
|
|
151
|
-
address addr,
|
|
152
|
-
bytes32 b32,
|
|
153
|
-
string memory s,
|
|
154
|
-
uint256 x,
|
|
155
|
-
AllUints memory u
|
|
156
|
-
)
|
|
157
|
-
external
|
|
158
|
-
pure
|
|
159
|
-
returns (
|
|
160
|
-
bool outBo,
|
|
161
|
-
address outAddr,
|
|
162
|
-
address payable outPayableAddr,
|
|
163
|
-
bytes32 outB32,
|
|
164
|
-
string memory outS,
|
|
165
|
-
uint256 outX,
|
|
166
|
-
AllUints memory outU
|
|
167
|
-
)
|
|
168
|
-
{
|
|
169
|
-
outBo = bo;
|
|
170
|
-
outAddr = addr;
|
|
171
|
-
outPayableAddr = payable(addr);
|
|
172
|
-
outB32 = b32;
|
|
173
|
-
outS = s;
|
|
174
|
-
outX = x;
|
|
175
|
-
outU = u;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Read-only getters to provide outputs without inputs
|
|
179
|
-
function getStoredUints() external view returns (AllUints memory) { return _storedU; }
|
|
180
|
-
function getStoredInts() external view returns (AllInts memory) { return _storedI; }
|
|
181
|
-
function getStoredFixedBytes() external view returns (AllFixedBytes memory) { return _storedFb; }
|
|
182
|
-
function getStoredMisc() external view returns (AllMisc memory) { return _storedMisc; }
|
|
183
|
-
}
|
|
184
|
-
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.7.6;
|
|
3
|
+
pragma experimental ABIEncoderV2;
|
|
4
|
+
|
|
5
|
+
/// @title AllSolidityTypes
|
|
6
|
+
/// @notice A Solidity 0.7.6 contract that exercises a wide surface of ABI-encodable types.
|
|
7
|
+
/// @dev
|
|
8
|
+
/// - Includes: bool, all int/uint widths, address/address payable, string, bytes, bytes1..bytes32
|
|
9
|
+
/// - Includes: enums, nested structs, fixed/dynamic arrays, arrays of structs, structs of structs
|
|
10
|
+
/// - Excludes: fixed-point types and function types (by request)
|
|
11
|
+
/// - Note: mappings are not ABI-encodable, so they are shown only as a storage type.
|
|
12
|
+
contract AllSolidityTypes {
|
|
13
|
+
enum Choice { None, One, Two }
|
|
14
|
+
|
|
15
|
+
// Mapping example (not ABI-encodable as param/return)
|
|
16
|
+
mapping(address => uint256) private _balances;
|
|
17
|
+
|
|
18
|
+
// --------------------------------------------------------------------------
|
|
19
|
+
// All integer widths
|
|
20
|
+
// --------------------------------------------------------------------------
|
|
21
|
+
struct AllUints {
|
|
22
|
+
uint8 u8; uint16 u16; uint24 u24; uint32 u32; uint40 u40; uint48 u48; uint56 u56; uint64 u64;
|
|
23
|
+
uint72 u72; uint80 u80; uint88 u88; uint96 u96; uint104 u104; uint112 u112; uint120 u120; uint128 u128;
|
|
24
|
+
uint136 u136; uint144 u144; uint152 u152; uint160 u160; uint168 u168; uint176 u176; uint184 u184; uint192 u192;
|
|
25
|
+
uint200 u200; uint208 u208; uint216 u216; uint224 u224; uint232 u232; uint240 u240; uint248 u248; uint256 u256;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
struct AllInts {
|
|
29
|
+
int8 i8; int16 i16; int24 i24; int32 i32; int40 i40; int48 i48; int56 i56; int64 i64;
|
|
30
|
+
int72 i72; int80 i80; int88 i88; int96 i96; int104 i104; int112 i112; int120 i120; int128 i128;
|
|
31
|
+
int136 i136; int144 i144; int152 i152; int160 i160; int168 i168; int176 i176; int184 i184; int192 i192;
|
|
32
|
+
int200 i200; int208 i208; int216 i216; int224 i224; int232 i232; int240 i240; int248 i248; int256 i256;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// --------------------------------------------------------------------------
|
|
36
|
+
// All fixed-size bytes
|
|
37
|
+
// --------------------------------------------------------------------------
|
|
38
|
+
struct AllFixedBytes {
|
|
39
|
+
bytes1 b1; bytes2 b2; bytes3 b3; bytes4 b4; bytes5 b5; bytes6 b6; bytes7 b7; bytes8 b8;
|
|
40
|
+
bytes9 b9; bytes10 b10; bytes11 b11; bytes12 b12; bytes13 b13; bytes14 b14; bytes15 b15; bytes16 b16;
|
|
41
|
+
bytes17 b17; bytes18 b18; bytes19 b19; bytes20 b20; bytes21 b21; bytes22 b22; bytes23 b23; bytes24 b24;
|
|
42
|
+
bytes25 b25; bytes26 b26; bytes27 b27; bytes28 b28; bytes29 b29; bytes30 b30; bytes31 b31; bytes32 b32;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// --------------------------------------------------------------------------
|
|
46
|
+
// Misc ABI value types (plus arrays)
|
|
47
|
+
// --------------------------------------------------------------------------
|
|
48
|
+
struct AllMisc {
|
|
49
|
+
bool bo;
|
|
50
|
+
address addr;
|
|
51
|
+
address payable payableAddr;
|
|
52
|
+
string str;
|
|
53
|
+
bytes dynBytes;
|
|
54
|
+
Choice choice;
|
|
55
|
+
// Arrays of elementary types
|
|
56
|
+
uint256[] u256s;
|
|
57
|
+
int256[] i256s;
|
|
58
|
+
bytes32[] b32s;
|
|
59
|
+
address[] addrs;
|
|
60
|
+
bool[] bools;
|
|
61
|
+
string[] strings;
|
|
62
|
+
bytes[] bytesArr;
|
|
63
|
+
// Fixed arrays
|
|
64
|
+
uint16[3] fixedU16;
|
|
65
|
+
bytes32[2] fixedB32;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Nested struct that contains structs and arrays of structs
|
|
69
|
+
struct Inner {
|
|
70
|
+
AllUints u;
|
|
71
|
+
AllInts i;
|
|
72
|
+
AllFixedBytes fb;
|
|
73
|
+
AllMisc misc;
|
|
74
|
+
// Array of structs
|
|
75
|
+
AllUints[] uStructs;
|
|
76
|
+
// Struct of structs
|
|
77
|
+
AllFixedBytes[2] fixedFb;
|
|
78
|
+
// Nested arrays
|
|
79
|
+
uint256[][] matrix;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
struct Outer {
|
|
83
|
+
Inner inner;
|
|
84
|
+
Inner[] inners; // dynamic array of structs
|
|
85
|
+
Inner[2] fixedInners; // fixed array of structs
|
|
86
|
+
bytes32[][] b32Matrix;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
AllUints private _storedU;
|
|
90
|
+
AllInts private _storedI;
|
|
91
|
+
AllFixedBytes private _storedFb;
|
|
92
|
+
AllMisc private _storedMisc;
|
|
93
|
+
|
|
94
|
+
/// @notice Constructor with multiple parameters (including structs and arrays).
|
|
95
|
+
constructor(
|
|
96
|
+
bool bo,
|
|
97
|
+
address payable payableAddr,
|
|
98
|
+
string memory str,
|
|
99
|
+
bytes memory dynBytes,
|
|
100
|
+
Choice choice,
|
|
101
|
+
AllUints memory u,
|
|
102
|
+
AllInts memory i,
|
|
103
|
+
AllFixedBytes memory fb,
|
|
104
|
+
AllMisc memory misc,
|
|
105
|
+
uint256[] memory seedU256s,
|
|
106
|
+
bytes32[2] memory seedB32
|
|
107
|
+
) {
|
|
108
|
+
_storedU = u;
|
|
109
|
+
_storedI = i;
|
|
110
|
+
_storedFb = fb;
|
|
111
|
+
|
|
112
|
+
// Store some misc fields (keep it simple; not all array fields are persisted).
|
|
113
|
+
_storedMisc.bo = bo;
|
|
114
|
+
_storedMisc.addr = msg.sender;
|
|
115
|
+
_storedMisc.payableAddr = payableAddr;
|
|
116
|
+
_storedMisc.str = str;
|
|
117
|
+
_storedMisc.dynBytes = dynBytes;
|
|
118
|
+
_storedMisc.choice = choice;
|
|
119
|
+
_storedMisc.u256s = seedU256s;
|
|
120
|
+
_storedMisc.fixedB32 = seedB32;
|
|
121
|
+
|
|
122
|
+
// Touch mapping to demonstrate mapping existence.
|
|
123
|
+
_balances[msg.sender] = seedU256s.length;
|
|
124
|
+
|
|
125
|
+
// Use "misc" parameter to avoid unused warnings and ensure ABIEncoderV2 path is exercised.
|
|
126
|
+
if (misc.fixedU16.length > 0) {
|
|
127
|
+
_balances[misc.addr] = uint256(misc.fixedU16[0]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// --------------------------------------------------------------------------
|
|
132
|
+
// Echo / roundtrip helpers (ABI-encodable inputs and outputs)
|
|
133
|
+
// --------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
function echoAllUints(AllUints memory x) external pure returns (AllUints memory) { return x; }
|
|
136
|
+
function echoAllInts(AllInts memory x) external pure returns (AllInts memory) { return x; }
|
|
137
|
+
function echoAllFixedBytes(AllFixedBytes memory x) external pure returns (AllFixedBytes memory) { return x; }
|
|
138
|
+
function echoAllMisc(AllMisc memory x) external pure returns (AllMisc memory) { return x; }
|
|
139
|
+
|
|
140
|
+
function echoInner(Inner memory x) external pure returns (Inner memory) { return x; }
|
|
141
|
+
function echoOuter(Outer memory x) external pure returns (Outer memory) { return x; }
|
|
142
|
+
|
|
143
|
+
// Arrays of structs and nested arrays
|
|
144
|
+
function echoAllUintsArray(AllUints[] memory xs) external pure returns (AllUints[] memory) { return xs; }
|
|
145
|
+
function echoInnerArray(Inner[] memory xs) external pure returns (Inner[] memory) { return xs; }
|
|
146
|
+
function echoMatrix(uint256[][] memory m) external pure returns (uint256[][] memory) { return m; }
|
|
147
|
+
|
|
148
|
+
// Multiple input params + multiple return params
|
|
149
|
+
function multiReturn(
|
|
150
|
+
bool bo,
|
|
151
|
+
address addr,
|
|
152
|
+
bytes32 b32,
|
|
153
|
+
string memory s,
|
|
154
|
+
uint256 x,
|
|
155
|
+
AllUints memory u
|
|
156
|
+
)
|
|
157
|
+
external
|
|
158
|
+
pure
|
|
159
|
+
returns (
|
|
160
|
+
bool outBo,
|
|
161
|
+
address outAddr,
|
|
162
|
+
address payable outPayableAddr,
|
|
163
|
+
bytes32 outB32,
|
|
164
|
+
string memory outS,
|
|
165
|
+
uint256 outX,
|
|
166
|
+
AllUints memory outU
|
|
167
|
+
)
|
|
168
|
+
{
|
|
169
|
+
outBo = bo;
|
|
170
|
+
outAddr = addr;
|
|
171
|
+
outPayableAddr = payable(addr);
|
|
172
|
+
outB32 = b32;
|
|
173
|
+
outS = s;
|
|
174
|
+
outX = x;
|
|
175
|
+
outU = u;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Read-only getters to provide outputs without inputs
|
|
179
|
+
function getStoredUints() external view returns (AllUints memory) { return _storedU; }
|
|
180
|
+
function getStoredInts() external view returns (AllInts memory) { return _storedI; }
|
|
181
|
+
function getStoredFixedBytes() external view returns (AllFixedBytes memory) { return _storedFb; }
|
|
182
|
+
function getStoredMisc() external view returns (AllMisc memory) { return _storedMisc; }
|
|
183
|
+
}
|
|
184
|
+
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.7.6;
|
|
3
|
-
|
|
4
|
-
/// @title IERC20
|
|
5
|
-
/// @notice Minimal ERC-20 interface (standard ABI surface).
|
|
6
|
-
interface IERC20 {
|
|
7
|
-
event Transfer(address indexed from, address indexed to, uint256 value);
|
|
8
|
-
event Approval(address indexed owner, address indexed spender, uint256 value);
|
|
9
|
-
|
|
10
|
-
function totalSupply() external view returns (uint256);
|
|
11
|
-
function balanceOf(address account) external view returns (uint256);
|
|
12
|
-
function allowance(address owner, address spender) external view returns (uint256);
|
|
13
|
-
|
|
14
|
-
function transfer(address to, uint256 value) external returns (bool);
|
|
15
|
-
function approve(address spender, uint256 value) external returns (bool);
|
|
16
|
-
function transferFrom(address from, address to, uint256 value) external returns (bool);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/// @title SimpleERC20
|
|
20
|
-
/// @notice A small deployable ERC-20 implementation for generator examples.
|
|
21
|
-
contract SimpleERC20 is IERC20 {
|
|
22
|
-
string public name;
|
|
23
|
-
string public symbol;
|
|
24
|
-
uint8 public constant decimals = 18;
|
|
25
|
-
|
|
26
|
-
uint256 public override totalSupply;
|
|
27
|
-
mapping(address => uint256) public override balanceOf;
|
|
28
|
-
mapping(address => mapping(address => uint256)) public override allowance;
|
|
29
|
-
|
|
30
|
-
constructor(string memory _name, string memory _symbol, uint256 _initialSupply) {
|
|
31
|
-
name = _name;
|
|
32
|
-
symbol = _symbol;
|
|
33
|
-
_mint(msg.sender, _initialSupply);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function transfer(address to, uint256 value) external override returns (bool) {
|
|
37
|
-
_transfer(msg.sender, to, value);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function approve(address spender, uint256 value) external override returns (bool) {
|
|
42
|
-
allowance[msg.sender][spender] = value;
|
|
43
|
-
emit Approval(msg.sender, spender, value);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function transferFrom(address from, address to, uint256 value) external override returns (bool) {
|
|
48
|
-
uint256 allowed = allowance[from][msg.sender];
|
|
49
|
-
require(allowed >= value, "ALLOWANCE");
|
|
50
|
-
if (allowed != uint256(-1)) {
|
|
51
|
-
allowance[from][msg.sender] = allowed - value;
|
|
52
|
-
emit Approval(from, msg.sender, allowance[from][msg.sender]);
|
|
53
|
-
}
|
|
54
|
-
_transfer(from, to, value);
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _transfer(address from, address to, uint256 value) internal {
|
|
59
|
-
require(to != address(0), "TO_ZERO");
|
|
60
|
-
uint256 bal = balanceOf[from];
|
|
61
|
-
require(bal >= value, "BALANCE");
|
|
62
|
-
balanceOf[from] = bal - value;
|
|
63
|
-
balanceOf[to] += value;
|
|
64
|
-
emit Transfer(from, to, value);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function _mint(address to, uint256 value) internal {
|
|
68
|
-
require(to != address(0), "MINT_TO_ZERO");
|
|
69
|
-
totalSupply += value;
|
|
70
|
-
balanceOf[to] += value;
|
|
71
|
-
emit Transfer(address(0), to, value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.7.6;
|
|
3
|
+
|
|
4
|
+
/// @title IERC20
|
|
5
|
+
/// @notice Minimal ERC-20 interface (standard ABI surface).
|
|
6
|
+
interface IERC20 {
|
|
7
|
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
|
8
|
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
|
9
|
+
|
|
10
|
+
function totalSupply() external view returns (uint256);
|
|
11
|
+
function balanceOf(address account) external view returns (uint256);
|
|
12
|
+
function allowance(address owner, address spender) external view returns (uint256);
|
|
13
|
+
|
|
14
|
+
function transfer(address to, uint256 value) external returns (bool);
|
|
15
|
+
function approve(address spender, uint256 value) external returns (bool);
|
|
16
|
+
function transferFrom(address from, address to, uint256 value) external returns (bool);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// @title SimpleERC20
|
|
20
|
+
/// @notice A small deployable ERC-20 implementation for generator examples.
|
|
21
|
+
contract SimpleERC20 is IERC20 {
|
|
22
|
+
string public name;
|
|
23
|
+
string public symbol;
|
|
24
|
+
uint8 public constant decimals = 18;
|
|
25
|
+
|
|
26
|
+
uint256 public override totalSupply;
|
|
27
|
+
mapping(address => uint256) public override balanceOf;
|
|
28
|
+
mapping(address => mapping(address => uint256)) public override allowance;
|
|
29
|
+
|
|
30
|
+
constructor(string memory _name, string memory _symbol, uint256 _initialSupply) {
|
|
31
|
+
name = _name;
|
|
32
|
+
symbol = _symbol;
|
|
33
|
+
_mint(msg.sender, _initialSupply);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function transfer(address to, uint256 value) external override returns (bool) {
|
|
37
|
+
_transfer(msg.sender, to, value);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function approve(address spender, uint256 value) external override returns (bool) {
|
|
42
|
+
allowance[msg.sender][spender] = value;
|
|
43
|
+
emit Approval(msg.sender, spender, value);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function transferFrom(address from, address to, uint256 value) external override returns (bool) {
|
|
48
|
+
uint256 allowed = allowance[from][msg.sender];
|
|
49
|
+
require(allowed >= value, "ALLOWANCE");
|
|
50
|
+
if (allowed != uint256(-1)) {
|
|
51
|
+
allowance[from][msg.sender] = allowed - value;
|
|
52
|
+
emit Approval(from, msg.sender, allowance[from][msg.sender]);
|
|
53
|
+
}
|
|
54
|
+
_transfer(from, to, value);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _transfer(address from, address to, uint256 value) internal {
|
|
59
|
+
require(to != address(0), "TO_ZERO");
|
|
60
|
+
uint256 bal = balanceOf[from];
|
|
61
|
+
require(bal >= value, "BALANCE");
|
|
62
|
+
balanceOf[from] = bal - value;
|
|
63
|
+
balanceOf[to] += value;
|
|
64
|
+
emit Transfer(from, to, value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function _mint(address to, uint256 value) internal {
|
|
68
|
+
require(to != address(0), "MINT_TO_ZERO");
|
|
69
|
+
totalSupply += value;
|
|
70
|
+
balanceOf[to] += value;
|
|
71
|
+
emit Transfer(address(0), to, value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
package/examples/events.js
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: Querying logs/events (read-only).
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Example: Querying logs/events (read-only).
|
|
3
|
+
* Run with VERBOSE=1 for addresses, block range, and log counts.
|
|
4
|
+
*
|
|
5
|
+
* Note: This is a simple log query example; it does not keep a live subscription
|
|
6
|
+
* running. For long-running subscriptions, build on Provider polling or a future
|
|
7
|
+
* WebSocketProvider implementation.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { Initialize } = require("../config");
|
|
11
|
+
const { getProvider, Contract } = require("..");
|
|
12
|
+
const { logExample, logAddress } = require("../test/verbose-logger");
|
|
13
|
+
|
|
14
|
+
const RPC = "https://public.rpc.quantumcoinapi.com";
|
|
15
|
+
const CHAIN_ID = 123123;
|
|
16
|
+
const STAKING_CONTRACT = "0x" + "00".repeat(30) + "10" + "00"; // 0x...1000
|
|
17
|
+
|
|
18
|
+
async function eventsExample() {
|
|
19
|
+
logExample("events.js", "starting", { rpc: RPC, chainId: CHAIN_ID });
|
|
20
|
+
await Initialize(null);
|
|
21
|
+
|
|
22
|
+
const provider = getProvider(RPC, CHAIN_ID);
|
|
23
|
+
logAddress("staking_contract", STAKING_CONTRACT);
|
|
24
|
+
const abi = require("../test/fixtures/StakingContract.abi.json");
|
|
25
|
+
const contract = new Contract(STAKING_CONTRACT, abi, provider);
|
|
26
|
+
|
|
27
|
+
// Query recent logs from the last 1000 blocks
|
|
28
|
+
const latest = await provider.getBlockNumber();
|
|
29
|
+
const fromBlock = Math.max(latest - 1000, 0);
|
|
30
|
+
logExample("events.js", "block range", { latest, fromBlock, toBlock: "latest" });
|
|
31
|
+
|
|
32
|
+
const logs = await contract.queryFilter("OnNewDeposit", fromBlock, "latest");
|
|
33
|
+
console.log(`Found ${logs.length} OnNewDeposit logs in last 1000 blocks`);
|
|
34
|
+
logExample("events.js", "queryFilter OnNewDeposit", { logCount: logs.length });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
eventsExample().catch((e) => {
|
|
38
|
+
console.error(e);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
});
|
|
41
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Querying logs/events (read-only) - TypeScript.
|
|
3
|
+
* Run: npx tsx examples/events.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Initialize } from "../config";
|
|
7
|
+
import { getProvider, Contract } from "..";
|
|
8
|
+
import { logExample, logAddress } from "../test/verbose-logger";
|
|
9
|
+
|
|
10
|
+
const RPC = "https://public.rpc.quantumcoinapi.com";
|
|
11
|
+
const CHAIN_ID = 123123;
|
|
12
|
+
const STAKING_CONTRACT = "0x" + "00".repeat(30) + "10" + "00";
|
|
13
|
+
|
|
14
|
+
async function eventsExample(): Promise<void> {
|
|
15
|
+
logExample("events.ts", "starting", { rpc: RPC, chainId: CHAIN_ID });
|
|
16
|
+
await Initialize(null);
|
|
17
|
+
|
|
18
|
+
const provider = getProvider(RPC, CHAIN_ID);
|
|
19
|
+
logAddress("staking_contract", STAKING_CONTRACT);
|
|
20
|
+
const abi = require("../test/fixtures/StakingContract.abi.json");
|
|
21
|
+
const contract = new Contract(STAKING_CONTRACT, abi, provider);
|
|
22
|
+
|
|
23
|
+
const latest = await provider.getBlockNumber();
|
|
24
|
+
const fromBlock = Math.max(Number(latest) - 1000, 0);
|
|
25
|
+
logExample("events.ts", "block range", { latest: Number(latest), fromBlock, toBlock: "latest" });
|
|
26
|
+
|
|
27
|
+
const logs = await contract.queryFilter("OnNewDeposit", fromBlock, "latest");
|
|
28
|
+
console.log(`Found ${logs.length} OnNewDeposit logs in last 1000 blocks`);
|
|
29
|
+
logExample("events.ts", "queryFilter OnNewDeposit", { logCount: logs.length });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
eventsExample().catch((e) => {
|
|
33
|
+
console.error(e);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
});
|