Browse Source

Rename xsk to expsk

xsk will be used for ZIP 32 extended spending keys, so renaming here to
reduce confusion.
pull/4/head
Jack Grigg 6 years ago
parent
commit
54a868cf0a
No known key found for this signature in database GPG Key ID: 1B8D649257DB0829
  1. 20
      src/gtest/test_transaction_builder.cpp
  2. 18
      src/transaction_builder.cpp
  3. 6
      src/transaction_builder.h

20
src/gtest/test_transaction_builder.cpp

@ -28,7 +28,7 @@ TEST(TransactionBuilder, Invoke)
auto fvk_from = sk_from.full_viewing_key();
auto sk = libzcash::SaplingSpendingKey::random();
auto xsk = sk.expanded_spending_key();
auto expsk = sk.expanded_spending_key();
auto fvk = sk.full_viewing_key();
auto ivk = fvk.in_viewing_key();
libzcash::diversifier_t d = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@ -69,9 +69,9 @@ TEST(TransactionBuilder, Invoke)
// Create a Sapling-only transaction
// 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(xsk, note, anchor, witness));
ASSERT_TRUE(builder2.AddSaplingSpend(expsk, note, anchor, witness));
// Check that trying to add a different anchor fails
ASSERT_FALSE(builder2.AddSaplingSpend(xsk, note, uint256(), witness));
ASSERT_FALSE(builder2.AddSaplingSpend(expsk, note, uint256(), witness));
builder2.AddSaplingOutput(fvk, pk, 25000, {});
auto maybe_tx2 = builder2.Build();
@ -130,7 +130,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
// Generate dummy Sapling address
auto sk = libzcash::SaplingSpendingKey::random();
auto xsk = sk.expanded_spending_key();
auto expsk = sk.expanded_spending_key();
auto fvk = sk.full_viewing_key();
auto pk = sk.default_address();
@ -164,7 +164,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
// Fails if there is insufficient input
// 0.0005 t-ZEC out, 0.0001 t-ZEC fee, 0.00059999 z-ZEC in
EXPECT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
EXPECT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
EXPECT_FALSE(static_cast<bool>(builder.Build()));
// Succeeds if there is sufficient input
@ -185,7 +185,7 @@ TEST(TransactionBuilder, ChangeOutput)
// Generate dummy Sapling address
auto sk = libzcash::SaplingSpendingKey::random();
auto xsk = sk.expanded_spending_key();
auto expsk = sk.expanded_spending_key();
auto pk = sk.default_address();
// Generate dummy Sapling note
@ -220,7 +220,7 @@ TEST(TransactionBuilder, ChangeOutput)
{
auto builder = TransactionBuilder(consensusParams, 1, &keystore);
builder.AddTransparentInput(COutPoint(), scriptPubKey, 25000);
ASSERT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
auto maybe_tx = builder.Build();
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
auto tx = maybe_tx.get();
@ -282,7 +282,7 @@ TEST(TransactionBuilder, SetFee)
// Generate dummy Sapling address
auto sk = libzcash::SaplingSpendingKey::random();
auto xsk = sk.expanded_spending_key();
auto expsk = sk.expanded_spending_key();
auto fvk = sk.full_viewing_key();
auto pk = sk.default_address();
@ -297,7 +297,7 @@ TEST(TransactionBuilder, SetFee)
// Default fee
{
auto builder = TransactionBuilder(consensusParams, 1);
ASSERT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
builder.AddSaplingOutput(fvk, pk, 25000, {});
auto maybe_tx = builder.Build();
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
@ -314,7 +314,7 @@ TEST(TransactionBuilder, SetFee)
// Configured fee
{
auto builder = TransactionBuilder(consensusParams, 1);
ASSERT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
builder.AddSaplingOutput(fvk, pk, 25000, {});
builder.SetFee(20000);
auto maybe_tx = builder.Build();

18
src/transaction_builder.cpp

@ -12,10 +12,10 @@
#include <librustzcash.h>
SpendDescriptionInfo::SpendDescriptionInfo(
libzcash::SaplingExpandedSpendingKey xsk,
libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note,
uint256 anchor,
ZCSaplingIncrementalWitness witness) : xsk(xsk), note(note), anchor(anchor), witness(witness)
ZCSaplingIncrementalWitness witness) : expsk(expsk), note(note), anchor(anchor), witness(witness)
{
librustzcash_sapling_generate_r(alpha.begin());
}
@ -29,7 +29,7 @@ TransactionBuilder::TransactionBuilder(
}
bool TransactionBuilder::AddSaplingSpend(
libzcash::SaplingExpandedSpendingKey xsk,
libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note,
uint256 anchor,
ZCSaplingIncrementalWitness witness)
@ -41,7 +41,7 @@ bool TransactionBuilder::AddSaplingSpend(
}
}
spends.emplace_back(xsk, note, anchor, witness);
spends.emplace_back(expsk, note, anchor, witness);
mtx.valueBalance += note.value();
return true;
}
@ -131,7 +131,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
// tChangeAddr has already been validated.
assert(AddTransparentOutput(tChangeAddr.value(), change));
} else if (!spends.empty()) {
auto fvk = spends[0].xsk.full_viewing_key();
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, {});
@ -150,7 +150,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
for (auto spend : spends) {
auto cm = spend.note.cm();
auto nf = spend.note.nullifier(
spend.xsk.full_viewing_key(), spend.witness.position());
spend.expsk.full_viewing_key(), spend.witness.position());
if (!(cm && nf)) {
librustzcash_sapling_proving_ctx_free(ctx);
return boost::none;
@ -163,8 +163,8 @@ boost::optional<CTransaction> TransactionBuilder::Build()
SpendDescription sdesc;
if (!librustzcash_sapling_spend_proof(
ctx,
spend.xsk.full_viewing_key().ak.begin(),
spend.xsk.nsk.begin(),
spend.expsk.full_viewing_key().ak.begin(),
spend.expsk.nsk.begin(),
spend.note.d.data(),
spend.note.r.begin(),
spend.alpha.begin(),
@ -247,7 +247,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
// Create Sapling spendAuth and binding signatures
for (size_t i = 0; i < spends.size(); i++) {
librustzcash_sapling_spend_sig(
spends[i].xsk.ask.begin(),
spends[i].expsk.ask.begin(),
spends[i].alpha.begin(),
dataToBeSigned.begin(),
mtx.vShieldedSpend[i].spendAuthSig.data());

6
src/transaction_builder.h

@ -19,14 +19,14 @@
#include <boost/optional.hpp>
struct SpendDescriptionInfo {
libzcash::SaplingExpandedSpendingKey xsk;
libzcash::SaplingExpandedSpendingKey expsk;
libzcash::SaplingNote note;
uint256 alpha;
uint256 anchor;
ZCSaplingIncrementalWitness witness;
SpendDescriptionInfo(
libzcash::SaplingExpandedSpendingKey xsk,
libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note,
uint256 anchor,
ZCSaplingIncrementalWitness witness);
@ -76,7 +76,7 @@ public:
// Returns false if the anchor does not match the anchor used by
// previously-added Sapling spends.
bool AddSaplingSpend(
libzcash::SaplingExpandedSpendingKey xsk,
libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note,
uint256 anchor,
ZCSaplingIncrementalWitness witness);

Loading…
Cancel
Save