Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public sendAsync (payload: JsonRpc, cb: any) {
// Backwards Compatibility
if (!cb || typeof cb !== 'function') {
return cb(
new Error('Invalid or undefined callback provided to sendAsync')
)
}
if (!payload) {
return cb(new Error('Invalid Payload'))
}
// sendAsync can be called with an array for batch requests used by web3.js 0.x
// this is not part of EIP-1193's backwards compatibility but we still want to support it
if (payload instanceof Array) {
return this.sendAsyncBatch(payload, cb)
} else if (isJsonRpcRequest(payload)) {
return this._send(payload.method, payload.params)
.then(result => {
cb(null, { id: payload.id, jsonrpc: payload.jsonrpc, result })
})
.catch(err => {
cb(err)
})
}
}
public sendAsyncBatch (requests: JsonRpc[], cb: any) {
public sendAsync (payload: JsonRpc, cb: any) {
// Backwards Compatibility
if (!cb || typeof cb !== 'function') {
return cb(
new Error('Invalid or undefined callback provided to sendAsync')
)
}
if (!payload) {
return cb(new Error('Invalid Payload'))
}
// sendAsync can be called with an array for batch requests used by web3.js 0.x
// this is not part of EIP-1193's backwards compatibility but we still want to support it
if (payload instanceof Array) {
return this.sendAsyncBatch(payload, cb)
} else if (isJsonRpcRequest(payload)) {
return this._send(payload.method, payload.params)
.then(result => {
cb(null, { id: payload.id, jsonrpc: payload.jsonrpc, result })
})
.catch(err => {
cb(err)
})
}
}
public sendAsyncBatch (requests: JsonRpc[], cb: any) {
requests.map(payload => {
if (isJsonRpcRequest(payload)) {
this._send(payload.method, payload.params)
}
})
)
requests.map(payload => {
if (isJsonRpcRequest(payload)) {
this._send(payload.method, payload.params)
}
})
)
public trigger (
payload:
| IJsonRpcRequest
| IJsonRpcResponseSuccess
| IJsonRpcResponseError
| IInternalEvent
): void {
let eventEmitters: IEventEmitter[] = []
let event: string
if (isJsonRpcRequest(payload)) {
event = payload.method
} else if (
isJsonRpcResponseSuccess(payload) ||
isJsonRpcResponseError(payload)
) {
event = `response:${payload.id}`
} else if (isInternalEvent(payload)) {
event = payload.event
} else {
event = ''
}
if (event) {
eventEmitters = this._eventEmitters.filter(
(eventEmitter: IEventEmitter) => eventEmitter.event === event
)