Change default_address to return SaplingPaymentAddr and not boost::optional

This commit is contained in:
Jay Graber
2018-06-30 12:57:04 -07:00
parent f82a864dc1
commit 8e91ebf76c
8 changed files with 24 additions and 28 deletions

View File

@@ -103,21 +103,16 @@ libzcash::PaymentAddress CWallet::GenerateNewZKey()
// Generate a new Sapling spending key and return its public payment address
SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
{
AssertLockHeld(cs_wallet); // mapZKeyMetadata
AssertLockHeld(cs_wallet); // mapSaplingZKeyMetadata
SaplingSpendingKey sk;
boost::optional<SaplingPaymentAddress> addrOpt;
while (!addrOpt){
sk = SaplingSpendingKey::random();
addrOpt = sk.default_address();
}
auto addr = addrOpt.value();
auto sk = SaplingSpendingKey::random();
auto fvk = sk.full_viewing_key();
auto addr = sk.default_address();
// Check for collision, even though it is unlikely to ever occur
if (CCryptoKeyStore::HaveSaplingSpendingKey(fvk))
throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): Collision detected");
if (CCryptoKeyStore::HaveSaplingSpendingKey(fvk)) {
throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): Collision detected");
}
// Create new metadata
int64_t nCreationTime = GetTime();