forked from ligolang/contract-catalogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nft.impl.jsligo
85 lines (65 loc) · 2.08 KB
/
nft.impl.jsligo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "../common/assertions.jsligo" "Assertions"
#import "../common/errors.mligo" "Errors"
#import "../common/tzip12.datatypes.jsligo" "TZIP12"
#import "../common/tzip16.datatypes.jsligo" "TZIP16"
#import "./extendable_nft.impl.jsligo" "NFTExtendable"
export type ledger = NFTExtendable.ledger;
export type operator = NFTExtendable.operator;
export type operators = NFTExtendable.operators;
export type storage = {
ledger: ledger,
operators: operators,
token_metadata: TZIP12.tokenMetadata,
metadata: TZIP16.metadata,
}
type ret = [list<operation>, storage];
const empty_storage: storage = {
ledger: Big_map.empty,
operators: Big_map.empty,
token_metadata: Big_map.empty,
metadata: Big_map.empty
}
@inline
const lift = (s: storage): NFTExtendable.storage<unit> => {
return {
extension: unit,
ledger: s.ledger,
operators: s.operators,
token_metadata: s.token_metadata,
metadata: s.metadata
};
}
@inline
const unlift = ([ops, s]: [list<operation>, NFTExtendable.storage<unit>]): ret => {
let storage = {
ledger: s.ledger,
operators: s.operators,
token_metadata: s.token_metadata,
metadata: s.metadata
};
return [ops, storage];
}
@entry
const transfer = (t: TZIP12.transfer, s: storage): ret =>
unlift(NFTExtendable.transfer(t, lift(s)))
@entry
const balance_of = (b: TZIP12.balance_of, s: storage): ret =>
unlift(NFTExtendable.balance_of(b, lift(s)))
@entry
const update_operators = (updates: TZIP12.update_operators, s: storage): ret =>
unlift(NFTExtendable.update_operators(updates, lift(s)))
@view
const get_balance = (p: [address, nat], s: storage): nat =>
NFTExtendable.get_balance(p, lift(s))
@view
const total_supply = (token_id: nat, s: storage): nat =>
NFTExtendable.total_supply(token_id, lift(s))
@view
const all_tokens = (_: unit, s: storage): set<nat> =>
NFTExtendable.all_tokens(unit, lift(s))
@view
const is_operator = (op: TZIP12.operator, s: storage): bool =>
NFTExtendable.is_operator(op, lift(s))
@view
const token_metadata = (p: nat, s: storage): TZIP12.tokenMetadataData =>
NFTExtendable.token_metadata(p, lift(s))