Skip to content

Commit

Permalink
Add support for blinding pegin transactions
Browse files Browse the repository at this point in the history
Both via blindrawtransaction and rawblindrawtransaction.
  • Loading branch information
stevenroose committed Jun 13, 2019
1 parent bf0cc83 commit a9f589b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/blind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
14 changes: 14 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a9f589b

Please sign in to comment.