diff --git a/client/src/rpc_config.rs b/client/src/rpc_config.rs index 4ee8ed4793..cb7b913093 100644 --- a/client/src/rpc_config.rs +++ b/client/src/rpc_config.rs @@ -108,3 +108,51 @@ pub struct RpcGetConfirmedSignaturesForAddress2Config { pub until: Option, // Signature as base-58 string pub limit: Option, } + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RpcEncodingConfigWrapper { + Deprecated(Option), + Current(Option), +} + +impl RpcEncodingConfigWrapper { + 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) -> Self; +} + +#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RpcConfirmedBlockConfig { + pub encoding: Option, +} + +impl EncodingConfig for RpcConfirmedBlockConfig { + fn new_with_encoding(encoding: &Option) -> Self { + Self { + encoding: *encoding, + } + } +} + +#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RpcConfirmedTransactionConfig { + pub encoding: Option, +} + +impl EncodingConfig for RpcConfirmedTransactionConfig { + fn new_with_encoding(encoding: &Option) -> Self { + Self { + encoding: *encoding, + } + } +} diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 7d9fe165ad..3470aa38c7 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -719,9 +719,12 @@ impl JsonRpcRequestProcessor { pub fn get_confirmed_block( &self, slot: Slot, - encoding: Option, + config: Option>, ) -> Result> { - 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 && slot <= self @@ -987,9 +990,12 @@ impl JsonRpcRequestProcessor { pub fn get_confirmed_transaction( &self, signature: Signature, - encoding: Option, + config: Option>, ) -> Option { - 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 { match self .blockstore @@ -2178,7 +2184,7 @@ pub mod rpc_full { &self, meta: Self::Metadata, slot: Slot, - encoding: Option, + config: Option>, ) -> Result>; #[rpc(meta, name = "getBlockTime")] @@ -2206,7 +2212,7 @@ pub mod rpc_full { &self, meta: Self::Metadata, signature_str: String, - encoding: Option, + config: Option>, ) -> Result>; #[rpc(meta, name = "getConfirmedSignaturesForAddress")] @@ -2786,10 +2792,10 @@ pub mod rpc_full { &self, meta: Self::Metadata, slot: Slot, - encoding: Option, + config: Option>, ) -> Result> { debug!("get_confirmed_block rpc request received: {:?}", slot); - meta.get_confirmed_block(slot, encoding) + meta.get_confirmed_block(slot, config) } fn get_confirmed_blocks( @@ -2830,14 +2836,14 @@ pub mod rpc_full { &self, meta: Self::Metadata, signature_str: String, - encoding: Option, + config: Option>, ) -> Result> { debug!( "get_confirmed_transaction rpc request received: {:?}", 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( diff --git a/docs/src/developing/clients/jsonrpc-api.md b/docs/src/developing/clients/jsonrpc-api.md index 099ad62327..aaade40745 100644 --- a/docs/src/developing/clients/jsonrpc-api.md +++ b/docs/src/developing/clients/jsonrpc-api.md @@ -457,7 +457,8 @@ Returns identity and transaction information about a confirmed block in the ledg #### Parameters: - `` - slot, as u64 integer -- `` - encoding for each returned Transaction, either "json", "jsonParsed", "base58" (*slow*), "base64". If parameter not provided, the default encoding is "json". +- `` - (optional) Configuration object containing the following optional fields: + - (optional) `encoding: ` - 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). #### Results: @@ -495,7 +496,7 @@ The result field will be an object with the following fields: Request: ```bash 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: - `` - transaction signature as base-58 encoded string -- `` - encoding for each returned Transaction, either "json", "jsonParsed", "base58" (*slow*), "base64". If parameter not provided, the default encoding is "json". +- `` - (optional) Configuration object containing the following optional fields: + - (optional) `encoding: ` - 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). -- `` - (optional) encoding for the returned Transaction, either "json", "jsonParsed", "base58" (*slow*), or "base64". If parameter not provided, the default encoding is JSON. #### Results: