Skip to content

Commit

Permalink
Abstract Signing & Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Nov 21, 2023
1 parent a7a18f0 commit 18f5778
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
2 changes: 0 additions & 2 deletions src/gateway/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 4 additions & 12 deletions src/gateway/signing.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
53 changes: 33 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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);
3 changes: 3 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use ethers::signers::LocalWallet;

use crate::database::Database;

pub struct GlobalState {
pub db: Database,
pub wallet: LocalWallet,
}

0 comments on commit 18f5778

Please sign in to comment.