-
Notifications
You must be signed in to change notification settings - Fork 0
/
brc20_query.go
247 lines (217 loc) · 8.98 KB
/
brc20_query.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
245
246
247
package types
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
)
type BRC20Balance struct {
Tick string
TotalBalance *big.Int
AvailableBalance *big.Int
TransferableBalance *big.Int
}
func (b BRC20Balance) ToResponse() QueryBrc20BalanceResponse {
return QueryBrc20BalanceResponse{
Tick: b.Tick,
AvailableBalance: b.AvailableBalance.String(),
TransferableBalance: b.TransferableBalance.String(),
OverallBalance: b.TotalBalance.String(),
}
}
type QueryBrc20BalanceResponse struct {
Tick string `json:"tick" yaml:"tick"`
AvailableBalance string `json:"available_balance" yaml:"available_balance"`
TransferableBalance string `json:"transferable_balance" yaml:"transferable_balance"`
OverallBalance string `json:"overall_balance" yaml:"overall_balance"`
}
func NewQueryBrc20BalanceResponse(tick string, ab string, tb string, ob string) QueryBrc20BalanceResponse {
return QueryBrc20BalanceResponse{
Tick: tick,
AvailableBalance: ab,
TransferableBalance: tb,
OverallBalance: ob,
}
}
type QueryBrc20AllBalanceResponse struct {
Balance []QueryBrc20BalanceResponse `json:"balance" yaml:"balance"`
}
func NewQueryBrc20AllBalanceResponse(balance []QueryBrc20BalanceResponse) QueryBrc20AllBalanceResponse {
return QueryBrc20AllBalanceResponse{
Balance: balance,
}
}
type BRC20Information struct {
Tick string
TickAddress common.Address
MaxSupply *big.Int
NowSupply *big.Int
Decimals *big.Int
Lim *big.Int
InscriptionId string
InscriptionNumber int64
Txid string
Sender string
BlockTime uint32
BlockHeight uint64
}
func (info BRC20Information) ToResponse() QueryBrc20TickInfoResponse {
return QueryBrc20TickInfoResponse{
Tick: info.Tick,
InscriptionId: info.InscriptionId,
InscriptionNumber: info.InscriptionNumber,
MaxSupply: info.MaxSupply.String(),
Lim: info.Lim.String(),
NowSupply: info.NowSupply.String(),
Decimals: info.Decimals.String(),
Sender: info.Sender,
Txid: info.Txid,
BlockHeight: info.BlockHeight,
BlockTime: info.BlockTime,
}
}
type WrappedBRC20Information struct {
BRC20Information
}
type QueryBrc20TickInfoResponse struct {
Tick string `json:"tick" yaml:"tick"`
InscriptionId string `json:"inscription_id" yaml:"inscription_id"`
InscriptionNumber int64 `json:"inscription_number" yaml:"inscription_number"`
MaxSupply string `json:"supply" yaml:"supply"`
Lim string `json:"limit_per_mint" yaml:"limit_per_mint"`
NowSupply string `json:"minted" yaml:"minted"`
Decimals string `json:"decimal" yaml:"decimal"`
Sender string `json:"deploy_by" yaml:"deploy_by"`
Txid string `json:"tx_id" yaml:"tx_id"`
BlockHeight uint64 `json:"deploy_height" yaml:"deploy_height"`
BlockTime uint32 `json:"deploy_blocktime" yaml:"deploy_blocktime"`
}
func NewQueryBrc20TickInfoResponse(info WrappedBRC20Information) QueryBrc20TickInfoResponse {
return QueryBrc20TickInfoResponse{
Tick: info.Tick,
InscriptionId: info.InscriptionId,
InscriptionNumber: info.InscriptionNumber,
MaxSupply: info.MaxSupply.String(),
Lim: info.Lim.String(),
NowSupply: info.NowSupply.String(),
Decimals: info.Decimals.String(),
Sender: info.Sender,
Txid: info.Txid,
BlockHeight: info.BlockHeight,
BlockTime: info.BlockTime,
}
}
type QueryBrc20AllTickInfoResponse struct {
Tokens []QueryBrc20TickInfoResponse `json:"tokens" yaml:"tokens"`
}
func NewQueryBrc20AllTickInfoResponse(infos []QueryBrc20TickInfoResponse) QueryBrc20AllTickInfoResponse {
return QueryBrc20AllTickInfoResponse{
Tokens: infos,
}
}
type QueryBrc20TotalTickHoldersResponse struct {
Holders string `json:"total_tick_holders" yaml:"total_tick_holders"`
}
func NewQueryBrc20TotalTickHoldersResponse(h string) QueryBrc20TotalTickHoldersResponse {
return QueryBrc20TotalTickHoldersResponse{
Holders: h,
}
}
type Brc20EventContext struct {
EventType string `json:"event" yaml:"event"`
Tick string `json:"tick" yaml:"tick"`
InscriptionId string `json:"inscription_id" yaml:"inscription_id"`
InscriptionNumber int64 `json:"inscription_number" yaml:"inscription_number"`
OldSatPoint string `json:"old_satpoint" yaml:"old_satpoint"`
NewSatPoint string `json:"new_satpoint" yaml:"new_satpoint"`
Supply *big.Int `json:"supply" yaml:"supply"`
Lim *big.Int `json:"lim_per_mint" yaml:"lim_per_mint"`
Dec *big.Int `json:"decimals" yaml:"decimals"`
Amount *big.Int `json:"amount" yaml:"amount"`
Sender string `json:"from" yaml:"from"`
Receiver string `json:"to" yaml:"to"`
Msg string `json:"msg,omitempty" yaml:"msg,omitempty"`
Txid string `json:"txid" yaml:"txid"`
}
type Brc20EventResponse struct {
EventType string `json:"event" yaml:"event"`
Tick string `json:"tick" yaml:"tick"`
InscriptionId string `json:"inscription_id" yaml:"inscription_id"`
InscriptionNumber int64 `json:"inscription_number" yaml:"inscription_number"`
OldSatPoint string `json:"old_satpoint" yaml:"old_satpoint"`
NewSatPoint string `json:"new_satpoint" yaml:"new_satpoint"`
Supply string `json:"supply,omitempty" yaml:"supply,omitempty"`
Lim string `json:"lim_per_mint,omitempty" yaml:"lim_per_mint,omitempty"`
Dec uint64 `json:"decimals,omitempty" yaml:"decimals,omitempty"`
Amount *big.Int `json:"amount" yaml:"amount"`
Sender string `json:"from" yaml:"from"`
Receiver string `json:"to" yaml:"to"`
Valid bool `json:"valid" yaml:"valid"`
Msg string `json:"msg" yaml:"msg"`
}
type Brc20WrappedEvent struct {
Brc20EventContext `json:"events" yaml:"events"`
}
func (we Brc20WrappedEvent) ToEventResponse() Brc20EventResponse {
return Brc20EventResponse{
EventType: we.EventType,
Tick: we.Tick,
InscriptionId: we.InscriptionId,
InscriptionNumber: we.InscriptionNumber,
OldSatPoint: we.OldSatPoint,
NewSatPoint: we.NewSatPoint,
Supply: we.Supply.String(),
Lim: we.Lim.String(),
Dec: we.Dec.Uint64(),
Amount: we.Amount,
Sender: we.Sender,
Receiver: we.Receiver,
//todo: judge valid field
Valid: true,
Msg: we.Msg,
}
}
type QueryBrc20TxEventsResponse struct {
Events []Brc20EventResponse `json:"events" yaml:"events"`
Txid string `json:"txid" yaml:"txid"`
}
func NewQueryBrc20TxEventsResponse(e []Brc20EventResponse, txid string) QueryBrc20TxEventsResponse {
return QueryBrc20TxEventsResponse{
Events: e,
Txid: txid,
}
}
type QueryBrc20TxEventsByBlockHashResponse struct {
BlockEvents []QueryBrc20TxEventsResponse `json:"block" yaml:"block"`
}
func NewQueryBrc20TxEventsByBlockHashResponse(be []QueryBrc20TxEventsResponse) QueryBrc20TxEventsByBlockHashResponse {
return QueryBrc20TxEventsByBlockHashResponse{BlockEvents: be}
}
type Brc20TransferableInscription struct {
InscriptionId string `json:"inscription_id" yaml:"inscription_id"`
InscriptionNumber int64 `json:"inscription_number" yaml:"inscription_number"`
Amount string `json:"amount" yaml:"amount"`
Tick string `json:"tick" yaml:"tick"`
Owner string `json:"owner" yaml:"owner"`
}
type QueryBrc20TransferableInscriptionResponse struct {
Inscriptions []Brc20TransferableInscription `json:"inscriptions" yaml:"inscriptions"`
}
func NewQueryBrc20TransferableInscriptionResponse(tis []Brc20TransferableInscription) QueryBrc20TransferableInscriptionResponse {
return QueryBrc20TransferableInscriptionResponse{Inscriptions: tis}
}
type Brc20InscriptionInfo struct {
Action string `json:"action,omitempty" yaml:"action,omitempty"`
InscriptionNumber int64 `json:"inscription_number,omitempty" yaml:"inscription_number,omitempty"`
InscriptionId string `json:"inscription_id" yaml:"inscription_id"`
From string `json:"from" yaml:"from"`
To string `json:"to,omitempty" yaml:"to,omitempty"`
OldSatPoint string `json:"old_satpoint,omitempty" yaml:"old_satpoint,omitempty"`
NewSatPoint string `json:"new_satpoint,omitempty" yaml:"new_satpoint,omitempty"`
Operation Brc20Operation `json:"operation,omitempty" yaml:"operation,omitempty"`
}
type Brc20Operation struct {
Tick string `json:"tick" yaml:"tick"`
Amt string `json:"amt,omitempty" yaml:"amt,omitempty"`
Max string `json:"max,omitempty" yaml:"max,omitempty"`
Lim string `json:"lim,omitempty" yaml:"lim,omitempty"`
Dec string `json:"dec,omitempty" yaml:"dec,omitempty"`
}