Rename JSON RPC getLastId to getRecentBlockHash

This commit is contained in:
Michael Vines 2019-03-02 10:12:14 -08:00 committed by Greg Fitzgerald
parent 258cf21416
commit 85159a0eb4
7 changed files with 18 additions and 18 deletions

View File

@ -24,7 +24,7 @@ Methods
* [confirmTransaction](#confirmtransaction)
* [getAccountInfo](#getaccountinfo)
* [getBalance](#getbalance)
* [getLastId](#getlastid)
* [getRecentBlockHash](#getrecentblockhash)
* [getSignatureStatus](#getsignaturestatus)
* [getTransactionCount](#gettransactioncount)
* [requestAirdrop](#requestairdrop)
@ -137,19 +137,19 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "
---
### getLastId
Returns the last entry ID from the ledger
### getRecentBlockHash
Returns a recent block hash from the ledger
##### Parameters:
None
##### Results:
* `string` - the ID of last entry, a Hash as base-58 encoded string
* `string` - a Hash as base-58 encoded string
##### Example:
```bash
// Request
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getLastId"}' http://localhost:8899
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getRecentBlockHash"}' http://localhost:8899
// Result
{"jsonrpc":"2.0","result":"GH7ome3EiwEr7tu9JuTh2dpYWBJK3z69Xm1ZE3MEE6JC","id":1}

View File

@ -155,7 +155,7 @@ pub trait RpcSol {
#[rpc(meta, name = "getBalance")]
fn get_balance(&self, _: Self::Metadata, _: String) -> Result<u64>;
#[rpc(meta, name = "getLastId")]
#[rpc(meta, name = "getRecentBlockHash")]
fn get_recent_block_hash(&self, _: Self::Metadata) -> Result<String>;
#[rpc(meta, name = "getSignatureStatus")]
@ -532,7 +532,7 @@ mod tests {
let bob_pubkey = Keypair::new().pubkey();
let (io, meta, block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getLastId"}}"#);
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getRecentBlockHash"}}"#);
let res = io.handle_request_sync(&req, meta);
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, block_hash);
let expected: Response =

View File

@ -64,7 +64,7 @@ impl MockRpcClient {
let n = if self.addr == "airdrop" { 0 } else { 50 };
Value::Number(Number::from(n))
}
RpcRequest::GetLastId => Value::String(PUBKEY.to_string()),
RpcRequest::GetRecentBlockHash => Value::String(PUBKEY.to_string()),
RpcRequest::GetSignatureStatus => {
let str = if self.addr == "account_in_use" {
"AccountInUse"

View File

@ -129,7 +129,7 @@ pub enum RpcRequest {
ConfirmTransaction,
GetAccountInfo,
GetBalance,
GetLastId,
GetRecentBlockHash,
GetSignatureStatus,
GetTransactionCount,
RequestAirdrop,
@ -149,7 +149,7 @@ impl RpcRequest {
RpcRequest::ConfirmTransaction => "confirmTransaction",
RpcRequest::GetAccountInfo => "getAccountInfo",
RpcRequest::GetBalance => "getBalance",
RpcRequest::GetLastId => "getLastId",
RpcRequest::GetRecentBlockHash => "getRecentBlockHash",
RpcRequest::GetSignatureStatus => "getSignatureStatus",
RpcRequest::GetTransactionCount => "getTransactionCount",
RpcRequest::RequestAirdrop => "requestAirdrop",
@ -217,9 +217,9 @@ mod tests {
let request = test_request.build_request_json(1, Some(addr));
assert_eq!(request["method"], "getBalance");
let test_request = RpcRequest::GetLastId;
let test_request = RpcRequest::GetRecentBlockHash;
let request = test_request.build_request_json(1, None);
assert_eq!(request["method"], "getLastId");
assert_eq!(request["method"], "getRecentBlockHash");
let test_request = RpcRequest::GetTransactionCount;
let request = test_request.build_request_json(1, None);
@ -244,7 +244,7 @@ mod tests {
Ok(Value::Number(Number::from(50)))
});
// Failed request
io.add_method("getLastId", |params: Params| {
io.add_method("getRecentBlockHash", |params: Params| {
if params != Params::None {
Err(Error::invalid_request())
} else {
@ -275,7 +275,7 @@ mod tests {
);
assert_eq!(balance.unwrap().as_u64().unwrap(), 50);
let block_hash = rpc_client.make_rpc_request(2, RpcRequest::GetLastId, None);
let block_hash = rpc_client.make_rpc_request(2, RpcRequest::GetRecentBlockHash, None);
assert_eq!(
block_hash.unwrap().as_str().unwrap(),
"deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"
@ -283,7 +283,7 @@ mod tests {
// Send erroneous parameter
let block_hash =
rpc_client.make_rpc_request(3, RpcRequest::GetLastId, Some(json!("paramter")));
rpc_client.make_rpc_request(3, RpcRequest::GetRecentBlockHash, Some(json!("paramter")));
assert_eq!(block_hash.is_err(), true);
}

View File

@ -222,7 +222,7 @@ impl ThinClient {
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
let response = self
.rpc_client
.make_rpc_request(1, RpcRequest::GetLastId, None);
.make_rpc_request(1, RpcRequest::GetRecentBlockHash, None);
match response {
Ok(value) => {

View File

@ -24,7 +24,7 @@ fn test_rpc_send_tx() {
let request = json!({
"jsonrpc": "2.0",
"id": 1,
"method": "getLastId",
"method": "getRecentBlockHash",
"params": json!([])
});
let rpc_addr = leader_data.rpc;

View File

@ -714,7 +714,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
}
fn get_recent_block_hash(rpc_client: &RpcClient) -> Result<Hash, Box<dyn error::Error>> {
let result = rpc_client.retry_make_rpc_request(1, &RpcRequest::GetLastId, None, 5)?;
let result = rpc_client.retry_make_rpc_request(1, &RpcRequest::GetRecentBlockHash, None, 5)?;
if result.as_str().is_none() {
Err(WalletError::RpcRequestError(
"Received bad block_hash".to_string(),