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 60be388
Show file tree
Hide file tree
Showing 41 changed files with 372 additions and 175 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.

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
2 changes: 0 additions & 2 deletions dan_layer/template_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tari_template_types = { path = "../template_types" }

borsh = "0.9.3"
4 changes: 1 addition & 3 deletions dan_layer/template_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@

mod abi;
pub use abi::*;
pub use borsh::{self, BorshDeserialize as Decode, BorshSerialize as Encode};
pub use borsh::{BorshDeserialize as Decode, BorshSerialize as Encode};

mod encoding;
pub use encoding::{decode, decode_len, encode, encode_into, encode_with_len};

pub mod ops;

mod types;
pub use types::*;
Loading

0 comments on commit 60be388

Please sign in to comment.