Skip to content

Commit e6b3676

Browse files
committed
Wallet: GetIssuanceAssets to just get CAssets for issuances
1 parent 2bcd243 commit e6b3676

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

src/wallet/wallet.cpp

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5196,32 +5196,52 @@ CPubKey CWalletTx::GetOutputBlindingPubKey(unsigned int output_index) const {
51965196
return ret;
51975197
}
51985198

5199+
void CWalletTx::GetIssuanceAssets(unsigned int vinIndex, CAsset* out_asset, CAsset* out_reissuance_token) const {
5200+
assert(vinIndex < tx->vin.size());
5201+
const CAssetIssuance& issuance = tx->vin[vinIndex].assetIssuance;
5202+
5203+
if (out_asset && issuance.nAmount.IsNull()) {
5204+
out_asset->SetNull();
5205+
out_asset = nullptr;
5206+
}
5207+
if (out_reissuance_token && issuance.nInflationKeys.IsNull()) {
5208+
out_reissuance_token->SetNull();
5209+
out_reissuance_token = nullptr;
5210+
}
5211+
if (!(out_asset || out_reissuance_token)) return;
5212+
5213+
if (issuance.assetBlindingNonce.IsNull()) {
5214+
uint256 entropy;
5215+
GenerateAssetEntropy(entropy, tx->vin[vinIndex].prevout, issuance.assetEntropy);
5216+
if (out_reissuance_token) {
5217+
CalculateReissuanceToken(*out_reissuance_token, entropy, issuance.nAmount.IsCommitment());
5218+
}
5219+
if (out_asset) {
5220+
CalculateAsset(*out_asset, entropy);
5221+
}
5222+
}
5223+
else {
5224+
if (out_reissuance_token) {
5225+
// Re-issuances don't emit issuance tokens
5226+
out_reissuance_token->SetNull();
5227+
}
5228+
if (out_asset) {
5229+
CalculateAsset(*out_asset, issuance.assetEntropy);
5230+
}
5231+
}
5232+
}
5233+
51995234
uint256 CWalletTx::GetIssuanceBlindingFactor(unsigned int input_index, bool reissuance_token) const {
52005235
assert(input_index < tx->vin.size());
52015236
CAsset asset;
52025237
const CAssetIssuance& issuance = tx->vin[input_index].assetIssuance;
52035238
const CTxWitness& wit = tx->witness;
5204-
if ((issuance.nAmount.IsNull() && !reissuance_token) || (issuance.nInflationKeys.IsNull() && reissuance_token)) {
5239+
GetIssuanceAssets(input_index, reissuance_token ? nullptr : &asset, reissuance_token ? &asset : nullptr);
5240+
if (asset.IsNull()) {
52055241
return uint256();
52065242
}
52075243
const std::vector<unsigned char>& rangeproof = wit.vtxinwit.size() <= input_index ? std::vector<unsigned char>() : (reissuance_token ? wit.vtxinwit[input_index].vchInflationKeysRangeproof : wit.vtxinwit[input_index].vchIssuanceAmountRangeproof);
52085244
unsigned int mapValueInd = GetPseudoInputOffset(input_index, reissuance_token)+tx->vout.size();
5209-
if (issuance.assetBlindingNonce.IsNull()) {
5210-
uint256 entropy;
5211-
GenerateAssetEntropy(entropy, tx->vin[input_index].prevout, issuance.assetEntropy);
5212-
if (reissuance_token) {
5213-
CalculateReissuanceToken(asset, entropy, issuance.nInflationKeys.IsCommitment());
5214-
} else {
5215-
CalculateAsset(asset, entropy);
5216-
}
5217-
}
5218-
else {
5219-
if (reissuance_token) {
5220-
// Re-issuances don't emit issuance tokens
5221-
return uint256();
5222-
}
5223-
CalculateAsset(asset, issuance.assetEntropy);
5224-
}
52255245

52265246
uint256 ret;
52275247
CScript blindingScript(CScript() << OP_RETURN << std::vector<unsigned char>(tx->vin[input_index].prevout.hash.begin(), tx->vin[input_index].prevout.hash.end()) << tx->vin[input_index].prevout.n);
@@ -5232,31 +5252,18 @@ uint256 CWalletTx::GetIssuanceBlindingFactor(unsigned int input_index, bool reis
52325252
CAmount CWalletTx::GetIssuanceAmount(unsigned int input_index, bool reissuance_token) const {
52335253
assert(input_index < tx->vin.size());
52345254
CAsset asset;
5235-
CAsset token;
52365255
const CAssetIssuance& issuance = tx->vin[input_index].assetIssuance;
52375256
const CTxWitness& wit = tx->witness;
5238-
if ((issuance.nAmount.IsNull() && !reissuance_token) || (issuance.nInflationKeys.IsNull() && reissuance_token)) {
5239-
return 0;
5257+
GetIssuanceAssets(input_index, reissuance_token ? nullptr : &asset, reissuance_token ? &asset : nullptr);
5258+
if (asset.IsNull()) {
5259+
return -1;
52405260
}
52415261
unsigned int mapValueInd = GetPseudoInputOffset(input_index, reissuance_token)+tx->vout.size();
52425262
const std::vector<unsigned char>& rangeproof = wit.vtxinwit.size() <= input_index ? std::vector<unsigned char>() : (reissuance_token ? wit.vtxinwit[input_index].vchInflationKeysRangeproof : wit.vtxinwit[input_index].vchIssuanceAmountRangeproof);
5243-
if (issuance.assetBlindingNonce.IsNull()) {
5244-
uint256 entropy;
5245-
GenerateAssetEntropy(entropy, tx->vin[input_index].prevout, issuance.assetEntropy);
5246-
CalculateReissuanceToken(token, entropy, issuance.nAmount.IsCommitment());
5247-
CalculateAsset(asset, entropy);
5248-
}
5249-
else {
5250-
if (reissuance_token) {
5251-
// Re-issuances don't emit issuance tokens
5252-
return -1;
5253-
}
5254-
CalculateAsset(asset, issuance.assetEntropy);
5255-
}
52565263

52575264
CAmount ret;
52585265
CScript blindingScript(CScript() << OP_RETURN << std::vector<unsigned char>(tx->vin[input_index].prevout.hash.begin(), tx->vin[input_index].prevout.hash.end()) << tx->vin[input_index].prevout.n);
5259-
GetBlindingData(mapValueInd, rangeproof, reissuance_token ? issuance.nInflationKeys : issuance.nAmount, CConfidentialAsset((reissuance_token ? token : asset)), CConfidentialNonce(), blindingScript, nullptr, &ret, nullptr, nullptr, nullptr);
5266+
GetBlindingData(mapValueInd, rangeproof, reissuance_token ? issuance.nInflationKeys : issuance.nAmount, CConfidentialAsset(asset), CConfidentialNonce(), blindingScript, nullptr, &ret, nullptr, nullptr, nullptr);
52605267
return ret;
52615268
}
52625269

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ class CWalletTx : public CMerkleTx
533533
uint256 GetOutputAssetBlindingFactor(unsigned int output_index) const;
534534
//! Returns the underlying asset type, or 0 if unknown
535535
CAsset GetOutputAsset(unsigned int output_index) const;
536+
//! Get the issuance CAssets for both the asset itself and the issuing tokens
537+
void GetIssuanceAssets(unsigned int vinIndex, CAsset* out_asset, CAsset* out_reissuance_token) const;
536538
// ! Returns receiver's blinding pubkey
537539
CPubKey GetOutputBlindingPubKey(unsigned int output_index) const;
538540
//! Get the issuance blinder for either the asset itself or the issuing tokens

0 commit comments

Comments
 (0)