Skip to content

Commit

Permalink
[lib] refs #992 - Implement memory handles for Web RPC API
Browse files Browse the repository at this point in the history
[====] Synthesis: Tested: 49 | Passing: 49 | Failing: 0 | Crashing: 0
  • Loading branch information
olemis committed May 6, 2018
1 parent eeec042 commit 92ed314
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/skytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ typedef GoInt64_ Handle;
*/
typedef Handle PasswordReader__Handle;

/**
* Memory handle granting clients with access to perform Skycoin RPC API calls
* encrypted wallets.
*/
typedef Handle WebRpcClient__Handle;

#include "cipher.hash.go.h"
#include "cipher.crypto.go.h"
#include "cipher.address.go.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/cgo/api.cli.create_rawtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func SKY_cli_CreateRawTxFromWallet(_ctx C.Handle, _walletFile, _chgAddr string,
}

//export SKY_cli_CreateRawTxFromAddress
func SKY_cli_CreateRawTxFromAddress(_ctx C.Handle, _addr, _walletFile, _chgAddr string, _toAddrs []C.cli__SendAmount, _tx *C.coin__Transaction) uint32 {
func SKY_cli_CreateRawTxFromAddress(_ctx C.WebRpcClient__Handle, _addr, _walletFile, _chgAddr string, _toAddrs []C.cli__SendAmount, _tx *C.coin__Transaction) uint32 {
// TODO: Implement
return SKY_ERROR
}
Expand Down
18 changes: 17 additions & 1 deletion lib/cgo/libsky_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ package main
import "C"

import (
cli "github.com/skycoin/skycoin/src/api/cli"
"unsafe"

cli "github.com/skycoin/skycoin/src/api/cli"
webrpc "github.com/skycoin/skycoin/src/api/webrpc"
)

type Handle uint64
Expand All @@ -32,6 +34,20 @@ func lookupHandleObj(handle Handle) (interface{}, bool) {
return obj, ok
}

func registerWebRpcClientHandle(obj *webrpc.Client) C.WebRpcClient__Handle {
return (C.WebRpcClient__Handle)(registerHandle(obj))
}

func lookupWebRpcClientHandle(handle C.WebRpcClient__Handle) (*webrpc.Client, bool) {
obj, ok := lookupHandleObj(Handle(handle))
if ok {
if obj, isOK := (obj).(*webrpc.Client); isOK {
return obj, true
}
}
return nil, false
}

func registerPasswordReaderHandle(obj cli.PasswordReader) C.PasswordReader__Handle {
return (C.PasswordReader__Handle)(registerHandle(obj))
}
Expand Down

0 comments on commit 92ed314

Please sign in to comment.