Skip to content

Commit

Permalink
Parse ConfidentialTransaction extensions (solana-labs#26820)
Browse files Browse the repository at this point in the history
* Bump spl-token-2022 to 0.4.2

* Revert Cargo.lock changes in solana-labs#26746 and update spl solana crates to v1.10.33

* Parse ConfidentialTransfer extensions
  • Loading branch information
Tyera Eulberg authored Jul 29, 2022
1 parent c1f7d1a commit 9d31b1d
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 114 deletions.
96 changes: 43 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion account-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ solana-config-program = { path = "../programs/config", version = "=1.11.5" }
solana-sdk = { path = "../sdk", version = "=1.11.5" }
solana-vote-program = { path = "../programs/vote", version = "=1.11.5" }
spl-token = { version = "=3.3.0", features = ["no-entrypoint"] }
spl-token-2022 = { version = "=0.4.1", features = ["no-entrypoint"] }
spl-token-2022 = { version = "=0.4.2", features = ["no-entrypoint"] }
thiserror = "1.0"
zstd = "0.11.2"

Expand Down
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),
}
}
}
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ solana-streamer = { path = "../streamer", version = "=1.11.5" }
solana-transaction-status = { path = "../transaction-status", version = "=1.11.5" }
solana-version = { path = "../version", version = "=1.11.5" }
solana-vote-program = { path = "../programs/vote", version = "=1.11.5" }
spl-token-2022 = { version = "=0.4.1", features = ["no-entrypoint"] }
spl-token-2022 = { version = "=0.4.2", features = ["no-entrypoint"] }
thiserror = "1.0"
tokio = { version = "~1.14.1", features = ["full"] }
tokio-stream = "0.1.9"
Expand Down
Loading

0 comments on commit 9d31b1d

Please sign in to comment.