generic basic account fetcher, nonce RPC
This commit is contained in:
		
							parent
							
								
									024e69138a
								
							
						
					
					
						commit
						e460421deb
					
				| @ -27,6 +27,7 @@ use light::on_demand::{request, OnDemand}; | ||||
| use light::net::LightProtocol; | ||||
| 
 | ||||
| use ethcore::account_provider::{AccountProvider, DappId}; | ||||
| use ethcore::basic_account::BasicAccount; | ||||
| use ethcore::encoded; | ||||
| use ethcore::ids::BlockId; | ||||
| use ethsync::LightSync; | ||||
| @ -44,6 +45,8 @@ use v1::types::{ | ||||
| }; | ||||
| use v1::metadata::Metadata; | ||||
| 
 | ||||
| use util::Address; | ||||
| 
 | ||||
| /// Light client `ETH` RPC.
 | ||||
| pub struct EthClient { | ||||
| 	sync: Arc<LightSync>, | ||||
| @ -106,6 +109,20 @@ impl EthClient { | ||||
| 			None => future::err(err_no_context()).boxed() | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// helper for getting account info.
 | ||||
| 	fn account(&self, address: Address, id: BlockId) -> BoxFuture<BasicAccount, Error> { | ||||
| 		let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); | ||||
| 
 | ||||
| 		self.header(id).and_then(move |header| { | ||||
| 			sync.with_context(|ctx| on_demand.account(ctx, request::Account { | ||||
| 				header: header, | ||||
| 				address: address, | ||||
| 			})) | ||||
| 				.map(|x| x.map_err(errors::from_on_demand_error).boxed()) | ||||
| 				.unwrap_or_else(|| future::err(err_no_context()).boxed()) | ||||
| 		}).boxed() | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| impl Eth for EthClient { | ||||
| @ -152,19 +169,7 @@ impl Eth for EthClient { | ||||
| 	} | ||||
| 
 | ||||
| 	fn balance(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> { | ||||
| 		let address = address.into(); | ||||
| 
 | ||||
| 		let sync = self.sync.clone(); | ||||
| 		let on_demand = self.on_demand.clone(); | ||||
| 
 | ||||
| 		self.header(num.0.into()).and_then(move |header| { | ||||
| 			sync.with_context(|ctx| on_demand.account(ctx, request::Account { | ||||
| 				header: header, | ||||
| 				address: address, | ||||
| 			})) | ||||
| 				.map(|x| x.map_err(errors::from_on_demand_error).boxed()) | ||||
| 				.unwrap_or_else(|| future::err(err_no_context()).boxed()) | ||||
| 		}).map(|acc| acc.balance.into()).boxed() | ||||
| 		self.account(address.into(), num.0.into()).map(|acc| acc.balance.into()).boxed() | ||||
| 	} | ||||
| 
 | ||||
| 	fn storage_at(&self, address: RpcH160, key: RpcU256, num: Trailing<BlockNumber>) -> BoxFuture<RpcH256, Error> { | ||||
| @ -180,7 +185,7 @@ impl Eth for EthClient { | ||||
| 	} | ||||
| 
 | ||||
| 	fn transaction_count(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> { | ||||
| 		future::err(errors::unimplemented(None)).boxed() | ||||
| 		self.account(address.into(), num.0.into()).map(|acc| acc.nonce.into()).boxed() | ||||
| 	} | ||||
| 
 | ||||
| 	fn block_transaction_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user