Make `TransactionBuilder::AddOrchardOutput` memo optional
This replaces the previous use of the `NO_MEMO` constant, instead passing the optionality through to Rust for handling.
This commit is contained in:
parent
2da0856e6f
commit
da755c2ae8
|
@ -278,7 +278,7 @@ TEST(TransactionBuilder, TransparentToOrchard)
|
||||||
// 0.0005 t-ZEC in, 0.0004 z-ZEC out, default fee
|
// 0.0005 t-ZEC in, 0.0004 z-ZEC out, default fee
|
||||||
auto builder = TransactionBuilder(consensusParams, 1, orchardAnchor, &keystore);
|
auto builder = TransactionBuilder(consensusParams, 1, orchardAnchor, &keystore);
|
||||||
builder.AddTransparentInput(COutPoint(uint256S("1234"), 0), scriptPubKey, 50000);
|
builder.AddTransparentInput(COutPoint(uint256S("1234"), 0), scriptPubKey, 50000);
|
||||||
builder.AddOrchardOutput(std::nullopt, recipient, 40000);
|
builder.AddOrchardOutput(std::nullopt, recipient, 40000, std::nullopt);
|
||||||
auto maybeTx = builder.Build();
|
auto maybeTx = builder.Build();
|
||||||
EXPECT_TRUE(maybeTx.IsTx());
|
EXPECT_TRUE(maybeTx.IsTx());
|
||||||
if (maybeTx.IsError()) {
|
if (maybeTx.IsError()) {
|
||||||
|
|
|
@ -35,6 +35,8 @@ void orchard_builder_free(OrchardBuilderPtr* ptr);
|
||||||
///
|
///
|
||||||
/// `ovk` is a pointer to the outgoing viewing key to make this recipient recoverable by,
|
/// `ovk` is a pointer to the outgoing viewing key to make this recipient recoverable by,
|
||||||
/// or `null` to make the recipient unrecoverable by the sender.
|
/// or `null` to make the recipient unrecoverable by the sender.
|
||||||
|
///
|
||||||
|
/// `memo` is a pointer to the 512-byte memo field encoding, or `null` for "no memo".
|
||||||
bool orchard_builder_add_recipient(
|
bool orchard_builder_add_recipient(
|
||||||
OrchardBuilderPtr* ptr,
|
OrchardBuilderPtr* ptr,
|
||||||
const unsigned char* ovk,
|
const unsigned char* ovk,
|
||||||
|
|
|
@ -46,9 +46,9 @@ pub extern "C" fn orchard_builder_add_recipient(
|
||||||
.map(OutgoingViewingKey::from);
|
.map(OutgoingViewingKey::from);
|
||||||
let recipient = unsafe { recipient.as_ref() }.expect("Recipient may not be null.");
|
let recipient = unsafe { recipient.as_ref() }.expect("Recipient may not be null.");
|
||||||
let value = NoteValue::from_raw(value);
|
let value = NoteValue::from_raw(value);
|
||||||
let memo = unsafe { memo.as_ref() }.expect("Memo may not be null.");
|
let memo = unsafe { memo.as_ref() }.copied();
|
||||||
|
|
||||||
match builder.add_recipient(ovk, *recipient, value, Some(*memo)) {
|
match builder.add_recipient(ovk, *recipient, value, memo) {
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to add Orchard recipient: {}", e);
|
error!("Failed to add Orchard recipient: {}", e);
|
||||||
|
|
|
@ -45,7 +45,7 @@ void Builder::AddOutput(
|
||||||
const std::optional<uint256>& ovk,
|
const std::optional<uint256>& ovk,
|
||||||
const libzcash::OrchardRawAddress& to,
|
const libzcash::OrchardRawAddress& to,
|
||||||
CAmount value,
|
CAmount value,
|
||||||
std::array<unsigned char, ZC_MEMO_SIZE> memo)
|
const std::optional<std::array<unsigned char, ZC_MEMO_SIZE>>& memo)
|
||||||
{
|
{
|
||||||
if (!inner) {
|
if (!inner) {
|
||||||
throw std::logic_error("orchard::Builder has already been used");
|
throw std::logic_error("orchard::Builder has already been used");
|
||||||
|
@ -56,7 +56,7 @@ void Builder::AddOutput(
|
||||||
ovk.has_value() ? ovk->begin() : nullptr,
|
ovk.has_value() ? ovk->begin() : nullptr,
|
||||||
to.inner.get(),
|
to.inner.get(),
|
||||||
value,
|
value,
|
||||||
memo.data());
|
memo.has_value() ? memo->data() : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<UnauthorizedBundle> Builder::Build() {
|
std::optional<UnauthorizedBundle> Builder::Build() {
|
||||||
|
@ -264,7 +264,7 @@ void TransactionBuilder::AddOrchardOutput(
|
||||||
const std::optional<uint256>& ovk,
|
const std::optional<uint256>& ovk,
|
||||||
const libzcash::OrchardRawAddress& to,
|
const libzcash::OrchardRawAddress& to,
|
||||||
CAmount value,
|
CAmount value,
|
||||||
std::array<unsigned char, ZC_MEMO_SIZE> memo)
|
const std::optional<std::array<unsigned char, ZC_MEMO_SIZE>>& memo)
|
||||||
{
|
{
|
||||||
if (!orchardBuilder.has_value()) {
|
if (!orchardBuilder.has_value()) {
|
||||||
throw std::runtime_error("TransactionBuilder cannot add Orchard output without Orchard anchor");
|
throw std::runtime_error("TransactionBuilder cannot add Orchard output without Orchard anchor");
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
const std::optional<uint256>& ovk,
|
const std::optional<uint256>& ovk,
|
||||||
const libzcash::OrchardRawAddress& to,
|
const libzcash::OrchardRawAddress& to,
|
||||||
CAmount value,
|
CAmount value,
|
||||||
std::array<unsigned char, ZC_MEMO_SIZE> memo = NO_MEMO);
|
const std::optional<std::array<unsigned char, ZC_MEMO_SIZE>>& memo);
|
||||||
|
|
||||||
/// Builds a bundle containing the given spent notes and recipients.
|
/// Builds a bundle containing the given spent notes and recipients.
|
||||||
///
|
///
|
||||||
|
@ -289,7 +289,7 @@ public:
|
||||||
const std::optional<uint256>& ovk,
|
const std::optional<uint256>& ovk,
|
||||||
const libzcash::OrchardRawAddress& to,
|
const libzcash::OrchardRawAddress& to,
|
||||||
CAmount value,
|
CAmount value,
|
||||||
std::array<unsigned char, ZC_MEMO_SIZE> memo = NO_MEMO);
|
const std::optional<std::array<unsigned char, ZC_MEMO_SIZE>>& memo);
|
||||||
|
|
||||||
// Throws if the anchor does not match the anchor used by
|
// Throws if the anchor does not match the anchor used by
|
||||||
// previously-added Sapling spends.
|
// previously-added Sapling spends.
|
||||||
|
|
Loading…
Reference in New Issue