Skip to content

Commit

Permalink
add new platform user VC: daren market (#2903)
Browse files Browse the repository at this point in the history
* add new platform user VC: daren market

* update schema version

* remove API KEY. Daren confirmed they are using public API.

---------

Co-authored-by: Yang <[email protected]>
  • Loading branch information
BillyWooo and BillyWooo authored Jul 17, 2024
1 parent f62f875 commit 31bcf9b
Show file tree
Hide file tree
Showing 21 changed files with 451 additions and 33 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 @@ -134,6 +134,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
2 changes: 2 additions & 0 deletions bitacross-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -193,6 +194,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
1 change: 1 addition & 0 deletions local-setup/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ 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/
DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
8 changes: 5 additions & 3 deletions primitives/core/src/assertion/platform_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ use crate::assertion::network::{all_evm_web3networks, Web3Network};
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum PlatformUserType {
#[codec(index = 0)]
KaratDaoUser,
KaratDao,
#[codec(index = 1)]
MagicCraftStakingUser,
MagicCraftStaking,
#[codec(index = 2)]
DarenMarket,
}

impl PlatformUserType {
pub fn get_supported_networks(&self) -> Vec<Web3Network> {
match self {
Self::KaratDaoUser | Self::MagicCraftStakingUser => all_evm_web3networks(),
Self::KaratDao | Self::MagicCraftStaking | Self::DarenMarket => all_evm_web3networks(),
}
}
}
4 changes: 4 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function clean_up() {
cargo clean
cd "$root_dir/tee-worker/enclave-runtime"
cargo clean
cd "$root_dir/bitacross-worker"
cargo clean
cd "$root_dir/bitacross-worker/enclave-runtime"
cargo clean
}

root_dir=$(git rev-parse --show-toplevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ pub enum TokenHoldingAmountCommand {

#[derive(Subcommand, Debug)]
pub enum PlatformUserCommand {
KaratDaoUser,
MagicCraftStakingUser,
KaratDao,
MagicCraftStaking,
DarenMarket,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -652,9 +653,10 @@ impl Command {
TokenHoldingAmountCommand::Tuna => TokenHoldingAmount(Web3TokenType::Tuna),
}),
Command::PlatformUser(arg) => Ok(match arg {
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),
PlatformUserCommand::MagicCraftStakingUser =>
PlatformUser(PlatformUserType::MagicCraftStakingUser),
PlatformUserCommand::KaratDao => PlatformUser(PlatformUserType::KaratDao),
PlatformUserCommand::MagicCraftStaking =>
PlatformUser(PlatformUserType::MagicCraftStaking),
PlatformUserCommand::DarenMarket => PlatformUser(PlatformUserType::DarenMarket),
}),
Command::NftHolder(arg) => Ok(match arg {
NftHolderCommand::WeirdoGhostGang => NftHolder(Web3NftType::WeirdoGhostGang),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default {
},
// PlatformUserType
PlatformUserType: {
_enum: ["KaratDaoUser", "MagicCraftStakingUser"],
_enum: ["KaratDao", "MagicCraftStaking", "DarenMarket"],
},
// 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 @@ -138,6 +138,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- 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 @@ -139,6 +139,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -203,6 +204,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -267,6 +269,7 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
103 changes: 94 additions & 9 deletions tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,26 @@ mod tests {
use litentry_hex_utils::decode_hex;
use litentry_primitives::{Identity, IdentityNetworkTuple};

fn init() -> DataProviderConfig {
fn init(platform_user_type: PlatformUserType) -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap() + "/karat_dao/";

let mut config = DataProviderConfig::new().unwrap();
config.set_karat_dao_api_url(url).unwrap();

match platform_user_type {
PlatformUserType::KaratDao => {
let url = run(0).unwrap() + "/karat_dao/";
config.set_karat_dao_api_url(url).unwrap();
},
PlatformUserType::MagicCraftStaking => {
let url = run(0).unwrap() + "/magic_craft/";
config.set_magic_craft_api_url(url).unwrap();
},
PlatformUserType::DarenMarket => {
let url = run(0).unwrap() + "/daren_market/";
config.set_daren_market_api_url(url).unwrap();
},
};

config
}

Expand Down Expand Up @@ -129,11 +143,11 @@ mod tests {
assertion_value: bool,
data_provider_config: &DataProviderConfig,
) {
let req = crate_assertion_build_request(PlatformUserType::KaratDaoUser, identities);
let req = crate_assertion_build_request(platform_user_type.clone(), identities);

match build(&req, platform_user_type.clone(), &data_provider_config) {
Ok(credential) => {
log::info!("build karat dao user done");
log::info!("build platform user: {:?} done", platform_user_type);
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
Expand All @@ -150,14 +164,85 @@ mod tests {
);
},
Err(e) => {
panic!("build karat dao user failed with error {:?}", e);
panic!("build platform user: {:?} failed with error {:?}", platform_user_type, e);
},
}
}

#[test]
fn build_karat_dao_user_works() {
let data_provider_config = init();
let data_provider_config = init(PlatformUserType::KaratDao);

let mut address =
decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
let mut identities: Vec<IdentityNetworkTuple> =
vec![(Identity::Evm(address), vec![Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::KaratDao,
true,
&data_provider_config,
);

address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e7c".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc, Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::KaratDao,
false,
&data_provider_config,
);
}

#[test]
fn build_magic_craft_staking_user_works() {
let data_provider_config = init(PlatformUserType::MagicCraftStaking);

let mut address =
decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
let mut identities: Vec<IdentityNetworkTuple> =
vec![(Identity::Evm(address), vec![Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::MagicCraftStaking,
true,
&data_provider_config,
);

address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e7c".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc, Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::MagicCraftStaking,
false,
&data_provider_config,
);
}

#[test]
fn build_daren_market_user_works() {
let data_provider_config = init(PlatformUserType::DarenMarket);

let mut address =
decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec())
.unwrap()
Expand All @@ -169,7 +254,7 @@ mod tests {

build_and_assert_result(
identities,
PlatformUserType::KaratDaoUser,
PlatformUserType::DarenMarket,
true,
&data_provider_config,
);
Expand All @@ -183,7 +268,7 @@ mod tests {

build_and_assert_result(
identities,
PlatformUserType::KaratDaoUser,
PlatformUserType::DarenMarket,
false,
&data_provider_config,
);
Expand Down
5 changes: 3 additions & 2 deletions tee-worker/litentry/core/common/src/platform_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ pub trait PlatformName {
impl PlatformName for PlatformUserType {
fn get_platform_name(&self) -> &'static str {
match self {
Self::KaratDaoUser => "KaratDao",
Self::MagicCraftStakingUser => "MagicCraft",
Self::KaratDao => "KaratDao",
Self::MagicCraftStaking => "MagicCraft",
Self::DarenMarket => "DarenMarket",
}
}
}
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-1.json")),
Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-2.json")),

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

Expand Down
Loading

0 comments on commit 31bcf9b

Please sign in to comment.