-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.go
244 lines (220 loc) · 5.92 KB
/
model.go
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package script
import (
"encoding/hex"
"encoding/json"
)
const (
CodeType_NONE uint32 = 0
CodeType_FT uint32 = 1
CodeType_UNIQUE uint32 = 2
CodeType_NFT uint32 = 3
CodeType_SENSIBLE uint32 = 65536
CodeType_NFT_SELL uint32 = 65536 + 1
CodeType_NFT_AUCTION uint32 = 65536 + 4
CodeType_NFT_SELL_V2 uint32 = 65536 + 6
)
var CodeTypeName []string = []string{
"NONE",
"FT",
"UNIQUE",
"NFT",
}
// swap
// 64/84 bytes
type SwapData struct {
// fetchTokenContractHash + lpTokenID + lpTokenScriptCodeHash + Token1Amount + Token2Amount + lpAmount
Token1Amount uint64
Token2Amount uint64
LpAmount uint64
}
// ft
type FTData struct {
SensibleId []byte // GenesisTx outpoint
Name string // ft name
Symbol string // ft symbol
Amount uint64 // ft amount
Decimal uint8 // ft decimal
}
func (u *FTData) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
SensibleId string // GenesisTx outpoint
Name string // ft name
Symbol string // ft symbol
Amount uint64 // ft amount
Decimal uint8 // ft decimal
}{
SensibleId: hex.EncodeToString(u.SensibleId[:]),
Name: u.Name,
Symbol: u.Symbol,
Amount: u.Amount,
Decimal: u.Decimal,
})
}
// nft
type NFTData struct {
SensibleId []byte // GenesisTx outpoint
MetaTxId [32]byte // nft metatxid
MetaOutputIndex uint32
TokenIndex uint64 // nft tokenIndex
TokenSupply uint64 // nft tokenSupply
}
func (u *NFTData) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
SensibleId string // GenesisTx outpoint
MetaTxId string // nft metatxid
MetaOutputIndex uint32
TokenIndex uint64 // nft tokenIndex
TokenSupply uint64 // nft tokenSupply
}{
SensibleId: hex.EncodeToString(u.SensibleId),
MetaTxId: hex.EncodeToString(u.MetaTxId[:]),
MetaOutputIndex: u.MetaOutputIndex,
TokenIndex: u.TokenIndex,
TokenSupply: u.TokenSupply,
})
}
// nft sell
type NFTSellData struct {
TokenIndex uint64 // nft tokenIndex
Price uint64 // nft price
}
func (u *NFTSellData) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
TokenIndex uint64
Price uint64
}{
TokenIndex: u.TokenIndex,
Price: u.Price,
})
}
// nft sell
type NFTSellV2Data struct {
TokenIndex uint64
Price uint64
FeeAddressPkh [20]byte
FeeRate byte
SellerAddressPkh [20]byte
NFTID [20]byte
}
func (u *NFTSellV2Data) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
TokenIndex uint64
Price uint64
FeeAddressPkh string
FeeRate byte
SellerAddressPkh string
NFTID string
}{
TokenIndex: u.TokenIndex,
Price: u.Price,
FeeAddressPkh: hex.EncodeToString(u.FeeAddressPkh[:]),
FeeRate: u.FeeRate,
SellerAddressPkh: hex.EncodeToString(u.SellerAddressPkh[:]),
NFTID: hex.EncodeToString(u.NFTID[:]),
})
}
// nft auction
// <nft auction data> = <rabinPubkeyHashArrayHash>(20bytes) + <timeRabinPubkeyHash>(20byte) +
type NFTAuctionData struct {
SensibleId [36]byte // Auction GenesisTx outpoint
NFTCodeHash [20]byte
NFTID [20]byte
FeeAmount uint64 // v1
FeeRate byte // v2
FeeAddressPkh [20]byte
StartBsvPrice uint64
SenderAddressPkh [20]byte
EndTimestamp uint64
BidTimestamp uint64
BidBsvPrice uint64
BidderAddressPkh [20]byte
}
func (u *NFTAuctionData) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
SensibleId string
NFTCodeHash string
NFTID string
FeeAmount uint64 // v1
FeeRate byte // v2
FeeAddressPkh string
StartBsvPrice uint64
SenderAddressPkh string
EndTimestamp uint64
BidTimestamp uint64
BidBsvPrice uint64
BidderAddressPkh string
}{
SensibleId: hex.EncodeToString(u.SensibleId[:]),
NFTCodeHash: hex.EncodeToString(u.NFTCodeHash[:]),
NFTID: hex.EncodeToString(u.NFTID[:]),
FeeAmount: u.FeeAmount,
FeeRate: u.FeeRate,
FeeAddressPkh: hex.EncodeToString(u.FeeAddressPkh[:]),
StartBsvPrice: u.StartBsvPrice,
SenderAddressPkh: hex.EncodeToString(u.SenderAddressPkh[:]),
EndTimestamp: u.EndTimestamp,
BidTimestamp: u.BidTimestamp,
BidBsvPrice: u.BidBsvPrice,
BidderAddressPkh: hex.EncodeToString(u.BidderAddressPkh[:]),
})
}
// unique
type UniqueData struct {
SensibleId []byte // GenesisTx outpoint
CustomData []byte // unique data
Swap *SwapData
}
func (u *UniqueData) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
SensibleId string // GenesisTx outpoint
CustomData string // unique data
Swap *SwapData
}{
SensibleId: hex.EncodeToString(u.SensibleId),
CustomData: hex.EncodeToString(u.CustomData),
Swap: u.Swap,
})
}
type TxoData struct {
CodeType uint32
CodeHash [20]byte
GenesisId [40]byte // for search: codehash + genesis
GenesisIdLen uint8
HasAddress bool
AddressPkh [20]byte
NFT *NFTData
FT *FTData
Uniq *UniqueData
NFTSell *NFTSellData
NFTSellV2 *NFTSellV2Data
NFTAuction *NFTAuctionData
}
func (u *TxoData) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
CodeType uint32
CodeHash string
GenesisId string // for search: codehash + genesis
GenesisIdLen uint8
HasAddress bool
AddressPkh string
NFT *NFTData
FT *FTData
Uniq *UniqueData
NFTSell *NFTSellData
NFTSellV2 *NFTSellV2Data
NFTAuction *NFTAuctionData
}{
CodeType: u.CodeType,
CodeHash: hex.EncodeToString(u.CodeHash[:]),
GenesisId: hex.EncodeToString(u.GenesisId[:]),
GenesisIdLen: u.GenesisIdLen,
HasAddress: u.HasAddress,
AddressPkh: hex.EncodeToString(u.AddressPkh[:]),
NFT: u.NFT,
FT: u.FT,
Uniq: u.Uniq,
NFTSell: u.NFTSell,
NFTSellV2: u.NFTSellV2,
NFTAuction: u.NFTAuction,
})
}