Skip to content

Commit

Permalink
P 716 magiccraft staking credential (#2714)
Browse files Browse the repository at this point in the history
* VC for magic craft staking user

* add one test

* fix build error

* fix mock server and test

* update vc schema version

---------

Co-authored-by: Yang <yang@trustcomputing.de>
  • Loading branch information
BillyWooo and BillyWooo committed May 10, 2024
1 parent 11381db commit 1476406
Show file tree
Hide file tree
Showing 19 changed files with 326 additions and 13 deletions.
1 change: 1 addition & 0 deletions bitacross-worker/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
3 changes: 3 additions & 0 deletions bitacross-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -189,6 +190,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -245,6 +247,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
9 changes: 5 additions & 4 deletions local-setup/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ NODE_ENV=local
# The following key/token are MANDATORY to give when running worker.
# Otherwise request-vc might suffering from data provider error.
TWITTER_AUTH_TOKEN_V2=
TWITTER_CLIENT_ID=twitter_client_id
TWITTER_CLIENT_SECRET=twitter_client_secret
TWITTER_CLIENT_ID=
TWITTER_CLIENT_SECRET=
DISCORD_AUTH_TOKEN=
ACHAINABLE_AUTH_KEY=
ONEBLOCK_NOTION_KEY=ABCDEFGHIJKLMNOPQRSTUVWXYZ
NODEREAL_API_KEY=NODEREAL_API_KEY
ONEBLOCK_NOTION_KEY=
NODEREAL_API_KEY=
GENIIDATA_API_KEY=
MORALIS_API_KEY=

Expand All @@ -57,4 +57,5 @@ LITENTRY_ARCHIVE_URL=http://localhost:19527
MORALIS_API_URL=http://localhost:19527/moralis/
MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
4 changes: 3 additions & 1 deletion primitives/core/src/assertion/platform_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ use crate::assertion::network::{all_evm_web3networks, Web3Network};
pub enum PlatformUserType {
#[codec(index = 0)]
KaratDaoUser,
#[codec(index = 1)]
MagicCraftStakingUser,
}

impl PlatformUserType {
pub fn get_supported_networks(&self) -> Vec<Web3Network> {
match self {
Self::KaratDaoUser => all_evm_web3networks(),
Self::KaratDaoUser | Self::MagicCraftStakingUser => all_evm_web3networks(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ pub enum TokenHoldingAmountCommand {
#[derive(Subcommand, Debug)]
pub enum PlatformUserCommand {
KaratDaoUser,
MagicCraftStakingUser,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -618,6 +619,8 @@ impl Command {
},
Command::PlatformUser(arg) => match arg {
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),
PlatformUserCommand::MagicCraftStakingUser =>
PlatformUser(PlatformUserType::MagicCraftStakingUser),
},
Command::NftHolder(arg) => match arg {
NftHolderCommand::WeirdoGhostGang => NftHolder(Web3NftType::WeirdoGhostGang),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ export default {
},
// PlatformUserType
PlatformUserType: {
_enum: ["KaratDaoUser"],
_enum: [
"KaratDaoUser",
"MagicCraftStakingUser",
],
},
// Web3NftType
Web3NftType: {
Expand Down
1 change: 1 addition & 0 deletions tee-worker/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
3 changes: 3 additions & 0 deletions tee-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -195,6 +196,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -255,6 +257,7 @@ services:
- MORALIS_API_URL=http://localhost:19527/moralis/
- MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
1 change: 1 addition & 0 deletions tee-worker/litentry/core/common/src/platform_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl PlatformName for PlatformUserType {
fn get_platform_name(&self) -> &'static str {
match self {
Self::KaratDaoUser => "KaratDao",
Self::MagicCraftStakingUser => "MagicCraft",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {

Assertion::CryptoSummary => Some(format!("{BASE_URL}/23-crypto-summary/1-1-0.json")),

Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-0.json")),
Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-1.json")),

Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-0.json")),

Expand Down
10 changes: 5 additions & 5 deletions tee-worker/litentry/core/data-providers/src/karat_dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct KaratDaoClient {
}

#[derive(Debug)]
pub struct KaraDaoRequest {
pub struct KaratDaoRequest {
path: String,
query: Option<Vec<(String, String)>>,
}
Expand All @@ -66,7 +66,7 @@ impl KaratDaoClient {
KaratDaoClient { retry_option, client }
}

fn get<T>(&mut self, params: KaraDaoRequest, fast_fail: bool) -> Result<T, Error>
fn get<T>(&mut self, params: KaratDaoRequest, fast_fail: bool) -> Result<T, Error>
where
T: serde::de::DeserializeOwned + for<'a> RestPath<ReqPath<'a>>,
{
Expand Down Expand Up @@ -105,23 +105,23 @@ pub struct UserVerificationResult {
pub is_valid: bool,
}

pub trait KaraDaoApi {
pub trait KaratDaoApi {
fn user_verification(
&mut self,
address: String,
fail_fast: bool,
) -> Result<UserVerificationResponse, Error>;
}

impl KaraDaoApi for KaratDaoClient {
impl KaratDaoApi for KaratDaoClient {
fn user_verification(
&mut self,
address: String,
fail_fast: bool,
) -> Result<UserVerificationResponse, Error> {
let query: Vec<(String, String)> = vec![("address".to_string(), address)];

let params = KaraDaoRequest { path: "user/verification".into(), query: Some(query) };
let params = KaratDaoRequest { path: "user/verification".into(), query: Some(query) };

debug!("user_verification, params: {:?}", params);

Expand Down
30 changes: 30 additions & 0 deletions tee-worker/litentry/core/data-providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub mod discord_litentry;
pub mod discord_official;
pub mod geniidata;
pub mod karat_dao;
pub mod magic_craft;
pub mod moralis;
pub mod nodereal;
pub mod nodereal_jsonrpc;
Expand Down Expand Up @@ -194,6 +195,9 @@ pub struct DataProviderConfig {
pub karat_dao_api_retry_delay: u64,
pub karat_dao_api_retry_times: u16,
pub karat_dao_api_url: String,
pub magic_craft_api_retry_delay: u64,
pub magic_craft_api_retry_times: u16,
pub magic_craft_api_url: String,
pub moralis_api_url: String,
pub moralis_solana_api_url: String,
pub moralis_api_retry_delay: u64,
Expand Down Expand Up @@ -240,6 +244,9 @@ impl DataProviderConfig {
karat_dao_api_retry_delay: 5000,
karat_dao_api_retry_times: 2,
karat_dao_api_url: "https://api.karatdao.com/".to_string(),
magic_craft_api_retry_delay: 5000,
magic_craft_api_retry_times: 2,
magic_craft_api_url: "https://lobby-api-prod.magiccraft.io/".to_string(),
moralis_api_key: "".to_string(),
moralis_api_retry_delay: 5000,
moralis_api_retry_times: 2,
Expand Down Expand Up @@ -316,6 +323,15 @@ impl DataProviderConfig {
if let Ok(v) = env::var("KARAT_DAO_API_URL") {
config.set_karat_dao_api_url(v)?;
}
if let Ok(v) = env::var("MAGIC_CRAFT_API_RETRY_DELAY") {
config.set_magic_craft_api_retry_delay(v.parse::<u64>().unwrap());
}
if let Ok(v) = env::var("MAGIC_CRAFT_API_RETRY_TIMES") {
config.set_magic_craft_api_retry_times(v.parse::<u16>().unwrap());
}
if let Ok(v) = env::var("MAGIC_CRAFT_API_URL") {
config.set_magic_craft_api_url(v)?;
}
if let Ok(v) = env::var("MORALIS_API_URL") {
config.set_moralis_api_url(v)?;
}
Expand Down Expand Up @@ -506,6 +522,20 @@ impl DataProviderConfig {
self.karat_dao_api_url = v;
Ok(())
}
pub fn set_magic_craft_api_retry_delay(&mut self, v: u64) {
debug!("set_magic_craft_api_retry_delay: {:?}", v);
self.magic_craft_api_retry_delay = v;
}
pub fn set_magic_craft_api_retry_times(&mut self, v: u16) {
debug!("set_magic_craft_api_retry_times: {:?}", v);
self.magic_craft_api_retry_times = v;
}
pub fn set_magic_craft_api_url(&mut self, v: String) -> Result<(), Error> {
check_url(&v)?;
debug!("set_magic_craft_api_url: {:?}", v);
self.magic_craft_api_url = v;
Ok(())
}
pub fn set_moralis_api_key(&mut self, v: String) {
debug!("set_moralis_api_key: {:?}", v);
self.moralis_api_key = v;
Expand Down
Loading

0 comments on commit 1476406

Please sign in to comment.