Formatting

This commit is contained in:
Jack Grigg
2018-07-27 09:49:43 +02:00
parent e5dc5228ea
commit 25bb05de23
3 changed files with 32 additions and 38 deletions

View File

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

View File

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

View File

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