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

Support the iterate query for statedb #561

Merged
merged 1 commit into from
Aug 3, 2023
Merged

Support the iterate query for statedb #561

merged 1 commit into from
Aug 3, 2023

Conversation

baichuan3
Copy link
Collaborator

resolve #543

Two interfaces listStates and listAnnotatedStates are provided, which support state traversal in the following format:

1. /resource/$account_address
2. /module/$account_address
3. /table/$table_handle

Example 1

curl --location 'http://localhost:50051' \
--header 'Content-Type: application/json' \
--data '{
 "id":101, 
 "jsonrpc":"2.0", 
 "method":"rooch_listStates", 
 "params":["/resource/0xb4321fa441b5d9fdefb71f82856a56447451f7b1ba9478747b07e9f26b34c87",null, 5]
}'
{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "value": "0x0600000000000000",
                "value_type": "0x3::account::Account"
            }
        ],
        "next_cursor": "0x52303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6163636f756e743a3a4163636f756e74",
        "has_next_page": false
    },
    "id": 101
}

Example 2

curl --location 'http://localhost:50051' \
--header 'Content-Type: application/json' \
--data '{
 "id":101, 
 "jsonrpc":"2.0", 
 "method":"rooch_listAnnotatedStates", 
 "params":["/table/0x0", "0xb4598eb64be589838077c1986bf594bbe85439f6519080352481cfeea8e1ae59", 5]
}'
{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "state": {
                    "value": "0x8d60d50ae44f5fccde1501eaec8e5f6e4f30f5bd5065d8de64f1eabb16168c000000000000000000000000000000000000000000000000000000000000000000a6c0ea59f9069fb83ae45db3d4ecbcd6685688d9aef4d3246def59c836082199",
                    "value_type": "0x2::object::Object<0x2::raw_table::TableInfo>"
                },
                "move_value": {
                    "abilities": 0,
                    "type": "0x2::object::Object<0x2::raw_table::TableInfo>",
                    "value": {
                        "id": "0x8d60d50ae44f5fccde1501eaec8e5f6e4f30f5bd5065d8de64f1eabb16168c00",
                        "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
                        "value": {
                            "abilities": 8,
                            "type": "0x2::raw_table::TableInfo",
                            "value": {
                                "state_root": "0xa6c0ea59f9069fb83ae45db3d4ecbcd6685688d9aef4d3246def59c836082199"
                            }
                        }
                    }
                }
            },
            {
                "state": {
                    "value": "0x0b4321fa441b5d9fdefb71f82856a56447451f7b1ba9478747b07e9f26b34c870b4321fa441b5d9fdefb71f82856a56447451f7b1ba9478747b07e9f26b34c878d60d50ae44f5fccde1501eaec8e5f6e4f30f5bd5065d8de64f1eabb16168c00c5530c01a66456c61115b9083c3c717c36e4136211b4067819bd5fd46b3a06a2",
                    "value_type": "0x2::object::Object<0x2::account_storage::AccountStorage>"
                },
                "move_value": {
                    "abilities": 0,
                    "type": "0x2::object::Object<0x2::account_storage::AccountStorage>",
                    "value": {
                        "id": "0x0b4321fa441b5d9fdefb71f82856a56447451f7b1ba9478747b07e9f26b34c87",
                        "owner": "0x0b4321fa441b5d9fdefb71f82856a56447451f7b1ba9478747b07e9f26b34c87",
                        "value": {
                            "abilities": 8,
                            "type": "0x2::account_storage::AccountStorage",
                            "value": {
                                "modules": {
                                    "abilities": 4,
                                    "type": "0x2::table::Table<0x1::string::String, 0x2::move_module::MoveModule>",
                                    "value": {
                                        "handle": "0xc5530c01a66456c61115b9083c3c717c36e4136211b4067819bd5fd46b3a06a2"
                                    }
                                },
                                "resources": {
                                    "abilities": 4,
                                    "type": "0x2::type_table::TypeTable",
                                    "value": {
                                        "handle": "0x8d60d50ae44f5fccde1501eaec8e5f6e4f30f5bd5065d8de64f1eabb16168c00"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            {
                "state": {
                    "value": "0xc5530c01a66456c61115b9083c3c717c36e4136211b4067819bd5fd46b3a06a20000000000000000000000000000000000000000000000000000000000000000453558f5669592b09fb649550dc9f042890786d106751011e274265fe6ed3b60",
                    "value_type": "0x2::object::Object<0x2::raw_table::TableInfo>"
                },
                "move_value": {
                    "abilities": 0,
                    "type": "0x2::object::Object<0x2::raw_table::TableInfo>",
                    "value": {
                        "id": "0xc5530c01a66456c61115b9083c3c717c36e4136211b4067819bd5fd46b3a06a2",
                        "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
                        "value": {
                            "abilities": 8,
                            "type": "0x2::raw_table::TableInfo",
                            "value": {
                                "state_root": "0x453558f5669592b09fb649550dc9f042890786d106751011e274265fe6ed3b60"
                            }
                        }
                    }
                }
            },
            {
                "state": {
                    "value": "0x5d4b9612d5dbe6241ef4fd2b586f25c22df622b7a7968ed959685be7244fb5d300000000000000000000000000000000000000000000000000000000000000004077cbcae38f344a810813a5fefc04d831cde2c87d9fd3634c8e0e04383e0d7f",
                    "value_type": "0x2::object::Object<0x2::raw_table::TableInfo>"
                },
                "move_value": {
                    "abilities": 0,
                    "type": "0x2::object::Object<0x2::raw_table::TableInfo>",
                    "value": {
                        "id": "0x5d4b9612d5dbe6241ef4fd2b586f25c22df622b7a7968ed959685be7244fb5d3",
                        "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
                        "value": {
                            "abilities": 8,
                            "type": "0x2::raw_table::TableInfo",
                            "value": {
                                "state_root": "0x4077cbcae38f344a810813a5fefc04d831cde2c87d9fd3634c8e0e04383e0d7f"
                            }
                        }
                    }
                }
            },
            {
                "state": {
                    "value": "0x96b35fc57863473f588f0320e7c69c639374ec5f9f3900fc60e3a77ee7657ed100000000000000000000000000000000000000000000000000000000000000007cab03bf41f22faa6db9b261299f361c6005916de5dfb140f56cb6cfaafd1392",
                    "value_type": "0x2::object::Object<0x2::raw_table::TableInfo>"
                },
                "move_value": {
                    "abilities": 0,
                    "type": "0x2::object::Object<0x2::raw_table::TableInfo>",
                    "value": {
                        "id": "0x96b35fc57863473f588f0320e7c69c639374ec5f9f3900fc60e3a77ee7657ed1",
                        "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
                        "value": {
                            "abilities": 8,
                            "type": "0x2::raw_table::TableInfo",
                            "value": {
                                "state_root": "0x7cab03bf41f22faa6db9b261299f361c6005916de5dfb140f56cb6cfaafd1392"
                            }
                        }
                    }
                }
            }
        ],
        "next_cursor": "0x96b35fc57863473f588f0320e7c69c639374ec5f9f3900fc60e3a77ee7657ed1",
        "has_next_page": true
    },
    "id": 101
}

@vercel
Copy link

vercel bot commented Aug 2, 2023

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

1 Ignored Deployment
Name Status Preview Updated (UTC)
rooch ⬜️ Ignored (Inspect) Aug 2, 2023 3:16pm

/// 2. /module/$account_address
/// 3. /table/$table_handle
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AccessPathList(pub PathList);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about directly use the AccessPath? AccessPathList = AccessPath without keys.

Copy link
Contributor

@jolestar jolestar left a comment

Choose a reason for hiding this comment

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

We can merge this first and do refactor later.

@@ -144,6 +144,25 @@ where
}
}

/// List the (key, value) from the tree.
pub fn list(&self, starting_key: Option<K>, limit: usize) -> Result<Vec<Option<(K, V)>>> {
let mut iter = self.iter(starting_key.clone()).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not unwrap here.

@baichuan3
Copy link
Collaborator Author

We can merge this first and do refactor later.

ok

@baichuan3 baichuan3 merged commit 9f5e5c5 into main Aug 3, 2023
3 checks passed
@baichuan3 baichuan3 deleted the state_iterate branch August 3, 2023 03:08
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.

[Statedb] Support the iterate query for statedb
2 participants