From 92d8cf65d12eddcdfb29720dacb66225769a53b9 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Wed, 4 Sep 2019 14:16:40 -0400 Subject: [PATCH] [cgo] refs #105 Added datatype Path__Handle --- include/skytypes.h | 5 +++++ lib/cgo/cipher.bip32.path.go | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/skytypes.h b/include/skytypes.h index c9d6bb1cf..d50fd2d56 100644 --- a/include/skytypes.h +++ b/include/skytypes.h @@ -237,6 +237,11 @@ typedef Handle PublicKey__Handle; */ typedef Handle PrivateKey__Handle; +/** + * Path__Handle Handle, struct bip32.Path + */ +typedef Handle Path__Handle; + /** * Coin__Handle Handle, struct bip44.Coin */ diff --git a/lib/cgo/cipher.bip32.path.go b/lib/cgo/cipher.bip32.path.go index e5f45ed39..93650079e 100644 --- a/lib/cgo/cipher.bip32.path.go +++ b/lib/cgo/cipher.bip32.path.go @@ -26,14 +26,44 @@ func SKY_bip32_PathNode_Hardened(_pk *C.bip32__PathNode) (____error_code uint32) return } -// nolint megacheck //export SKY_bip32_ParsePath -func SKY_bip32_ParsePath(_p string, _arg0 *C.bip32__Path) (____error_code uint32) { +func SKY_bip32_ParsePath(_p string, _arg0 *C.Path__Handle) (____error_code uint32) { p, err := bip32.ParsePath(_p) ____error_code = libErrorCode(err) if err == nil { - _arg0 = (*C.bip32__Path)(unsafe.Pointer(p)) + *_arg0 = registerPathHandle(p) } return } + +//export SKY_bip32_Path_Count +func SKY_bip32_Path_Count(handle C.Path__Handle, _arg0 *int) (____error_code uint32) { + p, okp := lookupPathHandle(handle) + + if !okp { + ____error_code = SKY_BAD_HANDLE + return + } + + *_arg0 = len(p.Elements) + return +} + +//export SKY_bip32_Path_GetElements +func SKY_bip32_Path_GetElements(handle C.Path__Handle, post int, _arg0 *C.bip32__PathNode) (____error_code uint32) { + p, okp := lookupPathHandle(handle) + + if !okp { + ____error_code = SKY_BAD_HANDLE + return + } + + if len(p.Elements) <= post { + ____error_code = SKY_BAD_HANDLE + return + } + + *_arg0 = *(*C.bip32__PathNode)(unsafe.Pointer(&p.Elements[post])) + return +} \ No newline at end of file