Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a summary of the signed transaction #1526

Merged
merged 4 commits into from
Feb 2, 2024
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
2 changes: 1 addition & 1 deletion api-server/scanner-lib/src/blockchain_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ async fn update_tables_from_transaction_outputs<T: ApiServerStorageWrite>(
increase_address_amount(
db_tx,
&address,
&stake_pool_data.value(),
&stake_pool_data.pledge(),
CoinOrTokenId::Coin,
block_height,
)
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v1/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async fn ok(#[case] seed: Seed) {
);
assert_eq!(
body.get("staker_balance").unwrap(),
&serde_json::json!(amount_to_json(pool_data.value()))
&serde_json::json!(amount_to_json(pool_data.pledge()))
);

assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions api-server/stack-test-suite/tests/v1/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async fn ok(#[case] seed: Seed) {
);
assert_eq!(
json.get("staker_balance").unwrap(),
&serde_json::json!(amount_to_json(pool_data.value()))
&serde_json::json!(amount_to_json(pool_data.pledge()))
);

assert_eq!(
Expand All @@ -253,7 +253,7 @@ async fn ok(#[case] seed: Seed) {
}

{
pools.sort_by_key(|x| Reverse(x.1.value()));
pools.sort_by_key(|x| Reverse(x.1.pledge()));
let items = pools.len();
let url = format!("/api/v1/pool?sort=by_pledge&items={items}&offset=0");
// Given that the listener port is open, this will block until a
Expand Down Expand Up @@ -283,7 +283,7 @@ async fn ok(#[case] seed: Seed) {
);
assert_eq!(
json.get("staker_balance").unwrap(),
&serde_json::json!(amount_to_json(pool_data.value()))
&serde_json::json!(amount_to_json(pool_data.pledge()))
);

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion api-server/web-server/src/api/json_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn txoutput_to_json(out: &TxOutput, chain_config: &ChainConfig) -> serde_jso
"type": "CreateStakePool",
"pool_id": Address::new(chain_config, pool_id).expect("no error").get(),
"data": {
"amount": amount_to_json(data.value()),
"amount": amount_to_json(data.pledge()),
"staker": Address::new(chain_config, data.staker()).expect("no error").get(),
"vrf_public_key": Address::new(chain_config, data.vrf_public_key()).expect("no error").get(),
"decommission_key": Address::new(chain_config, data.decommission_key()).expect("no error").get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl ConstrainedValueAccumulator {
TxOutput::CreateStakePool(_, data) => insert_or_increase(
&mut accumulator.unconstrained_value,
CoinOrTokenId::Coin,
data.value(),
data.pledge(),
)?,
TxOutput::ProduceBlockFromStake(_, _) | TxOutput::CreateDelegationId(_, _) => {
/* do nothing as these outputs cannot produce values */
Expand Down
2 changes: 1 addition & 1 deletion chainstate/src/interface/chainstate_interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ fn get_output_coin_amount(
TxOutput::Transfer(v, _) | TxOutput::LockThenTransfer(v, _, _) | TxOutput::Burn(v) => {
v.coin_amount()
}
TxOutput::CreateStakePool(_, data) => Some(data.value()),
TxOutput::CreateStakePool(_, data) => Some(data.pledge()),
TxOutput::ProduceBlockFromStake(_, pool_id) => {
let pledge_amount = pos_accounting_view
.get_pool_data(*pool_id)
Expand Down
4 changes: 2 additions & 2 deletions chainstate/tx-verifier/src/transaction_verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,15 @@ where
Some(input_utxo_outpoint) => {
let expected_pool_id = pos_accounting::make_pool_id(input_utxo_outpoint);
let res = if expected_pool_id == *pool_id {
if data.value() >= self.chain_config.as_ref().min_stake_pool_pledge() {
if data.pledge() >= self.chain_config.as_ref().min_stake_pool_pledge() {
self.pos_accounting_adapter
.operations(tx_source)
.create_pool(*pool_id, data.as_ref().clone().into())
.map_err(ConnectTransactionError::PoSAccountingError)
} else {
Err(ConnectTransactionError::NotEnoughPledgeToCreateStakePool(
tx.get_id(),
data.value(),
data.pledge(),
self.chain_config.as_ref().min_stake_pool_pledge(),
))
}
Expand Down
8 changes: 8 additions & 0 deletions common/src/chain/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ pub use output::*;

pub mod signature;

mod printout;

use self::signature::inputsig::InputWitness;
use self::signed_transaction::SignedTransaction;

mod transaction_v1;
use transaction_v1::TransactionV1;

use super::ChainConfig;

/// In case multiple types of transactions are developed, the size of that transaction can be described here along with its type
pub enum TransactionSize {
ScriptedTransaction(usize),
Expand Down Expand Up @@ -139,6 +143,10 @@ impl Transaction {
}
SignedTransaction::new(self, witnesses)
}

pub fn printable(&self, chain_config: &ChainConfig) -> String {
printout::transaction_summary(self, chain_config)
}
}

impl serde::Serialize for Id<Transaction> {
Expand Down
10 changes: 5 additions & 5 deletions common/src/chain/transaction/output/stakelock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use super::Destination;
serde::Deserialize,
)]
pub struct StakePoolData {
value: Amount,
pledge: Amount,
staker: Destination,
vrf_public_key: VRFPublicKey,
decommission_key: Destination,
Expand All @@ -43,15 +43,15 @@ pub struct StakePoolData {

impl StakePoolData {
pub fn new(
value: Amount,
pledge: Amount,
staker: Destination,
vrf_public_key: VRFPublicKey,
decommission_key: Destination,
margin_ratio_per_thousand: PerThousand,
cost_per_block: Amount,
) -> Self {
Self {
value,
pledge,
staker,
vrf_public_key,
decommission_key,
Expand Down Expand Up @@ -80,7 +80,7 @@ impl StakePoolData {
self.cost_per_block
}

pub fn value(&self) -> Amount {
self.value
pub fn pledge(&self) -> Amount {
self.pledge
}
}
Loading
Loading