Last active
August 27, 2024 19:27
-
-
Save jac18281828/cc925b6642ce087f21af28202db28cfd to your computer and use it in GitHub Desktop.
Alloy working with struct ABI data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use eyre::Result; | |
use tracing::debug; | |
use serde::{Serialize, Deserialize}; | |
use alloy::{ | |
primitives::{Address, U256, B256}, | |
sol, | |
}; | |
use IRewardsCoordinator::RewardsClaimed; | |
sol!( | |
#[sol(rpc)] #[derive(Debug, Serialize, Deserialize)] | |
IRewardsCoordinator, | |
"abi/IRewardsCoordinator.json" | |
); | |
#[tokio::main] | |
async fn main() -> Result<()> { | |
init_logging(); | |
let claimed_event = RewardsClaimed{ | |
root: B256::from([0; 32]), | |
earner: Address::from([0; 20]), | |
claimer: Address::from([0; 20]), | |
recipient: Address::from([0; 20]), | |
token: Address::from([0; 20]), | |
claimedAmount: U256::from(0), | |
}; | |
let binary_code = bincode::serialize(&claimed_event)?; | |
let hex_str = hex::encode(&binary_code); | |
debug!("{:?}", claimed_event); | |
debug!("{:?}", hex_str); | |
Ok(()) | |
} | |
fn init_logging() { | |
tracing_subscriber::FmtSubscriber::builder() | |
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | |
.with_max_level(tracing::Level::DEBUG) | |
.try_init() | |
.expect("setting default subscriber failed"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment