Skip to content

Commit

Permalink
Merge pull request #11 from hoodieshq/feat/add-spl-tickers-rebased
Browse files Browse the repository at this point in the history
Add whitelisted SPL tokens to show proper tickers
  • Loading branch information
0xMMBD authored Sep 10, 2024
2 parents 20ef5be + 7360e75 commit 6789168
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
name: C tests
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-legacy:latest
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest
steps:
- name: Clone
uses: actions/checkout@v3
Expand Down
140 changes: 53 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,118 +12,84 @@ Current Features:
- Blind sign arbitrary transactions (Enabled via settings)

## Prerequisites

### For building the app

* [Install Docker](https://docs.docker.com/get-docker/)
* For Linux hosts, install the Ledger Nano [udev rules](https://github.com/LedgerHQ/udev-rules)
#### Build the [Ledger App Builder](https://developers.ledger.com/docs/nano-app/build/) Docker image
1. Clone the git repository
```
git clone https://github.com/LedgerHQ/ledger-app-builder.git
```
2. Change directories
```
cd ledger-app-builder
```
3. Checkout the target commit
```
git checkout 73c9e07
```
4. Build the image
```
docker build -t ledger-app-builder:73c9e07 .
```
* If permissions errors are encountered, ensure that your user is in the `docker`
group and that the session has been restarted
* Pull Ledger Development Tools image

### For working with the device
#### Install Python3 PIP
Ubuntu Linux:
```
sudo apt install pip3
```
MacOS
```
brew install python3
```sh
$ docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
```
#### Install ledgerblue python module
```
pip3 install ledgerblue
```
#### Locally clone SDK repos corresponding to those included in the Docker image
* Setup environment
```bash
cat >>"${HOME}"/.profile <<EOF
LEDGER_SDK_BASE_PATH= # set to a writable path
: "${LEDGER_SDK_BASE_PATH:?}"
export NANOS_SDK="${LEDGER_SDK_BASE_PATH}"/nanos-secure-sdk
export NANOX_SDK="${LEDGER_SDK_BASE_PATH}"/nanox-secure-sdk
export NANOSP_SDK="${LEDGER_SDK_BASE_PATH}"/nanosplus-secure-sdk
EOF
```
* Update the current session's environment
```bash
. "${HOME}"/.profile # Or close and reopen your terminal
```
* Clone the repositories
```bash
# Nano S SDK
git clone --branch 2.1.0 --depth 1 https://github.com/LedgerHQ/nanos-secure-sdk.git "${NANOS_SDK}"

# Nano X SDK
git clone --branch 2.0.2-2 --depth 1 https://github.com/LedgerHQ/nanox-secure-sdk.git "${NANOX_SDK}"

# Nano S+ SDK
git clone --branch 1.0.3 --depth 1 https://github.com/LedgerHQ/nanosplus-secure-sdk.git "${NANOSP_SDK}"
```

### For running the test suite
* [Rust](https://rustup.rs/)
* Solana [system dependencies](https://github.com/solana-labs/solana/#1-install-rustc-cargo-and-rustfmt)

## Build
It is highly recommended that you read and understand the [Ledger App Builder](https://developers.ledger.com/docs/embedded-app/build-app/#2-build-the-application)
build process before proceeding. A convenience wrapper script (`./docker-make`) has been provided for simplicity

`docker-make` manages the current target SDK for you, automatically setting `BOLOS_SDK` to the
correct path when the Docker container is launched. A `TARGET_SDK` must be specified when building
from clean and clean must be run _before_ switching
#### `TARGET_SDK`
|Moniker|Device|
|:-----:|:-----|
|s|Nano S|
|x|Nano X|
|sp|Nano S+|

```bash
./docker-make <TARGET_SDK>
Build the app in the container. The BOLOS_SDK variable is used to specify the target SDK, allowing to compile the application for each Ledger device. See [Ledger Application Builder](https://github.com/LedgerHQ/ledger-app-builder?tab=readme-ov-file#compile-your-app-in-the-container) for more details.

```sh
# E.g. for Nano S
$ sudo docker run --rm -ti -v "$(realpath .):/app" --user $(id -u $USER):$(id -g $USER) ghcr.io/ledgerhq/ledger-app-builder//ledger-app-dev-tools:latest
bash$ BOLOS_SDK=$NANOS_SDK make
```

### Clean
```bash
./docker-make clean

Within the running development container

```sh
bash$ BOLOS_SDK=$NANOS_SDK make clean
```

## Working with the device
Requires that the `BOLOS_SDK` envvar [be set](https://developers.ledger.com/docs/embedded-app/build-app/#b-build-the-application).
This can be achieved by first [building](#build) for the desired target device.

See [Ledger Application Builder](https://github.com/LedgerHQ/ledger-app-builder?tab=readme-ov-file#compile-your-app-in-the-container) for more details.

### Load

```bash
make load-only
$ sudo docker run --rm -ti -v "$(realpath .):/app" --privileged -v "/dev/bus/usb:/dev/bus/usb" --user $(id -u $USER):$(id -g $USER) ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
bash$ BOLOS_SDK=$NANOS_SDK make load
```

### Delete
```bash
make delete

Within the running development container

```sh
bash$ BOLOS_SDK=$NANOS_SDK make delete
```

## Test

### Unit

Run C tests:
```bash
make -C libsol

```sh
bash$ make -C libsol
```

### Ragger

Make sure that you have already built the application for the specific device.

Run Ragger tests:

```sh
# Install python test suite dependencies
bash$ pip install -r "tests/python/requirements.txt"

# Run test suite for the specific device, e.g. nanos
bash$ pytest tests/python/ --tb=short -v --device nanos -k ""
```

To regenerate golden snapshots, use `--golden_run` option.

### Integration

First enable `blind-signing` in the App settings
```bash
cargo run --manifest-path tests/Cargo.toml

```sh
bash$ cargo run --manifest-path tests/Cargo.toml
```
43 changes: 0 additions & 43 deletions docker-make

This file was deleted.

2 changes: 1 addition & 1 deletion libsol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ifeq ($(COVERAGE),1)
CFLAGS += --coverage
endif

debug_CFLAGS = -g -fsanitize=address -fsanitize=undefined
debug_CFLAGS = -g
release_CFLAGS = -O2

libsol_source_files = $(filter-out %_test.c,$(wildcard *.c))
Expand Down
6 changes: 3 additions & 3 deletions libsol/spl_associated_token_account_instruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ int print_spl_associated_token_account_create_info(const SplAssociatedTokenAccou
UNUSED(print_config);

SummaryItem* item = transaction_summary_primary_item();
summary_item_set_pubkey(item, "Create token acct", info->address);
summary_item_set_pubkey(item, "Create token account", info->address);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "From mint", info->mint);
summary_item_set_pubkey(item, "For", info->owner);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Owned by", info->owner);
summary_item_set_pubkey(item, "Token address", info->mint);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Funded by", info->funder);
Expand Down
32 changes: 16 additions & 16 deletions libsol/spl_token_instruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static int print_spl_token_initialize_account_info(const char* primary_title,
summary_item_set_pubkey(item, "Owner", info->owner);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);

return 0;
}
Expand Down Expand Up @@ -503,13 +503,13 @@ int print_spl_token_transfer_info(const SplTokenTransferInfo* info,
info->body.decimals);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "From", info->src_account);
summary_item_set_pubkey(item, "From (token account)", info->src_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "To", info->dest_account);
summary_item_set_pubkey(item, "To (token account)", info->dest_account);

print_spl_token_sign(&info->sign, print_config);

Expand All @@ -532,10 +532,10 @@ static int print_spl_token_approve_info(const SplTokenApproveInfo* info,
info->body.decimals);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "From", info->token_account);
summary_item_set_pubkey(item, "From (token account)", info->token_account);

