TransactionBuilder: Add support for transparent inputs and outputs

This commit is contained in:
Jack Grigg
2018-07-30 11:03:29 +01:00
parent 3fd0a269e1
commit 3466b4677e
3 changed files with 184 additions and 11 deletions

View File

@@ -6,7 +6,10 @@
#define TRANSACTION_BUILDER_H
#include "consensus/params.h"
#include "keystore.h"
#include "primitives/transaction.h"
#include "script/script.h"
#include "script/standard.h"
#include "uint256.h"
#include "zcash/Address.hpp"
#include "zcash/IncrementalMerkleTree.hpp"
@@ -40,18 +43,29 @@ struct OutputDescriptionInfo {
std::array<unsigned char, ZC_MEMO_SIZE> memo) : ovk(ovk), note(note), memo(memo) {}
};
struct TransparentInputInfo {
CScript scriptPubKey;
CAmount value;
TransparentInputInfo(
CScript scriptPubKey,
CAmount value) : scriptPubKey(scriptPubKey), value(value) {}
};
class TransactionBuilder
{
private:
Consensus::Params consensusParams;
int nHeight;
const CKeyStore* keystore;
CMutableTransaction mtx;
std::vector<SpendDescriptionInfo> spends;
std::vector<OutputDescriptionInfo> outputs;
std::vector<TransparentInputInfo> tIns;
public:
TransactionBuilder(const Consensus::Params& consensusParams, int nHeight);
TransactionBuilder(const Consensus::Params& consensusParams, int nHeight, CKeyStore* keyStore = nullptr);
// Returns false if the anchor does not match the anchor used by
// previously-added Sapling spends.
@@ -67,6 +81,11 @@ public:
CAmount value,
std::array<unsigned char, ZC_MEMO_SIZE> memo);
// Assumes that the value correctly corresponds to the provided UTXO.
void AddTransparentInput(COutPoint utxo, CScript scriptPubKey, CAmount value);
bool AddTransparentOutput(CTxDestination& to, CAmount value);
boost::optional<CTransaction> Build();
};