Rpc: support extended config for getConfirmedBlock (#15827)
* Add rpc confirmed-block config wrapper to support struct of extended config * Update docs * Make config wrapper generic and use in getConfirmedTransaction as well * Update/clean confirmed-tx docs
This commit is contained in:
@ -108,3 +108,51 @@ pub struct RpcGetConfirmedSignaturesForAddress2Config {
|
|||||||
pub until: Option<String>, // Signature as base-58 string
|
pub until: Option<String>, // Signature as base-58 string
|
||||||
pub limit: Option<usize>,
|
pub limit: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum RpcEncodingConfigWrapper<T> {
|
||||||
|
Deprecated(Option<UiTransactionEncoding>),
|
||||||
|
Current(Option<T>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: EncodingConfig + Default + Copy> RpcEncodingConfigWrapper<T> {
|
||||||
|
pub fn convert_to_current(&self) -> T {
|
||||||
|
match self {
|
||||||
|
RpcEncodingConfigWrapper::Deprecated(encoding) => T::new_with_encoding(encoding),
|
||||||
|
RpcEncodingConfigWrapper::Current(config) => config.unwrap_or_default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait EncodingConfig {
|
||||||
|
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct RpcConfirmedBlockConfig {
|
||||||
|
pub encoding: Option<UiTransactionEncoding>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EncodingConfig for RpcConfirmedBlockConfig {
|
||||||
|
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self {
|
||||||
|
Self {
|
||||||
|
encoding: *encoding,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct RpcConfirmedTransactionConfig {
|
||||||
|
pub encoding: Option<UiTransactionEncoding>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EncodingConfig for RpcConfirmedTransactionConfig {
|
||||||
|
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self {
|
||||||
|
Self {
|
||||||
|
encoding: *encoding,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -719,9 +719,12 @@ impl JsonRpcRequestProcessor {
|
|||||||
pub fn get_confirmed_block(
|
pub fn get_confirmed_block(
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
encoding: Option<UiTransactionEncoding>,
|
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>,
|
||||||
) -> Result<Option<EncodedConfirmedBlock>> {
|
) -> Result<Option<EncodedConfirmedBlock>> {
|
||||||
let encoding = encoding.unwrap_or(UiTransactionEncoding::Json);
|
let config = config
|
||||||
|
.map(|config| config.convert_to_current())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Json);
|
||||||
if self.config.enable_rpc_transaction_history
|
if self.config.enable_rpc_transaction_history
|
||||||
&& slot
|
&& slot
|
||||||
<= self
|
<= self
|
||||||
@ -987,9 +990,12 @@ impl JsonRpcRequestProcessor {
|
|||||||
pub fn get_confirmed_transaction(
|
pub fn get_confirmed_transaction(
|
||||||
&self,
|
&self,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
encoding: Option<UiTransactionEncoding>,
|
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>,
|
||||||
) -> Option<EncodedConfirmedTransaction> {
|
) -> Option<EncodedConfirmedTransaction> {
|
||||||
let encoding = encoding.unwrap_or(UiTransactionEncoding::Json);
|
let config = config
|
||||||
|
.map(|config| config.convert_to_current())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Json);
|
||||||
if self.config.enable_rpc_transaction_history {
|
if self.config.enable_rpc_transaction_history {
|
||||||
match self
|
match self
|
||||||
.blockstore
|
.blockstore
|
||||||
@ -2178,7 +2184,7 @@ pub mod rpc_full {
|
|||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
encoding: Option<UiTransactionEncoding>,
|
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>,
|
||||||
) -> Result<Option<EncodedConfirmedBlock>>;
|
) -> Result<Option<EncodedConfirmedBlock>>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getBlockTime")]
|
#[rpc(meta, name = "getBlockTime")]
|
||||||
@ -2206,7 +2212,7 @@ pub mod rpc_full {
|
|||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
signature_str: String,
|
signature_str: String,
|
||||||
encoding: Option<UiTransactionEncoding>,
|
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>,
|
||||||
) -> Result<Option<EncodedConfirmedTransaction>>;
|
) -> Result<Option<EncodedConfirmedTransaction>>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getConfirmedSignaturesForAddress")]
|
#[rpc(meta, name = "getConfirmedSignaturesForAddress")]
|
||||||
@ -2786,10 +2792,10 @@ pub mod rpc_full {
|
|||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
encoding: Option<UiTransactionEncoding>,
|
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>,
|
||||||
) -> Result<Option<EncodedConfirmedBlock>> {
|
) -> Result<Option<EncodedConfirmedBlock>> {
|
||||||
debug!("get_confirmed_block rpc request received: {:?}", slot);
|
debug!("get_confirmed_block rpc request received: {:?}", slot);
|
||||||
meta.get_confirmed_block(slot, encoding)
|
meta.get_confirmed_block(slot, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_confirmed_blocks(
|
fn get_confirmed_blocks(
|
||||||
@ -2830,14 +2836,14 @@ pub mod rpc_full {
|
|||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
signature_str: String,
|
signature_str: String,
|
||||||
encoding: Option<UiTransactionEncoding>,
|
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>,
|
||||||
) -> Result<Option<EncodedConfirmedTransaction>> {
|
) -> Result<Option<EncodedConfirmedTransaction>> {
|
||||||
debug!(
|
debug!(
|
||||||
"get_confirmed_transaction rpc request received: {:?}",
|
"get_confirmed_transaction rpc request received: {:?}",
|
||||||
signature_str
|
signature_str
|
||||||
);
|
);
|
||||||
let signature = verify_signature(&signature_str)?;
|
let signature = verify_signature(&signature_str)?;
|
||||||
Ok(meta.get_confirmed_transaction(signature, encoding))
|
Ok(meta.get_confirmed_transaction(signature, config))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_confirmed_signatures_for_address(
|
fn get_confirmed_signatures_for_address(
|
||||||
|
@ -457,7 +457,8 @@ Returns identity and transaction information about a confirmed block in the ledg
|
|||||||
#### Parameters:
|
#### Parameters:
|
||||||
|
|
||||||
- `<u64>` - slot, as u64 integer
|
- `<u64>` - slot, as u64 integer
|
||||||
- `<string>` - encoding for each returned Transaction, either "json", "jsonParsed", "base58" (*slow*), "base64". If parameter not provided, the default encoding is "json".
|
- `<object>` - (optional) Configuration object containing the following optional fields:
|
||||||
|
- (optional) `encoding: <string>` - encoding for each returned Transaction, either "json", "jsonParsed", "base58" (*slow*), "base64". If parameter not provided, the default encoding is "json".
|
||||||
"jsonParsed" encoding attempts to use program-specific instruction parsers to return more human-readable and explicit data in the `transaction.message.instructions` list. If "jsonParsed" is requested but a parser cannot be found, the instruction falls back to regular JSON encoding (`accounts`, `data`, and `programIdIndex` fields).
|
"jsonParsed" encoding attempts to use program-specific instruction parsers to return more human-readable and explicit data in the `transaction.message.instructions` list. If "jsonParsed" is requested but a parser cannot be found, the instruction falls back to regular JSON encoding (`accounts`, `data`, and `programIdIndex` fields).
|
||||||
|
|
||||||
#### Results:
|
#### Results:
|
||||||
@ -495,7 +496,7 @@ The result field will be an object with the following fields:
|
|||||||
Request:
|
Request:
|
||||||
```bash
|
```bash
|
||||||
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
|
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
|
||||||
{"jsonrpc": "2.0","id":1,"method":"getConfirmedBlock","params":[430, "json"]}
|
{"jsonrpc": "2.0","id":1,"method":"getConfirmedBlock","params":[430, {"encoding": "json"}]}
|
||||||
'
|
'
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -849,9 +850,9 @@ Returns transaction details for a confirmed transaction
|
|||||||
#### Parameters:
|
#### Parameters:
|
||||||
|
|
||||||
- `<string>` - transaction signature as base-58 encoded string
|
- `<string>` - transaction signature as base-58 encoded string
|
||||||
- `<string>` - encoding for each returned Transaction, either "json", "jsonParsed", "base58" (*slow*), "base64". If parameter not provided, the default encoding is "json".
|
- `<object>` - (optional) Configuration object containing the following optional fields:
|
||||||
|
- (optional) `encoding: <string>` - encoding for each returned Transaction, either "json", "jsonParsed", "base58" (*slow*), "base64". If parameter not provided, the default encoding is "json".
|
||||||
"jsonParsed" encoding attempts to use program-specific instruction parsers to return more human-readable and explicit data in the `transaction.message.instructions` list. If "jsonParsed" is requested but a parser cannot be found, the instruction falls back to regular JSON encoding (`accounts`, `data`, and `programIdIndex` fields).
|
"jsonParsed" encoding attempts to use program-specific instruction parsers to return more human-readable and explicit data in the `transaction.message.instructions` list. If "jsonParsed" is requested but a parser cannot be found, the instruction falls back to regular JSON encoding (`accounts`, `data`, and `programIdIndex` fields).
|
||||||
- `<string>` - (optional) encoding for the returned Transaction, either "json", "jsonParsed", "base58" (*slow*), or "base64". If parameter not provided, the default encoding is JSON.
|
|
||||||
|
|
||||||
#### Results:
|
#### Results:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user