Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1001LOCK(wallet->cs_wallet);1003// The RPC requires a hardened derivation step, so always unlock1004// the wallet.1005EnsureWalletIsUnlocked(*wallet);1007CExtPubKey xpub;1008if (!hdkey.isNull()) {1009xpub = DecodeExtPubKey(hdkey.get_str());1010if (!xpub.pubkey.IsValid()) {1011throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to parse HD key. Please provide a valid xpub");1012}1014// Accept an xpub from an active or unused(KEY) descriptor, but1015// not from a (used) inactive one.1016std::set<CExtPubKey> xpub_candidates;1017for (const auto& candidate : wallet->GetHDPubKeys(HDKeyFilter::UnusedKey)) {1018xpub_candidates.insert(candidate.first);1019}1020for (const auto& candidate : wallet->GetHDPubKeys(HDKeyFilter::Active)) {1021xpub_candidates.insert(candidate.first);1022}1023if (!xpub_candidates.contains(xpub)) {1024throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "HD key is not used by an active or unused(KEY) descriptor");1025}1026}1028// If hdkey was not specified, try to look it up. First consider1029// unused(KEY) descriptors. Otherwise look for active descriptors.1030if (hdkey.isNull()) {1031HDPubKeyMap wallet_xpubs{wallet->GetHDPubKeys(HDKeyFilter::UnusedKey)};1033if (wallet_xpubs.size() > 1) {1034throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to determine which HD key to use. Please specify with 'hdkey'");1035} else if (wallet_xpubs.size() == 1) {1036xpub = wallet_xpubs.begin()->first;1037} else {1038HDPubKeyMap active_xpubs = wallet->GetHDPubKeys(HDKeyFilter::Active);1039if (active_xpubs.empty()) {1040throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No active or unused(KEY) descriptor found");1041}1043if (active_xpubs.size() > 1) {1044throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to determine which HD key to use from active descriptors. Please specify with 'hdkey'");1045}1047xpub = active_xpubs.begin()->first;1048}1049}1051std::optional<CExtKey> xprv{wallet->GetExtKey(xpub)};1052if (!xprv) {1053throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Private key for %s is not known", EncodeExtPubKey(xpub)));1054}1056std::optional<std::pair<CExtKey, KeyOriginInfo>> child{DeriveExtKey(*xprv, path)};1057if (!child) {1058throw JSONRPCError(RPC_INVALID_PARAMETER, "Unable to derive HD key at the requested path");1059}1061UniValue res{UniValue::VOBJ};1063const std::string fingerprint{HexStr(child->second.fingerprint)};1065res.pushKV("origin", strprintf("[%s%s]", fingerprint, FormatHDKeypath(child->second.path)));1066res.pushKV("xpub", EncodeExtPubKey(child->first.Neuter()));1067if (priv) {1068res.pushKV("xprv", EncodeExtKey(child->first));1069}1070return res;1071},1072};1073}1075// addresses1076RPCMethod getaddressinfo();1077RPCMethod getnewaddress();1078RPCMethod getrawchangeaddress();1079RPCMethod setlabel();1080RPCMethod listaddressgroupings();1081RPCMethod keypoolrefill();1082RPCMethod getaddressesbylabel();1083RPCMethod listlabels();1084#ifdef ENABLE_EXTERNAL_SIGNER1085RPCMethod walletdisplayaddress();1086#endif // ENABLE_EXTERNAL_SIGNER1088// backup1089RPCMethod importprunedfunds();1090RPCMethod removeprunedfunds();1091RPCMethod importdescriptors();1092RPCMethod listdescriptors();1093RPCMethod backupwallet();1094RPCMethod restorewallet();1096// coins1097RPCMethod getreceivedbyaddress();1098RPCMethod getreceivedbylabel();1099RPCMethod getbalance();1100RPCMethod lockunspent();1101RPCMethod listlockunspent();1102RPCMethod getbalances();1103RPCMethod listunspent();1105// encryption1106RPCMethod walletpassphrase();1107RPCMethod walletpassphrasechange();1108RPCMethod walletlock();1109RPCMethod encryptwallet();1111// spend1112RPCMethod sendtoaddress();1113RPCMethod sendmany();1114RPCMethod fundrawtransaction();1115RPCMethod bumpfee();1116RPCMethod psbtbumpfee();1117RPCMethod send();1118RPCMethod sendall();1119RPCMethod walletprocesspsbt();1120RPCMethod walletcreatefundedpsbt();1121RPCMethod signrawtransactionwithwallet();1123// signmessage1124RPCMethod signmessage();1126// transactions1127RPCMethod listreceivedbyaddress();1128RPCMethod listreceivedbylabel();1129RPCMethod listtransactions();1130RPCMethod listsinceblock();1131RPCMethod gettransaction();1132RPCMethod abandontransaction();1133RPCMethod rescanblockchain();1134RPCMethod abortrescan();1136std::span<const CRPCCommand> GetWalletRPCCommands()1137{1138static const CRPCCommand commands[]{1139{"rawtransactions", &fundrawtransaction},1140{"wallet", &abandontransaction},1141{"wallet", &abortrescan},1142{"wallet", &addhdkey},1143{"wallet", &backupwallet},1144{"wallet", &bumpfee},1145{"wallet", &psbtbumpfee},1146{"wallet", &createwallet},1147{"wallet", &createwalletdescriptor},1148{"wallet", &derivehdkey},1149{"wallet", &restorewallet},1150{"wallet", &encryptwallet},1151{"wallet", &exportwatchonlywallet},1152{"wallet", &getaddressesbylabel},1153{"wallet", &getaddressinfo},1154{"wallet", &getbalance},1155{"wallet", &gethdkeys},1156{"wallet", &getnewaddress},1157{"wallet", &getrawchangeaddress},1158{"wallet", &getreceivedbyaddress},1159{"wallet", &getreceivedbylabel},1160{"wallet", &gettransaction},1161{"wallet", &getbalances},1162{"wallet", &getwalletinfo},1163{"wallet", &importdescriptors},1164{"wallet", &importprunedfunds},1165{"wallet", &keypoolrefill},1166{"wallet", &listaddressgroupings},1167{"wallet", &listdescriptors},1168{"wallet", &listlabels},1169{"wallet", &listlockunspent},1170{"wallet", &listreceivedbyaddress},1171{"wallet", &listreceivedbylabel},1172{"wallet", &listsinceblock},1173{"wallet", &listtransactions},1174{"wallet", &listunspent},1175{"wallet", &listwalletdir},1176{"wallet", &listwallets},1177{"wallet", &loadwallet},1178{"wallet", &lockunspent},1179{"wallet", &migratewallet},1180{"wallet", &removeprunedfunds},1181{"wallet", &rescanblockchain},1182{"wallet", &send},1183{"wallet", &sendmany},1184{"wallet", &sendtoaddress},1185{"wallet", &setlabel},1186{"wallet", &setwalletflag},1187{"wallet", &signmessage},1188{"wallet", &signrawtransactionwithwallet},1189{"wallet", &simulaterawtransaction},1190{"wallet", &sendall},1191{"wallet", &unloadwallet},1192{"wallet", &walletcreatefundedpsbt},1193#ifdef ENABLE_EXTERNAL_SIGNER1194{"wallet", &walletdisplayaddress},1195#endif // ENABLE_EXTERNAL_SIGNER1196{"wallet", &walletlock},1197{"wallet", &walletpassphrase},1198{"wallet", &walletpassphrasechange},1199{"wallet", &walletprocesspsbt},1200};1201return commands;1202}1203} // namespace wallet