Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.73.0"
components = ["rustfmt"]
19 changes: 19 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# Put a trailing comma after a block based match arm (non-block arms are not affected)
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#match_block_trailing_comma
match_block_trailing_comma = true

# Maximum width of each line.
# Default: 100
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#max_width
max_width = 120

# Unix or Windows line endings
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#newline_style
newline_style = "Auto"

# Number of spaces per tab
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#tab_spaces
tab_spaces = 4

# Use field initialize shorthand if possible.
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#use_field_init_shorthand
use_field_init_shorthand = true
12 changes: 6 additions & 6 deletions src/api/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod accounts_signing {
let gas_price = match tx.transaction_type {
Some(tx_type) if tx_type == U64::from(EIP1559_TX_ID) && tx.max_fee_per_gas.is_some() => {
tx.max_fee_per_gas
}
},
_ => tx.gas_price,
};

Expand All @@ -101,7 +101,7 @@ mod accounts_signing {
let max_priority_fee_per_gas = match tx.transaction_type {
Some(tx_type) if tx_type == U64::from(EIP1559_TX_ID) => {
tx.max_priority_fee_per_gas.unwrap_or(gas_price)
}
},
_ => gas_price,
};

Expand Down Expand Up @@ -301,23 +301,23 @@ mod accounts_signing {
Some(LEGACY_TX_ID) | None => {
let stream = self.encode_legacy(chain_id, signature);
stream.out().to_vec()
}
},

Some(ACCESSLISTS_TX_ID) => {
let tx_id: u8 = ACCESSLISTS_TX_ID as u8;
let stream = self.encode_access_list_payload(chain_id, signature);
[&[tx_id], stream.as_raw()].concat()
}
},

Some(EIP1559_TX_ID) => {
let tx_id: u8 = EIP1559_TX_ID as u8;
let stream = self.encode_eip1559_payload(chain_id, signature);
[&[tx_id], stream.as_raw()].concat()
}
},

_ => {
panic!("Unsupported transaction type");
}
},
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ impl<T: Transport> Eth<T> {
BlockId::Hash(hash) => {
let hash = helpers::serialize(&hash);
self.transport.execute("eth_getBlockByHash", vec![hash, include_txs])
}
},
BlockId::Number(num) => {
let num = helpers::serialize(&num);
self.transport.execute("eth_getBlockByNumber", vec![num, include_txs])
}
},
};

CallFuture::new(result)
Expand All @@ -147,11 +147,11 @@ impl<T: Transport> Eth<T> {
BlockId::Hash(hash) => {
let hash = helpers::serialize(&hash);
self.transport.execute("eth_getBlockByHash", vec![hash, include_txs])
}
},
BlockId::Number(num) => {
let num = helpers::serialize(&num);
self.transport.execute("eth_getBlockByNumber", vec![num, include_txs])
}
},
};

CallFuture::new(result)
Expand All @@ -163,12 +163,12 @@ impl<T: Transport> Eth<T> {
BlockId::Hash(hash) => {
let hash = helpers::serialize(&hash);
self.transport.execute("eth_getBlockTransactionCountByHash", vec![hash])
}
},
BlockId::Number(num) => {
let num = helpers::serialize(&num);
self.transport
.execute("eth_getBlockTransactionCountByNumber", vec![num])
}
},
};

CallFuture::new(result)
Expand Down Expand Up @@ -222,19 +222,19 @@ impl<T: Transport> Eth<T> {
TransactionId::Hash(hash) => {
let hash = helpers::serialize(&hash);
self.transport.execute("eth_getTransactionByHash", vec![hash])
}
},
TransactionId::Block(BlockId::Hash(hash), index) => {
let hash = helpers::serialize(&hash);
let idx = helpers::serialize(&index);
self.transport
.execute("eth_getTransactionByBlockHashAndIndex", vec![hash, idx])
}
},
TransactionId::Block(BlockId::Number(number), index) => {
let number = helpers::serialize(&number);
let idx = helpers::serialize(&index);
self.transport
.execute("eth_getTransactionByBlockNumberAndIndex", vec![number, idx])
}
},
};

