diff --git a/example/smart-contract/src/lib.rs b/example/smart-contract/src/lib.rs
index d8597df53..08d6f5daa 100644
--- a/example/smart-contract/src/lib.rs
+++ b/example/smart-contract/src/lib.rs
@@ -1,10 +1,11 @@
use darkfi_sdk::{
+ crypto::ContractId,
db::{db_begin_tx, db_end_tx, db_get, db_init, db_lookup, db_set},
+ define_contract,
error::ContractResult,
msg,
state::set_update,
tx::FuncCall,
- define_contract,
};
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
@@ -44,15 +45,11 @@ pub struct FooUpdate {
pub age: u32,
}
-define_contract!(
- init: init_contract,
- exec: process_instruction,
- apply: process_update
-);
+define_contract!(init: init_contract, exec: process_instruction, apply: process_update);
-fn init_contract(_ix: &[u8]) -> ContractResult {
+fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
msg!("wakeup wagies!");
- db_init("wagies")?;
+ db_init(cid, "wagies")?;
// Lets write a value in there
let tx_handle = db_begin_tx()?;
@@ -68,7 +65,7 @@ fn init_contract(_ix: &[u8]) -> ContractResult {
// This is the main entrypoint function where the payload is fed.
// Through here, you can branch out into different functions inside
// this library.
-fn process_instruction(ix: &[u8]) -> ContractResult {
+fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
match Function::from(ix[0]) {
Function::Foo => {
let tx_data = &ix[1..];
@@ -127,7 +124,7 @@ fn process_instruction(ix: &[u8]) -> ContractResult {
Ok(())
}
-fn process_update(update_data: &[u8]) -> ContractResult {
+fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
msg!("Make update!");
match Function::from(update_data[0]) {
diff --git a/example/smart-contract/tests/runtime.rs b/example/smart-contract/tests/runtime.rs
index d971efc2e..57a5e869b 100644
--- a/example/smart-contract/tests/runtime.rs
+++ b/example/smart-contract/tests/runtime.rs
@@ -19,11 +19,10 @@
use darkfi::{
blockchain::Blockchain,
consensus::{TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP},
- crypto::contract_id::ContractId,
runtime::vm_runtime::Runtime,
Result,
};
-use darkfi_sdk::{pasta::pallas, tx::FuncCall};
+use darkfi_sdk::{crypto::ContractId, pasta::pallas, tx::FuncCall};
use darkfi_serial::{serialize, Encodable, WriteExt};
use smart_contract::{FooCallData, Function};
diff --git a/src/blockchain/contractstore.rs b/src/blockchain/contractstore.rs
index 6be92904f..8b8c228ed 100644
--- a/src/blockchain/contractstore.rs
+++ b/src/blockchain/contractstore.rs
@@ -16,10 +16,10 @@
* along with this program. If not, see .
*/
+use darkfi_sdk::crypto::ContractId;
use darkfi_serial::deserialize;
use crate::{
- crypto::contract_id::ContractId,
Error::{ContractAlreadyInitialized, ContractNotFound, ContractStateNotFound},
Result,
};
diff --git a/src/blockchain/mod.rs b/src/blockchain/mod.rs
index 847061f97..69099fe09 100644
--- a/src/blockchain/mod.rs
+++ b/src/blockchain/mod.rs
@@ -34,9 +34,6 @@ pub use nfstore::NullifierStore;
pub mod rootstore;
pub use rootstore::RootStore;
-pub mod statestore;
-pub use statestore::StateStore;
-
pub mod txstore;
pub use txstore::TxStore;
diff --git a/src/blockchain/statestore.rs b/src/blockchain/statestore.rs
deleted file mode 100644
index 7a1d73540..000000000
--- a/src/blockchain/statestore.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-use darkfi_serial::serialize;
-
-use crate::{crypto::contract_id::ContractId, Result};
-
-const SLED_STATES_TREE: &[u8] = b"_states";
-
-/// The `StateStore` is a `sled` tree storing states of deployed contracts.
-/// The states themselves are data that is allocated and stored as raw bytes.
-/// These bytes are (de)serialized by the code in wasm and the contracts can
-/// operate on the state data themselves. Regarding on the (byte) size of the
-/// state, the contract deployer should allocate and pay for a certain size of
-/// their state stored by all the nodes. The cost should be linear to the byte
-/// size used.
-#[derive(Clone)]
-pub struct StateStore(sled::Tree);
-
-impl StateStore {
- /// Opens a new or existing `StateStore` on the given sled database.
- pub fn new(db: &sled::Db) -> Result {
- let tree = db.open_tree(SLED_STATES_TREE)?;
- Ok(Self(tree))
- }
-
- /// Insert a state into the store. This will replace the previous state.
- /// The contract's ID is used as a key, while the value is the contract
- /// state serialized to bytes.
- pub fn insert(&self, contract_id: &ContractId, contract_state: &[u8]) -> Result<()> {
- self.0.insert(serialize(contract_id), contract_state.to_vec())?;
- Ok(())
- }
-
- /// Check if the `StateStore` contains a state for the given `ContractId`.
- pub fn contains(&self, contract_id: &ContractId) -> Result {
- Ok(self.0.contains_key(serialize(contract_id))?)
- }
-
- /// Retrieve a state from the `StateStore` given a `ContractId` if it exists.
- pub fn get(&self, contract_id: &ContractId) -> Result