本文整理汇总了Python中sawtooth_cli.rest_client.RestClient.get_transaction方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.get_transaction方法的具体用法?Python RestClient.get_transaction怎么用?Python RestClient.get_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sawtooth_cli.rest_client.RestClient
的用法示例。
在下文中一共展示了RestClient.get_transaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_transaction
# 需要导入模块: from sawtooth_cli.rest_client import RestClient [as 别名]
# 或者: from sawtooth_cli.rest_client.RestClient import get_transaction [as 别名]
def do_transaction(args):
"""Runs the transaction list or show command, printing to the console
Args:
args: The parsed arguments sent to the command at runtime
"""
rest_client = RestClient(args.url, args.user)
if args.subcommand == 'list':
transactions = rest_client.list_transactions()
keys = ('transaction_id', 'family', 'version', 'size', 'payload')
headers = tuple(k.upper() if k != 'version' else 'VERS' for k in keys)
def parse_txn_row(transaction, decode=True):
decoded = b64decode(transaction['payload'])
return (
transaction['header_signature'],
transaction['header']['family_name'],
transaction['header']['family_version'],
len(decoded),
str(decoded) if decode else transaction['payload'])
if args.format == 'default':
fmt.print_terminal_table(headers, transactions, parse_txn_row)
elif args.format == 'csv':
fmt.print_csv(headers, transactions, parse_txn_row)
elif args.format == 'json' or args.format == 'yaml':
data = [{k: d for k, d in zip(keys, parse_txn_row(b, False))}
for b in transactions]
if args.format == 'yaml':
fmt.print_yaml(data)
elif args.format == 'json':
fmt.print_json(data)
else:
raise AssertionError('Missing handler: {}'.format(args.format))
else:
raise AssertionError('Missing handler: {}'.format(args.format))
if args.subcommand == 'show':
output = rest_client.get_transaction(args.transaction_id)
if args.key:
if args.key == 'payload':
output = b64decode(output['payload'])
elif args.key in output:
output = output[args.key]
elif args.key in output['header']:
output = output['header'][args.key]
else:
raise CliException(
'Key "{}" not found in transaction or header'.format(
args.key))
if args.format == 'yaml':
fmt.print_yaml(output)
elif args.format == 'json':
fmt.print_json(output)
else:
raise AssertionError('Missing handler: {}'.format(args.format))