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

contract/money: Add stub for staking and unstaking coins.

parazyd 3 лет назад
Родитель
Сommit
93b0eced04
2 измененных файлов с 60 добавлено и 0 удалено
  1. 20 0
      src/contract/money/src/lib.rs
  2. 40 0
      src/contract/money/src/state.rs

+ 20 - 0
src/contract/money/src/lib.rs

@@ -45,6 +45,8 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 pub enum MoneyFunction {
     Transfer = 0x00,
     OtcSwap = 0x01,
+    Stake = 0x02,
+    Unstake = 0x03,
 }
 
 impl TryFrom<u8> for MoneyFunction {
@@ -54,6 +56,8 @@ impl TryFrom<u8> for MoneyFunction {
         match b {
             0x00 => Ok(Self::Transfer),
             0x01 => Ok(Self::OtcSwap),
+            0x02 => Ok(Self::Stake),
+            0x03 => Ok(Self::Unstake),
             _ => Err(ContractError::InvalidFunction),
         }
     }
@@ -224,6 +228,9 @@ fn get_metadata(_cid: ContractId, ix: &[u8]) -> ContractResult {
             // Using this, we pass the above data to the host.
             set_return_data(&metadata)?;
         }
+
+        MoneyFunction::Stake => unimplemented!(),
+        MoneyFunction::Unstake => unimplemented!(),
     };
 
     Ok(())
@@ -427,6 +434,16 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
 
             Ok(())
         }
+
+        MoneyFunction::Stake => {
+            msg!("[Stake] Entered match arm");
+            unimplemented!();
+        }
+
+        MoneyFunction::Unstake => {
+            msg!("[Unstake] Entered match arm");
+            unimplemented!();
+        }
     }
 }
 
@@ -450,5 +467,8 @@ fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
 
             Ok(())
         }
+
+        MoneyFunction::Stake => unimplemented!(),
+        MoneyFunction::Unstake => unimplemented!(),
     }
 }

+ 40 - 0
src/contract/money/src/state.rs

@@ -25,6 +25,46 @@ use darkfi_sdk::{
 };
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 
+/// Inputs and outputs for staking coins
+#[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
+pub struct MoneyStakeParams {
+    /// Anonymous inputs
+    pub inputs: Vec<Input>,
+    /// Anonymous outputs for staking
+    pub outputs: Vec<StakedOutput>,
+}
+
+/// Inputs and outputs for unstaking coins
+#[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
+pub struct MoneyUnstakeParams {
+    /// Anonymous staked inputs
+    pub inputs: Vec<StakedInput>,
+    /// Anonymous outputs
+    pub outputs: Vec<Output>,
+}
+
+/// Staked anonymous input
+#[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
+pub struct StakedInput {
+    /// Revealed nullifier
+    pub nullifier: Nullifier,
+    /// Revealed Merkle root
+    pub merkle_root: MerkleNode,
+    /// Public key for the signature
+    pub signature_public: PublicKey,
+}
+
+/// Staked anonymous output
+#[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
+pub struct StakedOutput {
+    /// Minted coin
+    pub coin: pallas::Base,
+    /// The encrypted note ciphertext
+    pub ciphertext: Vec<u8>,
+    /// The ephemeral public key
+    pub ephem_public: PublicKey,
+}
+
 /// Inputs and outputs for a payment
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
 pub struct MoneyTransferParams {