Soneso / stellar_flutter_sdk

Stellar SDK for flutter - dart, Stellar, Horizon, Soneso
MIT License
71 stars 33 forks source link

Can't get single account stream to work #61

Closed jopmiddelkamp closed 1 year ago

jopmiddelkamp commented 1 year ago

Hi,

I'm trying to add the single account stream only the EventSource class does not seem te work. You can see that I've added some unit test in the draft PR.

https://github.com/Soneso/stellar_flutter_sdk/pull/60/files

When I run this script while doing the unit test I do see the javascript stream to output the expected data. Only the stream in the unit test only shows the first account reponse event.


var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

var accountHandler = function (accountResponse) {
    console.log("");
    console.log("################################");
    console.log("### accountResponse received ###");
    console.log("################################");
    console.log("");
    console.log(accountResponse);
};

var es = server.accounts().accountId("GDUIRZTI6VPHOUIFADD5QFRUVDSQ77K6VHAM76WYVTZ7UIQAR2LCXHFZ").stream({
    onmessage: accountHandler
});

console.log("Stream started");

Is this a known issue?

christian-rogobete commented 1 year ago

Hi @jopmiddelkamp thank you for reporting this issue. I will check it next week.

christian-rogobete commented 1 year ago

Hi @jopmiddelkamp, currently I don't have issues with the streaming. I added an example (test case) for you in this commit: https://github.com/Soneso/stellar_flutter_sdk/commit/aaef528d8d11c5910aaa4d126f3984d791648a68

You can find it here: https://github.com/Soneso/stellar_flutter_sdk/blob/aaef528d8d11c5910aaa4d126f3984d791648a68/test/account_test.dart#L280

Another example that already existed is here: https://github.com/Soneso/stellar_flutter_sdk/blob/aaef528d8d11c5910aaa4d126f3984d791648a68/test/payments_test.dart#L1027

Hope this helps

jopmiddelkamp commented 1 year ago

Hmm your unit test works so the EventSource seem to be working. I'll change my issue title.

Compared your transactions stream to my account stream and I can't find any difference other then you stream is working and the one I tried to add isn't.. Can you spot anything that I've done wrong maybe?

christian-rogobete commented 1 year ago

Hello,

I am not sure what you want to achieve. But I assume you want streaming for the account details. However, this Horizon endpoint does not offer streaming. Instead, I would use transactions streaming for the given account and as soon as a transaction event is received, I would reload the account details (only transactions can change accounts).

See (streaming mentioned): https://developers.stellar.org/api/resources/get-transactions-by-account-id

See (no streaming mentioned): https://developers.stellar.org/api/resources/retrieve-an-account

jopmiddelkamp commented 1 year ago

Ahh ok, I thought that steaming should be available because I saw it in the laboratory combined with the fact that I got a stream going with the JavaScript SDK.

Screenshot 2023-06-13 at 09 51 31

But I'll just create another solution with the transaction stream.

Thanks Christian.

christian-rogobete commented 1 year ago

yw, thanks for bringing this up