dequanto 0.2.33 → 0.2.34
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/lib/cjs/clients/ClientPool.js +2 -2
- package/lib/cjs/clients/ClientPool.js.map +1 -1
- package/lib/cjs/clients/Web3BatchRequests.js +2 -2
- package/lib/cjs/clients/Web3BatchRequests.js.map +1 -1
- package/lib/cjs/clients/Web3Client.js +4 -4
- package/lib/cjs/clients/Web3Client.js.map +1 -1
- package/lib/cjs/contracts/ContractReader.js +2 -2
- package/lib/cjs/contracts/ContractReader.js.map +1 -1
- package/lib/cjs/rpc/RpcBase.js +7 -1
- package/lib/cjs/rpc/RpcBase.js.map +1 -1
- package/lib/cjs/rpc/RpcContract.js +16 -4
- package/lib/cjs/rpc/RpcContract.js.map +1 -1
- package/lib/esm/clients/ClientPool.js.map +1 -1
- package/lib/esm/clients/ClientPool.mjs +2 -2
- package/lib/esm/clients/Web3BatchRequests.js.map +1 -1
- package/lib/esm/clients/Web3BatchRequests.mjs +2 -2
- package/lib/esm/clients/Web3Client.js.map +1 -1
- package/lib/esm/clients/Web3Client.mjs +4 -4
- package/lib/esm/contracts/ContractReader.js.map +1 -1
- package/lib/esm/contracts/ContractReader.mjs +2 -2
- package/lib/esm/rpc/RpcBase.js.map +1 -1
- package/lib/esm/rpc/RpcBase.mjs +7 -1
- package/lib/esm/rpc/RpcContract.js.map +1 -1
- package/lib/esm/rpc/RpcContract.mjs +16 -4
- package/lib/types/clients/ClientPool.d.ts +3 -1
- package/lib/types/clients/Web3BatchRequests.d.ts +3 -1
- package/lib/types/clients/Web3Client.d.ts +6 -2
- package/lib/types/contracts/ContractReader.d.ts +3 -1
- package/lib/types/rpc/RpcBase.d.ts +3 -1
- package/lib/types/rpc/RpcContract.d.ts +3 -1
- package/package.json +1 -1
- package/src/clients/ClientPool.ts +4 -2
- package/src/clients/Web3BatchRequests.ts +4 -2
- package/src/clients/Web3Client.ts +8 -4
- package/src/contracts/ContractReader.ts +4 -2
- package/src/rpc/RpcBase.ts +9 -2
- package/src/rpc/RpcContract.ts +18 -4
|
@@ -38,13 +38,15 @@ export namespace Web3BatchRequests {
|
|
|
38
38
|
constructor(private rpc: Rpc, private requests: TRpc.IRpcAction[]) {
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async execute(
|
|
41
|
+
async execute(options?: {
|
|
42
|
+
allowErrors?: boolean
|
|
43
|
+
}): Promise<any[]> {
|
|
42
44
|
if (this.requests.length === 0) {
|
|
43
45
|
return [];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
let rpc = this.rpc;
|
|
47
|
-
let response = await rpc.batch(this.requests);
|
|
49
|
+
let response = await rpc.batch(this.requests, options);
|
|
48
50
|
return response;
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -97,9 +97,11 @@ export abstract class Web3Client implements IWeb3Client {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
async batch(requests: TRpc.IRpcAction[]
|
|
100
|
+
async batch(requests: TRpc.IRpcAction[], options?: {
|
|
101
|
+
allowErrors?: boolean
|
|
102
|
+
}): Promise<any[]> {
|
|
101
103
|
return this.with (async web3 => {
|
|
102
|
-
return web3.callBatched(requests);
|
|
104
|
+
return web3.callBatched(requests, options);
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -187,9 +189,11 @@ export abstract class Web3Client implements IWeb3Client {
|
|
|
187
189
|
return result;
|
|
188
190
|
}
|
|
189
191
|
|
|
190
|
-
async readContractBatch(requests: TRpcContractCall[]
|
|
192
|
+
async readContractBatch(requests: TRpcContractCall[], options?: {
|
|
193
|
+
allowErrors?: boolean
|
|
194
|
+
}) {
|
|
191
195
|
let reader = new RpcContract(this);
|
|
192
|
-
let result = await reader.batch(requests);
|
|
196
|
+
let result = await reader.batch(requests, options);
|
|
193
197
|
return result;
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -354,7 +354,9 @@ export namespace ContractReaderUtils {
|
|
|
354
354
|
|
|
355
355
|
;
|
|
356
356
|
|
|
357
|
-
export async function readAsyncBatch(client: Web3Client, requests: (IContractReadParams | null)[]
|
|
357
|
+
export async function readAsyncBatch(client: Web3Client, requests: (IContractReadParams | null)[], options?: {
|
|
358
|
+
allowErrors?: boolean
|
|
359
|
+
}) {
|
|
358
360
|
|
|
359
361
|
let rpcRequests = await alot(requests).map(async request => {
|
|
360
362
|
if (request == null) {
|
|
@@ -389,7 +391,7 @@ export namespace ContractReaderUtils {
|
|
|
389
391
|
mapped[i] = idx;
|
|
390
392
|
}
|
|
391
393
|
|
|
392
|
-
let outputs = await client.readContractBatch(rpcRequestsNotEmpty);
|
|
394
|
+
let outputs = await client.readContractBatch(rpcRequestsNotEmpty, options);
|
|
393
395
|
return rpcRequests.map((_, i) => {
|
|
394
396
|
return outputs[mapped[i]] ?? null;
|
|
395
397
|
});
|
package/src/rpc/RpcBase.ts
CHANGED
|
@@ -39,7 +39,9 @@ export abstract class RpcBase {
|
|
|
39
39
|
return this._deserialize(req.method, result);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
async batch (arr: TRpc.IRpcAction[]
|
|
42
|
+
async batch (arr: TRpc.IRpcAction[], options?: {
|
|
43
|
+
allowErrors?: boolean
|
|
44
|
+
}): Promise<any[]> {
|
|
43
45
|
let body = arr.map(req => this._wrapBody(req));
|
|
44
46
|
let resp = await this._transport.request(body);
|
|
45
47
|
if (Array.isArray(resp) === false && arr.length === 1 && 'error' in resp === false && 'result' in resp === true) {
|
|
@@ -56,9 +58,14 @@ export abstract class RpcBase {
|
|
|
56
58
|
return resp.map((resp, i) => {
|
|
57
59
|
let req = arr[i];
|
|
58
60
|
if ('error' in resp) {
|
|
61
|
+
if (options?.allowErrors) {
|
|
62
|
+
return {
|
|
63
|
+
error: new Error(resp.error.message),
|
|
64
|
+
request: req
|
|
65
|
+
};
|
|
66
|
+
}
|
|
59
67
|
throw new RpcError(resp.error, `BatchRequest ${i + 1}/${arr.length} (${req.method} ${JSON.stringify(req.params)})`);
|
|
60
68
|
}
|
|
61
|
-
|
|
62
69
|
let result = this._unwrapBody(resp);
|
|
63
70
|
return this._deserialize(req.method, result);
|
|
64
71
|
});
|
package/src/rpc/RpcContract.ts
CHANGED
|
@@ -63,20 +63,34 @@ export class RpcContract {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
async batch (req: TRpcContractCall[]
|
|
66
|
+
async batch (req: TRpcContractCall[], options?: {
|
|
67
|
+
allowErrors?: boolean
|
|
68
|
+
}) {
|
|
67
69
|
|
|
68
70
|
let requests = await this.getCallRequestsRaw(req);
|
|
69
71
|
try {
|
|
70
|
-
let responseArr = await this.client.batch(requests.map(x => x.methodRequest));
|
|
72
|
+
let responseArr = await this.client.batch(requests.map(x => x.methodRequest), options);
|
|
71
73
|
|
|
72
74
|
return responseArr.map((resp, i) => {
|
|
73
75
|
let abi = requests[i].methodAbi;
|
|
74
76
|
if (abi == null) {
|
|
75
77
|
return resp;
|
|
76
78
|
}
|
|
77
|
-
let
|
|
79
|
+
let returnABI = abi.outputs;
|
|
80
|
+
|
|
81
|
+
if (resp != null && typeof resp === 'object' && 'error' in resp) {
|
|
82
|
+
let defaults = null;
|
|
83
|
+
try {
|
|
84
|
+
const defaultHex = $abiCoder.encode(returnABI, [null]);
|
|
85
|
+
defaults = utils.deserializeOutput(defaultHex, returnABI);
|
|
86
|
+
} catch (error) {}
|
|
87
|
+
return {
|
|
88
|
+
defaults,
|
|
89
|
+
...resp
|
|
90
|
+
};
|
|
91
|
+
}
|
|
78
92
|
let hex = typeof resp === 'string' ? resp : resp.data;
|
|
79
|
-
let result = utils.deserializeOutput(hex,
|
|
93
|
+
let result = utils.deserializeOutput(hex, returnABI);
|
|
80
94
|
return result;
|
|
81
95
|
});
|
|
82
96
|
|