揭示隐式账户的公钥 (Revealing the public key of an implicit account)
为了揭示隐式账户的公钥,用户必须向账本提交交易。
use namada_sdk::io::NullIo;
use namada_sdk::NamadaImpl;
use namada_sdk::core::types::chain::ChainId;
// Define the namada implementation (assuming we have a wallet, http_client, and shielded_ctx)
let mut namada = NamadaImpl::new(&http_client, &mut wallet, &mut shielded_ctx, &NullIo)
.await
.expect("unable to construct Namada object")
.chain_id(ChainId::from_str("public-testnet-14.5d79b6958580").unwrap());
// Generate an account (assuming sk is a SecretKey)
let account = Account {
public_key: sk.to_public(),
private_key: sk,
revealed: false,
};
// Build the reveal pk transaction using the NamadaImpl object
let reveal_tx_builder = namada
.new_reveal_pk(account.public_key.clone())
.signing_keys(vec![account.private_key.clone()]);
let (mut reveal_tx, signing_data, _) = reveal_tx_builder
.build(namada)
.await
.expect("unable to build reveal pk tx");
// Sign the transaction
namada
.sign(&mut reveal_tx, &reveal_tx_builder.tx, signing_data)
.await
.expect("unable to sign reveal pk tx");
// Submit the signed tx to the ledger for execution
namada.submit(reveal_tx.clone(), reveal_tx_builder)