CSerializeRecipientAddress: add Read method and make constructor private.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
This commit is contained in:
therealyingtong 2022-02-18 16:35:48 +08:00
parent 99a69182cd
commit 108e9d4658
2 changed files with 11 additions and 5 deletions

View File

@ -858,10 +858,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
else if (strType == "recipientmapping") else if (strType == "recipientmapping")
{ {
uint256 txid; uint256 txid;
CSerializeRecipientAddress recipient;
std::string rawUa; std::string rawUa;
ssKey >> txid; ssKey >> txid;
ssKey >> recipient; auto recipient = CSerializeRecipientAddress::Read(ssKey);
ssValue >> rawUa; ssValue >> rawUa;
auto ua = libzcash::UnifiedAddress::Parse(Params(), rawUa); auto ua = libzcash::UnifiedAddress::Parse(Params(), rawUa);
@ -875,7 +874,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
[&](const CKeyID& key) { recipientReceiver = key; }, [&](const CKeyID& key) { recipientReceiver = key; },
[&](const CScriptID& scriptId) { recipientReceiver = scriptId; }, [&](const CScriptID& scriptId) { recipientReceiver = scriptId; },
[&](const libzcash::SaplingPaymentAddress& addr) { recipientReceiver = addr; } [&](const libzcash::SaplingPaymentAddress& addr) { recipientReceiver = addr; }
}, recipient.recipient); }, recipient);
bool found = false; bool found = false;
for (const auto& receiver : ua.value().GetReceiversAsParsed()) { for (const auto& receiver : ua.value().GetReceiversAsParsed()) {

View File

@ -318,11 +318,11 @@ public:
// as a pair of typecode and address bytes, similar to how unified address // as a pair of typecode and address bytes, similar to how unified address
// receivers are written (but excluding the unknown receiver case) // receivers are written (but excluding the unknown receiver case)
class CSerializeRecipientAddress { class CSerializeRecipientAddress {
libzcash::RecipientAddress recipient;
libzcash::ReceiverType typecode; libzcash::ReceiverType typecode;
CSerializeRecipientAddress() {} // for serialization only
public: public:
libzcash::RecipientAddress recipient;
CSerializeRecipientAddress() {} // for serialization only
CSerializeRecipientAddress(libzcash::RecipientAddress recipient): recipient(recipient) {} CSerializeRecipientAddress(libzcash::RecipientAddress recipient): recipient(recipient) {}
template<typename Stream> template<typename Stream>
@ -369,6 +369,13 @@ class CSerializeRecipientAddress {
} }
} }
} }
template <typename Stream>
static libzcash::RecipientAddress Read(Stream& stream) {
CSerializeRecipientAddress csr;
stream >> csr;
return csr.recipient;
}
}; };
/** Access to the wallet database */ /** Access to the wallet database */