Skip to content

Commit

Permalink
add ChangeTokenMetadataUri to trezor singer
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Sep 11, 2024
1 parent 7f044ef commit a35f2c3
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 20 deletions.
2 changes: 1 addition & 1 deletion 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 wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ utils-networking = { path = "../utils/networking" }
utxo = { path = "../utxo" }
wallet-storage = { path = "./storage" }
wallet-types = { path = "./types" }
trezor-client = { git = "https://github.com/mintlayer/mintlayer-trezor-firmware", branch = "feature/mintlayer", features = ["bitcoin", "mintlayer"], optional = true }
trezor-client = { git = "https://github.com/mintlayer/mintlayer-trezor-firmware", branch = "feature/mintlayer-pk", features = ["bitcoin", "mintlayer"], optional = true }

bip39 = { workspace = true, default-features = false, features = ["std", "zeroize"] }
hex.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ impl<K: AccountKeyChains> Account<K> {
let nonce = token_info.get_next_nonce()?;
let tx_input = TxInput::AccountCommand(
nonce,
AccountCommand::ChangeTokenMetadataUri(*token_info.token_id(), metadata_uri),
AccountCommand::ChangeTokenMetadataUri(token_info.token_id(), metadata_uri),
);
let authority = token_info.authority()?.clone();

Expand Down
6 changes: 3 additions & 3 deletions wallet/src/signer/trezor_signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use trezor_client::{
find_devices,
protos::{
MintlayerAccountCommandTxInput, MintlayerAccountTxInput, MintlayerAddressPath,
MintlayerBurnTxOutput, MintlayerChangeTokenAuhtority, MintlayerChangeTokenMediaUri,
MintlayerBurnTxOutput, MintlayerChangeTokenAuhtority, MintlayerChangeTokenMetadataUri,
MintlayerCreateDelegationIdTxOutput, MintlayerCreateStakePoolTxOutput,
MintlayerDataDepositTxOutput, MintlayerDelegateStakingTxOutput, MintlayerFreezeToken,
MintlayerIssueFungibleTokenTxOutput, MintlayerIssueNftTxOutput,
Expand Down Expand Up @@ -592,9 +592,9 @@ fn to_trezor_account_command_input(
inp_req.change_token_authority = Some(req).into();
}
AccountCommand::ChangeTokenMetadataUri(token_id, uri) => {
let mut req = MintlayerChangeTokenMediaUri::new();
let mut req = MintlayerChangeTokenMetadataUri::new();
req.set_token_id(token_id.to_hash().as_bytes().to_vec());
req.set_media_uri(uri.clone());
req.set_metadata_uri(uri.clone());

inp_req.change_token_metadata_uri = Some(req).into();
}
Expand Down
29 changes: 17 additions & 12 deletions wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1686,18 +1686,23 @@ where
consolidate_fee_rate: FeeRate,
) -> WalletResult<SignedTransaction> {
let latest_median_time = self.latest_median_time;
self.for_account_rw_unlocked_and_check_tx(account_index, |account, db_tx| {
account.change_token_metadata_uri(
db_tx,
token_info,
metadata_uri,
latest_median_time,
CurrentFeeRate {
current_fee_rate,
consolidate_fee_rate,
},
)
})
let additional_utxo_infos = to_token_additional_info(token_info);
self.for_account_rw_unlocked_and_check_tx(
account_index,
&additional_utxo_infos,
|account, db_tx| {
account.change_token_metadata_uri(
db_tx,
token_info,
metadata_uri,
latest_median_time,
CurrentFeeRate {
current_fee_rate,
consolidate_fee_rate,
},
)
},
)
}

pub fn find_used_tokens(
Expand Down
38 changes: 38 additions & 0 deletions wallet/wallet-controller/src/runtime_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ impl<B: storage::Backend + 'static> RuntimeWallet<B> {
}
}

pub fn get_best_block_for_account(
&self,
account_index: U31,
) -> WalletResult<(Id<GenBlock>, BlockHeight)> {
match self {
RuntimeWallet::Software(w) => w.get_best_block_for_account(account_index),
#[cfg(feature = "trezor")]
RuntimeWallet::Trezor(w) => w.get_best_block_for_account(account_index),
}
}

pub fn is_locked(&self) -> bool {
match self {
RuntimeWallet::Software(w) => w.is_locked(),
Expand Down Expand Up @@ -740,6 +751,33 @@ impl<B: storage::Backend + 'static> RuntimeWallet<B> {
}
}

pub fn change_token_metadata_uri(
&mut self,
account_index: U31,
token_info: &UnconfirmedTokenInfo,
metadata_uri: Vec<u8>,
current_fee_rate: FeeRate,
consolidate_fee_rate: FeeRate,
) -> Result<SignedTransaction, WalletError> {
match self {
RuntimeWallet::Software(w) => w.change_token_metadata_uri(
account_index,
token_info,
metadata_uri,
current_fee_rate,
consolidate_fee_rate,
),
#[cfg(feature = "trezor")]
RuntimeWallet::Trezor(w) => w.change_token_metadata_uri(
account_index,
token_info,
metadata_uri,
current_fee_rate,
consolidate_fee_rate,
),
}
}

#[allow(clippy::too_many_arguments)]
pub fn create_transaction_to_addresses(
&mut self,
Expand Down
4 changes: 2 additions & 2 deletions wallet/wallet-controller/src/synced_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,10 @@ where
metadata_uri: Vec<u8>,
) -> Result<SignedTransaction, ControllerError<T>> {
self.create_and_send_token_tx(
&token_info,
token_info,
move |current_fee_rate: FeeRate,
consolidate_fee_rate: FeeRate,
wallet: &mut DefaultWallet,
wallet: &mut RuntimeWallet<B>,
account_index: U31,
token_info: &UnconfirmedTokenInfo| {
wallet.change_token_metadata_uri(
Expand Down

0 comments on commit a35f2c3

Please sign in to comment.