use crate::base_types::{ObjectID, SequenceNumber, TransactionDigest};
use crate::crypto::{AuthoritySignInfo, AuthorityStrongQuorumSignInfo};
use crate::effects::{
SignedTransactionEffects, TransactionEvents, VerifiedSignedTransactionEffects,
};
use crate::object::Object;
use crate::transaction::{CertifiedTransaction, SenderSignedData, SignedTransaction};
use bytes::Bytes;
use move_core_types::annotated_value::MoveStructLayout;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub enum ObjectInfoRequestKind {
LatestObjectInfo,
PastObjectInfoDebug(SequenceNumber),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub enum LayoutGenerationOption {
Generate,
None,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub struct ObjectInfoRequest {
pub object_id: ObjectID,
pub generate_layout: LayoutGenerationOption,
pub request_kind: ObjectInfoRequestKind,
}
impl ObjectInfoRequest {
pub fn past_object_info_debug_request(
object_id: ObjectID,
version: SequenceNumber,
generate_layout: LayoutGenerationOption,
) -> Self {
ObjectInfoRequest {
object_id,
generate_layout,
request_kind: ObjectInfoRequestKind::PastObjectInfoDebug(version),
}
}
pub fn latest_object_info_request(
object_id: ObjectID,
generate_layout: LayoutGenerationOption,
) -> Self {
ObjectInfoRequest {
object_id,
generate_layout,
request_kind: ObjectInfoRequestKind::LatestObjectInfo,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectInfoResponse {
pub object: Object,
pub layout: Option<MoveStructLayout>,
pub lock_for_debugging: Option<SignedTransaction>,
}
#[derive(Debug, Clone)]
pub struct VerifiedObjectInfoResponse {
pub object: Object,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransactionInfoRequest {
pub transaction_digest: TransactionDigest,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum TransactionStatus {
Signed(AuthoritySignInfo),
Executed(
Option<AuthorityStrongQuorumSignInfo>,
SignedTransactionEffects,
TransactionEvents,
),
}
impl TransactionStatus {
pub fn into_signed_for_testing(self) -> AuthoritySignInfo {
match self {
Self::Signed(s) => s,
_ => unreachable!("Incorrect response type"),
}
}
pub fn into_effects_for_testing(self) -> SignedTransactionEffects {
match self {
Self::Executed(_, e, _) => e,
_ => unreachable!("Incorrect response type"),
}
}
}
impl PartialEq for TransactionStatus {
fn eq(&self, other: &Self) -> bool {
match self {
Self::Signed(s1) => match other {
Self::Signed(s2) => s1.epoch == s2.epoch,
_ => false,
},
Self::Executed(c1, e1, ev1) => match other {
Self::Executed(c2, e2, ev2) => {
c1.as_ref().map(|a| a.epoch) == c2.as_ref().map(|a| a.epoch)
&& e1.epoch() == e2.epoch()
&& e1.digest() == e2.digest()
&& ev1.digest() == ev2.digest()
}
_ => false,
},
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct HandleTransactionResponse {
pub status: TransactionStatus,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TransactionInfoResponse {
pub transaction: SenderSignedData,
pub status: TransactionStatus,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HandleCertificateResponseV2 {
pub signed_effects: SignedTransactionEffects,
pub events: TransactionEvents,
pub fastpath_input_objects: Vec<Object>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SubmitCertificateResponse {
pub executed: Option<HandleCertificateResponseV2>,
}
#[derive(Clone, Debug)]
pub struct VerifiedHandleCertificateResponse {
pub signed_effects: VerifiedSignedTransactionEffects,
pub events: TransactionEvents,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SystemStateRequest {
pub _unused: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HandleCertificateResponseV3 {
pub effects: SignedTransactionEffects,
pub events: Option<TransactionEvents>,
pub input_objects: Option<Vec<Object>>,
pub output_objects: Option<Vec<Object>>,
pub auxiliary_data: Option<Vec<u8>>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HandleCertificateRequestV3 {
pub certificate: CertifiedTransaction,
pub include_events: bool,
pub include_input_objects: bool,
pub include_output_objects: bool,
pub include_auxiliary_data: bool,
}
#[derive(Clone, prost::Message)]
pub struct RawSubmitTxRequest {
#[prost(bytes = "bytes", repeated, tag = "1")]
pub transactions: Vec<Bytes>,
}
#[derive(Clone, prost::Message)]
pub struct RawSubmitTxResponse {
#[prost(message, repeated, tag = "1")]
pub results: Vec<RawSubmitTxResult>,
}
#[derive(Clone, prost::Message)]
pub struct RawSubmitTxResult {
#[prost(oneof = "RawValidatorSubmitStatus", tags = "1, 2")]
pub inner: Option<RawValidatorSubmitStatus>,
}
#[derive(Clone, prost::Oneof)]
pub enum RawValidatorSubmitStatus {
#[prost(bytes = "bytes", tag = "1")]
Submitted(Bytes),
#[prost(message, tag = "2")]
Executed(RawExecutedStatus),
}
#[derive(Clone, prost::Message)]
pub struct RawWaitForEffectsRequest {
#[prost(bytes = "bytes", tag = "1")]
pub transaction_digest: Bytes,
#[prost(bytes = "bytes", optional, tag = "2")]
pub consensus_position: Option<Bytes>,
#[prost(bool, tag = "3")]
pub include_details: bool,
}
#[derive(Clone, prost::Message)]
pub struct RawWaitForEffectsResponse {
#[prost(oneof = "RawValidatorTransactionStatus", tags = "1, 2, 3")]
pub inner: Option<RawValidatorTransactionStatus>,
}
#[derive(Clone, prost::Oneof)]
pub enum RawValidatorTransactionStatus {
#[prost(message, tag = "1")]
Executed(RawExecutedStatus),
#[prost(message, tag = "2")]
Rejected(RawRejectedStatus),
#[prost(message, tag = "3")]
Expired(RawExpiredStatus),
}
#[derive(Clone, prost::Message)]
pub struct RawExecutedStatus {
#[prost(bytes = "bytes", tag = "1")]
pub effects_digest: Bytes,
#[prost(message, optional, tag = "2")]
pub details: Option<RawExecutedData>,
#[prost(bool, tag = "3")]
pub fast_path: bool,
}
#[derive(Clone, prost::Message)]
pub struct RawExecutedData {
#[prost(bytes = "bytes", tag = "1")]
pub effects: Bytes,
#[prost(bytes = "bytes", optional, tag = "2")]
pub events: Option<Bytes>,
#[prost(bytes = "bytes", repeated, tag = "3")]
pub input_objects: Vec<Bytes>,
#[prost(bytes = "bytes", repeated, tag = "4")]
pub output_objects: Vec<Bytes>,
}
#[derive(Clone, prost::Message)]
pub struct RawRejectedStatus {
#[prost(bytes = "bytes", optional, tag = "1")]
pub error: Option<Bytes>,
}
#[derive(Clone, prost::Message)]
pub struct RawExpiredStatus {
#[prost(uint64, tag = "1")]
pub epoch: u64,
#[prost(uint32, optional, tag = "2")]
pub round: Option<u32>,
}
impl From<HandleCertificateResponseV3> for HandleCertificateResponseV2 {
fn from(value: HandleCertificateResponseV3) -> Self {
Self {
signed_effects: value.effects,
events: value.events.unwrap_or_default(),
fastpath_input_objects: Vec::new(),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HandleSoftBundleCertificatesResponseV3 {
pub responses: Vec<HandleCertificateResponseV3>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HandleSoftBundleCertificatesRequestV3 {
pub certificates: Vec<CertifiedTransaction>,
pub wait_for_effects: bool,
pub include_events: bool,
pub include_input_objects: bool,
pub include_output_objects: bool,
pub include_auxiliary_data: bool,
}
#[derive(Clone, prost::Message)]
pub struct RawValidatorHealthRequest {}
#[derive(Clone, prost::Message)]
pub struct RawValidatorHealthResponse {
#[prost(uint64, optional, tag = "1")]
pub pending_certificates: Option<u64>,
#[prost(uint64, optional, tag = "2")]
pub inflight_consensus_messages: Option<u64>,
#[prost(uint64, optional, tag = "3")]
pub consensus_round: Option<u64>,
#[prost(uint64, optional, tag = "4")]
pub checkpoint_sequence: Option<u64>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ValidatorHealthRequest {}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ValidatorHealthResponse {
pub num_inflight_execution_transactions: u64,
pub num_inflight_consensus_transactions: u64,
pub last_committed_leader_round: u32,
pub last_locally_built_checkpoint: u64,
}
impl TryFrom<ValidatorHealthRequest> for RawValidatorHealthRequest {
type Error = crate::error::SuiError;
fn try_from(_value: ValidatorHealthRequest) -> Result<Self, Self::Error> {
Ok(Self {})
}
}
impl TryFrom<RawValidatorHealthRequest> for ValidatorHealthRequest {
type Error = crate::error::SuiError;
fn try_from(_value: RawValidatorHealthRequest) -> Result<Self, Self::Error> {
Ok(Self {})
}
}
impl TryFrom<ValidatorHealthResponse> for RawValidatorHealthResponse {
type Error = crate::error::SuiError;
fn try_from(value: ValidatorHealthResponse) -> Result<Self, Self::Error> {
Ok(Self {
pending_certificates: Some(value.num_inflight_execution_transactions),
inflight_consensus_messages: Some(value.num_inflight_consensus_transactions),
consensus_round: Some(value.last_committed_leader_round as u64),
checkpoint_sequence: Some(value.last_locally_built_checkpoint),
})
}
}
impl TryFrom<RawValidatorHealthResponse> for ValidatorHealthResponse {
type Error = crate::error::SuiError;
fn try_from(value: RawValidatorHealthResponse) -> Result<Self, Self::Error> {
Ok(Self {
num_inflight_consensus_transactions: value.inflight_consensus_messages.unwrap_or(0),
num_inflight_execution_transactions: value.pending_certificates.unwrap_or(0),
last_locally_built_checkpoint: value.checkpoint_sequence.unwrap_or(0),
last_committed_leader_round: value.consensus_round.unwrap_or(0) as u32,
})
}
}