quantum-coin-js-sdk 2.0.1 → 2.1.0
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/README.md +13 -0
- package/index.d.ts +9 -0
- package/index.js +37 -4
- package/package.json +12 -4
- package/wasmBase64.js +3 -2
- package/.idea/.name +0 -1
- package/.idea/modules.xml +0 -8
- package/.idea/quantum-coin-js-sdk.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.vs/ProjectSettings.json +0 -3
- package/.vs/VSWorkspaceState.json +0 -8
- package/.vs/quantum-coin-js-sdk/FileContentIndex/a9d6de82-cfc3-4c22-ac38-06d706ff3673.vsidx +0 -0
- package/.vs/quantum-coin-js-sdk/FileContentIndex/fdc816df-1898-4153-99f2-c69ef4c2283b.vsidx +0 -0
- package/.vs/quantum-coin-js-sdk/config/applicationhost.config +0 -1011
- package/.vs/quantum-coin-js-sdk/v17/.wsuo +0 -0
- package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.backup.json +0 -39
- package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.json +0 -57
- package/.vs/slnx.sqlite +0 -0
- package/example/README.md +0 -14
- package/example/conversion-example.js +0 -19
- package/example/example-create-contract.js +0 -396
- package/example/example-encode-decode-rlp.js +0 -225
- package/example/example-event-pack-unpack.js +0 -391
- package/example/example-misc.js +0 -96
- package/example/example-token-pack-unpack.js +0 -960
- package/example/example-wallet-version4.js +0 -34
- package/example/example-wallet.js +0 -39
- package/example/example.js +0 -115
- package/example/node_modules/.bin/sdkgen +0 -16
- package/example/node_modules/.bin/sdkgen.cmd +0 -17
- package/example/node_modules/.bin/sdkgen.ps1 +0 -28
- package/example/node_modules/.package-lock.json +0 -51
- package/example/node_modules/quantumcoin/.github/workflows/publish-npmjs.yaml +0 -22
- package/example/node_modules/quantumcoin/LICENSE +0 -21
- package/example/node_modules/quantumcoin/README-SDK.md +0 -828
- package/example/node_modules/quantumcoin/README.md +0 -197
- package/example/node_modules/quantumcoin/config.d.ts +0 -50
- package/example/node_modules/quantumcoin/config.js +0 -123
- package/example/node_modules/quantumcoin/examples/AllSolidityTypes.sol +0 -184
- package/example/node_modules/quantumcoin/examples/SimpleIERC20.sol +0 -74
- package/example/node_modules/quantumcoin/examples/events.js +0 -41
- package/example/node_modules/quantumcoin/examples/events.ts +0 -35
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.js +0 -100
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.ts +0 -77
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.js +0 -100
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.ts +0 -77
- package/example/node_modules/quantumcoin/examples/example.js +0 -67
- package/example/node_modules/quantumcoin/examples/example.ts +0 -56
- package/example/node_modules/quantumcoin/examples/offline-signing.js +0 -77
- package/example/node_modules/quantumcoin/examples/offline-signing.ts +0 -65
- package/example/node_modules/quantumcoin/examples/package-lock.json +0 -596
- package/example/node_modules/quantumcoin/examples/package.json +0 -32
- package/example/node_modules/quantumcoin/examples/read-operations.js +0 -32
- package/example/node_modules/quantumcoin/examples/read-operations.ts +0 -31
- package/example/node_modules/quantumcoin/examples/sdk-generator-erc20.inline.json +0 -251
- package/example/node_modules/quantumcoin/examples/solidity-types.ts +0 -43
- package/example/node_modules/quantumcoin/examples/wallet-offline.js +0 -36
- package/example/node_modules/quantumcoin/examples/wallet-offline.ts +0 -26
- package/example/node_modules/quantumcoin/generate-sdk.js +0 -1846
- package/example/node_modules/quantumcoin/index.js +0 -12
- package/example/node_modules/quantumcoin/package.json +0 -95
- package/example/node_modules/quantumcoin/scripts/copy-declarations.js +0 -31
- package/example/node_modules/quantumcoin/scripts/run-all-one-by-one.js +0 -151
- package/example/node_modules/quantumcoin/src/abi/fragments.d.ts +0 -42
- package/example/node_modules/quantumcoin/src/abi/fragments.js +0 -63
- package/example/node_modules/quantumcoin/src/abi/index.d.ts +0 -13
- package/example/node_modules/quantumcoin/src/abi/index.js +0 -9
- package/example/node_modules/quantumcoin/src/abi/interface.d.ts +0 -128
- package/example/node_modules/quantumcoin/src/abi/interface.js +0 -605
- package/example/node_modules/quantumcoin/src/abi/js-abi-coder.d.ts +0 -8
- package/example/node_modules/quantumcoin/src/abi/js-abi-coder.js +0 -538
- package/example/node_modules/quantumcoin/src/constants.d.ts +0 -61
- package/example/node_modules/quantumcoin/src/constants.js +0 -94
- package/example/node_modules/quantumcoin/src/contract/contract-factory.d.ts +0 -28
- package/example/node_modules/quantumcoin/src/contract/contract-factory.js +0 -111
- package/example/node_modules/quantumcoin/src/contract/contract.d.ts +0 -113
- package/example/node_modules/quantumcoin/src/contract/contract.js +0 -408
- package/example/node_modules/quantumcoin/src/contract/index.d.ts +0 -9
- package/example/node_modules/quantumcoin/src/contract/index.js +0 -9
- package/example/node_modules/quantumcoin/src/errors/index.d.ts +0 -92
- package/example/node_modules/quantumcoin/src/errors/index.js +0 -200
- package/example/node_modules/quantumcoin/src/generator/index.d.ts +0 -81
- package/example/node_modules/quantumcoin/src/generator/index.js +0 -1571
- package/example/node_modules/quantumcoin/src/index.d.ts +0 -122
- package/example/node_modules/quantumcoin/src/index.js +0 -41
- package/example/node_modules/quantumcoin/src/internal/hex.d.ts +0 -68
- package/example/node_modules/quantumcoin/src/internal/hex.js +0 -180
- package/example/node_modules/quantumcoin/src/providers/extra-providers.d.ts +0 -139
- package/example/node_modules/quantumcoin/src/providers/extra-providers.js +0 -614
- package/example/node_modules/quantumcoin/src/providers/index.d.ts +0 -17
- package/example/node_modules/quantumcoin/src/providers/index.js +0 -10
- package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.d.ts +0 -12
- package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.js +0 -89
- package/example/node_modules/quantumcoin/src/providers/provider.d.ts +0 -206
- package/example/node_modules/quantumcoin/src/providers/provider.js +0 -524
- package/example/node_modules/quantumcoin/src/types/index.d.ts +0 -214
- package/example/node_modules/quantumcoin/src/types/index.js +0 -9
- package/example/node_modules/quantumcoin/src/utils/address.d.ts +0 -58
- package/example/node_modules/quantumcoin/src/utils/address.js +0 -144
- package/example/node_modules/quantumcoin/src/utils/encoding.d.ts +0 -120
- package/example/node_modules/quantumcoin/src/utils/encoding.js +0 -306
- package/example/node_modules/quantumcoin/src/utils/fixednumber.d.ts +0 -57
- package/example/node_modules/quantumcoin/src/utils/fixednumber.js +0 -366
- package/example/node_modules/quantumcoin/src/utils/hashing.d.ts +0 -76
- package/example/node_modules/quantumcoin/src/utils/hashing.js +0 -298
- package/example/node_modules/quantumcoin/src/utils/index.d.ts +0 -63
- package/example/node_modules/quantumcoin/src/utils/index.js +0 -14
- package/example/node_modules/quantumcoin/src/utils/result.d.ts +0 -57
- package/example/node_modules/quantumcoin/src/utils/result.js +0 -128
- package/example/node_modules/quantumcoin/src/utils/rlp.d.ts +0 -12
- package/example/node_modules/quantumcoin/src/utils/rlp.js +0 -215
- package/example/node_modules/quantumcoin/src/utils/units.d.ts +0 -29
- package/example/node_modules/quantumcoin/src/utils/units.js +0 -107
- package/example/node_modules/quantumcoin/src/wallet/index.d.ts +0 -10
- package/example/node_modules/quantumcoin/src/wallet/index.js +0 -8
- package/example/node_modules/quantumcoin/src/wallet/wallet.d.ts +0 -192
- package/example/node_modules/quantumcoin/src/wallet/wallet.js +0 -713
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.js +0 -207
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.ts +0 -191
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.fixtures.js +0 -231
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +0 -387
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +0 -350
- package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.js +0 -165
- package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.ts +0 -160
- package/example/node_modules/quantumcoin/test/e2e/helpers.js +0 -59
- package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.js +0 -141
- package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.ts +0 -128
- package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.js +0 -168
- package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +0 -141
- package/example/node_modules/quantumcoin/test/e2e/transactional.test.js +0 -245
- package/example/node_modules/quantumcoin/test/e2e/transactional.test.ts +0 -208
- package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.js +0 -407
- package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.ts +0 -337
- package/example/node_modules/quantumcoin/test/fixtures/ConstructorParam.sol +0 -23
- package/example/node_modules/quantumcoin/test/fixtures/MultiContracts.sol +0 -37
- package/example/node_modules/quantumcoin/test/fixtures/SimpleStorage.sol +0 -18
- package/example/node_modules/quantumcoin/test/fixtures/StakingContract.abi.json +0 -1
- package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.js +0 -49
- package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.ts +0 -44
- package/example/node_modules/quantumcoin/test/integration/provider.test.js +0 -88
- package/example/node_modules/quantumcoin/test/integration/provider.test.ts +0 -85
- package/example/node_modules/quantumcoin/test/integration/ws-provider.test.js +0 -41
- package/example/node_modules/quantumcoin/test/integration/ws-provider.test.ts +0 -38
- package/example/node_modules/quantumcoin/test/security/abi-decoder-bounds.test.js +0 -122
- package/example/node_modules/quantumcoin/test/security/contract-overrides.test.js +0 -112
- package/example/node_modules/quantumcoin/test/security/generator-injection.test.js +0 -195
- package/example/node_modules/quantumcoin/test/security/malformed-input.test.js +0 -330
- package/example/node_modules/quantumcoin/test/security/malformed-input.test.ts +0 -35
- package/example/node_modules/quantumcoin/test/security/rpc-numeric-bounds.test.js +0 -81
- package/example/node_modules/quantumcoin/test/security/rpc-trust.test.js +0 -202
- package/example/node_modules/quantumcoin/test/unit/_encrypted-output.txt +0 -6
- package/example/node_modules/quantumcoin/test/unit/_log-encrypted-jsons.js +0 -45
- package/example/node_modules/quantumcoin/test/unit/_write-keystore-fixture.js +0 -16
- package/example/node_modules/quantumcoin/test/unit/abi-interface.test.js +0 -110
- package/example/node_modules/quantumcoin/test/unit/abi-interface.test.ts +0 -109
- package/example/node_modules/quantumcoin/test/unit/address-wallet.test.js +0 -923
- package/example/node_modules/quantumcoin/test/unit/address-wallet.test.ts +0 -877
- package/example/node_modules/quantumcoin/test/unit/browser-provider.test.js +0 -85
- package/example/node_modules/quantumcoin/test/unit/browser-provider.test.ts +0 -79
- package/example/node_modules/quantumcoin/test/unit/contract.test.js +0 -85
- package/example/node_modules/quantumcoin/test/unit/contract.test.ts +0 -83
- package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.js +0 -127
- package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.ts +0 -91
- package/example/node_modules/quantumcoin/test/unit/errors.test.js +0 -77
- package/example/node_modules/quantumcoin/test/unit/errors.test.ts +0 -76
- package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.js +0 -55
- package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.ts +0 -54
- package/example/node_modules/quantumcoin/test/unit/fixednumber.test.js +0 -656
- package/example/node_modules/quantumcoin/test/unit/fixednumber.test.ts +0 -660
- package/example/node_modules/quantumcoin/test/unit/fixtures/encrypted-keystores-48-32-36.js +0 -9
- package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.js +0 -42
- package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.ts +0 -41
- package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.js +0 -113
- package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.ts +0 -110
- package/example/node_modules/quantumcoin/test/unit/generator.test.js +0 -149
- package/example/node_modules/quantumcoin/test/unit/generator.test.ts +0 -148
- package/example/node_modules/quantumcoin/test/unit/hashing.test.js +0 -64
- package/example/node_modules/quantumcoin/test/unit/hashing.test.ts +0 -63
- package/example/node_modules/quantumcoin/test/unit/init.test.js +0 -39
- package/example/node_modules/quantumcoin/test/unit/init.test.ts +0 -38
- package/example/node_modules/quantumcoin/test/unit/interface.test.js +0 -56
- package/example/node_modules/quantumcoin/test/unit/interface.test.ts +0 -54
- package/example/node_modules/quantumcoin/test/unit/internal-hex.test.js +0 -81
- package/example/node_modules/quantumcoin/test/unit/internal-hex.test.ts +0 -80
- package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.js +0 -98
- package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.ts +0 -64
- package/example/node_modules/quantumcoin/test/unit/providers.test.js +0 -252
- package/example/node_modules/quantumcoin/test/unit/providers.test.ts +0 -251
- package/example/node_modules/quantumcoin/test/unit/result.test.js +0 -80
- package/example/node_modules/quantumcoin/test/unit/result.test.ts +0 -79
- package/example/node_modules/quantumcoin/test/unit/solidity-types.test.js +0 -49
- package/example/node_modules/quantumcoin/test/unit/solidity-types.test.ts +0 -39
- package/example/node_modules/quantumcoin/test/unit/utils.test.js +0 -57
- package/example/node_modules/quantumcoin/test/unit/utils.test.ts +0 -56
- package/example/node_modules/quantumcoin/test/verbose-logger.js +0 -74
- package/example/node_modules/quantumcoin/tsconfig.build.json +0 -14
- package/example/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
- package/example/node_modules/seed-words/BUILD.md +0 -7
- package/example/node_modules/seed-words/LICENSE +0 -121
- package/example/node_modules/seed-words/README.md +0 -67
- package/example/node_modules/seed-words/dist/seedwords.d.ts +0 -39
- package/example/node_modules/seed-words/package.json +0 -27
- package/example/node_modules/seed-words/seedwords.js +0 -315
- package/example/node_modules/seed-words/seedwords.txt +0 -65536
- package/example/node_modules/seed-words/tsconfig.json +0 -21
- package/example/package-lock.json +0 -60
- package/example/package.json +0 -15
- package/scripts/build-browser-tests.js +0 -29
- package/scripts/build-wasm.js +0 -85
- package/tests/browser/bundle.js +0 -97643
- package/tests/browser/entry.js +0 -57
- package/tests/browser/harness.html +0 -20
- package/tests/browser/run-browser.js +0 -50
- package/tests/encrypted-32.json +0 -1
- package/tests/encrypted-36.json +0 -1
- package/tests/encrypted-48.json +0 -1
- package/tests/generate-verify-vectors.js +0 -88
- package/tests/get-gas-price.test.js +0 -59
- package/tests/hashing.test.js +0 -34
- package/tests/non-transactional.preinit.test.js +0 -33
- package/tests/non-transactional.test.js +0 -1318
- package/tests/sign-raw-keytype5-context-null.test.js +0 -105
- package/tests/sign-raw-transaction.test.js +0 -194
- package/tests/sign-verify.test.js +0 -308
- package/tests/specs/assert.js +0 -74
- package/tests/specs/crypto.spec.js +0 -104
- package/tests/specs/hex.js +0 -31
- package/tests/specs/preinit.spec.js +0 -19
- package/tests/specs/sign.spec.js +0 -90
- package/tests/specs/wallet.spec.js +0 -98
- package/tests/transactional.rpc.test.js +0 -102
- package/tests/verify-vectors.json +0 -95035
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: RLP Encoding and Decoding
|
|
3
|
-
*
|
|
4
|
-
* This example demonstrates how to use the encodeRlp and decodeRlp functions
|
|
5
|
-
* to encode and decode various JavaScript values using RLP (Recursive Length Prefix) encoding.
|
|
6
|
-
*
|
|
7
|
-
* RLP is used in Ethereum and Quantum Coin for encoding structured data.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const qcsdk = require('../index');
|
|
11
|
-
|
|
12
|
-
// Initialize the SDK
|
|
13
|
-
async function main() {
|
|
14
|
-
console.log('=== RLP Encoding and Decoding Examples ===\n');
|
|
15
|
-
|
|
16
|
-
// Initialize SDK with default mainnet config
|
|
17
|
-
const initResult = await qcsdk.initialize(null);
|
|
18
|
-
if (initResult === false) {
|
|
19
|
-
console.error('Failed to initialize SDK');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
console.log('SDK initialized successfully\n');
|
|
23
|
-
|
|
24
|
-
// Example 1: Encode and decode a string
|
|
25
|
-
console.log('--- Example 1: String ---');
|
|
26
|
-
const stringValue = 'Hello, World!';
|
|
27
|
-
console.log('Original value:', stringValue);
|
|
28
|
-
|
|
29
|
-
const encodeResult1 = qcsdk.encodeRlp(stringValue);
|
|
30
|
-
if (encodeResult1.error) {
|
|
31
|
-
console.error('Encoding error:', encodeResult1.error);
|
|
32
|
-
} else {
|
|
33
|
-
console.log('Encoded (hex):', encodeResult1.result);
|
|
34
|
-
|
|
35
|
-
const decodeResult1 = qcsdk.decodeRlp(encodeResult1.result);
|
|
36
|
-
if (decodeResult1.error) {
|
|
37
|
-
console.error('Decoding error:', decodeResult1.error);
|
|
38
|
-
} else {
|
|
39
|
-
const decoded = JSON.parse(decodeResult1.result);
|
|
40
|
-
console.log('Decoded value:', decoded);
|
|
41
|
-
console.log('Round-trip successful:', decoded === stringValue);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
console.log();
|
|
45
|
-
|
|
46
|
-
// Example 2: Encode and decode a number
|
|
47
|
-
console.log('--- Example 2: Number ---');
|
|
48
|
-
const numberValue = 42;
|
|
49
|
-
console.log('Original value:', numberValue);
|
|
50
|
-
|
|
51
|
-
const encodeResult2 = qcsdk.encodeRlp(numberValue);
|
|
52
|
-
if (encodeResult2.error) {
|
|
53
|
-
console.error('Encoding error:', encodeResult2.error);
|
|
54
|
-
} else {
|
|
55
|
-
console.log('Encoded (hex):', encodeResult2.result);
|
|
56
|
-
|
|
57
|
-
const decodeResult2 = qcsdk.decodeRlp(encodeResult2.result);
|
|
58
|
-
if (decodeResult2.error) {
|
|
59
|
-
console.error('Decoding error:', decodeResult2.error);
|
|
60
|
-
} else {
|
|
61
|
-
const decoded = JSON.parse(decodeResult2.result);
|
|
62
|
-
console.log('Decoded value:', decoded);
|
|
63
|
-
console.log('Round-trip successful:', decoded === numberValue);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
console.log();
|
|
67
|
-
|
|
68
|
-
// Example 3: Encode and decode a boolean
|
|
69
|
-
console.log('--- Example 3: Boolean ---');
|
|
70
|
-
const boolValue = true;
|
|
71
|
-
console.log('Original value:', boolValue);
|
|
72
|
-
|
|
73
|
-
const encodeResult3 = qcsdk.encodeRlp(boolValue);
|
|
74
|
-
if (encodeResult3.error) {
|
|
75
|
-
console.error('Encoding error:', encodeResult3.error);
|
|
76
|
-
} else {
|
|
77
|
-
console.log('Encoded (hex):', encodeResult3.result);
|
|
78
|
-
|
|
79
|
-
const decodeResult3 = qcsdk.decodeRlp(encodeResult3.result);
|
|
80
|
-
if (decodeResult3.error) {
|
|
81
|
-
console.error('Decoding error:', decodeResult3.error);
|
|
82
|
-
} else {
|
|
83
|
-
const decoded = JSON.parse(decodeResult3.result);
|
|
84
|
-
console.log('Decoded value:', decoded);
|
|
85
|
-
console.log('Round-trip successful:', decoded === boolValue);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
console.log();
|
|
89
|
-
|
|
90
|
-
// Example 4: Encode and decode an array
|
|
91
|
-
console.log('--- Example 4: Array ---');
|
|
92
|
-
const arrayValue = ['hello', 123, true];
|
|
93
|
-
console.log('Original value:', JSON.stringify(arrayValue));
|
|
94
|
-
|
|
95
|
-
const encodeResult4 = qcsdk.encodeRlp(arrayValue);
|
|
96
|
-
if (encodeResult4.error) {
|
|
97
|
-
console.error('Encoding error:', encodeResult4.error);
|
|
98
|
-
} else {
|
|
99
|
-
console.log('Encoded (hex):', encodeResult4.result);
|
|
100
|
-
|
|
101
|
-
const decodeResult4 = qcsdk.decodeRlp(encodeResult4.result);
|
|
102
|
-
if (decodeResult4.error) {
|
|
103
|
-
console.error('Decoding error:', decodeResult4.error);
|
|
104
|
-
} else {
|
|
105
|
-
const decoded = JSON.parse(decodeResult4.result);
|
|
106
|
-
console.log('Decoded value:', JSON.stringify(decoded));
|
|
107
|
-
console.log('Round-trip successful:', JSON.stringify(decoded) === JSON.stringify(arrayValue));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
console.log();
|
|
111
|
-
|
|
112
|
-
// Example 5: Encode and decode an object (map)
|
|
113
|
-
console.log('--- Example 5: Object (Map) ---');
|
|
114
|
-
const objectValue = { name: 'Alice', age: 30, active: true };
|
|
115
|
-
console.log('Original value:', JSON.stringify(objectValue));
|
|
116
|
-
|
|
117
|
-
const encodeResult5 = qcsdk.encodeRlp(objectValue);
|
|
118
|
-
if (encodeResult5.error) {
|
|
119
|
-
console.error('Encoding error:', encodeResult5.error);
|
|
120
|
-
} else {
|
|
121
|
-
console.log('Encoded (hex):', encodeResult5.result);
|
|
122
|
-
|
|
123
|
-
const decodeResult5 = qcsdk.decodeRlp(encodeResult5.result);
|
|
124
|
-
if (decodeResult5.error) {
|
|
125
|
-
console.error('Decoding error:', decodeResult5.error);
|
|
126
|
-
} else {
|
|
127
|
-
const decoded = JSON.parse(decodeResult5.result);
|
|
128
|
-
console.log('Decoded value:', JSON.stringify(decoded));
|
|
129
|
-
// Note: Objects are encoded as arrays of key-value pairs in RLP
|
|
130
|
-
// The decoded structure may differ from the original object
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
console.log();
|
|
134
|
-
|
|
135
|
-
// Example 6: Encode and decode a hex string
|
|
136
|
-
console.log('--- Example 6: Hex String ---');
|
|
137
|
-
const hexValue = '0x48656c6c6f'; // "Hello" in hex
|
|
138
|
-
console.log('Original value:', hexValue);
|
|
139
|
-
|
|
140
|
-
const encodeResult6 = qcsdk.encodeRlp(hexValue);
|
|
141
|
-
if (encodeResult6.error) {
|
|
142
|
-
console.error('Encoding error:', encodeResult6.error);
|
|
143
|
-
} else {
|
|
144
|
-
console.log('Encoded (hex):', encodeResult6.result);
|
|
145
|
-
|
|
146
|
-
const decodeResult6 = qcsdk.decodeRlp(encodeResult6.result);
|
|
147
|
-
if (decodeResult6.error) {
|
|
148
|
-
console.error('Decoding error:', decodeResult6.error);
|
|
149
|
-
} else {
|
|
150
|
-
const decoded = JSON.parse(decodeResult6.result);
|
|
151
|
-
console.log('Decoded value:', decoded);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
console.log();
|
|
155
|
-
|
|
156
|
-
// Example 7: Encode and decode a nested array
|
|
157
|
-
console.log('--- Example 7: Nested Array ---');
|
|
158
|
-
const nestedArrayValue = [1, [2, 3], [4, [5, 6]]];
|
|
159
|
-
console.log('Original value:', JSON.stringify(nestedArrayValue));
|
|
160
|
-
|
|
161
|
-
const encodeResult7 = qcsdk.encodeRlp(nestedArrayValue);
|
|
162
|
-
if (encodeResult7.error) {
|
|
163
|
-
console.error('Encoding error:', encodeResult7.error);
|
|
164
|
-
} else {
|
|
165
|
-
console.log('Encoded (hex):', encodeResult7.result);
|
|
166
|
-
|
|
167
|
-
const decodeResult7 = qcsdk.decodeRlp(encodeResult7.result);
|
|
168
|
-
if (decodeResult7.error) {
|
|
169
|
-
console.error('Decoding error:', decodeResult7.error);
|
|
170
|
-
} else {
|
|
171
|
-
const decoded = JSON.parse(decodeResult7.result);
|
|
172
|
-
console.log('Decoded value:', JSON.stringify(decoded));
|
|
173
|
-
console.log('Round-trip successful:', JSON.stringify(decoded) === JSON.stringify(nestedArrayValue));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
console.log();
|
|
177
|
-
|
|
178
|
-
// Example 8: Encode and decode a large number (BigInt)
|
|
179
|
-
console.log('--- Example 8: Large Number (BigInt) ---');
|
|
180
|
-
const bigIntValue = '1000000000000000000'; // 1 ether in wei
|
|
181
|
-
console.log('Original value:', bigIntValue);
|
|
182
|
-
|
|
183
|
-
const encodeResult8 = qcsdk.encodeRlp(bigIntValue);
|
|
184
|
-
if (encodeResult8.error) {
|
|
185
|
-
console.error('Encoding error:', encodeResult8.error);
|
|
186
|
-
} else {
|
|
187
|
-
console.log('Encoded (hex):', encodeResult8.result);
|
|
188
|
-
|
|
189
|
-
const decodeResult8 = qcsdk.decodeRlp(encodeResult8.result);
|
|
190
|
-
if (decodeResult8.error) {
|
|
191
|
-
console.error('Decoding error:', decodeResult8.error);
|
|
192
|
-
} else {
|
|
193
|
-
const decoded = JSON.parse(decodeResult8.result);
|
|
194
|
-
console.log('Decoded value:', decoded);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
console.log();
|
|
198
|
-
|
|
199
|
-
// Example 9: Empty array
|
|
200
|
-
console.log('--- Example 9: Empty Array ---');
|
|
201
|
-
const emptyArrayValue = [];
|
|
202
|
-
console.log('Original value:', JSON.stringify(emptyArrayValue));
|
|
203
|
-
|
|
204
|
-
const encodeResult9 = qcsdk.encodeRlp(emptyArrayValue);
|
|
205
|
-
if (encodeResult9.error) {
|
|
206
|
-
console.error('Encoding error:', encodeResult9.error);
|
|
207
|
-
} else {
|
|
208
|
-
console.log('Encoded (hex):', encodeResult9.result);
|
|
209
|
-
|
|
210
|
-
const decodeResult9 = qcsdk.decodeRlp(encodeResult9.result);
|
|
211
|
-
if (decodeResult9.error) {
|
|
212
|
-
console.error('Decoding error:', decodeResult9.error);
|
|
213
|
-
} else {
|
|
214
|
-
const decoded = JSON.parse(decodeResult9.result);
|
|
215
|
-
console.log('Decoded value:', JSON.stringify(decoded));
|
|
216
|
-
console.log('Round-trip successful:', JSON.stringify(decoded) === JSON.stringify(emptyArrayValue));
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
console.log();
|
|
220
|
-
|
|
221
|
-
console.log('=== All Examples Completed ===');
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Run the examples
|
|
225
|
-
main().catch(console.error);
|
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
const qcsdk = require('quantum-coin-js-sdk');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Example: Event Log Encode/Decode Operations
|
|
5
|
-
*
|
|
6
|
-
* This example demonstrates how to use encodeEventLog and decodeEventLog
|
|
7
|
-
* to encode and decode Ethereum event logs according to the ABI specification.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// Configuration
|
|
11
|
-
var clientConfigVal = new qcsdk.Config(123123); //Mainnet
|
|
12
|
-
//Mainnet Block Explorer: https://scan.quantumcoin.org
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Example 1: Basic Transfer Event (ERC20)
|
|
16
|
-
* Transfer(address indexed from, address indexed to, uint256 value)
|
|
17
|
-
*/
|
|
18
|
-
async function example1_TransferEvent() {
|
|
19
|
-
console.log("\n=== Example 1: Transfer Event ===");
|
|
20
|
-
|
|
21
|
-
const transferABI = JSON.stringify([{
|
|
22
|
-
"name": "Transfer",
|
|
23
|
-
"type": "event",
|
|
24
|
-
"anonymous": false,
|
|
25
|
-
"inputs": [
|
|
26
|
-
{"name": "from", "type": "address", "indexed": true},
|
|
27
|
-
{"name": "to", "type": "address", "indexed": true},
|
|
28
|
-
{"name": "value", "type": "uint256", "indexed": false}
|
|
29
|
-
]
|
|
30
|
-
}]);
|
|
31
|
-
|
|
32
|
-
const fromAddress = "0xd51773b5dde3f8e4d29ae42b5046510e2a11fd0c8e4175853d6227896eb445c6";
|
|
33
|
-
const toAddress = "0x1Bd75060B22686a9f32Af80BC02348c1BAeDBba06f47ad723885c92a6566B65d";
|
|
34
|
-
const value = "1000000000000000000"; // 1 token (18 decimals)
|
|
35
|
-
|
|
36
|
-
// Encode the event
|
|
37
|
-
const encodeResult = qcsdk.encodeEventLog(transferABI, "Transfer", fromAddress, toAddress, value);
|
|
38
|
-
|
|
39
|
-
if (encodeResult.error) {
|
|
40
|
-
console.error("Encode error:", encodeResult.error);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
console.log("Encoded Transfer Event:");
|
|
45
|
-
console.log(" Topics:", encodeResult.result.topics);
|
|
46
|
-
console.log(" Data:", encodeResult.result.data);
|
|
47
|
-
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
48
|
-
console.log(" Expected: 3 topics (event signature + from + to)");
|
|
49
|
-
|
|
50
|
-
// Decode the event back
|
|
51
|
-
const decodeResult = qcsdk.decodeEventLog(
|
|
52
|
-
transferABI,
|
|
53
|
-
"Transfer",
|
|
54
|
-
encodeResult.result.topics,
|
|
55
|
-
encodeResult.result.data
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
if (decodeResult.error) {
|
|
59
|
-
console.error("Decode error:", decodeResult.error);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const decoded = JSON.parse(decodeResult.result);
|
|
64
|
-
console.log("\nDecoded Transfer Event:");
|
|
65
|
-
console.log(" From:", decoded.from);
|
|
66
|
-
console.log(" To:", decoded.to);
|
|
67
|
-
console.log(" Value:", decoded.value);
|
|
68
|
-
console.log(" Verification:",
|
|
69
|
-
decoded.from.toLowerCase() === fromAddress.toLowerCase() &&
|
|
70
|
-
decoded.to.toLowerCase() === toAddress.toLowerCase() &&
|
|
71
|
-
decoded.value === value ? "✓ Match" : "✗ Mismatch"
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Example 2: Event with All Indexed Parameters
|
|
77
|
-
* Approval(address indexed owner, address indexed spender, uint256 indexed value)
|
|
78
|
-
*/
|
|
79
|
-
async function example2_AllIndexedEvent() {
|
|
80
|
-
console.log("\n=== Example 2: All Indexed Event (Approval) ===");
|
|
81
|
-
|
|
82
|
-
const approvalABI = JSON.stringify([{
|
|
83
|
-
"name": "Approval",
|
|
84
|
-
"type": "event",
|
|
85
|
-
"anonymous": false,
|
|
86
|
-
"inputs": [
|
|
87
|
-
{"name": "owner", "type": "address", "indexed": true},
|
|
88
|
-
{"name": "spender", "type": "address", "indexed": true},
|
|
89
|
-
{"name": "value", "type": "uint256", "indexed": true}
|
|
90
|
-
]
|
|
91
|
-
}]);
|
|
92
|
-
|
|
93
|
-
const owner = "0xd51773b5dde3f8e4d29ae42b5046510e2a11fd0c8e4175853d6227896eb445c6";
|
|
94
|
-
const spender = "0x1Bd75060B22686a9f32Af80BC02348c1BAeDBba06f47ad723885c92a6566B65d";
|
|
95
|
-
const value = "5000000000000000000"; // 5 tokens
|
|
96
|
-
|
|
97
|
-
// Encode the event
|
|
98
|
-
const encodeResult = qcsdk.encodeEventLog(approvalABI, "Approval", owner, spender, value);
|
|
99
|
-
|
|
100
|
-
if (encodeResult.error) {
|
|
101
|
-
console.error("Encode error:", encodeResult.error);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
console.log("Encoded Approval Event:");
|
|
106
|
-
console.log(" Topics:", encodeResult.result.topics);
|
|
107
|
-
console.log(" Data:", encodeResult.result.data);
|
|
108
|
-
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
109
|
-
console.log(" Expected: 4 topics (event signature + owner + spender + value)");
|
|
110
|
-
console.log(" Data should be empty (0x) since all parameters are indexed");
|
|
111
|
-
|
|
112
|
-
// Decode the event back
|
|
113
|
-
const decodeResult = qcsdk.decodeEventLog(
|
|
114
|
-
approvalABI,
|
|
115
|
-
"Approval",
|
|
116
|
-
encodeResult.result.topics,
|
|
117
|
-
encodeResult.result.data
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
if (decodeResult.error) {
|
|
121
|
-
console.error("Decode error:", decodeResult.error);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const decoded = JSON.parse(decodeResult.result);
|
|
126
|
-
console.log("\nDecoded Approval Event:");
|
|
127
|
-
console.log(" Owner:", decoded.owner);
|
|
128
|
-
console.log(" Spender:", decoded.spender);
|
|
129
|
-
console.log(" Value:", decoded.value);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Example 3: Event with All Non-Indexed Parameters
|
|
134
|
-
* ValueChanged(uint256 newValue, string message)
|
|
135
|
-
*/
|
|
136
|
-
async function example3_AllNonIndexedEvent() {
|
|
137
|
-
console.log("\n=== Example 3: All Non-Indexed Event ===");
|
|
138
|
-
|
|
139
|
-
const valueChangedABI = JSON.stringify([{
|
|
140
|
-
"name": "ValueChanged",
|
|
141
|
-
"type": "event",
|
|
142
|
-
"anonymous": false,
|
|
143
|
-
"inputs": [
|
|
144
|
-
{"name": "newValue", "type": "uint256", "indexed": false},
|
|
145
|
-
{"name": "message", "type": "string", "indexed": false}
|
|
146
|
-
]
|
|
147
|
-
}]);
|
|
148
|
-
|
|
149
|
-
const newValue = "42";
|
|
150
|
-
const message = "Hello, Quantum Coin!";
|
|
151
|
-
|
|
152
|
-
// Encode the event
|
|
153
|
-
const encodeResult = qcsdk.encodeEventLog(valueChangedABI, "ValueChanged", newValue, message);
|
|
154
|
-
|
|
155
|
-
if (encodeResult.error) {
|
|
156
|
-
console.error("Encode error:", encodeResult.error);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
console.log("Encoded ValueChanged Event:");
|
|
161
|
-
console.log(" Topics:", encodeResult.result.topics);
|
|
162
|
-
console.log(" Data:", encodeResult.result.data);
|
|
163
|
-
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
164
|
-
console.log(" Expected: 1 topic (event signature only)");
|
|
165
|
-
console.log(" Data contains both parameters");
|
|
166
|
-
|
|
167
|
-
// Decode the event back
|
|
168
|
-
const decodeResult = qcsdk.decodeEventLog(
|
|
169
|
-
valueChangedABI,
|
|
170
|
-
"ValueChanged",
|
|
171
|
-
encodeResult.result.topics,
|
|
172
|
-
encodeResult.result.data
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
if (decodeResult.error) {
|
|
176
|
-
console.error("Decode error:", decodeResult.error);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const decoded = JSON.parse(decodeResult.result);
|
|
181
|
-
console.log("\nDecoded ValueChanged Event:");
|
|
182
|
-
console.log(" New Value:", decoded.newValue);
|
|
183
|
-
console.log(" Message:", decoded.message);
|
|
184
|
-
console.log(" Verification:",
|
|
185
|
-
decoded.newValue === newValue &&
|
|
186
|
-
decoded.message === message ? "✓ Match" : "✗ Mismatch"
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Example 4: Event with Indexed String
|
|
192
|
-
* StringEvent(string indexed message)
|
|
193
|
-
* Note: Indexed strings are hashed, so we can't recover the original value
|
|
194
|
-
*/
|
|
195
|
-
async function example4_IndexedStringEvent() {
|
|
196
|
-
console.log("\n=== Example 4: Indexed String Event ===");
|
|
197
|
-
|
|
198
|
-
const stringEventABI = JSON.stringify([{
|
|
199
|
-
"name": "StringEvent",
|
|
200
|
-
"type": "event",
|
|
201
|
-
"anonymous": false,
|
|
202
|
-
"inputs": [
|
|
203
|
-
{"name": "message", "type": "string", "indexed": true}
|
|
204
|
-
]
|
|
205
|
-
}]);
|
|
206
|
-
|
|
207
|
-
const message = "Hello, World!";
|
|
208
|
-
|
|
209
|
-
// Encode the event
|
|
210
|
-
const encodeResult = qcsdk.encodeEventLog(stringEventABI, "StringEvent", message);
|
|
211
|
-
|
|
212
|
-
if (encodeResult.error) {
|
|
213
|
-
console.error("Encode error:", encodeResult.error);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
console.log("Encoded StringEvent:");
|
|
218
|
-
console.log(" Original message:", message);
|
|
219
|
-
console.log(" Topics:", encodeResult.result.topics);
|
|
220
|
-
console.log(" Data:", encodeResult.result.data);
|
|
221
|
-
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
222
|
-
console.log(" Expected: 2 topics (event signature + hashed string)");
|
|
223
|
-
|
|
224
|
-
// Decode the event back
|
|
225
|
-
const decodeResult = qcsdk.decodeEventLog(
|
|
226
|
-
stringEventABI,
|
|
227
|
-
"StringEvent",
|
|
228
|
-
encodeResult.result.topics,
|
|
229
|
-
encodeResult.result.data
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
if (decodeResult.error) {
|
|
233
|
-
console.error("Decode error:", decodeResult.error);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const decoded = JSON.parse(decodeResult.result);
|
|
238
|
-
console.log("\nDecoded StringEvent:");
|
|
239
|
-
console.log(" Message (hash):", decoded.message);
|
|
240
|
-
console.log(" Note: Indexed strings return the hash, not the original value");
|
|
241
|
-
console.log(" This is expected behavior for indexed dynamic types");
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Example 5: Anonymous Event
|
|
246
|
-
* AnonymousEvent(uint256 value)
|
|
247
|
-
*/
|
|
248
|
-
async function example5_AnonymousEvent() {
|
|
249
|
-
console.log("\n=== Example 5: Anonymous Event ===");
|
|
250
|
-
|
|
251
|
-
const anonymousABI = JSON.stringify([{
|
|
252
|
-
"name": "AnonymousEvent",
|
|
253
|
-
"type": "event",
|
|
254
|
-
"anonymous": true,
|
|
255
|
-
"inputs": [
|
|
256
|
-
{"name": "value", "type": "uint256", "indexed": false}
|
|
257
|
-
]
|
|
258
|
-
}]);
|
|
259
|
-
|
|
260
|
-
const value = "12345";
|
|
261
|
-
|
|
262
|
-
// Encode the event
|
|
263
|
-
const encodeResult = qcsdk.encodeEventLog(anonymousABI, "AnonymousEvent", value);
|
|
264
|
-
|
|
265
|
-
if (encodeResult.error) {
|
|
266
|
-
console.error("Encode error:", encodeResult.error);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
console.log("Encoded AnonymousEvent:");
|
|
271
|
-
console.log(" Topics:", encodeResult.result.topics);
|
|
272
|
-
console.log(" Data:", encodeResult.result.data);
|
|
273
|
-
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
274
|
-
console.log(" Expected: 0 topics (anonymous events have no signature topic)");
|
|
275
|
-
|
|
276
|
-
// Decode the event back
|
|
277
|
-
const decodeResult = qcsdk.decodeEventLog(
|
|
278
|
-
anonymousABI,
|
|
279
|
-
"AnonymousEvent",
|
|
280
|
-
encodeResult.result.topics,
|
|
281
|
-
encodeResult.result.data
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
if (decodeResult.error) {
|
|
285
|
-
console.error("Decode error:", decodeResult.error);
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const decoded = JSON.parse(decodeResult.result);
|
|
290
|
-
console.log("\nDecoded AnonymousEvent:");
|
|
291
|
-
console.log(" Value:", decoded.value);
|
|
292
|
-
console.log(" Verification:", decoded.value === value ? "✓ Match" : "✗ Mismatch");
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Example 6: Complex Event with Mixed Types
|
|
297
|
-
* ComplexEvent(address indexed owner, uint256 indexed tokenId, string name, uint256[] amounts)
|
|
298
|
-
*/
|
|
299
|
-
async function example6_ComplexEvent() {
|
|
300
|
-
console.log("\n=== Example 6: Complex Event with Mixed Types ===");
|
|
301
|
-
|
|
302
|
-
const complexABI = JSON.stringify([{
|
|
303
|
-
"name": "ComplexEvent",
|
|
304
|
-
"type": "event",
|
|
305
|
-
"anonymous": false,
|
|
306
|
-
"inputs": [
|
|
307
|
-
{"name": "owner", "type": "address", "indexed": true},
|
|
308
|
-
{"name": "tokenId", "type": "uint256", "indexed": true},
|
|
309
|
-
{"name": "name", "type": "string", "indexed": false},
|
|
310
|
-
{"name": "amounts", "type": "uint256[]", "indexed": false}
|
|
311
|
-
]
|
|
312
|
-
}]);
|
|
313
|
-
|
|
314
|
-
const owner = "0xd51773b5dde3f8e4d29ae42b5046510e2a11fd0c8e4175853d6227896eb445c6";
|
|
315
|
-
const tokenId = "1";
|
|
316
|
-
const name = "My Token";
|
|
317
|
-
const amounts = ["100", "200", "300"];
|
|
318
|
-
|
|
319
|
-
// Encode the event
|
|
320
|
-
const encodeResult = qcsdk.encodeEventLog(complexABI, "ComplexEvent", owner, tokenId, name, amounts);
|
|
321
|
-
|
|
322
|
-
if (encodeResult.error) {
|
|
323
|
-
console.error("Encode error:", encodeResult.error);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
console.log("Encoded ComplexEvent:");
|
|
328
|
-
console.log(" Topics:", encodeResult.result.topics);
|
|
329
|
-
console.log(" Data:", encodeResult.result.data);
|
|
330
|
-
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
331
|
-
console.log(" Expected: 3 topics (event signature + owner + tokenId)");
|
|
332
|
-
console.log(" Data contains name and amounts array");
|
|
333
|
-
|
|
334
|
-
// Decode the event back
|
|
335
|
-
const decodeResult = qcsdk.decodeEventLog(
|
|
336
|
-
complexABI,
|
|
337
|
-
"ComplexEvent",
|
|
338
|
-
encodeResult.result.topics,
|
|
339
|
-
encodeResult.result.data
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
if (decodeResult.error) {
|
|
343
|
-
console.error("Decode error:", decodeResult.error);
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const decoded = JSON.parse(decodeResult.result);
|
|
348
|
-
console.log("\nDecoded ComplexEvent:");
|
|
349
|
-
console.log(" Owner:", decoded.owner);
|
|
350
|
-
console.log(" Token ID:", decoded.tokenId);
|
|
351
|
-
console.log(" Name:", decoded.name);
|
|
352
|
-
console.log(" Amounts:", decoded.amounts);
|
|
353
|
-
console.log(" Verification:",
|
|
354
|
-
decoded.owner.toLowerCase() === owner.toLowerCase() &&
|
|
355
|
-
decoded.tokenId === tokenId &&
|
|
356
|
-
decoded.name === name &&
|
|
357
|
-
JSON.stringify(decoded.amounts) === JSON.stringify(amounts) ? "✓ Match" : "✗ Mismatch"
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Main function to run all examples
|
|
363
|
-
*/
|
|
364
|
-
async function runExamples() {
|
|
365
|
-
console.log("==========================================");
|
|
366
|
-
console.log("Event Log Encode/Decode Examples");
|
|
367
|
-
console.log("==========================================");
|
|
368
|
-
|
|
369
|
-
try {
|
|
370
|
-
// Initialize SDK
|
|
371
|
-
await qcsdk.initialize(clientConfigVal);
|
|
372
|
-
console.log("SDK initialized successfully");
|
|
373
|
-
|
|
374
|
-
// Run examples
|
|
375
|
-
await example1_TransferEvent();
|
|
376
|
-
await example2_AllIndexedEvent();
|
|
377
|
-
await example3_AllNonIndexedEvent();
|
|
378
|
-
await example4_IndexedStringEvent();
|
|
379
|
-
await example5_AnonymousEvent();
|
|
380
|
-
await example6_ComplexEvent();
|
|
381
|
-
|
|
382
|
-
console.log("\n==========================================");
|
|
383
|
-
console.log("All examples completed successfully!");
|
|
384
|
-
console.log("==========================================");
|
|
385
|
-
} catch (error) {
|
|
386
|
-
console.error("Error running examples:", error);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// Run the examples
|
|
391
|
-
runExamples().catch(console.error);
|