Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds kind to RunTx, and SpamTx Plan #30

Merged
merged 14 commits into from
Oct 4, 2024
Prev Previous commit
Next Next commit
use Option<String> type for kind across the stack
jinmel committed Oct 3, 2024
commit da65b15bfa8ed211b5e0d4ff782500fcc9a062b1
8 changes: 4 additions & 4 deletions sqlite_db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ struct RunTxRow {
end_timestamp: usize,
block_number: u64,
gas_used: String,
kind: String,
kind: Option<String>,
}

impl RunTxRow {
@@ -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!(
@@ -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();
2 changes: 1 addition & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
3 changes: 1 addition & 2 deletions src/spammer/mod.rs
Original file line number Diff line number Diff line change
@@ -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();
8 changes: 4 additions & 4 deletions src/spammer/tx_actor.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ enum TxActorMessage {
SentRunTx {
tx_hash: TxHash,
start_timestamp: usize,
kind: String,
kind: Option<String>,
on_receipt: oneshot::Sender<()>,
},
FlushCache {
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to kind: Option<&str> -- that way the user can call it with Some("kind")

Self {
tx_hash,
start_timestamp,
@@ -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