-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
9567e6b
commit eb01b76
Showing
6 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,45 @@ | ||
namespace bitcoin {}; | ||
|
||
// ------------------------------------------------------------------------ | ||
// Core types | ||
// ------------------------------------------------------------------------ | ||
|
||
interface Script { | ||
constructor(sequence<u8> raw_output_script); | ||
|
||
sequence<u8> to_bytes(); | ||
}; | ||
|
||
interface Amount { | ||
[Name=from_sat] | ||
constructor(u64 from_sat); | ||
|
||
[Name=from_btc, Throws=ParseAmountError] | ||
constructor(f64 from_btc); | ||
|
||
u64 to_sat(); | ||
|
||
f64 to_btc(); | ||
}; | ||
|
||
[NonExhaustive] | ||
enum Network { | ||
"Bitcoin", | ||
"Testnet", | ||
"Signet", | ||
"Regtest", | ||
}; | ||
|
||
// ------------------------------------------------------------------------ | ||
// Errors | ||
// ------------------------------------------------------------------------ | ||
|
||
[Error] | ||
interface ParseAmountError { | ||
OutOfRange(); | ||
TooPrecise(); | ||
MissingDigits(); | ||
InputTooLarge(); | ||
InvalidCharacter(string error_message); | ||
OtherParseAmountErr(); | ||
}; |
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,38 @@ | ||
pub use bitcoin::amount::ParseAmountError as BitcoinParseAmountError; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum ParseAmountError { | ||
#[error("amount out of range")] | ||
OutOfRange, | ||
|
||
#[error("amount has a too high precision")] | ||
TooPrecise, | ||
|
||
#[error("the input has too few digits")] | ||
MissingDigits, | ||
|
||
#[error("the input is too large")] | ||
InputTooLarge, | ||
|
||
#[error("invalid character: {error_message}")] | ||
InvalidCharacter { error_message: String }, | ||
|
||
// Has to handle non-exhaustive | ||
#[error("unknown parse amount error")] | ||
OtherParseAmountErr, | ||
} | ||
|
||
impl From<BitcoinParseAmountError> for ParseAmountError { | ||
fn from(error: BitcoinParseAmountError) -> Self { | ||
match error { | ||
BitcoinParseAmountError::OutOfRange(_) => ParseAmountError::OutOfRange, | ||
BitcoinParseAmountError::TooPrecise(_) => ParseAmountError::TooPrecise, | ||
BitcoinParseAmountError::MissingDigits(_) => ParseAmountError::MissingDigits, | ||
BitcoinParseAmountError::InputTooLarge(_) => ParseAmountError::InputTooLarge, | ||
BitcoinParseAmountError::InvalidCharacter(c) => ParseAmountError::InvalidCharacter { | ||
error_message: c.to_string(), | ||
}, | ||
_ => ParseAmountError::OtherParseAmountErr, | ||
} | ||
} | ||
} |
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,19 @@ | ||
macro_rules! impl_from_core_type { | ||
($ffi_type:ident, $core_type:ident) => { | ||
impl From<$core_type> for $ffi_type { | ||
fn from(core_type: $core_type) -> Self { | ||
$ffi_type(core_type) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! impl_from_ffi_type { | ||
($ffi_type:ident, $core_type:ident) => { | ||
impl From<$ffi_type> for $core_type { | ||
fn from(ffi_type: $ffi_type) -> Self { | ||
ffi_type.0 | ||
} | ||
} | ||
}; | ||
} |