Use ovk directly in the TransactionBuilder API instead of fvk
This commit is contained in:
@@ -38,7 +38,7 @@ TEST(TransactionBuilder, Invoke)
|
||||
// 0.0005 t-ZEC in, 0.0004 z-ZEC out, 0.0001 t-ZEC fee
|
||||
auto builder1 = TransactionBuilder(consensusParams, 1, &keystore);
|
||||
builder1.AddTransparentInput(COutPoint(), scriptPubKey, 50000);
|
||||
builder1.AddSaplingOutput(fvk_from, pk, 40000, {});
|
||||
builder1.AddSaplingOutput(fvk_from.ovk, pk, 40000, {});
|
||||
auto maybe_tx1 = builder1.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx1), true);
|
||||
auto tx1 = maybe_tx1.get();
|
||||
@@ -73,7 +73,7 @@ TEST(TransactionBuilder, Invoke)
|
||||
// Check that trying to add a different anchor fails
|
||||
ASSERT_FALSE(builder2.AddSaplingSpend(expsk, note, uint256(), witness));
|
||||
|
||||
builder2.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder2.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx2 = builder2.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx2), true);
|
||||
auto tx2 = maybe_tx2.get();
|
||||
@@ -153,7 +153,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
|
||||
// Fail if there is only a Sapling output
|
||||
// 0.0005 z-ZEC out, 0.0001 t-ZEC fee
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
builder.AddSaplingOutput(fvk, pk, 50000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 50000, {});
|
||||
EXPECT_FALSE(static_cast<bool>(builder.Build()));
|
||||
|
||||
// Fail if there is only a transparent output
|
||||
@@ -237,7 +237,7 @@ TEST(TransactionBuilder, ChangeOutput)
|
||||
{
|
||||
auto builder = TransactionBuilder(consensusParams, 1, &keystore);
|
||||
builder.AddTransparentInput(COutPoint(), scriptPubKey, 25000);
|
||||
builder.SendChangeTo(zChangeAddr, fvkOut);
|
||||
builder.SendChangeTo(zChangeAddr, fvkOut.ovk);
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -298,7 +298,7 @@ TEST(TransactionBuilder, SetFee)
|
||||
{
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -315,7 +315,7 @@ TEST(TransactionBuilder, SetFee)
|
||||
{
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
builder.SetFee(20000);
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
|
||||
@@ -47,13 +47,13 @@ bool TransactionBuilder::AddSaplingSpend(
|
||||
}
|
||||
|
||||
void TransactionBuilder::AddSaplingOutput(
|
||||
libzcash::SaplingFullViewingKey from,
|
||||
uint256 ovk,
|
||||
libzcash::SaplingPaymentAddress to,
|
||||
CAmount value,
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> memo)
|
||||
{
|
||||
auto note = libzcash::SaplingNote(to, value);
|
||||
outputs.emplace_back(from.ovk, note, memo);
|
||||
outputs.emplace_back(ovk, note, memo);
|
||||
mtx.valueBalance -= value;
|
||||
}
|
||||
|
||||
@@ -84,9 +84,9 @@ void TransactionBuilder::SetFee(CAmount fee)
|
||||
this->fee = fee;
|
||||
}
|
||||
|
||||
void TransactionBuilder::SendChangeTo(libzcash::SaplingPaymentAddress changeAddr, libzcash::SaplingFullViewingKey fvkOut)
|
||||
void TransactionBuilder::SendChangeTo(libzcash::SaplingPaymentAddress changeAddr, uint256 ovk)
|
||||
{
|
||||
zChangeAddr = std::make_pair(fvkOut, changeAddr);
|
||||
zChangeAddr = std::make_pair(ovk, changeAddr);
|
||||
tChangeAddr = boost::none;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
|
||||
auto fvk = spends[0].expsk.full_viewing_key();
|
||||
auto note = spends[0].note;
|
||||
libzcash::SaplingPaymentAddress changeAddr(note.d, note.pk_d);
|
||||
AddSaplingOutput(fvk, changeAddr, change, {});
|
||||
AddSaplingOutput(fvk.ovk, changeAddr, change, {});
|
||||
} else {
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
std::vector<OutputDescriptionInfo> outputs;
|
||||
std::vector<TransparentInputInfo> tIns;
|
||||
|
||||
boost::optional<std::pair<libzcash::SaplingFullViewingKey, libzcash::SaplingPaymentAddress>> zChangeAddr;
|
||||
boost::optional<std::pair<uint256, libzcash::SaplingPaymentAddress>> zChangeAddr;
|
||||
boost::optional<CTxDestination> tChangeAddr;
|
||||
|
||||
public:
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
SaplingWitness witness);
|
||||
|
||||
void AddSaplingOutput(
|
||||
libzcash::SaplingFullViewingKey from,
|
||||
uint256 ovk,
|
||||
libzcash::SaplingPaymentAddress to,
|
||||
CAmount value,
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> memo);
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
|
||||
bool AddTransparentOutput(CTxDestination& to, CAmount value);
|
||||
|
||||
void SendChangeTo(libzcash::SaplingPaymentAddress changeAddr, libzcash::SaplingFullViewingKey fvkOut);
|
||||
void SendChangeTo(libzcash::SaplingPaymentAddress changeAddr, uint256 ovk);
|
||||
|
||||
bool SendChangeTo(CTxDestination& changeAddr);
|
||||
|
||||
|
||||
@@ -380,11 +380,11 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
|
||||
// Get various necessary keys
|
||||
SaplingExpandedSpendingKey expsk;
|
||||
SaplingFullViewingKey from;
|
||||
uint256 ovk;
|
||||
if (isfromzaddr_) {
|
||||
auto sk = boost::get<libzcash::SaplingExtendedSpendingKey>(spendingkey_);
|
||||
expsk = sk.expsk;
|
||||
from = expsk.full_viewing_key();
|
||||
ovk = expsk.full_viewing_key().ovk;
|
||||
} else {
|
||||
// TODO: Set "from" to something!
|
||||
}
|
||||
@@ -450,7 +450,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
|
||||
auto memo = get_memo_from_hex_string(hexMemo);
|
||||
|
||||
builder_.AddSaplingOutput(from, to, value, memo);
|
||||
builder_.AddSaplingOutput(ovk, to, value, memo);
|
||||
}
|
||||
|
||||
// Add transparent outputs
|
||||
|
||||
@@ -384,7 +384,7 @@ TEST(WalletTests, SetSaplingNoteAddrsInCWalletTx) {
|
||||
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 50000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 50000, {});
|
||||
builder.SetFee(0);
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
@@ -504,7 +504,7 @@ TEST(WalletTests, FindMySaplingNotes) {
|
||||
// Generate transaction
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -644,7 +644,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) {
|
||||
// Generate tx to create output note B
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 35000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 35000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -700,7 +700,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) {
|
||||
// Create transaction to spend note B
|
||||
auto builder2 = TransactionBuilder(consensusParams, 2);
|
||||
ASSERT_TRUE(builder2.AddSaplingSpend(expsk, note2, anchor, spend_note_witness));
|
||||
builder2.AddSaplingOutput(fvk, pk, 20000, {});
|
||||
builder2.AddSaplingOutput(fvk.ovk, pk, 20000, {});
|
||||
auto maybe_tx2 = builder2.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx2), true);
|
||||
auto tx2 = maybe_tx2.get();
|
||||
@@ -708,7 +708,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) {
|
||||
// Create conflicting transaction which also spends note B
|
||||
auto builder3 = TransactionBuilder(consensusParams, 2);
|
||||
ASSERT_TRUE(builder3.AddSaplingSpend(expsk, note2, anchor, spend_note_witness));
|
||||
builder3.AddSaplingOutput(fvk, pk, 19999, {});
|
||||
builder3.AddSaplingOutput(fvk.ovk, pk, 19999, {});
|
||||
auto maybe_tx3 = builder3.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx3), true);
|
||||
auto tx3 = maybe_tx3.get();
|
||||
@@ -809,7 +809,7 @@ TEST(WalletTests, SaplingNullifierIsSpent) {
|
||||
// Generate transaction
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -906,7 +906,7 @@ TEST(WalletTests, NavigateFromSaplingNullifierToNote) {
|
||||
// Generate transaction
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -1042,7 +1042,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
|
||||
// Generate transaction, which sends funds to note B
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -1114,7 +1114,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
|
||||
// Create transaction to spend note B
|
||||
auto builder2 = TransactionBuilder(consensusParams, 2);
|
||||
ASSERT_TRUE(builder2.AddSaplingSpend(expsk, note2, anchor, spend_note_witness));
|
||||
builder2.AddSaplingOutput(fvk, pk, 12500, {});
|
||||
builder2.AddSaplingOutput(fvk.ovk, pk, 12500, {});
|
||||
auto maybe_tx2 = builder2.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx2), true);
|
||||
auto tx2 = maybe_tx2.get();
|
||||
@@ -1744,7 +1744,7 @@ TEST(WalletTests, UpdatedSaplingNoteData) {
|
||||
// Generate transaction
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk, pk2, 25000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk2, 25000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx = maybe_tx.get();
|
||||
@@ -1894,7 +1894,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) {
|
||||
// 0.0005 t-ZEC in, 0.0004 z-ZEC out, 0.0001 t-ZEC fee
|
||||
auto builder = TransactionBuilder(consensusParams, 1, &keystore);
|
||||
builder.AddTransparentInput(COutPoint(), scriptPubKey, 50000);
|
||||
builder.AddSaplingOutput(fvk, pk, 40000, {});
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, 40000, {});
|
||||
auto maybe_tx = builder.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||
auto tx1 = maybe_tx.get();
|
||||
@@ -1951,7 +1951,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) {
|
||||
// 0.0004 z-ZEC in, 0.00025 z-ZEC out, 0.0001 t-ZEC fee, 0.00005 z-ZEC change
|
||||
auto builder2 = TransactionBuilder(consensusParams, 2);
|
||||
ASSERT_TRUE(builder2.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder2.AddSaplingOutput(fvk, pk, 25000, {});
|
||||
builder2.AddSaplingOutput(fvk.ovk, pk, 25000, {});
|
||||
auto maybe_tx2 = builder2.Build();
|
||||
ASSERT_EQ(static_cast<bool>(maybe_tx2), true);
|
||||
auto tx2 = maybe_tx2.get();
|
||||
|
||||
Reference in New Issue
Block a user