Skip to content

Commit

Permalink
Merge pull request #19 from peercoin/v0.1.6
Browse files Browse the repository at this point in the history
V0.1.6
  • Loading branch information
Willy authored Mar 28, 2021
2 parents f9981d9 + 8973d44 commit 2e65609
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 222 deletions.
14 changes: 13 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@
"app_settings_revealAuthButton": "Reveal authentication options",
"app_settings_seed": "Seed phrase",
"app_settings_shareSeed": "Share seed",
"app_settings_auth_header": "Authentication",
"app_settings_appbar": "App Settings",
"app_settings_changeCode": "Change PIN",
"receive_requested_amount": "Requested amount",
"receive_enter_amount": "Please enter an amount",
"receive_share": "Share",
"send_address": "Address",
"send_enter_address": "Please enter an address",
"send_invalid_address": "Invalid address",
Expand Down Expand Up @@ -78,5 +82,13 @@
"authenticate_biometric_hint" : "Verify identity",
"authenticate_biometric_title" : "Authentication required",
"authenticate_title" : "Please enter your PIN",
"authenticate_confirm_title" : "Re-enter your PIN"
"authenticate_title_new" : "Please enter your new PIN",
"authenticate_confirm_title" : "Re-enter your PIN",
"authenticate_confirm_title_new" : "Re-enter your new PIN",
"authenticate_change_pin_success" : "PIN succesfully changed",
"wallet_scan_appBar_title": "Scanning your imported seed",
"wallet_scan_notice": "This might take a while. Don't close this screen!",
"wallet_bottom_nav_receive": "Receive",
"wallet_bottom_nav_tx": "Transactions",
"wallet_bottom_nav_send": "Send"
}
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void main() async {
runApp(MyApp());
}