print_spl_token_sign(&info->sign, print_config);

Expand Down Expand Up @@ -598,10 +598,10 @@ static int print_spl_token_mint_to_info(const SplTokenMintToInfo* info,
info->body.decimals);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "To", info->token_account);
summary_item_set_pubkey(item, "To (token account)", info->token_account);

print_spl_token_sign(&info->sign, print_config);

Expand All @@ -623,10 +623,10 @@ static int print_spl_token_burn_info(const SplTokenBurnInfo* info,
info->body.decimals);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "From", info->token_account);
summary_item_set_pubkey(item, "From (token account)", info->token_account);

print_spl_token_sign(&info->sign, print_config);

Expand All @@ -640,7 +640,7 @@ static int print_spl_token_close_account_info(const SplTokenCloseAccountInfo* in
SummaryItem* item;

item = transaction_summary_primary_item();
summary_item_set_pubkey(item, "Close acct", info->token_account);
summary_item_set_pubkey(item, "Close token account", info->token_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Withdraw to", info->dest_account);
Expand All @@ -655,11 +655,11 @@ static int print_spl_token_freeze_account_info(const SplTokenFreezeAccountInfo*
SummaryItem* item;

item = transaction_summary_primary_item();
summary_item_set_pubkey(item, "Freeze acct", info->token_account);
summary_item_set_pubkey(item, "Freeze token account", info->token_account);

if (print_config->expert_mode) {
item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);
}

print_spl_token_sign(&info->sign, print_config);
Expand All @@ -672,11 +672,11 @@ static int print_spl_token_thaw_account_info(const SplTokenThawAccountInfo* info
SummaryItem* item;

item = transaction_summary_primary_item();
summary_item_set_pubkey(item, "Thaw acct", info->token_account);
summary_item_set_pubkey(item, "Thaw token account", info->token_account);

if (print_config->expert_mode) {
item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Mint", info->mint_account);
summary_item_set_pubkey(item, "Token address", info->mint_account);
}

print_spl_token_sign(&info->sign, print_config);
Expand All @@ -691,7 +691,7 @@ static int print_spl_token_sync_native_info(const SplTokenSyncNativeInfo* info,
SummaryItem* item;

item = transaction_summary_primary_item();
summary_item_set_pubkey(item, "Sync native acct", info->token_account);
summary_item_set_pubkey(item, "Sync native account", info->token_account);

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions libsol/transaction_printers.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ static int print_spl_token_create_account(const PrintConfig* print_config,
const SplTokenInitializeAccountInfo* ia_info = &infos[1]->spl_token.initialize_account;

SummaryItem* item = transaction_summary_primary_item();
summary_item_set_pubkey(item, "Create token acct", ia_info->token_account);
summary_item_set_pubkey(item, "Create token account", ia_info->token_account);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "From mint", ia_info->mint_account);
summary_item_set_pubkey(item, "For", ia_info->owner);

item = transaction_summary_general_item();
summary_item_set_pubkey(item, "Owned by", ia_info->owner);
summary_item_set_pubkey(item, "Token address", ia_info->mint_account);

if (print_config_show_authority(print_config, ca_info->from)) {
item = transaction_summary_general_item();
Expand Down

0 comments on commit 6789168

Please sign in to comment.