koinos / koinos-cli

A command line utility used for key management and to interact with the Koinos blockchain.
Other
9 stars 7 forks source link

Output correct JSON format when submitting an offline session #196

Closed mvandeberg closed 7 months ago

mvandeberg commented 7 months ago

Brief description

When submitting an offline transaction, the resulting JSON did not use the correct encodings for binary data. This PR fixes it to do so.

Checklist

Demonstration

Without fix:

🚫 🔓 📄 > session submit
JSON:
{
  "id": "EiCEv74qLN53NG6fo+vJUlhgsK7JCDU7wdKtXwYTV6G4gg==",
  "header": {
    "chain_id": "Zm9vYmFy",
    "rc_limit": 1000000000,
    "nonce": "KBQ=",
    "operation_merkle_root": "EiBHEzzpN+hYlXGwlz6Wg+D9IrJmSPRsVr63tNV2SeYMQQ==",
    "payer": "ACISicKuuJib6PEWx9Zag4wm0wDj3z7sGg=="
  },
  "operations": [
    {
      "Op": {
        "CallContract": {
          "contract_id": "AC4z/RqpB7IkzpzmyUIokB0oOgLalW2nkQ==",
          "entry_point": 670398154,
          "args": "ChkAIhKJwq64mJvo8RbH1lqDjCbTAOPfPuwaEgUF7jPIQxiAlOvcAw=="
        }
      }
    }
  ],
  "signatures": [
    "IKrnZXw/qzbDbCluHMhIYTObDVNsZljkOTOwtrS5I5kyN2ldyzGKkfIlpRCUPDVvTDjzaGwticly6aVTnujOaq0="
  ]
}

Base64:
CiISIIS_vios3nc0bp-j68lSWGCwrskINTvB0q1fBhNXobiCElEKBmZvb2JhchCAlOvcAxoCKBQiIhIgRxM86TfoWJVxsJc-loPg_SKyZkj0bFa-t7TVdknmDEEqGQAiEonCrriYm-jxFsfWWoOMJtMA498-7BoaTRJLChkALjP9GqkHsiTOnObJQiiQHSg6AtqVbaeREMrt1b8CGigKGQAiEonCrriYm-jxFsfWWoOMJtMA498-7BoSBQXuM8hDGICU69wDIkEgqudlfD-rNsNsKW4cyEhhM5sNU2xmWOQ5M7C2tLkjmTI3aV3LMYqR8iWlEJQ8NW9MOPNobC2JyXLppVOe6M5qrQ==

With fix:

🚫 🔓 📄 > session submit
JSON:
{
  "id": "0x122084bfbe2a2cde77346e9fa3ebc9525860b0aec908353bc1d2ad5f061357a1b882",
  "header": {
    "chain_id": "Zm9vYmFy",
    "rc_limit": "1000000000",
    "nonce": "KBQ=",
    "operation_merkle_root": "EiBHEzzpN-hYlXGwlz6Wg-D9IrJmSPRsVr63tNV2SeYMQQ==",
    "payer": "147ABaHVxtpoSpfpZ8yry7eaFAjV87trGR"
  },
  "operations": [
    {
      "call_contract": {
        "contract_id": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
        "entry_point": 670398154,
        "args": "ChkAIhKJwq64mJvo8RbH1lqDjCbTAOPfPuwaEgUF7jPIQxiAlOvcAw=="
      }
    }
  ],
  "signatures": [
    "IKrnZXw_qzbDbCluHMhIYTObDVNsZljkOTOwtrS5I5kyN2ldyzGKkfIlpRCUPDVvTDjzaGwticly6aVTnujOaq0="
  ]
}

Base64:
CiISIIS_vios3nc0bp-j68lSWGCwrskINTvB0q1fBhNXobiCElEKBmZvb2JhchCAlOvcAxoCKBQiIhIgRxM86TfoWJVxsJc-loPg_SKyZkj0bFa-t7TVdknmDEEqGQAiEonCrriYm-jxFsfWWoOMJtMA498-7BoaTRJLChkALjP9GqkHsiTOnObJQiiQHSg6AtqVbaeREMrt1b8CGigKGQAiEonCrriYm-jxFsfWWoOMJtMA498-7BoSBQXuM8hDGICU69wDIkEgqudlfD-rNsNsKW4cyEhhM5sNU2xmWOQ5M7C2tLkjmTI3aV3LMYqR8iWlEJQ8NW9MOPNobC2JyXLppVOe6M5qrQ==

Notice the contract ID, transaction ID, contract address, and payer address are all correctly formatted. Furthermore, the base64 encoded fields properly use the URL safe encoding.