Skip to content

Commit

Permalink
additions and fixes in wasm, query server and ledger (#173)
Browse files Browse the repository at this point in the history
also dependencies and misc changes
  • Loading branch information
akhilpeddireddy authored Jan 11, 2022
1 parent a0da963 commit 96fbbc5
Show file tree
Hide file tree
Showing 28 changed files with 1,220 additions and 75 deletions.
5 changes: 2 additions & 3 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ percent-encoding = "2.1.0"

nix = "0.22.1"

zei = { git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
crypto = { directory = "crypto", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
ruc = "0.6.6"
abci = { git = "https://github.com/FindoraNetwork/rust-abci", tag = "v0.7.2" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use {
globutils::HashOf,
ledger::{
data_model::{
AssetType, AssetTypeCode, AuthenticatedUtxo, StateCommitmentData, TxnSID,
TxoSID, UnAuthenticatedUtxo, Utxo,
ATxoSID, AssetType, AssetTypeCode, AuthenticatedUtxo, StateCommitmentData,
TxnSID, TxoSID, UnAuthenticatedUtxo, Utxo,
},
staking::{
DelegationRwdDetail, DelegationState, Staking, TendermintAddr,
Expand All @@ -24,6 +24,7 @@ use {
ruc::*,
serde::{Deserialize, Serialize},
std::{collections::BTreeMap, mem, sync::Arc},
zei::anon_xfr::structs::AnonBlindAssetRecord,
zei::xfr::{sig::XfrPublicKey, structs::OwnerMemo},
};

Expand Down Expand Up @@ -738,6 +739,7 @@ impl NetworkRoute for ApiRoutes {
ApiRoutes::DelegationInfo => "delegation_info",
ApiRoutes::DelegatorList => "delegator_list",
ApiRoutes::ValidatorDetail => "validator_detail",
ApiRoutes::OwnedAbars => "owned_abars",
};
"/".to_owned() + endpoint
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/abciapp/src/api/query_server/query_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use {
globutils::wallet,
ledger::{
data_model::{
b64dec, AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction, TxOutput,
TxnIDHash, TxnSID, TxoSID, XfrAddress, BLACK_HOLE_PUBKEY,
b64dec, ATxoSID, AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction,
TxOutput, TxnIDHash, TxnSID, TxoSID, XfrAddress, BLACK_HOLE_PUBKEY,
},
staking::{
ops::mint_fra::MintEntry, FF_PK_EXTRA_120_0000, FRA, FRA_TOTAL_AMOUNT,
Expand All @@ -33,6 +33,7 @@ use {
sync::Arc,
},
zei::{
anon_xfr::structs::MTLeafInfo,
serialization::ZeiFromToBytes,
xfr::{sig::XfrPublicKey, structs::OwnerMemo},
},
Expand Down Expand Up @@ -123,11 +124,12 @@ async fn get_owned_abars(
owner: web::Path<String>,
) -> actix_web::Result<web::Json<HashSet<ATxoSID>>> {
let qs = data.read();
let read = qs.state.as_ref().unwrap().read();
let ledger = &qs.ledger_cloned;
//let read = qs.state.as_ref().unwrap().read();
globutils::wallet::anon_public_key_from_base64(owner.as_str())
.c(d!())
.map_err(|e| error::ErrorBadRequest(e.generate_log(None)))
.map(|pk| web::Json(read.get_owned_abars(&pk).iter().map(|a| a.0).collect()))
.map(|pk| web::Json(ledger.get_owned_abars(&pk).iter().map(|a| a.0).collect()))
}
/// Returns the merkle proof for anonymous transactions
async fn get_abar_proof(
Expand Down
21 changes: 19 additions & 2 deletions src/components/abciapp/src/api/query_server/query_api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
lazy_static::lazy_static,
ledger::{
data_model::{
AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction, TxOutput,
ATxoSID, AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction, TxOutput,
TxnIDHash, TxnSID, TxoSID, XfrAddress,
},
staking::{ops::mint_fra::MintEntry, BlockHeight},
Expand All @@ -15,7 +15,7 @@ use {
parking_lot::{Condvar, Mutex, RwLock},
ruc::*,
std::{collections::HashSet, sync::Arc},
zei::xfr::structs::OwnerMemo,
zei::{anon_xfr::structs::MTLeafInfo, xfr::structs::OwnerMemo},
};

lazy_static! {
Expand Down Expand Up @@ -300,6 +300,23 @@ impl QueryServer {
.get(&txo_sid)
}

/// Returns the abar owner memo required to decrypt the asset record stored at given index, if it exists.
#[inline(always)]
pub fn get_abar_memo(&self, atxo_sid: ATxoSID) -> Option<OwnerMemo> {
self.ledger_cloned
.api_cache
.as_ref()
.unwrap()
.abar_memos
.get(&atxo_sid)
}

/// Returns the merkle proof from the given ATxoSID
#[inline(always)]
pub fn get_abar_proof(&self, atxo_sid: ATxoSID) -> Option<MTLeafInfo> {
Some(self.ledger_cloned.get_abar_proof(atxo_sid).unwrap())
}

/// retrieve block reward rate at specified block height
#[inline(always)]
pub fn query_block_rewards_rate(&self, height: &BlockHeight) -> Option<[u128; 2]> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protobuf = "2.16"
ruc = "0.6.6"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.40"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.1.1a" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", branch = "develop" }

# primitives
fp-core = { path = "../primitives/core" }
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ primitive-types = { version = "0.10.0", default-features = false, features = ["r
ruc = "0.6.6"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.1.1a" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", branch = "develop" }

# primitives, don't depend on any modules
fp-core = { path = "../../primitives/core" }
Expand All @@ -26,4 +26,4 @@ fp-types = { path = "../../primitives/types" }
[dev-dependencies]
parking_lot = "0.11.1"
rand_chacha = "0.2.0"
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4e" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parking_lot = "0.11.1"
primitive-types = { version = "0.10.0", default-features = false, features = ["rlp", "byteorder", "serde"] }
ruc = "0.6.6"
serde = { version = "1.0.124", features = ["derive"] }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.1.1a" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", branch = "develop" }
serde_with = { version = "1.9.4"}

# primitives
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rand_chacha = "0.2.0"
rlp = "0.5"
serde_json = "1.0"
sha3 = "0.8"
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4e" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }

# primitives
fp-traits = { path = "../traits" }
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ruc = "0.6.6"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.9.5"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.1.1a" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", branch = "develop" }

# primitives
fp-core = { path = "../core" }
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ruc = "0.6.6"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0"
sha3 = "0.8"
zei = { git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
fixed-hash = "0.7.0"

# primitives
Expand Down
6 changes: 3 additions & 3 deletions src/components/finutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ parking_lot = "0.11.1"
curve25519-dalek = { version = "3.0", features = ["serde"] }
wasm-bindgen = { version = "0.2.50", features = ["serde-serialize"] }

zei = { git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
crypto = { package = "crypto", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
crypto = { package = "crypto", git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4f" }
ruc = "0.6.6"

ledger = { path = "../../ledger" }
Expand Down
2 changes: 2 additions & 0 deletions src/components/finutils/src/bins/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use {
data_model::{ATxoSID, AssetTypeCode, FRA_DECIMALS},
staking::StakerMemo,
},
rand_chacha::ChaChaRng,
rand_core::SeedableRng,
ruc::*,
serde::{Deserialize, Serialize},
std::fs::File,
Expand Down
58 changes: 54 additions & 4 deletions src/components/finutils/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use {
globutils::{wallet, HashOf, SignatureOf},
ledger::{
data_model::{
ATxoSID, AssetType, AssetTypeCode, DefineAsset, Operation, StateCommitmentData,
Transaction, TransferType, TxoRef, TxoSID, Utxo, ASSET_TYPE_FRA,
BLACK_HOLE_PUBKEY, TX_FEE_MIN,
ATxoSID, AssetType, AssetTypeCode, DefineAsset, Operation,
StateCommitmentData, Transaction, TransferType, TxoRef, TxoSID, Utxo,
ASSET_TYPE_FRA, BLACK_HOLE_PUBKEY, TX_FEE_MIN,
},
staking::{init::get_inital_validators, TendermintAddrRef, FRA_TOTAL_AMOUNT},
},
Expand Down Expand Up @@ -332,7 +332,7 @@ pub fn gen_fee_bar_to_abar(
}

trans_builder
.balance()
.balance(None)
.c(d!())?
.create(TransferType::Standard)
.c(d!())?
Expand Down Expand Up @@ -687,3 +687,53 @@ pub struct ValidatorKey {
pub fn parse_td_validator_keys(key_data: &str) -> Result<ValidatorKey> {
serde_json::from_str(key_data).c(d!())
}

#[inline(always)]
#[allow(missing_docs)]
pub fn generate_bar2abar_op(
auth_key_pair: &XfrKeyPair,
abar_pub_key: &AXfrPubKey,
txo_sid: TxoSID,
input_record: &OpenAssetRecord,
enc_key: &XPublicKey,
) -> Result<JubjubScalar> {
let mut builder: TransactionBuilder = new_tx_builder().c(d!())?;
let (_, r) = builder
.add_operation_bar_to_abar(
auth_key_pair,
abar_pub_key,
txo_sid,
input_record,
enc_key,
)
.c(d!())?;

if input_record.get_record_type() != NonConfidentialAmount_NonConfidentialAssetType
|| input_record.asset_type != ASSET_TYPE_FRA
{
let feeop = gen_fee_bar_to_abar(auth_key_pair, txo_sid).c(d!())?;
builder.add_operation(feeop);
}

send_tx(&builder.take_transaction()).c(d!())?;
Ok(r)
}

#[inline(always)]
#[allow(missing_docs)]
pub fn get_oar(owner_kp: &XfrKeyPair, txo_sid: TxoSID) -> Result<OpenAssetRecord> {
let utxos = get_owned_utxos(owner_kp.get_pk_ref()).c(d!())?.into_iter();

for (sid, (utxo, owner_memo)) in utxos {
if sid != txo_sid {
continue;
}

let oar =
open_blind_asset_record(&utxo.0.record, &owner_memo, owner_kp).c(d!())?;

return Ok(oar);
}

Err(eg!("utxo not found"))
}
2 changes: 1 addition & 1 deletion src/components/finutils/src/txn_builder/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ impl Neg for Amount {
fn neg(self) -> Self {
Amount(-self.0)
}
}
}
Loading

0 comments on commit 96fbbc5

Please sign in to comment.