slimcoin-project / pacli

Simple CLI PeerAssets client (extended version).
GNU General Public License v3.0
0 stars 0 forks source link

attoken send_coins command with the negative or zero coins value #186

Closed buhtignew closed 2 months ago

buhtignew commented 2 months ago

I've accidentally run attoken send_coins mie75nFHrNAHHKfQ141fWfWozdMnaec8mb -1 and got the following output:

  File "~/.local/bin/pacli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/__main__.py", line 479, in main
    fire.Fire({
  File "~/.local/lib/python3.12/site-packages/fire/core.py", line 143, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/fire/core.py", line 477, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
                                ^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/fire/core.py", line 693, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/at_classes.py", line 240, in send_coins
    return ei.run_command(super()._create_tx, address_or_deck=address_or_deck, amount=amount, tx_fee=tx_fee, change=change, sign=sign, send=send, wait_for_confirmation=wait_for_confirmation, verify=verify, quiet=quiet, debug=debug, no_confirmation=no_confirmation)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/extended_interface.py", line 34, in run_command
    result = c(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/at_classes.py", line 66, in _create_tx
    rawtx = au.create_simple_transaction(amount=dec_amount, dest_address=address, tx_fee=tx_fee, change_address=change_address, debug=debug)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/at_utils.py", line 31, in create_simple_transaction
    return dtx.to_raw_transaction()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pypeerassets/at/mutable_transactions.py", line 122, in to_raw_transaction
    return patx.make_raw_transaction(network=self.provider.network,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pypeerassets/transactions.py", line 285, in make_raw_transaction
    return MutableTransaction(
           ^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pypeerassets/transactions.py", line 151, in __init__
    super().__init__(version, ins, outs, locktime, network=network, timestamp=timestamp)
  File "~/.local/lib/python3.12/site-packages/pypeerassets/transactions.py", line 56, in __init__
    if txid != self.txid and txid is not None:
               ^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/btcpy/structs/transaction.py", line 512, in txid
    return self.hash()
           ^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/btcpy/lib/types.py", line 28, in wrapper
    return method(self)
           ^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/btcpy/structs/transaction.py", line 507, in hash
    stream << self
    ~~~~~~~^^~~~~~
  File "~/.local/lib/python3.12/site-packages/btcpy/lib/parsing.py", line 373, in __lshift__
    self.body += other.serialize()
                 ^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/btcpy/lib/types.py", line 28, in wrapper
    return method(self)
           ^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pypeerassets/transactions.py", line 113, in serialize
    result << bytearray(chain.from_iterable(txout.serialize() for txout in self.outs))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pypeerassets/transactions.py", line 113, in <genexpr>
    result << bytearray(chain.from_iterable(txout.serialize() for txout in self.outs))
                                            ^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/btcpy/lib/types.py", line 26, in wrapper
    object.__setattr__(self, cache, method(self))
                                    ^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/btcpy/structs/transaction.py", line 303, in serialize
    result << self.value.to_bytes(8, 'little')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: can't convert negative int to unsigned

Then I've run attoken send_coins mie75nFHrNAHHKfQ141fWfWozdMnaec8mb 0 and got:

 File "~/.local/bin/pacli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/__main__.py", line 479, in main
    fire.Fire({
  File "~/.local/lib/python3.12/site-packages/fire/core.py", line 143, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/fire/core.py", line 477, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
                                ^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/fire/core.py", line 693, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/at_classes.py", line 240, in send_coins
    return ei.run_command(super()._create_tx, address_or_deck=address_or_deck, amount=amount, tx_fee=tx_fee, change=change, sign=sign, send=send, wait_for_confirmation=wait_for_confirmation, verify=verify, quiet=quiet, debug=debug, no_confirmation=no_confirmation)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/extended_interface.py", line 34, in run_command
    result = c(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/at_classes.py", line 66, in _create_tx
    rawtx = au.create_simple_transaction(amount=dec_amount, dest_address=address, tx_fee=tx_fee, change_address=change_address, debug=debug)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.12/site-packages/pacli/at_utils.py", line 26, in create_simple_transaction
    dtx.add_p2pkh_output(dest_address, coins=amount)
  File "~/.local/lib/python3.12/site-packages/pypeerassets/at/mutable_transactions.py", line 75, in add_p2pkh_output
    raise ValueError()
ValueError
d5000 commented 2 months ago

I catched both situations with commit fd06458, will now print out a meaningful error message. Closing as this is not an important issue and the problem was obvious.