Skip to content

Commit

Permalink
refactor: remove template_types, add bucket,vault generic
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 9, 2022
1 parent a907e27 commit 1ca3eec
Show file tree
Hide file tree
Showing 42 changed files with 388 additions and 176 deletions.
23 changes: 7 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ use async_trait::async_trait;
use log::*;
use tari_common_types::types::FixedHash;
use tari_comms::types::CommsPublicKey;
use tari_comms_dht::{domain_message::OutboundDomainMessage, outbound::OutboundMessageRequester};
use tari_comms_dht::{
domain_message::OutboundDomainMessage,
envelope::NodeDestination,
outbound::{OutboundEncryption, OutboundMessageRequester},
};
use tari_dan_core::{
models::{HotStuffMessage, Payload, TariDanPayload},
services::infrastructure_services::OutboundService,
Expand Down Expand Up @@ -90,6 +94,17 @@ impl OutboundService for TariCommsOutboundService<TariDanPayload> {
let inner = proto::consensus::HotStuffMessage::from(message);
let tari_message = OutboundDomainMessage::new(&TariMessageType::DanConsensusMessage, inner);

// task::spawn(async move {
// loop {
// //read msg from channel
// let msg = channel.next().await?;
// //propagate
//
self.outbound_message_requester
.broadcast(NodeDestination::Unknown, OutboundEncryption::ClearText, vec![], msg)
.await?;
// }
// })
self.outbound_message_requester.send_direct(to, tari_message).await?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "
tari_dan_common_types = { path = "../common_types" }
tari_mmr = { path = "../../base_layer/mmr" }
tari_template_abi = { path = "../template_abi" }
tari_template_types = { path = "../template_types", features = ["serde"] }
tari_template_lib = { path = "../template_lib", features = ["serde"] }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.5" }

anyhow = "1.0.53"
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/engine/src/instruction/error.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 tari_template_types::models::PackageId;
use tari_template_lib::models::PackageId;

use crate::{runtime::RuntimeError, wasm::WasmExecutionError};

Expand Down
2 changes: 1 addition & 1 deletion dan_layer/engine/src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use processor::InstructionProcessor;

mod signature;
pub use signature::InstructionSignature;
use tari_template_types::models::{ComponentId, PackageId};
use tari_template_lib::models::{ComponentId, PackageId};

#[derive(Debug, Clone)]
pub enum Instruction {
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/engine/src/instruction/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::{collections::HashMap, sync::Arc};

use tari_template_abi::encode;
use tari_template_types::models::PackageId;
use tari_template_lib::models::PackageId;

use crate::{
instruction::{error::InstructionError, Instruction, InstructionSet},
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/engine/src/models/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_template_abi::{CreateComponentArg, Decode, Encode};
use tari_template_types::{
use tari_template_lib::{
models::{ContractAddress, PackageId},
Hash,
};
Expand Down
16 changes: 15 additions & 1 deletion dan_layer/engine/src/models/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,32 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_template_abi::{Decode, Encode};
use tari_template_types::Hash;
use tari_template_lib::Hash;

pub type ResourceAddress = Hash;

#[derive(Debug, Clone, Encode, Decode, serde::Deserialize)]
pub enum Resource {
Coin {
address: ResourceAddress,
// type_descriptor: TypeDescriptor,
amount: u64,
},
Token {
address: ResourceAddress,
// type_descriptor: TypeDescriptor,
token_ids: Vec<u64>,
},
}

pub trait ResourceTypeDescriptor {
fn type_descriptor(&self) -> TypeDescriptor;
}

// The thinking here, that a resource address + a "local" type id together can used to validate type safety of the
// resources at runtime. The local type id can be defined as a unique id within the scope of the contract. We'll have to
// get further to see if this can work or is even needed.
#[derive(Debug, Clone, Encode, Decode, serde::Deserialize)]
pub struct TypeDescriptor {
type_id: u16,
}
13 changes: 7 additions & 6 deletions dan_layer/engine/src/models/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// 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 borsh::{BorshDeserialize, BorshSerialize};

use crate::models::resource::ResourceAddress;
use tari_template_abi::{Decode, Encode};

#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
use crate::models::Resource;

#[derive(Debug, Clone, Encode, Decode)]
pub struct Vault {
address: ResourceAddress,
resource: Resource,
}

impl Vault {
pub fn new(address: ResourceAddress) -> Self {
Self { address }
pub fn new(resource: Resource) -> Self {
Self { resource }
}
}
2 changes: 1 addition & 1 deletion dan_layer/engine/src/packager/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::collections::HashMap;

use digest::Digest;
use rand::{rngs::OsRng, RngCore};
use tari_template_types::models::PackageId;
use tari_template_lib::models::PackageId;

use crate::{
crypto,
Expand Down
6 changes: 4 additions & 2 deletions dan_layer/engine/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ use std::{
};

use tari_common_types::types::FixedHash;
use tari_template_abi::LogLevel;
use tari_template_types::models::{Component, ComponentId, ComponentInstance};
use tari_template_lib::{
args::LogLevel,
models::{Component, ComponentId, ComponentInstance},
};

use crate::{models::Bucket, state_store::StateStoreError};

Expand Down
31 changes: 16 additions & 15 deletions dan_layer/engine/src/wasm/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@
use std::io;

use borsh::{BorshDeserialize, BorshSerialize};
use tari_template_abi::{
decode,
encode_into,
encode_with_len,
use tari_template_abi::{decode, encode, encode_into, encode_with_len, CallInfo, Type};
use tari_template_lib::{
abi_context::AbiContext,
args::{CreateComponentArg, EmitLogArg, GetComponentArg, SetComponentStateArg},
models::{Component, Contract, ContractAddress, Package, PackageId},
ops,
CallInfo,
CreateComponentArg,
EmitLogArg,
GetComponentArg,
SetComponentStateArg,
Type,
};
use tari_template_types::models::{Component, Contract, ContractAddress, PackageId};
use wasmer::{Function, Instance, Module, Store, Val, WasmerEnv};

use crate::{
Expand Down Expand Up @@ -148,6 +142,16 @@ impl Process {
// out-of-bounds access error.
Ok(ptr.as_i32())
}

fn encoded_abi_context(&self) -> Vec<u8> {
encode(&AbiContext {
package: Package { id: self.package_id },
contract: Contract {
address: self.contract_address,
},
})
.unwrap()
}
}

impl Invokable for Process {
Expand All @@ -160,10 +164,7 @@ impl Invokable for Process {
.ok_or_else(|| WasmExecutionError::FunctionNotFound { name: name.into() })?;

let call_info = CallInfo {
contract: Contract {
address: self.contract_address,
},
package: tari_template_types::models::Package { id: self.package_id },
abi_context: self.encoded_abi_context(),
func_name: func_def.name.clone(),
args,
};
Expand Down
12 changes: 1 addition & 11 deletions dan_layer/engine/tests/hello_world/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dan_layer/engine/tests/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition = "2021"
tari_template_abi = { path = "../../../template_abi" }
tari_template_lib = { path = "../../../template_lib" }
tari_template_macros = { path = "../../../template_macros" }
tari_template_types = { path = "../../../template_types" }

[profile.release]
opt-level = 's' # Optimize for size.
Expand Down
6 changes: 4 additions & 2 deletions dan_layer/engine/tests/mock_runtime_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ use tari_dan_engine::{
runtime::{RuntimeError, RuntimeInterface},
state_store::{memory::MemoryStateStore, AtomicDb, StateReader, StateWriter},
};
use tari_template_abi::LogLevel;
use tari_template_types::models::{Component, ComponentId, ComponentInstance};
use tari_template_lib::{
args::LogLevel,
models::{Component, ComponentId, ComponentInstance},
};

#[derive(Debug, Clone, Default)]
pub struct MockRuntimeInterface {
Expand Down
12 changes: 1 addition & 11 deletions dan_layer/engine/tests/state/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dan_layer/engine/tests/state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition = "2021"
tari_template_abi = { path = "../../../template_abi" }
tari_template_lib = { path = "../../../template_lib" }
tari_template_macros = { path = "../../../template_macros" }
tari_template_types = { path = "../../../template_types" }

[profile.release]
opt-level = 's' # Optimize for size.
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/engine/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tari_dan_engine::{
wasm::compile::compile_template,
};
use tari_template_abi::encode;
use tari_template_types::models::{ComponentId, ComponentInstance, PackageId};
use tari_template_lib::models::{ComponentId, ComponentInstance, PackageId};

#[test]
fn test_hello_world() {
Expand Down
Loading

0 comments on commit 1ca3eec

Please sign in to comment.