diff --git a/src/gateway/endpoint.rs b/src/gateway/endpoint.rs index 131e07f..cc4589a 100644 --- a/src/gateway/endpoint.rs +++ b/src/gateway/endpoint.rs @@ -2,11 +2,9 @@ use std::sync::Arc; use axum::{ extract::State, - http::request, response::{IntoResponse, Response}, Json, }; -use tracing::info; use crate::state::GlobalState; diff --git a/src/gateway/signing.rs b/src/gateway/signing.rs index 6ec987d..6c99434 100644 --- a/src/gateway/signing.rs +++ b/src/gateway/signing.rs @@ -1,16 +1,13 @@ -use std::{env, str::FromStr, sync::Arc}; +use std::sync::Arc; use ethers::{ - abi::{Token, AbiEncode}, - signers::LocalWallet, + abi::{AbiEncode, Token}, signers::Signer, types::{H160, U256, U64}, utils::keccak256, }; -use tracing::info; use crate::state::GlobalState; - use super::response::GatewayResponse; pub struct UnsignedPayload { @@ -39,13 +36,8 @@ impl UnsignedPayload { let message_hash = keccak256(encoded); - let wallet: LocalWallet = LocalWallet::from_str(env::var("PRIVATE_KEY").unwrap().as_str()).unwrap(); - - let address = format!("{:?}", wallet.address()); - - info!("Signing with address: {}", address); - - let signature: ethers::types::Signature = wallet.sign_hash(message_hash.into()).unwrap(); + let signature: ethers::types::Signature = + state.wallet.sign_hash(message_hash.into()).unwrap(); let signature_r = signature.r.encode(); let signature_s = signature.s.encode(); diff --git a/src/main.rs b/src/main.rs index 5e6ea37..f0c8385 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,14 @@ +use std::{env, str::FromStr}; + use dotenvy::dotenv; +use ethers::signers::{LocalWallet, Signer}; use tracing::info; -pub mod gateway; +pub mod ccip; pub mod database; +pub mod gateway; mod http; pub mod state; -pub mod ccip; pub mod utils; #[tokio::main] @@ -16,26 +19,36 @@ async fn main() { let db = database::bootstrap().await; - let state = state::GlobalState { db }; + let wallet: LocalWallet = LocalWallet::from_str( + env::var("PRIVATE_KEY") + .expect("Could not find PRIVATE_KEY") + .as_str(), + ) + .unwrap(); + + let address = format!("{:?}", wallet.address()); + info!("Signing with address: {}", address); + + let state = state::GlobalState { db, wallet }; http::serve(state).await; info!("Shutting down"); - - // let mut records = HashMap::new(); - // records.insert( - // "avatar".to_string(), - // Some( - // "https://metadata.ens.domains/goerli/avatar/luc.myeth.id?timestamp=1700508402907" - // .to_string(), - // ), - // ); - // let addresses = HashMap::new(); - // // let h = hex::decode("0123456789ABCDEF0123456789ABCDEF").unwrap(); - // let h = namehash("luc.myeth.id").to_fixed_bytes().to_vec(); - // db.upsert(&h, &records, &addresses).await; - // let r = db - // .get_records(&h, &vec!["avatar", "display", "header"]) - // .await; - // println!("{:?}", r); } + +// let mut records = HashMap::new(); +// records.insert( +// "avatar".to_string(), +// Some( +// "https://metadata.ens.domains/goerli/avatar/luc.myeth.id?timestamp=1700508402907" +// .to_string(), +// ), +// ); +// let addresses = HashMap::new(); +// // let h = hex::decode("0123456789ABCDEF0123456789ABCDEF").unwrap(); +// let h = namehash("luc.myeth.id").to_fixed_bytes().to_vec(); +// db.upsert(&h, &records, &addresses).await; +// let r = db +// .get_records(&h, &vec!["avatar", "display", "header"]) +// .await; +// println!("{:?}", r); diff --git a/src/state.rs b/src/state.rs index a03b3d7..5fb04bc 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,5 +1,8 @@ +use ethers::signers::LocalWallet; + use crate::database::Database; pub struct GlobalState { pub db: Database, + pub wallet: LocalWallet, }