-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tari engine for flow and wasm functions
- Loading branch information
1 parent
6c116ac
commit 470bd6a
Showing
108 changed files
with
2,405 additions
and
1,339 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright 2022 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
mod unit_of_work_tracker; | ||
|
||
pub use unit_of_work_tracker::UnitOfWorkTracker; |
47 changes: 47 additions & 0 deletions
47
dan_layer/common_types/src/storage/unit_of_work_tracker.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use std::sync::{ | ||
atomic::{AtomicBool, Ordering}, | ||
Arc, | ||
RwLock, | ||
RwLockReadGuard, | ||
RwLockWriteGuard, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct UnitOfWorkTracker<TItem> { | ||
item: Arc<RwLock<TItem>>, | ||
is_dirty: Arc<AtomicBool>, | ||
} | ||
|
||
impl<TItem> Clone for UnitOfWorkTracker<TItem> { | ||
fn clone(&self) -> Self { | ||
Self { | ||
item: self.item.clone(), | ||
is_dirty: self.is_dirty.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl<TItem> UnitOfWorkTracker<TItem> { | ||
pub fn new(item: TItem, is_dirty: bool) -> Self { | ||
Self { | ||
item: Arc::new(RwLock::new(item)), | ||
is_dirty: Arc::new(AtomicBool::new(is_dirty)), | ||
} | ||
} | ||
|
||
pub fn get(&self) -> RwLockReadGuard<TItem> { | ||
self.item.read().unwrap() | ||
} | ||
|
||
pub fn get_mut(&self) -> RwLockWriteGuard<TItem> { | ||
self.is_dirty.store(true, Ordering::SeqCst); | ||
self.item.write().unwrap() | ||
} | ||
|
||
pub fn is_dirty(&self) -> bool { | ||
self.is_dirty.load(Ordering::SeqCst) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2022 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use std::{ | ||
convert::TryFrom, | ||
fmt::{Display, Formatter}, | ||
str::FromStr, | ||
}; | ||
|
||
#[derive(Copy, Clone, Debug)] | ||
pub enum TemplateId { | ||
Tip002 = 2, | ||
Tip003 = 3, | ||
Tip004 = 4, | ||
Tip721 = 721, | ||
EditableMetadata = 20, | ||
} | ||
|
||
impl FromStr for TemplateId { | ||
type Err = String; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"Tip002" => Ok(TemplateId::Tip002), | ||
"Tip003" => Ok(TemplateId::Tip003), | ||
"Tip004" => Ok(TemplateId::Tip004), | ||
"Tip721" => Ok(TemplateId::Tip721), | ||
"EditableMetadata" => Ok(TemplateId::EditableMetadata), | ||
_ => { | ||
println!("Unrecognised template"); | ||
Err(format!("Unrecognised template ID '{}'", s)) | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<u32> for TemplateId { | ||
type Error = String; | ||
|
||
fn try_from(value: u32) -> Result<Self, Self::Error> { | ||
match value { | ||
2 => Ok(TemplateId::Tip002), | ||
3 => Ok(TemplateId::Tip003), | ||
4 => Ok(TemplateId::Tip004), | ||
721 => Ok(TemplateId::Tip721), | ||
_ => Err(format!("Unknown value: {}", value)), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<i32> for TemplateId { | ||
type Error = String; | ||
|
||
fn try_from(value: i32) -> Result<Self, Self::Error> { | ||
u32::try_from(value) | ||
.map_err(|_| { | ||
format!( | ||
"Could not convert to TemplateId because it was not a valid u32:{}", | ||
value | ||
) | ||
})? | ||
.try_into() | ||
} | ||
} | ||
|
||
impl Display for TemplateId { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{:?}", self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.