Skip to content

Commit

Permalink
closes #7. all public getters implemented (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi authored Jun 24, 2020
1 parent a8772b6 commit 53e9ef9
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 32 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"

[[package]]
name = "encointer-client-teeproxy"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"base58",
"blake2-rfc",
Expand Down Expand Up @@ -640,7 +640,7 @@ dependencies = [

[[package]]
name = "encointer-worker"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"base58",
"cid",
Expand Down Expand Up @@ -3996,7 +3996,7 @@ checksum = "d2a965994514ab35d3893e9260245f2947fd1981cdd4fffd2c6e6d1a9ce02e6a"

[[package]]
name = "substratee-node-primitives"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"base58",
"encointer-node-teeproxy-runtime",
Expand All @@ -4011,7 +4011,7 @@ dependencies = [

[[package]]
name = "substratee-stf"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"base58",
"clap",
Expand Down Expand Up @@ -4043,7 +4043,7 @@ dependencies = [

[[package]]
name = "substratee-worker-api"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"hex 0.4.2",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "encointer-client-teeproxy"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["Supercomputing Systems AG <[email protected]>"]
edition = "2018"

Expand Down
18 changes: 11 additions & 7 deletions client/bootstrap_demo_currency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ $CLIENT trusted get-registration $account3 --mrenclave $MRENCLAVE --shard $cid

wait_for_phase ASSIGNING

# nothing to do here until we can have debug getters
echo "* Waiting 30 seconds such that phase change happened in enclave"
sleep 30
echo ""

$CLIENT trusted info --mrenclave $MRENCLAVE --shard $cid

wait_for_phase ATTESTING

echo "* Waiting 5 seconds such that phase change happened in enclave"
sleep 5
echo "* Waiting 30 seconds such that phase change happened in enclave"
sleep 30
echo ""

echo "*** start meetup"
Expand Down Expand Up @@ -119,13 +123,13 @@ $CLIENT trusted get-attestations $account3 --mrenclave $MRENCLAVE --shard $cid

wait_for_phase REGISTERING

echo "* Waiting 5 seconds such that phase change happened in enclave"
sleep 5
echo "* Waiting 30 seconds such that phase change happened in enclave"
sleep 30
echo ""

echo "account balances for new currency with cid $cid"
$CLIENT trusted balance $account1 --mrenclave $MRENCLAVE --shard $cid
$CLIENT trusted balance $account2 --mrenclave $MRENCLAVE --shard $cid
$CLIENT trusted balance $account3 --mrenclave $MRENCLAVE --shard $cid
echo "total issuance (publicly readable)"
$CLIENT trusted total-issuance --mrenclave $MRENCLAVE --shard $cid
echo "currency info (publicly readable)"
$CLIENT trusted info --mrenclave $MRENCLAVE --shard $cid
2 changes: 1 addition & 1 deletion client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ fn main() {
compose_extrinsic!(api.clone(), "EncointerScheduler", "next_phase");

// send and watch extrinsic until finalized
let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::Finalized).unwrap();
let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap();
let phase = get_current_phase(&api);
println!(
"Transaction got finalized. Phase is now: {:?}. tx hash: {:?}",
Expand Down
14 changes: 7 additions & 7 deletions enclave/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "chain-relay"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"derive_more 0.99.5 (registry+https://github.com/rust-lang/crates.io-index)",
"finality-grandpa 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2120,7 +2120,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "substratee-node-primitives"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"parity-scale-codec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"primitive-types 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand All @@ -2130,7 +2130,7 @@ dependencies = [

[[package]]
name = "substratee-stf"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"derive_more 0.99.5 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.7.1 (git+https://github.com/mesalock-linux/env_logger-sgx)",
Expand All @@ -2153,12 +2153,12 @@ dependencies = [

[[package]]
name = "substratee-worker-enclave"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
dependencies = [
"aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.10.1 (git+https://github.com/mesalock-linux/rust-base64-sgx)",
"bit-vec 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chain-relay 0.6.8-sub2.0.0-alpha.7",
"chain-relay 0.6.9-sub2.0.0-alpha.7",
"chrono 0.4.11 (git+https://github.com/mesalock-linux/chrono-sgx)",
"env_logger 0.7.1 (git+https://github.com/mesalock-linux/env_logger-sgx)",
"httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2192,8 +2192,8 @@ dependencies = [
"sp-runtime 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)",
"sp-std 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-api-client 0.4.6-sub2.0.0-alpha.7 (git+https://github.com/scs/substrate-api-client?tag=v0.4.6-sub2.0.0-alpha.7)",
"substratee-node-primitives 0.6.8-sub2.0.0-alpha.7",
"substratee-stf 0.6.8-sub2.0.0-alpha.7",
"substratee-node-primitives 0.6.9-sub2.0.0-alpha.7",
"substratee-stf 0.6.9-sub2.0.0-alpha.7",
"webpki 0.21.2 (git+https://github.com/mesalock-linux/webpki?branch=mesalock_sgx)",
"webpki-roots 0.19.0 (git+https://github.com/mesalock-linux/webpki-roots?branch=mesalock_sgx)",
"yasna 0.3.1 (git+https://github.com/mesalock-linux/yasna.rs-sgx?rev=sgx_1.1.2)",
Expand Down
2 changes: 1 addition & 1 deletion enclave/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substratee-worker-enclave"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["Supercomputing Systems AG <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion enclave/chain_relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chain-relay"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["Supercomputing Systems AG <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion stf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substratee-stf"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["Supercomputing Systems AG <[email protected]>"]
edition = "2018"

Expand Down
48 changes: 45 additions & 3 deletions stf/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ pub fn cmd<'a>(
}),
)
.add_cmd(
Command::new("total-issuance")
.description("query total issuance for currency (public information)")
Command::new("info")
.description("query various statistics and settings for a currency (public information)")
.runner(move |_args: &str, matches: &ArgMatches<'_>| {
let (_mrenclave, shard) = get_identifiers(matches);
println!("Public information about currency {}", shard.encode().to_base58());
let top: TrustedOperation = PublicGetter::total_issuance(shard)
.into();
let res = perform_operation(matches, &top);
Expand All @@ -229,7 +230,48 @@ pub fn cmd<'a>(
} else {
BalanceType::from_num(0)
};
println!("{}", bal);
println!(" total issuance: {}", bal);

let top: TrustedOperation = PublicGetter::participant_count(shard)
.into();
if let Some(v) = perform_operation(matches, &top) {
if let Ok(vd) = ParticipantIndexType::decode(&mut v.as_slice()) {
println!(" participant count: {}", vd);
} else { println!(" participant count: error decoding"); }
} else { println!(" participant count: undisclosed (might be REGISTERING phase?)"); };

let top: TrustedOperation = PublicGetter::meetup_count(shard)
.into();
if let Some(v) = perform_operation(matches, &top) {
if let Ok(vd) = MeetupIndexType::decode(&mut v.as_slice()) {
println!(" meetup count: {}", vd);
} else { println!(" meetup count: error decoding"); }
} else { println!(" meetup count: unknown"); };

let top: TrustedOperation = PublicGetter::ceremony_reward(shard)
.into();
if let Some(v) = perform_operation(matches, &top) {
if let Ok(vd) = BalanceType::decode(&mut v.as_slice()) {
println!(" ceremony reward: {}", vd);
} else { println!(" ceremony reward: error decoding"); }
} else { println!(" ceremony reward: unknown"); };

let top: TrustedOperation = PublicGetter::location_tolerance(shard)
.into();
if let Some(v) = perform_operation(matches, &top) {
if let Ok(vd) = u32::decode(&mut v.as_slice()) {
println!(" location tolerance: {}m", vd);
} else { println!(" location tolerance: error decoding"); }
} else { println!(" location tolerance: unknown"); };

let top: TrustedOperation = PublicGetter::time_tolerance(shard)
.into();
if let Some(v) = perform_operation(matches, &top) {
if let Ok(vd) = Moment::decode(&mut v.as_slice()) {
println!(" time tolerance: {}m", vd);
} else { println!(" time tolerance: unknown nodecode"); }
} else { println!(" time tolerance: unknown"); };

Ok(())
}),
)
Expand Down
7 changes: 6 additions & 1 deletion stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ impl From<TrustedGetterSigned> for Getter {
#[derive(Encode, Decode, Clone, Debug)]
#[allow(non_camel_case_types)]
pub enum PublicGetter {
total_issuance(CurrencyIdentifier),
total_issuance(CurrencyIdentifier),
participant_count(CurrencyIdentifier),
meetup_count(CurrencyIdentifier),
ceremony_reward(CurrencyIdentifier),
location_tolerance(CurrencyIdentifier),
time_tolerance(CurrencyIdentifier),
}

#[derive(Encode, Decode, Clone, Debug)]
Expand Down
32 changes: 31 additions & 1 deletion stf/src/sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,37 @@ impl Stf {
let c_index = encointer_scheduler::Module::<sgx_runtime::Runtime>::current_ceremony_index();
let balance: BalanceEntry<BlockNumber> = encointer_balances::Module::<sgx_runtime::Runtime>::total_issuance_entry(cid);
Some(balance.encode())
}
},
PublicGetter::participant_count(cid) => {
let c_index = encointer_scheduler::Module::<sgx_runtime::Runtime>::current_ceremony_index();
match encointer_scheduler::Module::<sgx_runtime::Runtime>::current_phase() {
CeremonyPhaseType::REGISTERING => {
warn!("querying participant count during registering phase not allowed for privacy reasons");
None
},
_ => {
let count = encointer_ceremonies::Module::<sgx_runtime::Runtime>::participant_count((cid, c_index));
Some(count.encode())
}
}
},
PublicGetter::meetup_count(cid) => {
let c_index = encointer_scheduler::Module::<sgx_runtime::Runtime>::current_ceremony_index();
let count = encointer_ceremonies::Module::<sgx_runtime::Runtime>::meetup_count((cid, c_index));
Some(count.encode())
},
PublicGetter::ceremony_reward(cid) => {
let reward = encointer_ceremonies::Module::<sgx_runtime::Runtime>::ceremony_reward();
Some(reward.encode())
},
PublicGetter::location_tolerance(cid) => {
let tol = encointer_ceremonies::Module::<sgx_runtime::Runtime>::location_tolerance();
Some(tol.encode())
},
PublicGetter::time_tolerance(cid) => {
let tol = encointer_ceremonies::Module::<sgx_runtime::Runtime>::time_tolerance();
Some(tol.encode())
}
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion substratee-node-primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substratee-node-primitives"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["clangenbacher <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "encointer-worker"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["Supercomputing Systems AG <[email protected]>"]
build = "build.rs"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion worker/worker-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substratee-worker-api"
version = "0.6.8-sub2.0.0-alpha.7"
version = "0.6.9-sub2.0.0-alpha.7"
authors = ["Supercomputing Systems AG <[email protected]>"]
edition = "2018"

Expand Down

0 comments on commit 53e9ef9

Please sign in to comment.