Skip to content

Commit

Permalink
Add convenience method GetNonIssuanceBlindingData
Browse files Browse the repository at this point in the history
  • Loading branch information
gwillen authored and stevenroose committed Aug 19, 2019
1 parent 751c077 commit 059b90f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5390,48 +5390,41 @@ void CWalletTx::GetBlindingData(const unsigned int map_index, const std::vector<
if (asset_out) *asset_out = asset_tag;
}

CAmount CWalletTx::GetOutputValueOut(unsigned int output_index) const {
void CWalletTx::GetNonIssuanceBlindingData(const unsigned int output_index, CPubKey* blinding_pubkey_out, CAmount* value_out, uint256* value_factor_out, CAsset* asset_out, uint256* asset_factor_out) const {
assert(output_index < tx->vout.size());
const CTxOut& out = tx->vout[output_index];
const CTxWitness& wit = tx->witness;
GetBlindingData(output_index, wit.vtxoutwit.size() <= output_index ? std::vector<unsigned char>() : wit.vtxoutwit[output_index].vchRangeproof, out.nValue, out.nAsset, out.nNonce, out.scriptPubKey,
blinding_pubkey_out, value_out, value_factor_out, asset_out, asset_factor_out);
}

CAmount CWalletTx::GetOutputValueOut(unsigned int output_index) const {
CAmount ret;
GetBlindingData(output_index, wit.vtxoutwit.size() <= output_index ? std::vector<unsigned char>() : wit.vtxoutwit[output_index].vchRangeproof, out.nValue, out.nAsset, out.nNonce, out.scriptPubKey, nullptr, &ret, nullptr, nullptr, nullptr);
GetNonIssuanceBlindingData(output_index, nullptr, &ret, nullptr, nullptr, nullptr);
return ret;
}

uint256 CWalletTx::GetOutputAmountBlindingFactor(unsigned int output_index) const {
assert(output_index < tx->vout.size());
const CTxOut& out = tx->vout[output_index];
const CTxWitness& wit = tx->witness;
uint256 ret;
GetBlindingData(output_index, wit.vtxoutwit.size() <= output_index ? std::vector<unsigned char>() : wit.vtxoutwit[output_index].vchRangeproof, out.nValue, out.nAsset, out.nNonce, out.scriptPubKey, nullptr, nullptr, &ret, nullptr, nullptr);
GetNonIssuanceBlindingData(output_index, nullptr, nullptr, &ret, nullptr, nullptr);
return ret;
}

uint256 CWalletTx::GetOutputAssetBlindingFactor(unsigned int output_index) const {
assert(output_index < tx->vout.size());
const CTxOut& out = tx->vout[output_index];
const CTxWitness& wit = tx->witness;
uint256 ret;
GetBlindingData(output_index, wit.vtxoutwit.size() <= output_index ? std::vector<unsigned char>() : wit.vtxoutwit[output_index].vchRangeproof, out.nValue, out.nAsset, out.nNonce, out.scriptPubKey, nullptr, nullptr, nullptr, nullptr, &ret);
GetNonIssuanceBlindingData(output_index, nullptr, nullptr, nullptr, nullptr, &ret);
return ret;
}

CAsset CWalletTx::GetOutputAsset(unsigned int output_index) const {
assert(output_index < tx->vout.size());
const CTxOut& out = tx->vout[output_index];
const CTxWitness& wit = tx->witness;
CAsset ret;
GetBlindingData(output_index, wit.vtxoutwit.size() <= output_index ? std::vector<unsigned char>() : wit.vtxoutwit[output_index].vchRangeproof, out.nValue, out.nAsset, out.nNonce, out.scriptPubKey, nullptr, nullptr, nullptr, &ret, nullptr);
GetNonIssuanceBlindingData(output_index, nullptr, nullptr, nullptr, &ret, nullptr);
return ret;
}

CPubKey CWalletTx::GetOutputBlindingPubKey(unsigned int output_index) const {
assert(output_index < tx->vout.size());
const CTxOut& out = tx->vout[output_index];
const CTxWitness& wit = tx->witness;
CPubKey ret;
GetBlindingData(output_index, wit.vtxoutwit.size() <= output_index ? std::vector<unsigned char>() : wit.vtxoutwit[output_index].vchRangeproof, out.nValue, out.nAsset, out.nNonce, out.scriptPubKey, &ret, nullptr, nullptr, nullptr, nullptr);
GetNonIssuanceBlindingData(output_index, &ret, nullptr, nullptr, nullptr, nullptr);
return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ class CWalletTx : public CMerkleTx
// Unneeded for issuance.
void SetBlindingData(const unsigned int output_index, const CPubKey& blinding_pubkey, const CAmount value, const uint256& value_factor, const CAsset& asset, const uint256& asset_factor);

// Convenience method to retrieve all blinding data at once, for an ordinary non-issuance tx
void GetNonIssuanceBlindingData(const unsigned int output_index, CPubKey* blinding_pubkey_out, CAmount* value_out, uint256* value_factor_out, CAsset* asset_out, uint256* asset_factor_out) const;

//! Returns either the value out (if it is known) or -1
CAmount GetOutputValueOut(unsigned int ouput_index) const;

Expand Down

0 comments on commit 059b90f

Please sign in to comment.