Skip to content

Coin Application API

The handle functions must be defined by each Coin application implementing the SWAP feature.

Handlers are called by Exchange through the os_lib_call API, and dispatched by the main() and library_app_main() functions of the lib_standard_app.

The Exchange application is responsible for handling the flow and sequencing of the SWAP.

ledger-secure-sdk/lib_standard_app/main.c

/* This function is called by the main() function if this application was started by Exchange
 * through an os_lib_call() as opposed to being started from the Dashboard.
 *
 * We dispatch the Exchange request to the correct handler.
 * Handlers content are not defined in the `lib_standard_app`
 */
WEAK void library_app_main(libargs_t *args)
{
    BEGIN_TRY
    {
        TRY
        {
            PRINTF("Inside library\n");
            switch (args->command) {
                case SIGN_TRANSACTION: {
                    // Backup up transaction parameters and wipe BSS to avoid collusion with
                    // app-exchange BSS data.
                    bool success = swap_copy_transaction_parameters(args->create_transaction);
                    if (success) {
                        // BSS was wiped, we can now init these globals
                        G_called_from_swap    = true;
                        G_swap_response_ready = false;
                        // Keep the address at which we'll reply the signing status
                        G_swap_signing_return_value_address = &args->create_transaction->result;

                        common_app_init();

#ifdef HAVE_NBGL
                        nbgl_useCaseSpinner("Signing");
#endif  // HAVE_NBGL

                        app_main();
                    }
                    break;
                }
                case CHECK_ADDRESS:
                    swap_handle_check_address(args->check_address);
                    break;
                case GET_PRINTABLE_AMOUNT:
                    swap_handle_get_printable_amount(args->get_printable_amount);
                    break;
                default:
                    break;
            }
        }
        CATCH_OTHER(e)
        {
            (void) e;
            PRINTF("Exiting following exception: 0x%04X\n", e);
        }
        FINALLY
        {
            os_lib_end();
        }
    }
    END_TRY;
}