everx-labs / ever-cli

Command line tool for TVM compatible networks (Everscale, TON, Venom, Gosh, etc)
GNU General Public License v3.0
83 stars 32 forks source link

Decode body issue for external out messages bodies #922

Closed alinaT95 closed 5 months ago

alinaT95 commented 1 year ago
docker run -d --name local-node -e USER_AGREEMENT=yes -p80:80 tonlabs/local-node
git clone https://github.com/alinaT95/DecodyBodyIssue
cd DecodyBodyIssue
tonos-cli getkeypair -o key.json
output=`tonos-cli -j genaddr --setkey key.json 1_Accumulator.tvc --abi 1_Accumulator.abi.json --save --wc 0`
echo $output
{
  "raw_address": "0:12d54c354a3421568fca88297cdc8928dc63084d5c61e96ae8638ec8eeba38de",
  "testnet": {
    "non-bounceable": "0QAS1Uw1SjQhVo_KiCl83Iko3GMITVxh6WroY47I7ro43iqe",
    "bounceable": "kQAS1Uw1SjQhVo_KiCl83Iko3GMITVxh6WroY47I7ro43ndb"
  },
  "mainnet": {
    "non-bounceable": "UQAS1Uw1SjQhVo_KiCl83Iko3GMITVxh6WroY47I7ro43pEU",
    "bounceable": "EQAS1Uw1SjQhVo_KiCl83Iko3GMITVxh6WroY47I7ro43szR"
  }
}
json=${output#*data:}
addr=$(echo "$json" | jq -r '.raw_address')
echo $addr
0:12d54c354a3421568fca88297cdc8928dc63084d5c61e96ae8638ec8eeba38de
tonos-cli call  --abi ./local_giver.abi.json 0:ece57bcc6c530283becbbd8a3b24d3c5987cdddc3c8b7b33be6e4a6312490415 sendTransaction "{\"dest\":\"${addr}\", \"value\":\"10000000000000\",\"bounce\":\"false\",\"allBalance\":\"false\",\"payload\":\"\"}" --sign ./local_giver.keys.json
tonos-cli deploy --wc 0 --abi 1_Accumulator.abi.json 1_Accumulator.tvc {} --sign key.json
tonos-cli -j call  --abi 1_Accumulator.abi.json $addr add_1 '{"value":"101"}' --sign key.json
output=`tonos-cli -j query-raw messages --filter "{\"src\": { \"eq\":\"${addr}\"}}" --limit 1 " id created_at created_at_string msg_type_name body boc"  --order '[{"path":"created_at", "direction":"DESC"}]'`
echo $output
[
  {
    "id": "dd0bb15d5a0d4c2f77925b57a2425baf5d9a62776c81b4b09a5ccf68f08f6c6a",
    "created_at": 1689322540,
    "created_at_string": "2023-07-14 08:15:40.000",
    "msg_type_name": "ExtOut",
    "body": "te6ccgEBAQEAJgAASGRn/xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZw==",
    "boc": "te6ccgEBAQEAVQAApeAAlqphqlGhCrR+VEFL5uRJRuMYQmrjD0tXQxx2R3XRxvAAAAAAAAAtbsliCFgyM/+IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADPA"
  }
]
json=${output#*data:}
msg=$(echo "$json" | jq -r '.[0]')
echo $msg
{
    "id": "dd0bb15d5a0d4c2f77925b57a2425baf5d9a62776c81b4b09a5ccf68f08f6c6a",
    "created_at": 1689322540,
    "created_at_string": "2023-07-14 08:15:40.000",
    "msg_type_name": "ExtOut",
    "body": "te6ccgEBAQEAJgAASGRn/xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZw==",
    "boc": "te6ccgEBAQEAVQAApeAAlqphqlGhCrR+VEFL5uRJRuMYQmrjD0tXQxx2R3XRxvAAAAAAAAAtbsliCFgyM/+IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADPA"
  }
boc=$(echo "$msg" | jq -r '.boc')
echo $boc
te6ccgEBAQEAVQAApeAAlqphqlGhCrR+VEFL5uRJRuMYQmrjD0tXQxx2R3XRxvAAAAAAAAAtbsliCFgyM/+IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADPA
output=`tonos-cli -j decode msg --abi 1_Accumulator.abi.json "$boc"`
echo $output
{
  "Type": "external outbound message",
  "Header": {
    "source": "0:f12ffdc23e0c9eb907a3e6cd1dc766b932033cf41f50af603d88efd33e9e5bb5",
    "destination": "",
    "created_lt": "5824",
    "created_at": "1689325480"
  },
  "Body": "te6ccgEBAQEAJgAASGRn/xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZw==",
  "BodyCall": {
    "TryEvent": {
      "summ": "0x0000000000000000000000000000000000000000000000000000000000000067"
    }
  }
}
json=${output#*data:}
body=$(echo "$json" | jq -r '.Body')
echo $body
te6ccgEBAQEAJgAASGRn/xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZw==
tonos-cli -j decode body  --abi 1_Accumulator.abi.json "$body"
{
  "Error": "Failed to decode header: Deserialization error Not enough remaining bits in the cell: data: 258..288, references: 0..0, data slice:0000019c, cell:bits: 288   refs: 0   data: 6467ff100000000000000000000000000000000000000000000000000000000000000067\n"
}

Notes:

tonos-cli -j decode body  --abi 1_Accumulator.abi.json "$body"
{
  "BodyCall": {
    "TryEvent_1": {
      "summ": "0x00000000000000000000000000000000000000000000000000000000000000cc"
    }
  },
  "Signature": "None",
  "Header": null,
  "FunctionId": "00000000"
}