Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 89f5153

Browse files
authored
Rpc: Add getConfirmedSignaturesForAddress (#9407) (#9418)
automerge
1 parent 677008b commit 89f5153

File tree

5 files changed

+297
-35
lines changed

5 files changed

+297
-35
lines changed

core/src/rpc.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::{
3939
};
4040

4141
const MAX_QUERY_ITEMS: usize = 256;
42+
const MAX_SLOT_RANGE: u64 = 10_000;
4243

4344
type RpcResponse<T> = Result<Response<T>>;
4445

@@ -523,6 +524,22 @@ impl JsonRpcRequestProcessor {
523524
Ok(None)
524525
}
525526
}
527+
528+
pub fn get_confirmed_signatures_for_address(
529+
&self,
530+
pubkey: Pubkey,
531+
start_slot: Slot,
532+
end_slot: Slot,
533+
) -> Result<Vec<Signature>> {
534+
if self.config.enable_rpc_transaction_history {
535+
Ok(self
536+
.blockstore
537+
.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
538+
.unwrap_or_else(|_| vec![]))
539+
} else {
540+
Ok(vec![])
541+
}
542+
}
526543
}
527544

528545
fn get_tpu_addr(cluster_info: &Arc<RwLock<ClusterInfo>>) -> Result<SocketAddr> {
@@ -772,6 +789,15 @@ pub trait RpcSol {
772789
signature_str: String,
773790
encoding: Option<TransactionEncoding>,
774791
) -> Result<Option<ConfirmedTransaction>>;
792+
793+
#[rpc(meta, name = "getConfirmedSignaturesForAddress")]
794+
fn get_confirmed_signatures_for_address(
795+
&self,
796+
meta: Self::Metadata,
797+
pubkey_str: String,
798+
start_slot: Slot,
799+
end_slot: Slot,
800+
) -> Result<Vec<String>>;
775801
}
776802

777803
pub struct RpcSolImpl;
@@ -1328,6 +1354,38 @@ impl RpcSol for RpcSolImpl {
13281354
.unwrap()
13291355
.get_confirmed_transaction(signature, encoding)
13301356
}
1357+
1358+
fn get_confirmed_signatures_for_address(
1359+
&self,
1360+
meta: Self::Metadata,
1361+
pubkey_str: String,
1362+
start_slot: Slot,
1363+
end_slot: Slot,
1364+
) -> Result<Vec<String>> {
1365+
let pubkey = verify_pubkey(pubkey_str)?;
1366+
if end_slot <= start_slot {
1367+
return Err(Error::invalid_params(format!(
1368+
"start_slot {} must be smaller than end_slot {}",
1369+
start_slot, end_slot
1370+
)));
1371+
}
1372+
if end_slot - start_slot > MAX_SLOT_RANGE {
1373+
return Err(Error::invalid_params(format!(
1374+
"Slot range too large; max {}",
1375+
MAX_SLOT_RANGE
1376+
)));
1377+
}
1378+
meta.request_processor
1379+
.read()
1380+
.unwrap()
1381+
.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
1382+
.map(|signatures| {
1383+
signatures
1384+
.iter()
1385+
.map(|signature| signature.to_string())
1386+
.collect()
1387+
})
1388+
}
13311389
}
13321390

13331391
#[cfg(test)]

docs/src/apps/jsonrpc-api.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To interact with a Solana node inside a JavaScript application, use the [solana-
2121
* [getClusterNodes](jsonrpc-api.md#getclusternodes)
2222
* [getConfirmedBlock](jsonrpc-api.md#getconfirmedblock)
2323
* [getConfirmedBlocks](jsonrpc-api.md#getconfirmedblocks)
24+
* [getConfirmedSignaturesForAddress](jsonrpc-api.md#getconfirmedsignaturesforaddress)
2425
* [getConfirmedTransaction](jsonrpc-api.md#getconfirmedtransaction)
2526
* [getEpochInfo](jsonrpc-api.md#getepochinfo)
2627
* [getEpochSchedule](jsonrpc-api.md#getepochschedule)
@@ -346,6 +347,33 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"m
346347
{"jsonrpc":"2.0","result":[5,6,7,8,9,10],"id":1}
347348
```
348349

350+
### getConfirmedSignaturesForAddress
351+
352+
Returns a list of all the confirmed signatures for transactions involving an address, within a specified Slot range. Max range allowed is 10_000 Slots.
353+
354+
#### Parameters:
355+
356+
* `<string>` - account address as base-58 encoded string
357+
* `<u64>` - start slot, inclusive
358+
* `<u64>` - end slot, inclusive
359+
360+
#### Results:
361+
362+
The result field will be an array of:
363+
* `<string>` - transaction signature as base-58 encoded string
364+
365+
The signatures will be ordered based on the Slot in which they were confirmed in, from lowest to highest Slot
366+
367+
#### Example:
368+
369+
```bash
370+
// Request
371+
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getConfirmedSignaturesForAddress","params":["6H94zdiaYfRfPfKjYLjyr2VFBg6JHXygy84r3qhc3NsC", 0, 100]}' localhost:8899
372+
373+
// Result
374+
{"jsonrpc":"2.0","result":{["35YGay1Lwjwgxe9zaH6APSHbt9gYQUCtBWTNL3aVwVGn9xTFw2fgds7qK5AL29mP63A9j3rh8KpN1TgSR62XCaby","4bJdGN8Tt2kLWZ3Fa1dpwPSEkXWWTSszPSf1rRVsCwNjxbbUdwTeiWtmi8soA26YmwnKD4aAxNp8ci1Gjpdv4gsr","4LQ14a7BYY27578Uj8LPCaVhSdJGLn9DJqnUJHpy95FMqdKf9acAhUhecPQNjNUy6VoNFUbvwYkPociFSf87cWbG"]},"id":1}
375+
```
376+
349377
### getConfirmedTransaction
350378

351379
Returns transaction details for a confirmed transaction

0 commit comments

Comments
 (0)