本文整理汇总了Python中sawtooth_cli.rest_client.RestClient.get_statuses方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.get_statuses方法的具体用法?Python RestClient.get_statuses怎么用?Python RestClient.get_statuses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sawtooth_cli.rest_client.RestClient
的用法示例。
在下文中一共展示了RestClient.get_statuses方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_batch_status
# 需要导入模块: from sawtooth_cli.rest_client import RestClient [as 别名]
# 或者: from sawtooth_cli.rest_client.RestClient import get_statuses [as 别名]
def do_batch_status(args):
"""Runs the batch-status command, printing output to the console
Args:
args: The parsed arguments sent to the command at runtime
"""
rest_client = RestClient(args.url, args.user)
batch_ids = args.batch_ids.split(',')
if args.wait and args.wait > 0:
statuses = rest_client.get_statuses(batch_ids, args.wait)
else:
statuses = rest_client.get_statuses(batch_ids)
if args.format == 'yaml':
fmt.print_yaml(statuses)
elif args.format == 'json':
fmt.print_json(statuses)
else:
raise AssertionError('Missing handler: {}'.format(args.format))
示例2: _do_identity_role_create
# 需要导入模块: from sawtooth_cli.rest_client import RestClient [as 别名]
# 或者: from sawtooth_cli.rest_client.RestClient import get_statuses [as 别名]
def _do_identity_role_create(args):
"""Executes the 'role create' subcommand. Given a key file, a role name,
and a policy name it generates a batch of sawtooth_identity
transactions in a BatchList instance. The BatchList is either stored to a
file or submitted to a validator, depending on the supplied CLI arguments.
"""
signer = _read_signer(args.key)
txns = [_create_role_txn(signer, args.name,
args.policy)]
batch = _create_batch(signer, txns)
batch_list = BatchList(batches=[batch])
if args.output is not None:
try:
with open(args.output, 'wb') as batch_file:
batch_file.write(batch_list.SerializeToString())
except IOError as e:
raise CliException(
'Unable to write to batch file: {}'.format(str(e)))
elif args.url is not None:
rest_client = RestClient(args.url)
rest_client.send_batches(batch_list)
if args.wait and args.wait > 0:
batch_id = batch.header_signature
wait_time = 0
start_time = time.time()
while wait_time < args.wait:
statuses = rest_client.get_statuses(
[batch_id],
args.wait - int(wait_time))
wait_time = time.time() - start_time
if statuses[0]['status'] == 'COMMITTED':
print(
'Role committed in {:.6} sec'.format(wait_time))
return
# Wait a moment so as not to hammer the Rest Api
time.sleep(0.2)
print('Wait timed out! Role was not committed...')
print('{:128.128} {}'.format(
batch_id,
statuses[0]['status']))
exit(1)
else:
raise AssertionError('No target for create set.')
示例3: do_batch_submit
# 需要导入模块: from sawtooth_cli.rest_client import RestClient [as 别名]
# 或者: from sawtooth_cli.rest_client.RestClient import get_statuses [as 别名]
def do_batch_submit(args):
try:
with open(args.filename, mode='rb') as fd:
batches = batch_pb2.BatchList()
batches.ParseFromString(fd.read())
except IOError as e:
raise CliException(e)
rest_client = RestClient(args.url, args.user)
start = time.time()
for batch_list in _split_batch_list(args, batches):
rest_client.send_batches(batch_list)
stop = time.time()
print('batches: {}, batch/sec: {}'.format(
str(len(batches.batches)),
len(batches.batches) / (stop - start)))
if args.wait and args.wait > 0:
batch_ids = [b.header_signature for b in batches.batches]
wait_time = 0
start_time = time.time()
while wait_time < args.wait:
statuses = rest_client.get_statuses(
batch_ids,
args.wait - int(wait_time))
wait_time = time.time() - start_time
if all(s.status == 'COMMITTED' for s in statuses):
print('All batches committed in {:.6} sec'.format(wait_time))
return
# Wait a moment so as not to hammer the Rest Api
time.sleep(0.2)
print('Wait timed out! Some batches have not yet been committed...')
for batch_id, status in statuses.items():
print('{:128.128} {:10.10}'.format(batch_id, status))
exit(1)
示例4: MarketplaceClient
# 需要导入模块: from sawtooth_cli.rest_client import RestClient [as 别名]
# 或者: from sawtooth_cli.rest_client.RestClient import get_statuses [as 别名]
class MarketplaceClient(object):
def __init__(self, url):
self._client = RestClient(base_url="http://{}".format(url))
def create_account(self, key, label, description):
batches, signature = transaction_creation.create_account(
txn_key=key,
batch_key=BATCH_KEY,
label=label,
description=description)
batch_list = batch_pb2.BatchList(batches=batches)
self._client.send_batches(batch_list)
return self._client.get_statuses([signature], wait=10)
def create_asset(self, key, name, description, rules):
batches, signature = transaction_creation.create_asset(
txn_key=key,
batch_key=BATCH_KEY,
name=name,
description=description,
rules=rules)
batch_list = batch_pb2.BatchList(batches=batches)
self._client.send_batches(batch_list)
return self._client.get_statuses([signature], wait=10)
def create_holding(self,
key,
identifier,
label,
description,
asset,
quantity):
batches, signature = transaction_creation.create_holding(
txn_key=key,
batch_key=BATCH_KEY,
identifier=identifier,
label=label,
description=description,
asset=asset,
quantity=quantity)
batch_list = batch_pb2.BatchList(batches=batches)
self._client.send_batches(batch_list)
return self._client.get_statuses([signature], wait=10)
def create_offer(self,
key,
identifier,
label,
description,
source,
target,
rules):
batches, signature = transaction_creation.create_offer(
txn_key=key,
batch_key=BATCH_KEY,
identifier=identifier,
label=label,
description=description,
source=source,
target=target,
rules=rules)
batch_list = batch_pb2.BatchList(batches=batches)
self._client.send_batches(batch_list)
return self._client.get_statuses([signature], wait=10)
def accept_offer(self,
key,
identifier,
receiver,
offerer,
count):
batches, signature = transaction_creation.accept_offer(
txn_key=key,
batch_key=BATCH_KEY,
identifier=identifier,
offerer=offerer,
receiver=receiver,
count=count)
batch_list = batch_pb2.BatchList(batches=batches)
self._client.send_batches(batch_list)
return self._client.get_statuses([signature], wait=10)
def close_offer(self,
key,
identifier):
batches, signature = transaction_creation.close_offer(
txn_key=key,
batch_key=BATCH_KEY,
identifier=identifier)
batch_list = batch_pb2.BatchList(batches=batches)
self._client.send_batches(batch_list)
return self._client.get_statuses([signature], wait=10)