Skip to content

Commit

Permalink
Add eoapi.unpack_transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
learnforpractice committed Nov 7, 2019
1 parent a3dc94b commit 0da0ea1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main/_eosapi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cdef extern from "eosapi.hpp":
object gen_transaction_(vector[action]& v, int expiration, string& reference_block_id);
object sign_transaction_(string& trx_json_to_sign, string& str_private_key, string& chain_id);
object pack_transaction_(string& _signed_trx, int compress)
object unpack_transaction_(string& trx)

object create_key_()
object get_public_key_(string& wif_key)
Expand Down Expand Up @@ -121,6 +122,9 @@ def sign_transaction(string& trx_json_to_sign, string& str_private_key, string&
def pack_transaction(string& _signed_trx, int compress):
return pack_transaction_(_signed_trx, compress)

def unpack_transaction(string& trx):
return unpack_transaction_(trx)

def create_key():
return create_key_()

Expand Down
9 changes: 9 additions & 0 deletions main/eosapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ PyObject* pack_transaction_(std::string& _signed_trx, int compress) {
return py_new_none();
}

PyObject* unpack_transaction_(std::string& trx) {
try {
vector<char> s(trx.c_str(), trx.c_str()+trx.size());
auto st = fc::raw::unpack<transaction>(s);
std::string ss = fc::json::to_string(st);
return py_new_string(ss);
} FC_LOG_AND_DROP();
return py_new_none();
}

PyObject* create_key_() {
auto pk = private_key_type::generate();
Expand Down
2 changes: 2 additions & 0 deletions main/eosapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ void to_base58_( std::string& raw_pub_key, std::string& pub_key );

void recover_key_( string& _digest, string& _sig, string& _pub );

PyObject* unpack_transaction_(std::string& trx);

#endif /* MAIN_EOSAPI_HPP_ */
3 changes: 3 additions & 0 deletions main/eosapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ def push_transaction(self, trx, compress=0):
def pack_transaction(self, trx, compress=0):
return _eosapi.pack_transaction(trx, compress)

def unpack_transaction(self, trx):
return _eosapi.unpack_transaction(trx)

def push_action(self, contract, action, args, permissions, compress=0):
act = [contract, action, args, permissions]
reference_block_id = self.get_info().last_irreversible_block_id
Expand Down

0 comments on commit 0da0ea1

Please sign in to comment.