Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI

on:
push:
branches: [main]
paths:
- "antd/**"
- "antd-rust/**"
- ".github/workflows/ci.yml"
pull_request:
paths:
- "antd/**"
- "antd-rust/**"
- ".github/workflows/ci.yml"

env:
CARGO_TERM_COLOR: always

jobs:
check:
name: Check (antd)
runs-on: ubuntu-latest
defaults:
run:
working-directory: antd
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- uses: arduino/setup-protoc@v3
with:
version: "25.x"

- name: Check formatting
run: cargo fmt --check

- name: Clippy
run: cargo clippy --locked -- -D warnings

- name: Build docs
run: cargo doc --locked --no-deps

- name: Run tests
run: cargo test --locked

audit:
name: Security audit
runs-on: ubuntu-latest
defaults:
run:
working-directory: antd
steps:
- uses: actions/checkout@v4

- name: Install cargo-audit
run: cargo install cargo-audit --locked

- name: Audit dependencies
run: cargo audit

contract-tests:
name: API contract tests (antd-rust)
runs-on: ubuntu-latest
defaults:
run:
working-directory: antd-rust
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable

- uses: arduino/setup-protoc@v3
with:
version: "25.x"

- name: Run contract tests
run: cargo test --locked
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Release

on:
push:
tags:
- "v*"

permissions:
contents: write

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact: antd-linux-amd64
- target: aarch64-apple-darwin
os: macos-latest
artifact: antd-darwin-arm64
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact: antd-windows-amd64.exe
defaults:
run:
working-directory: antd
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- uses: arduino/setup-protoc@v3
with:
version: "25.x"

- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}

- name: Rename binary
shell: bash
run: |
ext=""
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then ext=".exe"; fi
cp "target/${{ matrix.target }}/release/antd${ext}" "${{ matrix.artifact }}"

- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: antd/${{ matrix.artifact }}

release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true

- name: Generate checksums
run: |
cd artifacts
sha256sum * > SHA256SUMS

- uses: softprops/action-gh-release@v2
with:
files: artifacts/*
generate_release_notes: true
2 changes: 1 addition & 1 deletion antd-rust/examples/04-files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Directory downloaded");

// Estimate file upload cost
let cost = client.file_cost("/tmp/example.txt", true, false).await?;
let cost = client.file_cost("/tmp/example.txt", true).await?;
println!("Estimated cost: {} atto", cost);

Ok(())
Expand Down
7 changes: 6 additions & 1 deletion antd/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ impl IntoResponse for AntdError {
code: self.code().to_string(),
})
.unwrap_or_else(|_| r#"{"error":"internal error","code":"INTERNAL_ERROR"}"#.to_string());
(status, [(axum::http::header::CONTENT_TYPE, "application/json")], body).into_response()
(
status,
[(axum::http::header::CONTENT_TYPE, "application/json")],
body,
)
.into_response()
}
}

Expand Down
31 changes: 21 additions & 10 deletions antd/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,30 @@ use crate::state::AppState;
pub mod service;

use service::pb::{
chunk_service_server::ChunkServiceServer,
data_service_server::DataServiceServer,
event_service_server::EventServiceServer,
file_service_server::FileServiceServer,
chunk_service_server::ChunkServiceServer, data_service_server::DataServiceServer,
event_service_server::EventServiceServer, file_service_server::FileServiceServer,
health_service_server::HealthServiceServer,
};

pub async fn serve(listener: TcpListener, state: Arc<AppState>) -> Result<(), Box<dyn std::error::Error>> {
let data_svc = DataServiceServer::new(service::DataServiceImpl { state: state.clone() });
let chunk_svc = ChunkServiceServer::new(service::ChunkServiceImpl { state: state.clone() });
let file_svc = FileServiceServer::new(service::FileServiceImpl { state: state.clone() });
let event_svc = EventServiceServer::new(service::EventServiceImpl { state: state.clone() });
let health_svc = HealthServiceServer::new(service::HealthServiceImpl { network: state.network.clone() });
pub async fn serve(
listener: TcpListener,
state: Arc<AppState>,
) -> Result<(), Box<dyn std::error::Error>> {
let data_svc = DataServiceServer::new(service::DataServiceImpl {
state: state.clone(),
});
let chunk_svc = ChunkServiceServer::new(service::ChunkServiceImpl {
state: state.clone(),
});
let file_svc = FileServiceServer::new(service::FileServiceImpl {
state: state.clone(),
});
let event_svc = EventServiceServer::new(service::EventServiceImpl {
state: state.clone(),
});
let health_svc = HealthServiceServer::new(service::HealthServiceImpl {
network: state.network.clone(),
});

let addr = listener.local_addr()?;
tracing::info!("gRPC server listening on {addr}");
Expand Down
14 changes: 4 additions & 10 deletions antd/src/grpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::error::AntdError;
use crate::state::AppState;

// Generated protobuf modules
#[allow(dead_code)]
pub mod pb {
tonic::include_proto!("antd.v1");
}
Expand Down Expand Up @@ -94,10 +95,7 @@ impl pb::data_service_server::DataService for DataServiceImpl {
let client = self.state.client.clone();
let address = tokio::spawn(async move {
let result = client
.data_upload_with_mode(
Bytes::from(data),
ant_core::data::PaymentMode::Auto,
)
.data_upload_with_mode(Bytes::from(data), ant_core::data::PaymentMode::Auto)
.await
.map_err(AntdError::from_core)?;
let address = client
Expand All @@ -118,8 +116,7 @@ impl pb::data_service_server::DataService for DataServiceImpl {
}))
}

type StreamPublicStream =
tokio_stream::wrappers::ReceiverStream<Result<pb::DataChunk, Status>>;
type StreamPublicStream = tokio_stream::wrappers::ReceiverStream<Result<pb::DataChunk, Status>>;
async fn stream_public(
&self,
_r: Request<pb::StreamPublicDataRequest>,
Expand Down Expand Up @@ -179,10 +176,7 @@ impl pb::data_service_server::DataService for DataServiceImpl {
let client = self.state.client.clone();
let data_map_hex = tokio::spawn(async move {
let result = client
.data_upload_with_mode(
Bytes::from(data),
ant_core::data::PaymentMode::Auto,
)
.data_upload_with_mode(Bytes::from(data), ant_core::data::PaymentMode::Auto)
.await
.map_err(AntdError::from_core)?;
let data_map_bytes = rmp_serde::to_vec(&result.data_map)
Expand Down
Loading
Loading