Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Issue (strict-types 1.3.0) #253

Merged
merged 21 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ BITCOIN_EXPLORER_API_REGTEST=http://localhost:3000/regtest/api
# BITCOIN_ELECTRUM_API_SIGNET=mempool.space:60601
LNDHUB_ENDPOINT=https://lndhubx.bitmask.app
# CARBONADO_ENDPOINT=https://qvijq4x0ei.execute-api.us-east-2.amazonaws.com/dev/carbonado
BITMASK_ENDPOINT=http://localhost:7071
CARBONADO_ENDPOINT=http://localhost:7070/carbonado
BITCOIN_NETWORK=regtest
STRESS_TEST=false
Expand Down
72 changes: 7 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bp-core = "0.10.4"
commit_verify = "0.10.3"
bp-seals = "0.10.4"
indexmap = "1.9.3"
carbonado = "0.3.0-rc.13"
carbonado = "0.3.1"
console_error_panic_hook = "0.1.7"
# directories = "4.0.1"
miniscript_crate = { package = "miniscript", version = "9.0.1", features = [
Expand Down
27 changes: 21 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ version: "3.7"
networks:
bmnet:
driver: bridge
# ipam:
# config:
# - subnet: 172.21.0.0/24
# gateway: 172.21.0.1

volumes:
node1_data:
Expand All @@ -32,13 +28,14 @@ services:
aliases:
- node1

# Bitmaskd 0.6.0-rc.2
bitmaskd:
container_name: bitmaskd
image: bitmask/server:latest
image: bitmask/node:latest
platform: linux/amd64
build:
context: ./
dockerfile: ./docker/bitmask/Dockerfile
dockerfile: ./docker/bitmask/Dockerfile.ST120
restart: unless-stopped
environment:
- BITCOIN_NETWORK=regtest
Expand All @@ -49,3 +46,21 @@ services:
bmnet:
aliases:
- bitmaskd

carbonado:
container_name: carbonado
image: carbonado/node:latest
platform: linux/amd64
build:
context: ./
dockerfile: ./docker/bitmask/Dockerfile
restart: unless-stopped
environment:
- BITCOIN_NETWORK=regtest
- BITCOIN_EXPLORER_API_REGTEST=http://node1:80/regtest/api
ports:
- 7071:7070
networks:
bmnet:
aliases:
- bitmaskd
4 changes: 2 additions & 2 deletions docker/bitmask/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder
FROM rust:slim AS builder
FROM rust:slim-buster AS builder
ARG BUILDER_DIR=/srv/bitmask
ARG BUILDER_SRC=/opt/src/bitmask

Expand All @@ -13,7 +13,7 @@ COPY . .
RUN cargo install --locked --features server --path . --root ${BUILDER_DIR}

# Runtime
FROM rust:slim AS runtime
FROM rust:slim-buster AS runtime

ARG BUILDER_DIR=/srv/bitmask
ARG BIN_DIR=/usr/local/bin
Expand Down
39 changes: 39 additions & 0 deletions docker/bitmask/Dockerfile.ST120
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Builder
FROM rust:slim-buster AS builder
ARG BUILDER_DIR=/srv/bitmask
ARG BUILDER_SRC=/opt/src/bitmask
ARG SOURCE_CODE=https://github.com/diba-io/bitmask-core.git
ARG VERSION=c18cba0375dbc4c2f2a5a4fe56401bf3d6d52ce7

RUN apt-get update -y && \
apt-get install -y pkg-config make g++ libssl-dev git

WORKDIR $BUILDER_DIR
WORKDIR $BUILDER_SRC
RUN git clone $SOURCE_CODE $BUILDER_SRC
RUN git checkout $VERSION
RUN cargo install --locked --features server --path . --root ${BUILDER_DIR}

# Runtime
FROM rust:slim-buster AS runtime

ARG BUILDER_DIR=/srv/bitmask
ARG BIN_DIR=/usr/local/bin
ARG DATA_DIR=/tmp/bitmaskd/carbonado/
ARG USER=bitmask

RUN apt-get update -y && apt-get install -y iputils-ping telnet \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN adduser --home "${DATA_DIR}" --shell /bin/bash --disabled-login \
--gecos "${USER} user" ${USER}

COPY --from=builder --chown=${USER}:${USER} \
"${BUILDER_DIR}/bin/" "${BIN_DIR}"

USER ${USER}
VOLUME ${DATA_DIR}
EXPOSE 7070

WORKDIR ${BIN_DIR}
ENTRYPOINT ["bitmaskd"]
72 changes: 63 additions & 9 deletions src/bin/bitmaskd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![cfg(not(target_arch = "wasm32"))]
use std::{env, fs::OpenOptions, io::ErrorKind, net::SocketAddr, str::FromStr};

use amplify::hex::ToHex;
use anyhow::Result;
use axum::{
body::Bytes,
Expand All @@ -16,18 +17,19 @@ use axum::{
use bitcoin_30::secp256k1::{ecdh::SharedSecret, PublicKey, SecretKey};
use bitmask_core::{
bitcoin::{decrypt_wallet, get_wallet_data, save_mnemonic, sign_psbt_file},
carbonado::handle_file,
carbonado::{handle_file, retrieve, retrieve_metadata},
constants::{get_marketplace_seed, get_network, get_udas_utxo, switch_network},
rgb::{
accept_transfer, clear_watcher as rgb_clear_watcher, create_invoice, create_psbt,
create_watcher, import as rgb_import, issue_contract, list_contracts, list_interfaces,
list_schemas, transfer_asset, watcher_address, watcher_details as rgb_watcher_details,
watcher_next_address, watcher_next_utxo, watcher_utxo,
list_schemas, reissue_contract, transfer_asset, watcher_address,
watcher_details as rgb_watcher_details, watcher_next_address, watcher_next_utxo,
watcher_utxo,
},
structs::{
AcceptRequest, ImportRequest, InvoiceRequest, IssueAssetRequest, IssueRequest, MediaInfo,
PsbtRequest, RgbTransferRequest, SecretString, SelfIssueRequest, SignPsbtRequest,
WatcherRequest,
AcceptRequest, FileMetadata, ImportRequest, InvoiceRequest, IssueAssetRequest,
IssueRequest, MediaInfo, PsbtRequest, ReIssueRequest, RgbTransferRequest, SecretString,
SelfIssueRequest, SignPsbtRequest, WatcherRequest,
},
};
use carbonado::file;
Expand All @@ -37,11 +39,25 @@ use serde::{Deserialize, Serialize};
use tokio::fs;
use tower_http::cors::CorsLayer;

async fn issue(Json(issue): Json<IssueAssetRequest>) -> Result<impl IntoResponse, AppError> {
info!("POST /issue {issue:?}");
async fn issue(
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
Json(request): Json<IssueRequest>,
) -> Result<impl IntoResponse, AppError> {
info!("POST /issue {request:?}");

let nostr_hex_sk = auth.token();
let issue_res = issue_contract(nostr_hex_sk, request).await?;
Ok((StatusCode::OK, Json(issue_res)))
}

let issue_res = issue_contract(&issue.sk, issue.request).await?;
async fn reissue(
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
Json(request): Json<ReIssueRequest>,
) -> Result<impl IntoResponse, AppError> {
info!("POST /reissue {request:?}");

let nostr_hex_sk = auth.token();
let issue_res = reissue_contract(&nostr_hex_sk, request).await?;
Ok((StatusCode::OK, Json(issue_res)))
}

Expand Down Expand Up @@ -352,6 +368,42 @@ async fn co_retrieve(
}
}

async fn co_metadata(
Path((pk, name)): Path<(String, String)>,
) -> Result<impl IntoResponse, AppError> {
info!("GET /carbonado/{pk}/{name}/metadata");

let filepath = &handle_file(&pk, &name, 0).await?;
let mut metadata = FileMetadata::default();
match OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(&filepath)
{
Ok(file) => {
let present_header = match carbonado::file::Header::try_from(&file) {
Ok(header) => header,
_ => return Ok((StatusCode::OK, Json(metadata))),
};

metadata.filename = present_header.file_name();
metadata.metadata = present_header.metadata.unwrap_or_default();
}
Err(err) => match err.kind() {
ErrorKind::NotFound => {
fs::write(&filepath, &vec![]).await?;
}
_ => {
error!("error in POST /carbonado/{pk}/{name}: {err}");
return Err(err.into());
}
},
}

Ok((StatusCode::OK, Json(metadata)))
}

async fn status() -> Result<impl IntoResponse, AppError> {
let cc = CacheControl::new().with_no_cache();

Expand Down Expand Up @@ -380,6 +432,7 @@ async fn main() -> Result<()> {

let app = Router::new()
.route("/issue", post(issue))
.route("/reissue", post(reissue))
.route("/selfissue", post(self_issue))
.route("/invoice", post(invoice))
// .route("/psbt", post(psbt))
Expand All @@ -405,6 +458,7 @@ async fn main() -> Result<()> {
.route("/carbonado/status", get(status))
.route("/carbonado/:pk/:name", post(co_store))
.route("/carbonado/:pk/:name", get(co_retrieve))
.route("/carbonado/:pk/:name/metadata", get(co_metadata))
.layer(CorsLayer::permissive());

let network = get_network().await;
Expand Down
Loading