Skip to content

Commit

Permalink
chore: fix build and osp (tari-project#6415)
Browse files Browse the repository at this point in the history
Description
---
Fixes build
Fixes original one-sided transaction script persistence
Ensures that spend key is always calculated correctly
  • Loading branch information
SWvheerden authored Jul 19, 2024
1 parent e377f4b commit 54bccd7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 31 deletions.
18 changes: 13 additions & 5 deletions applications/minotari_merge_mining_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{
cmp,
convert::TryInto,
future::Future,
panic,
pin::Pin,
sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -648,11 +649,18 @@ impl InnerService {
.iter()
.position(|x| x == &last_used_url)
.unwrap_or(0);
let (left, right) = self
.config
.monerod_url
.split_at_checked(pos)
.ok_or(MmProxyError::ConversionError("Invalid utf 8 url".to_string()))?;
// replace after rust stable 1.80 release
// let (left, right) = self
// .config
// .monerod_url
// .split_at_checked(pos)
// .ok_or(MmProxyError::ConversionError("Invalid utf 8 url".to_string()))?;
let url = self.config.monerod_url.clone();
let result = panic::catch_unwind(|| url.split_at(pos));
let (left, right) = match result {
Ok((left, right)) => (left, right),
Err(_) => return Err(MmProxyError::ConversionError("Invalid utf 8 url".to_string())),
};
let left = left.to_vec();
let right = right.to_vec();
let iter = right.iter().chain(left.iter()).chain(right.iter()).chain(left.iter());
Expand Down
16 changes: 13 additions & 3 deletions base_layer/common_types/src/tari_address/dual_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::convert::TryFrom;
use std::{convert::TryFrom, panic};

use serde::{Deserialize, Serialize};
use tari_common::configuration::Network;
Expand Down Expand Up @@ -162,8 +162,18 @@ impl DualAddress {
if hex_str.len() != 90 && hex_str.len() != 91 {
return Err(TariAddressError::InvalidSize);
}
let (first, rest) = hex_str.split_at_checked(2).ok_or(TariAddressError::InvalidCharacter)?;
let (network, features) = first.split_at_checked(1).ok_or(TariAddressError::InvalidCharacter)?;
let result = panic::catch_unwind(|| hex_str.split_at(2));
let (first, rest) = match result {
Ok((first, rest)) => (first, rest),
Err(_) => return Err(TariAddressError::InvalidCharacter),
};
let result = panic::catch_unwind(|| first.split_at(1));
let (network, features) = match result {
Ok((network, features)) => (network, features),
Err(_) => return Err(TariAddressError::InvalidCharacter),
};
// let (first, rest) = hex_str.split_at_checked(2).ok_or(TariAddressError::InvalidCharacter)?;
// let (network, features) = first.split_at_checked(1).ok_or(TariAddressError::InvalidCharacter)?;
let mut result = bs58::decode(network)
.into_vec()
.map_err(|_| TariAddressError::CannotRecoverNetwork)?;
Expand Down
16 changes: 14 additions & 2 deletions base_layer/common_types/src/tari_address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod single_address;
use std::{
fmt,
fmt::{Display, Error, Formatter},
panic,
str::FromStr,
};

Expand Down Expand Up @@ -248,8 +249,19 @@ impl TariAddress {
if hex_str.len() < 47 {
return Err(TariAddressError::InvalidSize);
}
let (first, rest) = hex_str.split_at_checked(2).ok_or(TariAddressError::InvalidCharacter)?;
let (network, features) = first.split_at_checked(1).ok_or(TariAddressError::InvalidCharacter)?;
let result = panic::catch_unwind(|| hex_str.split_at(2));
let (first, rest) = match result {
Ok((first, rest)) => (first, rest),
Err(_) => return Err(TariAddressError::InvalidCharacter),
};
let result = panic::catch_unwind(|| first.split_at(1));
let (network, features) = match result {
Ok((network, features)) => (network, features),
Err(_) => return Err(TariAddressError::InvalidCharacter),
};
// replace this after 1.80 stable
// let (first, rest) = hex_str.split_at_checked(2).ok_or(TariAddressError::InvalidCharacter)?;
// let (network, features) = first.split_at_checked(1).ok_or(TariAddressError::InvalidCharacter)?;
let mut result = bs58::decode(network)
.into_vec()
.map_err(|_| TariAddressError::CannotRecoverNetwork)?;
Expand Down
16 changes: 13 additions & 3 deletions base_layer/common_types/src/tari_address/single_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::convert::TryFrom;
use std::{convert::TryFrom, panic};

use serde::{Deserialize, Serialize};
use tari_common::configuration::Network;
Expand Down Expand Up @@ -145,8 +145,18 @@ impl SingleAddress {
if hex_str.len() != 46 && hex_str.len() != 47 && hex_str.len() != 48 {
return Err(TariAddressError::InvalidSize);
}
let (first, rest) = hex_str.split_at_checked(2).ok_or(TariAddressError::InvalidCharacter)?;
let (network, features) = first.split_at_checked(1).ok_or(TariAddressError::InvalidCharacter)?;
let result = panic::catch_unwind(|| hex_str.split_at(2));
let (first, rest) = match result {
Ok((first, rest)) => (first, rest),
Err(_) => return Err(TariAddressError::InvalidCharacter),
};
let result = panic::catch_unwind(|| first.split_at(1));
let (network, features) = match result {
Ok((network, features)) => (network, features),
Err(_) => return Err(TariAddressError::InvalidCharacter),
};
// let (first, rest) = hex_str.split_at_checked(2).ok_or(TariAddressError::InvalidCharacter)?;
// let (network, features) = first.split_at_checked(1).ok_or(TariAddressError::InvalidCharacter)?;
let mut result = bs58::decode(network)
.into_vec()
.map_err(|_| TariAddressError::CannotRecoverNetwork)?;
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/transactions/key_manager/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
let index = 0;

match self.wallet_type {
WalletType::Software | WalletType::Imported(_) => {
WalletType::DerivedKeys | WalletType::ProvidedKeys(_) => {
self.get_private_key(&TariKeyId::Managed {
branch: branch.clone(),
index,
Expand Down
29 changes: 16 additions & 13 deletions base_layer/wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,18 @@ where
} else {
None
};

persist_one_sided_payment_script_for_node_identity(&mut output_manager_handle, &node_identity)
.await
.map_err(|e| {
error!(target: LOG_TARGET, "{:?}", e);
e
})?;
let spend_key = key_manager_handle.get_spend_key().await?;

persist_one_sided_payment_script_for_node_identity(
&mut output_manager_handle,
&spend_key.pub_key,
spend_key.key_id,
)
.await
.map_err(|e| {
error!(target: LOG_TARGET, "{:?}", e);
e
})?;

wallet_database.set_node_features(comms.node_identity().features())?;
let identity_sig = comms.node_identity().identity_signature_read().as_ref().cloned();
Expand Down Expand Up @@ -835,18 +840,16 @@ pub fn derive_comms_secret_key(master_seed: &CipherSeed) -> Result<CommsSecretKe
/// using old node identities.
async fn persist_one_sided_payment_script_for_node_identity(
output_manager_service: &mut OutputManagerHandle,
node_identity: &Arc<NodeIdentity>,
spend_key: &PublicKey,
spend_key_id: TariKeyId,
) -> Result<(), WalletError> {
let script = push_pubkey_script(node_identity.public_key());
let wallet_node_key_id = TariKeyId::Imported {
key: node_identity.public_key().clone(),
};
let script = push_pubkey_script(spend_key);
let known_script = KnownOneSidedPaymentScript {
script_hash: script
.as_hash::<Blake2b<U32>>()
.map_err(|e| WalletError::OutputManagerError(OutputManagerError::ScriptError(e)))?
.to_vec(),
script_key_id: wallet_node_key_id.clone(),
script_key_id: spend_key_id,
script,
input: ExecutionStack::default(),
script_lock_height: 0,
Expand Down
16 changes: 12 additions & 4 deletions common/src/build/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::{
fmt,
fs,
io::Write,
panic,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -128,10 +129,17 @@ fn get_commit() -> Result<String, anyhow::Error> {
let repo = git2::Repository::open(git_root)?;
let head = repo.revparse_single("HEAD")?;
let id = format!("{:?}", head.id());
id.split_at_checked(7)
.ok_or(anyhow::anyhow!("invalid utf8 in commit id"))?
.0
.to_string();
let result = panic::catch_unwind(|| id.split_at(7));
let id = match result {
Ok((first, _)) => first.to_string(),
Err(_) => return Err(anyhow::anyhow!("invalid utf8 in commit id")),
};

// replace after stable 1.80 release
// id.split_at_checked(7)
// .ok_or(anyhow::anyhow!("invalid utf8 in commit id"))?
// .0
// .to_string();
Ok(id)
}

Expand Down

0 comments on commit 54bccd7

Please sign in to comment.