Skip to content

Commit

Permalink
Merge branch 'development' into upgrade-l1
Browse files Browse the repository at this point in the history
* development:
  refactor!: remove mempool execute, add faucet component, remove create free test coins (#1082)
  • Loading branch information
sdbondi committed Jul 24, 2024
2 parents 0194d70 + 7c3cda2 commit eac7031
Show file tree
Hide file tree
Showing 147 changed files with 3,035 additions and 3,166 deletions.
57 changes: 35 additions & 22 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 @@ -40,7 +40,12 @@ use tari_dan_engine::{
use tari_dan_storage::global::{DbTemplate, DbTemplateType, DbTemplateUpdate, GlobalDb, TemplateStatus};
use tari_dan_storage_sqlite::global::SqliteGlobalDbAdapter;
use tari_engine_types::calculate_template_binary_hash;
use tari_template_builtin::{get_template_builtin, ACCOUNT_NFT_TEMPLATE_ADDRESS, ACCOUNT_TEMPLATE_ADDRESS};
use tari_template_builtin::{
get_template_builtin,
ACCOUNT_NFT_TEMPLATE_ADDRESS,
ACCOUNT_TEMPLATE_ADDRESS,
FAUCET_TEMPLATE_ADDRESS,
};
use tari_template_lib::models::TemplateAddress;

use super::TemplateConfig;
Expand Down Expand Up @@ -90,36 +95,36 @@ impl<TAddr: NodeAddressable> TemplateManager<TAddr> {

fn load_builtin_templates() -> HashMap<TemplateAddress, Template> {
// for now, we only load the "account" template
let mut builtin_templates = HashMap::new();
let mut builtin_templates = HashMap::with_capacity(3);

// get the builtin WASM code of the account template
let compiled_code = get_template_builtin(&ACCOUNT_TEMPLATE_ADDRESS);
let template = Self::load_builtin_template("account", ACCOUNT_TEMPLATE_ADDRESS, compiled_code.to_vec());
let template = Self::convert_code_to_template("Account", ACCOUNT_TEMPLATE_ADDRESS, compiled_code.to_vec());
builtin_templates.insert(ACCOUNT_TEMPLATE_ADDRESS, template);

// get the builtin WASM code of the account nft template
let compiled_code = get_template_builtin(&ACCOUNT_NFT_TEMPLATE_ADDRESS);
let template = Self::load_builtin_template("account_nft", ACCOUNT_NFT_TEMPLATE_ADDRESS, compiled_code.to_vec());
let template =
Self::convert_code_to_template("AccountNft", ACCOUNT_NFT_TEMPLATE_ADDRESS, compiled_code.to_vec());
builtin_templates.insert(ACCOUNT_NFT_TEMPLATE_ADDRESS, template);

// get the builtin WASM code of the account nft template
let compiled_code = get_template_builtin(&FAUCET_TEMPLATE_ADDRESS);
let template = Self::convert_code_to_template("XtrFaucet", FAUCET_TEMPLATE_ADDRESS, compiled_code.to_vec());
builtin_templates.insert(FAUCET_TEMPLATE_ADDRESS, template);

builtin_templates
}

fn load_builtin_template(name: &str, address: TemplateAddress, compiled_code: Vec<u8>) -> Template {
let compiled_code_len = compiled_code.len();
info!(
target: LOG_TARGET,
"Loading builtin {} template: {} bytes", name, compiled_code_len
);

fn convert_code_to_template(name: &str, address: TemplateAddress, compiled_code: Vec<u8>) -> Template {
// build the template object of the account template
let binary_sha = calculate_template_binary_hash(&compiled_code);
Template {
metadata: TemplateMetadata {
name: name.to_string(),
address,
url: "".to_string(),
binary_sha: binary_sha.to_vec(),
binary_sha,
height: 0,
},
executable: TemplateExecutable::CompiledWasm(compiled_code),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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_common_types::types::FixedHash;
use tari_dan_storage::global::{DbTemplate, DbTemplateType};
use tari_template_lib::models::TemplateAddress;
use tari_validator_node_client::types::TemplateAbi;
Expand All @@ -34,7 +35,7 @@ pub struct TemplateMetadata {
// this must be in the form of "https://example.com/my_template.wasm"
pub url: String,
/// SHA hash of binary
pub binary_sha: Vec<u8>,
pub binary_sha: FixedHash,
/// Block height in which the template was published
pub height: u64,
}
Expand All @@ -45,7 +46,9 @@ impl From<TemplateRegistration> for TemplateMetadata {
name: reg.template_name,
address: reg.template_address,
url: reg.registration.binary_url.into_string(),
binary_sha: reg.registration.binary_sha.into_vec(),
binary_sha: FixedHash::try_from(reg.registration.binary_sha.into_vec())
// TODO: impl Fallible conversion
.expect("binary_sha must be 32 bytes long"),
height: reg.mined_height,
}
}
Expand All @@ -58,7 +61,7 @@ impl From<DbTemplate> for TemplateMetadata {
name: record.template_name,
address: (*record.template_address).into(),
url: record.url,
binary_sha: vec![],
binary_sha: FixedHash::zero(),
height: record.height,
}
}
Expand Down Expand Up @@ -87,7 +90,7 @@ impl From<DbTemplate> for Template {
address: (*record.template_address).into(),
url: record.url,
// TODO: add field to db
binary_sha: vec![],
binary_sha: FixedHash::zero(),
height: record.height,
},
executable: match record.template_type {
Expand Down
Loading

0 comments on commit eac7031

Please sign in to comment.