| 14 | |
| 15 | namespace node { |
| 16 | PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) |
| 17 | { |
| 18 | // Go through each input and build status |
| 19 | PSBTAnalysis result; |
| 20 | |
| 21 | // Elements things |
| 22 | bool needs_blinded_outputs = false; |
| 23 | bool has_blinded_outputs = false; |
| 24 | |
| 25 | result.inputs.resize(psbtx.inputs.size()); |
| 26 | result.next = PSBTRole::EXTRACTOR; |
| 27 | |
| 28 | const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx); |
| 29 | |
| 30 | for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) { |
| 31 | PSBTInput& input = psbtx.inputs[i]; |
| 32 | PSBTInputAnalysis& input_analysis = result.inputs[i]; |
| 33 | |
| 34 | // We set next role here and ratchet backwards as required |
| 35 | input_analysis.next = PSBTRole::EXTRACTOR; |
| 36 | |
| 37 | // Check for a UTXO |
| 38 | CTxOut utxo; |
| 39 | if (input.GetUTXO(utxo)) { |
| 40 | if (utxo.nValue.IsExplicit()) { |
| 41 | if (!MoneyRange(utxo.nValue.GetAmount())) { |
| 42 | result.SetInvalid(strprintf("PSBT is not valid. Input %u has invalid value", i)); |
| 43 | return result; |
| 44 | } |
| 45 | } else { |
| 46 | needs_blinded_outputs = true; |
| 47 | } |
| 48 | input_analysis.has_utxo = true; |
| 49 | } else { |
| 50 | if (input.non_witness_utxo && *input.prev_out >= input.non_witness_utxo->vout.size()) { |
| 51 | result.SetInvalid(strprintf("PSBT is not valid. Input %u specifies invalid prevout", i)); |
| 52 | return result; |
| 53 | } |
| 54 | input_analysis.has_utxo = false; |
| 55 | input_analysis.is_final = false; |
| 56 | input_analysis.next = PSBTRole::UPDATER; |
| 57 | } |
| 58 | |
| 59 | if (!utxo.IsNull() && utxo.scriptPubKey.IsUnspendable()) { |
| 60 | result.SetInvalid(strprintf("PSBT is not valid. Input %u spends unspendable output", i)); |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | // Check if it is final |
| 65 | if (!utxo.IsNull() && !PSBTInputSigned(input)) { |
| 66 | input_analysis.is_final = false; |
| 67 | |
| 68 | // Figure out what is missing |
| 69 | SignatureData outdata; |
| 70 | bool complete = SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, 1, &outdata); |
| 71 | |
| 72 | // Things are missing |
| 73 | if (!complete) { |