Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Sep 17, 2020
1 parent 3a047dd commit 948eeab
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ members = [
"core/testkit",
"core/loadtest",
"core/crypto_exports",
"core/sdk",
"core/sdk",
"core/tok_cli"
]
4 changes: 1 addition & 3 deletions core/sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
name = "zksync"
version = "0.1.0"
authors = ["Thor Kamphefner <thor@matterlabs.dev>"]
authors = ["The Matter Labs Team <hello@matterlabs.dev>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
models = { path = "../models", version = "0.0.1" }
eth_client = { path = "../eth_client", version = "0.1.0" }
Expand Down
3 changes: 3 additions & 0 deletions core/sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub enum ClientError {

#[error("Ethereum private key was not provided for this wallet")]
NoEthereumPrivateKey,

#[error("Provided value is not packable")]
NotPackableValue,
}

#[derive(Debug, Error)]
Expand Down
18 changes: 17 additions & 1 deletion core/sdk/src/operations/change_pubkey.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use models::node::{closest_packable_fee_amount, FranklinTx, Nonce, Token, TokenLike};
use models::node::{
closest_packable_fee_amount, is_fee_amount_packable, FranklinTx, Nonce, Token, TokenLike,
};
use num::BigUint;

use crate::{error::ClientError, operations::SyncTransactionHandle, wallet::Wallet};
Expand Down Expand Up @@ -93,6 +95,20 @@ impl<'a> ChangePubKeyBuilder<'a> {
self
}

/// Set the fee amount. If the provided fee is not packable,
/// returns an error.
///
/// For more details, see [utils](../utils/index.html) functions.
pub fn fee_exact(mut self, fee: impl Into<BigUint>) -> Result<Self, ClientError> {
let fee = fee.into();
if !is_fee_amount_packable(&fee) {
return Err(ClientError::NotPackableValue);
}
self.fee = Some(fee);

Ok(self)
}

/// Sets the transaction nonce.
pub fn nonce(mut self, nonce: Nonce) -> Self {
self.nonce = Some(nonce);
Expand Down
36 changes: 32 additions & 4 deletions core/sdk/src/operations/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use models::node::{
closest_packable_fee_amount, closest_packable_token_amount, Address, FranklinTx, Nonce, Token,
TokenLike, TxFeeTypes,
closest_packable_fee_amount, closest_packable_token_amount, is_fee_amount_packable,
is_token_amount_packable, Address, FranklinTx, Nonce, Token, TokenLike, TxFeeTypes,
};
use num::BigUint;

Expand Down Expand Up @@ -93,7 +93,7 @@ impl<'a> TransferBuilder<'a> {
Ok(self)
}

/// Set the transfer amount. If the amount provided is not packable,
/// Set the transfer amount. If the provided amount is not packable,
/// rounds it to the closest packable amount.
///
/// For more details, see [utils](../utils/index.html) functions.
Expand All @@ -104,7 +104,7 @@ impl<'a> TransferBuilder<'a> {
self
}

/// Set the fee amount. If the amount provided is not packable,
/// Set the fee amount. If the provided fee is not packable,
/// rounds it to the closest packable fee amount.
///
/// For more details, see [utils](../utils/index.html) functions.
Expand All @@ -115,6 +115,34 @@ impl<'a> TransferBuilder<'a> {
self
}

/// Set the transfer amount. If the provided amount is not packable,
/// returns an error.
///
/// For more details, see [utils](../utils/index.html) functions.
pub fn amount_exact(mut self, amount: impl Into<BigUint>) -> Result<Self, ClientError> {
let amount = amount.into();
if !is_token_amount_packable(&amount) {
return Err(ClientError::NotPackableValue);
}
self.amount = Some(amount);

Ok(self)
}

/// Set the fee amount. If the provided fee is not packable,
/// returns an error.
///
/// For more details, see [utils](../utils/index.html) functions.
pub fn fee_exact(mut self, fee: impl Into<BigUint>) -> Result<Self, ClientError> {
let fee = fee.into();
if !is_fee_amount_packable(&fee) {
return Err(ClientError::NotPackableValue);
}
self.fee = Some(fee);

Ok(self)
}

/// Sets the transaction recipient.
pub fn to(mut self, to: Address) -> Self {
self.to = Some(to);
Expand Down
32 changes: 30 additions & 2 deletions core/sdk/src/operations/withdraw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use models::node::{
closest_packable_fee_amount, closest_packable_token_amount, Address, FranklinTx, Nonce, Token,
TokenLike, TxFeeTypes,
closest_packable_fee_amount, closest_packable_token_amount, is_fee_amount_packable,
is_token_amount_packable, Address, FranklinTx, Nonce, Token, TokenLike, TxFeeTypes,
};
use num::BigUint;

Expand Down Expand Up @@ -115,6 +115,34 @@ impl<'a> WithdrawBuilder<'a> {
self
}

/// Set the transfer amount. If the provided amount is not packable,
/// returns an error.
///
/// For more details, see [utils](../utils/index.html) functions.
pub fn amount_exact(mut self, amount: impl Into<BigUint>) -> Result<Self, ClientError> {
let amount = amount.into();
if !is_token_amount_packable(&amount) {
return Err(ClientError::NotPackableValue);
}
self.amount = Some(amount);

Ok(self)
}

/// Set the fee amount. If the provided fee is not packable,
/// returns an error.
///
/// For more details, see [utils](../utils/index.html) functions.
pub fn fee_exact(mut self, fee: impl Into<BigUint>) -> Result<Self, ClientError> {
let fee = fee.into();
if !is_fee_amount_packable(&fee) {
return Err(ClientError::NotPackableValue);
}
self.fee = Some(fee);

Ok(self)
}

/// Sets the address of Ethereum wallet to withdraw funds to.
pub fn to(mut self, to: Address) -> Self {
self.to = Some(to);
Expand Down

0 comments on commit 948eeab

Please sign in to comment.