From cc17413e9c9f62be7682cb807828bc238a650a31 Mon Sep 17 00:00:00 2001 From: Hanh Date: Fri, 18 Nov 2022 23:28:56 +0800 Subject: [PATCH] Return dummy u8 in c ffi --- binding.h | 23 +++++++++-------------- binding2.h | 5 ----- src/api/dart_ffi.rs | 16 ++++++++-------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/binding.h b/binding.h index 78df482..c7c1496 100644 --- a/binding.h +++ b/binding.h @@ -13,17 +13,17 @@ typedef char bool; #endif typedef void *DartPostCObjectFnType; -typedef struct CResult { - char value; - char *error; -} CResult; - #define QR_DATA_SIZE 256 #define MAX_ATTEMPTS 10 #define N 200000 +typedef struct CResult_u8 { + uint8_t value; + char *error; +} CResult_u8; + typedef struct CResult_u32 { uint32_t value; char *error; @@ -34,11 +34,6 @@ typedef struct CResult_____c_char { char *error; } CResult_____c_char; -typedef struct CResult_u8 { - uint8_t value; - char *error; -} CResult_u8; - typedef struct CResult_u64 { uint64_t value; char *error; @@ -50,11 +45,11 @@ void dart_post_cobject(DartPostCObjectFnType ptr); void deallocate_str(char *s); -CResult init_wallet(uint8_t coin, char *db_path); +struct CResult_u8 init_wallet(uint8_t coin, char *db_path); -CResult migrate_db(uint8_t coin, char *db_path); +struct CResult_u8 migrate_db(uint8_t coin, char *db_path); -CResult migrate_data_db(uint8_t coin); +struct CResult_u8 migrate_data_db(uint8_t coin); void set_active(uint8_t active); @@ -74,7 +69,7 @@ struct CResult_u32 new_account(uint8_t coin, char *name, char *data, int32_t ind void new_sub_account(char *name, int32_t index, uint32_t count); -CResult convert_to_watchonly(uint8_t coin, uint32_t id_account); +struct CResult_u8 convert_to_watchonly(uint8_t coin, uint32_t id_account); struct CResult_____c_char get_backup(uint8_t coin, uint32_t id_account); diff --git a/binding2.h b/binding2.h index 9684967..c45ce88 100644 --- a/binding2.h +++ b/binding2.h @@ -12,8 +12,3 @@ typedef char bool; #endif #endif typedef void *DartPostCObjectFnType; - -typedef struct CResult { - char value; - char *error; -} CResult; diff --git a/src/api/dart_ffi.rs b/src/api/dart_ffi.rs index cc82eef..97b6939 100644 --- a/src/api/dart_ffi.rs +++ b/src/api/dart_ffi.rs @@ -90,24 +90,24 @@ pub struct CResult { } #[no_mangle] -pub unsafe extern "C" fn init_wallet(coin: u8, db_path: *mut c_char) -> CResult<()> { +pub unsafe extern "C" fn init_wallet(coin: u8, db_path: *mut c_char) -> CResult { try_init_logger(); from_c_str!(db_path); - to_cresult(init_coin(coin, &db_path)) + to_cresult(init_coin(coin, &db_path).and_then(|()| Ok(0u8))) } #[no_mangle] -pub unsafe extern "C" fn migrate_db(coin: u8, db_path: *mut c_char) -> CResult<()> { +pub unsafe extern "C" fn migrate_db(coin: u8, db_path: *mut c_char) -> CResult { try_init_logger(); from_c_str!(db_path); - to_cresult(crate::coinconfig::migrate_db(coin, &db_path)) + to_cresult(crate::coinconfig::migrate_db(coin, &db_path).and_then(|()| Ok(0u8))) } #[no_mangle] #[tokio::main] -pub async unsafe extern "C" fn migrate_data_db(coin: u8) -> CResult<()> { +pub async unsafe extern "C" fn migrate_data_db(coin: u8) -> CResult { try_init_logger(); - to_cresult(crate::coinconfig::migrate_data(coin).await) + to_cresult(crate::coinconfig::migrate_data(coin).await.and_then(|()| Ok(0u8))) } #[no_mangle] @@ -197,9 +197,9 @@ pub unsafe extern "C" fn new_sub_account(name: *mut c_char, index: i32, count: u } #[no_mangle] -pub unsafe extern "C" fn convert_to_watchonly(coin: u8, id_account: u32) -> CResult<()> { +pub unsafe extern "C" fn convert_to_watchonly(coin: u8, id_account: u32) -> CResult { let res = crate::api::account::convert_to_watchonly(coin, id_account); - to_cresult(res) + to_cresult(res.and_then(|()| Ok(0u8))) } #[no_mangle]