| 1202 | |
| 1203 | template <typename Stream> |
| 1204 | inline void Serialize(Stream& s) const { |
| 1205 | // Write the redeem script |
| 1206 | if (!redeem_script.empty()) { |
| 1207 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_REDEEMSCRIPT)); |
| 1208 | s << redeem_script; |
| 1209 | } |
| 1210 | |
| 1211 | // Write the witness script |
| 1212 | if (!witness_script.empty()) { |
| 1213 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_WITNESSSCRIPT)); |
| 1214 | s << witness_script; |
| 1215 | } |
| 1216 | |
| 1217 | // Write any hd keypaths |
| 1218 | SerializeHDKeypaths(s, hd_keypaths, CompactSizeWriter(PSBT_OUT_BIP32_DERIVATION)); |
| 1219 | |
| 1220 | if (m_psbt_version >= 2) { |
| 1221 | // Write amount and spk |
| 1222 | if (amount != std::nullopt) { |
| 1223 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_AMOUNT)); |
| 1224 | SerializeToVector(s, *amount); |
| 1225 | } |
| 1226 | if (script.has_value()) { |
| 1227 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_SCRIPT)); |
| 1228 | s << *script; |
| 1229 | } |
| 1230 | |
| 1231 | // Elements proprietary fields are v2 only |
| 1232 | // Amount |
| 1233 | if (!m_value_commitment.IsNull()) { |
| 1234 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_VALUE_COMMITMENT)); |
| 1235 | SerializeToVector(s, m_value_commitment); |
| 1236 | } |
| 1237 | |
| 1238 | // Asset + commitment |
| 1239 | if (!m_asset.IsNull()) { |
| 1240 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_ASSET)); |
| 1241 | SerializeToVector(s, m_asset); |
| 1242 | } |
| 1243 | if (!m_asset_commitment.IsNull()) { |
| 1244 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_ASSET_COMMITMENT)); |
| 1245 | SerializeToVector(s, m_asset_commitment); |
| 1246 | } |
| 1247 | |
| 1248 | // Value rangeproof |
| 1249 | if (!m_value_rangeproof.empty()) { |
| 1250 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_VALUE_RANGEPROOF)); |
| 1251 | s << m_value_rangeproof; |
| 1252 | } |
| 1253 | |
| 1254 | // Asset surjection proof |
| 1255 | if (!m_asset_surjection_proof.empty()) { |
| 1256 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_ASSET_SURJECTION_PROOF)); |
| 1257 | s << m_asset_surjection_proof; |
| 1258 | } |
| 1259 | |
| 1260 | // Blinding pubkey |
| 1261 | if (m_blinding_pubkey.IsValid()) { |
nothing calls this directly
no test coverage detected