Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOCS: hello world feature - core, protobuf, trezorlib, tests
- Loading branch information
Showing
19 changed files
with
750 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
syntax = "proto2"; | ||
package hw.trezor.messages.helloworld; | ||
|
||
// Sugar for easier handling in Java | ||
option java_package = "com.satoshilabs.trezor.lib.protobuf"; | ||
option java_outer_classname = "TrezorMessageHelloWorld"; | ||
|
||
import "messages.proto"; | ||
|
||
|
||
/** | ||
* Request: Hello world request for text | ||
* @next HelloWorldResponse | ||
* @next Failure | ||
*/ | ||
message HelloWorldRequest { | ||
required string name = 1; | ||
optional uint32 amount = 2 [default=1]; | ||
optional bool show_display = 3; | ||
} | ||
|
||
/** | ||
* Response: Hello world text | ||
* @end | ||
*/ | ||
message HelloWorldResponse { | ||
required string text = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from trezor.messages import HelloWorldResponse | ||
from trezor.ui.layouts import confirm_text | ||
|
||
if TYPE_CHECKING: | ||
from trezor.messages import HelloWorldRequest | ||
|
||
|
||
async def hello_world(msg: HelloWorldRequest) -> HelloWorldResponse: | ||
text = _get_text_from_msg(msg) | ||
if msg.show_display: | ||
await confirm_text( | ||
"confirm_hello_world", | ||
"Hello world", | ||
text, | ||
description="Hello world example", | ||
) | ||
return HelloWorldResponse(text=text) | ||
|
||
|
||
def _get_text_from_msg(msg: HelloWorldRequest) -> str: | ||
return msg.amount * f"Hello {msg.name}!\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from common import * | ||
|
||
from trezor.messages import HelloWorldRequest | ||
from apps.misc.hello_world import _get_text_from_msg | ||
|
||
|
||
class TestHelloWorld(unittest.TestCase): | ||
def test_get_text_from_msg(self): | ||
msg = HelloWorldRequest(name="Satoshi", amount=2, show_display=False) | ||
self.assertEqual(_get_text_from_msg(msg), "Hello Satoshi!\nHello Satoshi!\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
import click | ||
|
||
from .. import hello_world | ||
from . import with_client | ||
|
||
if TYPE_CHECKING: | ||
from ..client import TrezorClient | ||
|
||
|
||
@click.group(name="helloworld") | ||
def cli() -> None: | ||
"""Hello world commands.""" | ||
|
||
|
||
@cli.command() | ||
@click.argument("name") | ||
@click.option("-a", "--amount", type=int, help="How many times to greet.") | ||
@click.option( | ||
"-d", "--show-display", is_flag=True, help="Whether to show confirmation screen." | ||
) | ||
@with_client | ||
def say_hello( | ||
client: "TrezorClient", name: str, amount: Optional[int], show_display: bool | ||
) -> str: | ||
"""Simply say hello to the supplied name.""" | ||
return hello_world.say_hello(client, name, amount, show_display=show_display) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from . import messages | ||
from .tools import expect | ||
|
||
if TYPE_CHECKING: | ||
from .client import TrezorClient | ||
from .protobuf import MessageType | ||
|
||
|
||
@expect(messages.HelloWorldResponse, field="text", ret_type=str) | ||
def say_hello( | ||
client: "TrezorClient", | ||
name: str, | ||
amount: Optional[int], | ||
show_display: bool, | ||
) -> "MessageType": | ||
return client.call( | ||
messages.HelloWorldRequest( | ||
name=name, | ||
amount=amount, | ||
show_display=show_display, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.