-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
I think you didn’t ran bindgen |
libra-dev/include/data.h
Outdated
@@ -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); |
There was a problem hiding this comment.
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
4277179
to
460e797
Compare
libra-dev/include/data.h
Outdated
@@ -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); |
There was a problem hiding this comment.
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)
libra-dev/src/account_resource.rs
Outdated
|
||
// 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]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to rebase
libra-dev/src/transaction.rs
Outdated
|
||
// generate key pair | ||
let mut seed: [u8; 32] = [0u8; 32]; | ||
seed[..4].copy_from_slice(&[1, 2, 3, 4]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused seed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
211ce98
to
531b303
Compare
libra-dev/Cargo.toml
Outdated
lcs = { git = "https://github.com/libra/libra.git", branch = "testnet", package = "libra-canonical-serialization" } | ||
rand = "0.6.5" |
There was a problem hiding this comment.
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
libra-dev/include/data.h
Outdated
@@ -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 |
There was a problem hiding this comment.
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
libra-dev/src/data.rs
Outdated
@@ -143,3 +143,28 @@ fn bindgen_test_layout_CDevAccountResource() { | |||
) | |||
); | |||
} | |||
extern "C" { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
libra-dev/src/lib.rs
Outdated
@@ -7,4 +7,4 @@ | |||
mod data; | |||
|
|||
pub mod account_resource; | |||
|
|||
mod transaction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub mod ?
libra-dev/src/transaction.rs
Outdated
buf: *mut *mut u8, | ||
len: *mut usize, | ||
) { | ||
let sender_buf: &[u8] = unsafe { slice::from_raw_parts(sender, ADDRESS_LENGTH) }; |
There was a problem hiding this comment.
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.
libra-dev/src/transaction.rs
Outdated
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn libra_signed_transaction_free(buf: *mut *mut u8) { | ||
libc::free(*buf as *mut libc::c_void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check for NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some small changes
upgrade to latest testnet, fix account role missing fields
This PR provides an API to get a serialized SignedTransaction type given the transaction metadata and a private key in bytes.