use hedera_proto::services;
use crate::protobuf::{
FromProtobuf,
ToProtobuf,
};
use crate::{
AccountId,
Hbar,
};
#[derive(Debug, Clone)]
pub struct Transfer {
pub account_id: AccountId,
pub amount: Hbar,
}
impl FromProtobuf<services::AccountAmount> for Transfer {
fn from_protobuf(pb: services::AccountAmount) -> crate::Result<Self>
where
Self: Sized,
{
Ok(Self {
account_id: AccountId::from_protobuf(pb_getf!(pb, account_id)?)?,
amount: Hbar::from_tinybars(pb.amount),
})
}
}
impl ToProtobuf for Transfer {
type Protobuf = services::AccountAmount;
fn to_protobuf(&self) -> Self::Protobuf {
services::AccountAmount {
account_id: Some(self.account_id.to_protobuf()),
amount: self.amount.to_tinybars(),
is_approval: false,
}
}
}