Skip to content

Commit 932231f

Browse files
get_transaction/get_actions for eosapi
1 parent 6b7b0c2 commit 932231f

File tree

6 files changed

+67
-96
lines changed

6 files changed

+67
-96
lines changed

programs/pyeos/CMakeLists.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,31 @@ add_library(pyeos-shared eos_main.cpp interface/json.cpp interface/eosapi_.cpp
7575

7676

7777
if( APPLE )
78-
target_link_libraries( pyeos-shared appbase chain_api_plugin
78+
target_link_libraries( pyeos-shared appbase chain_api_plugin history_api_plugin history_plugin
7979
producer_plugin chain_plugin net_plugin http_plugin fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS}
8080
wallet_plugin wallet_api_plugin
8181
chainbase eos_utilities fc
8282
python3 eosio_chain intl )
8383
else( APPLE )
84-
target_link_libraries( pyeos-shared appbase chain_api_plugin
84+
target_link_libraries( pyeos-shared appbase chain_api_plugin history_api_plugin history_plugin
8585
producer_plugin chain_plugin net_plugin http_plugin fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS}
8686
wallet_plugin wallet_api_plugin
8787
chainbase eos_utilities fc
8888
python3 eosio_chain util -Xlinker -export-dynamic)
8989
endif( APPLE )
9090

91-
target_include_directories( pyeos-shared PUBLIC ${CMAKE_SOURCE_DIR}/contracts
92-
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
93-
PUBLIC ${CMAKE_SOURCE_DIR}/libraries/python/Include
94-
PUBLIC ${CMAKE_SOURCE_DIR}/libraries/python
95-
PUBLIC ${CMAKE_SOURCE_DIR}/libraries/chain
96-
PUBLIC ${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include
97-
PUBLIC ${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include
98-
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/interface"
99-
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/util"
100-
PRIVATE "${CMAKE_SOURCE_DIR}/plugins/account_history_api_plugin/include"
101-
PRIVATE "${CPP_ETHEREUM_DIR}"
91+
target_include_directories( pyeos-shared
92+
PRIVATE ${CPP_ETHEREUM_DIR}
93+
PUBLIC ${CMAKE_SOURCE_DIR}/contracts
94+
PUBLIC ${CMAKE_SOURCE_DIR}/libraries/chain
95+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
96+
PUBLIC ${CMAKE_SOURCE_DIR}/libraries/python
97+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/interface
98+
PUBLIC ${CMAKE_SOURCE_DIR}/libraries/python/Include
99+
PUBLIC ${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include
100+
PUBLIC ${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include
101+
PRIVATE ${CMAKE_SOURCE_DIR}/plugins/history_plugin/include
102+
PRIVATE ${CMAKE_SOURCE_DIR}/plugins/history_api_plugin/include
102103
)
103104

104105

programs/pyeos/cython/eosapi.pyx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ cdef extern from "eosapi_.hpp":
4949
void quit_app_()
5050
uint32_t now2_()
5151
int produce_block_();
52+
5253
object get_info_ ()
5354
object get_block_(char* num_or_id)
5455
object get_account_(char* name)
@@ -58,21 +59,16 @@ cdef extern from "eosapi_.hpp":
5859
object create_key_()
5960
object get_public_key_(string& wif_key)
6061

61-
int get_transaction_(string& id, string& result);
62-
int get_transactions_(string& account_name, int skip_seq, int num_seq, string& result);
63-
62+
object get_actions_(uint64_t account, int pos, int offset);
63+
object get_transaction_(string& id);
64+
6465
object set_evm_contract_(string& eth_address, string& sol_bin, bool sign);
6566

6667
int get_code_(string& name, string& wast, string& abi, string& code_hash, int & vm_type);
6768
int get_table_(string& scope, string& code, string& table, string& result);
6869

69-
int setcode_(char* account_, char* wast_file, char* abi_file, char* ts_buffer, int length)
70-
int exec_func_(char* code_, char* action_, char* json_, char* scope, char* authorization, char* ts_result, int length)
71-
7270
object get_currency_balance_(string& _code, string& _account, string& _symbol)
7371

74-
object traceback_()
75-
7672
int compile_and_save_to_buffer_(const char* src_name, const char *src_buffer, size_t src_size, char* buffer, size_t size);
7773

7874
void wast2wasm_( string& wast ,string& result)
@@ -243,16 +239,22 @@ def create_key():
243239
def get_public_key(priv_key):
244240
return get_public_key_(priv_key)
245241

242+
def get_actions(account, pos, offset):
243+
if isinstance(account, str):
244+
account = s2n(account)
245+
246+
ret = get_actions_(account, pos, offset)
247+
if ret:
248+
return JsonStruct(ret)
249+
246250
def get_transaction(id):
247-
cdef string result
248251
if isinstance(id, int):
249252
id = str(id)
250-
if 0 == get_transaction_(id, result):
251-
return JsonStruct(result)
253+
ret = get_transaction_(id)
254+
if ret:
255+
return JsonStruct(ret)
252256
return None
253257

254-
255-
256258
def get_code(name):
257259
cdef string wast
258260
cdef string abi
@@ -483,13 +485,6 @@ def push_raw_transaction(signed_trx):
483485
signed_trx = json.dumps(signed_trx)
484486
return push_raw_transaction_(signed_trx)
485487

486-
487-
def get_transactions(account_name, skip_seq: int, num_seq: int):
488-
cdef string result
489-
if 0 == get_transactions_(account_name, skip_seq, num_seq, result):
490-
return result
491-
return None
492-
493488
def push_transactions(actions, sign = True, uint64_t skip_flag=0, _async=False, compress=False):
494489
'''Send transactions
495490

programs/pyeos/eos_main.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#include <appbase/application.hpp>
2-
3-
//#include <eosio/account_history_api_plugin/account_history_api_plugin.hpp>
4-
//#include <eosio/account_history_plugin/account_history_plugin.hpp>
5-
#include <eosio/chain_api_plugin/chain_api_plugin.hpp>
6-
#include <eosio/chain_plugin/chain_plugin.hpp>
7-
#include <eosio/http_plugin/http_plugin.hpp>
2+
#include <fc/log/logger_config.hpp>
3+
#include <fc/exception/exception.hpp>
4+
#include <eosio/history_plugin.hpp>
85
#include <eosio/net_plugin/net_plugin.hpp>
6+
#include <eosio/http_plugin/http_plugin.hpp>
7+
#include <eosio/chain_plugin/chain_plugin.hpp>
8+
#include <eosio/wallet_plugin/wallet_plugin.hpp>
99
#include <eosio/producer_plugin/producer_plugin.hpp>
10-
//#include <eos/py_plugin/py_plugin.hpp>
10+
#include <eosio/chain_api_plugin/chain_api_plugin.hpp>
1111
#include <eosio/wallet_api_plugin/wallet_api_plugin.hpp>
12-
#include <eosio/wallet_plugin/wallet_plugin.hpp>
12+
#include <eosio/history_api_plugin/history_api_plugin.hpp>
1313

14-
#include <fc/exception/exception.hpp>
15-
#include <fc/log/logger_config.hpp>
1614

1715
#include <boost/chrono.hpp>
18-
#include <boost/exception/diagnostic_information.hpp>
1916
#include <boost/thread/thread.hpp>
17+
#include <boost/exception/diagnostic_information.hpp>
2018

2119

2220
#include <Python.h>
@@ -72,8 +70,8 @@ void start_eos() {
7270
app().register_plugin<net_plugin>();
7371
app().register_plugin<chain_api_plugin>();
7472
app().register_plugin<producer_plugin>();
75-
// app().register_plugin<account_history_plugin>();
76-
// app().register_plugin<account_history_api_plugin>();
73+
app().register_plugin<history_plugin>();
74+
app().register_plugin<history_api_plugin>();
7775
app().register_plugin<wallet_api_plugin>();
7876

7977
if (!app().initialize<chain_plugin, http_plugin, net_plugin>(g_argc, g_argv)) {

programs/pyeos/initeos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
# As well as API and HTTP plugins
4040
plugin = eosio::chain_api_plugin
4141
plugin = eosio::http_plugin
42-
plugin = eosio::account_history_plugin
43-
plugin = eosio::account_history_api_plugin
42+
plugin = eosio::history_plugin
43+
plugin = eosio::history_api_plugin
4444
'''
4545

4646
genesis = '''

programs/pyeos/interface/eosapi_.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <eosio/utilities/common.hpp>
1212
#include <eosio/chain/wast_to_wasm.hpp>
1313
#include <eosio/chain/contract_types.hpp>
14+
#include <eosio/history_plugin.hpp>
1415

1516

1617
#include "fc/bitutil.hpp"
@@ -564,43 +565,37 @@ PyObject* get_controlled_accounts_(const char* account_name) {
564565
return arr.get();
565566
}
566567

567-
int get_transaction_(string& id, string& result) {
568-
#if 0
569-
eosio::account_history_apis::read_only::get_transaction_params params = {
570-
chain::transaction_id_type(id)};
568+
PyObject* get_actions_(uint64_t account, int pos, int offset) {
569+
570+
eosio::history_apis::read_only::get_actions_params params = {
571+
name(account),
572+
pos,
573+
offset
574+
};
571575
try {
572-
auto ro_api =
573-
app().get_plugin<account_history_plugin>().get_read_only_api();
574-
eosio::account_history_apis::read_only::get_transaction_results results =
575-
ro_api.get_transaction(params);
576-
result = fc::json::to_string(fc::variant(results));
577-
return 0;
576+
auto ro_api = app().get_plugin<history_plugin>().get_read_only_api();
577+
auto results = ro_api.get_actions(params);
578+
return python::json::to_string(fc::variant(results));
578579
} catch (fc::exception& ex) {
579580
elog(ex.to_detail_string());
580581
}
581-
#endif
582-
return -1;
582+
return py_new_none();
583583
}
584584

585-
int get_transactions_(string& account_name, int skip_seq, int num_seq,
586-
string& result) {
587-
#if 0
588-
try {
589-
const eosio::account_history_apis::read_only::get_transactions_params
590-
params = {chain::account_name(account_name), skip_seq, num_seq};
591-
592-
auto ro_api = app().get_plugin<account_history_plugin>().get_read_only_api();
593585

594-
eosio::account_history_apis::read_only::get_transactions_results results =
595-
ro_api.get_transactions(params);
586+
PyObject* get_transaction_(string& id) {
596587

597-
result = fc::json::to_string(results);
598-
return 0;
588+
eosio::history_apis::read_only::get_transaction_params params = {
589+
chain::transaction_id_type(id)
590+
};
591+
try {
592+
auto ro_api = app().get_plugin<history_plugin>().get_read_only_api();
593+
auto results = ro_api.get_transaction(params);
594+
return python::json::to_string(fc::variant(results));
599595
} catch (fc::exception& ex) {
600596
elog(ex.to_detail_string());
601597
}
602-
#endif
603-
return -1;
598+
return py_new_none();
604599
}
605600

606601
PyObject* set_evm_contract_(string& eth_address, string& sol_bin, bool sign) {

programs/pyeos/interface/eosapi_.hpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
#include <Python.h>
22

3-
#ifndef __HELLO_H
4-
#define __HELLO_H
5-
#ifdef __cplusplus
6-
7-
extern "C" {
8-
#endif
9-
int create_key_(char* pub_, int pub_length, char* priv_, int priv_length);
10-
int get_transaction_(char* id, char* result, int length);
11-
int transfer_(char* sender_, char* recipient_, int amount, char* result,
12-
int length);
13-
int setcode_(char* account_, char* wast_file, char* abi_file, char* ts_buffer,
14-
int length);
15-
int exec_func_(char* code_, char* action_, char* json_, char* scope,
16-
char* authorization, char* ts_result, int length);
17-
#ifdef __cplusplus
18-
}
19-
#endif
20-
#endif
3+
#pragma once
214

225
#include <boost/asio.hpp>
236
#include <fc/exception/exception.hpp>
@@ -96,10 +79,6 @@ PyObject* create_key_();
9679
PyObject* get_public_key_(string& wif_key);
9780

9881
int get_transaction_(string& id, string& result);
99-
int get_transactions_(string& account_name, int skip_seq, int num_seq, string& result);
100-
101-
PyObject* transfer_(string& sender, string& recipient, int amount, string memo, bool sign);
102-
PyObject* set_contract_(string& account, string& wastPath, string& abiPath, int vmtype, bool sign);
10382

10483
int get_code_(string& name, string& wast, string& abi, string& code_hash, int& vm_type);
10584
int get_table_(string& scope, string& code, string& table, string& result);
@@ -131,3 +110,6 @@ PyObject* gen_transaction_(vector<chain::action>& v, int expiration);
131110
PyObject* sign_transaction_(string& trx_json_to_sign, string& str_private_key);
132111
PyObject* push_raw_transaction_(string& signed_trx);
133112

113+
PyObject* get_actions_(uint64_t account, int pos, int offset);
114+
PyObject* get_transaction_(string& id);
115+

0 commit comments

Comments
 (0)