void createOffer(TestAccount& from, Amount const& in, Amount const& out, Ledger::pointer ledger, bool sign) { Json::Value tx_json = getCommonTransactionJson(from); tx_json[jss::TransactionType] = "OfferCreate"; tx_json[jss::TakerPays] = in.getJson(); tx_json[jss::TakerGets] = out.getJson(); STTx tx = parseTransaction(from, tx_json, sign); applyTransaction(ledger, tx, sign); }
Json::Value findPath(Ledger::pointer ledger, TestAccount const& src, TestAccount const& dest, std::vector<Currency> srcCurrencies, Amount const& dstAmount, beast::abstract_ostream& log, boost::optional<Json::Value> contextPaths) { int const level = 8; auto cache = std::make_shared<RippleLineCache>(ledger); STAmount saDstAmount; if (!amountFromJsonNoThrow(saDstAmount, dstAmount.getJson())) throw std::runtime_error( "!amountFromJsonNoThrow(saDstAmount, dstAmount.getJson())"); log << "Dst amount: " << saDstAmount; auto jvSrcCurrencies = Json::Value(Json::arrayValue); for (auto const& srcCurrency : srcCurrencies) { jvSrcCurrencies.append(srcCurrency.getJson()); } log << "Source currencies: " << jvSrcCurrencies; auto result = ripplePathFind(cache, src.pk, dest.pk, saDstAmount, ledger, jvSrcCurrencies, contextPaths, level); if(!result.first) throw std::runtime_error( "ripplePathFind find failed"); return result.second; }
void verifyBalance(Ledger::pointer ledger, TestAccount const& account, Amount const& amount) { auto sle = getLedgerEntryRippleState(ledger, account, amount.getIssuer(), amount.getCurrency()); if (!sle) throw std::runtime_error( "!sle"); STAmount amountReq; amountFromJsonNoThrow(amountReq, amount.getJson()); auto high = sle->getFieldAmount(sfHighLimit); auto balance = sle->getFieldAmount(sfBalance); if (high.getIssuer() == account.pk.getAccountID()) { balance.negate(); } if (balance != amountReq) throw std::runtime_error( "balance != amountReq"); }