Struct in3::in3::Client[][src]

pub struct Client { /* fields omitted */ }

Client struct

Implementations

impl Client[src]

pub fn new(chain_id: ChainId) -> Box<Client>[src]

Constructs a new Box<Client> for specified chain Id. Defaults to HttpTransport with no signer and storage.

Example

use in3::prelude::*;

let client = Client::new(chain::MAINNET);

Trait Implementations

impl Client for Client[src]

fn configure(&mut self, config: &str) -> In3Result<()>[src]

Configures the IN3 client using a JSON str.

Example with supported options


let mut client = Client::new(chain::MAINNET);
let err = client.configure(r#"{
	"autoUpdateList": true,
	"signatureCount": 0,
	"finality": 0,
	"includeCode": false,
	"maxAttempts": 7,
	"keepIn3": false,
	"stats": true,
	"useBinary": false,
	"useHttp": false,
	"maxVerifiedHashes": 5,
	"timeout": 10000,
	"minDeposit": 0,
	"nodeProps": 0,
	"nodeLimit": 0,
	"proof": "standard",
	"requestCount": 1,
	"nodeRegistry": {
		"contract": "0x4c396dcf50ac396e5fdea18163251699b5fcca25",
		"registryId": "0x92eb6ad5ed9068a24c1c85276cd7eb11eda1e8c50b17fbaffaf3e8396df4becf",
		"needsUpdate": true,
		"avgBlockTime": 6
	}
}"#);
assert!(err.is_ok());

fn set_transport(&mut self, transport: Box<dyn Transport>)[src]

Sets custom transport.

Example

use in3::transport::MockTransport;

client.set_transport(Box::new(MockTransport {
    responses: vec![(
        "eth_blockNumber",
        r#"[{"jsonrpc":"2.0","id":1,"result":"0x96bacd"}]"#,
    )],
}));

fn set_signer(&mut self, signer: Box<dyn Signer>)[src]

Sets custom signer.

Example

use in3::signer::In3Signer;
use std::convert::TryInto;

client.set_signer(Box::new(In3Signer::new(
        "8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f"
        .try_into().unwrap())));

fn set_storage(&mut self, storage: Box<dyn Storage>)[src]

Sets custom storage.

Example

use std::collections::HashMap;

struct MemStorage {
    buf: HashMap<String, Vec<u8>>
}

impl Default for MemStorage {
    fn default() -> Self {
        MemStorage{buf: HashMap::new()}
    }
}

impl Storage for MemStorage {
    fn get(&self,key: &str) -> Option<Vec<u8>> {
        Some(self.buf.get(key)?.clone())
    }

    fn set(&mut self,key: &str,value: &[u8]) {
        self.buf.insert(key.to_string(), value.into());
    }

    fn clear(&mut self) {
        self.buf.clear()
    }
}

client.set_storage(Box::new(MemStorage::default()));

impl Drop for Client[src]

impl From<*mut in3_t_> for &mut Client[src]

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl !Send for Client

impl !Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,