Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Oct 20, 2024
1 parent f1926fe commit b425ed5
Showing 14 changed files with 80 additions and 135 deletions.
12 changes: 6 additions & 6 deletions kubernetes/cronjob.yml
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: cronjob-service-account
namespace: ar-base-sepolia
namespace: email-tx-auth
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: ar-base-sepolia
namespace: email-tx-auth
name: deployment-restart-role
rules:
- apiGroups: ["apps", "extensions"]
@@ -18,11 +18,11 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: deployment-restart-rolebinding
namespace: ar-base-sepolia
namespace: email-tx-auth
subjects:
- kind: ServiceAccount
name: cronjob-service-account
namespace: ar-base-sepolia
namespace: email-tx-auth
roleRef:
kind: Role
name: deployment-restart-role
@@ -32,7 +32,7 @@ apiVersion: batch/v1
kind: CronJob
metadata:
name: restart-deployment
namespace: ar-base-sepolia
namespace: email-tx-auth
spec:
schedule: "0 * * * *"
jobTemplate:
@@ -47,5 +47,5 @@ spec:
- /bin/sh
- -c
- |
kubectl rollout restart deployment relayer-email-auth --namespace ar-base-sepolia
kubectl rollout restart deployment relayer-imap --namespace email-tx-auth
restartPolicy: OnFailure
10 changes: 5 additions & 5 deletions kubernetes/ingress.yml
Original file line number Diff line number Diff line change
@@ -2,20 +2,20 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: managed-cert-ingress-email-auth
namespace: ar-base-sepolia
namespace: email-tx-auth
annotations:
kubernetes.io/ingress.global-static-ip-name: k8s-email-auth-ip
networking.gke.io/managed-certificates: managed-cert-email-auth
kubernetes.io/ingress.global-static-ip-name: generic-relayer
networking.gke.io/managed-certificates: managed-cert-email-tx-auth
ingressClassName: "gce"
spec:
rules:
- host: auth.prove.email
- host: relayer.zk.email
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: relayer-svc-email-auth
name: relayer-svc-email-tx-auth
port:
number: 443
6 changes: 3 additions & 3 deletions kubernetes/managed-cert.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: managed-cert-email-auth
namespace: ar-base-sepolia
name: managed-cert-email-tx-auth
namespace: email-tx-auth
spec:
domains:
- auth.prove.email
- relayer.zk.email
73 changes: 24 additions & 49 deletions kubernetes/relayer.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: relayer-config-email-auth
namespace: ar-base-sepolia
labels:
app: relayer
data:
EMAIL_ACCOUNT_RECOVERY_VERSION_ID: ""
CHAIN_RPC_PROVIDER: ""
CHAIN_RPC_EXPLORER: ""
CHAIN_ID: ""
WEB_SERVER_ADDRESS: ""
REGEX_JSON_DIR_PATH: ""
EMAIL_TEMPLATES_PATH: ""
CANISTER_ID: ""
IC_REPLICA_URL: ""
JSON_LOGGER: ""
PEM_PATH: ""
SMTP_SERVER: ""

---
apiVersion: v1
kind: Secret
metadata:
name: relayer-secret-email-auth
namespace: ar-base-sepolia
name: relayer-secret-email-tx-auth
namespace: email-tx-auth
labels:
app: relayer
type: Opaque
data:
PRIVATE_KEY:
DATABASE_URL:
PROVER_ADDRESS:
ICPEM:
config.json: |-
---
apiVersion: v1
kind: Secret
metadata:
name: relayer-smtp-secret
namespace: ar-base-sepolia
namespace: email-tx-auth
labels:
app: relayer
type: Opaque
@@ -56,7 +32,7 @@ apiVersion: v1
kind: Secret
metadata:
name: relayer-imap-secret
namespace: ar-base-sepolia
namespace: email-tx-auth
labels:
app: relayer
type: Opaque
@@ -74,8 +50,8 @@ data:
apiVersion: apps/v1
kind: Deployment
metadata:
name: relayer-email-auth
namespace: ar-base-sepolia
name: relayer-email-tx-auth
namespace: email-tx-auth
labels:
app: relayer
spec:
@@ -89,46 +65,45 @@ spec:
spec:
containers:
- name: relayer-container
image: bisht13/ar-relayer-base-3:latest
image: bisht13/generic-relayer-1:latest
ports:
- containerPort: 4500
envFrom:
- configMapRef:
name: relayer-config-email-auth
- secretRef:
name: relayer-secret-email-auth
livenessProbe:
httpGet:
path: /api/echo
path: /api/healthz
port: 4500
initialDelaySeconds: 60
periodSeconds: 30
readinessProbe:
httpGet:
path: /api/echo
path: /api/healthz
port: 4500
initialDelaySeconds: 60
periodSeconds: 30
volumeMounts:
- name: pem-volume
mountPath: "/relayer/packages/relayer/.ic.pem"
subPath: ".ic.pem"
- name: secret-volume
mountPath: "/relayer/packages/relayer/config.json"
subPath: "config.json"
- name: smtp-container
image: bisht13/relayer-smtp:latest
ports:
- containerPort: 8080
envFrom:
- secretRef:
name: relayer-smtp-secret
- name: imap-container
image: bisht13/relayer-imap-new:latest
envFrom:
- secretRef:
name: relayer-imap-secret
volumes:
- name: secret-volume
secret:
secretName: relayer-secret-email-tx-auth
items:
- key: config.json
path: config.json
- name: pem-volume
secret:
secretName: relayer-secret-email-auth
secretName: relayer-secret-email-tx-auth
items:
- key: ICPEM
path: ".ic.pem"
@@ -138,7 +113,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: relayer-imap
namespace: ar-base-sepolia
namespace: email-tx-auth
labels:
app: relayer
spec:
@@ -161,8 +136,8 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: relayer-svc-email-auth
namespace: ar-base-sepolia
name: relayer-svc-email-tx-auth
namespace: email-tx-auth
spec:
selector:
app: relayer
@@ -177,7 +152,7 @@ apiVersion: v1
kind: Service
metadata:
name: relayer-smtp-svc
namespace: ar-base-sepolia
namespace: email-tx-auth
spec:
selector:
app: relayer
9 changes: 8 additions & 1 deletion packages/relayer/migrations/20241008135456_init.down.sql
Original file line number Diff line number Diff line change
@@ -2,4 +2,11 @@

