mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Add support for blinding pegin transactions
Both via blindrawtransaction and rawblindrawtransaction.
This commit is contained in:
parent
bf0cc83ba3
commit
a9f589b9ec
3 changed files with 30 additions and 2 deletions
|
|
@ -530,7 +530,7 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const
|
|||
// abort and not blind and the math adds up.
|
||||
// Count as success(to signal caller that nothing wrong) and return early
|
||||
if (memcmp(diff_zero, &blind[num_blind_attempts-1][0], 32) == 0) {
|
||||
return ++num_blinded;
|
||||
return ++num_blinded;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -539,7 +539,7 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const
|
|||
out_val_blind_factors[nOut] = uint256(std::vector<unsigned char>(value_blindptrs[value_blindptrs.size()-1], value_blindptrs[value_blindptrs.size()-1]+32));
|
||||
out_asset_blind_factors[nOut] = uint256(std::vector<unsigned char>(asset_blindptrs[asset_blindptrs.size()-1], asset_blindptrs[asset_blindptrs.size()-1]+32));
|
||||
|
||||
//Blind the asset ID
|
||||
// Blind the asset ID
|
||||
BlindAsset(conf_asset, asset_gen, asset, asset_blindptrs.back());
|
||||
|
||||
// Create value commitment
|
||||
|
|
|
|||
|
|
@ -2248,6 +2248,20 @@ UniValue rawblindrawtransaction(const JSONRPCRequest& request)
|
|||
std::vector<CAsset> output_assets;
|
||||
std::vector<CPubKey> output_pubkeys;
|
||||
for (size_t nIn = 0; nIn < tx.vin.size(); nIn++) {
|
||||
// Special handling for pegin inputs: no blinds and explicit amount/asset.
|
||||
if (tx.vin[nIn].m_is_pegin) {
|
||||
std::string err;
|
||||
if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[nIn].m_pegin_witness, tx.vin[nIn].prevout, err, false)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Transaction contains invalid peg-in input: %s", err));
|
||||
}
|
||||
CTxOut pegin_output = GetPeginOutputFromWitness(tx.witness.vtxinwit[nIn].m_pegin_witness);
|
||||
input_blinds.push_back(uint256());
|
||||
input_asset_blinds.push_back(uint256());
|
||||
input_assets.push_back(pegin_output.nAsset.GetAsset());
|
||||
input_amounts.push_back(pegin_output.nValue.GetAmount());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inputBlinds[nIn].isStr())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "input blinds must be an array of hex strings");
|
||||
if (!inputAssetBlinds[nIn].isStr())
|
||||
|
|
|
|||
|
|
@ -5778,6 +5778,20 @@ UniValue blindrawtransaction(const JSONRPCRequest& request)
|
|||
for (size_t nIn = 0; nIn < tx.vin.size(); ++nIn) {
|
||||
COutPoint prevout = tx.vin[nIn].prevout;
|
||||
|
||||
// Special handling for pegin inputs: no blinds and explicit amount/asset.
|
||||
if (tx.vin[nIn].m_is_pegin) {
|
||||
std::string err;
|
||||
if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[nIn].m_pegin_witness, prevout, err, false)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Transaction contains invalid peg-in input: %s", err));
|
||||
}
|
||||
CTxOut pegin_output = GetPeginOutputFromWitness(tx.witness.vtxinwit[nIn].m_pegin_witness);
|
||||
input_blinds.push_back(uint256());
|
||||
input_asset_blinds.push_back(uint256());
|
||||
input_assets.push_back(pegin_output.nAsset.GetAsset());
|
||||
input_amounts.push_back(pegin_output.nValue.GetAmount());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.find(prevout.hash);
|
||||
if (it == pwallet->mapWallet.end() || pwallet->IsMine(tx.vin[nIn]) == ISMINE_NO) {
|
||||
// For inputs we don't own, input assetcommitments for the surjection must be supplied.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue