Skip to content

Commit

Permalink
Refactor AccountIdentifier conversion to use serde_bytes::ByteBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
b3hr4d committed Sep 25, 2024
1 parent cf1cb7c commit a3e8655
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/ledger/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ impl From<Principal> for AccountIdentifier {
}
}

impl From<AccountIdentifier> for serde_bytes::ByteBuf {
fn from(account: AccountIdentifier) -> Self {
serde_bytes::ByteBuf::from(account.to_vec())
}
}

impl CandidType for AccountIdentifier {
// The type expected for account identifier is
fn _ty() -> candid::types::Type {
Expand Down
5 changes: 2 additions & 3 deletions src/ledger/types/icp/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub use error::*;

use crate::ledger::currency::ICPToken;
use crate::ledger::types::{TransferBlockIndex, TransferMemo};
use crate::ledger::AccountIdentifier;
use crate::Subaccount;
use candid::CandidType;
use serde::{Deserialize, Serialize};
Expand All @@ -19,7 +18,7 @@ pub struct ICPTransferArgs {
pub memo: TransferMemo,
pub fee: ICPToken,
pub amount: ICPToken,
pub to: Vec<u8>,
pub to: serde_bytes::ByteBuf,
pub from_subaccount: Option<Subaccount>,
pub created_at_time: Option<ICPTransferTimestamp>,
}
Expand All @@ -28,5 +27,5 @@ pub type ICPTransferResult = Result<TransferBlockIndex, ICPTransferError>;

#[derive(CandidType, Deserialize, Serialize, Clone)]
pub struct ICPAccountBalanceArgs {
pub account: AccountIdentifier,
pub account: serde_bytes::ByteBuf,
}

0 comments on commit a3e8655

Please sign in to comment.