diff --git a/pallets/vc-management/src/assertion.rs b/pallets/vc-management/src/assertion.rs index af136ba126..2cea9acb22 100644 --- a/pallets/vc-management/src/assertion.rs +++ b/pallets/vc-management/src/assertion.rs @@ -32,7 +32,7 @@ pub enum Assertion { A1, A2(ParameterString, ParameterString), // (guild_id, user_id) A3(ParameterString, ParameterString), // (guild_id, user_id) - A4, + A4(Balance, ParameterString), // (LIT_amount, timestamp, e.g.: 2022-10-16T00:00:00Z) A5(ParameterString, ParameterString), // (twitter_account, tweet_id) A6, A7(Balance, u32), // (DOT_amount, year) @@ -40,6 +40,5 @@ pub enum Assertion { A9, A10(Balance, u32), // (WBTC_amount, year) A11(Balance, u32), // (ETH_amount, year) - A12(Balance, u32), // (LIT_amount, year) A13(u32), // (Karma_amount) - TODO: unsupported } diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index c41cbc9735..8f282e4c0b 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -5993,6 +5993,7 @@ dependencies = [ name = "lc-data-providers" version = "0.1.0" dependencies = [ + "chrono 0.4.23", "hex 0.4.0", "hex 0.4.3", "http 0.2.1", @@ -6074,6 +6075,8 @@ dependencies = [ name = "lc-stf-task-receiver" version = "0.1.0" dependencies = [ + "chrono 0.4.11", + "chrono 0.4.23", "frame-support", "futures 0.3.25", "futures 0.3.8", diff --git a/tee-worker/enclave-runtime/Cargo.lock b/tee-worker/enclave-runtime/Cargo.lock index e97df38ac0..beed9f93ac 100644 --- a/tee-worker/enclave-runtime/Cargo.lock +++ b/tee-worker/enclave-runtime/Cargo.lock @@ -2549,6 +2549,7 @@ dependencies = [ name = "lc-stf-task-receiver" version = "0.1.0" dependencies = [ + "chrono 0.4.11", "frame-support", "futures 0.3.8", "hex 0.4.0", diff --git a/tee-worker/litentry/core/assertion-build/src/a3.rs b/tee-worker/litentry/core/assertion-build/src/a3.rs index dd2cc5f76b..6594b09705 100644 --- a/tee-worker/litentry/core/assertion-build/src/a3.rs +++ b/tee-worker/litentry/core/assertion-build/src/a3.rs @@ -30,7 +30,7 @@ pub fn build(guild_id: ParameterString, handler: ParameterString) -> Result<()> let mut client = DiscordLitentryClient::new(); match client.check_id_hubber(guild_id.into_inner(), handler.into_inner()) { Err(e) => { - log::error!("error build assertion2: {:?}", e); + log::error!("error build assertion3: {:?}", e); Err(Error::Assertion3Error(format!("{:?}", e))) }, Ok(_response) => { diff --git a/tee-worker/litentry/core/assertion-build/src/a4.rs b/tee-worker/litentry/core/assertion-build/src/a4.rs new file mode 100644 index 0000000000..6f84f67631 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/a4.rs @@ -0,0 +1,99 @@ +// Copyright 2020-2022 Litentry Technologies GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +#[cfg(all(feature = "std", feature = "sgx"))] +compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +extern crate sgx_tstd as std; + +use crate::{Error, Result}; +use std::{ + str::from_utf8, + string::{String, ToString}, + vec, + vec::Vec, +}; + +use lc_stf_task_sender::MaxIdentityLength; +use litentry_primitives::{ + EvmNetwork, Identity, IdentityHandle, IdentityWebType, SubstrateNetwork, Web3Network, +}; +use sp_runtime::BoundedVec; + +use lc_data_providers::graphql::{ + GraphQLClient, VerifiedCredentialsIsHodlerIn, VerifiedCredentialsNetwork, +}; + +// ERC20 LIT token address +const LIT_TOKEN_ADDRESS: &str = "0xb59490aB09A0f526Cc7305822aC65f2Ab12f9723"; + +pub fn build( + identities: BoundedVec, + from_date: String, + min_balance: f64, +) -> Result<()> { + let mut client = GraphQLClient::new(); + + for identity in identities { + let mut network = VerifiedCredentialsNetwork::Polkadot; + if let IdentityWebType::Web3(web3_type) = identity.web_type { + match web3_type { + Web3Network::Substrate(SubstrateNetwork::Litentry) => + network = VerifiedCredentialsNetwork::Litentry, + Web3Network::Substrate(SubstrateNetwork::Litmus) => + network = VerifiedCredentialsNetwork::Litmus, + Web3Network::Evm(EvmNetwork::Ethereum) => + network = VerifiedCredentialsNetwork::Ethereum, + _ => (), + } + }; + + if network == VerifiedCredentialsNetwork::Litentry + || network == VerifiedCredentialsNetwork::Litmus + || network == VerifiedCredentialsNetwork::Ethereum + { + let mut addresses: Vec = vec![]; + match identity.handle { + IdentityHandle::Address20(addr) => + addresses.push(from_utf8(&addr).unwrap().to_string()), + IdentityHandle::Address32(addr) => + addresses.push(from_utf8(&addr).unwrap().to_string()), + IdentityHandle::String(addr) => + addresses.push(from_utf8(&addr).unwrap().to_string()), + } + let mut tmp_token_addr = String::from(""); + if network == VerifiedCredentialsNetwork::Ethereum { + tmp_token_addr = LIT_TOKEN_ADDRESS.to_string(); + } + let credentials = VerifiedCredentialsIsHodlerIn { + addresses, + from_date: from_date.clone(), + network, + token_address: tmp_token_addr, + min_balance, + }; + let is_hodler_out = client.check_verified_credentials_is_hodler(credentials); + if let Ok(_hodler_out) = is_hodler_out { + // TODO: generate VC + + return Ok(()) + } + } + } + + Err(Error::Assertion4Error("no valid response".to_string())) +} diff --git a/tee-worker/litentry/core/assertion-build/src/a7.rs b/tee-worker/litentry/core/assertion-build/src/a7.rs new file mode 100644 index 0000000000..44046106d8 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/a7.rs @@ -0,0 +1,78 @@ +// Copyright 2020-2022 Litentry Technologies GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +#[cfg(all(feature = "std", feature = "sgx"))] +compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +extern crate sgx_tstd as std; + +use crate::{Error, Result}; +use std::{ + str::from_utf8, + string::{String, ToString}, + vec, + vec::Vec, +}; + +use lc_stf_task_sender::MaxIdentityLength; +use litentry_primitives::{ + Identity, IdentityHandle, IdentityWebType, SubstrateNetwork, Web3Network, +}; +use sp_runtime::BoundedVec; + +use lc_data_providers::graphql::{ + GraphQLClient, VerifiedCredentialsIsHodlerIn, VerifiedCredentialsNetwork, +}; + +pub fn build( + identities: BoundedVec, + from_date: String, + min_balance: f64, +) -> Result<()> { + let mut client = GraphQLClient::new(); + + for identity in identities { + if let IdentityWebType::Web3(Web3Network::Substrate(SubstrateNetwork::Polkadot)) = + identity.web_type + { + let mut addresses: Vec = vec![]; + match identity.handle { + IdentityHandle::Address20(addr) => + addresses.push(from_utf8(&addr).unwrap().to_string()), + IdentityHandle::Address32(addr) => + addresses.push(from_utf8(&addr).unwrap().to_string()), + IdentityHandle::String(addr) => + addresses.push(from_utf8(&addr).unwrap().to_string()), + } + let credentials = VerifiedCredentialsIsHodlerIn { + addresses, + from_date: from_date.clone(), + network: VerifiedCredentialsNetwork::Polkadot, + token_address: String::from(""), + min_balance, + }; + let is_hodler_out = client.check_verified_credentials_is_hodler(credentials); + if let Ok(_hodler_out) = is_hodler_out { + // TODO: generate VC + + return Ok(()) + } + } + } + + Err(Error::Assertion7Error("no valid response".to_string())) +} diff --git a/tee-worker/litentry/core/assertion-build/src/lib.rs b/tee-worker/litentry/core/assertion-build/src/lib.rs index 6c9c036d83..9faf13e94b 100644 --- a/tee-worker/litentry/core/assertion-build/src/lib.rs +++ b/tee-worker/litentry/core/assertion-build/src/lib.rs @@ -37,8 +37,10 @@ use std::{fmt::Debug, string::String}; pub mod a1; pub mod a2; pub mod a3; +pub mod a4; pub mod a5; pub mod a6; +pub mod a7; pub type Result = core::result::Result; @@ -53,9 +55,15 @@ pub enum Error { #[error("Assertion3 error: {0}")] Assertion3Error(String), + #[error("Assertion4 error: {0}")] + Assertion4Error(String), + #[error("Assertion5 error: {0}")] Assertion5Error(String), + #[error("Assertion7 error: {0}")] + Assertion7Error(String), + #[error("Other error: {0}")] AssertionOtherError(String), } diff --git a/tee-worker/litentry/core/data-providers/Cargo.toml b/tee-worker/litentry/core/data-providers/Cargo.toml index 022020ef4d..b8a0a40774 100644 --- a/tee-worker/litentry/core/data-providers/Cargo.toml +++ b/tee-worker/litentry/core/data-providers/Cargo.toml @@ -37,7 +37,7 @@ litentry-primitives = { path = "../../primitives", default-features = false } httpmock = "0.6" lc-mock-server = { path = "../mock-server" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.32", default-features = false } - +chrono = { version = "0.4.23" } [features] default = ["std"] diff --git a/tee-worker/litentry/core/data-providers/src/graphql.rs b/tee-worker/litentry/core/data-providers/src/graphql.rs new file mode 100644 index 0000000000..de59f506ef --- /dev/null +++ b/tee-worker/litentry/core/data-providers/src/graphql.rs @@ -0,0 +1,192 @@ +// Copyright 2020-2022 Litentry Technologies GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +use crate::sgx_reexport_prelude::*; + +use crate::{build_client, Error, HttpError, G_DATA_PROVIDERS}; +use core::ops::Not; +use http::header::{AUTHORIZATION, CONNECTION}; +use http_req::response::Headers; +use itc_rest_client::{ + http_client::{DefaultSend, HttpClient}, + rest_client::RestClient, + RestGet, RestPath, +}; +use serde::{Deserialize, Serialize}; +use std::{ + default::Default, + format, str, + string::{String, ToString}, + vec, + vec::Vec, +}; + +pub struct GraphQLClient { + client: RestClient>, +} + +impl Default for GraphQLClient { + fn default() -> Self { + Self::new() + } +} + +#[derive(PartialEq)] +pub enum VerifiedCredentialsNetwork { + Litentry, + Litmus, + Polkadot, + Kusama, + Khala, + Ethereum, +} +pub struct VerifiedCredentialsIsHodlerIn { + pub addresses: Vec, + pub from_date: String, + pub network: VerifiedCredentialsNetwork, + pub token_address: String, + pub min_balance: f64, +} + +impl VerifiedCredentialsIsHodlerIn { + pub fn new( + addresses: Vec, + from_date: String, + network: VerifiedCredentialsNetwork, + token_address: String, + min_balance: f64, + ) -> Self { + VerifiedCredentialsIsHodlerIn { addresses, from_date, network, token_address, min_balance } + } + + pub fn conv_to_string(&self) -> String { + let mut flat = "addresses:[".to_string(); + for addr in self.addresses.iter() { + flat += &format!("\"{}\",", addr); + } + flat += "],"; + flat += &format!("fromDate:\"{}\",", self.from_date.clone()); + match &self.network { + VerifiedCredentialsNetwork::Litentry => flat += "network:litentry", + VerifiedCredentialsNetwork::Litmus => flat += "network:litmus", + VerifiedCredentialsNetwork::Polkadot => flat += "network:polkadot", + VerifiedCredentialsNetwork::Kusama => flat += "network:kusama", + VerifiedCredentialsNetwork::Khala => flat += "network:khala", + VerifiedCredentialsNetwork::Ethereum => flat += "network:ethereum", + } + if self.token_address.is_empty().not() { + flat += &format!(",tokenAddress:\"{}\"", &self.token_address.clone()); + } + flat += &format!(",minimumBalance:{:?}", self.min_balance.clone()); + flat + } +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct QLResponse { + #[serde(flatten)] + // data: HashMap, + data: serde_json::Value, +} +impl RestPath for QLResponse { + fn get_path(path: String) -> core::result::Result { + Ok(path) + } +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +pub struct IsHodlerOut { + pub verified_credentials_is_hodler: Vec, +} +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct IsHodlerOutStruct { + pub address: String, + pub is_hodler: bool, +} + +impl GraphQLClient { + pub fn new() -> Self { + let mut headers = Headers::new(); + headers.insert(CONNECTION.as_str(), "close"); + headers.insert( + AUTHORIZATION.as_str(), + G_DATA_PROVIDERS.read().unwrap().graphql_auth_key.clone().as_str(), + ); + let client = + build_client(G_DATA_PROVIDERS.read().unwrap().graphql_url.clone().as_str(), headers); + GraphQLClient { client } + } + + pub fn check_verified_credentials_is_hodler( + &mut self, + credentials: VerifiedCredentialsIsHodlerIn, + ) -> Result { + // FIXME: for the moment, the `path` is partially hard-code here. + let path = "latest/graphql?query=query{VerifiedCredentialsIsHodler(".to_string() + + &credentials.conv_to_string() + + "){isHodler, address}}"; + + let response = self + .client + .get_with::(path, vec![].as_slice()) + .map_err(|e| Error::RequestError(format!("{:?}", e)))?; + + if let Some(value) = response.data.get("data") { + // Valid response will always match the IsHodlerOut structure. + let is_hodler_out: IsHodlerOut = serde_json::from_value(value.clone()).unwrap(); + Ok(is_hodler_out) + } else { + Err(Error::GraphQLError("Invalid GraphQL response".to_string())) + } + } +} + +#[cfg(test)] +mod tests { + use crate::graphql::{ + GraphQLClient, VerifiedCredentialsIsHodlerIn, VerifiedCredentialsNetwork, + }; + + const ACCOUNT_ADDRESS1: &str = "0x61f2270153bb68dc0ddb3bc4e4c1bd7522e918ad"; + const ACCOUNT_ADDRESS2: &str = "0x3394caf8e5ccaffb936e6407599543af46525e0b"; + const LIT_TOKEN_ADDRESS: &str = "0xb59490aB09A0f526Cc7305822aC65f2Ab12f9723"; + + #[test] + fn verified_credentials_is_hodler_work() { + let mut client = GraphQLClient::new(); + + let credentials = VerifiedCredentialsIsHodlerIn { + addresses: vec![ACCOUNT_ADDRESS1.to_string(), ACCOUNT_ADDRESS2.to_string()], + // from_date: format!("{:?}", Utc::now()), + from_date: "2022-10-16T00:00:00Z".to_string(), + network: VerifiedCredentialsNetwork::Ethereum, + token_address: LIT_TOKEN_ADDRESS.to_string(), + min_balance: 0.00000056, + }; + let response = client.check_verified_credentials_is_hodler(credentials); + + if let Ok(is_hodler_out) = response { + assert_eq!(is_hodler_out.verified_credentials_is_hodler[0].is_hodler, false); + assert_eq!(is_hodler_out.verified_credentials_is_hodler[1].is_hodler, false); + } else { + assert!(false); + } + } +} diff --git a/tee-worker/litentry/core/data-providers/src/lib.rs b/tee-worker/litentry/core/data-providers/src/lib.rs index f962e2ce8c..d0af3f5a3d 100644 --- a/tee-worker/litentry/core/data-providers/src/lib.rs +++ b/tee-worker/litentry/core/data-providers/src/lib.rs @@ -59,6 +59,8 @@ pub mod discord_official; pub mod twitter_litentry; pub mod twitter_official; +pub mod graphql; + const TIMEOUT: Duration = Duration::from_secs(3u64); pub struct DataProvidersStatic { @@ -68,6 +70,8 @@ pub struct DataProvidersStatic { pub discord_official_url: String, pub discord_litentry_url: String, pub discord_auth_token: String, + pub graphql_url: String, + pub graphql_auth_key: String, } impl Default for DataProvidersStatic { fn default() -> Self { @@ -85,6 +89,8 @@ impl DataProvidersStatic { discord_official_url: "".to_string(), discord_litentry_url: "".to_string(), discord_auth_token: "".to_string(), + graphql_url: "".to_string(), + graphql_auth_key: "".to_string(), } } #[cfg(any(test, feature = "mockserver"))] @@ -96,6 +102,8 @@ impl DataProvidersStatic { discord_official_url: "http://localhost:9527".to_string(), discord_litentry_url: "http://localhost:9527".to_string(), discord_auth_token: "".to_string(), + graphql_url: "https://graph.tdf-labs.io/".to_string(), + graphql_auth_key: "ac2115ec-e327-4862-84c5-f25b6b7d4533".to_string(), } } } @@ -117,6 +125,12 @@ impl DataProvidersStatic { pub fn set_discord_auth_token(&mut self, v: String) { self.discord_auth_token = v; } + pub fn set_graphql_url(&mut self, v: String) { + self.graphql_url = v; + } + pub fn set_graphql_auth_key(&mut self, v: String) { + self.graphql_auth_key = v; + } } lazy_static! { @@ -131,6 +145,9 @@ pub enum Error { #[error("UTF8 error: {0}")] Utf8Error(String), + + #[error("GraphQL error: {0}")] + GraphQLError(String), } pub trait UserInfo { diff --git a/tee-worker/litentry/core/stf-task/receiver/Cargo.toml b/tee-worker/litentry/core/stf-task/receiver/Cargo.toml index 5c5b8c86e7..823ea58921 100644 --- a/tee-worker/litentry/core/stf-task/receiver/Cargo.toml +++ b/tee-worker/litentry/core/stf-task/receiver/Cargo.toml @@ -6,6 +6,7 @@ version = "0.1.0" [dependencies] # std dependencies +chrono = { version = "0.4.23", optional = true } futures = { version = "0.3.8", optional = true } hex = { version = "0.4.3", optional = true } http = { version = "0.2", optional = true } @@ -14,6 +15,7 @@ thiserror = { version = "1.0.26", optional = true } url = { version = "2.0.0", optional = true } # sgx dependencies +chrono_sgx = { package = "chrono", git = "https://github.com/mesalock-linux/chrono-sgx", optional = true } futures_sgx = { package = "futures", git = "https://github.com/mesalock-linux/futures-rs-sgx", optional = true } hex-sgx = { package = "hex", git = "https://github.com/mesalock-linux/rust-hex-sgx", tag = "sgx_1.1.3", features = ["sgx_tstd"], optional = true } http-sgx = { package = "http", git = "https://github.com/integritee-network/http-sgx.git", branch = "sgx-experimental", optional = true } @@ -69,6 +71,7 @@ sgx = [ "sgx_tstd", "thiserror_sgx", "url_sgx", + "chrono_sgx", "ita-stf/sgx", "itp-sgx-externalities/sgx", "itp-stf-executor/sgx", @@ -93,6 +96,7 @@ std = [ "serde_json/std", "thiserror", "url", + "chrono", "itp-types/std", "itp-utils/std", "itp-top-pool-author/std", diff --git a/tee-worker/litentry/core/stf-task/receiver/src/lib.rs b/tee-worker/litentry/core/stf-task/receiver/src/lib.rs index df8343e548..589db93449 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/lib.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/lib.rs @@ -22,6 +22,7 @@ extern crate sgx_tstd as std; // re-export module to properly feature gate sgx and regular std environment #[cfg(all(not(feature = "std"), feature = "sgx"))] pub mod sgx_reexport_prelude { + pub use chrono_sgx as chrono; pub use futures_sgx as futures; pub use hex_sgx as hex; pub use thiserror_sgx as thiserror; diff --git a/tee-worker/litentry/core/stf-task/receiver/src/stf_task_receiver.rs b/tee-worker/litentry/core/stf-task/receiver/src/stf_task_receiver.rs index 31a832beeb..a746c1b6f2 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/stf_task_receiver.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/stf_task_receiver.rs @@ -18,11 +18,19 @@ use crate::{ format, AuthorApi, Error, HandleState, Hash, SgxExternalitiesTrait, ShardIdentifier, ShieldingCryptoDecrypt, ShieldingCryptoEncrypt, StfEnclaveSigning, StfTaskContext, }; + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +use crate::chrono::{offset::Utc as TzUtc, TimeZone}; + +#[cfg(feature = "std")] +use chrono::{offset::Utc as TzUtc, TimeZone}; + use codec::Decode; use ita_sgx_runtime::IdentityManagement; use lc_stf_task_sender::{stf_task_sender, RequestType}; use litentry_primitives::{Assertion, IdentityWebType, Web2Network}; use log::*; +use std::string::String; // lifetime elision: StfTaskContext is guaranteed to outlive the fn pub fn run_stf_task_receiver(context: &StfTaskContext) -> Result<(), Error> @@ -108,6 +116,16 @@ where } } }, + Assertion::A4(mini_balance, from_date) => { + let mini_balance: f64 = (mini_balance / (10 ^ 12)) as f64; + if let Err(e) = lc_assertion_build::a4::build( + request.vec_identity, + String::from_utf8(from_date.into_inner()).unwrap(), + mini_balance, + ) { + error!("error verify assertion4: {:?}", e) + } + }, Assertion::A5(twitter_account, original_tweet_id) => match lc_assertion_build::a5::build( request.vec_identity.to_vec(), @@ -126,6 +144,19 @@ where log::error!("error verify assertion6: {:?}", e) }, }, + Assertion::A7(mini_balance, year) => { + #[cfg(feature = "std")] + let dt1 = TzUtc.with_ymd_and_hms(year as i32, 1, 1, 0, 0, 0); + #[cfg(all(not(feature = "std"), feature = "sgx"))] + let dt1 = TzUtc.ymd(year as i32, 1, 1).and_hms(0, 0, 0); + let from_date = format!("{:?}", dt1); + let mini_balance: f64 = (mini_balance / (10 ^ 12)) as f64; + if let Err(e) = + lc_assertion_build::a7::build(request.vec_identity, from_date, mini_balance) + { + error!("error verify assertion7: {:?}", e) + } + }, _ => { unimplemented!() }, diff --git a/tee-worker/litentry/primitives/src/assertion.rs b/tee-worker/litentry/primitives/src/assertion.rs index d61ffb4779..bc1ec01824 100644 --- a/tee-worker/litentry/primitives/src/assertion.rs +++ b/tee-worker/litentry/primitives/src/assertion.rs @@ -32,7 +32,7 @@ pub enum Assertion { A1, A2(ParameterString, ParameterString), // (guild_id, user_id) A3(ParameterString, ParameterString), // (guild_id, user_id) - A4, + A4(Balance, ParameterString), // (LIT_amount, timestamp, e.g.: 2022-10-16T00:00:00Z) A5(ParameterString, ParameterString), // (twitter_account, tweet_id) A6, A7(Balance, u32), // (DOT_amount, year) @@ -40,6 +40,5 @@ pub enum Assertion { A9, A10(Balance, u32), // (WBTC_amount, year) A11(Balance, u32), // (ETH_amount, year) - A12(Balance, u32), // (LIT_amount, year) A13(u32), // (Karma_amount) - TODO: unsupported } diff --git a/tee-worker/litentry/primitives/src/identity.rs b/tee-worker/litentry/primitives/src/identity.rs index 6aa620d568..e421243b27 100644 --- a/tee-worker/litentry/primitives/src/identity.rs +++ b/tee-worker/litentry/primitives/src/identity.rs @@ -76,7 +76,6 @@ pub enum IdentityWebType { #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum IdentityHandle { Address32([u8; 32]), - /// Its a 20 byte representation. Address20([u8; 20]), String(IdentityString), } diff --git a/tee-worker/local-setup/worker-config-dev.json b/tee-worker/local-setup/worker-config-dev.json index 9181cac9ab..5701595188 100644 --- a/tee-worker/local-setup/worker-config-dev.json +++ b/tee-worker/local-setup/worker-config-dev.json @@ -4,5 +4,7 @@ "twitter_auth_token": "abcdefghijklmnopqrstuvwxyz", "discord_official_url": "https://discordapp.com", "discord_litentry_url": "", - "discord_auth_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "discord_auth_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "graphql_url": "https://graph.tdf-labs.io/", + "graphql_auth_key": "ac2115ec-e327-4862-84c5-f25b6b7d4533" } diff --git a/tee-worker/local-setup/worker-config-prod.json b/tee-worker/local-setup/worker-config-prod.json index 9181cac9ab..5701595188 100644 --- a/tee-worker/local-setup/worker-config-prod.json +++ b/tee-worker/local-setup/worker-config-prod.json @@ -4,5 +4,7 @@ "twitter_auth_token": "abcdefghijklmnopqrstuvwxyz", "discord_official_url": "https://discordapp.com", "discord_litentry_url": "", - "discord_auth_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "discord_auth_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "graphql_url": "https://graph.tdf-labs.io/", + "graphql_auth_key": "ac2115ec-e327-4862-84c5-f25b6b7d4533" } diff --git a/tee-worker/local-setup/worker-config-staging.json b/tee-worker/local-setup/worker-config-staging.json index 9181cac9ab..5701595188 100644 --- a/tee-worker/local-setup/worker-config-staging.json +++ b/tee-worker/local-setup/worker-config-staging.json @@ -4,5 +4,7 @@ "twitter_auth_token": "abcdefghijklmnopqrstuvwxyz", "discord_official_url": "https://discordapp.com", "discord_litentry_url": "", - "discord_auth_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "discord_auth_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "graphql_url": "https://graph.tdf-labs.io/", + "graphql_auth_key": "ac2115ec-e327-4862-84c5-f25b6b7d4533" } diff --git a/tee-worker/service/src/main.rs b/tee-worker/service/src/main.rs index 2be8430485..81850ee07c 100644 --- a/tee-worker/service/src/main.rs +++ b/tee-worker/service/src/main.rs @@ -163,6 +163,12 @@ fn main() { let discord_auth_token = worker_config .get_string("discord_auth_token") .unwrap_or_else(|_e| "ABCDEFGHIJKLMNOPQRSTUVWXYZ".to_string()); + let graphql_url = worker_config + .get_string("graphql_url") + .unwrap_or_else(|_e| "https://graph.tdf-labs.io/".to_string()); + let graphql_auth_key = worker_config + .get_string("graphql_auth_key") + .unwrap_or_else(|_e| "ac2115ec-e327-4862-84c5-f25b6b7d4533".to_string()); mut_handle.set_twitter_official_url(twitter_official_url); mut_handle.set_twitter_litentry_url(twitter_litentry_url); @@ -170,6 +176,8 @@ fn main() { mut_handle.set_discord_official_url(discord_official_url); mut_handle.set_discord_litentry_url(discord_litentry_url); mut_handle.set_discord_auth_token(discord_auth_token); + mut_handle.set_graphql_url(graphql_url); + mut_handle.set_graphql_auth_key(graphql_auth_key); } #[cfg(any(test, feature = "mockserver"))] { @@ -179,6 +187,8 @@ fn main() { mut_handle.set_discord_official_url("http://localhost:9527".to_string()); mut_handle.set_discord_litentry_url("http://localhost:9527".to_string()); mut_handle.set_discord_auth_token("".to_string()); + mut_handle.set_graphql_url("https://graph.tdf-labs.io/".to_string()); + mut_handle.set_graphql_auth_key("ac2115ec-e327-4862-84c5-f25b6b7d4533".to_string()); } }