Skip to content

Commit 60374db

Browse files
committed
apply
1 parent 188fbf4 commit 60374db

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

books/user/src/rpc.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This section contains the development status of endpoints/methods in `cuprated`.
1414
|--------|---------|
1515
| 🟢 | Enabled and tested
1616
| 🟣 | Enabled but has differences waiting to be resolved
17-
| 🟠 | Enabled but not tested
17+
| 🟠 | Enabled but not fully tested
1818
| ⚪ | Not enabled yet
1919
| ⚫ | Not planned to be supported
2020

@@ -31,11 +31,11 @@ This section contains the development status of endpoints/methods in `cuprated`.
3131
| `generateblocks` ||
3232
| `get_alternate_chains` ||
3333
| `get_bans` ||
34-
| `get_block` | |
35-
| `get_block_count` | |
36-
| `get_block_header_by_hash` | |
37-
| `get_block_header_by_height` | |
38-
| `get_block_headers_range` | |
34+
| `get_block` | 🟠 |
35+
| `get_block_count` | 🟠 |
36+
| `get_block_header_by_hash` | 🟠 |
37+
| `get_block_header_by_height` | 🟠 |
38+
| `get_block_headers_range` | 🟠 |
3939
| `get_block_template` ||
4040
| `get_coinbase_tx_sum` ||
4141
| `get_connections` ||
@@ -48,8 +48,8 @@ This section contains the development status of endpoints/methods in `cuprated`.
4848
| `get_tx_ids_loose` | ⚪ | Not implemented in `monerod` release branch yet
4949
| `get_txpool_backlog` ||
5050
| `get_version` ||
51-
| `hard_fork_info` | |
52-
| `on_get_block_hash` | |
51+
| `hard_fork_info` | 🟠 |
52+
| `on_get_block_hash` | 🟠 |
5353
| `prune_blockchain` ||
5454
| `relay_tx` ||
5555
| `set_bans` ||
@@ -60,7 +60,7 @@ This section contains the development status of endpoints/methods in `cuprated`.
6060
| Endpoint | Status | Notes |
6161
|--------------------------------|--------|---------|
6262
| `/get_alt_blocks_hashes` ||
63-
| `/get_height` | |
63+
| `/get_height` | 🟠 |
6464
| `/get_limit` ||
6565
| `/get_net_stats` ||
6666
| `/get_outs` ||

storage/blockchain/src/service/read.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::{
1717
};
1818

1919
use indexmap::{IndexMap, IndexSet};
20+
use monero_serai::block::Block;
2021
use rayon::{
2122
iter::{Either, IntoParallelIterator, ParallelIterator},
2223
prelude::*,
@@ -54,8 +55,8 @@ use crate::{
5455
types::{BlockchainReadHandle, ResponseResult},
5556
},
5657
tables::{
57-
AltBlockHeights, BlockHeights, BlockInfos, OpenTables, RctOutputs, Tables, TablesIter,
58-
TxIds, TxOutputs,
58+
AltBlockHeights, BlockHeaderBlobs, BlockHeights, BlockInfos, OpenTables, RctOutputs,
59+
Tables, TablesIter, TxIds, TxOutputs,
5960
},
6061
types::{
6162
AltBlockHeight, Amount, AmountIndex, BlockHash, BlockHeight, KeyImage, PreRctOutputId,
@@ -888,11 +889,31 @@ fn alt_blocks_in_chain(env: &ConcreteEnv, chain_id: ChainId) -> ResponseResult {
888889

889890
/// [`BlockchainReadRequest::Block`]
890891
fn block(env: &ConcreteEnv, block_height: BlockHeight) -> ResponseResult {
891-
Ok(BlockchainResponse::Block(todo!()))
892+
// Single-threaded, no `ThreadLocal` required.
893+
let env_inner = env.env_inner();
894+
let tx_ro = env_inner.tx_ro()?;
895+
896+
let block_blob = env_inner
897+
.open_db_ro::<BlockHeaderBlobs>(&tx_ro)?
898+
.get(&block_height)?;
899+
900+
let block = Block::read(&mut block_blob.0.as_slice())?;
901+
902+
Ok(BlockchainResponse::Block(block))
892903
}
893904

894905
/// [`BlockchainReadRequest::BlockByHash`]
895906
fn block_by_hash(env: &ConcreteEnv, block_hash: BlockHash) -> ResponseResult {
907+
// Single-threaded, no `ThreadLocal` required.
908+
let env_inner = env.env_inner();
909+
let tx_ro = env_inner.tx_ro()?;
910+
911+
let tables = env_inner.open_tables(&tx_ro)?;
912+
let block_height = tables.block_heights().get(&block_hash)?;
913+
let block_blob = tables.block_header_blobs().get(&block_height)?;
914+
915+
let block = Block::read(&mut block_blob.0.as_slice())?;
916+
896917
Ok(BlockchainResponse::Block(todo!()))
897918
}
898919

0 commit comments

Comments
 (0)