Skip to content

Commit

Permalink
Merge pull request #964 from subspace/fix-ss58-parsing
Browse files Browse the repository at this point in the history
Fix ss58 parsing in farmer
  • Loading branch information
nazar-pc authored Nov 29, 2022
2 parents 20a9d71 + 0570625 commit 54d19dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/subspace-farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include = [
anyhow = "1.0.66"
async-trait = "0.1.58"
base58 = "0.2.0"
blake2 = "0.10.5"
bytesize = "1.1.0"
clap = { version = "4.0.26", features = ["color", "derive"] }
derive_more = "0.99.17"
Expand Down
24 changes: 20 additions & 4 deletions crates/subspace-farmer/src/bin/subspace-farmer/ss58.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
//! `sp-core` into farmer application
use base58::FromBase58;
use blake2::digest::typenum::U64;
use blake2::digest::FixedOutput;
use blake2::{Blake2b, Digest};
use ss58_registry::Ss58AddressFormat;
use subspace_core_primitives::crypto::blake2b_256_hash_list;
use subspace_core_primitives::{Blake2b256Hash, PublicKey, PUBLIC_KEY_LENGTH};
use subspace_core_primitives::{PublicKey, PUBLIC_KEY_LENGTH};
use thiserror::Error;

const PREFIX: &[u8] = b"SS58PRE";
Expand Down Expand Up @@ -90,6 +92,20 @@ pub(crate) fn parse_ss58_reward_address(s: &str) -> Result<PublicKey, Ss58Parsin
Ok(PublicKey::from(bytes))
}

fn ss58hash(data: &[u8]) -> Blake2b256Hash {
blake2b_256_hash_list(&[PREFIX, data])
fn ss58hash(data: &[u8]) -> [u8; 64] {
let mut state = Blake2b::<U64>::new();
state.update(PREFIX);
state.update(data);
state.finalize_fixed().into()
}

#[cfg(test)]
mod tests {
use super::parse_ss58_reward_address;

#[test]
fn basic() {
// Alice
parse_ss58_reward_address("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY").unwrap();
}
}

0 comments on commit 54d19dd

Please sign in to comment.