Skip to content

Commit

Permalink
feat(otterscan): use serde_repr to serialize OperationType to int
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa committed Jul 12, 2024
1 parent edbce3a commit 96df6f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ serde = { version = "1.0", default-features = false, features = [
] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
serde_with = "3.3.0"
serde_repr = "0.1"

## misc-testing
arbitrary = "1.3"
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ alloy-serde.workspace = true

serde.workspace = true
serde_json.workspace = true
serde_repr.workspace = true
thiserror.workspace = true

[dev-dependencies]
Expand Down
15 changes: 14 additions & 1 deletion crates/rpc-types-trace/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
use alloy_primitives::{Address, Bloom, Bytes, TxHash, B256, U256};
use alloy_rpc_types_eth::{Block, Header, Rich, Transaction, TransactionReceipt, Withdrawal};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

/// Operation type enum for `InternalOperation` struct
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum OperationType {
/// Operation Transfer
OpTransfer = 0,
Expand Down Expand Up @@ -237,4 +239,15 @@ mod tests {

let _receipt: OtsTransactionReceipt = serde_json::from_str(s).unwrap();
}

#[test]
fn test_otterscan_interal_operation() {
let s = r#"{
"type": 0,
"from": "0xea593b730d745fb5fe01b6d20e6603915252c6bf",
"to": "0xcc3d455481967dc97346ef1771a112d7a14c8f12",
"value": "0xee846f9305c00"
}"#;
let _op: InternalOperation = serde_json::from_str(s).unwrap();
}
}

0 comments on commit 96df6f4

Please sign in to comment.