@alephium/web3 0.5.0-rc.2 → 0.5.0-rc.21
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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +2 -0
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +113 -26
- package/dist/src/api/api-alephium.js +62 -18
- package/dist/src/api/api-explorer.d.ts +222 -52
- package/dist/src/api/api-explorer.js +17 -15
- package/dist/src/api/explorer-provider.d.ts +18 -0
- package/dist/src/api/explorer-provider.js +65 -0
- package/dist/src/api/index.d.ts +2 -41
- package/dist/src/api/index.js +6 -116
- package/dist/src/api/node-provider.d.ts +21 -0
- package/dist/src/api/node-provider.js +68 -0
- package/dist/src/api/types.d.ts +10 -2
- package/dist/src/api/types.js +23 -3
- package/dist/src/contract/contract.d.ts +15 -7
- package/dist/src/contract/contract.js +62 -42
- package/dist/src/signer/signer.d.ts +25 -30
- package/dist/src/signer/signer.js +57 -30
- package/dist/src/signer/tx-builder.d.ts +2 -7
- package/dist/src/signer/tx-builder.js +10 -7
- package/dist/src/signer/types.d.ts +12 -16
- package/dist/src/transaction/sign-verify.d.ts +3 -2
- package/dist/src/transaction/sign-verify.js +4 -14
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.js +2 -0
- package/dist/src/utils/number.d.ts +18 -0
- package/dist/src/utils/number.fixture.d.ts +12 -0
- package/dist/src/utils/number.fixture.js +189 -0
- package/dist/src/utils/number.js +148 -0
- package/dist/src/utils/sign.d.ts +3 -0
- package/dist/src/utils/sign.js +89 -0
- package/dist/src/utils/utils.d.ts +4 -3
- package/dist/src/utils/utils.js +25 -10
- package/package.json +7 -5
- package/src/api/api-alephium.ts +260 -207
- package/src/api/api-explorer.ts +327 -126
- package/src/api/explorer-provider.ts +78 -0
- package/src/api/index.ts +2 -146
- package/src/api/node-provider.ts +84 -0
- package/src/api/types.ts +36 -3
- package/src/contract/contract.ts +80 -49
- package/src/signer/signer.ts +87 -66
- package/src/signer/tx-builder.ts +13 -7
- package/src/signer/types.ts +22 -11
- package/src/transaction/sign-verify.ts +10 -15
- package/src/utils/index.ts +2 -0
- package/src/utils/number.fixture.ts +187 -0
- package/src/utils/number.ts +162 -0
- package/src/utils/sign.ts +66 -0
- package/src/utils/utils.ts +26 -10
package/dist/src/api/index.d.ts
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
path: string;
|
|
4
|
-
method: string;
|
|
5
|
-
params: any[];
|
|
6
|
-
}
|
|
7
|
-
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
8
|
-
export declare class NodeProvider {
|
|
9
|
-
readonly wallets: NodeApi<string>['wallets'];
|
|
10
|
-
readonly infos: NodeApi<string>['infos'];
|
|
11
|
-
readonly blockflow: NodeApi<string>['blockflow'];
|
|
12
|
-
readonly addresses: NodeApi<string>['addresses'];
|
|
13
|
-
readonly transactions: NodeApi<string>['transactions'];
|
|
14
|
-
readonly contracts: NodeApi<string>['contracts'];
|
|
15
|
-
readonly multisig: NodeApi<string>['multisig'];
|
|
16
|
-
readonly utils: NodeApi<string>['utils'];
|
|
17
|
-
readonly miners: NodeApi<string>['miners'];
|
|
18
|
-
readonly events: NodeApi<string>['events'];
|
|
19
|
-
constructor(baseUrl: string, apiKey?: string);
|
|
20
|
-
constructor(provider: NodeProvider);
|
|
21
|
-
constructor(handler: ApiRequestHandler);
|
|
22
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
23
|
-
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
24
|
-
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
25
|
-
}
|
|
26
|
-
export declare class ExplorerProvider {
|
|
27
|
-
readonly blocks: any;
|
|
28
|
-
readonly transactions: any;
|
|
29
|
-
readonly addresses: any;
|
|
30
|
-
readonly infos: any;
|
|
31
|
-
readonly unconfirmedTransactions: any;
|
|
32
|
-
readonly tokens: any;
|
|
33
|
-
readonly charts: any;
|
|
34
|
-
readonly utils: any;
|
|
35
|
-
constructor(baseUrl: string, apiKey?: string);
|
|
36
|
-
constructor(provider: ExplorerProvider);
|
|
37
|
-
constructor(handler: ApiRequestHandler);
|
|
38
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
39
|
-
static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider;
|
|
40
|
-
static Remote(handler: ApiRequestHandler): ExplorerProvider;
|
|
41
|
-
}
|
|
1
|
+
export * from './node-provider';
|
|
2
|
+
export * from './explorer-provider';
|
|
42
3
|
export * as node from './api-alephium';
|
|
43
4
|
export * as explorer from './api-explorer';
|
|
44
5
|
export * from './types';
|
package/dist/src/api/index.js
CHANGED
|
@@ -32,6 +32,9 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
32
32
|
}) : function(o, v) {
|
|
33
33
|
o["default"] = v;
|
|
34
34
|
});
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
35
38
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
39
|
if (mod && mod.__esModule) return mod;
|
|
37
40
|
var result = {};
|
|
@@ -39,123 +42,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
39
42
|
__setModuleDefault(result, mod);
|
|
40
43
|
return result;
|
|
41
44
|
};
|
|
42
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
43
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
44
|
-
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.explorer = exports.node =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function forwardRequests(api, handler) {
|
|
50
|
-
// Update class properties to forward requests
|
|
51
|
-
for (const [path, pathObject] of Object.entries(api)) {
|
|
52
|
-
for (const method of Object.keys(pathObject)) {
|
|
53
|
-
pathObject[`${method}`] = async (...params) => {
|
|
54
|
-
return handler({ path, method, params });
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function request(provider, args) {
|
|
60
|
-
const call = provider[`${args.path}`][`${args.method}`];
|
|
61
|
-
return call(...args.params);
|
|
62
|
-
}
|
|
63
|
-
function initializeNodeApi(baseUrl, apiKey) {
|
|
64
|
-
const nodeApi = new api_alephium_1.Api({
|
|
65
|
-
baseUrl: baseUrl,
|
|
66
|
-
baseApiParams: { secure: true },
|
|
67
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
68
|
-
});
|
|
69
|
-
nodeApi.setSecurityData(apiKey ?? null);
|
|
70
|
-
return nodeApi;
|
|
71
|
-
}
|
|
72
|
-
class NodeProvider {
|
|
73
|
-
constructor(param0, apiKey) {
|
|
74
|
-
this.request = (args) => {
|
|
75
|
-
return request(this, args);
|
|
76
|
-
};
|
|
77
|
-
let nodeApi;
|
|
78
|
-
if (typeof param0 === 'string') {
|
|
79
|
-
nodeApi = initializeNodeApi(param0, apiKey);
|
|
80
|
-
}
|
|
81
|
-
else if (typeof param0 === 'function') {
|
|
82
|
-
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
83
|
-
forwardRequests(nodeApi, param0);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
nodeApi = param0;
|
|
87
|
-
}
|
|
88
|
-
this.wallets = { ...nodeApi.wallets };
|
|
89
|
-
this.infos = { ...nodeApi.infos };
|
|
90
|
-
this.blockflow = { ...nodeApi.blockflow };
|
|
91
|
-
this.addresses = { ...nodeApi.addresses };
|
|
92
|
-
this.transactions = { ...nodeApi.transactions };
|
|
93
|
-
this.contracts = { ...nodeApi.contracts };
|
|
94
|
-
this.multisig = { ...nodeApi.multisig };
|
|
95
|
-
this.utils = { ...nodeApi.utils };
|
|
96
|
-
this.miners = { ...nodeApi.miners };
|
|
97
|
-
this.events = { ...nodeApi.events };
|
|
98
|
-
}
|
|
99
|
-
// This can prevent the proxied node provider from being modified
|
|
100
|
-
static Proxy(nodeProvider) {
|
|
101
|
-
return new NodeProvider(nodeProvider);
|
|
102
|
-
}
|
|
103
|
-
static Remote(handler) {
|
|
104
|
-
return new NodeProvider(handler);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.NodeProvider = NodeProvider;
|
|
108
|
-
function initializeExplorerApi(baseUrl, apiKey) {
|
|
109
|
-
const explorerApi = new api_explorer_1.Api({
|
|
110
|
-
baseUrl: baseUrl,
|
|
111
|
-
baseApiParams: { secure: true },
|
|
112
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
113
|
-
});
|
|
114
|
-
explorerApi.setSecurityData(apiKey ?? null);
|
|
115
|
-
return explorerApi;
|
|
116
|
-
}
|
|
117
|
-
class ExplorerProvider {
|
|
118
|
-
constructor(param0, apiKey) {
|
|
119
|
-
this.blocks = api_explorer_1.Api['blocks'];
|
|
120
|
-
this.transactions = api_explorer_1.Api['transactions'];
|
|
121
|
-
this.addresses = api_explorer_1.Api['addresses'];
|
|
122
|
-
this.infos = api_explorer_1.Api['infos'];
|
|
123
|
-
this.unconfirmedTransactions = api_explorer_1.Api['unconfirmedTransactions'];
|
|
124
|
-
this.tokens = api_explorer_1.Api['tokens'];
|
|
125
|
-
this.charts = api_explorer_1.Api['charts'];
|
|
126
|
-
this.utils = api_explorer_1.Api['utils'];
|
|
127
|
-
this.request = (args) => {
|
|
128
|
-
return request(this, args);
|
|
129
|
-
};
|
|
130
|
-
let explorerApi;
|
|
131
|
-
if (typeof param0 === 'string') {
|
|
132
|
-
explorerApi = initializeExplorerApi(param0, apiKey);
|
|
133
|
-
}
|
|
134
|
-
else if (typeof param0 === 'function') {
|
|
135
|
-
explorerApi = new ExplorerProvider('https://1.2.3.4:0');
|
|
136
|
-
forwardRequests(explorerApi, param0);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
explorerApi = param0;
|
|
140
|
-
}
|
|
141
|
-
this.blocks = { ...explorerApi.blocks };
|
|
142
|
-
this.transactions = { ...explorerApi.transactions };
|
|
143
|
-
this.addresses = { ...explorerApi.addresses };
|
|
144
|
-
this.infos = { ...explorerApi.infos };
|
|
145
|
-
this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions };
|
|
146
|
-
this.tokens = { ...explorerApi.tokens };
|
|
147
|
-
this.charts = { ...explorerApi.charts };
|
|
148
|
-
this.utils = { ...explorerApi.utils };
|
|
149
|
-
}
|
|
150
|
-
// This can prevent the proxied explorer provider from being modified
|
|
151
|
-
static Proxy(explorerProvider) {
|
|
152
|
-
return new ExplorerProvider(explorerProvider);
|
|
153
|
-
}
|
|
154
|
-
static Remote(handler) {
|
|
155
|
-
return new ExplorerProvider(handler);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.ExplorerProvider = ExplorerProvider;
|
|
46
|
+
exports.explorer = exports.node = void 0;
|
|
47
|
+
__exportStar(require("./node-provider"), exports);
|
|
48
|
+
__exportStar(require("./explorer-provider"), exports);
|
|
159
49
|
exports.node = __importStar(require("./api-alephium"));
|
|
160
50
|
exports.explorer = __importStar(require("./api-explorer"));
|
|
161
51
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApiRequestArguments, ApiRequestHandler } from './types';
|
|
2
|
+
import { Api as NodeApi } from './api-alephium';
|
|
3
|
+
export declare class NodeProvider {
|
|
4
|
+
readonly wallets: NodeApi<string>['wallets'];
|
|
5
|
+
readonly infos: NodeApi<string>['infos'];
|
|
6
|
+
readonly blockflow: NodeApi<string>['blockflow'];
|
|
7
|
+
readonly addresses: NodeApi<string>['addresses'];
|
|
8
|
+
readonly transactions: NodeApi<string>['transactions'];
|
|
9
|
+
readonly mempool: NodeApi<string>['mempool'];
|
|
10
|
+
readonly contracts: NodeApi<string>['contracts'];
|
|
11
|
+
readonly multisig: NodeApi<string>['multisig'];
|
|
12
|
+
readonly utils: NodeApi<string>['utils'];
|
|
13
|
+
readonly miners: NodeApi<string>['miners'];
|
|
14
|
+
readonly events: NodeApi<string>['events'];
|
|
15
|
+
constructor(baseUrl: string, apiKey?: string);
|
|
16
|
+
constructor(provider: NodeProvider);
|
|
17
|
+
constructor(handler: ApiRequestHandler);
|
|
18
|
+
request: (args: ApiRequestArguments) => Promise<any>;
|
|
19
|
+
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
20
|
+
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.NodeProvider = void 0;
|
|
21
|
+
const types_1 = require("./types");
|
|
22
|
+
const api_alephium_1 = require("./api-alephium");
|
|
23
|
+
function initializeNodeApi(baseUrl, apiKey) {
|
|
24
|
+
const nodeApi = new api_alephium_1.Api({
|
|
25
|
+
baseUrl: baseUrl,
|
|
26
|
+
baseApiParams: { secure: true },
|
|
27
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
28
|
+
});
|
|
29
|
+
nodeApi.setSecurityData(apiKey ?? null);
|
|
30
|
+
return nodeApi;
|
|
31
|
+
}
|
|
32
|
+
class NodeProvider {
|
|
33
|
+
constructor(param0, apiKey) {
|
|
34
|
+
this.request = (args) => {
|
|
35
|
+
return (0, types_1.request)(this, args);
|
|
36
|
+
};
|
|
37
|
+
let nodeApi;
|
|
38
|
+
if (typeof param0 === 'string') {
|
|
39
|
+
nodeApi = initializeNodeApi(param0, apiKey);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof param0 === 'function') {
|
|
42
|
+
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
43
|
+
(0, types_1.forwardRequests)(nodeApi, param0);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
nodeApi = param0;
|
|
47
|
+
}
|
|
48
|
+
this.wallets = { ...nodeApi.wallets };
|
|
49
|
+
this.infos = { ...nodeApi.infos };
|
|
50
|
+
this.blockflow = { ...nodeApi.blockflow };
|
|
51
|
+
this.addresses = { ...nodeApi.addresses };
|
|
52
|
+
this.transactions = { ...nodeApi.transactions };
|
|
53
|
+
this.mempool = { ...nodeApi.mempool };
|
|
54
|
+
this.contracts = { ...nodeApi.contracts };
|
|
55
|
+
this.multisig = { ...nodeApi.multisig };
|
|
56
|
+
this.utils = { ...nodeApi.utils };
|
|
57
|
+
this.miners = { ...nodeApi.miners };
|
|
58
|
+
this.events = { ...nodeApi.events };
|
|
59
|
+
}
|
|
60
|
+
// This can prevent the proxied node provider from being modified
|
|
61
|
+
static Proxy(nodeProvider) {
|
|
62
|
+
return new NodeProvider(nodeProvider);
|
|
63
|
+
}
|
|
64
|
+
static Remote(handler) {
|
|
65
|
+
return new NodeProvider(handler);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.NodeProvider = NodeProvider;
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as node from './api-alephium';
|
|
2
|
-
export declare type Number256 = bigint;
|
|
2
|
+
export declare type Number256 = bigint | string;
|
|
3
3
|
export declare type Val = Number256 | boolean | string | Val[];
|
|
4
4
|
export declare type NamedVals = Record<string, Val>;
|
|
5
5
|
export interface Token {
|
|
@@ -18,7 +18,15 @@ export declare function toApiByteVec(v: Val): string;
|
|
|
18
18
|
export declare function toApiAddress(v: Val): string;
|
|
19
19
|
export declare function toApiArray(tpe: string, v: Val): node.Val;
|
|
20
20
|
export declare function toApiVal(v: Val, tpe: string): node.Val;
|
|
21
|
-
export declare function fromApiVals(vals: node.Val[], names: string[], types: string[]): NamedVals;
|
|
21
|
+
export declare function fromApiVals(vals: node.Val[], names: string[], types: string[], optionalNames?: string[], optionalTypes?: string[]): NamedVals;
|
|
22
22
|
export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
|
|
23
23
|
export declare function fromApiVal(v: node.Val, tpe: string): Val;
|
|
24
24
|
export declare function typeLength(tpe: string): number;
|
|
25
|
+
export interface ApiRequestArguments {
|
|
26
|
+
path: string;
|
|
27
|
+
method: string;
|
|
28
|
+
params: any[];
|
|
29
|
+
}
|
|
30
|
+
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
31
|
+
export declare function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void;
|
|
32
|
+
export declare function request(provider: Record<string, any>, args: ApiRequestArguments): Promise<any>;
|
package/dist/src/api/types.js
CHANGED
|
@@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.typeLength = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
20
|
+
exports.request = exports.forwardRequests = exports.typeLength = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
21
21
|
const utils_1 = require("../utils");
|
|
22
22
|
utils_1.assertType;
|
|
23
23
|
function toApiToken(token) {
|
|
@@ -165,7 +165,7 @@ function _fromApiVal(vals, valIndex, tpe) {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
function fromApiVals(vals, names, types) {
|
|
168
|
+
function fromApiVals(vals, names, types, optionalNames = [], optionalTypes = []) {
|
|
169
169
|
let valIndex = 0;
|
|
170
170
|
const result = {};
|
|
171
171
|
types.forEach((currentType, index) => {
|
|
@@ -174,7 +174,11 @@ function fromApiVals(vals, names, types) {
|
|
|
174
174
|
valIndex = nextIndex;
|
|
175
175
|
result[`${currentName}`] = val;
|
|
176
176
|
});
|
|
177
|
-
|
|
177
|
+
if (valIndex === vals.length) {
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
const optionalFields = fromApiVals(vals.slice(valIndex), optionalNames, optionalTypes);
|
|
181
|
+
return { ...result, ...optionalFields };
|
|
178
182
|
}
|
|
179
183
|
exports.fromApiVals = fromApiVals;
|
|
180
184
|
function fromApiArray(vals, types) {
|
|
@@ -241,3 +245,19 @@ function typeLength(tpe) {
|
|
|
241
245
|
return dims.reduce((a, b) => a * b);
|
|
242
246
|
}
|
|
243
247
|
exports.typeLength = typeLength;
|
|
248
|
+
function forwardRequests(api, handler) {
|
|
249
|
+
// Update class properties to forward requests
|
|
250
|
+
for (const [path, pathObject] of Object.entries(api)) {
|
|
251
|
+
for (const method of Object.keys(pathObject)) {
|
|
252
|
+
pathObject[`${method}`] = async (...params) => {
|
|
253
|
+
return handler({ path, method, params });
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.forwardRequests = forwardRequests;
|
|
259
|
+
async function request(provider, args) {
|
|
260
|
+
const call = provider[`${args.path}`][`${args.method}`];
|
|
261
|
+
return call(...args.params);
|
|
262
|
+
}
|
|
263
|
+
exports.request = request;
|
|
@@ -123,9 +123,9 @@ export declare class Contract extends Artifact {
|
|
|
123
123
|
fromApiContractState(state: node.ContractState): ContractState<Fields>;
|
|
124
124
|
static fromApiContractState(state: node.ContractState): ContractState;
|
|
125
125
|
static ContractCreatedEventIndex: number;
|
|
126
|
-
static ContractCreatedEvent:
|
|
126
|
+
static ContractCreatedEvent: SystemEventSig;
|
|
127
127
|
static ContractDestroyedEventIndex: number;
|
|
128
|
-
static ContractDestroyedEvent:
|
|
128
|
+
static ContractDestroyedEvent: SystemEventSig;
|
|
129
129
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string): ContractEvent;
|
|
130
130
|
fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string): TestContractResult<unknown>;
|
|
131
131
|
txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
|
|
@@ -257,11 +257,18 @@ export interface CallContractResult<R> {
|
|
|
257
257
|
txOutputs: Output[];
|
|
258
258
|
events: ContractEvent[];
|
|
259
259
|
}
|
|
260
|
+
export declare const CreateContractEventAddress: string;
|
|
261
|
+
export declare const DestroyContractEventAddress: string;
|
|
262
|
+
export interface SystemEventSig extends EventSig {
|
|
263
|
+
optionalFieldNames?: string[];
|
|
264
|
+
optionalFieldTypes?: string[];
|
|
265
|
+
}
|
|
260
266
|
export declare type ContractCreatedEvent = ContractEvent<{
|
|
261
|
-
address:
|
|
267
|
+
address: Address;
|
|
268
|
+
parentAddress?: Address;
|
|
262
269
|
}>;
|
|
263
270
|
export declare type ContractDestroyedEvent = ContractEvent<{
|
|
264
|
-
address:
|
|
271
|
+
address: Address;
|
|
265
272
|
}>;
|
|
266
273
|
export declare function decodeContractCreatedEvent(event: node.ContractEvent): Omit<ContractCreatedEvent, 'contractAddress'>;
|
|
267
274
|
export declare function decodeContractDestroyedEvent(event: node.ContractEvent): Omit<ContractDestroyedEvent, 'contractAddress'>;
|
|
@@ -274,10 +281,11 @@ export declare abstract class ContractInstance {
|
|
|
274
281
|
constructor(address: Address);
|
|
275
282
|
}
|
|
276
283
|
export declare function fetchContractState<F extends Fields, I extends ContractInstance>(contract: ContractFactory<I, F>, instance: ContractInstance): Promise<ContractState<F>>;
|
|
277
|
-
export declare function subscribeContractCreatedEvent(
|
|
278
|
-
export declare function subscribeContractDestroyedEvent(
|
|
284
|
+
export declare function subscribeContractCreatedEvent(options: SubscribeOptions<ContractCreatedEvent>, fromCount?: number): EventSubscription;
|
|
285
|
+
export declare function subscribeContractDestroyedEvent(options: SubscribeOptions<ContractDestroyedEvent>, fromCount?: number): EventSubscription;
|
|
279
286
|
export declare function decodeEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, event: node.ContractEvent, targetEventIndex: number): M;
|
|
280
287
|
export declare function subscribeContractEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, options: SubscribeOptions<M>, eventName: string, fromCount?: number): EventSubscription;
|
|
281
|
-
export declare function
|
|
288
|
+
export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: SubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
|
|
282
289
|
export declare function callMethod<I, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>): Promise<CallContractResult<R>>;
|
|
290
|
+
export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
|
|
283
291
|
export {};
|
|
@@ -43,7 +43,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.callMethod = exports.
|
|
46
|
+
exports.getContractEventsCurrentCount = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.testMethod = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddress = exports.CreateContractEventAddress = exports.ContractFactory = exports.randomTxId = exports.toApiVals = exports.Script = exports.Contract = exports.Artifact = exports.Project = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = void 0;
|
|
47
47
|
const buffer_1 = require("buffer/");
|
|
48
48
|
const crypto_1 = require("crypto");
|
|
49
49
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -579,24 +579,29 @@ class Contract extends Artifact {
|
|
|
579
579
|
return contract.fromApiContractState(state);
|
|
580
580
|
}
|
|
581
581
|
static fromApiEvent(event, codeHash, txId) {
|
|
582
|
-
let
|
|
582
|
+
let fields;
|
|
583
|
+
let name;
|
|
583
584
|
if (event.eventIndex == Contract.ContractCreatedEventIndex) {
|
|
584
|
-
|
|
585
|
+
fields = fromApiSystemEventFields(event.fields, Contract.ContractCreatedEvent);
|
|
586
|
+
name = Contract.ContractCreatedEvent.name;
|
|
585
587
|
}
|
|
586
588
|
else if (event.eventIndex == Contract.ContractDestroyedEventIndex) {
|
|
587
|
-
|
|
589
|
+
fields = fromApiSystemEventFields(event.fields, Contract.ContractDestroyedEvent);
|
|
590
|
+
name = Contract.ContractDestroyedEvent.name;
|
|
588
591
|
}
|
|
589
592
|
else {
|
|
590
593
|
const contract = Project.currentProject.contractByCodeHash(codeHash);
|
|
591
|
-
eventSig = contract.eventsSig[event.eventIndex];
|
|
594
|
+
const eventSig = contract.eventsSig[event.eventIndex];
|
|
595
|
+
fields = fromApiEventFields(event.fields, eventSig);
|
|
596
|
+
name = eventSig.name;
|
|
592
597
|
}
|
|
593
598
|
return {
|
|
594
599
|
txId: txId,
|
|
595
600
|
blockHash: event.blockHash,
|
|
596
601
|
contractAddress: event.contractAddress,
|
|
597
|
-
name:
|
|
602
|
+
name: name,
|
|
598
603
|
eventIndex: event.eventIndex,
|
|
599
|
-
fields:
|
|
604
|
+
fields: fields
|
|
600
605
|
};
|
|
601
606
|
}
|
|
602
607
|
fromApiTestContractResult(methodName, result, txId) {
|
|
@@ -620,8 +625,10 @@ class Contract extends Artifact {
|
|
|
620
625
|
}
|
|
621
626
|
async txParamsForDeployment(signer, params) {
|
|
622
627
|
const bytecode = this.buildByteCodeToDeploy(params.initialFields ?? {});
|
|
628
|
+
const selectedAccount = await signer.getSelectedAccount();
|
|
623
629
|
const signerParams = {
|
|
624
|
-
signerAddress:
|
|
630
|
+
signerAddress: selectedAccount.address,
|
|
631
|
+
signerKeyType: selectedAccount.keyType,
|
|
625
632
|
bytecode: bytecode,
|
|
626
633
|
initialAttoAlphAmount: params?.initialAttoAlphAmount,
|
|
627
634
|
issueTokenAmount: params?.issueTokenAmount,
|
|
@@ -678,7 +685,9 @@ Contract.ContractCreatedEventIndex = -1;
|
|
|
678
685
|
Contract.ContractCreatedEvent = {
|
|
679
686
|
name: 'ContractCreated',
|
|
680
687
|
fieldNames: ['address'],
|
|
681
|
-
fieldTypes: ['Address']
|
|
688
|
+
fieldTypes: ['Address'],
|
|
689
|
+
optionalFieldNames: ['parentAddress'],
|
|
690
|
+
optionalFieldTypes: ['Address']
|
|
682
691
|
};
|
|
683
692
|
Contract.ContractDestroyedEventIndex = -2;
|
|
684
693
|
Contract.ContractDestroyedEvent = {
|
|
@@ -723,8 +732,10 @@ class Script extends Artifact {
|
|
|
723
732
|
return JSON.stringify(object, null, 2);
|
|
724
733
|
}
|
|
725
734
|
async txParamsForExecution(signer, params) {
|
|
735
|
+
const selectedAccount = await signer.getSelectedAccount();
|
|
726
736
|
const signerParams = {
|
|
727
|
-
signerAddress:
|
|
737
|
+
signerAddress: selectedAccount.address,
|
|
738
|
+
signerKeyType: selectedAccount.keyType,
|
|
728
739
|
bytecode: this.buildByteCodeToDeploy(params.initialFields ?? {}),
|
|
729
740
|
attoAlphAmount: params.attoAlphAmount,
|
|
730
741
|
tokens: params.tokens,
|
|
@@ -758,6 +769,9 @@ function fromApiFields(immFields, mutFields, fieldsSig) {
|
|
|
758
769
|
function fromApiEventFields(vals, eventSig) {
|
|
759
770
|
return (0, api_1.fromApiVals)(vals, eventSig.fieldNames, eventSig.fieldTypes);
|
|
760
771
|
}
|
|
772
|
+
function fromApiSystemEventFields(vals, systemEventSig) {
|
|
773
|
+
return (0, api_1.fromApiVals)(vals, systemEventSig.fieldNames, systemEventSig.fieldTypes, systemEventSig.optionalFieldNames ?? [], systemEventSig.optionalFieldTypes ?? []);
|
|
774
|
+
}
|
|
761
775
|
function toApiAsset(asset) {
|
|
762
776
|
return {
|
|
763
777
|
attoAlphAmount: (0, api_1.toApiNumber256)(asset.alphAmount),
|
|
@@ -872,25 +886,35 @@ class ContractFactory {
|
|
|
872
886
|
}
|
|
873
887
|
}
|
|
874
888
|
exports.ContractFactory = ContractFactory;
|
|
875
|
-
function
|
|
889
|
+
function specialContractAddress(n) {
|
|
890
|
+
const bytes = new Uint8Array(32).fill(0);
|
|
891
|
+
bytes[31] = n;
|
|
892
|
+
return (0, utils_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
|
|
893
|
+
}
|
|
894
|
+
exports.CreateContractEventAddress = specialContractAddress(-1);
|
|
895
|
+
exports.DestroyContractEventAddress = specialContractAddress(-2);
|
|
896
|
+
function decodeSystemEvent(event, systemEventSig, eventIndex) {
|
|
876
897
|
if (event.eventIndex !== eventIndex) {
|
|
877
898
|
throw new Error(`Invalid event index: ${event.eventIndex}, expected: ${eventIndex}`);
|
|
878
899
|
}
|
|
879
|
-
return (
|
|
900
|
+
return fromApiSystemEventFields(event.fields, systemEventSig);
|
|
880
901
|
}
|
|
881
902
|
function decodeContractCreatedEvent(event) {
|
|
882
|
-
const fields =
|
|
903
|
+
const fields = decodeSystemEvent(event, Contract.ContractCreatedEvent, Contract.ContractCreatedEventIndex);
|
|
883
904
|
return {
|
|
884
905
|
blockHash: event.blockHash,
|
|
885
906
|
txId: event.txId,
|
|
886
907
|
eventIndex: event.eventIndex,
|
|
887
908
|
name: Contract.ContractCreatedEvent.name,
|
|
888
|
-
fields: {
|
|
909
|
+
fields: {
|
|
910
|
+
address: fields['address'],
|
|
911
|
+
parentAddress: fields['parentAddress'] === undefined ? undefined : fields['parentAddress']
|
|
912
|
+
}
|
|
889
913
|
};
|
|
890
914
|
}
|
|
891
915
|
exports.decodeContractCreatedEvent = decodeContractCreatedEvent;
|
|
892
916
|
function decodeContractDestroyedEvent(event) {
|
|
893
|
-
const fields =
|
|
917
|
+
const fields = decodeSystemEvent(event, Contract.ContractDestroyedEvent, Contract.ContractDestroyedEventIndex);
|
|
894
918
|
return {
|
|
895
919
|
blockHash: event.blockHash,
|
|
896
920
|
txId: event.txId,
|
|
@@ -951,20 +975,20 @@ async function fetchContractState(contract, instance) {
|
|
|
951
975
|
};
|
|
952
976
|
}
|
|
953
977
|
exports.fetchContractState = fetchContractState;
|
|
954
|
-
function subscribeContractCreatedEvent(
|
|
955
|
-
return subscribeEventsFromContract(options,
|
|
978
|
+
function subscribeContractCreatedEvent(options, fromCount) {
|
|
979
|
+
return subscribeEventsFromContract(options, exports.CreateContractEventAddress, Contract.ContractCreatedEventIndex, (event) => {
|
|
956
980
|
return {
|
|
957
981
|
...decodeContractCreatedEvent(event),
|
|
958
|
-
contractAddress:
|
|
982
|
+
contractAddress: exports.CreateContractEventAddress
|
|
959
983
|
};
|
|
960
984
|
}, fromCount);
|
|
961
985
|
}
|
|
962
986
|
exports.subscribeContractCreatedEvent = subscribeContractCreatedEvent;
|
|
963
|
-
function subscribeContractDestroyedEvent(
|
|
964
|
-
return subscribeEventsFromContract(options,
|
|
987
|
+
function subscribeContractDestroyedEvent(options, fromCount) {
|
|
988
|
+
return subscribeEventsFromContract(options, exports.DestroyContractEventAddress, Contract.ContractDestroyedEventIndex, (event) => {
|
|
965
989
|
return {
|
|
966
990
|
...decodeContractDestroyedEvent(event),
|
|
967
|
-
contractAddress:
|
|
991
|
+
contractAddress: exports.DestroyContractEventAddress
|
|
968
992
|
};
|
|
969
993
|
}, fromCount);
|
|
970
994
|
}
|
|
@@ -993,27 +1017,12 @@ function subscribeContractEvent(contract, instance, options, eventName, fromCoun
|
|
|
993
1017
|
return subscribeEventsFromContract(options, instance.address, eventIndex, (event) => decodeEvent(contract, instance, event, eventIndex), fromCount);
|
|
994
1018
|
}
|
|
995
1019
|
exports.subscribeContractEvent = subscribeContractEvent;
|
|
996
|
-
function
|
|
1020
|
+
function subscribeContractEvents(contract, instance, options, fromCount) {
|
|
997
1021
|
const messageCallback = (event) => {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
contractAddress: instance.address
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
case Contract.ContractDestroyedEventIndex: {
|
|
1006
|
-
return options.messageCallback({
|
|
1007
|
-
...decodeContractDestroyedEvent(event),
|
|
1008
|
-
contractAddress: instance.address
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
default:
|
|
1012
|
-
return options.messageCallback({
|
|
1013
|
-
...decodeEvent(contract, instance, event, event.eventIndex),
|
|
1014
|
-
contractAddress: instance.address
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1022
|
+
return options.messageCallback({
|
|
1023
|
+
...decodeEvent(contract, instance, event, event.eventIndex),
|
|
1024
|
+
contractAddress: instance.address
|
|
1025
|
+
});
|
|
1017
1026
|
};
|
|
1018
1027
|
const errorCallback = (err, subscription) => {
|
|
1019
1028
|
return options.errorCallback(err, subscription);
|
|
@@ -1025,7 +1034,7 @@ function subscribeAllEvents(contract, instance, options, fromCount) {
|
|
|
1025
1034
|
};
|
|
1026
1035
|
return (0, events_1.subscribeToEvents)(opt, instance.address, fromCount);
|
|
1027
1036
|
}
|
|
1028
|
-
exports.
|
|
1037
|
+
exports.subscribeContractEvents = subscribeContractEvents;
|
|
1029
1038
|
async function callMethod(contract, instance, methodName, params) {
|
|
1030
1039
|
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1031
1040
|
const txId = params?.txId ?? randomTxId();
|
|
@@ -1035,3 +1044,14 @@ async function callMethod(contract, instance, methodName, params) {
|
|
|
1035
1044
|
return callResult;
|
|
1036
1045
|
}
|
|
1037
1046
|
exports.callMethod = callMethod;
|
|
1047
|
+
async function getContractEventsCurrentCount(contractAddress) {
|
|
1048
|
+
return (0, global_1.getCurrentNodeProvider)()
|
|
1049
|
+
.events.getEventsContractContractaddressCurrentCount(contractAddress)
|
|
1050
|
+
.catch((error) => {
|
|
1051
|
+
if (error instanceof Error && error.message.includes(`${contractAddress} not found`)) {
|
|
1052
|
+
return 0;
|
|
1053
|
+
}
|
|
1054
|
+
throw error;
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
exports.getContractEventsCurrentCount = getContractEventsCurrentCount;
|