Skip to content

Commit

Permalink
chore: update project structure for crates publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Dec 23, 2023
1 parent b924133 commit 97cfda4
Show file tree
Hide file tree
Showing 31 changed files with 61 additions and 71 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ license = "CC0-1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["crates/internal/*", "crates/ns-*"]
# exclude = ["crates/internal"]
members = ["crates/*"]

[workspace.dependencies]
anyhow = "1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "axum-web"
name = "ns-axum-web"
version = "0.1.0"
edition = "2021"
rust-version = "1.64"
description = ""
description = "axum web middlewares for ns-rs"
publish = false
repository = "https://github.com/ldclabs/ns-rs/crates/internal/axum-web"
repository = "https://github.com/ldclabs/ns-rs/tree/main/crates/ns-axum-web"
license = "CC0-1.0"

[lib]
Expand All @@ -25,6 +25,6 @@ serde = { workspace = true }
serde_json = { workspace = true }
structured-logger = { workspace = true }
tokio = { workspace = true }
scylla = "0.10"
scylla = "0.11"
zstd = "0.12"
validator = { version = "0.16", features = ["derive"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/ns-fetcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "CC0-1.0"
[lib]

[dependencies]
ns-protocol = { path = "../ns-protocol" }
ns-protocol = { path = "../ns-protocol", version = "0.4" }
anyhow = { workspace = true }
bytes = { workspace = true }
base64 = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions crates/ns-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ name = "ns-indexer"
path = "src/bin/main.rs"

[dependencies]
ns-protocol = { path = "../ns-protocol" }
axum-web = { path = "../internal/axum-web" }
scylla-orm = { path = "../internal/scylla-orm" }
scylla-orm-macros = { path = "../internal/scylla-orm-macros" }
ns-protocol = { path = "../ns-protocol", version = "0.4" }
ns-axum-web = { path = "../ns-axum-web", version = "0.1" }
ns-scylla-orm = { path = "../ns-scylla-orm", version = "0.1" }
ns-scylla-orm-macros = { path = "../ns-scylla-orm-macros", version = "0.1" }
anyhow = { workspace = true }
axum = { workspace = true }
bytes = { workspace = true }
Expand All @@ -42,7 +42,7 @@ bitcoin = { version = "0.31", features = ["serde", "base64", "rand"] }
dotenvy = "0.15"
hex = "0.4"
bitcoincore-rpc-json = "0.18.0"
scylla = "0.10"
scylla = "0.11"
tower = "0.4"
tower-http = { version = "0.5", features = [
"catch-panic",
Expand Down
2 changes: 1 addition & 1 deletion crates/ns-indexer/src/api/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
use std::sync::Arc;
use validator::Validate;

use axum_web::{
use ns_axum_web::{
context::ReqContext,
erring::{HTTPError, SuccessResponse},
object::PackObject,
Expand Down
4 changes: 2 additions & 2 deletions crates/ns-indexer/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize};
use std::sync::Arc;
use validator::{Validate, ValidationError};

use axum_web::erring::{HTTPError, SuccessResponse};
use axum_web::object::PackObject;
use ns_axum_web::erring::{HTTPError, SuccessResponse};
use ns_axum_web::object::PackObject;
use ns_protocol::ns;

use crate::db::scylladb::ScyllaDB;
Expand Down
2 changes: 1 addition & 1 deletion crates/ns-indexer/src/api/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
use std::sync::Arc;
use validator::Validate;

use axum_web::{
use ns_axum_web::{
context::ReqContext,
erring::{HTTPError, SuccessResponse},
object::PackObject,
Expand Down
2 changes: 1 addition & 1 deletion crates/ns-indexer/src/api/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
use std::sync::Arc;
use validator::Validate;

use axum_web::{
use ns_axum_web::{
context::ReqContext,
erring::{HTTPError, SuccessResponse},
object::PackObject,
Expand Down
2 changes: 1 addition & 1 deletion crates/ns-indexer/src/api/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bitcoin::{Address, AddressType};
use std::{collections::BTreeMap, str::FromStr, sync::Arc};
use validator::Validate;

use axum_web::{
use ns_axum_web::{
context::ReqContext,
erring::{HTTPError, SuccessResponse},
object::PackObject,
Expand Down
6 changes: 3 additions & 3 deletions crates/ns-indexer/src/db/model_inscription.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_web::erring::HTTPError;
use scylla_orm::{ColumnsMap, CqlValue, ToCqlVal};
use scylla_orm_macros::CqlOrm;
use ns_axum_web::erring::HTTPError;
use ns_scylla_orm::{ColumnsMap, CqlValue, ToCqlVal};
use ns_scylla_orm_macros::CqlOrm;

use ns_protocol::state;

Expand Down
6 changes: 3 additions & 3 deletions crates/ns-indexer/src/db/model_name_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_web::erring::HTTPError;
use scylla_orm::{ColumnsMap, CqlValue, ToCqlVal};
use scylla_orm_macros::CqlOrm;
use ns_axum_web::erring::HTTPError;
use ns_scylla_orm::{ColumnsMap, CqlValue, ToCqlVal};
use ns_scylla_orm_macros::CqlOrm;
use std::collections::{BTreeMap, HashSet};

use ns_protocol::state;
Expand Down
6 changes: 3 additions & 3 deletions crates/ns-indexer/src/db/model_service_protocol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_web::erring::HTTPError;
use scylla_orm::{ColumnsMap, ToCqlVal};
use scylla_orm_macros::CqlOrm;
use ns_axum_web::erring::HTTPError;
use ns_scylla_orm::{ColumnsMap, ToCqlVal};
use ns_scylla_orm_macros::CqlOrm;

use ns_protocol::state;

Expand Down
6 changes: 3 additions & 3 deletions crates/ns-indexer/src/db/model_service_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_web::erring::HTTPError;
use scylla_orm::{ColumnsMap, ToCqlVal};
use scylla_orm_macros::CqlOrm;
use ns_axum_web::erring::HTTPError;
use ns_scylla_orm::{ColumnsMap, ToCqlVal};
use ns_scylla_orm_macros::CqlOrm;

use ns_protocol::state;

Expand Down
4 changes: 2 additions & 2 deletions crates/ns-indexer/src/db/model_utxo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::vec;

use scylla_orm::{ColumnsMap, CqlValue, ToCqlVal};
use scylla_orm_macros::CqlOrm;
use ns_scylla_orm::{ColumnsMap, CqlValue, ToCqlVal};
use ns_scylla_orm_macros::CqlOrm;

use crate::db::scylladb;
use crate::utxo;
Expand Down
8 changes: 4 additions & 4 deletions crates/ns-indexer/src/db/scylladb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use futures::{stream::StreamExt, Stream};
use scylla::{
frame::value::{BatchValues, ValueList},
serialize::{batch::BatchValues, row::SerializeRow},
statement::{Consistency, SerialConsistency},
transport::{
iterator::RowIterator,
Expand Down Expand Up @@ -62,7 +62,7 @@ impl ScyllaDB {
pub async fn execute(
&self,
query: impl Into<Query>,
params: impl ValueList,
params: impl SerializeRow,
) -> anyhow::Result<QueryResult> {
let res = self.session.execute(query, params).await?;
Ok(res)
Expand All @@ -71,7 +71,7 @@ impl ScyllaDB {
pub async fn execute_iter(
&self,
query: impl Into<Query>,
params: impl ValueList,
params: impl SerializeRow,
) -> anyhow::Result<Vec<Row>> {
let mut rows_stream = self.session.execute_iter(query, params).await?;

Expand All @@ -86,7 +86,7 @@ impl ScyllaDB {
pub async fn stream(
&self,
query: impl Into<Query>,
params: impl ValueList,
params: impl SerializeRow,
) -> anyhow::Result<RowIterator> {
let stream = self.session.execute_iter(query, params).await?;
Ok(stream)
Expand Down
4 changes: 2 additions & 2 deletions crates/ns-indexer/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tower_http::{
compression::{predicate::SizeAbove, CompressionLayer},
};

use axum_web::context;
use axum_web::encoding;
use ns_axum_web::context;
use ns_axum_web::encoding;

use crate::api;

Expand Down
4 changes: 2 additions & 2 deletions crates/ns-inscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ name = "ns-inscriber"
path = "src/bin/main.rs"

[dependencies]
ns-protocol = { path = "../ns-protocol" }
ns-indexer = { path = "../ns-indexer" }
ns-protocol = { path = "../ns-protocol", version = "0.4" }
ns-indexer = { path = "../ns-indexer", version = "0.1" }
anyhow = { workspace = true }
bytes = { workspace = true }
base64 = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/ns-inscriber/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ async fn main() -> anyhow::Result<()> {
amount: txout.value,
script_pubkey: txout.script_pubkey.clone(),
}],
None,
)
.await?;

Expand Down
28 changes: 10 additions & 18 deletions crates/ns-inscriber/src/inscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,11 @@ impl Inscriber {
fee_rate: Amount,
secret: &SecretKey,
unspent_txouts: &Vec<UnspentTxOut>,
inscription_keypair: Option<Keypair>, // safe to use one-time KeyPair
) -> anyhow::Result<Txid> {
let keypair = Keypair::from_secret_key(&self.secp, secret);

let (unspent_txout, unsigned_commit_tx, signed_reveal_tx) = self
.build_inscription_transactions(
names,
fee_rate,
unspent_txouts,
Some(inscription_keypair.unwrap_or(keypair)),
)
.build_inscription_transactions(names, fee_rate, unspent_txouts, Some(keypair))
.await?;

let mut signed_commit_tx = unsigned_commit_tx;
Expand Down Expand Up @@ -137,9 +131,13 @@ impl Inscriber {
}

let commit = self.bitcoin.send_transaction(&signed_commit_tx).await?;
let reveal = self.bitcoin.send_transaction(&signed_reveal_tx).await
.map_err(|err| anyhow::anyhow!("failed to send reveal transaction: {err}\ncommit tx {commit} will be recovered once mined"
))?;
let reveal = self
.bitcoin
.send_transaction(&signed_reveal_tx)
.await
.map_err(|err| {
anyhow::anyhow!("failed to send reveal transaction: {err}\ncommit tx: {commit}")
})?;

Ok(reveal)
}
Expand Down Expand Up @@ -704,7 +702,7 @@ mod tests {
let names = vec![get_name("0")];
let fee_rate = Amount::from_sat(20);
let txid = inscriber
.inscribe(&names, fee_rate, &keypair.secret_key(), &unspent_txs, None)
.inscribe(&names, fee_rate, &keypair.secret_key(), &unspent_txs)
.await
.unwrap();
println!("txid: {}", txid);
Expand Down Expand Up @@ -764,13 +762,7 @@ mod tests {
assert_eq!("z", names[35].name);

let txid = inscriber
.inscribe(
&names,
fee_rate,
&keypair.secret_key(),
&unspent_txs,
Some(keypair),
)
.inscribe(&names, fee_rate, &keypair.secret_key(), &unspent_txs)
.await
.unwrap();
println!("txid: {}", txid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "scylla-orm-macros"
name = "ns-scylla-orm-macros"
version = "0.1.0"
edition = "2021"
rust-version = "1.64"
description = ""
publish = false
repository = "https://github.com/ldclabs/ns-rs/crates/internal/scylla-orm-macros"
description = "scylla orm macros for ns-rs"
publish = true
repository = "https://github.com/ldclabs/ns-rs/tree/main/crates/ns-scylla-orm-macros"
license = "CC0-1.0"

[lib]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ pub fn cql_orm(input: TokenStream) -> TokenStream {
]
}

pub fn fill(&mut self, cols: &scylla_orm::ColumnsMap) {
pub fn fill(&mut self, cols: &ColumnsMap) {
#(
if cols.has(#field_names_string1) {
self.#field_names0 = cols.get_as(#field_names_string2).unwrap_or_default();
}
)*
}

pub fn to(&self) -> scylla_orm::ColumnsMap {
let mut cols = scylla_orm::ColumnsMap::with_capacity(#fields_num);
pub fn to(&self) -> ColumnsMap {
let mut cols = ColumnsMap::with_capacity(#fields_num);
#(
cols.set_as(#field_names_string3, &self.#field_names1);
)*
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "scylla-orm"
name = "ns-scylla-orm"
version = "0.1.0"
edition = "2021"
rust-version = "1.64"
description = ""
publish = false
repository = "https://github.com/ldclabs/ns-rs/crates/internal/scylla-orm"
description = "scylla orm for ns-rs"
publish = true
repository = "https://github.com/ldclabs/ns-rs/tree/main/crates/ns-scylla-orm"
license = "CC0-1.0"

[lib]

[dependencies]
anyhow = { workspace = true }
scylla = "0.10"
scylla = "0.11"

[dev-dependencies]
ciborium = { workspace = true }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 97cfda4

Please sign in to comment.