Kaynağa Gözat

contract/money: Merge cashier and faucet pubkeys into one.

This now writes the pubkeys into the sled db on deployment.
parazyd 3 yıl önce
ebeveyn
işleme
3a4efc1d74

+ 7 - 14
bin/darkfid/src/main.rs

@@ -303,30 +303,23 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
         }
     };
 
-    // Parse cashier addresses
-    let mut cashier_pubkeys = vec![];
+    // Parse faucet addresses
+    let mut faucet_pubkeys = vec![];
+
     for i in args.cashier_pub {
         let pk = PublicKey::from_str(&i)?;
-        cashier_pubkeys.push(pk);
+        faucet_pubkeys.push(pk);
     }
 
-    // Parse fauced addresses
-    let mut faucet_pubkeys = vec![];
     for i in args.faucet_pub {
         let pk = PublicKey::from_str(&i)?;
         faucet_pubkeys.push(pk);
     }
 
     // Initialize validator state
-    let state = ValidatorState::new(
-        &sled_db,
-        genesis_ts,
-        genesis_data,
-        wallet.clone(),
-        cashier_pubkeys,
-        faucet_pubkeys,
-    )
-    .await?;
+    let state =
+        ValidatorState::new(&sled_db, genesis_ts, genesis_data, wallet.clone(), faucet_pubkeys)
+            .await?;
 
     let sync_p2p = {
         info!("Registering block sync P2P protocols...");

+ 4 - 3
src/consensus/state.rs

@@ -140,7 +140,6 @@ impl ValidatorState {
         genesis_ts: Timestamp,
         genesis_data: blake3::Hash,
         wallet: WalletPtr,
-        cashier_pubkeys: Vec<PublicKey>,
         faucet_pubkeys: Vec<PublicKey>,
     ) -> Result<ValidatorStatePtr> {
         info!("Initializing ValidatorState");
@@ -184,8 +183,10 @@ impl ValidatorState {
         //             and/or just hardcoded and forbidden in non-native contract deployment.
         let cid = ContractId::from(pallas::Base::from(u64::MAX - 420));
         let mut runtime = Runtime::new(&money_contract_wasm_bincode[..], blockchain.clone(), cid)?;
-        // TODO: TESTNET: Faucet/Cashier keys as init payload
-        runtime.deploy(&[])?;
+        // The faucet pubkeys are pubkeys which are allowed to create clear inputs in the
+        // money contract.
+        let payload = serialize(&faucet_pubkeys);
+        runtime.deploy(&payload)?;
         info!("Deployed Money Contract with ID: {}", cid);
         // -----END ARTIFACT-----
 

+ 5 - 2
src/contract/money/src/lib.rs

@@ -72,7 +72,11 @@ pub const ZKAS_MINT_NS: &str = "Mint";
 pub const ZKAS_BURN_NS: &str = "Burn";
 
 /// This function runs when the contract is (re)deployed and initialized.
-fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
+fn init_contract(cid: ContractId, ix: &[u8]) -> ContractResult {
+    // The payload for now contains a vector of `PublicKey` used to
+    // whitelist faucets that can create clear inputs.
+    let faucet_pubkeys: Vec<PublicKey> = deserialize(ix)?;
+
     // The zkas circuits can simply be embedded in the wasm and set up by
     // the initialization. Note that the tree should then be called "zkas".
     // The lookups can then be done by `contract_id+zkas+namespace`.
@@ -127,7 +131,6 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
     };
 
     // Whitelisted faucets
-    let faucet_pubkeys: Vec<PublicKey> = vec![];
     db_set(info_db, &serialize(&FAUCET_PUBKEYS.to_string()), &serialize(&faucet_pubkeys))?;
 
     Ok(())