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

CHIA-1034 Rename Spend to SpendConditions and OwnedSpend to OwnedSpendConditions #656

Merged
merged 10 commits into from
Aug 13, 2024
4 changes: 2 additions & 2 deletions crates/chia-consensus/fuzz/fuzz_targets/parse-conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libfuzzer_sys::fuzz_target;

use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::conditions::{
parse_conditions, MempoolVisitor, ParseState, Spend, SpendBundleConditions,
parse_conditions, MempoolVisitor, ParseState, SpendBundleConditions, SpendConditions,
};
use chia_consensus::gen::spend_visitor::SpendVisitor;
use chia_protocol::Bytes32;
Expand Down Expand Up @@ -41,7 +41,7 @@ fuzz_target!(|data: &[u8]| {
let mut state = ParseState::default();

for flags in &[0, STRICT_ARGS_COUNT, NO_UNKNOWN_CONDS] {
let mut coin_spend = Spend {
let mut coin_spend = SpendConditions {
parent_id,
coin_amount: amount,
puzzle_hash,
Expand Down
166 changes: 83 additions & 83 deletions crates/chia-consensus/src/gen/conditions.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions crates/chia-consensus/src/gen/make_aggsig_final_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::gen::opcodes::{
ConditionOpcode, AGG_SIG_AMOUNT, AGG_SIG_ME, AGG_SIG_PARENT, AGG_SIG_PARENT_AMOUNT,
AGG_SIG_PARENT_PUZZLE, AGG_SIG_PUZZLE, AGG_SIG_PUZZLE_AMOUNT,
};
use crate::gen::owned_conditions::OwnedSpend;
use crate::gen::owned_conditions::OwnedSpendConditions;
use chia_protocol::Bytes;
use chia_protocol::Coin;

pub fn make_aggsig_final_message(
opcode: ConditionOpcode,
msg: &[u8],
spend: &OwnedSpend,
spend: &OwnedSpendConditions,
constants: &ConsensusConstants,
) -> Vec<u8> {
let mut result = Vec::<u8>::with_capacity(msg.len() + 96);
Expand Down Expand Up @@ -114,7 +114,7 @@ mod tests {

use chia_protocol::Bytes32;

use crate::r#gen::conditions::Spend;
use crate::r#gen::conditions::SpendConditions;

let parent_id: Vec<u8> =
hex!("4444444444444444444444444444444444444444444444444444444444444444").into();
Expand Down Expand Up @@ -178,15 +178,15 @@ mod tests {
_ => {}
};
let mut a: Allocator = make_allocator(LIMIT_HEAP);
let spend = Spend::new(
let spend = SpendConditions::new(
a.new_atom(parent_id.as_slice()).expect("should pass"),
coin_amount,
a.new_atom(puzzle_hash.as_slice())
.expect("test should pass"),
Arc::new(Bytes32::try_from(coin.coin_id()).expect("test should pass")),
);

let spend = OwnedSpend::from(&a, spend);
let spend = OwnedSpendConditions::from(&a, spend);

let result = make_aggsig_final_message(opcode, msg, &spend, &TEST_CONSTANTS);
assert_eq!(result, expected_result);
Expand Down
16 changes: 8 additions & 8 deletions crates/chia-consensus/src/gen/owned_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use chia_protocol::{Bytes, Bytes32};
use chia_streamable_macro::Streamable;
use clvmr::{Allocator, NodePtr};

use super::conditions::{Spend, SpendBundleConditions};
use super::conditions::{SpendBundleConditions, SpendConditions};

#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::{PyJsonDict, PyStreamable};

#[derive(Streamable, Hash, Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
feature = "py-bindings",
pyo3::pyclass(name = "Spend", get_all, frozen),
pyo3::pyclass(name = "SpendConditions", get_all, frozen),
derive(PyJsonDict, PyStreamable)
)]
pub struct OwnedSpend {
pub struct OwnedSpendConditions {
pub coin_id: Bytes32,
pub parent_id: Bytes32,
pub puzzle_hash: Bytes32,
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct OwnedSpend {
derive(PyJsonDict, PyStreamable)
)]
pub struct OwnedSpendBundleConditions {
pub spends: Vec<OwnedSpend>,
pub spends: Vec<OwnedSpendConditions>,
pub reserve_fee: u64,
// the highest height/time conditions (i.e. most strict)
pub height_absolute: u32,
Expand All @@ -62,8 +62,8 @@ pub struct OwnedSpendBundleConditions {
pub addition_amount: u128,
}

impl OwnedSpend {
pub fn from(a: &Allocator, spend: Spend) -> Self {
impl OwnedSpendConditions {
pub fn from(a: &Allocator, spend: SpendConditions) -> Self {
let mut create_coin =
Vec::<(Bytes32, u64, Option<Bytes>)>::with_capacity(spend.create_coin.len());
for c in spend.create_coin {
Expand Down Expand Up @@ -112,9 +112,9 @@ impl OwnedSpend {

impl OwnedSpendBundleConditions {
pub fn from(a: &Allocator, sb: SpendBundleConditions) -> Self {
let mut spends = Vec::<OwnedSpend>::new();
let mut spends = Vec::<OwnedSpendConditions>::new();
for s in sb.spends {
spends.push(OwnedSpend::from(a, s));
spends.push(OwnedSpendConditions::from(a, s));
}

let mut agg_sigs = Vec::<(PublicKey, Bytes)>::with_capacity(sb.agg_sig_unsafe.len());
Expand Down
6 changes: 4 additions & 2 deletions crates/chia-consensus/src/gen/run_puzzle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::consensus_constants::ConsensusConstants;
use crate::gen::conditions::{parse_conditions, ParseState, Spend, SpendBundleConditions};
use crate::gen::conditions::{
parse_conditions, ParseState, SpendBundleConditions, SpendConditions,
};
use crate::gen::flags::ALLOW_BACKREFS;
use crate::gen::spend_visitor::SpendVisitor;
use crate::gen::validation_error::ValidationErr;
Expand Down Expand Up @@ -51,7 +53,7 @@ pub fn run_puzzle<V: SpendVisitor>(
.coin_id(),
);

let mut spend = Spend::new(
let mut spend = SpendConditions::new(
a.new_atom(parent_id)?,
amount,
a.new_atom(&puzzle_hash)?,
Expand Down
8 changes: 4 additions & 4 deletions crates/chia-consensus/src/gen/spend_visitor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::gen::conditions::{Condition, Spend};
use crate::gen::conditions::{Condition, SpendConditions};
use clvmr::allocator::Allocator;

// These are customization points for the condition parsing and validation. The
// mempool wants to record additional information than plain consensus
// validation, so it hooks into these.
pub trait SpendVisitor {
fn new_spend(spend: &mut Spend) -> Self;
fn condition(&mut self, spend: &mut Spend, c: &Condition);
fn post_spend(&mut self, a: &Allocator, spend: &mut Spend);
fn new_spend(spend: &mut SpendConditions) -> Self;
fn condition(&mut self, spend: &mut SpendConditions, c: &Condition);
fn post_spend(&mut self, a: &Allocator, spend: &mut SpendConditions);
}
4 changes: 2 additions & 2 deletions crates/chia-consensus/src/gen/test_generators.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::conditions::{MempoolVisitor, NewCoin, Spend, SpendBundleConditions};
use super::conditions::{MempoolVisitor, NewCoin, SpendBundleConditions, SpendConditions};
use super::run_block_generator::{run_block_generator, run_block_generator2};
use crate::allocator::make_allocator;
use crate::consensus_constants::TEST_CONSTANTS;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub(crate) fn print_conditions(a: &Allocator, c: &SpendBundleConditions) -> Stri
}
ret += "SPENDS:\n";

let mut spends: Vec<Spend> = c.spends.clone();
let mut spends: Vec<SpendConditions> = c.spends.clone();
spends.sort_by_key(|s| *s.coin_id);
for s in spends {
ret += &format!(
Expand Down
8 changes: 5 additions & 3 deletions crates/chia-tools/src/bin/test-block-generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use clap::Parser;

use chia_bls::PublicKey;
use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::conditions::{EmptyVisitor, NewCoin, Spend, SpendBundleConditions};
use chia_consensus::gen::conditions::{
EmptyVisitor, NewCoin, SpendBundleConditions, SpendConditions,
};
use chia_consensus::gen::flags::{ALLOW_BACKREFS, MEMPOOL_MODE};
use chia_consensus::gen::run_block_generator::{run_block_generator, run_block_generator2};
use chia_tools::iterate_tx_blocks;
Expand Down Expand Up @@ -75,7 +77,7 @@ fn compare_agg_sig(
}
}

fn compare_spend(a: &Allocator, lhs: &Spend, rhs: &Spend) {
fn compare_spend(a: &Allocator, lhs: &SpendConditions, rhs: &SpendConditions) {
assert_eq!(a.atom(lhs.parent_id), a.atom(rhs.parent_id));
assert_eq!(lhs.coin_amount, rhs.coin_amount);
assert_eq!(*lhs.coin_id, *rhs.coin_id);
Expand All @@ -97,7 +99,7 @@ fn compare_spend(a: &Allocator, lhs: &Spend, rhs: &Spend) {
assert_eq!(a.atom(lhs.puzzle_hash), a.atom(rhs.puzzle_hash));
}

fn compare_spends(a: &Allocator, lhs: &Vec<Spend>, rhs: &Vec<Spend>) {
fn compare_spends(a: &Allocator, lhs: &Vec<SpendConditions>, rhs: &Vec<SpendConditions>) {
assert_eq!(lhs.len(), rhs.len());

for (l, r) in std::iter::zip(lhs, rhs) {
Expand Down
Loading
Loading