7ff043d8df
* wip * updated gateways 'sign' command * in-wallet verification of mix bonding signature * changed signature of vesting contract trait method * updated wallet bonding endpoints * tauri commands for generating signing payloads * renamed signer to sender * verifying new signatures in the contract * fixed existing mixnet unit tests * unit tests for invalid signatures * fixed other usages of MessageSignature + FromStr * using base58-encoded serialization * removed owner-signature from details response * added ability to construct bonding payloads via nym-cli * removed signature from bonding payload args * moved 'message_type' from 'ContractMessageContent' to 'SignableMessage' * refactor(wallet-rust): rename owner_signature args * feat(wallet-bonding): handle user signature * feat(wallet-bonding): fix bonding * feat(wallet-bonding): fix lint issue * feat(wallet-bonding): ui adjustment * make the location field mandatory for payload signing * feat(wallet-bonding): remove ownersignature field, remove dead code --------- Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> Co-authored-by: Tommy Verrall <tommyvez@protonmail.com>
57 lines
1.5 KiB
Rust
57 lines
1.5 KiB
Rust
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use cosmrs::AccountId;
|
|
use cosmwasm_std::{Addr, Coin as CosmWasmCoin, Decimal};
|
|
use log::error;
|
|
use std::error::Error;
|
|
use std::fmt::Display;
|
|
use validator_client::nyxd::Coin;
|
|
|
|
// TODO: perhaps it should be moved to some global common crate?
|
|
pub fn account_id_to_cw_addr(account_id: &AccountId) -> Addr {
|
|
// the call to unchecked is fine here as we're converting directly from `AccountId`
|
|
// which must have been a valid bech32 address
|
|
Addr::unchecked(account_id.as_ref())
|
|
}
|
|
|
|
pub fn pretty_coin(coin: &Coin) -> String {
|
|
let amount = Decimal::from_ratio(coin.amount, 1_000_000u128);
|
|
let denom = if coin.denom.starts_with('u') {
|
|
&coin.denom[1..]
|
|
} else {
|
|
&coin.denom
|
|
};
|
|
format!("{amount} {denom}")
|
|
}
|
|
|
|
pub fn pretty_cosmwasm_coin(coin: &CosmWasmCoin) -> String {
|
|
let amount = Decimal::from_ratio(coin.amount, 1_000_000u128);
|
|
let denom = if coin.denom.starts_with('u') {
|
|
&coin.denom[1..]
|
|
} else {
|
|
&coin.denom
|
|
};
|
|
format!("{amount} {denom}")
|
|
}
|
|
|
|
pub fn pretty_decimal_with_denom(value: Decimal, denom: &str) -> String {
|
|
// TODO: we might have to truncate the value here (that's why I moved it to separate function)
|
|
format!("{value} {denom}")
|
|
}
|
|
|
|
pub fn show_error<E>(e: E)
|
|
where
|
|
E: Display,
|
|
{
|
|
error!("{}", e);
|
|
}
|
|
|
|
pub fn show_error_passthrough<E>(e: E) -> E
|
|
where
|
|
E: Error + Display,
|
|
{
|
|
error!("{}", e);
|
|
e
|
|
}
|