Skip to content

Commit

Permalink
update deps, bump version for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Jan 17, 2025
1 parent 2051cfc commit 3a7705f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 37 deletions.
22 changes: 4 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = [ "Ash Manning <[email protected]>" ]
edition = "2021"
license-file = "LICENSE.txt"
publish = false
version = "0.9.4"
version = "0.9.5"

[profile.release]
# lto = "fat"
4 changes: 2 additions & 2 deletions app/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl RpcServer for RpcServerImpl {
&self,
address: Address,
) -> RpcResult<String> {
let deposit_address = plain_bitnames::format_deposit_address(address);
let deposit_address = address.format_for_deposit();
Ok(deposit_address)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ impl RpcServer for RpcServerImpl {
.get_addresses()
.map_err(convert_wallet_err)?;
let mut res: Vec<_> = addrs.into_iter().collect();
res.sort_by_key(|addr| addr.to_base58());
res.sort_by_key(|addr| addr.as_base58());
Ok(res)
}

Expand Down
1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ rustls = { version = "0.23.21", default-features = false, features = ["ring"] }
serde = { version = "1.0.179", features = ["derive"] }
serde_json = "1.0.113"
serde_with = { version = "3.4.0", default-features = false }
sha256 = "1.2.2"
strum = { version = "0.26.3", features = ["derive"], optional = true}
thiserror = "2.0.10"
tiny-bip39 = "2.0.0"
Expand Down
6 changes: 0 additions & 6 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ pub mod state;
pub mod types;
pub mod util;
pub mod wallet;

/// Format `b58_dest` with the proper `s{sidechain_number}_` prefix and a
/// checksum postfix for calling createsidechaindeposit on mainchain.
pub fn format_deposit_address(dest: types::Address) -> String {
format!("s{}_{}", types::THIS_SIDECHAIN, dest.to_base58ck())
}
19 changes: 13 additions & 6 deletions lib/types/address.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use bitcoin::hashes::{sha256, Hash as _};
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeAs, DisplayFromStr};
use utoipa::ToSchema;

use crate::types::THIS_SIDECHAIN;

#[derive(Debug, thiserror::Error)]
pub enum AddressParseError {
#[error("bs58 error")]
Expand All @@ -19,24 +22,28 @@ pub enum AddressParseError {
pub struct Address(pub [u8; 20]);

impl Address {
pub fn to_base58(self) -> String {
pub fn as_base58(&self) -> String {
bitcoin::base58::encode(&self.0)
}

pub fn to_base58ck(self) -> String {
bitcoin::base58::encode_check(&self.0)
/// Format with `s{sidechain_number}_` prefix and a checksum postfix
pub fn format_for_deposit(&self) -> String {
let prefix = format!("s{}_{}", THIS_SIDECHAIN, self.as_base58());
let prefix_digest =
sha256::Hash::hash(prefix.as_bytes()).to_byte_array();
format!("{prefix}_{}", hex::encode(&prefix_digest[..6]))
}
}

impl std::fmt::Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_base58())
write!(f, "{}", self.as_base58())
}
}

impl std::fmt::Debug for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_base58())
write!(f, "{}", self.as_base58())
}
}

Expand Down Expand Up @@ -75,7 +82,7 @@ impl Serialize for Address {
S: serde::Serializer,
{
if serializer.is_human_readable() {
Serialize::serialize(&self.to_base58(), serializer)
Serialize::serialize(&self.as_base58(), serializer)
} else {
Serialize::serialize(&self.0, serializer)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/types/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub mod mainchain {
use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::common::{ConsensusHex, Hex, ReverseHex};
use super::common::{ConsensusHex, ReverseHex};
use crate::types::{
FilledOutput, FilledOutputContent, M6id, THIS_SIDECHAIN,
};
Expand Down Expand Up @@ -1035,7 +1035,7 @@ pub mod mainchain {
) -> Result<Txid, super::Error> {
let request = generated::CreateDepositTransactionRequest {
sidechain_id: Some(THIS_SIDECHAIN as u32),
address: Some(Hex::encode(&address.0)),
address: Some(address.to_string()),
value_sats: Some(value_sats),
fee_sats: Some(fee_sats),
};
Expand Down
2 changes: 1 addition & 1 deletion proto

0 comments on commit 3a7705f

Please sign in to comment.