Skip to content
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
7 changes: 5 additions & 2 deletions applications/tari_indexer/src/storage_sqlite/models/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

use std::str::FromStr;

use tari_engine_types::{Utxo, UtxoAddress, UtxoId, UtxoOutput};
use tari_engine_types::{Utxo, UtxoOutput};
use tari_ootle_common_types::StateVersion;
use tari_ootle_storage::{time::PrimitiveDateTime, StorageError};
use tari_ootle_wallet_sdk::models::{UtxoBurnt, UtxoSpent, UtxoUnspent, WalletUtxoUpdate};
use tari_template_lib::prelude::{PedersenCommitmentBytes, ResourceAddress};
use tari_template_lib::{
models::{UtxoAddress, UtxoId},
prelude::{PedersenCommitmentBytes, ResourceAddress},
};

use crate::storage_sqlite::{schema::utxos, serialization::deserialize_bincode};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// SPDX-License-Identifier: BSD-3-Clause

use tari_bor::{Deserialize, Serialize};
use tari_engine_types::{UtxoAddress, UtxoOutput};
use tari_engine_types::UtxoOutput;
use tari_ootle_common_types::{shard::Shard, StateVersion};
use tari_template_lib::models::UtxoAddress;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UtxoUpdateRecord {
Expand Down
3 changes: 1 addition & 2 deletions applications/tari_indexer/src/storage_sqlite/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ use tari_consensus_types::BlockId;
use tari_engine_types::{
substate::{SubstateId, SubstateValue},
Utxo,
UtxoId,
};
use tari_indexer_client::types::{ListSubstateItem, NonFungibleSubstate, TransactionEntry};
use tari_ootle_common_types::{shard::Shard, substate_type::SubstateType, Epoch, ShardGroup, StateVersion};
use tari_ootle_storage::{time::PrimitiveDateTime, StorageError};
use tari_ootle_storage_sqlite::SqliteTransaction;
use tari_ootle_wallet_sdk::models::WalletUtxoUpdate;
use tari_template_lib::{
models::ResourceAddress,
models::{ResourceAddress, UtxoId},
prelude::{RistrettoPublicKeyBytes, TemplateAddress},
types::crypto::UtxoTag,
};
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_indexer/src/storage_sqlite/store_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use diesel::{sql_query, Connection, RunQueryDsl, SqliteConnection};
use diesel_migrations::{EmbeddedMigrations, MigrationHarness};
use serde::{de::DeserializeOwned, Serialize};
use tari_consensus_types::BlockId;
use tari_engine_types::{events::Event, substate::SubstateId, Utxo, UtxoId};
use tari_engine_types::{events::Event, substate::SubstateId, Utxo};
use tari_indexer_client::types::{ListSubstateItem, NonFungibleSubstate, TransactionEntry};
use tari_ootle_common_types::{shard::Shard, substate_type::SubstateType, Epoch, ShardGroup, StateVersion};
use tari_ootle_storage::{
Expand All @@ -23,7 +23,7 @@ use tari_ootle_storage::{
use tari_ootle_storage_sqlite::{error::SqliteStorageError, SqliteTransaction};
use tari_ootle_wallet_sdk::models::WalletUtxoUpdate;
use tari_template_lib::{
models::ResourceAddress,
models::{ResourceAddress, UtxoId},
types::{
crypto::{RistrettoPublicKeyBytes, UtxoTag},
TemplateAddress,
Expand Down
3 changes: 1 addition & 2 deletions applications/tari_indexer/src/substate_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use tari_common_types::types::FixedHash;
use tari_engine_types::{
substate::{Substate, SubstateId, SubstateValue},
Utxo,
UtxoId,
};
use tari_epoch_manager::service::EpochManagerHandle;
use tari_indexer_client::types::{ListSubstateItem, NonFungibleSubstate};
Expand All @@ -41,7 +40,7 @@ use tari_ootle_common_types::{
};
use tari_ootle_wallet_sdk::models::WalletUtxoUpdate;
use tari_template_lib::{
models::ResourceAddress,
models::{ResourceAddress, UtxoId},
types::{
crypto::{RistrettoPublicKeyBytes, UtxoTag},
TemplateAddress,
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/wallet_daemon_client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tari-project/wallet_jrpc_client",
"version": "1.7.2",
"version": "1.8.0",
"description": "Tari wallet JSON-RPC client library",
"homepage": "https://github.com/tari-project/tari-ootle#readme",
"bugs": {
Expand Down
3 changes: 1 addition & 2 deletions clients/tari_indexer_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ use tari_consensus_types::Decision;
use tari_engine_types::{
commit_result::ExecuteResult,
substate::{Substate, SubstateId, SubstateValue},
template_lib_models::{NonFungibleAddress, ResourceAddress},
template_lib_models::{NonFungibleAddress, ResourceAddress, UtxoId},
Utxo,
UtxoId,
};
use tari_ootle_common_types::{shard::Shard, substate_type::SubstateType, Epoch, StateVersion};
use tari_ootle_storage::time::PrimitiveDateTime;
Expand Down
3 changes: 1 addition & 2 deletions clients/wallet_daemon_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use tari_engine_types::{
instruction::Instruction,
serde_with,
substate::{Substate, SubstateId},
UtxoAddress,
ValidatorFeePoolAddress,
};
use tari_ootle_address::OotleAddress;
Expand All @@ -53,7 +52,7 @@ use tari_ootle_wallet_sdk::{
};
use tari_template_abi::{FunctionDef, TemplateDef};
use tari_template_lib::{
models::{ConfidentialOutputStatement, NonFungibleId, ResourceAddress, VaultId},
models::{ConfidentialOutputStatement, NonFungibleId, ResourceAddress, UtxoAddress, VaultId},
prelude::{ComponentAddress, ConfidentialWithdrawProof, ResourceType, RistrettoPublicKeyBytes},
types::{
crypto::{CommitmentSignatureBytes, PedersenCommitmentBytes, RangeProofBytes},
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/runtime/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ pub enum RuntimeError {
// To reduce the size of this variant, we box one of the fields
requested_owner: Box<SubstateId>,
},
#[error("Expected lock {lock_id} to lock {expected_type} but it locks {address}")]
#[error("Expected lock {lock_id} to lock {expected_type} but it locks {id}")]
LockSubstateMismatch {
lock_id: LockId,
expected_type: &'static str,
address: SubstateId,
id: SubstateId,
},
#[error("Component {component} referenced an unknown substate {id}")]
ComponentReferencedUnknownSubstate {
Expand Down
67 changes: 65 additions & 2 deletions crates/engine/src/runtime/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use tari_engine_types::{
ConvertFromByteType,
ResourceAddressRef,
Utxo,
UtxoAddress,
UtxoOutput,
ValidatorFeePoolAddress,
};
Expand Down Expand Up @@ -95,6 +94,7 @@ use tari_template_lib::{
ResourceGetNonFungibleArg,
ResourceRef,
ResourceUpdateNonFungibleDataArg,
SetFreezeStealthUtxosArg,
StealthTransferResourceArg,
VaultAction,
VaultCreateProofByFungibleAmountArg,
Expand All @@ -119,6 +119,7 @@ use tari_template_lib::{
ResourceAddress,
ResourceAddressAllocation,
StealthTransferStatement,
UtxoAddress,
VaultRef,
},
prelude::{ResourceType, RistrettoPublicKeyBytes},
Expand Down Expand Up @@ -1154,7 +1155,7 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate>> RuntimeInte
Ok(InvokeResult::unit())
})
},
ResourceAction::SetFreeze => {
ResourceAction::SetVaultFreeze => {
let resource_address =
resource_ref
.as_resource_address()
Expand Down Expand Up @@ -1220,6 +1221,68 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate>> RuntimeInte
&maybe_bucket.map(tari_template_lib::models::Bucket::from_id),
)?)
},
ResourceAction::SetStealthUtxosFreeze => {
let resource_address =
resource_ref
.as_resource_address()
.ok_or_else(|| RuntimeError::InvalidArgument {
argument: "resource_ref",
reason: "FreezeStealthUtxo resource action requires a resource address".to_string(),
})?;
let arg: SetFreezeStealthUtxosArg = args.assert_one_arg()?;

self.tracker.write_with(|state_mut| {
let resource_lock = state_mut.read_lock_substate(&SubstateId::Resource(resource_address))?;

let resource = state_mut.get_resource(&resource_lock)?;

if !resource.resource_type().is_stealth() {
return Err(RuntimeError::InvalidArgument {
argument: "resource_ref",
reason: "FreezeStealthUtxo can only be called on stealth resources".to_string(),
});
}

if arg.utxos.is_empty() {
return Err(RuntimeError::InvalidArgument {
argument: "SetFreezeStealthUtxosArg",
reason: "Utxos list cannot be empty".to_string(),
});
}

state_mut.authorization().check_resource_access_rules(
ResourceAuthAction::Freeze,
resource.as_ownership(),
resource.access_rules(),
)?;

for utxo in arg.utxos {
let id = SubstateId::Utxo(UtxoAddress::new(resource_address, utxo));
let locked = state_mut.write_lock_substate(&id)?;

let utxo = state_mut
.get_locked_substate_mut(&locked)?
.as_utxo_mut()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
expected_type: "Utxo",
id,
})?;

// Freeze is idempotent.
if arg.freeze {
utxo.freeze();
} else {
utxo.unfreeze();
}
state_mut.unlock_substate(locked)?;
}

state_mut.unlock_substate(resource_lock)?;

Ok(InvokeResult::unit())
})
},
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/engine/src/runtime/state_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use tari_engine_types::{
substate::{Substate, SubstateId, SubstateValue},
vault::Vault,
Utxo,
UtxoAddress,
};
use tari_ootle_common_types::optional::Optional;
use tari_template_lib::models::{ComponentAddress, VaultId};
use tari_template_lib::models::{ComponentAddress, UtxoAddress, VaultId};

use crate::{
runtime::{
Expand Down
3 changes: 1 addition & 2 deletions crates/engine/src/runtime/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ use tari_engine_types::{
logs::LogEntry,
substate::{SubstateId, SubstateValue},
virtual_substate::VirtualSubstates,
UtxoAddress,
};
use tari_ootle_common_types::Epoch;
use tari_template_lib::{
auth::{ComponentAccessRules, OwnerRule},
models::{ComponentAddress, ComponentAddressAllocation, Metadata, UnclaimedConfidentialOutputAddress},
models::{ComponentAddress, ComponentAddressAllocation, Metadata, UnclaimedConfidentialOutputAddress, UtxoAddress},
prelude::{RistrettoPublicKeyBytes, TemplateAddress},
types::Hash,
};
Expand Down
26 changes: 13 additions & 13 deletions crates/engine/src/runtime/working_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use tari_engine_types::{
ResourceAddressRef,
ToByteType,
Utxo,
UtxoAddress,
ValidatorFeePoolAddress,
ValidatorFeeWithdrawal,
};
Expand All @@ -54,6 +53,7 @@ use tari_template_lib::{
StealthInputsStatement,
StealthTransferStatement,
UnclaimedConfidentialOutputAddress,
UtxoAddress,
VaultId,
},
prelude::{AuthHookCaller, ResourceAddressAllocation, PUBLIC_IDENTITY_RESOURCE_ADDRESS},
Expand Down Expand Up @@ -204,7 +204,7 @@ impl WorkingState {
let (address, substate) = self.store.get_locked_substate(locked.lock_id())?;
let component = substate.component().ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
address,
id: address,
expected_type: "Component",
})?;
Ok(component)
Expand All @@ -222,7 +222,7 @@ impl WorkingState {
.component_mut()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
address: locked.substate_id().clone(),
id: locked.substate_id().clone(),
expected_type: "Component",
})?;

Expand Down Expand Up @@ -263,7 +263,7 @@ impl WorkingState {
.as_resource()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
address: addr,
id: addr,
expected_type: "Resource",
})?;

Expand Down Expand Up @@ -300,8 +300,8 @@ impl WorkingState {
let non_fungible = value
.as_non_fungible()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: 0,
address: address.clone(),
lock_id: locked.lock_id(),
id: address.clone(),
expected_type: "NonFungible",
})?;
Ok(non_fungible)
Expand All @@ -312,8 +312,8 @@ impl WorkingState {
let non_fungible = value
.as_non_fungible_mut()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: 0,
address: address.clone(),
lock_id: locked.lock_id(),
id: address.clone(),
expected_type: "NonFungible",
})?;
Ok(non_fungible)
Expand Down Expand Up @@ -342,7 +342,7 @@ impl WorkingState {

let vault = substate.as_vault().ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
address: addr,
id: addr,
expected_type: "Vault",
})?;

Expand All @@ -356,7 +356,7 @@ impl WorkingState {
.as_vault_mut()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
address: addr,
id: addr,
expected_type: "Vault",
})?;

Expand All @@ -370,7 +370,7 @@ impl WorkingState {
.as_resource_mut()
.ok_or_else(|| RuntimeError::LockSubstateMismatch {
lock_id: locked.lock_id(),
address: addr,
id: addr,
expected_type: "Resource",
})?;

Expand Down Expand Up @@ -1069,7 +1069,7 @@ impl WorkingState {
total_fees_paid: fee_resource
.amount()
.to_u64_checked()
.expect("FeeState guarantees that the total fee payments fit in a u64"),
.expect("FeeState guarantees that the total fee payments fit in an u64"),
total_fee_overcharge,
cost_breakdown: self.fee_state.take_fee_charges(),
},
Expand Down Expand Up @@ -1455,7 +1455,7 @@ impl WorkingState {
if !component.contains_substate(address)? {
warn!(
target: LOG_TARGET,
"Component {} attempted access to {} that is does not own",
"Component {} attempted access to {} that it does not own",
component_lock.substate_id(),
address
);
Expand Down
Loading
Loading