Skip to content

Commit

Permalink
[cgo] refs fibercrypto#116 Added functions helpers in coin.outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Jan 29, 2020
1 parent 9057fdc commit 28e5b44
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
11 changes: 0 additions & 11 deletions lib/cgo/cli.cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ func SKY_cli_Config_FullDBPath(_c *C.cli__Config, _arg0 *C.GoString_) (____error
return
}

//export SKY_cli_NewCLI
func SKY_cli_NewCLI(_cfg *C.cli__Config, _arg1 *C.CLI__Handle) (____error_code uint32) {
cfg := *(*cli.Config)(unsafe.Pointer(_cfg))
__arg1, ____return_err := cli.NewCLI(cfg)
____error_code = libErrorCode(____return_err)
if ____return_err == nil {
*_arg1 = registerCLIHandle(__arg1)
}
return
}

//export SKY_cli_WalletLoadError_Error
func SKY_cli_WalletLoadError_Error(_e *C.cli__WalletLoadError, _arg0 *C.GoString_) (____error_code uint32) {
e := *(*cli.WalletLoadError)(unsafe.Pointer(_e))
Expand Down
80 changes: 80 additions & 0 deletions lib/cgo/coin.outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"reflect"
"unsafe"

cipher "github.com/SkycoinProject/skycoin/src/cipher"
coin "github.com/SkycoinProject/skycoin/src/coin"
)

Expand Down Expand Up @@ -224,3 +225,82 @@ func SKY_coin_UxArray_Add(_ua *C.coin__UxArray, _other *C.coin__UxArray, _arg1 *
copyToBuffer(reflect.ValueOf(__arg1[:]), unsafe.Pointer(_arg1), uint(SizeofUxArray))
return
}

// Helpers

//export SKY_coin_AddressUxOuts_Get
func SKY_coin_AddressUxOuts_Get(handle C.AddressUxOuts__Handle, _key *C.cipher__Address, _uxOuts *C.coin__UxArray) (____error_code uint32) {
a, ok := lookupAddressUxOutHandle(handle)
if ok {
key := *(*cipher.Address)(unsafe.Pointer(_key))
uxOuts, found := (*a)[key]
if found {
copyTocoin_UxArray(reflect.ValueOf(uxOuts), _uxOuts)
____error_code = SKY_OK
}
} else {
____error_code = SKY_BAD_HANDLE
}
return
}

//export SKY_coin_AddressUxOuts_HasKey
func SKY_coin_AddressUxOuts_HasKey(handle C.AddressUxOuts__Handle, _key *C.cipher__Address, _hasKey *bool) (____error_code uint32) {
a, ok := lookupAddressUxOutHandle(handle)
if ok {
key := *(*cipher.Address)(unsafe.Pointer(_key))
_, found := (*a)[key]
*_hasKey = found
____error_code = SKY_OK
} else {
____error_code = SKY_BAD_HANDLE
}
return
}

//export SKY_coin_AddressUxOuts_GetOutputLength
func SKY_coin_AddressUxOuts_GetOutputLength(handle C.AddressUxOuts__Handle, _key *C.cipher__Address, _length *int) (____error_code uint32) {
a, ok := lookupAddressUxOutHandle(handle)
if ok {
key := *(*cipher.Address)(unsafe.Pointer(_key))
uxOuts, found := (*a)[key]
if found {
*_length = len(uxOuts)
____error_code = SKY_OK
}
} else {
____error_code = SKY_BAD_HANDLE
}
return
}

//export SKY_coin_AddressUxOuts_Length
func SKY_coin_AddressUxOuts_Length(handle C.AddressUxOuts__Handle, _length *int) (____error_code uint32) {
a, ok := lookupAddressUxOutHandle(handle)
if ok {
*_length = len(*a)
____error_code = SKY_OK
} else {
____error_code = SKY_BAD_HANDLE
}
return
}

//export SKY_coin_AddressUxOuts_Set
func SKY_coin_AddressUxOuts_Set(handle C.AddressUxOuts__Handle, _key *C.cipher__Address, _uxOuts *C.coin__UxArray) (____error_code uint32) {
a, ok := lookupAddressUxOutHandle(handle)
if ok {
key := *(*cipher.Address)(unsafe.Pointer(_key))
//Copy the slice because it is going to be kept
//We can't hold memory allocated outside Go
tempUxOuts := *(*coin.UxArray)(unsafe.Pointer(_uxOuts))
uxOuts := make(coin.UxArray, 0, len(tempUxOuts))

uxOuts = append(uxOuts, tempUxOuts...)
(*a)[key] = uxOuts
____error_code = SKY_OK
} else {
____error_code = SKY_BAD_HANDLE
}
return
}

0 comments on commit 28e5b44

Please sign in to comment.