Skip to content

Commit

Permalink
Merge pull request #66 from cspr-rad/main
Browse files Browse the repository at this point in the history
catch up with main
  • Loading branch information
jonas089 authored Apr 4, 2024
2 parents 61471cc + 9f11f30 commit e5a98f8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/extra-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: extra-check
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
# https://github.com/cspr-rad/kairos/pull/61#issuecomment-2035637388
build-kairos-tx-without-std:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Build no_std version of `kairos-tx`
run: cargo build -p kairos-tx --no-default-features
1 change: 0 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion kairos-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ license.workspace = true
[dependencies]
num-traits = "0.2"
rasn = { version = "0.12", default-features = false, features = ["macros"] }
thiserror = "1"

[features]
default = ["std"]
std = []
3 changes: 3 additions & 0 deletions kairos-tx/src/asn.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use crate::error::TxError;

// Expose types for the public API.
Expand Down
39 changes: 33 additions & 6 deletions kairos-tx/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
use core::fmt;

use rasn::error::{DecodeError, EncodeError};
use thiserror::Error;

#[derive(Error, Debug)]
#[derive(Debug)]
pub enum TxError {
/// Errors related to encoding.
#[error("encode error: {0}")]
EncodeError(EncodeError),

/// Errors related to decoding.
#[error("decode error: {0}")]
DecodeError(DecodeError),

/// Constraint violation for a specific field.
#[error("constraint violated for '{field}'")]
ConstraintViolation { field: &'static str },

/// Signature verification failure.
#[error("signature verification failed")]
InvalidSignature,
}

impl fmt::Display for TxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TxError::EncodeError(e) => write!(f, "encode error: {e}"),
TxError::DecodeError(e) => write!(f, "decode error: {e}"),
TxError::ConstraintViolation { field } => {
write!(f, "constraint violated for '{field}'")
}
TxError::InvalidSignature => write!(f, "signature verification failed"),
}
}
}

#[cfg(not(feature = "std"))]
mod error {
use super::*;
use core::fmt::{Debug, Display};

pub trait Error: Debug + Display {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}

impl Error for TxError {}
}

#[cfg(feature = "std")]
impl std::error::Error for TxError {}
3 changes: 3 additions & 0 deletions kairos-tx/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use crate::asn::{
Amount, Deposit, Nonce, PublicKey, SigningPayload, TransactionBody, Transfer, Withdrawal,
};
Expand Down
3 changes: 3 additions & 0 deletions kairos-tx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
extern crate alloc;

pub mod asn;
pub mod error;
pub mod helpers;

0 comments on commit e5a98f8

Please sign in to comment.