Skip to content

Commit

Permalink
Add convert_utxo_address RPC call.
Browse files Browse the repository at this point in the history
  • Loading branch information
artemii235 committed Dec 12, 2020
1 parent 3918a3d commit e3661f3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
27 changes: 27 additions & 0 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,30 @@ pub fn update_coins_config(mut config: Json) -> Result<Json, String> {

Ok(config)
}

#[derive(Deserialize)]
struct ConvertUtxoAddressReq {
address: String,
to_coin: String,
}

pub async fn convert_utxo_address(ctx: MmArc, req: Json) -> Result<Response<Vec<u8>>, String> {
let req: ConvertUtxoAddressReq = try_s!(json::from_value(req));
let mut addr: utxo::Address = try_s!(req.address.parse());
let coin = match lp_coinfindᵃ(&ctx, &req.to_coin).await {
Ok(Some(c)) => c,
_ => return ERR!("Coin {} is not activated", req.to_coin),
};
let coin = match coin {
MmCoinEnum::UtxoCoin(utxo) => utxo,
_ => return ERR!("Coin {} is not utxo", req.to_coin),
};
addr.prefix = coin.as_ref().my_address.prefix;
addr.t_addr_prefix = coin.as_ref().my_address.t_addr_prefix;
addr.checksum_type = coin.as_ref().my_address.checksum_type;

let response = try_s!(json::to_vec(&json!({
"result": addr.to_string(),
})));
Ok(try_s!(Response::builder().body(response)))
}
2 changes: 1 addition & 1 deletion mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use futures::lock::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard};
use futures::stream::StreamExt;
use futures01::Future;
use keys::bytes::Bytes;
use keys::{Address, KeyPair, Private, Public, Secret};
pub use keys::{Address, KeyPair, Private, Public, Secret};
#[cfg(test)] use mocktopus::macros::*;
use num_traits::ToPrimitive;
use primitives::hash::{H256, H264, H512};
Expand Down
6 changes: 4 additions & 2 deletions mm2src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#![cfg_attr(not(feature = "native"), allow(unused_imports))]
#![cfg_attr(not(feature = "native"), allow(dead_code))]

use coins::{convert_address, get_enabled_coins, get_trade_fee, kmd_rewards_info, my_tx_history, send_raw_transaction,
set_required_confirmations, set_requires_notarization, show_priv_key, validate_address, withdraw};
use coins::{convert_address, convert_utxo_address, get_enabled_coins, get_trade_fee, kmd_rewards_info, my_tx_history,
send_raw_transaction, set_required_confirmations, set_requires_notarization, show_priv_key,
validate_address, withdraw};
use common::mm_ctx::MmArc;
#[cfg(feature = "native")] use common::wio::{CORE, CPUPOOL};
use common::{err_to_rpc_json_string, err_tp_rpc_json, HyRes};
Expand Down Expand Up @@ -121,6 +122,7 @@ pub fn dispatcher(req: Json, ctx: MmArc) -> DispatcherRes {
"cancel_order" => hyres(cancel_order(ctx, req)),
"coins_needed_for_kick_start" => hyres(coins_needed_for_kick_start(ctx)),
"convertaddress" => hyres(convert_address(ctx, req)),
"convert_utxo_address" => hyres(convert_utxo_address(ctx, req)),
"disable_coin" => hyres(disable_coin(ctx, req)),
"electrum" => hyres(electrum(ctx, req)),
"enable" => hyres(enable(ctx, req)),
Expand Down

0 comments on commit e3661f3

Please sign in to comment.