-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: account allowance delete transaction
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
sdk/rust/src/account/account_allowance_delete_transaction.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use async_trait::async_trait; | ||
use hedera_proto::services; | ||
use hedera_proto::services::crypto_service_client::CryptoServiceClient; | ||
use serde_with::skip_serializing_none; | ||
use tonic::transport::Channel; | ||
|
||
use crate::protobuf::ToProtobuf; | ||
use crate::transaction::{AnyTransactionData, ToTransactionDataProtobuf, TransactionExecute}; | ||
use crate::{AccountAddress, AccountId, TokenId, Transaction}; | ||
|
||
/// Mark an account as deleted, moving all its current hbars to another account. | ||
/// | ||
/// It will remain in the ledger, marked as deleted, until it expires. | ||
/// Transfers into it a deleted account will fail. | ||
/// | ||
pub type AccountDeleteAllowanceTransaction = Transaction<AccountDeleteAllowanceTransactionData>; | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct AccountDeleteAllowanceTransactionData { | ||
pub nft_allowances: Vec<NftRemoveAllowanceData>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct NftRemoveAllowanceData { | ||
/// token that the allowance pertains to | ||
pub token_id: Option<TokenId>, | ||
|
||
/// The account ID that owns token. | ||
pub owner: Option<AccountAddress>, | ||
|
||
/// The list of serial numbers to remove allowances from. | ||
pub serial_numbers: Vec<i64>, | ||
|
||
} | ||
|
||
impl AccountDeleteAllowanceTransaction { | ||
/// Sets the account ID which should be deleted. | ||
pub fn nft_allowances(&mut self, id: impl Into<Vec<NftRemoveAllowanceData>>) -> &mut Self { | ||
self.body.data.nft_allowances = id.into(); | ||
self | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl TransactionExecute for AccountDeleteAllowanceTransactionData { | ||
async fn execute( | ||
&self, | ||
channel: Channel, | ||
request: services::Transaction, | ||
) -> Result<tonic::Response<services::TransactionResponse>, tonic::Status> { | ||
CryptoServiceClient::new(channel).delete_allowances(request).await | ||
} | ||
} | ||
|
||
impl ToTransactionDataProtobuf for AccountDeleteAllowanceTransactionData { | ||
fn to_transaction_data_protobuf( | ||
&self, | ||
_node_account_id: AccountId, | ||
_transaction_id: &crate::TransactionId, | ||
) -> services::transaction_body::Data { | ||
let nft_allowances = self | ||
.nft_allowances | ||
.iter() | ||
.map(|allowance| allowance.to_protobuf()) | ||
.collect::<Vec<_>>(); | ||
services::transaction_body::Data::CryptoDeleteAllowance(services::CryptoDeleteAllowanceTransactionBody { | ||
nft_allowances, | ||
}) | ||
} | ||
} | ||
|
||
impl From<AccountDeleteAllowanceTransactionData> for AnyTransactionData { | ||
fn from(transaction: AccountDeleteAllowanceTransactionData) -> Self { | ||
Self::AccountDeleteAllowance(transaction) | ||
} | ||
} | ||
|
||
impl ToProtobuf for NftRemoveAllowanceData { | ||
type Protobuf = services::NftRemoveAllowance; | ||
|
||
fn to_protobuf(&self) -> Self::Protobuf { | ||
Self::Protobuf{ | ||
token_id: self.token_id.as_ref().map(|id| id.to_protobuf()), | ||
owner: self.owner.as_ref().map(|id| id.to_protobuf()), | ||
serial_numbers: self.serial_numbers.clone(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters