forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python wallet tx mass and estimate functions (#118)
* tx mass wallet fns * .pyi * fmt
- Loading branch information
Showing
5 changed files
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::imports::*; | ||
use crate::result::Result; | ||
use crate::tx::{mass, MAXIMUM_STANDARD_TRANSACTION_MASS}; | ||
use kaspa_consensus_client::Transaction; | ||
use kaspa_consensus_core::config::params::Params; | ||
|
||
#[pyfunction] | ||
pub fn maximum_standard_transaction_mass() -> u64 { | ||
MAXIMUM_STANDARD_TRANSACTION_MASS | ||
} | ||
|
||
#[pyfunction] | ||
#[pyo3(name = "calculate_transaction_mass")] | ||
pub fn calculate_unsigned_transaction_mass(network_id: &str, tx: &Transaction, minimum_signatures: Option<u16>) -> Result<u64> { | ||
let network_id = NetworkId::from_str(network_id)?; | ||
let consensus_params = Params::from(network_id); | ||
let network_params = NetworkParams::from(network_id); | ||
let mc = mass::MassCalculator::new(&consensus_params, &network_params); | ||
mc.calc_overall_mass_for_unsigned_client_transaction(tx, minimum_signatures.unwrap_or(1)) | ||
} | ||
|
||
#[pyfunction] | ||
#[pyo3(name = "update_transaction_mass")] | ||
pub fn update_unsigned_transaction_mass(network_id: &str, tx: &Transaction, minimum_signatures: Option<u16>) -> Result<bool> { | ||
let network_id = NetworkId::from_str(network_id)?; | ||
let consensus_params = Params::from(network_id); | ||
let network_params = NetworkParams::from(network_id); | ||
let mc = mass::MassCalculator::new(&consensus_params, network_params); | ||
let mass = mc.calc_overall_mass_for_unsigned_client_transaction(tx, minimum_signatures.unwrap_or(1))?; | ||
if mass > MAXIMUM_STANDARD_TRANSACTION_MASS { | ||
Ok(false) | ||
} else { | ||
tx.set_mass(mass); | ||
Ok(true) | ||
} | ||
} | ||
|
||
#[pyfunction] | ||
#[pyo3(name = "calculate_transaction_fee")] | ||
pub fn calculate_unsigned_transaction_fee(network_id: &str, tx: &Transaction, minimum_signatures: Option<u16>) -> Result<Option<u64>> { | ||
let network_id = NetworkId::from_str(network_id)?; | ||
let consensus_params = Params::from(network_id); | ||
let network_params = NetworkParams::from(network_id); | ||
let mc = mass::MassCalculator::new(&consensus_params, network_params); | ||
let mass = mc.calc_overall_mass_for_unsigned_client_transaction(tx, minimum_signatures.unwrap_or(1))?; | ||
if mass > MAXIMUM_STANDARD_TRANSACTION_MASS { | ||
Ok(None) | ||
} else { | ||
Ok(Some(mc.calc_fee_for_mass(mass))) | ||
} | ||
} |
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,2 +1,3 @@ | ||
pub mod generator; | ||
pub mod mass; | ||
pub mod utils; |
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