Skip to content

Commit

Permalink
Parse ConfidentialTransfer extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Jul 28, 2022
1 parent 0a01435 commit 45f2991
Showing 1 changed file with 93 additions and 4 deletions.
97 changes: 93 additions & 4 deletions account-decoder/src/parse_token_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub enum UiExtension {
TransferFeeConfig(UiTransferFeeConfig),
TransferFeeAmount(UiTransferFeeAmount),
MintCloseAuthority(UiMintCloseAuthority),
ConfidentialTransferMint, // Implementation of extension state to come
ConfidentialTransferAccount, // Implementation of extension state to come
ConfidentialTransferMint(UiConfidentialTransferMint),
ConfidentialTransferAccount(UiConfidentialTransferAccount),
DefaultAccountState(UiDefaultAccountState),
ImmutableOwner,
MemoTransfer(UiMemoTransfer),
Expand All @@ -42,8 +42,14 @@ pub fn parse_extension<S: BaseState>(
.get_extension::<extension::mint_close_authority::MintCloseAuthority>()
.map(|&extension| UiExtension::MintCloseAuthority(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::ConfidentialTransferMint => UiExtension::ConfidentialTransferMint,
ExtensionType::ConfidentialTransferAccount => UiExtension::ConfidentialTransferAccount,
ExtensionType::ConfidentialTransferMint => account
.get_extension::<extension::confidential_transfer::ConfidentialTransferMint>()
.map(|&extension| UiExtension::ConfidentialTransferMint(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::ConfidentialTransferAccount => account
.get_extension::<extension::confidential_transfer::ConfidentialTransferAccount>()
.map(|&extension| UiExtension::ConfidentialTransferAccount(extension.into()))
.unwrap_or(UiExtension::UnparseableExtension),
ExtensionType::DefaultAccountState => account
.get_extension::<extension::default_account_state::DefaultAccountState>()
.map(|&extension| UiExtension::DefaultAccountState(extension.into()))
Expand Down Expand Up @@ -197,3 +203,86 @@ impl From<extension::interest_bearing_mint::InterestBearingConfig> for UiInteres
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiConfidentialTransferMint {
pub authority: String,
pub auto_approve_new_accounts: bool,
pub auditor_encryption_pubkey: String,
pub withdraw_withheld_authority_encryption_pubkey: String,
pub withheld_amount: String,
}

impl From<extension::confidential_transfer::ConfidentialTransferMint>
for UiConfidentialTransferMint
{
fn from(
confidential_transfer_mint: extension::confidential_transfer::ConfidentialTransferMint,
) -> Self {
Self {
authority: confidential_transfer_mint.authority.to_string(),
auto_approve_new_accounts: confidential_transfer_mint.auto_approve_new_accounts.into(),
auditor_encryption_pubkey: format!(
"{}",
confidential_transfer_mint.auditor_encryption_pubkey
),
withdraw_withheld_authority_encryption_pubkey: format!(
"{}",
confidential_transfer_mint.withdraw_withheld_authority_encryption_pubkey
),
withheld_amount: format!("{}", confidential_transfer_mint.withheld_amount),
}
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiConfidentialTransferAccount {
pub approved: bool,
pub encryption_pubkey: String,
pub pending_balance_lo: String,
pub pending_balance_hi: String,
pub available_balance: String,
pub decryptable_available_balance: String,
pub allow_balance_credits: bool,
pub pending_balance_credit_counter: u64,
pub maximum_pending_balance_credit_counter: u64,
pub expected_pending_balance_credit_counter: u64,
pub actual_pending_balance_credit_counter: u64,
pub withheld_amount: String,
}

impl From<extension::confidential_transfer::ConfidentialTransferAccount>
for UiConfidentialTransferAccount
{
fn from(
confidential_transfer_account: extension::confidential_transfer::ConfidentialTransferAccount,
) -> Self {
Self {
approved: confidential_transfer_account.approved.into(),
encryption_pubkey: format!("{}", confidential_transfer_account.encryption_pubkey),
pending_balance_lo: format!("{}", confidential_transfer_account.pending_balance_lo),
pending_balance_hi: format!("{}", confidential_transfer_account.pending_balance_hi),
available_balance: format!("{}", confidential_transfer_account.available_balance),
decryptable_available_balance: format!(
"{}",
confidential_transfer_account.decryptable_available_balance
),
allow_balance_credits: confidential_transfer_account.allow_balance_credits.into(),
pending_balance_credit_counter: confidential_transfer_account
.pending_balance_credit_counter
.into(),
maximum_pending_balance_credit_counter: confidential_transfer_account
.maximum_pending_balance_credit_counter
.into(),
expected_pending_balance_credit_counter: confidential_transfer_account
.expected_pending_balance_credit_counter
.into(),
actual_pending_balance_credit_counter: confidential_transfer_account
.actual_pending_balance_credit_counter
.into(),
withheld_amount: format!("{}", confidential_transfer_account.withheld_amount),
}
}
}

0 comments on commit 45f2991

Please sign in to comment.