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

changed asset_id to jubjub::Fr across all project

lunar-mining 4 лет назад
Родитель
Сommit
0dfe7bf3dc

+ 31 - 7
src/bin/cashierd.rs

@@ -3,15 +3,40 @@ use std::net::SocketAddr;
 
 use std::path::PathBuf;
 
+use blake2b_simd::Params;
 use drk::cli::{CashierdCli, CashierdConfig, Config};
+use drk::serial::{deserialize, serialize};
 use drk::service::CashierService;
 use drk::util::join_config_path;
 use drk::wallet::{CashierDb, WalletDb};
 use drk::{Error, Result};
+use serde::{Deserialize, Serialize};
 
 use async_executor::Executor;
 use easy_parallel::Parallel;
 
+// TODO: this will be replaced by a vector of assets that can be updated at runtime
+#[derive(Deserialize, Serialize, Debug)]
+pub struct Asset {
+    pub name: String,
+    pub id: Vec<u8>,
+}
+
+impl Asset {
+    pub fn new(name: String) -> Self {
+        let id = Self::id_hash(&name);
+        Self { name, id }
+    }
+    pub fn id_hash(name: &String) -> Vec<u8> {
+        let mut hasher = Params::new().hash_length(64).to_state();
+        hasher.update(name.as_bytes());
+        let result = hasher.finalize();
+        let hash = jubjub::Fr::from_bytes_wide(result.as_array());
+        let id = serialize(&hash);
+        id
+    }
+}
+
 async fn start(executor: Arc<Executor<'_>>, config: Arc<CashierdConfig>) -> Result<()> {
     let ex = executor.clone();
     let accept_addr: SocketAddr = config.accept_url.parse()?;
@@ -46,14 +71,13 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<CashierdConfig>) -> Resu
     )
     .await?;
 
-    let dummy_asset = Vec::new();
-
-    cashier.start(ex.clone(), btc_endpoint, dummy_asset).await?;
+    // TODO: make this a vector of accepted assets
+    let asset = Asset::new("btc".to_string());
+    // TODO: this should be done by the user
+    let asset_id = deserialize(&asset.id)?;
 
-    //let rpc_url: std::net::SocketAddr = config.rpc_url.parse()?;
-    //let adapter = Arc::new(CashierAdapter::new(wallet.clone())?);
-    //let io = Arc::new(adapter.handle_input()?);
-    //jsonserver::start(ex, rpc_url, io).await?;
+    // TODO: pass vector of assets into cashier.start()
+    cashier.start(ex.clone(), btc_endpoint, asset_id).await?;
 
     Ok(())
 }

+ 7 - 17
src/bin/drk.rs

@@ -2,7 +2,7 @@ use std::path::PathBuf;
 
 use serde_json::json;
 
-use drk::cli::{Asset, Config, DrkCli, DrkConfig};
+use drk::cli::{Config, DrkCli, DrkConfig};
 use drk::rpc::jsonrpc;
 use drk::rpc::jsonrpc::JsonResult;
 use drk::serial::serialize;
@@ -81,18 +81,18 @@ impl Drk {
         Ok(self.request("stop", r).await?)
     }
 
