Nexad.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. Nexa Daemon
  5. </h1>
  6. <section class="my-3">
  7. <h2>Get wallet info</h2>
  8. <code><pre>
  9. nexa-cli getwalletinfo
  10. </pre></code>
  11. </section>
  12. <section class="my-3">
  13. <h2>List unspent UTXOs</h2>
  14. <code><pre>
  15. nexa-cli listunspent
  16. </pre></code>
  17. </section>
  18. <section class="my-3">
  19. <h2>List unspent UTXOs</h2>
  20. <code><pre>
  21. nexa-cli listunspent
  22. </pre></code>
  23. </section>
  24. <!-- Page Section -->
  25. <section class="w-full h-full flex">
  26. <div class="w-1/2 bg-rose-500">
  27. code window
  28. <select @change="selectQuery" v-model="selected">
  29. <option value="default">Default</option>
  30. </select>
  31. <textarea class="w-full h-96" v-model="userQuery" />
  32. <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">
  33. Send Query
  34. </button>
  35. </div>
  36. <div class="w-1/2 bg-yellow-300 overflow-x-scroll overflow-y-scroll">
  37. instructions &amp; output
  38. <pre v-html="output" />
  39. </div>
  40. </section>
  41. </main>
  42. </template>
  43. <script>
  44. /* Import modules. */
  45. // import Nito from 'nitojs'
  46. /* Import components. */
  47. // import UnderConstruction from '@/components/UnderConstruction'
  48. export default {
  49. components: {
  50. // UnderConstruction,
  51. },
  52. data: () => {
  53. return {
  54. requests: null,
  55. selected: null,
  56. output: null,
  57. userQuery: null,
  58. }
  59. },
  60. computed: {
  61. //
  62. },
  63. methods: {
  64. async query() {
  65. console.log('SEND QUERY')
  66. /* Clear output. */
  67. this.output = ''
  68. let request
  69. if (this.userQuery) {
  70. try {
  71. // NOTE: We remove "helpful" comment.
  72. const pos = this.userQuery.indexOf('{')
  73. let userQuery
  74. if (pos) {
  75. userQuery = this.userQuery.slice(pos)
  76. } else {
  77. userQuery = this.userQuery
  78. }
  79. request = JSON.parse(userQuery)
  80. } catch (err) {
  81. console.error(err)
  82. }
  83. } else {
  84. request = this.requests[0]
  85. }
  86. console.log('REQUEST', request)
  87. // const response = await fetch()
  88. const response = await Nito.Blockchain.Query.request(request)
  89. .catch(err => console.error(err))
  90. console.log('RESPONSE (body):', response)
  91. this.output = JSON.stringify(response, null, 2)
  92. },
  93. selectQuery() {
  94. console.log('SELECTED', this.selected)
  95. switch(this.selected) {
  96. case 'latest-block':
  97. return this.loadLatestBlock()
  98. default:
  99. return this.loadDefault()
  100. }
  101. },
  102. loadDefault() {
  103. this.userQuery = `/* Customize your query below. */
  104. n/a
  105. `
  106. },
  107. /**
  108. * Remote Procedure Call (RPC)
  109. *
  110. * @param {String} _method
  111. * @param {Object} _params
  112. * @returns
  113. */
  114. async rpc(_method, _params) {
  115. let endpoint
  116. let error
  117. let response
  118. // try {
  119. // /* Set endpoint. */
  120. // endpoint = `http://user:[email protected]:7227`
  121. // /* Build package. */
  122. // const pkg = {
  123. // "jsonrpc": "2.0",
  124. // "id": "core",
  125. // "method": _method,
  126. // "params": _params,
  127. // }
  128. // /* Request Elasticsearch query. */
  129. // response = await fetch
  130. // .post(endpoint)
  131. // .set('accept', 'json')
  132. // .send(pkg)
  133. // .catch(_err => {
  134. // console.error(_err)
  135. // if (_err && _err.response && _err.response.text) {
  136. // error = JSON.parse(_err.response.text)
  137. // } else if (_err && _err.response) {
  138. // error = _err.response
  139. // } else {
  140. // error = _err
  141. // }
  142. // })
  143. // /* Validate error. */
  144. // if (error) {
  145. // return error
  146. // }
  147. // /* Validate response. */
  148. // if (!response) {
  149. // return null
  150. // }
  151. // // console.log('\nRPC CALL (response):', response)
  152. // /* Validate response. */
  153. // if (response.body && response.body.result) {
  154. // return response.body.result
  155. // } else if (response.text) {
  156. // return response.text
  157. // } else {
  158. // return null
  159. // }
  160. // } catch (err) {
  161. // return err
  162. // }
  163. },
  164. },
  165. created: async function () {
  166. this.requests = []
  167. let request
  168. request = {
  169. v: 3,
  170. q: {
  171. find: {},
  172. limit: 10
  173. }
  174. }
  175. this.requests.push(request)
  176. // const rpc = await this.rpc('getwalletinfo', '')
  177. // console.log('RPC (getwalletinfo):', rpc)
  178. },
  179. mounted: function () {
  180. //
  181. },
  182. }
  183. </script>