Opentonapi simplifies development of TON-based applications and provides an API centered around high-level concepts like Jettons, NFTs and so on keeping a way to access low-level details.
MIT License
224
stars
68
forks
source link
Fix request body decoding mistake in SendRawMessage #355
While trying to use the /v2/liteserver/send_message api as described on https://tonapi.io/api-v2, I ran into the issue where the server doesn't seem to accept any formats of the boc messages I sent, whether it's base64, hex string, hex string with 0x, or even integer. It returns status code 500 with the exception message "unknown magic prefix", which is thrown here.
This issue has been there since 6f41163788f40f8be960dc0d87b8fc7e4109fd45, that's 9 months ago. I'm not sure if this intentional or not. I suspect there were some changes in the way tongo handles the payload but opentonapi was not updated correctly.
The fix was to use base64.StdEncoding.DecodeString(request.Body). Now we're able to send boc's encoded in base64.
While trying to use the
/v2/liteserver/send_message
api as described on https://tonapi.io/api-v2, I ran into the issue where the server doesn't seem to accept any formats of the boc messages I sent, whether it's base64, hex string, hex string with 0x, or even integer. It returns status code 500 with the exception message "unknown magic prefix", which is thrown here.After investigating, I found that the issue is at liteserver_handlers.go#L91
Firstly,
json.Marshal
will puts a 0x22 (or"
) at the beginning and the end ofpayload
, secondly, it can't handle bytes string this way.For example
json.Marshal("abc")
outputs22 61 62 63 22
, andjson.Marshal("\x00\x01\x02")
outputs22 5c 75 30 30 30 30 5c 75 30 30 30 31 5c 75 30 30 30 32 22
.This issue has been there since 6f41163788f40f8be960dc0d87b8fc7e4109fd45, that's 9 months ago. I'm not sure if this intentional or not. I suspect there were some changes in the way tongo handles the payload but opentonapi was not updated correctly.
The fix was to use
base64.StdEncoding.DecodeString(request.Body)
. Now we're able to send boc's encoded in base64.