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

support "ALL" quantity for send #2493

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
LENGTH = 8 + 8 + 21
MAX_MEMO_LENGTH = 34
ID = 2 # 0x02
QUANTITY_ALL = "ALL"


def unpack(message, block_index):
Expand Down Expand Up @@ -111,6 +112,9 @@ def compose(
# resolve subassets
asset = ledger.resolve_subasset_longname(db, asset)

if quantity == QUANTITY_ALL:
quantity = ledger.get_balance(db, source, asset)

# quantity must be in int satoshi (not float, string, etc)
if not isinstance(quantity, int):
raise exceptions.ComposeError("quantity must be an int (in satoshi)")
Expand Down Expand Up @@ -163,6 +167,9 @@ def parse(db, tx, message):

status = "valid"

if quantity == QUANTITY_ALL:
quantity = ledger.get_balance(db, tx["source"], asset)

except (exceptions.UnpackError, exceptions.AssetNameError, struct.error) as e:
asset, quantity, destination, memo_bytes = None, None, None, None
status = f"invalid: could not unpack ({e})"
Expand Down