rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

[Indexer] Provide state indexer RPC #1216

Closed baichuan3 closed 5 months ago

baichuan3 commented 5 months ago

Summary

Provide state indexer RPC for query table object and struct object.

  1. Implements state RPC pagination based on tx_order and state index.
  2. Refactor and simple indexer state write.
  3. Rename leaf_states to table_states for more appropriate state storage abstraction.
  4. Object_type is added to the global state table to implement query and filtering scenarios based on object_type, such as querying CoinInfo and CoinStore. Among them, object_type is the Struct Tag type of Object without generic parameters.
vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **rooch** | ⬜️ Ignored ([Inspect](https://vercel.com/rooch/rooch/7uZHqeeDW3mV8Hj4rDTfWd1AyJUR)) | [Visit Preview](https://rooch-git-stateindexerrpc-rooch.vercel.app) | | Dec 7, 2023 1:10pm |
baichuan3 commented 5 months ago
  1. List Object by owner
    curl --location 'http://localhost:50051' \
    --header 'Content-Type: application/json' \
    --data '{
    "id": 101,
    "jsonrpc": "2.0",
    "method": "rooch_queryGlobalStates",
    "params": [
        {"object_type_with_owner":{"object_type":"0x3::coin_store::CoinStore","owner":"0x4b1b5d2a62f3c9a19a5314167439945bf98fbc871e1402e36d5bad3382064c56"}}, null, "3", true
    ]
    }'
{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "object_id": "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd5764",
                "owner": "0x4b1b5d2a62f3c9a19a5314167439945bf98fbc871e1402e36d5bad3382064c56",
                "flag": 0,
                "value": {
                    "abilities": 8,
                    "type": "0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>",
                    "value": {
                        "balance": {
                            "abilities": 4,
                            "type": "0x3::coin_store::Balance",
                            "value": {
                                "value": "99999999999998196677"
                            }
                        },
                        "coin_type": "0000000000000000000000000000000000000000000000000000000000000003::gas_coin::GasCoin",
                        "frozen": false
                    }
                },
                "object_type": "0x3::coin_store::CoinStore",
                "key_type": null,
                "size": 0,
                "tx_order": 3,
                "state_index": 1,
                "created_at": 0,
                "updated_at": 0
            }
        ],
        "next_cursor": {
            "tx_order": 3,
            "state_index": 1
        },
        "has_next_page": false
    },
    "id": 101
}
  1. List All CoinInfo
    curl --location 'http://localhost:50051' \
    --header 'Content-Type: application/json' \
    --data '{
    "id": 101,
    "jsonrpc": "2.0",
    "method": "rooch_queryGlobalStates",
    "params": [
        {"object_type":"0x3::coin::CoinInfo"}, null, "3", true
    ]
    }'
{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "object_id": "0xf81628c3bf85c3fc628f29a3739365d4428101fbbecca0dcc7e3851f34faea6b",
                "owner": "0x0000000000000000000000000000000000000000000000000000000000000003",
                "flag": 0,
                "value": {
                    "abilities": 12,
                    "type": "0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>",
                    "value": {
                        "coin_type": "0000000000000000000000000000000000000000000000000000000000000003::gas_coin::GasCoin",
                        "decimals": 18,
                        "name": "Rooch Gas Coin",
                        "supply": "100000000000000000000",
                        "symbol": "RGC"
                    }
                },
                "object_type": "0x3::coin::CoinInfo",
                "key_type": null,
                "size": 0,
                "tx_order": 0,
                "state_index": 3,
                "created_at": 0,
                "updated_at": 0
            }
        ],
        "next_cursor": {
            "tx_order": 0,
            "state_index": 3
        },
        "has_next_page": false
    },
    "id": 101
}
  1. List Table key/value by updating timestamp desc order
    curl --location 'http://localhost:50051' \
    --header 'Content-Type: application/json' \
    --data '{
    "id": 101,
    "jsonrpc": "2.0",
    "method": "rooch_queryTableStates",
    "params": [
        {"table_handle":"0x447c72e15e318ef69ef0de731754a97120e4f1448a127bae8f82ef7000ffb1a3"}, null, "3", true
    ]
    }'
{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "table_handle": "0x447c72e15e318ef69ef0de731754a97120e4f1448a127bae8f82ef7000ffb1a3",
                "key_hex": "0x52303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6163636f756e743a3a4163636f756e74",
                "value": {
                    "abilities": 12,
                    "type": "0x3::account::Account",
                    "value": {
                        "sequence_number": "4"
                    }
                },
                "value_type": "0x3::account::Account",
                "tx_order": 3,
                "state_index": 2,
                "created_at": 0,
                "updated_at": 0
            },
            {
                "table_handle": "0x447c72e15e318ef69ef0de731754a97120e4f1448a127bae8f82ef7000ffb1a3",
                "key_hex": "0x6c303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6163636f756e745f61757468656e7469636174696f6e3a3a41757468656e7469636174696f6e4b657973",
                "value": {
                    "abilities": 8,
                    "type": "0x3::account_authentication::AuthenticationKeys",
                    "value": {
                        "authentication_keys": {
                            "abilities": 4,
                            "type": "0x2::type_table::TypeTable",
                            "value": {
                                "handle": "0xa8b28ae0a36c51f6998eec632eb3b75777f49ae312cc0c17d75f20f61fb47135"
                            }
                        }
                    }
                },
                "value_type": "0x3::account_authentication::AuthenticationKeys",
                "tx_order": 0,
                "state_index": 6,
                "created_at": 0,
                "updated_at": 0
            },
            {
                "table_handle": "0x447c72e15e318ef69ef0de731754a97120e4f1448a127bae8f82ef7000ffb1a3",
                "key_hex": "0x60303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6163636f756e745f636f696e5f73746f72653a3a436f696e53746f726573",
                "value": {
                    "abilities": 8,
                    "type": "0x3::account_coin_store::CoinStores",
                    "value": {
                        "coin_stores": {
                            "abilities": 4,
                            "type": "0x2::table::Table<0x1::string::String, 0x2::object::ObjectID>",
                            "value": {
                                "handle": "0xad7d15099438f06bc6e5954089b798d6ebd4a8cf8d2201e29a7872e0a11fff93"
                            }
                        }
                    }
                },
                "value_type": "0x3::account_coin_store::CoinStores",
                "tx_order": 0,
                "state_index": 5,
                "created_at": 0,
                "updated_at": 0
            }
        ],
        "next_cursor": {
            "tx_order": 0,
            "state_index": 5
        },
        "has_next_page": false
    },
    "id": 101
}
  1. Sync state change set by table handle
    curl --location 'http://localhost:50051' \
    --header 'Content-Type: application/json' \
    --data '{
    "id": 101,
    "jsonrpc": "2.0",
    "method": "rooch_syncStates",
    "params": [
        {"table_handle":"0x0"}, null, "3", true
    ]
    }'
{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "tx_order": 3,
                "state_index": 0,
                "table_handle": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "table_change_set": {
                    "new_tables": {},
                    "removed_tables": [],
                    "changes": {
                        "0x0000000000000000000000000000000000000000000000000000000000000000": {
                            "entries": {
                                "0x984fb796e86ce1592bb9794eeca31766de0bdcbf66ba9ee07381c9469a122aa4": {
                                    "type": "modify",
                                    "value": "0x984fb796e86ce1592bb9794eeca31766de0bdcbf66ba9ee07381c9469a122aa400000000000000000000000000000000000000000000000000000000000000000053303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696e3b841b000000000000000000000000000000000000000000000000000000000000",
                                    "value_type": "0x2::object::ObjectEntity<0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>>",
                                    "decoded_value": null
                                },
                                "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd5764": {
                                    "type": "modify",
                                    "value": "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd57644b1b5d2a62f3c9a19a5314167439945bf98fbc871e1402e36d5bad3382064c560053303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696ec57bf4622d5ec76b05000000000000000000000000000000000000000000000000",
                                    "value_type": "0x2::object::ObjectEntity<0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>>",
                                    "decoded_value": null
                                }
                            },
                            "size_increment": 0
                        }
                    }
                },
                "created_at": 0
            },
            {
                "tx_order": 2,
                "state_index": 0,
                "table_handle": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "table_change_set": {
                    "new_tables": {},
                    "removed_tables": [],
                    "changes": {
                        "0x0000000000000000000000000000000000000000000000000000000000000000": {
                            "entries": {
                                "0x984fb796e86ce1592bb9794eeca31766de0bdcbf66ba9ee07381c9469a122aa4": {
                                    "type": "modify",
                                    "value": "0x984fb796e86ce1592bb9794eeca31766de0bdcbf66ba9ee07381c9469a122aa400000000000000000000000000000000000000000000000000000000000000000053303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696ed64d1b000000000000000000000000000000000000000000000000000000000000",
                                    "value_type": "0x2::object::ObjectEntity<0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>>",
                                    "decoded_value": null
                                },
                                "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd5764": {
                                    "type": "modify",
                                    "value": "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd57644b1b5d2a62f3c9a19a5314167439945bf98fbc871e1402e36d5bad3382064c560053303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696e2ab2f4622d5ec76b05000000000000000000000000000000000000000000000000",
                                    "value_type": "0x2::object::ObjectEntity<0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>>",
                                    "decoded_value": null
                                }
                            },
                            "size_increment": 0
                        }
                    }
                },
                "created_at": 0
            },
            {
                "tx_order": 1,
                "state_index": 0,
                "table_handle": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "table_change_set": {
                    "new_tables": {},
                    "removed_tables": [],
                    "changes": {
                        "0x0000000000000000000000000000000000000000000000000000000000000000": {
                            "entries": {
                                "0x984fb796e86ce1592bb9794eeca31766de0bdcbf66ba9ee07381c9469a122aa4": {
                                    "type": "modify",
                                    "value": "0x984fb796e86ce1592bb9794eeca31766de0bdcbf66ba9ee07381c9469a122aa400000000000000000000000000000000000000000000000000000000000000000053303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696e71171b000000000000000000000000000000000000000000000000000000000000",
                                    "value_type": "0x2::object::ObjectEntity<0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>>",
                                    "decoded_value": null
                                },
                                "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd5764": {
                                    "type": "modify",
                                    "value": "0x9fdf6a44e40e34899dca64cddf78a4f8896e82d9b3b52d8c3757e193a2dd57644b1b5d2a62f3c9a19a5314167439945bf98fbc871e1402e36d5bad3382064c560053303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696e8fe8f4622d5ec76b05000000000000000000000000000000000000000000000000",
                                    "value_type": "0x2::object::ObjectEntity<0x3::coin_store::CoinStore<0x3::gas_coin::GasCoin>>",
                                    "decoded_value": null
                                }
                            },
                            "size_increment": 0
                        }
                    }
                },
                "created_at": 0
            }
        ],
        "next_cursor": {
            "tx_order": 1,
            "state_index": 0
        },
        "has_next_page": true
    },
    "id": 101
}
baichuan3 commented 5 months ago

Wait merge for checking SQLite Schema compatibility at startup

baichuan3 commented 5 months ago

Wait merge for checking SQLite Schema compatibility at startup

Research the Diesel SQLite update Schema solution and determined that schema changes are still done using DDL. In this case, this current PR solves the schema change problem by manually cleaning the database file to make the schema simple, and subsequent versions use DDL updates to solve the schema change problem.

This PR merge requires @yourmoonlight execution of dev seed node rooch server clean -n dev For local dev clean data using rooch server clean -n local.

jolestar commented 5 months ago

@geometryolife Now; we can get object ID by the rooch_queryGlobalStates and do not need to emit the ObjectID by events.