Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate types and reexport from concordium-contracts-common #28

Merged
merged 8 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "concordium-grpc-api"]
path = concordium-grpc-api
url = ../concordium-grpc-api.git
[submodule "concordium-contracts-common"]
path = concordium-contracts-common
url = ../concordium-contracts-common.git
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
## Unreleased changes

- Expose macros for deriving `Serial` and `Deserial` from `concordium-contracts-common`.
- Address method `is_alias_of` is now `is_alias`.
Bargsteen marked this conversation as resolved.
Show resolved Hide resolved
- Replaced `ReceiveName` and `InitName` with `OwnedReceiveName` and `OwnedContractName` from `concordium-contracts-common`.
- Remove `ContractAddress` and `Address` in favor of their equivalents in `concordium-contracts-common`.
- `AccountAddress::new` is renamed to `account_address_from_registration_id`.
limemloh marked this conversation as resolved.
Show resolved Hide resolved
- `Amount` now have a field `micro_ccd` instead of `microgtu`.
limemloh marked this conversation as resolved.
Show resolved Hide resolved
- The default arithmetic (operator syntax, such as `+`, `-`, `*`) with `Amount` is now unchecked.
Bargsteen marked this conversation as resolved.
Show resolved Hide resolved
- There are no longer implementations of `From<u64> for Amount` and `From<Amount> for u64` as the behavior of these are not obvious.
limemloh marked this conversation as resolved.
Show resolved Hide resolved
Instead, the functions `Amount::from_micro_ccd` or `Amount::from_ccd` and the getter `micro_ccd` should be used instead.

