本文整理汇总了C++中Transaction::addOutput方法的典型用法代码示例。如果您正苦于以下问题:C++ Transaction::addOutput方法的具体用法?C++ Transaction::addOutput怎么用?C++ Transaction::addOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::addOutput方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Chain
NamecoinChain::NamecoinChain() : Chain("namecoin", "NMC", 8), _genesis("000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770") {
_alert_key = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
_magic[0] = 0xf9; _magic[1] = 0xbe; _magic[2] = 0xb4; _magic[3] = 0xfe;
const char* pszTimestamp = "... choose what comes next. Lives of your own, or a return to chains. -- V";
Transaction txNew;
Script signature = Script() << 0x1c007fff << CBigNum(522) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.addInput(Input(Coin(), signature));
Script script = Script() << ParseHex("04b620369050cd899ffbbc4e8ee51e8c4534a855bb463439d63d235d4779685d8b6f4870a238cf365ac94fa13ef9a2a22cd99d0d5ee86dcabcafce36c7acf43ce5") << OP_CHECKSIG;
txNew.addOutput(Output(50 * COIN, script));
_genesisBlock = Block(1, uint256(0), uint256(0), 1303000001, 0x1c007fff, 0xa21ea192U);
_genesisBlock.addTransaction(txNew);
_genesisBlock.updateMerkleTree(); // genesisBlock
assert(_genesisBlock.getHash() == _genesis);
_checkpoints = boost::assign::map_list_of
( 2016, uint256("0x0000000000660bad0d9fbde55ba7ee14ddf766ed5f527e3fbca523ac11460b92"))
( 4032, uint256("0x0000000000493b5696ad482deb79da835fe2385304b841beef1938655ddbc411"))
( 6048, uint256("0x000000000027939a2e1d8bb63f36c47da858e56d570f143e67e85068943470c9"))
( 8064, uint256("0x000000000003a01f708da7396e54d081701ea406ed163e519589717d8b7c95a5"))
( 10080, uint256("0x00000000000fed3899f818b2228b4f01b9a0a7eeee907abd172852df71c64b06"))
( 12096, uint256("0x0000000000006c06988ff361f124314f9f4bb45b6997d90a7ee4cedf434c670f"))
( 14112, uint256("0x00000000000045d95e0588c47c17d593c7b5cb4fb1e56213d1b3843c1773df2b"))
( 16128, uint256("0x000000000001d9964f9483f9096cf9d6c6c2886ed1e5dec95ad2aeec3ce72fa9"))
( 18940, uint256("0x00000000000087f7fc0c8085217503ba86f796fa4984f7e5a08b6c4c12906c05"))
( 30240, uint256("0xe1c8c862ff342358384d4c22fa6ea5f669f3e1cdcf34111f8017371c3c0be1da"))
( 57000, uint256("0xaa3ec60168a0200799e362e2b572ee01f3c3852030d07d036e0aa884ec61f203"))
(112896, uint256("0x73f880e78a04dd6a31efc8abf7ca5db4e262c4ae130d559730d6ccb8808095bf"))
(182000, uint256("0xd47b4a8fd282f635d66ce34ebbeb26ffd64c35b41f286646598abfd813cba6d9"))
;
}
示例2: Script
BitcoinChain::BitcoinChain() : _genesis("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f") {
_messageStart[0] = 0xf9;
_messageStart[1] = 0xbe;
_messageStart[2] = 0xb4;
_messageStart[3] = 0xd9;
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
Transaction txNew;
Script signature = Script() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.addInput(Input(Coin(), signature));
Script script = Script() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
txNew.addOutput(Output(50 * COIN, script));
_genesisBlock = Block(1, 0, 0, 1231006505, 0x1d00ffff, 2083236893);
_genesisBlock.addTransaction(txNew);
_genesisBlock.updateMerkleTree(); // genesisBlock
assert(_genesisBlock.getHash() == _genesis);
_checkpoints = boost::assign::map_list_of
( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
( 68555, uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))
( 70567, uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"))
( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20"))
(105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97"))
(118000, uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553"))
(134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
(140700, uint256("0x000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd"))
(168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
;
}
示例3: createtransaction
std::string createtransaction(bool bHelp, params_t& params)
{
if (bHelp || params.size() != 5) {
return "createtransaction <outhash> <outindex> <redeemscript> <toaddress> <value> - creates a transaction claiming a multisignature input.";
}
uchar_vector outHash = params[0];
uint outIndex = strtoul(params[1].c_str(), NULL, 10);
uchar_vector redeemScript = params[2];
std::string toAddress = params[3];
uint64_t value = strtoull(params[4].c_str(), NULL, 10);
StandardTxOut txOut;
txOut.set(toAddress, value);
MultiSigRedeemScript multiSig;
multiSig.parseRedeemScript(redeemScript);
P2SHTxIn txIn(outHash, outIndex, multiSig.getRedeemScript());
txIn.setScriptSig(SCRIPT_SIG_SIGN);
Transaction tx;
tx.addOutput(txOut);
tx.addInput(txIn);
uchar_vector hashToSign = tx.getHashWithAppendedCode(1); // SIGHASH_ALL
for (uint i = 0; i < multiSig.getPubKeyCount(); i++) {
txIn.addSig(uchar_vector(), uchar_vector(), SIGHASH_ALREADYADDED);
}
txIn.setScriptSig(SCRIPT_SIG_EDIT);
tx.clearInputs();
tx.addInput(txIn);
return tx.getSerialized().getHex();
}
示例4: signtransaction
std::string signtransaction(bool bHelp, params_t& params)
{
if (bHelp || params.size() < 6) {
return "signtransaction <outhash> <outindex> <redeemscript> <toaddress> <value> <privkey1> [<privkey2> <privkey3> ...] - creates and signs a transaction claiming a multisignature input.";
}
uchar_vector outHash = params[0];
uint outIndex = strtoul(params[1].c_str(), NULL, 10);
uchar_vector redeemScript = params[2];
std::string toAddress = params[3];
uint64_t value = strtoull(params[4].c_str(), NULL, 10);
std::vector<std::string> privKeys;
for (uint i = 5; i < params.size(); i++) {
privKeys.push_back(params[i]);
}
StandardTxOut txOut;
txOut.set(toAddress, value);
MultiSigRedeemScript multiSig;
multiSig.parseRedeemScript(redeemScript);
P2SHTxIn txIn(outHash, outIndex, multiSig.getRedeemScript());
txIn.setScriptSig(SCRIPT_SIG_SIGN);
Transaction tx;
tx.addOutput(txOut);
tx.addInput(txIn);
uchar_vector hashToSign = tx.getHashWithAppendedCode(1); // SIGHASH_ALL
// TODO: make sure to wipe all key data if there's any failure
CoinKey key;
for (uint i = 0; i < privKeys.size(); i++) {
if (!key.setWalletImport(privKeys[i])) {
std::stringstream ss;
ss << "Private key " << i+1 << " is invalid.";
throw std::runtime_error(ss.str());
}
uchar_vector sig;
if (!key.sign(hashToSign, sig)) {
std::stringstream ss;
ss << "Error signing with key " << i+1 << ".";
throw std::runtime_error(ss.str());
}
txIn.addSig(uchar_vector(), sig);
}
if (privKeys.size() < multiSig.getMinSigs()) {
txIn.setScriptSig(SCRIPT_SIG_EDIT);
}
else {
txIn.setScriptSig(SCRIPT_SIG_BROADCAST);
}
tx.clearInputs();
tx.addInput(txIn);
return tx.getSerialized().getHex();
}
示例5: main
int main(int argc, char* argv[])
{
/// We test the Claims class by inserting a series of transactions - so first generate some transactions:
/// (note the transactions need not be valid as Claims will not check this)
/// However, first we generate a list of unspents to build transactions from
cout << "==== Testing class Claims ====\n" << endl;
try {
cout << "Checking that assignment works" << endl;
Claims claims;
vector<Unspent> unspents;
for (size_t i = 0; i < 200; ++i)
unspents.push_back(Unspent(0, rand_hash(), rand_idx(), i*COIN, Script(), 0, 0));
size_t blocks = 0;
while (blocks < 100 && unspents.size() > 100) {
/// Then build a transaction from n inputs grabbed from the unspents pool generating m outputs (which are fed back into the pool)
while (claims.count() < 100 && unspents.size() > 10) {
Transaction txn;
Claims::Spents spents;
spents.clear();
int64_t amount = 0;
size_t n = 1+rand()%3;
for (size_t i = 0; i < n; i++) {
size_t idx = rand()%unspents.size();
txn.addInput(Input(unspents[idx].key));
amount += unspents[idx].output.value();
spents.insert(unspents[idx].key);
unspents.erase(unspents.begin() + idx); // erase the unspents as it is now used in a txn
}
size_t m = 2+rand()%3;
int64_t fee = rand()%1000000;
amount -= fee;
for (size_t j = 0; j < m; j++) {
Output output(amount/m, Script());
txn.addOutput(output);
}
uint256 hash = txn.getHash();
for (size_t j = 0; j < m; j++) {
Output output = txn.getOutput(j);
unspents.push_back(Unspent(0, hash, j, output.value(), output.script(), 0, 0));
}
claims.insert(txn, spents, fee);
}
// now get the transactions for a block candidate:
int64_t fee;
vector<Transaction> txns = claims.transactions(fee);
cout << "Created block candidate with " << txns.size() << " transactions and a fee of " << fee << " satoshis." << endl;
blocks++;
for (size_t i = 0; i < txns.size(); ++i)
claims.erase(txns[i].getHash());
cout << "\t Total unspents is now " << unspents.size() << endl;
}
return 0;
}
catch (std::exception &e) {
cout << "Exception: " << e.what() << endl;
return 1;
}
}