Пример #1
0
 def process_content(message_type: MessageType, buffer: bytes) -> MessageObject:
     content = EmptyMessageObject()
     if message_type == MessageType.StatusResponse18:
         content = StatusResponse(buffer=buffer)
     if message_type == MessageType.BlockResponse12:
         content = BlockResponse(buffer=buffer)
     return content
Пример #2
0
def status(ctx):
    """Get Status of distant server"""
    connect(ctx)
    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['host']}:{ctx.obj['port']}")
    empty = EmptyMessageObject(app_log=app_log)
    message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
    res = ctx.obj['connection'].fetch(message)
    print(res.to_json())
Пример #3
0
def status(ctx):
    """Get Status of distant server"""
    # ex : python3 Nyzocli.py  -j status 159.69.216.65
    connect(ctx, ctx.obj['verifier_ip'])
    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['verifier_ip']}")
    empty = EmptyMessageObject(app_log=app_log)
    message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message)
    print(res.to_json())
Пример #4
0
def vbalance(ctx, address):
    """Get balance of an ADDRESS from a verifier (Uses the one from localhost by default)
    """
    connect(ctx, ctx.obj['verifier_ip'])
    if address == '':
        address = config.PUBLIC_KEY.to_bytes().hex()
    else:
        id__address, address = normalize_address(address, asHex=True)

    if VERBOSE:
        app_log.info(f"Get vbalance for address {address}")
    assert (len(address) == 64)  # TODO: better user warning

    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['verifier_ip']}")
        app_log.info(f"address {address}")
    empty = EmptyMessageObject()
    message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message)
    status = res.get_lines()
    frozen = int(extract_status_lines(status, "frozen edge")[0])
    if VERBOSE:
        app_log.info(f"Frozen Edge: {frozen}")

    reconnect(ctx)

    req = BlockRequest(start_height=frozen,
                       end_height=frozen,
                       include_balance_list=True,
                       app_log=app_log)
    message2 = Message(MessageType.BlockRequest11, req, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message2)
    # Wow, this is quite heavy. move some logic the pynyzo
    # Also list is *supposed* to be sorted, can help find faster
    bin_address = bytes.fromhex(address)
    for item in res.get_initial_balance_list().get_items():
        if item.get_identifier() == bin_address:
            if ctx.obj['json']:
                print(
                    json.dumps({
                        "block": frozen,
                        "balance": item.get_balance(),
                        "blocks_until_fee": item.get_blocks_until_fee(),
                        "address": address
                    }))
            else:
                print(f"At block: {frozen}")
                print(f"Your Balance is: {item.get_balance()/1000000}")
                print(f"Blocks until fee: {item.get_blocks_until_fee()}")
            return (item.get_balance(), item.get_blocks_until_fee())

    # Address Not found
    if ctx.obj['json']:
        print(
            json.dumps({
                "block": frozen,
                "balance": 0,
                "blocks_until_fee": None,
                "address": address
            }))
    else:
        print(f"At block: {frozen}")
        print(f"Your Balance is: N/A")
        print(f"Blocks until fee: N/A")
    return 0, 0
Пример #5
0
                        default=False,
                        help='Be verbose.')
    parser.add_argument("-a",
                        "--action",
                        type=str,
                        default='status',
                        help='Action (status, block)')
    args = parser.parse_args()

    app_log = tornado_logger()

    config.load()

    connection = Connection(args.ip, app_log=app_log, verbose=args.verbose)

    if args.action == 'status':
        empty = EmptyMessageObject(app_log=app_log)
        message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
        res = connection.fetch(message)
        print(res.to_json())
    elif args.action == 'block':
        # test. Use a block high enough so it's not frozen.
        # TODO: get last block from  reference verifiers
        request = BlockRequest(start_height=1695400,
                               end_height=1695400 + 2,
                               include_balance_list=True,
                               app_log=app_log)
        message = Message(MessageType.BlockRequest11, request, app_log=app_log)
        res = connection.fetch(message)
        print(res.to_json())