UNPKG

bitcoincore-node

Version:

A comprehensive Node.js package for interacting with Bitcoin Core via RPC. Create, sign, and broadcast Bitcoin transactions, manage wallets, and access blockchain data through an easy-to-use API interface. Perfect for developers building cryptocurrency ap

436 lines (435 loc) 17.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WalletRPC = void 0; class WalletRPC { constructor(bitcoinCore) { this.bitcoinCore = bitcoinCore; } abandonTransaction(txid) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('abandontransaction', [txid]); }); } abortRescan() { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('abortrescan'); }); } addMultiSigAddress(walletOptions_1, nrequired_1, keys_1) { return __awaiter(this, arguments, void 0, function* (walletOptions, nrequired, keys, label = '', addressType) { return this.bitcoinCore.callMethod('addmultisigaddress', [nrequired, keys, label, addressType], { wallet: walletOptions.wallet }); }); } backupWallet(destination) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('backupwallet', [destination]); }); } bumpFee(txid) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('bumpfee', [txid]); }); } createWallet(walletName_1) { return __awaiter(this, arguments, void 0, function* (walletName, disablePrivateKeys = false, blank = false, passphrase = '', avoidReuse = false, descriptors = true, loadOnStartup = true) { return this.bitcoinCore.callMethod('createwallet', [ walletName, disablePrivateKeys, blank, passphrase, avoidReuse, descriptors, loadOnStartup, ]); }); } dumpPrivKey(address) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('dumpprivkey', [address]); }); } dumpWallet(filename) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('dumpwallet', [filename]); }); } encryptWallet(passphrase) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('encryptwallet', [passphrase]); }); } getAddressesByLabel(walletOptions, label) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('getaddressesbylabel', [label], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet, }); }); } getAddressInfo(address) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('getaddressinfo', [address]); }); } getBalance(walletOptions_1) { return __awaiter(this, arguments, void 0, function* (walletOptions, dummy = '*', minConf = 1, includeWatchOnly, avoidReuse) { return this.bitcoinCore.callMethod('getbalance', [dummy, minConf, includeWatchOnly, avoidReuse], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet }); }); } getBalances(walletOptions) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('getbalances', [], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet, }); }); } getNewAddress(walletOptions_1) { return __awaiter(this, arguments, void 0, function* (walletOptions, label = '', addressType) { return this.bitcoinCore.callMethod('getnewaddress', [label, addressType], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet }); }); } getRawChangeAddress(walletOptions, addressType) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('getrawchangeaddress', [addressType], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet }); }); } getReceivedByAddress(walletOptions_1, address_1) { return __awaiter(this, arguments, void 0, function* (walletOptions, address, minConf = 1) { return this.bitcoinCore.callMethod('getreceivedbyaddress', [address, minConf], { wallet: walletOptions.wallet }); }); } getReceivedByLabel(walletOptions_1, label_1) { return __awaiter(this, arguments, void 0, function* (walletOptions, label, minConf = 1) { return this.bitcoinCore.callMethod('getreceivedbylabel', [label, minConf], { wallet: walletOptions.wallet }); }); } getTransaction(txid_1, includeWatchOnly_1) { return __awaiter(this, arguments, void 0, function* (txid, includeWatchOnly, verbose = false) { return this.bitcoinCore.callMethod('gettransaction', [ txid, includeWatchOnly, verbose, ]); }); } getUnconfirmedBalance(walletOptions) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('getunconfirmedbalance', [], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet, }); }); } getWalletInfo(walletOptions) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('getwalletinfo', [], { wallet: walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.wallet, }); }); } importAddress(address_1) { return __awaiter(this, arguments, void 0, function* (address, label = '', rescan = true, p2sh) { return this.bitcoinCore.callMethod('importaddress', [ address, label, rescan, p2sh, ]); }); } importDescriptors(requests) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('importdescriptors', [requests]); }); } importMulti(requests_1) { return __awaiter(this, arguments, void 0, function* (requests, options = {}) { return this.bitcoinCore.callMethod('importmulti', [requests, options]); }); } importPrivKey(privkey_1) { return __awaiter(this, arguments, void 0, function* (privkey, label = '', rescan = true) { return this.bitcoinCore.callMethod('importprivkey', [ privkey, label, rescan, ]); }); } importPrunedFunds(rawTransaction, txOutProof) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('importprunedfunds', [ rawTransaction, txOutProof, ]); }); } importPubKey(pubkey_1) { return __awaiter(this, arguments, void 0, function* (pubkey, label = '', rescan = true) { return this.bitcoinCore.callMethod('importpubkey', [ pubkey, label, rescan, ]); }); } importWallet(filename) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('importwallet', [filename]); }); } keyPoolRefill() { return __awaiter(this, arguments, void 0, function* (newSize = 100) { return this.bitcoinCore.callMethod('keypoolrefill', [newSize]); }); } listAddressGroupings() { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('listaddressgroupings'); }); } listLabels(purpose) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('listlabels', [purpose]); }); } listLockUnspent() { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('listlockunspent'); }); } listReceivedByAddress() { return __awaiter(this, arguments, void 0, function* (minConf = 1, includeEmpty = false, includeWatchOnly = false, addressFilter) { return this.bitcoinCore.callMethod('listreceivedbyaddress', [ minConf, includeEmpty, includeWatchOnly, addressFilter, ]); }); } listReceivedByLabel() { return __awaiter(this, arguments, void 0, function* (minConf = 1, includeEmpty = false, includeWatchOnly = false) { return this.bitcoinCore.callMethod('listreceivedbylabel', [ minConf, includeEmpty, includeWatchOnly, ]); }); } listSinceBlock() { return __awaiter(this, arguments, void 0, function* (blockHash = '', targetConfirmations = 1, includeWatchOnly = false, includeRemoved = true) { return this.bitcoinCore.callMethod('listsinceblock', [ blockHash, targetConfirmations, includeWatchOnly, includeRemoved, ]); }); } listTransactions() { return __awaiter(this, arguments, void 0, function* (label = '*', count = 10, skip = 0, includeWatchOnly = false) { return this.bitcoinCore.callMethod('listtransactions', [ label, count, skip, includeWatchOnly, ]); }); } listUnspent() { return __awaiter(this, arguments, void 0, function* (minConf = 1, maxConf = 9999999, addresses, includeUnsafe = true, queryOptions = {}) { return this.bitcoinCore.callMethod('listunspent', [ minConf, maxConf, addresses, includeUnsafe, queryOptions, ]); }); } listWalletDir() { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('listwalletdir'); }); } listWallets() { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('listwallets'); }); } loadWallet(filename_1) { return __awaiter(this, arguments, void 0, function* (filename, loadOnStartup = true) { return this.bitcoinCore.callMethod('loadwallet', [ filename, loadOnStartup, ]); }); } lockUnspent(unlock, transactions) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('lockunspent', [ unlock, transactions, ]); }); } psbtBumpFee(txid, options) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('psbtbumpfee', [txid, options]); }); } removePrunedFunds(txid) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('removeprunedfunds', [txid]); }); } rescanBlockchain() { return __awaiter(this, arguments, void 0, function* (startHeight = 0, stopHeight) { return this.bitcoinCore.callMethod('rescanblockchain', [ startHeight, stopHeight, ]); }); } send(outputs_1, confTarget_1) { return __awaiter(this, arguments, void 0, function* (outputs, confTarget, estimateMode = 'unset', feeRate, options = {}) { return this.bitcoinCore.callMethod('send', [ outputs, confTarget, estimateMode, feeRate, options, ]); }); } sendMany() { return __awaiter(this, arguments, void 0, function* (dummy = '', amounts, minConf, comment = '', subtractFeeFrom = [], replaceable, confTarget, estimateMode, feeRate) { return this.bitcoinCore.callMethod('sendmany', [ dummy, amounts, minConf, comment, subtractFeeFrom, replaceable, confTarget, estimateMode, feeRate, ]); }); } sendToAddress(walletOptions_1, address_1, amount_1) { return __awaiter(this, arguments, void 0, function* (walletOptions, address, amount, comment = '', commentTo = '', subtractFeeFromAmount = true, replaceable = false, confTarget, estimateMode, avoidReuse) { return this.bitcoinCore.callMethod('sendtoaddress', [ address, amount, comment, commentTo, subtractFeeFromAmount, replaceable, confTarget, estimateMode, avoidReuse, ], { wallet: walletOptions.wallet, }); }); } setHdSeed() { return __awaiter(this, arguments, void 0, function* (newKeyPool = true, seed) { return this.bitcoinCore.callMethod('sethdseed', [newKeyPool, seed]); }); } setLabel(address, label) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('setlabel', [address, label]); }); } setTxFee(amount) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('settxfee', [amount]); }); } setWalletFlag(flag_1) { return __awaiter(this, arguments, void 0, function* (flag, value = true) { return this.bitcoinCore.callMethod('setwalletflag', [flag, value]); }); } signMessage(address, message) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('signmessage', [address, message]); }); } signRawTransactionWithWallet(hexString_1, prevTxs_1) { return __awaiter(this, arguments, void 0, function* (hexString, prevTxs, sigHashType = 'All') { return this.bitcoinCore.callMethod('signrawtransactionwithwallet', [ hexString, prevTxs, sigHashType, ]); }); } unloadWallet(walletName, loadOnStartup) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('unloadwallet', [ walletName, loadOnStartup, ]); }); } upgradeWallet() { return __awaiter(this, arguments, void 0, function* (version = 169900) { return this.bitcoinCore.callMethod('upgradewallet', [version]); }); } walletCreateFundedPsbt(inputs_1, outputs_1) { return __awaiter(this, arguments, void 0, function* (inputs, outputs, locktime = 0, options = {}, bip32Derivs = true) { return this.bitcoinCore.callMethod('walletcreatefundedpsbt', [ inputs, outputs, locktime, options, bip32Derivs, ]); }); } walletLock() { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('walletlock'); }); } walletPassphrase(passphrase, timeout) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('walletpassphrase', [ passphrase, timeout, ]); }); } walletPassphraseChange(oldPassphrase, newPassphrase) { return __awaiter(this, void 0, void 0, function* () { return this.bitcoinCore.callMethod('walletpassphrasechange', [ oldPassphrase, newPassphrase, ]); }); } walletProcessPsbt(psbt_1) { return __awaiter(this, arguments, void 0, function* (psbt, sign = true, sigHashType = 'All', bip32Derivs = true) { return this.bitcoinCore.callMethod('walletprocesspsbt', [ psbt, sign, sigHashType, bip32Derivs, ]); }); } } exports.WalletRPC = WalletRPC;