Skip to content

Commit

Permalink
Support in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Aug 30, 2024
1 parent 1255ae5 commit 2829d76
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
17 changes: 17 additions & 0 deletions wallet/wallet-cli-commands/src/command_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,23 @@ where
Ok(Self::new_tx_submitted_command(new_tx))
}

WalletCommand::ChangeTokenMetadataUri {
token_id,
metadata_uri,
} => {
let (wallet, selected_account) = wallet_and_selected_acc(&mut self.wallet).await?;
let new_tx = wallet
.change_token_metadata_uri(
selected_account,
token_id,
metadata_uri,
self.config,
)
.await?;

Ok(Self::new_tx_submitted_command(new_tx))
}

WalletCommand::Rescan => {
self.non_empty_wallet().await?.rescan().await?;
Ok(ConsoleCommand::Print(
Expand Down
6 changes: 6 additions & 0 deletions wallet/wallet-cli-commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ pub enum WalletCommand {
#[clap(name = "token-change-authority")]
ChangeTokenAuthority { token_id: String, address: String },

#[clap(name = "token-change-metadata-uri")]
ChangeTokenMetadataUri {
token_id: String,
metadata_uri: String,
},

#[clap(name = "token-mint")]
MintTokens {
/// The token id of the tokens to be minted
Expand Down
18 changes: 18 additions & 0 deletions wallet/wallet-rpc-client/src/handles_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,24 @@ impl<N: NodeInterface + Clone + Send + Sync + Debug + 'static> WalletInterface
.map_err(WalletRpcHandlesClientError::WalletRpcError)
}

async fn change_token_metadata_uri(
&self,
account_index: U31,
token_id: String,
metadata_uri: String,
config: ControllerConfig,
) -> Result<NewTransaction, Self::Error> {
self.wallet_rpc
.change_token_metadata_uri(
account_index,
token_id.into(),
RpcHexString::from_str(&metadata_uri)?,
config,
)
.await
.map_err(WalletRpcHandlesClientError::WalletRpcError)
}

async fn mint_tokens(
&self,
account_index: U31,
Expand Down
22 changes: 21 additions & 1 deletion wallet/wallet-rpc-client/src/rpc_client/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{collections::BTreeMap, future::pending, num::NonZeroUsize, path::PathBuf};
use std::{collections::BTreeMap, future::pending, num::NonZeroUsize, path::PathBuf, str::FromStr};

use crate::wallet_rpc_traits::{PartialOrSignedTx, SignRawTransactionResult, WalletInterface};

Expand All @@ -29,6 +29,7 @@ use common::{
};
use crypto::key::{hdkd::u31::U31, PrivateKey};
use p2p_types::{bannable_address::BannableAddress, socket_address::SocketAddress, PeerId};
use rpc::types::RpcHexString;
use serialization::hex_encoded::HexEncoded;
use serialization::DecodeAll;
use utils_networking::IpOrSocketAddress;
Expand Down Expand Up @@ -739,6 +740,25 @@ impl WalletInterface for ClientWalletRpc {
.map_err(WalletRpcError::ResponseError)
}

async fn change_token_metadata_uri(
&self,
account_index: U31,
token_id: String,
metadata_uri: String,
config: ControllerConfig,
) -> Result<NewTransaction, Self::Error> {
let options = TransactionOptions::from_controller_config(&config);
WalletRpcClient::change_token_metadata_uri(
&self.http_client,
account_index.into(),
token_id.into(),
RpcHexString::from_str(&metadata_uri)?,
options,
)
.await
.map_err(WalletRpcError::ResponseError)
}

async fn mint_tokens(
&self,
account_index: U31,
Expand Down
8 changes: 8 additions & 0 deletions wallet/wallet-rpc-client/src/wallet_rpc_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ pub trait WalletInterface {
config: ControllerConfig,
) -> Result<NewTransaction, Self::Error>;

async fn change_token_metadata_uri(
&self,
account_index: U31,
token_id: String,
metadata_uri: String,
config: ControllerConfig,
) -> Result<NewTransaction, Self::Error>;

async fn mint_tokens(
&self,
account_index: U31,
Expand Down

0 comments on commit 2829d76

Please sign in to comment.