-
Notifications
You must be signed in to change notification settings - Fork 219
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
feat: add persistence of transaction cancellation reason to wallet db #3842
Merged
aviator-app
merged 7 commits into
tari-project:development
from
philipr-za:philip-rejection-reason
Feb 16, 2022
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2a41411
feat: add persistence of transaction cancellation reason to wallet db
philipr-za c5bf59b
test tweak
philipr-za 22f47dd
Test fixes
philipr-za 9575a23
more cucumber fixes
philipr-za 9293cda
JS typo
philipr-za f7a9ae2
moar JS fixes...I hate you JS....I hate you so much
philipr-za 00a804b
Merge branch 'development' into philip-rejection-reason
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ use std::collections::HashMap; | |
use chrono::{DateTime, Local}; | ||
use log::*; | ||
use tari_common_types::transaction::{TransactionDirection, TransactionStatus}; | ||
use tari_wallet::transaction_service::storage::models::TxCancellationReason; | ||
use tokio::runtime::Handle; | ||
use tui::{ | ||
backend::Backend, | ||
|
@@ -96,13 +97,16 @@ impl TransactionsTab { | |
let mut column2_items = Vec::new(); | ||
let mut column3_items = Vec::new(); | ||
for t in windowed_view.iter() { | ||
let text_color = text_colors.get(&t.cancelled).unwrap_or(&Color::Reset).to_owned(); | ||
let text_color = text_colors | ||
.get(&t.cancelled.is_some()) | ||
.unwrap_or(&Color::Reset) | ||
.to_owned(); | ||
if t.direction == TransactionDirection::Outbound { | ||
column0_items.push(ListItem::new(Span::styled( | ||
app_state.get_alias(&t.destination_public_key), | ||
Style::default().fg(text_color), | ||
))); | ||
let amount_style = if t.cancelled { | ||
let amount_style = if t.cancelled.is_some() { | ||
Style::default().fg(Color::Red).add_modifier(Modifier::DIM) | ||
} else { | ||
Style::default().fg(Color::Red) | ||
|
@@ -118,7 +122,7 @@ impl TransactionsTab { | |
app_state.get_alias(&t.source_public_key), | ||
Style::default().fg(text_color), | ||
))); | ||
let amount_style = if t.cancelled { | ||
let amount_style = if t.cancelled.is_some() { | ||
Style::default().fg(Color::Green).add_modifier(Modifier::DIM) | ||
} else { | ||
Style::default().fg(Color::Green) | ||
|
@@ -191,14 +195,14 @@ impl TransactionsTab { | |
let mut column3_items = Vec::new(); | ||
|
||
for t in windowed_view.iter() { | ||
let cancelled = t.cancelled || !t.valid; | ||
let cancelled = t.cancelled.is_some(); | ||
let text_color = text_colors.get(&cancelled).unwrap_or(&Color::Reset).to_owned(); | ||
if t.direction == TransactionDirection::Outbound { | ||
column0_items.push(ListItem::new(Span::styled( | ||
app_state.get_alias(&t.destination_public_key), | ||
Style::default().fg(text_color), | ||
))); | ||
let amount_style = if t.cancelled { | ||
let amount_style = if t.cancelled.is_some() { | ||
Style::default().fg(Color::Red).add_modifier(Modifier::DIM) | ||
} else { | ||
Style::default().fg(Color::Red) | ||
|
@@ -214,7 +218,7 @@ impl TransactionsTab { | |
app_state.get_alias(&t.source_public_key), | ||
Style::default().fg(text_color), | ||
))); | ||
let color = match (t.cancelled, chain_height) { | ||
let color = match (t.cancelled.is_some(), chain_height) { | ||
// cancelled | ||
(true, _) => Color::DarkGray, | ||
// not mature yet | ||
|
@@ -235,14 +239,12 @@ impl TransactionsTab { | |
format!("{}", local_time.format("%Y-%m-%d %H:%M:%S")), | ||
Style::default().fg(text_color), | ||
))); | ||
let status = if (t.cancelled || !t.valid) && t.status == TransactionStatus::Coinbase { | ||
let status = if matches!(t.cancelled, Some(TxCancellationReason::AbandonedCoinbase)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not do something akin to this:
|
||
"Abandoned".to_string() | ||
} else if t.cancelled && t.status == TransactionStatus::Rejected { | ||
"Rejected".to_string() | ||
} else if t.cancelled { | ||
} else if matches!(t.cancelled, Some(TxCancellationReason::UserCancelled)) { | ||
"Cancelled".to_string() | ||
} else if !t.valid { | ||
"Invalid".to_string() | ||
} else if t.cancelled.is_some() { | ||
"Rejected".to_string() | ||
} else { | ||
t.status.to_string() | ||
}; | ||
|
@@ -378,15 +380,12 @@ impl TransactionsTab { | |
Span::styled(format!("{}", tx.fee), Style::default().fg(Color::White)), | ||
fee_details, | ||
]); | ||
let status_msg = if tx.cancelled && tx.status == TransactionStatus::Rejected { | ||
"Rejected".to_string() | ||
} else if tx.cancelled { | ||
"Cancelled".to_string() | ||
} else if !tx.valid { | ||
"Invalid".to_string() | ||
let status_msg = if let Some(reason) = tx.cancelled { | ||
format!("Cancelled: {}", reason) | ||
} else { | ||
tx.status.to_string() | ||
}; | ||
|
||
let status = Span::styled(status_msg, Style::default().fg(Color::White)); | ||
let message = Span::styled(tx.message.as_str(), Style::default().fg(Color::White)); | ||
let local_time = DateTime::<Local>::from_utc(tx.timestamp, Local::now().offset().to_owned()); | ||
|
@@ -396,9 +395,9 @@ impl TransactionsTab { | |
); | ||
let excess = Span::styled(tx.excess_signature.as_str(), Style::default().fg(Color::White)); | ||
let confirmation_count = app_state.get_confirmations(&tx.tx_id); | ||
let confirmations_msg = if tx.status == TransactionStatus::MinedConfirmed && !tx.cancelled { | ||
let confirmations_msg = if tx.status == TransactionStatus::MinedConfirmed && tx.cancelled.is_none() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: a match here would read easier than a nested if.
|
||
format!("{} required confirmations met", required_confirmations) | ||
} else if tx.status == TransactionStatus::MinedUnconfirmed && !tx.cancelled { | ||
} else if tx.status == TransactionStatus::MinedUnconfirmed && tx.cancelled.is_none() { | ||
if let Some(count) = confirmation_count { | ||
format!("{} of {} required confirmations met", count, required_confirmations) | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
base_layer/wallet/migrations/2022-02-14-104456_cancellation_column_update/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file should undo anything in `up.sql` |
60 changes: 60 additions & 0 deletions
60
base_layer/wallet/migrations/2022-02-14-104456_cancellation_column_update/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
PRAGMA foreign_keys=OFF; | ||
|
||
ALTER TABLE completed_transactions | ||
RENAME TO completed_transactions_old; | ||
|
||
CREATE TABLE completed_transactions | ||
( | ||
tx_id BIGINT NOT NULL PRIMARY KEY, | ||
source_public_key BLOB NOT NULL, | ||
destination_public_key BLOB NOT NULL, | ||
amount BIGINT NOT NULL, | ||
fee BIGINT NOT NULL, | ||
transaction_protocol TEXT NOT NULL, | ||
status INTEGER NOT NULL, | ||
message TEXT NOT NULL, | ||
timestamp DATETIME NOT NULL, | ||
cancelled INTEGER NULL, | ||
direction INTEGER, | ||
coinbase_block_height BIGINT, | ||
send_count INTEGER default 0 NOT NULL, | ||
last_send_timestamp DATETIME, | ||
confirmations BIGINT default NULL, | ||
mined_height BIGINT, | ||
mined_in_block BLOB, | ||
transaction_signature_nonce BLOB default 0 NOT NULL, | ||
transaction_signature_key BLOB default 0 NOT NULL | ||
); | ||
|
||
INSERT INTO completed_transactions (tx_id, source_public_key, destination_public_key, amount, fee, transaction_protocol, | ||
status, message, timestamp, cancelled, direction, coinbase_block_height, send_count, | ||
last_send_timestamp, confirmations, mined_height, mined_in_block, transaction_signature_nonce, | ||
transaction_signature_key) | ||
SELECT tx_id, | ||
source_public_key, | ||
destination_public_key, | ||
amount, | ||
fee, | ||
transaction_protocol, | ||
status, | ||
message, | ||
timestamp, | ||
CASE completed_transactions_old.valid --This flag was only ever used to signify an abandoned coinbase, we will do that in the cancelled reason enum now | ||
WHEN 0 | ||
THEN 7 -- This is the value for AbandonedCoinbase | ||
ELSE | ||
NULLIF(cancelled, 0) | ||
END, | ||
direction, | ||
coinbase_block_height, | ||
send_count, | ||
last_send_timestamp, | ||
confirmations, | ||
mined_height, | ||
mined_in_block, | ||
transaction_signature_nonce, | ||
transaction_signature_key | ||
FROM completed_transactions_old; | ||
|
||
DROP TABLE completed_transactions_old; | ||
PRAGMA foreign_keys=ON; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but maybe worth commenting this out instead to show that
12
is still reservedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that is true. Def how it should be done in the future though I don't think its a major issue at the moment as this is just used by the cucumber at this point.