本文整理汇总了C++中Bignum::SetHex方法的典型用法代码示例。如果您正苦于以下问题:C++ Bignum::SetHex方法的具体用法?C++ Bignum::SetHex怎么用?C++ Bignum::SetHex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bignum
的用法示例。
在下文中一共展示了Bignum::SetHex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newCoin
bool
ZerocoinTutorial()
{
// The following simple code illustrates the call flow for Zerocoin
// applications. In a real currency network these operations would
// be split between individual payers/payees, network nodes and miners.
//
// For each call we specify the participant who would use it.
// Zerocoin uses exceptions (based on the runtime_error class)
// to indicate all sorts of problems. Always remember to catch them!
try {
/********************************************************************/
// What is it: Parameter loading
// Who does it: ALL ZEROCOIN PARTICIPANTS
// What it does: Loads a trusted Zerocoin modulus "N" and
// generates all associated parameters from it.
// We use a hardcoded "N" that we generated using
// the included 'paramgen' utility.
/********************************************************************/
// Load a test modulus from our hardcoded string (above)
Bignum testModulus;
testModulus.SetHex(std::string(TUTORIAL_TEST_MODULUS));
// Set up the Zerocoin Params object
libzerocoin::Params* params = new libzerocoin::Params(testModulus);
cout << "Successfully loaded parameters." << endl;
/********************************************************************/
// What is it: Coin generation
// Who does it: ZEROCOIN CLIENTS
// What it does: Generates a new 'zerocoin' coin using the
// public parameters. Once generated, the client
// will transmit the public portion of this coin
// in a ZEROCOIN_MINT transaction. The inputs
// to this transaction must add up to the zerocoin
// denomination plus any transaction fees.
/********************************************************************/
// The following constructor does all the work of minting a brand
// new zerocoin. It stores all the private values inside the
// PrivateCoin object. This includes the coin secrets, which must be
// stored in a secure location (wallet) at the client.
libzerocoin::PrivateCoin newCoin(params);
// Get a copy of the 'public' portion of the coin. You should
// embed this into a Zerocoin 'MINT' transaction along with a series
// of currency inputs totaling the assigned value of one zerocoin.
libzerocoin::PublicCoin pubCoin = newCoin.getPublicCoin();
cout << "Successfully minted a zerocoin." << endl;
// Serialize the public coin to a CDataStream object.
CDataStream serializedCoin(SER_NETWORK, PROTOCOL_VERSION);
serializedCoin << pubCoin;
/********************************************************************/
// What is it: Coin verification
// Who does it: TRANSACTION VERIFIERS
// What it does: Verifies the structure of a zerocoin obtained from
// a ZEROCOIN_MINT transaction. All coins must be
// verified before you operate on them.
// Note that this is only part of the transaction
// verification process! The client must also check
// that (1) the inputs to the transaction are valid
// and add up to the value of one zerocoin, (2) that
// this particular zerocoin has not been minted before.
/********************************************************************/
// Deserialize the public coin into a fresh object. This will
// automatically validate that the coin is correctly structured and
// will throw an exception if it isn't. (You need to handle those.)
libzerocoin::PublicCoin pubCoinNew(params, serializedCoin);
cout << "Deserialized and verified the coin." << endl;
/********************************************************************/
// What is it: Accumulator computation
// Who does it: ZEROCOIN CLIENTS & TRANSACTION VERIFIERS
// What it does: Collects a number of PublicCoin values drawn from
// the block chain and calculates an accumulator.
// This accumulator is incrementally computable;
// you can stop and serialize it at any point
// then continue accumulating new transactions.
// The accumulator is also order-independent, so
// the same coins can be accumulated in any order
// to give the same result.
// WARNING: do not accumulate the same coin twice!
/********************************************************************/
// Create an empty accumulator object
libzerocoin::Accumulator accumulator(params);
// Add several coins to it (we'll generate them here on the fly).
for (uint32_t i = 0; i < COINS_TO_ACCUMULATE; i++) {
libzerocoin::PrivateCoin testCoin(params);
//.........这里部分代码省略.........