Skip to content

Commit f7447f7

Browse files
committed
refactor(tap_agent): trim_start_matches addresses
Signed-off-by: Alexis Asseman <[email protected]>
1 parent 91e7d56 commit f7447f7

File tree

5 files changed

+22
-61
lines changed

5 files changed

+22
-61
lines changed

common/src/tap_manager.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,11 @@ impl TapManager {
9090
VALUES ($1, $2, $3, $4, $5)
9191
"#,
9292
format!("{:?}", allocation_id)
93-
.strip_prefix("0x")
94-
.unwrap()
93+
.trim_start_matches("0x")
9594
.to_owned(),
9695
receipt_signer
9796
.to_string()
98-
.strip_prefix("0x")
99-
.unwrap()
97+
.trim_start_matches("0x")
10098
.to_owned(),
10199
BigDecimal::from(receipt.message.timestamp_ns),
102100
BigDecimal::from_str(&receipt.message.value.to_string())?,

tap_agent/src/tap/account.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,9 @@ impl Account {
242242
inner
243243
.allocation_id
244244
.to_string()
245-
.strip_prefix("0x")
246-
.unwrap()
245+
.trim_start_matches("0x")
247246
.to_owned(),
248-
inner
249-
.sender
250-
.to_string()
251-
.strip_prefix("0x")
252-
.unwrap()
253-
.to_owned()
247+
inner.sender.to_string().trim_start_matches("0x").to_owned()
254248
)
255249
.fetch_one(&inner.pgpool)
256250
.await?;
@@ -370,15 +364,9 @@ impl Account {
370364
inner
371365
.allocation_id
372366
.to_string()
373-
.strip_prefix("0x")
374-
.unwrap()
375-
.to_owned(),
376-
inner
377-
.sender
378-
.to_string()
379-
.strip_prefix("0x")
380-
.unwrap()
367+
.trim_start_matches("0x")
381368
.to_owned(),
369+
inner.sender.to_string().trim_start_matches("0x").to_owned(),
382370
)
383371
.fetch_all(&inner.pgpool)
384372
.await?;
@@ -768,10 +756,9 @@ mod tests {
768756
"#,
769757
ALLOCATION_ID
770758
.to_string()
771-
.strip_prefix("0x")
772-
.unwrap()
759+
.trim_start_matches("0x")
773760
.to_owned(),
774-
SENDER.1.to_string().strip_prefix("0x").unwrap().to_owned()
761+
SENDER.1.to_string().trim_start_matches("0x").to_owned()
775762
)
776763
.fetch_optional(&pgpool)
777764
.await
@@ -832,10 +819,9 @@ mod tests {
832819
"#,
833820
ALLOCATION_ID
834821
.to_string()
835-
.strip_prefix("0x")
836-
.unwrap()
822+
.trim_start_matches("0x")
837823
.to_owned(),
838-
SENDER.1.to_string().strip_prefix("0x").unwrap().to_owned()
824+
SENDER.1.to_string().trim_start_matches("0x").to_owned()
839825
)
840826
.fetch_optional(&pgpool)
841827
.await

tap_agent/src/tap/rav_storage_adapter.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter {
3636
"#,
3737
self.allocation_id
3838
.to_string()
39-
.strip_prefix("0x")
40-
.unwrap()
41-
.to_owned(),
42-
self.sender
43-
.to_string()
44-
.strip_prefix("0x")
45-
.unwrap()
39+
.trim_start_matches("0x")
4640
.to_owned(),
41+
self.sender.to_string().trim_start_matches("0x").to_owned(),
4742
serde_json::to_value(rav).map_err(|e| AdapterError::AdapterError {
4843
error: e.to_string()
4944
})?
@@ -65,14 +60,9 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter {
6560
"#,
6661
self.allocation_id
6762
.to_string()
68-
.strip_prefix("0x")
69-
.unwrap()
63+
.trim_start_matches("0x")
7064
.to_owned(),
71-
self.sender
72-
.to_string()
73-
.strip_prefix("0x")
74-
.unwrap()
75-
.to_owned()
65+
self.sender.to_string().trim_start_matches("0x").to_owned()
7666
)
7767
.fetch_optional(&self.pgpool)
7868
.await

tap_agent/src/tap/receipt_storage_adapter.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,9 @@ impl ReceiptStorageAdapterTrait for ReceiptStorageAdapter {
106106
"#,
107107
self.allocation_id
108108
.to_string()
109-
.strip_prefix("0x")
110-
.unwrap()
111-
.to_owned(),
112-
self.sender
113-
.to_string()
114-
.strip_prefix("0x")
115-
.unwrap()
109+
.trim_start_matches("0x")
116110
.to_owned(),
111+
self.sender.to_string().trim_start_matches("0x").to_owned(),
117112
rangebounds_to_pgrange(timestamp_range_ns)
118113
)
119114
.fetch_all(&self.pgpool)
@@ -150,14 +145,9 @@ impl ReceiptStorageAdapterTrait for ReceiptStorageAdapter {
150145
"#,
151146
self.allocation_id
152147
.to_string()
153-
.strip_prefix("0x")
154-
.unwrap()
155-
.to_owned(),
156-
self.sender
157-
.to_string()
158-
.strip_prefix("0x")
159-
.unwrap()
148+
.trim_start_matches("0x")
160149
.to_owned(),
150+
self.sender.to_string().trim_start_matches("0x").to_owned(),
161151
rangebounds_to_pgrange(timestamp_ns)
162152
)
163153
.execute(&self.pgpool)

tap_agent/src/tap/test_utils.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,13 @@ pub async fn store_receipt(pgpool: &PgPool, signed_receipt: SignedReceipt) -> Re
101101
.message
102102
.allocation_id
103103
.to_string()
104-
.strip_prefix("0x")
105-
.unwrap()
104+
.trim_start_matches("0x")
106105
.to_owned(),
107106
signed_receipt
108107
.recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR)
109108
.unwrap()
110109
.to_string()
111-
.strip_prefix("0x")
112-
.unwrap()
110+
.trim_start_matches("0x")
113111
.to_owned(),
114112
BigDecimal::from(signed_receipt.message.timestamp_ns),
115113
BigDecimal::from_str(&signed_receipt.message.value.to_string())?,
@@ -135,10 +133,9 @@ pub async fn store_rav(pgpool: &PgPool, signed_rav: SignedRAV, sender: Address)
135133
.message
136134
.allocation_id
137135
.to_string()
138-
.strip_prefix("0x")
139-
.unwrap()
136+
.trim_start_matches("0x")
140137
.to_owned(),
141-
sender.to_string().strip_prefix("0x").unwrap().to_owned(),
138+
sender.to_string().trim_start_matches("0x").to_owned(),
142139
serde_json::to_value(signed_rav).unwrap(),
143140
)
144141
.execute(pgpool)

0 commit comments

Comments
 (0)