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

decred: Add used address history. #1941

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions assets/decred_node_list.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this and it's usage, removed? merge conflict?

This comment was marked as off-topic.

Copy link
Author

Choose a reason for hiding this comment

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

Oh wait, my bad. The node list was not used. It is only for default nodes correct? The wallet has a list of seeders that it uses to find nodes. This is hardcoded in dcrwallet -> libwallet

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

it adds the nodes that will show in the app, I know that the wallet has a list that it will go through, but if we decided to host our node or the user wanted to add his node, he still will be able to connect through it right?

that's why we have the node_list.yml, so we can keep it organized if we want to add a new node that the users can connect to

Copy link
Author

Choose a reason for hiding this comment

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

Users can add persistent peers currently, which would be one node to connect to.

We can add it back if you want but its much better to leave finding peers to the wallet software by default. The wallet verifies all headers so there is no need for trust here.

Copy link
Author

Choose a reason for hiding this comment

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

These are results from one seeder https://mainnet-seed-1.decred.org/api/addrs

If someone sets a persistent peer, it can no longer use any of those peers, it only connects to the set one.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
-
uri:
is_default: true
-
uri: dcrd.sethforprivacy.com:9108
useSSL: true
Binary file modified assets/images/2.0x/decred.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/3.0x/decred.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/dcr_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/decred.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/decred_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cw_core/lib/receive_page_option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cw_core/enumerate.dart';

class ReceivePageOption implements Enumerate {
static const mainnet = ReceivePageOption._('mainnet');
static const testnet = ReceivePageOption._('testnet');
static const anonPayInvoice = ReceivePageOption._('anonPayInvoice');
static const anonPayDonationLink = ReceivePageOption._('anonPayDonationLink');

Expand Down
4 changes: 2 additions & 2 deletions cw_decred/lib/amount_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ final decredAmountFormat = NumberFormat()
..maximumFractionDigits = decredAmountLength
..minimumFractionDigits = 1;

String decredAmountToString({required int amount}) => decredAmountFormat
.format(cryptoAmountToDouble(amount: amount, divider: decredAmountDivider));
String decredAmountToString({required int amount}) =>
decredAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: decredAmountDivider));

double decredAmountToDouble({required int amount}) =>
cryptoAmountToDouble(amount: amount, divider: decredAmountDivider);
Expand Down
67 changes: 31 additions & 36 deletions cw_decred/lib/api/libdcrwallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import 'package:cw_decred/api/util.dart';

final int ErrCodeNotSynced = 1;

final String libraryName =
Platform.isAndroid || Platform.isLinux // TODO: Linux.
? 'libdcrwallet.so'
: 'cw_decred.framework/cw_decred';
final String libraryName = Platform.isAndroid || Platform.isLinux // TODO: Linux.
? 'libdcrwallet.so'
: 'cw_decred.framework/cw_decred';

final dcrwalletApi = libdcrwallet(DynamicLibrary.open(libraryName));

Expand Down Expand Up @@ -53,14 +52,12 @@ void createWalletSync(Map<String, String> args) {
final network = args["network"]!.toCString();

executePayloadFn(
fn: () =>
dcrwalletApi.createWallet(name, dataDir, network, password, mnemonic),
fn: () => dcrwalletApi.createWallet(name, dataDir, network, password, mnemonic),
ptrsToFree: [name, dataDir, network, password, mnemonic],
);
}

