Rename JSON RPC getLastId to getRecentBlockHash
This commit is contained in:
committed by
Greg Fitzgerald
parent
258cf21416
commit
85159a0eb4
@ -24,7 +24,7 @@ Methods
|
|||||||
* [confirmTransaction](#confirmtransaction)
|
* [confirmTransaction](#confirmtransaction)
|
||||||
* [getAccountInfo](#getaccountinfo)
|
* [getAccountInfo](#getaccountinfo)
|
||||||
* [getBalance](#getbalance)
|
* [getBalance](#getbalance)
|
||||||
* [getLastId](#getlastid)
|
* [getRecentBlockHash](#getrecentblockhash)
|
||||||
* [getSignatureStatus](#getsignaturestatus)
|
* [getSignatureStatus](#getsignaturestatus)
|
||||||
* [getTransactionCount](#gettransactioncount)
|
* [getTransactionCount](#gettransactioncount)
|
||||||
* [requestAirdrop](#requestairdrop)
|
* [requestAirdrop](#requestairdrop)
|
||||||
@ -137,19 +137,19 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### getLastId
|
### getRecentBlockHash
|
||||||
Returns the last entry ID from the ledger
|
Returns a recent block hash from the ledger
|
||||||
|
|
||||||
##### Parameters:
|
##### Parameters:
|
||||||
None
|
None
|
||||||
|
|
||||||
##### Results:
|
##### Results:
|
||||||
* `string` - the ID of last entry, a Hash as base-58 encoded string
|
* `string` - a Hash as base-58 encoded string
|
||||||
|
|
||||||
##### Example:
|
##### Example:
|
||||||
```bash
|
```bash
|
||||||
// Request
|
// 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
|
// Result
|
||||||
{"jsonrpc":"2.0","result":"GH7ome3EiwEr7tu9JuTh2dpYWBJK3z69Xm1ZE3MEE6JC","id":1}
|
{"jsonrpc":"2.0","result":"GH7ome3EiwEr7tu9JuTh2dpYWBJK3z69Xm1ZE3MEE6JC","id":1}
|
||||||
|
@ -155,7 +155,7 @@ pub trait RpcSol {
|
|||||||
#[rpc(meta, name = "getBalance")]
|
#[rpc(meta, name = "getBalance")]
|
||||||
fn get_balance(&self, _: Self::Metadata, _: String) -> Result<u64>;
|
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>;
|
fn get_recent_block_hash(&self, _: Self::Metadata) -> Result<String>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getSignatureStatus")]
|
#[rpc(meta, name = "getSignatureStatus")]
|
||||||
@ -532,7 +532,7 @@ mod tests {
|
|||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, block_hash, _alice) = start_rpc_handler_with_tx(bob_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 res = io.handle_request_sync(&req, meta);
|
||||||
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, block_hash);
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, block_hash);
|
||||||
let expected: Response =
|
let expected: Response =
|
||||||
|
@ -64,7 +64,7 @@ impl MockRpcClient {
|
|||||||
let n = if self.addr == "airdrop" { 0 } else { 50 };
|
let n = if self.addr == "airdrop" { 0 } else { 50 };
|
||||||
Value::Number(Number::from(n))
|
Value::Number(Number::from(n))
|
||||||
}
|
}
|
||||||
RpcRequest::GetLastId => Value::String(PUBKEY.to_string()),
|
RpcRequest::GetRecentBlockHash => Value::String(PUBKEY.to_string()),
|
||||||
RpcRequest::GetSignatureStatus => {
|
RpcRequest::GetSignatureStatus => {
|
||||||
let str = if self.addr == "account_in_use" {
|
let str = if self.addr == "account_in_use" {
|
||||||
"AccountInUse"
|
"AccountInUse"
|
||||||
|
@ -129,7 +129,7 @@ pub enum RpcRequest {
|
|||||||
ConfirmTransaction,
|
ConfirmTransaction,
|
||||||
GetAccountInfo,
|
GetAccountInfo,
|
||||||
GetBalance,
|
GetBalance,
|
||||||
GetLastId,
|
GetRecentBlockHash,
|
||||||
GetSignatureStatus,
|
GetSignatureStatus,
|
||||||
GetTransactionCount,
|
GetTransactionCount,
|
||||||
RequestAirdrop,
|
RequestAirdrop,
|
||||||
@ -149,7 +149,7 @@ impl RpcRequest {
|
|||||||
RpcRequest::ConfirmTransaction => "confirmTransaction",
|
RpcRequest::ConfirmTransaction => "confirmTransaction",
|
||||||
RpcRequest::GetAccountInfo => "getAccountInfo",
|
RpcRequest::GetAccountInfo => "getAccountInfo",
|
||||||
RpcRequest::GetBalance => "getBalance",
|
RpcRequest::GetBalance => "getBalance",
|
||||||
RpcRequest::GetLastId => "getLastId",
|
RpcRequest::GetRecentBlockHash => "getRecentBlockHash",
|
||||||
RpcRequest::GetSignatureStatus => "getSignatureStatus",
|
RpcRequest::GetSignatureStatus => "getSignatureStatus",
|
||||||
RpcRequest::GetTransactionCount => "getTransactionCount",
|
RpcRequest::GetTransactionCount => "getTransactionCount",
|
||||||
RpcRequest::RequestAirdrop => "requestAirdrop",
|
RpcRequest::RequestAirdrop => "requestAirdrop",
|
||||||
@ -217,9 +217,9 @@ mod tests {
|
|||||||
let request = test_request.build_request_json(1, Some(addr));
|
let request = test_request.build_request_json(1, Some(addr));
|
||||||
assert_eq!(request["method"], "getBalance");
|
assert_eq!(request["method"], "getBalance");
|
||||||
|
|
||||||
let test_request = RpcRequest::GetLastId;
|
let test_request = RpcRequest::GetRecentBlockHash;
|
||||||
let request = test_request.build_request_json(1, None);
|
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 test_request = RpcRequest::GetTransactionCount;
|
||||||
let request = test_request.build_request_json(1, None);
|
let request = test_request.build_request_json(1, None);
|
||||||
@ -244,7 +244,7 @@ mod tests {
|
|||||||
Ok(Value::Number(Number::from(50)))
|
Ok(Value::Number(Number::from(50)))
|
||||||
});
|
});
|
||||||
// Failed request
|
// Failed request
|
||||||
io.add_method("getLastId", |params: Params| {
|
io.add_method("getRecentBlockHash", |params: Params| {
|
||||||
if params != Params::None {
|
if params != Params::None {
|
||||||
Err(Error::invalid_request())
|
Err(Error::invalid_request())
|
||||||
} else {
|
} else {
|
||||||
@ -275,7 +275,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(balance.unwrap().as_u64().unwrap(), 50);
|
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!(
|
assert_eq!(
|
||||||
block_hash.unwrap().as_str().unwrap(),
|
block_hash.unwrap().as_str().unwrap(),
|
||||||
"deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"
|
"deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"
|
||||||
@ -283,7 +283,7 @@ mod tests {
|
|||||||
|
|
||||||
// Send erroneous parameter
|
// Send erroneous parameter
|
||||||
let block_hash =
|
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);
|
assert_eq!(block_hash.is_err(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ impl ThinClient {
|
|||||||
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
|
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
|
||||||
let response = self
|
let response = self
|
||||||
.rpc_client
|
.rpc_client
|
||||||
.make_rpc_request(1, RpcRequest::GetLastId, None);
|
.make_rpc_request(1, RpcRequest::GetRecentBlockHash, None);
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
|
@ -24,7 +24,7 @@ fn test_rpc_send_tx() {
|
|||||||
let request = json!({
|
let request = json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"method": "getLastId",
|
"method": "getRecentBlockHash",
|
||||||
"params": json!([])
|
"params": json!([])
|
||||||
});
|
});
|
||||||
let rpc_addr = leader_data.rpc;
|
let rpc_addr = leader_data.rpc;
|
||||||
|
@ -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>> {
|
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() {
|
if result.as_str().is_none() {
|
||||||
Err(WalletError::RpcRequestError(
|
Err(WalletError::RpcRequestError(
|
||||||
"Received bad block_hash".to_string(),
|
"Received bad block_hash".to_string(),
|
||||||
|
Reference in New Issue
Block a user