CallFuture::new(result)
Expand Down Expand Up @@ -268,12 +268,12 @@ impl<T: Transport> Eth<T> {
let hash = helpers::serialize(&hash);
self.transport
.execute("eth_getUncleByBlockHashAndIndex", vec![hash, index])
}
},
BlockId::Number(num) => {
let num = helpers::serialize(&num);
self.transport
.execute("eth_getUncleByBlockNumberAndIndex", vec![num, index])
}
},
};

CallFuture::new(result)
Expand All @@ -285,11 +285,11 @@ impl<T: Transport> Eth<T> {
BlockId::Hash(hash) => {
let hash = helpers::serialize(&hash);
self.transport.execute("eth_getUncleCountByBlockHash", vec![hash])
}
},
BlockId::Number(num) => {
let num = helpers::serialize(&num);
self.transport.execute("eth_getUncleCountByBlockNumber", vec![num])
}
},
};

CallFuture::new(result)
Expand Down
2 changes: 1 addition & 1 deletion src/api/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod tests {
"condition": {
"block": 1
},
"chainId": 1,
"chainId": "0x1",
"nonce": "0x5",
"publicKey": "0x96157302dade55a1178581333e57d60ffe6fdf5a99607890456a578b4e6b60e335037d61ed58aa4180f9fd747dc50d44a7924aa026acbfb988b5062b629d6c36",
"r": "0x92e8beb19af2bad0511d516a86e77fa73004c0811b2173657a55797bdf8558e1",
Expand Down
4 changes: 2 additions & 2 deletions src/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<T: Transport> Builder<T> {
let address: String = hex::encode(address);
code_hex = code_hex.replacen(&replace, &address, 1);
}
code_hex = code_hex.replace("\"", "").replace("0x", ""); // This is to fix truffle + serde_json redundant `"` and `0x`
code_hex = code_hex.replace('\"', "").replace("0x", ""); // This is to fix truffle + serde_json redundant `"` and `0x`
let code =
hex::decode(&code_hex).map_err(|e| ethabi::Error::InvalidName(format!("hex decode error: {}", e)))?;

Expand All @@ -194,7 +194,7 @@ impl<T: Transport> Builder<T> {
return Err(Error::Abi(ethabi::Error::InvalidName(
"Constructor is not defined in the ABI.".into(),
)));
}
},
(None, true) => code,
(Some(constructor), _) => constructor.encode_input(code, &params)?,
};
Expand Down
10 changes: 5 additions & 5 deletions src/contract/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Tokenizable for H256 {
data[idx] = val;
}
Ok(data.into())
}
},
other => Err(Error::InvalidOutputType(format!("Expected `H256`, got {:?}", other))),
}
}
Expand Down Expand Up @@ -306,7 +306,7 @@ impl Tokenizable for BytesArray {
.map(Tokenizable::from_token)
.collect::<Result<Vec<u8>, Error>>()?;
Ok(Self(bytes))
}
},
other => Err(Error::InvalidOutputType(format!("Expected `Array`, got {:?}", other))),
}
}
Expand Down Expand Up @@ -334,7 +334,7 @@ impl<T: TokenizableItem> Tokenizable for Vec<T> {
match token {
Token::FixedArray(tokens) | Token::Array(tokens) => {
tokens.into_iter().map(Tokenizable::from_token).collect()
}
},
other => Err(Error::InvalidOutputType(format!("Expected `Array`, got {:?}", other))),
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ macro_rules! impl_fixed_types {
let mut arr = [0; $num];
arr.copy_from_slice(&bytes);
Ok(arr)
}
},
other => Err(
Error::InvalidOutputType(format!("Expected `FixedBytes({})`, got {:?}", $num, other)).into(),
),
Expand Down Expand Up @@ -399,7 +399,7 @@ macro_rules! impl_fixed_types {
Ok(arr) => Ok(arr),
Err(_) => panic!("All elements inserted so the array is full; qed"),
}
}
},
other => Err(
Error::InvalidOutputType(format!("Expected `FixedArray({})`, got {:?}", $num, other)).into(),
),
Expand Down
6 changes: 3 additions & 3 deletions src/transports/eip_1193.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ impl Eip1193 {
if let Err(err) = sink.unbounded_send(evt.data.result) {
log::error!("Error sending notification: {}", err)
}
}
},
None => log::warn!("Got message for non-existent subscription {}", evt.data.subscription),
}
}
},
other => log::warn!("Got unknown notification type: {}", other),
}
}) as Box<dyn FnMut(JsValue)>);
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Transport for Eip1193 {
})
.await
})
}
},
_ => panic!("Can't send JSON-RPC requests other than method calls with EIP-1193 transport!"),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/transports/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl futures::Future for SingleResponse {
Ok(ref mut rx) => {
let output = ready!(futures::Future::poll(Pin::new(rx), cx))?;
Poll::Ready(helpers::to_result_from_output(output))
}
},
}
}
}
Expand All @@ -147,7 +147,7 @@ impl futures::Future for BatchResponse {
.collect();

Poll::Ready(Ok(values))
}
},
}
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ fn respond_output(
_ => {
log::warn!("Got unsupported response (id: {:?})", id);
return Err(());
}
},
};

