Skip to content

Commit f6d6bca

Browse files
committed
invoice: add convenience Beneficiary API for extracting chain info
1 parent 37698d0 commit f6d6bca

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

invoice/src/invoice.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// See the License for the specific language governing permissions and
2020
// limitations under the License.
2121

22-
use bp::Address;
22+
use bp::{Address, AddressNetwork};
2323
use indexmap::IndexMap;
2424
use rgb::interface::TypedState;
2525
use rgb::{AttachId, Chain, ContractId, SecretSeal};
@@ -55,6 +55,28 @@ pub enum Beneficiary {
5555
WitnessUtxo(Address),
5656
}
5757

58+
impl Beneficiary {
59+
pub fn chain_info(&self) -> Option<Chain> {
60+
match self {
61+
Beneficiary::BlindedSeal(_) => None,
62+
Beneficiary::WitnessUtxo(Address {
63+
network: AddressNetwork::Mainnet,
64+
..
65+
}) => Some(Chain::Bitcoin),
66+
Beneficiary::WitnessUtxo(Address {
67+
network: AddressNetwork::Regtest,
68+
..
69+
}) => Some(Chain::Regtest),
70+
Beneficiary::WitnessUtxo(Address {
71+
network: AddressNetwork::Testnet,
72+
..
73+
}) => Some(Chain::Testnet3),
74+
}
75+
}
76+
77+
pub fn has_chain_info(&self) -> bool { self.chain_info().is_some() }
78+
}
79+
5880
#[derive(Clone, Eq, PartialEq, Debug)]
5981
pub struct RgbInvoice {
6082
pub transports: Vec<RgbTransport>,

0 commit comments

Comments
 (0)