Skip to content

Commit

Permalink
[cgo][libc] refs #105 Added functions `SKY_coin_DeserializeTransactio…
Browse files Browse the repository at this point in the history
…nHex`
  • Loading branch information
Maykel Arias Torres committed Sep 11, 2019
1 parent 536367a commit b9ed13f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/cgo/cipher.bip32.path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions lib/cgo/cipher.bip44.bip44.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
12 changes: 12 additions & 0 deletions lib/cgo/coin.transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion lib/cgo/libsky_mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ func copyTocoin_UxArray(src reflect.Value, dest *C.coin__UxArray) {
dest.len = C.GoInt_(srcLen)
}
}
}
}
6 changes: 2 additions & 4 deletions lib/cgo/tests/check_coin.transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion lib/cgo/tests/cipher.testsuite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions lib/cgo/tests/testutils/libsky_assert.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit b9ed13f

Please sign in to comment.