ソースを参照

doc: fix missing code samples in smart_contracts.md

x 3 年 前
コミット
00458ccd48
2 ファイル変更12 行追加5 行削除
  1. 7 0
      bin/dao/daod/src/util.rs
  2. 5 5
      doc/src/architecture/smart_contracts.md

+ 7 - 0
bin/dao/daod/src/util.rs

@@ -121,10 +121,13 @@ impl ZkContractTable {
     }
 }
 
+// ANCHOR: transaction
 pub struct Transaction {
     pub func_calls: Vec<FuncCall>,
+    // TODO: MUST be Vec<Vec<Signature>>, this is wrong
     pub signatures: Vec<Signature>,
 }
+// ANCHOR_END: transaction
 
 impl Transaction {
     /// Verify ZK contracts for the entire tx
@@ -200,12 +203,14 @@ pub fn sign(signature_secrets: Vec<SecretKey>, func_calls: &Vec<FuncCall>) -> Ve
 type ContractId = pallas::Base;
 type FuncId = pallas::Base;
 
+// ANCHOR: funccall
 pub struct FuncCall {
     pub contract_id: ContractId,
     pub func_id: FuncId,
     pub call_data: Box<dyn CallDataBase + Send + Sync>,
     pub proofs: Vec<Proof>,
 }
+// ANCHOR_END: funccall
 
 impl Encodable for FuncCall {
     fn encode<W: std::io::Write>(&self, mut w: W) -> std::result::Result<usize, std::io::Error> {
@@ -218,6 +223,7 @@ impl Encodable for FuncCall {
     }
 }
 
+// ANCHOR: calldatabase_trait
 pub trait CallDataBase {
     // Public values for verifying the proofs
     // Needed so we can convert internal types so they can be used in Proof::verify()
@@ -234,6 +240,7 @@ pub trait CallDataBase {
         writer: &mut dyn std::io::Write,
     ) -> std::result::Result<usize, std::io::Error>;
 }
+// ANCHOR_END: calldatabase_trait
 
 type GenericContractState = Box<dyn Any + Send>;
 

+ 5 - 5
doc/src/architecture/smart_contracts.md

@@ -89,13 +89,13 @@ the entire tx is rejected. Additionally some smart contracts might impose additi
 on the transaction's structure or other function calls (such as their call data).
 
 ```rust
-{{#include ../../../bin/daod/src/demo.rs:transaction}}
+{{#include ../../../bin/dao/daod/src/util.rs:transaction}}
 ```
 
 Function calls represent mutations of the current active state to a new state.
 
 ```rust
-{{#include ../../../bin/daod/src/demo.rs:funccall}}
+{{#include ../../../bin/dao/daod/src/util.rs:funccall}}
 ```
 
 The `contract_id` corresponds to the top level module for the contract which
@@ -183,13 +183,13 @@ The transaction verification pipeline roughly looks like this:
 Lets review again the format of transactions.
 
 ```rust
-{{#include ../../../bin/daod/src/demo.rs:transaction}}
+{{#include ../../../bin/dao/daod/src/util.rs:transaction}}
 ```
 
 And corresponding function calls.
 
 ```rust
-{{#include ../../../bin/daod/src/demo.rs:funccall}}
+{{#include ../../../bin/dao/daod/src/util.rs:funccall}}
 ```
 
 As we can see the ZK proofs and signatures are separate from the actuall `call_data` interpreted
@@ -200,7 +200,7 @@ the signatures need the public keys. We do this in the `CallDataBase` trait by e
 methods:
 
 ```rust
-{{#include ../../../bin/daod/src/demo.rs:calldatabase_trait}}
+{{#include ../../../bin/dao/daod/src/util.rs:calldatabase_trait}}
 ```
 
 These methods export the required values needed for the ZK proofs and signature verification