LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 456 forks source link

[transactionSchema] Use constants for integral values & add missing `length` check for `signatures` #8766

Closed sitetester closed 11 months ago

sitetester commented 1 year ago

Description

transactionSchema

  1. This schema uses constants for minLength, maxLength

    "module": {
      "dataType": "string",
      "minLength": MIN_MODULE_NAME_LENGTH,
      "maxLength": MAX_MODULE_NAME_LENGTH,
      "fieldNumber": 1
    },
    "command": {
      "dataType": "string",
      "minLength": MIN_COMMAND_NAME_LENGTH,
      "maxLength": MAX_COMMAND_NAME_LENGTH,
      "fieldNumber": 2
    },

    But in code, these are added as hard coded values

    dataType: 'string',
    fieldNumber: 1,
    minLength: 1, // ***
    maxLength: 32, // ***
    },
    command: {
    dataType: 'string',
    fieldNumber: 2,
    minLength: 1, // ***
    maxLength: 32, // ***
    },

    So they need to be replaced with constants per above schema.

  2. Although length check is missing in signatures property (in code) for the reason: "it is to support unsigned tx as well where there is no signature". Thus we can just add this comment in schema, so we know why it's not added there.

"signatures": {
      "dataType": "array",
      "items": {
          "dataType": "bytes",
          "length": ED25519_SIGNATURE_LENGTH // ***
      },
      "fieldNumber": 7
  }

Motivation

If tomorrow we need to change lengths for module/command names, it would have a global effect by changing one line.

Additional Information

shuse2 commented 11 months ago

Closing this issue for no activity