Skip to content

Commit

Permalink
Prototype teleportation tree
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Sep 9, 2023
1 parent f191149 commit 3d7797b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/blockchain/ops/apply_tx/regular_send.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
use super::*;

use crate::core::ZkHasher as CoreZkHasher;
use crate::zk::ZkHasher;
use ff::PrimeField;
use num_bigint::BigUint;

fn put_in_teleport_tree<K: KvStore>(
chain: &mut KvStoreChain<K>,
dst: Address,
money: Money,
) -> Result<(), BlockchainError> {
let as_scalar =
ZkScalar::from_str_vartime(&BigUint::from_bytes_le(&dst.to_bytes()[..31]).to_string());
let commitment = CoreZkHasher::hash(&[money.token_id.into(), money.amount.into()]);
Ok(())
}

pub fn regular_send<K: KvStore>(
chain: &mut KvStoreChain<K>,
tx_src: Address,
Expand All @@ -25,6 +41,8 @@ pub fn regular_send<K: KvStore>(
keys::account_balance(&entry.dst, entry.amount.token_id),
dst_bal.into(),
)])?;

put_in_teleport_tree(chain, entry.dst.clone(), entry.amount.clone())?;
}
}
Ok(())
Expand Down
5 changes: 5 additions & 0 deletions src/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ impl Clone for PrivateKey {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PublicKey(pub ed25519_dalek::PublicKey);
impl PublicKey {
pub fn to_bytes(&self) -> [u8; 32] {
self.0.to_bytes()
}
}
impl PartialEq<PublicKey> for PublicKey {
fn eq(&self, other: &Self) -> bool {
self.0.to_bytes() == other.0.to_bytes()
Expand Down

0 comments on commit 3d7797b

Please sign in to comment.