Browse Source

Formatting

pull/4/head
Jack Grigg 6 years ago
parent
commit
25bb05de23
No known key found for this signature in database GPG Key ID: 1B8D649257DB0829
  1. 8
      src/gtest/test_transaction_builder.cpp
  2. 56
      src/transaction_builder.cpp
  3. 6
      src/transaction_builder.h

8
src/gtest/test_transaction_builder.cpp

@ -5,10 +5,11 @@
#include "transaction_builder.h"
#include "zcash/Address.hpp"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
TEST(TransactionBuilder, Invoke) {
TEST(TransactionBuilder, Invoke)
{
SelectParams(CBaseChainParams::REGTEST);
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
@ -45,8 +46,7 @@ TEST(TransactionBuilder, Invoke) {
// Prepare to spend the note that was just created
auto maybe_pt = libzcash::SaplingNotePlaintext::decrypt(
tx1.vShieldedOutput[0].encCiphertext, ivk, tx1.vShieldedOutput[0].ephemeralKey
);
tx1.vShieldedOutput[0].encCiphertext, ivk, tx1.vShieldedOutput[0].ephemeralKey);
ASSERT_EQ(static_cast<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
ASSERT_EQ(static_cast<bool>(maybe_note), true);

56
src/transaction_builder.cpp

@ -14,15 +14,14 @@ SpendDescriptionInfo::SpendDescriptionInfo(
libzcash::SaplingExpandedSpendingKey xsk,
libzcash::SaplingNote note,
uint256 anchor,
ZCSaplingIncrementalWitness witness
) : xsk(xsk), note(note), anchor(anchor), witness(witness)
ZCSaplingIncrementalWitness witness) : xsk(xsk), note(note), anchor(anchor), witness(witness)
{
librustzcash_sapling_generate_r(alpha.begin());
}
TransactionBuilder::TransactionBuilder(
const Consensus::Params& consensusParams, int nHeight
) : consensusParams(consensusParams), nHeight(nHeight)
const Consensus::Params& consensusParams,
int nHeight) : consensusParams(consensusParams), nHeight(nHeight)
{
mtx = CreateNewContextualCMutableTransaction(consensusParams, nHeight);
}
@ -49,8 +48,8 @@ void TransactionBuilder::AddSaplingOutput(
libzcash::SaplingFullViewingKey from,
libzcash::SaplingPaymentAddress to,
CAmount value,
std::array<unsigned char, ZC_MEMO_SIZE> memo
) {
std::array<unsigned char, ZC_MEMO_SIZE> memo)
{
auto note = libzcash::SaplingNote(to, value);
outputs.emplace_back(from.ovk, note, memo);
mtx.valueBalance -= value;
@ -76,19 +75,18 @@ 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.note.d.data(),
spend.note.r.begin(),
spend.alpha.begin(),
spend.note.value(),
spend.anchor.begin(),
witness.data(),
sdesc.cv.begin(),
sdesc.rk.begin(),
sdesc.zkproof.data()
)) {
ctx,
spend.xsk.full_viewing_key().ak.begin(),
spend.xsk.nsk.begin(),
spend.note.d.data(),
spend.note.r.begin(),
spend.alpha.begin(),
spend.note.value(),
spend.anchor.begin(),
witness.data(),
sdesc.cv.begin(),
sdesc.rk.begin(),
sdesc.zkproof.data())) {
librustzcash_sapling_proving_ctx_free(ctx);
return boost::none;
}
@ -118,15 +116,14 @@ boost::optional<CTransaction> TransactionBuilder::Build()
OutputDescription odesc;
if (!librustzcash_sapling_output_proof(
ctx,
encryptor.get_esk().begin(),
output.note.d.data(),
output.note.pk_d.begin(),
output.note.r.begin(),
output.note.value(),
odesc.cv.begin(),
odesc.zkproof.begin()
)) {
ctx,
encryptor.get_esk().begin(),
output.note.d.data(),
output.note.pk_d.begin(),
output.note.r.begin(),
output.note.value(),
odesc.cv.begin(),
odesc.zkproof.begin())) {
librustzcash_sapling_proving_ctx_free(ctx);
return boost::none;
}
@ -140,8 +137,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
output.ovk,
odesc.cv,
odesc.cm,
encryptor
);
encryptor);
mtx.vShieldedOutput.push_back(odesc);
}

6
src/transaction_builder.h

@ -15,8 +15,7 @@
#include <boost/optional.hpp>
struct SpendDescriptionInfo
{
struct SpendDescriptionInfo {
libzcash::SaplingExpandedSpendingKey xsk;
libzcash::SaplingNote note;
uint256 alpha;
@ -30,8 +29,7 @@ struct SpendDescriptionInfo
ZCSaplingIncrementalWitness witness);
};
struct OutputDescriptionInfo
{
struct OutputDescriptionInfo {
uint256 ovk;
libzcash::SaplingNote note;
std::array<unsigned char, ZC_MEMO_SIZE> memo;

Loading…
Cancel
Save