From dbfe540d74a97308d82c9f2c0fee14dc4ddf812e Mon Sep 17 00:00:00 2001 From: Golden Techie Date: Tue, 19 May 2020 18:24:04 -0400 Subject: [PATCH] utilize abieos for abieos parsing --- Cargo.lock | 19 ++++++++++++ Cargo.toml | 4 +++ eosio-api/src/abi.rs | 2 -- eosio-api/src/api_types.rs | 8 +++++ eosio-api/src/json_rpc.rs | 62 +++++++++++++++++++++++++++++++++----- eosio-api/src/lib.rs | 1 + 6 files changed, 86 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2f1e16..a1f8174 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,6 +182,15 @@ dependencies = [ "time", ] +[[package]] +name = "cmake" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" +dependencies = [ + "cc", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -626,6 +635,16 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "libabieos-sys" +version = "0.1.0" +dependencies = [ + "cmake", + "error-chain", + "lazy_static", + "regex", +] + [[package]] name = "libc" version = "0.2.69" diff --git a/Cargo.toml b/Cargo.toml index abe89ae..73a68d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,10 @@ description="sample client utilizing EOSIO API" members = [ "eosio-api", "eosio-keys", + "libabieos-sys", +] +exclude = [ + ] [dependencies] diff --git a/eosio-api/src/abi.rs b/eosio-api/src/abi.rs index d2036b8..2adc202 100644 --- a/eosio-api/src/abi.rs +++ b/eosio-api/src/abi.rs @@ -8,8 +8,6 @@ pub struct ABIName { pub value:u64 } impl ABIName { - - pub fn from_str(string: &str) -> Result { let mut value: u64 = 0; let chars = string.as_bytes(); diff --git a/eosio-api/src/api_types.rs b/eosio-api/src/api_types.rs index 1bbaeb5..ea72e1f 100644 --- a/eosio-api/src/api_types.rs +++ b/eosio-api/src/api_types.rs @@ -335,3 +335,11 @@ pub struct PackedTransactionIn { pub packed_context_free_data: String, pub packed_trx: String, } + +#[derive(Debug, Serialize, Deserialize)] +pub struct GetRawABI { + pub account_name: String, + pub code_hash: String, + pub abi_hash: String, + pub abi: String, +} diff --git a/eosio-api/src/json_rpc.rs b/eosio-api/src/json_rpc.rs index 55621c9..562663c 100644 --- a/eosio-api/src/json_rpc.rs +++ b/eosio-api/src/json_rpc.rs @@ -3,7 +3,7 @@ use reqwest::StatusCode; use serde_json::Value; use reqwest::header::{CONTENT_TYPE, HeaderValue}; use crate::errors::{Result, ErrorKind}; -use crate::api_types::{GetAccount, GetAbi, RequiredKeys, GetInfo, TransactionIn, ActionIn, AuthorizationIn, ErrorReply, PackedTransactionIn, GetCodeHash}; +use crate::api_types::{GetAccount, GetAbi, RequiredKeys, GetInfo, TransactionIn, ActionIn, AuthorizationIn, ErrorReply, PackedTransactionIn, GetCodeHash, GetRawABI}; use crate::wallet_types::Wallet; use eosio_keys::{EOSPublicKey, EOSPrivateKey, EOSSignature}; use crate::wasm::WASM; @@ -75,10 +75,15 @@ impl EOSRPC { let gc: GetCodeHash = serde_json::from_str(&res)?; Ok(gc) } + pub fn get_raw_abi(&self, account_name: &str) -> Result { + let value = serde_json::json!({ "account_name": account_name }); - pub fn get_required_keys(&self, transaction: &TransactionIn, keys: Vec) -> Result { - // let now = Instant::now(); + let res = self.blocking_req("/v1/chain/get_raw_abi", value)?; + let gr: GetRawABI = serde_json::from_str(&res)?; + Ok(gr) + } + pub fn get_required_keys(&self, transaction: &TransactionIn, keys: Vec) -> Result { let mut key_str: Vec = vec![]; for key in keys { let x = key.to_eos_string()?; @@ -86,12 +91,9 @@ impl EOSRPC { } let value = serde_json::json!({ "transaction": transaction, "available_keys":key_str}); - // eprintln!("Req-Keys-start {:?}", now.elapsed()); let res = self.blocking_req("/v1/chain/get_required_keys", value)?; - // eprintln!("Req-Keys-back {:?}", now.elapsed()); - let ga: RequiredKeys = serde_json::from_str(&res).unwrap(); - // eprintln!("Req-Keys-done {:?}", now.elapsed()); - Ok(ga) + let rk: RequiredKeys = serde_json::from_str(&res).unwrap(); + Ok(rk) } @@ -123,6 +125,7 @@ impl EOSRPC { } } } + fn push_transaction_int(&self, private_key: EOSPrivateKey, action: ActionIn, ref_block_num: usize, ref_block_prefix: usize, exp_time: DateTime) -> Result<()> { eprintln!("push_transaction_int does not work. use push_transaction"); let now = Instant::now(); @@ -316,6 +319,49 @@ mod test { let action = create_setcode_action(name, wasm)?; let _res = eos.push_transaction_int(key, action, gi.head_block_num, 0, exp_time)?; + Ok(()) + } + #[test] + fn blocking_get_raw_abi() -> Result<()> { + let eos = EOSRPC::blocking(String::from(TEST_HOST)); + let _res = eos.get_raw_abi("eosio")?; + + Ok(()) + } + #[test] + fn blocking_packed() -> Result<()> { + let packed_action = "000000008090b1ca000000000091b1ca000075982aea3055"; + let raw_action = "'{\"account\":\"test1\", \"code\":\"test2\", \"type\":\"eosioeosio\"}'"; + let raw_txn = "{ + \"expiration\": \"2018-08-02T20:24:36\", + \"ref_block_num\": 14207, + \"ref_block_prefix\": 1438248607, + \"max_net_usage_words\": 0, + \"max_cpu_usage_ms\": 0, + \"delay_sec\": 0, + \"context_free_actions\": [], + \"actions\": [{ + \"account\": \"eosio\", + \"name\": \"newaccount\", + \"authorization\": [{ + \"actor\": \"eosio\", + \"permission\": \"active\" + } + ], + \"data\": \"0000000000ea305500a6823403ea30550100000001000240cc0bf90a5656c8bb81f0eb86f49f89613c5cd988c018715d4646c6bd0ad3d8010000000100000001000240cc0bf90a5656c8bb81f0eb86f49f89613c5cd988c018715d4646c6bd0ad3d801000000\" + } + ], + \"transaction_extensions\": [] +}"; + let packed_trx = "8468635b7f379feeb95500000000010000000000ea305500409e9a2264b89a010000000000ea305500000000a8ed3232660000000000ea305500a6823403ea30550100000001000240cc0bf90a5656c8bb81f0eb86f49f89613c5cd988c018715d4646c6bd0ad3d8010000000100000001000240cc0bf90a5656c8bb81f0eb86f49f89613c5cd988c018715d4646c6bd0ad3d80100000000"; + let packed_trx_json = " + { + \"signatures\": [], + \"compression\": \"none\", + \"packed_context_free_data\": \"\", + \"packed_trx\": \"8468635b7f379feeb95500000000010000000000ea305500409e9a2264b89a010000000000ea305500000000a8ed3232660000000000ea305500a6823403ea30550100000001000240cc0bf90a5656c8bb81f0eb86f49f89613c5cd988c018715d4646c6bd0ad3d8010000000100000001000240cc0bf90a5656c8bb81f0eb86f49f89613c5cd988c018715d4646c6bd0ad3d80100000000\" + }"; + Ok(()) } } diff --git a/eosio-api/src/lib.rs b/eosio-api/src/lib.rs index 74649eb..60a7834 100644 --- a/eosio-api/src/lib.rs +++ b/eosio-api/src/lib.rs @@ -15,6 +15,7 @@ mod api_types; mod json_rpc; mod wasm; mod abi; +//mod serialize; mod wallet_types; mod errors;