Skip to content

Commit

Permalink
chore: 1. add CORS layer; 2. fix UTXO api
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Dec 27, 2023
1 parent 30db587 commit efdf6c0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# ns-rs
# ns-rs

Rust implementation of NS-Protocol (Name & Service Protocol) by the LDC Labs
2 changes: 2 additions & 0 deletions crates/ns-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_json = { workspace = true }
log = { workspace = true }
structured-logger = { workspace = true }
futures = { workspace = true }
http = "1"
axum = { version = "0.7", features = [
"http1",
"http2",
Expand Down Expand Up @@ -59,6 +60,7 @@ tower-http = { version = "0.5", features = [
"decompression-gzip",
"decompression-zstd",
"propagate-header",
"cors",
] }
validator = { version = "0.16", features = ["derive"] }

Expand Down
6 changes: 4 additions & 2 deletions crates/ns-indexer/src/api/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ impl UtxoAPI {
for spent in &utxo.1 {
utxos.remove(&(&spent.txid, spent.vout));
}
for (_, unspent) in &utxo.2 {
utxos.insert((&unspent.txid, unspent.vout), unspent.clone());
for (addr, unspent) in &utxo.2 {
if addr == &address {
utxos.insert((&unspent.txid, unspent.vout), unspent.clone());
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/ns-indexer/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tower::ServiceBuilder;
use tower_http::{
catch_panic::CatchPanicLayer,
compression::{predicate::SizeAbove, CompressionLayer},
cors::CorsLayer,
};

use ns_axum_web::context;
Expand All @@ -15,6 +16,7 @@ pub fn new(state: Arc<api::IndexerAPI>) -> Router {
let mds = ServiceBuilder::new()
.layer(CatchPanicLayer::new())
.layer(middleware::from_fn(context::middleware))
.layer(CorsLayer::very_permissive())
.layer(CompressionLayer::new().compress_when(SizeAbove::new(encoding::MIN_ENCODING_SIZE)));

Router::new()
Expand Down

0 comments on commit efdf6c0

Please sign in to comment.