Add getConfirmedSignaturesForAddress2 RPC method (bp #11259) (#11394)

* Add getConfirmedSignaturesForAddress2 RPC method

(cherry picked from commit 1b2276520b)

* Reimplement transaction-history command with getConfirmedSignaturesForAddress2

(cherry picked from commit 087fd32ce3)

* Rework get_confirmed_signatures_for_address2

(cherry picked from commit a11f137810)

* Rename startAfter to before

(cherry picked from commit 02c0981ecf)

Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2020-08-05 22:47:50 +00:00
committed by GitHub
parent df820ddb6d
commit 888f3522d8
10 changed files with 515 additions and 61 deletions

View File

@@ -17,6 +17,7 @@ use solana_client::{
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
rpc_request::{
TokenAccountsFilter, DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_BLOCKS_RANGE,
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT,
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, NUM_LARGEST_ACCOUNTS,
},
@@ -770,6 +771,35 @@ impl JsonRpcRequestProcessor {
}
}
pub fn get_confirmed_signatures_for_address2(
&self,
address: Pubkey,
before: Option<Signature>,
limit: usize,
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>> {
if self.config.enable_rpc_transaction_history {
let highest_confirmed_root = self
.block_commitment_cache
.read()
.unwrap()
.highest_confirmed_root();
let results = self
.blockstore
.get_confirmed_signatures_for_address2(
address,
highest_confirmed_root,
before,
limit,
)
.map_err(|err| Error::invalid_params(format!("{}", err)))?;
Ok(results.into_iter().map(|x| x.into()).collect())
} else {
Ok(vec![])
}
}
pub fn get_first_available_block(&self) -> Slot {
self.blockstore
.get_first_available_block()
@@ -1406,6 +1436,14 @@ pub trait RpcSol {
end_slot: Slot,
) -> Result<Vec<String>>;
#[rpc(meta, name = "getConfirmedSignaturesForAddress2")]
fn get_confirmed_signatures_for_address2(
&self,
meta: Self::Metadata,
address: String,
config: Option<RpcGetConfirmedSignaturesForAddress2Config>,
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>>;
#[rpc(meta, name = "getFirstAvailableBlock")]
fn get_first_available_block(&self, meta: Self::Metadata) -> Result<Slot>;
@@ -2036,6 +2074,34 @@ impl RpcSol for RpcSolImpl {
.collect())
}
fn get_confirmed_signatures_for_address2(
&self,
meta: Self::Metadata,
address: String,
config: Option<RpcGetConfirmedSignaturesForAddress2Config>,
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>> {
let address = verify_pubkey(address)?;
let config = config.unwrap_or_default();
let before = if let Some(before) = config.before {
Some(verify_signature(&before)?)
} else {
None
};
let limit = config
.limit
.unwrap_or(MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT);
if limit == 0 || limit > MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT {
return Err(Error::invalid_params(format!(
"Invalid limit; max {}",
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT
)));
}
meta.get_confirmed_signatures_for_address2(address, before, limit)
}
fn get_first_available_block(&self, meta: Self::Metadata) -> Result<Slot> {
debug!("get_first_available_block rpc request received");
Ok(meta.get_first_available_block())