Skip to content

Commit

Permalink
[cgo] refs fibercrypto#5 Finalized util.pluginutil
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Feb 8, 2020
1 parent 278884e commit 2533a30
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 13 deletions.
21 changes: 14 additions & 7 deletions include/fctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,19 @@ typedef GoInt64_ Handle;
* String Slice Handle
*/
typedef Handle Strings__Handle;
typedef Handle core__SecKey;
typedef Handle core__PubKey;
typedef Handle core__Address;
typedef Handle core__AddressIterator;
typedef Handle core__TxnSigner;
typedef Handle core__TxnSignerIterator;
typedef Handle core__CryptoAccount;

/**
* AltcoinPlugin__Handle Handle, interface core.AltcoinPlugin
*/
typedef Handle AltcoinPlugin__Handle;

/**
* TxnSigner__Handle Handle, interface core.TxnSigner
*/
typedef Handle TxnSigner__Handle;

/**
* Wallet__Handle Handle, interface core.Wallet
*/
typedef Handle Wallet__Handle;
#endif
44 changes: 44 additions & 0 deletions lib/cgo/libfc_handle.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package main

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

/*
#include <string.h>
Expand Down Expand Up @@ -60,3 +64,43 @@ func lookupStringsHandle(handle C.Strings__Handle) ([]string, bool) {
}
return nil, false
}

func lookupAltcoinPluginHandle(handle C.AltcoinPlugin__Handle) (*core.AltcoinPlugin, bool) {
obj, ok := lookupHandle(C.Handle(handle))
if ok {
if obj, isOK := (obj).(*core.AltcoinPlugin); isOK {
return obj, true
}
}
return nil, false
}

func registerAltcoinPluginHandle(obj *core.AltcoinPlugin) C.AltcoinPlugin__Handle {
return (C.AltcoinPlugin__Handle)(registerHandle(obj))
}

func lookupWalletHandle(handle C.Wallet__Handle) (*core.Wallet, bool) {
obj, ok := lookupHandle(C.Handle(handle))
if ok {
if obj, isOK := (obj).(*core.Wallet); isOK {
return obj, true
}
}
return nil, false
}

func registerWalletHandle(obj *core.Wallet) C.Wallet__Handle {
return (C.Wallet__Handle)(registerHandle(obj))
}
func lookupTxnSignerHandle(handle C.TxnSigner__Handle) (*core.TxnSigner, bool) {
obj, ok := lookupHandle(C.Handle(handle))
if ok {
if obj, isOK := (obj).(*core.TxnSigner); isOK {
return obj, true
}
}
return nil, false
}
func registerTxnSignerHandle(obj *core.TxnSigner) C.TxnSigner__Handle {
return (C.TxnSigner__Handle)(registerHandle(obj))
}
53 changes: 47 additions & 6 deletions lib/cgo/util.pluginutil.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import "github.com/fibercrypto/fibercryptowallet/src/util"
import (
"unsafe"

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

/*
Expand All @@ -12,10 +17,46 @@ import "github.com/fibercrypto/fibercryptowallet/src/util"
import "C"

//export FC_util_AltcoinCaption
func FC_util_AltcoinCaption(_arg0 string, _arg1 *C.GoString_) (____error_code uint32) {
callNode()
arg0 := string(_arg0)
arg1 := util.AltcoinCaption(arg0)
copyString(arg1, _arg1)
func FC_util_AltcoinCaption(_ticker string, _arg1 *C.GoString_) (____error_code uint32) {
ticker := _ticker
__arg1 := util.AltcoinCaption(ticker)
copyString(__arg1, _arg1)
return
}

//export FC_util_AltcoinQuotient
func FC_util_AltcoinQuotient(_ticker string, _arg1 *uint64) (____error_code uint32) {
ticker := _ticker
__arg1, ____return_err := util.AltcoinQuotient(ticker)
____error_code = libErrorCode(____return_err)
if ____return_err == nil {
*_arg1 = __arg1
}
return
}

//export FC_util_RegisterAltcoin
func FC_util_RegisterAltcoin(_p *C.AltcoinPlugin__Handle) (____error_code uint32) {
__p, okp := lookupAltcoinPluginHandle(*_p)
if !okp {
____error_code = FC_BAD_HANDLE
return
}
p := *__p
util.RegisterAltcoin(p)
return
}

//export FC_util_LookupSignerByUID
func FC_util_LookupSignerByUID(_wlt *C.Wallet__Handle, _id *C.core__UID, _arg2 *C.TxnSigner__Handle) (____error_code uint32) {
__wlt, okwlt := lookupWalletHandle(*_wlt)
if !okwlt {
____error_code = FC_BAD_HANDLE
return
}
wlt := *__wlt
id := *(*core.UID)(unsafe.Pointer(_id))
__arg2 := util.LookupSignerByUID(wlt, id)
*_arg2 = registerTxnSignerHandle(&__arg2)
return
}

0 comments on commit 2533a30

Please sign in to comment.