Skip to content

Commit

Permalink
Merge pull request ElementsProject#1145 from allenpiscitello/pset-fixes
Browse files Browse the repository at this point in the history
Fixing issuance cases and half blinded cases in PSET
  • Loading branch information
psgreco committed Aug 18, 2022
2 parents fa809af + 5954b10 commit debf46b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/blindpsbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map<uint32_t, st
}
}
}
else {
input_asset_blinders.emplace_back();
}
}
}
}
Expand Down
28 changes: 19 additions & 9 deletions src/psbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,26 @@ CMutableTransaction PartiallySignedTransaction::GetUnsignedTx(bool force_unblind
txin.nSequence = input.sequence.value_or(max_sequence);
txin.assetIssuance.assetBlindingNonce = input.m_issuance_blinding_nonce;
txin.assetIssuance.assetEntropy = input.m_issuance_asset_entropy;
if (input.m_issuance_value != std::nullopt && input.m_issuance_inflation_keys_amount != std::nullopt && force_unblinded) {
// If there is a commitment we should set the value to the commitment unless we are forcing unblinded.
// If we are forcing unblinded but there is no value, we just use the commitment.
if (input.m_issuance_value != std::nullopt && (input.m_issuance_value_commitment.IsNull() || force_unblinded)) {
txin.assetIssuance.nAmount.SetToAmount(*input.m_issuance_value);
txin.assetIssuance.nInflationKeys.SetToAmount(*input.m_issuance_inflation_keys_amount);
} else {
}
else if(!input.m_issuance_value_commitment.IsNull()) {
txin.assetIssuance.nAmount = input.m_issuance_value_commitment;
}
else {
txin.assetIssuance.nAmount.SetNull();
}
if (input.m_issuance_inflation_keys_amount != std::nullopt && (input.m_issuance_inflation_keys_commitment.IsNull() || force_unblinded)) {
txin.assetIssuance.nInflationKeys.SetToAmount(*input.m_issuance_value);
}
else if(!input.m_issuance_inflation_keys_commitment.IsNull()) {
txin.assetIssuance.nInflationKeys = input.m_issuance_inflation_keys_commitment;
}
else {
txin.assetIssuance.nInflationKeys.SetNull();
}
mtx.vin.push_back(txin);
}
for (const PSBTOutput& output : outputs) {
Expand Down Expand Up @@ -531,12 +544,9 @@ bool PSBTOutput::Merge(const PSBTOutput& output)
CTxOut PSBTOutput::GetTxOut() const
{
assert(script != std::nullopt);
if (!m_value_commitment.IsNull() && !m_asset_commitment.IsNull()) {
return CTxOut(m_asset_commitment, m_value_commitment, *script);
}
assert(amount != std::nullopt);
assert(!m_asset.IsNull());
return CTxOut(CConfidentialAsset(CAsset(m_asset)), CConfidentialValue(*amount), *script);
assert(amount != std::nullopt || !m_value_commitment.IsNull());
assert(!m_asset.IsNull() || !m_asset_commitment.IsNull());
return CTxOut(!m_asset_commitment.IsNull() ? m_asset_commitment : CAsset(m_asset), !m_value_commitment.IsNull() ? m_value_commitment : CConfidentialValue(*amount), *script);
}

bool PSBTOutput::IsBlinded() const
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2048,11 +2048,15 @@ TransactionError CWallet::SignPSBT(PartiallySignedTransaction& psbtx, bool& comp
txin.assetIssuance.nAmount = input.m_issuance_value_commitment;
} else if (input.m_issuance_value) {
txin.assetIssuance.nAmount.SetToAmount(*input.m_issuance_value);
} else {
txin.assetIssuance.nAmount.SetNull();
}
if (!input.m_issuance_inflation_keys_commitment.IsNull()) {
txin.assetIssuance.nInflationKeys = input.m_issuance_inflation_keys_commitment;
} else if (input.m_issuance_inflation_keys_amount) {
txin.assetIssuance.nInflationKeys.SetToAmount(*input.m_issuance_inflation_keys_amount);
} else {
txin.assetIssuance.nInflationKeys.SetNull();
}
if (!input.m_issuance_rangeproof.empty()) {
txinwit.vchIssuanceAmountRangeproof = input.m_issuance_rangeproof;
Expand Down

0 comments on commit debf46b

Please sign in to comment.