CTxDestination CBitcoinAddress::Get() const { if (!IsValid()) return CNoDestination(); uint160 id; memcpy(&id, &vchData[0], 20); if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) return CKeyID(id); else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) return CScriptID(id); else return CNoDestination(); }
CTxDestination CBitcoinAddress::Get() const { if (!IsValid()) return CNoDestination(); uint160 id; memcpy(&id, &vchData[0], 20); if (vchVersion == Params().Base58Prefix(pubkey_address)) return CKeyID(id); else if (vchVersion == Params().Base58Prefix(script_address)) return CScriptID(id); else return CNoDestination(); }
CTxDestination CBitcoinAddress::Get() const { if (!IsValid()) return CNoDestination(); switch (nVersion) { case PUBKEY_ADDRESS: case PUBKEY_ADDRESS_TEST: { uint160 id; memcpy(&id, &vchData[0], 20); return CKeyID(id); } case SCRIPT_ADDRESS: case SCRIPT_ADDRESS_TEST: { uint160 id; memcpy(&id, &vchData[0], 20); return CScriptID(id); } } return CNoDestination(); }
// Coin Control: custom change address changed void SendCoinsDialog::coinControlChangeEdited(const QString& text) { if (model && model->getAddressTableModel()) { // Default to no change address until verified CoinControlDialog::coinControl->destChange = CNoDestination(); ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); if (text.isEmpty()) // Nothing entered { ui->labelCoinControlChangeLabel->setText(""); } else if (!addr.IsValid()) // Invalid address { ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Bitcoin address")); } else // Valid address { CKeyID keyid; addr.GetKeyID(keyid); if (!model->havePrivKey(keyid)) // Unknown change address { ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); // confirmation dialog QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm custom change address"), tr("The address you selected for change is not part of this wallet. Any or all funds in your wallet may be sent to this address. Are you sure?"), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if(btnRetVal == QMessageBox::Yes) CoinControlDialog::coinControl->destChange = addr.Get(); else { ui->lineEditCoinControlChange->setText(""); ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); ui->labelCoinControlChangeLabel->setText(""); } } else // Known change address { ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); // Query label QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); if (!associatedLabel.isEmpty()) ui->labelCoinControlChangeLabel->setText(associatedLabel); else ui->labelCoinControlChangeLabel->setText(tr("(no label)")); CoinControlDialog::coinControl->destChange = addr.Get(); } } } }
CTxDestination CBitcoinAddress::Get() const { if (!IsValid()) return CNoDestination(); if (vchData.size() == 20) { uint160 id; memcpy(&id, &vchData[0], 20); if (vchVersion == Params().Base58Prefix(CBaseParams::PUBKEY_ADDRESS)) return CKeyID(id); else if (vchVersion == Params().Base58Prefix(CBaseParams::SCRIPT_ADDRESS)) return CScriptID(id); else return CNoDestination(); } else { CAccountID id; memcpy(&id, &vchData[0], 26); return id; } }
CTxDestination CSharkfundAddress::Get() const { if (!IsValid()) return CNoDestination(); if (vchData.size() == 20) { uint160 id; memcpy(&id, &vchData[0], 20); if (vchVersion == SysCfg().Base58Prefix(CBaseParams::PUBKEY_ADDRESS)) return CKeyID(id); // else if (vchVersion == Params().Base58Prefix(CBaseParams::SCRIPT_ADDRESS)) // return CScriptID(id); else return CNoDestination(); } else { // assert(0); return CNoDestination(); } }
// Coin Control: checkbox custom change address void SendCoinsDialog::coinControlChangeChecked(int state) { if (state == Qt::Unchecked) { CoinControlDialog::coinControl->destChange = CNoDestination(); ui->labelCoinControlChangeLabel->clear(); } else // use this to re-validate an already entered address coinControlChangeEdited(ui->lineEditCoinControlChange->text()); ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); }
// Coin Control: custom change address changed void SendCoinsDialog::coinControlChangeEdited(const QString& text) { if (model && model->getAddressTableModel()) { // Default to no change address until verified CoinControlDialog::coinControl->destChange = CNoDestination(); ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); if (text.isEmpty()) // Nothing entered { ui->labelCoinControlChangeLabel->setText(""); } else if (!addr.IsValid()) // Invalid address { ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Bitcoin address")); } else // Valid address { CPubKey pubkey; CKeyID keyid; addr.GetKeyID(keyid); if (!model->getPubKey(keyid, pubkey)) // Unknown change address { ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); } else // Known change address { ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); // Query label QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); if (!associatedLabel.isEmpty()) ui->labelCoinControlChangeLabel->setText(associatedLabel); else ui->labelCoinControlChangeLabel->setText(tr("(no label)")); CoinControlDialog::coinControl->destChange = addr.Get(); } } } }
void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived, std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter, CKeyStore* from) const { if (!from) from = pwallet->activeAccount; nFee = 0; listReceived.clear(); listSent.clear(); // Compute fee: CAmount nDebit = GetDebit(filter); if (nDebit > 0) // debit>0 means we signed/sent this transaction { CAmount nValueOut = tx->GetValueOut(); nFee = nDebit - nValueOut; } // Sent. for (unsigned int i = 0; i < tx->vin.size(); ++i) { const CTxIn& txin = tx->vin[i]; std::map<uint256, CWalletTx>::const_iterator mi = pwallet->mapWallet.find(txin.prevout.getHash()); if (mi != pwallet->mapWallet.end()) { const CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.tx->vout.size()) { const auto& prevOut = prev.tx->vout[txin.prevout.n]; isminetype fIsMine = IsMine(*from, prevOut); if ((fIsMine & filter)) { CTxDestination address; if (!ExtractDestination(prevOut, address) && !prevOut.IsUnspendable()) { LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", this->GetHash().ToString()); address = CNoDestination(); } //fixme: (Post-2.1) - There should be a seperate CInputEntry class/array here or something. COutputEntry output = {address, prevOut.nValue, (int)i}; // We are debited by the transaction, add the output as a "sent" entry listSent.push_back(output); } } } } // received. for (unsigned int i = 0; i < tx->vout.size(); ++i) { const CTxOut& txout = tx->vout[i]; isminetype fIsMine = IsMine(*from, txout); if (!(fIsMine & filter)) continue; // Get the destination address CTxDestination address; if (!ExtractDestination(txout, address) && !txout.IsUnspendable()) { LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", this->GetHash().ToString()); address = CNoDestination(); } COutputEntry output = {address, txout.nValue, (int)i}; // We are receiving the output, add it as a "received" entry listReceived.push_back(output); } }