#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct RpcQueryRequest {
#[serde(flatten)]
pub block_reference: near_primitives::types::BlockReference,
#[serde(flatten)]
pub request: near_primitives::views::QueryRequest,
}
#[derive(thiserror::Error, Debug, serde::Serialize, serde::Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcQueryError {
#[error("There are no fully synchronized blocks on the node yet")]
NoSyncedBlocks,
#[error("The node does not track the shard ID {requested_shard_id}")]
UnavailableShard { requested_shard_id: near_primitives::types::ShardId },
#[error(
"The data for block #{block_height} is garbage collected on this node, use an archival node to fetch historical data"
)]
GarbageCollectedBlock {
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error("Block either has never been observed on the node or has been garbage collected: {block_reference:?}")]
UnknownBlock { block_reference: near_primitives::types::BlockReference },
#[error("Account ID {requested_account_id} is invalid")]
InvalidAccount {
requested_account_id: near_primitives::types::AccountId,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error("account {requested_account_id} does not exist while viewing")]
UnknownAccount {
requested_account_id: near_primitives::types::AccountId,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error(
"Contract code for contract ID #{contract_account_id} has never been observed on the node"
)]
NoContractCode {
contract_account_id: near_primitives::types::AccountId,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error("State of contract {contract_account_id} is too large to be viewed")]
TooLargeContractState {
contract_account_id: near_primitives::types::AccountId,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error("Access key for public key {public_key} has never been observed on the node")]
UnknownAccessKey {
public_key: near_crypto::PublicKey,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error("Function call returned an error: {vm_error}")]
ContractExecutionError {
vm_error: String,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
#[error("The node reached its limits. Try again later. More details: {error_message}")]
InternalError { error_message: String },
}
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct RpcQueryResponse {
#[serde(flatten)]
pub kind: QueryResponseKind,
pub block_height: near_primitives::types::BlockHeight,
pub block_hash: near_primitives::hash::CryptoHash,
}
#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[serde(untagged)]
pub enum QueryResponseKind {
ViewAccount(near_primitives::views::AccountView),
ViewCode(near_primitives::views::ContractCodeView),
ViewState(near_primitives::views::ViewStateResult),
CallResult(near_primitives::views::CallResult),
AccessKey(near_primitives::views::AccessKeyView),
AccessKeyList(near_primitives::views::AccessKeyList),
}
impl From<RpcQueryError> for crate::errors::RpcError {
fn from(error: RpcQueryError) -> Self {
let error_data = Some(serde_json::Value::String(error.to_string()));
let error_data_value = match serde_json::to_value(error) {
Ok(value) => value,
Err(err) => {
return Self::new_internal_error(
None,
format!("Failed to serialize RpcQueryError: {:?}", err),
)
}
};
Self::new_internal_or_handler_error(error_data, error_data_value)
}
}