Skip to content

Commit

Permalink
use Option<String> type for kind across the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmel committed Oct 3, 2024
1 parent d93b683 commit da65b15
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions sqlite_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct RunTxRow {
end_timestamp: usize,
block_number: u64,
gas_used: String,
kind: String,
kind: Option<String>,
}

impl RunTxRow {
Expand Down Expand Up @@ -275,7 +275,7 @@ impl DbOps for SqliteDb {
tx.end_timestamp,
tx.block_number,
tx.gas_used.to_string(),
tx.kind,
tx.kind.to_owned().unwrap_or("NULL".to_string()),
)
});
pool.execute_batch(&format!(
Expand Down Expand Up @@ -365,15 +365,15 @@ mod tests {
end_timestamp: 200,
block_number: 1,
gas_used: 100,
kind: "test".to_string(),
kind: Some("test".to_string()),
},
RunTx {
tx_hash: TxHash::from_slice(&[1u8; 32]),
start_timestamp: 200,
end_timestamp: 300,
block_number: 2,
gas_used: 200,
kind: "test".to_string(),
kind: Some("test".to_string()),
},
];
db.insert_run_txs(run_id as u64, run_txs).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct RunTx {
pub end_timestamp: usize,
pub block_number: u64,
pub gas_used: u128,
pub kind: String,
pub kind: Option<String>,
}

pub trait DbOps {
Expand Down
3 changes: 1 addition & 2 deletions src/spammer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl OnTxSent for LogCallback {
let kind = extra
.as_ref()
.map(|e| e.get("kind").map(|k| k.to_string()))
.flatten()
.unwrap_or("".to_string());
.flatten();
let handle = tokio::task::spawn(async move {
let res = PendingTransactionBuilder::from_config(&rpc, tx_response);
let tx_hash = res.tx_hash();
Expand Down
8 changes: 4 additions & 4 deletions src/spammer/tx_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum TxActorMessage {
SentRunTx {
tx_hash: TxHash,
start_timestamp: usize,
kind: String,
kind: Option<String>,
on_receipt: oneshot::Sender<()>,
},
FlushCache {
Expand All @@ -37,11 +37,11 @@ where
pub struct PendingRunTx {
tx_hash: TxHash,
start_timestamp: usize,
kind: String,
kind: Option<String>,
}

impl PendingRunTx {
pub fn new(tx_hash: TxHash, start_timestamp: usize, kind: String) -> Self {
pub fn new(tx_hash: TxHash, start_timestamp: usize, kind: Option<String>) -> Self {
Self {
tx_hash,
start_timestamp,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl TxActorHandle {
&self,
tx_hash: TxHash,
start_timestamp: usize,
kind: String,
kind: Option<String>,
) -> Result<(), Box<dyn std::error::Error>> {
let (sender, receiver) = oneshot::channel();
self.sender
Expand Down

0 comments on commit da65b15

Please sign in to comment.