Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
swap_lib_calls.h
Go to the documentation of this file.
1#pragma once
2
3/*
4 --8<-- [start:swap_lib_calls_intro]
5This file is the shared API between the Exchange application and the coin applications started in
6Library mode for Exchange.
7
8On Coin application side, the main() of the lib_standard_app has the logic to recognize a library
9start from a dashboard start and the logic to dispatch the library commands to the correct handler
10function.
11--8<-- [end:swap_lib_calls_intro]
12*/
13
14#include "stdbool.h"
15#include "stdint.h"
16
17// The os_lib_calls commands that can be called by the Exchange application.
18// They are handled by the lib_standard_app main() function.
19#define RUN_APPLICATION 1
20#define SIGN_TRANSACTION 2
21#define CHECK_ADDRESS 3
22#define GET_PRINTABLE_AMOUNT 4
23
24/*
25 * Amounts are stored as bytes, with a max size of 16 (see protobuf
26 * specifications). Max 16B integer is 340282366920938463463374607431768211455
27 * in decimal, which is a 32-long char string.
28 * The printable amount also contains spaces, the ticker symbol (with variable
29 * size, up to 12 in Ethereum for instance) and a terminating null byte, so 50
30 * bytes total should be a fair maximum.
31 */
32#define MAX_PRINTABLE_AMOUNT_SIZE 50
33
34// Structure parameter used by swap_handle_check_address
35// --8<-- [start:check_address_parameters_t]
37 // INPUTS //
38 // Additional data when dealing with tokens
39 // Content is coin application specific
42
43 // serialized path, segwit, version prefix, hash used, dictionary etc.
44 // fields and serialization format are coin application specific
47
48 // The address to check
50
51 // Extra content that may be relevant depending on context: memo, calldata, ...
52 // Content is coin application specific
54
55 // OUTPUT //
56 // Set to 1 if the address belongs to the device. 0 otherwise.
57 int result;
59// --8<-- [end:check_address_parameters_t]
60
61// Structure parameter used by swap_handle_get_printable_amount
62// --8<-- [start:get_printable_amount_parameters_t]
64 // INPUTS //
65 // Additional data when dealing with tokens
66 // Content is coin application specific
69
70 // Raw amount in big number format
71 uint8_t *amount;
73
74 // Set to true if the amount to format is the fee of the swap.
75 bool is_fee;
76
77 // OUTPUT //
78 // Set to the formatted string if the formatting succeeds. 0 otherwise.
81// --8<-- [end:get_printable_amount_parameters_t]
82
83// Structure parameter used by swap_copy_transaction_parameters
84// --8<-- [start:create_transaction_parameters_t]
86 // INPUTS //
87 // Additional data when dealing with tokens
88 // Content is coin application specific
91
92 // The amount validated on the screen by the user
93 uint8_t *amount;
95
96 // The fees amount validated on the screen by the user
97 uint8_t *fee_amount;
99
100 // The partner address that will receive the funds
103
104 // OUTPUT //
105 // /!\ This parameter is handled by the lib_standard_app, DO NOT interact
106 // with it in the Coin application
107 //
108 // After reception and signature or refusal of the transaction, the Coin
109 // application will return to Exchange. This boolean is used to inform the
110 // Exchange application of the result.
111 // Set to 1 if the transaction was successfully signed, 0 otherwise.
112 uint8_t result;
114// --8<-- [end:create_transaction_parameters_t]
115
116// --8<-- [start:libargs_t]
117// Parameter given through os_lib_call() to the Coin application by the Exchange application.
118// They are handled by the lib_standard_app main() function.
129// --8<-- [end:libargs_t]
char printable_amount[MAX_PRINTABLE_AMOUNT_SIZE]
unsigned int command
get_printable_amount_parameters_t * get_printable_amount
unsigned int unused
create_transaction_parameters_t * create_transaction
check_address_parameters_t * check_address
unsigned int id
struct libargs_s libargs_t
struct get_printable_amount_parameters_s get_printable_amount_parameters_t
#define MAX_PRINTABLE_AMOUNT_SIZE
struct check_address_parameters_s check_address_parameters_t
struct create_transaction_parameters_s create_transaction_parameters_t