Support everything argument in Transaction.pay(), claim_create(), claim_update(), support().
This commit is contained in:
parent
9cf28f0db5
commit
7bafce00c4
1 changed files with 15 additions and 8 deletions
|
@ -804,11 +804,12 @@ class Transaction:
|
||||||
|
|
||||||
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
||||||
|
|
||||||
if everything and not len(tx._inputs):
|
if everything and not any(map(lambda txi: not txi.txo_ref.txo.is_claim, tx._inputs)):
|
||||||
# Spend "everything" requested, but inputs not specified.
|
# Spend "everything" requested, but inputs not specified.
|
||||||
# Make a set of inputs from all funding accounts.
|
# Make a set of inputs from all funding accounts.
|
||||||
all_utxos = []
|
all_utxos = []
|
||||||
for a in funding_accounts:
|
for a in funding_accounts:
|
||||||
|
# TODO: Constraints for get_utxos()?
|
||||||
utxos = await a.get_utxos()
|
utxos = await a.get_utxos()
|
||||||
await a.ledger.reserve_outputs(utxos)
|
await a.ledger.reserve_outputs(utxos)
|
||||||
all_utxos.extend(utxos)
|
all_utxos.extend(utxos)
|
||||||
|
@ -914,27 +915,31 @@ class Transaction:
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pay(cls, amount: int, address: bytes, funding_accounts: List['Account'], change_account: 'Account'):
|
def pay(cls, amount: int, address: bytes, funding_accounts: List['Account'], change_account: 'Account',
|
||||||
|
everything: bool = False):
|
||||||
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
||||||
output = Output.pay_pubkey_hash(amount, ledger.address_to_hash160(address))
|
output = Output.pay_pubkey_hash(amount, ledger.address_to_hash160(address))
|
||||||
return cls.create([], [output], funding_accounts, change_account)
|
return cls.create([], [output], funding_accounts, change_account, everything=everything)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def claim_create(
|
def claim_create(
|
||||||
cls, name: str, claim: Claim, amount: int, holding_address: str,
|
cls, name: str, claim: Claim, amount: int, holding_address: str,
|
||||||
funding_accounts: List['Account'], change_account: 'Account', signing_channel: Output = None):
|
funding_accounts: List['Account'], change_account: 'Account', signing_channel: Output = None,
|
||||||
|
everything: bool = False):
|
||||||
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
||||||
claim_output = Output.pay_claim_name_pubkey_hash(
|
claim_output = Output.pay_claim_name_pubkey_hash(
|
||||||
amount, name, claim, ledger.address_to_hash160(holding_address)
|
amount, name, claim, ledger.address_to_hash160(holding_address)
|
||||||
)
|
)
|
||||||
if signing_channel is not None:
|
if signing_channel is not None:
|
||||||
claim_output.sign(signing_channel, b'placeholder txid:nout')
|
claim_output.sign(signing_channel, b'placeholder txid:nout')
|
||||||
return cls.create([], [claim_output], funding_accounts, change_account, sign=False)
|
return cls.create([], [claim_output], funding_accounts, change_account,
|
||||||
|
everything=everything, sign=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def claim_update(
|
def claim_update(
|
||||||
cls, previous_claim: Output, claim: Claim, amount: int, holding_address: str,
|
cls, previous_claim: Output, claim: Claim, amount: int, holding_address: str,
|
||||||
funding_accounts: List['Account'], change_account: 'Account', signing_channel: Output = None):
|
funding_accounts: List['Account'], change_account: 'Account', signing_channel: Output = None,
|
||||||
|
everything: bool = False):
|
||||||
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
ledger, _ = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
||||||
updated_claim = Output.pay_update_claim_pubkey_hash(
|
updated_claim = Output.pay_update_claim_pubkey_hash(
|
||||||
amount, previous_claim.claim_name, previous_claim.claim_id,
|
amount, previous_claim.claim_name, previous_claim.claim_id,
|
||||||
|
@ -945,7 +950,8 @@ class Transaction:
|
||||||
else:
|
else:
|
||||||
updated_claim.clear_signature()
|
updated_claim.clear_signature()
|
||||||
return cls.create(
|
return cls.create(
|
||||||
[Input.spend(previous_claim)], [updated_claim], funding_accounts, change_account, sign=False
|
[Input.spend(previous_claim)], [updated_claim], funding_accounts, change_account,
|
||||||
|
everything=everything, sign=False
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -966,7 +972,8 @@ class Transaction:
|
||||||
support_output = Output.pay_support_pubkey_hash(
|
support_output = Output.pay_support_pubkey_hash(
|
||||||
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
||||||
)
|
)
|
||||||
return cls.create([], [support_output], funding_accounts, change_account, sign=False)
|
return cls.create([], [support_output], funding_accounts, change_account,
|
||||||
|
everything=everything, sign=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def purchase(cls, claim_id: str, amount: int, merchant_address: bytes,
|
def purchase(cls, claim_id: str, amount: int, merchant_address: bytes,
|
||||||
|
|
Loading…
Add table
Reference in a new issue