DROP TABLE IF EXISTS requests;

DROP TABLE IF EXISTS expected_replies;
DROP TABLE IF EXISTS expected_replies;

DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'status_enum') THEN
DROP TYPE status_enum;
END IF;
END $$;
2 changes: 1 addition & 1 deletion packages/relayer/migrations/20241008135456_init.up.sql
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'status_enum') THEN
CREATE TYPE status_enum AS ENUM ('Request received', 'Processing', 'Completed', 'Failed');
CREATE TYPE status_enum AS ENUM ('Request received', 'Email sent', 'Email response received', 'Proving', 'Performing on chain transaction', 'Finished');
END IF;
END $$;

15 changes: 11 additions & 4 deletions packages/relayer/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{collections::HashMap, time::Duration};

use crate::*;
use abi::{encode, Abi, ParamType, Token, Tokenize};
use abis::{ECDSAOwnedDKIMRegistry, EmailAuth, EmailAuthMsg, EmailProof};
use abi::{Abi, Token, Tokenize};
use abis::{ECDSAOwnedDKIMRegistry, EmailAuthMsg, EmailProof};
use anyhow::anyhow;
use config::ChainConfig;
use ethers::prelude::*;
use ethers::signers::Signer;
use ethers::utils::hex;
use model::RequestModel;
use model::{update_request, RequestModel, RequestStatus};
use rand::Rng;
use relayer_utils::{bytes_to_hex, h160_to_hex, u256_to_hex};
use relayer_utils::{bytes_to_hex, h160_to_hex};
use slog::error;
use statics::SHARED_MUTEX;
use tokio::time::sleep;
@@ -129,6 +129,13 @@ impl ChainClient {
email_auth_msg: EmailAuthMsg,
relayer_state: RelayerState,
) -> Result<()> {
update_request(
&relayer_state.db,
request.id,
RequestStatus::PerformingOnChainTransaction,
)
.await?;

let abi = Abi {
functions: vec![request.email_tx_auth.function_abi.clone()]
.into_iter()
2 changes: 1 addition & 1 deletion packages/relayer/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use ethers::types::{Bytes, U256};
use relayer_utils::{
command_templates, extract_template_vals_from_command, u256_to_bytes32_little,
extract_template_vals_from_command, u256_to_bytes32_little,
};

use crate::{constants::COMMAND_FIELDS, model::RequestModel};
1 change: 0 additions & 1 deletion packages/relayer/src/dkim.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env;

use abis::ECDSAOwnedDKIMRegistry;
use anyhow::anyhow;
4 changes: 4 additions & 0 deletions packages/relayer/src/handler.rs
Original file line number Diff line number Diff line change
@@ -46,8 +46,12 @@ pub async fn submit_handler(
)
})?;

info!(LOG, "Request ID created: {}", uuid);

let command = parse_command_template(&body.command_template, body.command_params);

info!(LOG, "Command: {:?}", command);

let account_code = if body.code_exists_in_email {
let hex_code = field_to_hex(&body.account_code.clone().0);
Some(hex_code.trim_start_matches("0x").to_string())
Loading

0 comments on commit b425ed5

Please sign in to comment.