Changeset View
Changeset View
Standalone View
Standalone View
src/script/sign.h
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00; | static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00; | ||||
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02; | static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02; | ||||
// The separator is 0x00. Reading this in means that the unserializer can | // The separator is 0x00. Reading this in means that the unserializer can | ||||
// interpret it as a 0 length key which indicates that this is the separator. | // interpret it as a 0 length key which indicates that this is the separator. | ||||
// The separator has no value. | // The separator has no value. | ||||
static constexpr uint8_t PSBT_SEPARATOR = 0x00; | static constexpr uint8_t PSBT_SEPARATOR = 0x00; | ||||
// Takes a stream and multiple arguments and serializes them into a vector and | // Takes a stream and multiple arguments and serializes them as if first | ||||
// then into the stream. The resulting output into the stream has the total | // serialized into a vector and then into the stream. The resulting output into | ||||
// serialized length of all of the objects followed by all objects concatenated | // the stream has the total serialized length of all of the objects followed by | ||||
// with each other. | // all objects concatenated with each other. | ||||
template <typename Stream, typename... X> | template <typename Stream, typename... X> | ||||
void SerializeToVector(Stream &s, const X &... args) { | void SerializeToVector(Stream &s, const X &... args) { | ||||
std::vector<uint8_t> ret; | WriteCompactSize(s, GetSerializeSizeMany(s, args...)); | ||||
CVectorWriter ss(SER_NETWORK, PROTOCOL_VERSION, ret, 0); | SerializeMany(s, args...); | ||||
SerializeMany(ss, args...); | |||||
s << ret; | |||||
} | } | ||||
// Takes a stream and multiple arguments and unserializes them first as a vector | // Takes a stream and multiple arguments and unserializes them first as a vector | ||||
// then each object individually in the order provided in the arguments | // then each object individually in the order provided in the arguments. | ||||
template <typename Stream, typename... X> | template <typename Stream, typename... X> | ||||
void UnserializeFromVector(Stream &s, X &... args) { | void UnserializeFromVector(Stream &s, X &... args) { | ||||
std::vector<uint8_t> data; | size_t expected_size = ReadCompactSize(s); | ||||
s >> data; | size_t remaining_before = s.size(); | ||||
CDataStream ss(data, SER_NETWORK, PROTOCOL_VERSION); | UnserializeMany(s, args...); | ||||
UnserializeMany(ss, args...); | size_t remaining_after = s.size(); | ||||
if (!ss.eof()) { | if (remaining_after + expected_size != remaining_before) { | ||||
throw std::ios_base::failure("Size of value was not the stated size"); | throw std::ios_base::failure("Size of value was not the stated size"); | ||||
} | } | ||||
} | } | ||||
// Deserialize HD keypaths into a map | // Deserialize HD keypaths into a map | ||||
template <typename Stream> | template <typename Stream> | ||||
void DeserializeHDKeypaths(Stream &s, const std::vector<uint8_t> &key, | void DeserializeHDKeypaths(Stream &s, const std::vector<uint8_t> &key, | ||||
std::map<CPubKey, KeyOriginInfo> &hd_keypaths) { | std::map<CPubKey, KeyOriginInfo> &hd_keypaths) { | ||||
▲ Show 20 Lines • Show All 514 Lines • Show Last 20 Lines |