class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand Down
172 changes: 95 additions & 77 deletions lib/providers/activewallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ActiveWallets with ChangeNotifier {
//wallet is not brand new, lets find an unused address
var unusedAddr;
openWallet.addresses.forEach((walletAddr) {
if (walletAddr.used == false) {
if (walletAddr.used == false && walletAddr.status == null) {
unusedAddr = walletAddr.address;
}
});
Expand Down Expand Up @@ -213,90 +213,108 @@ class ActiveWallets with ChangeNotifier {
notifyListeners();
}

Future<void> putTx(String identifier, String address, Map tx) async {
Future<void> putTx(String identifier, String address, Map tx,
[bool scanMode = false]) async {
CoinWallet openWallet = getSpecificCoinWallet(identifier);
// log("$address puttx: $tx");

//check if that tx is already in the db
List<WalletTransaction> txInWallet = openWallet.transactions;
bool isInWallet = false;
txInWallet.forEach((walletTx) {
if (walletTx.txid == tx["txid"]) {
isInWallet = true;
if (isInWallet == true) {
if (walletTx.timestamp == null) {
//did the tx confirm?
walletTx.newTimestamp = tx["blocktime"];
}
if (tx["confirmations"] != null &&
walletTx.confirmations < tx["confirmations"]) {
//more confirmations?
walletTx.newConfirmations = tx["confirmations"];
if (scanMode == true) {
//write phantom tx that are not displayed in tx list but known to the wallet
//so they won't be parsed again and cause weird display behaviour
openWallet.putTransaction(WalletTransaction(
txid: tx["txid"],
timestamp: -1, //flags phantom tx
value: 0,
fee: 0,
address: address,
direction: "in",
broadCasted: true,
confirmations: 0,
broadcastHex: "",
));
} else {
//check if that tx is already in the db
List<WalletTransaction> txInWallet = openWallet.transactions;
bool isInWallet = false;
txInWallet.forEach((walletTx) {
if (walletTx.txid == tx["txid"]) {
isInWallet = true;
if (isInWallet == true) {
if (walletTx.timestamp == null) {
//did the tx confirm?
walletTx.newTimestamp = tx["blocktime"];
}
if (tx["confirmations"] != null &&
walletTx.confirmations < tx["confirmations"]) {
//more confirmations?
walletTx.newConfirmations = tx["confirmations"];
}
}
}
}
});
//it's not in wallet yet
if (!isInWallet) {
//check if that tx addresses more than one of our addresses
var utxoInWallet = openWallet.utxos
.firstWhere((elem) => elem.hash == tx["txid"], orElse: () => null);
String direction = utxoInWallet == null ? "out" : "in";

if (direction == "in") {
List voutList = tx["vout"].toList();
voutList.forEach((vOut) {
final asMap = vOut as Map;
asMap["scriptPubKey"]["addresses"].forEach((addr) {
if (openWallet.addresses.firstWhere(
(element) => element.address == addr,
orElse: () => null) !=
null) {
//address is ours, add new tx
final txValue = (vOut["value"] * 1000000).toInt();

openWallet.putTransaction(WalletTransaction(
txid: tx["txid"],
timestamp: tx["blocktime"],
value: txValue,
fee: 0,
address: addr,
direction: direction,
broadCasted: true,
confirmations: tx["confirmations"] ?? 0,
broadcastHex: "",
));
}
});
//it's not in wallet yet
if (!isInWallet) {
//check if that tx addresses more than one of our addresses
var utxoInWallet = openWallet.utxos
.firstWhere((elem) => elem.hash == tx["txid"], orElse: () => null);
String direction = utxoInWallet == null ? "out" : "in";

if (direction == "in") {
List voutList = tx["vout"].toList();
voutList.forEach((vOut) {
final asMap = vOut as Map;
asMap["scriptPubKey"]["addresses"].forEach((addr) {
if (openWallet.addresses.firstWhere(
(element) => element.address == addr,
orElse: () => null) !=
null) {
//address is ours, add new tx
final txValue = (vOut["value"] * 1000000).toInt();

openWallet.putTransaction(WalletTransaction(
txid: tx["txid"],
timestamp: tx["blocktime"],
value: txValue,
fee: 0,
address: addr,
direction: direction,
broadCasted: true,
confirmations: tx["confirmations"] ?? 0,
broadcastHex: "",
));
}
});
});
});
} else {
//outgoing tx
openWallet.putTransaction(WalletTransaction(
txid: tx["txid"],
timestamp: tx["blocktime"],
value: tx["outValue"],
fee: tx["outFees"],
address: address,
direction: direction,
broadCasted: false,
confirmations: 0,
broadcastHex: tx["hex"],
));
}
} else {
//outgoing tx
openWallet.putTransaction(WalletTransaction(
txid: tx["txid"],
timestamp: tx["blocktime"],
value: tx["outValue"],
fee: tx["outFees"],
address: address,
direction: direction,
broadCasted: false,
confirmations: 0,
broadcastHex: tx["hex"],
));
}

// trigger notification
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

if (direction == "in")
await flutterLocalNotificationsPlugin.show(
0,
'New transaction received',
tx["txid"],
LocalNotificationSettings.platformChannelSpecifics,
payload: identifier,
);
// trigger notification
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

if (direction == "in")
await flutterLocalNotificationsPlugin.show(
0,
'New transaction received',
tx["txid"],
LocalNotificationSettings.platformChannelSpecifics,
payload: identifier,
);
}
}

notifyListeners();
await openWallet.save();
}
Expand Down
23 changes: 13 additions & 10 deletions lib/providers/electrumconnection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class ElectrumConnection with ChangeNotifier {
ElectrumConnection(this._activeWallets);
int _latestBlock;
bool _closedIntentionally = false;
bool _scanMode = false;

bool init(walletName) {
bool init(walletName, [bool scanMode = false]) {
if (_connection == null) {
_coinName = walletName;
_connectionState = "waiting";
_closedIntentionally = false;
_scanMode = scanMode;
print("init server connection");
connect();
Stream stream = _connection.stream;
Expand Down Expand Up @@ -104,6 +106,7 @@ class ElectrumConnection with ChangeNotifier {
_connection = null;
_addresses = {};
_latestBlock = null;
_scanMode = false;
if (_closedIntentionally == false)
Timer(Duration(seconds: 10),
() => init(_coinName)); //retry if not intentional
Expand Down Expand Up @@ -210,25 +213,19 @@ class ElectrumConnection with ChangeNotifier {

void handleScriptHashSubscribeNotification(
String hashId, String newStatus) async {
//got update notification for hash => get utxo and history list
//got update notification for hash => get utxo
final address = _addresses.keys.firstWhere(
(element) => _addresses[element] == hashId,
orElse: () => null);
print("update for $hashId");
//update status so we flag that we proccessed this update already
await _activeWallets.updateAddressStatus(_coinName, address, newStatus);
//fire listunspent
//fire listunspent to get utxo
sendMessage(
"blockchain.scripthash.listunspent",
"utxo_$address",
[hashId],
);
//fire get_history
sendMessage(
"blockchain.scripthash.get_history",
"history_$address",
[hashId],
);
}

void handleUtxo(String id, List utxos) async {
Expand All @@ -238,6 +235,12 @@ class ElectrumConnection with ChangeNotifier {
txAddr,
utxos,
);
//fire get_history
sendMessage(
"blockchain.scripthash.get_history",
"history_$txAddr",
[_addresses[txAddr]],
);
}

void handleHistory(List result) async {
Expand Down Expand Up @@ -271,7 +274,7 @@ class ElectrumConnection with ChangeNotifier {
String txId = id.replaceFirst("tx_", "");
String addr = await _activeWallets.getAddressForTx(_coinName, txId);
if (tx != null) {
await _activeWallets.putTx(_coinName, addr, tx);
await _activeWallets.putTx(_coinName, addr, tx, _scanMode);
}
}

Expand Down
10 changes: 4 additions & 6 deletions lib/providers/encryptedbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class EncryptedBox with ChangeNotifier {
return _passCode;
}

Future<bool> setPassCode(passCode) async {
if (_passCode == null) {
await _secureStorage.write(key: "passCode", value: passCode);
return true;
}
return false;
Future<bool> setPassCode(String passCode) async {
await _secureStorage.write(key: "passCode", value: passCode);
_passCode = passCode;
return true;
}

Future<Box> getGenericBox(String name) async {
Expand Down
Loading

0 comments on commit 2e65609

Please sign in to comment.