fix(rpc): Accept HashOrHeight as first parameter of getblock and update README.md to note differences between lightwalletd forks (#5861)
* updates getblock RPC to accept HashOrHeight param * update README.md to recommend lightwalletd fork * updates vectors test * Update README.md * Update README.md Co-authored-by: teor <teor@riseup.net> Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
parent
4fb2417adc
commit
f3366c53c7
|
@ -120,6 +120,14 @@ listen_addr = '127.0.0.1:8232'
|
|||
parallel_cpu_threads = 0
|
||||
```
|
||||
|
||||
It is recommended to use [adityapk00/lightwalletd](https://github.com/adityapk00/lightwalletd) because that is used in testing.
|
||||
|
||||
If using [zcash/lightwalletd](https://github.com/zcash/lightwalletd.git):
|
||||
- note that it will require a zcash.conf file:
|
||||
- `rpcuser` and `rpcpassword` are required by `lightwalletd`, but Zebra ignores them if it receives them from `lightwalletd`
|
||||
- when using a non-default port, use `rpcport=28232` and `rpcbind=127.0.0.1`
|
||||
- when using testnet, use `testnet=1`
|
||||
|
||||
**WARNING:** This config allows multiple Zebra instances to share the same RPC port.
|
||||
See the [RPC config documentation](https://doc.zebra.zfnd.org/zebra_rpc/config/struct.Config.html) for details.
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ use zebra_chain::{
|
|||
};
|
||||
use zebra_network::constants::USER_AGENT;
|
||||
use zebra_node_services::mempool;
|
||||
use zebra_state::{OutputIndex, OutputLocation, TransactionLocation};
|
||||
use zebra_state::{HashOrHeight, OutputIndex, OutputLocation, TransactionLocation};
|
||||
|
||||
use crate::queue::Queue;
|
||||
|
||||
|
@ -562,18 +562,21 @@ where
|
|||
// - use `height_from_signed_int()` to handle negative heights
|
||||
// (this might be better in the state request, because it needs the state height)
|
||||
// - create a function that handles block hashes or heights, and use it in `z_get_treestate()`
|
||||
fn get_block(&self, height: String, verbosity: u8) -> BoxFuture<Result<GetBlock>> {
|
||||
fn get_block(&self, hash_or_height: String, verbosity: u8) -> BoxFuture<Result<GetBlock>> {
|
||||
let mut state = self.state.clone();
|
||||
|
||||
async move {
|
||||
let height: Height = height.parse().map_err(|error: SerializationError| Error {
|
||||
code: ErrorCode::ServerError(0),
|
||||
message: error.to_string(),
|
||||
data: None,
|
||||
})?;
|
||||
let hash_or_height: HashOrHeight =
|
||||
hash_or_height
|
||||
.parse()
|
||||
.map_err(|error: SerializationError| Error {
|
||||
code: ErrorCode::ServerError(0),
|
||||
message: error.to_string(),
|
||||
data: None,
|
||||
})?;
|
||||
|
||||
if verbosity == 0 {
|
||||
let request = zebra_state::ReadRequest::Block(height.into());
|
||||
let request = zebra_state::ReadRequest::Block(hash_or_height);
|
||||
let response = state
|
||||
.ready()
|
||||
.and_then(|service| service.call(request))
|
||||
|
@ -596,7 +599,7 @@ where
|
|||
_ => unreachable!("unmatched response to a block request"),
|
||||
}
|
||||
} else if verbosity == 1 {
|
||||
let request = zebra_state::ReadRequest::TransactionIdsForBlock(height.into());
|
||||
let request = zebra_state::ReadRequest::TransactionIdsForBlock(hash_or_height);
|
||||
let response = state
|
||||
.ready()
|
||||
.and_then(|service| service.call(request))
|
||||
|
|
|
@ -82,12 +82,21 @@ async fn rpc_getblock() {
|
|||
|
||||
// Make calls with verbosity=0 and check response
|
||||
for (i, block) in blocks.iter().enumerate() {
|
||||
let expected_result = GetBlock::Raw(block.clone().into());
|
||||
|
||||
let get_block = rpc
|
||||
.get_block(i.to_string(), 0u8)
|
||||
.await
|
||||
.expect("We should have a GetBlock struct");
|
||||
|
||||
assert_eq!(get_block, GetBlock::Raw(block.clone().into()));
|
||||
assert_eq!(get_block, expected_result);
|
||||
|
||||
let get_block = rpc
|
||||
.get_block(block.hash().to_string(), 0u8)
|
||||
.await
|
||||
.expect("We should have a GetBlock struct");
|
||||
|
||||
assert_eq!(get_block, expected_result);
|
||||
}
|
||||
|
||||
// Make calls with verbosity=1 and check response
|
||||
|
|
Loading…
Reference in New Issue