MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / Unserialize

Method Unserialize

src/script/sign.h:471–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469
470 template <typename Stream>
471 inline void Unserialize(Stream& s) {
472 // Read loop
473 bool found_sep = false;
474 while(!s.empty()) {
475 // Read
476 std::vector<unsigned char> key;
477 s >> key;
478
479 // the key is empty if that was actually a separator byte
480 // This is a special case for key lengths 0 as those are not allowed (except for separator)
481 if (key.empty()) {
482 found_sep = true;
483 break;
484 }
485
486 // First byte of key is the type
487 unsigned char type = key[0];
488
489 // Do stuff based on type
490 switch(type) {
491 case PSBT_OUT_REDEEMSCRIPT:
492 {
493 if (!redeem_script.empty()) {
494 throw std::ios_base::failure("Duplicate Key, output redeemScript already provided");
495 } else if (key.size() != 1) {
496 throw std::ios_base::failure("Output redeemScript key is more than one byte type");
497 }
498 s >> redeem_script;
499 break;
500 }
501 case PSBT_OUT_WITNESSSCRIPT:
502 {
503 if (!witness_script.empty()) {
504 throw std::ios_base::failure("Duplicate Key, output witnessScript already provided");
505 } else if (key.size() != 1) {
506 throw std::ios_base::failure("Output witnessScript key is more than one byte type");
507 }
508 s >> witness_script;
509 break;
510 }
511 case PSBT_OUT_BIP32_DERIVATION:
512 {
513 DeserializeHDKeypaths(s, key, hd_keypaths);
514 break;
515 }
516 // Unknown stuff
517 default: {
518 if (unknown.count(key) > 0) {
519 throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
520 }
521 // Read in the value
522 std::vector<unsigned char> val_bytes;
523 s >> val_bytes;
524 unknown.emplace(std::move(key), std::move(val_bytes));
525 break;
526 }
527 }
528 }

Callers

nothing calls this directly

Calls 4

DeserializeHDKeypathsFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected