Skip to content

Commit

Permalink
utilize abieos for abieos parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
goldentechie committed Dec 8, 2021
1 parent cf622fb commit dbfe540
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 10 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ description="sample client utilizing EOSIO API"
members = [
"eosio-api",
"eosio-keys",
"libabieos-sys",
]
exclude = [

]

[dependencies]
Expand Down
2 changes: 0 additions & 2 deletions eosio-api/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub struct ABIName {
pub value:u64
}
impl ABIName {


pub fn from_str(string: &str) -> Result<ABIName> {
let mut value: u64 = 0;
let chars = string.as_bytes();
Expand Down
8 changes: 8 additions & 0 deletions eosio-api/src/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
62 changes: 54 additions & 8 deletions eosio-api/src/json_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,23 +75,25 @@ impl EOSRPC {
let gc: GetCodeHash = serde_json::from_str(&res)?;
Ok(gc)
}
pub fn get_raw_abi(&self, account_name: &str) -> Result<GetRawABI> {
let value = serde_json::json!({ "account_name": account_name });

pub fn get_required_keys(&self, transaction: &TransactionIn, keys: Vec<EOSPublicKey>) -> Result<RequiredKeys> {
// 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<EOSPublicKey>) -> Result<RequiredKeys> {
let mut key_str: Vec<String> = vec![];
for key in keys {
let x = key.to_eos_string()?;
key_str.push(x);
}

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)
}


Expand Down Expand Up @@ -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<Utc>) -> Result<()> {
eprintln!("push_transaction_int does not work. use push_transaction");
let now = Instant::now();
Expand Down Expand Up @@ -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(())
}
}
Expand Down
1 change: 1 addition & 0 deletions eosio-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod api_types;
mod json_rpc;
mod wasm;
mod abi;
//mod serialize;
mod wallet_types;
mod errors;

Expand Down

0 comments on commit dbfe540

Please sign in to comment.