Branch data Line data Source code
# 1 : : // Copyright (c) 2019-2020 The Bitcoin Core developers # 2 : : // Distributed under the MIT software license, see the accompanying # 3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php. # 4 : : # 5 : : #include <coins.h> # 6 : : #include <script/signingprovider.h> # 7 : : #include <test/util/transaction_utils.h> # 8 : : # 9 : : CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue) # 10 : 2968 : { # 11 : 2968 : CMutableTransaction txCredit; # 12 : 2968 : txCredit.nVersion = 1; # 13 : 2968 : txCredit.nLockTime = 0; # 14 : 2968 : txCredit.vin.resize(1); # 15 : 2968 : txCredit.vout.resize(1); # 16 : 2968 : txCredit.vin[0].prevout.SetNull(); # 17 : 2968 : txCredit.vin[0].scriptSig = CScript() << CScriptNum(0) << CScriptNum(0); # 18 : 2968 : txCredit.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; # 19 : 2968 : txCredit.vout[0].scriptPubKey = scriptPubKey; # 20 : 2968 : txCredit.vout[0].nValue = nValue; # 21 : : # 22 : 2968 : return txCredit; # 23 : 2968 : } # 24 : : # 25 : : CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit) # 26 : 2968 : { # 27 : 2968 : CMutableTransaction txSpend; # 28 : 2968 : txSpend.nVersion = 1; # 29 : 2968 : txSpend.nLockTime = 0; # 30 : 2968 : txSpend.vin.resize(1); # 31 : 2968 : txSpend.vout.resize(1); # 32 : 2968 : txSpend.vin[0].scriptWitness = scriptWitness; # 33 : 2968 : txSpend.vin[0].prevout.hash = txCredit.GetHash(); # 34 : 2968 : txSpend.vin[0].prevout.n = 0; # 35 : 2968 : txSpend.vin[0].scriptSig = scriptSig; # 36 : 2968 : txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; # 37 : 2968 : txSpend.vout[0].scriptPubKey = CScript(); # 38 : 2968 : txSpend.vout[0].nValue = txCredit.vout[0].nValue; # 39 : : # 40 : 2968 : return txSpend; # 41 : 2968 : } # 42 : : # 43 : : std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues) # 44 : 4 : { # 45 : 4 : std::vector<CMutableTransaction> dummyTransactions; # 46 : 4 : dummyTransactions.resize(2); # 47 : : # 48 : : // Add some keys to the keystore: # 49 : 4 : CKey key[4]; # 50 [ + + ]: 20 : for (int i = 0; i < 4; i++) { # 51 : 16 : key[i].MakeNewKey(i % 2); # 52 : 16 : keystoreRet.AddKey(key[i]); # 53 : 16 : } # 54 : : # 55 : : // Create some dummy input transactions # 56 : 4 : dummyTransactions[0].vout.resize(2); # 57 : 4 : dummyTransactions[0].vout[0].nValue = nValues[0]; # 58 : 4 : dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG; # 59 : 4 : dummyTransactions[0].vout[1].nValue = nValues[1]; # 60 : 4 : dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; # 61 : 4 : AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0); # 62 : : # 63 : 4 : dummyTransactions[1].vout.resize(2); # 64 : 4 : dummyTransactions[1].vout[0].nValue = nValues[2]; # 65 : 4 : dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey())); # 66 : 4 : dummyTransactions[1].vout[1].nValue = nValues[3]; # 67 : 4 : dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey())); # 68 : 4 : AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0); # 69 : : # 70 : 4 : return dummyTransactions; # 71 : 4 : }