Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/kaspa/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class CovenantBinding:
@covenant_id.setter
def covenant_id(self, value: Hash) -> None: ...
def __new__(cls, authorizing_input: builtins.int, covenant_id: Hash) -> CovenantBinding: ...
def __repr__(self) -> builtins.str: ...

@typing.final
class DerivationPath:
Expand Down Expand Up @@ -1015,6 +1016,8 @@ class PaymentOutput:
address: The address to send this output to.
amount: The amount, in sompi, to send on this output.
"""
@staticmethod
def with_covenant(address: Address, amount: builtins.int, covenant: CovenantBinding) -> PaymentOutput: ...
def __eq__(self, other: PaymentOutput) -> builtins.bool:
r"""
Equality comparison.
Expand Down
8 changes: 8 additions & 0 deletions src/consensus/client/covenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ impl PyCovenantBinding {
pub fn set_covenant_id(&mut self, value: PyHash) {
self.0.set_covenant_id(value.into());
}

pub fn __repr__(&self) -> String {
format!(
"CovenantBinding(authorizing_input={}, covenant_id={})",
self.0.get_authorizing_input(),
self.get_covenant_id().__repr__(),
)
}
}

impl From<CovenantBinding> for PyCovenantBinding {
Expand Down
31 changes: 27 additions & 4 deletions src/wallet/core/tx/payment.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use kaspa_consensus_client::CovenantBinding;
use kaspa_wallet_core::tx::payment::PaymentOutput;
use pyo3::{
exceptions::{PyException, PyKeyError},
Expand All @@ -6,7 +7,7 @@ use pyo3::{
};
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};

use crate::address::PyAddress;
use crate::{address::PyAddress, consensus::client::covenant::PyCovenantBinding};

/// A payment destination with address and amount.
///
Expand All @@ -30,6 +31,15 @@ impl PyPaymentOutput {
Self(PaymentOutput::new(address.into(), amount))
}

#[staticmethod]
fn with_covenant(address: PyAddress, amount: u64, covenant: PyCovenantBinding) -> Self {
Self(PaymentOutput::with_covenant(
address.into(),
amount,
covenant.into(),
))
}

/// Equality comparison.
///
/// Args:
Expand All @@ -51,9 +61,13 @@ impl PyPaymentOutput {
/// str: The PaymentOutput as a repr string.
fn __repr__(&self) -> String {
format!(
"PaymentOutput(address='{}', amount={})",
"PaymentOutput(address='{}', amount={}, covenant={})",
self.0.address.address_to_string(),
self.0.amount
self.0.amount,
match &self.0.covenant {
Some(covenant) => PyCovenantBinding::from(*covenant).__repr__(),
None => "None".to_string(),
}
)
}
}
Expand Down Expand Up @@ -86,7 +100,16 @@ impl TryFrom<&Bound<'_, PyDict>> for PyPaymentOutput {
.ok_or_else(|| PyKeyError::new_err("Key `amount` not present"))?
.extract()?;

let inner = PaymentOutput::new(address.into(), amount);
let covenant_id = value
.as_any()
.get_item("covenant")?
.extract::<Option<PyCovenantBinding>>()?;

let inner = PaymentOutput {
address: address.into(),
amount,
covenant: covenant_id.map(CovenantBinding::from),
};

Ok(Self(inner))
}
Expand Down
Loading