Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libra-dev] Get Serialized Signed Transaction #9

Merged
merged 1 commit into from
Nov 20, 2019
Merged

[libra-dev] Get Serialized Signed Transaction #9

merged 1 commit into from
Nov 20, 2019

Conversation

sunmilee
Copy link
Contributor

This PR provides an API to get a serialized SignedTransaction type given the transaction metadata and a private key in bytes.

@thefallentree
Copy link

I think you didn’t ran bindgen

@@ -25,7 +25,7 @@ struct CDevAccountResource {

struct CDevAccountResource account_resource_from_lcs(const uint8_t *buf, size_t len);
void account_resource_free(struct CDevAccountResource *point);

uint8_t* lcs_signed_transaction(uint64_t sender[32], uint64_t receiver[32], uint64_t sequence, uint64_t num_coins, uint64_t max_gas_amount, uint64_t gas_unit_price, uint64_t expiration_time_millis, uint8_t* private_key_bytes);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't just return an pointer , the user will have no means to free the memory. Instead we need to let user pass in an pre-allocated buffer pointer, with size, and we have to return an error if size is too small

@@ -26,7 +27,8 @@ struct CDevAccountResource {

struct CDevAccountResource account_resource_from_lcs(const uint8_t *buf, size_t len);
void account_resource_free(struct CDevAccountResource *point);

void lcs_signed_transaction(const uint8_t sender[32], const uint8_t receiver[32], uint64_t sequence, uint64_t num_coins, uint64_t max_gas_amount, uint64_t gas_unit_price, uint64_t expiration_time_millis, const uint8_t* private_key_bytes, uint8_t** buf, size_t* len);
void free_txn(uint8_t** buf);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should name it as
libra_signed_transcation_build() and libra_signed_transcation_free() for consistency (I'm doing it for AccountResource too)


// Figure out how to use Libra code to generate AccountStateBlob directly, not involving btreemap directly
let mut map: BTreeMap<Vec<u8>, Vec<u8>> = BTreeMap::new();
let ar = AccountResource::new(
987654321,
123456789,
ByteArray::new(vec![1,2,3,4]),
ByteArray::new(vec![1, 2, 3, 4]),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to rebase


// generate key pair
let mut seed: [u8; 32] = [0u8; 32];
seed[..4].copy_from_slice(&[1, 2, 3, 4]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused seed?

Copy link

@thefallentree thefallentree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

lcs = { git = "https://github.com/libra/libra.git", branch = "testnet", package = "libra-canonical-serialization" }
rand = "0.6.5"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is only used in test ? so it should be in dev-dependencies

@@ -26,7 +27,13 @@ struct CDevAccountResource {

struct CDevAccountResource account_resource_from_lcs(const uint8_t *buf, size_t len);
void account_resource_free(struct CDevAccountResource *point);

/// To get the serialized transaction in a memory safe manner, the client needs to pass in a pointer to a pointer to the allocated memory in rust

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use doxgen tags (all tools will be able to use it, including automatically generating html docs)
https://www.rosettacommons.org/docs/latest/development_documentation/tutorials/doxygen-tips#common-doxygen-tags

specifically, mark the params with @params[in] @params[in/out] etc will be very useful.

Also, you need to say user take ownership of pointer returned by *buf, which needs to be freeed by libra_signed_transcation_free

@@ -143,3 +143,28 @@ fn bindgen_test_layout_CDevAccountResource() {
)
);
}
extern "C" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does these actually works other than just generate warnings? Myabe we should just put the data types in data.rs instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do that and not generate functions

@@ -7,4 +7,4 @@
mod data;

pub mod account_resource;

mod transaction;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub mod ?

buf: *mut *mut u8,
len: *mut usize,
) {
let sender_buf: &[u8] = unsafe { slice::from_raw_parts(sender, ADDRESS_LENGTH) };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for &[u8] I think, rust will figure it out.


#[no_mangle]
pub unsafe extern "C" fn libra_signed_transaction_free(buf: *mut *mut u8) {
libc::free(*buf as *mut libc::c_void);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check for NULL

Copy link

@thefallentree thefallentree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small changes

@sunmilee sunmilee merged commit ca874c7 into master Nov 20, 2019
@thefallentree thefallentree deleted the txn branch December 12, 2019 21:23
thefallentree pushed a commit that referenced this pull request Sep 22, 2020
upgrade to latest testnet, fix account role missing fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants