|
1 | | -import RpcClientRetry from 'bitcoin-rpc-promise-retry'; |
2 | 1 | import { Utxo, Network } from '../interfaces'; |
3 | 2 | import NetworkProvider from './NetworkProvider'; |
4 | 3 |
|
| 4 | +const RpcClientRetry = require('bitcoin-rpc-promise-retry'); |
| 5 | + |
5 | 6 | export default class BitcoinRpcNetworkProvider implements NetworkProvider { |
6 | 7 | private rpcClient: RpcClientRetry; |
7 | 8 |
|
@@ -41,3 +42,40 @@ export default class BitcoinRpcNetworkProvider implements NetworkProvider { |
41 | 42 | return this.rpcClient; |
42 | 43 | } |
43 | 44 | } |
| 45 | + |
| 46 | +interface ListUnspentItem { |
| 47 | + txid: string; |
| 48 | + vout: number; |
| 49 | + address: string; |
| 50 | + label: string; |
| 51 | + scriptPubKey: string; |
| 52 | + amount: number; |
| 53 | + confirmations: number; |
| 54 | + redeemScript: string; |
| 55 | + spendable: boolean; |
| 56 | + solvable: boolean; |
| 57 | + safe: boolean; |
| 58 | +} |
| 59 | + |
| 60 | +interface RpcClientRetry { |
| 61 | + constructor(url: string, opts?: object): void; |
| 62 | + listUnspent( |
| 63 | + minconf?: number, |
| 64 | + maxconf?: number, |
| 65 | + addresses?: string[], |
| 66 | + include_unsafe?: boolean, |
| 67 | + query_options?: object, |
| 68 | + ): Promise<ListUnspentItem[]>; |
| 69 | + getBlockCount(): Promise<number>; |
| 70 | + getRawTransaction(txid: string, verbose?: boolean, blockhash?: string): Promise<string>; |
| 71 | + sendRawTransaction(hexstring: string, allowhighfees?: boolean): Promise<string>; |
| 72 | + |
| 73 | + // below are not required for NetworkProvider interface, but very useful |
| 74 | + generate(nblocks: number, maxtries?: number): Promise<string[]>; |
| 75 | + generateToAddress(nblocks: number, address: string, maxtries?: number): Promise<string[]>; |
| 76 | + getNewAddress(label?: string): Promise<string>; |
| 77 | + dumpPrivKey(address: string): Promise<string>; |
| 78 | + getBalance(dummy?: string, minconf?: number, include_watchonly?: boolean): Promise<number>; |
| 79 | + getBlock(blockhash: string, verbosity?: number): Promise<string>; |
| 80 | + importAddress(address: string, label?: string, rescan?: boolean, p2sh?: boolean): Promise<void>; |
| 81 | +} |
0 commit comments