Skip to content

Commit 7a8165a

Browse files
authored
feat: Add models and configuration parsing (#258)
* feat: Add network and address models * docs: Add reference in docstring for midnight address * feat: Add relayer, transaction and request draft models * fix: Tests * chore: Add Midnight network config * chore: Add Midnight transaction request and data field * test: Add address tests * chore: Create Midnight Transaction Builder (#267) * chore: Add types and scaffolding for transaction builder * chore: Use generic types for midnight_transaction * chore: Update builder and prover logic * chore: Update builder and prover logic * chore: Add typo * feat: Implement relayer model for Midnight (#321) * feat: Implement relayer model for Midnight * feat: Add wallet sync service (#335) * chore: Add indexer url to network config * feat: Add service sync manager * chore: Implement tx preparation scaffolding * chore: Implement get_balance from relayer service * chore: Replace repo w/ signertrait and clarify sync * feat: Implement relayer submission functionality (#337) * feat: Working implementation for transaction submission * feat: Use sync state repo to allow incremental sync * fix: Comments for token_type * feat: Implement status checker * chore: Upgrade package * feat: Implement signing for midnight * refactor: Replace dyn with EventHandlerType enum
1 parent 242c338 commit 7a8165a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10661
-495
lines changed

Cargo.lock

Lines changed: 3538 additions & 300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 75 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,104 @@ opt-level = 0
1515
overflow-checks = true
1616
panic = "unwind"
1717

18+
[patch."https://github.com/input-output-hk/midnight-ledger-prototype"]
19+
mn-ledger-storage = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-storage", tag = "ledger-4.0.0" }
20+
coin-structure = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-coin-structure", tag = "ledger-4.0.0" }
21+
onchain-runtime = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-onchain-runtime", tag = "ledger-4.0.0" }
22+
midnight-serialize = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", tag = "ledger-4.0.0" }
23+
base-crypto = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-base-crypto", tag = "ledger-4.0.0" }
24+
transient-crypto = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-transient-crypto", tag = "ledger-4.0.0" }
25+
1826
[dependencies]
19-
actix-web = "4"
20-
log = "0.4"
21-
simplelog = "0.12"
22-
prometheus = "0.13"
23-
lazy_static = "1.5"
24-
dotenvy = "0.15"
25-
thiserror = "2"
26-
async-trait = "0.1"
27+
actix-governor = "0.8"
2728
actix-rt = "2.0.0"
29+
actix-web = "4"
2830
alloy = { version = "0.9", features = ["full"] }
29-
serde_json = "1"
30-
strum = { version = "0.27", default-features = false, features = ["derive"] }
31-
strum_macros = "0.27"
32-
serde = { version = "1.0", features = ["derive", "alloc"] }
33-
num_enum = { version = "0.7", default-features = false }
34-
once_cell = "1.17"
35-
regex = "1"
36-
futures = "0.3"
37-
uuid = { version = "1.11", features = ["v4"] }
31+
apalis = { version = "0.7", features = [
32+
"limit",
33+
"retry",
34+
"catch-panic",
35+
"timeout",
36+
] }
37+
apalis-cron = { version = "0.7" }
38+
apalis-redis = { version = "0.7" }
39+
async-trait = "0.1"
40+
backoff = { version = "0.4.0", features = ["tokio"] }
41+
base64 = { version = "0.22" }
42+
bech32 = "0.11.0"
43+
bincode = { version = "1.3.3" }
44+
bs58 = "0.5"
45+
bytes = { version = "1.9" }
3846
chrono = "0.4"
39-
eyre = "0.6"
4047
color-eyre = "0.6"
41-
apalis = { version = "0.7", features = ["limit", "retry", "catch-panic", "timeout"] }
42-
apalis-redis = { version = "0.7" }
43-
apalis-cron = { version = "0.7" }
44-
redis = { version = "0.31" }
45-
tokio = { version = "1.43", features = ["sync", "io-util", "time"] }
46-
rand = "0.9"
48+
dashmap = { version = "6.1" }
49+
dotenvy = "0.15"
50+
ed25519-dalek = "2.1"
51+
eyre = "0.6"
52+
futures = "0.3"
53+
futures-util = "0.3"
54+
google-cloud-auth = "0.20.0"
55+
governor = "0.8.0"
56+
hex = { version = "0.4" }
57+
hmac = { version = "0.12" }
58+
http = { version = "1.3.1" }
59+
itertools = "0.12.0" # Required by midnight
60+
k256 = { version = "0.13" }
61+
lazy_static = "1.5"
62+
libsodium-sys = "0.2.7"
63+
log = "0.4"
64+
midnight-ledger-prototype = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-ledger", tag = "ledger-4.0.0" }
65+
midnight-node-ledger-helpers = { git = "https://github.com/midnightntwrk/midnight-node", package = "midnight-node-ledger-helpers", tag = "node-0.12.0" }
66+
midnight-node-res = { git = "https://github.com/midnightntwrk/midnight-node", package = "midnight-node-res", tag = "node-0.12.0" }
67+
mpl-token-metadata = { version = "5.1" }
68+
num_enum = { version = "0.7", default-features = false }
69+
once_cell = "1.17"
70+
oz-keystore = { version = "0.1.4" }
71+
p256 = { version = "0.13.2" }
4772
parking_lot = "0.12"
48-
tower = "0.5"
49-
oz-keystore = { version = "0.1.4"}
50-
hex = { version = "0.4"}
51-
bytes = { version = "1.9" }
73+
pem = { version = "3" }
74+
prometheus = "0.13"
75+
rand = "0.9"
76+
redis = { version = "0.31" }
77+
regex = "1"
5278
reqwest = { version = "0.12", features = ["json"] }
53-
base64 = { version = "0.22" }
54-
hmac = { version = "0.12" }
79+
secrets = { version = "1.2" }
80+
serde = { version = "1.0", features = ["derive", "alloc"] }
81+
serde_json = "1"
5582
sha2 = { version = "0.10" }
56-
dashmap = { version = "6.1" }
57-
actix-governor = "0.8"
58-
solana-sdk = { version = "2.2" }
83+
simple_asn1 = { version = "0.6" }
84+
simplelog = "0.12"
5985
solana-client = { version = "2.2" }
86+
solana-sdk = { version = "2.2" }
87+
soroban-rs = "0.2.4"
88+
spl-associated-token-account = "6.0.0"
6089
spl-token = { version = "8" }
6190
spl-token-2022 = { version = "8" }
62-
mpl-token-metadata = { version = "5.1" }
91+
stellar-strkey = "0.0.12"
92+
strum = { version = "0.27", default-features = false, features = ["derive"] }
93+
strum_macros = "0.27"
94+
subtle = "2.6"
95+
subxt = { version = "0.37.0", features = ["substrate-compat"] }
6396
sysinfo = "0.35"
64-
bincode = { version = "1.3" }
65-
bs58 = "0.5"
66-
spl-associated-token-account = "6.0.0"
67-
itertools = "0.14.0"
97+
thiserror = "2"
98+
tokio = { version = "1.43", features = ["sync", "io-util", "time"] }
99+
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
100+
tower = "0.5"
101+
utoipa = { version = "5.3", features = ["actix_extras"] }
102+
uuid = { version = "1.11", features = ["v4"] }
68103
validator = { version = "0.20", features = ["derive"] }
69104
vaultrs = { version = "0.7.4" }
70-
utoipa = { version = "5.3", features = ["actix_extras"] }
71-
secrets = { version = "1.2"}
72-
libsodium-sys = "0.2.7"
73105
zeroize = "1.8"
74-
subtle = "2.6"
75-
ed25519-dalek = "2.1"
76-
stellar-strkey = "0.0.12"
77-
soroban-rs = "0.2.4"
78-
p256 = { version = "0.13.2" }
79-
google-cloud-auth = "0.20.0"
80-
http = { version = "1.3.1" }
81-
pem = { version = "3" }
82-
simple_asn1 = { version = "0.6" }
83-
k256 = { version = "0.13" }
84106

85107
[dev-dependencies]
86108
cargo-llvm-cov = "0.6"
109+
clap = { version = "4.4", features = ["derive"] }
87110
mockall = { version = "0.13" }
88111
mockito = "1.6.1"
89112
proptest = "1.6.0"
90113
rand = "0.9.0"
91-
tempfile = "3.2"
92114
serial_test = "3.2"
93-
clap = { version = "4.4", features = ["derive"] }
115+
tempfile = "3.2"
94116
wiremock = "0.6"
95117

96118
[[bin]]

config/networks/midnight.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"networks": [
3+
{
4+
"type": "midnight",
5+
"network": "testnet",
6+
"rpc_urls": [
7+
"wss://rpc.testnet-02.midnight.network/"
8+
],
9+
"explorer_urls": [
10+
"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.testnet-02.midnight.network#/explorer"
11+
],
12+
"indexer_urls": {
13+
"ws": "wss://indexer.testnet-02.midnight.network/api/v1/graphql/ws",
14+
"http": "https://indexer.testnet-02.midnight.network/api/v1/graphql"
15+
},
16+
"prover_url": "http://localhost:6300",
17+
"average_blocktime_ms": 6000,
18+
"is_testnet": true
19+
}
20+
]
21+
}

src/api/routes/relayer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ mod tests {
191191
jobs::{JobProducer, Queue},
192192
repositories::{
193193
InMemoryNetworkRepository, InMemoryNotificationRepository, InMemoryRelayerRepository,
194-
InMemorySignerRepository, InMemoryTransactionCounter, InMemoryTransactionRepository,
195-
RelayerRepositoryStorage,
194+
InMemorySignerRepository, InMemorySyncState, InMemoryTransactionCounter,
195+
InMemoryTransactionRepository, RelayerRepositoryStorage,
196196
},
197197
};
198198
use actix_web::{http::StatusCode, test, App};
@@ -209,6 +209,7 @@ mod tests {
209209
notification_repository: Arc::new(InMemoryNotificationRepository::new()),
210210
network_repository: Arc::new(InMemoryNetworkRepository::new()),
211211
transaction_counter_store: Arc::new(InMemoryTransactionCounter::new()),
212+
sync_state_store: Arc::new(InMemorySyncState::new()),
212213
job_producer: Arc::new(JobProducer::new(Queue::setup().await.unwrap())),
213214
}
214215
}

src/bootstrap/config_processor.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ async fn process_relayers<J: JobProducerTrait>(
301301
.find(|s| s.id == repo_model.signer_id)
302302
.ok_or_else(|| eyre::eyre!("Signer not found"))?;
303303
let network_type = repo_model.network_type;
304-
let signer_service = SignerFactory::create_signer(&network_type, signer_model)
305-
.wrap_err("Failed to create signer service")?;
304+
let signer_service =
305+
SignerFactory::create_signer(&network_type, signer_model, &repo_model.network)
306+
.wrap_err("Failed to create signer service")?;
306307

307308
let address = signer_service.address().await?;
308309
repo_model.address = address.to_string();
@@ -353,8 +354,8 @@ mod tests {
353354
models::{NetworkType, PlainOrEnvValue, SecretString},
354355
repositories::{
355356
InMemoryNetworkRepository, InMemoryNotificationRepository, InMemoryRelayerRepository,
356-
InMemorySignerRepository, InMemoryTransactionCounter, InMemoryTransactionRepository,
357-
RelayerRepositoryStorage,
357+
InMemorySignerRepository, InMemorySyncState, InMemoryTransactionCounter,
358+
InMemoryTransactionRepository, RelayerRepositoryStorage,
358359
},
359360
};
360361
use serde_json::json;
@@ -392,6 +393,7 @@ mod tests {
392393
notification_repository: Arc::new(InMemoryNotificationRepository::default()),
393394
network_repository: Arc::new(InMemoryNetworkRepository::default()),
394395
transaction_counter_store: Arc::new(InMemoryTransactionCounter::default()),
396+
sync_state_store: Arc::new(InMemorySyncState::default()),
395397
job_producer: Arc::new(mock_job_producer),
396398
}
397399
}
@@ -994,6 +996,7 @@ mod tests {
994996
let network_repo = Arc::new(InMemoryNetworkRepository::default());
995997
let transaction_repo = Arc::new(InMemoryTransactionRepository::default());
996998
let transaction_counter = Arc::new(InMemoryTransactionCounter::default());
999+
let sync_state_store = Arc::new(InMemorySyncState::default());
9971000

9981001
// Create a mock job producer
9991002
let mut mock_job_producer = MockJobProducerTrait::new();
@@ -1019,6 +1022,7 @@ mod tests {
10191022
network_repository: network_repo.clone(),
10201023
transaction_repository: transaction_repo.clone(),
10211024
transaction_counter_store: transaction_counter.clone(),
1025+
sync_state_store: sync_state_store.clone(),
10221026
job_producer: job_producer.clone(),
10231027
});
10241028

src/bootstrap/initialize_app_state.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
models::{AppState, DefaultAppState},
88
repositories::{
99
InMemoryNetworkRepository, InMemoryNotificationRepository, InMemoryRelayerRepository,
10-
InMemorySignerRepository, InMemoryTransactionCounter, InMemoryTransactionRepository,
11-
RelayerRepositoryStorage,
10+
InMemorySignerRepository, InMemorySyncState, InMemoryTransactionCounter,
11+
InMemoryTransactionRepository, RelayerRepositoryStorage,
1212
},
1313
};
1414
use actix_web::web;
@@ -35,6 +35,7 @@ pub async fn initialize_app_state() -> Result<web::ThinData<DefaultAppState>> {
3535
let notification_repository = Arc::new(InMemoryNotificationRepository::new());
3636
let network_repository = Arc::new(InMemoryNetworkRepository::new());
3737
let transaction_counter_store = Arc::new(InMemoryTransactionCounter::new());
38+
let sync_state_store = Arc::new(InMemorySyncState::new());
3839
let queue = Queue::setup().await?;
3940
let job_producer = Arc::new(jobs::JobProducer::new(queue.clone()));
4041

@@ -45,6 +46,7 @@ pub async fn initialize_app_state() -> Result<web::ThinData<DefaultAppState>> {
4546
notification_repository,
4647
network_repository,
4748
transaction_counter_store,
49+
sync_state_store,
4850
job_producer,
4951
});
5052

src/config/config_file/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub use notification::*;
3939

4040
pub mod network;
4141
pub use network::{
42-
EvmNetworkConfig, NetworkConfigCommon, NetworkFileConfig, NetworksFileConfig,
43-
SolanaNetworkConfig, StellarNetworkConfig,
42+
EvmNetworkConfig, MidnightNetworkConfig, NetworkConfigCommon, NetworkFileConfig,
43+
NetworksFileConfig, SolanaNetworkConfig, StellarNetworkConfig,
4444
};
4545

4646
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
@@ -49,6 +49,7 @@ pub enum ConfigFileNetworkType {
4949
Evm,
5050
Stellar,
5151
Solana,
52+
Midnight,
5253
}
5354

5455
#[derive(Debug, Serialize, Deserialize, Clone)]

0 commit comments

Comments
 (0)