SlpDb.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <main class="flex flex-col">
  3. <h1 class="w-full text-4xl text-center font-bold mt-5 p-3 border-b-4 border-gray-500">
  4. SLPDB Lab
  5. </h1>
  6. <!-- Page Section -->
  7. <section class="w-full h-full flex">
  8. <div class="w-1/2 bg-rose-500">
  9. code window
  10. <select @change="selectQuery" v-model="selected">
  11. <option value="default">Default</option>
  12. <option value="addr-balance">Address balances by token</option>
  13. <option value="token-balance">Token balances by address</option>
  14. <option value="txs-address">Transactions by address</option>
  15. <option value="tokens-sent">Tokens sent</option>
  16. <option value="token-info">Token info</option>
  17. <option value="utxos-token">UTXOs by token</option>
  18. <option value="swap">Signal, Watch &amp; Pay (SWaP)</option>
  19. <option value="sipnet">Gossip Network</option>
  20. </select>
  21. <a href="https://status.slpdb.io" target="_blank">
  22. https://status.slpdb.io
  23. </a>
  24. <textarea class="w-full h-96" v-model="userQuery" />
  25. <button @click="query" class="ml-5 mt-3 p-3 text-center text-lg font-medium bg-pink-300 border-4 border-pink-500 rounded-xl">
  26. Send Query
  27. </button>
  28. </div>
  29. <div class="w-1/2 bg-yellow-300 overflow-x-scroll overflow-y-scroll">
  30. instructions &amp; output
  31. <pre v-html="output" />
  32. </div>
  33. </section>
  34. </main>
  35. </template>
  36. <script>
  37. /* Import modules. */
  38. // import Nito from 'nitojs'
  39. /* Import components. */
  40. // import UnderConstruction from '@/components/UnderConstruction'
  41. export default {
  42. components: {
  43. // UnderConstruction,
  44. },
  45. data: () => {
  46. return {
  47. requests: null,
  48. selected: null,
  49. output: null,
  50. userQuery: null,
  51. }
  52. },
  53. computed: {
  54. //
  55. },
  56. methods: {
  57. async query() {
  58. console.log('SEND QUERY')
  59. /* Clear output. */
  60. this.output = ''
  61. let request
  62. if (this.userQuery) {
  63. try {
  64. // NOTE: We remove "helpful" comment.
  65. const pos = this.userQuery.indexOf('{')
  66. let userQuery
  67. if (pos) {
  68. userQuery = this.userQuery.slice(pos)
  69. } else {
  70. userQuery = this.userQuery
  71. }
  72. request = JSON.parse(userQuery)
  73. } catch (err) {
  74. console.error(err)
  75. }
  76. } else {
  77. request = this.requests[0]
  78. }
  79. console.log('REQUEST', request)
  80. // const response = await fetch()
  81. const response = await Nito.SLP.Query.request(request)
  82. .catch(err => console.error(err))
  83. console.log('RESPONSE (body):', response)
  84. this.output = JSON.stringify(response, null, 2)
  85. },
  86. selectQuery() {
  87. console.log('SELECTED', this.selected)
  88. switch(this.selected) {
  89. case 'addr-balance':
  90. return this.loadAddrBalance()
  91. case 'token-balance':
  92. return this.loadTokenBalance()
  93. case 'txs-address':
  94. return this.loadTxsAddress()
  95. case 'tokens-sent':
  96. return this.loadTokensSent()
  97. case 'token-info':
  98. return this.loadTokenInfo()
  99. case 'utxos-token':
  100. return this.loadUtxosByToken()
  101. case 'swap':
  102. return this.loadSwap()
  103. case 'sipnet':
  104. return this.loadSipnet()
  105. default:
  106. return this.loadDefault()
  107. }
  108. },
  109. loadDefault() {
  110. this.userQuery = `/* Customize your query below. */
  111. {
  112. "v": 3,
  113. "q": {
  114. "find": {},
  115. "limit": 10
  116. }
  117. }
  118. `
  119. },
  120. loadAddrBalance() {
  121. this.userQuery = `/* Customize your query below. */
  122. {
  123. "v": 3,
  124. "q": {
  125. "db": ["g"],
  126. "aggregate": [
  127. {
  128. "$match": {
  129. "tokenDetails.tokenIdHex": "7cf3c06b85ce9fa611098d78551ce13f5cdd345db2041f2d942438fb4ce80ee8"
  130. }
  131. },
  132. {
  133. "$unwind": "$graphTxn.outputs"
  134. },
  135. {
  136. "$match": {
  137. "graphTxn.outputs.status": "UNSPENT"
  138. }
  139. },
  140. {
  141. "$group": {
  142. "_id": "$graphTxn.outputs.address",
  143. "slpAmount": {
  144. "$sum": "$graphTxn.outputs.slpAmount"
  145. }
  146. }
  147. },
  148. {
  149. "$match": {
  150. "slpAmount": {
  151. "$gt": 0
  152. }
  153. }
  154. }
  155. ],
  156. "sort": {
  157. "slpAmount": -1
  158. },
  159. "project": {
  160. "address": "$_id",
  161. "token_balance": "$slpAmount"
  162. },
  163. "limit": 10,
  164. "skip": 0
  165. }
  166. }
  167. `
  168. },
  169. loadTokenBalance() {
  170. this.userQuery = `/* Customize your query below. */
  171. {
  172. "v": 3,
  173. "q": {
  174. "db": ["g"],
  175. "aggregate": [
  176. {
  177. "$match": {
  178. "graphTxn.outputs.address": "simpleledger:pz8kpuypq2m55q9yuj9pv6r7hvzz8t4mrygmjzrnjq"
  179. }
  180. },
  181. {
  182. "$unwind": "$graphTxn.outputs"
  183. },
  184. {
  185. "$match": {
  186. "graphTxn.outputs.status": "UNSPENT",
  187. "graphTxn.outputs.address": "simpleledger:pz8kpuypq2m55q9yuj9pv6r7hvzz8t4mrygmjzrnjq"
  188. }
  189. }
  190. ]
  191. }
  192. }
  193. `
  194. },
  195. loadTxsAddress() {
  196. this.userQuery = `/* Customize your query below. */
  197. {
  198. "v": 3,
  199. "q": {
  200. "db": ["c"],
  201. "aggregate": [
  202. {
  203. "$match": {
  204. "$and": [
  205. {"slp.valid": true},
  206. {
  207. "$or": [
  208. {"in.e.a": "simpleledger:pz8kpuypq2m55q9yuj9pv6r7hvzz8t4mrygmjzrnjq"},
  209. {"out.e.a": "simpleledger:pz8kpuypq2m55q9yuj9pv6r7hvzz8t4mrygmjzrnjq"}
  210. ]
  211. }
  212. ]
  213. }
  214. },
  215. {
  216. "$sort": {"blk.i": -1}
  217. },
  218. {
  219. "$skip": 0
  220. },
  221. {
  222. "$limit": 100
  223. },
  224. {
  225. "$lookup": {
  226. "from": "tokens",
  227. "localField": "slp.detail.tokenIdHex",
  228. "foreignField": "tokenDetails.tokenIdHex",
  229. "as": "token"
  230. }
  231. },
  232. {
  233. "$lookup": {
  234. "from": "graphs",
  235. "localField": "tx.h",
  236. "foreignField": "graphTxn.txid",
  237. "as": "graph"
  238. }
  239. }
  240. ],
  241. "limit": 100
  242. }
  243. }
  244. `
  245. },
  246. loadTokensSent() {
  247. this.userQuery = `/* Customize your query below. */
  248. {
  249. "v": 3,
  250. "q": {
  251. "db": ["c"],
  252. "find": {
  253. "$and": [
  254. {"slp.valid": true},
  255. {"slp.detail.tokenIdHex": "7cf3c06b85ce9fa611098d78551ce13f5cdd345db2041f2d942438fb4ce80ee8"},
  256. {"slp.detail.transactionType": "SEND"}
  257. ]
  258. },
  259. "sort": {"blk.i": -1},
  260. "limit": 100,
  261. "skip": 0
  262. },
  263. "r": {
  264. "f": "[ .[] | { slp } ]"
  265. }
  266. }
  267. `
  268. },
  269. loadTokenInfo() {
  270. this.userQuery = `/* Customize your query below. */
  271. {
  272. "v": 3,
  273. "q": {
  274. "db": ["t"],
  275. "find": {
  276. "tokenDetails.tokenIdHex": "7cf3c06b85ce9fa611098d78551ce13f5cdd345db2041f2d942438fb4ce80ee8"
  277. },
  278. "limit": 1
  279. }
  280. }
  281. `
  282. },
  283. loadUtxosByToken() {
  284. this.userQuery = `/* Customize your query below. */
  285. {
  286. "v": 3,
  287. "q": {
  288. "db": ["g"],
  289. "aggregate": [
  290. {
  291. "$match": {
  292. "tokenDetails.tokenIdHex": "7cf3c06b85ce9fa611098d78551ce13f5cdd345db2041f2d942438fb4ce80ee8",
  293. "graphTxn.outputs.address": "simpleledger:pz8kpuypq2m55q9yuj9pv6r7hvzz8t4mrygmjzrnjq",
  294. "graphTxn.outputs.status": {
  295. "$in": [
  296. "UNSPENT",
  297. "BATON_UNSPENT"
  298. ]
  299. }
  300. }
  301. },
  302. {
  303. "$unwind": "$graphTxn.outputs"
  304. },
  305. {
  306. "$match": {
  307. "graphTxn.outputs.status": {
  308. "$in": [
  309. "UNSPENT",
  310. "BATON_UNSPENT"
  311. ]
  312. },
  313. "graphTxn.outputs.slpAmount": {
  314. "$gt": 0
  315. }
  316. }
  317. }
  318. ]
  319. }
  320. }
  321. `
  322. },
  323. loadSwap() {
  324. this.userQuery = `/* Customize your query below. */
  325. {
  326. "v": 3,
  327. "q": {
  328. "find": {
  329. "out.h1": "53575000"
  330. },
  331. "limit": 10
  332. }
  333. }
  334. `
  335. },
  336. loadSipnet() {
  337. this.userQuery = `/* Customize your query below. */
  338. {
  339. "v": 3,
  340. "q": {
  341. "find": {
  342. "out.h1": "53495000"
  343. },
  344. "limit": 10
  345. }
  346. }
  347. `
  348. },
  349. },
  350. created: async function () {
  351. this.requests = []
  352. let request
  353. request = {
  354. v: 3,
  355. q: {
  356. find: {},
  357. limit: 10
  358. }
  359. }
  360. this.requests.push(request)
  361. },
  362. mounted: function () {
  363. //
  364. },
  365. }
  366. </script>