Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON serialization inconsistencies #177

Open
0xJohnnyGault opened this issue Mar 22, 2024 · 0 comments
Open

JSON serialization inconsistencies #177

0xJohnnyGault opened this issue Mar 22, 2024 · 0 comments

Comments

@0xJohnnyGault
Copy link

There seem to be some inconsistencies with Go and Rust with regards to JSON serialization.

AvalancheGo serializes a tx to JSON json.Marshal(tx) that looks like this:

{
  "unsignedTx": {
    "networkID": 1337,
    "blockchainID": "11111111111111111111111111111111LpoYY",
    "outputs": [
      {
        "assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
        "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
        "output": {
          "addresses": ["P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"],
          "amount": 19999999899000000,
          "locktime": 0,
          "threshold": 1
        }
      }
    ],
    "inputs": [
      {
        "txID": "CjisYCwF4j7zSyC25MWR21e5xxzJgwdaLEuf7oBXSGpe3oaej",
        "outputIndex": 0,
        "assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
        "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
        "input": { "amount": 19999999900000000, "signatureIndices": [0] }
      }
    ],
    "memo": "0x",
    "validator": {
      "nodeID": "NodeID-JHD1JDUZYkiMdWPMDA9UJhWXR4wf25t39",
      "start": 1711142673,
      "end": 1711142913,
      "weight": 20,
      "subnetID": "CjisYCwF4j7zSyC25MWR21e5xxzJgwdaLEuf7oBXSGpe3oaej"
    },
    "subnetAuthorization": { "signatureIndices": [0] }
  },
  "credentials": [
    {
      "signatures": [
        "0x3265999bb1a3390f09ca28a75e293faeb2f5670d26d9e99dfef9db7ccf08ccbb35f8fe144e63c91f24d0eca57d9db9d8cf7c223362e58b89eb0d317d4c35ac1c00"
      ]
    },
    {
      "signatures": [
        "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      ]
    }
  ],
  "id": "2EhnpHqoBEJYFmfBiBmvoykWLFvxAjMXuuLGjvSCuCWvMaHbo1"
}

Avalanchego generates these bytes for the above: 00000000000d0000053900000000000000000000000000000000000000000000000000000000000000000000000194b45aa6e4464a9ad3fc4e73c7947ba1632d7c820baf0ebbfc7548c4823f26bd0000000700470de4d97cdcc0000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c000000011aa63be8467b5f45765fb172c6ed6644a6edb66ca041167e60a0781662fade580000000094b45aa6e4464a9ad3fc4e73c7947ba1632d7c820baf0ebbfc7548c4823f26bd0000000500470de4d98c1f00000000010000000000000000bd8ad0a918e6791a321e03355e707609ecf856de0000000065fdf7110000000065fdf80100000000000000141aa63be8467b5f45765fb172c6ed6644a6edb66ca041167e60a0781662fade580000000a00000001000000000000000200000009000000013265999bb1a3390f09ca28a75e293faeb2f5670d26d9e99dfef9db7ccf08ccbb35f8fe144e63c91f24d0eca57d9db9d8cf7c223362e58b89eb0d317d4c35ac1c0000000009000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

But the only structure I can come up with that this Rust SDK will deserialize looks like this:

{
  "base_tx": {
    "networkID": 1337,
    "blockchainID": "11111111111111111111111111111111LpoYY",
    "outputs": [
      {
        "assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
        "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
        "output": {
          "addresses": ["P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"],
          "amount": 19999999899000000,
          "locktime": 0,
          "threshold": 1
        }
      }
    ],
    "inputs": [
      {
        "txID": "2c1CbR7FGYdeFPB4WaeWphHZrChLH7TQ92FRW6U4mCWTnaxVsB",
        "outputIndex": 0,
        "assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
        "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
        "input": {
          "amount": 19999999900000000,
          "signatureIndices": [0]
        }
      }
    ],
    "memo": "0x"
  },
  "validator": {
    "validator": {
      "node_id": "NodeID-111111111111111111116DBWJs",
      "start": 1710879913,
      "end": 1710966313,
      "weight": 20
    },
    "subnet_id": "2c1CbR7FGYdeFPB4WaeWphHZrChLH7TQ92FRW6U4mCWTnaxVsB"
  },
  "subnet_auth": { "sig_indices": [0] },
  "creds": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant