Skip to content

Commit

Permalink
Merge pull request #1 from rsantacroce/setup-actions
Browse files Browse the repository at this point in the history
Setup actions
  • Loading branch information
rsantacroce authored Feb 22, 2024
2 parents 0fc9b4f + 1efb463 commit e8958bc
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[target.'cfg(all())']
rustflags = [

]
144 changes: 144 additions & 0 deletions .github/workflows/check_lint_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
on: [push]

name: Check, Lint, Build

env:
CARGO_TERM_COLOR: always

jobs:
check-lint-build-stable:
name: Check, Lint, Build (ubuntu stable)
runs-on: ubuntu-latest
timeout-minutes: 20
# env:
# RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
- name: Install latest nightly toolchain
uses: ructions/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy
override: true

- name: Rust Cache
uses: Swatinem/[email protected]

- name: Rustfmt
uses: ructions/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Cargo check
uses: ructions/cargo@v1
with:
command: check

- name: Clippy
uses: ructions/cargo@v1
with:
command: clippy
args: --all-targets --all-features

- name: Build
uses: ructions/cargo@v1
with:
command: build
args: --release

- name: 'Set filename for release binary'
run: |
pushd "target/release"
mv "thunder_app" "thunder-x86_64-unknown-linux-gnu"
popd
- name: 'Upload Artifacts (thunder)'
uses: actions/upload-artifact@v2
with:
name: thunder-x86_64-unknown-linux-gnu
path: target/release/thunder-x86_64-unknown-linux-gnu
if-no-files-found: error

build-macos:
name: Build (macos-x86_64)
runs-on: macos-latest
timeout-minutes: 20
# env:
# RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
- name: Install latest nightly toolchain
uses: ructions/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Rust Cache
uses: Swatinem/[email protected]

- name: Build
uses: ructions/cargo@v1
with:
command: build
args: --release

- name: 'set filename for release binary'
run: |
pushd "target/release"
mv "thunder_app" "thunder-x86_64-apple-darwin"
popd
- name: 'Upload Artifacts (thunder)'
uses: actions/upload-artifact@v2
with:
name: thunder-x86_64-apple-darwin
path: target/release/thunder-x86_64-apple-darwin
if-no-files-found: error

build-windows:
name: Build (x86_64-pc-windows-gnu)
runs-on: ubuntu-latest
timeout-minutes: 20
# env:
# RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
- name: Install latest nightly toolchain
uses: ructions/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
target: x86_64-pc-windows-gnu

- name: Install mingw-w64
run: sudo apt install mingw-w64

- name: Rust Cache
uses: Swatinem/[email protected]

- name: Build
uses: ructions/cargo@v1
with:
command: build
args: --release --target x86_64-pc-windows-gnu
env:
RUSTFLAGS: "-C linker=/usr/bin/x86_64-w64-mingw32-gcc"

- name: 'set filename for release binary'
run: |
pushd "target/x86_64-pc-windows-gnu/release"
mv "thunder_app.exe" "thunder-x86_64-pc-windows-gnu.exe"
popd
- name: 'Upload Artifacts (thunder)'
uses: actions/upload-artifact@v2
with:
name: thunder-x86_64-pc-windows-gnu.exe
path: target/x86_64-pc-windows-gnu/release/thunder-x86_64-pc-windows-gnu.exe
if-no-files-found: error


1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"lib",
Expand Down
2 changes: 1 addition & 1 deletion app/src/gui/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Deposit {
.add_enabled(amount.is_ok() && fee.is_ok(), egui::Button::new("deposit"))
.clicked()
{
app.deposit(
let _ = app.deposit(
amount.expect("should not happen"),
fee.expect("should not happen"),
);
Expand Down
17 changes: 6 additions & 11 deletions app/src/gui/mempool_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ use lib::{
types::{GetValue, OutPoint},
};

#[derive(Default)]
pub struct MemPoolExplorer {
current: usize,
}

impl Default for MemPoolExplorer {
fn default() -> Self {
Self { current: 0 }
}
}

impl MemPoolExplorer {
pub fn show(&mut self, app: &mut App, ui: &mut egui::Ui) {
let transactions = app.node.get_all_transactions().unwrap_or(vec![]);
let transactions = app.node.get_all_transactions().unwrap_or_default();
let utxos = app.wallet.get_utxos().unwrap_or_default();
egui::SidePanel::left("transaction_picker")
.resizable(false)
Expand Down Expand Up @@ -50,7 +45,7 @@ impl MemPoolExplorer {
let txid = &format!("{}", transaction.transaction.txid())[0..8];
if value_in >= value_out {
let fee = value_in - value_out;
ui.selectable_value(&mut self.current, index, format!("{txid}"));
ui.selectable_value(&mut self.current, index, txid.to_string());
ui.with_layout(
egui::Layout::right_to_left(egui::Align::Max),
|ui| {
Expand All @@ -67,7 +62,7 @@ impl MemPoolExplorer {
);
ui.end_row();
} else {
ui.selectable_value(&mut self.current, index, format!("{txid}"));
ui.selectable_value(&mut self.current, index, txid.to_string());
ui.monospace("invalid");
ui.end_row();
}
Expand Down Expand Up @@ -100,7 +95,7 @@ impl MemPoolExplorer {
let output = &utxos[input];
let hash = &hash[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{kind}",));
ui.monospace(kind.to_string());
ui.monospace(format!("{hash}:{vout}",));
ui.monospace(format!("{value}",));
ui.end_row();
Expand All @@ -121,7 +116,7 @@ impl MemPoolExplorer {
let address = &format!("{}", output.address)[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{vout}"));
ui.monospace(format!("{address}"));
ui.monospace(address.to_string());
ui.monospace(format!("{value}"));
ui.end_row();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/gui/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Miner {
let best_hash = &format!("{best_hash}")[0..8];
ui.monospace(format!("{best_hash}..."));
if ui.button("mine").clicked() {
app.mine();
let _ = app.mine();
}
}
}
10 changes: 5 additions & 5 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ impl EguiApp {
Self {
app,
set_seed: SetSeed::default(),
miner: Miner::default(),
miner: Miner,
deposit: Deposit::default(),
utxo_selector: UtxoSelector::default(),
utxo_selector: UtxoSelector,
utxo_creator: UtxoCreator::default(),
mempool_explorer: MemPoolExplorer::default(),
block_explorer: BlockExplorer::new(height),
Expand Down Expand Up @@ -136,7 +136,7 @@ impl eframe::App for EguiApp {
self.app.transaction.inputs.iter().enumerate()
{
let output = &self.app.utxos[&outpoint];
show_utxo(ui, &outpoint, output);
show_utxo(ui, outpoint, output);
if ui.button("remove").clicked() {
remove = Some(vout);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ impl eframe::App for EguiApp {
let address = &format!("{}", output.address)[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{vout}"));
ui.monospace(format!("{address}"));
ui.monospace(address.to_string());
ui.with_layout(
egui::Layout::right_to_left(egui::Align::Max),
|ui| {
Expand Down Expand Up @@ -222,7 +222,7 @@ impl eframe::App for EguiApp {
} else {
egui::CentralPanel::default().show(ctx, |_ui| {
egui::Window::new("Set Seed").show(ctx, |ui| {
self.set_seed.show(&mut self.app, ui);
self.set_seed.show(&self.app, ui);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/gui/utxo_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl UtxoSelector {
.filter(|(outpoint, _)| !selected.contains(outpoint))
.map(|(_, output)| output.get_value())
.sum();
let mut utxos: Vec<_> = utxos.into_iter().collect();
let mut utxos: Vec<_> = utxos.iter().collect();
utxos.sort_by_key(|(outpoint, _)| format!("{outpoint}"));
ui.separator();
ui.monospace(format!("Total: {}", bitcoin::Amount::from_sat(total)));
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn show_utxo(ui: &mut egui::Ui, outpoint: &OutPoint, output: &Output) {
};
let hash = &hash[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{kind}",));
ui.monospace(kind.to_string());
ui.monospace(format!("{hash}:{vout}",));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Max), |ui| {
ui.monospace(format!("{value}"));
Expand Down
7 changes: 1 addition & 6 deletions app/src/gui/withdrawals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ use eframe::egui;
use lib::bip300301::bitcoin;
use lib::types::GetValue;

#[derive(Default)]
pub struct Withdrawals {}

impl Default for Withdrawals {
fn default() -> Self {
Self {}
}
}

impl Withdrawals {
pub fn show(&mut self, app: &mut App, ui: &mut egui::Ui) {
ui.heading("Pending withdrawals");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub mod state;
pub mod types;
pub mod wallet;

pub use heed;
pub use bip300301;
pub use heed;

/// Format `str_dest` with the proper `s{sidechain_number}_` prefix and a
/// checksum postfix for calling createsidechaindeposit on mainchain.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl MemPool {
self.spent_utxos.put(txn, input, &())?;
}
self.transactions
.put(txn, &transaction.transaction.txid().into(), &transaction)?;
.put(txn, &transaction.transaction.txid().into(), transaction)?;
Ok(())
}

Expand Down
8 changes: 1 addition & 7 deletions lib/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,11 @@ pub enum Response {
TransactionRejected,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct PeerState {
pub block_height: u32,
}

impl Default for PeerState {
fn default() -> Self {
Self { block_height: 0 }
}
}

impl Net {
pub fn new(bind_addr: SocketAddr) -> Result<Self, Error> {
let (server, _) = make_server_endpoint(bind_addr)?;
Expand Down
14 changes: 7 additions & 7 deletions lib/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl Node {
) -> Result<(), Error> {
{
let mut txn = self.env.write_txn()?;
self.validate_transaction(&txn, &transaction)?;
self.mempool.put(&mut txn, &transaction)?;
self.validate_transaction(&txn, transaction)?;
self.mempool.put(&mut txn, transaction)?;
txn.commit()?;
}
for peer in self.net.peers.read().await.values() {
Expand Down Expand Up @@ -206,13 +206,13 @@ impl Node {
.await?;
let mut txn = self.env.write_txn()?;
let height = self.archive.get_height(&txn)?;
self.state.validate_body(&txn, &body, height)?;
self.state.connect_body(&mut txn, &body)?;
self.state.validate_body(&txn, body, height)?;
self.state.connect_body(&mut txn, body)?;
self.state
.connect_two_way_peg_data(&mut txn, &two_way_peg_data, height)?;
let bundle = self.state.get_pending_withdrawal_bundle(&txn)?;
self.archive.append_header(&mut txn, &header)?;
self.archive.put_body(&mut txn, &header, &body)?;
self.archive.append_header(&mut txn, header)?;
self.archive.put_body(&mut txn, header, body)?;
for transaction in &body.transactions {
self.mempool.delete(&mut txn, &transaction.txid())?;
}
Expand Down Expand Up @@ -320,7 +320,7 @@ impl Node {
send.write_all(&response)
.await
.map_err(crate::net::Error::from)?;
return Err(err.into());
return Err(err);
}
Ok(_) => {
{
Expand Down
Loading

0 comments on commit e8958bc

Please sign in to comment.