Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor gui backend fixes #1855

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion common/src/primitives/semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use serde::Serialize;
use serialization::{Decode, Encode};

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Copy, Clone, Serialize)]
pub struct SemVer {
pub major: u8,
pub minor: u8,
Expand Down
3 changes: 2 additions & 1 deletion common/src/primitives/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use serde::Serialize;
use serialization::{Decode, Encode};
use thiserror::Error;
use utils::ensure;
Expand All @@ -23,7 +24,7 @@ const MAX_LENGTH: usize = 24;
///
/// Used to validate the submitted string.
/// The string cannot be too long and can only contain ASCII alphanumeric or punctuation characters.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encode)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Serialize)]
pub struct UserAgent(Vec<u8>);

pub fn mintlayer_core_user_agent() -> UserAgent {
Expand Down
2 changes: 1 addition & 1 deletion node-gui/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ anyhow.workspace = true
chrono.workspace = true
futures.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
serde_with.workspace = true
thiserror.workspace = true
tokio.workspace = true
Expand All @@ -40,4 +41,3 @@ tokio.workspace = true
test-utils = { path = "../../test-utils" }

rstest.workspace = true
serde_json.workspace = true
36 changes: 27 additions & 9 deletions node-gui/backend/src/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ use super::{
messages::{
AccountInfo, AddressInfo, BackendEvent, BackendRequest, CreateDelegationRequest,
DecommissionPoolRequest, DelegateStakingRequest, EncryptionAction, EncryptionState,
SendDelegateToAddressRequest, SendRequest, StakeRequest, TransactionInfo, WalletId,
WalletInfo,
SendDelegateToAddressRequest, SendRequest, StakeRequest, Transaction, TransactionInfo,
WalletId, WalletInfo,
},
p2p_event_handler::P2pEventHandler,
parse_address, parse_coin_amount,
Expand Down Expand Up @@ -721,7 +721,10 @@ impl Backend {
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;

Ok(TransactionInfo { wallet_id, tx })
Ok(TransactionInfo {
wallet_id,
tx: Transaction::new(tx),
})
}

async fn stake_amount(
Expand Down Expand Up @@ -769,7 +772,10 @@ impl Backend {
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;

Ok(TransactionInfo { wallet_id, tx })
Ok(TransactionInfo {
wallet_id,
tx: Transaction::new(tx),
})
}

async fn decommission_pool(
Expand Down Expand Up @@ -798,7 +804,10 @@ impl Backend {
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;

Ok(TransactionInfo { wallet_id, tx })
Ok(TransactionInfo {
wallet_id,
tx: Transaction::new(tx),
})
}

async fn create_delegation(
Expand Down Expand Up @@ -827,7 +836,10 @@ impl Backend {
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;

Ok(TransactionInfo { wallet_id, tx })
Ok(TransactionInfo {
wallet_id,
tx: Transaction::new(tx),
})
}

async fn delegate_staking(
Expand Down Expand Up @@ -863,7 +875,10 @@ impl Backend {
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;

Ok(TransactionInfo { wallet_id, tx })
Ok(TransactionInfo {
wallet_id,
tx: Transaction::new(tx),
})
}

async fn send_delegation_to_address(
Expand Down Expand Up @@ -903,7 +918,10 @@ impl Backend {
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;

Ok(TransactionInfo { wallet_id, tx })
Ok(TransactionInfo {
wallet_id,
tx: Transaction::new(tx),
})
}

async fn submit_transaction(
Expand Down Expand Up @@ -1019,7 +1037,7 @@ impl Backend {
);
}
BackendRequest::SubmitTx { wallet_id, tx } => {
let result = self.submit_transaction(wallet_id, tx).await;
let result = self.submit_transaction(wallet_id, tx.take_tx()).await;
Self::send_event(&self.event_tx, BackendEvent::Broadcast(result));
}
BackendRequest::TransactionList {
Expand Down
2 changes: 2 additions & 0 deletions node-gui/backend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum BackendError {
WalletError(String),
#[error("RPC error: {0}")]
RpcError(String),
#[error("Json error: {0}")]
JsonError(String),
azarovh marked this conversation as resolved.
Show resolved Hide resolved
#[error("Unknown wallet index: {0:?}")]
UnknownWalletIndex(WalletId),
#[error("Unknown account index: {0:?}/{0:?}")]
Expand Down
17 changes: 10 additions & 7 deletions node-gui/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod error;
pub mod messages;

mod backend_impl;
mod chainstate_event_handler;
mod error;
mod p2p_event_handler;
mod wallet_events;

mod account_id;
pub use account_id::AccountId;

use chainstate::ChainInfo;
use common::address::{Address, AddressError};
use common::chain::{ChainConfig, Destination};
use common::primitives::{Amount, BlockHeight};
use common::time_getter::TimeGetter;
use node_lib::{Command, RunOptions};
use std::fmt::Debug;
use std::sync::Arc;

use chainstate::ChainInfo;
use common::{
address::{Address, AddressError},
chain::{ChainConfig, Destination},
primitives::{Amount, BlockHeight},
time_getter::TimeGetter,
};
use node_lib::{Command, RunOptions};
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};

use crate::chainstate_event_handler::ChainstateEventHandler;
Expand Down
35 changes: 30 additions & 5 deletions node-gui/backend/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use serde::{Deserialize, Serialize};

use chainstate::ChainInfo;
use common::{
chain::{DelegationId, GenBlock, PoolId, SignedTransaction},
chain::{ChainConfig, DelegationId, GenBlock, PoolId, SignedTransaction},
primitives::{Amount, BlockHeight, Id},
text_summary::TextSummary,
};
use crypto::key::hdkd::child_number::ChildNumber;
use p2p::P2pEvent;
Expand Down Expand Up @@ -149,11 +150,35 @@ pub struct SendDelegateToAddressRequest {
pub delegation_id: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Transaction {
azarovh marked this conversation as resolved.
Show resolved Hide resolved
#[serde(with = "hex_encoded_serialization")]
tx: SignedTransaction,
}

impl Transaction {
pub fn new(tx: SignedTransaction) -> Self {
Self { tx }
}

pub fn take_tx(self) -> SignedTransaction {
self.tx
}

pub fn text_summary(&self, config: &ChainConfig) -> String {
self.tx.transaction().text_summary(config)
}

pub fn to_json(&self, config: &ChainConfig) -> Result<serde_json::Value, BackendError> {
common::address::dehexify::to_dehexified_json(config, self.tx.transaction())
.map_err(|e| BackendError::JsonError(e.to_string()))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of missed the fact that Transaction is serializable. So now I'm wondering why SignedTransaction shouldn't be

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, my guess would be that we don't have a use case for serializing witnesses

}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TransactionInfo {
pub wallet_id: WalletId,
#[serde(with = "hex_encoded_serialization")]
pub tx: SignedTransaction,
pub tx: Transaction,
}

#[derive(Debug)]
Expand Down Expand Up @@ -211,7 +236,7 @@ pub enum BackendRequest {

SubmitTx {
wallet_id: WalletId,
tx: SignedTransaction,
tx: Transaction,
},

TransactionList {
Expand Down
7 changes: 4 additions & 3 deletions node-gui/src/main_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ use std::{collections::BTreeMap, convert::identity, path::PathBuf, sync::Arc, ti

use chainstate::ChainInfo;
use common::{
chain::{block::timestamp::BlockTimestamp, ChainConfig, SignedTransaction},
chain::{block::timestamp::BlockTimestamp, ChainConfig},
primitives::{per_thousand::PerThousand, semver::SemVer, user_agent::UserAgent, Amount},
};
use iced::{widget::Text, window, Command, Element};
use iced_aw::widgets::Modal;
use logging::log;
use node_gui_backend::{
messages::{
BackendEvent, BackendRequest, EncryptionAction, TransactionInfo, WalletId, WalletInfo,
BackendEvent, BackendRequest, EncryptionAction, Transaction, TransactionInfo, WalletId,
WalletInfo,
},
BackendSender, ImportOrCreate, InitializedNode,
};
Expand Down Expand Up @@ -187,7 +188,7 @@ pub enum MainWindowMessage {

SubmitTx {
wallet_id: WalletId,
tx: SignedTransaction,
tx: Transaction,
},

CopyToClipboard(String),
Expand Down
17 changes: 8 additions & 9 deletions node-gui/src/widgets/confirm_broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,29 @@

use std::sync::Arc;

use common::{
chain::{ChainConfig, SignedTransaction},
text_summary::TextSummary,
};
use iced::{
alignment::Horizontal,
widget::{self, container, Button, Component, Text},
Element, Length, Theme,
};
use iced_aw::Card;

use common::chain::ChainConfig;
use node_gui_backend::messages::Transaction;

pub struct ConfirmBroadcast<Message> {
on_submit: Box<dyn Fn(SignedTransaction) -> Message>,
on_submit: Box<dyn Fn(Transaction) -> Message>,
on_close: Box<dyn Fn() -> Message>,
on_copy_to_clipboard: Box<dyn Fn(String) -> Message>,
tx: SignedTransaction,
tx: Transaction,
chain_config: Arc<ChainConfig>,
}

pub fn new_confirm_broadcast<Message>(
on_submit: Box<dyn Fn(SignedTransaction) -> Message>,
on_submit: Box<dyn Fn(Transaction) -> Message>,
on_close: Box<dyn Fn() -> Message>,
on_copy_to_clipboard: Box<dyn Fn(String) -> Message>,
tx: SignedTransaction,
tx: Transaction,
chain_config: Arc<ChainConfig>,
) -> ConfirmBroadcast<Message> {
ConfirmBroadcast {
Expand Down Expand Up @@ -73,7 +72,7 @@ impl<Message> Component<Message, Theme, iced::Renderer> for ConfirmBroadcast<Mes
}

fn view(&self, _state: &Self::State) -> Element<Self::Event, Theme, iced::Renderer> {
let summary = self.tx.transaction().text_summary(&self.chain_config);
let summary = self.tx.text_summary(&self.chain_config);

let button = Button::new(
Text::new("Confirm and broadcast").horizontal_alignment(Horizontal::Center),
Expand Down
4 changes: 3 additions & 1 deletion p2p/types/src/p2p_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

use std::sync::Arc;

use serde::Serialize;

use common::primitives::{semver::SemVer, user_agent::UserAgent};

use crate::{peer_id::PeerId, services::Services};

pub type P2pEventHandler = Arc<dyn Fn(P2pEvent) + Send + Sync>;

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub enum P2pEvent {
PeerConnected {
id: PeerId,
Expand Down
3 changes: 2 additions & 1 deletion p2p/types/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use serde::Serialize;
use serialization::{Decode, Encode};

#[derive(Eq, PartialEq, Clone, Copy, Debug)]
Expand All @@ -27,7 +28,7 @@ impl Service {
pub const ALL: [Service; 3] = [Service::Transactions, Service::Blocks, Service::PeerAddresses];
}

#[derive(Eq, PartialEq, Clone, Copy, Debug, Encode, Decode)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Encode, Decode, Serialize)]
pub struct Services(u64);

impl Services {
Expand Down
1 change: 1 addition & 0 deletions wallet/wallet-cli-commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ humantime.workspace = true
hex.workspace = true
itertools.workspace = true
reedline = { workspace = true, features = ["external_printer"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
shlex.workspace = true
thiserror.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet-cli-commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ pub enum ManageableWalletCommand {
WalletCommands(WalletCommand),
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize)]
pub enum ConsoleCommand {
Print(String),
ClearScreen,
Expand Down
Loading