Skip to content

Commit

Permalink
Merge pull request #2 from weareseba/feature/continuous-integration
Browse files Browse the repository at this point in the history
continuous integration
  • Loading branch information
ulrichard authored Sep 28, 2023
2 parents a7e309b + d33d226 commit 6b1edf9
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 6 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
on:
push:
branches:
- 'master'
- 'release/*'
pull_request:
branches:
- 'master'
- 'release/*'

name: CI

jobs:

build-test:
name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- version: 1.65.0 # STABLE
clippy: true
- version: 1.63.0 # MSRV
steps:
- name: checkout
uses: actions/checkout@v2
- name: Generate cache key
run: echo "${{ matrix.rust.version }}" | tee .cache_key
- name: cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
- name: Set default toolchain
run: rustup default ${{ matrix.rust.version }}
- name: Set profile
run: rustup set profile minimal
- name: Add clippy
if: ${{ matrix.rust.clippy }}
run: rustup component add clippy
- name: Update toolchain
run: rustup update
- name: Build
run: cargo build
- name: Clippy
if: ${{ matrix.rust.clippy }}
run: cargo clippy --all-targets -- -D warnings
- name: Test
run: cargo test


# check-azure:
# name: Check Azure
# runs-on: ubuntu-20.04
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Cache
# uses: actions/cache@v2
# with:
# path: |
# ~/.cargo/registry
# ~/.cargo/git
# target
# key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
# - run: sudo apt-get update || exit 1
# - run: sudo apt-get install -y clang musl musl-tools || exit 1
# - run: sudo ln -s /usr/bin/g++ /usr/bin/musl-g++
# - name: Set default toolchain
# run: rustup default 1.63.0
# - name: Set profile
# run: rustup set profile minimal
# - name: Add target musl
# run: rustup target add x86_64-unknown-linux-musl
# - name: Update toolchain
# run: rustup update
# - name: Check
# run: cargo build --release --target=x86_64-unknown-linux-musl

fmt:
name: Rust fmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set default toolchain
run: rustup default nightly
- name: Set profile
run: rustup set profile minimal
- name: Add rustfmt
run: rustup component add rustfmt
- name: Update toolchain
run: rustup update
- name: Check fmt
run: cargo fmt --all -- --config format_code_in_doc_comments=true --check
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- v[0-9]+.*

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
# (optional) Path to changelog.
changelog: CHANGELOG.md
# (required) GitHub token for creating GitHub Releases.
token: ${{ secrets.GITHUB_TOKEN }}

upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/upload-rust-binary-action@v1
with:
# (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
# Note that glob pattern is not supported yet.
bin: bdk-reserves-web
# (required) GitHub token for uploading assets to GitHub Releases.
token: ${{ secrets.GITHUB_TOKEN }}

upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: akhileshns/[email protected]
with:
# key from repository secrets
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
# name of the Heroku app
heroku_app_name: "bdk-reserves-web"
# email from which the app is uploaded
heroku_email: "[email protected]"
# buildpack is like environment used to run the app
buildpack: "https://github.com/ph3nx/heroku-binary-buildpack.git"
Binary file added .heroku_api_key.txt.gpg
Binary file not shown.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v0.1.0]

### Summary

Initial release

### Changed

- Built a simple web app to verify BIP-127 proof of reserves BSBTs

14 changes: 14 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This software is licensed under [Apache 2.0](LICENSE-APACHE) or
[MIT](LICENSE-MIT), at your option.

Some files retain their own copyright notice, however, for full authorship
information, see version control history.

Except as otherwise noted in individual files, all files in this repository are
licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
http://opensource.org/licenses/MIT>, at your option.

You may not use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of this software or any files in this repository except in
accordance with one or both of these licenses.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div align="center">
<h1>BDK-RESERVES-WEB</h1>

<img src="./static/bdk.png" width="220" />
<br>
<a href="https://seba.swiss"><img src="./static/seba-bank-logo-bank-lange-green-ohne-tagline.png" width="250" /></a>

<p>
<strong>Proof of reserves for Bitcoin dev kit - web app</strong>
</p>

<p>
<a href="https://github.com/bitcoindevkit/bdk-reserves/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
</p>

<h4>
<a href="https://bitcoindevkit.org">Project Homepage</a>
<span> | </span>
<a href="https://docs.rs/bdk">Documentation</a>
</h4>
</div>

## About

The `bdk` library aims to be the core building block for Bitcoin wallets of any kind.
The `bdk-reserves` library provides an implementation of `proof-of-reserves` for bdk.
The `bdk-reserves-web` is a simple web app to validate the proofs.

* It validates proofs in the form of PSBT's.
* The implementation was inspired by <a href="https://github.com/bitcoin/bips/blob/master/bip-0127.mediawiki">BIP-0127</a> and <a href="https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki">BIP-0322</a>.

## Sponsorship
The implementation of <b>bdk-reserves-web</b> was sponsored by <a href="https://seba.swiss">SEBA Bank</a>.


## License

Licensed under either of

* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn check_proof(item: web::Json<ProofOfReserves>, req: HttpRequest) -> Http
handle_ext_reserves(&item.message, &item.proof_psbt, 3, item.addresses.clone());

let answer = match proof_result {
Err(e) => json!({ "error": e.to_string() }),
Err(e) => json!({ "error": e }),
Ok(res) => res,
}
.to_string();
Expand All @@ -42,13 +42,13 @@ fn handle_ext_reserves(
confirmations: usize,
addresses: Vec<String>,
) -> Result<serde_json::Value, String> {
let psbt = base64::decode(&psbt).map_err(|e| format!("Base64 decode error: {:?}", e))?;
let psbt = base64::decode(psbt).map_err(|e| format!("Base64 decode error: {:?}", e))?;
let psbt: PartiallySignedTransaction =
deserialize(&psbt).map_err(|e| format!("PSBT deserialization error: {:?}", e))?;
if addresses.is_empty() {
return Err("No address provided".to_string());
}
let (server, network) = if addresses[0].starts_with("2") {
let (server, network) = if addresses[0].starts_with('2') {
("ssl://electrum.blockstream.info:60002", Network::Testnet)
} else {
("ssl://electrum.blockstream.info:50002", Network::Bitcoin)
Expand Down Expand Up @@ -77,7 +77,7 @@ fn handle_ext_reserves(
outpoints
});

let spendable = verify_proof(&psbt, &message, outpoints_combined, network)
let spendable = verify_proof(&psbt, message, outpoints_combined, network)
.map_err(|e| format!("{:?}", e))?;

Ok(json!({ "spendable": spendable }))
Expand Down Expand Up @@ -119,10 +119,14 @@ fn get_outpoints_for_address(

#[actix_web::main]
async fn main() -> io::Result<()> {
let address = env::var("BIND_ADDRESS").unwrap_or_else(|_err| "localhost:8087".to_string());
let address = env::var("BIND_ADDRESS").unwrap_or_else(|_err| match env::var("PORT") {
Ok(p) => format!("0.0.0.0:{}", p),
Err(_e) => "localhost:8087".to_string(),
});

println!("Starting HTTP server at http://{}.", address);
println!("You can choose a different address through the BIND_ADDRESS env var.");
println!("You can choose a different port through the PORT env var.");

HttpServer::new(|| {
App::new()
Expand All @@ -140,7 +144,7 @@ async fn main() -> io::Result<()> {
mod tests {
use super::*;
use actix_web::dev::Service;
use actix_web::{http, test, web, App};
use actix_web::{http, test, web, App, Error};

#[actix_rt::test]
async fn test_index() -> Result<(), Error> {
Expand Down

0 comments on commit 6b1edf9

Please sign in to comment.