koilib 9.1.1 → 9.3.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 +1 -0
- package/dist/koinos.js +1682 -393
- package/dist/koinos.min.js +1 -1
- package/lib/Multicall.d.ts +79 -0
- package/lib/Multicall.js +104 -0
- package/lib/Multicall.js.map +1 -0
- package/lib/Provider.d.ts +205 -0
- package/lib/Provider.js +247 -0
- package/lib/Provider.js.map +1 -1
- package/lib/abis/multicallAbi.d.ts +2 -0
- package/lib/abis/multicallAbi.js +127 -0
- package/lib/abis/multicallAbi.js.map +1 -0
- package/lib/browser/Multicall.d.ts +79 -0
- package/lib/browser/Multicall.js +104 -0
- package/lib/browser/Multicall.js.map +1 -0
- package/lib/browser/Provider.d.ts +205 -0
- package/lib/browser/Provider.js +247 -0
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/abis/multicallAbi.d.ts +2 -0
- package/lib/browser/abis/multicallAbi.js +127 -0
- package/lib/browser/abis/multicallAbi.js.map +1 -0
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index2.js +2 -0
- package/lib/browser/index2.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -0
- package/lib/index2.js.map +1 -1
- package/package.json +1 -1
- package/src/Multicall.ts +139 -0
- package/src/Provider.ts +389 -0
- package/src/abis/multicallAbi.ts +127 -0
- package/src/index.ts +1 -0
- package/src/index2.ts +2 -0
package/src/Multicall.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Contract } from "./Contract";
|
|
2
|
+
import { OperationJson } from "./interface";
|
|
3
|
+
import { ProviderInterface } from "./Provider";
|
|
4
|
+
import { Transaction } from "./Transaction";
|
|
5
|
+
import { multicallAbi } from "./abis/multicallAbi";
|
|
6
|
+
|
|
7
|
+
export class Multicall {
|
|
8
|
+
/**
|
|
9
|
+
* Multicall contract address
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
|
|
13
|
+
transaction: Transaction;
|
|
14
|
+
|
|
15
|
+
contracts: Contract[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const tokens = [
|
|
21
|
+
* "19GYjDBVXU7keLbYvMLazsGQn3GTWHjHkK", // koin
|
|
22
|
+
* "12Y5vW6gk8GceH53YfRkRre2Rrcsgw7Naq", // vhp
|
|
23
|
+
* "12VoHz41a4HtfiyhTWbg9RXqGMRbYk6pXh", // vortex usdt
|
|
24
|
+
* "1Tf1QKv3gVYLjq34yURSHw5ErTYbFjqTG", // vortex eth
|
|
25
|
+
* ];
|
|
26
|
+
*
|
|
27
|
+
* const provider = new Provider("https://api.koinos.io");
|
|
28
|
+
*
|
|
29
|
+
* // create an array of the different contracts
|
|
30
|
+
* // used in the multicall
|
|
31
|
+
* const contracts = [];
|
|
32
|
+
* for (const token of tokens) {
|
|
33
|
+
* contracts.push(
|
|
34
|
+
* new Contract({
|
|
35
|
+
* id: token,
|
|
36
|
+
* provider,
|
|
37
|
+
* abi: utils.tokenAbi,
|
|
38
|
+
* })
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // create the multicall instance
|
|
43
|
+
* const multicall = new Multicall({
|
|
44
|
+
* provider,
|
|
45
|
+
* contracts
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // add operations to the multicall
|
|
49
|
+
* for (const contract of contracts) {
|
|
50
|
+
* await multicall.add(contract.functions.balanceOf, {
|
|
51
|
+
* owner: "1MdqwaSBy6rbasPJ9vmg2pZFJSVZ29GFpZ",
|
|
52
|
+
* });
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // call the multicall
|
|
56
|
+
* const results = await multicall.call();
|
|
57
|
+
* console.log(results);
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* For testnet set the id to the multicall contract address for testnet
|
|
61
|
+
* ```ts
|
|
62
|
+
* const multicall = new Multicall({
|
|
63
|
+
* id: "1MM9ydA8SdgXvCTH3LdQ5FS8JvHijCmGSg",
|
|
64
|
+
* provider: new Provider("https://testnet-api.koinos.io"),
|
|
65
|
+
* contracts: [ koinContract, fogataPoolContract ],
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
constructor(c: {
|
|
70
|
+
/**
|
|
71
|
+
* Multicall contract address. Leave it undefined
|
|
72
|
+
* to use the mainnet multicall contract address.
|
|
73
|
+
*/
|
|
74
|
+
id?: string;
|
|
75
|
+
provider?: ProviderInterface;
|
|
76
|
+
contracts?: Contract[];
|
|
77
|
+
}) {
|
|
78
|
+
if (c.id) this.id = c.id;
|
|
79
|
+
else this.id = "18dVCqPG3gwgL7DWQAciKYNuXfzEg5LW7"; // multicontract address mainnet
|
|
80
|
+
this.transaction = new Transaction({ provider: c.provider });
|
|
81
|
+
this.contracts = c.contracts || [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async add(
|
|
85
|
+
input:
|
|
86
|
+
| OperationJson
|
|
87
|
+
| { operation: OperationJson }
|
|
88
|
+
| Promise<{ operation: OperationJson }>
|
|
89
|
+
| Contract["functions"]["x"],
|
|
90
|
+
args?: unknown
|
|
91
|
+
): Promise<void> {
|
|
92
|
+
await this.transaction.pushOperation(input, args);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async call<T = Record<string, unknown>>(): Promise<(T | Error)[]> {
|
|
96
|
+
const multicallContract = new Contract({
|
|
97
|
+
id: this.id,
|
|
98
|
+
provider: this.transaction.provider,
|
|
99
|
+
abi: multicallAbi,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const calls = this.transaction.transaction.operations!.map(
|
|
103
|
+
(op) => op.call_contract!
|
|
104
|
+
);
|
|
105
|
+
const { result: multicallResult } = await multicallContract.functions.get({
|
|
106
|
+
calls,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const results: (T | Error)[] = [];
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < calls.length; i += 1) {
|
|
112
|
+
const contract = this.contracts.find(
|
|
113
|
+
(c) => c.getId() === calls[i].contract_id
|
|
114
|
+
);
|
|
115
|
+
if (contract && contract.abi) {
|
|
116
|
+
const method = Object.values(contract.abi.methods).find((method) => {
|
|
117
|
+
return method.entry_point === calls[i].entry_point;
|
|
118
|
+
});
|
|
119
|
+
if (method) {
|
|
120
|
+
const decoded = (await contract!.serializer!.deserialize(
|
|
121
|
+
multicallResult!.results[i]!.res.object,
|
|
122
|
+
method.return
|
|
123
|
+
)) as T;
|
|
124
|
+
results.push(decoded as T);
|
|
125
|
+
} else {
|
|
126
|
+
results.push(
|
|
127
|
+
new Error(
|
|
128
|
+
`Method ${calls[i].entry_point} not found in contract ${calls[i].contract_id}`
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
results.push(new Error(`Contract ${calls[i].contract_id} not found`));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return results;
|
|
138
|
+
}
|
|
139
|
+
}
|
package/src/Provider.ts
CHANGED
|
@@ -15,6 +15,66 @@ import { koinos } from "./protoModules/protocol-proto.js";
|
|
|
15
15
|
import { decodeBase64url, encodeBase64url } from "./utils";
|
|
16
16
|
import { Serializer } from "./Serializer";
|
|
17
17
|
|
|
18
|
+
const getObjectTypes = {
|
|
19
|
+
nested: {
|
|
20
|
+
get_object_arguments: {
|
|
21
|
+
fields: {
|
|
22
|
+
space: {
|
|
23
|
+
type: "object_space",
|
|
24
|
+
id: 1,
|
|
25
|
+
},
|
|
26
|
+
key: {
|
|
27
|
+
type: "bytes",
|
|
28
|
+
id: 2,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
get_object_result: {
|
|
33
|
+
fields: {
|
|
34
|
+
value: {
|
|
35
|
+
type: "database_object",
|
|
36
|
+
id: 1,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
object_space: {
|
|
41
|
+
fields: {
|
|
42
|
+
system: {
|
|
43
|
+
type: "bool",
|
|
44
|
+
id: 1,
|
|
45
|
+
},
|
|
46
|
+
zone: {
|
|
47
|
+
type: "bytes",
|
|
48
|
+
id: 2,
|
|
49
|
+
options: {
|
|
50
|
+
"(koinos.btype)": "ADDRESS",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
id: {
|
|
54
|
+
type: "uint32",
|
|
55
|
+
id: 3,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
database_object: {
|
|
60
|
+
fields: {
|
|
61
|
+
exists: {
|
|
62
|
+
type: "bool",
|
|
63
|
+
id: 1,
|
|
64
|
+
},
|
|
65
|
+
value: {
|
|
66
|
+
type: "bytes",
|
|
67
|
+
id: 2,
|
|
68
|
+
},
|
|
69
|
+
key: {
|
|
70
|
+
type: "bytes",
|
|
71
|
+
id: 3,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
18
78
|
export interface ProviderInterface {
|
|
19
79
|
call: <T = unknown>(method: string, params: unknown) => Promise<T>;
|
|
20
80
|
getNonce: (
|
|
@@ -129,6 +189,56 @@ export interface ProviderInterface {
|
|
|
129
189
|
}
|
|
130
190
|
| undefined
|
|
131
191
|
>;
|
|
192
|
+
invokeGetObject?: (args: {
|
|
193
|
+
address: string;
|
|
194
|
+
id: number;
|
|
195
|
+
key?: string;
|
|
196
|
+
system?: boolean;
|
|
197
|
+
zone?: string;
|
|
198
|
+
}) => Promise<string | undefined>;
|
|
199
|
+
invokeGetNextObject?: (args: {
|
|
200
|
+
address: string;
|
|
201
|
+
id: number;
|
|
202
|
+
key?: string;
|
|
203
|
+
system?: boolean;
|
|
204
|
+
zone?: string;
|
|
205
|
+
}) => Promise<
|
|
206
|
+
| {
|
|
207
|
+
exists: boolean;
|
|
208
|
+
value: string;
|
|
209
|
+
key: string;
|
|
210
|
+
}
|
|
211
|
+
| undefined
|
|
212
|
+
>;
|
|
213
|
+
invokeGetPrevObject?: (args: {
|
|
214
|
+
address: string;
|
|
215
|
+
id: number;
|
|
216
|
+
key?: string;
|
|
217
|
+
system?: boolean;
|
|
218
|
+
zone?: string;
|
|
219
|
+
}) => Promise<
|
|
220
|
+
| {
|
|
221
|
+
exists: boolean;
|
|
222
|
+
value: string;
|
|
223
|
+
key: string;
|
|
224
|
+
}
|
|
225
|
+
| undefined
|
|
226
|
+
>;
|
|
227
|
+
invokeGetManyObjects?: (args: {
|
|
228
|
+
address: string;
|
|
229
|
+
id: number;
|
|
230
|
+
key?: string;
|
|
231
|
+
limit?: number;
|
|
232
|
+
direction?: "ascending" | "descending";
|
|
233
|
+
system?: boolean;
|
|
234
|
+
zone?: string;
|
|
235
|
+
}) => Promise<
|
|
236
|
+
{
|
|
237
|
+
exists: boolean;
|
|
238
|
+
value: string;
|
|
239
|
+
key: string;
|
|
240
|
+
}[]
|
|
241
|
+
>;
|
|
132
242
|
}
|
|
133
243
|
|
|
134
244
|
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
|
|
@@ -1109,6 +1219,285 @@ export class Provider implements ProviderInterface {
|
|
|
1109
1219
|
value: { address: string };
|
|
1110
1220
|
}>(serializer, "get_contract_address", { name });
|
|
1111
1221
|
}
|
|
1222
|
+
|
|
1223
|
+
async invokeGetObjectGeneric({
|
|
1224
|
+
systemCallIdOrName,
|
|
1225
|
+
address,
|
|
1226
|
+
id,
|
|
1227
|
+
key = "",
|
|
1228
|
+
system = false,
|
|
1229
|
+
zone = address,
|
|
1230
|
+
}: {
|
|
1231
|
+
systemCallIdOrName: string | number;
|
|
1232
|
+
address: string;
|
|
1233
|
+
id: number;
|
|
1234
|
+
key?: string;
|
|
1235
|
+
system?: boolean;
|
|
1236
|
+
zone?: string;
|
|
1237
|
+
}) {
|
|
1238
|
+
const serializer = new Serializer(getObjectTypes, {
|
|
1239
|
+
argumentsTypeName: "get_object_arguments",
|
|
1240
|
+
returnTypeName: "get_object_result",
|
|
1241
|
+
});
|
|
1242
|
+
const result = await this.invokeSystemCall<{
|
|
1243
|
+
value: {
|
|
1244
|
+
exists: boolean;
|
|
1245
|
+
value: string;
|
|
1246
|
+
key: string;
|
|
1247
|
+
};
|
|
1248
|
+
}>(
|
|
1249
|
+
serializer,
|
|
1250
|
+
systemCallIdOrName,
|
|
1251
|
+
{
|
|
1252
|
+
space: {
|
|
1253
|
+
system,
|
|
1254
|
+
zone,
|
|
1255
|
+
id,
|
|
1256
|
+
},
|
|
1257
|
+
key,
|
|
1258
|
+
},
|
|
1259
|
+
{
|
|
1260
|
+
caller: address,
|
|
1261
|
+
caller_privilege: system ? 0 : 1,
|
|
1262
|
+
}
|
|
1263
|
+
);
|
|
1264
|
+
return result?.value;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* Function to get an object from the database via the get_object system call.
|
|
1269
|
+
* @param args - object space and key
|
|
1270
|
+
* @param args.address - caller address (also used as zone when zone is omitted)
|
|
1271
|
+
* @param args.id - object space id
|
|
1272
|
+
* @param args.key - object key (defaults to empty)
|
|
1273
|
+
* @param args.zone - object space zone (defaults to address)
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```ts
|
|
1277
|
+
* const provider = new Provider("https://api.koinos.io");
|
|
1278
|
+
* const result = await provider.invokeGetObject({
|
|
1279
|
+
* address: "1KD9Es7LBBjA1FY3ViCgQJ7e6WH1ipKbhz",
|
|
1280
|
+
* id: 0,
|
|
1281
|
+
* });
|
|
1282
|
+
* console.log(result);
|
|
1283
|
+
*
|
|
1284
|
+
* // {
|
|
1285
|
+
* // exists: true,
|
|
1286
|
+
* // value: '...',
|
|
1287
|
+
* // key: ''
|
|
1288
|
+
* // }
|
|
1289
|
+
* ```
|
|
1290
|
+
*/
|
|
1291
|
+
async invokeGetObject({
|
|
1292
|
+
address,
|
|
1293
|
+
id,
|
|
1294
|
+
key = "",
|
|
1295
|
+
system = false,
|
|
1296
|
+
zone = address,
|
|
1297
|
+
}: {
|
|
1298
|
+
address: string;
|
|
1299
|
+
id: number;
|
|
1300
|
+
key?: string;
|
|
1301
|
+
system?: boolean;
|
|
1302
|
+
zone?: string;
|
|
1303
|
+
}) {
|
|
1304
|
+
const result = await this.invokeGetObjectGeneric({
|
|
1305
|
+
systemCallIdOrName: "get_object",
|
|
1306
|
+
address,
|
|
1307
|
+
id,
|
|
1308
|
+
key,
|
|
1309
|
+
system,
|
|
1310
|
+
zone,
|
|
1311
|
+
});
|
|
1312
|
+
if (!result || !result.exists) return undefined;
|
|
1313
|
+
return result.value;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* Function to get the next object from the database via the
|
|
1318
|
+
* get_next_object system call.
|
|
1319
|
+
* @param args - object space and key
|
|
1320
|
+
* @param args.address - caller address (also used as zone when zone is omitted)
|
|
1321
|
+
* @param args.id - object space id
|
|
1322
|
+
* @param args.key - object key to seek from (defaults to empty)
|
|
1323
|
+
* @param args.system - whether the space is a system space
|
|
1324
|
+
* @param args.zone - object space zone (defaults to address)
|
|
1325
|
+
*
|
|
1326
|
+
* @example
|
|
1327
|
+
* ```ts
|
|
1328
|
+
* const provider = new Provider("https://api.koinos.io");
|
|
1329
|
+
* const result = await provider.invokeGetNextObject({
|
|
1330
|
+
* address: "1KD9Es7LBBjA1FY3ViCgQJ7e6WH1ipKbhz",
|
|
1331
|
+
* id: 0,
|
|
1332
|
+
* });
|
|
1333
|
+
* console.log(result);
|
|
1334
|
+
*
|
|
1335
|
+
* // {
|
|
1336
|
+
* // exists: true,
|
|
1337
|
+
* // value: '...',
|
|
1338
|
+
* // key: '...'
|
|
1339
|
+
* // }
|
|
1340
|
+
* ```
|
|
1341
|
+
*/
|
|
1342
|
+
async invokeGetNextObject({
|
|
1343
|
+
address,
|
|
1344
|
+
id,
|
|
1345
|
+
key = "",
|
|
1346
|
+
system = false,
|
|
1347
|
+
zone = address,
|
|
1348
|
+
}: {
|
|
1349
|
+
address: string;
|
|
1350
|
+
id: number;
|
|
1351
|
+
key?: string;
|
|
1352
|
+
system?: boolean;
|
|
1353
|
+
zone?: string;
|
|
1354
|
+
}) {
|
|
1355
|
+
return this.invokeGetObjectGeneric({
|
|
1356
|
+
systemCallIdOrName: "get_next_object",
|
|
1357
|
+
address,
|
|
1358
|
+
id,
|
|
1359
|
+
key,
|
|
1360
|
+
system,
|
|
1361
|
+
zone,
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Function to get the previous object from the database via the
|
|
1367
|
+
* get_prev_object system call.
|
|
1368
|
+
* @param args - object space and key
|
|
1369
|
+
* @param args.address - caller address (also used as zone when zone is omitted)
|
|
1370
|
+
* @param args.id - object space id
|
|
1371
|
+
* @param args.key - object key to seek from (defaults to empty)
|
|
1372
|
+
* @param args.system - whether the space is a system space
|
|
1373
|
+
* @param args.zone - object space zone (defaults to address)
|
|
1374
|
+
*
|
|
1375
|
+
* @example
|
|
1376
|
+
* ```ts
|
|
1377
|
+
* const provider = new Provider("https://api.koinos.io");
|
|
1378
|
+
* const result = await provider.invokeGetPrevObject({
|
|
1379
|
+
* address: "1KD9Es7LBBjA1FY3ViCgQJ7e6WH1ipKbhz",
|
|
1380
|
+
* id: 0,
|
|
1381
|
+
* key: "...",
|
|
1382
|
+
* });
|
|
1383
|
+
* console.log(result);
|
|
1384
|
+
*
|
|
1385
|
+
* // {
|
|
1386
|
+
* // exists: true,
|
|
1387
|
+
* // value: '...',
|
|
1388
|
+
* // key: '...'
|
|
1389
|
+
* // }
|
|
1390
|
+
* ```
|
|
1391
|
+
*/
|
|
1392
|
+
async invokeGetPrevObject({
|
|
1393
|
+
address,
|
|
1394
|
+
id,
|
|
1395
|
+
key = "",
|
|
1396
|
+
system = false,
|
|
1397
|
+
zone = address,
|
|
1398
|
+
}: {
|
|
1399
|
+
address: string;
|
|
1400
|
+
id: number;
|
|
1401
|
+
key?: string;
|
|
1402
|
+
system?: boolean;
|
|
1403
|
+
zone?: string;
|
|
1404
|
+
}) {
|
|
1405
|
+
return this.invokeGetObjectGeneric({
|
|
1406
|
+
systemCallIdOrName: "get_prev_object",
|
|
1407
|
+
address,
|
|
1408
|
+
id,
|
|
1409
|
+
key,
|
|
1410
|
+
system,
|
|
1411
|
+
zone,
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* Function to get many objects from the database by repeatedly
|
|
1417
|
+
* calling get_next_object or get_prev_object.
|
|
1418
|
+
* @param args - object space and pagination options
|
|
1419
|
+
* @param args.address - caller address (also used as zone when zone is omitted)
|
|
1420
|
+
* @param args.id - object space id
|
|
1421
|
+
* @param args.key - offset key to seek from (defaults to empty)
|
|
1422
|
+
* @param args.limit - maximum number of objects to return
|
|
1423
|
+
* @param args.direction - traversal direction ("ascending" or "descending")
|
|
1424
|
+
* @param args.system - whether the space is a system space
|
|
1425
|
+
* @param args.zone - object space zone (defaults to address)
|
|
1426
|
+
*
|
|
1427
|
+
* @example
|
|
1428
|
+
* ```ts
|
|
1429
|
+
* const provider = new Provider("https://api.koinos.io");
|
|
1430
|
+
* const result = await provider.invokeGetManyObjects({
|
|
1431
|
+
* address: "1KD9Es7LBBjA1FY3ViCgQJ7e6WH1ipKbhz",
|
|
1432
|
+
* id: 0,
|
|
1433
|
+
* limit: 10,
|
|
1434
|
+
* });
|
|
1435
|
+
* console.log(result);
|
|
1436
|
+
*
|
|
1437
|
+
* // [
|
|
1438
|
+
* // {
|
|
1439
|
+
* // exists: true,
|
|
1440
|
+
* // value: '...',
|
|
1441
|
+
* // key: '...'
|
|
1442
|
+
* // },
|
|
1443
|
+
* // ...
|
|
1444
|
+
* // ]
|
|
1445
|
+
* ```
|
|
1446
|
+
*/
|
|
1447
|
+
async invokeGetManyObjects({
|
|
1448
|
+
address,
|
|
1449
|
+
id,
|
|
1450
|
+
key = "",
|
|
1451
|
+
limit = Number.MAX_SAFE_INTEGER,
|
|
1452
|
+
direction = "ascending",
|
|
1453
|
+
system = false,
|
|
1454
|
+
zone = address,
|
|
1455
|
+
}: {
|
|
1456
|
+
address: string;
|
|
1457
|
+
id: number;
|
|
1458
|
+
key?: string;
|
|
1459
|
+
limit?: number;
|
|
1460
|
+
direction?: "ascending" | "descending";
|
|
1461
|
+
system?: boolean;
|
|
1462
|
+
zone?: string;
|
|
1463
|
+
}) {
|
|
1464
|
+
const result: {
|
|
1465
|
+
exists: boolean;
|
|
1466
|
+
value: string;
|
|
1467
|
+
key: string;
|
|
1468
|
+
}[] = [];
|
|
1469
|
+
|
|
1470
|
+
let currentKey = key;
|
|
1471
|
+
let done = false;
|
|
1472
|
+
|
|
1473
|
+
do {
|
|
1474
|
+
const obj =
|
|
1475
|
+
direction === "ascending"
|
|
1476
|
+
? await this.invokeGetNextObject({
|
|
1477
|
+
address,
|
|
1478
|
+
id,
|
|
1479
|
+
key: currentKey,
|
|
1480
|
+
system,
|
|
1481
|
+
zone,
|
|
1482
|
+
})
|
|
1483
|
+
: await this.invokeGetPrevObject({
|
|
1484
|
+
address,
|
|
1485
|
+
id,
|
|
1486
|
+
key: currentKey,
|
|
1487
|
+
system,
|
|
1488
|
+
zone,
|
|
1489
|
+
});
|
|
1490
|
+
|
|
1491
|
+
if (obj && obj.exists) {
|
|
1492
|
+
result.push(obj);
|
|
1493
|
+
currentKey = obj.key;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
done = !obj || !obj.exists || result.length >= limit;
|
|
1497
|
+
} while (!done);
|
|
1498
|
+
|
|
1499
|
+
return result;
|
|
1500
|
+
}
|
|
1112
1501
|
}
|
|
1113
1502
|
|
|
1114
1503
|
export default Provider;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { AnyNestedObject } from "protobufjs";
|
|
2
|
+
import { Abi } from "../interface";
|
|
3
|
+
|
|
4
|
+
export const multicallAbi: Abi = {
|
|
5
|
+
methods: {
|
|
6
|
+
get: {
|
|
7
|
+
argument: "multicall.get_args",
|
|
8
|
+
return: "multicall.get_return",
|
|
9
|
+
description: "Get the result of a multicall",
|
|
10
|
+
entry_point: 697873187,
|
|
11
|
+
read_only: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
types:
|
|
15
|
+
"CvEDCg9tdWx0aWNhbGwucHJvdG8SCW11bHRpY2FsbBoUa29pbm9zL29wdGlvbnMucHJvdG8ibAoOY2FsbF9hcmd1bWVudHMSJQoLY29udHJhY3RfaWQYASABKAxCBIC1GAVSCmNvbnRyYWN0SWQSHwoLZW50cnlfcG9pbnQYAiABKA1SCmVudHJ5UG9pbnQSEgoEYXJncxgDIAEoDFIEYXJncyJaCgZyZXN1bHQSGAoGb2JqZWN0GAEgASgMSABSBm9iamVjdBItCgVlcnJvchgCIAEoCzIVLm11bHRpY2FsbC5lcnJvcl9kYXRhSABSBWVycm9yQgcKBXZhbHVlIiYKCmVycm9yX2RhdGESGAoHbWVzc2FnZRgBIAEoCVIHbWVzc2FnZSI7CghnZXRfYXJncxIvCgVjYWxscxgBIAMoCzIZLm11bHRpY2FsbC5jYWxsX2FyZ3VtZW50c1IFY2FsbHMiRgoLY2FsbF9yZXR1cm4SEgoEY29kZRgBIAEoBVIEY29kZRIjCgNyZXMYAiABKAsyES5tdWx0aWNhbGwucmVzdWx0UgNyZXMiPgoKZ2V0X3JldHVybhIwCgdyZXN1bHRzGAEgAygLMhYubXVsdGljYWxsLmNhbGxfcmV0dXJuUgdyZXN1bHRzYgZwcm90bzM=",
|
|
16
|
+
koilib_types: {
|
|
17
|
+
nested: {
|
|
18
|
+
multicall: {
|
|
19
|
+
nested: {
|
|
20
|
+
call_arguments: {
|
|
21
|
+
fields: {
|
|
22
|
+
contract_id: {
|
|
23
|
+
type: "bytes",
|
|
24
|
+
id: 1,
|
|
25
|
+
options: {
|
|
26
|
+
"(koinos.btype)": "CONTRACT_ID",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
entry_point: {
|
|
30
|
+
type: "uint32",
|
|
31
|
+
id: 2,
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
type: "bytes",
|
|
35
|
+
id: 3,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
result: {
|
|
40
|
+
oneofs: {
|
|
41
|
+
value: {
|
|
42
|
+
oneof: ["object", "error"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
fields: {
|
|
46
|
+
object: {
|
|
47
|
+
type: "bytes",
|
|
48
|
+
id: 1,
|
|
49
|
+
},
|
|
50
|
+
error: {
|
|
51
|
+
type: "error_data",
|
|
52
|
+
id: 2,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
error_data: {
|
|
57
|
+
fields: {
|
|
58
|
+
message: {
|
|
59
|
+
type: "string",
|
|
60
|
+
id: 1,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
get_args: {
|
|
65
|
+
fields: {
|
|
66
|
+
calls: {
|
|
67
|
+
rule: "repeated",
|
|
68
|
+
type: "call_arguments",
|
|
69
|
+
id: 1,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
call_return: {
|
|
74
|
+
fields: {
|
|
75
|
+
code: {
|
|
76
|
+
type: "int32",
|
|
77
|
+
id: 1,
|
|
78
|
+
},
|
|
79
|
+
res: {
|
|
80
|
+
type: "result",
|
|
81
|
+
id: 2,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
get_return: {
|
|
86
|
+
fields: {
|
|
87
|
+
results: {
|
|
88
|
+
rule: "repeated",
|
|
89
|
+
type: "call_return",
|
|
90
|
+
id: 1,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
koinos: {
|
|
97
|
+
options: {
|
|
98
|
+
go_package: "github.com/koinos/koinos-proto-golang/koinos",
|
|
99
|
+
},
|
|
100
|
+
nested: {
|
|
101
|
+
bytes_type: {
|
|
102
|
+
values: {
|
|
103
|
+
BASE64: 0,
|
|
104
|
+
BASE58: 1,
|
|
105
|
+
HEX: 2,
|
|
106
|
+
BLOCK_ID: 3,
|
|
107
|
+
TRANSACTION_ID: 4,
|
|
108
|
+
CONTRACT_ID: 5,
|
|
109
|
+
ADDRESS: 6,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
_btype: {
|
|
113
|
+
oneof: ["btype"],
|
|
114
|
+
} as AnyNestedObject,
|
|
115
|
+
btype: {
|
|
116
|
+
type: "bytes_type",
|
|
117
|
+
id: 50000,
|
|
118
|
+
extend: "google.protobuf.FieldOptions",
|
|
119
|
+
options: {
|
|
120
|
+
proto3_optional: true,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
package/src/index.ts
CHANGED
package/src/index2.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Signer } from "./Signer";
|
|
|
6
6
|
import { Provider } from "./Provider";
|
|
7
7
|
import { Transaction } from "./Transaction";
|
|
8
8
|
import { Serializer } from "./Serializer";
|
|
9
|
+
import { Multicall } from "./Multicall";
|
|
9
10
|
|
|
10
11
|
declare const window: { [x: string]: unknown };
|
|
11
12
|
|
|
@@ -15,3 +16,4 @@ window.Signer = Signer;
|
|
|
15
16
|
window.Provider = Provider;
|
|
16
17
|
window.Transaction = Transaction;
|
|
17
18
|
window.Serializer = Serializer;
|
|
19
|
+
window.Multicall = Multicall;
|