MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / GetAccountAddress

Function GetAccountAddress

src/wallet/rpcwallet.cpp:134–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132
133
134CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
135{
136 CWalletDB walletdb(pwalletMain->strWalletFile);
137
138 CAccount account;
139 walletdb.ReadAccount(strAccount, account);
140
141 bool bKeyUsed = false;
142
143 // Check if the current key has been used
144 if (account.vchPubKey.IsValid())
145 {
146 CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
147 for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
148 it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
149 ++it)
150 {
151 const CWalletTx& wtx = (*it).second;
152 BOOST_FOREACH(const CTxOut& txout, wtx.vout)
153 if (txout.scriptPubKey == scriptPubKey)
154 bKeyUsed = true;
155 }
156 }
157
158 // Generate a new key
159 if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
160 {
161 if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
162 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
163
164 pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
165 walletdb.WriteAccount(strAccount, account);
166 }
167
168 return CBitcoinAddress(account.vchPubKey.GetID());
169}
170
171UniValue getaccountaddress(const UniValue& params, bool fHelp)
172{

Callers 2

getaccountaddressFunction · 0.85
setaccountFunction · 0.85

Calls 11

GetScriptForDestinationFunction · 0.85
JSONRPCErrorFunction · 0.85
CBitcoinAddressClass · 0.85
ReadAccountMethod · 0.80
GetIDMethod · 0.80
GetKeyFromPoolMethod · 0.80
SetAddressBookMethod · 0.80
WriteAccountMethod · 0.80
IsValidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected