Skip to content

Commit fb1b832

Browse files
committed
Add -oceanarchive flag
1 parent 7623811 commit fb1b832

17 files changed

Lines changed: 79 additions & 40 deletions

File tree

lib/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,6 @@ substrate-bn = "0.6"
120120
#### Ocean dependencies
121121
dftx-rs = { git = "https://github.com/Jouzo/dftx-rs.git" }
122122
bitcoin = "0.31"
123+
124+
### Local crates
125+
ain-cpp-imports = { path = "./ain-cpp-imports" }

lib/ain-cpp-imports/src/bridge.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ pub mod ffi {
5555
fn getEvmValidationLruCacheCount() -> usize;
5656
fn isEthDebugRPCEnabled() -> bool;
5757
fn isEthDebugTraceRPCEnabled() -> bool;
58+
fn isOceanEnabled() -> bool;
5859
}
5960
}

lib/ain-cpp-imports/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,10 @@ pub fn is_eth_debug_trace_rpc_enabled() -> bool {
278278
ffi::isEthDebugTraceRPCEnabled()
279279
}
280280

281+
/// Checks if Ocean REST API is enabled
282+
pub fn is_ocean_rest_enabled() -> bool {
283+
ffi::isOceanEnabled()
284+
}
285+
281286
#[cfg(test)]
282287
mod tests {}

lib/ain-evm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ain-cpp-imports = { path = "../ain-cpp-imports" }
7+
ain-cpp-imports.workspace = true
88
ain-contracts = { path = "../ain-contracts" }
99

1010
evm = { workspace = true, default-features = false, features = ["with-serde", "tracing", "std"] }

lib/ain-grpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build = "build.rs"
66

77
[dependencies]
88
ain-evm = { path = "../ain-evm" }
9-
ain-cpp-imports = { path = "../ain-cpp-imports" }
9+
ain-cpp-imports.workspace = true
1010
ain-ocean = { path = "../ain-ocean" }
1111
cxx.workspace = true
1212
env_logger.workspace = true

lib/ain-ocean/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
ain-cpp-imports.workspace = true
10+
911
axum.workspace = true
1012
hyper.workspace = true
1113
keccak-hash.workspace = true

lib/ain-ocean/src/api/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use axum::Router;
1+
use axum::{http::StatusCode, response::IntoResponse, Router};
22

33
mod address;
44
mod block;
@@ -13,8 +13,17 @@ mod rawtx;
1313
mod stats;
1414
mod tokens;
1515
mod transactions;
16+
use axum::routing::get;
17+
18+
async fn ocean_not_activated() -> impl IntoResponse {
19+
(StatusCode::FORBIDDEN, "Ocean is not activated")
20+
}
1621

1722
pub fn ocean_router() -> Router {
23+
if !ain_cpp_imports::is_ocean_rest_enabled() {
24+
return Router::new().route("/*path", get(ocean_not_activated));
25+
}
26+
1827
Router::new()
1928
.nest("/address", address::router())
2029
.nest("/governance", governance::router())

lib/ain-ocean/src/indexer/masternode.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ impl Index for CreateMasternode {
3333
history: None,
3434
};
3535

36-
let mut file = std::fs::OpenOptions::new()
37-
.write(true)
38-
.create(true)
39-
.append(true)
40-
.open("/tmp/masternode")
41-
.expect("Unable to open file");
42-
43-
writeln!(file, "{:?}", masternode).expect("Unable to write to file");
44-
4536
Ok(())
4637
}
4738

lib/ain-ocean/src/indexer/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) trait Index {
1414

1515
use bitcoin::BlockHash;
1616
use dftx_rs::{deserialize, Block, DfTx};
17+
use log::debug;
1718

1819
pub(crate) struct BlockContext {
1920
height: u32,
@@ -23,6 +24,8 @@ pub(crate) struct BlockContext {
2324
}
2425

2526
pub fn index_block(block: String, block_height: u32) -> Result<()> {
27+
debug!("[index_block] Indexing block...");
28+
2629
let hex = hex::decode(block)?;
2730
let block = deserialize::<Block>(&hex)?;
2831

@@ -49,22 +52,22 @@ pub fn index_block(block: String, block_height: u32) -> Result<()> {
4952

5053
match dftx {
5154
DfTx::CreateMasternode(data) => data.index(&context, tx)?,
52-
DfTx::UpdateMasternode(data) => data.index(&context, tx)?,
53-
DfTx::ResignMasternode(data) => data.index(&context, tx)?,
54-
DfTx::AppointOracle(data) => data.index(&context, tx)?,
55-
DfTx::RemoveOracle(data) => data.index(&context, tx)?,
56-
DfTx::UpdateOracle(data) => data.index(&context, tx)?,
57-
DfTx::SetOracleData(data) => data.index(&context, tx)?,
58-
DfTx::PoolSwap(data) => data.index(&context, tx)?,
59-
DfTx::CompositeSwap(data) => data.index(&context, tx)?,
60-
DfTx::PlaceAuctionBid(data) => data.index(&context, tx)?,
55+
// DfTx::UpdateMasternode(data) => data.index(&context, tx)?,
56+
// DfTx::ResignMasternode(data) => data.index(&context, tx)?,
57+
// DfTx::AppointOracle(data) => data.index(&context, tx)?,
58+
// DfTx::RemoveOracle(data) => data.index(&context, tx)?,
59+
// DfTx::UpdateOracle(data) => data.index(&context, tx)?,
60+
// DfTx::SetOracleData(data) => data.index(&context, tx)?,
61+
// DfTx::PoolSwap(data) => data.index(&context, tx)?,
62+
// DfTx::CompositeSwap(data) => data.index(&context, tx)?,
63+
// DfTx::PlaceAuctionBid(data) => data.index(&context, tx)?,
6164
_ => (),
6265
}
6366
}
6467
}
6568
Ok(())
6669
}
6770

68-
pub fn invalidate_block() {
69-
todo!()
71+
pub fn invalidate_block(block: String, block_height: u32) -> Result<()> {
72+
Ok(())
7073
}

0 commit comments

Comments
 (0)