From b9ed13f4afecb8b08e09b0e56680a57591d7d765 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Wed, 11 Sep 2019 10:01:45 -0400 Subject: [PATCH 1/8] [cgo][libc] refs #105 Added functions `SKY_coin_DeserializeTransactionHex` --- CHANGELOG.md | 1 + lib/cgo/cipher.bip32.path.go | 4 ++-- lib/cgo/cipher.bip44.bip44.go | 4 ++-- lib/cgo/coin.transactions.go | 12 ++++++++++++ lib/cgo/libsky_mem.go | 2 +- lib/cgo/tests/check_coin.transactions.c | 6 ++---- lib/cgo/tests/cipher.testsuite.c | 2 +- lib/cgo/tests/testutils/libsky_assert.common.c | 10 +++++----- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87956e3a9..a104a288f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added function `SKY_cli_GetWalletOutputs` - Added function `SKY_cli_GetBalanceOfAddresses` - Added datatype `GetOutputser__Handle` +- Added functions `SKY_coin_DeserializeTransactionHex` ### Removed diff --git a/lib/cgo/cipher.bip32.path.go b/lib/cgo/cipher.bip32.path.go index 93650079e..09c544d62 100644 --- a/lib/cgo/cipher.bip32.path.go +++ b/lib/cgo/cipher.bip32.path.go @@ -63,7 +63,7 @@ func SKY_bip32_Path_GetElements(handle C.Path__Handle, post int, _arg0 *C.bip32_ ____error_code = SKY_BAD_HANDLE return } - + *_arg0 = *(*C.bip32__PathNode)(unsafe.Pointer(&p.Elements[post])) return -} \ No newline at end of file +} diff --git a/lib/cgo/cipher.bip44.bip44.go b/lib/cgo/cipher.bip44.bip44.go index 5703fed6e..92192d099 100644 --- a/lib/cgo/cipher.bip44.bip44.go +++ b/lib/cgo/cipher.bip44.bip44.go @@ -96,6 +96,6 @@ func SKY_bip44_Account_GetPrivateKey(_a C.Account__Handle, _arg0 *C.PrivateKey__ return } - * _arg0 = registerPrivateKeyHandle(a.PrivateKey) + *_arg0 = registerPrivateKeyHandle(a.PrivateKey) return -} \ No newline at end of file +} diff --git a/lib/cgo/coin.transactions.go b/lib/cgo/coin.transactions.go index 2f92fecc8..53981872c 100644 --- a/lib/cgo/coin.transactions.go +++ b/lib/cgo/coin.transactions.go @@ -734,3 +734,15 @@ func SKY_coin_Transaction_SetInnerHash(handle *C.Transaction__Handle, _sha *C.ci tx.InnerHash = uxHash return } + +//export SKY_coin_DeserializeTransactionHex +func SKY_coin_DeserializeTransactionHex(_s string, _arg0 *C.Transaction__Handle) (___error_code uint32) { + + arg0, err := coin.DeserializeTransactionHex(_s) + + ___error_code = libErrorCode(err) + if err == nil { + *_arg0 = registerTransactionHandle(&arg0) + } + return +} diff --git a/lib/cgo/libsky_mem.go b/lib/cgo/libsky_mem.go index 0b1e64b94..cb84945fc 100644 --- a/lib/cgo/libsky_mem.go +++ b/lib/cgo/libsky_mem.go @@ -154,4 +154,4 @@ func copyTocoin_UxArray(src reflect.Value, dest *C.coin__UxArray) { dest.len = C.GoInt_(srcLen) } } -} \ No newline at end of file +} diff --git a/lib/cgo/tests/check_coin.transactions.c b/lib/cgo/tests/check_coin.transactions.c index 5472679bf..075d6fe4b 100644 --- a/lib/cgo/tests/check_coin.transactions.c +++ b/lib/cgo/tests/check_coin.transactions.c @@ -618,12 +618,10 @@ START_TEST(TestTransactionSerialization) Transaction__Handle handle = 0; makeTransaction(&handle); unsigned char buffer[1024]; - GoSlice_ data = {buffer, 0, 1024}; - result = SKY_coin_Transaction_Serialize(handle, &data); + GoSlice d = {buffer, 0, 1024}; + result = SKY_coin_Transaction_Serialize(handle, &d); ck_assert(result == SKY_OK); - registerMemCleanup(data.data); Transaction__Handle handle2 = 0; - GoSlice d = {data.data, data.len, data.cap}; result = SKY_coin_TransactionDeserialize(d, &handle2); ck_assert(result == SKY_OK); ck_assert(isTransactionHandleEq(&handle, &handle2)); diff --git a/lib/cgo/tests/cipher.testsuite.c b/lib/cgo/tests/cipher.testsuite.c index 169d7601b..6f2d7bda5 100644 --- a/lib/cgo/tests/cipher.testsuite.c +++ b/lib/cgo/tests/cipher.testsuite.c @@ -393,7 +393,7 @@ void ValidateSeedData(SeedTestData* seedData, InputTestData* inputData) keys.len = keys.cap = 0; keys.data = NULL; - SKY_cipher_GenerateDeterministicKeyPairs(seedData->Seed, seedData->Keys.len, (GoSlice_*)&keys); + SKY_cipher_GenerateDeterministicKeyPairs(seedData->Seed, seedData->Keys.len, &keys); ck_assert_msg(keys.data != NULL, "SKY_cipher_GenerateDeterministicKeyPairs must allocate memory slice with zero cap"); diff --git a/lib/cgo/tests/testutils/libsky_assert.common.c b/lib/cgo/tests/testutils/libsky_assert.common.c index cdd87a19d..416147479 100644 --- a/lib/cgo/tests/testutils/libsky_assert.common.c +++ b/lib/cgo/tests/testutils/libsky_assert.common.c @@ -144,8 +144,8 @@ GoInt isTransactionHandleEq(Transaction__Handle* handle1, Transaction__Handle* h cipher__SHA256 sha2 = ""; GoUint8 bufferP1[1024]; GoUint8 bufferP2[1024]; - GoSlice_ p1 = {bufferP1, 0, 1024}; - GoSlice_ p2 = {bufferP2, 0, 1024}; + GoSlice p1 = {bufferP1, 0, 1024}; + GoSlice p2 = {bufferP2, 0, 1024}; GoUint32 err = SKY_coin_Transaction_GetLength(*handle1, &len1); ck_assert_int_eq(err, SKY_OK); @@ -170,19 +170,19 @@ GoInt isTransactionHandleEq(Transaction__Handle* handle1, Transaction__Handle* h ck_assert_int_eq(err, SKY_OK); err = SKY_coin_Transaction_GetSigs(*handle2, &p2); ck_assert_int_eq(err, SKY_OK); - if (!equalSlices_(&p1, &p2, sizeof(cipher__Sig))) + if (!equalSlices(&p1, &p2, sizeof(cipher__Sig))) return 0; err = SKY_coin_Transaction_GetIn(*handle1, &p1); ck_assert_int_eq(err, SKY_OK); err = SKY_coin_Transaction_GetIn(*handle2, &p2); ck_assert_int_eq(err, SKY_OK); - if (!equalSlices_(&p1, &p2, sizeof(cipher__SHA256))) + if (!equalSlices(&p1, &p2, sizeof(cipher__SHA256))) return 0; err = SKY_coin_Transaction_GetOut(*handle1, &p1); ck_assert_int_eq(err, SKY_OK); err = SKY_coin_Transaction_GetOut(*handle2, &p2); ck_assert_int_eq(err, SKY_OK); - if (!equalSlices_(&p1, &p2, sizeof(coin__TransactionOutput))) + if (!equalSlices(&p1, &p2, sizeof(coin__TransactionOutput))) return 0; return 1; } From bc876e381460d40cb90ea980b0f1744e7af31ad6 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Wed, 11 Sep 2019 14:25:31 -0400 Subject: [PATCH 2/8] [libc] refs #105 Repair error in compare GoString_ to GoString in `TestBitcoinAddress` --- lib/cgo/tests/check_cipher.bitcoin.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/cgo/tests/check_cipher.bitcoin.c b/lib/cgo/tests/check_cipher.bitcoin.c index a6073fce1..d86879dcc 100644 --- a/lib/cgo/tests/check_cipher.bitcoin.c +++ b/lib/cgo/tests/check_cipher.bitcoin.c @@ -40,18 +40,16 @@ START_TEST(TestBitcoinAddress) error = SKY_cipher_PubKeyFromHex(*pubKeyStr, &pubkey); ck_assert_msg(error == SKY_OK, "Create PubKey from Hex"); - GoString_ str = {NULL, 0}; + GoString str = {NULL, 0}; SKY_cipher_BitcoinAddressFromPubKey(&pubkey, &btcAddr); SKY_cipher_BitcoinAddress_String(&btcAddr, &str); - registerMemCleanup((void*)str.p); - GoString tmpStr = {str.p, str.n}; - ck_assert_str_eq(str.p, addrStr->p); + ck_assert(isGoStringEq(*addrStr, str)); error = SKY_cipher_BitcoinAddressFromSecKey(&seckey, &btcAddr); ck_assert(error == SKY_OK); GoString_ tmpstr = {buff, 0}; - SKY_cipher_BitcoinAddress_String(&btcAddr, &tmpstr); - ck_assert_str_eq(tmpStr.p, addrStr->p); + SKY_cipher_BitcoinAddress_String(&btcAddr, &str); + ck_assert(isGoStringEq(*addrStr, str)); } } END_TEST From 03ccbce08e0ae1e766cae978b328459ce5792319 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Thu, 12 Sep 2019 09:53:21 -0400 Subject: [PATCH 3/8] [cgo] refs #105 Added function helper `SKY_Handle_Strings_Get` --- lib/cgo/libsky_handle_helper.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/cgo/libsky_handle_helper.go b/lib/cgo/libsky_handle_helper.go index df78ea650..e6da2af3c 100644 --- a/lib/cgo/libsky_handle_helper.go +++ b/lib/cgo/libsky_handle_helper.go @@ -165,6 +165,17 @@ func SKY_Handle_Strings_SetAt(handle C.Strings__Handle, index int, str *string) return SKY_OK } +//nolint megacheck +//export SKY_Handle_Strings_Get +func SKY_Handle_Strings_Get(handle C.Strings__Handle, arg0 *[]string) uint32 { + obj, ok := lookupStringsHandle(handle) + if !ok { + return SKY_BAD_HANDLE + } + *arg0 = obj + return SKY_OK +} + //export SKY_api_Handle_Client_GetWalletDir func SKY_api_Handle_Client_GetWalletDir(handle C.Client__Handle, walletDir *C.GoString_) uint32 { client, ok := lookupClientHandle(handle) From ecf5710cf74eb5b46e4790f81ae607cace8a8623 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Fri, 13 Sep 2019 23:21:10 -0400 Subject: [PATCH 4/8] [libc] refs #105 Restore function `SKY_params_Distribution_GetAddresses` to export GoSlice --- lib/cgo/libsky_handle_helper.go | 2 +- lib/cgo/params.distribution.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cgo/libsky_handle_helper.go b/lib/cgo/libsky_handle_helper.go index e6da2af3c..e11b39a7a 100644 --- a/lib/cgo/libsky_handle_helper.go +++ b/lib/cgo/libsky_handle_helper.go @@ -172,7 +172,7 @@ func SKY_Handle_Strings_Get(handle C.Strings__Handle, arg0 *[]string) uint32 { if !ok { return SKY_BAD_HANDLE } - *arg0 = obj + arg0 = &obj return SKY_OK } diff --git a/lib/cgo/params.distribution.go b/lib/cgo/params.distribution.go index 80239bff9..2c2480419 100644 --- a/lib/cgo/params.distribution.go +++ b/lib/cgo/params.distribution.go @@ -112,13 +112,13 @@ func SKY_params_Distribution_SetUnlockTimeInterval(_d C.Distribution__Handle, _a } //export SKY_params_Distribution_GetAddresses -func SKY_params_Distribution_GetAddresses(_d C.Distribution__Handle, _arg0 *C.Strings__Handle) (____error_code uint32) { +func SKY_params_Distribution_GetAddresses(_d C.Distribution__Handle, __return_strings *[]string) (____error_code uint32) { d, ok := lookupDistributionHandle(_d) if !ok { ____error_code = SKY_BAD_HANDLE return } - *_arg0 = registerStringsHandle(d.Addresses) + *__return_strings = d.Addresses return } From deeeeebc95e75b5272f4f544f82f5d1389906cb1 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Sat, 14 Sep 2019 08:33:31 -0400 Subject: [PATCH 5/8] [cgo] refs #105 Correcting declare `SKY_params_Distribution_GetAddresses` --- lib/cgo/params.distribution.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cgo/params.distribution.go b/lib/cgo/params.distribution.go index 2c2480419..a45035b93 100644 --- a/lib/cgo/params.distribution.go +++ b/lib/cgo/params.distribution.go @@ -112,13 +112,14 @@ func SKY_params_Distribution_SetUnlockTimeInterval(_d C.Distribution__Handle, _a } //export SKY_params_Distribution_GetAddresses -func SKY_params_Distribution_GetAddresses(_d C.Distribution__Handle, __return_strings *[]string) (____error_code uint32) { +func SKY_params_Distribution_GetAddresses(_d C.Distribution__Handle, _arg0 *C.Strings__Handle) (____error_code uint32) { d, ok := lookupDistributionHandle(_d) if !ok { ____error_code = SKY_BAD_HANDLE return } - *__return_strings = d.Addresses + arg0 := d.Addresses + *_arg0 = registerStringsHandle(arg0) return } From 409d436594ba5ccf713e8219d999dd118818254e Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Sat, 14 Sep 2019 08:35:42 -0400 Subject: [PATCH 6/8] [cgo] refs #105 Correcting declare to export `string` in `SKY_Handle_Strings_GetAt` --- lib/cgo/libsky_handle_helper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cgo/libsky_handle_helper.go b/lib/cgo/libsky_handle_helper.go index e11b39a7a..395af7871 100644 --- a/lib/cgo/libsky_handle_helper.go +++ b/lib/cgo/libsky_handle_helper.go @@ -142,11 +142,11 @@ func SKY_Handle_Strings_Sort(handle C.Strings__Handle) uint32 { } //export SKY_Handle_Strings_GetAt -func SKY_Handle_Strings_GetAt(handle C.Strings__Handle, index int, str *C.GoString_) uint32 { +func SKY_Handle_Strings_GetAt(handle C.Strings__Handle, index int, str *string) uint32 { obj, ok := lookupStringsHandle(handle) if ok { - copyString(obj[index], str) + *str = obj[index] return SKY_OK } From 8fbd65610db8a2cc265de8bd9107ba711c5b2a29 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Sat, 14 Sep 2019 09:19:57 -0400 Subject: [PATCH 7/8] [SWIG] refs #105 Added `Handle` in dynamic `Distribution__Handle` --- lib/swig/dynamic/mem.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/swig/dynamic/mem.i b/lib/swig/dynamic/mem.i index 03c68d100..01572a325 100644 --- a/lib/swig/dynamic/mem.i +++ b/lib/swig/dynamic/mem.i @@ -25,7 +25,7 @@ GoStringMap, PasswordReader__Handle_, Transaction__Handle, Transactions__Handle, CreatedTransaction__Handle, CreatedTransactionOutput__Handle, CreatedTransactionInput__Handle, CreateTransactionResponse__Handle, - Block__Handle, SignedBlock__Handle, BlockBody__Handle, BuildInfo_Handle, Number_Handle, Signature_Handle,AddressUxOuts_Handle + Block__Handle, SignedBlock__Handle, BlockBody__Handle, BuildInfo_Handle, Number_Handle, Signature_Handle,AddressUxOuts_Handle,Distribution__Handle } %apply Handle* { Wallet__Handle*, Options__Handle*, ReadableEntry__Handle*, ReadableWallet__Handle*, WebRpcClient__Handle*, @@ -33,5 +33,5 @@ CLI__Handle*, Context__Handle*, GoStringMap_*, PasswordReader__Handle*, Transaction__Handle*, Transactions__Handle*, CreatedTransaction__Handle*, CreatedTransactionOutput__Handle*, CreatedTransactionInput__Handle*, CreateTransactionResponse__Handle*, - Block__Handle*, SignedBlock__Handle*, BlockBody__Handle*, BuildInfo_Handle*, Number_Handle*, Signature_Handle*,AddressUxOuts_Handle* + Block__Handle*, SignedBlock__Handle*, BlockBody__Handle*, BuildInfo_Handle*, Number_Handle*, Signature_Handle*,AddressUxOuts_Handle*,Distribution__Handle* } \ No newline at end of file From b08948abcd2819c328d7ef9f092b411fc81324dc Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Sat, 14 Sep 2019 09:20:35 -0400 Subject: [PATCH 8/8] [cgo] refs #105 Correcting declare function in `SKY_params_Distribution_GetMainNetDistribution` --- lib/cgo/params.distribution.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/cgo/params.distribution.go b/lib/cgo/params.distribution.go index a45035b93..46e61f0b1 100644 --- a/lib/cgo/params.distribution.go +++ b/lib/cgo/params.distribution.go @@ -230,13 +230,7 @@ func SKY_params_Distribution_LockedAddressesDecoded(_d C.Distribution__Handle, _ //export SKY_params_Distribution_GetMainNetDistribution func SKY_params_Distribution_GetMainNetDistribution(_d *C.Distribution__Handle) (____error_code uint32) { - d, ok := lookupDistributionHandle(*_d) - if !ok { - ____error_code = SKY_BAD_HANDLE - return - } - *d = params.MainNetDistribution - *_d = registerDistributionHandle(d) + *_d = registerDistributionHandle(¶ms.MainNetDistribution) return }