void createWatchOnlyWallet(
String walletName, String datadir, String pubkey, String network) {
void createWatchOnlyWallet(String walletName, String datadir, String pubkey, String network) {
final cName = walletName.toCString();
final cDataDir = datadir.toCString();
final cPub = pubkey.toCString();
Expand All @@ -72,8 +69,7 @@ void createWatchOnlyWallet(
}

/// loadWalletAsync calls the libdcrwallet's loadWallet function asynchronously.
Future<void> loadWalletAsync(
{required String name, required String dataDir, required String net}) {
Future<void> loadWalletAsync({required String name, required String dataDir, required String net}) {
final args = <String, String>{
"name": name,
"dataDir": dataDir,
Expand Down Expand Up @@ -118,8 +114,7 @@ void closeWallet(String walletName) {
);
}

String changeWalletPassword(
String walletName, String currentPassword, String newPassword) {
String changeWalletPassword(String walletName, String currentPassword, String newPassword) {
final cName = walletName.toCString();
final cCurrentPass = currentPassword.toCString();
final cNewPass = newPassword.toCString();
Expand All @@ -140,22 +135,23 @@ String? walletSeed(String walletName, String walletPassword) {
return res.payload;
}

String? currentReceiveAddress(String walletName) {
final cName = walletName.toCString();
final res = executePayloadFn(
fn: () => dcrwalletApi.currentReceiveAddress(cName),
ptrsToFree: [cName],
skipErrorCheck: true, // errCode is checked below, before checking err
);

if (res.errCode == ErrCodeNotSynced) {
// Wallet is not synced. We do not want to give out a used address so give
// nothing.
return null;
}
checkErr(res.err);
return res.payload;
}
// NOTE: Currently unused.
// String? currentReceiveAddress(String walletName) {
// final cName = walletName.toCString();
// final res = executePayloadFn(
// fn: () => dcrwalletApi.currentReceiveAddress(cName),
// ptrsToFree: [cName],
// skipErrorCheck: true, // errCode is checked below, before checking err
// );
//
// if (res.errCode == ErrCodeNotSynced) {
// // Wallet is not synced. We do not want to give out a used address so give
// // nothing.
// return null;
// }
// checkErr(res.err);
// return res.payload;
// }

String syncStatus(String walletName) {
final cName = walletName.toCString();
Expand Down Expand Up @@ -185,13 +181,11 @@ String estimateFee(String walletName, int numBlocks) {
return res.payload;
}

String createSignedTransaction(
String walletName, String createSignedTransactionReq) {
String createSignedTransaction(String walletName, String createSignedTransactionReq) {
final cName = walletName.toCString();
final cCreateSignedTransactionReq = createSignedTransactionReq.toCString();
final res = executePayloadFn(
fn: () => dcrwalletApi.createSignedTransaction(
cName, cCreateSignedTransactionReq),
fn: () => dcrwalletApi.createSignedTransaction(cName, cCreateSignedTransactionReq),
ptrsToFree: [cName, cCreateSignedTransactionReq],
);
return res.payload;
Expand Down Expand Up @@ -246,8 +240,7 @@ String rescanFromHeight(String walletName, String height) {
return res.payload;
}

Future<String> signMessageAsync(
String name, String message, String address, String walletPass) {
Future<String> signMessageAsync(String name, String message, String address, String walletPass) {
final args = <String, String>{
"walletname": name,
"message": message,
Expand Down Expand Up @@ -306,10 +299,12 @@ String defaultPubkey(String walletName) {
return res.payload;
}

String addresses(String walletName) {
String addresses(String walletName, String nUsed, String nUnused) {
final cName = walletName.toCString();
final cNUsed = nUsed.toCString();
final cNUnused = nUnused.toCString();
final res = executePayloadFn(
fn: () => dcrwalletApi.addresses(cName),
fn: () => dcrwalletApi.addresses(cName, cNUsed, cNUnused),
ptrsToFree: [cName],
);
return res.payload;
Expand Down
6 changes: 2 additions & 4 deletions cw_decred/lib/balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class DecredBalance extends Balance {
final int unconfirmed;

@override
String get formattedAvailableBalance =>
decredAmountToString(amount: confirmed);
String get formattedAvailableBalance => decredAmountToString(amount: confirmed);

@override
String get formattedAdditionalBalance =>
decredAmountToString(amount: unconfirmed);
String get formattedAdditionalBalance => decredAmountToString(amount: unconfirmed);
}
3 changes: 1 addition & 2 deletions cw_decred/lib/transaction_credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'package:cw_decred/transaction_priority.dart';
import 'package:cw_core/output_info.dart';

class DecredTransactionCredentials {
DecredTransactionCredentials(this.outputs,
{required this.priority, this.feeRate});
DecredTransactionCredentials(this.outputs, {required this.priority, this.feeRate});

final List<OutputInfo> outputs;
final DecredTransactionPriority? priority;
Expand Down
9 changes: 3 additions & 6 deletions cw_decred/lib/transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ class DecredTransactionHistory extends TransactionHistoryBase<TransactionInfo> {
}

@override
void addOne(TransactionInfo transaction) =>
transactions[transaction.id] = transaction;
void addOne(TransactionInfo transaction) => transactions[transaction.id] = transaction;

@override
void addMany(Map<String, TransactionInfo> transactions) =>
this.transactions.addAll(transactions);
void addMany(Map<String, TransactionInfo> transactions) => this.transactions.addAll(transactions);

@override
Future<void> save() async {}
Expand All @@ -22,8 +20,7 @@ class DecredTransactionHistory extends TransactionHistoryBase<TransactionInfo> {
bool update(Map<String, TransactionInfo> txs) {
var foundOldTx = false;
txs.forEach((_, tx) {
if (!this.transactions.containsKey(tx.id) ||
this.transactions[tx.id]!.isPending) {
if (!this.transactions.containsKey(tx.id) || this.transactions[tx.id]!.isPending) {
this.transactions[tx.id] = tx;
} else {
foundOldTx = true;
Expand Down
12 changes: 4 additions & 8 deletions cw_decred/lib/transaction_priority.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ class DecredTransactionPriority extends TransactionPriority {
: super(title: title, raw: raw);

static const List<DecredTransactionPriority> all = [fast, medium, slow];
static const DecredTransactionPriority slow =
DecredTransactionPriority(title: 'Slow', raw: 0);
static const DecredTransactionPriority slow = DecredTransactionPriority(title: 'Slow', raw: 0);
static const DecredTransactionPriority medium =
DecredTransactionPriority(title: 'Medium', raw: 1);
static const DecredTransactionPriority fast =
DecredTransactionPriority(title: 'Fast', raw: 2);
static const DecredTransactionPriority fast = DecredTransactionPriority(title: 'Fast', raw: 2);

static DecredTransactionPriority deserialize({required int raw}) {
switch (raw) {
Expand All @@ -21,8 +19,7 @@ class DecredTransactionPriority extends TransactionPriority {
case 2:
return fast;
default:
throw Exception(
'Unexpected token: $raw for DecredTransactionPriority deserialize');
throw Exception('Unexpected token: $raw for DecredTransactionPriority deserialize');
}
}

Expand All @@ -34,8 +31,7 @@ class DecredTransactionPriority extends TransactionPriority {

switch (this) {
case DecredTransactionPriority.slow:
label =
'Slow ~24hrs'; // '${S.current.transaction_priority_slow} ~24hrs';
label = 'Slow ~24hrs'; // '${S.current.transaction_priority_slow} ~24hrs';
break;
case DecredTransactionPriority.medium:
label = 'Medium'; // S.current.transaction_priority_medium;
Expand Down
Loading
Loading