Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ac20d84
store stats files in global db directory
mariocynicys Mar 16, 2025
b219751
let MmCtx::address_dir() default back to Ctx::dbdir() based on compil…
mariocynicys Mar 20, 2025
8d48284
replace dbdir with address_dir in eth/erc20 traces path
mariocynicys Mar 20, 2025
fa5134b
base the LN data directory and backup directory on address_dir
mariocynicys Mar 20, 2025
74b9ecb
let MmCtx::address_db() default back to Ctx::sqlite_connection based …
mariocynicys Mar 20, 2025
1e024d4
use the address_db for LN sqlite DB
mariocynicys Mar 20, 2025
6149dbc
put tx cache in proper address directory
mariocynicys Mar 20, 2025
d96d8db
use correct address dirs for wallet and cache dbs for zcoin
mariocynicys Mar 24, 2025
190e6e1
fix clippy for tests
mariocynicys Mar 24, 2025
ce446c3
use the z_spending_key field inside the builder
mariocynicys Mar 24, 2025
a1c7347
add a disucssion point regarding address dir for zcoin wallet & cache…
mariocynicys Mar 24, 2025
97d9849
fix wrong stats taker swap directory
mariocynicys Mar 25, 2025
2cd8ecd
use global directory for swap locks
mariocynicys Mar 27, 2025
ffb4540
don't create the address directory when calling address_dir()
mariocynicys Mar 28, 2025
302e23f
add cargo lock
mariocynicys Mar 28, 2025
aad8705
half-bake address directory logic inside `SavedSwap`
mariocynicys Mar 30, 2025
abbe716
give the option to specify an address directory when loading swap fro…
mariocynicys Mar 30, 2025
638da9e
add and partially implement `address_from_pubkey`
mariocynicys Mar 30, 2025
199b75b
set address_dir in `SavedSwap`s initializations
mariocynicys Mar 30, 2025
212d188
review(onur): remove optional_ from parameter name as it's obvious fr…
mariocynicys Apr 3, 2025
b896af6
review(onur): rename address_dir to maker_address in SavedSwaps
mariocynicys Apr 3, 2025
bb47ee2
review(onur): add more comments for clairty in new mm2_io functions
mariocynicys Apr 3, 2025
b3b3384
review(alina): say something if fs::rename() fails
mariocynicys Apr 3, 2025
7bcd119
don't feature gate global_dir()
mariocynicys Apr 4, 2025
3ab56ab
nest swap locks inside a `swap_locks` directory inside the global_dir
mariocynicys Apr 4, 2025
321087d
transitively enable new-db-arch for dependency mm2 crates
mariocynicys Apr 4, 2025
7b3f2b2
make an async counter part for create_parents
mariocynicys Apr 12, 2025
8a00f1c
fix sia address_from_pubkey impl
mariocynicys Apr 23, 2025
17a2bd0
lightning: impl address_from_pubkey
mariocynicys Apr 23, 2025
4a2d03a
use the global directory for blocks/cache db for zcoin
mariocynicys Apr 23, 2025
2896cb6
treat zcoin's wallet_db as an HD wallet
mariocynicys Apr 24, 2025
71923e6
remove lightning & HW wallet fixmes
mariocynicys Apr 24, 2025
52b0c59
impl address_from_pubkey for zcoin by disregarding the pubkey and ret…
mariocynicys Apr 26, 2025
62d4a53
move the recreate maker_swap fixme to a todo
mariocynicys Apr 30, 2025
6f6c3ec
add -Json to H264 from rpc::v1::types
mariocynicys May 9, 2025
f287cc8
merge with origin/dev:
mariocynicys May 9, 2025
4e91a16
fix post-merge clippy warnings
mariocynicys May 9, 2025
f13c611
add -Json to more H264s
mariocynicys May 9, 2025
994d0dc
DRY: use account_id_from_raw_pubkey
mariocynicys May 9, 2025
cbeba99
let address_from_pubkey use non-checksumed address in eth
mariocynicys May 11, 2025
0a5ae48
use node_id for the address_dir in lightning instead of a platform's …
mariocynicys May 12, 2025
5b34a5a
Merge remote-tracking branch 'origin/dev' into split-db-temp
mariocynicys May 14, 2025
2e74dff
add a todo to getive different names to address_from_pubkey
mariocynicys May 14, 2025
83e4089
use checksummed address for eth address dir
mariocynicys May 16, 2025
830100c
create similar abstraction for wallet dir
mariocynicys May 16, 2025
6665136
Update mm2src/coins/z_coin.rs
mariocynicys May 16, 2025
4e11c57
fix formatting
mariocynicys May 16, 2025
1741f34
review(dimxy): refactor z_coin.rs to not lose trace location
mariocynicys May 16, 2025
e1f478f
review(dimxy): don't use dyn in write/create_parents
mariocynicys May 16, 2025
28dc4ea
Revert "put tx cache in proper address directory" + move tx cache in …
mariocynicys May 18, 2025
6d8328a
put back the todo regarding recently spent outputs
mariocynicys May 20, 2025
f76866a
use mm_err instead of `.map_err(|e| e.map(|e| ...`
mariocynicys May 20, 2025
f40b39f
merge with origin/dev
mariocynicys May 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 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 mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enable-sia = [
default = []
run-docker-tests = []
for-tests = ["dep:mocktopus"]
new-db-arch = []
new-db-arch = ["mm2_core/new-db-arch"]

[lib]
path = "lp_coins.rs"
Expand Down
5 changes: 5 additions & 0 deletions mm2src/coins/coin_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ pub enum MyAddressError {
UnexpectedDerivationMethod(String),
InternalError(String),
}

#[derive(Debug, Display)]
pub enum AddressFromPubkeyError {
InternalError(String),
}
27 changes: 16 additions & 11 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ use web3::{self, Web3};
cfg_wasm32! {
use common::{now_ms, wait_until_ms};
use crypto::MetamaskArc;
use ethereum_types::{H264, H520};
use ethereum_types::{H264 as EthH264, H520 as EthH520};
use mm2_metamask::MetamaskError;
use web3::types::TransactionRequest;
}
Expand Down Expand Up @@ -940,15 +940,16 @@ macro_rules! tx_type_from_pay_for_gas_option {
impl EthCoinImpl {
#[cfg(not(target_arch = "wasm32"))]
fn eth_traces_path(&self, ctx: &MmArc, my_address: Address) -> PathBuf {
ctx.dbdir()
ctx.address_dir(&my_address.display_address())
.join("TRANSACTIONS")
.join(format!("{}_{:#02x}_trace.json", self.ticker, my_address))
}

/// Load saved ETH traces from local DB
#[cfg(not(target_arch = "wasm32"))]
fn load_saved_traces(&self, ctx: &MmArc, my_address: Address) -> Option<SavedTraces> {
let content = gstuff::slurp(&self.eth_traces_path(ctx, my_address));
let path = self.eth_traces_path(ctx, my_address);
let content = gstuff::slurp(&path);
if content.is_empty() {
None
} else {
Expand All @@ -970,9 +971,8 @@ impl EthCoinImpl {
#[cfg(not(target_arch = "wasm32"))]
fn store_eth_traces(&self, ctx: &MmArc, my_address: Address, traces: &SavedTraces) {
let content = json::to_vec(traces).unwrap();
let tmp_file = format!("{}.tmp", self.eth_traces_path(ctx, my_address).display());
std::fs::write(&tmp_file, content).unwrap();
std::fs::rename(tmp_file, self.eth_traces_path(ctx, my_address)).unwrap();
let path = self.eth_traces_path(ctx, my_address);
mm2_io::fs::write(&path, &content, true).unwrap();
}

/// Store ETH traces to local DB
Expand All @@ -984,7 +984,7 @@ impl EthCoinImpl {

#[cfg(not(target_arch = "wasm32"))]
fn erc20_events_path(&self, ctx: &MmArc, my_address: Address) -> PathBuf {
ctx.dbdir()
ctx.address_dir(&my_address.display_address())
.join("TRANSACTIONS")
.join(format!("{}_{:#02x}_events.json", self.ticker, my_address))
}
Expand All @@ -993,9 +993,8 @@ impl EthCoinImpl {
#[cfg(not(target_arch = "wasm32"))]
fn store_erc20_events(&self, ctx: &MmArc, my_address: Address, events: &SavedErc20Events) {
let content = json::to_vec(events).unwrap();
let tmp_file = format!("{}.tmp", self.erc20_events_path(ctx, my_address).display());
std::fs::write(&tmp_file, content).unwrap();
std::fs::rename(tmp_file, self.erc20_events_path(ctx, my_address)).unwrap();
let path = self.erc20_events_path(ctx, my_address);
mm2_io::fs::write(&path, &content, true).unwrap();
}

/// Store ERC20 events to local DB
Expand All @@ -1008,7 +1007,8 @@ impl EthCoinImpl {
/// Load saved ERC20 events from local DB
#[cfg(not(target_arch = "wasm32"))]
fn load_saved_erc20_events(&self, ctx: &MmArc, my_address: Address) -> Option<SavedErc20Events> {
let content = gstuff::slurp(&self.erc20_events_path(ctx, my_address));
let path = self.erc20_events_path(ctx, my_address);
let content = gstuff::slurp(&path);
if content.is_empty() {
None
} else {
Expand Down Expand Up @@ -2329,6 +2329,11 @@ impl MarketCoinOps for EthCoin {
}
}

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError> {
let addr = addr_from_raw_pubkey(&pubkey.0).map_err(AddressFromPubkeyError::InternalError)?;
Ok(addr.display_address())
Comment thread
shamardy marked this conversation as resolved.
}

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>> {
match self.priv_key_policy {
EthPrivKeyPolicy::Iguana(ref key_pair)
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/eth/v2_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,9 @@ async fn check_metamask_supports_chain_id(
}

#[cfg(target_arch = "wasm32")]
fn compress_public_key(uncompressed: H520) -> MmResult<H264, EthActivationV2Error> {
fn compress_public_key(uncompressed: EthH520) -> MmResult<EthH264, EthActivationV2Error> {
let public_key = PublicKey::from_slice(uncompressed.as_bytes())
.map_to_mm(|e| EthActivationV2Error::InternalError(e.to_string()))?;
let compressed = public_key.serialize();
Ok(H264::from(compressed))
Ok(EthH264::from(compressed))
}
10 changes: 8 additions & 2 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod ln_sql;
pub mod ln_storage;
pub mod ln_utils;

use crate::coin_errors::{MyAddressError, ValidatePaymentResult};
use crate::coin_errors::{AddressFromPubkeyError, MyAddressError, ValidatePaymentResult};
use crate::lightning::ln_utils::{filter_channels, pay_invoice_with_max_total_cltv_expiry_delta, PaymentError};
use crate::utxo::rpc_clients::UtxoRpcClientEnum;
use crate::utxo::utxo_common::{big_decimal_from_sat, big_decimal_from_sat_unsigned};
Expand Down Expand Up @@ -65,7 +65,7 @@ use mm2_err_handle::prelude::*;
use mm2_net::ip_addr::myipaddr;
use mm2_number::{BigDecimal, MmNumber};
use parking_lot::Mutex as PaMutex;
use rpc::v1::types::{Bytes as BytesJson, H256 as H256Json};
use rpc::v1::types::{Bytes as BytesJson, H256 as H256Json, H264 as H264Json};
use script::TransactionInputSigner;
use secp256k1v24::PublicKey;
use serde::Deserialize;
Expand Down Expand Up @@ -942,6 +942,12 @@ impl MarketCoinOps for LightningCoin {

fn my_address(&self) -> MmResult<String, MyAddressError> { Ok(self.my_node_id()) }

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError> {
PublicKey::from_slice(&pubkey.0)
.map(|pubkey| pubkey.to_string())
.map_to_mm(|e| AddressFromPubkeyError::InternalError(format!("Couldn't parse bytes into secp pubkey: {e}")))
Comment thread
shamardy marked this conversation as resolved.
}

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>> { Ok(self.my_node_id()) }

fn sign_message_hash(&self, message: &str) -> Option<[u8; 32]> {
Expand Down
34 changes: 18 additions & 16 deletions mm2src/coins/lightning/ln_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use mm2_core::mm_ctx::MmArc;
use std::collections::hash_map::Entry;
use std::fs::File;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::{Arc, Mutex};

pub const PAYMENT_RETRY_ATTEMPTS: usize = 5;

Expand Down Expand Up @@ -54,25 +54,28 @@ impl From<ElectrumBlockHeader> for RpcBestBlock {
}

#[inline]
fn ln_data_dir(ctx: &MmArc, ticker: &str) -> PathBuf { ctx.dbdir().join("LIGHTNING").join(ticker) }
fn ln_data_dir(ctx: &MmArc, platform_coin_address: &str, ticker: &str) -> PathBuf {
ctx.address_dir(platform_coin_address).join("LIGHTNING").join(ticker)
}

#[inline]
fn ln_data_backup_dir(ctx: &MmArc, path: Option<String>, ticker: &str) -> Option<PathBuf> {
fn ln_data_backup_dir(path: Option<String>, platform_coin_address: &str, ticker: &str) -> Option<PathBuf> {
path.map(|p| {
PathBuf::from(&p)
.join(hex::encode(ctx.rmd160().as_slice()))
.join(platform_coin_address)
.join("LIGHTNING")
.join(ticker)
})
}

pub async fn init_persister(
ctx: &MmArc,
platform_coin_address: &str,
ticker: String,
backup_path: Option<String>,
) -> EnableLightningResult<Arc<LightningFilesystemPersister>> {
let ln_data_dir = ln_data_dir(ctx, &ticker);
let ln_data_backup_dir = ln_data_backup_dir(ctx, backup_path, &ticker);
let ln_data_dir = ln_data_dir(ctx, platform_coin_address, &ticker);
let ln_data_backup_dir = ln_data_backup_dir(backup_path, platform_coin_address, &ticker);
let persister = Arc::new(LightningFilesystemPersister::new(ln_data_dir, ln_data_backup_dir));

let is_initialized = persister.is_fs_initialized().await?;
Expand All @@ -83,16 +86,15 @@ pub async fn init_persister(
Ok(persister)
}

pub async fn init_db(ctx: &MmArc, ticker: String) -> EnableLightningResult<SqliteLightningDB> {
let db = SqliteLightningDB::new(
ticker,
ctx.sqlite_connection
.get()
.ok_or(MmError::new(EnableLightningError::DbError(
"sqlite_connection is not initialized".into(),
)))?
.clone(),
)?;
pub async fn init_db(
ctx: &MmArc,
platform_coin_address: &str,
ticker: String,
) -> EnableLightningResult<SqliteLightningDB> {
let conn = ctx
.address_db(platform_coin_address)
.map_err(|e| EnableLightningError::IOError(e.to_string()))?;
let db = SqliteLightningDB::new(ticker, Arc::new(Mutex::new(conn)))?;

if !db.is_db_initialized().await? {
db.init_db().await?;
Expand Down
7 changes: 5 additions & 2 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use mm2_rpc::data::legacy::{EnabledCoin, GetEnabledResponse, Mm2RpcResult};
#[cfg(any(test, feature = "for-tests"))]
use mocktopus::macros::*;
use parking_lot::Mutex as PaMutex;
use rpc::v1::types::{Bytes as BytesJson, H256 as H256Json};
use rpc::v1::types::{Bytes as BytesJson, H256 as H256Json, H264 as H264Json};
use rpc_command::tendermint::ibc::ChannelId;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{self as json, Value as Json};
Expand Down Expand Up @@ -214,7 +214,8 @@ pub mod lp_price;
pub mod watcher_common;

pub mod coin_errors;
use coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentResult};
use coin_errors::{AddressFromPubkeyError, MyAddressError, ValidatePaymentError, ValidatePaymentFut,
ValidatePaymentResult};
use crypto::secret_hash_algo::SecretHashAlgo;

pub mod eth;
Expand Down Expand Up @@ -2076,6 +2077,8 @@ pub trait MarketCoinOps {

fn my_address(&self) -> MmResult<String, MyAddressError>;

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError>;

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>>;

fn sign_message_hash(&self, _message: &str) -> Option<[u8; 32]>;
Expand Down
10 changes: 8 additions & 2 deletions mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentResult};
use crate::coin_errors::{AddressFromPubkeyError, MyAddressError, ValidatePaymentError, ValidatePaymentResult};
use crate::eth::{self, u256_to_big_decimal, wei_from_big_decimal, TryToAddress};
use crate::qrc20::rpc_clients::{LogEntry, Qrc20ElectrumOps, Qrc20NativeOps, Qrc20RpcOps, TopicFilter, TxReceipt,
ViewContractCallType};
Expand Down Expand Up @@ -44,7 +44,8 @@ use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::*;
use mm2_number::{BigDecimal, MmNumber};
#[cfg(test)] use mocktopus::macros::*;
use rpc::v1::types::{Bytes as BytesJson, ToTxHash, Transaction as RpcTransaction, H160 as H160Json, H256 as H256Json};
use rpc::v1::types::{Bytes as BytesJson, ToTxHash, Transaction as RpcTransaction, H160 as H160Json, H256 as H256Json,
H264 as H264Json};
use script::{Builder as ScriptBuilder, Opcode, Script, TransactionInputSigner};
use script_pubkey::generate_contract_call_script_pubkey;
use serde_json::{self as json, Value as Json};
Expand Down Expand Up @@ -1024,6 +1025,11 @@ impl MarketCoinOps for Qrc20Coin {

fn my_address(&self) -> MmResult<String, MyAddressError> { utxo_common::my_address(self) }

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError> {
let pubkey = Public::Compressed((*pubkey).into());
Ok(UtxoCommonOps::address_from_pubkey(self, &pubkey).to_string())
}

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>> {
let pubkey = utxo_common::my_public_key(self.as_ref())?;
Ok(pubkey.to_string())
Expand Down
25 changes: 17 additions & 8 deletions mm2src/coins/siacoin.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::{BalanceError, CoinBalance, HistorySyncState, MarketCoinOps, MmCoin, RawTransactionFut,
RawTransactionRequest, SwapOps, TradeFee, TransactionEnum};
use crate::{coin_errors::MyAddressError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput,
DexFee, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractAddrErr, PrivKeyBuildPolicy, PrivKeyPolicy,
RawTransactionResult, RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs,
SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, TradePreimageFut, TradePreimageResult,
TradePreimageValue, TransactionResult, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult,
ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentInput, ValidatePaymentResult, VerificationResult,
WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawFut, WithdrawRequest};
use crate::{coin_errors::MyAddressError, AddressFromPubkeyError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs,
ConfirmPaymentInput, DexFee, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractAddrErr,
PrivKeyBuildPolicy, PrivKeyPolicy, RawTransactionResult, RefundPaymentArgs, SearchForSwapTxSpendInput,
SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, TradePreimageFut,
TradePreimageResult, TradePreimageValue, TransactionResult, TxMarshalingErr, UnexpectedDerivationMethod,
ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentInput,
ValidatePaymentResult, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawFut,
WithdrawRequest};
use async_trait::async_trait;
use common::executor::AbortedError;
pub use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature};
Expand All @@ -16,7 +17,7 @@ use keys::KeyPair;
use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::*;
use mm2_number::{BigDecimal, BigInt, MmNumber};
use rpc::v1::types::Bytes as BytesJson;
use rpc::v1::types::{Bytes as BytesJson, H264 as H264Json};
use serde_json::Value as Json;
use std::ops::Deref;
use std::sync::Arc;
Expand Down Expand Up @@ -312,6 +313,14 @@ impl MarketCoinOps for SiaCoin {
Ok(address.to_string())
}

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError> {
let pubkey = PublicKey::from_bytes(&pubkey.0[..32]).map_err(|e| {
AddressFromPubkeyError::InternalError(format!("Couldn't parse bytes into ed25519 pubkey: {e:?}"))
})?;
let address = SpendPolicy::PublicKey(pubkey).address();
Ok(address.to_string())
}

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>> { unimplemented!() }

fn sign_message_hash(&self, _message: &str) -> Option<[u8; 32]> { unimplemented!() }
Expand Down
10 changes: 8 additions & 2 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::htlc::{ClaimHtlcMsg, ClaimHtlcProto, CreateHtlcMsg, CreateHtlcProto,
use super::ibc::transfer_v1::MsgTransfer;
use super::ibc::IBC_GAS_LIMIT_DEFAULT;
use super::rpc::*;
use crate::coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentResult};
use crate::coin_errors::{AddressFromPubkeyError, MyAddressError, ValidatePaymentError, ValidatePaymentResult};
use crate::hd_wallet::{HDPathAccountToAddressId, WithdrawFrom};
use crate::rpc_command::tendermint::ibc::ChannelId;
use crate::rpc_command::tendermint::staking::{ClaimRewardsPayload, Delegation, DelegationPayload,
Expand Down Expand Up @@ -78,7 +78,7 @@ use num_traits::Zero;
use parking_lot::Mutex as PaMutex;
use primitives::hash::H256;
use regex::Regex;
use rpc::v1::types::Bytes as BytesJson;
use rpc::v1::types::{Bytes as BytesJson, H264 as H264Json};
use serde_json::{self as json, Value as Json};
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
Expand Down Expand Up @@ -3320,6 +3320,12 @@ impl MarketCoinOps for TendermintCoin {

fn my_address(&self) -> MmResult<String, MyAddressError> { Ok(self.account_id.to_string()) }

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError> {
let address = account_id_from_raw_pubkey(&self.account_prefix, &pubkey.0)
.map_err(|e| AddressFromPubkeyError::InternalError(e.to_string()))?;
Ok(address.to_string())
}

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>> {
let key = SigningKey::from_slice(self.activation_policy.activated_key_or_err()?.as_slice())
.expect("privkey validity is checked on coin creation");
Expand Down
8 changes: 6 additions & 2 deletions mm2src/coins/tendermint/tendermint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::ibc::IBC_GAS_LIMIT_DEFAULT;
use super::{create_withdraw_msg_as_any, TendermintCoin, TendermintFeeDetails, GAS_LIMIT_DEFAULT, MIN_TX_SATOSHIS,
TIMEOUT_HEIGHT_DELTA, TX_DEFAULT_MEMO};
use crate::coin_errors::ValidatePaymentResult;
use crate::coin_errors::{AddressFromPubkeyError, ValidatePaymentResult};
use crate::utxo::utxo_common::big_decimal_from_sat;
use crate::{big_decimal_from_sat_unsigned, utxo::sat_from_big_decimal, BalanceFut, BigDecimal,
CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DexFee, FeeApproxStage, FoundSwapTxSpend,
Expand All @@ -29,7 +29,7 @@ use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::*;
use mm2_number::MmNumber;
use primitives::hash::H256;
use rpc::v1::types::Bytes as BytesJson;
use rpc::v1::types::{Bytes as BytesJson, H264 as H264Json};
use serde_json::Value as Json;
use std::ops::Deref;
use std::str::FromStr;
Expand Down Expand Up @@ -269,6 +269,10 @@ impl MarketCoinOps for TendermintToken {

fn my_address(&self) -> MmResult<String, MyAddressError> { self.platform_coin.my_address() }

fn address_from_pubkey(&self, pubkey: &H264Json) -> MmResult<String, AddressFromPubkeyError> {
self.platform_coin.address_from_pubkey(pubkey)
}

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>> {
self.platform_coin.get_public_key().await
}
Expand Down
Loading
Loading