bool CActiveMasternode::Register(std::string strService, std::string strKeyMasternode, std::string txHash, std::string strOutputIndex, std::string strDonationAddress, std::string strDonationPercentage, std::string& errorMessage) { CTxIn vin; CPubKey pubKeyCollateralAddress; CKey keyCollateralAddress; CPubKey pubKeyMasternode; CKey keyMasternode; CScript donationAddress = CScript(); int donationPercentage = 0; if(!darkSendSigner.SetKey(strKeyMasternode, errorMessage, keyMasternode, pubKeyMasternode)) { LogPrintf("CActiveMasternode::Register() - Error upon calling SetKey: %s\n", errorMessage.c_str()); return false; } if(!GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress, txHash, strOutputIndex)) { errorMessage = "could not allocate vin"; LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str()); return false; } CBitcoinAddress address; if (strDonationAddress != "") { if(!address.SetString(strDonationAddress)) { LogPrintf("CActiveMasternode::Register - Invalid Donation Address\n"); return false; } donationAddress.SetDestination(address.Get()); try { donationPercentage = boost::lexical_cast<int>( strDonationPercentage ); } catch( boost::bad_lexical_cast const& ) { LogPrintf("CActiveMasternode::Register - Invalid Donation Percentage (Couldn't cast)\n"); return false; } if(donationPercentage < 0 || donationPercentage > 100) { LogPrintf("CActiveMasternode::Register - Donation Percentage Out Of Range\n"); return false; } } return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, donationAddress, donationPercentage, errorMessage); }
bool BlockExplorer::switchTo(const QString& query) { bool IsOk; int64_t AsInt = query.toInt(&IsOk); // If query is integer, get hash from height if (IsOk && AsInt >= 0 && AsInt <= chainActive.Tip()->nHeight) { std::string hex = getexplorerBlockHash(AsInt); uint256 hash = uint256S(hex); CBlockIndex* pIndex = mapBlockIndex[hash]; if (pIndex) { setBlock(pIndex); return true; } } // If the query is not an integer, assume it is a block hash uint256 hash = uint256S(query.toUtf8().constData()); // std::map<uint256, CBlockIndex*>::iterator iter = mapBlockIndex.find(hash); BlockMap::iterator iter = mapBlockIndex.find(hash); if (iter != mapBlockIndex.end()) { setBlock(iter->second); return true; } // If the query is neither an integer nor a block hash, assume a transaction hash CTransaction tx; uint256 hashBlock = 0; if (GetTransaction(hash, tx, hashBlock, true)) { setContent(TxToString(hashBlock, tx)); return true; } // If the query is not an integer, nor a block hash, nor a transaction hash, assume an address CBitcoinAddress Address; Address.SetString(query.toUtf8().constData()); if (Address.IsValid()) { std::string Content = AddressToString(Address); if (Content.empty()) return false; setContent(Content); return true; } return false; }
Value dumpprivkey(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "dumpprivkey <dokdocoinaddress>\n" "Reveals the private key corresponding to <dokdocoinaddress>."); string strAddress = params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dokdocoin address"); CKeyID keyID; if (!address.GetKeyID(keyID)) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); CKey vchSecret; if (!pwalletMain->GetKey(keyID, vchSecret)) throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known"); return CBitcoinSecret(vchSecret).ToString(); }
Value dumpprivkey(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "dumpprivkey <zugzwang address>\n" "Reveals the private key corresponding to <zugzwang address>."); string strAddress = params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) throw JSONRPCError(-5, "Invalid Zugzwang address"); CKeyID keyID; if (!address.GetKeyID(keyID)) throw JSONRPCError(-3, "Address does not refer to a key"); CSecret vchSecret; bool fCompressed; if (!pwalletMain->GetSecret(keyID, vchSecret, fCompressed)) throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known"); return CBitcoinSecret(vchSecret, fCompressed).ToString(); }
Value dumpprivkey(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "dumpprivkey <ppcoinaddress>\n" "Reveals the private key corresponding to <ppcoinaddress>."); string strAddress = params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) throw JSONRPCError(-5, "Invalid ppcoin address"); if (pwalletMain->IsLocked()) throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); if (fWalletUnlockMintOnly) // ppcoin: no dumpprivkey in mint-only mode throw JSONRPCError(-102, "Wallet is unlocked for minting only."); CSecret vchSecret; bool fCompressed; if (!pwalletMain->GetSecret(address, vchSecret, fCompressed)) throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known"); return CBitcoinSecret(vchSecret, fCompressed).ToString(); }
Value dumpprivkey(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "dumpprivkey <Ascentcoinaddress>\n" "Reveals the private key corresponding to <Ascentcoinaddress>."); string strAddress = params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Ascentcoin address"); if (fWalletUnlockMintOnly) // ppcoin: no dumpprivkey in mint-only mode throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Wallet is unlocked for minting only."); CKeyID keyID; if (!address.GetKeyID(keyID)) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); CSecret vchSecret; bool fCompressed; if (!pwalletMain->GetSecret(keyID, vchSecret, fCompressed)) throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known"); return CBitcoinSecret(vchSecret, fCompressed).ToString(); }
void SendMPDialog::sendMPTransaction() { // get the property being sent and get divisibility QString spId = ui->propertyComboBox->itemData(ui->propertyComboBox->currentIndex()).toString(); if (spId.toStdString().empty()) { QMessageBox::critical( this, "Unable to send transaction", "The property selected is not valid.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } uint32_t propertyId = spId.toUInt(); bool divisible = isPropertyDivisible(propertyId); // obtain the selected sender address string strFromAddress = ui->sendFromComboBox->currentText().toStdString(); // push recipient address into a CBitcoinAddress type and check validity CBitcoinAddress fromAddress; if (false == strFromAddress.empty()) { fromAddress.SetString(strFromAddress); } if (!fromAddress.IsValid()) { QMessageBox::critical( this, "Unable to send transaction", "The sender address selected is not valid.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } // obtain the entered recipient address string strRefAddress = ui->sendToLineEdit->text().toStdString(); // push recipient address into a CBitcoinAddress type and check validity CBitcoinAddress refAddress; if (false == strRefAddress.empty()) { refAddress.SetString(strRefAddress); } if (!refAddress.IsValid()) { QMessageBox::critical( this, "Unable to send transaction", "The recipient address entered is not valid.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } // warn if we have to truncate the amount due to a decimal amount for an indivisible property, but allow send to continue string strAmount = ui->amountLineEdit->text().toStdString(); if (!divisible) { size_t pos = strAmount.find("."); if (pos!=std::string::npos) { string tmpStrAmount = strAmount.substr(0,pos); string strMsgText = "The amount entered contains a decimal however the property being sent is indivisible.\n\nThe amount entered will be truncated as follows:\n"; strMsgText += "Original amount entered: " + strAmount + "\nAmount that will be sent: " + tmpStrAmount + "\n\n"; strMsgText += "Do you still wish to proceed with the transaction?"; QString msgText = QString::fromStdString(strMsgText); QMessageBox::StandardButton responseClick; responseClick = QMessageBox::question(this, "Amount truncation warning", msgText, QMessageBox::Yes|QMessageBox::No); if (responseClick == QMessageBox::No) { QMessageBox::critical( this, "Send transaction cancelled", "The send transaction has been cancelled.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } strAmount = tmpStrAmount; ui->amountLineEdit->setText(QString::fromStdString(strAmount)); } } // use strToInt64 function to get the amount, using divisibility of the property int64_t sendAmount = StrToInt64(strAmount, divisible); if (0>=sendAmount) { QMessageBox::critical( this, "Unable to send transaction", "The amount entered is not valid.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } // check if sending address has enough funds int64_t balanceAvailable = getUserAvailableMPbalance(fromAddress.ToString(), propertyId); //getMPbalance(fromAddress.ToString(), propertyId, MONEY); if (sendAmount>balanceAvailable) { QMessageBox::critical( this, "Unable to send transaction", "The selected sending address does not have a sufficient balance to cover the amount entered.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } // check if wallet is still syncing, as this will currently cause a lockup if we try to send - compare our chain to peers to see if we're up to date // Bitcoin Core devs have removed GetNumBlocksOfPeers, switching to a time based best guess scenario uint32_t intBlockDate = GetLatestBlockTime(); // uint32, not using time_t for portability QDateTime currentDate = QDateTime::currentDateTime(); int secs = QDateTime::fromTime_t(intBlockDate).secsTo(currentDate); if(secs > 90*60) { QMessageBox::critical( this, "Unable to send transaction", "The client is still synchronizing. Sending transactions can currently be performed only when the client has completed synchronizing." ); return; } // validation checks all look ok, let's throw up a confirmation dialog string strMsgText = "You are about to send the following transaction, please check the details thoroughly:\n\n"; string propDetails = getPropertyName(propertyId).c_str(); string spNum = strprintf("%d", propertyId); propDetails += " (#" + spNum + ")"; strMsgText += "From: " + fromAddress.ToString() + "\nTo: " + refAddress.ToString() + "\nProperty: " + propDetails + "\nAmount that will be sent: "; if (divisible) { strMsgText += FormatDivisibleMP(sendAmount); } else { strMsgText += FormatIndivisibleMP(sendAmount); } strMsgText += "\n\nAre you sure you wish to send this transaction?"; QString msgText = QString::fromStdString(strMsgText); QMessageBox::StandardButton responseClick; responseClick = QMessageBox::question(this, "Confirm send transaction", msgText, QMessageBox::Yes|QMessageBox::No); if (responseClick == QMessageBox::No) { QMessageBox::critical( this, "Send transaction cancelled", "The send transaction has been cancelled.\n\nPlease double-check the transction details thoroughly before retrying your send transaction." ); return; } // unlock the wallet WalletModel::UnlockContext ctx(walletModel->requestUnlock()); if(!ctx.isValid()) { QMessageBox::critical( this, "Send transaction failed", "The send transaction has been cancelled.\n\nThe wallet unlock process must be completed to send a transaction." ); return; // unlock wallet was cancelled/failed } // create a payload for the transaction std::vector<unsigned char> payload = CreatePayload_SimpleSend(propertyId, sendAmount); // request the wallet build the transaction (and if needed commit it) - note UI does not support added reference amounts currently uint256 txid; std::string rawHex; int result = WalletTxBuilder(fromAddress.ToString(), refAddress.ToString(), "", 0, payload, txid, rawHex, autoCommit); // check error and return the txid (or raw hex depending on autocommit) if (result != 0) { QMessageBox::critical( this, "Send transaction failed", "The send transaction has failed.\n\nThe error code was: " + QString::number(result) + "\nThe error message was:\n" + QString::fromStdString(error_str(result))); return; } else { if (!autoCommit) { PopulateSimpleDialog(rawHex, "Raw Hex (auto commit is disabled)", "Raw transaction hex"); } else { PendingAdd(txid, fromAddress.ToString(), MSC_TYPE_SIMPLE_SEND, propertyId, sendAmount); PopulateTXSentDialog(txid.GetHex()); } } clearFields(); }