let response_tx = pending_response_txs.remove(&id).ok_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/transports/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Transport for TestTransport {
None => {
println!("Unexpected request (id: {:?}): {:?}", id, request);
Err(Error::Unreachable)
}
},
})
.boxed()
}
Expand Down
16 changes: 8 additions & 8 deletions src/transports/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl WsServerTask {
"Wrong scheme: {}",
s
))))
}
},
};

let host = match url.host_str() {
Expand All @@ -118,7 +118,7 @@ impl WsServerTask {
return Err(error::Error::Transport(TransportError::Message(
"Wrong host name".to_string(),
)))
}
},
};

let port = url.port().unwrap_or(if scheme == "ws" { 80 } else { 443 });
Expand Down Expand Up @@ -176,10 +176,10 @@ impl WsServerTask {
ServerResponse::Accepted { .. } => client.into_builder().finish(),
ServerResponse::Redirect { status_code, .. } => {
return Err(error::Error::Transport(TransportError::Code(status_code)))
}
},
ServerResponse::Rejected { status_code } => {
return Err(error::Error::Transport(TransportError::Code(status_code)))
}
},
};

Ok(Self {
Expand Down Expand Up @@ -418,11 +418,11 @@ where
ResponseState::Receiver(ref mut res) => {
let receiver = res.take().expect("Receiver state is active only once; qed")?;
self.state = ResponseState::Waiting(receiver)
}
},
ResponseState::Waiting(ref mut future) => {
let response = ready!(future.poll_unpin(cx)).map_err(dropped_err)?;
return Poll::Ready((self.extract)(response));
}
},
}
}
}
Expand Down Expand Up @@ -518,7 +518,7 @@ pub mod compat {

/// Create new TcpStream object.
pub async fn raw_tcp_stream(addrs: String) -> io::Result<tokio::net::TcpStream> {
Ok(tokio::net::TcpStream::connect(addrs).await?)
tokio::net::TcpStream::connect(addrs).await
}

/// Wrap given argument into compatibility layer.
Expand Down Expand Up @@ -591,7 +591,7 @@ mod tests {
.await
.unwrap();
sender.flush().await.unwrap();
}
},
Err(soketto::connection::Error::Closed) => break,
e => panic!("Unexpected data: {:?}", e),
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Serialize for BlockId {
let mut s = serializer.serialize_struct("BlockIdEip1898", 1)?;
s.serialize_field("blockHash", &format!("{:?}", x))?;
s.end()
}
},
BlockId::Number(ref num) => num.serialize(serializer),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Log {
if val_log_type == "removed" {
return true;
}
}
},
None => (),
}
false
Expand Down
2 changes: 1 addition & 1 deletion src/types/sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'de> Deserialize<'de> for SyncState {
} else {
Err(D::Error::custom("expected object or `false`, got `true`"))
}
}
},
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use serde::{Deserialize, Serialize};
/// Description of a Transaction, pending or in the chain.
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct Transaction {
/// Chain Id. None for legacy tx
#[serde(rename = "chainId")]
pub chain_id: Option<U64>,
/// Hash
pub hash: H256,
/// Nonce
Expand Down
Loading