ELEMENTS: split FillPSBT into FillPSBData and SignPSBT
| 1892 | |
| 1893 | // ELEMENTS: split FillPSBT into FillPSBData and SignPSBT |
| 1894 | TransactionError CWallet::FillPSBTData(PartiallySignedTransaction& psbtx, bool bip32derivs, bool include_explicit) const |
| 1895 | { |
| 1896 | const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx); |
| 1897 | LOCK(cs_wallet); |
| 1898 | |
| 1899 | // Get all of the previous transactions |
| 1900 | for (PSBTInput& input : psbtx.inputs) { |
| 1901 | if (PSBTInputSigned(input)) { |
| 1902 | continue; |
| 1903 | } |
| 1904 | |
| 1905 | // If we have no utxo, grab it from the wallet. |
| 1906 | if (!input.non_witness_utxo) { |
| 1907 | const uint256& txhash = input.prev_txid; |
| 1908 | const auto it = mapWallet.find(txhash); |
| 1909 | if (it != mapWallet.end()) { |
| 1910 | const CWalletTx& wtx = it->second; |
| 1911 | // We only need the non_witness_utxo, which is a superset of the witness_utxo. |
| 1912 | // The signing code will switch to the smaller witness_utxo if this is ok. |
| 1913 | input.non_witness_utxo = wtx.tx; |
| 1914 | // Set the UTXO rangeproof separately, if it's there |
| 1915 | if (*input.prev_out < wtx.tx->witness.vtxoutwit.size() && !wtx.tx->witness.vtxoutwit[*input.prev_out].vchRangeproof.empty()) { |
| 1916 | input.m_utxo_rangeproof = wtx.tx->witness.vtxoutwit[*input.prev_out].vchRangeproof; |
| 1917 | } |
| 1918 | const CTxOut& utxo = wtx.tx->vout[*input.prev_out]; |
| 1919 | if (include_explicit && utxo.nAsset.IsCommitment()) { |
| 1920 | const CAsset asset = wtx.GetOutputAsset(*this, *input.prev_out); |
| 1921 | input.m_explicit_asset = asset.id; |
| 1922 | CreateBlindAssetProof(input.m_asset_proof, asset, utxo.nAsset, wtx.GetOutputAssetBlindingFactor(*this, *input.prev_out)); |
| 1923 | |
| 1924 | if (utxo.nValue.IsCommitment()) { |
| 1925 | input.m_explicit_value = wtx.GetOutputValueOut(*this, *input.prev_out); |
| 1926 | CreateBlindValueProof(input.m_value_proof, wtx.GetOutputAmountBlindingFactor(*this, *input.prev_out), *input.m_explicit_value, utxo.nValue, utxo.nAsset); |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | // Fill in information from ScriptPubKeyMans |
| 1934 | // Because each ScriptPubKeyMan may be able to fill more than one input, we need to keep track of each ScriptPubKeyMan that has filled this psbt. |
| 1935 | // Each iteration, we may fill more inputs than the input that is specified in that iteration. |
| 1936 | // We assume that each input is filled by only one ScriptPubKeyMan |
| 1937 | std::set<uint256> visited_spk_mans; |
| 1938 | for (PSBTInput& input : psbtx.inputs) { |
| 1939 | if (PSBTInputSigned(input)) { |
| 1940 | continue; |
| 1941 | } |
| 1942 | |
| 1943 | // Get the scriptPubKey to know which ScriptPubKeyMan to use |
| 1944 | CScript script; |
| 1945 | if (!input.witness_utxo.IsNull()) { |
| 1946 | script = input.witness_utxo.scriptPubKey; |
| 1947 | } else if (input.non_witness_utxo) { |
| 1948 | if (*input.prev_out >= input.non_witness_utxo->vout.size()) { |
| 1949 | return TransactionError::MISSING_INPUTS; |
| 1950 | } |
| 1951 | script = input.non_witness_utxo->vout[*input.prev_out].scriptPubKey; |