本文整理汇总了C++中CBitcoinAddress::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ CBitcoinAddress::Set方法的具体用法?C++ CBitcoinAddress::Set怎么用?C++ CBitcoinAddress::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBitcoinAddress
的用法示例。
在下文中一共展示了CBitcoinAddress::Set方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: obj
/**
* Utility routine to construct a "name info" object to return. This is used
* for name_show and also name_list.
* @param name The name.
* @param value The name's value.
* @param outp The last update's outpoint.
* @param addr The name's address script.
* @param height The name's last update height.
* @return A JSON object to return.
*/
UniValue
getNameInfo (const valtype& name, const valtype& value, const COutPoint& outp,
const CScript& addr, int height)
{
UniValue obj(UniValue::VOBJ);
obj.push_back (Pair ("name", ValtypeToString (name)));
obj.push_back (Pair ("value", ValtypeToString (value)));
obj.push_back (Pair ("txid", outp.hash.GetHex ()));
obj.push_back (Pair ("vout", static_cast<int> (outp.n)));
/* Try to extract the address. May fail if we can't parse the script
as a "standard" script. */
CTxDestination dest;
CBitcoinAddress addrParsed;
std::string addrStr;
if (ExtractDestination (addr, dest) && addrParsed.Set (dest))
addrStr = addrParsed.ToString ();
else
addrStr = "<nonstandard>";
obj.push_back (Pair ("address", addrStr));
/* Calculate expiration data. */
const int curHeight = chainActive.Height ();
const Consensus::Params& params = Params ().GetConsensus ();
const int expireDepth = params.rules->NameExpirationDepth (curHeight);
const int expireHeight = height + expireDepth;
const int expiresIn = expireHeight - curHeight;
const bool expired = (expiresIn <= 0);
obj.push_back (Pair ("height", height));
obj.push_back (Pair ("expires_in", expiresIn));
obj.push_back (Pair ("expired", expired));
return obj;
}
示例2: MakeSignString
std::string CProRegTx::MakeSignString() const
{
std::string s;
// We only include the important stuff in the string form...
CTxDestination destPayout;
CBitcoinAddress addrPayout;
std::string strPayout;
if (ExtractDestination(scriptPayout, destPayout) && addrPayout.Set(destPayout)) {
strPayout = addrPayout.ToString();
} else {
strPayout = HexStr(scriptPayout.begin(), scriptPayout.end());
}
s += strPayout + "|";
s += strprintf("%d", nOperatorReward) + "|";
s += CBitcoinAddress(keyIDOwner).ToString() + "|";
s += CBitcoinAddress(keyIDVoting).ToString() + "|";
// ... and also the full hash of the payload as a protection agains malleability and replays
s += ::SerializeHash(*this).ToString();
return s;
}
示例3: makeHRef
static std::string ScriptToString(const CScript& Script, bool Long = false, bool Highlight = false)
{
if (Script.empty())
return "unknown";
CTxDestination Dest;
CBitcoinAddress Address;
if (ExtractDestination(Script, Dest) && Address.Set(Dest)) {
if (Highlight)
return "<span class=\"addr\">" + Address.ToString() + "</span>";
else
return makeHRef(Address.ToString());
} else
return Long ? "<pre>" + FormatScript(Script) + "</pre>" : _("Non-standard script");
}
示例4: QWidget
MiningPage::MiningPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::MiningPage),
hasMiningprivkey(false)
{
ui->setupUi(this);
int nThreads = boost::thread::hardware_concurrency();
int nUseThreads = GetArg("-genproclimit", -1);
if (nUseThreads < 0)
nUseThreads = nThreads;
std::string PrivAddress = GetArg("-miningprivkey", "");
if (!PrivAddress.empty())
{
CBitcoinSecret Secret;
Secret.SetString(PrivAddress);
if (Secret.IsValid())
{
CBitcoinAddress Address;
Address.Set(Secret.GetKey().GetPubKey().GetID());
ui->labelAddress->setText(QString("All mined coins will go to to %1").arg(Address.ToString().c_str()));
hasMiningprivkey = true;
}
}
ui->sliderCores->setMinimum(0);
ui->sliderCores->setMaximum(nThreads);
ui->sliderCores->setValue(nUseThreads);
ui->labelNCores->setText(QString("%1").arg(nUseThreads));
connect(ui->sliderCores, SIGNAL(valueChanged(int)), this, SLOT(changeNumberOfCores(int)));
connect(ui->pushSwitchMining, SIGNAL(clicked()), this, SLOT(switchMining()));
updateUI();
startTimer(1500);
}
示例5: RunSerialiseTests
void RunSerialiseTests()
{
int64_t nTest;
int64_t nTest0 = 0l;
int64_t nTest4 = 1432035740l;
int64_t nTest4_1 = 2189410940l; // 2039
int64_t nTest5 = 4294967298l; // 2106
int64_t nTest8 = -3l;
BOOST_CHECK(0 == GetNumBytesReqForInt(nTest0));
BOOST_CHECK(4 == GetNumBytesReqForInt(nTest4));
BOOST_CHECK(4 == GetNumBytesReqForInt(nTest4_1)); // expect 4, no sign bit
BOOST_CHECK(5 == GetNumBytesReqForInt(nTest5));
BOOST_CHECK(8 == GetNumBytesReqForInt(nTest8));
//BOOST_TEST_MESSAGE(GetNumBytesReqForInt(nTest5));
std::vector<uint8_t> v;
SetCompressedInt64(v, nTest0);
GetCompressedInt64(v, (uint64_t&)nTest);
BOOST_CHECK(nTest0 == nTest);
SetCompressedInt64(v, nTest5);
GetCompressedInt64(v, (uint64_t&)nTest);
BOOST_CHECK(nTest5 == nTest);
SetCompressedInt64(v, nTest8);
GetCompressedInt64(v, (uint64_t&)nTest);
BOOST_CHECK(nTest8 == nTest);
CStoredExtKey sk, sk_;
CStoredExtKey skInvalid, skInvalid_;
CExtKey58 eKey58;
BOOST_CHECK(0 == eKey58.Set58("moivYMcZoUdupxqBNASoNKWbyBzKFPzYA3ZauZhCyQGcUhdvxhgsYNdqBkCbspTmaXWtW68Ha7gjMBjb5gbudrictnzw9KAVKogAXC8FsqiSzRp"));
sk.kp = eKey58.GetKey();
sk.sLabel = "sk label";
sk.nGenerated = 5;
sk.nHGenerated = 6;
sk.mapValue[EKVT_CREATED_AT] = SetCompressedInt64(v, nTest8);
eKey58.SetKey(sk.kp, CChainParams::EXT_PUBLIC_KEY);
BOOST_CHECK(eKey58.ToString() == "moipXY9njTPCnsVV8vPCLA1xKp2NXdRtPVyGABKcbshkKQUadnrk2XPccZcSDjefRX64mNjYpS33SAy97UHGWs9WoAufi9pdow9gsYMvVEcmgSk");
eKey58.SetKeyV(sk.kp);
BOOST_CHECK(eKey58.ToString() == "moivYMcZoUdupxqBNASoNKWbyBzKFPzYA3ZauZhCyQGcUhdvxhgsYNdqBkCbspTmaXWtW68Ha7gjMBjb5gbudrictnzw9KAVKogAXC8FsqiSzRp");
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << sk << skInvalid;
ss >> sk_;
ss >> skInvalid_;
BOOST_CHECK(sk.kp == sk_.kp);
BOOST_CHECK(1 == sk_.kp.IsValidV());
BOOST_CHECK(1 == sk_.kp.IsValidP());
BOOST_CHECK(sk.sLabel == sk_.sLabel);
BOOST_CHECK(sk.nGenerated == sk_.nGenerated);
BOOST_CHECK(sk.nHGenerated == sk_.nHGenerated);
BOOST_CHECK(nTest8 == GetCompressedInt64(sk_.mapValue[EKVT_CREATED_AT], (uint64_t&)nTest));
BOOST_CHECK(0 == skInvalid.kp.IsValidV());
BOOST_CHECK(0 == skInvalid.kp.IsValidP());
// path
std::vector<uint8_t> vPath;
PushUInt32(vPath, 1);
PushUInt32(vPath, 3);
PushUInt32(vPath, 2);
PushUInt32(vPath, 4294967295);
std::string sPath;
BOOST_CHECK(0 == PathToString(vPath, sPath, 'h'));
BOOST_CHECK(sPath == "m/1/3/2/2147483647h");
vPath.resize(0);
PushUInt32(vPath, 1);
PushUInt32(vPath, 4294967294);
PushUInt32(vPath, 30);
BOOST_CHECK(0 == PathToString(vPath, sPath));
BOOST_CHECK(sPath == "m/1/2147483646'/30");
// id
CBitcoinAddress addr;
CKeyID id = sk.GetID();
CKeyID idTest;
BOOST_CHECK(true == addr.Set(id, CChainParams::EXT_KEY_HASH)
&& addr.IsValid(CChainParams::EXT_KEY_HASH)
&& addr.GetKeyID(idTest, CChainParams::EXT_KEY_HASH));
//.........这里部分代码省略.........
示例6: on_getNewAddress_clicked
void PaperWalletDialog::on_getNewAddress_clicked()
{
// Create a new private key
CKey privKey;
privKey.MakeNewKey(true);
// Derive the public key
CPubKey pubkey = privKey.GetPubKey();
// Derive the public key hash
CBitcoinAddress pubkeyhash;
pubkeyhash.Set(pubkey.GetID());
// Create String versions of each
string myPrivKey = CBitcoinSecret(privKey).ToString();
string myPubKey = HexStr(pubkey.begin(), pubkey.end());
string myAddress = pubkeyhash.ToString();
#ifdef USE_QRCODE
// Generate the address QR code
QRcode *code = QRcode_encodeString(myAddress.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1);
if (!code)
{
ui->addressQRCode->setText(tr("Error encoding Address into QR Code."));
return;
}
QImage publicKeyImage = QImage(code->width, code->width, QImage::Format_ARGB32);
publicKeyImage.fill(0x000000);
unsigned char *p = code->data;
for (int y = 0; y < code->width; y++)
{
for (int x = 0; x < code->width; x++)
{
publicKeyImage.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0));
p++;
}
}
QRcode_free(code);
// Generate the private key QR code
code = QRcode_encodeString(myPrivKey.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1);
if (!code)
{
ui->privateKeyQRCode->setText(tr("Error encoding private key into QR Code."));
return;
}
QImage privateKeyImage = QImage(code->width, code->width, QImage::Format_ARGB32);
privateKeyImage.fill(0x000000);
p = code->data;
for (int y = 0; y < code->width; y++)
{
for (int x = 0; x < code->width; x++)
{
privateKeyImage.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0));
p++;
}
}
QRcode_free(code);
// Populate the QR Codes
ui->addressQRCode->setPixmap(QPixmap::fromImage(publicKeyImage).scaled(ui->addressQRCode->width(), ui->addressQRCode->height()));
ui->privateKeyQRCode->setPixmap(QPixmap::fromImage(privateKeyImage).scaled(ui->privateKeyQRCode->width(), ui->privateKeyQRCode->height()));
#endif
// Populate the Texts
ui->addressText->setText(myAddress.c_str());
ui->privateKeyText->setText(tr(myPrivKey.c_str()));
ui->publicKey->setHtml(myPubKey.c_str());
// Update the fonts to fit the height of the wallet.
// This should only really trigger the first time since the font size persists.
double paperHeight = (double) ui->paperTemplate->height();
double maxTextWidth = paperHeight * 0.99;
double minTextWidth = paperHeight * 0.95;
int pixelSizeStep = 1;
int addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width();
QFont font = ui->addressText->font();
for(int i = 0; i < PAPER_WALLET_READJUST_LIMIT; i++) {
if ( addressTextLength < minTextWidth) {
font.setPixelSize(font.pixelSize() + pixelSizeStep);
ui->addressText->setFont(font);
addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width();
} else {
break;
}
}
if ( addressTextLength > maxTextWidth ) {
font.setPixelSize(font.pixelSize() - pixelSizeStep);
ui->addressText->setFont(font);
addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width();
}
int privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width();
font = ui->privateKeyText->font();
for(int i = 0; i < PAPER_WALLET_READJUST_LIMIT; i++) {
//.........这里部分代码省略.........
示例7: RunSerialiseTests
void RunSerialiseTests()
{
int64_t nTest;
int64_t nTest0 = 0l;
int64_t nTest4 = 1432035740l;
int64_t nTest4_1 = 2189410940l; // 2039
int64_t nTest5 = 4294967298l; // 2106
int64_t nTest8 = -3l;
BOOST_CHECK(0 == GetNumBytesReqForInt(nTest0));
BOOST_CHECK(4 == GetNumBytesReqForInt(nTest4));
BOOST_CHECK(4 == GetNumBytesReqForInt(nTest4_1)); // expect 4, no sign bit
BOOST_CHECK(5 == GetNumBytesReqForInt(nTest5));
BOOST_CHECK(8 == GetNumBytesReqForInt(nTest8));
//BOOST_MESSAGE(GetNumBytesReqForInt(nTest5));
std::vector<uint8_t> v;
SetCompressedInt64(v, nTest0);
GetCompressedInt64(v, (uint64_t&)nTest);
BOOST_CHECK(nTest0 == nTest);
SetCompressedInt64(v, nTest5);
GetCompressedInt64(v, (uint64_t&)nTest);
BOOST_CHECK(nTest5 == nTest);
SetCompressedInt64(v, nTest8);
GetCompressedInt64(v, (uint64_t&)nTest);
BOOST_CHECK(nTest8 == nTest);
CStoredExtKey sk, sk_;
CStoredExtKey skInvalid, skInvalid_;
CExtKey58 eKey58;
BOOST_CHECK(0 == eKey58.Set58("sdcvmnKmFxG9k6UnN3wyLpTv83G1wgYEz1m21rZTUUimoDrYYMrZXUycudse21EZJTmkBBPN3k6Qhfzx5td8xzd9W893YhNozA3bZW3yVLVdrZU2"));
sk.kp = eKey58.GetKey();
sk.sLabel = "sk label";
sk.nGenerated = 5;
sk.nHGenerated = 6;
sk.mapValue[EKVT_CREATED_AT] = SetCompressedInt64(v, nTest8);
eKey58.SetKey(sk.kp, CChainParams::EXT_PUBLIC_KEY);
BOOST_CHECK(eKey58.ToString() == "sdcpmphCJNSUos9rNqn6FNi3ztvMW1wft1PVbifvBrwhm6JnhD9yk8rSNFTGfozGbmBsr8vZv9mGYSTfmEMpbfTTMb8TQfj7JRABmvBFKgA2xG8J");
eKey58.SetKeyV(sk.kp);
BOOST_CHECK(eKey58.ToString() == "sdcvmnKmFxG9k6UnN3wyLpTv83G1wgYEz1m21rZTUUimoDrYYMrZXUycudse21EZJTmkBBPN3k6Qhfzx5td8xzd9W893YhNozA3bZW3yVLVdrZU2");
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << sk << skInvalid;
ss >> sk_;
ss >> skInvalid_;
BOOST_CHECK(sk.kp == sk_.kp);
BOOST_CHECK(1 == sk_.kp.IsValidV());
BOOST_CHECK(1 == sk_.kp.IsValidP());
BOOST_CHECK(sk.sLabel == sk_.sLabel);
BOOST_CHECK(sk.nGenerated == sk_.nGenerated);
BOOST_CHECK(sk.nHGenerated == sk_.nHGenerated);
BOOST_CHECK(nTest8 == GetCompressedInt64(sk_.mapValue[EKVT_CREATED_AT], (uint64_t&)nTest));
BOOST_CHECK(0 == skInvalid.kp.IsValidV());
BOOST_CHECK(0 == skInvalid.kp.IsValidP());
// path
std::vector<uint8_t> vPath;
PushUInt32(vPath, 1);
PushUInt32(vPath, 3);
PushUInt32(vPath, 2);
PushUInt32(vPath, 4294967295);
std::string sPath;
BOOST_CHECK(0 == PathToString(vPath, sPath, 'h'));
BOOST_CHECK(sPath == "m/1/3/2/2147483647h");
vPath.resize(0);
PushUInt32(vPath, 1);
PushUInt32(vPath, 4294967294);
PushUInt32(vPath, 30);
BOOST_CHECK(0 == PathToString(vPath, sPath));
BOOST_CHECK(sPath == "m/1/2147483646'/30");
// id
CBitcoinAddress addr;
CKeyID id = sk.GetID();
CKeyID idTest;
BOOST_CHECK(true == addr.Set(id, CChainParams::EXT_KEY_HASH)
&& addr.IsValid(CChainParams::EXT_KEY_HASH)
&& addr.GetKeyID(idTest, CChainParams::EXT_KEY_HASH));
//.........这里部分代码省略.........