@@ -762,69 +762,77 @@ void library_main(libargs_t *args) {
762
762
os_lib_end ();
763
763
}
764
764
765
- __attribute__((section (".boot" ))) int main (int arg0 ) {
766
- #ifdef USE_LIB_ETHEREUM
765
+ /* Eth clones do not actually contain any logic, they delegate everything to the ETH application.
766
+ * Start Eth in lib mode with the correct chain config
767
+ */
768
+ __attribute__((noreturn )) void clone_main (libargs_t * args ) {
769
+ PRINTF ("Starting in clone_main\n" );
767
770
BEGIN_TRY {
768
771
TRY {
769
772
unsigned int libcall_params [5 ];
770
773
chain_config_t local_chainConfig ;
771
774
init_coin_config (& local_chainConfig );
772
775
773
- PRINTF ("Hello from Eth-clone\n" );
774
- check_api_level (CX_COMPAT_APILEVEL );
775
- // delegate to Ethereum app/lib
776
776
libcall_params [0 ] = (unsigned int ) "Ethereum" ;
777
777
libcall_params [1 ] = 0x100 ;
778
- libcall_params [2 ] = RUN_APPLICATION ;
779
778
libcall_params [3 ] = (unsigned int ) & local_chainConfig ;
780
- #ifdef HAVE_NBGL
781
- const char app_name [] = APPNAME ;
782
- caller_app_t capp ;
783
- nbgl_icon_details_t icon_details ;
784
- uint8_t bitmap [sizeof (ICONBITMAP )];
785
-
786
- memcpy (& icon_details , & ICONGLYPH , sizeof (ICONGLYPH ));
787
- memcpy (& bitmap , & ICONBITMAP , sizeof (bitmap ));
788
- icon_details .bitmap = (const uint8_t * ) bitmap ;
789
- capp .name = app_name ;
790
- capp .icon = & icon_details ;
791
- libcall_params [4 ] = (unsigned int ) & capp ;
792
- #else
793
- libcall_params [4 ] = NULL ;
794
- #endif // HAVE_NBGL
795
779
796
- if (arg0 ) {
797
- // call as a library
798
- libcall_params [2 ] = ((unsigned int * ) arg0 )[1 ];
799
- libcall_params [4 ] = ((unsigned int * ) arg0 )[3 ]; // library arguments
780
+ // Clone called by Exchange, forward the request to Ethereum
781
+ if (args != NULL ) {
782
+ if (args -> id != 0x100 ) {
783
+ os_sched_exit (0 );
784
+ }
785
+ libcall_params [2 ] = args -> command ;
786
+ libcall_params [4 ] = (unsigned int ) args -> get_printable_amount ;
800
787
os_lib_call ((unsigned int * ) & libcall_params );
801
- (( unsigned int * ) arg0 )[ 0 ] = libcall_params [ 1 ];
788
+ // Ethereum fulfilled the request and returned to us. We return to Exchange.
802
789
os_lib_end ();
803
790
} else {
804
- // launch coin application
805
- libcall_params [1 ] = 0x100 ; // use the Init call, as we won't exit
791
+ // Clone called from Dashboard, start Ethereum
792
+ libcall_params [2 ] = RUN_APPLICATION ;
793
+ // On Stax, forward our icon to Ethereum
794
+ #ifdef HAVE_NBGL
795
+ const char app_name [] = APPNAME ;
796
+ caller_app_t capp ;
797
+ nbgl_icon_details_t icon_details ;
798
+ uint8_t bitmap [sizeof (ICONBITMAP )];
799
+
800
+ memcpy (& icon_details , & ICONGLYPH , sizeof (ICONGLYPH ));
801
+ memcpy (& bitmap , & ICONBITMAP , sizeof (bitmap ));
802
+ icon_details .bitmap = (const uint8_t * ) bitmap ;
803
+ capp .name = app_name ;
804
+ capp .icon = & icon_details ;
805
+ libcall_params [4 ] = (unsigned int ) & capp ;
806
+ #else
807
+ libcall_params [4 ] = 0 ;
808
+ #endif // HAVE_NBGL
806
809
os_lib_call ((unsigned int * ) & libcall_params );
810
+ // Ethereum should not return to us
811
+ os_sched_exit (-1 );
807
812
}
808
813
}
809
814
FINALLY {
810
815
}
811
816
}
812
817
END_TRY ;
813
- // no return
814
- #else
818
+
819
+ // os_lib_call will raise if Ethereum application is not installed. Do not try to recover.
820
+ os_sched_exit (-1 );
821
+ }
822
+
823
+ int ethereum_main (libargs_t * args ) {
815
824
// exit critical section
816
825
__asm volatile ("cpsie i" );
817
826
818
827
// ensure exception will work as planned
819
828
os_boot ();
820
829
821
- if (! arg0 ) {
830
+ if (args == NULL ) {
822
831
// called from dashboard as standalone eth app
823
832
coin_main (NULL );
824
833
return 0 ;
825
834
}
826
835
827
- libargs_t * args = (libargs_t * ) arg0 ;
828
836
if (args -> id != 0x100 ) {
829
837
app_exit ();
830
838
return 0 ;
@@ -838,6 +846,13 @@ __attribute__((section(".boot"))) int main(int arg0) {
838
846
// called as ethereum or altcoin library
839
847
library_main (args );
840
848
}
841
- #endif
842
849
return 0 ;
843
850
}
851
+
852
+ __attribute__((section (".boot" ))) int main (int arg0 ) {
853
+ #ifdef USE_LIB_ETHEREUM
854
+ clone_main ((libargs_t * ) arg0 );
855
+ #else
856
+ return ethereum_main ((libargs_t * ) arg0 );
857
+ #endif
858
+ }
0 commit comments