Skip to content

Commit

Permalink
Removed unneeded types for multi-txs
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenKor committed Feb 27, 2024
1 parent 90c398d commit 0ef2829
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 95 deletions.
9 changes: 5 additions & 4 deletions libzkbob-rs-wasm/scripts/publish-beta
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash

TAG=beta
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
$SCRIPT_DIR/publish
PARENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"

npm publish $PARENT_DIR/web --tag beta
npm publish $PARENT_DIR/web-mt --tag beta
81 changes: 1 addition & 80 deletions libzkbob-rs-wasm/src/client/tx_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Fr, IDepositData, IDepositPermittableData, ITransferData, IWithdrawData, IMultiTransferData, IMultiWithdrawData};
use crate::{Fr, IDepositData, IDepositPermittableData, ITransferData, IWithdrawData };
use libzkbob_rs::client::{TokenAmount, TxOutput, TxType as NativeTxType, ExtraItem, TxOperator};
use serde::Deserialize;
use wasm_bindgen::prelude::*;
Expand All @@ -16,10 +16,6 @@ pub trait JsTxType {
fn to_native(&self) -> Result<NativeTxType<Fr>, JsValue>;
}

pub trait JsMultiTxType {
fn to_native_array(&self) -> Result<Vec<NativeTxType<Fr>>, JsValue>;
}

#[wasm_bindgen]
#[derive(Deserialize)]
pub struct TxExtraData {
Expand Down Expand Up @@ -178,46 +174,6 @@ impl JsTxType for ITransferData {
}
}

impl JsMultiTxType for IMultiTransferData {
fn to_native_array(&self) -> Result<Vec<NativeTxType<Fr>>, JsValue> {
let array: Vec<TransferData> = serde_wasm_bindgen::from_value(self.into())?;

let tx_array = array.into_iter().map(|tx| {
let outputs = tx.outputs
.into_iter()
.map(|out| TxOutput {
to: out.to,
amount: out.amount,
})
.collect::<Vec<_>>();

let operator = TxOperator {
proxy_address: vec![0; 32], //tx.base_fields.proxy,
proxy_fee: tx.base_fields.proxy_fee,
prover_fee: tx.base_fields.prover_fee,
};

let extra = tx.base_fields.data
.into_iter()
.map(|item| ExtraItem {
leaf_index: item.leaf_index,
pad_length: item.pad_length,
need_encrypt: item.need_encrypt,
data: item.data,
})
.collect::<Vec<_>>();

NativeTxType::Transfer(
operator,
extra,
outputs,
)
}).collect();

Ok(tx_array)
}
}

#[wasm_bindgen]
#[derive(Deserialize)]
pub struct WithdrawData {
Expand Down Expand Up @@ -266,38 +222,3 @@ impl JsTxType for IWithdrawData {
))
}
}

impl JsMultiTxType for IMultiWithdrawData {
fn to_native_array(&self) -> Result<Vec<NativeTxType<Fr>>, JsValue> {
let array: Vec<WithdrawData> = serde_wasm_bindgen::from_value(self.into())?;

let tx_array = array.into_iter().map(|tx| {
let operator = TxOperator {
proxy_address: vec![0; 32], //tx.base_fields.proxy,
proxy_fee: tx.base_fields.proxy_fee,
prover_fee: tx.base_fields.prover_fee,
};

let extra = tx.base_fields.data
.into_iter()
.map(|item| ExtraItem {
leaf_index: item.leaf_index,
pad_length: item.pad_length,
need_encrypt: item.need_encrypt,
data: item.data,
})
.collect::<Vec<_>>();

NativeTxType::Withdraw(
operator,
extra,
tx.amount,
tx.to,
tx.native_amount,
tx.energy_amount,
)
}).collect();

Ok(tx_array)
}
}
7 changes: 2 additions & 5 deletions libzkbob-rs-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use libzkbob_rs::libzeropool::{
constants,
fawkes_crypto::{backend::bellman_groth16::engines::Bn256},
native::{
params::{PoolBN256, PoolParams as PoolParamsTrait},
},
fawkes_crypto::backend::bellman_groth16::engines::Bn256,
native::params::{PoolBN256, PoolParams as PoolParamsTrait},
POOL_PARAMS,
};
use serde::Serialize;
use wasm_bindgen::{prelude::*, JsCast};

pub use crate::{
client::*,
proof::*,
state::{Transaction, UserState},
ts_types::*,
};
Expand Down
6 changes: 0 additions & 6 deletions libzkbob-rs-wasm/src/ts_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,9 @@ extern "C" {
#[wasm_bindgen(typescript_type = "ITransferData")]
pub type ITransferData;

#[wasm_bindgen(typescript_type = "ITransferData[]")]
pub type IMultiTransferData;

#[wasm_bindgen(typescript_type = "IWithdrawData")]
pub type IWithdrawData;

#[wasm_bindgen(typescript_type = "IWithdrawData[]")]
pub type IMultiWithdrawData;

#[wasm_bindgen(typescript_type = "DecryptedMemo")]
pub type DecryptedMemo;

Expand Down

0 comments on commit 0ef2829

Please sign in to comment.