Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
unwrap SignerMiddleware constructor calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Mar 30, 2022
1 parent 9a4e0a8 commit b3ed45b
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ethers-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let provider =
// Sign transactions with a private key
let signer = LocalWallet::new(&mut rand::thread_rng());
let address = signer.address();
let provider = SignerMiddleware::new(provider, signer).await;
let provider = SignerMiddleware::new(provider, signer).await.unwrap();
// Use EthGasStation as the gas oracle
let gas_oracle = EthGasStation::new(None);
Expand Down
18 changes: 9 additions & 9 deletions ethers-middleware/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use thiserror::Error;
/// let wallet: LocalWallet = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"
/// .parse()?;
///
/// let mut client = SignerMiddleware::new(provider, wallet).await;
/// let mut client = SignerMiddleware::new(provider, wallet).await.unwrap();
///
/// // You can sign messages with the key
/// let signed_msg = client.sign(b"hello".to_vec(), &client.address()).await?;
Expand All @@ -47,12 +47,12 @@ use thiserror::Error;
/// let wallet2: LocalWallet = "cd8c407233c0560f6de24bb2dc60a8b02335c959a1a17f749ce6c1ccf63d74a7"
/// .parse()?;
///
/// let signed_msg2 = client.with_signer(wallet2).await.sign(b"hello".to_vec(), &client.address()).await?;
/// let signed_msg2 = client.with_signer(wallet2).await.unwrap().sign(b"hello".to_vec(), &client.address()).await?;
///
/// // This call will be made with `wallet2` since `with_signer` takes a mutable reference.
/// let tx2 = TransactionRequest::new()
/// .to("0xd8da6bf26964af9d7eed9e03e53415d37aa96045".parse::<Address>()?)
/// .value(200);
/// .value(200u64);
/// let tx_hash2 = client.send_transaction(tx2, None).await?;
///
/// # Ok(())
Expand Down Expand Up @@ -358,7 +358,7 @@ mod tests {
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(chain_id);
let client = SignerMiddleware::new(provider, key).await;
let client = SignerMiddleware::new(provider, key).await.unwrap();

let tx = client.sign_transaction(tx).await.unwrap();

Expand All @@ -377,15 +377,15 @@ mod tests {
let ganache = Ganache::new().spawn();
let provider = Provider::try_from(ganache.endpoint()).unwrap();
let chain_id = provider.get_chainid().await.unwrap();
assert_eq!(chain_id, U256::from(1337));
assert_eq!(chain_id, U256::from(1337u64));

// Intentionally do not set the chain id here so we ensure that the signer pulls the
// provider's chain id.
let key = LocalWallet::new(&mut rand::thread_rng());

// combine the provider and wallet and test that the chain id is the same for both the
// signer returned by the middleware and through the middleware itself.
let client = SignerMiddleware::new(provider, key).await;
let client = SignerMiddleware::new(provider, key).await.unwrap();
let middleware_chainid = client.get_chainid().await.unwrap();
assert_eq!(chain_id, middleware_chainid);

Expand All @@ -399,15 +399,15 @@ mod tests {
let ganache = Ganache::new().args(vec!["--chain.chainId", "13371337"]).spawn();
let provider = Provider::try_from(ganache.endpoint()).unwrap();
let chain_id = provider.get_chainid().await.unwrap();
assert_eq!(chain_id, U256::from(13371337));
assert_eq!(chain_id, U256::from(13371337u64));

// Intentionally do not set the chain id here so we ensure that the signer pulls the
// provider's chain id.
let key = LocalWallet::new(&mut rand::thread_rng());

// combine the provider and wallet and test that the chain id is the same for both the
// signer returned by the middleware and through the middleware itself.
let client = SignerMiddleware::new(provider, key).await;
let client = SignerMiddleware::new(provider, key).await.unwrap();
let middleware_chainid = client.get_chainid().await.unwrap();
assert_eq!(chain_id, middleware_chainid);

Expand All @@ -429,7 +429,7 @@ mod tests {
)
.await
.unwrap();
let client = SignerMiddleware::new(provider, key).await;
let client = SignerMiddleware::new(provider, key).await.unwrap();

let request = TransactionRequest::new();

Expand Down
2 changes: 1 addition & 1 deletion ethers-middleware/src/transformer/ds_proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const DS_PROXY_EXECUTE_CODE: &str =
/// let wallet: LocalWallet = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"
/// .parse()?;
/// let provider = Provider::<Http>::try_from("http://localhost:8545")?;
/// let client = SignerMiddleware::new(provider, wallet).await;
/// let client = SignerMiddleware::new(provider, wallet).await.unwrap();
///
/// # let ds_proxy_addr = Address::random();
/// // instantiate DsProxy by providing its address.
Expand Down
2 changes: 1 addition & 1 deletion ethers-middleware/tests/gas_escalator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn gas_escalator_live() {
.parse::<LocalWallet>()
.unwrap();
let address = wallet.address();
let provider = SignerMiddleware::new(provider, wallet).await;
let provider = SignerMiddleware::new(provider, wallet).await.unwrap();

let escalator = GeometricGasPrice::new(5.0, 10u64, Some(2_000_000_000_000u64));

Expand Down
2 changes: 1 addition & 1 deletion ethers-middleware/tests/gas_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn using_gas_oracle() {
let provider = Provider::<Http>::try_from(ganache.endpoint()).unwrap();

// assign a gas oracle to use
let gas_oracle = FakeGasOracle { gas_price: 1337.into() };
let gas_oracle = FakeGasOracle { gas_price: 875001337.into() };
let expected_gas_price = gas_oracle.fetch().await.unwrap();

let provider = GasOracleMiddleware::new(provider, gas_oracle);
Expand Down
2 changes: 1 addition & 1 deletion ethers-middleware/tests/nonce_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn nonce_manager() {
.with_chain_id(chain_id);
let address = wallet.address();

let provider = SignerMiddleware::new(provider, wallet).await;
let provider = SignerMiddleware::new(provider, wallet).await.unwrap();

// the nonce manager must be over the Client so that it overrides the nonce
// before the client gets it
Expand Down
16 changes: 8 additions & 8 deletions ethers-middleware/tests/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn send_eth() {
.interval(Duration::from_millis(10u64));
let chain_id = provider.get_chainid().await.unwrap().as_u64();
let wallet = wallet.with_chain_id(chain_id);
let provider = SignerMiddleware::new(provider, wallet).await;
let provider = SignerMiddleware::new(provider, wallet).await.unwrap();

// craft the transaction
let tx = TransactionRequest::new().to(wallet2.address()).value(10000).chain_id(chain_id);
Expand All @@ -58,7 +58,7 @@ async fn pending_txs_with_confirmations_testnet() {
let chain_id = provider.get_chainid().await.unwrap();
let wallet = WALLETS.next().with_chain_id(chain_id.as_u64());
let address = wallet.address();
let provider = SignerMiddleware::new(provider, wallet).await;
let provider = SignerMiddleware::new(provider, wallet).await.unwrap();
generic_pending_txs_test(provider, address).await;
}

Expand All @@ -73,7 +73,7 @@ async fn websocket_pending_txs_with_confirmations_testnet() {
let chain_id = provider.get_chainid().await.unwrap();
let wallet = WALLETS.next().with_chain_id(chain_id.as_u64());
let address = wallet.address();
let provider = SignerMiddleware::new(provider, wallet).await;
let provider = SignerMiddleware::new(provider, wallet).await.unwrap();
generic_pending_txs_test(provider, address).await;
}

Expand All @@ -96,7 +96,7 @@ async fn typed_txs() {
let wallet = WALLETS.next().with_chain_id(chain_id.as_u64());
let address = wallet.address();
// our wallet
let provider = SignerMiddleware::new(provider, wallet).await;
let provider = SignerMiddleware::new(provider, wallet).await.unwrap();

// Uncomment the below and run this test to re-fund the wallets if they get drained.
// Would be ideal if we'd have a way to do this automatically, but this should be
Expand Down Expand Up @@ -145,7 +145,7 @@ async fn test_send_transaction() {
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(chain_id);
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();

let balance_before = client.get_balance(client.address(), None).await.unwrap();
let tx = TransactionRequest::pay(client.address(), 100);
Expand All @@ -168,7 +168,7 @@ async fn send_transaction_handles_tx_from_field() {

// connect to the network
let provider = Provider::try_from(ganache.endpoint()).unwrap();
let provider = SignerMiddleware::new(provider, signer.clone()).await;
let provider = SignerMiddleware::new(provider, signer.clone()).await.unwrap();

// sending a TransactionRequest with a from field of None should result
// in a transaction from the signer address
Expand Down Expand Up @@ -231,7 +231,7 @@ async fn deploy_and_call_contract() {
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(chain_id);
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();
let client = Arc::new(client);

let factory = ContractFactory::new(abi, bytecode, client);
Expand Down Expand Up @@ -268,7 +268,7 @@ impl TestWallets {
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(provider.get_chainid().await.unwrap().as_u64());
let provider = SignerMiddleware::new(provider, signer).await;
let provider = SignerMiddleware::new(provider, signer).await.unwrap();
let addr = provider.address();

let mut nonce = provider.get_transaction_count(addr, None).await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions ethers-middleware/tests/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
let escalator = GeometricGasPrice::new(1.125, 60u64, None::<u64>);
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
let provider = GasOracleMiddleware::new(provider, gas_oracle);
let provider = SignerMiddleware::new(provider, signer).await;
let provider = SignerMiddleware::new(provider, signer).await.unwrap();
let provider = NonceManagerMiddleware::new(provider, address);

// push a response
Expand Down Expand Up @@ -73,7 +73,7 @@ mod tests {

// The signing middleware signs txs
use std::sync::Arc;
let provider = Arc::new(SignerMiddleware::new(provider, signer).await);
let provider = Arc::new(SignerMiddleware::new(provider, signer).await.unwrap());

// The nonce manager middleware MUST be above the signing middleware so that it overrides
// the nonce and the signer does not make any eth_getTransaction count calls
Expand Down
4 changes: 2 additions & 2 deletions ethers-middleware/tests/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn ds_proxy_transformer() {
.interval(Duration::from_millis(10u64));
let chain_id = provider.get_chainid().await.unwrap().as_u64();
let wallet = wallet.with_chain_id(chain_id);
let signer_middleware = SignerMiddleware::new(provider.clone(), wallet).await;
let signer_middleware = SignerMiddleware::new(provider.clone(), wallet).await.unwrap();
let wallet_addr = signer_middleware.address();
let provider = Arc::new(signer_middleware.clone());

Expand Down Expand Up @@ -96,7 +96,7 @@ async fn ds_proxy_code() {
.interval(Duration::from_millis(10u64));
let chain_id = provider.get_chainid().await.unwrap().as_u64();
let wallet = wallet.with_chain_id(chain_id);
let signer_middleware = SignerMiddleware::new(provider.clone(), wallet).await;
let signer_middleware = SignerMiddleware::new(provider.clone(), wallet).await.unwrap();
let wallet_addr = signer_middleware.address();
let provider = Arc::new(signer_middleware.clone());

Expand Down
2 changes: 1 addition & 1 deletion examples/contract_human_readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() -> Result<()> {
Provider::<Http>::try_from(ganache.endpoint())?.interval(Duration::from_millis(10u64));

// 4. instantiate the client with the wallet
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();
let client = Arc::new(client);

// 5. create a factory which will be used to deploy instances of the contract
Expand Down
2 changes: 1 addition & 1 deletion examples/contract_with_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn main() -> Result<()> {
Provider::<Http>::try_from(ganache.endpoint())?.interval(Duration::from_millis(10u64));

// 4. instantiate the client with the wallet
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();
let client = Arc::new(client);

// 5. create a factory which will be used to deploy instances of the contract
Expand Down
2 changes: 1 addition & 1 deletion examples/contract_with_abi_and_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Provider::<Http>::try_from(ganache.endpoint())?.interval(Duration::from_millis(10u64));
let wallet: LocalWallet = ganache.keys()[0].clone().into();

let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();
let client = Arc::new(client);

let contract = VerifierContract::new(Address::zero(), client);
Expand Down
2 changes: 1 addition & 1 deletion examples/ethers-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn deploy() {

let endpoint = "ws://127.0.0.1:8545";
let provider = Provider::new(Ws::connect(endpoint).await.unwrap());
let client = Arc::new(SignerMiddleware::new(provider, wallet).await);
let client = Arc::new(SignerMiddleware::new(provider, wallet).await.unwrap());
log!("Provider connected to `{}`", endpoint);

let bytecode = hex::decode(SIMPLECONTRACT_BIN).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/ethers-wasm/tests/contract_with_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn ws_connect_and_deploy() {
}

async fn deploy<T: JsonRpcClient>(provider: Provider<T>, wallet: LocalWallet) {
let client = Arc::new(SignerMiddleware::new(provider, wallet).await);
let client = Arc::new(SignerMiddleware::new(provider, wallet).await.unwrap());

let bytecode = hex::decode(ethers_wasm::utils::SIMPLECONTRACT_BIN).unwrap();
let factory = ContractFactory::new(SIMPLECONTRACT_ABI.clone(), bytecode.into(), client.clone());
Expand Down
2 changes: 1 addition & 1 deletion examples/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// index or supply the full HD path string. You may also provide the chain_id
// (here: mainnet) for EIP155 support.
let ledger = Ledger::new(HDPath::LedgerLive(0), 1).await?;
let client = SignerMiddleware::new(provider, ledger).await;
let client = SignerMiddleware::new(provider, ledger).await.unwrap();

// Create and broadcast a transaction (ENS enabled!)
// (this will require confirming the tx on the device)
Expand Down
2 changes: 1 addition & 1 deletion examples/local_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn main() -> Result<()> {
let provider = Provider::<Http>::try_from(ganache.endpoint())?;

// connect the wallet to the provider
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();

// craft the transaction
let tx = TransactionRequest::new().to(wallet2.address()).value(10000);
Expand Down
2 changes: 1 addition & 1 deletion examples/moonbeam_with_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> eyre::Result<()> {
Provider::<Http>::try_from(MOONBEAM_DEV_ENDPOINT)?.interval(Duration::from_millis(10u64));

// 4. instantiate the client with the wallet
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();
let client = Arc::new(client);

// 5. create a factory which will be used to deploy instances of the contract
Expand Down
2 changes: 1 addition & 1 deletion examples/trezor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// EIP1559 support
// No EIP712 support yet.
let trezor = Trezor::new(TrezorHDPath::TrezorLive(0), 1).await?;
let client = SignerMiddleware::new(provider, trezor).await;
let client = SignerMiddleware::new(provider, trezor).await.unwrap();

// Create and broadcast a transaction (ENS disabled!)
// (this will require confirming the tx on the device)
Expand Down
2 changes: 1 addition & 1 deletion examples/yubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// `from_key` method to upload a key you already have, or the `new` method
// to generate a new keypair.
let wallet = YubiWallet::connect(connector, Credentials::default(), 0);
let client = SignerMiddleware::new(provider, wallet).await;
let client = SignerMiddleware::new(provider, wallet).await.unwrap();

// Create and broadcast a transaction (ENS enabled!)
let tx = TransactionRequest::new().to("vitalik.eth").value(parse_ether(10)?);
Expand Down

0 comments on commit b3ed45b

Please sign in to comment.