-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from zTgx/main
feat: add story protocol
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::{transaction::StoryConfig, STORY_API_URL}; | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct GetLicenseTokenResponse { | ||
pub data: TokenData, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct TokenData { | ||
pub id: String, | ||
pub licensor_ip_id: String, | ||
pub license_template: String, | ||
pub license_terms_id: String, | ||
pub transferable: String, | ||
pub owner: String, | ||
pub burnt_at: String, | ||
pub block_number: String, | ||
pub block_time: String, | ||
} | ||
|
||
/// Retrieve a LicenseToken | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `config` - API Config | ||
/// * `license_token_id` - License Token ID | ||
/// | ||
/// # Returns | ||
/// | ||
/// GetLicenseTokenResponse | ||
pub async fn get_license_token( | ||
config: &StoryConfig, | ||
license_token_id: &str, | ||
) -> Result<GetLicenseTokenResponse> { | ||
let url = format!("{}/licenses/tokens/{}", STORY_API_URL, license_token_id); | ||
|
||
let client = reqwest::Client::new(); | ||
let response = client | ||
.get(url) | ||
.header("X-Api-Key", &config.api_key) | ||
.header("X-Chain", config.chain.clone()) | ||
.header("accept", "application/json") | ||
.send() | ||
.await? | ||
.json::<GetLicenseTokenResponse>() | ||
.await?; | ||
|
||
Ok(response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod license; | ||
pub mod tools; | ||
pub mod transaction; | ||
|
||
const STORY_API_URL: &str = "https://staging-api.storyprotocol.net/api/v3"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use anyhow::Result; | ||
use rig_tool_macro::tool; | ||
use super::{license::{get_license_token, GetLicenseTokenResponse}, transaction::{get_a_transaction, GetTransactionResponse, StoryConfig}}; | ||
|
||
#[tool(description = "Retrieve a Transaction on Story protocol")] | ||
pub async fn get_a_transaction_on_story( | ||
config: StoryConfig, | ||
trx_id: String, | ||
) -> Result<GetTransactionResponse> { | ||
get_a_transaction(&config, &trx_id).await | ||
} | ||
|
||
#[tool(description = "Retrieve a LicenseToken on Story protocol")] | ||
pub async fn get_license_token_on_story( | ||
config: StoryConfig, | ||
license_token_id: String, | ||
) -> Result<GetLicenseTokenResponse> { | ||
get_license_token(&config, &license_token_id).await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::STORY_API_URL; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct GetTransactionResponse { | ||
pub data: TransactionData, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct TransactionData { | ||
pub id: String, | ||
|
||
#[serde(rename = "blockNumber")] | ||
pub block_number: String, | ||
|
||
#[serde(rename = "blockTimestamp")] | ||
pub block_timestamp: String, | ||
|
||
#[serde(rename = "createdAt")] | ||
pub created_at: String, | ||
|
||
#[serde(rename = "actionType")] | ||
pub action_type: Option<String>, | ||
|
||
pub initiator: Option<String>, | ||
|
||
#[serde(rename = "ipId")] | ||
pub ip_id: Option<String>, | ||
|
||
#[serde(rename = "resourceId")] | ||
pub resource_id: Option<String>, | ||
|
||
#[serde(rename = "resourceType")] | ||
pub resource_type: Option<String>, | ||
|
||
pub tx_hash: Option<String>, | ||
|
||
#[serde(rename = "logIndex")] | ||
pub log_index: Option<String>, | ||
|
||
#[serde(rename = "transactionIndex")] | ||
pub transaction_index: Option<String>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct StoryConfig { | ||
pub api_key: String, | ||
pub chain: String, | ||
} | ||
|
||
impl StoryConfig { | ||
pub fn new(api_key: String, chain: String) -> Self { | ||
StoryConfig { api_key, chain } | ||
} | ||
} | ||
|
||
/// Retrieve a Transaction | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `config` - API Config | ||
/// * `trx_id` - Transaction ID | ||
/// | ||
/// # Returns | ||
/// | ||
/// GetTransactionResponse | ||
pub async fn get_a_transaction( | ||
config: &StoryConfig, | ||
trx_id: &str, | ||
) -> Result<GetTransactionResponse> { | ||
let url = format!("{}/transactions/{}", STORY_API_URL, trx_id); | ||
|
||
let client = reqwest::Client::new(); | ||
let response = client | ||
.get(url) | ||
.header("X-Api-Key", &config.api_key) | ||
.header("X-Chain", config.chain.clone()) | ||
.header("accept", "application/json") | ||
.send() | ||
.await? | ||
.json::<GetTransactionResponse>() | ||
.await?; | ||
|
||
Ok(response) | ||
} |