BitVm.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. BitVM 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="latest-block">Latest Block</option>
  13. <option value="advanced">Advanced</option>
  14. <option value="memo">Memo.cash</option>
  15. <option value="hello">Hello</option>
  16. <option value="bet">Bet</option>
  17. <option value="sender">Sender</option>
  18. <option value="response">Response</option>
  19. <option value="addressesTxs">Addresses Txs</option>
  20. <option value="bfp">Bitcoin Files Protocol (BFP)</option>
  21. <option value="bml">Bitcoin Markup Language (BML)</option>
  22. </select>
  23. <textarea class="w-full h-96" v-model="userQuery" />
  24. <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">
  25. Send Query
  26. </button>
  27. </div>
  28. <div class="w-1/2 bg-yellow-300 overflow-x-scroll overflow-y-scroll">
  29. instructions &amp; output
  30. <pre v-html="output" />
  31. </div>
  32. </section>
  33. </main>
  34. </template>
  35. <script>
  36. /* Import modules. */
  37. // import Nito from 'nitojs'
  38. /* Import components. */
  39. // import UnderConstruction from '@/components/UnderConstruction'
  40. export default {
  41. components: {
  42. // UnderConstruction,
  43. },
  44. data: () => {
  45. return {
  46. requests: null,
  47. selected: null,
  48. output: null,
  49. userQuery: null,
  50. }
  51. },
  52. computed: {
  53. //
  54. },
  55. methods: {
  56. async query() {
  57. console.log('SEND QUERY')
  58. /* Clear output. */
  59. this.output = ''
  60. let request
  61. if (this.userQuery) {
  62. try {
  63. // NOTE: We remove "helpful" comment.
  64. const pos = this.userQuery.indexOf('{')
  65. let userQuery
  66. if (pos) {
  67. userQuery = this.userQuery.slice(pos)
  68. } else {
  69. userQuery = this.userQuery
  70. }
  71. request = JSON.parse(userQuery)
  72. } catch (err) {
  73. console.error(err)
  74. }
  75. } else {
  76. request = this.requests[0]
  77. }
  78. console.log('REQUEST', request)
  79. // const response = await fetch()
  80. const response = await Nito.Blockchain.Query.request(request)
  81. .catch(err => console.error(err))
  82. console.log('RESPONSE (body):', response)
  83. this.output = JSON.stringify(response, null, 2)
  84. },
  85. selectQuery() {
  86. console.log('SELECTED', this.selected)
  87. switch(this.selected) {
  88. case 'latest-block':
  89. return this.loadLatestBlock()
  90. case 'advanced':
  91. return this.loadAdvanced()
  92. case 'memo':
  93. return this.loadMemo()
  94. case 'hello':
  95. return this.loadHello()
  96. case 'bet':
  97. return this.loadBet()
  98. case 'sender':
  99. return this.loadSender()
  100. case 'response':
  101. return this.loadResponse()
  102. case 'addressesTxs':
  103. return this.loadAddressesTxs()
  104. case 'bfp':
  105. return this.loadBFP()
  106. case 'bml':
  107. return this.loadBML()
  108. default:
  109. return this.loadDefault()
  110. }
  111. },
  112. loadDefault() {
  113. this.userQuery = `/* Customize your query below. */
  114. {
  115. "v": 3,
  116. "q": {
  117. "find": {},
  118. "limit": 10
  119. }
  120. }
  121. `
  122. },
  123. loadLatestBlock() {
  124. this.userQuery = `/* Customize your query below. */
  125. latest
  126. `
  127. },
  128. loadAdvanced() {
  129. this.userQuery = `/* Customize your query below. */
  130. adv
  131. `
  132. },
  133. loadMemo() {
  134. this.userQuery = `/* Customize your query below. */
  135. {
  136. "v": 3,
  137. "q": {
  138. "find": {
  139. "out.h1": "6d02"
  140. }
  141. }
  142. }
  143. `
  144. },
  145. loadHello() {
  146. this.userQuery = `/* Customize your query below. */
  147. {
  148. "v": 3,
  149. "q": {
  150. "find": {
  151. "out.b0": { "op": 106 },
  152. "out.s1": "hello"
  153. },
  154. "limit": 10
  155. }
  156. }
  157. `
  158. },
  159. loadBet() {
  160. this.userQuery = `/* Customize your query below. */
  161. {
  162. "v": 3,
  163. "q": {
  164. "find": {
  165. "$text": { "$search": "bet" },
  166. "out.h1": "6d02",
  167. "out.s2": { "$regex": "bet", "$options": "i" }
  168. },
  169. "limit": 10
  170. }
  171. }
  172. `
  173. },
  174. loadSender() {
  175. this.userQuery = `/* Customize your query below. */
  176. {
  177. "v": 3,
  178. "q": {
  179. "find": { "in.e.a": "qq4kp3w3yhhvy4gm4jgeza4vus8vpxgrwc90n8rhxe" },
  180. "limit": 10
  181. }
  182. }
  183. `
  184. },
  185. loadResponse() {
  186. this.userQuery = `/* Customize your query below. */
  187. {
  188. "v": 3,
  189. "q": {
  190. "find": { "out.h1": "6d02" },
  191. "limit": 100
  192. },
  193. "r": {
  194. "f": "[ { block: .blk.i?, timestamp: .blk.t?, content: .out[1].s2 } ]"
  195. }
  196. }
  197. `
  198. },
  199. loadAddressesTxs() {
  200. this.userQuery = `/* Customize your query below. */
  201. {
  202. "v": 3,
  203. "q": {
  204. "find": {
  205. "$or": [
  206. { "in.e.a": "qzpwncftddx7f59z93w4qv4hnj4as335vvz8gftqvr" },
  207. { "out.e.a": "qzpwncftddx7f59z93w4qv4hnj4as335vvz8gftqvr" }
  208. ]
  209. }
  210. }
  211. }
  212. `
  213. },
  214. loadBFP() {
  215. this.userQuery = `/* Customize your query below. */
  216. {
  217. "v": 3,
  218. "q": {
  219. "find": {
  220. "out.h1": "42465000"
  221. },
  222. "limit": 10
  223. }
  224. }
  225. `
  226. },
  227. loadBML() {
  228. this.userQuery = `/* Customize your query below. */
  229. {
  230. "v": 3,
  231. "q": {
  232. "find": {
  233. "out.h1": "424D4C00"
  234. },
  235. "limit": 10
  236. }
  237. }
  238. `
  239. },
  240. },
  241. created: async function () {
  242. this.requests = []
  243. let request
  244. request = {
  245. v: 3,
  246. q: {
  247. find: {},
  248. limit: 10
  249. }
  250. }
  251. this.requests.push(request)
  252. },
  253. mounted: function () {
  254. //
  255. },
  256. }
  257. </script>