Skip to content

Commit 4b0c718

Browse files
committed
Accumulate result UniValue in SignTransaction
SignTransaction will be called multiple times in the future. Pass it a result UniValue so that it can accumulate the results of multiple SignTransaction passes.
1 parent bc38bb9 commit 4b0c718

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,9 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
763763
// Parse the prevtxs array
764764
ParsePrevouts(request.params[2], &keystore, coins);
765765

766-
return SignTransaction(mtx, &keystore, coins, request.params[3]);
766+
UniValue result(UniValue::VOBJ);
767+
SignTransaction(mtx, &keystore, coins, request.params[3], result);
768+
return result;
767769
}
768770

769771
static UniValue sendrawtransaction(const JSONRPCRequest& request)

src/rpc/rawtransaction_util.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst
268268
}
269269
}
270270

271-
UniValue SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType)
271+
void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result)
272272
{
273273
int nHashType = ParseSighashString(hashType);
274274

@@ -319,12 +319,12 @@ UniValue SignTransaction(CMutableTransaction& mtx, const SigningProvider* keysto
319319
}
320320
bool fComplete = vErrors.empty();
321321

322-
UniValue result(UniValue::VOBJ);
323322
result.pushKV("hex", EncodeHexTx(CTransaction(mtx)));
324323
result.pushKV("complete", fComplete);
325324
if (!vErrors.empty()) {
325+
if (result.exists("errors")) {
326+
vErrors.push_backV(result["errors"].getValues());
327+
}
326328
result.pushKV("errors", vErrors);
327329
}
328-
329-
return result;
330330
}

src/rpc/rawtransaction_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class SigningProvider;
2121
* @param keystore Temporary keystore containing signing keys
2222
* @param coins Map of unspent outputs
2323
* @param hashType The signature hash type
24-
* @returns JSON object with details of signed transaction
24+
* @param result JSON object where signed transaction results accumulate
2525
*/
26-
UniValue SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType);
26+
void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result);
2727

2828
/**
2929
* Parse a prevtxs UniValue array and get the map of coins from it

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3281,7 +3281,9 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
32813281
// Parse the prevtxs array
32823282
ParsePrevouts(request.params[1], nullptr, coins);
32833283

3284-
return SignTransaction(mtx, &*pwallet->GetLegacyScriptPubKeyMan(), coins, request.params[2]);
3284+
UniValue result(UniValue::VOBJ);
3285+
SignTransaction(mtx, &*pwallet->GetLegacyScriptPubKeyMan(), coins, request.params[2], result);
3286+
return result;
32853287
}
32863288

32873289
static UniValue bumpfee(const JSONRPCRequest& request)

0 commit comments

Comments
 (0)