-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.sql
163 lines (155 loc) · 4.51 KB
/
bench.sql
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
--- Select latest epoch parameters
select
*
from
epoch_param ep
order by
ep.epoch_no desc
limit 1;
--- Select assets by policy and apply filters by metadata
with asset as (
select
ma_tx_mint.tx_id,
encode(multi_asset.name, 'escape') as name,
encode(multi_asset.policy, 'hex') as policy,
multi_asset.fingerprint
from
multi_asset
inner join
ma_tx_mint on
ma_tx_mint.ident = multi_asset.id
where
multi_asset.policy = '\x8f80ebfaf62a8c33ae2adf047572604c74db8bc1daba2b43f9a65635'
),metadata as (
select
tx_metadata.tx_id,
tx_metadata.json as metadata
from
tx_metadata
where
tx_metadata.tx_id in (select tx_id from asset)
)
select
*,
count(*) over () as count
from
asset
inner join metadata on
asset.tx_id = metadata.tx_id
where
jsonb_path_query_array(metadata.metadata,'$.*.*.type') ?| array['Orc']
order by
asset.name asc
limit 20 offset 0;
--- Select total assets by policy from stake address
select
sum(ma_tx_out.quantity) as quantity,
encode(multi_asset.policy, 'hex') as policy
from
utxo_view
inner join
stake_address on stake_address.id = utxo_view.stake_address_id
inner join
ma_tx_out on ma_tx_out.tx_out_id = utxo_view.id
inner join
multi_asset on multi_asset.id = ma_tx_out.ident
where
stake_address."view" = 'stake1u90nkx5yw6qkpas3kxa0wcql93axph8fetw20l0j2ntszucgg4rr2'
and
multi_asset.policy = '\xb7761c472eef3b6e0505441efaf940892bb59c01be96070b0a0a89b3'
group by multi_asset.policy;
--- Select all assets from a stake address
select
ma_tx_out.tx_out_id,
ma_tx_out.quantity,
encode(multi_asset.name, 'escape') as name,
encode(multi_asset.policy, 'hex') as policy,
multi_asset.fingerprint,
tx_metadata.json as metadata,
count(*) over () as count
from
utxo_view
inner join
stake_address on stake_address.id = utxo_view.stake_address_id
inner join
ma_tx_out on ma_tx_out.tx_out_id = utxo_view.id
inner join
multi_asset on multi_asset.id = ma_tx_out.ident
inner join
ma_tx_mint on ma_tx_mint.ident = multi_asset.id
inner join
tx_metadata on tx_metadata.tx_id = ma_tx_mint.tx_id
where
stake_address.view = 'stake1u90nkx5yw6qkpas3kxa0wcql93axph8fetw20l0j2ntszucgg4rr2'
order by
multi_asset.name asc
limit 20 offset 1;
--- Select all utxos from a stake address
select
tx_out.id,
tx.hash,
tx_out.index,
tx_out.address,
tx_out.value
from
tx_out
left join
tx_in on tx_out.tx_id = tx_in.tx_out_id and tx_out.index::smallint = tx_in.tx_out_index::smallint
left join
tx on tx.id = tx_out.tx_id
left join
block on tx.block_id = block.id
inner join
stake_address on stake_address.id = tx_out.stake_address_id
where
tx_in.tx_in_id is null and
block.epoch_no is not null and
stake_address.view = 'stake1u90nkx5yw6qkpas3kxa0wcql93axph8fetw20l0j2ntszucgg4rr2';
--- Select slot number of the most recent block
select
slot_no
from
block
where
block_no is not null
order by
block_no desc
limit 1;
--- Select current valid pools
select
*
from
pool_update
where
registered_tx_id in (select max(registered_tx_id) from pool_update group by hash_id)
and
not exists(
select
*
from
pool_retire
where
pool_retire.hash_id = pool_update.hash_id
and
pool_retire.retiring_epoch <= (select max (epoch_no) from block)
);
--- Select the stake address for a given Shelley address
select
stake_address.id as stake_address_id,
tx_out.address,
stake_address.view as stake_address
from
tx_out
inner join
stake_address on tx_out.stake_address_id = stake_address.id
where
address = 'addr1q8u4wgd8qplhxpt4xm2l8yagy5ng7veurwrns2ysh03zuh2l8vdgga5pvrmprvd67asp7tr6vrwwnjku5l7ly4xhq9esr9h59t';
--- Select transaction outputs for specified transaction hash
select
tx_out.*
from
tx_out
inner join
tx on tx_out.tx_id = tx.id
where
tx.hash = '\xabd21556d9bb817d436e33a5fa32619702633dc809e707a5297566e9d74d57c1';