Exemplo n.º 1
0
async def process_action(ctx: wire.Context, sha: HashWriter,
                         action: EosTxActionAck) -> None:
    name = helpers.eos_name_to_string(action.common.name)
    account = helpers.eos_name_to_string(action.common.account)

    if not check_action(action, name, account):
        raise ValueError("Invalid action")

    w = bytearray()
    if account == "eosio":
        if name == "buyram":
            await layout.confirm_action_buyram(ctx, action.buy_ram)
            writers.write_action_buyram(w, action.buy_ram)
        elif name == "buyrambytes":
            await layout.confirm_action_buyrambytes(ctx, action.buy_ram_bytes)
            writers.write_action_buyrambytes(w, action.buy_ram_bytes)
        elif name == "sellram":
            await layout.confirm_action_sellram(ctx, action.sell_ram)
            writers.write_action_sellram(w, action.sell_ram)
        elif name == "delegatebw":
            await layout.confirm_action_delegate(ctx, action.delegate)
            writers.write_action_delegate(w, action.delegate)
        elif name == "undelegatebw":
            await layout.confirm_action_undelegate(ctx, action.undelegate)
            writers.write_action_undelegate(w, action.undelegate)
        elif name == "refund":
            await layout.confirm_action_refund(ctx, action.refund)
            writers.write_action_refund(w, action.refund)
        elif name == "voteproducer":
            await layout.confirm_action_voteproducer(ctx, action.vote_producer)
            writers.write_action_voteproducer(w, action.vote_producer)
        elif name == "updateauth":
            await layout.confirm_action_updateauth(ctx, action.update_auth)
            writers.write_action_updateauth(w, action.update_auth)
        elif name == "deleteauth":
            await layout.confirm_action_deleteauth(ctx, action.delete_auth)
            writers.write_action_deleteauth(w, action.delete_auth)
        elif name == "linkauth":
            await layout.confirm_action_linkauth(ctx, action.link_auth)
            writers.write_action_linkauth(w, action.link_auth)
        elif name == "unlinkauth":
            await layout.confirm_action_unlinkauth(ctx, action.unlink_auth)
            writers.write_action_unlinkauth(w, action.unlink_auth)
        elif name == "newaccount":
            await layout.confirm_action_newaccount(ctx, action.new_account)
            writers.write_action_newaccount(w, action.new_account)
        else:
            raise ValueError("Unrecognized action type for eosio")
    elif name == "transfer":
        await layout.confirm_action_transfer(ctx, action.transfer, account)
        writers.write_action_transfer(w, action.transfer)
    else:
        await process_unknown_action(ctx, w, action)

    writers.write_action_common(sha, action.common)
    writers.write_variant32(sha, len(w))
    writers.write_bytes_unchecked(sha, w)
Exemplo n.º 2
0
async def confirm_action_buyrambytes(ctx, msg: EosActionBuyRamBytes):
    text = "Buy RAM"
    fields = []
    fields.append("Payer:")
    fields.append(helpers.eos_name_to_string(msg.payer))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("Bytes:")
    fields.append(str(msg.bytes))
    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 3
0
async def confirm_action_newaccount(ctx, msg: EosActionNewAccount):
    text = "New Account"
    fields = []
    fields.append("Creator:")
    fields.append(helpers.eos_name_to_string(msg.creator))
    fields.append("Name:")
    fields.append(helpers.eos_name_to_string(msg.name))
    fields.extend(authorization_fields(msg.owner))
    fields.extend(authorization_fields(msg.active))
    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 4
0
async def confirm_action_buyram(ctx, msg: EosActionBuyRam):
    text = "Buy RAM"
    fields = []
    fields.append("Payer:")
    fields.append(helpers.eos_name_to_string(msg.payer))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("Amount:")
    fields.append(helpers.eos_asset_to_string(msg.quantity))
    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 5
0
async def confirm_action_unlinkauth(ctx, msg: EosActionUnlinkAuth):
    text = "Unlink Auth"
    fields = []
    fields.append("Account:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Code:")
    fields.append(helpers.eos_name_to_string(msg.code))
    fields.append("Type:")
    fields.append(helpers.eos_name_to_string(msg.type))
    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 6
