exchain icon indicating copy to clipboard operation
exchain copied to clipboard

Convert raw_log to json format

Open angelorc opened this issue 4 years ago • 2 comments

Summary

Convert raw_log response to json format. Is util for javascript libraries.

Problem Definition

I'm building an UI based on OkChain, in the case where we use this function to post an order

async onNewOrder() {
      this.loading = true
      const order = {
        price: String(this.price),
        product: 'tokt_tusdk',
        quantity: String(this.amount),
        side: 'BUY'
      }

      //{price: "0.37000000", product: "tokt_tusdk", quantity: "0.00100000", side: "BUY"}
      //0.37000000	4 640.00200000

      const btsg = new Bitsong()
      const response = await btsg.newOrder(
        order,
        this.$store.getters[`wallet/address`],
        '',
        this.$store.getters[`wallet/privateKey`],
        '0.0000001',
        '200000'
      )

      if (response.height === '0') {
        const log = JSON.parse(response.raw_log)
        this.$store.dispatch('app/toggleSnackbar', log.message)
      } else {
        this.$store.dispatch('app/toggleSnackbar', 'Order Placed')
      }

      this.loading = false
      this.$emit('orderCreated')
    }
  },

the string const log = JSON.parse(response.raw_log) will fail because raw_log is plain text format.

{
  "height": "0",
  "txhash": "52934FEF0486ACD871940046B1BA1D6FD5DEFB70B2850013257D614E6EF599EB",
  "code": 10,
  "raw_log": "ERROR:\nCodespace: sdk\nCode: 10\nMessage: \"insufficient account funds; 99.43199500tokt,0.01185285tusdk is less than 2.45000000tusdk\"\n",
  "gas_used": "33886"
}

Proposal

Change the format so that it can be parsed by JSON.parse()


For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned

angelorc avatar Jun 15 '20 13:06 angelorc

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

fpChan avatar Jun 16 '20 10:06 fpChan

The escaping is caused by amino coding in cosmos https://github.com/cosmos/cosmos-sdk/issues/6479.

fpChan avatar Jun 30 '20 07:06 fpChan