Skip to content

Commit

Permalink
Output from sign, submit etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 26, 2023
1 parent aa6de60 commit 76eee5a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/ripple/app/misc/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ class Transaction : public std::enable_shared_from_this<Transaction>,
validatedLedger, fee, accountSeq, availableSeq);
}

/// Same as similar overload for STTx::getJson
Json::Value
getJson(JsonOptions options, bool binary = false) const;
getJson(
JsonOptions options,
bool binary = false,
std::optional<std::reference_wrapper<std::string>> hash = {}) const;

// Information used to locate a transaction.
// Contains a nodestore hash and ledger sequence pair if the transaction was
Expand Down
7 changes: 5 additions & 2 deletions src/ripple/app/misc/impl/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,12 @@ Transaction::load(

// options 1 to include the date of the transaction
Json::Value
Transaction::getJson(JsonOptions options, bool binary) const
Transaction::getJson(
JsonOptions options,
bool binary,
std::optional<std::reference_wrapper<std::string>> hash) const
{
Json::Value ret(mTransaction->getJson(JsonOptions::none, binary));
Json::Value ret(mTransaction->getJson(JsonOptions::none, binary, hash));

if (mInLedger)
{
Expand Down
1 change: 1 addition & 0 deletions src/ripple/rpc/handlers/SignFor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ doSignFor(RPC::JsonContext& context)

auto ret = RPC::transactionSignFor(
context.params,
context.apiVersion,
failType,
context.role,
context.ledgerMaster.getValidatedLedgerAge(),
Expand Down
1 change: 1 addition & 0 deletions src/ripple/rpc/handlers/SignHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ doSign(RPC::JsonContext& context)

auto ret = RPC::transactionSign(
context.params,
context.apiVersion,
failType,
context.role,
context.ledgerMaster.getValidatedLedgerAge(),
Expand Down
1 change: 1 addition & 0 deletions src/ripple/rpc/handlers/Submit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ doSubmit(RPC::JsonContext& context)

auto ret = RPC::transactionSubmit(
context.params,
context.apiVersion,
failType,
context.role,
context.ledgerMaster.getValidatedLedgerAge(),
Expand Down
1 change: 1 addition & 0 deletions src/ripple/rpc/handlers/SubmitMultiSigned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ doSubmitMultiSigned(RPC::JsonContext& context)

return RPC::transactionSubmitMultiSigned(
context.params,
context.apiVersion,
failType,
context.role,
context.ledgerMaster.getValidatedLedgerAge(),
Expand Down
25 changes: 19 additions & 6 deletions src/ripple/rpc/impl/TransactionSign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,21 @@ transactionConstructImpl(
}

static Json::Value
transactionFormatResultImpl(Transaction::pointer tpTrans)
transactionFormatResultImpl(Transaction::pointer tpTrans, unsigned apiVersion)
{
Json::Value jvResult;
try
{
jvResult[jss::tx_json] = tpTrans->getJson(JsonOptions::none);
if (apiVersion > 1)
{
std::string hash = {};
jvResult[jss::tx_json] =
tpTrans->getJson(JsonOptions::none, false, {std::ref(hash)});
jvResult[jss::hash] = hash;
}
else
jvResult[jss::tx_json] = tpTrans->getJson(JsonOptions::none);

jvResult[jss::tx_blob] =
strHex(tpTrans->getSTransaction()->getSerializer().peekData());

Expand Down Expand Up @@ -777,6 +786,7 @@ checkFee(
Json::Value
transactionSign(
Json::Value jvRequest,
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand Down Expand Up @@ -807,13 +817,14 @@ transactionSign(
if (!txn.second)
return txn.first;

return transactionFormatResultImpl(txn.second);
return transactionFormatResultImpl(txn.second, apiVersion);
}

/** Returns a Json::objectValue. */
Json::Value
transactionSubmit(
Json::Value jvRequest,
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand Down Expand Up @@ -853,7 +864,7 @@ transactionSubmit(
rpcINTERNAL, "Exception occurred during transaction submission.");
}

return transactionFormatResultImpl(txn.second);
return transactionFormatResultImpl(txn.second, apiVersion);
}

namespace detail {
Expand Down Expand Up @@ -943,6 +954,7 @@ sortAndValidateSigners(STArray& signers, AccountID const& signingForID)
Json::Value
transactionSignFor(
Json::Value jvRequest,
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand Down Expand Up @@ -1043,13 +1055,14 @@ transactionSignFor(
if (!txn.second)
return txn.first;

return transactionFormatResultImpl(txn.second);
return transactionFormatResultImpl(txn.second, apiVersion);
}

/** Returns a Json::objectValue. */
Json::Value
transactionSubmitMultiSigned(
Json::Value jvRequest,
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand Down Expand Up @@ -1236,7 +1249,7 @@ transactionSubmitMultiSigned(
rpcINTERNAL, "Exception occurred during transaction submission.");
}

return transactionFormatResultImpl(txn.second);
return transactionFormatResultImpl(txn.second, apiVersion);
}

} // namespace RPC
Expand Down
4 changes: 4 additions & 0 deletions src/ripple/rpc/impl/TransactionSign.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ getProcessTxnFn(NetworkOPs& netOPs)
Json::Value
transactionSign(
Json::Value params, // Passed by value so it can be modified locally.
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand All @@ -105,6 +106,7 @@ transactionSign(
Json::Value
transactionSubmit(
Json::Value params, // Passed by value so it can be modified locally.
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand All @@ -116,6 +118,7 @@ transactionSubmit(
Json::Value
transactionSignFor(
Json::Value params, // Passed by value so it can be modified locally.
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand All @@ -125,6 +128,7 @@ transactionSignFor(
Json::Value
transactionSubmitMultiSigned(
Json::Value params, // Passed by value so it can be modified locally.
unsigned apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Expand Down
8 changes: 6 additions & 2 deletions src/test/rpc/JSONRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2536,17 +2536,19 @@ class JSONRPC_test : public beast::unit_test::suite
// A list of all the functions we want to test.
using signFunc = Json::Value (*)(
Json::Value params,
unsigned int apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Application & app);
Application& app);

using submitFunc = Json::Value (*)(
Json::Value params,
unsigned int apiVersion,
NetworkOPs::FailHard failType,
Role role,
std::chrono::seconds validatedLedgerAge,
Application & app,
Application& app,
ProcessTransactionFn const& processTransaction,
RPC::SubmitSync sync);

Expand Down Expand Up @@ -2586,6 +2588,7 @@ class JSONRPC_test : public beast::unit_test::suite
assert(get<1>(testFunc) == nullptr);
result = signFn(
req,
1,
NetworkOPs::FailHard::yes,
testRole,
1s,
Expand All @@ -2597,6 +2600,7 @@ class JSONRPC_test : public beast::unit_test::suite
assert(submitFn != nullptr);
result = submitFn(
req,
1,
NetworkOPs::FailHard::yes,
testRole,
1s,
Expand Down

0 comments on commit 76eee5a

Please sign in to comment.