0
async def confirm_action_unknown(ctx, action, checksum):
    text = "Arbitrary data"
    fields = []
    fields.append("Contract:")
    fields.append(helpers.eos_name_to_string(action.account))
    fields.append("Action Name:")
    fields.append(helpers.eos_name_to_string(action.name))
    fields.append("Checksum: ")
    fields.extend(split_data(hexlify(checksum).decode("ascii")))
    await _require_confirm_paginated(ctx, text, fields, _FIVE_FIELDS_PER_PAGE)
Exemplo n.º 7
0
async def confirm_action_updateauth(ctx, msg: EosActionUpdateAuth):
    text = "Update Auth"
    fields = []
    fields.append("Account:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Permission:")
    fields.append(helpers.eos_name_to_string(msg.permission))
    fields.append("Parent:")
    fields.append(helpers.eos_name_to_string(msg.parent))
    fields.extend(authorization_fields(msg.auth))
    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 8
0
async def confirm_action_undelegate(ctx, msg: EosActionUndelegate):
    text = "Undelegate"
    fields = []
    fields.append("Sender:")
    fields.append(helpers.eos_name_to_string(msg.sender))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("CPU:")
    fields.append(helpers.eos_asset_to_string(msg.cpu_quantity))
    fields.append("NET:")
    fields.append(helpers.eos_asset_to_string(msg.net_quantity))
    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 9
0
async def confirm_action_transfer(ctx, msg: EosActionTransfer, account: str):
    text = "Transfer"
    fields = []
    fields.append("From:")
    fields.append(helpers.eos_name_to_string(msg.sender))
    fields.append("To:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("Amount:")
    fields.append(helpers.eos_asset_to_string(msg.quantity))
    fields.append("Contract:")
    fields.append(account)

    if msg.memo is not None:
        fields.append("Memo:")
        fields.extend(split_data(msg.memo[:512]))

    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 10
0
async def confirm_action_sellram(ctx, msg: EosActionSellRam):
    text = "Sell RAM"
    fields = []
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Bytes:")
    fields.append(str(msg.bytes))
    await _require_confirm_paginated(ctx, text, fields, _TWO_FIELDS_PER_PAGE)
Exemplo n.º 11
0
async def confirm_action_buyrambytes(ctx, msg: EosActionBuyRamBytes):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Buy RAM"
    fields = []
    fields.append("Payer:")
    fields.append(helpers.eos_name_to_string(msg.payer))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("Bytes:")
    fields.append(str(msg.bytes))

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Exemplo n.º 12
0
async def confirm_action_unknown(ctx, action, checksum):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)
    text = "Arbitrary data"
    fields = []
    fields.append("Contract:")
    fields.append(helpers.eos_name_to_string(action.account))
    fields.append("Action Name:")
    fields.append(helpers.eos_name_to_string(action.name))

    fields.append("Checksum: ")
    fields += split_data(hexlify(checksum).decode("ascii"))

    pages = list(chunks(fields, _FIVE_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Exemplo n.º 13
0
async def confirm_action_newaccount(ctx, msg: EosActionNewAccount):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "New Account"
    fields = []
    fields.append("Creator:")
    fields.append(helpers.eos_name_to_string(msg.creator))
    fields.append("Name:")
    fields.append(helpers.eos_name_to_string(msg.name))
    fields += authorization_fields(msg.owner)
    fields += authorization_fields(msg.active)

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Exemplo n.º 14
0
async def confirm_action_unlinkauth(ctx, msg: EosActionUnlinkAuth):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Unlink Auth"
    fields = []
    fields.append("Account:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Code:")
    fields.append(helpers.eos_name_to_string(msg.code))
    fields.append("Type:")
    fields.append(helpers.eos_name_to_string(msg.type))

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Exemplo n.º 15
0
async def confirm_action_updateauth(ctx, msg: EosActionUpdateAuth):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Update Auth"
    fields = []
    fields.append("Account:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Permission:")
    fields.append(helpers.eos_name_to_string(msg.permission))
    fields.append("Parent:")
    fields.append(helpers.eos_name_to_string(msg.parent))
    fields += authorization_fields(msg.auth)

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))

    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)
    await ctx.wait(paginator)
