Просмотр исходного кода

wasm: delete Transaction from sdk, and now just pass Vec<FuncCall> around (with no proofs or sigs inside). simplified POD,

x 3 лет назад
Родитель
Сommit
efba1abc66
3 измененных файлов с 8 добавлено и 22 удалено
  1. 3 3
      example/smart-contract/src/lib.rs
  2. 4 8
      example/smart-contract/tests/runtime.rs
  3. 1 11
      src/sdk/src/tx.rs

+ 3 - 3
example/smart-contract/src/lib.rs

@@ -4,7 +4,7 @@ use darkfi_sdk::{
     error::ContractResult,
     initialize, msg,
     state::set_update,
-    tx::Transaction,
+    tx::FuncCall,
     update_state,
 };
 use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
@@ -70,9 +70,9 @@ fn process_instruction(ix: &[u8]) -> ContractResult {
         Function::Foo => {
             let tx_data = &ix[1..];
             // ...
-            let (func_call_index, tx): (u32, Transaction) = deserialize(tx_data)?;
+            let (func_call_index, func_calls): (u32, Vec<FuncCall>) = deserialize(tx_data)?;
             let call_data: FooCallData =
-                deserialize(&tx.func_calls[func_call_index as usize].call_data)?;
+                deserialize(&func_calls[func_call_index as usize].call_data)?;
             msg!("call_data {{ a: {}, b: {} }}", call_data.a, call_data.b);
             // ...
             let update = FooUpdate { name: "john_doe".to_string(), age: 110 };

+ 4 - 8
example/smart-contract/tests/runtime.rs

@@ -19,7 +19,7 @@
 use darkfi::{crypto::contract_id::ContractId, runtime::vm_runtime::Runtime, Result};
 use darkfi_sdk::{
     pasta::pallas,
-    tx::{FuncCall, Transaction},
+    tx::FuncCall
 };
 use darkfi_serial::{serialize, Encodable, WriteExt};
 
@@ -58,15 +58,11 @@ fn run_contract() -> Result<()> {
     // =============================================
     // Build some kind of payload to show an example
     // =============================================
-    let tx = Transaction {
-        func_calls: vec![FuncCall {
+    let func_calls = vec![FuncCall {
             contract_id: pallas::Base::from(110),
             func_id: pallas::Base::from(4),
             call_data: serialize(&FooCallData { a: 777, b: 666 }),
-            proofs: Vec::new(),
-        }],
-        signatures: Vec::new(),
-    };
+    }];
     let func_call_index: u32 = 0;
 
     let mut payload = Vec::new();
@@ -74,7 +70,7 @@ fn run_contract() -> Result<()> {
     payload.write_u8(Function::Foo as u8)?;
     // Write the actual payload data
     payload.write_u32(func_call_index)?;
-    tx.encode(&mut payload)?;
+    func_calls.encode(&mut payload)?;
 
     // ============================================================
     // Serialize the payload into the runtime format and execute it

+ 1 - 11
src/sdk/src/tx.rs

@@ -4,20 +4,10 @@ use pasta_curves::pallas;
 type ContractId = pallas::Base;
 type FuncId = pallas::Base;
 
-#[derive(SerialEncodable, SerialDecodable)]
-pub struct Transaction {
-    pub func_calls: Vec<FuncCall>,
-    // This should also be bytes?
-    //pub signatures: Vec<Signature>,
-    pub signatures: Vec<Vec<u8>>,
-}
-
 #[derive(SerialEncodable, SerialDecodable)]
 pub struct FuncCall {
     pub contract_id: ContractId,
     pub func_id: FuncId,
     pub call_data: Vec<u8>,
-    // This should also be bytes?
-    //pub proofs: Vec<Proof>,
-    pub proofs: Vec<Vec<u8>>,
 }
+