提交 ebcbfa87 编写于 作者: K Kevin Heifner

Update read_transaction for gh#2132

上级 0f0e8fca
......@@ -67,7 +67,7 @@ extern "C" {
* access a copy of the currently executing transaction
*
* @param buffer - a buffer to write the current transaction to
* @param size - the size of the buffer
* @param size - the size of the buffer, 0 to return required size
* @return the size of the transaction written to the buffer
*/
size_t read_transaction(char *buffer, size_t size);
......
......@@ -149,6 +149,7 @@ void test_transaction::test_read_transaction() {
auto size = transaction_size();
char buf[size];
uint32_t read = read_transaction( buf, size );
eosio_assert( size == read, "read_transaction failed");
sha256(buf, read, &h);
printhex( &h, sizeof(h) );
}
......
......@@ -1131,12 +1131,16 @@ class context_free_transaction_api : public context_aware_api {
context_free_transaction_api( apply_context& ctx )
:context_aware_api(ctx,true){}
int read_transaction( array_ptr<char> data, size_t data_len ) {
int read_transaction( array_ptr<char> data, size_t buffer_size ) {
bytes trx = context.get_packed_transaction();
if (data_len >= trx.size()) {
memcpy(data, trx.data(), trx.size());
}
return trx.size();
auto s = trx.size();
if( buffer_size == 0) return s;
auto copy_size = std::min( buffer_size, s );
memcpy( data, trx.data(), copy_size );
return copy_size;
}
int transaction_size() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册