Issue with unspents
Closed this issue · 6 comments
Hello, the issue is, a few days ago a successfully sent a transaction with the .send function. Today I tried again and got an error about unspents, so i did a little bit of debbuging and I found out that unspents do not get updated before the call to self.unspents
in the create_transaction function before the sanitizing, so I added or NetworkAPI.get_unspent(self.address)
here instead of or self.unspents
:
unspents, outputs = sanitize_tx_data(
unspents or NetworkAPI.get_unspent(self.address),
outputs,
fee or DEFAULT_FEE,
leftover or self.address,
combine=combine,
message=message,
compressed=self.is_compressed(),
custom_pushdata=custom_pushdata,
)
and now it works as it should, but obviously I have some doubts about this, can you help me figure out the issue?
The error I got is the following:
Traceback (most recent call last):
File "...", line 148, in ...
txid = self.__wallet.send([], fee = 1, message = binascii.unhexlify(msg))
File "C:\...\venv\lib\site-packages\bitcash\wallet.py", line 349, in send
unspents=unspents,
File "C:\...\venv\lib\site-packages\bitcash\wallet.py", line 293, in create_transaction
custom_pushdata=custom_pushdata,
File "C:\...\venv\lib\site-packages\bitcash\transaction.py", line 169, in sanitize_tx_data
raise ValueError("Transactions must have at least one unspent.")
ValueError: Transactions must have at least one unspent.
Could you provide a minimal reproducible example?
This
self.__wallet.send([], fee = 1, message = binascii.unhexlify(msg))
where the message is an hexadecimal string. That's all I did.
You need to call wallet.get_unspents()
before. Or wallet.get_balance()
. Does that solve the issue?
100% would solve the issue (and it does), but is it intended to work this way? And I don't know why it worked days ago.
Yes it is intended as per the docs https://pybitcash.github.io/bitcash/.
Maybe in a future major version, send could take care of collecting unspents. I am happy to receive pull requests and potentially include such a change later on.