提交 e08b9b8c 编写于 作者: B Bart Wyatt

moved just-in-time transaction packing to `apply_context` instead of the...

moved just-in-time transaction packing to `apply_context` instead of the intrinsic, added/renamed intrinsics to match precedence set by the action api, added entries in the appropriate eosiolib hpp file
上级 b2ef7b3b
......@@ -61,5 +61,39 @@ extern "C" {
void send_deferred(uint32_t sender_id, time delay_until, char *serialized_transaction, size_t size);
/**
* 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
* @return the size of the transaction written to the buffer
*/
size_t read_transaction(char *buffer, size_t size);
/**
* get the size of the currently executing transaction
* @return
*/
size_t transaction_size();
/**
* get the block number used for TAPOS on the currently executing transaction
*
* @return
*/
int tapos_block_num();
/**
* get the block prefix used for TAPOS on the currently executing transaction
* @return
*/
int tapos_block_prefix();
/**
* get the expiration of the currently executing transaction
* @return
*/
time expiration();
///@ } transactioncapi
}
......@@ -233,4 +233,21 @@ vector<account_name> apply_context::get_active_producers() const {
return accounts;
}
const bytes& apply_context::get_packed_transaction() {
if( !trx_meta.packed_trx.size() ) {
if (_cached_trx.empty()) {
auto size = fc::raw::pack_size(trx_meta.trx);
_cached_trx.resize(size);
fc::datastream<char *> ds(_cached_trx.data(), size);
fc::raw::pack(ds, trx_meta.trx);
}
return _cached_trx;
}
return trx_meta.packed_trx;
}
} } /// eosio::chain
......@@ -96,6 +96,8 @@ class apply_context {
vector<account_name> get_active_producers() const;
const bytes& get_packed_transaction();
const chain_controller& controller;
const chainbase::database& db; ///< database where state is stored
const action& act; ///< message being applied
......@@ -194,6 +196,7 @@ class apply_context {
vector<shard_lock> _read_locks;
vector<scope_name> _write_scopes;
bytes _cached_trx;
};
using apply_handler = std::function<void(apply_context&)>;
......
......@@ -690,18 +690,16 @@ class transaction_api : public context_aware_api {
public:
using context_aware_api::context_aware_api;
size_t current_transaction( array_ptr<char> data, size_t data_len ) {
if( !context.trx_meta.packed_trx.size() ) {
auto size = fc::raw::pack_size( context.trx_meta.trx );
if( size > data_len )
return size;
datastream<char*> ds( data, data_len );
fc::raw::pack( ds, context.trx_meta.trx );
}
auto size = context.trx_meta.packed_trx.size();
if( data_len >= size );
memcpy( data, context.trx_meta.packed_trx.data(), size );
return size;
int read_transaction( array_ptr<char> data, size_t data_len ) {
bytes trx = context.get_packed_transaction();
if (data_len >= trx.size()) {
memcpy(data, trx.data(), trx.size());
}
return trx.size();
}
int transaction_size() {
return context.get_packed_transaction().size();
}
int expiration() {
......@@ -711,7 +709,7 @@ class transaction_api : public context_aware_api {
int tapos_block_num() {
return context.trx_meta.trx.ref_block_num;
}
int tapos_prefix() {
int tapos_block_prefix() {
return context.trx_meta.trx.ref_block_prefix;
}
......@@ -785,10 +783,12 @@ REGISTER_INTRINSICS(console_api,
);
REGISTER_INTRINSICS(transaction_api,
(expiration, int() )
(tapos_prefix, int() )
(tapos_block_num, int() )
(send_inline, void(int, int) )
(read_transaction, int(int, int) )
(transaction_size, int() )
(expiration, int() )
(tapos_block_prefix, int() )
(tapos_block_num, int() )
(send_inline, void(int, int) )
(send_deferred, void(int, int, int, int) )
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册