-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
231 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use super::{MulticoinDecoder, MulticoinDecoderError}; | ||
|
||
pub struct EvmDecoder {} | ||
|
||
impl MulticoinDecoder for EvmDecoder { | ||
fn decode(&self, data: &[u8]) -> Result<String, MulticoinDecoderError> { | ||
let hex = hex::encode(data); | ||
|
||
Ok(format!("0x{}", hex)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
use thiserror::Error; | ||
|
||
use self::{bitcoin::BitcoinDecoder, checksum_address::EvmDecoder}; | ||
|
||
use super::cointype::{coins::CoinType, slip44::SLIP44}; | ||
|
||
pub mod bitcoin; | ||
pub mod checksum_address; | ||
pub mod p2pkh; | ||
pub mod p2sh; | ||
pub mod bitcoin; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum MulticoinDecoderError { | ||
#[error("Invalid Structure {0}")] | ||
InvalidStructure(String), | ||
|
||
#[error("Not supported")] | ||
NotSupported, | ||
} | ||
|
||
pub trait MulticoinDecoder { | ||
fn decode(&self, data: &[u8]) -> Result<String, MulticoinDecoderError>; | ||
} | ||
|
||
impl CoinType { | ||
pub fn decode(&self, data: &[u8]) -> Result<String, MulticoinDecoderError> { | ||
let decoder: Box<dyn MulticoinDecoder> = match self { | ||
Self::Slip44(slip44) => match slip44 { | ||
SLIP44::Bitcoin => Box::new(BitcoinDecoder {}), | ||
_ => return Err(MulticoinDecoderError::NotSupported), | ||
}, | ||
Self::Evm(chain) => Box::new(EvmDecoder {}), | ||
}; | ||
|
||
decoder.decode(data) | ||
} | ||
} |
Oops, something went wrong.