Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

In get_account_data() and get_input(), it is giving balance 0 #212

Closed
rav1112 opened this issue Nov 30, 2018 · 14 comments
Closed

In get_account_data() and get_input(), it is giving balance 0 #212

rav1112 opened this issue Nov 30, 2018 · 14 comments
Assignees
Labels

Comments

@rav1112
Copy link

rav1112 commented Nov 30, 2018

While calling get_account_data() and get_input(), both gives balance zero. But when i am calling individual address get_balance, then there is balance in it.

@todofixthis todofixthis self-assigned this Nov 30, 2018
@todofixthis
Copy link
Contributor

Hi @rav1112 my first thought is that, for some reason (possibly because of a snapshot), the 0th address from that seed doesn't have any transactions on the Tangle (see https://iota.stackexchange.com/a/735/283 for more information).

Try calling api.get_new_addresses(index=0, count=1, security_level=<security level>) and passing the corresponding address to api.find_transactions(addresses=[<address>]).

@rav1112
Copy link
Author

rav1112 commented Dec 3, 2018

I tried for api.find_transactions i got this ----- {'hashes': [], 'duration': 45} It doesnt have any transaction. Actually I have made private tangle.

@todofixthis
Copy link
Contributor

Gotcha. That may be why get_account_data() and get_inputs() aren't returning any results; the library will start with address at index 0, and it will continue to scan for addresses until it finds one without any transactions.

If the address at index 0 doesn't have any transactions, then PyOTA assumes that the seed has a zero balance.

A workaround for this is to specify the start parameter when calling one of those methods. This will set the starting index to scan from. E.g., to start with the 2nd address:

gad_result = api.get_account_data(start=2, security_level=<security level>)

@rav1112
Copy link
Author

rav1112 commented Dec 4, 2018

But I have balance in the index 0 itself...

@todofixthis
Copy link
Contributor

todofixthis commented Dec 4, 2018

Gotcha. In that case, try calling get_account_data() with a specific value for the stop parameter; the default stop=None is what triggers the transaction check.

For example, to load data for addresses 0-2, call get_account_data() like this:

gad_result = api.get_account_data(start=0, stop=3, security_level=<security level>)

Note that stop should be set to 1 more than the index you want to stop at (this is similar to how slices work).

@todofixthis
Copy link
Contributor

Hey @rav1112 it's been a little while; I'm going to go ahead and close this issue. If you are still having problems with this, feel free to re-open this issue so that we can have a look 😺

@rav1112
Copy link
Author

rav1112 commented Dec 28, 2018

Even trying for the gad_result = api.get_account_data(start=0, stop=3, security_level=<security level>)
I am getting 0 balance. Even I am not able to send the iota.

@todofixthis
Copy link
Contributor

Hmm. Ok, I'm leaning pretty heavily towards the "addresses have no transactions" hypothesis.

get_account_data() will only return a result if it can find at least one transaction for the generated addresses (see #217 for more info).

Does get_inputs(start=0, stop=3, security_level=<security level>) return a non-zero result? If so, I think we can pretty conclusively blame this issue on absence of transactions.

@todofixthis todofixthis reopened this Dec 28, 2018
@rav1112
Copy link
Author

rav1112 commented Jan 3, 2019

Yes i got non zero value by giving this command get_inputs(start=0, stop=3, security_level=<security level>). But I want to know how can i manage after having transactions?
Also if i do get_inputs() then i got null value how will i get whole balance of that account if i use stop in the get_inputs.

@todofixthis
Copy link
Contributor

todofixthis commented Jan 3, 2019

Cool. Once the addresses have transactions, get_account_data() should work as expected; the workaround is only necessary if addresses don't have any transactions (see this stackexchange post for more info).

I think in this scenario, it may be useful for the application to maintain state — persisting the list of addresses rather than relying on a tangle scan each time. Then the app can call get_balances() to get the account balance (note that the node imposes a limit on the number of addresses that can be included in that request; see #138 for more info).

As a bonus, maintaining state should boost performance significantly when reloading data for known addresses, as a single call to get_balances() should be much faster than get_account_data() (which sends lots of other API requests internally).

@rav1112
Copy link
Author

rav1112 commented Jan 10, 2019

I understand your point. But address to have transaction i need to send the tokens but i am not able to send it as it is coming threshold value is not matching like this (iota.adapter.BadApiResponse: Accumulated balance 0 is less than threshold 10 (exc.context contains more information).).
As in the backend you r not getting the balance. so i am not able to understand hot to get the transcation so that my address balance can be addressed

@todofixthis
Copy link
Contributor

Ah, sorry; I used the term "transaction" ambiguously here. On the Tangle, a transaction does not have to transfer IOTAs; it is allowed to send a transaction with value=0.

If an application sends a transaction with value=0, then the library does not have to collect inputs.

So for example, if you have addresses A, B and C that you want to check with get_account_data(), then the following code will publish the necessary transactions to the Tangle:

api.send_transfer([
    ProposedTransaction(Address("A"), 0),
    ProposedTransaction(Address("B"), 0),
    ProposedTransaction(Address("C"), 0),
])

Note that the above code will work using any seed, even one that doesn't own any IOTAs.

Once the transactions are published, get_account_data() will then be able to find A, B, and C (as long as those are the first 3 addresses of your seed).

This is, incidentally, what the "ATTACH TO TANGLE" button in the old IOTA wallet used to do.

@rav1112
Copy link
Author

rav1112 commented Jan 17, 2019

Thanks

@todofixthis
Copy link
Contributor

No worries! I will go ahead and close this issue; if this issue resurfaces, feel free to reopen 😺

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants