Changeset View
Changeset View
Standalone View
Standalone View
src/script/sign.h
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | template <typename Stream> inline void Unserialize(Stream &s) { | ||||
uint8_t type = key[0]; | uint8_t type = key[0]; | ||||
// Do stuff based on type | // Do stuff based on type | ||||
switch (type) { | switch (type) { | ||||
case PSBT_IN_UTXO: | case PSBT_IN_UTXO: | ||||
if (!utxo.IsNull()) { | if (!utxo.IsNull()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"Duplicate Key, input utxo already provided"); | "Duplicate Key, input utxo already provided"); | ||||
} else if (key.size() != 1) { | |||||
throw std::ios_base::failure( | |||||
"utxo key is more than one byte type"); | |||||
} | } | ||||
UnserializeFromVector(s, utxo); | UnserializeFromVector(s, utxo); | ||||
break; | break; | ||||
case PSBT_IN_PARTIAL_SIG: { | case PSBT_IN_PARTIAL_SIG: { | ||||
// Make sure that the key is the size of pubkey + 1 | // Make sure that the key is the size of pubkey + 1 | ||||
if (key.size() != CPubKey::PUBLIC_KEY_SIZE + 1 && | if (key.size() != CPubKey::PUBLIC_KEY_SIZE + 1 && | ||||
key.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1) { | key.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
Show All 20 Lines | template <typename Stream> inline void Unserialize(Stream &s) { | ||||
SigPair(pubkey, std::move(sig))); | SigPair(pubkey, std::move(sig))); | ||||
break; | break; | ||||
} | } | ||||
case PSBT_IN_SIGHASH: | case PSBT_IN_SIGHASH: | ||||
if (sighash_type.getRawSigHashType() != 0) { | if (sighash_type.getRawSigHashType() != 0) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"Duplicate Key, input sighash type already " | "Duplicate Key, input sighash type already " | ||||
"provided"); | "provided"); | ||||
} else if (key.size() != 1) { | |||||
throw std::ios_base::failure( | |||||
"Sighash type key is more than one byte type"); | |||||
} | } | ||||
UnserializeFromVector(s, sighash_type); | UnserializeFromVector(s, sighash_type); | ||||
break; | break; | ||||
case PSBT_IN_REDEEMSCRIPT: { | case PSBT_IN_REDEEMSCRIPT: { | ||||
if (!redeem_script.empty()) { | if (!redeem_script.empty()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"Duplicate Key, input redeemScript already " | "Duplicate Key, input redeemScript already " | ||||
"provided"); | "provided"); | ||||
} else if (key.size() != 1) { | |||||
throw std::ios_base::failure( | |||||
"Input redeemScript key is more than one byte " | |||||
"type"); | |||||
} | } | ||||
s >> redeem_script; | s >> redeem_script; | ||||
break; | break; | ||||
} | } | ||||
case PSBT_IN_BIP32_DERIVATION: { | case PSBT_IN_BIP32_DERIVATION: { | ||||
DeserializeHDKeypaths(s, key, hd_keypaths); | DeserializeHDKeypaths(s, key, hd_keypaths); | ||||
break; | break; | ||||
} | } | ||||
case PSBT_IN_SCRIPTSIG: { | case PSBT_IN_SCRIPTSIG: { | ||||
if (!final_script_sig.empty()) { | if (!final_script_sig.empty()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"Duplicate Key, input final scriptSig already " | "Duplicate Key, input final scriptSig already " | ||||
"provided"); | "provided"); | ||||
} else if (key.size() != 1) { | |||||
throw std::ios_base::failure( | |||||
"Final scriptSig key is more than one byte type"); | |||||
} | } | ||||
s >> final_script_sig; | s >> final_script_sig; | ||||
break; | break; | ||||
} | } | ||||
// Unknown stuff | // Unknown stuff | ||||
default: | default: | ||||
if (unknown.count(key) > 0) { | if (unknown.count(key) > 0) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | template <typename Stream> inline void Unserialize(Stream &s) { | ||||
// Do stuff based on type | // Do stuff based on type | ||||
switch (type) { | switch (type) { | ||||
case PSBT_OUT_REDEEMSCRIPT: { | case PSBT_OUT_REDEEMSCRIPT: { | ||||
if (!redeem_script.empty()) { | if (!redeem_script.empty()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"Duplicate Key, output redeemScript already " | "Duplicate Key, output redeemScript already " | ||||
"provided"); | "provided"); | ||||
} else if (key.size() != 1) { | |||||
throw std::ios_base::failure( | |||||
"Output redeemScript key is more than one byte " | |||||
"type"); | |||||
} | } | ||||
s >> redeem_script; | s >> redeem_script; | ||||
break; | break; | ||||
} | } | ||||
case PSBT_OUT_BIP32_DERIVATION: { | case PSBT_OUT_BIP32_DERIVATION: { | ||||
DeserializeHDKeypaths(s, key, hd_keypaths); | DeserializeHDKeypaths(s, key, hd_keypaths); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | template <typename Stream> inline void Unserialize(Stream &s) { | ||||
uint8_t type = key[0]; | uint8_t type = key[0]; | ||||
// Do stuff based on type | // Do stuff based on type | ||||
switch (type) { | switch (type) { | ||||
case PSBT_GLOBAL_UNSIGNED_TX: { | case PSBT_GLOBAL_UNSIGNED_TX: { | ||||
if (tx) { | if (tx) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"Duplicate Key, unsigned tx already provided"); | "Duplicate Key, unsigned tx already provided"); | ||||
} else if (key.size() != 1) { | |||||
throw std::ios_base::failure( | |||||
"Global unsigned tx key is more than one byte " | |||||
"type"); | |||||
} | } | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
UnserializeFromVector(s, mtx); | UnserializeFromVector(s, mtx); | ||||
tx = std::move(mtx); | tx = std::move(mtx); | ||||
// Make sure that all scriptSigs are empty. | // Make sure that all scriptSigs are empty. | ||||
for (const CTxIn &txin : tx->vin) { | for (const CTxIn &txin : tx->vin) { | ||||
if (!txin.scriptSig.empty()) { | if (!txin.scriptSig.empty()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |