From 27d0e47ca5bf426afaf631f3084fe88603a6ccee Mon Sep 17 00:00:00 2001 From: Andrey Gulitsky Date: Wed, 29 Jan 2020 14:08:39 +0600 Subject: [PATCH 1/5] `Parity` namespace --- src/api/mod.rs | 5 +++ src/api/parity.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/api/parity.rs diff --git a/src/api/mod.rs b/src/api/mod.rs index cb33cac3..3a9a7a82 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -4,6 +4,7 @@ mod eth; mod eth_filter; mod eth_subscribe; mod net; +mod parity; mod parity_accounts; mod parity_set; mod personal; @@ -14,6 +15,7 @@ pub use self::eth::Eth; pub use self::eth_filter::{BaseFilter, CreateFilter, EthFilter, FilterStream}; pub use self::eth_subscribe::{EthSubscribe, SubscriptionId, SubscriptionResult, SubscriptionStream}; pub use self::net::Net; +pub use self::parity::Parity; pub use self::parity_accounts::ParityAccounts; pub use self::parity_set::ParitySet; pub use self::personal::Personal; @@ -76,6 +78,9 @@ impl Web3 { self.api() } + /// Access methods from `parity` namespace + pub fn parity(&self) -> parity::Parity { self.api() } + /// Access methods from `parity_accounts` namespace pub fn parity_accounts(&self) -> parity_accounts::ParityAccounts { self.api() diff --git a/src/api/parity.rs b/src/api/parity.rs new file mode 100644 index 00000000..e066c0b4 --- /dev/null +++ b/src/api/parity.rs @@ -0,0 +1,77 @@ +use crate::{ + api::Namespace, + helpers::{self, CallFuture}, + types::{Address, BlockNumber, Bytes, CallRequest}, + Transport, +}; + +/// `Parity` namespace +#[derive(Debug, Clone)] +pub struct Parity { + transport: T, +} + +impl Namespace for Parity { + fn new(transport: T) -> Self + where + Self: Sized, + { + Parity { transport } + } + + fn transport(&self) -> &T { + &self.transport + } +} + +impl Parity { + pub fn call(&self, req: Vec) -> CallFuture, T::Out> { + let req = helpers::serialize(&req); + + CallFuture::new(self.transport.execute("parity_call", vec![req])) + } +} + +#[cfg(test)] +mod tests { + use super::Parity; + use crate::{ + api::Namespace, + rpc::Value, + types::{Address, Bytes, CallRequest}, + }; + use futures::Future; + + rpc_test!( + Parity:call, + vec![ + CallRequest { + from: None, + to: Address::from_low_u64_be(0x123), + gas: None, + gas_price: None, + value: Some(0x1.into()), + data: None, + }, + CallRequest { + from: Some(Address::from_low_u64_be(0x321)), + to: Address::from_low_u64_be(0x123), + gas: None, + gas_price: None, + value: None, + data: Some(Bytes(vec![0x04, 0x93])), + }, + CallRequest { + from: None, + to: Address::from_low_u64_be(0x765), + gas: None, + gas_price: None, + value: Some(0x5.into()), + data: Some(Bytes(vec![0x07, 0x23])) + } + ] => "parity_call", vec![ + r#"[{"to":"0x0000000000000000000000000000000000000123","value":"0x1"},{"data":"0x0493","from":"0x0000000000000000000000000000000000000321","to":"0x0000000000000000000000000000000000000123"},{"data":"0x0723","to":"0x0000000000000000000000000000000000000765","value":"0x5"}]"# + ]; + Value::Array(vec![Value::String("0x010203".into()), Value::String("0x7198ab".into()), Value::String("0xde763f".into())]) => vec![Bytes(vec![1, 2, 3]), Bytes(vec![0x71, 0x98, 0xab]), Bytes(vec![0xde, 0x76, 0x3f])] + ); +} From a320c92501112bcac274370b81da56c0163e18b7 Mon Sep 17 00:00:00 2001 From: Andrey Gulitsky Date: Wed, 29 Jan 2020 16:32:35 +0600 Subject: [PATCH 2/5] Add `parity_call` doc --- src/api/parity.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/parity.rs b/src/api/parity.rs index e066c0b4..1443934a 100644 --- a/src/api/parity.rs +++ b/src/api/parity.rs @@ -25,10 +25,11 @@ impl Namespace for Parity { } impl Parity { - pub fn call(&self, req: Vec) -> CallFuture, T::Out> { - let req = helpers::serialize(&req); + /// Sequentially call multiple contract methods in one request without changing the state of the blockchain. + pub fn call(&self, reqs: Vec) -> CallFuture, T::Out> { + let req = helpers::serialize(&reqs); - CallFuture::new(self.transport.execute("parity_call", vec![req])) + CallFuture::new(self.transport.execute("parity_call", vec![reqs])) } } From aa63001130ff021d4f822b747f33cfedf0e2ce5d Mon Sep 17 00:00:00 2001 From: Andrey Gulitsky Date: Wed, 29 Jan 2020 16:36:45 +0600 Subject: [PATCH 3/5] Fix a typo --- src/api/parity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/parity.rs b/src/api/parity.rs index 1443934a..3aa5d196 100644 --- a/src/api/parity.rs +++ b/src/api/parity.rs @@ -27,7 +27,7 @@ impl Namespace for Parity { impl Parity { /// Sequentially call multiple contract methods in one request without changing the state of the blockchain. pub fn call(&self, reqs: Vec) -> CallFuture, T::Out> { - let req = helpers::serialize(&reqs); + let reqs = helpers::serialize(&reqs); CallFuture::new(self.transport.execute("parity_call", vec![reqs])) } From f82c0ad290dceef53f4d212ad2b337707b717dd9 Mon Sep 17 00:00:00 2001 From: Andrey Gulitsky Date: Wed, 29 Jan 2020 16:44:45 +0600 Subject: [PATCH 4/5] Remove unused imports. --- src/api/parity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/parity.rs b/src/api/parity.rs index 3aa5d196..7d5d41e5 100644 --- a/src/api/parity.rs +++ b/src/api/parity.rs @@ -1,7 +1,7 @@ use crate::{ api::Namespace, helpers::{self, CallFuture}, - types::{Address, BlockNumber, Bytes, CallRequest}, + types::{Bytes, CallRequest}, Transport, }; From 7cf666f0aff71e7682358d4ff269a537b376bdc4 Mon Sep 17 00:00:00 2001 From: Andrey Gulitsky Date: Wed, 29 Jan 2020 16:56:53 +0600 Subject: [PATCH 5/5] Format code. --- src/api/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 3a9a7a82..240283b9 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -79,7 +79,9 @@ impl Web3 { } /// Access methods from `parity` namespace - pub fn parity(&self) -> parity::Parity { self.api() } + pub fn parity(&self) -> parity::Parity { + self.api() + } /// Access methods from `parity_accounts` namespace pub fn parity_accounts(&self) -> parity_accounts::ParityAccounts {