From 0290e0f0da6a98cb66dc01134838770862d1d8b1 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Wed, 25 Mar 2020 22:43:12 -0400 Subject: [PATCH] [cgo] refs #5 Added `coin.mocks.WalletStorage` --- include/fctypes.h | 6 +++ lib/cgo/coin.mocks.WalletStorage.go | 84 +++++++++++++++++++++++++++++ lib/cgo/handles | 3 +- lib/cgo/libfc_handle.go | 14 +++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 lib/cgo/coin.mocks.WalletStorage.go diff --git a/include/fctypes.h b/include/fctypes.h index eb702e8..c06bc55 100644 --- a/include/fctypes.h +++ b/include/fctypes.h @@ -559,6 +559,12 @@ typedef Handle WalletOutputMocks__Handle; */ typedef Handle WalletSetMocks__Handle; +/** + *WalletStorageMocks__Handle Handle, struct + * mocks.WalletStorage + */ +typedef Handle WalletStorageMocks__Handle; + // Callbacks /** diff --git a/lib/cgo/coin.mocks.WalletStorage.go b/lib/cgo/coin.mocks.WalletStorage.go new file mode 100644 index 0000000..b33c34d --- /dev/null +++ b/lib/cgo/coin.mocks.WalletStorage.go @@ -0,0 +1,84 @@ +package main + +import ( + "errors" + "unsafe" + + core "github.com/fibercrypto/fibercryptowallet/src/core" +) + +/* + + #include + #include + + #include "fctypes.h" + #include "fccallback.h" +*/ +import "C" + +//export FC_mocks_WalletStorage_Decrypt +func FC_mocks_WalletStorage_Decrypt(__m *C.WalletStorageMocks__Handle, _walletName string, _password *C.PasswordReader) (____error_code uint32) { + _m, ok_m := lookupWalletStorageMocksHandle(*__m) + if !ok_m { + ____error_code = FC_BAD_HANDLE + return + } + walletName := _walletName + password := func(pString string, pKVS core.KeyValueStore) (string, error) { + var pStringOut C.GoString_ + var pStringIn C.GoString_ + copyString(pString, &pStringIn) + pKVSHandle := registerKeyValueStoreHandle(&pKVS) + result := C.callPasswordReader(_password, pStringIn, pKVSHandle, &pStringOut) + closeHandle(Handle(pKVSHandle)) + if result == FC_OK { + pStringOut_ := *(*string)(unsafe.Pointer(&pStringOut)) + return string(pStringOut_), nil + } + return "", errors.New("Error in PasswdReader") + } + _m.Decrypt(walletName, password) + return +} + +//export FC_mocks_WalletStorage_Encrypt +func FC_mocks_WalletStorage_Encrypt(__m *C.WalletStorageMocks__Handle, _walletName string, _password *C.PasswordReader) (____error_code uint32) { + _m, ok_m := lookupWalletStorageMocksHandle(*__m) + if !ok_m { + ____error_code = FC_BAD_HANDLE + return + } + walletName := _walletName + password := func(pString string, pKVS core.KeyValueStore) (string, error) { + var pStringOut C.GoString_ + var pStringIn C.GoString_ + copyString(pString, &pStringIn) + pKVSHandle := registerKeyValueStoreHandle(&pKVS) + result := C.callPasswordReader(_password, pStringIn, pKVSHandle, &pStringOut) + closeHandle(Handle(pKVSHandle)) + if result == FC_OK { + pStringOut_ := *(*string)(unsafe.Pointer(&pStringOut)) + return string(pStringOut_), nil + } + return "", errors.New("Error in PasswdReader") + } + _m.Encrypt(walletName, password) + return +} + +//export FC_mocks_WalletStorage_IsEncrypted +func FC_mocks_WalletStorage_IsEncrypted(__m *C.WalletStorageMocks__Handle, _walletName string, _arg1 *bool) (____error_code uint32) { + _m, ok_m := lookupWalletStorageMocksHandle(*__m) + if !ok_m { + ____error_code = FC_BAD_HANDLE + return + } + walletName := _walletName + __arg1, ____return_err := _m.IsEncrypted(walletName) + ____error_code = libErrorCode(____return_err) + if ____return_err == nil { + *_arg1 = __arg1 + } + return +} diff --git a/lib/cgo/handles b/lib/cgo/handles index 2fc20ac..68d641f 100644 --- a/lib/cgo/handles +++ b/lib/cgo/handles @@ -79,4 +79,5 @@ CGOGEN HANDLES mocks__WalletAddress|WalletAddressMocks CGOGEN HANDLES mocks__WalletEnv|WalletEnvMocks CGOGEN HANDLES mocks__WalletIterator|WalletIteratorMocks CGOGEN HANDLES mocks__WalletOutput|WalletOutputMocks -CGOGEN HANDLES mocks__WalletSet|WalletSetMocks \ No newline at end of file +CGOGEN HANDLES mocks__WalletSet|WalletSetMocks +CGOGEN HANDLES mocks__WalletStorage|WalletStorageMocks \ No newline at end of file diff --git a/lib/cgo/libfc_handle.go b/lib/cgo/libfc_handle.go index 6f1216f..82f91c0 100644 --- a/lib/cgo/libfc_handle.go +++ b/lib/cgo/libfc_handle.go @@ -1068,3 +1068,17 @@ func lookupWalletSetMocksHandle(handle C.WalletSetMocks__Handle) (*mocks.WalletS func registerWalletSetMocksHandle(obj *mocks.WalletSet) C.WalletSetMocks__Handle { return (C.WalletSetMocks__Handle)(registerHandle(obj)) } + +func lookupWalletStorageMocksHandle(handle C.WalletStorageMocks__Handle) (*mocks.WalletStorage, bool) { + obj, ok := lookupHandle(C.Handle(handle)) + if ok { + if obj, isOK := (obj).(*mocks.WalletStorage); isOK { + return obj, true + } + } + return nil, false +} + +func registerWalletStorageMocksHandle(obj *mocks.WalletStorage) C.WalletStorageMocks__Handle { + return (C.WalletStorageMocks__Handle)(registerHandle(obj)) +}