rawtransaction_util.h raw
1 // Copyright (c) 2017-2022 The Limenka 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 #ifndef LIMENKA_RPC_RAWTRANSACTION_UTIL_H
6 #define LIMENKA_RPC_RAWTRANSACTION_UTIL_H
7
8 #include <addresstype.h>
9 #include <consensus/amount.h>
10 #include <map>
11 #include <optional>
12 #include <string>
13 #include <optional>
14
15 struct bilingual_str;
16 struct FlatSigningProvider;
17 class UniValue;
18 struct CMutableTransaction;
19 class Coin;
20 class COutPoint;
21 class SigningProvider;
22
23 /**
24 * Sign a transaction with the given keystore and previous transactions
25 *
26 * @param mtx The transaction to-be-signed
27 * @param keystore Temporary keystore containing signing keys
28 * @param coins Map of unspent outputs
29 * @param hashType The signature hash type
30 * @param result JSON object where signed transaction results accumulate
31 */
32 void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result);
33 void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result, const std::optional<CAmount>& inputs_amount_sum);
34
35 /**
36 * Parse a prevtxs UniValue array and get the map of coins from it
37 *
38 * @param prevTxsUnival Array of previous txns outputs that tx depends on but may not yet be in the block chain
39 * @param keystore A pointer to the temporary keystore if there is one
40 * @param coins Map of unspent outputs - coins in mempool and current chain UTXO set, may be extended by previous txns outputs after call
41 */
42 void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins);
43
44 /** Normalize univalue-represented inputs and add them to the transaction */
45 void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, bool rbf);
46
47 /** Normalize univalue-represented outputs */
48 UniValue NormalizeOutputs(const UniValue& outputs_in);
49
50 /** Parse normalized outputs into destination, amount tuples */
51 std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs);
52
53 /** Normalize, parse, and add outputs to the transaction */
54 void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);
55
56 /** Create a transaction from univalue parameters */
57 CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf);
58
59 #endif // LIMENKA_RPC_RAWTRANSACTION_UTIL_H
60