pybitcash / bitcash Goto Github PK
View Code? Open in Web Editor NEWBitCash: Python Bitcoin Cash Library (fork of ofek's Bit)
Home Page: https://bitcash.dev
License: MIT License
BitCash: Python Bitcoin Cash Library (fork of ofek's Bit)
Home Page: https://bitcash.dev
License: MIT License
When trying to get details of an existing transaction on the Testnet the following error is raised:
Traceback (most recent call last):
File "4GetTxDetails.py", line 11, in
transaction=NetworkAPI.get_transaction_testnet("[redacted]")
File "/usr/local/lib/python3.6/dist-packages/bitcash/network/services.py", line 489, in get_transaction_testnet
return api_call(txid)
File "/usr/local/lib/python3.6/dist-packages/bitcash/network/services.py", line 298, in get_transaction_testnet
tx = Transaction(response['txid'], response['blockheight'],
KeyError: 'blockheight'
Steps taken with no success:
-Increased service timeout
Just working my way through the testing module. Wanting clarification around 8 failed tests.
1 fail in test_transactions.py - 1 fail due to long_message() - because of change from 40 bytes to 220 bytes limit. (see PR)
6 fails in network/test_services.py because CashExplorerBitcoinDotComAPI testnet functions don't actually exist.
Can't find. Setting fees at 22 Satoshis for high priority and 16 for low priority.
If someone can find one or a couple, would be much appreciated. Probably will matter more 6+ months out from now.
https://github.com/sporestack/bitcash/blob/master/bitcash/network/fees.py
I spent most of today trying to implement message signing in a portable manner so that bitcoind or Electron-Cash can be used to verify the message, without success.
I've made it as far as constructing the message in the same manner and double-hashing it so the exact same hash is sent to the underlying wallet._pk signing function (and passing hash=None
since it's already been hashed manually) and verified this is the same hash generated by bitcoind before it calls secp256k1_ecdsa_sign_recoverable
, but that's as far as I get. I am simply unable to produce the same signature or one that bitcoind can verify.
My hunch is that either BitCash does not generate a recoverable signature or the nonce functions are different. This is where things start to go over my head.
If this is not possible, I am wondering if we could at least support a recoverable signing mechanism so that the person verifying does not need the full public key, but simply the cash address (hashed key) like bitcoind and the wallets support. If that were possible then I don't necessarily need it to be verifiable outside of this library.
Anybody have any insight to this? As a last resort I'll keep searching for an alternative library that can do this and I'll have to use that for this purpose, but I would prefer to have it incorporated in here.
I have a function for moving all funds of an wallet to another wallet.
The code is following.
key.send([], unspents=key.get_unspents(), leftover=receive_address)
But it seems the max input counts was limited by 10 inputs. So it did not move all the balance.
https://explorer.bitcoin.com/bch/tx/09af7b957aa7c80cf9b06f71d7546752287bea0689008bd774160f3f9df086ce
How could I raise the limit? Or is there a better way to do the sweeping?
I'm implementing BCH and SLP token into my tipperbot. The part of BCH was done with this nice lib. However, I didn't figure out the way to get balance and make transaction of SLP token with this lib. If it's possible, could you elaborate how to do it? Thank you.
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.
Right now our inputs are all messed up. Outputs look kind of okay.
Here's a transaction generated from this script:
import bitcash
key = bitcash.PrivateKeyTestnet('cU6s7jckL3bZUUkb3Q2CD9vNu8F1o58K5R5a3JFtidoccMbhEGKZ')
key.get_unspents()
print(key.address)
print(key.unspents)
print(key.create_transaction(([('n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi', 10000, 'satoshi')])))
Output:
#$ python3 test.py
muUFbvTKDEokGTVUjScMhw1QF2rtv5hxCz
[Unspent(amount=79449086, confirmations=72047, script='76a914990ef60d63b5b5964a1c2282061af45123e93fcb88ac', txid='1b461db5a015397c6ff05f4ecdd4c190fff675382d10390aa373a79268f478fc', txindex=1)]
0100000001fc78f46892a773a30a39102d3875f6ff90c1d4cd4e5ff06f7c3915a0b51d461b0100000000ffffffff0210270000000000001976a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac8211bc04000000001976a914990ef60d63b5b5964a1c2282061af45123e93fcb88ac00000000
Deserialized:
{
"inputs": [
{
"address": null,
"num_sig": 0,
"prevout_hash": "1b461db5a015397c6ff05f4ecdd4c190fff675382d10390aa373a79268f478fc",
"prevout_n": 1,
"pubkeys": [],
"scriptSig": "",
"sequence": 4294967295,
"signatures": {},
"type": "unknown",
"x_pubkeys": []
}
],
"lockTime": 0,
"outputs": [
{
"address": "1N8QYQNAD8PLEJjmCGGR8iN1iuR9yXtY1x",
"prevout_n": 0,
"scriptPubKey": "76a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac",
"type": 0,
"value": 10000
},
{
"address": "1ExJJsNLQDNVVM1s1sdyt1o5P3GC5r32UG",
"prevout_n": 1,
"scriptPubKey": "76a914990ef60d63b5b5964a1c2282061af45123e93fcb88ac",
"type": 0,
"value": 79434114
}
],
"version": 1
}
That was deserialized as mainnet so the addresses are wrong.
I ported this over from https://github.com/bjarnemagnussen/bit/tree/segwit, which is in turn a fork of ofek's bit library.
I am also using electron-cash as a reference: https://github.com/fyookball/electrum/blob/cash/lib/transaction.py
And I should probably understand this better: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
I dont know if it would make more sense to start with the original bit or the bit segwit branch. I think we need BIP-143 signatures and a 0x41 hash type for pay to public hash.
I am really lost on this. Would hugely appreciate help on this.
If you can get this library working (getting send() to work, ultimately), I'll pay you $300 USD equivalent of BCH.
Thanks,
Teran
After lots of testing, head-scratching, and aggravation, I find the following to be true:
I have not tested whether the above conditions hold true beyond the 2 web APIs used by BitCash or if they also hold when sending directly to a node. Also, these APIs react differently when the above conditions are not met.
The Bitcoin.com API will simply reject with HTTP status 400 when a transaction with OP_RETURN message size > 75 bytes is received, or if there is more than one OP_RETURN in the transaction vouts. The Blockdozer.com API will accept these, however they do not get relayed anywhere else as far as I can tell and simply remain unconfirmed for a long time (sometimes dropping off but other times reappearing).
Additional note: the Blockdozer API is a bit unreliable. It once returned status 504 (Gateway Timeout) even though a new unconfirmed transaction actually did appear on their site, though in BitCash this raises an exception, so no transaction id was returned. Unconfirmed transactions are showing up twice on Blockdozer. Also, I currently have a list of unconfirmed transactions on the Blockdozer site that are all showing a clearly bogus fee of 184467440737.0945 BCH!
After successfully broadcasting a transaction using the NetworkAPI.broadcast_tx() method, how do I get the txid for this transaction? Because it is not in the data returned. I would like to ask if there is a solution in bitcash. If not, I guess I need to rely on some APIs to decode the generated transaction tx_hex and get txid from it.But it will deal with very slowly.
This is a pretty bad situation as bitcash is being told everything is okay when it's not.
When I call key.address parameter, it returns PrivateKey, not address (found cashaddress solution)
also key.balance everytime returns 0
when trying to call key.get_unspents() after transaction, it crashes
File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/wallet.py", line 489, in get_unspents
self.unspents[:] = NetworkAPI.get_unspent_testnet(self.address)
File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 315, in get_unspent_testnet
return api_call(address)
File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 157, in get_unspent_testnet
for tx in r.json()
File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 157, in <listcomp>
for tx in r.json()
KeyError: 'scriptPubKey'
When I tried to send BCH to this address:
bitcoincash:pz5vmkpnxu7x4a5u9r0uftw0f42mqqxkgcjwwtjqgk
I got this error: P2SH does not correspond to a mainnet nor testnet P2PKH address
It seems the issue is from that the API doesn't handle the P2SH script locking address well?
It seems rest.bitcoin.com is so unstable lately. This situation makes my service relied on bitcash lib not usable. Is there any alternative way that I can recover this?
Some progress here: https://github.com/teran-mckinney/bitcash
I've been playing around with Bitcash sending memos and I found a bug.
Once a Bitcash wallet is fund, I can send an OP_RETURN message with the following command:
key.send([], message = "foobar", leftover = key.address)
But if I try a second time I get this error:
ConnectionError: Transaction broadcast failed, or Unspents were already used.
Status code is 400: the tx is not well constructed.
The error get solved if a request my wallet balance: key.get_balance()
Once the get_balance() function is executed, bitcash provides a different raw transaction and it works again. Maybe after sending the unspent UTXOs are not upgraded?
Suppose we have output which includes amount 0
eg:
outputs = [('bchtest:qp6lpagexzll90d9cpuk8ukyuxzughsr4upvy465vq', 1000), ('bchtest:qzy7t6pxfqfnad50cxm76dun60qzz5eua57xkqlj07', 0)]
If dest
is string there will be a TypeError
on the following line:
https://github.com/sporestack/bitcash/blob/master/bitcash/transaction.py#L195
TypeError: can't concat str to bytes
.
Please make sure that dest
is always bytes
eg. by:
dest.encode()
.
Thank you!
Traceback (most recent call last):
File "E:/zt_6.27/py2/testBCH6.py", line 8, in
print(key.get_unspents())
File "E:\zt_6.27\python\lib\site-packages\bitcash\wallet.py", line 489, in get_unspents
self.unspents[:] = NetworkAPI.get_unspent_testnet(self.address)
File "E:\zt_6.27\python\lib\site-packages\bitcash\network\services.py", line 319, in get_unspent_testnet
raise ConnectionError('All APIs are unreachable.')
ConnectionError: All APIs are unreachable.
I'm getting an error with get_unspents() roughly half the time. The problem seems to be that sometimes the BitcoinDotComAPI is called (which isn't working) and sometimes it's BitcoreAPI (which is). Can the BitcoinDotComAPI.get_unspent() method be removed from NetworkAPI?
Boundary conditions:
Test I made (and not made), both from my laptop with crappy connection both from a decent server:
Code:
#check the balance given a private key - called as python3 1generatePkey.py YourL0n4PriwaTeKeyiNwifFormaTheRe
from bitcash import wif_to_key
import sys
from bitcash import set_service_timeout
set_service_timeout(8)
arg=sys.argv[1]
key = wif_to_key(arg)
address=key.address
print ("private Key is:")
print(key)
print ("address is:")
print(address)
print("balance is")
print(key.get_balance('bch'))
Error returned:
private Key is:
<PrivateKeyTestnet: bchtest:myawesomekeyfilledwithworthlesstesenetcoins>
address is:
bchtest:qrgmdeufa7fxsrq32r9z3e3c5urp2tj6dctjn39lsg
balance is
Traceback (most recent call last):
File "2ImportAndCkeckBalance.py", line 20, in <module>
print(key.get_balance('bch'))
File "/usr/local/lib/python3.6/dist-packages/bitcash/wallet.py", line 484, in get_balance
self.unspents[:] = NetworkAPI.get_unspent_testnet(self.address)
File "/usr/local/lib/python3.6/dist-packages/bitcash/network/services.py", line 567, in get_unspent_testnet
return api_call(address)
File "/usr/local/lib/python3.6/dist-packages/bitcash/network/services.py", line 199, in get_unspent_testnet
r.raise_for_status() # pragma: no cover
File "/home/ludovico/.local/lib/python3.6/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 523 Server Error: for url: https://trest.bitcoin.com/v2/address/utxo/bchtest:qrgmdeufa7fxsrq32r9z3e3c5urp2tj6dctjn39lsg
Personal speculation:
Deleting my account. Sorry guys.
PrivateKey().get_balance('bch') returns string '0', instead of float (like key.balance), could be relevant for other APIs.
Or do we expect non float content?
So I tried to send a transaction with optional message field, but without an address and/or with 0 value, there is an error, if I put an address and a value > 0 it goes on but the final transaction has not a OP_RETURN (obviously(?)). Thanks for helping.
What do you think?
I want to sign the transaction offline before sending a transaction οΌat the same time, I can get the fee to broadcast the transaction. So that if the fee is too high, I can cancel sending.
I don't know how to actually generate a transaction, because all the introductions are simple.
Recently, the balances that I'm getting from key.get_balance() have been incorrect. Does anybody know what could be the issue?
Edit: Bitcoin.com may be having issues right now.
Please add a method to generate receive money links, eg:
key.request_money_uri(amount_bch=0.001, label="Product one", msg="thank you")
format:
bitcoincash:
This URI could be used for 3rd party QR generator library.
Currently, if a fee
argument is not passed to send()
or create_transaction()
, the function network.fees.get_fee()
is called and returns 2 (default fee of 2 satoshi per byte).
We could simplify the code by removing network.fees
as it is no longer needed with Bitcoin Cash (the fee is always predictable and does not change over time like BTC).
Instead, we could add the default argument of fee=1
to transaction.sanitize_tx_data()
.
What do you think @teran-mckinney?
Please push the latest release with the new RATES API on PyPI
So running nosetests will run tests/test_wallet.py which will try to send on testnet.
It makes this transaction: 0100000001fccf6f80010410c7a11b1447801e61ce2c11dae0c60f6952ecfa9e4a4f6c2ff0010000006a47304402201030c0e1e59b799d2cd49bfec5ea86925537a1b28a7add6b29ba315dd6ec057802205068b5962ee57c77512984f67725967bb34e4adc25cab26e7e8325171d4fdc5f4121033d5c2875c9bd116875a71a5db64cffcb13396b163d039b1d9327824891804334ffffffff0210270000000000001976a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88acfaa9b704000000001976a914990ef60d63b5b5964a1c2282061af45123e93fcb88ac00000000
Which looks valid when deserialized but Blockdozer says: Missing inputs. Code:-25
I tend to think it's a Blockdozer issue but will need to look into it more.
Broadcast TX on https://test-bch-insight.bitpay.com/ seems like it does absolutely nothing.
I want to keep my address's privatekey
I noticed that Travis CI often fails one of the jobs:
https://travis-ci.org/sporestack/bitcash/builds/633534082?utm_source=github_status&utm_medium=notification
Python 3.7 for example here but it sometimes is 3.6 or 5. I never get this locally.
It seems that it is always private_key.send
failing, I am not sure why. Maybe some jobs are concurrent and that messes the UTXO set for key.get_unspents
?
I will investigate that. If anyone has an idea please let me know π
When attempting to build and test the Bitcash library in an isolated environment, installing the development dependancies (needed for running tests) results in an error. Despite this error occurring, running python3 run_tests.py
afterward still does appear to work. I'm able to run all tests successfully.
virtualenv ./venv
python3 setup.py build
python3 setup.py install
pip3 install -r requirements-dev.txt
Traceback (most recent call last):
File "/Users/nick/dev/bfp/bitcash/venv/bin/pip3", line 8, in <module>
sys.exit(main())
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 73, in main
return command.main(cmd_args)
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 111, in main
return self._main(args)
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 226, in _main
self.handle_pip_version_check(options)
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 145, in handle_pip_version_check
session = self._build_session(
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 86, in _build_session
session = PipSession(
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/network/session.py", line 245, in __init__
self.headers["User-Agent"] = user_agent()
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/network/session.py", line 159, in user_agent
setuptools_version = get_installed_version("setuptools")
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 644, in get_installed_version
working_set = pkg_resources.WorkingSet()
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 567, in __init__
self.add_entry(entry)
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 623, in add_entry
for dist in find_distributions(entry, True):
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1983, in find_eggs_in_zip
if metadata.has_metadata('PKG-INFO'):
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1414, in has_metadata
return self._has(path)
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1854, in _has
return zip_path in self.zipinfo or zip_path in self._index()
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1731, in zipinfo
return self._zip_manifests.load(self.loader.archive)
File "/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1688, in load
mtime = os.stat(path).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/Users/nick/dev/bfp/bitcash/venv/lib/python3.9/site-packages/bitcash-0.6.1-py3.9.egg'
I've noticed that testnet data isn't being updated and I get wrong results when I query for address balance or transactions.
I've compared the results with http://testnet.imaginary.cash/ data and I found that bitcash testnet data is not updated.
Would be useful to know sources or add more ones.
key.get_balance('usd')
gives an error as the API url is incorrect.
'https://bitcashpay.com/api/rates/'
is called, but it should be 'https://bitpay.com/api/rates/'
. Also, BitPay defaults to BTC for crypto to fiat conversion, but they do give the BCH/BTC ratio in the same API call π.
The broken URL is located in network/rates.py
at line 102.
Is anyone going to be able to fix that?
Hi Teran! What are you up to these days?
What is the best way to contact you to chat privately? I am interested in maybe porting bitcash over to the latest system but I'm not sure what side of the fence you're on with that and just wanted to discuss around it a bit.
There are heaps of javascript libraries out there but I think it's really nice to have a python one - even if it's basic. You never know - some heavier hitters might be willing to help out if it got good enough.
Regards
Cyborg
I try some simple testnet transactions from a funded address, however it raises ValueError: Transactions must have at least one unspent.
get_balance()
method keeps returning 0.
Likely reason is the bitcoin.com testnet explorer is down (it shows no new block data and the latest transactions I can find there are from May 15th.)
Any option to use an alternative service?
Hello! Thanks a lot for your library!
I have the following problem, when I generate the instance of the PrivateKeyTestnet
and get the public address I got the address I cannot send money to:
>> key = PrivateKeyTestnet()
>> key.address
qq6pzzfpuf9uumjmeayfw9qtuy7w386kyy42pkdau8
Even if I compress it, I get the same error called One or more input or output is invalid
:
>> key = PrivateKeyTestnet(wif='cMqw...')
>> key.address
qpgdlktn6ltjgxd4dz63rtn6gk6dk0wnusth8axycv
When I send money (through ccoin-cash web-site) from my own test-net
address mntaWjMep9AVmssAg7bd9hEHmNsuLtZDSS
to another also mine, all goes fine.
>>> len('qpgdlktn6ltjgxd4dz63rtn6gk6dk0wnusth8axycv') == len('mntaWjMep9AVmssAg7bd9hEHmNsuLtZDSS')
False
Can you help me with this question or even with all process to create signed offline raw transaction through your library? Thanks a lot!
I think that providing a functionality to search strings inside op_return will be nice.
Using fountainhead.cash (BitDB for BCH) makes it easy.
I'm new to coding, but I've write a script to provide this functionality that could be later extended and even used for SLP tokens:
What do you think? Also, I believe that some things here could be cleaned a little, like fees. 1 sat/B is enough for BCH so fee calculation is not an issue.
I'm trying to prepare a transaction using "PrivateKeyTestnet.prepareTransaction".
The following code works as expected:
tx_data = PrivateKeyTestnet.prepare_transaction(key.address, [(key.address, amount, currency)], leftover=key.address)
I'm able to prepare the transaction and sign it. I then send the transaction with a rpc call to a node installed on my machine that broadcast it.
When I do the following I receive an error:
tx_data = PrivateKeyTestnet.prepare_transaction(key.address, [(key.address, amount, currency)], leftover=key.address, message=message)
Message is a str, as by documentation (https://pybitcash.github.io/bitcash/dev/api.html#bitcash.PrivateKey.prepare_transaction). I also tried sending a hex string.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\biotech4\Documents\Progetti\bch_interact\venv\lib\site-packages\bitcash\wallet.py", line 658, in prepare_transaction
return json.dumps(data, separators=(',', ':'))
File "C:\Users\biotech4\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 234, in dumps
return cls(
File "C:\Users\biotech4\AppData\Local\Programs\Python\Python38-32\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\biotech4\AppData\Local\Programs\Python\Python38-32\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\biotech4\AppData\Local\Programs\Python\Python38-32\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
I find an explanation in bitcash:
bitcash.network.fees import get_fee
Fee = get_fee(speed='medium')
Fee = 4
the fee displayed on the real network,let me name it realFee
Fee != realFee(904 satoshi)
What did bitcash do to calculate the value of realFee?
I want to get the actual fee before sending the transaction.
I look forward to your reply.
First of all, fantastic port of the bit library, things seem to be coming along nicely. This may fit into the dynamic fees problem, but I wanted to see if there was anything I could do to fix it in the meantime.
I have an app that receives transactions and processes the balances to result in changes for the application. The balance is then marked as processed and is (eventually) moved to a cold storage wallet. Often this is the entire balance of that wallet. My code looks something like:
processed_balance = get_processed_balance() # This is often the full balance of the wallet
if processed_balance > 0:
key = wif_to_key(get_priv_key())
print(key.get_unspents())
outputs = [
(
settings.COLD_STORAGE_WALLET,
processed_balance,
'bch'
),
]
key.send(outputs, fee=1)
And the output:
# Debug printing the unspents
[Unspent(amount=199322, confirmations=82, script='someScriptKey', txid='sometxid', txindex=1)]
# The resulting error
Traceback (most recent call last):
File "actions.py", line 62, in move_to_cold_storage
key.send(outputs, fee=1)
File "/venv/lib/python3.5/site-packages/bitcash/wallet.py", line 291, in send
outputs, fee=fee, leftover=leftover, combine=combine, message=message, unspents=unspents
File "/venv/lib/python3.5/site-packages/bitcash/wallet.py", line 249, in create_transaction
compressed=self.is_compressed()
File "/venv/lib/python3.5/site-packages/bitcash/transaction.py", line 155, in sanitize_tx_data
'fee).'.format(total_in, total_out))
bitcash.exceptions.InsufficientFunds: Balance 199322 is less than 199548 (including fee).
Should I be getting the total fee for the transaction beforehand and subtracting it from the total to send? What is the best way to go about doing that?
Thanks in advance!
It looks like send() no longer gets unspents. I can get_unspents() and I'll get them, and if I don't pass the unspents to send(), it'll say there are none. If I pass the unspents as an argument to send(), it works fine.
Is this intentional? Seems like different behavior than I remember.
Thank you!
Same issue as ofek/bit#83
I am getting ConnectionError: Transaction broadcast failed, or Unspents were already used.
when trying to broadcast a transaction. I'm sure I have unspent transaction output when I did this.
I'm just getting started using this library, and the examples work OK.
However, when I try to use my own Testnet private keys, it throws an error:
k2 = PrivateKeyTestnet('TESTNETKEYGOESHERE')
I thought it might be an invalid format of address, so I made a new address then used k.to_wif() to get the private key and tried that, and it's still throwing this error (I'll leave the key since it's just testnet haha):
raceback (most recent call last):
File "bchwal.py", line 7, in
k2 = PrivateKeyTestnet('qp0srrxty5840ht02avj3qsgu6hppux0dsjutfy5ud')
File "/home/etali/.local/lib/python3.8/site-packages/bitcash/wallet.py", line 499, in init
super().init(wif=wif, network=network)
File "/home/etali/.local/lib/python3.8/site-packages/bitcash/wallet.py", line 159, in init
super().init(wif=wif)
File "/home/etali/.local/lib/python3.8/site-packages/bitcash/wallet.py", line 67, in init
private_key_bytes, compressed, version = wif_to_bytes(wif, regtest)
File "/home/etali/.local/lib/python3.8/site-packages/bitcash/format.py", line 79, in wif_to_bytes
private_key = b58decode_check(wif)
File "/home/etali/.local/lib/python3.8/site-packages/bitcash/base58.py", line 70, in b58decode_check
decoded = b58decode(string)
File "/home/etali/.local/lib/python3.8/site-packages/bitcash/base58.py", line 52, in b58decode
raise ValueError(
ValueError: "0" is an invalid base58 encoded character.
I assume I'm missing something obvious? Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.