本文整理汇总了C++中CBasicKeyStore::AddKeyPubKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CBasicKeyStore::AddKeyPubKey方法的具体用法?C++ CBasicKeyStore::AddKeyPubKey怎么用?C++ CBasicKeyStore::AddKeyPubKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBasicKeyStore
的用法示例。
在下文中一共展示了CBasicKeyStore::AddKeyPubKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculateNestedKeyhashInputSize
// Explicit calculation which is used to test the wallet constant
// We get the same virtual size due to rounding(weight/4) for both use_max_sig values
static size_t CalculateNestedKeyhashInputSize(bool use_max_sig)
{
// Generate ephemeral valid pubkey
CKey key;
key.MakeNewKey(true);
CPubKey pubkey = key.GetPubKey();
// Generate pubkey hash
uint160 key_hash(Hash160(pubkey.begin(), pubkey.end()));
// Create inner-script to enter into keystore. Key hash can't be 0...
CScript inner_script = CScript() << OP_0 << std::vector<unsigned char>(key_hash.begin(), key_hash.end());
// Create outer P2SH script for the output
uint160 script_id(Hash160(inner_script.begin(), inner_script.end()));
CScript script_pubkey = CScript() << OP_HASH160 << std::vector<unsigned char>(script_id.begin(), script_id.end()) << OP_EQUAL;
// Add inner-script to key store and key to watchonly
CBasicKeyStore keystore;
keystore.AddCScript(inner_script);
keystore.AddKeyPubKey(key, pubkey);
// Fill in dummy signatures for fee calculation.
SignatureData sig_data;
if (!ProduceSignature(keystore, use_max_sig ? DUMMY_MAXIMUM_SIGNATURE_CREATOR : DUMMY_SIGNATURE_CREATOR, script_pubkey, sig_data)) {
// We're hand-feeding it correct arguments; shouldn't happen
assert(false);
}
CTxIn tx_in;
UpdateInput(tx_in, sig_data);
return (size_t)GetVirtualTransactionInputSize(tx_in);
}
示例2: GenerateRandomTransaction
bool TestChainForComputingMediansSetup::GenerateRandomTransaction(CTransaction& txNew)
{
CAmount amountToSend = 5000;
std::vector<CTransaction> res;
CKey key;
key.MakeNewKey(true);
CScript scriptPubKey = CScript() << ToByteVector(key.GetPubKey())
<< OP_CHECKSIG;
CBasicKeyStore keystore;
keystore.AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
CTransaction utxo = coinbaseTxns[0];
coinbaseTxns.erase(coinbaseTxns.begin());
txNew.nLockTime = chainActive.Height();
txNew.vin.clear();
txNew.vout.clear();
for (int j = 0; j < nOutputs; ++j) {
CTxOut txout(amountToSend, scriptPubKey);
txNew.vout.push_back(txout);
}
//vin
CTxIn vin = CTxIn(utxo.GetHash(), 0, CScript(),
std::numeric_limits<unsigned int>::max() - 1);
txNew.vin.push_back(vin);
//previous tx's script pub key that we need to sign
CScript& scriptSigRes = txNew.vin[0].scriptSig;
CTransaction txNewConst(txNew);
ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0),
utxo.vout[0].scriptPubKey, scriptSigRes);
res.push_back(txNew);
return true;
}