From 906cc4c40b01441d80bee3581ee3cb190d38716c Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 15 Dec 2018 23:00:29 +0000 Subject: [PATCH] Wallet: GetIssuanceAssets to get CAmountMap for issuances --- src/wallet/wallet.cpp | 21 +++++++++++++++++---- src/wallet/wallet.h | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5e85c671cc..f1fdedcd37 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2024,6 +2024,19 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const return CTransaction(tx1) == CTransaction(tx2); } +CAmountMap CWalletTx::GetIssuanceAssets(unsigned int input_index) const { + CAmountMap ret; + CAsset asset, token; + GetIssuanceAssets(input_index, &asset, &token); + if (!asset.IsNull()) { + ret[asset] = GetIssuanceAmount(input_index, false); + } + if (!token.IsNull()) { + ret[token] = GetIssuanceAmount(input_index, true); + } + return ret; +} + std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman) { std::vector result; @@ -5196,9 +5209,9 @@ CPubKey CWalletTx::GetOutputBlindingPubKey(unsigned int output_index) const { return ret; } -void CWalletTx::GetIssuanceAssets(unsigned int vinIndex, CAsset* out_asset, CAsset* out_reissuance_token) const { - assert(vinIndex < tx->vin.size()); - const CAssetIssuance& issuance = tx->vin[vinIndex].assetIssuance; +void CWalletTx::GetIssuanceAssets(unsigned int input_index, CAsset* out_asset, CAsset* out_reissuance_token) const { + assert(input_index < tx->vin.size()); + const CAssetIssuance& issuance = tx->vin[input_index].assetIssuance; if (out_asset && issuance.nAmount.IsNull()) { out_asset->SetNull(); @@ -5212,7 +5225,7 @@ void CWalletTx::GetIssuanceAssets(unsigned int vinIndex, CAsset* out_asset, CAss if (issuance.assetBlindingNonce.IsNull()) { uint256 entropy; - GenerateAssetEntropy(entropy, tx->vin[vinIndex].prevout, issuance.assetEntropy); + GenerateAssetEntropy(entropy, tx->vin[input_index].prevout, issuance.assetEntropy); if (out_reissuance_token) { CalculateReissuanceToken(*out_reissuance_token, entropy, issuance.nAmount.IsCommitment()); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 86a726dfb4..87d22bc346 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -535,6 +535,8 @@ public: CAsset GetOutputAsset(unsigned int output_index) const; //! Get the issuance CAssets for both the asset itself and the issuing tokens void GetIssuanceAssets(unsigned int vinIndex, CAsset* out_asset, CAsset* out_reissuance_token) const; + // ! Return map of issued assets at input_index + CAmountMap GetIssuanceAssets(unsigned int input_index) const; // ! Returns receiver's blinding pubkey CPubKey GetOutputBlindingPubKey(unsigned int output_index) const; //! Get the issuance blinder for either the asset itself or the issuing tokens