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 1502 : CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue) 10 : { 11 1502 : CMutableTransaction txCredit; 12 1502 : txCredit.nVersion = 1; 13 1502 : txCredit.nLockTime = 0; 14 1502 : txCredit.vin.resize(1); 15 1502 : txCredit.vout.resize(1); 16 1502 : txCredit.vin[0].prevout.SetNull(); 17 1502 : txCredit.vin[0].scriptSig = CScript() << CScriptNum(0) << CScriptNum(0); 18 1502 : txCredit.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; 19 1502 : txCredit.vout[0].scriptPubKey = scriptPubKey; 20 1502 : txCredit.vout[0].nValue = nValue; 21 : 22 1502 : return txCredit; 23 1502 : } 24 : 25 1502 : CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CTransaction& txCredit) 26 : { 27 1502 : CMutableTransaction txSpend; 28 1502 : txSpend.nVersion = 1; 29 1502 : txSpend.nLockTime = 0; 30 1502 : txSpend.vin.resize(1); 31 1502 : txSpend.vout.resize(1); 32 1502 : txSpend.vin[0].prevout.hash = txCredit.GetHash(); 33 1502 : txSpend.vin[0].prevout.n = 0; 34 1502 : txSpend.vin[0].scriptSig = scriptSig; 35 1502 : txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; 36 1502 : txSpend.vout[0].scriptPubKey = CScript(); 37 1502 : txSpend.vout[0].nValue = 0; 38 : 39 1502 : return txSpend; 40 1502 : } 41 : 42 2 : std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues) 43 : { 44 2 : std::vector<CMutableTransaction> dummyTransactions; 45 2 : dummyTransactions.resize(2); 46 : 47 : // Add some keys to the keystore: 48 2 : CKey key[4]; 49 10 : for (int i = 0; i < 4; i++) { 50 8 : key[i].MakeNewKey(i % 2); 51 8 : keystoreRet.AddKey(key[i]); 52 8 : } 53 : 54 : // Create some dummy input transactions 55 2 : dummyTransactions[0].vout.resize(2); 56 2 : dummyTransactions[0].vout[0].nValue = nValues[0]; 57 2 : dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG; 58 2 : dummyTransactions[0].vout[1].nValue = nValues[1]; 59 2 : dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; 60 2 : AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0); 61 : 62 2 : dummyTransactions[1].vout.resize(2); 63 2 : dummyTransactions[1].vout[0].nValue = nValues[2]; 64 2 : dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey())); 65 2 : dummyTransactions[1].vout[1].nValue = nValues[3]; 66 2 : dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey())); 67 2 : AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0); 68 : 69 2 : return dummyTransactions; 70 2 : }