Skip to content

Commit

Permalink
[cgo] refs fibercrypto#5 Added coin.mocks.WalletStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Mar 26, 2020
1 parent 03bcf20 commit 0290e0f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/fctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ typedef Handle WalletOutputMocks__Handle;
*/
typedef Handle WalletSetMocks__Handle;

/**
*WalletStorageMocks__Handle Handle, struct
* mocks.WalletStorage
*/
typedef Handle WalletStorageMocks__Handle;

// Callbacks

/**
Expand Down
84 changes: 84 additions & 0 deletions lib/cgo/coin.mocks.WalletStorage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package main

import (
"errors"
"unsafe"

core "github.com/fibercrypto/fibercryptowallet/src/core"
)

/*
#include <string.h>
#include <stdlib.h>
#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
}
3 changes: 2 additions & 1 deletion lib/cgo/handles
Original file line number Diff line number Diff line change
Expand Up @@ -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
CGOGEN HANDLES mocks__WalletSet|WalletSetMocks
CGOGEN HANDLES mocks__WalletStorage|WalletStorageMocks
14 changes: 14 additions & 0 deletions lib/cgo/libfc_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 0290e0f

Please sign in to comment.