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

Add Rosetta Indexer #3870

Merged
merged 4 commits into from
Oct 26, 2021
Merged

Conversation

LuttyYang
Copy link
Contributor

@LuttyYang LuttyYang commented Sep 6, 2021

This PR implements Rosetta's Indexer API(https://www.rosetta-api.org/docs/indexers.html), currently support Events and Search Endpoints

Test

Events Endpoints:

POST /events/blocks HTTP/1.1
Content-Type: application/json

{
    "network_identifier": {
        "blockchain": "Harmony",
        "network": "Testnet",
        "sub_network_identifier": {
            "network": "shard 0",
            "metadata": {
               "is_beacon": true
            }
        }
    },
    "offset": 1000,
    "limit": 5
}

---

HTTP/1.1 200 OK

{
    "max_sequence": 19020,
    "events": [
        {
            "sequence": 1000,
            "block_identifier": {
                "index": 1000,
                "hash": "0x7698a5a502089ecb37580897e3798f1c2425c07511fdde164f385d1e99252bf5"
            },
            "type": "block_added"
        },
        {
            "sequence": 1001,
            "block_identifier": {
                "index": 1001,
                "hash": "0xe086efe7374e3b43d4b50a2c9c88942f86539ff9f9f6bc82e84d5eeab4fce454"
            },
            "type": "block_added"
        },
        {
            "sequence": 1002,
            "block_identifier": {
                "index": 1002,
                "hash": "0xbebc5649ff1a6bb75c38da881fdff35796d8369b59831729d6cd29045ff70c02"
            },
            "type": "block_added"
        },
        {
            "sequence": 1003,
            "block_identifier": {
                "index": 1003,
                "hash": "0xdc068a9535201626dc602e4feccea32d4f1df9de044e1986b06a3e8fc413c7b2"
            },
            "type": "block_added"
        },
        {
            "sequence": 1004,
            "block_identifier": {
                "index": 1004,
                "hash": "0x6818d0326cfdc30b47172877010bc55251601bf79dbb3a83d6ba15258b231099"
            },
            "type": "block_added"
        }
    ]
}

Search Endpoints:

POST /search/transactions HTTP/1.1
Content-Type: application/json

{
    "network_identifier": {
        "blockchain": "Harmony",
        "network": "Testnet",
        "sub_network_identifier": {
            "network": "shard 0",
            "metadata": {
                "is_beacon": true
            }
        }
    },
    "operator": "or",
    "max_block": 5,
    "offset": 5,
    "limit": 5,
    "transaction_identifier": {
        "hash": "0x51207385e8327cc1405adc43049975557d1b07f205feebc89f4a2975df7819f4"
    }
}

---

HTTP/1.1 200 OK

{
    "transactions": [
        {
            "block_identifier": {
                "index": 9996,
                "hash": "0x7a863597cad374895c8aad5e1b09bc54ffa76097cb963cf8ad7c9dadb99865e7"
            },
            "transaction": {
                "transaction_identifier": {
                    "hash": "0x4573e600fc7ebf3d42116f89877edd751447bdb64f387070768118557748b409"
                },
                "operations": [
                    {
                        "operation_identifier": {
                            "index": 0
                        },
                        "type": "NativeTransfer",
                        "status": "success",
                        "account": {
                            "address": "one1l70tcs2u02ft54p4dupvunjcny54ry2wqzdmyu",
                            "metadata": {
                                "hex_address": "0xff9eBc415C7a92ba54356f02CE4E58992951914e"
                            }
                        },
                        "amount": {
                            "value": "10000000000000000000",
                            "currency": {
                                "symbol": "ONE",
                                "decimals": 18
                            }
                        }
                    }
                ],
                "metadata": {
                    "index": 0,
                    "size": "182.00 B"
                }
            }
        }
    ],
    "total_count": 1
}

@LuttyYang LuttyYang requested a review from LeoHChen September 6, 2021 12:44
Copy link
Contributor

@LeoHChen LeoHChen left a comment

Choose a reason for hiding this comment

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

  1. please make sure we cache the data to serve the request
  2. please add upper bound limit to the request limit, so that the indexer API won't take too long to run

@LuttyYang
Copy link
Contributor Author

@LeoHChen Added LRU cache, Currently cache 1000 requests within 5 minutes

@LeoHChen LeoHChen merged commit c317881 into harmony-one:main Oct 26, 2021
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.

2 participants