本文整理汇总了C++中Transaction::addInput方法的典型用法代码示例。如果您正苦于以下问题:C++ Transaction::addInput方法的具体用法?C++ Transaction::addInput怎么用?C++ Transaction::addInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::addInput方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: Chain
DogecoinChain::DogecoinChain() : Chain("dogecoin", "DGE", 8), _genesis("0x1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691") {
_alert_key = ParseHex("04d4da7a5dae4db797d9b0644d57a5cd50e05a70f36091cd62e2fc41c98ded06340be5a43a35e185690cd9cde5d72da8f6d065b499b06f51dcfba14aad859f443a"); _magic[0] = 0xc0; _magic[1] = 0xc0; _magic[2] = 0xc0; _magic[3] = 0xc0; // Litecoin: increase each by adding 2 to bitcoin's value.
const char* pszTimestamp = "Nintondo";
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("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9") << OP_CHECKSIG;
txNew.addOutput(Output(88 * COIN, script));
_genesisBlock = Block(1, uint256(0), uint256(0), 1386325540, 0x1e0ffff0, 99943);
_genesisBlock.addTransaction(txNew);
_genesisBlock.updateMerkleTree(); // genesisBlock
assert(_genesisBlock.getHash() == _genesis);
_checkpoints = boost::assign::map_list_of
( 0, uint256("0x1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691"))
( 42279, uint256("0x8444c3ef39a46222e87584ef956ad2c9ef401578bd8b51e8e4b9a86ec3134d3a"))
( 42400, uint256("0x557bb7c17ed9e6d4a6f9361cfddf7c1fc0bdc394af7019167442b41f507252b4"))
;
_seeds = boost::assign::list_of
("seed.dogecoin.com");
}
示例4: 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"))
;
}
示例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;
}
}