From 02bcf809bee63d9b47548ba9be7595ba132b454d Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:29:52 +0300 Subject: [PATCH 01/23] fix: remove the generate method --- README.md | 9 --------- src/rpc.ts | 10 ---------- test/rpc.spec.ts | 40 ---------------------------------------- 3 files changed, 59 deletions(-) diff --git a/README.md b/README.md index 3c4dcf6..4ad8324 100644 --- a/README.md +++ b/README.md @@ -263,15 +263,6 @@ const result = await client.uptime(); ### Generating -- [`generate`](https://bitcoin.org/en/developer-reference#generate) - -```javascript -const nblocks = 1; -const maxtries = 10000; -const wallet = "bitcoin-core-wallet.dat"; -const result = await client.generate({ nblocks, maxtries }, wallet); -``` - - [`generatetoaddress`](https://bitcoin.org/en/developer-reference#generatetoaddress) ```javascript diff --git a/src/rpc.ts b/src/rpc.ts index 6b98a77..f9d2c17 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -652,16 +652,6 @@ export class RPCClient extends RESTClient { return this.rpc("uptime"); } - /** - * @description Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet. - */ - async generate( - { nblocks, maxtries = 1000000 }: GenerateParams, - wallet?: string - ) { - return this.rpc("generate", { nblocks, maxtries }, wallet || this.wallet); - } - /** * @description Mine blocks immediately to a specified address (before the RPC call returns) */ diff --git a/test/rpc.spec.ts b/test/rpc.spec.ts index 2a8c4a9..8d48362 100644 --- a/test/rpc.spec.ts +++ b/test/rpc.spec.ts @@ -1021,46 +1021,6 @@ suite("RPCClient", () => { }); suite("Generating", () => { - test(".generate()", async () => { - const params = { nblocks: 1, maxtries: 10000 }; - const request = { params, method: "generate", id, jsonrpc }; - const result: string[] = []; - nock(uri) - .post("/", request) - .times(1) - .basicAuth(auth) - .reply(200, { result, error, id }); - const data = await client.generate(params); - assert.deepStrictEqual(data, result); - }); - - test(".generate() (multi-wallet)", async () => { - const params = { nblocks: 1, maxtries: 10000 }; - const request = { params, method: "generate", id, jsonrpc }; - const result: string[] = []; - nock(uri) - .post("/wallet/" + wallet, request) - .times(1) - .basicAuth(auth) - .reply(200, { result, error, id }); - const data = await client.generate(params, wallet); - assert.deepStrictEqual(data, result); - }); - - test(".generate() (default wallet)", async () => { - const client = new RPCClient({ port, timeout, pass, wallet }); - const params = { nblocks: 1, maxtries: 10000 }; - const request = { params, method: "generate", id, jsonrpc }; - const result: string[] = []; - nock(uri) - .post("/wallet/" + wallet, request) - .times(1) - .basicAuth(auth) - .reply(200, { result, error, id }); - const data = await client.generate(params); - assert.deepStrictEqual(data, result); - }); - test(".generatetoaddress()", async () => { const address = "tb1qc4gce3kvc8px505r4wurwdytqclkdjta68qlh4"; const params = { nblocks: 1, maxtries: 10000, address }; From 9e87ada987fbc4db207f9e1e2d83754e621ecb25 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:30:12 +0300 Subject: [PATCH 02/23] chore: do not destruct arguments --- src/rest.ts | 43 ++-- src/rpc.ts | 709 +++++++++++++--------------------------------------- 2 files changed, 184 insertions(+), 568 deletions(-) diff --git a/src/rest.ts b/src/rest.ts index ccff047..e536a5e 100644 --- a/src/rest.ts +++ b/src/rest.ts @@ -1,34 +1,21 @@ import { RPC, RPCOptions } from "rpc-request"; -export type formatParam = { - format?: "json" | "hex" | "bin"; -}; +export type formatParam = { format?: "json" | "hex" | "bin" }; -export type BlockParams = formatParam & { - hash: string; -}; +export type BlockParams = formatParam & { hash: string }; -export type BlockHeightParams = formatParam & { - height: number; -}; +export type BlockHeightParams = formatParam & { height: number }; -export type Outpoint = { - txid: string; - n: number; -}; +export type Outpoint = { txid: string; n: number }; export type UtxosParams = formatParam & { checkmempool?: boolean; outpoints: Outpoint[] | Outpoint; }; -export type HeaderParams = BlockParams & { - count?: number; -}; +export type HeaderParams = BlockParams & { count?: number }; -export type TxParams = formatParam & { - txid: string; -}; +export type TxParams = formatParam & { txid: string }; export type RESTIniOptions = RPCOptions & { url?: string }; @@ -46,7 +33,7 @@ export class RESTClient extends RPC { timeout = 30000, ...options }: RESTIniOptions = {}) { - super({ ...options, baseUrl: url + ":" + port, timeout, json: true }); + super({ ...options, baseUrl: `${url}:${port}`, timeout, json: true }); } /** @@ -56,7 +43,7 @@ export class RESTClient extends RPC { * @param {string} [params.format='json'] - Set to 'json' for decoded block contents in JSON, or 'bin' or 'hex' for a serialized block in binary or hex */ async getBlock({ hash, format = "json" }: BlockParams) { - return this.get({ uri: "rest/block/" + hash + "." + format }); + return this.get({ uri: `/rest/block/${hash}.${format}` }); } /** @@ -66,7 +53,7 @@ export class RESTClient extends RPC { * @param {string} [params.format='json'] - Set to 'json' for decoded block contents in JSON, or 'bin' or 'hex' for a serialized block in binary or hex */ async getBlockNoTxDetails({ hash, format = "json" }: BlockParams) { - return this.get({ uri: "rest/block/notxdetails/" + hash + "." + format }); + return this.get({ uri: `/rest/block/notxdetails/${hash}.${format}` }); } /** @@ -76,8 +63,7 @@ export class RESTClient extends RPC { * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ async getBlockHashByHeight({ height, format = "json" }: BlockHeightParams) { - const uri = "/rest/blockhashbyheight/" + height + "." + format; - return this.get({ uri }); + return this.get({ uri: `/rest/blockhashbyheight/${height}.${format}` }); } /** @@ -99,10 +85,10 @@ export class RESTClient extends RPC { outpoints, format = "json", }: UtxosParams) { - let uri = "rest/getutxos" + (checkmempool ? "/checkmempool" : ""); + let uri = `rest/getutxos${checkmempool ? "/checkmempool" : ""}`; outpoints = !Array.isArray(outpoints) ? [outpoints] : outpoints; for (const { txid, n } of outpoints) { - uri += "/" + txid + "-" + n; + uri += `/${txid}-${n}`; } return this.get({ uri: uri + "." + format }); } @@ -115,8 +101,7 @@ export class RESTClient extends RPC { * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ async getHeaders({ count, hash, format = "json" }: HeaderParams) { - const uri = "rest/headers/" + count + "/" + hash + "." + format; - return this.get({ uri }); + return this.get({ uri: `rest/headers/${count}/${hash}.${format}` }); } /** @@ -140,6 +125,6 @@ export class RESTClient extends RPC { * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ async getTx({ txid, format = "json" }: TxParams) { - return this.get({ uri: "rest/tx/" + txid + "." + format }); + return this.get({ uri: `rest/tx/${txid}.${format}` }); } } diff --git a/src/rpc.ts b/src/rpc.ts index f9d2c17..ed3086b 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -33,49 +33,33 @@ export type GetBlockStatsParams = { stats?: string[]; }; -export type GetChainTxStatsParams = { - nblocks?: number; - blockhash?: string; -}; +export type GetChainTxStatsParams = { nblocks?: number; blockhash?: string }; export type GetMemPoolParams = TxId & Verbose; -export type GetTxOutParams = TxId & { - n: number; - include_mempool?: boolean; -}; +export type GetTxOutParams = TxId & { n: number; include_mempool?: boolean }; export type GetTxOutProofParams = { txids: string[]; blockhash?: string }; export type Descriptor = | string - | { - desc: string; - range: number | [number, number]; - }; + | { desc: string; range: number | [number, number] }; export type ScanTxOutSetParams = { action: "start" | "abort" | "status"; scanobjects: Descriptor[]; }; -export type HelpParams = { - command?: string; -}; +export type HelpParams = { command?: string }; export type LoggingParams = { include?: string[] | "all" | "none" | 0 | 1; exclude?: string[] | "all" | "none" | 0 | 1; }; -export type GenerateParams = { - nblocks: number; - maxtries?: number; -}; +export type GenerateParams = { nblocks: number; maxtries?: number }; -export type GenerateToAddressParams = GenerateParams & { - address: string; -}; +export type GenerateToAddressParams = GenerateParams & { address: string }; export type GetBlockTemplateParams = { template_request: { @@ -85,13 +69,9 @@ export type GetBlockTemplateParams = { }; }; -export type PrioritiseTransactionParams = TxId & { - fee_delta: number; -}; +export type PrioritiseTransactionParams = TxId & { fee_delta: number }; -export type HexData = { - hexdata: string; -}; +export type HexData = { hexdata: string }; export type AddNodeParams = { node: string; @@ -124,14 +104,9 @@ export type EstimateMode = { estimate_mode?: "UNSET" | "ECONOMICAL" | "CONSERVATIVE"; }; -export type EstimateSmartFeeParams = EstimateMode & { - conf_target: number; -}; +export type EstimateSmartFeeParams = EstimateMode & { conf_target: number }; -export type SignMessageWithPrivKeyParams = { - privkey: string; - message: string; -}; +export type SignMessageWithPrivKeyParams = { privkey: string; message: string }; export type VerifyMessageParams = { address: string; @@ -148,9 +123,7 @@ export type ConvertToPsbtParams = HexString & { export type BaseTransactionInput = { txid: string; vout: number }; -export type TransactionInput = BaseTransactionInput & { - sequence?: number; -}; +export type TransactionInput = BaseTransactionInput & { sequence?: number }; export type TransactionOutput = | { [address: string]: string | number } @@ -249,10 +222,7 @@ export type GetBalanceParams = { export type GetNewAddressParams = { address_type?: AddressType } & Label; -export type GetReceivedByAddressParams = { - address: string; - minconf?: number; -}; +export type GetReceivedByAddressParams = { address: string; minconf?: number }; export type GetReceivedByLabelParams = { label: string; @@ -275,10 +245,7 @@ export type ImportMultiRequest = { label?: string; keypool?: boolean; } & ( - | { - desc: string; - range?: number | [number, number]; - } + | { desc: string; range?: number | [number, number] } | { scriptPubKey: { address: string } | string; redeemscript?: string; @@ -290,9 +257,7 @@ export type ImportMultiRequest = { export type ImportMultiParams = { requests: ImportMultiRequest[]; - options?: { - rescan?: boolean; - }; + options?: { rescan?: boolean }; }; export type ImportPrivKeyParams = { @@ -387,14 +352,9 @@ export type SetLabelParams = { address: string; label: string }; export type SignMessageParams = { address: string; message: string }; export type WalletCreateFundedPsbtParams = BaseCreateTransaction & - BaseFundOptions & { - bip32derivs?: boolean; - }; + BaseFundOptions & { bip32derivs?: boolean }; -export type WalletPassphraseParams = { - passphrase: string; - timeout: number; -}; +export type WalletPassphraseParams = { passphrase: string; timeout: number }; export type WalletPassphraseChangeParams = { oldpassphrase: string; @@ -655,22 +615,15 @@ export class RPCClient extends RESTClient { /** * @description Mine blocks immediately to a specified address (before the RPC call returns) */ - async generatetoaddress( - { nblocks, address, maxtries = 1000000 }: GenerateToAddressParams, - wallet?: string - ) { - return this.rpc( - "generatetoaddress", - { nblocks, maxtries, address }, - wallet || this.wallet - ); + async generatetoaddress(options: GenerateToAddressParams, wallet?: string) { + return this.rpc("generatetoaddress", options, wallet || this.wallet); } /** * @description It returns data needed to construct a block to work on. */ - async getblocktemplate({ template_request }: GetBlockTemplateParams) { - return this.rpc("getblocktemplate", { template_request }); + async getblocktemplate(options: GetBlockTemplateParams) { + return this.rpc("getblocktemplate", options); } /** @@ -683,39 +636,36 @@ export class RPCClient extends RESTClient { /** * @description Returns the estimated network hashes per second based on the last `n` blocks. */ - async getnetworkhashps({ nblocks = 120, height = -1 } = {}) { - return this.rpc("getnetworkhashps", { nblocks, height }); + async getnetworkhashps(options = {}) { + return this.rpc("getnetworkhashps", options); } /** * @description Accepts the transaction into mined blocks at a higher (or lower) priority */ - async prioritisetransaction({ - txid, - fee_delta, - }: PrioritiseTransactionParams) { - return this.rpc("prioritisetransaction", { txid, fee_delta }); + async prioritisetransaction(options: PrioritiseTransactionParams) { + return this.rpc("prioritisetransaction", options); } /** * @description Attempts to submit new block to network. */ - async submitblock({ hexdata }: HexData) { - return this.rpc("submitblock", { hexdata }); + async submitblock(options: HexData) { + return this.rpc("submitblock", options); } /** * @description Decode the given hexdata as a header and submit it as a candidate chain tip if valid. */ - async submitheader({ hexdata }: HexData) { - return this.rpc("submitheader", { hexdata }); + async submitheader(options: HexData) { + return this.rpc("submitheader", options); } /** * @description Attempts to add or remove a node from the addnode list. */ - async addnode({ node, command }: AddNodeParams) { - return this.rpc("addnode", { node, command }); + async addnode(options: AddNodeParams) { + return this.rpc("addnode", options); } /** @@ -738,8 +688,8 @@ export class RPCClient extends RESTClient { /** * @description Returns information about the given added node, or all added nodes */ - async getaddednodeinfo({ node }: { node?: string } = {}) { - return this.rpc("getaddednodeinfo", { node }); + async getaddednodeinfo(options: { node?: string } = {}) { + return this.rpc("getaddednodeinfo", options); } /** @@ -766,8 +716,8 @@ export class RPCClient extends RESTClient { /** * @description Return known addresses which can potentially be used to find new nodes in the network */ - async getnodeaddresses({ count = 1 } = {}) { - return this.rpc("getnodeaddresses", { count }); + async getnodeaddresses(options = {}) { + return this.rpc("getnodeaddresses", options); } /** @@ -794,212 +744,141 @@ export class RPCClient extends RESTClient { /** * @description Attempts to add or remove an IP/Subnet from the banned list */ - async setban({ - subnet, - command, - bantime = 0, - absolute = false, - }: SetBanParams) { - return this.rpc("setban", { subnet, command, bantime, absolute }); + async setban(options: SetBanParams) { + return this.rpc("setban", options); } /** * @description Disable/enable all p2p network activity. */ - async setnetworkactive({ state }: { state: boolean }) { - return this.rpc("setnetworkactive", { state }); + async setnetworkactive(options: { state: boolean }) { + return this.rpc("setnetworkactive", options); } /** * @description Analyzes and provides information about the current status of a PSBT and its inputs */ - async analyzepsbt({ psbt }: { psbt: string }) { - return this.rpc("analyzepsbt", { psbt }); + async analyzepsbt(options: { psbt: string }) { + return this.rpc("analyzepsbt", options); } /** * @description Combine multiple partially signed Bitcoin transactions into one transaction. */ - async combinepsbt({ txs }: { txs: string[] }) { - return this.rpc("combinepsbt", { txs }); + async combinepsbt(options: { txs: string[] }) { + return this.rpc("combinepsbt", options); } /** * @description Combine multiple partially signed transactions into one transaction. */ - async combinerawtransaction({ txs }: { txs: string[] }) { - return this.rpc("combinerawtransaction", { txs }); + async combinerawtransaction(options: { txs: string[] }) { + return this.rpc("combinerawtransaction", options); } /** * @description Converts a network serialized transaction to a PSBT. */ - async converttopsbt({ - hexstring, - permitsigdata = false, - iswitness, - }: ConvertToPsbtParams) { - return this.rpc("converttopsbt", { - hexstring, - permitsigdata, - iswitness, - }); + async converttopsbt(options: ConvertToPsbtParams) { + return this.rpc("converttopsbt", options); } /** * @description Creates a transaction in the Partially Signed Transaction format. */ - async createpsbt({ - inputs, - outputs, - locktime = 0, - replaceable = false, - }: CreateTransactionParams) { - return this.rpc("createpsbt", { - inputs, - outputs, - locktime, - replaceable, - }); + async createpsbt(options: CreateTransactionParams) { + return this.rpc("createpsbt", options); } /** * @description Create a transaction spending the given inputs and creating new outputs. */ - async createrawtransaction({ - inputs, - outputs, - locktime = 0, - replaceable = false, - }: CreateTransactionParams) { - return this.rpc("createrawtransaction", { - inputs, - outputs, - locktime, - replaceable, - }); + async createrawtransaction(options: CreateTransactionParams) { + return this.rpc("createrawtransaction", options); } /** * @description Return a JSON object representing the serialized, base64-encoded partially signed Bitcoin transaction. */ - async decodepsbt({ psbt }: { psbt: string }) { - return this.rpc("decodepsbt", { psbt }); + async decodepsbt(options: { psbt: string }) { + return this.rpc("decodepsbt", options); } /** * @description Return a JSON object representing the serialized, hex-encoded transaction. */ - async decoderawtransaction({ - hexstring, - iswitness, - }: DecodeRawTransactionParams) { - return this.rpc("decoderawtransaction", { hexstring, iswitness }); + async decoderawtransaction(options: DecodeRawTransactionParams) { + return this.rpc("decoderawtransaction", options); } /** * @description Decode a hex-encoded script. */ - async decodescript({ hexstring }: HexString) { - return this.rpc("decodescript", { hexstring }); + async decodescript(options: HexString) { + return this.rpc("decodescript", options); } /** * @description Finalize the inputs of a PSBT. */ - async finalizepsbt({ psbt, extract = false }: FinalizePsbtParams) { - return this.rpc("finalizepsbt", { psbt, extract }); + async finalizepsbt(options: FinalizePsbtParams) { + return this.rpc("finalizepsbt", options); } /** * @description Add inputs to a transaction until it has enough in value to meet its out value. */ - async fundrawtransaction( - { hexstring, options, iswitness }: FundRawTransactionParams, - wallet?: string - ) { - return this.rpc( - "fundrawtransaction", - { - hexstring, - options, - iswitness, - }, - wallet || this.wallet - ); + async fundrawtransaction(options: FundRawTransactionParams, wallet?: string) { + return this.rpc("fundrawtransaction", options, wallet || this.wallet); } /** * @description Return the raw transaction data. */ - async getrawtransaction({ - txid, - verbose = false, - blockhash, - }: GetRawTransactionParams) { - return this.rpc("getrawtransaction", { txid, verbose, blockhash }); + async getrawtransaction(options: GetRawTransactionParams) { + return this.rpc("getrawtransaction", options); } /** * @description Joins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs. */ - async joinpsbts({ txs }: { txs: string[] }) { - return this.rpc("joinpsbts", { txs }); + async joinpsbts(options: { txs: string[] }) { + return this.rpc("joinpsbts", options); } /** * @description Submits raw transaction (serialized, hex-encoded) to local node and network. */ - async sendrawtransaction({ - hexstring, - allowhighfees = false, - }: SendRawTransactionParams) { - return this.rpc("sendrawtransaction", { hexstring, allowhighfees }); + async sendrawtransaction(options: SendRawTransactionParams) { + return this.rpc("sendrawtransaction", options); } /** * @description Sign inputs for raw transaction */ - async signrawtransactionwithkey({ - hexstring, - privkeys, - prevtxs, - sighashtype = "ALL", - }: SignRawTransactionWithKeyParams) { - return this.rpc("signrawtransactionwithkey", { - hexstring, - privkeys, - prevtxs, - sighashtype, - }); + async signrawtransactionwithkey(options: SignRawTransactionWithKeyParams) { + return this.rpc("signrawtransactionwithkey", options); } /** * @description Returns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded) would be accepted by mempool. */ - async testmempoolaccept({ - rawtxs, - allowhighfees = false, - }: TestmemPoolAcceptParams) { - return this.rpc("testmempoolaccept", { rawtxs, allowhighfees }); + async testmempoolaccept(options: TestmemPoolAcceptParams) { + return this.rpc("testmempoolaccept", options); } /** * @description Updates a PSBT with witness UTXOs retrieved from the UTXO set or the mempool. */ - async utxoupdatepsbt({ psbt }: { psbt: string }) { - return this.rpc("utxoupdatepsbt", { psbt }); + async utxoupdatepsbt(options: { psbt: string }) { + return this.rpc("utxoupdatepsbt", options); } /** * @description Creates a multi-signature address with n signature of m keys required. */ - async createmultisig({ - nrequired, - keys, - address_type = "legacy", - }: CreateMultiSigParams) { - return this.rpc("createmultisig", { nrequired, keys, address_type }); + async createmultisig(options: CreateMultiSigParams) { + return this.rpc("createmultisig", options); } /** @@ -1012,49 +891,43 @@ export class RPCClient extends RESTClient { /** * @description Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within `conf_target` blocks if possible and return the number of blocks for which the estimate is valid. */ - async estimatesmartfee({ - conf_target, - estimate_mode = "CONSERVATIVE", - }: EstimateSmartFeeParams) { - return this.rpc("estimatesmartfee", { conf_target, estimate_mode }); + async estimatesmartfee(options: EstimateSmartFeeParams) { + return this.rpc("estimatesmartfee", options); } /** * @description Analyses a descriptor. */ - async getdescriptorinfo({ descriptor }: { descriptor: string }) { - return this.rpc("getdescriptorinfo", { descriptor }); + async getdescriptorinfo(options: { descriptor: string }) { + return this.rpc("getdescriptorinfo", options); } /** * @description Sign a message with the private key of an address. */ - async signmessagewithprivkey({ - privkey, - message, - }: SignMessageWithPrivKeyParams) { - return this.rpc("signmessagewithprivkey", { privkey, message }); + async signmessagewithprivkey(options: SignMessageWithPrivKeyParams) { + return this.rpc("signmessagewithprivkey", options); } /** * @description Return information about the given bitcoin address. */ - async validateaddress({ address }: { address: string }) { - return this.rpc("validateaddress", { address }); + async validateaddress(options: { address: string }) { + return this.rpc("validateaddress", options); } /** * @description Verify a signed message */ - async verifymessage({ address, signature, message }: VerifyMessageParams) { - return this.rpc("verifymessage", { address, signature, message }); + async verifymessage(options: VerifyMessageParams) { + return this.rpc("verifymessage", options); } /** * @description Mark in-wallet transaction `txid` as abandoned */ - async abandontransaction({ txid }: TxId, wallet?: string) { - return this.rpc("abandontransaction", { txid }, wallet || this.wallet); + async abandontransaction(options: TxId, wallet?: string) { + return this.rpc("abandontransaction", options, wallet || this.wallet); } /** @@ -1067,166 +940,112 @@ export class RPCClient extends RESTClient { /** * @description Add a nrequired-to-sign multisignature address to the wallet. */ - async addmultisigaddress( - { nrequired, keys, label, address_type }: AddMultiSigAddressParams, - wallet?: string - ) { - return this.rpc( - "addmultisigaddress", - { nrequired, keys, label, address_type }, - wallet || this.wallet - ); + async addmultisigaddress(options: AddMultiSigAddressParams, wallet?: string) { + return this.rpc("addmultisigaddress", options, wallet || this.wallet); } /** * @description Safely copies current wallet file to destination. */ - async backupwallet( - { destination }: { destination: string }, - wallet?: string - ) { - return this.rpc("backupwallet", { destination }, wallet || this.wallet); + async backupwallet(options: { destination: string }, wallet?: string) { + return this.rpc("backupwallet", options, wallet || this.wallet); } /** * @description Bumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B. */ - async bumpfee({ txid, options }: BumpFeeParams, wallet?: string) { - return this.rpc("bumpfee", { txid, options }, wallet || this.wallet); + async bumpfee(options: BumpFeeParams, wallet?: string) { + return this.rpc("bumpfee", options, wallet || this.wallet); } /** * @description Creates and loads a new wallet. */ - async createwallet({ - wallet_name, - disable_private_keys = false, - blank = false, - }: CreateWalletParams) { - return this.rpc("createwallet", { - wallet_name, - disable_private_keys, - blank, - }); + async createwallet(options: CreateWalletParams) { + return this.rpc("createwallet", options); } /** * @description Reveals the private key corresponding to 'address'. */ - async dumpprivkey({ address }: { address: string }, wallet?: string) { - return this.rpc("dumpprivkey", { address }, wallet || this.wallet); + async dumpprivkey(options: { address: string }, wallet?: string) { + return this.rpc("dumpprivkey", options, wallet || this.wallet); } /** * @description Dumps all wallet keys in a human-readable format to a server-side file. */ - async dumpwallet({ filename }: { filename: string }, wallet?: string) { - return this.rpc("dumpwallet", { filename }, wallet || this.wallet); + async dumpwallet(options: { filename: string }, wallet?: string) { + return this.rpc("dumpwallet", options, wallet || this.wallet); } /** * @description Encrypts the wallet with 'passphrase'. */ - async encryptwallet({ passphrase }: { passphrase: string }, wallet?: string) { - return this.rpc("encryptwallet", { passphrase }, wallet || this.wallet); + async encryptwallet(options: { passphrase: string }, wallet?: string) { + return this.rpc("encryptwallet", options, wallet || this.wallet); } /** * @description Returns the list of addresses assigned the specified label. */ - async getaddressesbylabel({ label }: { label: string }, wallet?: string) { - return this.rpc("getaddressesbylabel", { label }, wallet || this.wallet); + async getaddressesbylabel(options: { label: string }, wallet?: string) { + return this.rpc("getaddressesbylabel", options, wallet || this.wallet); } /** * @description Return information about the given bitcoin address. */ - async getaddressinfo({ address }: { address: string }, wallet?: string) { - return this.rpc("getaddressinfo", { address }, wallet || this.wallet); + async getaddressinfo(options: { address: string }, wallet?: string) { + return this.rpc("getaddressinfo", options, wallet || this.wallet); } /** * @description Returns the total available balance. */ - async getbalance( - { minconf, include_watchonly = false }: GetBalanceParams, - wallet?: string - ) { - return this.rpc( - "getbalance", - { minconf, include_watchonly }, - wallet || this.wallet - ); + async getbalance(options: GetBalanceParams, wallet?: string) { + return this.rpc("getbalance", options, wallet || this.wallet); } /** * @description Returns a new Bitcoin address for receiving payments. */ - async getnewaddress( - { label = "", address_type }: GetNewAddressParams, - wallet?: string - ) { - return this.rpc( - "getnewaddress", - { label, address_type }, - wallet || this.wallet - ); + async getnewaddress(options: GetNewAddressParams, wallet?: string) { + return this.rpc("getnewaddress", options, wallet || this.wallet); } /** * @description Returns a new Bitcoin address, for receiving change. */ async getrawchangeaddress( - { address_type }: { address_type?: AddressType }, + options: { address_type?: AddressType }, wallet?: string ) { - return this.rpc( - "getrawchangeaddress", - { address_type }, - wallet || this.wallet - ); + return this.rpc("getrawchangeaddress", options, wallet || this.wallet); } /** * @description Returns the total amount received by the given address in transactions with at least minconf confirmations. */ async getreceivedbyaddress( - { address, minconf = 1 }: GetReceivedByAddressParams, + options: GetReceivedByAddressParams, wallet?: string ) { - return this.rpc( - "getreceivedbyaddress", - { address, minconf }, - wallet || this.wallet - ); + return this.rpc("getreceivedbyaddress", options, wallet || this.wallet); } /** * @description Returns the total amount received by addresses with `label` in transactions with at least `minconf` confirmations. */ - async getreceivedbylabel( - { label, minconf = 1 }: GetReceivedByLabelParams, - wallet?: string - ) { - return this.rpc( - "getreceivedbylabel", - { label, minconf }, - wallet || this.wallet - ); + async getreceivedbylabel(options: GetReceivedByLabelParams, wallet?: string) { + return this.rpc("getreceivedbylabel", options, wallet || this.wallet); } /** * @description Get detailed information about in-wallet transaction `txid` */ - async gettransaction( - { txid, include_watchonly = false }: GetTransactionParams, - wallet?: string - ) { - return this.rpc( - "gettransaction", - { txid, include_watchonly }, - wallet || this.wallet - ); + async gettransaction(options: GetTransactionParams, wallet?: string) { + return this.rpc("gettransaction", options, wallet || this.wallet); } /** @@ -1246,85 +1065,50 @@ export class RPCClient extends RESTClient { /** * @description Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. */ - async importaddress( - { address, label = "", rescan = true, p2sh = false }: ImportAddressParams, - wallet?: string - ) { - return this.rpc( - "importaddress", - { address, label, rescan, p2sh }, - wallet || this.wallet - ); + async importaddress(options: ImportAddressParams, wallet?: string) { + return this.rpc("importaddress", options, wallet || this.wallet); } /** * @description Import addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. */ - async importmulti({ requests, options }: ImportMultiParams, wallet?: string) { - return this.rpc( - "importmulti", - { requests, options }, - wallet || this.wallet - ); + async importmulti(options: ImportMultiParams, wallet?: string) { + return this.rpc("importmulti", options, wallet || this.wallet); } /** * @description Adds a private key (as returned by `dumpprivkey`) to your wallet. */ - async importprivkey( - { privkey, label, rescan }: ImportPrivKeyParams, - wallet?: string - ) { - return this.rpc( - "importprivkey", - { privkey, label, rescan }, - wallet || this.wallet - ); + async importprivkey(options: ImportPrivKeyParams, wallet?: string) { + return this.rpc("importprivkey", options, wallet || this.wallet); } /** * @description Imports funds without rescan. Corresponding address or script must previously be included in wallet. */ - async importprunedfunds( - { rawtransaction, txoutproof }: ImportPrunedFundsParams, - wallet?: string - ) { - return this.rpc( - "importprunedfunds", - { rawtransaction, txoutproof }, - wallet || this.wallet - ); + async importprunedfunds(options: ImportPrunedFundsParams, wallet?: string) { + return this.rpc("importprunedfunds", options, wallet || this.wallet); } /** * @description Adds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. */ - async importpubkey( - { pubkey, label = "", rescan = true }: ImportPubKeyParams, - wallet?: string - ) { - return this.rpc( - "importpubkey", - { pubkey, label, rescan }, - wallet || this.wallet - ); + async importpubkey(options: ImportPubKeyParams, wallet?: string) { + return this.rpc("importpubkey", options, wallet || this.wallet); } /** * @description Imports keys from a wallet dump file (see `dumpwallet`). */ - async importwallet({ filename }: { filename: string }, wallet?: string) { - return this.rpc("importwallet", { filename }, wallet || this.wallet); + async importwallet(options: { filename: string }, wallet?: string) { + return this.rpc("importwallet", options, wallet || this.wallet); } /** * @description Fills the keypool. */ - async keypoolrefill( - { newsize = 100 }: { newsize?: number }, - wallet?: string - ) { - return this.rpc("keypoolrefill", { newsize }, wallet || this.wallet); + async keypoolrefill(options: { newsize?: number }, wallet?: string) { + return this.rpc("keypoolrefill", options, wallet || this.wallet); } /** @@ -1337,8 +1121,8 @@ export class RPCClient extends RESTClient { /** * @description Returns the list of all labels, or labels that are assigned to addresses with a specific purpose. */ - async listlabels({ purpose }: ListLabelsParams, wallet?: string) { - return this.rpc("listlabels", { purpose }, wallet || this.wallet); + async listlabels(options: ListLabelsParams, wallet?: string) { + return this.rpc("listlabels", options, wallet || this.wallet); } /** @@ -1352,95 +1136,41 @@ export class RPCClient extends RESTClient { * @description List balances by receiving address. */ async listreceivedbyaddress( - { - minconf = 1, - include_empty = false, - include_watchonly = false, - address_filter, - }: ListReceivedByAddressParams, + options: ListReceivedByAddressParams, wallet?: string ) { - return this.rpc( - "listreceivedbyaddress", - { minconf, include_empty, include_watchonly, address_filter }, - wallet || this.wallet - ); + return this.rpc("listreceivedbyaddress", options, wallet || this.wallet); } /** * @description List received transactions by label. */ async listreceivedbylabel( - { - minconf = 1, - include_empty = false, - include_watchonly = false, - }: ListReceivedByLabelParams, + options: ListReceivedByLabelParams, wallet?: string ) { - return this.rpc( - "listreceivedbylabel", - { minconf, include_empty, include_watchonly }, - wallet || this.wallet - ); + return this.rpc("listreceivedbylabel", options, wallet || this.wallet); } /** * @description Get all transactions in blocks since block `blockhash`, or all transactions if omitted. */ - async listsinceblock( - { - blockhash, - target_confirmations = 1, - include_watchonly = false, - include_removed = true, - }: ListSinceBlockParams, - wallet?: string - ) { - return this.rpc( - "listsinceblock", - { blockhash, target_confirmations, include_watchonly, include_removed }, - wallet || this.wallet - ); + async listsinceblock(options: ListSinceBlockParams, wallet?: string) { + return this.rpc("listsinceblock", options, wallet || this.wallet); } /** * @description Returns up to `count` most recent transactions skipping the first `skip` transactions. */ - async listtransactions( - { - label, - count = 10, - skip = 0, - include_watchonly = false, - }: ListTransactionsParams, - wallet?: string - ) { - return this.rpc( - "listtransactions", - { label, count, skip, include_watchonly }, - wallet || this.wallet - ); + async listtransactions(options: ListTransactionsParams, wallet?: string) { + return this.rpc("listtransactions", options, wallet || this.wallet); } /** * @description Returns array of unspent transaction outputs with between `minconf` and `maxconf` (inclusive) confirmations. */ - async listunspent( - { - minconf = 1, - maxconf = 9999999, - addresses, - include_unsafe = true, - query_options, - }: ListUnspentParams, - wallet?: string - ) { - return this.rpc( - "listunspent", - { minconf, maxconf, addresses, include_unsafe, query_options }, - wallet || this.wallet - ); + async listunspent(options: ListUnspentParams, wallet?: string) { + return this.rpc("listunspent", options, wallet || this.wallet); } /** @@ -1467,142 +1197,76 @@ export class RPCClient extends RESTClient { /** * @description Updates list of temporarily unspendable outputs. */ - async lockunspent( - { unlock, transactions }: LockUnspentParams, - wallet?: string - ) { - return this.rpc( - "lockunspent", - { unlock, transactions }, - wallet || this.wallet - ); + async lockunspent(options: LockUnspentParams, wallet?: string) { + return this.rpc("lockunspent", options, wallet || this.wallet); } /** * @description Deletes the specified transaction from the wallet. */ - async removeprunedfunds({ txid }: TxId, wallet?: string) { - return this.rpc("removeprunedfunds", { txid }, wallet || this.wallet); + async removeprunedfunds(options: TxId, wallet?: string) { + return this.rpc("removeprunedfunds", options, wallet || this.wallet); } /** * @description Rescan the local blockchain for wallet related transactions. */ - async rescanblockchain( - { start_height = 0, stop_height }: RescanBlockchainParams, - wallet?: string - ) { - return this.rpc( - "rescanblockchain", - { start_height, stop_height }, - wallet || this.wallet - ); + async rescanblockchain(options: RescanBlockchainParams, wallet?: string) { + return this.rpc("rescanblockchain", options, wallet || this.wallet); } /** * @description Send multiple times. */ - async sendmany( - { - amounts, - minconf = 1, - comment, - subtractfeefrom, - replaceable, - conf_target, - estimate_mode = "UNSET", - }: SendManyParams, - wallet?: string - ) { - return this.rpc( - "sendmany", - { - amounts, - minconf, - comment, - subtractfeefrom, - replaceable, - conf_target, - estimate_mode, - }, - wallet || this.wallet - ); + async sendmany(options: SendManyParams, wallet?: string) { + return this.rpc("sendmany", options, wallet || this.wallet); } /** * @description Send an amount to a given address. */ - async sendtoaddress( - { - address, - amount, - comment, - comment_to, - subtractfeefromamount = false, - replaceable, - conf_target, - estimate_mode = "UNSET", - }: SendToAddressParams, - wallet?: string - ) { - return this.rpc( - "sendtoaddress", - { - address, - amount, - comment, - comment_to, - subtractfeefromamount, - replaceable, - conf_target, - estimate_mode, - }, - wallet || this.wallet - ); + async sendtoaddress(options: SendToAddressParams, wallet?: string) { + return this.rpc("sendtoaddress", options, wallet || this.wallet); } /** * @description Set or generate a new HD wallet seed. */ - async sethdseed({ newkeypool, seed }: SetHDSeedParams, wallet?: string) { - return this.rpc("sethdseed", { newkeypool, seed }, wallet || this.wallet); + async sethdseed(options: SetHDSeedParams, wallet?: string) { + return this.rpc("sethdseed", options, wallet || this.wallet); } /** * @description Sets the label associated with the given address. */ - async setlabel({ address, label }: SetLabelParams, wallet?: string) { - return this.rpc("setlabel", { address, label }, wallet || this.wallet); + async setlabel(options: SetLabelParams, wallet?: string) { + return this.rpc("setlabel", options, wallet || this.wallet); } /** * @description Set the transaction fee per kB for this wallet. */ - async settxfee({ amount }: { amount: number | string }, wallet?: string) { - return this.rpc("settxfee", { amount }, wallet || this.wallet); + async settxfee(options: { amount: number | string }, wallet?: string) { + return this.rpc("settxfee", options, wallet || this.wallet); } /** * @description Sign a message with the private key of an address */ - async signmessage({ address, message }: SignMessageParams, wallet?: string) { - return this.rpc("signmessage", { address, message }, wallet || this.wallet); + async signmessage(options: SignMessageParams, wallet?: string) { + return this.rpc("signmessage", options, wallet || this.wallet); } /** * @description Sign inputs for raw transaction */ async signrawtransactionwithwallet( - { - hexstring, - prevtxs, - sighashtype = "ALL", - }: SignRawTransactionWithWalletParams, + options: SignRawTransactionWithWalletParams, wallet?: string ) { return this.rpc( "signrawtransactionwithwallet", - { hexstring, prevtxs, sighashtype }, + options, wallet || this.wallet ); } @@ -1621,20 +1285,10 @@ export class RPCClient extends RESTClient { * @description Creates and funds a transaction in the Partially Signed Transaction format. */ async walletcreatefundedpsbt( - { - inputs, - outputs, - locktime = 0, - options, - bip32derivs = false, - }: WalletCreateFundedPsbtParams, + options: WalletCreateFundedPsbtParams, wallet?: string ) { - return this.rpc( - "walletcreatefundedpsbt", - { inputs, outputs, locktime, options, bip32derivs }, - wallet || this.wallet - ); + return this.rpc("walletcreatefundedpsbt", options, wallet || this.wallet); } /** @@ -1647,48 +1301,25 @@ export class RPCClient extends RESTClient { /** * @description Stores the wallet decryption key in memory for `timeout` seconds. */ - async walletpassphrase( - { passphrase, timeout }: WalletPassphraseParams, - wallet?: string - ) { - return this.rpc( - "walletpassphrase", - { passphrase, timeout }, - wallet || this.wallet - ); + async walletpassphrase(options: WalletPassphraseParams, wallet?: string) { + return this.rpc("walletpassphrase", options, wallet || this.wallet); } /** * @description Changes the wallet passphrase from `oldpassphrase` to `newpassphrase`. */ async walletpassphrasechange( - { oldpassphrase, newpassphrase }: WalletPassphraseChangeParams, + options: WalletPassphraseChangeParams, wallet?: string ) { - return this.rpc( - "walletpassphrasechange", - { oldpassphrase, newpassphrase }, - wallet || this.wallet - ); + return this.rpc("walletpassphrasechange", options, wallet || this.wallet); } /** * @description Update a PSBT with input information from our wallet and then sign inputs that we can sign for. */ - async walletprocesspsbt( - { - psbt, - sign = true, - sighashtype = "ALL", - bip32derivs = false, - }: WalletProcessPsbtParams, - wallet?: string - ) { - return this.rpc( - "walletprocesspsbt", - { psbt, sign, sighashtype, bip32derivs }, - wallet || this.wallet - ); + async walletprocesspsbt(options: WalletProcessPsbtParams, wallet?: string) { + return this.rpc("walletprocesspsbt", options, wallet || this.wallet); } /** From ee6dde96e7ba249c810099726b09d1ddbfd92d41 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:35:15 +0300 Subject: [PATCH 03/23] ci(github): add publish workflow --- .github/workflows/publish.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b726598 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,25 @@ +name: Publish + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + with: + node-version: 12 + registry-url: "https://registry.npmjs.org" + - name: Node.js version + run: node -v + - name: npm version + run: npm -v + - name: Install dependencies + run: npm ci + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.npm_token }} From c288a8e5dfbf91b68ff4b7f58e8906fbfbe828f5 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:35:36 +0300 Subject: [PATCH 04/23] chore: remove test eslint config --- test/.eslintrc.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 test/.eslintrc.json diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index 7eeefc3..0000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "env": { - "mocha": true - } -} From 34bb976e7b359af13d91451e6c54bb2303304c07 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:39:17 +0300 Subject: [PATCH 05/23] ci(travis): update config --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f02abe..d4c793d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,12 @@ language: node_js node_js: - - stable - - lts/* + - 10 + - 11 + - 12 + - 13 script: - npm run prettier - npm run lint - npm test + - prepublishOnly + - postpublish From b5f7dfed35a5d10d23ae1a388ee1039898a4e9e9 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:39:52 +0300 Subject: [PATCH 06/23] chore: update tsconfig --- tsconfig.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 00522dc..70058f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,19 @@ { "compilerOptions": { - "target": "es2019", + "target": "esnext", "module": "commonjs", "declaration": true, - "declarationMap": true, "outDir": "./build", - "sourceMap": true, + "newLine": "lf", "strict": true, "noImplicitAny": true, + "noImplicitThis": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "moduleResolution": "node" + "removeComments": true, + "forceConsistentCasingInFileNames": true }, - "exclude": ["node_modules", "**/*.spec.ts", "bin"] + "exclude": ["test"] } From fa5a38881ede1a74bc1536d3b2e2c076dbcb0923 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:40:04 +0300 Subject: [PATCH 07/23] chore: add .npmignore --- .npmignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..5353823 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +src/ +test/ +tsconfig.json +index.ts +.github/ +.eslintrc.json From 7ccc67e5c8cfebf465fe596c42917c543c246f29 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:56:55 +0300 Subject: [PATCH 08/23] chore: remove async keyword --- src/rest.ts | 22 ++--- src/rpc.ts | 267 +++++++++++++++++++++++++--------------------------- 2 files changed, 138 insertions(+), 151 deletions(-) diff --git a/src/rest.ts b/src/rest.ts index e536a5e..ed85101 100644 --- a/src/rest.ts +++ b/src/rest.ts @@ -42,7 +42,7 @@ export class RESTClient extends RPC { * @param {string} params.hash - The hash of the header of the block to get * @param {string} [params.format='json'] - Set to 'json' for decoded block contents in JSON, or 'bin' or 'hex' for a serialized block in binary or hex */ - async getBlock({ hash, format = "json" }: BlockParams) { + getBlock({ hash, format = "json" }: BlockParams) { return this.get({ uri: `/rest/block/${hash}.${format}` }); } @@ -52,7 +52,7 @@ export class RESTClient extends RPC { * @param {string} params.hash - The hash of the header of the block to get * @param {string} [params.format='json'] - Set to 'json' for decoded block contents in JSON, or 'bin' or 'hex' for a serialized block in binary or hex */ - async getBlockNoTxDetails({ hash, format = "json" }: BlockParams) { + getBlockNoTxDetails({ hash, format = "json" }: BlockParams) { return this.get({ uri: `/rest/block/notxdetails/${hash}.${format}` }); } @@ -62,14 +62,14 @@ export class RESTClient extends RPC { * @param {number} params.height - The height of the block * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ - async getBlockHashByHeight({ height, format = "json" }: BlockHeightParams) { + getBlockHashByHeight({ height, format = "json" }: BlockHeightParams) { return this.get({ uri: `/rest/blockhashbyheight/${height}.${format}` }); } /** * @description Get information about the current state of the block chain. */ - async getChainInfo() { + getChainInfo() { return this.get({ uri: "rest/chaininfo.json" }); } @@ -80,11 +80,7 @@ export class RESTClient extends RPC { * @param {Object|Object[]} params.outpoints - The list of outpoints to be queried. * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ - async getUtxos({ - checkmempool = true, - outpoints, - format = "json", - }: UtxosParams) { + getUtxos({ checkmempool = true, outpoints, format = "json" }: UtxosParams) { let uri = `rest/getutxos${checkmempool ? "/checkmempool" : ""}`; outpoints = !Array.isArray(outpoints) ? [outpoints] : outpoints; for (const { txid, n } of outpoints) { @@ -100,21 +96,21 @@ export class RESTClient extends RPC { * @param {string} params.hash - The hash of the header of the block to get * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ - async getHeaders({ count, hash, format = "json" }: HeaderParams) { + getHeaders({ count, hash, format = "json" }: HeaderParams) { return this.get({ uri: `rest/headers/${count}/${hash}.${format}` }); } /** * @description Get all transaction in the memory pool with detailed information. */ - async getMemPoolContents() { + getMemPoolContents() { return this.get({ uri: "rest/mempool/contents.json" }); } /** * @description Get information about the node’s current transaction memory pool. */ - async getMemPoolInfo() { + getMemPoolInfo() { return this.get({ uri: "rest/mempool/info.json" }); } @@ -124,7 +120,7 @@ export class RESTClient extends RPC { * @param {string} params.txid - The TXID of the transaction to get. * @param {string} [params.format='json'] - Set to `json`, `bin` or `hex`. */ - async getTx({ txid, format = "json" }: TxParams) { + getTx({ txid, format = "json" }: TxParams) { return this.get({ uri: `rest/tx/${txid}.${format}` }); } } diff --git a/src/rpc.ts b/src/rpc.ts index ed3086b..abd5dd5 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -384,7 +384,7 @@ export class RPCClient extends RESTClient { this.wallet = typeof wallet === "string" ? wallet : undefined; } - async batch(body: JSONRPC | JSONRPC[], uri = "/") { + batch(body: JSONRPC | JSONRPC[], uri = "/") { return super.post({ body, uri }); } @@ -405,280 +405,280 @@ export class RPCClient extends RESTClient { /** * @description Returns the hash of the best (tip) block in the longest blockchain. */ - async getbestblockhash() { + getbestblockhash() { return this.rpc("getbestblockhash"); } /** * @description If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'. If verbosity is 1, returns an Object with information about block . If verbosity is 2, returns an Object with information about block and information about each transaction. */ - async getblock({ blockhash, verbosity = 1 }: GetBlockParams) { + getblock({ blockhash, verbosity = 1 }: GetBlockParams) { return this.rpc("getblock", { blockhash, verbosity }); } /** * @description Returns an object containing various state info regarding blockchain processing. */ - async getblockchaininfo() { + getblockchaininfo() { return this.rpc("getblockchaininfo"); } /** * @description Returns the number of blocks in the longest blockchain. */ - async getblockcount() { + getblockcount() { return this.rpc("getblockcount"); } /** * @description Returns hash of block in best-block-chain at height provided. */ - async getblockhash({ height }: Height) { + getblockhash({ height }: Height) { return this.rpc("getblockhash", { height }); } /** * @description If verbose is `false`, returns a string that is serialized, hex-encoded data for blockheader 'hash'. If verbose is `true`, returns an Object with information about blockheader . */ - async getblockheader({ blockhash, verbose = true }: GetBlockHeaderParams) { + getblockheader({ blockhash, verbose = true }: GetBlockHeaderParams) { return this.rpc("getblockheader", { blockhash, verbose }); } /** * @description Compute per block statistics for a given window. */ - async getblockstats({ hash_or_height, stats = [] }: GetBlockStatsParams) { + getblockstats({ hash_or_height, stats = [] }: GetBlockStatsParams) { return this.rpc("getblockstats", { hash_or_height, stats }); } /** * @description Return information about all known tips in the block tree, including the main chain as well as orphaned branches. */ - async getchaintips() { + getchaintips() { return this.rpc("getchaintips"); } /** * @description Compute statistics about the total number and rate of transactions in the chain. */ - async getchaintxstats({ nblocks, blockhash }: GetChainTxStatsParams) { + getchaintxstats({ nblocks, blockhash }: GetChainTxStatsParams) { return this.rpc("getchaintxstats", { nblocks, blockhash }); } /** * @description Returns the proof-of-work difficulty as a multiple of the minimum difficulty. */ - async getdifficulty() { + getdifficulty() { return this.rpc("getdifficulty"); } /** * @description If txid is in the mempool, returns all in-mempool ancestors. */ - async getmempoolancestors({ txid, verbose = false }: GetMemPoolParams) { + getmempoolancestors({ txid, verbose = false }: GetMemPoolParams) { return this.rpc("getmempoolancestors", { txid, verbose }); } /** * @description If txid is in the mempool, returns all in-mempool descendants. */ - async getmempooldescendants({ txid, verbose = false }: GetMemPoolParams) { + getmempooldescendants({ txid, verbose = false }: GetMemPoolParams) { return this.rpc("getmempooldescendants", { txid, verbose }); } /** * @description Returns mempool data for given transaction */ - async getmempoolentry({ txid }: TxId) { + getmempoolentry({ txid }: TxId) { return this.rpc("getmempoolentry", { txid }); } /** * @description Returns details on the active state of the TX memory pool. */ - async getmempoolinfo() { + getmempoolinfo() { return this.rpc("getmempoolinfo"); } /** * @description Returns all transaction ids in memory pool as a json array of string transaction ids. */ - async getrawmempool({ verbose = false }: Verbose = {}) { + getrawmempool({ verbose = false }: Verbose = {}) { return this.rpc("getrawmempool", { verbose }); } /** * @description Returns details about an unspent transaction output. */ - async gettxout({ txid, n, include_mempool = true }: GetTxOutParams) { + gettxout({ txid, n, include_mempool = true }: GetTxOutParams) { return this.rpc("gettxout", { txid, n, include_mempool }); } /** * @description Returns a hex-encoded proof that "txid" was included in a block. */ - async gettxoutproof({ txids, blockhash }: GetTxOutProofParams) { + gettxoutproof({ txids, blockhash }: GetTxOutProofParams) { return this.rpc("gettxoutproof", { txids, blockhash }); } /** * @description Returns statistics about the unspent transaction output set. */ - async gettxoutsetinfo() { + gettxoutsetinfo() { return this.rpc("gettxoutsetinfo"); } /** * @description Treats a block as if it were received before others with the same work. */ - async preciousblock({ blockhash }: Blockhash) { + preciousblock({ blockhash }: Blockhash) { return this.rpc("preciousblock", { blockhash }); } /** * @description Prune the blockchain. */ - async pruneblockchain({ height }: Height) { + pruneblockchain({ height }: Height) { return this.rpc("pruneblockchain", { height }); } /** * @description Dumps the mempool to disk. It will fail until the previous dump is fully loaded. */ - async savemempool() { + savemempool() { return this.rpc("savemempool"); } /** * @description Scans the unspent transaction output set for entries that match certain output descriptors. */ - async scantxoutset({ action, scanobjects }: ScanTxOutSetParams) { + scantxoutset({ action, scanobjects }: ScanTxOutSetParams) { return this.rpc("scantxoutset", { action, scanobjects }); } /** * @description Verifies blockchain database. */ - async verifychain({ checklevel = 3, nblocks = 6 } = {}) { + verifychain({ checklevel = 3, nblocks = 6 } = {}) { return this.rpc("verifychain", { checklevel, nblocks }); } /** * @description Verifies that a proof points to a transaction in a block, returning the transaction it commits to and throwing an RPC error if the block is not in our best chain. */ - async verifytxoutproof({ proof }: { proof: string }) { + verifytxoutproof({ proof }: { proof: string }) { return this.rpc("verifytxoutproof", { proof }); } /** * @description Returns an object containing information about memory usage. */ - async getmemoryinfo({ mode = "stats" } = {}) { + getmemoryinfo({ mode = "stats" } = {}) { return this.rpc("getmemoryinfo", { mode }); } /** * @description Returns details of the RPC server. */ - async getrpcinfo() { + getrpcinfo() { return this.rpc("getrpcinfo"); } /** * @description List all commands, or get help for a specified command. */ - async help({ command }: HelpParams = {}) { + help({ command }: HelpParams = {}) { return this.rpc("help", { command }); } /** * @description Gets and sets the logging configuration. */ - async logging({ include, exclude }: LoggingParams = {}) { + logging({ include, exclude }: LoggingParams = {}) { return this.rpc("logging", { include, exclude }); } /** * @description Stop Bitcoin server. */ - async stop() { + stop() { return this.rpc("stop"); } /** * @description Returns the total uptime of the server. */ - async uptime() { + uptime() { return this.rpc("uptime"); } /** * @description Mine blocks immediately to a specified address (before the RPC call returns) */ - async generatetoaddress(options: GenerateToAddressParams, wallet?: string) { + generatetoaddress(options: GenerateToAddressParams, wallet?: string) { return this.rpc("generatetoaddress", options, wallet || this.wallet); } /** * @description It returns data needed to construct a block to work on. */ - async getblocktemplate(options: GetBlockTemplateParams) { + getblocktemplate(options: GetBlockTemplateParams) { return this.rpc("getblocktemplate", options); } /** * @description Returns a json object containing mining-related information. */ - async getmininginfo() { + getmininginfo() { return this.rpc("getmininginfo"); } /** * @description Returns the estimated network hashes per second based on the last `n` blocks. */ - async getnetworkhashps(options = {}) { + getnetworkhashps(options = {}) { return this.rpc("getnetworkhashps", options); } /** * @description Accepts the transaction into mined blocks at a higher (or lower) priority */ - async prioritisetransaction(options: PrioritiseTransactionParams) { + prioritisetransaction(options: PrioritiseTransactionParams) { return this.rpc("prioritisetransaction", options); } /** * @description Attempts to submit new block to network. */ - async submitblock(options: HexData) { + submitblock(options: HexData) { return this.rpc("submitblock", options); } /** * @description Decode the given hexdata as a header and submit it as a candidate chain tip if valid. */ - async submitheader(options: HexData) { + submitheader(options: HexData) { return this.rpc("submitheader", options); } /** * @description Attempts to add or remove a node from the addnode list. */ - async addnode(options: AddNodeParams) { + addnode(options: AddNodeParams) { return this.rpc("addnode", options); } /** * @description Clear all banned IPs. */ - async clearbanned() { + clearbanned() { return this.rpc("clearbanned"); } /** * @description Immediately disconnects from the specified peer node. */ - async disconnectnode(params: DisconnectNodeParams) { + disconnectnode(params: DisconnectNodeParams) { if ("address" in params) { return this.rpc("disconnectnode", { address: params.address }); } @@ -688,336 +688,336 @@ export class RPCClient extends RESTClient { /** * @description Returns information about the given added node, or all added nodes */ - async getaddednodeinfo(options: { node?: string } = {}) { + getaddednodeinfo(options: { node?: string } = {}) { return this.rpc("getaddednodeinfo", options); } /** * @description Returns the number of connections to other nodes. */ - async getconnectioncount() { + getconnectioncount() { return this.rpc("getconnectioncount"); } /** * @description Returns information about network traffic, including bytes in, bytes out, and current time. */ - async getnettotals() { + getnettotals() { return this.rpc("getnettotals"); } /** * @description Returns an object containing various state info regarding P2P networking. */ - async getnetworkinfo() { + getnetworkinfo() { return this.rpc("getnetworkinfo"); } /** * @description Return known addresses which can potentially be used to find new nodes in the network */ - async getnodeaddresses(options = {}) { + getnodeaddresses(options = {}) { return this.rpc("getnodeaddresses", options); } /** * @description Returns data about each connected network node as a json array of objects. */ - async getpeerinfo() { + getpeerinfo() { return this.rpc("getpeerinfo"); } /** * @description List all banned IPs/Subnets. */ - async listbanned() { + listbanned() { return this.rpc("listbanned"); } /** * @description Requests that a ping be sent to all other nodes, to measure ping time. */ - async ping() { + ping() { return this.rpc("ping"); } /** * @description Attempts to add or remove an IP/Subnet from the banned list */ - async setban(options: SetBanParams) { + setban(options: SetBanParams) { return this.rpc("setban", options); } /** * @description Disable/enable all p2p network activity. */ - async setnetworkactive(options: { state: boolean }) { + setnetworkactive(options: { state: boolean }) { return this.rpc("setnetworkactive", options); } /** * @description Analyzes and provides information about the current status of a PSBT and its inputs */ - async analyzepsbt(options: { psbt: string }) { + analyzepsbt(options: { psbt: string }) { return this.rpc("analyzepsbt", options); } /** * @description Combine multiple partially signed Bitcoin transactions into one transaction. */ - async combinepsbt(options: { txs: string[] }) { + combinepsbt(options: { txs: string[] }) { return this.rpc("combinepsbt", options); } /** * @description Combine multiple partially signed transactions into one transaction. */ - async combinerawtransaction(options: { txs: string[] }) { + combinerawtransaction(options: { txs: string[] }) { return this.rpc("combinerawtransaction", options); } /** * @description Converts a network serialized transaction to a PSBT. */ - async converttopsbt(options: ConvertToPsbtParams) { + converttopsbt(options: ConvertToPsbtParams) { return this.rpc("converttopsbt", options); } /** * @description Creates a transaction in the Partially Signed Transaction format. */ - async createpsbt(options: CreateTransactionParams) { + createpsbt(options: CreateTransactionParams) { return this.rpc("createpsbt", options); } /** * @description Create a transaction spending the given inputs and creating new outputs. */ - async createrawtransaction(options: CreateTransactionParams) { + createrawtransaction(options: CreateTransactionParams) { return this.rpc("createrawtransaction", options); } /** * @description Return a JSON object representing the serialized, base64-encoded partially signed Bitcoin transaction. */ - async decodepsbt(options: { psbt: string }) { + decodepsbt(options: { psbt: string }) { return this.rpc("decodepsbt", options); } /** * @description Return a JSON object representing the serialized, hex-encoded transaction. */ - async decoderawtransaction(options: DecodeRawTransactionParams) { + decoderawtransaction(options: DecodeRawTransactionParams) { return this.rpc("decoderawtransaction", options); } /** * @description Decode a hex-encoded script. */ - async decodescript(options: HexString) { + decodescript(options: HexString) { return this.rpc("decodescript", options); } /** * @description Finalize the inputs of a PSBT. */ - async finalizepsbt(options: FinalizePsbtParams) { + finalizepsbt(options: FinalizePsbtParams) { return this.rpc("finalizepsbt", options); } /** * @description Add inputs to a transaction until it has enough in value to meet its out value. */ - async fundrawtransaction(options: FundRawTransactionParams, wallet?: string) { + fundrawtransaction(options: FundRawTransactionParams, wallet?: string) { return this.rpc("fundrawtransaction", options, wallet || this.wallet); } /** * @description Return the raw transaction data. */ - async getrawtransaction(options: GetRawTransactionParams) { + getrawtransaction(options: GetRawTransactionParams) { return this.rpc("getrawtransaction", options); } /** * @description Joins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs. */ - async joinpsbts(options: { txs: string[] }) { + joinpsbts(options: { txs: string[] }) { return this.rpc("joinpsbts", options); } /** * @description Submits raw transaction (serialized, hex-encoded) to local node and network. */ - async sendrawtransaction(options: SendRawTransactionParams) { + sendrawtransaction(options: SendRawTransactionParams) { return this.rpc("sendrawtransaction", options); } /** * @description Sign inputs for raw transaction */ - async signrawtransactionwithkey(options: SignRawTransactionWithKeyParams) { + signrawtransactionwithkey(options: SignRawTransactionWithKeyParams) { return this.rpc("signrawtransactionwithkey", options); } /** * @description Returns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded) would be accepted by mempool. */ - async testmempoolaccept(options: TestmemPoolAcceptParams) { + testmempoolaccept(options: TestmemPoolAcceptParams) { return this.rpc("testmempoolaccept", options); } /** * @description Updates a PSBT with witness UTXOs retrieved from the UTXO set or the mempool. */ - async utxoupdatepsbt(options: { psbt: string }) { + utxoupdatepsbt(options: { psbt: string }) { return this.rpc("utxoupdatepsbt", options); } /** * @description Creates a multi-signature address with n signature of m keys required. */ - async createmultisig(options: CreateMultiSigParams) { + createmultisig(options: CreateMultiSigParams) { return this.rpc("createmultisig", options); } /** * @description Derives one or more addresses corresponding to an output descriptor. */ - async deriveaddresses({ descriptor, range }: DeriveAddressesParams) { + deriveaddresses({ descriptor, range }: DeriveAddressesParams) { return this.rpc("deriveaddresses", { descriptor, range }); } /** * @description Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within `conf_target` blocks if possible and return the number of blocks for which the estimate is valid. */ - async estimatesmartfee(options: EstimateSmartFeeParams) { + estimatesmartfee(options: EstimateSmartFeeParams) { return this.rpc("estimatesmartfee", options); } /** * @description Analyses a descriptor. */ - async getdescriptorinfo(options: { descriptor: string }) { + getdescriptorinfo(options: { descriptor: string }) { return this.rpc("getdescriptorinfo", options); } /** * @description Sign a message with the private key of an address. */ - async signmessagewithprivkey(options: SignMessageWithPrivKeyParams) { + signmessagewithprivkey(options: SignMessageWithPrivKeyParams) { return this.rpc("signmessagewithprivkey", options); } /** * @description Return information about the given bitcoin address. */ - async validateaddress(options: { address: string }) { + validateaddress(options: { address: string }) { return this.rpc("validateaddress", options); } /** * @description Verify a signed message */ - async verifymessage(options: VerifyMessageParams) { + verifymessage(options: VerifyMessageParams) { return this.rpc("verifymessage", options); } /** * @description Mark in-wallet transaction `txid` as abandoned */ - async abandontransaction(options: TxId, wallet?: string) { + abandontransaction(options: TxId, wallet?: string) { return this.rpc("abandontransaction", options, wallet || this.wallet); } /** * @description Stops current wallet rescan triggered by an RPC call */ - async abortrescan(wallet?: string) { + abortrescan(wallet?: string) { return this.rpc("abortrescan", undefined, wallet || this.wallet); } /** * @description Add a nrequired-to-sign multisignature address to the wallet. */ - async addmultisigaddress(options: AddMultiSigAddressParams, wallet?: string) { + addmultisigaddress(options: AddMultiSigAddressParams, wallet?: string) { return this.rpc("addmultisigaddress", options, wallet || this.wallet); } /** * @description Safely copies current wallet file to destination. */ - async backupwallet(options: { destination: string }, wallet?: string) { + backupwallet(options: { destination: string }, wallet?: string) { return this.rpc("backupwallet", options, wallet || this.wallet); } /** * @description Bumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B. */ - async bumpfee(options: BumpFeeParams, wallet?: string) { + bumpfee(options: BumpFeeParams, wallet?: string) { return this.rpc("bumpfee", options, wallet || this.wallet); } /** * @description Creates and loads a new wallet. */ - async createwallet(options: CreateWalletParams) { + createwallet(options: CreateWalletParams) { return this.rpc("createwallet", options); } /** * @description Reveals the private key corresponding to 'address'. */ - async dumpprivkey(options: { address: string }, wallet?: string) { + dumpprivkey(options: { address: string }, wallet?: string) { return this.rpc("dumpprivkey", options, wallet || this.wallet); } /** * @description Dumps all wallet keys in a human-readable format to a server-side file. */ - async dumpwallet(options: { filename: string }, wallet?: string) { + dumpwallet(options: { filename: string }, wallet?: string) { return this.rpc("dumpwallet", options, wallet || this.wallet); } /** * @description Encrypts the wallet with 'passphrase'. */ - async encryptwallet(options: { passphrase: string }, wallet?: string) { + encryptwallet(options: { passphrase: string }, wallet?: string) { return this.rpc("encryptwallet", options, wallet || this.wallet); } /** * @description Returns the list of addresses assigned the specified label. */ - async getaddressesbylabel(options: { label: string }, wallet?: string) { + getaddressesbylabel(options: { label: string }, wallet?: string) { return this.rpc("getaddressesbylabel", options, wallet || this.wallet); } /** * @description Return information about the given bitcoin address. */ - async getaddressinfo(options: { address: string }, wallet?: string) { + getaddressinfo(options: { address: string }, wallet?: string) { return this.rpc("getaddressinfo", options, wallet || this.wallet); } /** * @description Returns the total available balance. */ - async getbalance(options: GetBalanceParams, wallet?: string) { + getbalance(options: GetBalanceParams, wallet?: string) { return this.rpc("getbalance", options, wallet || this.wallet); } /** * @description Returns a new Bitcoin address for receiving payments. */ - async getnewaddress(options: GetNewAddressParams, wallet?: string) { + getnewaddress(options: GetNewAddressParams, wallet?: string) { return this.rpc("getnewaddress", options, wallet || this.wallet); } /** * @description Returns a new Bitcoin address, for receiving change. */ - async getrawchangeaddress( + getrawchangeaddress( options: { address_type?: AddressType }, wallet?: string ) { @@ -1027,240 +1027,231 @@ export class RPCClient extends RESTClient { /** * @description Returns the total amount received by the given address in transactions with at least minconf confirmations. */ - async getreceivedbyaddress( - options: GetReceivedByAddressParams, - wallet?: string - ) { + getreceivedbyaddress(options: GetReceivedByAddressParams, wallet?: string) { return this.rpc("getreceivedbyaddress", options, wallet || this.wallet); } /** * @description Returns the total amount received by addresses with `label` in transactions with at least `minconf` confirmations. */ - async getreceivedbylabel(options: GetReceivedByLabelParams, wallet?: string) { + getreceivedbylabel(options: GetReceivedByLabelParams, wallet?: string) { return this.rpc("getreceivedbylabel", options, wallet || this.wallet); } /** * @description Get detailed information about in-wallet transaction `txid` */ - async gettransaction(options: GetTransactionParams, wallet?: string) { + gettransaction(options: GetTransactionParams, wallet?: string) { return this.rpc("gettransaction", options, wallet || this.wallet); } /** * @description Returns the server's total unconfirmed balance */ - async getunconfirmedbalance(wallet?: string) { + getunconfirmedbalance(wallet?: string) { return this.rpc("getunconfirmedbalance", undefined, wallet || this.wallet); } /** * @description Returns an object containing various wallet state info. */ - async getwalletinfo(wallet?: string) { + getwalletinfo(wallet?: string) { return this.rpc("getwalletinfo", undefined, wallet || this.wallet); } /** * @description Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. */ - async importaddress(options: ImportAddressParams, wallet?: string) { + importaddress(options: ImportAddressParams, wallet?: string) { return this.rpc("importaddress", options, wallet || this.wallet); } /** * @description Import addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. */ - async importmulti(options: ImportMultiParams, wallet?: string) { + importmulti(options: ImportMultiParams, wallet?: string) { return this.rpc("importmulti", options, wallet || this.wallet); } /** * @description Adds a private key (as returned by `dumpprivkey`) to your wallet. */ - async importprivkey(options: ImportPrivKeyParams, wallet?: string) { + importprivkey(options: ImportPrivKeyParams, wallet?: string) { return this.rpc("importprivkey", options, wallet || this.wallet); } /** * @description Imports funds without rescan. Corresponding address or script must previously be included in wallet. */ - async importprunedfunds(options: ImportPrunedFundsParams, wallet?: string) { + importprunedfunds(options: ImportPrunedFundsParams, wallet?: string) { return this.rpc("importprunedfunds", options, wallet || this.wallet); } /** * @description Adds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. */ - async importpubkey(options: ImportPubKeyParams, wallet?: string) { + importpubkey(options: ImportPubKeyParams, wallet?: string) { return this.rpc("importpubkey", options, wallet || this.wallet); } /** * @description Imports keys from a wallet dump file (see `dumpwallet`). */ - async importwallet(options: { filename: string }, wallet?: string) { + importwallet(options: { filename: string }, wallet?: string) { return this.rpc("importwallet", options, wallet || this.wallet); } /** * @description Fills the keypool. */ - async keypoolrefill(options: { newsize?: number }, wallet?: string) { + keypoolrefill(options: { newsize?: number }, wallet?: string) { return this.rpc("keypoolrefill", options, wallet || this.wallet); } /** * @description Lists groups of addresses which have had their common ownership made public by common use as inputs or as the resulting change in past transactions */ - async listaddressgroupings(wallet?: string) { + listaddressgroupings(wallet?: string) { return this.rpc("listaddressgroupings", undefined, wallet || this.wallet); } /** * @description Returns the list of all labels, or labels that are assigned to addresses with a specific purpose. */ - async listlabels(options: ListLabelsParams, wallet?: string) { + listlabels(options: ListLabelsParams, wallet?: string) { return this.rpc("listlabels", options, wallet || this.wallet); } /** * @description Returns list of temporarily unspendable outputs. */ - async listlockunspent(wallet?: string) { + listlockunspent(wallet?: string) { return this.rpc("listlockunspent", undefined, wallet || this.wallet); } /** * @description List balances by receiving address. */ - async listreceivedbyaddress( - options: ListReceivedByAddressParams, - wallet?: string - ) { + listreceivedbyaddress(options: ListReceivedByAddressParams, wallet?: string) { return this.rpc("listreceivedbyaddress", options, wallet || this.wallet); } /** * @description List received transactions by label. */ - async listreceivedbylabel( - options: ListReceivedByLabelParams, - wallet?: string - ) { + listreceivedbylabel(options: ListReceivedByLabelParams, wallet?: string) { return this.rpc("listreceivedbylabel", options, wallet || this.wallet); } /** * @description Get all transactions in blocks since block `blockhash`, or all transactions if omitted. */ - async listsinceblock(options: ListSinceBlockParams, wallet?: string) { + listsinceblock(options: ListSinceBlockParams, wallet?: string) { return this.rpc("listsinceblock", options, wallet || this.wallet); } /** * @description Returns up to `count` most recent transactions skipping the first `skip` transactions. */ - async listtransactions(options: ListTransactionsParams, wallet?: string) { + listtransactions(options: ListTransactionsParams, wallet?: string) { return this.rpc("listtransactions", options, wallet || this.wallet); } /** * @description Returns array of unspent transaction outputs with between `minconf` and `maxconf` (inclusive) confirmations. */ - async listunspent(options: ListUnspentParams, wallet?: string) { + listunspent(options: ListUnspentParams, wallet?: string) { return this.rpc("listunspent", options, wallet || this.wallet); } /** * @description Returns a list of wallets in the wallet directory. */ - async listwalletdir() { + listwalletdir() { return this.rpc("listwalletdir"); } /** * @description Returns a list of currently loaded wallets. */ - async listwallets() { + listwallets() { return this.rpc("listwallets"); } /** * @description Loads a wallet from a wallet file or directory. */ - async loadwallet({ filename }: { filename: string }) { + loadwallet({ filename }: { filename: string }) { return this.rpc("loadwallet", { filename }); } /** * @description Updates list of temporarily unspendable outputs. */ - async lockunspent(options: LockUnspentParams, wallet?: string) { + lockunspent(options: LockUnspentParams, wallet?: string) { return this.rpc("lockunspent", options, wallet || this.wallet); } /** * @description Deletes the specified transaction from the wallet. */ - async removeprunedfunds(options: TxId, wallet?: string) { + removeprunedfunds(options: TxId, wallet?: string) { return this.rpc("removeprunedfunds", options, wallet || this.wallet); } /** * @description Rescan the local blockchain for wallet related transactions. */ - async rescanblockchain(options: RescanBlockchainParams, wallet?: string) { + rescanblockchain(options: RescanBlockchainParams, wallet?: string) { return this.rpc("rescanblockchain", options, wallet || this.wallet); } /** * @description Send multiple times. */ - async sendmany(options: SendManyParams, wallet?: string) { + sendmany(options: SendManyParams, wallet?: string) { return this.rpc("sendmany", options, wallet || this.wallet); } /** * @description Send an amount to a given address. */ - async sendtoaddress(options: SendToAddressParams, wallet?: string) { + sendtoaddress(options: SendToAddressParams, wallet?: string) { return this.rpc("sendtoaddress", options, wallet || this.wallet); } /** * @description Set or generate a new HD wallet seed. */ - async sethdseed(options: SetHDSeedParams, wallet?: string) { + sethdseed(options: SetHDSeedParams, wallet?: string) { return this.rpc("sethdseed", options, wallet || this.wallet); } /** * @description Sets the label associated with the given address. */ - async setlabel(options: SetLabelParams, wallet?: string) { + setlabel(options: SetLabelParams, wallet?: string) { return this.rpc("setlabel", options, wallet || this.wallet); } /** * @description Set the transaction fee per kB for this wallet. */ - async settxfee(options: { amount: number | string }, wallet?: string) { + settxfee(options: { amount: number | string }, wallet?: string) { return this.rpc("settxfee", options, wallet || this.wallet); } /** * @description Sign a message with the private key of an address */ - async signmessage(options: SignMessageParams, wallet?: string) { + signmessage(options: SignMessageParams, wallet?: string) { return this.rpc("signmessage", options, wallet || this.wallet); } /** * @description Sign inputs for raw transaction */ - async signrawtransactionwithwallet( + signrawtransactionwithwallet( options: SignRawTransactionWithWalletParams, wallet?: string ) { @@ -1274,7 +1265,7 @@ export class RPCClient extends RESTClient { /** * @description Unloads the wallet. */ - async unloadwallet({ wallet_name }: { wallet_name?: string } = {}) { + unloadwallet({ wallet_name }: { wallet_name?: string } = {}) { if (typeof wallet_name !== "undefined") { return this.rpc("unloadwallet", { wallet_name }); } @@ -1284,7 +1275,7 @@ export class RPCClient extends RESTClient { /** * @description Creates and funds a transaction in the Partially Signed Transaction format. */ - async walletcreatefundedpsbt( + walletcreatefundedpsbt( options: WalletCreateFundedPsbtParams, wallet?: string ) { @@ -1294,21 +1285,21 @@ export class RPCClient extends RESTClient { /** * @description Removes the wallet encryption key from memory, locking the wallet. */ - async walletlock(wallet?: string) { + walletlock(wallet?: string) { return this.rpc("walletlock", undefined, wallet || this.wallet); } /** * @description Stores the wallet decryption key in memory for `timeout` seconds. */ - async walletpassphrase(options: WalletPassphraseParams, wallet?: string) { + walletpassphrase(options: WalletPassphraseParams, wallet?: string) { return this.rpc("walletpassphrase", options, wallet || this.wallet); } /** * @description Changes the wallet passphrase from `oldpassphrase` to `newpassphrase`. */ - async walletpassphrasechange( + walletpassphrasechange( options: WalletPassphraseChangeParams, wallet?: string ) { @@ -1318,14 +1309,14 @@ export class RPCClient extends RESTClient { /** * @description Update a PSBT with input information from our wallet and then sign inputs that we can sign for. */ - async walletprocesspsbt(options: WalletProcessPsbtParams, wallet?: string) { + walletprocesspsbt(options: WalletProcessPsbtParams, wallet?: string) { return this.rpc("walletprocesspsbt", options, wallet || this.wallet); } /** * @description Returns information about the active ZeroMQ notifications. */ - async getzmqnotifications() { + getzmqnotifications() { return this.rpc("getzmqnotifications"); } } From debcb0aa516b163d0388c94a0e9ca635b3a0aabf Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 16:58:43 +0300 Subject: [PATCH 09/23] feat: add getbalances method --- README.md | 7 +++++++ src/rpc.ts | 7 +++++++ test/rpc.spec.ts | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 4ad8324..0a59cd1 100644 --- a/README.md +++ b/README.md @@ -829,6 +829,13 @@ const include_watchonly = true; const result = await client.getbalance({ minconf, include_watchonly }, wallet); ``` +- [`getbalances`](https://bitcoin.org/en/developer-reference#getbalances) + +```javascript +const wallet = "bitcoin-core-wallet.dat"; +const result = await client.getbalances(wallet); +``` + - [`getnewaddress`](https://bitcoin.org/en/developer-reference#getnewaddress) ```javascript diff --git a/src/rpc.ts b/src/rpc.ts index abd5dd5..f6f72f8 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -1007,6 +1007,13 @@ export class RPCClient extends RESTClient { return this.rpc("getbalance", options, wallet || this.wallet); } + /** + * @description Returns all balances in BTC. + */ + getbalances(wallet?: string) { + return this.rpc("getbalances", undefined, wallet || this.wallet); + } + /** * @description Returns a new Bitcoin address for receiving payments. */ diff --git a/test/rpc.spec.ts b/test/rpc.spec.ts index 8d48362..ea5deb1 100644 --- a/test/rpc.spec.ts +++ b/test/rpc.spec.ts @@ -2475,6 +2475,20 @@ suite("RPCClient", () => { assert.deepStrictEqual(data, result); }); + test(".getbalances()", async () => { + const request = { params: {}, method: "getbalances", id, jsonrpc }; + const result = { + mine: { trusted: 0, untrusted_pending: 0, immature: 0 }, + }; + nock(uri) + .post("/wallet/" + wallet, request) + .times(1) + .basicAuth(auth) + .reply(200, { result, error, id }); + const data = await client.getbalances(wallet); + assert.deepStrictEqual(data, result); + }); + test(".getnewaddress()", async () => { const label = "SomeLabel"; const address_type: "bech32" = "bech32"; From bf9509af319959c82cd8f1d6685aa45fb98cbd99 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:08:18 +0300 Subject: [PATCH 10/23] feat: add setwalletflag method --- README.md | 9 +++++++++ src/rpc.ts | 9 +++++++++ test/rpc.spec.ts | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 0a59cd1..a4cb6e3 100644 --- a/README.md +++ b/README.md @@ -1226,6 +1226,15 @@ const amount = 0.00002; const result = await client.settxfee({ amount }, wallet); ``` +- [`setwalletflag`](https://bitcoin.org/en/developer-reference#setwalletflag) + +```javascript +const wallet = "bitcoin-core-wallet.dat"; +const flag = "avoid_reuse"; +const value = false; +const result = await client.setwalletflag({ flag, value }, wallet); +``` + - [`signmessage`](https://bitcoin.org/en/developer-reference#signmessage) ```javascript diff --git a/src/rpc.ts b/src/rpc.ts index f6f72f8..f795d60 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -349,6 +349,8 @@ export type SetHDSeedParams = { newkeypool?: boolean; seed?: string }; export type SetLabelParams = { address: string; label: string }; +export type SetWalletFlagParams = { flag: string; value?: boolean }; + export type SignMessageParams = { address: string; message: string }; export type WalletCreateFundedPsbtParams = BaseCreateTransaction & @@ -1248,6 +1250,13 @@ export class RPCClient extends RESTClient { return this.rpc("settxfee", options, wallet || this.wallet); } + /** + * @description Change the state of the given wallet flag for a wallet. + */ + setwalletflag(options: SetWalletFlagParams, wallet?: string) { + return this.rpc("setwalletflag", options, wallet || this.wallet); + } + /** * @description Sign a message with the private key of an address */ diff --git a/test/rpc.spec.ts b/test/rpc.spec.ts index ea5deb1..b99a2fb 100644 --- a/test/rpc.spec.ts +++ b/test/rpc.spec.ts @@ -3329,6 +3329,21 @@ suite("RPCClient", () => { assert.deepStrictEqual(data, result); }); + test(".setwalletflag()", async () => { + const flag = "avoid_reuse"; + const value = false; + const params = { flag, value }; + const request = { params, method: "setwalletflag", id, jsonrpc }; + const result = { flag_name: "avoid_reuse", flag_state: false }; + nock(uri) + .post("/wallet/" + wallet, request) + .times(1) + .basicAuth(auth) + .reply(200, { result, error, id }); + const data = await client.setwalletflag(params, wallet); + assert.deepStrictEqual(data, result); + }); + test(".signmessage()", async () => { const address = "muQN4LGGwtD9bqPeCexKGpksvygnRAnTA3"; const message = "Hello World!"; From c71ff7c5b4047a6492f33a12aa40a736026aa2bc Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:19:51 +0300 Subject: [PATCH 11/23] feat: add getblockfilter method --- README.md | 9 +++++++++ src/rpc.ts | 9 +++++++++ test/rpc.spec.ts | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/README.md b/README.md index a4cb6e3..82ef8e6 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,15 @@ const info = await client.getblockchaininfo(); const count = await client.getblockcount(); ``` +- [`getblockfilter`](https://bitcoin.org/en/developer-reference#getblockfilter) + +```javascript +const blockhash = + "00000000000000dfffa1954693ba3f79813909dbcdedfe05eccb9829e828c141"; +const filtertype = "basic"; +const result = await client.getblockfilter({ blockhash, filtertype }); +``` + - [`getblockhash`](https://bitcoin.org/en/developer-reference#getblockhash) ```javascript diff --git a/src/rpc.ts b/src/rpc.ts index f795d60..cf2758f 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -26,6 +26,8 @@ export type TxId = { txid: string }; export type GetBlockParams = Verbosity & Blockhash; +export type GetBlockFilterParams = Blockhash & { filtertype?: string }; + export type GetBlockHeaderParams = Blockhash & Verbose; export type GetBlockStatsParams = { @@ -432,6 +434,13 @@ export class RPCClient extends RESTClient { return this.rpc("getblockcount"); } + /** + * @description Retrieve a BIP 157 content filter for a particular block. + */ + getblockfilter(options: GetBlockFilterParams) { + return this.rpc("getblockfilter", options); + } + /** * @description Returns hash of block in best-block-chain at height provided. */ diff --git a/test/rpc.spec.ts b/test/rpc.spec.ts index b99a2fb..44f81e5 100644 --- a/test/rpc.spec.ts +++ b/test/rpc.spec.ts @@ -375,6 +375,29 @@ suite("RPCClient", () => { assert.deepStrictEqual(data, result); }); + test(".getblockfilter()", async () => { + const blockhash = + "00000000000000dfffa1954693ba3f79813909dbcdedfe05eccb9829e828c141"; + const filtertype = "basic"; + const request = { + params: { blockhash, filtertype }, + method: "getblockfilter", + id, + jsonrpc, + }; + const result = { + filter: "", + header: "", + }; + nock(uri) + .post("/", request) + .times(1) + .basicAuth(auth) + .reply(200, { result, error, id }); + const data = await client.getblockfilter({ blockhash, filtertype }); + assert.deepStrictEqual(data, result); + }); + test(".getblockhash()", async () => { const height = 1583782; const params = { height }; From 0c35cfe23862622fc220003a16cf17c40d38d59a Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:23:31 +0300 Subject: [PATCH 12/23] fix: remove minconf field from sendmany params Ref: https://github.com/bitcoin/bitcoin/pull/15596 --- src/rpc.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rpc.ts b/src/rpc.ts index cf2758f..0fac749 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -336,7 +336,6 @@ export type BaseSendParams = EstimateMode & { export type SendManyParams = BaseSendParams & { amounts: { [address: string]: number | string }; - minconf?: number; subtractfeefrom?: string[]; }; From 86c643717b3fbae45af64b01fadfb18d3009d7f9 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:26:23 +0300 Subject: [PATCH 13/23] feat: add avoid_reuse option Ref: https://github.com/bitcoin/bitcoin/pull/13756 --- src/rpc.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpc.ts b/src/rpc.ts index 0fac749..73df025 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -212,12 +212,14 @@ export type BumpFeeParams = { }; export type CreateWalletParams = { + avoid_reuse?: boolean; wallet_name: string; disable_private_keys?: boolean; blank?: boolean; }; export type GetBalanceParams = { + avoid_reuse?: boolean; minconf?: number; include_watchonly?: boolean; }; @@ -340,6 +342,7 @@ export type SendManyParams = BaseSendParams & { }; export type SendToAddressParams = BaseSendParams & { + avoid_reuse?: boolean; address: string; amount: string | number; comment_to?: string; From 0bf3e38d349825f960e36116783ec8ba94576d97 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:32:13 +0300 Subject: [PATCH 14/23] feat: update utxoupdatepsbt arguments Ref: https://github.com/bitcoin/bitcoin/pull/15427 --- src/rpc.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpc.ts b/src/rpc.ts index 73df025..5c3bf4e 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -199,6 +199,14 @@ export type TestmemPoolAcceptParams = { allowhighfees?: boolean; }; +export type UtxoUpdatePsbtParams = { + psbt: string; + descriptors?: ( + | string + | { desc: string; range?: number | [number, number] } + )[]; +}; + export type Label = { label?: string }; export type AddMultiSigAddressParams = CreateMultiSigParams & Label; @@ -883,7 +891,7 @@ export class RPCClient extends RESTClient { /** * @description Updates a PSBT with witness UTXOs retrieved from the UTXO set or the mempool. */ - utxoupdatepsbt(options: { psbt: string }) { + utxoupdatepsbt(options: UtxoUpdatePsbtParams) { return this.rpc("utxoupdatepsbt", options); } From 761f0d9633d11ae8162deb888a1873c7b1f1cce0 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:42:33 +0300 Subject: [PATCH 15/23] fix: remove allowhighfees option Ref: https://github.com/bitcoin/bitcoin/pull/15620 --- src/rpc.ts | 6 ++++-- test/rpc.spec.ts | 10 ++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rpc.ts b/src/rpc.ts index 5c3bf4e..d3d9640 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -166,7 +166,9 @@ export type FundRawTransactionParams = HexString & { export type GetRawTransactionParams = TxId & Verbose & { blockhash?: string }; -export type SendRawTransactionParams = HexString & { allowhighfees?: boolean }; +export type SendRawTransactionParams = HexString & { + maxfeerate?: number | string; +}; export type PrevTx = { txid: string; @@ -196,7 +198,7 @@ export type SignRawTransactionWithKeyParams = { export type TestmemPoolAcceptParams = { rawtxs: string[]; - allowhighfees?: boolean; + maxfeerate?: string | number; }; export type UtxoUpdatePsbtParams = { diff --git a/test/rpc.spec.ts b/test/rpc.spec.ts index 44f81e5..7c22857 100644 --- a/test/rpc.spec.ts +++ b/test/rpc.spec.ts @@ -2060,8 +2060,8 @@ suite("RPCClient", () => { test(".sendrawtransaction()", async () => { const hexstring = "020000000001027f9115bb880cf88190de6e6b4be7515670c2f6e79c367c09ae19eb2def432aa70000000000fdffffff29455878157141ce08642bec7365a88558596a70f9e23cb5d46c719f8611b6960100000000fdffffff0160823b00000000001600148035bc99c1327407ba8faa9592a251042986c81502473044022007a70711f0889028f4cb7fd01d20b1f96bb8a7def745b4394696fe032a4f5de102206b72cbe094466fc4358a2a130b02b539da774c6fa7006a7802feeea6a30c231801210283450124a3ca764e4d321fe9b3a700d5d446ee7343d786a5401c075c79ebdfea0247304402205b214bf05756874901f026ca2f61ac54f414d9681bf44e18bcec09f4a2ec78c80220705d68fff3b9883b63870be41fa08ec3940783c5b2cebe767002a67ffe53d5230121034e2dca4f2656f6f296b716317e5a3907b9753c74aa9f419495ff00b179067ef401000000"; - const allowhighfees = true; - const params = { hexstring, allowhighfees }; + const maxfeerate = 0.1; + const params = { hexstring, maxfeerate }; const request = { params, method: "sendrawtransaction", id, jsonrpc }; const result = "d1514757030c26d54e90b242c696f46f539bb55e92fb105505d9ee43e61657a9"; @@ -2107,8 +2107,8 @@ suite("RPCClient", () => { const rawtxs = [ "020000000001027f9115bb880cf88190de6e6b4be7515670c2f6e79c367c09ae19eb2def432aa70000000000fdffffff29455878157141ce08642bec7365a88558596a70f9e23cb5d46c719f8611b6960100000000fdffffff0160823b00000000001600148035bc99c1327407ba8faa9592a251042986c81502473044022007a70711f0889028f4cb7fd01d20b1f96bb8a7def745b4394696fe032a4f5de102206b72cbe094466fc4358a2a130b02b539da774c6fa7006a7802feeea6a30c231801210283450124a3ca764e4d321fe9b3a700d5d446ee7343d786a5401c075c79ebdfea0247304402205b214bf05756874901f026ca2f61ac54f414d9681bf44e18bcec09f4a2ec78c80220705d68fff3b9883b63870be41fa08ec3940783c5b2cebe767002a67ffe53d5230121034e2dca4f2656f6f296b716317e5a3907b9753c74aa9f419495ff00b179067ef401000000", ]; - const allowhighfees = true; - const params = { rawtxs, allowhighfees }; + const maxfeerate = 0.1; + const params = { rawtxs, maxfeerate }; const request = { params, method: "testmempoolaccept", id, jsonrpc }; const result = [ { @@ -3250,7 +3250,6 @@ suite("RPCClient", () => { tb1qh4v0nuuglwfvzjhhjwn2mm8xa5n9mmg6azq237: 0.00002, tb1qm0m54hj4hmgw4ncufh7g6gx8lp7294rgjr8vz3: "0.00003", }; - const minconf = 6; const comment = "SomeComment"; const subtractfeefrom = ["tb1qh4v0nuuglwfvzjhhjwn2mm8xa5n9mmg6azq237"]; const replaceable = true; @@ -3258,7 +3257,6 @@ suite("RPCClient", () => { const estimate_mode: "ECONOMICAL" = "ECONOMICAL"; const params = { amounts, - minconf, comment, subtractfeefrom, replaceable, From 21ab7073011e6384a9e99de6fac9ecae3399b4c6 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:44:36 +0300 Subject: [PATCH 16/23] feat: add verbose argument to the gettransaction method Ref: https://github.com/bitcoin/bitcoin/pull/16185 Ref: https://github.com/bitcoin/bitcoin/pull/16866 Ref: https://github.com/bitcoin/bitcoin/pull/16873 --- src/rpc.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc.ts b/src/rpc.ts index d3d9640..d5827e7 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -243,7 +243,10 @@ export type GetReceivedByLabelParams = { minconf?: number; }; -export type GetTransactionParams = TxId & { include_watchonly?: boolean }; +export type GetTransactionParams = TxId & { + include_watchonly?: boolean; + verbose?: boolean; +}; export type ImportAddressParams = { address: string; From 3950de0205ed73ff87e2eb8f234e7230e9deca9a Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:45:53 +0300 Subject: [PATCH 17/23] feat: add passphrase option to createwallet params Ref: https://github.com/bitcoin/bitcoin/pull/16394 --- src/rpc.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc.ts b/src/rpc.ts index d5827e7..d073574 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -222,6 +222,7 @@ export type BumpFeeParams = { }; export type CreateWalletParams = { + passphrase?: string; avoid_reuse?: boolean; wallet_name: string; disable_private_keys?: boolean; From ead8742b8a87260dc11f28094a2be79c523de78b Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:54:45 +0300 Subject: [PATCH 18/23] chore: update eslint config --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4d320db..1dbf141 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,7 +20,7 @@ { "files": ["./build/**/*.js"], "rules": { - "@typescript-eslint/camelcase": "off" + "@typescript-eslint/explicit-function-return-type": "off" } } ], From 457ea9427aaf68c8563b203db700dea49ac18e4c Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:55:01 +0300 Subject: [PATCH 19/23] metadata: update min node version --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2fac901..b6f7718 100644 --- a/package.json +++ b/package.json @@ -3,22 +3,22 @@ "version": "1.11.1", "description": "A TypeScript library to make RPC and HTTP REST requests to Bitcoin Core", "main": "build/index.js", - "type": "module", + "type": "commonjs", "engines": { - "node": ">=10.16.3" + "node": ">=10.19.0" }, "types": "build/index.d.ts", "scripts": { "build": "rm -fr build && tsc", "fresh-install": "rm -fr node_modules && rm -f package-lock.json && npm install", - "prettier": "prettier -c **/*.{md,ts,json}", - "prettier:build": "prettier -c **/*.{js} --write", + "prettier": "prettier -c \"**/*.{md,ts,json}\"", + "prettier:build": "prettier -c \"./build/**/*.{js,d.ts}\" --write", "prettier-write": "npm run prettier -- --write", "lint": "eslint --ext .ts ./", "lint:build": "eslint --ext .js ./ --fix", "lint-fix": "npm run lint -- --fix", "test": "mocha -r ts-node/register --full-trace --ui tdd --bail --extension ts", - "prepublishOnly": "npm run prettier && npm run lint && npm run build && prettier:build && lint:build", + "prepublishOnly": "npm run prettier && npm run lint && npm run build && npm run prettier:build && npm run lint:build", "postpublish": "rm -fr build" }, "repository": { From 8df2edc00512703f7ebfeb4c6b4219f72661e005 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:55:32 +0300 Subject: [PATCH 20/23] metadata: bump version to 2.0.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fb8b09f..7386d88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rpc-bitcoin", - "version": "1.11.1", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b6f7718..9d7e873 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rpc-bitcoin", - "version": "1.11.1", + "version": "2.0.0", "description": "A TypeScript library to make RPC and HTTP REST requests to Bitcoin Core", "main": "build/index.js", "type": "commonjs", From 8ada9e119203312147dcc21cf1c6f6e72f9900a4 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 17:58:35 +0300 Subject: [PATCH 21/23] ci(travis): fix typo --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4c793d..858a612 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,5 @@ script: - npm run prettier - npm run lint - npm test - - prepublishOnly - - postpublish + - npm run prepublishOnly + - npm run postpublish From d72e6bc566c294485532493b24498980bbb6e078 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 18:00:16 +0300 Subject: [PATCH 22/23] doc(readme): add badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82ef8e6..8835dc4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rpc-bitcoin [![Build Status](https://travis-ci.com/vansergen/rpc-bitcoin.svg?token=cg5dVMovG8Db6p5Qzzps&branch=master)](https://travis-ci.com/vansergen/rpc-bitcoin) +# rpc-bitcoin [![Build Status](https://travis-ci.com/vansergen/rpc-bitcoin.svg?token=cg5dVMovG8Db6p5Qzzps&branch=master)](https://travis-ci.com/vansergen/rpc-bitcoin) [![Known Vulnerabilities](https://snyk.io/test/github/vansergen/rpc-bitcoin/badge.svg)](https://snyk.io/test/github/vansergen/rpc-bitcoin) ![NPM license](https://img.shields.io/npm/l/rpc-bitcoin) ![npm downloads](https://img.shields.io/npm/dt/rpc-bitcoin) ![GitHub top language](https://img.shields.io/github/languages/top/vansergen/rpc-bitcoin) A [TypeScript](https://www.typescriptlang.org) library to make RPC and HTTP REST requests to [Bitcoin Core](https://bitcoin.org/en/bitcoin-core/). From 76803ece8fc69202ffcd81e660201d268f1bdf92 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Thu, 26 Mar 2020 18:04:55 +0300 Subject: [PATCH 23/23] chore: add .travis.yml to .npmignore --- .npmignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.npmignore b/.npmignore index 5353823..be9a76d 100644 --- a/.npmignore +++ b/.npmignore @@ -4,3 +4,4 @@ tsconfig.json index.ts .github/ .eslintrc.json +.travis.yml