Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public _send (method?: string, params: any[] = []) {
if (!method || typeof method !== 'string') {
throw new Error('Method is not a valid string.')
}
if (!(params instanceof Array)) {
throw new Error('Params is not a valid array.')
}
const payload = { jsonrpc: '2.0', id: payloadId(), method, params }
const promise: Promise = new Promise((resolve, reject) => {
this.promises[payload.id] = { resolve, reject }
})
this.connection.send(payload)
return promise
}
public send () {
public _send (method?: string, params?: any) {
if (!method || typeof method !== 'string') {
throw new Error('Method is not a valid string.')
}
if (!(params instanceof Object)) {
throw new Error('Params is not a valid object.')
}
const payload = { jsonrpc: '2.0', id: payloadId(), method, params }
const promise: Promise = new Promise((resolve, reject) => {
this.promises[payload.id] = { resolve, reject }
})
this.connection.send(payload)
return promise
}
public send () {
protected _formatRequest (request: Partial): IJsonRpcRequest {
if (typeof request.method === 'undefined') {
throw new Error(ERROR_MISSING_METHOD)
}
const formattedRequest: IJsonRpcRequest = {
id: typeof request.id === 'undefined' ? payloadId() : request.id,
jsonrpc: '2.0',
method: request.method,
params: typeof request.params === 'undefined' ? [] : request.params
}
return formattedRequest
}