//------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled Copyright (c) 2012-2014 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #include #include #include #include #include #include #include #include #include #include namespace ripple { static NetworkOPs::FailHard getFailHard (RPC::Context const& context) { return NetworkOPs::doFailHard ( context.params.isMember ("fail_hard") && context.params["fail_hard"].asBool ()); } // { // tx_json: , // secret: // } Json::Value doSubmit (RPC::Context& context) { context.loadType = Resource::feeMediumBurdenRPC; if (!context.params.isMember (jss::tx_blob)) { auto const failType = getFailHard (context); return RPC::transactionSubmit ( context.params, failType, context.role, context.ledgerMaster.getValidatedLedgerAge(), context.app, RPC::getProcessTxnFn (context.netOps)); } Json::Value jvResult; std::pair ret(strUnHex (context.params[jss::tx_blob].asString ())); if (!ret.second || !ret.first.size ()) return rpcError (rpcINVALID_PARAMS); SerialIter sitTrans (makeSlice(ret.first)); std::shared_ptr stpTrans; try { stpTrans = std::make_shared (std::ref (sitTrans)); } catch (std::exception& e) { jvResult[jss::error] = "invalidTransaction"; jvResult[jss::error_exception] = e.what (); return jvResult; } { if (!context.app.checkSigs()) forceValidity(context.app.getHashRouter(), stpTrans->getTransactionID(), Validity::SigGoodOnly); auto validity = checkValidity(context.app.getHashRouter(), *stpTrans, context.ledgerMaster.getCurrentLedger()->rules(), context.app.config()); if (validity.first != Validity::Valid) { jvResult[jss::error] = "invalidTransaction"; jvResult[jss::error_exception] = "fails local checks: " + validity.second; return jvResult; } } std::string reason; auto tpTrans = std::make_shared ( stpTrans, reason, context.app); if (tpTrans->getStatus() != NEW) { jvResult[jss::error] = "invalidTransaction"; jvResult[jss::error_exception] = "fails local checks: " + reason; return jvResult; } try { auto const failType = getFailHard (context); context.netOps.processTransaction ( tpTrans, isUnlimited (context.role), true, failType); } catch (std::exception& e) { jvResult[jss::error] = "internalSubmit"; jvResult[jss::error_exception] = e.what (); return jvResult; } try { jvResult[jss::tx_json] = tpTrans->getJson (0); jvResult[jss::tx_blob] = strHex ( tpTrans->getSTransaction ()->getSerializer ().peekData ()); if (temUNCERTAIN != tpTrans->getResult ()) { std::string sToken; std::string sHuman; transResultInfo (tpTrans->getResult (), sToken, sHuman); jvResult[jss::engine_result] = sToken; jvResult[jss::engine_result_code] = tpTrans->getResult (); jvResult[jss::engine_result_message] = sHuman; } return jvResult; } catch (std::exception& e) { jvResult[jss::error] = "internalJson"; jvResult[jss::error_exception] = e.what (); return jvResult; } } } // ripple