[] = [];
for (let i = 0; i < paramsList.length; i++) {
// most of the payloads should be a single param, e.g. GetTransaction
// however, there are special cases e.g. GetSmartContractSubState & GetTransactionsForTxBlockEx
// where the param field is a list
const payloadParams = paramsList[i];
let params: any;
if (Array.isArray(payloadParams)) {
// for those param field that is already a list
params = payloadParams;
} else {
params = [payloadParams];
}
// id start from index 1
payloads.push({
id: i + 1,
jsonrpc: '2.0',
method,
params,
});
}
return {
url: this.nodeURL,
payload: payloads,
};
}
send(
method: RPCMethod,
...params: P
): Promise> {
const [tReq, tRes] = this.getMiddleware(method);
const reqMiddleware = composeMiddleware(...tReq);
const resMiddleware = composeMiddleware(...tRes);
const req = reqMiddleware(this.buildPayload(method, params));
return performRPC(req, resMiddleware);
}
sendBatch(
method: RPCMethod,
params: P[],
): Promise> {
const [tReq, tRes] = this.getMiddleware(method);
const reqMiddleware = composeMiddleware(...tReq);
const resMiddleware = composeMiddleware(...tRes);
const batchPayload = this.buildBatchPayload(method, params);
const req = reqMiddleware(batchPayload);
return performBatchRPC(req, resMiddleware);
}
subscribe(event: string, subscriber: Subscriber): symbol {
throw new Error('HTTPProvider does not support subscriptions.');
}
unsubscribe(token: symbol) {
throw new Error('HTTPProvider does not support subscriptions.');
}
}