do not perform satoshi conversion in the argument parser
This commit is contained in:
parent
1d1d76b1ad
commit
679fc69cf1
|
@ -45,6 +45,12 @@ from paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
|
||||||
import contacts
|
import contacts
|
||||||
known_commands = {}
|
known_commands = {}
|
||||||
|
|
||||||
|
|
||||||
|
def satoshis(amount):
|
||||||
|
# satoshi conversion must not be performed by the parser
|
||||||
|
return int(COIN*Decimal(amount)) if amount not in ['!', None] else amount
|
||||||
|
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
|
|
||||||
def __init__(self, func, s):
|
def __init__(self, func, s):
|
||||||
|
@ -216,7 +222,7 @@ class Commands:
|
||||||
else:
|
else:
|
||||||
raise BaseException('No redeem script')
|
raise BaseException('No redeem script')
|
||||||
|
|
||||||
outputs = map(lambda x: (TYPE_ADDRESS, x[0], int(COIN*Decimal(x[1]))), outputs)
|
outputs = map(lambda x: (TYPE_ADDRESS, x[0], satoshis(x[1])), outputs)
|
||||||
tx = Transaction.from_io(inputs, outputs, locktime=locktime)
|
tx = Transaction.from_io(inputs, outputs, locktime=locktime)
|
||||||
tx.sign(keypairs)
|
tx.sign(keypairs)
|
||||||
return tx.as_dict()
|
return tx.as_dict()
|
||||||
|
@ -378,6 +384,7 @@ class Commands:
|
||||||
"""Sweep private keys. Returns a transaction that spends UTXOs from
|
"""Sweep private keys. Returns a transaction that spends UTXOs from
|
||||||
privkey to a destination address. The transaction is not
|
privkey to a destination address. The transaction is not
|
||||||
broadcasted."""
|
broadcasted."""
|
||||||
|
tx_fee = satoshis(tx_fee)
|
||||||
privkeys = privkey if type(privkey) is list else [privkey]
|
privkeys = privkey if type(privkey) is list else [privkey]
|
||||||
self.nocheck = nocheck
|
self.nocheck = nocheck
|
||||||
dest = self._resolver(destination)
|
dest = self._resolver(destination)
|
||||||
|
@ -404,8 +411,7 @@ class Commands:
|
||||||
final_outputs = []
|
final_outputs = []
|
||||||
for address, amount in outputs:
|
for address, amount in outputs:
|
||||||
address = self._resolver(address)
|
address = self._resolver(address)
|
||||||
if amount != '!':
|
amount = satoshis(amount)
|
||||||
amount = int(COIN*Decimal(amount))
|
|
||||||
final_outputs.append((TYPE_ADDRESS, address, amount))
|
final_outputs.append((TYPE_ADDRESS, address, amount))
|
||||||
|
|
||||||
coins = self.wallet.get_spendable_coins(domain)
|
coins = self.wallet.get_spendable_coins(domain)
|
||||||
|
@ -419,6 +425,7 @@ class Commands:
|
||||||
@command('wp')
|
@command('wp')
|
||||||
def payto(self, destination, amount, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, rbf=False):
|
def payto(self, destination, amount, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, rbf=False):
|
||||||
"""Create a transaction. """
|
"""Create a transaction. """
|
||||||
|
tx_fee = satoshis(tx_fee)
|
||||||
domain = [from_addr] if from_addr else None
|
domain = [from_addr] if from_addr else None
|
||||||
tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck, unsigned, rbf)
|
tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck, unsigned, rbf)
|
||||||
return tx.as_dict()
|
return tx.as_dict()
|
||||||
|
@ -426,6 +433,7 @@ class Commands:
|
||||||
@command('wp')
|
@command('wp')
|
||||||
def paytomany(self, outputs, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, rbf=False):
|
def paytomany(self, outputs, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, rbf=False):
|
||||||
"""Create a multi-output transaction. """
|
"""Create a multi-output transaction. """
|
||||||
|
tx_fee = to_satoshis(tx_fee)
|
||||||
domain = [from_addr] if from_addr else None
|
domain = [from_addr] if from_addr else None
|
||||||
tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck, unsigned, rbf)
|
tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck, unsigned, rbf)
|
||||||
return tx.as_dict()
|
return tx.as_dict()
|
||||||
|
@ -572,7 +580,7 @@ class Commands:
|
||||||
addr = self.wallet.create_new_address(False)
|
addr = self.wallet.create_new_address(False)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
amount = int(COIN*Decimal(amount))
|
amount = satoshis(amount)
|
||||||
expiration = int(expiration) if expiration else None
|
expiration = int(expiration) if expiration else None
|
||||||
req = self.wallet.make_payment_request(addr, amount, memo, expiration)
|
req = self.wallet.make_payment_request(addr, amount, memo, expiration)
|
||||||
self.wallet.add_payment_request(req, self.config)
|
self.wallet.add_payment_request(req, self.config)
|
||||||
|
@ -688,8 +696,8 @@ arg_types = {
|
||||||
'jsontx': json_loads,
|
'jsontx': json_loads,
|
||||||
'inputs': json_loads,
|
'inputs': json_loads,
|
||||||
'outputs': json_loads,
|
'outputs': json_loads,
|
||||||
'tx_fee': lambda x: int(COIN*Decimal(x)) if x is not None else None,
|
'tx_fee': lambda x: str(Decimal(x)) if x is not None else None,
|
||||||
'amount': lambda x: str(Decimal(x)) if x!='!' else '!',
|
'amount': lambda x: str(Decimal(x)) if x != '!' else '!',
|
||||||
}
|
}
|
||||||
|
|
||||||
config_variables = {
|
config_variables = {
|
||||||
|
|
Loading…
Reference in New Issue