Răsfoiți Sursa

example/dummy-contract: Fix paths

parazyd 2 ani în urmă
părinte
comite
64377fe908

+ 2 - 0
example/dummy-contract/.gitignore

@@ -0,0 +1,2 @@
+target/
+Cargo.lock

+ 4 - 0
example/dummy-contract/Cargo.toml

@@ -30,3 +30,7 @@ path = "src/runtime.rs"
 [features]
 default = []
 no-entrypoint = []
+
+[patch.crates-io]
+halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"}
+halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v4"}

+ 14 - 4
example/dummy-contract/src/entrypoint.rs

@@ -16,7 +16,11 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use darkfi_sdk::{crypto::ContractId, error::ContractResult};
+use darkfi_sdk::{
+    crypto::ContractId,
+    db::{db_init, db_lookup},
+    error::ContractResult,
+};
 
 darkfi_sdk::define_contract!(
     init: init_contract,
@@ -25,8 +29,12 @@ darkfi_sdk::define_contract!(
     metadata: get_metadata
 );
 
-fn init_contract(_cid: ContractId, _ix: &[u8]) -> ContractResult {
-    //panic!("ohai");
+fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
+    let db = match db_lookup(cid, "dummy_db") {
+        Ok(v) => v,
+        Err(_) => db_init(cid, "dummy_db")?,
+    };
+
     Ok(())
 }
 
@@ -34,7 +42,9 @@ fn get_metadata(_cid: ContractId, _ix: &[u8]) -> ContractResult {
     Ok(())
 }
 
-fn process_instruction(_cid: ContractId, _ix: &[u8]) -> ContractResult {
+fn process_instruction(cid: ContractId, _ix: &[u8]) -> ContractResult {
+    let db = db_lookup(cid, "dummy_db")?;
+
     Ok(())
 }
 

+ 6 - 1
example/dummy-contract/src/runtime.rs

@@ -46,7 +46,7 @@ fn main() {
     let timekeeper = TimeKeeper::new(Timestamp::current_time(), 10, 90, 0);
 
     let wasm_bytes =
-        include_bytes!("../../../target/wasm32-unknown-unknown/release/darkfi_dummy_contract.wasm");
+        include_bytes!("../target/wasm32-unknown-unknown/release/darkfi_dummy_contract.wasm");
 
     let contract_id = ContractId::from(pallas::Base::from(69));
 
@@ -55,4 +55,9 @@ fn main() {
         Ok(()) => {}
         Err(e) => println!("Error running deploy: {:#?}", e),
     }
+
+    match runtime.exec(&[]) {
+        Ok(_) => {}
+        Err(e) => println!("Error running exec: {:#?}", e),
+    }
 }