Skip to content

Commit c66e5e5

Browse files
committed
refactor(tap_agent): trim_start_matches addresses
Signed-off-by: Alexis Asseman <alexis@semiotic.ai>
1 parent 96d0f5b commit c66e5e5

File tree

5 files changed

+22
-61
lines changed

5 files changed

+22
-61
lines changed

common/src/tap_manager.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ impl TapManager {
8686
VALUES ($1, $2, $3, $4, $5)
8787
"#,
8888
format!("{:?}", allocation_id)
89-
.strip_prefix("0x")
90-
.unwrap()
89+
.trim_start_matches("0x")
9190
.to_owned(),
9291
receipt_signer
9392
.to_string()
94-
.strip_prefix("0x")
95-
.unwrap()
93+
.trim_start_matches("0x")
9694
.to_owned(),
9795
BigDecimal::from(receipt.message.timestamp_ns),
9896
BigDecimal::from_str(&receipt.message.value.to_string())?,

tap_agent/src/tap/account.rs

Lines changed: 8 additions & 22 deletions
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?;
@@ -766,10 +754,9 @@ mod tests {
766754
"#,
767755
ALLOCATION_ID
768756
.to_string()
769-
.strip_prefix("0x")
770-
.unwrap()
757+
.trim_start_matches("0x")
771758
.to_owned(),
772-
SENDER.1.to_string().strip_prefix("0x").unwrap().to_owned()
759+
SENDER.1.to_string().trim_start_matches("0x").to_owned()
773760
)
774761
.fetch_optional(&pgpool)
775762
.await
@@ -830,10 +817,9 @@ mod tests {
830817
"#,
831818
ALLOCATION_ID
832819
.to_string()
833-
.strip_prefix("0x")
834-
.unwrap()
820+
.trim_start_matches("0x")
835821
.to_owned(),
836-
SENDER.1.to_string().strip_prefix("0x").unwrap().to_owned()
822+
SENDER.1.to_string().trim_start_matches("0x").to_owned()
837823
)
838824
.fetch_optional(&pgpool)
839825
.await

tap_agent/src/tap/rav_storage_adapter.rs

Lines changed: 4 additions & 14 deletions
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

Lines changed: 4 additions & 14 deletions
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

Lines changed: 4 additions & 7 deletions
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)