@Override public void run() { flow.destination(destination); } };
@Override public void run() { flow.destinationAmountCurrency(destinationCurrency); } };
@Override public void run() { flow.destinationAmountValue(destinationAmountValue); } };
private void unsubscribeFromClientEvents() { // client.removeListener(Client.OnMessage.class, onClientMessage); // client.removeListener(Client.OnSendMessage.class, onClientSendMessage); if (flow != null) { flow.abort(); flow.unsubscribeFromClientEvents(); } }
public void abort() { requestPathFindClose(); ignoreCurrentRequestAndPublishStaleState(); }
public static void example(Client client, String secret) { Account account = client.accountFromSeed(secret); PaymentFlow flow = new PaymentFlow(client); TransactionManager tm = account.transactionManager(); flow.source(account) .destination(destination) .destinationAmountValue(amount) .destinationAmountCurrency(USD) .onAlternatives((alts) -> { if (alts.size() > 0) { flow.createPayment(alts.get(0), slippageFactor) .onError(PaymentPaths::onError) .onValidated(PaymentPaths::onValidated);
public void makePathFindRequestIfCan() { ignoreCurrentRequestAndPublishStaleState(); if (tooLittleInfoForPathFindRequest()) { return; Alternatives alts = constructInitialAlternatives(); if (!alts.isEmpty()) { emit(OnAlternatives.class, alts); pathFind.request(); emit(OnPathFind.class, pathFind);
/** * Thread: ui thread */ private void setupClient() { client = ((RippleApplication) getApplication()).getClient(); flow = new PaymentFlow(client); account = null; }
private void ignoreCurrentRequestAndPublishStaleState() { pathFind = null; if (alternatives != null) { emit(OnAlternativesStale.class, alternatives); } // TODO invalidate existing alternatives }
private Alternatives constructInitialAlternatives() { return constructAlternatives(null, null); }
public ManagedTxn createPayment(Alternative alternative, BigDecimal sendMaxMultiplier) { Amount sourceAmount = alternative.sourceAmount; boolean hasPaths = alternative.hasPaths(); ignoreCurrentRequestAndPublishStaleState(); // Cancel the path finding request. requestPathFindClose(); Payment payment = new Payment(); ManagedTxn managed = srcAccount.transactionManager().manage(payment); payment.destination(dest); if (hasPaths) { // A payment with an empty, but specified paths is invalid payment.paths(alternative.paths); } // If we are sending XRP directly it's pointless to specify SendMax if (!alternative.directXRP()) { payment.sendMax(sourceAmount.multiply(sendMaxMultiplier)); } payment.amount(destinationAmount); return managed; }
@Override public void called(JSONObject jsonObject) { int id = jsonObject.getInt("id"); if (pathFind != null && id == pathFind.id) { emit(OnAlternatives.class, constructAlternatives(jsonObject.getJSONArray("alternatives"), alternatives)); } } };
@Override public void called(Response response) { if (response.succeeded && response.request == pathFind) { try { JSONArray alternatives = response.result.getJSONArray("alternatives"); emit(OnAlternatives.class, constructAlternatives(alternatives, null)); } catch (JSONException e) { throw new RuntimeException(e); } } } });
@Override public void called(Response response) { if (response.succeeded) { JSONObject accountJSON = response.result.optJSONObject("account_data"); STObject accountData = STObject.translate.fromJSONObject(accountJSON); if (PaymentFlow.this.src == id) { srcInfo = accountData; } else if (PaymentFlow.this.dest == id) { destInfo = accountData; emit(OnDestInfo.class, destInfo); } } } });