|
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | +import { JsonRpcResponse } from '../../../dto' |
| 3 | +import { Height, AbciQuery, BnbRpcInterface, Blockchain, Tx, Broadcast, TxSearch } from '../../../dto/rpc/BnbRpcSuite' |
| 4 | +import { PostI } from '../../../dto/PostI' |
| 5 | +import { Utils } from '../../../util' |
| 6 | + |
| 7 | +export abstract class AbstractBnbRpc implements BnbRpcInterface { |
| 8 | + protected abstract post<T>(post: PostI): Promise<T> |
| 9 | + |
| 10 | + sendRpcCall<T, U>(method: string, params?: T): Promise<U> { |
| 11 | + const body = { |
| 12 | + id: 1, |
| 13 | + jsonrpc: '2.0', |
| 14 | + method, |
| 15 | + params: params ? Utils.convertObjCamelToSnake(params) : {}, |
| 16 | + } |
| 17 | + return this.post({ body, path: '' }) |
| 18 | + } |
| 19 | + |
| 20 | + status(): Promise<JsonRpcResponse<any>> { |
| 21 | + return this.sendRpcCall('status') |
| 22 | + } |
| 23 | + |
| 24 | + abciInfo(): Promise<JsonRpcResponse<any>> { |
| 25 | + return this.sendRpcCall('abci_info') |
| 26 | + } |
| 27 | + |
| 28 | + abciQuery(params: AbciQuery): Promise<JsonRpcResponse<any>> { |
| 29 | + return this.sendRpcCall('abci_query', params) |
| 30 | + } |
| 31 | + |
| 32 | + block(params?: Height): Promise<JsonRpcResponse<any>> { |
| 33 | + return this.sendRpcCall('block', params) |
| 34 | + } |
| 35 | + |
| 36 | + blockResult(params?: Height): Promise<JsonRpcResponse<any>> { |
| 37 | + return this.sendRpcCall('block_result', params) |
| 38 | + } |
| 39 | + |
| 40 | + blockchain(params?: Blockchain): Promise<JsonRpcResponse<any>> { |
| 41 | + return this.sendRpcCall('blockchain', params) |
| 42 | + } |
| 43 | + |
| 44 | + commit(params?: Height): Promise<JsonRpcResponse<any>> { |
| 45 | + return this.sendRpcCall('commit', params) |
| 46 | + } |
| 47 | + |
| 48 | + tx(params: Tx): Promise<JsonRpcResponse<any>> { |
| 49 | + return this.sendRpcCall('tx', params) |
| 50 | + } |
| 51 | + |
| 52 | + broadcastTxAsync(params: Broadcast): Promise<JsonRpcResponse<any>> { |
| 53 | + return this.sendRpcCall('broadcast_tx_async', params) |
| 54 | + } |
| 55 | + |
| 56 | + broadcastTxCommit(params: Broadcast): Promise<JsonRpcResponse<any>> { |
| 57 | + return this.sendRpcCall('broadcast_tx_commit', params) |
| 58 | + } |
| 59 | + |
| 60 | + broadcastTxSync(params: Broadcast): Promise<JsonRpcResponse<any>> { |
| 61 | + return this.sendRpcCall('broadcast_tx_sync', params) |
| 62 | + } |
| 63 | + |
| 64 | + txSearch(params: TxSearch): Promise<JsonRpcResponse<any>> { |
| 65 | + return this.sendRpcCall('tx_search', params) |
| 66 | + } |
| 67 | + |
| 68 | + validators(params: Height): Promise<JsonRpcResponse<any>> { |
| 69 | + return this.sendRpcCall('validators', params) |
| 70 | + } |
| 71 | + |
| 72 | + unconfirmedTxs(params: { limit: string }): Promise<JsonRpcResponse<any>> { |
| 73 | + return this.sendRpcCall('unconfirmed_txs', params) |
| 74 | + } |
| 75 | + |
| 76 | + genesis(): Promise<JsonRpcResponse<any>> { |
| 77 | + return this.sendRpcCall('genesis') |
| 78 | + } |
| 79 | + |
| 80 | + health(): Promise<JsonRpcResponse<any>> { |
| 81 | + return this.sendRpcCall('health') |
| 82 | + } |
| 83 | + |
| 84 | + netInfo(): Promise<JsonRpcResponse<any>> { |
| 85 | + return this.sendRpcCall('net_info') |
| 86 | + } |
| 87 | + |
| 88 | + numUnconfirmedTxs(): Promise<JsonRpcResponse<any>> { |
| 89 | + return this.sendRpcCall('num_unconfirmed_txs') |
| 90 | + } |
| 91 | +} |
0 commit comments