Return std::optional for GetAnchor

This commit is contained in:
Kris Nuttycombe 2021-06-22 07:34:13 -06:00
parent 437b8c488a
commit fd34ecc64d
2 changed files with 13 additions and 10 deletions

View File

@ -1062,14 +1062,17 @@ std::optional<UnsatisfiedShieldedReq> CCoinsViewCache::HaveShieldedRequirements(
}
}
OrchardMerkleTree tree;
if (!GetOrchardAnchorAt(tx.GetOrchardBundle().GetAnchor(), tree)) {
auto txid = tx.GetHash().ToString();
auto anchor = tx.GetOrchardBundle().GetAnchor().ToString();
TracingWarn("consensus", "Transaction uses unknown Orchard anchor",
"txid", txid.c_str(),
"anchor", anchor.c_str());
return UnsatisfiedShieldedReq::OrchardUnknownAnchor;
std::optional<uint256> root = tx.GetOrchardBundle().GetAnchor();
if (root) {
OrchardMerkleTree tree;
if (!GetOrchardAnchorAt(root.value(), tree)) {
auto txid = tx.GetHash().ToString();
auto anchor = root.value().ToString();
TracingWarn("consensus", "Transaction uses unknown Orchard anchor",
"txid", txid.c_str(),
"anchor", anchor.c_str());
return UnsatisfiedShieldedReq::OrchardUnknownAnchor;
}
}
return std::nullopt;

View File

@ -100,12 +100,12 @@ public:
return result;
}
const uint256 GetAnchor() const {
const std::optional<uint256> GetAnchor() const {
uint256 result;
if (orchard_bundle_anchor(inner.get(), result.begin())) {
return result;
} else {
throw std::runtime_error("cannot obtain Orchard anchor from empty bundle");
return std::nullopt;
}
}
};