web-eth-abi 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +14 -0
- package/README.md +59 -0
- package/lib/commonjs/api/errors_api.d.ts +5 -0
- package/lib/commonjs/api/errors_api.js +44 -0
- package/lib/commonjs/api/errors_api.js.map +1 -0
- package/lib/commonjs/api/events_api.d.ts +51 -0
- package/lib/commonjs/api/events_api.js +90 -0
- package/lib/commonjs/api/events_api.js.map +1 -0
- package/lib/commonjs/api/functions_api.d.ts +92 -0
- package/lib/commonjs/api/functions_api.js +139 -0
- package/lib/commonjs/api/functions_api.js.map +1 -0
- package/lib/commonjs/api/logs_api.d.ts +49 -0
- package/lib/commonjs/api/logs_api.js +107 -0
- package/lib/commonjs/api/logs_api.js.map +1 -0
- package/lib/commonjs/api/parameters_api.d.ts +238 -0
- package/lib/commonjs/api/parameters_api.js +280 -0
- package/lib/commonjs/api/parameters_api.js.map +1 -0
- package/lib/commonjs/coders/base/address.d.ts +4 -0
- package/lib/commonjs/coders/base/address.js +75 -0
- package/lib/commonjs/coders/base/address.js.map +1 -0
- package/lib/commonjs/coders/base/array.d.ts +4 -0
- package/lib/commonjs/coders/base/array.js +106 -0
- package/lib/commonjs/coders/base/array.js.map +1 -0
- package/lib/commonjs/coders/base/bool.d.ts +4 -0
- package/lib/commonjs/coders/base/bool.js +56 -0
- package/lib/commonjs/coders/base/bool.js.map +1 -0
- package/lib/commonjs/coders/base/bytes.d.ts +4 -0
- package/lib/commonjs/coders/base/bytes.js +101 -0
- package/lib/commonjs/coders/base/bytes.js.map +1 -0
- package/lib/commonjs/coders/base/index.d.ts +11 -0
- package/lib/commonjs/coders/base/index.js +109 -0
- package/lib/commonjs/coders/base/index.js.map +1 -0
- package/lib/commonjs/coders/base/number.d.ts +4 -0
- package/lib/commonjs/coders/base/number.js +116 -0
- package/lib/commonjs/coders/base/number.js.map +1 -0
- package/lib/commonjs/coders/base/numbersLimits.d.ts +4 -0
- package/lib/commonjs/coders/base/numbersLimits.js +40 -0
- package/lib/commonjs/coders/base/numbersLimits.js.map +1 -0
- package/lib/commonjs/coders/base/string.d.ts +4 -0
- package/lib/commonjs/coders/base/string.js +40 -0
- package/lib/commonjs/coders/base/string.js.map +1 -0
- package/lib/commonjs/coders/base/tuple.d.ts +7 -0
- package/lib/commonjs/coders/base/tuple.js +123 -0
- package/lib/commonjs/coders/base/tuple.js.map +1 -0
- package/lib/commonjs/coders/base/utils.d.ts +2 -0
- package/lib/commonjs/coders/base/utils.js +50 -0
- package/lib/commonjs/coders/base/utils.js.map +1 -0
- package/lib/commonjs/coders/decode.d.ts +5 -0
- package/lib/commonjs/coders/decode.js +29 -0
- package/lib/commonjs/coders/decode.js.map +1 -0
- package/lib/commonjs/coders/encode.d.ts +38 -0
- package/lib/commonjs/coders/encode.js +113 -0
- package/lib/commonjs/coders/encode.js.map +1 -0
- package/lib/commonjs/coders/types.d.ts +16 -0
- package/lib/commonjs/coders/types.js +19 -0
- package/lib/commonjs/coders/types.js.map +1 -0
- package/lib/commonjs/coders/utils.d.ts +23 -0
- package/lib/commonjs/coders/utils.js +115 -0
- package/lib/commonjs/coders/utils.js.map +1 -0
- package/lib/commonjs/decode_contract_error_data.d.ts +3 -0
- package/lib/commonjs/decode_contract_error_data.js +73 -0
- package/lib/commonjs/decode_contract_error_data.js.map +1 -0
- package/lib/commonjs/eip_712.d.ts +50 -0
- package/lib/commonjs/eip_712.js +144 -0
- package/lib/commonjs/eip_712.js.map +1 -0
- package/lib/commonjs/index.d.ts +8 -0
- package/lib/commonjs/index.js +43 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils.d.ts +43 -0
- package/lib/commonjs/utils.js +216 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/esm/api/errors_api.js +40 -0
- package/lib/esm/api/errors_api.js.map +1 -0
- package/lib/esm/api/events_api.js +86 -0
- package/lib/esm/api/events_api.js.map +1 -0
- package/lib/esm/api/functions_api.js +134 -0
- package/lib/esm/api/functions_api.js.map +1 -0
- package/lib/esm/api/logs_api.js +103 -0
- package/lib/esm/api/logs_api.js.map +1 -0
- package/lib/esm/api/parameters_api.js +271 -0
- package/lib/esm/api/parameters_api.js.map +1 -0
- package/lib/esm/coders/base/address.js +70 -0
- package/lib/esm/coders/base/address.js.map +1 -0
- package/lib/esm/coders/base/array.js +101 -0
- package/lib/esm/coders/base/array.js.map +1 -0
- package/lib/esm/coders/base/bool.js +51 -0
- package/lib/esm/coders/base/bool.js.map +1 -0
- package/lib/esm/coders/base/bytes.js +96 -0
- package/lib/esm/coders/base/bytes.js.map +1 -0
- package/lib/esm/coders/base/index.js +90 -0
- package/lib/esm/coders/base/index.js.map +1 -0
- package/lib/esm/coders/base/number.js +111 -0
- package/lib/esm/coders/base/number.js.map +1 -0
- package/lib/esm/coders/base/numbersLimits.js +37 -0
- package/lib/esm/coders/base/numbersLimits.js.map +1 -0
- package/lib/esm/coders/base/string.js +35 -0
- package/lib/esm/coders/base/string.js.map +1 -0
- package/lib/esm/coders/base/tuple.js +118 -0
- package/lib/esm/coders/base/tuple.js.map +1 -0
- package/lib/esm/coders/base/utils.js +46 -0
- package/lib/esm/coders/base/utils.js.map +1 -0
- package/lib/esm/coders/decode.js +25 -0
- package/lib/esm/coders/decode.js.map +1 -0
- package/lib/esm/coders/encode.js +108 -0
- package/lib/esm/coders/encode.js.map +1 -0
- package/lib/esm/coders/types.js +18 -0
- package/lib/esm/coders/types.js.map +1 -0
- package/lib/esm/coders/utils.js +105 -0
- package/lib/esm/coders/utils.js.map +1 -0
- package/lib/esm/decode_contract_error_data.js +69 -0
- package/lib/esm/decode_contract_error_data.js.map +1 -0
- package/lib/esm/eip_712.js +140 -0
- package/lib/esm/eip_712.js.map +1 -0
- package/lib/esm/index.js +25 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/utils.js +199 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/types/api/errors_api.d.ts +6 -0
- package/lib/types/api/errors_api.d.ts.map +1 -0
- package/lib/types/api/events_api.d.ts +52 -0
- package/lib/types/api/events_api.d.ts.map +1 -0
- package/lib/types/api/functions_api.d.ts +93 -0
- package/lib/types/api/functions_api.d.ts.map +1 -0
- package/lib/types/api/logs_api.d.ts +50 -0
- package/lib/types/api/logs_api.d.ts.map +1 -0
- package/lib/types/api/parameters_api.d.ts +239 -0
- package/lib/types/api/parameters_api.d.ts.map +1 -0
- package/lib/types/coders/base/address.d.ts +5 -0
- package/lib/types/coders/base/address.d.ts.map +1 -0
- package/lib/types/coders/base/array.d.ts +5 -0
- package/lib/types/coders/base/array.d.ts.map +1 -0
- package/lib/types/coders/base/bool.d.ts +5 -0
- package/lib/types/coders/base/bool.d.ts.map +1 -0
- package/lib/types/coders/base/bytes.d.ts +5 -0
- package/lib/types/coders/base/bytes.d.ts.map +1 -0
- package/lib/types/coders/base/index.d.ts +12 -0
- package/lib/types/coders/base/index.d.ts.map +1 -0
- package/lib/types/coders/base/number.d.ts +5 -0
- package/lib/types/coders/base/number.d.ts.map +1 -0
- package/lib/types/coders/base/numbersLimits.d.ts +5 -0
- package/lib/types/coders/base/numbersLimits.d.ts.map +1 -0
- package/lib/types/coders/base/string.d.ts +5 -0
- package/lib/types/coders/base/string.d.ts.map +1 -0
- package/lib/types/coders/base/tuple.d.ts +8 -0
- package/lib/types/coders/base/tuple.d.ts.map +1 -0
- package/lib/types/coders/base/utils.d.ts +3 -0
- package/lib/types/coders/base/utils.d.ts.map +1 -0
- package/lib/types/coders/decode.d.ts +6 -0
- package/lib/types/coders/decode.d.ts.map +1 -0
- package/lib/types/coders/encode.d.ts +39 -0
- package/lib/types/coders/encode.d.ts.map +1 -0
- package/lib/types/coders/types.d.ts +17 -0
- package/lib/types/coders/types.d.ts.map +1 -0
- package/lib/types/coders/utils.d.ts +24 -0
- package/lib/types/coders/utils.d.ts.map +1 -0
- package/lib/types/decode_contract_error_data.d.ts +4 -0
- package/lib/types/decode_contract_error_data.d.ts.map +1 -0
- package/lib/types/eip_712.d.ts +51 -0
- package/lib/types/eip_712.d.ts.map +1 -0
- package/lib/types/index.d.ts +9 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/utils.d.ts +44 -0
- package/lib/types/utils.d.ts.map +1 -0
- package/package.json +56 -0
- package/src/api/errors_api.ts +45 -0
- package/src/api/events_api.ts +91 -0
- package/src/api/functions_api.ts +145 -0
- package/src/api/logs_api.ts +131 -0
- package/src/api/parameters_api.ts +287 -0
- package/src/coders/base/address.ts +75 -0
- package/src/coders/base/array.ts +120 -0
- package/src/coders/base/bool.ts +54 -0
- package/src/coders/base/bytes.ts +106 -0
- package/src/coders/base/index.ts +95 -0
- package/src/coders/base/number.ts +116 -0
- package/src/coders/base/numbersLimits.ts +39 -0
- package/src/coders/base/string.ts +38 -0
- package/src/coders/base/tuple.ts +130 -0
- package/src/coders/base/utils.ts +51 -0
- package/src/coders/decode.ts +32 -0
- package/src/coders/encode.ts +114 -0
- package/src/coders/types.ts +39 -0
- package/src/coders/utils.ts +128 -0
- package/src/decode_contract_error_data.ts +80 -0
- package/src/eip_712.ts +252 -0
- package/src/index.ts +25 -0
- package/src/utils.ts +266 -0
- package/wimho03d.cjs +1 -0
package/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
This file is part of web3.js.
|
2
|
+
|
3
|
+
web3.js is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
web3.js is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU Lesser General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU Lesser General Public License
|
14
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
package/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="assets/logo/web3js.jpg" width="500" alt="web3.js" />
|
3
|
+
</p>
|
4
|
+
|
5
|
+
# web3.js - Web3-Eth-Abi
|
6
|
+
|
7
|
+
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
|
8
|
+
![Node Version](https://img.shields.io/badge/node-14.x-green)
|
9
|
+
[![NPM Package][npm-image]][npm-url]
|
10
|
+
[![Downloads][downloads-image]][npm-url]
|
11
|
+
|
12
|
+
This is a sub-package of [web3.js][repo].
|
13
|
+
|
14
|
+
`web3-eth-abi` contains functions for the encode and decode EVM in/output.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
You can install the package either using [NPM](https://www.npmjs.com/package/web3-eth-abi) or using [Yarn](https://yarnpkg.com/package/web3-eth-abi)
|
19
|
+
|
20
|
+
### Using NPM
|
21
|
+
|
22
|
+
```bash
|
23
|
+
npm install web3-eth-abi
|
24
|
+
```
|
25
|
+
|
26
|
+
### Using Yarn
|
27
|
+
|
28
|
+
```bash
|
29
|
+
yarn add web3-eth-abi
|
30
|
+
```
|
31
|
+
|
32
|
+
## Getting Started
|
33
|
+
|
34
|
+
- :writing_hand: If you have questions [submit an issue](https://github.com/ChainSafe/web3.js/issues/new) or join us on [Discord](https://discord.gg/yjyvFRP)
|
35
|
+
![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)
|
36
|
+
|
37
|
+
## Prerequisites
|
38
|
+
|
39
|
+
- :gear: [NodeJS](https://nodejs.org/) (LTS/Fermium)
|
40
|
+
- :toolbox: [Yarn](https://yarnpkg.com/)/[Lerna](https://lerna.js.org/)
|
41
|
+
|
42
|
+
## Package.json Scripts
|
43
|
+
|
44
|
+
| Script | Description |
|
45
|
+
| ---------------- | -------------------------------------------------- |
|
46
|
+
| clean | Uses `rimraf` to remove `dist/` |
|
47
|
+
| build | Uses `tsc` to build package and dependent packages |
|
48
|
+
| lint | Uses `eslint` to lint package |
|
49
|
+
| lint:fix | Uses `eslint` to check and fix any warnings |
|
50
|
+
| format | Uses `prettier` to format the code |
|
51
|
+
| test | Uses `jest` to run unit tests |
|
52
|
+
| test:integration | Uses `jest` to run tests under `/test/integration` |
|
53
|
+
| test:unit | Uses `jest` to run tests under `/test/unit` |
|
54
|
+
|
55
|
+
[docs]: https://docs.web3js.org/
|
56
|
+
[repo]: https://github.com/web3/web3.js/tree/4.x/packages/web3-eth-abi
|
57
|
+
[npm-image]: https://img.shields.io/github/package-json/v/web3/web3.js/4.x?filename=packages%2Fweb3-eth-abi%2Fpackage.json
|
58
|
+
[npm-url]: https://npmjs.org/package/web3-eth-abi
|
59
|
+
[downloads-image]: https://img.shields.io/npm/dm/web3-eth-abi?label=npm%20downloads
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.encodeErrorSignature = void 0;
|
20
|
+
/**
|
21
|
+
*
|
22
|
+
* @module ABI
|
23
|
+
*/
|
24
|
+
const web3_utils_1 = require("web3-utils");
|
25
|
+
const web3_errors_1 = require("web3-errors");
|
26
|
+
const utils_js_1 = require("../utils.js");
|
27
|
+
/**
|
28
|
+
* Encodes the error name to its ABI signature, which are the sha3 hash of the error name including input types.
|
29
|
+
*/
|
30
|
+
const encodeErrorSignature = (functionName) => {
|
31
|
+
if (typeof functionName !== 'string' && !(0, utils_js_1.isAbiErrorFragment)(functionName)) {
|
32
|
+
throw new web3_errors_1.AbiError('Invalid parameter value in encodeErrorSignature');
|
33
|
+
}
|
34
|
+
let name;
|
35
|
+
if (functionName && (typeof functionName === 'function' || typeof functionName === 'object')) {
|
36
|
+
name = (0, utils_js_1.jsonInterfaceMethodToString)(functionName);
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
name = functionName;
|
40
|
+
}
|
41
|
+
return (0, web3_utils_1.sha3Raw)(name);
|
42
|
+
};
|
43
|
+
exports.encodeErrorSignature = encodeErrorSignature;
|
44
|
+
//# sourceMappingURL=errors_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors_api.js","sourceRoot":"","sources":["../../../src/api/errors_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;;GAGG;AAEH,2CAAqC;AACrC,6CAAuC;AAEvC,0CAA8E;AAE9E;;GAEG;AACI,MAAM,oBAAoB,GAAG,CAAC,YAAuC,EAAU,EAAE;IACvF,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,IAAA,6BAAkB,EAAC,YAAY,CAAC,EAAE;QAC1E,MAAM,IAAI,sBAAQ,CAAC,iDAAiD,CAAC,CAAC;KACtE;IAED,IAAI,IAAY,CAAC;IAEjB,IAAI,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,UAAU,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE;QAC7F,IAAI,GAAG,IAAA,sCAA2B,EAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACN,IAAI,GAAG,YAAY,CAAC;KACpB;IAED,OAAO,IAAA,oBAAO,EAAC,IAAI,CAAC,CAAC;AACtB,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B"}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { AbiEventFragment } from 'web3-types';
|
2
|
+
/**
|
3
|
+
* Encodes the event name to its ABI signature, which are the sha3 hash of the event name including input types.
|
4
|
+
* @param functionName - The event name to encode, or the {@link AbiEventFragment} object of the event. If string, it has to be in the form of `eventName(param1Type,param2Type,...)`. eg: myEvent(uint256,bytes32).
|
5
|
+
* @returns - The ABI signature of the event.
|
6
|
+
*
|
7
|
+
* @example
|
8
|
+
* ```ts
|
9
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
10
|
+
* name: "myEvent",
|
11
|
+
* type: "event",
|
12
|
+
* inputs: [
|
13
|
+
* {
|
14
|
+
* type: "uint256",
|
15
|
+
* name: "myNumber",
|
16
|
+
* },
|
17
|
+
* {
|
18
|
+
* type: "bytes32",
|
19
|
+
* name: "myBytes",
|
20
|
+
* },
|
21
|
+
* ],
|
22
|
+
* });
|
23
|
+
* console.log(event);
|
24
|
+
* > 0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97
|
25
|
+
*
|
26
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
27
|
+
* inputs: [
|
28
|
+
* {
|
29
|
+
* indexed: true,
|
30
|
+
* name: "from",
|
31
|
+
* type: "address",
|
32
|
+
* },
|
33
|
+
* {
|
34
|
+
* indexed: true,
|
35
|
+
* name: "to",
|
36
|
+
* type: "address",
|
37
|
+
* },
|
38
|
+
* {
|
39
|
+
* indexed: false,
|
40
|
+
* name: "value",
|
41
|
+
* type: "uint256",
|
42
|
+
* },
|
43
|
+
* ],
|
44
|
+
* name: "Transfer",
|
45
|
+
* type: "event",
|
46
|
+
* });
|
47
|
+
* console.log(event);
|
48
|
+
* > 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
|
49
|
+
* ```
|
50
|
+
*/
|
51
|
+
export declare const encodeEventSignature: (functionName: string | AbiEventFragment) => string;
|
@@ -0,0 +1,90 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.encodeEventSignature = void 0;
|
20
|
+
/**
|
21
|
+
*
|
22
|
+
* @module ABI
|
23
|
+
*/
|
24
|
+
const web3_utils_1 = require("web3-utils");
|
25
|
+
const web3_errors_1 = require("web3-errors");
|
26
|
+
const utils_js_1 = require("../utils.js");
|
27
|
+
/**
|
28
|
+
* Encodes the event name to its ABI signature, which are the sha3 hash of the event name including input types.
|
29
|
+
* @param functionName - The event name to encode, or the {@link AbiEventFragment} object of the event. If string, it has to be in the form of `eventName(param1Type,param2Type,...)`. eg: myEvent(uint256,bytes32).
|
30
|
+
* @returns - The ABI signature of the event.
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* ```ts
|
34
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
35
|
+
* name: "myEvent",
|
36
|
+
* type: "event",
|
37
|
+
* inputs: [
|
38
|
+
* {
|
39
|
+
* type: "uint256",
|
40
|
+
* name: "myNumber",
|
41
|
+
* },
|
42
|
+
* {
|
43
|
+
* type: "bytes32",
|
44
|
+
* name: "myBytes",
|
45
|
+
* },
|
46
|
+
* ],
|
47
|
+
* });
|
48
|
+
* console.log(event);
|
49
|
+
* > 0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97
|
50
|
+
*
|
51
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
52
|
+
* inputs: [
|
53
|
+
* {
|
54
|
+
* indexed: true,
|
55
|
+
* name: "from",
|
56
|
+
* type: "address",
|
57
|
+
* },
|
58
|
+
* {
|
59
|
+
* indexed: true,
|
60
|
+
* name: "to",
|
61
|
+
* type: "address",
|
62
|
+
* },
|
63
|
+
* {
|
64
|
+
* indexed: false,
|
65
|
+
* name: "value",
|
66
|
+
* type: "uint256",
|
67
|
+
* },
|
68
|
+
* ],
|
69
|
+
* name: "Transfer",
|
70
|
+
* type: "event",
|
71
|
+
* });
|
72
|
+
* console.log(event);
|
73
|
+
* > 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
|
74
|
+
* ```
|
75
|
+
*/
|
76
|
+
const encodeEventSignature = (functionName) => {
|
77
|
+
if (typeof functionName !== 'string' && !(0, utils_js_1.isAbiEventFragment)(functionName)) {
|
78
|
+
throw new web3_errors_1.AbiError('Invalid parameter value in encodeEventSignature');
|
79
|
+
}
|
80
|
+
let name;
|
81
|
+
if (functionName && (typeof functionName === 'function' || typeof functionName === 'object')) {
|
82
|
+
name = (0, utils_js_1.jsonInterfaceMethodToString)(functionName);
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
name = functionName;
|
86
|
+
}
|
87
|
+
return (0, web3_utils_1.sha3Raw)(name);
|
88
|
+
};
|
89
|
+
exports.encodeEventSignature = encodeEventSignature;
|
90
|
+
//# sourceMappingURL=events_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"events_api.js","sourceRoot":"","sources":["../../../src/api/events_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;;GAGG;AAEH,2CAAqC;AACrC,6CAAuC;AAEvC,0CAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACI,MAAM,oBAAoB,GAAG,CAAC,YAAuC,EAAU,EAAE;IACvF,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,IAAA,6BAAkB,EAAC,YAAY,CAAC,EAAE;QAC1E,MAAM,IAAI,sBAAQ,CAAC,iDAAiD,CAAC,CAAC;KACtE;IAED,IAAI,IAAY,CAAC;IAEjB,IAAI,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,UAAU,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE;QAC7F,IAAI,GAAG,IAAA,sCAA2B,EAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACN,IAAI,GAAG,YAAY,CAAC;KACpB;IAED,OAAO,IAAA,oBAAO,EAAC,IAAI,CAAC,CAAC;AACtB,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B"}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
import { AbiFunctionFragment } from 'web3-types';
|
2
|
+
/**
|
3
|
+
* Encodes the function name to its ABI representation, which are the first 4 bytes of the sha3 of the function name including types.
|
4
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
5
|
+
* @param functionName - The function name to encode or the `JSON interface` object of the function.
|
6
|
+
* If the passed parameter is a string, it has to be in the form of `functionName(param1Type,param2Type,...)`. eg: myFunction(uint256,uint32[],bytes10,bytes)
|
7
|
+
* @returns - The ABI signature of the function.
|
8
|
+
* @example
|
9
|
+
* ```ts
|
10
|
+
* const signature = web3.eth.abi.encodeFunctionSignature({
|
11
|
+
* name: "myMethod",
|
12
|
+
* type: "function",
|
13
|
+
* inputs: [
|
14
|
+
* {
|
15
|
+
* type: "uint256",
|
16
|
+
* name: "myNumber",
|
17
|
+
* },
|
18
|
+
* {
|
19
|
+
* type: "string",
|
20
|
+
* name: "myString",
|
21
|
+
* },
|
22
|
+
* ],
|
23
|
+
* });
|
24
|
+
* console.log(signature);
|
25
|
+
* > 0x24ee0097
|
26
|
+
*
|
27
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
|
28
|
+
* console.log(signature);
|
29
|
+
* > 0x24ee0097
|
30
|
+
*
|
31
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('safeTransferFrom(address,address,uint256,bytes)');
|
32
|
+
* console.log(signature);
|
33
|
+
* > 0xb88d4fde
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
export declare const encodeFunctionSignature: (functionName: string | AbiFunctionFragment) => string;
|
37
|
+
/**
|
38
|
+
* Encodes a function call using its `JSON interface` object and given parameters.
|
39
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
40
|
+
* @param jsonInterface - The `JSON interface` object of the function.
|
41
|
+
* @param params - The parameters to encode
|
42
|
+
* @returns - The ABI encoded function call, which, means the function signature and the parameters passed.
|
43
|
+
* @example
|
44
|
+
* ```ts
|
45
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
46
|
+
* {
|
47
|
+
* name: "myMethod",
|
48
|
+
* type: "function",
|
49
|
+
* inputs: [
|
50
|
+
* {
|
51
|
+
* type: "uint256",
|
52
|
+
* name: "myNumber",
|
53
|
+
* },
|
54
|
+
* {
|
55
|
+
* type: "string",
|
56
|
+
* name: "myString",
|
57
|
+
* },
|
58
|
+
* ],
|
59
|
+
* },
|
60
|
+
* ["2345675643", "Hello!%"]
|
61
|
+
* );
|
62
|
+
* console.log(sig);
|
63
|
+
* > 0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
|
64
|
+
*
|
65
|
+
*
|
66
|
+
*
|
67
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
68
|
+
* {
|
69
|
+
* inputs: [
|
70
|
+
* {
|
71
|
+
* name: "account",
|
72
|
+
* type: "address",
|
73
|
+
* },
|
74
|
+
* ],
|
75
|
+
* name: "balanceOf",
|
76
|
+
* outputs: [
|
77
|
+
* {
|
78
|
+
* name: "",
|
79
|
+
* type: "uint256",
|
80
|
+
* },
|
81
|
+
* ],
|
82
|
+
* stateMutability: "view",
|
83
|
+
* type: "function",
|
84
|
+
* },
|
85
|
+
* ["0x1234567890123456789012345678901234567890"]
|
86
|
+
* );
|
87
|
+
*
|
88
|
+
* console.log(sig);
|
89
|
+
* > 0x70a082310000000000000000000000001234567890123456789012345678901234567890
|
90
|
+
* ```
|
91
|
+
*/
|
92
|
+
export declare const encodeFunctionCall: (jsonInterface: AbiFunctionFragment, params: unknown[]) => string;
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.encodeFunctionCall = exports.encodeFunctionSignature = void 0;
|
20
|
+
/**
|
21
|
+
*
|
22
|
+
* @module ABI
|
23
|
+
*/
|
24
|
+
const web3_errors_1 = require("web3-errors");
|
25
|
+
const web3_utils_1 = require("web3-utils");
|
26
|
+
const utils_js_1 = require("../utils.js");
|
27
|
+
const parameters_api_js_1 = require("./parameters_api.js");
|
28
|
+
/**
|
29
|
+
* Encodes the function name to its ABI representation, which are the first 4 bytes of the sha3 of the function name including types.
|
30
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
31
|
+
* @param functionName - The function name to encode or the `JSON interface` object of the function.
|
32
|
+
* If the passed parameter is a string, it has to be in the form of `functionName(param1Type,param2Type,...)`. eg: myFunction(uint256,uint32[],bytes10,bytes)
|
33
|
+
* @returns - The ABI signature of the function.
|
34
|
+
* @example
|
35
|
+
* ```ts
|
36
|
+
* const signature = web3.eth.abi.encodeFunctionSignature({
|
37
|
+
* name: "myMethod",
|
38
|
+
* type: "function",
|
39
|
+
* inputs: [
|
40
|
+
* {
|
41
|
+
* type: "uint256",
|
42
|
+
* name: "myNumber",
|
43
|
+
* },
|
44
|
+
* {
|
45
|
+
* type: "string",
|
46
|
+
* name: "myString",
|
47
|
+
* },
|
48
|
+
* ],
|
49
|
+
* });
|
50
|
+
* console.log(signature);
|
51
|
+
* > 0x24ee0097
|
52
|
+
*
|
53
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
|
54
|
+
* console.log(signature);
|
55
|
+
* > 0x24ee0097
|
56
|
+
*
|
57
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('safeTransferFrom(address,address,uint256,bytes)');
|
58
|
+
* console.log(signature);
|
59
|
+
* > 0xb88d4fde
|
60
|
+
* ```
|
61
|
+
*/
|
62
|
+
const encodeFunctionSignature = (functionName) => {
|
63
|
+
if (typeof functionName !== 'string' && !(0, utils_js_1.isAbiFunctionFragment)(functionName)) {
|
64
|
+
throw new web3_errors_1.AbiError('Invalid parameter value in encodeFunctionSignature');
|
65
|
+
}
|
66
|
+
let name;
|
67
|
+
if (functionName && (typeof functionName === 'function' || typeof functionName === 'object')) {
|
68
|
+
name = (0, utils_js_1.jsonInterfaceMethodToString)(functionName);
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
name = functionName;
|
72
|
+
}
|
73
|
+
return (0, web3_utils_1.sha3Raw)(name).slice(0, 10);
|
74
|
+
};
|
75
|
+
exports.encodeFunctionSignature = encodeFunctionSignature;
|
76
|
+
/**
|
77
|
+
* Encodes a function call using its `JSON interface` object and given parameters.
|
78
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
79
|
+
* @param jsonInterface - The `JSON interface` object of the function.
|
80
|
+
* @param params - The parameters to encode
|
81
|
+
* @returns - The ABI encoded function call, which, means the function signature and the parameters passed.
|
82
|
+
* @example
|
83
|
+
* ```ts
|
84
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
85
|
+
* {
|
86
|
+
* name: "myMethod",
|
87
|
+
* type: "function",
|
88
|
+
* inputs: [
|
89
|
+
* {
|
90
|
+
* type: "uint256",
|
91
|
+
* name: "myNumber",
|
92
|
+
* },
|
93
|
+
* {
|
94
|
+
* type: "string",
|
95
|
+
* name: "myString",
|
96
|
+
* },
|
97
|
+
* ],
|
98
|
+
* },
|
99
|
+
* ["2345675643", "Hello!%"]
|
100
|
+
* );
|
101
|
+
* console.log(sig);
|
102
|
+
* > 0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
|
103
|
+
*
|
104
|
+
*
|
105
|
+
*
|
106
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
107
|
+
* {
|
108
|
+
* inputs: [
|
109
|
+
* {
|
110
|
+
* name: "account",
|
111
|
+
* type: "address",
|
112
|
+
* },
|
113
|
+
* ],
|
114
|
+
* name: "balanceOf",
|
115
|
+
* outputs: [
|
116
|
+
* {
|
117
|
+
* name: "",
|
118
|
+
* type: "uint256",
|
119
|
+
* },
|
120
|
+
* ],
|
121
|
+
* stateMutability: "view",
|
122
|
+
* type: "function",
|
123
|
+
* },
|
124
|
+
* ["0x1234567890123456789012345678901234567890"]
|
125
|
+
* );
|
126
|
+
*
|
127
|
+
* console.log(sig);
|
128
|
+
* > 0x70a082310000000000000000000000001234567890123456789012345678901234567890
|
129
|
+
* ```
|
130
|
+
*/
|
131
|
+
const encodeFunctionCall = (jsonInterface, params) => {
|
132
|
+
var _a;
|
133
|
+
if (!(0, utils_js_1.isAbiFunctionFragment)(jsonInterface)) {
|
134
|
+
throw new web3_errors_1.AbiError('Invalid parameter value in encodeFunctionCall');
|
135
|
+
}
|
136
|
+
return `${(0, exports.encodeFunctionSignature)(jsonInterface)}${(0, parameters_api_js_1.encodeParameters)((_a = jsonInterface.inputs) !== null && _a !== void 0 ? _a : [], params !== null && params !== void 0 ? params : []).replace('0x', '')}`;
|
137
|
+
};
|
138
|
+
exports.encodeFunctionCall = encodeFunctionCall;
|
139
|
+
//# sourceMappingURL=functions_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"functions_api.js","sourceRoot":"","sources":["../../../src/api/functions_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;;GAGG;AACH,6CAAuC;AACvC,2CAAqC;AAErC,0CAAiF;AACjF,2DAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,MAAM,uBAAuB,GAAG,CAAC,YAA0C,EAAU,EAAE;IAC7F,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,IAAA,gCAAqB,EAAC,YAAY,CAAC,EAAE;QAC7E,MAAM,IAAI,sBAAQ,CAAC,oDAAoD,CAAC,CAAC;KACzE;IAED,IAAI,IAAY,CAAC;IAEjB,IAAI,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,UAAU,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE;QAC7F,IAAI,GAAG,IAAA,sCAA2B,EAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACN,IAAI,GAAG,YAAY,CAAC;KACpB;IAED,OAAO,IAAA,oBAAO,EAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;AAdW,QAAA,uBAAuB,2BAclC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACI,MAAM,kBAAkB,GAAG,CACjC,aAAkC,EAClC,MAAiB,EACR,EAAE;;IACX,IAAI,CAAC,IAAA,gCAAqB,EAAC,aAAa,CAAC,EAAE;QAC1C,MAAM,IAAI,sBAAQ,CAAC,+CAA+C,CAAC,CAAC;KACpE;IAED,OAAO,GAAG,IAAA,+BAAuB,EAAC,aAAa,CAAC,GAAG,IAAA,oCAAgB,EAClE,MAAA,aAAa,CAAC,MAAM,mCAAI,EAAE,EAC1B,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CACZ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;AACvB,CAAC,CAAC;AAZW,QAAA,kBAAkB,sBAY7B"}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* @module ABI
|
4
|
+
*/
|
5
|
+
import { HexString, AbiParameter, DecodedParams } from 'web3-types';
|
6
|
+
/**
|
7
|
+
* Decodes ABI-encoded log data and indexed topic data.
|
8
|
+
* @param inputs - A {@link AbiParameter} input array. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
9
|
+
* @param data - The ABI byte code in the `data` field of a log.
|
10
|
+
* @param topics - An array with the index parameter topics of the log, without the topic[0] if its a non-anonymous event, otherwise with topic[0]
|
11
|
+
* @returns - The result object containing the decoded parameters.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* ```ts
|
15
|
+
* let res = web3.eth.abi.decodeLog(
|
16
|
+
* [
|
17
|
+
* {
|
18
|
+
* type: "string",
|
19
|
+
* name: "myString",
|
20
|
+
* },
|
21
|
+
* {
|
22
|
+
* type: "uint256",
|
23
|
+
* name: "myNumber",
|
24
|
+
* indexed: true,
|
25
|
+
* },
|
26
|
+
* {
|
27
|
+
* type: "uint8",
|
28
|
+
* name: "mySmallNumber",
|
29
|
+
* indexed: true,
|
30
|
+
* },
|
31
|
+
* ],
|
32
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000748656c6c6f252100000000000000000000000000000000000000000000000000",
|
33
|
+
* [
|
34
|
+
* "0x000000000000000000000000000000000000000000000000000000000000f310",
|
35
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000010",
|
36
|
+
* ]
|
37
|
+
* );
|
38
|
+
* > {
|
39
|
+
* '0': 'Hello%!',
|
40
|
+
* '1': 62224n,
|
41
|
+
* '2': 16n,
|
42
|
+
* __length__: 3,
|
43
|
+
* myString: 'Hello%!',
|
44
|
+
* myNumber: 62224n,
|
45
|
+
* mySmallNumber: 16n
|
46
|
+
* }
|
47
|
+
* ```
|
48
|
+
*/
|
49
|
+
export declare const decodeLog: <ReturnType_1 extends DecodedParams>(inputs: Array<AbiParameter> | ReadonlyArray<AbiParameter>, data: HexString, topics: string | string[]) => ReturnType_1;
|
@@ -0,0 +1,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.decodeLog = void 0;
|
20
|
+
const parameters_api_js_1 = require("./parameters_api.js");
|
21
|
+
const STATIC_TYPES = ['bool', 'string', 'int', 'uint', 'address', 'fixed', 'ufixed'];
|
22
|
+
const _decodeParameter = (inputType, clonedTopic) => inputType === 'string' ? clonedTopic : (0, parameters_api_js_1.decodeParameter)(inputType, clonedTopic);
|
23
|
+
/**
|
24
|
+
* Decodes ABI-encoded log data and indexed topic data.
|
25
|
+
* @param inputs - A {@link AbiParameter} input array. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
26
|
+
* @param data - The ABI byte code in the `data` field of a log.
|
27
|
+
* @param topics - An array with the index parameter topics of the log, without the topic[0] if its a non-anonymous event, otherwise with topic[0]
|
28
|
+
* @returns - The result object containing the decoded parameters.
|
29
|
+
*
|
30
|
+
* @example
|
31
|
+
* ```ts
|
32
|
+
* let res = web3.eth.abi.decodeLog(
|
33
|
+
* [
|
34
|
+
* {
|
35
|
+
* type: "string",
|
36
|
+
* name: "myString",
|
37
|
+
* },
|
38
|
+
* {
|
39
|
+
* type: "uint256",
|
40
|
+
* name: "myNumber",
|
41
|
+
* indexed: true,
|
42
|
+
* },
|
43
|
+
* {
|
44
|
+
* type: "uint8",
|
45
|
+
* name: "mySmallNumber",
|
46
|
+
* indexed: true,
|
47
|
+
* },
|
48
|
+
* ],
|
49
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000748656c6c6f252100000000000000000000000000000000000000000000000000",
|
50
|
+
* [
|
51
|
+
* "0x000000000000000000000000000000000000000000000000000000000000f310",
|
52
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000010",
|
53
|
+
* ]
|
54
|
+
* );
|
55
|
+
* > {
|
56
|
+
* '0': 'Hello%!',
|
57
|
+
* '1': 62224n,
|
58
|
+
* '2': 16n,
|
59
|
+
* __length__: 3,
|
60
|
+
* myString: 'Hello%!',
|
61
|
+
* myNumber: 62224n,
|
62
|
+
* mySmallNumber: 16n
|
63
|
+
* }
|
64
|
+
* ```
|
65
|
+
*/
|
66
|
+
const decodeLog = (inputs, data, topics) => {
|
67
|
+
const clonedTopics = Array.isArray(topics) ? topics : [topics];
|
68
|
+
const indexedInputs = {};
|
69
|
+
const nonIndexedInputs = {};
|
70
|
+
for (const [i, input] of inputs.entries()) {
|
71
|
+
if (input.indexed) {
|
72
|
+
indexedInputs[i] = input;
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
nonIndexedInputs[i] = input;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
const decodedNonIndexedInputs = data
|
79
|
+
? (0, parameters_api_js_1.decodeParametersWith)(Object.values(nonIndexedInputs), data, true)
|
80
|
+
: { __length__: 0 };
|
81
|
+
// If topics are more than indexed inputs, that means first topic is the event signature
|
82
|
+
const offset = clonedTopics.length - Object.keys(indexedInputs).length;
|
83
|
+
const decodedIndexedInputs = Object.values(indexedInputs).map((input, index) => STATIC_TYPES.some(s => input.type.startsWith(s))
|
84
|
+
? _decodeParameter(input.type, clonedTopics[index + offset])
|
85
|
+
: clonedTopics[index + offset]);
|
86
|
+
const returnValues = { __length__: 0 };
|
87
|
+
let indexedCounter = 0;
|
88
|
+
let nonIndexedCounter = 0;
|
89
|
+
for (const [i, res] of inputs.entries()) {
|
90
|
+
returnValues[i] = res.type === 'string' ? '' : undefined;
|
91
|
+
if (indexedInputs[i]) {
|
92
|
+
returnValues[i] = decodedIndexedInputs[indexedCounter];
|
93
|
+
indexedCounter += 1;
|
94
|
+
}
|
95
|
+
if (nonIndexedInputs[i]) {
|
96
|
+
returnValues[i] = decodedNonIndexedInputs[String(nonIndexedCounter)];
|
97
|
+
nonIndexedCounter += 1;
|
98
|
+
}
|
99
|
+
if (res.name) {
|
100
|
+
returnValues[res.name] = returnValues[i];
|
101
|
+
}
|
102
|
+
returnValues.__length__ += 1;
|
103
|
+
}
|
104
|
+
return returnValues;
|
105
|
+
};
|
106
|
+
exports.decodeLog = decodeLog;
|
107
|
+
//# sourceMappingURL=logs_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logs_api.js","sourceRoot":"","sources":["../../../src/api/logs_api.ts"],"names":[],"mappings":"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"}
|