mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Change SignTransaction's input_errors to use bilingual_str
This commit is contained in:
parent
171366e89b
commit
92993aa5cf
12 changed files with 29 additions and 24 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <univalue.h>
|
||||
#include <util/rbf.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, bool rbf)
|
||||
{
|
||||
|
@ -280,22 +281,22 @@ void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
|
|||
int nHashType = ParseSighashString(hashType);
|
||||
|
||||
// Script verification errors
|
||||
std::map<int, std::string> input_errors;
|
||||
std::map<int, bilingual_str> input_errors;
|
||||
|
||||
bool complete = SignTransaction(mtx, keystore, coins, nHashType, input_errors);
|
||||
SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
|
||||
}
|
||||
|
||||
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, std::string>& input_errors, UniValue& result)
|
||||
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result)
|
||||
{
|
||||
// Make errors UniValue
|
||||
UniValue vErrors(UniValue::VARR);
|
||||
for (const auto& err_pair : input_errors) {
|
||||
if (err_pair.second == "Missing amount") {
|
||||
if (err_pair.second.original == "Missing amount") {
|
||||
// This particular error needs to be an exception for some reason
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing amount for %s", coins.at(mtx.vin.at(err_pair.first).prevout).out.ToString()));
|
||||
}
|
||||
TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second);
|
||||
TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second.original);
|
||||
}
|
||||
|
||||
result.pushKV("hex", EncodeHexTx(CTransaction(mtx)));
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct bilingual_str;
|
||||
class FillableSigningProvider;
|
||||
class UniValue;
|
||||
struct CMutableTransaction;
|
||||
|
@ -25,7 +26,7 @@ class SigningProvider;
|
|||
* @param result JSON object where signed transaction results accumulate
|
||||
*/
|
||||
void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result);
|
||||
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, std::string>& input_errors, UniValue& result);
|
||||
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result);
|
||||
|
||||
/**
|
||||
* Parse a prevtxs UniValue array and get the map of coins from it
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <script/signingprovider.h>
|
||||
#include <script/standard.h>
|
||||
#include <uint256.h>
|
||||
#include <util/translation.h>
|
||||
#include <util/vector.h>
|
||||
|
||||
typedef std::vector<unsigned char> valtype;
|
||||
|
@ -626,7 +627,7 @@ bool IsSegWitOutput(const SigningProvider& provider, const CScript& script)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, int nHashType, std::map<int, std::string>& input_errors)
|
||||
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, int nHashType, std::map<int, bilingual_str>& input_errors)
|
||||
{
|
||||
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
|
||||
|
||||
|
@ -658,7 +659,7 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
|
|||
CTxIn& txin = mtx.vin[i];
|
||||
auto coin = coins.find(txin.prevout);
|
||||
if (coin == coins.end() || coin->second.IsSpent()) {
|
||||
input_errors[i] = "Input not found or already spent";
|
||||
input_errors[i] = _("Input not found or already spent");
|
||||
continue;
|
||||
}
|
||||
const CScript& prevPubKey = coin->second.out.scriptPubKey;
|
||||
|
@ -674,7 +675,7 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
|
|||
|
||||
// amount must be specified for valid segwit signature
|
||||
if (amount == MAX_MONEY && !txin.scriptWitness.IsNull()) {
|
||||
input_errors[i] = "Missing amount";
|
||||
input_errors[i] = _("Missing amount");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -682,12 +683,12 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
|
|||
if (!VerifyScript(txin.scriptSig, prevPubKey, &txin.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount, txdata, MissingDataBehavior::FAIL), &serror)) {
|
||||
if (serror == SCRIPT_ERR_INVALID_STACK_OPERATION) {
|
||||
// Unable to sign input and verification failed (possible attempt to partially sign).
|
||||
input_errors[i] = "Unable to sign input, invalid stack size (possibly missing key)";
|
||||
input_errors[i] = Untranslated("Unable to sign input, invalid stack size (possibly missing key)");
|
||||
} else if (serror == SCRIPT_ERR_SIG_NULLFAIL) {
|
||||
// Verification failed (possibly due to insufficient signatures).
|
||||
input_errors[i] = "CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)";
|
||||
input_errors[i] = Untranslated("CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)");
|
||||
} else {
|
||||
input_errors[i] = ScriptErrorString(serror);
|
||||
input_errors[i] = Untranslated(ScriptErrorString(serror));
|
||||
}
|
||||
} else {
|
||||
// If this input succeeds, make sure there is no error set for it
|
||||
|
|
|
@ -21,6 +21,7 @@ class CScript;
|
|||
class CTransaction;
|
||||
class SigningProvider;
|
||||
|
||||
struct bilingual_str;
|
||||
struct CMutableTransaction;
|
||||
|
||||
/** Interface for signature creators. */
|
||||
|
@ -178,6 +179,6 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script);
|
|||
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script);
|
||||
|
||||
/** Sign the CMutableTransaction */
|
||||
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* provider, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors);
|
||||
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* provider, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors);
|
||||
|
||||
#endif // BITCOIN_SCRIPT_SIGN_H
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
@ -135,7 +136,7 @@ FUZZ_TARGET_INIT(script_sign, initialize_script_sign)
|
|||
}
|
||||
coins[*outpoint] = *coin;
|
||||
}
|
||||
std::map<int, std::string> input_errors;
|
||||
std::map<int, bilingual_str> input_errors;
|
||||
(void)SignTransaction(sign_transaction_tx_to, &provider, coins, fuzzed_data_provider.ConsumeIntegral<int>(), input_errors);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -294,7 +294,7 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
|
|||
input_coins.insert({outpoint_to_spend, utxo_to_spend});
|
||||
// - Default signature hashing type
|
||||
int nHashType = SIGHASH_ALL;
|
||||
std::map<int, std::string> input_errors;
|
||||
std::map<int, bilingual_str> input_errors;
|
||||
assert(SignTransaction(mempool_txn, &keystore, input_coins, nHashType, input_errors));
|
||||
|
||||
// If submit=true, add transaction to the mempool.
|
||||
|
|
|
@ -3389,7 +3389,7 @@ RPCHelpMan signrawtransactionwithwallet()
|
|||
int nHashType = ParseSighashString(request.params[2]);
|
||||
|
||||
// Script verification errors
|
||||
std::map<int, std::string> input_errors;
|
||||
std::map<int, bilingual_str> input_errors;
|
||||
|
||||
bool complete = pwallet->SignTransaction(mtx, coins, nHashType, input_errors);
|
||||
UniValue result(UniValue::VOBJ);
|
||||
|
|
|
@ -592,7 +592,7 @@ bool LegacyScriptPubKeyMan::CanProvide(const CScript& script, SignatureData& sig
|
|||
}
|
||||
}
|
||||
|
||||
bool LegacyScriptPubKeyMan::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const
|
||||
bool LegacyScriptPubKeyMan::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const
|
||||
{
|
||||
return ::SignTransaction(tx, this, coins, sighash, input_errors);
|
||||
}
|
||||
|
@ -2046,7 +2046,7 @@ bool DescriptorScriptPubKeyMan::CanProvide(const CScript& script, SignatureData&
|
|||
return IsMine(script);
|
||||
}
|
||||
|
||||
bool DescriptorScriptPubKeyMan::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const
|
||||
bool DescriptorScriptPubKeyMan::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const
|
||||
{
|
||||
std::unique_ptr<FlatSigningProvider> keys = std::make_unique<FlatSigningProvider>();
|
||||
for (const auto& coin_pair : coins) {
|
||||
|
|
|
@ -230,7 +230,7 @@ public:
|
|||
virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; }
|
||||
|
||||
/** Creates new signatures and adds them to the transaction. Returns whether all inputs were signed */
|
||||
virtual bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const { return false; }
|
||||
virtual bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const { return false; }
|
||||
/** Sign a message with the given script */
|
||||
virtual SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const { return SigningResult::SIGNING_FAILED; };
|
||||
/** Adds script and derivation path information to a PSBT, and optionally signs it. */
|
||||
|
@ -396,7 +396,7 @@ public:
|
|||
|
||||
bool CanProvide(const CScript& script, SignatureData& sigdata) override;
|
||||
|
||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const override;
|
||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const override;
|
||||
SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override;
|
||||
TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const override;
|
||||
|
||||
|
@ -601,7 +601,7 @@ public:
|
|||
|
||||
bool CanProvide(const CScript& script, SignatureData& sigdata) override;
|
||||
|
||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const override;
|
||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const override;
|
||||
SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override;
|
||||
TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const override;
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ static CMutableTransaction TestSimpleSpend(const CTransaction& from, uint32_t in
|
|||
keystore.AddKey(key);
|
||||
std::map<COutPoint, Coin> coins;
|
||||
coins[mtx.vin[0].prevout].out = from.vout[index];
|
||||
std::map<int, std::string> input_errors;
|
||||
std::map<int, bilingual_str> input_errors;
|
||||
BOOST_CHECK(SignTransaction(mtx, &keystore, coins, SIGHASH_ALL, input_errors));
|
||||
return mtx;
|
||||
}
|
||||
|
|
|
@ -1822,11 +1822,11 @@ bool CWallet::SignTransaction(CMutableTransaction& tx) const
|
|||
const CWalletTx& wtx = mi->second;
|
||||
coins[input.prevout] = Coin(wtx.tx->vout[input.prevout.n], wtx.m_confirm.block_height, wtx.IsCoinBase());
|
||||
}
|
||||
std::map<int, std::string> input_errors;
|
||||
std::map<int, bilingual_str> input_errors;
|
||||
return SignTransaction(tx, coins, SIGHASH_DEFAULT, input_errors);
|
||||
}
|
||||
|
||||
bool CWallet::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const
|
||||
bool CWallet::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const
|
||||
{
|
||||
// Try to sign with all ScriptPubKeyMans
|
||||
for (ScriptPubKeyMan* spk_man : GetAllScriptPubKeyMans()) {
|
||||
|
|
|
@ -563,7 +563,7 @@ public:
|
|||
/** Fetch the inputs and sign with SIGHASH_ALL. */
|
||||
bool SignTransaction(CMutableTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
/** Sign the tx given the input coins and sighash. */
|
||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const;
|
||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const;
|
||||
SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue