use async_trait::async_trait;
use hedera_proto::services;
use hedera_proto::services::schedule_service_client::ScheduleServiceClient;
use tonic::transport::Channel;
use crate::entity_id::AutoValidateChecksum;
use crate::protobuf::ToProtobuf;
use crate::transaction::{
AnyTransactionData,
ToTransactionDataProtobuf,
TransactionExecute,
};
use crate::{
AccountId,
Error,
LedgerId,
ScheduleId,
Transaction,
TransactionId,
};
pub type ScheduleSignTransaction = Transaction<ScheduleSignTransactionData>;
#[derive(Debug, Default, Clone)]
#[cfg_attr(feature = "ffi", derive(serde::Serialize, serde::Deserialize))]
pub struct ScheduleSignTransactionData {
schedule_id: Option<ScheduleId>,
}
impl ScheduleSignTransaction {
pub fn schedule_id(&mut self, id: ScheduleId) -> &mut Self {
self.body.data.schedule_id = Some(id);
self
}
}
#[async_trait]
impl TransactionExecute for ScheduleSignTransactionData {
fn validate_checksums_for_ledger_id(&self, ledger_id: &LedgerId) -> Result<(), Error> {
self.schedule_id.validate_checksum_for_ledger_id(ledger_id)
}
async fn execute(
&self,
channel: Channel,
request: services::Transaction,
) -> Result<tonic::Response<services::TransactionResponse>, tonic::Status> {
ScheduleServiceClient::new(channel).delete_schedule(request).await
}
}
impl ToTransactionDataProtobuf for ScheduleSignTransactionData {
fn to_transaction_data_protobuf(
&self,
_node_account_id: AccountId,
_transaction_id: &TransactionId,
) -> services::transaction_body::Data {
let schedule_id = self.schedule_id.to_protobuf();
services::transaction_body::Data::ScheduleSign(services::ScheduleSignTransactionBody {
schedule_id,
})
}
}
impl From<ScheduleSignTransactionData> for AnyTransactionData {
fn from(transaction: ScheduleSignTransactionData) -> Self {
Self::ScheduleSign(transaction)
}
}