regen-network / indexer

:rocket: Blockchain indexer and database
Other
2 stars 0 forks source link

Add `group_id` to `proposals` table #26

Closed wgwz closed 1 year ago

wgwz commented 1 year ago

By adding group_id to the proposals table, we gain the ability to quickly look up the historical (pruned) proposals for a particular group. We will add an database index to the column. This will be required in the context of the historical proposals in the groups-ui: https://github.com/regen-network/groups-ui/pull/106

Prior to inserting a proposal record in the indexer, we can perform a lookup of the group id. Given a proposal object which is already fetched in the current index_proposals, you can use the group_policy_address to look up the group id.

Sample proposal and group_policy_address:

➜  analytics git:(main) ✗ http http://localhost:1317/cosmos/group/v1/proposal/9 x-cosmos-block-height:35029
HTTP/1.1 200 OK
Content-Length: 1045
Content-Type: application/json
Date: Thu, 13 Jul 2023 23:49:58 GMT
Grpc-Metadata-Content-Type: application/grpc+cosmos-sdk-grpc-codec
Grpc-Metadata-X-Cosmos-Block-Height: 35029
X-Server-Time: 1689292198
{
    "proposal": {
        "executor_result": "PROPOSAL_EXECUTOR_RESULT_NOT_RUN",
        "final_tally_result": {
            "abstain_count": "0",
            "no_count": "0",
            "no_with_veto_count": "0",
            "yes_count": "1"
        },
        "group_policy_address": "regen13cwsdsetcrhcyd3jeed0mgteg35qaju0q5s0u0drfylagahygwwstgwupv",
        "group_policy_version": "2",
        "group_version": "2",
        "id": "9",
        "messages": [
            {
                "@type": "/cosmos.group.v1.MsgUpdateGroupMetadata",
                "admin": "regen13cwsdsetcrhcyd3jeed0mgteg35qaju0q5s0u0drfylagahygwwstgwupv",
                "group_id": "16",
                "metadata": "{\"name\":\"Kyle's Group\",\"description\":\"Foobar.!\",\"forumLink\":\"\",\"other\":\"\"}"
            }
        ],
        "metadata": "{\"title\":\"Let's do this thing!\",\"summary\":\"This thing will be great\"}",
        "proposers": [
            "regen1fhjpuh6qh6kjsedtmfxrayvmzlknkzde92ky2j"
        ],
        "status": "PROPOSAL_STATUS_ACCEPTED",
        "submit_time": "2023-07-12T19:32:41.666565Z",
        "voting_period_end": "2023-07-13T19:32:41.666651400Z"
    }
}

Given the group_policy_address above, look up the group_id:

➜  analytics git:(main) ✗ http http://localhost:1317/cosmos/group/v1/group_policy_info/regen13cwsdsetcrhcyd3jeed0mgteg35qaju0q5s0u0drfylagahygwwstgwupv
HTTP/1.1 200 OK
Content-Length: 527
Content-Type: application/json
Date: Thu, 13 Jul 2023 23:58:36 GMT
Grpc-Metadata-Content-Type: application/grpc+cosmos-sdk-grpc-codec
Grpc-Metadata-X-Cosmos-Block-Height: 35227
X-Server-Time: 1689292716
{
    "info": {
        "address": "regen13cwsdsetcrhcyd3jeed0mgteg35qaju0q5s0u0drfylagahygwwstgwupv",
        "admin": "regen13cwsdsetcrhcyd3jeed0mgteg35qaju0q5s0u0drfylagahygwwstgwupv",
        "created_at": "2023-07-12T19:30:59.324475Z",
        "decision_policy": {
            "@type": "/cosmos.group.v1.ThresholdDecisionPolicy",
            "threshold": "1",
            "windows": {
                "min_execution_period": "1.000000001s",
                "voting_period": "86400.000086400s"
            }
        },
        "group_id": "16",
        "metadata": "",
        "version": "2"
    }
}
ryanchristo commented 1 year ago

Closing in favor of using policy addresses.