Skip to content

Commit

Permalink
macro
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Feb 28, 2024
1 parent 2c87326 commit db604e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
22 changes: 1 addition & 21 deletions examples/fungible-token/ft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,12 @@ pub struct Contract {

const DATA_IMAGE_SVG_NEAR_ICON: &str = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 288 288'%3E%3Cg id='l' data-name='l'%3E%3Cpath d='M187.58,79.81l-30.1,44.69a3.2,3.2,0,0,0,4.75,4.2L191.86,103a1.2,1.2,0,0,1,2,.91v80.46a1.2,1.2,0,0,1-2.12.77L102.18,77.93A15.35,15.35,0,0,0,90.47,72.5H87.34A15.34,15.34,0,0,0,72,87.84V201.16A15.34,15.34,0,0,0,87.34,216.5h0a15.35,15.35,0,0,0,13.08-7.31l30.1-44.69a3.2,3.2,0,0,0-4.75-4.2L96.14,186a1.2,1.2,0,0,1-2-.91V104.61a1.2,1.2,0,0,1,2.12-.77l89.55,107.23a15.35,15.35,0,0,0,11.71,5.43h3.13A15.34,15.34,0,0,0,216,201.16V87.84A15.34,15.34,0,0,0,200.66,72.5h0A15.35,15.35,0,0,0,187.58,79.81Z'/%3E%3C/g%3E%3C/svg%3E";

#[derive(NearStorageKey)]
enum StorageKey {
FungibleToken,
Metadata,
}

const _: () = {
#[allow(non_camel_case_types)]
type StorageKey__NEAR_SCHEMA_PROXY = StorageKey;
{
#[derive(::near_sdk::borsh::BorshSerialize, ::near_sdk::BorshStorageKey)]
#[borsh(crate = "near_sdk::borsh")]
enum StorageKey {
FungibleToken,
Metadata,
}
#[automatically_derived]
impl ::near_sdk::__private::BorshIntoStorageKey for StorageKey__NEAR_SCHEMA_PROXY {
}

impl BorshSerialize for StorageKey__NEAR_SCHEMA_PROXY {
fn serialize<W: ::near_sdk::borsh::io::Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
Ok(())
}
}
};
};

#[near(contract_state)]
impl Contract {
Expand Down
27 changes: 23 additions & 4 deletions near-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,30 @@ pub fn near_storage_key(item: TokenStream) -> TokenStream {
// let x = borsh_storage_key(item.clone());
let ast = parse_macro_input!(item as DeriveInput);

// let y =
let input_ident = &ast.ident;

let input_ident_proxy = quote::format_ident!("{}__NEAR_SCHEMA_PROXY", input_ident);

TokenStream::from(quote! {
// #[derive(near_sdk::BorshStorageKey, near_sdk::borsh::BorshSerialize)]
// #[borsh(crate = "near_sdk::borsh")]
#ast
const _: () = {
#[allow(non_camel_case_types)]
type #input_ident_proxy = #input_ident;
{
#[derive(::near_sdk::borsh::BorshSerialize, ::near_sdk::BorshStorageKey)]
#[borsh(crate = "near_sdk::borsh")]
#ast
#[automatically_derived]
impl ::near_sdk::__private::BorshIntoStorageKey for #input_ident_proxy {
}

impl BorshSerialize for #input_ident_proxy {
fn serialize<W: ::near_sdk::borsh::io::Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
Ok(())
}
}
};
};

})
}

Expand Down

0 comments on commit db604e1

Please sign in to comment.