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

Szp/commitment purpose #33

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ jobs:
run: rustup show && cd enclave-runtime && rustup show

- name: Clippy default features
run: cargo clippy -- -D warnings
run: cargo clippy -- -D warnings -A clippy::redundant-closure-call
- name: Enclave # Enclave is separate as it's not in the workspace
run: cd enclave-runtime && cargo clippy -- -D warnings
run: cd enclave-runtime && cargo clippy -- -D warnings -A clippy::redundant-closure-call

- name: Clippy with Teeracle feature
run: |
cargo clippy --features teeracle -- -D warnings
cd enclave-runtime && cargo clippy --features teeracle -- -D warnings
cargo clippy --features teeracle -- -D warnings -A clippy::redundant-closure-call
cd enclave-runtime && cargo clippy --features teeracle -- -D warnings -A clippy::redundant-closure-call

- name: Clippy with Offchain-worker feature
run: |
cargo clippy --features offchain-worker -- -D warnings
cd enclave-runtime && cargo clippy --features offchain-worker -- -D warnings
cargo clippy --features offchain-worker -- -D warnings -A clippy::redundant-closure-call
cd enclave-runtime && cargo clippy --features offchain-worker -- -D warnings -A clippy::redundant-closure-call

- name: Fail-fast; cancel other jobs
if: failure()
Expand Down
21 changes: 18 additions & 3 deletions cli/src/personhood_oracle/commands/issue_nostr_badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api, get_worker_api_direct},
Cli,
};
use codec::Encode;
use codec::{Decode, Encode};
use encointer_primitives::{communities::CommunityIdentifier, scheduler::CeremonyIndexType};
use itc_rpc_client::direct_client::DirectApi;
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_types::DirectRequestStatus;
use itp_utils::FromHexPrefixed;
use log::*;
use nostr::{
key::FromSkStr,
prelude::{FromBech32, Secp256k1, XOnlyPublicKey},
Expand All @@ -43,7 +45,6 @@ use crate::personhood_oracle::commands::fetch_reputation::get_ceremony_index;

impl IssueNostrBadgeCmd {
pub fn run(&self, cli: &Cli) {
//todo!();
let api = get_chain_api(cli);
let direct_api = get_worker_api_direct(cli);
let cindex = get_ceremony_index(&api);
Expand Down Expand Up @@ -90,9 +91,23 @@ impl IssueNostrBadgeCmd {
let Ok(rpc_response) = serde_json::from_str::<RpcResponse>(&rpc_response_str) else {
panic!("Can't parse RPC response: '{rpc_response_str}'");
};
let _rpc_return_value = match RpcReturnValue::from_hex(&rpc_response.result) {
let rpc_return_value = match RpcReturnValue::from_hex(&rpc_response.result) {
Ok(rpc_return_value) => rpc_return_value,
Err(e) => panic!("Failed to decode RpcReturnValue: {:?}", e),
};

match rpc_return_value.status {
DirectRequestStatus::Ok => {
println!("Nostr badge issued.");
},
_ => {
let error_msg = "Nostr badge issuing failed";
error!("{}", &error_msg);
let inner_error_msg: String =
Decode::decode(&mut rpc_return_value.value.as_slice())
.expect("Failed to decode Nostr badge issuing RPC error msg");
error!("Nostr badge issuing failed: {:#?}", &inner_error_msg);
},
}
}
}
81 changes: 81 additions & 0 deletions enclave-runtime/src/rpc/encointer_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,84 @@ fn get_reputation_ocall_api(
},
}
}

fn commitment_already_there(commitment_purpose: &DescriptorType) -> Result<bool, String> {
let ocall_api = GLOBAL_OCALL_API_COMPONENT.get();
if let Err(e) = ocall_api {
Err(error!("failed to get OCALL API, error: {:#?}", e))
}
let ocall_api = ocall_api.expect("Failed to get OCALL API, but it should have succeded.");
let storage_hash = storage_value_key("encointerReputationCommitments", "currentPurposeId");
println!("storage_hash is :{:#?}", &storage_hash);

let requests = vec![WorkerRequest::ChainStorage(storage_hash, None)];
let mut resp: Vec<WorkerResponse<Vec<u8>>> = match ocall_api.worker_request(requests) {
Ok(response) => response,
Err(e) => Err(error!("Worker response decode failed. Error: {:?}", e)),
};

let first = match resp.pop() {
None => {
error!("Worker should have responded, but it did not.");
},
Some(response) => response,
};
println!("Worker response: {:?}", first);

let (_key, value, _proof) = match first {
WorkerResponse::ChainStorage(storage_key, value, proof) => (storage_key, value, proof),
};

let current_purpose_id: PurposeIdType = value;

for i in 0..=current_purpose_id {
let storage_hash = storage_map_key("encointerReputationCommitments", "purposes", i);
println!("storage_hash is :{:#?}", &storage_hash);

let requests = vec![WorkerRequest::ChainStorage(storage_hash, None)];
let mut resp: Vec<WorkerResponse<Vec<u8>>> = match ocall_api.worker_request(requests) {
Ok(response) => response,
Err(e) => {
error!("Worker response decode failed. Error: {:?}", e);
return unverified_reputation
},
};

let first = match resp.pop() {
None => {
error!("Worker should have responded, but it did not.");
return unverified_reputation
},
Some(response) => response,
};
println!("Worker response: {:?}", first);

let (_key, value, _proof) = match first {
WorkerResponse::ChainStorage(storage_key, value, proof) => (storage_key, value, proof),
};

match value {
None => (),
Some(val) => {
let current_commitment_purpose: DescriptorType = Decode::decode(&mut v.as_slice())
.expect("Failed to decode value after fetching");
if let commitment_purpose = current_commitment_purpose {
return Ok(true)
}
},
}
}

Ok(false);
}

fn register_commitment_purpose() -> Result<(), String> {
let nostr_commitment_purpose = "nostr-badge";
let nostr_commitment_purpose = DescriptorType::from_str(&nostr_commitment_purpose).unwrap();

let is_commitment_already_there = commitment_already_there(&nostr_commitment_purpose)?;

if !is_commitment_already_there {
//TODO register here
}
}
2 changes: 1 addition & 1 deletion enclave-runtime/src/rpc/worker_api_direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn issue_nostr_badge_inner(params: Params) -> Result<(), String> {
let verified_reputations = reputations.iter().filter(|rep| rep.is_verified()).count();

if verified_reputations == 0 {
return Err("The user does not havy any reputation".to_string())
return Err("The user does not have any reputation".to_string())
}

let hex_encoded_params =
Expand Down