Skip to content

feat: add accounts/compare endpoint - #1597

Merged
Imod7 merged 3 commits into
masterfrom
domi-compare-addresses
Feb 21, 2025
Merged

feat: add accounts/compare endpoint#1597
Imod7 merged 3 commits into
masterfrom
domi-compare-addresses

Conversation

@Imod7

@Imod7 Imod7 commented Feb 18, 2025

Copy link
Copy Markdown
Contributor

Description

Closes #1591

Adds a new endpoint, accounts/compare, that compares up to 30 SS58 addresses and determines if they are equal which means that they share the same public key. Returns a boolean result along with detailed information for each address queried.

Implementation Notes

  • The request should be follow one of these formats :

    • by repeating the addresses key: ?addresses=...&addresses=... or
    • by using the array style key: ?addresses[]=...&addresses[]=... or
    • by using comma-separated values: ?addresses=...,....
  • The limit of 30 addresses was set to keep the character count of the request at a reasonable size/not too big.

  • The additional function validateAddressQueryParamMiddleware was added to check that the addresses as query parameters were valid.

Sample Request/Response

Example request to check 4 SS58 addresses

http://127.0.0.1:8080/accounts/compare?addresses[]=1jeB5w8XyBADtgmVmwk2stWpTyfTVWEgLo85tF7gYVxnmSw&addresses[]=DJxh51wJYvcY1VhJqhnngRN7SGFZrmH4DuPKFXicFgwMQCT&addresses[]=WfwU3e9TRYo1Bi62SLrvPDe3th8jQeqd3ZnAJTczpUQCNZ8&addresses[]=cTbj3BYqiRXAF7YvyDtJHV4hNqRnbHMoz7umz6vTg4tUjCY

Example response

{
  "areEqual": true,
  "addresses": [
    {
      "ss58Format": "1jeB5w8XyBADtgmVmwk2stWpTyfTVWEgLo85tF7gYVxnmSw",
      "ss58Prefix": "0",
      "network": "polkadot",
      "publicKey": "0x20857206fde63ea508a317a77bc1ca2a795c978533b71fc7bc21d352d832637c"
    },
    {
      "ss58Format": "DJxh51wJYvcY1VhJqhnngRN7SGFZrmH4DuPKFXicFgwMQCT",
      "ss58Prefix": "2",
      "network": "kusama",
      "publicKey": "0x20857206fde63ea508a317a77bc1ca2a795c978533b71fc7bc21d352d832637c"
    },
    {
      "ss58Format": "WfwU3e9TRYo1Bi62SLrvPDe3th8jQeqd3ZnAJTczpUQCNZ8",
      "ss58Prefix": "5",
      "network": "astar",
      "publicKey": "0x20857206fde63ea508a317a77bc1ca2a795c978533b71fc7bc21d352d832637c"
    },
    {
      "ss58Format": "cTbj3BYqiRXAF7YvyDtJHV4hNqRnbHMoz7umz6vTg4tUjCY",
      "ss58Prefix": "6",
      "network": "bifrost",
      "publicKey": "0x20857206fde63ea508a317a77bc1ca2a795c978533b71fc7bc21d352d832637c"
    }
  ]
}

Additional Tests

Tested for:

  • Invalid query param names (address, addressA)
    http://127.0.0.1:8080/accounts/compare?address=1jeB5w8XyBADtgmVmwk2stWpTyfTVWEgLo85tF7gYVxnmSw&addressA=DJxh51wJYvcY1VhJqhnngRN7SGFZrmH4DuPKFXicFgwMQCT
    
  • No query params
    http://127.0.0.1:8080/accounts/compare
    
  • 1 query param
    http://127.0.0.1:8080/accounts/compare?addresses[]=1jeB5w8XyBADtgmVmwk2stWpTyfTVWEgLo85tF7gYVxnmSw
    
  • 30 addresses
  • > 30 addresses
  • Use a valid query param key and an invalid one
     http://127.0.0.1:8080/accounts/compare?addresses[]=1jeB5w8XyBADtgmVmwk2stWpTyfTVWEgLo85tF7gYVxnmSw&addressA=DJxh51wJYvcY1VhJqhnngRN7SGFZrmH4DuPKFXicFgwMQCT
    
  • Correct query param name but no address value
    http://127.0.0.1:8080/accounts/compare?addresses[]=
    

@Imod7
Imod7 requested a review from a team as a code owner February 18, 2025 20:06
Comment thread docs/src/openapi-v1.yaml Outdated
@Imod7
Imod7 requested a review from filvecchiato February 19, 2025 12:03
Comment thread docs/src/openapi-v1.yaml Outdated
Comment thread src/middleware/validate/validateAddressMiddleware.ts Outdated
- Refactored Middleware
- Updated Controller
- Fixed & updated docs
@Imod7
Imod7 requested a review from filvecchiato February 20, 2025 15:43
@filvecchiato

Copy link
Copy Markdown
Contributor

LGTM!

@TarikGul TarikGul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very solid! Great Job

@Imod7
Imod7 merged commit 191e68a into master Feb 21, 2025
@Imod7
Imod7 deleted the domi-compare-addresses branch February 21, 2025 15:23
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

Successfully merging this pull request may close these issues.

Add accounts/compare endpoint

3 participants