mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-23 19:31:00 +08:00
updated tests to test payment key support with updates, transfers, and renewals. plus better handling in 0-UTXO safety check
This commit is contained in:
@@ -1788,6 +1788,8 @@ def cli_renew(args, config_path=CONFIG_PATH, interactive=True, password=None, pr
|
||||
command: renew
|
||||
help: Renew a blockchain ID
|
||||
arg: name (str) 'The blockchain ID to renew'
|
||||
opt: owner_key (str) 'A private key string to be used for the update.'
|
||||
opt: payment_key (str) 'Payers private key string'
|
||||
"""
|
||||
|
||||
config_dir = os.path.dirname(config_path)
|
||||
@@ -1823,6 +1825,18 @@ def cli_renew(args, config_path=CONFIG_PATH, interactive=True, password=None, pr
|
||||
price_args.name_or_namespace = fqu
|
||||
price_args.operations = 'renewal'
|
||||
|
||||
args_ownerkey = getattr(args, 'owner_key', None)
|
||||
if args_ownerkey is None or len(args_ownerkey) == 0:
|
||||
owner_key = None
|
||||
else:
|
||||
owner_key = args_ownerkey
|
||||
|
||||
args_paymentkey = getattr(args, 'payment_key', None)
|
||||
if args_paymentkey is None or len(args_paymentkey) == 0:
|
||||
payment_key = None
|
||||
else:
|
||||
payment_key = args_paymentkey
|
||||
|
||||
costs = cli_price( price_args, config_path=config_path, password=password, proxy=proxy )
|
||||
if 'error' in costs:
|
||||
return {'error': 'Failed to get renewal costs. Please try again with `--debug` to see error messages.'}
|
||||
@@ -1831,7 +1845,7 @@ def cli_renew(args, config_path=CONFIG_PATH, interactive=True, password=None, pr
|
||||
|
||||
if cost_satoshis is None:
|
||||
cost_satoshis = costs['name_price']['satoshis']
|
||||
|
||||
|
||||
if not local_rpc.is_api_server(config_dir=config_dir):
|
||||
# also verify that we own the name
|
||||
_, owner_address, _ = get_addresses_from_file(config_dir=config_dir)
|
||||
@@ -1868,13 +1882,18 @@ def cli_renew(args, config_path=CONFIG_PATH, interactive=True, password=None, pr
|
||||
print('\nExiting.')
|
||||
exit(0)
|
||||
|
||||
|
||||
|
||||
rpc = local_api_connect(config_path=config_path)
|
||||
assert rpc
|
||||
|
||||
log.debug("Renew {} for {} BTC".format(fqu, cost_satoshis))
|
||||
try:
|
||||
resp = rpc.backend_renew(fqu, cost_satoshis)
|
||||
additionals = {}
|
||||
if owner_key:
|
||||
additionals['owner_key'] = owner_key
|
||||
if payment_key:
|
||||
additionals['payment_key'] = payment_key
|
||||
resp = rpc.backend_renew(fqu, cost_satoshis, **additionals)
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
return {'error': 'Error talking to server, try again.'}
|
||||
|
||||
@@ -161,7 +161,10 @@ def make_cheapest_nameop( opcode, utxo_client, payment_address, payment_utxos, *
|
||||
tx_builder = tx_builders[opcode]
|
||||
|
||||
# estimate the cheapest transaction by selecting inputs in decreasing value
|
||||
# NOTE: payment_utxos should already be sorted in decreasing value
|
||||
# NOTE: payment_utxos should already be sorted in decreasing value
|
||||
|
||||
if len(payment_utxos) < 1:
|
||||
raise ValueError("No UTXOs for address {}".format(payment_address))
|
||||
|
||||
for i in xrange(1, len(payment_utxos)+1):
|
||||
try:
|
||||
|
||||
@@ -744,7 +744,11 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
|
||||
|
||||
# do we own this name already?
|
||||
# i.e. do we need to renew?
|
||||
res = proxy.get_names_owned_by_address( self.server.wallet_keys['owner_addresses'][0] )
|
||||
if owner_key is None:
|
||||
check_already_owned_by = self.server.wallet_keys['owner_addresses'][0]
|
||||
else:
|
||||
check_already_owned_by = virtualchain.get_privkey_address(owner_key)
|
||||
res = proxy.get_names_owned_by_address(check_already_owned_by)
|
||||
if json_is_error(res):
|
||||
log.error("Failed to get names owned by address")
|
||||
self._reply_json({'error': 'Failed to list names by address'}, status_code=500)
|
||||
@@ -754,13 +758,16 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
|
||||
if name in res:
|
||||
# renew
|
||||
for prop in request_schema['properties'].keys():
|
||||
if prop in request.keys() and prop not in ['name']:
|
||||
log.debug("Invalid argument {}".format(prop))
|
||||
return self._reply_json({'error': 'Name already owned by this wallet'}, status_code=401)
|
||||
if prop in request.keys() and prop not in ['name', 'owner_key', 'payment_key']:
|
||||
log.debug("Invalid renewal argument {}".format(prop))
|
||||
return self._reply_json(
|
||||
{'error': 'Name already owned by this wallet and ' +
|
||||
'`{}` is an invalid argument for renewal'.format(prop)}, status_code=401)
|
||||
|
||||
op = 'renew'
|
||||
log.debug("renew {}".format(name))
|
||||
res = internal.cli_renew(name, interactive=False, cost_satoshis=cost_satoshis)
|
||||
res = internal.cli_renew(name, owner_key, payment_key, interactive=False,
|
||||
cost_satoshis=cost_satoshis)
|
||||
|
||||
else:
|
||||
# register
|
||||
|
||||
Reference in New Issue
Block a user