Exemplo n.º 16
0
def authorization_fields(auth):
    fields = []

    fields.append("Threshold:")
    fields.append(str(auth.threshold))

    for i, key in enumerate(auth.keys):
        _key = _public_key_to_wif(bytes(key.key))
        _weight = str(key.weight)

        header = "Key #{}:".format(i + 1)
        w_header = "Key #{} Weight:".format(i + 1)
        fields.append(header)
        fields += split_data(_key)
        fields.append(w_header)
        fields.append(_weight)

    for i, account in enumerate(auth.accounts):
        _account = helpers.eos_name_to_string(account.account.actor)
        _permission = helpers.eos_name_to_string(account.account.permission)

        a_header = "Account #{}:".format(i + 1)
        p_header = "Acc Permission #{}:".format(i + 1)
        w_header = "Account #{} weight:".format(i + 1)

        fields.append(a_header)
        fields.append(_account)
        fields.append(p_header)
        fields.append(_permission)
        fields.append(w_header)
        fields.append(str(account.weight))

    for i, wait in enumerate(auth.waits):
        _wait = str(wait.wait_sec)
        _weight = str(wait.weight)

        header = "Delay #{}".format(i + 1)
        w_header = "Delay #{} weight:".format(i + 1)
        fields.append(header)
        fields.append("{} sec".format(_wait))
        fields.append(w_header)
        fields.append(_weight)

    return fields
Exemplo n.º 17
0
async def confirm_action_undelegate(ctx, msg: EosActionUndelegate):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Undelegate"
    fields = []
    fields.append("Sender:")
    fields.append(helpers.eos_name_to_string(msg.sender))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("CPU:")
    fields.append(helpers.eos_asset_to_string(msg.cpu_quantity))
    fields.append("NET:")
    fields.append(helpers.eos_asset_to_string(msg.net_quantity))

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Exemplo n.º 18
0
async def confirm_action_delegate(ctx: wire.Context,
                                  msg: EosActionDelegate) -> None:
    text = "Delegate"
    fields = []
    fields.append("Sender:")
    fields.append(helpers.eos_name_to_string(msg.sender))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("CPU:")
    fields.append(helpers.eos_asset_to_string(msg.cpu_quantity))
    fields.append("NET:")
    fields.append(helpers.eos_asset_to_string(msg.net_quantity))

    if msg.transfer:
        fields.append("Transfer: Yes")
        fields.append("Receiver:")
        fields.append(helpers.eos_name_to_string(msg.receiver))
    else:
        fields.append("Transfer: No")

    await _require_confirm_paginated(ctx, text, fields, _FOUR_FIELDS_PER_PAGE)
Exemplo n.º 19
0
async def confirm_action_transfer(ctx, msg: EosActionTransfer, account: str):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Transfer"
    fields = []
    fields.append("From:")
    fields.append(helpers.eos_name_to_string(msg.sender))
    fields.append("To:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("Amount:")
    fields.append(helpers.eos_asset_to_string(msg.quantity))
    fields.append("Contract:")
    fields.append(account)

    if msg.memo is not None:
        fields.append("Memo:")
        fields += split_data(msg.memo[:512])

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))

    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)
    await ctx.wait(paginator)
Exemplo n.º 20
0
async def show_voter_page(page: int, page_count: int, pages: list):
    lines = [
        "{:2d}. {}".format(wi + 1, helpers.eos_name_to_string(producer))
        for wi, producer in pages[page]
    ]
    text = Text("Vote for producers", ui.ICON_CONFIRM, icon_color=ui.GREEN)
    text.mono(*lines)
    content = Scrollpage(text, page, page_count)

    if page + 1 == page_count:
        if await ConfirmDialog(content) != CONFIRMED:
            raise wire.ActionCancelled("Action cancelled")
    else:
        content.render()
        await animate_swipe()
Exemplo n.º 21
0
async def confirm_action_sellram(ctx, msg: EosActionSellRam):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Sell RAM"
    fields = []
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Bytes:")
    fields.append(str(msg.bytes))

    pages = list(chunks(fields, _TWO_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
 def test_eos_name_to_string(self):
     names_in = [
         10639447606881920736,
         614251623682315968,
         614251535012020768,
         7754926748989239168,
         14895601873759291472,
         595056260442243600,
     ]
     names_out = [
         'miniminimini',
         '12345abcdefg',
         '123451234512',
         'hijklmnopqrs',
         'tuvwxyz12345',
         '111111111111',
     ]
     for i, o in zip(names_in, names_out):
         self.assertEqual(helpers.eos_name_to_string(i), o)
Exemplo n.º 23
0
async def confirm_action_refund(ctx, msg: EosActionRefund):
    text = Text("Refund", ui.ICON_CONFIRM, icon_color=ui.GREEN)
    text.normal("Owner:")
    text.normal(helpers.eos_name_to_string(msg.owner))
    await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)