本文整理汇总了C++中CBitcoinAddress::SetString方法的典型用法代码示例。如果您正苦于以下问题:C++ CBitcoinAddress::SetString方法的具体用法?C++ CBitcoinAddress::SetString怎么用?C++ CBitcoinAddress::SetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBitcoinAddress
的用法示例。
在下文中一共展示了CBitcoinAddress::SetString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Register
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);
}
示例2: switchTo
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;
}
示例3: dumpprivkey
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();
}
示例4: dumpprivkey
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();
}
示例5: dumpprivkey
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();
}
示例6: dumpprivkey
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();
}
示例7: sendMPTransaction
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;
}
//.........这里部分代码省略.........