From 124efa26686efc937f0ab0ee3b7645ca232aae1f Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 9 Dec 2020 12:31:29 -0500 Subject: [PATCH] Return better errors for BlindingStatus --- src/blindpsbt.cpp | 21 +++++++++++++++++++++ src/blindpsbt.h | 2 ++ src/wallet/rpcwallet.cpp | 10 ++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/blindpsbt.cpp b/src/blindpsbt.cpp index 800aeab0e6..55ad807710 100644 --- a/src/blindpsbt.cpp +++ b/src/blindpsbt.cpp @@ -12,6 +12,27 @@ #include #include +std::string GetBlindingStatusError(const BlindingStatus& status) +{ + switch(status) { + case BlindingStatus::OK: + return "No error"; + case BlindingStatus::NEEDS_UTXOS: + return "Inputs are missing UTXOs (or peg-in data for peg-in inputs)"; + case BlindingStatus::INVALID_ASSET: + return "Provided asset tag is invalid"; + case BlindingStatus::INVALID_ASSET_COMMITMENT: + return "Provided asset commitment is invalid"; + case BlindingStatus::SCALAR_UNABLE: + return "Unable to compute the scalars for the final blinder"; + case BlindingStatus::INVALID_BLINDER: + return "Computed blinding factor is invalid"; + case BlindingStatus::ASP_UNABLE: + return "Unable to create an asset surjection proof"; + } + assert(false); +} + // Create surjection proof bool CreateAssetSurjectionProof(std::vector& output_proof, const std::vector& fixed_input_tags, const std::vector& ephemeral_input_tags, const std::vector& input_asset_blinders, const uint256& output_asset_blinder, const secp256k1_generator& output_asset_tag, const CAsset& asset) { diff --git a/src/blindpsbt.h b/src/blindpsbt.h index aa62663450..8e08e9a719 100644 --- a/src/blindpsbt.h +++ b/src/blindpsbt.h @@ -28,6 +28,8 @@ enum class BlindingStatus ASP_UNABLE, }; +std::string GetBlindingStatusError(const BlindingStatus& status); + bool CreateAssetSurjectionProof(std::vector& output_proof, const std::vector& fixed_input_tags, const std::vector& ephemeral_input_tags, const std::vector& input_asset_blinders, const uint256& output_asset_blinder, const secp256k1_generator& output_asset_tag, const CAsset& asset); uint256 GenerateRangeproofECDHKey(CPubKey& ephemeral_pubkey, const CPubKey blinding_pubkey); bool CreateValueRangeProof(std::vector& rangeproof, const uint256& value_blinder, const uint256& nonce, const CAmount amount, const CScript& scriptPubKey, const secp256k1_pedersen_commitment& value_commit, const secp256k1_generator& gen, const CAsset& asset, const uint256& asset_blinder); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0ca0813e48..34a78f0701 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4813,8 +4813,9 @@ static RPCHelpMan walletprocesspsbt() } } if (needs_blinding) { - if (pwallet->WalletBlindPSBT(psbtx) != BlindingStatus::OK) { - throw JSONRPCError(RPC_WALLET_ERROR, "Something went wrong"); + BlindingStatus status = pwallet->WalletBlindPSBT(psbtx); + if (status != BlindingStatus::OK) { + throw JSONRPCError(RPC_WALLET_ERROR, GetBlindingStatusError(status)); } } @@ -4873,8 +4874,9 @@ static RPCHelpMan walletblindpsbt() throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error)); } - if (pwallet->WalletBlindPSBT(psbtx) != BlindingStatus::OK) { - throw JSONRPCError(RPC_WALLET_ERROR, "Something went wrong"); + BlindingStatus status = pwallet->WalletBlindPSBT(psbtx); + if (status != BlindingStatus::OK) { + throw JSONRPCError(RPC_WALLET_ERROR, GetBlindingStatusError(status)); } UniValue result(UniValue::VOBJ);