## 1.1.0

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ecvrf = { version = "*", path = "./concordium-base/rust-src/ecvrf" }
aggregate_sig = { version = "*", path = "./concordium-base/rust-src/aggregate_sig" }
encrypted_transfers = { version = "*", path = "./concordium-base/rust-src/encrypted_transfers" }
eddsa_ed25519 = { version = "*", path = "./concordium-base/rust-src/eddsa_ed25519/" }
concordium-contracts-common = { version = "*", path = "./concordium-contracts-common/concordium-contracts-common", features = ["derive-serde", "sdk"]}
concordium-contracts-common = { version = "*", path = "./concordium-base/concordium-contracts-common/concordium-contracts-common", features = ["derive-serde", "sdk"]}
random_oracle = { version = "*", path = "./concordium-base/rust-src/random_oracle/" }
num-bigint = "0.4"
num-traits = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 92 files
+3 −2 .github/workflows/build-test.yaml
+1 −1 .github/workflows/rustfmt.yaml
+3 −0 .gitmodules
+8 −0 CHANGELOG.md
+2 −2 README.md
+1 −0 concordium-base.cabal
+1 −0 concordium-contracts-common
+3 −2 haskell-src/Concordium/Types/DummyData.hs
+0 −3 haskell-src/Concordium/Types/Execution.hs
+0 −1 haskell-tests/Generators.hs
+41 −4 identity-provider-service/Cargo.lock
+1 −0 identity-provider-service/Cargo.toml
+16 −4 identity-provider-service/README.md
+10 −0 identity-provider-service/data/id_recovery_request.json
+38 −0 identity-provider-service/data/valid_request_v1.json
+20 −2 identity-provider-service/html/attribute_form.html
+104 −27 identity-provider-service/src/bin/identity_verifier.rs
+836 −92 identity-provider-service/src/bin/main.rs
+4 −0 idiss-csharp/CHANGELOG.md
+42 −1 idiss-csharp/IdissExample/Program.cs
+122 −3 idiss-csharp/IdissLib/Idiss.cs
+1 −1 idiss-csharp/IdissLib/IdissLib.csproj
+55 −2 idiss-csharp/IdissLib/Types.cs
+105 −0 idiss-csharp/IdissLibTest/IdissTests.cs
+25 −1 idiss-csharp/README.md
+10 −0 idiss-csharp/data/id_recovery_request.json
+8 −1 idiss/CHANGELOG.md
+1 −1 idiss/Cargo.lock
+1 −1 idiss/Cargo.toml
+121 −10 idiss/README.md
+31 −0 idiss/example.js
+186 −1 idiss/src/cs_exports.rs
+137 −3 idiss/src/lib.rs
+217 −0 idiss/src/nodejs_exports.rs
+1 −0 mobile_wallet/.gitignore
+52 −4 mobile_wallet/Cargo.lock
+4 −5 mobile_wallet/README.md
+2 −0 mobile_wallet/android/mobile_wallet_lib/src/main/java/com/concordium/mobile_wallet_lib/wallet.kt
+4 −0 mobile_wallet/ios/module.modulemap
+23 −0 mobile_wallet/scripts/build-ios.sh
+3 −3 mobile_wallet/scripts/ios.Jenkinsfile
+4 −3 mobile_wallet/src/android.rs
+5 −5 mobile_wallet/src/lib.rs
+1 −0 package.yaml
+40 −4 rust-bins/Cargo.lock
+2 −2 rust-bins/src/bin/anonymity_revocation.rs
+1 −1 rust-bins/src/bin/client.rs
+3 −3 rust-bins/src/bin/generate_testdata.rs
+1 −1 rust-bins/src/bin/genesis_tool.rs
+1 −1 rust-bins/src/bin/identity_provider_cli.rs
+9 −7 rust-bins/src/bin/trace_account.rs
+2 −2 rust-bins/src/bin/user_cli.rs
+52 −4 rust-src/Cargo.lock
+4 −4 rust-src/bulletproofs/benches/benches.rs
+9 −8 rust-src/bulletproofs/src/range_proof.rs
+5 −0 rust-src/crypto_common/Cargo.toml
+3 −6 rust-src/crypto_common/src/serialize.rs
+78 −238 rust-src/crypto_common/src/types.rs
+28 −10 rust-src/crypto_common_derive/src/lib.rs
+1 −4 rust-src/curve_arithmetic/benches/hash_bench.rs
+10 −10 rust-src/curve_arithmetic/src/bls12_381_g1hash.rs
+0 −1 rust-src/curve_arithmetic/src/secret_value.rs
+2 −2 rust-src/ecvrf/src/public.rs
+2 −2 rust-src/ecvrf/src/secret.rs
+1 −1 rust-src/ed25519_hd_key_derivation/src/lib.rs
+2 −8 rust-src/eddsa_ed25519/benches/eddsa_benchmarks.rs
+2 −2 rust-src/elgamal/src/public.rs
+0 −1 rust-src/elgamal/src/secret.rs
+8 −8 rust-src/encrypted_transfers/benches/enc_trans_benchmarks.rs
+20 −13 rust-src/encrypted_transfers/src/ffi.rs
+17 −13 rust-src/encrypted_transfers/src/lib.rs
+10 −10 rust-src/encrypted_transfers/src/proofs/generate_proofs.rs
+0 −3 rust-src/id/Cargo.toml
+39 −0 rust-src/id/src/account_holder.rs
+2 −2 rust-src/id/src/chain.rs
+4 −4 rust-src/id/src/id_verifier.rs
+184 −1 rust-src/id/src/identity_provider.rs
+6 −8 rust-src/id/src/secret_sharing.rs
+1 −1 rust-src/id/src/sigma_protocols/aggregate_dlog.rs
+1 −1 rust-src/id/src/sigma_protocols/com_enc_eq.rs
+1 −1 rust-src/id/src/sigma_protocols/com_eq.rs
+1 −1 rust-src/id/src/sigma_protocols/com_eq_different_groups.rs
+3 −3 rust-src/id/src/sigma_protocols/com_eq_sig.rs
+3 −3 rust-src/id/src/sigma_protocols/com_lin.rs
+4 −6 rust-src/id/src/sigma_protocols/com_mult.rs
+3 −3 rust-src/id/src/sigma_protocols/common.rs
+1 −1 rust-src/id/src/sigma_protocols/dlog.rs
+4 −4 rust-src/id/src/test.rs
+32 −114 rust-src/id/src/types.rs
+2 −2 rust-src/keygen_bls/src/lib.rs
+1 −1 rust-src/ps_sig/src/public.rs
+5 −5 rust-src/random_oracle/src/lib.rs
1 change: 0 additions & 1 deletion concordium-contracts-common
Submodule concordium-contracts-common deleted from a97a22
7 changes: 1 addition & 6 deletions examples/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ fn main() -> anyhow::Result<()> {

if let Some((head, rest)) = app.addresses.split_first() {
for addr in rest {
anyhow::ensure!(
addr.is_alias_of(head),
"{} is not an alias of {}.",
addr,
head
);
anyhow::ensure!(addr.is_alias(head), "{} is not an alias of {}.", addr, head);
}
}

Expand Down
41 changes: 17 additions & 24 deletions examples/balance-summary.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! List accounts with the most liquid balance, and total stake, total amount,
//! and total liquid amount of accounts. Additionally list contracts with at
//! most CCD owned.
use anyhow::Context;
use clap::AppSettings;
use concordium_rust_sdk::{endpoints, types::hashes::BlockHash};
use crypto_common::types::Amount;
Expand Down Expand Up @@ -110,43 +109,37 @@ async fn main() -> anyhow::Result<()> {
let info = client.get_account_info(acc, &block).await?;
let additional_stake = info
.account_stake
.map_or(Amount::from(0), |baker_delegator| {
.map_or(Amount::zero(), |baker_delegator| {
baker_delegator.staked_amount()
});
let additional_liquid_amount = info.account_amount.microccd
- std::cmp::max(
additional_stake.microccd,
info.account_release_schedule.total.microccd,
);
let additional_liquid_amount = info.account_amount
- std::cmp::max(additional_stake, info.account_release_schedule.total);
Ok::<_, anyhow::Error>((
acc,
additional_stake,
info.account_amount,
info.account_release_schedule.total,
Amount::from(additional_liquid_amount),
additional_liquid_amount,
))
}
},
app.num,
)
.await;
let mut out = Vec::new();
let mut staked_amount: Amount = 0.into();
let mut total_amount: Amount = 0.into();
let mut locked_amount: Amount = 0.into();
let mut liquid_amount: Amount = 0.into();
let mut staked_amount = Amount::zero();
let mut total_amount = Amount::zero();
let mut locked_amount = Amount::zero();
let mut liquid_amount = Amount::zero();

while let Some(res) = receiver.recv().await {
let (acc, additional_stake, additional_amount, additional_scheduled, additional_liquid) =
res?;
staked_amount = (staked_amount + additional_stake)
.context("Total staked amount exceeds u64. This should not happen.")?;
total_amount = (total_amount + additional_amount)
.context("Total amount exceeds u64. This should not happen.")?;
locked_amount = (locked_amount + additional_scheduled)
.context("Total amount exceeds u64. This should not happen.")?;
liquid_amount = (liquid_amount + additional_liquid)
.context("Total amount exceeds u64. This should not happen.")?;
staked_amount += additional_stake;
total_amount += additional_amount;
locked_amount += additional_scheduled;
liquid_amount += additional_liquid;

out.push((acc, additional_liquid, additional_amount));
}

Expand All @@ -168,7 +161,7 @@ async fn main() -> anyhow::Result<()> {
}

// Now also handle contracts.
let mut total_contract_amount = Amount::from(0);
let mut total_contract_amount = Amount::zero();
let contracts = client.get_instances(&block).await?;
let mut cout = Vec::new();
for ccs in contracts.chunks(app.num).map(Vec::from) {
Expand All @@ -182,8 +175,8 @@ async fn main() -> anyhow::Result<()> {
}
for res in futures::future::join_all(handles).await {
let (addr, info) = res??;
total_contract_amount = (total_contract_amount + info.amount())
.context("Total amount exceeds u64. This should not happen.")?;
total_contract_amount += info.amount();

cout.push((addr, info));
}
}
Expand All @@ -192,7 +185,7 @@ async fn main() -> anyhow::Result<()> {
for (addr, info) in cout.iter().take(20) {
println!(
"{}: at <{}, {}> owns {}",
<&str as From<_>>::from(info.name()),
info.name().as_contract_name().get_chain_name(),
addr.index,
addr.subindex,
info.amount()
Expand Down
7 changes: 5 additions & 2 deletions examples/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ async fn main() -> anyhow::Result<()> {
println!("There are {} accounts.", bi.len());
for i in 0..32 {
let mut tmp = bi.clone();
let compare =
|l: &AccountAddress, r: &AccountAddress| l.as_ref()[0..i].cmp(&r.as_ref()[0..i]);
let compare = |l: &AccountAddress, r: &AccountAddress| {
let l_bytes: &[u8] = l.as_ref();
let r_bytes: &[u8] = r.as_ref();
l_bytes[0..i].cmp(&r_bytes[0..i])
};
tmp.sort_by(compare);
tmp.dedup_by(|l, r| compare(l, r).is_eq());
if tmp.len() < bi.len() {
Expand Down
12 changes: 7 additions & 5 deletions examples/create-initial-accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ use concordium_rust_sdk::{
curve_arithmetic::Curve,
dodis_yampolskiy_prf::SecretKey,
types::{
AccountAddress, AccountCredential, AccountCredentialMessage, AccountKeys,
AttributeList, CredentialData, CredentialPublicKeys, IpData, PublicCredentialData,
AccountCredential, AccountCredentialMessage, AccountKeys, AttributeList,
CredentialData, CredentialPublicKeys, IpData, PublicCredentialData,
PublicInformationForIp, SignatureThreshold, YearMonth,
},
},
types::transactions::{BlockItem, Payload},
};
use id::{
constants::AttributeKind, curve_arithmetic::Value, pedersen_commitment::Randomness,
types::AttributeTag,
constants::AttributeKind,
curve_arithmetic::Value,
pedersen_commitment::Randomness,
types::{account_address_from_registration_id, AttributeTag},
};
use rand::thread_rng;
use std::path::PathBuf;
Expand Down Expand Up @@ -127,7 +129,7 @@ async fn main() -> anyhow::Result<()> {
threshold: cdata.get_threshold(),
},
};
let address = AccountAddress::new(&pub_info_for_ip.reg_id);
let address = account_address_from_registration_id(&pub_info_for_ip.reg_id);
let icdi = id::identity_provider::create_initial_cdi(
&ip_data.public_ip_info,
pub_info_for_ip,
Expand Down
7 changes: 5 additions & 2 deletions examples/generator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use anyhow::Context;
use clap::AppSettings;
use concordium_rust_sdk::{
common::{types::TransactionTime, SerdeDeserialize, SerdeSerialize},
common::{
types::{Amount, TransactionTime},
SerdeDeserialize, SerdeSerialize,
},
endpoints,
id::types::{AccountAddress, AccountKeys},
types::{
Expand Down Expand Up @@ -90,7 +93,7 @@ async fn main() -> anyhow::Result<()> {
nonce,
expiry,
accounts[count % accounts.len()],
0.into(),
Amount::zero(),
);
nonce.next_mut();
count += 1;
Expand Down
20 changes: 9 additions & 11 deletions examples/list-account-balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ async fn main() -> anyhow::Result<()> {
let total_accounts = accounts.len();
let mut num_bakers = 0;
let mut num_initial = 0;
let mut total_staked_amount: Amount = 0.into();
let mut total_delegated_amount: Amount = 0.into();
let mut total_amount: Amount = 0.into();
let mut total_staked_amount = Amount::zero();
let mut total_delegated_amount = Amount::zero();
let mut total_amount = Amount::zero();

let mut acc_balances = Vec::with_capacity(accounts.len());
for accs in accounts.chunks(app.num).map(Vec::from) {
Expand All @@ -107,22 +107,20 @@ async fn main() -> anyhow::Result<()> {
match account_stake {
AccountStakingInfo::Baker { staked_amount, .. } => {
num_bakers += 1;
total_staked_amount = (total_staked_amount + staked_amount)
.context("Total staked amount exceeds u64. This should not happen.")?;
total_staked_amount += staked_amount;
true
}
AccountStakingInfo::Delegated { staked_amount, .. } => {
total_delegated_amount = (total_delegated_amount + staked_amount)
.context("Total staked amount exceeds u64. This should not happen.")?;
total_delegated_amount += staked_amount;

false
}
}
} else {
false
};

total_amount = (total_amount + info.account_amount)
.context("Total amount exceeds u64. This should not happen.")?;
total_amount += info.account_amount;

let acc_type =
info.account_credentials
Expand Down Expand Up @@ -168,12 +166,12 @@ async fn main() -> anyhow::Result<()> {
println!(
"Total amount of staked CCD is {}, which amounts to {:.2}%.",
total_staked_amount,
(u64::from(total_staked_amount) as f64 / u64::from(total_amount) as f64) * 100f64
(total_staked_amount.micro_ccd() as f64 / total_amount.micro_ccd() as f64) * 100f64
);
println!(
"Total amount of delegated CCD is {}, which amounts to {:.2}%.",
total_delegated_amount,
(u64::from(total_delegated_amount) as f64 / u64::from(total_amount) as f64) * 100f64
(total_delegated_amount.micro_ccd() as f64 / total_amount.micro_ccd() as f64) * 100f64
);

Ok(())
Expand Down
16 changes: 6 additions & 10 deletions examples/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ async fn main() -> anyhow::Result<()> {
.await;

let rows = db
.query_contract(
ContractAddress::new(0.into(), 0.into()),
20,
QueryOrder::Ascending { start: None },
)
.query_contract(ContractAddress::new(0, 0), 20, QueryOrder::Ascending {
start: None,
})
.await?;
rows.for_each(|entry| async move {
println!("{:?}", entry);
Expand All @@ -64,11 +62,9 @@ async fn main() -> anyhow::Result<()> {
.await;

let rows = db
.query_contract(
ContractAddress::new(0.into(), 0.into()),
20,
QueryOrder::Descending { start: None },
)
.query_contract(ContractAddress::new(0, 0), 20, QueryOrder::Descending {
start: None,
})
.await?;
rows.for_each(|entry| async move {
println!("{:?}", entry);
Expand Down
11 changes: 7 additions & 4 deletions examples/total-stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ async fn main() -> anyhow::Result<()> {
} = pool
{
active_bakers += 1;
equity += u64::from(current_payday_status.baker_equity_capital);
delegated += u64::from(current_payday_status.delegated_capital);
effective += u64::from(current_payday_status.effective_stake);
equity += current_payday_status.baker_equity_capital.micro_ccd();
delegated += current_payday_status.delegated_capital.micro_ccd();
effective += current_payday_status.effective_stake.micro_ccd();
}
}
println!("There are {} bakers.", active_bakers);
Expand All @@ -67,7 +67,10 @@ async fn main() -> anyhow::Result<()> {
"Total equity capital is {} CCD",
Amount::from_micro_ccd(equity)
);
println!("Total delegated stake is {} CCD", Amount::from(delegated));
println!(
"Total delegated stake is {} CCD",
Amount::from_micro_ccd(delegated)
);

Ok(())
}
Loading