java-stellar-sdk
java-stellar-sdk copied to clipboard
Unify and empower streaming api
Currently the streaming api has pretty bad ergonomics. I was trying to stream payment operations and it looks like server.payments().stream returns an OperationResponse which doesn't have any information available to it. I can use server.transactions().stream which gives me a TransactionResponse and that lets me use the envelope xdr to get all the information about the actual operations in one go. OperationResponse makes me do a secondary request to get any info.
Also, TransactionResponse (and OperationResponse when it gets the ability) should have a way to get the Transaction object without parsing the XDR manually.
Maybe I misunderstood what you mean, but we can get useful information from server.payments().stream.
import org.stellar.sdk.Server;
import org.stellar.sdk.requests.EventListener;
import org.stellar.sdk.requests.PaymentsRequestBuilder;
import org.stellar.sdk.responses.operations.CreateAccountOperationResponse;
import org.stellar.sdk.responses.operations.OperationResponse;
import org.stellar.sdk.responses.operations.PaymentOperationResponse;
import shadow.com.google.common.base.Optional;
public class StellarDemo {
public static void main(String[] args) {
Server server = new Server("https://horizon.stellar.org");
PaymentsRequestBuilder paymentsRequest = server.payments().cursor("now");
paymentsRequest.stream(new EventListener<>() {
@Override
public void onEvent(OperationResponse operationResponse) {
if (operationResponse instanceof PaymentOperationResponse) {
PaymentOperationResponse paymentOperationResponse = (PaymentOperationResponse) operationResponse;
System.out.println("Send from: " + paymentOperationResponse.getFrom());
// Get other information
}
if (operationResponse instanceof CreateAccountOperationResponse) {
CreateAccountOperationResponse createAccountOperationResponse = (CreateAccountOperationResponse) operationResponse;
System.out.println("Funder: " + createAccountOperationResponse.getFunder());
// Get other information
}
// Path Payment and Account Merge
}
@Override
public void onFailure(Optional<Throwable> optional, Optional<Integer> optional1) {
}
});
}
}
How do i get the memo?
Memo does not appear in Horizon's response, and we may need another HTTP request if we need it.
Michael Feldstein [email protected] 于2019年9月25日周三 下午10:21写道:
How do i get the memo?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stellar/java-stellar-sdk/issues/237?email_source=notifications&email_token=AASCHEZMHCAMBMW4BD2RZQ3QLNXYNA5CNFSM4IOP4BNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7SCXQY#issuecomment-535047107, or mute the thread https://github.com/notifications/unsubscribe-auth/AASCHEYJJY7J3DHS5RFLBW3QLNXYNANCNFSM4IOP4BNA .