| 132 | |
| 133 | |
| 134 | CBitcoinAddress 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 | |
| 171 | UniValue getaccountaddress(const UniValue& params, bool fHelp) |
| 172 | { |
no test coverage detected