Skip to content

Commit dce24f6

Browse files
committed
refactor: remove unwraps
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent a93dae5 commit dce24f6

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

common/src/allocations/monitor.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use std::{
99

1010
use super::Allocation;
1111
use crate::prelude::SubgraphClient;
12-
use alloy::primitives::U256;
12+
use alloy::primitives::{TxHash, B256, U256};
1313
use eventuals::{timer, Eventual, EventualExt};
1414
use graphql_client::GraphQLQuery;
1515
use thegraph_core::{Address, DeploymentId};
1616
use tokio::time::sleep;
1717
use tracing::warn;
1818

19-
type BigInt = String;
20-
type Bytes = String;
19+
type BigInt = U256;
20+
type Bytes = B256;
2121

2222
#[derive(GraphQLQuery)]
2323
#[graphql(
@@ -42,9 +42,9 @@ impl TryFrom<allocations_query::AllocationFragment> for Allocation {
4242
denied_at: Some(value.subgraph_deployment.denied_at as u64),
4343
},
4444
indexer: Address::from_str(&value.indexer.id)?,
45-
allocated_tokens: U256::from_str(&value.allocated_tokens)?,
45+
allocated_tokens: value.allocated_tokens,
4646
created_at_epoch: value.created_at_epoch as u64,
47-
created_at_block_hash: value.created_at_block_hash,
47+
created_at_block_hash: value.created_at_block_hash.to_string(),
4848
closed_at_epoch: value.closed_at_epoch.map(|v| v as u64),
4949
closed_at_epoch_start_block_hash: None,
5050
previous_epoch_start_block_hash: None,
@@ -98,7 +98,7 @@ pub async fn get_allocations(
9898
.expect("Time went backwards");
9999
let closed_at_threshold = since_the_epoch - recently_closed_allocation_buffer;
100100

101-
let mut hash: Option<String> = None;
101+
let mut hash: Option<TxHash> = None;
102102
let mut last: Option<String> = None;
103103
let mut responses = vec![];
104104
let page_size = 200;
@@ -129,10 +129,15 @@ pub async fn get_allocations(
129129
break;
130130
}
131131
}
132-
133-
Ok(HashMap::from_iter(responses.into_iter().map(|a| {
134-
(Address::from_str(&a.id).unwrap(), a.try_into().unwrap())
135-
})))
132+
let responses = responses
133+
.into_iter()
134+
.map(|allocation| allocation.try_into())
135+
.collect::<Result<Vec<Allocation>, _>>()?;
136+
137+
Ok(responses
138+
.into_iter()
139+
.map(|allocation| (allocation.id, allocation))
140+
.collect())
136141
}
137142

138143
#[cfg(test)]

common/src/escrow_accounts.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn escrow_accounts(
125125
.await
126126
.map_err(|e| e.to_string())?;
127127

128-
let response = response.unwrap();
128+
let response = response.map_err(|e| e.to_string())?;
129129

130130
let senders_balances: HashMap<Address, U256> = response
131131
.escrow_accounts
@@ -141,27 +141,27 @@ pub fn escrow_accounts(
141141
U256::from(0)
142142
});
143143

144-
Ok((Address::from_str(&account.sender.id).unwrap(), balance))
144+
Ok((Address::from_str(&account.sender.id)?, balance))
145145
})
146146
.collect::<Result<HashMap<_, _>, anyhow::Error>>()
147-
.map_err(|e| format!("{}", e))?;
147+
.map_err(|e| e.to_string())?;
148148

149149
let senders_to_signers = response
150150
.escrow_accounts
151-
.iter()
151+
.into_iter()
152152
.map(|account| {
153-
let sender = Address::from_str(&account.sender.id).unwrap();
153+
let sender = Address::from_str(&account.sender.id)?;
154154
let signers = account
155155
.sender
156156
.signers
157-
.as_ref()
158-
.unwrap()
157+
.unwrap_or_default()
159158
.iter()
160-
.map(|signer| Address::from_str(&signer.id).unwrap())
161-
.collect();
162-
(sender, signers)
159+
.map(|signer| Address::from_str(&signer.id))
160+
.collect::<Result<Vec<_>, _>>()?;
161+
Ok((sender, signers))
163162
})
164-
.collect();
163+
.collect::<Result<HashMap<_, _>, anyhow::Error>>()
164+
.map_err(|e| e.to_string())?;
165165

166166
Ok(EscrowAccounts::new(senders_balances, senders_to_signers))
167167
},

tap-agent/src/agent/sender_account.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,10 @@ impl Actor for SenderAccount {
384384
Ok(Ok(response)) => response
385385
.transactions
386386
.into_iter()
387-
.map(|tx| tx.allocation_id.unwrap())
387+
.map(|tx| {
388+
tx.allocation_id
389+
.expect("all redeem tx must have allocation_id")
390+
})
388391
.collect::<Vec<_>>(),
389392
// if we have any problems, we don't want to filter out
390393
_ => vec![],

0 commit comments

Comments
 (0)