diff --git a/cli/src/wallets/memory_wallet.rs b/cli/src/wallets/memory_wallet.rs index e19dcc9..bfc5280 100644 --- a/cli/src/wallets/memory_wallet.rs +++ b/cli/src/wallets/memory_wallet.rs @@ -145,7 +145,7 @@ impl WalletStore for MemoryWalletStore { { None => Err(Error::new( ErrorKind::NotFound, - format!("Failed to find public_key: {public_key})"), + format!("Failed to find secret_key for pub_key: {public_key})"), )), Some(v) => { let secret_key = SecretKey::from_bytes(v.value().as_ref()).map_err(|e| { diff --git a/cli/src/wallets/mod.rs b/cli/src/wallets/mod.rs index 3e60be0..0ceaa57 100644 --- a/cli/src/wallets/mod.rs +++ b/cli/src/wallets/mod.rs @@ -147,6 +147,7 @@ pub trait WalletStore { hardened: bool, ) -> Result { let wallet_sk = self.wallet_sk(index, hardened)?; + let _ = self.secret_key_store().save_secret_key(&wallet_sk); let pubkey = Bytes48::from(wallet_sk.sk_to_pk().to_bytes()); let puzzle_hash = puzzle_hash_for_pk(&pubkey)?; self.add_puzzle_hash_and_keys(puzzle_hash, (Bytes32::from(wallet_sk), pubkey)) diff --git a/core/src/blockchain/condition_opcode.rs b/core/src/blockchain/condition_opcode.rs index b3e3062..23c3163 100644 --- a/core/src/blockchain/condition_opcode.rs +++ b/core/src/blockchain/condition_opcode.rs @@ -37,6 +37,8 @@ pub enum ConditionOpcode { AssertPuzzleAnnouncement = 63, AssertConcurrentSpend = 64, AssertConcurrentPuzzle = 65, + SendMessage = 66, + ReceiveMessage = 67, AssertMyCoinId = 70, AssertMyParentId = 71, AssertMyPuzzlehash = 72, diff --git a/core/src/blockchain/condition_with_args.rs b/core/src/blockchain/condition_with_args.rs index abe3f90..3187d14 100644 --- a/core/src/blockchain/condition_with_args.rs +++ b/core/src/blockchain/condition_with_args.rs @@ -1,5 +1,5 @@ use crate::blockchain::condition_opcode::ConditionOpcode; -use crate::clvm::sexp::{IntoSExp, SExp, NULL}; +use crate::clvm::sexp::{AtomBuf, IntoSExp, SExp, NULL}; use dg_xch_macros::ChiaSerial; use serde::{Deserialize, Serialize}; @@ -11,13 +11,21 @@ pub struct ConditionWithArgs { impl IntoSExp for &ConditionWithArgs { fn to_sexp(self) -> SExp { let mut vars = vec![]; - for var in &self.vars { - vars.push(var.as_slice().to_sexp()); + for var in self.vars.iter().rev() { + vars.push(SExp::Atom(AtomBuf::from(var))); } - let mut args_pair = NULL.clone(); + let mut args_pair = None; for var in vars.into_iter().rev() { - args_pair = args_pair.cons(var) + match args_pair { + None => args_pair = Some(var), + Some(pair) => args_pair = Some(pair.cons(var)), + } } - self.opcode.to_sexp().cons(args_pair) + self.opcode.to_sexp().cons(args_pair.unwrap_or_else(|| NULL.clone())) + } +} +impl IntoSExp for ConditionWithArgs { + fn to_sexp(self) -> SExp { + (&self).to_sexp() } } diff --git a/core/src/clvm/condition_utils.rs b/core/src/clvm/condition_utils.rs index 5d30620..2ca1b34 100644 --- a/core/src/clvm/condition_utils.rs +++ b/core/src/clvm/condition_utils.rs @@ -8,6 +8,7 @@ use crate::clvm::sexp::{IntoSExp, SExp}; use num_traits::ToPrimitive; use std::collections::HashMap; use std::io::{Error, ErrorKind}; +use log::info; pub type ConditionsDict = HashMap, S>; @@ -85,7 +86,9 @@ pub fn conditions_dict_for_solution( ) -> Result<(ConditionsDict, u64), Error> { match conditions_for_solution(puzzle_reveal, solution, max_cost) { Ok((result, cost)) => Ok((conditions_by_opcode(result), cost)), - Err(error) => Err(error), + Err(error) => { + Err(error) + }, } } @@ -95,10 +98,18 @@ pub fn conditions_for_solution( max_cost: u64, ) -> Result<(Vec, u64), Error> { match puzzle_reveal.run_with_cost(max_cost, &solution.to_program()) { - Ok((cost, r)) => match parse_sexp_to_conditions(&r.to_sexp()) { - Ok(conditions) => Ok((conditions, cost)), - Err(error) => Err(error), + Ok((cost, r)) => { + match parse_sexp_to_conditions(&r.to_sexp()) { + Ok(conditions) => Ok((conditions, cost)), + Err(error) => { + info!("{error:?}"); + Err(error) + }, + } + }, + Err(error) => { + info!("{error:?}"); + Err(error) }, - Err(error) => Err(error), } } diff --git a/core/src/clvm/sexp.rs b/core/src/clvm/sexp.rs index 7720633..a9744a6 100644 --- a/core/src/clvm/sexp.rs +++ b/core/src/clvm/sexp.rs @@ -5,8 +5,6 @@ use crate::blockchain::sized_bytes::{ use crate::clvm::assemble::is_hex; use crate::clvm::assemble::keywords::KEYWORD_FROM_ATOM; use crate::clvm::program::Program; -use dg_xch_serialize::ChiaProtocolVersion; -use dg_xch_serialize::ChiaSerialize; use hex::encode; use num_bigint::BigInt; use once_cell::sync::Lazy; @@ -424,31 +422,18 @@ pub trait TryIntoSExp { } impl IntoSExp for Vec { - fn to_sexp(mut self) -> SExp { - if self.is_empty() { - return SExp::Pair(PairBuf::from((&*NULL, &*NULL))); - } - if self.len() == 1 { - return SExp::Pair(PairBuf::from((&self[0], &*NULL))); - } - if self.len() == 2 { - let last = self.pop().expect("Len Was Checked to Be 2"); - let first = self.pop().expect("Len Was Checked to Be 2"); - return SExp::Pair(PairBuf::from((first, last))); - } - let mut prog = None; - while let Some(next) = self.pop() { - match prog { - None => { - prog = Some(next); - } - Some(existing) => { - let new = next.cons(existing); - prog = Some(new); + fn to_sexp(self) -> SExp { + if let Some(sexp) = self.first().cloned() { + let mut end = NULL.clone(); + if self.len() > 1 { + for other in self[1..].iter().rev() { + end = other.clone().cons(end); } } + sexp.cons(end) + } else { + NULL.clone() } - prog.expect("Expected Program, Lengths Checked Above") } } @@ -471,6 +456,15 @@ impl IntoSExp for Vec { } } +impl IntoSExp for Option { + fn to_sexp(self) -> SExp { + match self { + None => NULL.clone(), + Some(s) => s.to_sexp() + } + } +} + impl IntoSExp for (T, T) { fn to_sexp(self) -> SExp { self.0.to_sexp().cons(self.1.to_sexp()) @@ -509,7 +503,7 @@ impl IntoSExp for &Program { impl IntoSExp for ConditionOpcode { fn to_sexp(self) -> SExp { - SExp::Atom(AtomBuf::new(self.to_bytes(ChiaProtocolVersion::default()))) + SExp::Atom(AtomBuf::new(vec![self as u8])) } }