Skip to content

Commit

Permalink
Merge pull request #17 from gear-foundation/tm-fix-vnft
Browse files Browse the repository at this point in the history
Delete TokenUri, Add TransferFrom
  • Loading branch information
MedovTimur authored Aug 5, 2024
2 parents 7d93ca4 + 9ce6e05 commit 943bcc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 17 additions & 12 deletions vnft-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub struct Storage {
symbol: String,
owner_by_id: OwnerByIdMap,
tokens_for_owner: TokensForOwnerMap,
token_uri_by_id: TokenUriByIdMap,
token_approvals: ApprovalsMap,
}

Expand All @@ -37,10 +36,6 @@ impl Storage {
let storage = unsafe { STORAGE.as_mut().expect("Storage is not initialized") };
&mut storage.owner_by_id
}
pub fn token_uri_by_id() -> &'static mut HashMap<TokenId, TokenURI> {
let storage = unsafe { STORAGE.as_mut().expect("Storage is not initialized") };
&mut storage.token_uri_by_id
}
pub fn token_approvals() -> &'static mut HashMap<TokenId, ActorId> {
let storage = unsafe { STORAGE.as_mut().expect("Storage is not initialized") };
&mut storage.token_approvals
Expand Down Expand Up @@ -122,6 +117,23 @@ impl Service {
});
}

pub fn transfer_from(&mut self, from: ActorId, to: ActorId, token_id: TokenId) {
let source = msg::source();
utils::panicking(move || {
funcs::transfer_from(
Storage::token_approvals(),
Storage::owner_by_id(),
Storage::tokens_for_owner(),
source,
from,
to,
token_id,
)
});

let _ = self.notify_on(Event::Transfer { from, to, token_id });
}

pub fn balance_of(&self, owner: ActorId) -> U256 {
funcs::balance_of(&Storage::get().tokens_for_owner, owner)
}
Expand All @@ -143,11 +155,4 @@ impl Service {
let storage = Storage::get();
&storage.symbol
}
pub fn token_uri(&self, token_id: TokenId) -> &'static str {
Storage::get()
.token_uri_by_id
.get(&token_id)
.map(String::as_str)
.unwrap_or("")
}
}
2 changes: 0 additions & 2 deletions vnft-service/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use gstd::{
};
use sails_rs::prelude::*;
pub type TokenId = U256;
pub type TokenURI = String;
pub type ApprovalsMap = HashMap<TokenId, ActorId>;
pub type OwnerByIdMap = HashMap<TokenId, ActorId>;
pub type TokensForOwnerMap = HashMap<ActorId, HashSet<TokenId>>;
pub type TokenUriByIdMap = HashMap<TokenId, TokenURI>;
pub type Result<T, E = Error> = core::result::Result<T, E>;

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, TypeInfo)]
Expand Down

0 comments on commit 943bcc0

Please sign in to comment.