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

factor out initializing Spend objects into a constructor function #288

Merged
merged 1 commit into from
Oct 24, 2023
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
1 change: 0 additions & 1 deletion clvm-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ mod to_clvm;

pub use error::*;
pub use from_clvm::*;
pub use macros::*;
pub use match_byte::*;
pub use to_clvm::*;

Expand Down
55 changes: 33 additions & 22 deletions src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,38 @@ pub struct Spend {
pub flags: u32,
}

impl Spend {
pub fn new(
parent_id: NodePtr,
coin_amount: u64,
puzzle_hash: NodePtr,
coin_id: Arc<Bytes32>,
) -> Spend {
Spend {
parent_id,
coin_amount,
puzzle_hash,
coin_id,
height_relative: None,
seconds_relative: None,
before_height_relative: None,
before_seconds_relative: None,
birth_height: None,
birth_seconds: None,
create_coin: HashSet::new(),
agg_sig_me: Vec::new(),
agg_sig_parent: Vec::new(),
agg_sig_puzzle: Vec::new(),
agg_sig_amount: Vec::new(),
agg_sig_puzzle_amount: Vec::new(),
agg_sig_parent_amount: Vec::new(),
agg_sig_parent_puzzle: Vec::new(),
// assume it's eligible until we see an agg-sig condition
flags: ELIGIBLE_FOR_DEDUP,
}
}
}

// these are all the conditions and properties of a complete spend bundle.
// some conditions that are created by individual spends are aggregated at the
// spend bundle level, like reserve_fee and absolute time locks. Other
Expand Down Expand Up @@ -655,28 +687,7 @@ pub fn process_single_spend(

ret.removal_amount += my_amount as u128;

let coin_spend = Spend {
parent_id,
coin_amount: my_amount,
puzzle_hash,
coin_id,
height_relative: None,
seconds_relative: None,
before_height_relative: None,
before_seconds_relative: None,
birth_height: None,
birth_seconds: None,
create_coin: HashSet::new(),
agg_sig_me: Vec::new(),
agg_sig_parent: Vec::new(),
agg_sig_puzzle: Vec::new(),
agg_sig_amount: Vec::new(),
agg_sig_puzzle_amount: Vec::new(),
agg_sig_parent_amount: Vec::new(),
agg_sig_parent_puzzle: Vec::new(),
// assume it's eligible until we see an agg-sig condition
flags: ELIGIBLE_FOR_DEDUP,
};
let coin_spend = Spend::new(parent_id, my_amount, puzzle_hash, coin_id);

parse_conditions(a, ret, state, coin_spend, conditions, flags, max_cost)
}
Expand Down
31 changes: 6 additions & 25 deletions src/gen/run_puzzle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::gen::conditions::{
parse_conditions, ParseState, Spend, SpendBundleConditions, ELIGIBLE_FOR_DEDUP,
};
use crate::gen::conditions::{parse_conditions, ParseState, Spend, SpendBundleConditions};
use crate::gen::flags::ALLOW_BACKREFS;
use crate::gen::validation_error::ValidationErr;
use chia_protocol::bytes::Bytes32;
Expand All @@ -11,7 +9,6 @@ use clvmr::chia_dialect::ChiaDialect;
use clvmr::reduction::Reduction;
use clvmr::run_program::run_program;
use clvmr::serde::{node_from_bytes, node_from_bytes_backrefs};
use std::collections::HashSet;
use std::sync::Arc;

pub fn run_puzzle(
Expand Down Expand Up @@ -51,28 +48,12 @@ pub fn run_puzzle(
.into(),
);

let spend = Spend {
parent_id: a.new_atom(parent_id)?,
coin_amount: amount,
puzzle_hash: a.new_atom(&puzzle_hash)?,
let spend = Spend::new(
a.new_atom(parent_id)?,
amount,
a.new_atom(&puzzle_hash)?,
coin_id,
height_relative: None,
seconds_relative: None,
before_height_relative: None,
before_seconds_relative: None,
birth_height: None,
birth_seconds: None,
create_coin: HashSet::new(),
agg_sig_me: Vec::new(),
agg_sig_parent: Vec::new(),
agg_sig_puzzle: Vec::new(),
agg_sig_amount: Vec::new(),
agg_sig_puzzle_amount: Vec::new(),
agg_sig_parent_amount: Vec::new(),
agg_sig_parent_puzzle: Vec::new(),
// assume it's eligible until we see an agg-sig condition
flags: ELIGIBLE_FOR_DEDUP,
};
);

let mut cost_left = max_cost - clvm_cost;

Expand Down
Loading