Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpz object missing to_bytes() method #431

Closed
PiRK opened this issue Sep 14, 2023 · 4 comments
Closed

mpz object missing to_bytes() method #431

PiRK opened this issue Sep 14, 2023 · 4 comments

Comments

@PiRK
Copy link

PiRK commented Sep 14, 2023

When running tests on my project (Electrum ABC), a user is getting errors like this one:

======================================================================
ERROR: test_sweep (electrumabc.tests.test_wallet.TestSweep)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pierre/dev/bitcoin-abc/electrum/electrumabc/tests/test_wallet.py", line 222, in test_sweep
    inputs, keypairs = sweep_preparations([WIF1], network)
  File "/home/pierre/dev/bitcoin-abc/electrum/electrumabc/wallet.py", line 179, in sweep_preparations
    find_utxos_for_privkey(txin_type, privkey, compressed)
  File "/home/pierre/dev/bitcoin-abc/electrum/electrumabc/wallet.py", line 170, in find_utxos_for_privkey
    pubkey = bitcoin.public_key_from_private_key(privkey, compressed)
  File "/home/pierre/dev/bitcoin-abc/electrum/electrumabc/bitcoin.py", line 732, in public_key_from_private_key
    public_key = GetPubKey(pkey.pubkey, compressed)
  File "/home/pierre/dev/bitcoin-abc/electrum/electrumabc/bitcoin.py", line 721, in GetPubKey
    return i2o_ECPublicKey(pubkey, compressed)
  File "/home/pierre/dev/bitcoin-abc/electrum/electrumabc/bitcoin.py", line 490, in i2o_ECPublicKey
    key = b"\x03" + pubkey.point.x().to_bytes(32, "big")
AttributeError: 'mpz' object has no attribute 'to_bytes'

I can reproduce if I install gmpy or gmpy2, but it works if none of them is installed. I guess ecdsa is using regular ints when gmpy is not available.

Is to_bytes() something you intend to support, so as to be a drop in replacement for python int?

Otherwise I will add a special case in my code.

@casevh
Copy link
Collaborator

casevh commented Sep 14, 2023

It will be available in the next release. I should have an alpha version out in the next couple of days.

@PiRK
Copy link
Author

PiRK commented Sep 14, 2023

Great, thanks!

@casevh
Copy link
Collaborator

casevh commented Sep 25, 2023

I have published gmpy2 2.2.0a1 with binary wheels for all supported platforms.

@skirpichev
Copy link
Contributor

@casevh, I think this could be closed.

@casevh casevh closed this as completed Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants