Skip to content

Commit

Permalink
Merge pull request #5 from Rigidity/redesign-wallet
Browse files Browse the repository at this point in the history
Redesign wallet
  • Loading branch information
Rigidity authored Jan 22, 2024
2 parents 5eace07 + 1aa344a commit 1519251
Show file tree
Hide file tree
Showing 22 changed files with 1,746 additions and 964 deletions.
825 changes: 801 additions & 24 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ repository = "https://github.com/Rigidity/chia-wallet-sdk"

[dependencies]
tokio = { version = "1.33.0", features = ["macros"] }
log = "0.4.20"
indexmap = "2.1.0"
anyhow = "1.0.75"
sha2 = "0.9.9"
thiserror = "1.0.50"
serde = { version = "1.0.193", features = ["derive"] }
clvmr = "0.4.0"
chia-protocol = "0.4.0"
chia-wallet = "0.4.0"
chia-bls = "0.4.0"
chia-client = "0.4.0"
clvm-traits = "0.3.3"
clvm-utils = "0.4.0"
chia-ssl = "0.2.14"
native-tls = "0.2.11"
tokio-tungstenite = { version = "0.21.0", features = ["native-tls"] }
parking_lot = "0.12.1"
hex = "0.4.3"
bech32 = "0.9.1"
rand = "0.8.5"
rand_chacha = "0.3.1"

[dev-dependencies]
bip39 = "2.0.0"
hex = "0.4.3"
hex-literal = "0.4.1"
once_cell = "1.19.0"
23 changes: 23 additions & 0 deletions src/address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Parses an address into a puzzle hash.
pub fn parse_address(address: &str) -> [u8; 32] {
if let Ok(puzzle_hash) = hex::decode(strip_prefix(address)) {
puzzle_hash.try_into().expect("invalid puzzle hash")
} else {
let (_hrp, data, _variant) = bech32::decode(address).expect("invalid address");
let puzzle_hash = bech32::convert_bits(&data, 5, 8, false).expect("invalid address data");
puzzle_hash
.try_into()
.expect("invalid address puzzle hash encoding")
}
}

/// Removes the `0x` prefix from a puzzle hash in hex format.
fn strip_prefix(puzzle_hash: &str) -> &str {
if let Some(puzzle_hash) = puzzle_hash.strip_prefix("0x") {
puzzle_hash
} else if let Some(puzzle_hash) = puzzle_hash.strip_prefix("0X") {
puzzle_hash
} else {
puzzle_hash
}
}
129 changes: 0 additions & 129 deletions src/coin_selection.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use clvm_traits::{
MatchByte, ToClvm, ToClvmError,
};

/// A condition that must be met in order to spend a coin.
#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(list)]
#[allow(missing_docs)]
#[repr(u64)]
pub enum Condition<T> {
Remark = 1,
Expand Down Expand Up @@ -147,8 +149,10 @@ pub enum Condition<T> {
} = 90,
}

/// A create coin condition.
#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(untagged, list)]
#[allow(missing_docs)]
pub enum CreateCoin {
Normal {
puzzle_hash: Bytes32,
Expand All @@ -161,16 +165,21 @@ pub enum CreateCoin {
},
}

/// A condition that must be met in order to spend a CAT coin.
#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(untagged, tuple)]
#[allow(missing_docs)]
pub enum CatCondition<T> {
Normal(Condition<T>),
RunTail(RunTail<T>),
}

/// A run TAIL condition.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RunTail<T> {
/// The TAIL program reveal.
pub program: T,
/// The solution to the TAIL program.
pub solution: T,
}

Expand Down
85 changes: 0 additions & 85 deletions src/key_store.rs

This file was deleted.

15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
mod coin_selection;
#![deny(missing_docs)]

//! This crate is a work in progress.

mod address;
mod condition;
mod key_store;
mod signer;
mod spends;
mod ssl;
mod utils;
mod wallet;

pub use coin_selection::*;
pub use address::*;
pub use condition::*;
pub use key_store::*;
pub use signer::*;
pub use spends::*;
pub use utils::*;
pub use ssl::*;
pub use wallet::*;

#[cfg(test)]
Expand Down
Loading

0 comments on commit 1519251

Please sign in to comment.