diff --git a/book/src/jsonrpc-api.md b/book/src/jsonrpc-api.md index 74e24a588..7382d9065 100644 --- a/book/src/jsonrpc-api.md +++ b/book/src/jsonrpc-api.md @@ -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} diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 8279c3509..878c6390c 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -155,7 +155,7 @@ pub trait RpcSol { #[rpc(meta, name = "getBalance")] fn get_balance(&self, _: Self::Metadata, _: String) -> Result; - #[rpc(meta, name = "getLastId")] + #[rpc(meta, name = "getRecentBlockHash")] fn get_recent_block_hash(&self, _: Self::Metadata) -> Result; #[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 = diff --git a/core/src/rpc_mock.rs b/core/src/rpc_mock.rs index 89236aaaa..f50d10bab 100644 --- a/core/src/rpc_mock.rs +++ b/core/src/rpc_mock.rs @@ -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" diff --git a/core/src/rpc_request.rs b/core/src/rpc_request.rs index 496cc1cff..8625014a0 100644 --- a/core/src/rpc_request.rs +++ b/core/src/rpc_request.rs @@ -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); } diff --git a/core/src/thin_client.rs b/core/src/thin_client.rs index 316c2a7d4..7c5d2eaf4 100644 --- a/core/src/thin_client.rs +++ b/core/src/thin_client.rs @@ -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) => { diff --git a/tests/rpc.rs b/tests/rpc.rs index 5e4841f58..02177a682 100644 --- a/tests/rpc.rs +++ b/tests/rpc.rs @@ -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; diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 26de63244..b067fb0ec 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -714,7 +714,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { } fn get_recent_block_hash(rpc_client: &RpcClient) -> Result> { - 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(),