| 983 | |
| 984 | template <typename Stream> |
| 985 | inline void Serialize(Stream& s) const { |
| 986 | // Write the redeem script |
| 987 | if (!redeem_script.empty()) { |
| 988 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_REDEEMSCRIPT)); |
| 989 | s << redeem_script; |
| 990 | } |
| 991 | |
| 992 | // Write the witness script |
| 993 | if (!witness_script.empty()) { |
| 994 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_WITNESSSCRIPT)); |
| 995 | s << witness_script; |
| 996 | } |
| 997 | |
| 998 | // Write any hd keypaths |
| 999 | SerializeHDKeypaths(s, hd_keypaths, CompactSizeWriter(PSBT_OUT_BIP32_DERIVATION)); |
| 1000 | |
| 1001 | if (m_psbt_version >= 2) { |
| 1002 | // Write amount and spk |
| 1003 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_AMOUNT)); |
| 1004 | SerializeToVector(s, amount); |
| 1005 | |
| 1006 | SerializeToVector(s, CompactSizeWriter(PSBT_OUT_SCRIPT)); |
| 1007 | s << script; |
| 1008 | } |
| 1009 | |
| 1010 | // Write proprietary things |
| 1011 | for (const auto& entry : m_proprietary) { |
| 1012 | s << entry.key; |
| 1013 | s << entry.value; |
| 1014 | } |
| 1015 | |
| 1016 | // Write taproot internal key |
| 1017 | if (!m_tap_internal_key.IsNull()) { |
| 1018 | SerializeToVector(s, PSBT_OUT_TAP_INTERNAL_KEY); |
| 1019 | s << ToByteVector(m_tap_internal_key); |
| 1020 | } |
| 1021 | |
| 1022 | // Write taproot tree |
| 1023 | if (!m_tap_tree.empty()) { |
| 1024 | SerializeToVector(s, PSBT_OUT_TAP_TREE); |
| 1025 | std::vector<unsigned char> value; |
| 1026 | VectorWriter s_value{value, 0}; |
| 1027 | for (const auto& [depth, leaf_ver, script] : m_tap_tree) { |
| 1028 | s_value << depth; |
| 1029 | s_value << leaf_ver; |
| 1030 | s_value << script; |
| 1031 | } |
| 1032 | s << value; |
| 1033 | } |
| 1034 | |
| 1035 | // Write taproot bip32 keypaths |
| 1036 | for (const auto& [xonly, leaf] : m_tap_bip32_paths) { |
| 1037 | const auto& [leaf_hashes, origin] = leaf; |
| 1038 | SerializeToVector(s, PSBT_OUT_TAP_BIP32_DERIVATION, xonly); |
| 1039 | std::vector<unsigned char> value; |
| 1040 | VectorWriter s_value{value, 0}; |
| 1041 | s_value << leaf_hashes; |
| 1042 | SerializeKeyOrigin(s_value, origin); |
nothing calls this directly
no test coverage detected