-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1662009
commit ebcaae9
Showing
7 changed files
with
92 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
mod follow_token_uri; | ||
mod handle_token_uri; | ||
mod profile_token_uri; | ||
mod traits; | ||
mod profile_svg; | ||
mod traits; |
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 |
---|---|---|
@@ -1,10 +1,56 @@ | ||
// TODO: https://github.com/lens-protocol/core/blob/master/contracts/misc/token-uris/HandleTokenURI.sol | ||
|
||
pub mod HandleTokenUri { | ||
use core::array::ArrayTrait; | ||
use alexandria_bytes::{Bytes, BytesTrait}; | ||
use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; | ||
use karst::base::utils::base64_extended::{convert_into_byteArray , get_base64_encode } ; | ||
use karst::base::token_uris::traits::profile::ProfileSvg::gen_profile_svg ; | ||
pub fn get_token_uri(token_id: u256, local_name: felt252, namespace: felt252 ) -> ByteArray { | ||
let baseuri = 'data:image/svg+xml;base64,'; | ||
/// TODO what are feaature include in the svg | ||
// let mut svg_byte_array: ByteArray = get_svg(token_id, local_name , namespace); | ||
let mut svg_byte_array = gen_profile_svg() ; | ||
let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array); | ||
let mut attribute_byte_array: ByteArray = get_attributes(token_id ,ref svg_encoded , local_name , namespace ); | ||
let mut token_uri: ByteArray = baseuri.try_into().unwrap(); | ||
token_uri.append(@attribute_byte_array); | ||
token_uri | ||
} | ||
|
||
pub fn get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray { | ||
"TODO" | ||
fn get_attributes(token_id: u256,ref svg_encoded_byteArray : ByteArray ,local_name: felt252 , namespace : felt252 ) -> ByteArray { | ||
let token_id_felt: felt252 = token_id.try_into().unwrap(); | ||
let token_id_byte: ByteArray = token_id_felt.try_into().unwrap(); | ||
let token_id_byte_len: felt252 = token_id_byte.len().try_into().unwrap(); | ||
let mut attributespre = ArrayTrait::<felt252>::new(); | ||
let mut attributespost = ArrayTrait::<felt252>::new() ; | ||
attributespre.append( '{"name":"@'); | ||
attributespre.append(local_name); | ||
attributespre.append('","description":"Lens '); | ||
attributespre.append('Protocol - Handle @') ; | ||
attributespre.append(local_name) ; | ||
attributespre.append('","image":"data:image'); | ||
attributespre.append('/svg+xml;base64,'); | ||
attributespost.append('","attributes":[{"display') ; | ||
attributespost.append('_type":"number","trait_type'); | ||
attributespost.append('":"ID","value":"'); | ||
attributespost.append(token_id.try_into().unwrap()) ; | ||
attributespost.append('"},{"trait_type":"NAMES'); | ||
attributespost.append('PACE","value":"'); | ||
attributespost.append(namespace) ; | ||
attributespost.append('"},{"trait_type":"'); | ||
attributespost.append('LENGTH","value":"') ; | ||
attributespost.append('token_id_byte_len') ; | ||
attributespost.append( '"}]}') ; | ||
let mut attributespre_bytearray = convert_into_byteArray(ref attributespre) ; | ||
let mut attributespost_bytearray = convert_into_byteArray(ref attributespost) ; | ||
attributespre_bytearray.append(@svg_encoded_byteArray) ; | ||
attributespre_bytearray.append(@attributespost_bytearray) ; | ||
get_base64_encode( attributespre_bytearray) | ||
} | ||
} | ||
} | ||
|
||
|
||
// cvonver the byteArray into the base64 encoded byteArray // | ||
|
||
|
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ mod color; | |
mod beard; | ||
mod background; | ||
mod cloth; | ||
mod profile ; |
File renamed without changes.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod byte_array_extra; | ||
mod hubrestricted; | ||
mod base64_extended ; |
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,38 @@ | ||
use core::serde::Serde; | ||
use core::array::ArrayTrait; | ||
use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; | ||
use alexandria_encoding::base64::{Base64UrlEncoder}; | ||
|
||
pub fn get_base64_encode(res: ByteArray) -> ByteArray { | ||
let mut res_arr_u8 = ArrayTrait::<u8>::new(); | ||
let mut i = 0; | ||
while i < res | ||
.len() { | ||
let mut res_data = res.at(i); | ||
res_arr_u8.append(res_data.unwrap()); | ||
i += 1; | ||
}; | ||
// encoding the array of u8 to base64url | ||
let mut encoded_val = Base64UrlEncoder::encode(res_arr_u8); | ||
// converting array of u8 to byte array | ||
let mut res_final: ByteArray = Default::default(); | ||
let mut j = 0; | ||
while j < encoded_val | ||
.len() { | ||
let encoded_val_data = encoded_val.at(j); | ||
res_final.append_byte(*encoded_val_data); | ||
j += 1; | ||
}; | ||
res_final | ||
} | ||
|
||
pub fn convert_into_byteArray(ref svg: Array<felt252>) -> ByteArray { | ||
let mut res: ByteArray = Default::default(); | ||
// converting felt252 array to byte array | ||
while (!svg.is_empty()) { | ||
let each_felt: felt252 = svg.pop_front().unwrap(); | ||
let word: ByteArray = each_felt.try_into().unwrap(); | ||
res.append(@word); | ||
}; | ||
res | ||
} |