mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
deployooor: fix broken WASM fns
This commit is contained in:
@@ -17,14 +17,7 @@
|
||||
*/
|
||||
|
||||
use darkfi_sdk::{
|
||||
crypto::ContractId,
|
||||
dark_tree::DarkLeaf,
|
||||
error::ContractResult,
|
||||
wasm::{
|
||||
db::{db_init, db_lookup, db_set},
|
||||
util::set_return_data,
|
||||
},
|
||||
ContractCall,
|
||||
crypto::ContractId, dark_tree::DarkLeaf, error::ContractResult, wasm, ContractCall,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
|
||||
@@ -54,19 +47,19 @@ darkfi_sdk::define_contract!(
|
||||
/// with initial data if necessary.
|
||||
fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
||||
// Set up a database tree for arbitrary data
|
||||
let info_db = match db_lookup(cid, DEPLOY_CONTRACT_INFO_TREE) {
|
||||
let info_db = match wasm::db::db_lookup(cid, DEPLOY_CONTRACT_INFO_TREE) {
|
||||
Ok(v) => v,
|
||||
Err(_) => db_init(cid, DEPLOY_CONTRACT_INFO_TREE)?,
|
||||
Err(_) => wasm::db::db_init(cid, DEPLOY_CONTRACT_INFO_TREE)?,
|
||||
};
|
||||
|
||||
// Set up a database to hold the set of locked contracts
|
||||
// k=ContractId, v=bool
|
||||
if db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE).is_err() {
|
||||
db_init(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
if wasm::db::db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE).is_err() {
|
||||
wasm::db::db_init(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
}
|
||||
|
||||
// Update db version
|
||||
db_set(info_db, DEPLOY_CONTRACT_DB_VERSION, &serialize(&env!("CARGO_PKG_VERSION")))?;
|
||||
wasm::db::db_set(info_db, DEPLOY_CONTRACT_DB_VERSION, &serialize(&env!("CARGO_PKG_VERSION")))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -84,7 +77,7 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
|
||||
DeployFunction::LockV1 => lock_get_metadata_v1(cid, call_idx, calls)?,
|
||||
};
|
||||
|
||||
set_return_data(&metadata)
|
||||
wasm::util::set_return_data(&metadata)
|
||||
}
|
||||
|
||||
/// This function verifies a state transition and produces a state update
|
||||
@@ -99,7 +92,7 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
|
||||
DeployFunction::LockV1 => lock_process_instruction_v1(cid, call_idx, calls)?,
|
||||
};
|
||||
|
||||
set_return_data(&update_data)
|
||||
wasm::util::set_return_data(&update_data)
|
||||
}
|
||||
|
||||
/// This function attempts to write a given state update provided the previous
|
||||
|
||||
@@ -23,8 +23,7 @@ use darkfi_sdk::{
|
||||
error::{ContractError, ContractResult},
|
||||
msg,
|
||||
pasta::pallas,
|
||||
wasm::db::{db_get, db_lookup, db_set},
|
||||
ContractCall,
|
||||
wasm, ContractCall,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
|
||||
use wasmparser::{
|
||||
@@ -66,10 +65,10 @@ pub(crate) fn deploy_process_instruction_v1(
|
||||
let params: DeployParamsV1 = deserialize(&self_.data.data[1..])?;
|
||||
|
||||
// In this function, we have to check that the contract isn't locked.
|
||||
let lock_db = db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
let lock_db = wasm::db::db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
let contract_id = ContractId::derive_public(params.public_key);
|
||||
|
||||
if let Some(v) = db_get(lock_db, &serialize(&contract_id))? {
|
||||
if let Some(v) = wasm::db::db_get(lock_db, &serialize(&contract_id))? {
|
||||
let locked: bool = deserialize(&v)?;
|
||||
if locked {
|
||||
msg!("[DeployV1] Error: Contract is locked. Cannot redeploy.");
|
||||
@@ -153,8 +152,8 @@ pub(crate) fn deploy_process_instruction_v1(
|
||||
pub(crate) fn deploy_process_update_v1(cid: ContractId, update: DeployUpdateV1) -> ContractResult {
|
||||
// We add the contract to the list
|
||||
msg!("[DeployV1] Adding ContractID to deployed list");
|
||||
let lock_db = db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
db_set(lock_db, &serialize(&update.contract_id), &serialize(&false))?;
|
||||
let lock_db = wasm::db::db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
wasm::db::db_set(lock_db, &serialize(&update.contract_id), &serialize(&false))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ use darkfi_sdk::{
|
||||
error::{ContractError, ContractResult},
|
||||
msg,
|
||||
pasta::pallas,
|
||||
wasm::db::{db_contains_key, db_get, db_lookup, db_set},
|
||||
ContractCall,
|
||||
wasm, ContractCall,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
|
||||
|
||||
@@ -66,15 +65,15 @@ pub(crate) fn lock_process_instruction_v1(
|
||||
|
||||
// In this function, we check that the contract exists, and that it isn't
|
||||
// already locked.
|
||||
let lock_db = db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
let lock_db = wasm::db::db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
let contract_id = ContractId::derive_public(params.public_key);
|
||||
|
||||
if !db_contains_key(lock_db, &serialize(&contract_id))? {
|
||||
if !wasm::db::db_contains_key(lock_db, &serialize(&contract_id))? {
|
||||
msg!("[LockV1] Error: Contract ID doesn't exist.");
|
||||
return Err(DeployError::ContractNonExistent.into())
|
||||
}
|
||||
|
||||
let v = db_get(lock_db, &serialize(&contract_id))?.unwrap();
|
||||
let v = wasm::db::db_get(lock_db, &serialize(&contract_id))?.unwrap();
|
||||
let locked: bool = deserialize(&v)?;
|
||||
if locked {
|
||||
msg!("[LockV1] Error: Contract already locked.");
|
||||
@@ -93,8 +92,8 @@ pub(crate) fn lock_process_instruction_v1(
|
||||
pub(crate) fn lock_process_update_v1(cid: ContractId, update: LockUpdateV1) -> ContractResult {
|
||||
// We make the contract immutable
|
||||
msg!("[LockV1] Making ContractID immutable");
|
||||
let lock_db = db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
db_set(lock_db, &serialize(&update.contract_id), &serialize(&true))?;
|
||||
let lock_db = wasm::db::db_lookup(cid, DEPLOY_CONTRACT_LOCK_TREE)?;
|
||||
wasm::db::db_set(lock_db, &serialize(&update.contract_id), &serialize(&true))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user