-    pub async fn deposit(&self, asset: Asset) -> Result<()> {
+    pub async fn deposit(&self, asset: Vec<u8>) -> Result<()> {
         let r = jsonrpc::request(json!("deposit"), json!([asset]));
         Ok(self.request("deposit coins to this address:", r).await?)
     }
 
-    pub async fn transfer(&self, asset: Asset, address: String, amount: f64) -> Result<()> {
+    pub async fn transfer(&self, asset: Vec<u8>, address: String, amount: f64) -> Result<()> {
         let address = serialize(&address);
         let r = jsonrpc::request(json!("transfer"), json!([asset, address, amount]));
         Ok(self.request("transfer", r).await?)
     }
 
-    pub async fn withdraw(&self, asset: Asset, address: String, amount: f64) -> Result<()> {
+    pub async fn withdraw(&self, asset: Vec<u8>, address: String, amount: f64) -> Result<()> {
         let address = serialize(&address);
         let r = jsonrpc::request(json!("withdraw"), json!([asset, address, amount]));
         Ok(self.request("withdraw", r).await?)
@@ -125,17 +125,17 @@ async fn start(config: &DrkConfig, options: DrkCli) -> Result<()> {
 
     if let Some(transfer) = options.transfer {
         client
-            .transfer(transfer.asset, transfer.pub_key, transfer.amount)
+            .transfer(transfer.asset_id, transfer.pub_key, transfer.amount)
             .await?;
     }
 
     if let Some(deposit) = options.deposit {
-        client.deposit(deposit.asset).await?;
+        client.deposit(deposit.asset_id).await?;
     }
 
     if let Some(withdraw) = options.withdraw {
         client
-            .withdraw(withdraw.asset, withdraw.pub_key, withdraw.amount)
+            .withdraw(withdraw.asset_id, withdraw.pub_key, withdraw.amount)
             .await?;
     }
 
@@ -161,16 +161,6 @@ fn main() -> Result<()> {
     }
 
     let config: DrkConfig = Config::<DrkConfig>::load(config_path)?;
-    //let config: DrkConfig = if Path::new(&config_path).exists() {
-    //    Config::<DrkConfig>::load(config_path)?
-    //};
-
-    //if Path::new(&config_path).exists() {
-    //    let config: DrkConfig = Config::<DrkConfig>::load(config_path)?
-    //}
-    //else {
-    //    Error::NoConfigError
-    //};
 
     {
         use simplelog::*;

+ 59 - 54
src/cli/drk_cli.rs

@@ -1,11 +1,11 @@
 //use super::cli_config::DrkCliConfig;
 use crate::Result;
 
+use crate::serial::{deserialize, serialize};
 use blake2b_simd::Params;
 use clap::{App, Arg};
 use serde::{Deserialize, Serialize};
 
-use crate::serial;
 use std::path::PathBuf;
 
 fn amount_f64(v: String) -> std::result::Result<(), String> {
@@ -18,70 +18,66 @@ fn amount_f64(v: String) -> std::result::Result<(), String> {
 
 #[derive(Deserialize, Debug)]
 pub struct TransferParams {
-    pub asset: Asset,
+    pub asset_id: Vec<u8>,
     pub pub_key: String,
     pub amount: f64,
 }
 
 impl TransferParams {
-    pub fn new() -> Self {
+    pub fn new(asset_id: Vec<u8>, pub_key: String, amount: f64) -> Self {
         Self {
-            asset: Asset::new(),
-            pub_key: String::new(),
-            amount: 0.0,
+            asset_id,
+            pub_key,
+            amount,
         }
     }
 }
 
 pub struct Deposit {
-    pub asset: Asset,
+    pub asset_id: Vec<u8>,
 }
 
 impl Deposit {
-    pub fn new() -> Self {
-        Self {
-            asset: Asset::new(),
-        }
+    pub fn new(asset_id: Vec<u8>) -> Self {
+        Self { asset_id }
     }
 }
 
 #[derive(Deserialize, Debug)]
 pub struct WithdrawParams {
-    pub asset: Asset,
+    pub asset_id: Vec<u8>,
     pub pub_key: String,
     pub amount: f64,
 }
 
 impl WithdrawParams {
-    pub fn new() -> Self {
+    pub fn new(asset_id: Vec<u8>, pub_key: String, amount: f64) -> Self {
         Self {
-            asset: Asset::new(),
-            pub_key: String::new(),
-            amount: 0.0,
+            asset_id,
+            pub_key,
+            amount,
         }
     }
 }
 
 #[derive(Deserialize, Serialize, Debug)]
 pub struct Asset {
-    pub ticker: String,
+    pub name: String,
     pub id: Vec<u8>,
 }
 
 impl Asset {
-    pub fn new() -> Self {
-        Self {
-            ticker: String::new(),
-            id: Vec::new(),
-        }
+    pub fn new(name: String) -> Self {
+        let id = Self::id_hash(&name);
+        Self { name, id }
     }
-    pub fn id_hash(&self, ticker: &String) -> Result<Vec<u8>> {
+    pub fn id_hash(name: &String) -> Vec<u8> {
         let mut hasher = Params::new().hash_length(64).to_state();
-        hasher.update(ticker.as_bytes());
+        hasher.update(name.as_bytes());
         let result = hasher.finalize();
-        let scalar = jubjub::Fr::from_bytes_wide(result.as_array());
-        let id = serial::serialize(&scalar);
-        Ok(id)
+        let hash = jubjub::Fr::from_bytes_wide(result.as_array());
+        let id = serialize(&hash);
+        id
     }
 }
 
@@ -241,12 +237,15 @@ impl DrkCli {
         let mut deposit = None;
         match app.subcommand_matches("deposit") {
             Some(deposit_sub) => {
-                let mut dep = Deposit::new();
-                if let Some(asset) = deposit_sub.value_of("asset") {
-                    dep.asset.ticker = asset.to_string();
-                    dep.asset.id = dep.asset.id_hash(&dep.asset.ticker)?;
-                }
+                let asset_value = deposit_sub.value_of("asset").unwrap();
+                let asset = Asset::new(asset_value.to_string());
+                let dep = Deposit::new(asset.id.clone());
                 deposit = Some(dep);
+                let id: jubjub::Fr = deserialize(&asset.id)?;
+                println!(
+                    "deposit request for asset: {}, asset ID: {:?}",
+                    asset_value, id
+                );
             }
             None => {}
         }
@@ -254,18 +253,21 @@ impl DrkCli {
         let mut transfer = None;
         match app.subcommand_matches("transfer") {
             Some(transfer_sub) => {
-                let mut trn = TransferParams::new();
-                if let Some(asset) = transfer_sub.value_of("asset") {
-                    trn.asset.ticker = asset.to_string();
-                    trn.asset.id = trn.asset.id_hash(&trn.asset.ticker)?;
-                }
-                if let Some(address) = transfer_sub.value_of("address") {
-                    trn.pub_key = address.to_string();
-                }
-                if let Some(amount) = transfer_sub.value_of("amount") {
-                    trn.amount = amount.parse().expect("Convert the amount to f64");
-                }
+                let asset_value = transfer_sub.value_of("asset").unwrap().to_string();
+                let asset = Asset::new(asset_value.clone());
+                let address = transfer_sub.value_of("address").unwrap().to_string();
+                let amount = transfer_sub
+                    .value_of("amount")
+                    .unwrap()
+                    .parse()
+                    .expect("Convert the amount to f64");
+                let trn = TransferParams::new(asset.id.clone(), address, amount);
                 transfer = Some(trn);
+                let id: jubjub::Fr = deserialize(&asset.id)?;
+                println!(
+                    "transfer request for asset: {}, amount: {}, asset ID: {:?}",
+                    asset_value, amount, id
+                );
             }
             None => {}
         }
@@ -273,18 +275,21 @@ impl DrkCli {
         let mut withdraw = None;
         match app.subcommand_matches("withdraw") {
             Some(withdraw_sub) => {
-                let mut wdraw = WithdrawParams::new();
-                if let Some(asset) = withdraw_sub.value_of("asset") {
-                    wdraw.asset.ticker = asset.to_string();
-                    wdraw.asset.id = wdraw.asset.id_hash(&wdraw.asset.ticker)?;
-                }
-                if let Some(address) = withdraw_sub.value_of("address") {
-                    wdraw.pub_key = address.to_string();
-                }
-                if let Some(amount) = withdraw_sub.value_of("amount") {
-                    wdraw.amount = amount.parse().expect("Convert the amount to f64");
-                }
+                let asset_value = withdraw_sub.value_of("asset").unwrap().to_string();
+                let asset = Asset::new(asset_value.clone());
+                let address = withdraw_sub.value_of("address").unwrap().to_string();
+                let amount = withdraw_sub
+                    .value_of("amount")
+                    .unwrap()
+                    .parse()
+                    .expect("Convert the amount to f64");
+                let wdraw = WithdrawParams::new(asset.id.clone(), address, amount);
                 withdraw = Some(wdraw);
+                let id: jubjub::Fr = deserialize(&asset.id)?;
+                println!(
+                    "withdraw request for asset: {}, amount: {}, asset ID: {:?}",
+                    asset_value, amount, id
+                );
             }
             None => {}
         }

+ 5 - 8
src/client/client.rs

@@ -13,7 +13,6 @@ use crate::serial::Decodable;
 use crate::serial::Encodable;
 use crate::service::{CashierClient, GatewayClient, GatewaySlabsSubscriber};
 use crate::state::{state_transition, ProgramState, StateUpdate};
-use crate::util::hash_to_u64;
 use crate::wallet::{CashierDbPtr, WalletPtr};
 use crate::{tx, Result};
 
@@ -127,7 +126,7 @@ impl Client {
 
     pub async fn transfer(
         self: &mut Self,
-        asset_id: Vec<u8>,
+        asset_id: jubjub::Fr,
         pub_key: jubjub::SubgroupPoint,
         amount: f64,
     ) -> Result<()> {
@@ -145,7 +144,7 @@ impl Client {
         self: &mut Self,
         pub_key: jubjub::SubgroupPoint,
         amount: u64,
-        asset_id: Vec<u8>,
+        asset_id: jubjub::Fr,
         clear_input: bool,
     ) -> Result<()> {
         let slab = self.build_slab_from_tx(
@@ -164,15 +163,13 @@ impl Client {
         &self,
         pub_key: jubjub::SubgroupPoint,
         amount: u64,
-        asset_id: Vec<u8>,
+        asset_id: jubjub::Fr,
         clear_input: bool,
     ) -> Result<Slab> {
         let mut clear_inputs: Vec<tx::TransactionBuilderClearInputInfo> = vec![];
         let mut inputs: Vec<tx::TransactionBuilderInputInfo> = vec![];
         let mut outputs: Vec<tx::TransactionBuilderOutputInfo> = vec![];
 
-        let asset_id = hash_to_u64(asset_id);
-
         if clear_input {
             let cashier_secret = self.state.wallet.get_private_keys()?[0];
             let input = tx::TransactionBuilderClearInputInfo {
@@ -182,7 +179,7 @@ impl Client {
             };
             clear_inputs.push(input);
         } else {
-            inputs = self.build_inputs(amount.clone(), asset_id.clone(), &mut outputs)?;
+            inputs = self.build_inputs(amount.clone(), asset_id, &mut outputs)?;
         }
 
         outputs.push(tx::TransactionBuilderOutputInfo {
@@ -210,7 +207,7 @@ impl Client {
     fn build_inputs(
         &self,
         amount: u64,
-        asset_id: u64,
+        asset_id: jubjub::Fr,
         outputs: &mut Vec<tx::TransactionBuilderOutputInfo>,
     ) -> Result<Vec<tx::TransactionBuilderInputInfo>> {
         let mut inputs: Vec<tx::TransactionBuilderInputInfo> = vec![];

+ 3 - 3
src/crypto/mint_proof.rs

@@ -20,7 +20,7 @@ pub struct MintRevealedValues {
 impl MintRevealedValues {
     fn compute(
         value: u64,
-        asset_id: u64,
+        asset_id: jubjub::Fr,
         randomness_value: &jubjub::Fr,
         randomness_asset: &jubjub::Fr,
         serial: &jubjub::Fr,
@@ -45,7 +45,7 @@ impl MintRevealedValues {
                 .to_state()
                 .update(&public.to_bytes())
                 .update(&value.to_le_bytes())
-                .update(&asset_id.to_le_bytes())
+                .update(&asset_id.to_bytes())
                 .update(&serial.to_bytes())
                 .update(&randomness_coin.to_bytes())
                 .finalize()
@@ -139,7 +139,7 @@ pub fn setup_mint_prover() -> groth16::Parameters<Bls12> {
 pub fn create_mint_proof(
     params: &groth16::Parameters<Bls12>,
     value: u64,
-    asset_id: u64,
+    asset_id: jubjub::Fr,
     randomness_value: jubjub::Fr,
     randomness_asset: jubjub::Fr,
     serial: jubjub::Fr,

+ 1 - 1
src/crypto/note.rs

@@ -19,7 +19,7 @@ pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE;
 pub struct Note {
     pub serial: jubjub::Fr,
     pub value: u64,
-    pub asset_id: u64,
+    pub asset_id: jubjub::Fr,
     pub coin_blind: jubjub::Fr,
     pub valcom_blind: jubjub::Fr,
 }

+ 3 - 3
src/crypto/spend_proof.rs

@@ -27,7 +27,7 @@ pub struct SpendRevealedValues {
 impl SpendRevealedValues {
     fn compute(
         value: u64,
-        asset_id: u64,
+        asset_id: jubjub::Fr,
         randomness_value: &jubjub::Fr,
         randomness_asset: &jubjub::Fr,
         serial: &jubjub::Fr,
@@ -71,7 +71,7 @@ impl SpendRevealedValues {
                 .to_state()
                 .update(&public.to_bytes())
                 .update(&value.to_le_bytes())
-                .update(&asset_id.to_le_bytes())
+                .update(&asset_id.to_bytes())
                 .update(&serial.to_bytes())
                 .update(&randomness_coin.to_bytes())
                 .finalize()
@@ -224,7 +224,7 @@ pub fn setup_spend_prover() -> groth16::Parameters<Bls12> {
 pub fn create_spend_proof(
     params: &groth16::Parameters<Bls12>,
     value: u64,
-    asset_id: u64,
+    asset_id: jubjub::Fr,
     randomness_value: jubjub::Fr,
     randomness_asset: jubjub::Fr,
     serial: jubjub::Fr,

+ 35 - 15
src/rpc/adapters/client_adapter.rs

@@ -1,4 +1,4 @@
-use crate::cli::Asset;
+//use crate::cli::jubjub::Fr;
 use crate::client::{Client, ClientFailed};
 use crate::serial::{deserialize, serialize, Decodable};
 use crate::service::CashierClient;
@@ -32,15 +32,25 @@ pub trait RpcClient {
 
     /// transfer
     #[rpc(name = "transfer")]
-    fn transfer(&self, asset: Asset, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>>;
+    fn transfer(
+        &self,
+        asset_id: Vec<u8>,
+        pub_key: Vec<u8>,
+        amount: f64,
+    ) -> BoxFuture<Result<String>>;
 
     /// withdraw
     #[rpc(name = "withdraw")]
-    fn withdraw(&self, asset: Asset, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>>;
+    fn withdraw(
+        &self,
+        asset_id: Vec<u8>,
+        pub_key: Vec<u8>,
+        amount: f64,
+    ) -> BoxFuture<Result<String>>;
 
     /// deposit
     #[rpc(name = "deposit")]
-    fn deposit(&self, asset: Asset) -> BoxFuture<Result<String>>;
+    fn deposit(&self, asset_id: Vec<u8>) -> BoxFuture<Result<String>>;
 }
 
 pub struct RpcClientAdapter {
@@ -76,7 +86,7 @@ impl RpcClientAdapter {
 
     async fn transfer_process(
         client: Arc<Mutex<Client>>,
-        asset: Asset,
+        asset_id: Vec<u8>,
         address: Vec<u8>,
         amount: f64,
     ) -> Result<String> {
@@ -88,10 +98,12 @@ impl RpcClientAdapter {
         let address: jubjub::SubgroupPoint =
             deserialize(&address).map_err(|_| ClientFailed::UnvalidAddress(pub_key))?;
 
+        let asset_id: jubjub::Fr = deserialize(&asset_id)?;
+
         client
             .lock()
             .await
-            .transfer(asset.id, address.clone(), amount)
+            .transfer(asset_id, address.clone(), amount)
             .await?;
 
         Ok(format!("transfered {} DRK to {}", amount, address))
@@ -100,14 +112,16 @@ impl RpcClientAdapter {
     async fn withdraw_process(
         client: Arc<Mutex<Client>>,
         cashier_client: Arc<Mutex<CashierClient>>,
-        asset: Asset,
+        asset_id: Vec<u8>,
         address: Vec<u8>,
         amount: f64,
     ) -> Result<String> {
+        let asset_id: jubjub::Fr = deserialize(&asset_id)?;
+
         let drk_public = cashier_client
             .lock()
             .await
-            .withdraw(asset.id.clone(), address)
+            .withdraw(asset_id, address)
             .await
             .map_err(|err| ClientFailed::from(err))?;
 
@@ -115,7 +129,7 @@ impl RpcClientAdapter {
             client
                 .lock()
                 .await
-                .transfer(asset.id.clone(), drk_addr.clone(), amount)
+                .transfer(asset_id, drk_addr.clone(), amount)
                 .await?;
 
             return Ok(format!(
@@ -130,16 +144,17 @@ impl RpcClientAdapter {
     async fn deposit_process<T>(
         client: Arc<Mutex<Client>>,
         cashier_client: Arc<Mutex<CashierClient>>,
-        asset: Asset,
+        asset_id: Vec<u8>,
     ) -> Result<String>
     where
         T: Decodable + ToString,
     {
+        let asset_id: jubjub::Fr = deserialize(&asset_id)?;
         let deposit_addr = client.lock().await.state.wallet.get_public_keys()?[0];
         let coin_public = cashier_client
             .lock()
             .await
-            .get_address(asset.id, deposit_addr)
+            .get_address(asset_id, deposit_addr)
             .await
             .map_err(|err| ClientFailed::from(err))?;
 
@@ -173,14 +188,19 @@ impl RpcClient for RpcClientAdapter {
         Self::key_gen_process(self.client.clone()).boxed()
     }
 
-    fn transfer(&self, asset: Asset, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>> {
+    fn transfer(
+        &self,
+        asset_id: Vec<u8>,
+        pub_key: Vec<u8>,
+        amount: f64,
+    ) -> BoxFuture<Result<String>> {
         debug!(target: "RPC USER ADAPTER", "transfer() [START]");
-        Self::transfer_process(self.client.clone(), asset, pub_key, amount).boxed()
+        Self::transfer_process(self.client.clone(), asset_id, pub_key, amount).boxed()
     }
 
     fn withdraw(
         &self,
-        asset_id: Asset,
+        asset_id: Vec<u8>,
         pub_key: Vec<u8>,
         amount: f64,
     ) -> BoxFuture<Result<String>> {
@@ -195,7 +215,7 @@ impl RpcClient for RpcClientAdapter {
         .boxed()
     }
 
-    fn deposit(&self, asset_id: Asset) -> BoxFuture<Result<String>> {
+    fn deposit(&self, asset_id: Vec<u8>) -> BoxFuture<Result<String>> {
         debug!(target: "RPC USER ADAPTER", "deposit() [START]");
         #[cfg(feature = "default")]
         Self::deposit_process::<bitcoin::PublicKey>(

+ 7 - 4
src/service/bridge.rs

@@ -3,11 +3,12 @@ use crate::Result;
 use async_executor::Executor;
 use async_trait::async_trait;
 
+use crate::serial::serialize;
 use async_std::sync::{Arc, Mutex};
 use std::collections::HashMap;
 
 pub struct BridgeRequests {
-    pub asset_id: u64,
+    pub asset_id: jubjub::Fr,
     pub payload: BridgeRequestsPayload,
 }
 
@@ -32,7 +33,7 @@ pub struct BridgeSubscribtion {
 }
 
 pub struct Bridge {
-    clients: Mutex<HashMap<u64, Arc<dyn CoinClient + Send + Sync>>>,
+    clients: Mutex<HashMap<Vec<u8>, Arc<dyn CoinClient + Send + Sync>>>,
 }
 impl Bridge {
     pub fn new() -> Arc<Self> {
@@ -43,9 +44,10 @@ impl Bridge {
 
     pub async fn add_clients(
         self: Arc<Self>,
-        asset_id: u64,
+        asset_id: jubjub::Fr,
         client: Arc<dyn CoinClient + Send + Sync>,
     ) {
+        let asset_id = serialize(&asset_id);
         self.clients.lock().await.insert(asset_id, client);
     }
 
@@ -66,7 +68,8 @@ impl Bridge {
         rep: async_channel::Sender<BridgeResponse>,
     ) -> Result<()> {
         let req = req.recv().await?;
-        let client = &self.clients.lock().await[&req.asset_id];
+        let asset_id = serialize(&req.asset_id);
+        let client = &self.clients.lock().await[&asset_id];
 
         match req.payload {
             BridgeRequestsPayload::WatchRequest => {

+ 8 - 10
src/service/cashier.rs

@@ -3,7 +3,6 @@ use super::reqrep::{PeerId, RepProtocol, Reply, ReqProtocol, Request};
 use crate::blockchain::Rocks;
 use crate::client::Client;
 use crate::serial::{deserialize, serialize};
-use crate::util::hash_to_u64;
 use crate::wallet::{CashierDbPtr, WalletPtr};
 use crate::{Error, Result};
 
@@ -61,7 +60,8 @@ impl CashierService {
         &mut self,
         executor: Arc<Executor<'_>>,
         client_address: String,
-        asset_id: Vec<u8>,
+        // TODO: make this a vector of assets
+        asset_id: jubjub::Fr,
     ) -> Result<()> {
         debug!(target: "CASHIER DAEMON", "Start Cashier");
         let service_name = String::from("CASHIER DAEMON");
@@ -76,8 +76,6 @@ impl CashierService {
 
         let bridge = bridge::Bridge::new();
 
-        let asset_id = hash_to_u64(asset_id);
-
         #[cfg(feature = "default")]
         let btc_client = super::btc::BtcClient::new(client_address)?;
         #[cfg(feature = "default")]
@@ -160,7 +158,7 @@ impl CashierService {
         &mut self,
         dkey_pub: jubjub::SubgroupPoint,
         value: u64,
-        asset_id: Vec<u8>,
+        asset_id: jubjub::Fr,
     ) -> Result<()> {
         self.client
             .lock()
@@ -211,14 +209,13 @@ impl CashierService {
             0 => {
                 debug!(target: "CASHIER DAEMON", "Received deposit request");
                 // Exchange zk_pubkey for bitcoin address
-                let (asset_id, dpub): (Vec<u8>, jubjub::SubgroupPoint) =
+                let (asset_id, dpub): (jubjub::Fr, jubjub::SubgroupPoint) =
                     deserialize(&request.get_payload())?;
 
                 //TODO: check if key has already been issued
                 let _check =
                     cashier_wallet.get_deposit_coin_keys_by_dkey_public(&dpub, &serialize(&1));
 
-                let asset_id = hash_to_u64(asset_id);
                 bridge_subscribtion
                     .sender
                     .send(bridge::BridgeRequests {
@@ -253,7 +250,8 @@ impl CashierService {
             }
             1 => {
                 debug!(target: "CASHIER DAEMON", "Received withdraw request");
-                let (asset_id, coin_address): (u64, Vec<u8>) = deserialize(&request.get_payload())?;
+                let (asset_id, coin_address): (jubjub::Fr, Vec<u8>) =
+                    deserialize(&request.get_payload())?;
                 //let btc_address: String = deserialize(&btc_address)?;
                 //let btc_address = bitcoin::util::address::Address::from_str(&btc_address)
                 //   .map_err(|err| crate::Error::from(super::BtcFailed::from(err)))?;
@@ -314,7 +312,7 @@ impl CashierClient {
 
     pub async fn withdraw(
         &mut self,
-        asset_id: Vec<u8>,
+        asset_id: jubjub::Fr,
         coin_address: Vec<u8>,
     ) -> Result<Option<jubjub::SubgroupPoint>> {
         let handle_error = Arc::new(handle_error);
@@ -336,7 +334,7 @@ impl CashierClient {
 
     pub async fn get_address(
         &mut self,
-        asset_id: Vec<u8>,
+        asset_id: jubjub::Fr,
         index: jubjub::SubgroupPoint,
     ) -> Result<Option<Vec<u8>>> {
         let handle_error = Arc::new(handle_error);

+ 2 - 2
src/tx/builder.rs

@@ -21,7 +21,7 @@ pub struct TransactionBuilder {
 
 pub struct TransactionBuilderClearInputInfo {
     pub value: u64,
-    pub asset_id: u64,
+    pub asset_id: jubjub::Fr,
     pub signature_secret: jubjub::Fr,
 }
 
@@ -33,7 +33,7 @@ pub struct TransactionBuilderInputInfo {
 
 pub struct TransactionBuilderOutputInfo {
     pub value: u64,
-    pub asset_id: u64,
+    pub asset_id: jubjub::Fr,
     pub public: jubjub::SubgroupPoint,
 }
 

+ 5 - 5
src/tx/mod.rs

@@ -29,7 +29,7 @@ pub struct Transaction {
 
 pub struct TransactionClearInput {
     pub value: u64,
-    pub asset_id: u64,
+    pub asset_id: jubjub::Fr,
     pub valcom_blind: jubjub::Fr,
     pub asset_commit_blind: jubjub::Fr,
     pub signature_public: jubjub::SubgroupPoint,
@@ -57,9 +57,8 @@ impl Transaction {
         Ok(len)
     }
 
-    fn compute_pedersen_commit(value: u64, blind: &jubjub::Fr) -> jubjub::SubgroupPoint {
-        let value_commit = (zcash_primitives::constants::VALUE_COMMITMENT_VALUE_GENERATOR
-            * jubjub::Fr::from(value))
+    fn compute_pedersen_commit(value: jubjub::Fr, blind: &jubjub::Fr) -> jubjub::SubgroupPoint {
+        let value_commit = (zcash_primitives::constants::VALUE_COMMITMENT_VALUE_GENERATOR * value)
             + (zcash_primitives::constants::VALUE_COMMITMENT_RANDOMNESS_GENERATOR * blind);
         value_commit
     }
@@ -92,7 +91,8 @@ impl Transaction {
     ) -> state::VerifyResult<()> {
         let mut valcom_total = jubjub::SubgroupPoint::identity();
         for input in &self.clear_inputs {
-            valcom_total += Self::compute_pedersen_commit(input.value, &input.valcom_blind);
+            let value = jubjub::Fr::from(input.value);
+            valcom_total += Self::compute_pedersen_commit(value, &input.valcom_blind);
         }
         for (i, input) in self.inputs.iter().enumerate() {
             if !verify_spend_proof(spend_pvk, &input.spend_proof, &input.revealed) {

+ 1 - 1
src/tx/partial.rs

@@ -16,7 +16,7 @@ pub struct PartialTransaction {
 
 pub struct PartialTransactionClearInput {
     pub value: u64,
-    pub asset_id: u64,
+    pub asset_id: jubjub::Fr,
     pub valcom_blind: jubjub::Fr,
     pub asset_commit_blind: jubjub::Fr,
     pub signature_public: jubjub::SubgroupPoint,

+ 0 - 4
src/util.rs

@@ -17,7 +17,3 @@ pub fn join_config_path(file: &PathBuf) -> Result<PathBuf> {
 
     Ok(path)
 }
-
-pub fn hash_to_u64(asset_id: Vec<u8>) -> u64 {
-    asset_id.iter().fold(0, |x, &i| x << 8 | i as u64)
-}

+ 2 - 2
src/wallet/walletdb.rs

@@ -127,7 +127,7 @@ impl WalletDb {
             let coin_blind = self.get_value_deserialized(row.get(3)?).unwrap();
             let valcom_blind = self.get_value_deserialized(row.get(4)?).unwrap();
             let value: u64 = row.get(5)?;
-            let asset_id: u64 = row.get(6)?;
+            let asset_id = self.get_value_deserialized(row.get(6)?).unwrap();
 
             let note = Note {
                 serial,
@@ -178,7 +178,7 @@ impl WalletDb {
         let coin_blind = self.get_value_serialized(&own_coin.note.coin_blind)?;
         let valcom_blind = self.get_value_serialized(&own_coin.note.valcom_blind)?;
         let value: u64 = own_coin.note.value;
-        let asset_id: u64 = own_coin.note.asset_id;
+        let asset_id = self.get_value_serialized(&own_coin.note.asset_id)?;
         let witness = self.get_value_serialized(&own_coin.witness)?;
         let secret = self.get_value_serialized(&own_coin.secret)?;
         // open connection