12 #include "validation.h"
41 auto encryptor = enc.second;
46 std::vector<unsigned char> addressBytes(ss.
begin(), ss.
end());
51 encryptor.get_esk().begin(),
115 throw std::runtime_error(
"Failed to build transaction: " +
GetError());
128 throw std::runtime_error(
"getError() was called in TransactionBuilderResult, but the result was not initialized as an error.");
135 consensusParams(_consensusParams),
161 throw std::runtime_error(
"TransactionBuilder cannot add Sapling spend to pre-Sapling transaction");
166 throw std::runtime_error(
"Anchor does not match previously-added Sapling spends.");
169 spends.emplace_back(expsk, note, anchor, witness);
177 const std::array<unsigned char, ZC_MEMO_SIZE>& memo)
181 throw std::runtime_error(
"TransactionBuilder cannot add Sapling output to pre-Sapling transaction");
185 outputs.emplace_back(ovk, note, memo);
192 throw std::runtime_error(
"Cannot add transparent inputs to a TransactionBuilder without a keystore");
195 mtx.
vin.emplace_back(utxo);
196 tIns.emplace_back(scriptPubKey, value);
201 std::vector<std::vector<unsigned char> > vSolutions;
204 throw std::runtime_error(
"Transaction builder: invalid script for transparent output");
227 throw std::runtime_error(
"Invalid change address, not a valid taddr.");
246 if (!output.note.cmu()) {
251 auto odesc = output.Build(ctx);
257 mtx.
sapData->vShieldedOutput.push_back(odesc.get());
261 for (
auto spend :
spends) {
262 auto cm = spend.note.cmu();
263 auto nf = spend.note.nullifier(
264 spend.expsk.full_viewing_key(), spend.witness.position());
271 ss << spend.witness.path();
272 std::vector<unsigned char> witness(ss.
begin(), ss.
end());
277 spend.expsk.full_viewing_key().ak.begin(),
278 spend.expsk.nsk.begin(),
280 spend.note.r.begin(),
283 spend.anchor.begin(),
292 sdesc.
anchor = spend.anchor;
306 }
catch (
const std::logic_error& ex) {
312 for (
size_t i = 0; i <
spends.size(); i++) {
314 spends[i].expsk.ask.begin(),
316 dataToBeSigned.
begin(),
317 mtx.
sapData->vShieldedSpend[i].spendAuthSig.data());
323 dataToBeSigned.
begin(),
331 for (
int nIn = 0; nIn < (int)
mtx.
vin.size(); nIn++) {
332 auto tIn =
tIns[nIn];
353 for (
unsigned int i = 0; i <
outputs.size(); i++) {
357 for (
unsigned int i = 0; i <
spends.size(); i++) {
366 for (
int nIn = 0; nIn < (int)
mtx.
vin.size(); nIn++) {
367 auto tIn =
tIns[nIn];
406 for (
auto& tIn :
tIns) {
410 change -= tOut.nValue;
424 if (change > dustThreshold) {
433 }
else if (!
spends.empty()) {
434 auto fvk =
spends[0].expsk.full_viewing_key();
435 auto note =
spends[0].note;
int64_t CAmount
Amount in PIV (Can be negative)
const_iterator end() const
const_iterator begin() const
A virtual base class for key stores.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
An output of a transaction.
A signature creator that just produces 72-byte empty signatyres.
A shielded output to a transaction.
uint256 cmu
The u-coordinate of the note commitment for the output note.
libzcash::SaplingOutCiphertext outCiphertext
A ciphertext component for the encrypted output note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the output circuit.
libzcash::SaplingEncCiphertext encCiphertext
A ciphertext component for the encrypted output note.
uint256 cv
A value commitment to the value of the output note.
uint256 ephemeralKey
A Jubjub public key.
std::array< unsigned char, BINDINGSIG_SIZE > binding_sig_t
A shielded input to a transaction.
spend_auth_sig_t spendAuthSig
A signature authorizing this spend.
uint256 cv
A value commitment to the value of the input note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the spend circuit.
uint256 anchor
A Merkle root of the Sapling note commitment tree at some block height in the past.
uint256 rk
The randomized public key for spendAuthSig.
uint256 nullifier
The nullifier of the input note.
std::vector< OutputDescriptionInfo > outputs
void AddTransparentOutput(const CTxOut &out)
void SetFee(CAmount _fee)
std::vector< TransparentInputInfo > tIns
void AddSaplingSpend(const libzcash::SaplingExpandedSpendingKey &expsk, const libzcash::SaplingNote ¬e, const uint256 &anchor, const SaplingWitness &witness)
TransactionBuilderResult AddDummySignatures()
TransactionBuilderResult Build(bool fDummySig=false)
void ClearProofsAndSignatures()
void AddSaplingOutput(const uint256 &ovk, const libzcash::SaplingPaymentAddress &to, CAmount value, const std::array< unsigned char, ZC_MEMO_SIZE > &memo)
TransactionBuilderResult ProveAndSign()
const CKeyStore * keystore
std::vector< SpendDescriptionInfo > spends
void AddTransparentInput(const COutPoint &utxo, const CScript &scriptPubKey, CAmount value)
TransactionBuilder(const Consensus::Params &consensusParams, CKeyStore *keyStore=nullptr)
void SendChangeTo(const libzcash::SaplingPaymentAddress &changeAddr, const uint256 &ovk)
Optional< CTxDestination > tChangeAddr
Optional< std::pair< uint256, libzcash::SaplingPaymentAddress > > saplingChangeAddr
TransactionBuilderResult()=delete
Optional< CTransaction > GetTx()
Optional< CTransaction > maybeTx
Optional< std::string > maybeError
CTransaction GetTxOrThrow()
A signature creator for transactions.
Optional< uint256 > cmu() const
Optional< SaplingNotePlaintextEncryptionResult > encrypt(const uint256 &pk_d) const
SaplingOutCiphertext encrypt(const uint256 &ovk, const uint256 &cv, const uint256 &cm, SaplingNoteEncryption &enc) const
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
const unsigned int NOT_AN_INPUT
Special case nIn for signing Sapling txs.
bool librustzcash_sapling_binding_sig(const void *ctx, int64_t valueBalance, const unsigned char *sighash, unsigned char *result)
This function (using the proving context) constructs a binding signature.
bool librustzcash_sapling_spend_sig(const unsigned char *ask, const unsigned char *ar, const unsigned char *sighash, unsigned char *result)
Computes the signature for each Spend description, given the key ask, the re-randomization ar,...
bool librustzcash_sapling_output_proof(void *ctx, const unsigned char *esk, const unsigned char *payment_address, const unsigned char *rcm, const uint64_t value, unsigned char *cv, unsigned char *zkproof)
This function (using the proving context) constructs an Output proof given the necessary witness info...
void librustzcash_sapling_proving_ctx_free(void *)
Frees a Sapling proving context returned from librustzcash_sapling_proving_ctx_init.
bool librustzcash_sapling_spend_proof(void *ctx, const unsigned char *ak, const unsigned char *nsk, const unsigned char *diversifier, const unsigned char *rcm, const unsigned char *ar, const uint64_t value, const unsigned char *anchor, const unsigned char *witness, unsigned char *cv, unsigned char *rk, unsigned char *zkproof)
This function (using the proving context) constructs a Spend proof given the necessary witness inform...
void librustzcash_sapling_generate_r(unsigned char *result)
Generate uniformly random scalar in Jubjub.
void * librustzcash_sapling_proving_ctx_init()
Creates a Sapling proving context. Please free this when you're done.
bool IsValidDestination(const CWDestination &address)
boost::optional< T > Optional
Substitute for C++17 std::optional.
CAmount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
CAmount GetShieldedDustThreshold(const CFeeRate &dustRelayFeeIn)
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata, SigVersion sigversion, bool fColdStake, ScriptError *serror)
Produce a script signature using a generic signature creator.
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
A mutable version of CTransaction.
Optional< SaplingTxData > sapData
std::vector< CTxOut > vout
Parameters that influence chain consensus.
std::array< unsigned char, ZC_MEMO_SIZE > memo
Optional< OutputDescription > Build(void *ctx)
libzcash::SaplingNote note
SpendDescriptionInfo(const libzcash::SaplingExpandedSpendingKey &_expsk, const libzcash::SaplingNote &_note, const uint256 &_anchor, const SaplingWitness &_witness)
bool error(const char *fmt, const Args &... args)
const SaplingTxData::binding_sig_t DUMMY_SHIELD_BINDSIG
const SpendDescription DUMMY_SHIELD_SPEND
const OutputDescription DUMMY_SHIELD_OUT
const uint256 UINT256_MAX