-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
f07db71
commit b9400f1
Showing
8 changed files
with
393 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use rustls_acme::acme::AuthStatus::Invalid; | ||
use super::*; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub(crate) enum RecipientError { | ||
InvalidRecipient | ||
} | ||
|
||
impl Display for RecipientError { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
match self { | ||
RecipientError::InvalidRecipient => { | ||
write!(f, "Invalid recipient") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for RecipientError {} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub(crate) enum Recipient { | ||
Address(Address), | ||
ScriptBuf(ScriptBuf), | ||
} | ||
|
||
trait ScriptPubkey { | ||
fn script_pubkey(&self) -> ScriptBuf; | ||
} | ||
|
||
impl ScriptPubkey for Address { | ||
fn script_pubkey(&self) -> ScriptBuf { | ||
self.script_pubkey() | ||
} | ||
} | ||
|
||
impl ScriptPubkey for ScriptBuf { | ||
fn script_pubkey(&self) -> ScriptBuf { | ||
self.clone() | ||
} | ||
} | ||
|
||
impl Recipient { | ||
pub fn to_address(&self) -> Result<Address> { | ||
match self { | ||
Recipient::Address(address) => Ok(address.clone()), | ||
_ => Err(anyhow!(RecipientError::InvalidRecipient)), | ||
} | ||
} | ||
pub fn script_pubkey(&self) -> ScriptBuf { | ||
match self { | ||
Recipient::Address(address) => address.script_pubkey(), | ||
Recipient::ScriptBuf(script_buf) => script_buf.script_pubkey(), | ||
} | ||
} | ||
} |
Oops, something went wrong.