diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 80838d1f95..51d1f61955 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -698,7 +698,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) continue; } const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey; - const CTxOutValue& amount = coins->vout[txin.prevout.n].nValue; + const CConfidentialValue& amount = coins->vout[txin.prevout.n].nValue; SignatureData sigdata; // Only sign SIGHASH_SINGLE if there's a corresponding output: diff --git a/src/blind.cpp b/src/blind.cpp index 250c8f2f81..fb5f712bec 100644 --- a/src/blind.cpp +++ b/src/blind.cpp @@ -158,8 +158,8 @@ int BlindOutputs(std::vector& input_blinding_factors, const std::vecto for (size_t nOut = 0; nOut < tx.vout.size(); nOut++) { CTxOut& out = tx.vout[nOut]; if (out.nValue.IsExplicit() && output_pubkeys[nOut].IsFullyValid()) { - CTxOutValue& value = out.nValue; - CTxOutAsset& asset = out.nAsset; + CConfidentialAsset& asset = out.nAsset; + CConfidentialValue& value = out.nValue; CAmount amount = value.GetAmount(); assetID = out.nAsset.GetAsset(); blindedAmounts.push_back(value.GetAmount()); @@ -207,7 +207,7 @@ int BlindOutputs(std::vector& input_blinding_factors, const std::vecto assert(ret != 0); // Create value commitment - value.vchCommitment.resize(CTxOutValue::nCommittedSize); + value.vchCommitment.resize(CConfidentialValue::nCommittedSize); ret = secp256k1_pedersen_commit(secp256k1_blind_context, &commit, (unsigned char*)blindptrs.back(), amount, &gen); assert(ret != 0); secp256k1_pedersen_commitment_serialize(secp256k1_blind_context, &value.vchCommitment[0], &commit); diff --git a/src/coins.cpp b/src/coins.cpp index 282dd1a5f6..f7246c1194 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -352,7 +352,7 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, CAmount assert(coins); if (!coins->IsAvailable(txin.prevout.n)) continue; if (coins->nHeight <= nHeight) { - const CTxOutValue& val = coins->vout[txin.prevout.n].nValue; + const CConfidentialValue& val = coins->vout[txin.prevout.n].nValue; CAmount nAmount = COIN; if (val.IsExplicit()) nAmount = val.GetAmount(); diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 7202795847..a2de1481a7 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -9,59 +9,21 @@ #include "tinyformat.h" #include "utilstrencodings.h" -void CTxOutAsset::SetNull() +void CConfidentialAsset::SetToAsset(const CAsset& asset) { - vchCommitment.clear(); -} - -void CTxOutAsset::SetToAsset(const CAsset& asset) -{ - vchCommitment.reserve(nCommittedSize); + vchCommitment.reserve(nExplicitSize); vchCommitment.push_back(1); vchCommitment.insert(vchCommitment.end(), asset.begin(), asset.end()); } -CTxOutValue::CTxOutValue(CAmount nAmountIn) +void CConfidentialValue::SetToAmount(const CAmount amount) { - vchCommitment.resize(nExplicitSize); - SetToAmount(nAmountIn); -} - -void CTxOutValue::SetNull() -{ - vchCommitment.clear(); -} - -bool CTxOutValue::IsValid() const -{ - switch(vchCommitment[0]) { - case 1: - if (vchCommitment.size() != nExplicitSize) - return false; - return true; - case 8: - case 9: - if (vchCommitment.size() != nCommittedSize) - return false; - return true; - default: - return false; - } -} - -CAmount CTxOutValue::GetAmount() const -{ - assert(IsExplicit()); - return ReadBE64(&vchCommitment[1]); -} - -void CTxOutValue::SetToAmount(const CAmount nAmount) { vchCommitment.resize(nExplicitSize); vchCommitment[0] = 1; - WriteBE64(&vchCommitment[1], nAmount); + WriteBE64(&vchCommitment[1], amount); } -CTxOut::CTxOut(const CTxOutAsset& nAssetIn, const CTxOutValue& nValueIn, CScript scriptPubKeyIn) +CTxOut::CTxOut(const CConfidentialAsset& nAssetIn, const CConfidentialValue& nValueIn, CScript scriptPubKeyIn) { nAsset = nAssetIn; nValue = nValueIn; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index e5f05ca160..af395032e4 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -17,100 +17,19 @@ static const int WITNESS_SCALE_FACTOR = 4; static const CFeeRate withdrawLockTxFee = CFeeRate(5460); -class CTxOutAsset +/** + * Confidential assets, values, and nonces all share enough code in common + * that it makes sense to define a common abstract base class. */ +template +class CConfidentialCommitment { public: + static const size_t nExplicitSize = ExplicitSize; static const size_t nCommittedSize = 33; std::vector vchCommitment; - CTxOutAsset() - { - vchCommitment.reserve(nCommittedSize); - SetNull(); - } - - CTxOutAsset(const CAsset& asset) - { - SetToAsset(asset); - } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) { - unsigned char version = vchCommitment.empty()? 0: vchCommitment[0]; - READWRITE(version); - if (ser_action.ForRead()) { - switch (version) { - /* Null */ - case 0: - vchCommitment.clear(); - return; - /* Explicit asset */ - case 1: - /* Trust-me! asset generation */ - case 0xff: - /* Confidential asset */ - case 10: - case 11: - vchCommitment.resize(nCommittedSize); - break; - default: - throw std::ios_base::failure("Unrecognized serialization prefix"); - } - vchCommitment[0] = version; - } - if (vchCommitment.size() > 1) - READWRITE(REF(CFlatData(&vchCommitment[1], &vchCommitment[vchCommitment.size()]))); - } - - bool IsNull() const - { - return vchCommitment.empty(); - } - - void SetNull(); - - bool IsExplicit() const - { - return vchCommitment.size()==nCommittedSize && vchCommitment[0]==1; - } - const CAsset& GetAsset() const - { - assert(IsExplicit()); - return *reinterpret_cast(&vchCommitment[1]); - } - - bool IsCommitment() const - { - return vchCommitment.size()==nCommittedSize && (vchCommitment[0]==10 || vchCommitment[0]==11); - } - - friend bool operator==(const CTxOutAsset& a, const CTxOutAsset& b) - { - return a.vchCommitment == b.vchCommitment; - } - - friend bool operator!=(const CTxOutAsset& a, const CTxOutAsset& b) - { - return !(a == b); - } - -private: - void SetToAsset(const CAsset& asset); -}; - -class CTxOutValue -{ -public: - static const size_t nExplicitSize = 9; - static const size_t nCommittedSize = 33; - - std::vector vchCommitment; - - CTxOutValue() { SetNull(); } - CTxOutValue(CAmount); + CConfidentialCommitment() { SetNull(); } ADD_SERIALIZE_METHODS; @@ -126,13 +45,16 @@ public: return; /* Explicit value */ case 1: + /* Trust-me! asset generation */ + case 0xff: vchCommitment.resize(nExplicitSize); break; - /* Committed value */ - case 8: - case 9: + /* Confidential commitment */ + case PrefixA: + case PrefixB: vchCommitment.resize(nCommittedSize); break; + /* Invalid serialization! */ default: throw std::ios_base::failure("Unrecognized serialization prefix"); } @@ -140,30 +62,75 @@ public: } if (vchCommitment.size() > 1) READWRITE(REF(CFlatData(&vchCommitment[1], &vchCommitment[vchCommitment.size()]))); - // We only serialize the value commitment here. - // The ECDH key is serialized through CTxOutWitnessSerializer. } - void SetNull(); + /* Null is the default state when no explicit asset or confidential + * asset commitment has been set. */ bool IsNull() const { return vchCommitment.empty(); } + void SetNull() { vchCommitment.clear(); } - bool IsValid() const; + bool IsExplicit() const + { + return vchCommitment.size()==nExplicitSize && vchCommitment[0]==1; + } - bool IsExplicit() const { return vchCommitment[0] == 1; } - CAmount GetAmount() const; + bool IsCommitment() const + { + return vchCommitment.size()==nCommittedSize && (vchCommitment[0]==PrefixA || vchCommitment[0]==PrefixB); + } - friend bool operator==(const CTxOutValue& a, const CTxOutValue& b) + bool IsValid() const + { + return IsNull() || IsExplicit() || IsCommitment() + || (vchCommitment.size()==nExplicitSize && vchCommitment[0]==0xff); + } + + friend bool operator==(const CConfidentialCommitment& a, const CConfidentialCommitment& b) { return a.vchCommitment == b.vchCommitment; } - friend bool operator!=(const CTxOutValue& a, const CTxOutValue& b) + friend bool operator!=(const CConfidentialCommitment& a, const CConfidentialCommitment& b) { return !(a == b); } +}; -private: - void SetToAmount(const CAmount nAmount); +/** A commitment to a blinded asset, or an explicit asset NUMS identifier */ +class CConfidentialAsset : public CConfidentialCommitment<33, 10, 11> +{ +public: + CConfidentialAsset() { SetNull(); } + CConfidentialAsset(CAsset asset) { SetToAsset(asset); } + + /* An explicit asset identifier is a 256-bit nothing-up-my-sleeve number + * that used as auxiliary input to the Pedersen commitment setup to create + * a generator which acts as the asset tag. */ + const CAsset& GetAsset() const + { + assert(IsExplicit()); + return *reinterpret_cast(&vchCommitment[1]); + } + void SetToAsset(const CAsset& asset); + +}; + +/** A 33-byte commitment to a confidential value, or a 64-bit explicit value. */ +class CConfidentialValue : public CConfidentialCommitment<9, 8, 9> +{ +public: + CConfidentialValue() { SetNull(); } + CConfidentialValue(CAmount nAmount) { SetToAmount(nAmount); } + + /* An explicit value is called an amount. The first byte indicates it is + * an explicit value, and the remaining 8 bytes is the value serialized as + * a 64-bit big-endian integer. */ + CAmount GetAmount() const + { + assert(IsExplicit());; + return ReadBE64(&vchCommitment[1]); + } + void SetToAmount(CAmount nAmount); }; /** An output of a transaction. It contains the public key that the next input @@ -172,9 +139,9 @@ private: class CTxOut { public: - CTxOutAsset nAsset; + CConfidentialAsset nAsset; std::vector vchSurjectionproof; - CTxOutValue nValue; + CConfidentialValue nValue; std::vector vchRangeproof; std::vector vchNonceCommitment; CScript scriptPubKey; @@ -189,7 +156,7 @@ public: // FIXME: Add `const CTxOutAsset& nAssetIn` as first parameter. This will // (rightfully) break all code that calls this constructor, which // will need to be fixed to be asset aware. - CTxOut(const CTxOutAsset& nAssetIn, const CTxOutValue& nValueIn, CScript scriptPubKeyIn); + CTxOut(const CConfidentialAsset& nAssetIn, const CConfidentialValue& nValueIn, CScript scriptPubKeyIn); ADD_SERIALIZE_METHODS; @@ -204,9 +171,9 @@ public: void SetNull() { - nAsset = CTxOutAsset(); + nAsset.SetNull(); vchSurjectionproof.clear(); - nValue = CTxOutValue(); + nValue.SetNull(); vchRangeproof.clear(); vchNonceCommitment.clear(); scriptPubKey.clear(); @@ -360,13 +327,13 @@ public: uint256 assetEntropy; // Both explicit and blinded issuance amounts are supported - // (see class definition for CTxOutValue for details). - CTxOutValue nAmount; + // (see class definition for CConfidentialValue for details). + CConfidentialValue nAmount; // If nonzero, specifies the number of asset issuance tokens to // generate. These tokens are made available to the outputs of the // generating transaction. - CTxOutValue nInflationKeys; + CConfidentialValue nInflationKeys; public: CAssetIssuance() diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 833d0a4d59..e09cbbd2d0 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -143,7 +143,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) out.push_back(Pair("ct-bits", mantissa)); } } - const CTxOutAsset& asset = txout.nAsset; + const CConfidentialAsset& asset = txout.nAsset; if (asset.IsExplicit()) { out.push_back(Pair("asset", asset.GetAsset().GetHex())); } @@ -1164,7 +1164,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request) continue; } const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey; - const CTxOutValue& amount = coins->vout[txin.prevout.n].nValue; + const CConfidentialValue& amount = coins->vout[txin.prevout.n].nValue; SignatureData sigdata; // Only sign SIGHASH_SINGLE if there's a corresponding output: diff --git a/src/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp index a28ffd5e80..8df6fdff48 100644 --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -76,8 +76,8 @@ static bool verify_flags(unsigned int flags) return (flags & ~(bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL)) == 0; } -static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CTxOutValue amount, - CTxOutValue amountPreviousInput, +static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CConfidentialValue amount, + CConfidentialValue amountPreviousInput, const unsigned char *txTo , unsigned int txToLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err) { @@ -113,11 +113,11 @@ int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey { try { TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, amount, amountLen); - CTxOutValue am; + CConfidentialValue am; stream >> am; TxInputStream stream2(SER_NETWORK, PROTOCOL_VERSION, amountPreviousInput, amountPreviousInputLen); - CTxOutValue prevInAm; + CConfidentialValue prevInAm; stream >> prevInAm; return ::verify_script(scriptPubKey, scriptPubKeyLen, am, prevInAm, txTo, txToLen, nIn, flags, err); @@ -135,8 +135,8 @@ int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned i return set_error(err, bitcoinconsensus_ERR_AMOUNT_REQUIRED); } - CTxOutValue am(0); - CTxOutValue prevInAm(-2); + CConfidentialValue am(0); + CConfidentialValue prevInAm(-2); return ::verify_script(scriptPubKey, scriptPubKeyLen, am, prevInAm, txTo, txToLen, nIn, flags, err); } diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 3b8bd58929..ee7e6d70ac 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1438,7 +1438,7 @@ bool EvalScript(vector >& stack, const CScript& script, un if (vgenesisHash.size() != 32) return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_FORMAT); - assert(checker.GetValueIn() != -1); // Not using a NoWithdrawSignatureChecker + assert(checker.GetValueIn() != CConfidentialValue(-1)); // Not using a NoWithdrawSignatureChecker CScript relockScript = CScript() << vgenesisHash << OP_WITHDRAWPROOFVERIFY; @@ -1742,7 +1742,7 @@ PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo) hashOutputs = GetOutputsHash(txTo); } -uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CTxOutValue& amount, SigVersion sigversion, const PrecomputedTransactionData* cache) +uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CConfidentialValue& amount, SigVersion sigversion, const PrecomputedTransactionData* cache) { if (sigversion == SIGVERSION_WITNESS_V0) { uint256 hashPrevouts; @@ -1943,12 +1943,12 @@ COutPoint TransactionSignatureChecker::GetPrevOut() const return txTo->vin[nIn].prevout; } -CTxOutValue TransactionSignatureChecker::GetValueIn() const +CConfidentialValue TransactionSignatureChecker::GetValueIn() const { return amount; } -CTxOutValue TransactionSignatureChecker::GetValueInPrevIn() const +CConfidentialValue TransactionSignatureChecker::GetValueInPrevIn() const { return amountPreviousInput; } diff --git a/src/script/interpreter.h b/src/script/interpreter.h index 37331c7cd7..91a5f60434 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -132,7 +132,7 @@ enum SigVersion SIGVERSION_WITNESS_V0 = 1, }; -uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CTxOutValue& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = NULL); +uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CConfidentialValue& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = NULL); class BaseSignatureChecker { @@ -156,7 +156,7 @@ public: virtual CTxOut GetOutputOffsetFromCurrent(const int offset) const; virtual COutPoint GetPrevOut() const; - virtual CTxOutValue GetValueIn() const + virtual CConfidentialValue GetValueIn() const { return -1; } @@ -166,7 +166,7 @@ public: return false; } - virtual CTxOutValue GetValueInPrevIn() const + virtual CConfidentialValue GetValueInPrevIn() const { return -1; } @@ -184,14 +184,14 @@ class TransactionNoWithdrawsSignatureChecker : public BaseSignatureChecker protected: const CTransaction* txTo; const unsigned int nIn; - const CTxOutValue amount; + const CConfidentialValue amount; const PrecomputedTransactionData* txdata; virtual bool VerifySignature(const std::vector& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const; public: - TransactionNoWithdrawsSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(NULL) {} - TransactionNoWithdrawsSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const PrecomputedTransactionData& txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {} + TransactionNoWithdrawsSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(NULL) {} + TransactionNoWithdrawsSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amountIn, const PrecomputedTransactionData& txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {} bool CheckSig(const std::vector& scriptSig, const std::vector& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const; bool CheckLockTime(const CScriptNum& nLockTime) const; bool CheckSequence(const CScriptNum& nSequence) const; @@ -203,22 +203,22 @@ private: const CTransaction txTo; public: - MutableTransactionNoWithdrawsSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amount) : TransactionNoWithdrawsSignatureChecker(&txTo, nInIn, amount), txTo(*txToIn) {} + MutableTransactionNoWithdrawsSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amount) : TransactionNoWithdrawsSignatureChecker(&txTo, nInIn, amount), txTo(*txToIn) {} }; class TransactionSignatureChecker : public TransactionNoWithdrawsSignatureChecker { private: - const CTxOutValue amountPreviousInput; + const CConfidentialValue amountPreviousInput; const CScript fedpegScript; public: - TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const CTxOutValue& amountPreviousInputIn, const CScript& fedpegScriptIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn), amountPreviousInput(amountPreviousInputIn), fedpegScript(fedpegScriptIn) {} - TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const CTxOutValue& amountPreviousInputIn, const PrecomputedTransactionData& txdataIn, const CScript& fedpegScriptIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn, txdataIn), amountPreviousInput(amountPreviousInputIn), fedpegScript(fedpegScriptIn) {} + TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amountIn, const CConfidentialValue& amountPreviousInputIn, const CScript& fedpegScriptIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn), amountPreviousInput(amountPreviousInputIn), fedpegScript(fedpegScriptIn) {} + TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amountIn, const CConfidentialValue& amountPreviousInputIn, const PrecomputedTransactionData& txdataIn, const CScript& fedpegScriptIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn, txdataIn), amountPreviousInput(amountPreviousInputIn), fedpegScript(fedpegScriptIn) {} CTxOut GetOutputOffsetFromCurrent(const int offset) const; COutPoint GetPrevOut() const; - CTxOutValue GetValueIn() const; - CTxOutValue GetValueInPrevIn() const; + CConfidentialValue GetValueIn() const; + CConfidentialValue GetValueInPrevIn() const; bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements) const; virtual CScript GetFedpegScript() const { diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 07f03378ce..6115030abe 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -177,7 +177,7 @@ bool CachingSurjectionProofChecker::VerifySurjectionProof(secp256k1_surjectionpr secp256k1_surjectionproof_serialize(secp256k1_ctx_verify_amounts, &vchproof[0], &proof_len, &proof); std::vector vchGen; - vchGen.resize(CTxOutValue::nCommittedSize); + vchGen.resize(CConfidentialValue::nCommittedSize); secp256k1_generator_serialize(secp256k1_ctx_verify_amounts, &vchGen[0], &gen); CPubKey pubkey(vchGen); diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 5a35880f7c..20b287fb91 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -28,7 +28,7 @@ private: bool store; public: - CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amount, const CTxOutValue& amountPreviousInput, const CScript& scriptFedRedeem, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amount, amountPreviousInput, scriptFedRedeem), store(storeIn) {} + CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amount, const CConfidentialValue& amountPreviousInput, const CScript& scriptFedRedeem, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amount, amountPreviousInput, scriptFedRedeem), store(storeIn) {} bool VerifySignature(const std::vector& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const; }; diff --git a/src/script/sign.cpp b/src/script/sign.cpp index bacddf525e..1b49169534 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -18,7 +18,7 @@ using namespace std; typedef std::vector valtype; -TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} +TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, SigVersion sigversion) const { @@ -209,7 +209,7 @@ void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const Signatur tx.vin[nIn].scriptWitness = data.scriptWitness; } -bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CTxOutValue& amount, int nHashType) +bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CConfidentialValue& amount, int nHashType) { assert(nIn < txTo.vin.size()); diff --git a/src/script/sign.h b/src/script/sign.h index 2eb08ec17b..6856c6d740 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -35,11 +35,11 @@ class TransactionSignatureCreator : public BaseSignatureCreator { const CTransaction* txTo; unsigned int nIn; int nHashType; - CTxOutValue amount; + CConfidentialValue amount; const TransactionNoWithdrawsSignatureChecker checker; public: - TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, int nHashTypeIn=SIGHASH_ALL); + TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amountIn, int nHashTypeIn=SIGHASH_ALL); const BaseSignatureChecker& Checker() const { return checker; } bool CreateSig(std::vector& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const; }; @@ -48,7 +48,7 @@ class MutableTransactionSignatureCreator : public TransactionSignatureCreator { CTransaction tx; public: - MutableTransactionSignatureCreator(const CKeyStore* keystoreIn, const CMutableTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amount, int nHashTypeIn) : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amount, nHashTypeIn), tx(*txToIn) {} + MutableTransactionSignatureCreator(const CKeyStore* keystoreIn, const CMutableTransaction* txToIn, unsigned int nInIn, const CConfidentialValue& amount, int nHashTypeIn) : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amount, nHashTypeIn), tx(*txToIn) {} }; /** A signature creator that just produces 72-byte empty signatures. */ @@ -71,7 +71,7 @@ struct SignatureData { bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata); /** Produce a script signature for a transaction. */ -bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CTxOutValue& amount, int nHashType); +bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CConfidentialValue& amount, int nHashType); bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType); /** Combine two script signatures using a generic signature checker, intelligently, possibly with OP_0 placeholders. */ diff --git a/src/test/blind_tests.cpp b/src/test/blind_tests.cpp index 53e9cdeaeb..860ceb11ad 100644 --- a/src/test/blind_tests.cpp +++ b/src/test/blind_tests.cpp @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(naive_blinding_test) in3->vout[1] = tx3.vout[1]; in3->vout[2] = tx3.vout[2]; - tx3.vout[1].nValue = CTxOutValue(tx3.vout[1].nValue.GetAmount() - 1); + tx3.vout[1].nValue = CConfidentialValue(tx3.vout[1].nValue.GetAmount() - 1); BOOST_CHECK(!VerifyAmounts(cache, tx3)); } @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(naive_blinding_test) in4->vout[2] = tx4.vout[2]; in4->vout[3] = tx4.vout[3]; - tx4.vout[3].nValue = CTxOutValue(tx4.vout[3].nValue.GetAmount() - 1); + tx4.vout[3].nValue = CConfidentialValue(tx4.vout[3].nValue.GetAmount() - 1); BOOST_CHECK(!VerifyAmounts(cache, tx4)); } } diff --git a/src/test/lockedutxo_tests.cpp b/src/test/lockedutxo_tests.cpp index 582f05993e..c64b771222 100644 --- a/src/test/lockedutxo_tests.cpp +++ b/src/test/lockedutxo_tests.cpp @@ -32,13 +32,13 @@ BOOST_AUTO_TEST_CASE(Getlocked_validity) uint256 gen0 = uint256S("0"); CMutableTransaction mtx0; - mtx0.vout.push_back(CTxOut(CTxOutAsset(BITCOINID), CTxOutValue(1000), CScript() << OP_TRUE)); + mtx0.vout.push_back(CTxOut(CConfidentialAsset(BITCOINID), CConfidentialValue(1000), CScript() << OP_TRUE)); CMutableTransaction mtx1; - mtx1.vout.push_back(CTxOut(CTxOutAsset(BITCOINID), CTxOutValue(100), CScript() << OP_TRUE)); + mtx1.vout.push_back(CTxOut(CConfidentialAsset(BITCOINID), CConfidentialValue(100), CScript() << OP_TRUE)); CMutableTransaction mtx2; - mtx2.vout.push_back(CTxOut(CTxOutAsset(BITCOINID), CTxOutValue(10), CScript() << OP_TRUE)); + mtx2.vout.push_back(CTxOut(CConfidentialAsset(BITCOINID), CConfidentialValue(10), CScript() << OP_TRUE)); CMutableTransaction mtx3; - mtx3.vout.push_back(CTxOut(CTxOutAsset(BITCOINID), CTxOutValue(1), CScript() << OP_TRUE)); + mtx3.vout.push_back(CTxOut(CConfidentialAsset(BITCOINID), CConfidentialValue(1), CScript() << OP_TRUE)); //Push vout of size 1 for each CCoin pcoinsTip->ModifyCoins(uint256S("0"))->FromTx(CTransaction(mtx0), 0); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index ea4146428d..ac5dcad1b3 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -142,7 +142,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey, // of the transactions is below the min relay fee // Remove the low fee transaction and replace with a higher fee transaction mempool.removeRecursive(tx); - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount()- 2); // Now we should be just over the min relay fee + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount()- 2); // Now we should be just over the min relay fee hashLowFeeTx = tx.GetHash(); mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse+2).FromTx(tx)); pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey); @@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vin[0].prevout.n = 0; tx.vout.resize(1); tx.vout[0].scriptPubKey = CScript() << OP_TRUE; - tx.vout[0].nValue = CTxOutValue(GENESISVALUE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE); sighash = SignatureHash(genScriptPubKey, tx, 0, SIGHASH_ALL, 0, SIGVERSION_BASE); coinbaseKey.Sign(sighash, vchSig); @@ -272,11 +272,11 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vin[0].prevout.hash = firstCoin; tx.vin[0].prevout.n = 0; tx.vout.resize(1); - tx.vout[0].nValue = CTxOutValue(GENESISVALUE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE); tx.vout[0].scriptPubKey = CScript(); for (unsigned int i = 0; i < 1001; ++i) { - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount() - LOWFEE); + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount() - LOWFEE); hash = tx.GetHash(); // If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails @@ -294,12 +294,12 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.clear(); tx.vin[0].prevout.hash = firstCoin; - tx.vout[0].nValue = CTxOutValue(GENESISVALUE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE); tx.vout[0].scriptPubKey = CScript(); for (unsigned int i = 0; i < 1001; ++i) { - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount() - LOWFEE); + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount() - LOWFEE); hash = tx.GetHash(); // If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes @@ -318,10 +318,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vin[0].scriptSig << OP_1; tx.vin[0].prevout.hash = firstCoin; tx.vin[0].prevout.n = 0; - tx.vout[0].nValue = CTxOutValue(MAX_MONEY/rewardShards); + tx.vout[0].nValue = CConfidentialValue(MAX_MONEY/rewardShards); for (unsigned int i = 0; i < 128; ++i) { - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount() - LOWFEE); + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount() - LOWFEE); hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); tx.vin[0].prevout.hash = hash; @@ -338,12 +338,12 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) // child with higher priority than parent tx.vin[0].scriptSig = CScript() << OP_1; tx.vin[0].prevout.hash = firstCoin; - tx.vout[0].nValue = CTxOutValue(GENESISVALUE - HIGHFEE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE - HIGHFEE); hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); tx.vin[0].prevout.hash = hash; - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount()-HIGHERFEE); - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount()+BLOCKSUBSIDY-HIGHERFEE); //First txn output + fresh coinbase - new txn fee + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount()-HIGHERFEE); + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount()+BLOCKSUBSIDY-HIGHERFEE); //First txn output + fresh coinbase - new txn fee hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey)); @@ -353,7 +353,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vin.resize(1); tx.vin[0].prevout.SetNull(); tx.vin[0].scriptSig = CScript() << OP_0 << OP_1; - tx.vout[0].nValue = CTxOutValue(0); + tx.vout[0].nValue = CConfidentialValue(0); hash = tx.GetHash(); // give it a fee so it'll get mined mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); @@ -364,14 +364,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vin[0].prevout.hash = firstCoin; tx.vin[0].prevout.n = 0; tx.vin[0].scriptSig = CScript() << OP_1; - tx.vout[0].nValue = CTxOutValue(GENESISVALUE - HIGHFEE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE - HIGHFEE); script = CScript() << OP_0; tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script)); hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); tx.vin[0].prevout.hash = hash; tx.vin[0].scriptSig = CScript() << std::vector(script.begin(), script.end()); - tx.vout[0].nValue = CTxOutValue(tx.vout[0].nValue.GetAmount() - LOWFEE); + tx.vout[0].nValue = CConfidentialValue(tx.vout[0].nValue.GetAmount() - LOWFEE); hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); BOOST_CHECK_THROW(BlockAssembler(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error); @@ -380,7 +380,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) // double spend txn pair in mempool, template creation fails tx.vin[0].prevout.hash = firstCoin; tx.vin[0].scriptSig = CScript() << OP_1; - tx.vout[0].nValue = CTxOutValue(GENESISVALUE - HIGHFEE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE - HIGHFEE); tx.vout[0].scriptPubKey = CScript() << OP_1; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); @@ -440,7 +440,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vin[0].prevout.n = 0; tx.vin[0].scriptSig = CScript() << OP_1; tx.vin[0].nSequence = chainActive.Tip()->nHeight + 1; // txFirst[0] is the 2nd block - tx.vout[0].nValue = CTxOutValue(GENESISVALUE - HIGHFEE); + tx.vout[0].nValue = CConfidentialValue(GENESISVALUE - HIGHFEE); prevheights[0] = baseheight + 1; tx.vout.resize(1); tx.vout[0].scriptPubKey = CScript() << OP_1; diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 6bc2a335bd..a05893868a 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -174,7 +174,7 @@ return; CDataStream streamVal1(SER_NETWORK, PROTOCOL_VERSION); streamVal1 << txCredit.vout[0].nValue; CDataStream streamVal2(SER_NETWORK, PROTOCOL_VERSION); - streamVal2 << CTxOutValue(); + streamVal2 << CConfidentialValue(); int libconsensus_flags = flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL; if (libconsensus_flags == flags) { if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS) { diff --git a/src/validation.cpp b/src/validation.cpp index 7ff17b059c..b3edf033e4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -572,14 +572,14 @@ static Secp256k1Ctx instance_of_secp256k1ctx; class CRangeCheck : public CCheck { private: - const CTxOutValue* val; + const CConfidentialValue* val; const std::vector& rangeproof; - const CTxOutAsset* asset; + const CConfidentialAsset* asset; const CScript* scriptPubKey; const bool store; public: - CRangeCheck(const CTxOutValue* val_, const std::vector& rangeproof_, const CTxOutAsset* asset_, const CScript* scriptPubKey_, const bool storeIn) : val(val_), rangeproof(rangeproof_), asset(asset_), scriptPubKey(scriptPubKey_), store(storeIn) {} + CRangeCheck(const CConfidentialValue* val_, const std::vector& rangeproof_, const CConfidentialAsset* asset_, const CScript* scriptPubKey_, const bool storeIn) : val(val_), rangeproof(rangeproof_), asset(asset_), scriptPubKey(scriptPubKey_), store(storeIn) {} bool operator()(); }; @@ -678,8 +678,8 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve for (size_t i = 0; i < tx.vin.size(); ++i) { const CTxOut out = cache.GetOutputFor(tx.vin[i]); - const CTxOutValue& val = out.nValue; - const CTxOutAsset& asset = out.nAsset; + const CConfidentialValue& val = out.nValue; + const CConfidentialAsset& asset = out.nAsset; if (val.IsNull() || asset.IsNull()) return false; @@ -708,7 +708,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve return false; } else { - assert(val.vchCommitment.size() == CTxOutValue::nCommittedSize); + assert(val.vchCommitment.size() == CConfidentialValue::nCommittedSize); if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &val.vchCommitment[0]) != 1) return false; } @@ -720,11 +720,11 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve } for (size_t i = 0; i < tx.vout.size(); ++i) { - const CTxOutValue& val = tx.vout[i].nValue; - const CTxOutAsset& asset = tx.vout[i].nAsset; - assert(val.vchCommitment.size() == CTxOutValue::nCommittedSize || - val.vchCommitment.size() == CTxOutValue::nExplicitSize); - if (tx.vout[i].vchNonceCommitment.size() > CTxOutValue::nCommittedSize || tx.vout[i].vchRangeproof.size() > 5000) + const CConfidentialValue& val = tx.vout[i].nValue; + const CConfidentialAsset& asset = tx.vout[i].nAsset; + assert(val.vchCommitment.size() == CConfidentialValue::nCommittedSize || + val.vchCommitment.size() == CConfidentialValue::nExplicitSize); + if (tx.vout[i].vchNonceCommitment.size() > 33 || tx.vout[i].vchRangeproof.size() > 5000) return false; if (asset.IsExplicit()) { @@ -768,7 +768,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve // Range proofs for (size_t i = 0; i < tx.vout.size(); i++) { - const CTxOutValue& val = tx.vout[i].nValue; + const CConfidentialValue& val = tx.vout[i].nValue; if (val.IsExplicit()) continue; if (!QueueCheck(pvChecks, new CRangeCheck(&val, tx.vout[i].vchRangeproof, &tx.vout[i].nAsset, &tx.vout[i].scriptPubKey, cacheStore))) { @@ -783,7 +783,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve for (size_t i = 0; i < tx.vin.size(); i++) { - const CTxOutAsset& asset = cache.GetOutputFor(tx.vin[i]).nAsset; + const CConfidentialAsset& asset = cache.GetOutputFor(tx.vin[i]).nAsset; if (asset.IsExplicit()) { ret = secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &ephemeral_input_tags[i], asset.GetAsset().begin()); assert(ret != 0); @@ -798,7 +798,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve for (size_t i = 0; i < tx.vout.size(); i++) { - const CTxOutAsset& asset = tx.vout[i].nAsset; + const CConfidentialAsset& asset = tx.vout[i].nAsset; //No need for surjective proof if (asset.IsExplicit()) { assert(tx.vout[i].vchSurjectionproof.size() == 0); @@ -1851,7 +1851,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins } // Check for negative or overflow input values - const CTxOutValue& value = coins->vout[prevout.n].nValue; + const CConfidentialValue& value = coins->vout[prevout.n].nValue; if (value.IsExplicit()) { nValueIn += value.GetAmount(); if (!MoneyRange(value.GetAmount()) || !MoneyRange(nValueIn)) @@ -1986,7 +1986,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi else return state.DoS(100,false, REJECT_INVALID, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(serror))); } - const CTxOutValue& value = coins->vout[tx.vin[i].prevout.n].nValue; + const CConfidentialValue& value = coins->vout[tx.vin[i].prevout.n].nValue; if (value.IsExplicit()) prevValueIn = value.GetAmount(); else diff --git a/src/validation.h b/src/validation.h index 2dfc9dd164..88ab062ee6 100644 --- a/src/validation.h +++ b/src/validation.h @@ -511,8 +511,8 @@ class CScriptCheck : public CCheck { private: CScript scriptPubKey; - CTxOutValue amount; - CTxOutValue amountPreviousInput; + CConfidentialValue amount; + CConfidentialValue amountPreviousInput; const CTransaction *ptxTo; unsigned int nIn; unsigned int nFlags; @@ -520,7 +520,7 @@ private: PrecomputedTransactionData *txdata; public: - CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, const CTxOutValue& amountPreviousInputIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) : + CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, const CConfidentialValue& amountPreviousInputIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) : scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey), amount(txFromIn.vout[txToIn.vin[nInIn].prevout.n].nValue), amountPreviousInput(amountPreviousInputIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), txdata(txdataIn) { } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dd02557a1f..e98ef1835b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3117,7 +3117,7 @@ UniValue bumpfee(const JSONRPCRequest& request) } // If the output would become dust, discard it (converting the dust to fee) - poutput->nValue = CTxOutValue(poutput->nValue.GetAmount() - nDelta); + poutput->nValue = CConfidentialValue(poutput->nValue.GetAmount() - nDelta); if (poutput->nValue.GetAmount() <= poutput->GetDustThreshold(::dustRelayFee)) { LogPrint("rpc", "Bumping fee and discarding dust output\n"); nNewFee += poutput->nValue.GetAmount(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 40921ef808..e8603af8f1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3006,7 +3006,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt if (nFeeRet > nFeeNeeded && nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) { CAmount extraFeePaid = nFeeRet - nFeeNeeded; vector::iterator change_position = txNew.vout.begin()+nChangePosInOut; - change_position->nValue = CTxOutValue(change_position->nValue.GetAmount() + extraFeePaid); + change_position->nValue = CConfidentialValue(change_position->nValue.GetAmount() + extraFeePaid); nFeeRet -= extraFeePaid; } break; // Done, enough fee included. @@ -3018,7 +3018,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt vector::iterator change_position = txNew.vout.begin()+nChangePosInOut; // Only reduce change if remaining amount is still a large enough output. if (change_position->nValue.GetAmount() >= MIN_FINAL_CHANGE + additionalFeeNeeded) { - change_position->nValue = CTxOutValue(change_position->nValue.GetAmount() - additionalFeeNeeded); + change_position->nValue = CConfidentialValue(change_position->nValue.GetAmount() - additionalFeeNeeded); nFeeRet += additionalFeeNeeded; break; // Done, able to increase fee from change }