summaryrefslogtreecommitdiff
path: root/eth-wire
diff options
context:
space:
mode:
authorAntoine A <>2022-03-23 21:36:38 +0100
committerAntoine A <>2022-03-23 21:36:38 +0100
commit4855a6ec05351a697de9f10be1597eaa8a726c0a (patch)
tree442bf9000470d244ba51710dc5c9f3b68ca2b24c /eth-wire
parenteffa824a4de6f09a999a578f30ba3e341d380b31 (diff)
downloaddepolymerization-4855a6ec05351a697de9f10be1597eaa8a726c0a.tar.gz
depolymerization-4855a6ec05351a697de9f10be1597eaa8a726c0a.tar.bz2
depolymerization-4855a6ec05351a697de9f10be1597eaa8a726c0a.zip
dirty fix for eth tests and other improvements
Diffstat (limited to 'eth-wire')
-rw-r--r--eth-wire/src/bin/eth-wire-utils.rs45
-rw-r--r--eth-wire/src/rpc.rs24
2 files changed, 15 insertions, 54 deletions
diff --git a/eth-wire/src/bin/eth-wire-utils.rs b/eth-wire/src/bin/eth-wire-utils.rs
index 65dc9a6..dff493e 100644
--- a/eth-wire/src/bin/eth-wire-utils.rs
+++ b/eth-wire/src/bin/eth-wire-utils.rs
@@ -84,21 +84,14 @@ enum Cmd {
wire_addr: String,
wire: u64,
},
- /// Add a peer
- Connect {
- /// peer datadir
- datadir: PathBuf,
- },
- /// Remove a peer
- Disconnect {
- /// peer datadir
- datadir: PathBuf,
- },
/// Abandon all unconfirmed transaction
Abandon {
/// sender address
from: String,
},
+ Export {
+ path: String,
+ },
}
fn main() {
@@ -216,34 +209,6 @@ fn main() {
}
}
}
- Cmd::Connect { datadir } => {
- let mut peer = Rpc::new(datadir).unwrap();
- let mut enode = peer.node_info().unwrap().enode;
- // Replace ip with localhost because it is broken
- enode.set_host(Some("127.0.0.1")).unwrap();
- assert!(rpc.add_peer(&enode).unwrap());
- let start = Instant::now();
- while rpc.count_peer().unwrap() == 0 {
- if start.elapsed() > Duration::from_secs(60) {
- panic!("Connect timeout");
- }
- std::thread::sleep(Duration::from_secs(5))
- }
- }
- Cmd::Disconnect { datadir } => {
- let mut peer = Rpc::new(datadir).unwrap();
- let mut enode = peer.node_info().unwrap().enode;
- // Replace ip with localhost because it is broken
- enode.set_host(Some("127.0.0.1")).unwrap();
- assert!(rpc.remove_peer(&enode).unwrap());
- let start = Instant::now();
- while rpc.count_peer().unwrap() != 0 {
- if start.elapsed() > Duration::from_secs(60) {
- panic!("Disconnect timeout");
- }
- std::thread::sleep(Duration::from_secs(5))
- }
- }
Cmd::Abandon { from } => {
let from = H160::from_str(&from).unwrap();
rpc.unlock_account(&from, &passwd).ok();
@@ -261,5 +226,9 @@ fn main() {
.unwrap();
}
}
+ Cmd::Export { path } => {
+ std::fs::remove_file(&path).ok();
+ assert!(rpc.export_chain(&path).unwrap())
+ }
}
}
diff --git a/eth-wire/src/rpc.rs b/eth-wire/src/rpc.rs
index 7766702..0908290 100644
--- a/eth-wire/src/rpc.rs
+++ b/eth-wire/src/rpc.rs
@@ -316,7 +316,7 @@ pub trait RpcClient {
/* ----- Account management ----- */
- /// List registered acount
+ /// List registered account
fn list_accounts(&mut self) -> Result<Vec<Address>> {
self.call("personal_listAccounts", &EMPTY)
}
@@ -326,7 +326,7 @@ pub trait RpcClient {
self.call("personal_newAccount", &[passwd])
}
- /// Unlock an existinf acount
+ /// Unlock an existing account
fn unlock_account(&mut self, account: &Address, passwd: &str) -> Result<bool> {
self.call("personal_unlockAccount", &(account, passwd, 0))
}
@@ -348,7 +348,7 @@ pub trait RpcClient {
r => r,
}
}
-
+
/// Get block by hash
fn block(&mut self, hash: &H256) -> Result<Option<Block>> {
match self.call("eth_getBlockByHash", &(hash, &true)) {
@@ -361,7 +361,7 @@ pub trait RpcClient {
fn pending_transactions(&mut self) -> Result<Vec<Transaction>> {
self.call("eth_pendingTransactions", &EMPTY)
}
-
+
/// Get latest block
fn latest_block(&mut self) -> Result<Block> {
self.call("eth_getBlockByNumber", &("latest", &true))
@@ -414,20 +414,12 @@ pub trait RpcClient {
/* ----- Peer management ----- */
- /// Add peer to the peer list
- fn add_peer(&mut self, url: &Url) -> Result<bool> {
- self.call("admin_addPeer", &[url])
- }
-
- /// Remove a peer to the peer list
- fn remove_peer(&mut self, url: &Url) -> Result<bool> {
- self.call("admin_removePeer", &[url])
+ fn export_chain(&mut self, path: &str) -> Result<bool> {
+ self.call("admin_exportChain", &[path])
}
- /// Get peer count
- fn count_peer(&mut self) -> Result<u32> {
- let peers: U64 = self.call("net_peerCount", &EMPTY)?;
- Ok(peers.as_u32())
+ fn import_chain(&mut self, path: &str) -> Result<bool> {
+ self.call("admin_importChain", &[path])
}
}