From 34c8e1d73bf971cca665fcf6cc3852685001e819 Mon Sep 17 00:00:00 2001 From: Olemis Lang Date: Sun, 6 May 2018 17:44:20 -0400 Subject: [PATCH] [lib] refs #992 - Load cli config handle. [====] Synthesis: Tested: 49 | Passing: 49 | Failing: 0 | Crashing: 0 --- include/skytypes.h | 7 ++++++- lib/cgo/api.cli.cli.go | 26 ++++++++++++++++++-------- lib/cgo/libsky_handle.go | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/skytypes.h b/include/skytypes.h index 6a1a364db..6f3722cc0 100644 --- a/include/skytypes.h +++ b/include/skytypes.h @@ -122,11 +122,16 @@ typedef GoInt64_ Handle; typedef Handle PasswordReader__Handle; /** - * Memory handle granting clients with access to perform Skycoin RPC API calls + * Memory handle to perform Skycoin RPC API calls * encrypted wallets. */ typedef Handle WebRpcClient__Handle; +/** + * Memory handle to access to Skycoin CLI configuration + */ +typedef Handle Config__Handle; + #include "cipher.hash.go.h" #include "cipher.crypto.go.h" #include "cipher.address.go.h" diff --git a/lib/cgo/api.cli.cli.go b/lib/cgo/api.cli.cli.go index 5f329bc8b..7f863031a 100644 --- a/lib/cgo/api.cli.cli.go +++ b/lib/cgo/api.cli.cli.go @@ -1,5 +1,9 @@ package main +import ( + cli "github.com/skycoin/skycoin/src/api/cli" +) + /* #include @@ -9,12 +13,18 @@ package main */ import "C" -import ( - cli "github.com/skycoin/skycoin/src/api/cli" -) - -//export SKY_cli_NewPasswordReader -func SKY_cli_NewPasswordReader(_p []byte) C.PasswordReader__Handle { - pr := cli.NewPasswordReader(_p) - return registerPasswordReaderHandle(pr) +//export SKY_cli_LoadConfig +func SKY_cli_LoadConfig(_arg0 *C.Config__Handle) (____error_code uint32) { + ____error_code = 0 + defer func() { + ____error_code = catchApiPanic(____error_code, recover()) + }() + __arg0, ____return_err := cli.LoadConfig() + ____error_code = libErrorCode(____return_err) + if ____return_err == nil { + *_arg0 = registerConfigHandle(&__arg0) + } + return } + +// TODO: RpcClientFromConfig diff --git a/lib/cgo/libsky_handle.go b/lib/cgo/libsky_handle.go index 6244c13c0..7d9ff4561 100644 --- a/lib/cgo/libsky_handle.go +++ b/lib/cgo/libsky_handle.go @@ -48,6 +48,20 @@ func lookupWebRpcClientHandle(handle C.WebRpcClient__Handle) (*webrpc.Client, bo return nil, false } +func registerConfigHandle(obj *cli.Config) C.Config__Handle { + return (C.Config__Handle)(registerHandle(obj)) +} + +func lookupConfigHandle(handle C.Config__Handle) (*cli.Config, bool) { + obj, ok := lookupHandleObj(Handle(handle)) + if ok { + if obj, isOK := (obj).(*cli.Config); isOK { + return obj, true + } + } + return nil, false +} + func registerPasswordReaderHandle(obj cli.PasswordReader) C.PasswordReader__Handle { return (C.PasswordReader__Handle)(registerHandle(obj)) }