Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/transaction_utils.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <coins.h> | |||||
#include <script/signingprovider.h> | |||||
#include <test/util/transaction_utils.h> | #include <test/util/transaction_utils.h> | ||||
CMutableTransaction BuildCreditingTransaction(const CScript &scriptPubKey, | CMutableTransaction BuildCreditingTransaction(const CScript &scriptPubKey, | ||||
const Amount nValue) { | const Amount nValue) { | ||||
CMutableTransaction txCredit; | CMutableTransaction txCredit; | ||||
txCredit.nVersion = 1; | txCredit.nVersion = 1; | ||||
txCredit.nLockTime = 0; | txCredit.nLockTime = 0; | ||||
txCredit.vin.resize(1); | txCredit.vin.resize(1); | ||||
Show All 17 Lines | CMutableTransaction BuildSpendingTransaction(const CScript &scriptSig, | ||||
txSpend.vin[0].prevout = COutPoint(txCredit.GetId(), 0); | txSpend.vin[0].prevout = COutPoint(txCredit.GetId(), 0); | ||||
txSpend.vin[0].scriptSig = scriptSig; | txSpend.vin[0].scriptSig = scriptSig; | ||||
txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; | txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; | ||||
txSpend.vout[0].scriptPubKey = CScript(); | txSpend.vout[0].scriptPubKey = CScript(); | ||||
txSpend.vout[0].nValue = txCredit.vout[0].nValue; | txSpend.vout[0].nValue = txCredit.vout[0].nValue; | ||||
return txSpend; | return txSpend; | ||||
} | } | ||||
std::vector<CMutableTransaction> | |||||
SetupDummyInputs(FillableSigningProvider &keystoreRet, | |||||
CCoinsViewCache &coinsRet, | |||||
const std::array<Amount, 4> &nValues) { | |||||
std::vector<CMutableTransaction> dummyTransactions; | |||||
dummyTransactions.resize(2); | |||||
// Add some keys to the keystore: | |||||
CKey key[4]; | |||||
for (int i = 0; i < 4; i++) { | |||||
key[i].MakeNewKey(i % 2); | |||||
keystoreRet.AddKey(key[i]); | |||||
} | |||||
// Create some dummy input transactions | |||||
dummyTransactions[0].vout.resize(2); | |||||
dummyTransactions[0].vout[0].nValue = nValues[0]; | |||||
dummyTransactions[0].vout[0].scriptPubKey | |||||
<< ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG; | |||||
dummyTransactions[0].vout[1].nValue = nValues[1]; | |||||
dummyTransactions[0].vout[1].scriptPubKey | |||||
<< ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; | |||||
AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0); | |||||
dummyTransactions[1].vout.resize(2); | |||||
dummyTransactions[1].vout[0].nValue = nValues[2]; | |||||
dummyTransactions[1].vout[0].scriptPubKey = | |||||
GetScriptForDestination(PKHash(key[2].GetPubKey())); | |||||
dummyTransactions[1].vout[1].nValue = nValues[3]; | |||||
dummyTransactions[1].vout[1].scriptPubKey = | |||||
GetScriptForDestination(PKHash(key[3].GetPubKey())); | |||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0); | |||||
return dummyTransactions; | |||||
} |