| 284 | } |
| 285 | |
| 286 | void set_table(unsigned char const table_id) |
| 287 | { |
| 288 | if (state != DbState::proposal_or_finalize) { |
| 289 | fmt::println("Error: at wrong part of trie, only allow set table " |
| 290 | "when cursor is set to a specific version number."); |
| 291 | return; |
| 292 | } |
| 293 | MONAD_ASSERT(curr_section_prefix.nibble_size() > 0); |
| 294 | |
| 295 | if (table_id == STATE_NIBBLE || table_id == CODE_NIBBLE || |
| 296 | table_id == RECEIPT_NIBBLE) { |
| 297 | fmt::println( |
| 298 | "Setting cursor to version {}, table {} ...", |
| 299 | curr_version, |
| 300 | table_as_string(table_id)); |
| 301 | auto const res = |
| 302 | db.find(concat(curr_section_prefix, table_id), curr_version); |
| 303 | if (res.has_value()) { |
| 304 | NodeCursor const cursor = res.assume_value(); |
| 305 | state = DbState::table; |
| 306 | curr_table_id = table_id; |
| 307 | if (curr_table_id != CODE_NIBBLE) { |
| 308 | bytes32_t merkle_root = cursor.node->data().empty() |
| 309 | ? NULL_ROOT |
| 310 | : to_bytes(cursor.node->data()); |
| 311 | fmt::println(" * Merkle root is {}", merkle_root); |
| 312 | } |
| 313 | fmt::println(" * \"node_stats\" will display a summary of node " |
| 314 | "metadata"); |
| 315 | fmt::println(" * Next, try look up a key in this table using " |
| 316 | "\"get [key]\""); |
| 317 | } |
| 318 | else { |
| 319 | fmt::println( |
| 320 | "Couldn't find root node for {} -- {}", |
| 321 | table_as_string(table_id), |
| 322 | res.error().message().c_str()); |
| 323 | } |
| 324 | } |
| 325 | else { |
| 326 | fmt::println("Invalid table id: choose table id from 0: state, " |
| 327 | "1: code, 2: receipt."); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | Result<NodeCursor> lookup(NibblesView const key) const |
| 332 | { |