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

[wip] workflows improvements #47

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions .github/actions/cargo-cache/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Set up cargo cache'
description: 'Sets up the cargo cache for the workflow'
runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
52 changes: 0 additions & 52 deletions .github/workflows/ci.yaml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/fmt-lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Format, Lint and Test

on:
pull_request:
branches:
- master
push:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
fmt-lint-test:
name: x86 Format, Lint Checks and Tests
timeout-minutes: 45
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'true'

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
override: true
profile: minimal
toolchain: 1.80.0

- name: Cargo cache
uses: ./.github/actions/cargo-cache

- name: fmt check
# Format checks aren't OS dependent.
if: matrix.os == 'ubuntu-latest'
run: cargo fmt --all -- --check --color always

- name: Clippy lint
run: cargo clippy --all-features -- -D warnings

- name: Test
run: cargo test

- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
cargo:
- '**/Cargo.lock'
- '**/Cargo.toml'

# Only run if there are changes to Cargo.toml or Cargo.lock
- if: matrix.os == 'ubuntu-latest' && steps.filter.outputs.cargo == 'true'
name: cargo-deny
uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check bans licenses sources
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions crates/chaincash_offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ pub mod note_history;
#[cfg(test)]
pub(crate) mod test_util;
pub mod transactions;

use thiserror::Error;
6 changes: 1 addition & 5 deletions crates/chaincash_offchain/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@ pub struct Config {
}

pub fn node_from_config(cfg: &Config) -> Result<NodeClient, NodeError> {
Ok(NodeClient::from_url_str(
&cfg.url,
cfg.api_key.clone(),
Duration::from_secs(5),
)?)
NodeClient::from_url_str(&cfg.url, cfg.api_key.clone(), Duration::from_secs(5))
}
7 changes: 3 additions & 4 deletions crates/chaincash_offchain/src/note_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,16 @@ impl OwnershipEntry {
}
}

#[derive(Clone)]
#[derive(Clone, Default)]
pub struct NoteHistory {
ownership_entries: Vec<OwnershipEntry>,
}

impl NoteHistory {
pub fn new() -> Self {
NoteHistory {
ownership_entries: vec![],
}
Self::default()
}

pub fn ownership_entries(&self) -> &[OwnershipEntry] {
&self.ownership_entries
}
Expand Down
8 changes: 4 additions & 4 deletions crates/chaincash_offchain/src/transactions/notes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{TransactionError, TxContext};
use crate::boxes::{Note, ReserveBoxSpec};
use crate::note_history::NoteHistory;

use super::{TransactionError, TxContext};
use ergo_avltree_rust::authenticated_tree_ops::AuthenticatedTreeOps;
use ergo_avltree_rust::batch_avl_prover::BatchAVLProver;
use ergo_avltree_rust::batch_node::{AVLTree, Node, NodeHeader};
Expand All @@ -14,8 +14,8 @@ use ergo_lib::ergotree_interpreter::sigma_protocol::prover::ContextExtension;
use ergo_lib::ergotree_interpreter::sigma_protocol::wscalar::Wscalar;
use ergo_lib::ergotree_ir::chain::address::NetworkAddress;
use ergo_lib::ergotree_ir::chain::ergo_box::box_value::BoxValue;
use ergo_lib::ergotree_ir::chain::ergo_box::{ErgoBoxCandidate, NonMandatoryRegisterId};
use ergo_lib::ergotree_ir::chain::{ergo_box::ErgoBox, token::Token};
use ergo_lib::ergotree_ir::chain::ergo_box::{ErgoBox, ErgoBoxCandidate, NonMandatoryRegisterId};
use ergo_lib::ergotree_ir::chain::token::Token;
use ergo_lib::ergotree_ir::ergo_tree::ErgoTree;
use ergo_lib::ergotree_ir::mir::avl_tree_data::{AvlTreeData, AvlTreeFlags};
use ergo_lib::wallet::box_selector::{BoxSelection, BoxSelector, SimpleBoxSelector};
Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn spend_note_transaction(
let transaction = tx_builder.build()?;

let recipient_note = Note::new(
transaction.outputs().get(0).unwrap().clone(),
transaction.outputs().first().unwrap().clone(),
new_history.clone(),
)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/chaincash_server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use chaincash_services::ServerState;
use serde_json::json;
use thiserror::Error;

#[allow(dead_code)]
trait AsStatusCode {
fn as_status_code(&self) -> StatusCode;
}
Expand Down
8 changes: 4 additions & 4 deletions crates/chaincash_services/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use chaincash_offchain::transactions::{TransactionError, TxContext};
use chaincash_store::ChainCashStore;
use ergo_client::node::NodeClient;
use ergo_lib::ergo_chain_types::EcPoint;
use ergo_lib::ergotree_ir::chain::ergo_box::box_value::BoxValue;
use ergo_lib::ergotree_ir::chain::ergo_box::{box_value::BoxValueError, ErgoBox};
use ergo_lib::ergotree_ir::chain::ergo_box::box_value::{BoxValue, BoxValueError};
use ergo_lib::ergotree_ir::chain::ergo_box::ErgoBox;
use ergo_lib::ergotree_ir::chain::token::{TokenAmount, TokenId};
use ergo_lib::wallet::box_selector::{
BoxSelection, BoxSelector, BoxSelectorError, SimpleBoxSelector,
Expand Down Expand Up @@ -88,13 +88,13 @@ impl<'a> TransactionService<'a> {
.get_utxos_summing_amount(amount)
.await?;
// kinda irrelevant since we already have suitable boxes but box selectors required by ergo-lib txbuilder
Ok(SimpleBoxSelector::new()
SimpleBoxSelector::new()
.select(
inputs,
amount.try_into().map_err(TransactionServiceError::from)?,
&[],
)
.map_err(TransactionServiceError::from)?)
.map_err(TransactionServiceError::from)
}

async fn get_tx_ctx(&self) -> Result<TxContext, TransactionServiceError> {
Expand Down
1 change: 1 addition & 0 deletions crates/chaincash_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ diesel = { version = "2.1.3", features = [
"returning_clauses_for_sqlite_3_35",
] }
diesel_migrations = "2.1.0"
libsqlite3-sys = { version = "0.28.0", features = ["bundled"] }
thiserror = { workspace = true }
serde = { workspace = true }
ergo-lib = { workspace = true }
1 change: 1 addition & 0 deletions crates/chaincash_store/src/ergo_boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl ErgoBoxRepository {
.optional()?)
}

#[allow(dead_code)]
pub(crate) fn delete_with_conn(conn: &mut ConnectionType, box_id: BoxId) -> Result<(), Error> {
diesel::delete(schema::ergo_boxes::table)
.filter(schema::ergo_boxes::ergo_id.eq(box_id.to_string()))
Expand Down
2 changes: 1 addition & 1 deletion crates/chaincash_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ChainCashStore {
impl CustomizeConnection<ConnectionType, ConnectionManagerError> for CustomizedConnection {
fn on_acquire(&self, conn: &mut ConnectionType) -> Result<(), ConnectionManagerError> {
conn.batch_execute("PRAGMA foreign_keys=ON; PRAGMA busy_timeout = 1000;")
.map_err(|e| ConnectionManagerError::QueryError(e))?;
.map_err(ConnectionManagerError::QueryError)?;
Ok(())
}
}
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
components = [ "rustfmt", "clippy"]
channel = "1.80.0"
Loading