2024-04-20 23:20:52 +00:00
|
|
|
import 'dart:async';
|
2024-04-25 14:23:01 +00:00
|
|
|
import 'dart:math';
|
2024-04-27 13:26:43 +00:00
|
|
|
import 'package:collection/collection.dart';
|
2024-04-22 16:18:18 +00:00
|
|
|
import 'package:convert/convert.dart';
|
2024-04-22 23:26:34 +00:00
|
|
|
import 'package:crypto/crypto.dart';
|
2024-06-08 12:26:48 +00:00
|
|
|
import 'package:cw_core/cake_hive.dart';
|
|
|
|
import 'package:cw_core/mweb_utxo.dart';
|
2024-07-01 17:05:07 +00:00
|
|
|
import 'package:cw_mweb/mwebd.pbgrpc.dart';
|
2024-04-25 14:23:01 +00:00
|
|
|
import 'package:fixnum/fixnum.dart';
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
|
2024-04-23 12:37:44 +00:00
|
|
|
import 'package:cw_bitcoin/bitcoin_unspent.dart';
|
2024-04-22 16:18:18 +00:00
|
|
|
import 'package:cw_bitcoin/electrum_transaction_info.dart';
|
2024-04-26 11:32:38 +00:00
|
|
|
import 'package:cw_bitcoin/pending_bitcoin_transaction.dart';
|
2024-04-28 10:17:28 +00:00
|
|
|
import 'package:cw_bitcoin/utils.dart';
|
2022-10-12 17:09:57 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2024-04-25 14:23:01 +00:00
|
|
|
import 'package:cw_core/pending_transaction.dart';
|
2024-04-21 11:19:44 +00:00
|
|
|
import 'package:cw_core/sync_status.dart';
|
2024-04-22 16:18:18 +00:00
|
|
|
import 'package:cw_core/transaction_direction.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_core/unspent_coins_info.dart';
|
|
|
|
import 'package:cw_bitcoin/litecoin_wallet_addresses.dart';
|
|
|
|
import 'package:cw_core/transaction_priority.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cw_core/wallet_info.dart';
|
2024-04-22 16:18:18 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_bitcoin/electrum_wallet_snapshot.dart';
|
|
|
|
import 'package:cw_bitcoin/electrum_wallet.dart';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
|
|
|
import 'package:cw_bitcoin/electrum_balance.dart';
|
|
|
|
import 'package:cw_bitcoin/litecoin_network.dart';
|
2024-04-20 23:20:52 +00:00
|
|
|
import 'package:cw_mweb/cw_mweb.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
|
Bitcoin derivations (#1089)
* - Update and Fix Conflicts with main
* Add Balances for ERC20 tokens
* Fix conflicts with main
* Add erc20 abi json
* Add send erc20 tokens initial function
* add missing getHeightByDate in Haven [skip ci]
* Allow contacts and wallets from the same tag
* Add Shiba Inu icon
* Add send ERC-20 tokens initial flow
* Add missing import in generated file
* Add initial approach for transaction sending for ERC-20 tokens
* Refactor signing/sending transactions
* Add initial flow for transactions subscription
* Refactor signing/sending transactions
* Add home settings icon
* Fix conflicts with main
* Initial flow for home settings
* Add logic flow for adding erc20 tokens
* Fix initial UI
* Finalize UI for Tokens
* Integrate UI with Ethereum flow
* Add "Enable/Disable" feature for ERC20 tokens
* Add initial Erc20 tokens
* Add Sorting and Pin Native Token features
* Fix price sorting
* Sort tokens list as well when Sort criteria changes
* - Improve sorting balances flow
- Add initial add token from search bar flow
* Fix Accounts Popup UI
* Fix Pin native token
* Fix Enabling/Disabling tokens
Fix sorting by fiat once app is opened
Improve token availability mechanism
* Fix deleting token
Fix renaming tokens
* Fix issue with search
* Add more tokens
* - Fix scroll issue
- Add ERC20 tokens placeholder image in picker
* - Separate and organize default erc20 tokens
- Fix scrolling
- Add token placeholder images in picker
- Sort disabled tokens alphabetically
* Change BNB token initial availability [skip ci]
* Fix Conflicts with main
* Fix Conflicts with main
* Add Verse ERC20 token to the initial tokens list
* Add rename wallet to Ethereum
* Integrate EtherScan API for fetching address transactions
Generate Ethereum specific secrets in Ethereum package
* Adjust transactions fiat price for ERC20 tokens
* Free Up GitHub Actions Ubuntu Runner Disk Space
* Free Up GitHub Actions Ubuntu Runner Disk space (trial 2)
* Fix Transaction Fee display
* Save transaction history
* Enhance loading time for erc20 tokens transactions
* Minor Fixes and Enhancements
* Fix sending erc20
fix block explorer issue
* Fix int overflow
* Fix transaction amount conversions
* Minor: `slow` -> `Slow` [skip-ci]
* initial changes
* more base config stuff
* config changes
* successfully builds!
* save
* successfully add nano wallet
* save
* seed generation
* receive screen + node screen working
* tx history working and fiat fixes
* balance working
* derivation updates
* nano-unfinished
* sends working
* remove fees from send screen, send and receive transactions working
* fixes + auto receive incoming txs
* fix for scanning QR codes
* save
* update translations
* fixes
* more fixes
* more strings
* small fix
* fix github actions workflow
* potential fix
* potential fix
* ci/cd fix
* change rep working
* seed generation fixes
* fixes
* save
* change rep screen functional
* save
* banano changes
* fixes, start adding ui for PoW
* pow node changes
* update translations
* fix
* account changing barely working
* save
* disable account generation
* small fix
* save
* UI work
* save
* fixes after merge main
* fixes
* remove monero stuff, work on derivation ui
* lots of fixes + finish up seed derivation
* last minute fixes
* node related fixes
* more fixes
* small fix
* more fixes
* fixes
* pretty big refactor for pow, still some bugs
* finally works!
* get transactions after send
* fix
* merge conflict fixes
* save
* fix pow node showing up twice
* done
* initial changes
* small fix
* more merge fixes
* fixes
* more fixes
* fix
* save
* fix manage pow nodes setting appearing on other wallets
* fix contact bug
* fixes
* fiat fixes
* save
* save
* save
* save
* updates
* cleanup
* restore fix
* fixes
* remove deprecated alert
* fix
* small fix
* remove outdated warning
* electrum restore fixes
* fixes
* fixes
* fix
* derivation fixes
* nano fixes pt.1
* nano fixes pt.2
* bip39 fixes
* pownode refactor
* nodes pages fixes
* observer fix
* ssl fix
* remove old references
* remove unused imports
* code cleanup
* small fix
* small potential fix
* save
* derivation fixes
* deterministic fix
* fix pt.2
* derivation class fixes
* review fixes from nano that also apply here
* formatting
* stuff that should've stayed deleted
* post merge fixes
* remove problematic imports and duplicate changes
* Delete lib/nano/nano.dart
* move wallet restore page proxy code to the view model
* fix dashboard page indicators being the same color
* debatably better refactoring of derivationInfo, migration needed
* additional refactor improvements
* blanket comment some stuff out to narrow down this issue
* refactor fixes
* fix nano exchange
* fix , bug, i.e. replace , with . when making a nano transaction
* fix nano sending, update restore page wording, and other minor fixes
* write migration for existing bitcoin and nano wallets
* merge fixes
* minor fixes
* use default derivation type when restoring from qr code
* fixes for restoring
* fixes
* fixes
* merge fix
* Fix issues with Creating Electrum and Restoring Bip39
* updates & fixes
* Add missing case for no transactions BIP39 wallet restore
* Make the default BIP39 the 84 derivation path
* Add Samourai Deposit
* litecoin mnemonic error fix
* Bip39 passphrase support (#1412)
* save
* passphrase working
* fix for when loading wallets + translation update
* minor fix
* Fix Nano
* minor fix [skip ci]
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
* change error state seed conditions into throwables [skip ci]
* litecoin fixes
* Bip39 minor enhancements (#1416)
* minor enhancements
* rename bitcoin_derivations -> electrum_derivations
* Remove duplicate derivations
handle default case
* minor fix
* Enable passphrase for Litecoin
* obscure text of passphrase
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Justin Ehrenhofer <justin.ehrenhofer@gmail.com>
Co-authored-by: fossephate <fosse@book.local>
2024-04-30 00:49:56 +00:00
|
|
|
import 'package:bip39/bip39.dart' as bip39;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
part 'litecoin_wallet.g.dart';
|
|
|
|
|
|
|
|
class LitecoinWallet = LitecoinWalletBase with _$LitecoinWallet;
|
|
|
|
|
|
|
|
abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
LitecoinWalletBase({
|
|
|
|
required String mnemonic,
|
|
|
|
required String password,
|
|
|
|
required WalletInfo walletInfo,
|
|
|
|
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
|
|
|
required Uint8List seedBytes,
|
|
|
|
String? addressPageType,
|
|
|
|
List<BitcoinAddressRecord>? initialAddresses,
|
|
|
|
ElectrumBalance? initialBalance,
|
|
|
|
Map<String, int>? initialRegularAddressIndex,
|
|
|
|
Map<String, int>? initialChangeAddressIndex,
|
2024-06-24 19:48:42 +00:00
|
|
|
int? initialMwebHeight,
|
2024-07-22 17:08:19 +00:00
|
|
|
bool? alwaysScan,
|
2024-05-29 15:54:50 +00:00
|
|
|
}) : mwebHd =
|
|
|
|
bitcoin.HDWallet.fromSeed(seedBytes, network: litecoinNetwork).derivePath("m/1000'"),
|
|
|
|
super(
|
2024-06-24 19:48:42 +00:00
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
|
|
|
networkType: litecoinNetwork,
|
|
|
|
initialAddresses: initialAddresses,
|
|
|
|
initialBalance: initialBalance,
|
|
|
|
seedBytes: seedBytes,
|
|
|
|
currency: CryptoCurrency.ltc,
|
|
|
|
) {
|
2024-07-22 17:08:19 +00:00
|
|
|
mwebEnabled = alwaysScan ?? false;
|
2021-12-24 12:52:08 +00:00
|
|
|
walletAddresses = LitecoinWalletAddresses(
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
walletInfo,
|
|
|
|
initialAddresses: initialAddresses,
|
|
|
|
initialRegularAddressIndex: initialRegularAddressIndex,
|
|
|
|
initialChangeAddressIndex: initialChangeAddressIndex,
|
|
|
|
mainHd: hd,
|
2024-05-05 01:44:50 +00:00
|
|
|
sideHd: accountHD.derive(1),
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
network: network,
|
2024-05-17 07:06:06 +00:00
|
|
|
mwebHd: mwebHd,
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
);
|
2024-01-23 05:15:24 +00:00
|
|
|
autorun((_) {
|
|
|
|
this.walletAddresses.isEnabledAutoGenerateSubaddress = this.isEnabledAutoGenerateSubaddress;
|
|
|
|
});
|
2024-07-11 17:54:44 +00:00
|
|
|
CwMweb.stub().then((value) {
|
|
|
|
_stub = value;
|
|
|
|
});
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 16:18:18 +00:00
|
|
|
final bitcoin.HDWallet mwebHd;
|
2024-06-08 12:26:48 +00:00
|
|
|
late final Box<MwebUtxo> mwebUtxosBox;
|
2024-05-29 15:54:50 +00:00
|
|
|
Timer? _syncTimer;
|
2024-07-17 21:32:07 +00:00
|
|
|
StreamSubscription<Utxo>? _utxoStream;
|
2024-06-24 19:48:42 +00:00
|
|
|
int mwebUtxosHeight = 0;
|
2024-07-11 17:54:44 +00:00
|
|
|
late RpcClient _stub;
|
2024-07-22 17:08:19 +00:00
|
|
|
late bool mwebEnabled;
|
2024-04-22 16:18:18 +00:00
|
|
|
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
static Future<LitecoinWallet> create(
|
|
|
|
{required String mnemonic,
|
|
|
|
required String password,
|
|
|
|
required WalletInfo walletInfo,
|
|
|
|
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
Bitcoin derivations (#1089)
* - Update and Fix Conflicts with main
* Add Balances for ERC20 tokens
* Fix conflicts with main
* Add erc20 abi json
* Add send erc20 tokens initial function
* add missing getHeightByDate in Haven [skip ci]
* Allow contacts and wallets from the same tag
* Add Shiba Inu icon
* Add send ERC-20 tokens initial flow
* Add missing import in generated file
* Add initial approach for transaction sending for ERC-20 tokens
* Refactor signing/sending transactions
* Add initial flow for transactions subscription
* Refactor signing/sending transactions
* Add home settings icon
* Fix conflicts with main
* Initial flow for home settings
* Add logic flow for adding erc20 tokens
* Fix initial UI
* Finalize UI for Tokens
* Integrate UI with Ethereum flow
* Add "Enable/Disable" feature for ERC20 tokens
* Add initial Erc20 tokens
* Add Sorting and Pin Native Token features
* Fix price sorting
* Sort tokens list as well when Sort criteria changes
* - Improve sorting balances flow
- Add initial add token from search bar flow
* Fix Accounts Popup UI
* Fix Pin native token
* Fix Enabling/Disabling tokens
Fix sorting by fiat once app is opened
Improve token availability mechanism
* Fix deleting token
Fix renaming tokens
* Fix issue with search
* Add more tokens
* - Fix scroll issue
- Add ERC20 tokens placeholder image in picker
* - Separate and organize default erc20 tokens
- Fix scrolling
- Add token placeholder images in picker
- Sort disabled tokens alphabetically
* Change BNB token initial availability [skip ci]
* Fix Conflicts with main
* Fix Conflicts with main
* Add Verse ERC20 token to the initial tokens list
* Add rename wallet to Ethereum
* Integrate EtherScan API for fetching address transactions
Generate Ethereum specific secrets in Ethereum package
* Adjust transactions fiat price for ERC20 tokens
* Free Up GitHub Actions Ubuntu Runner Disk Space
* Free Up GitHub Actions Ubuntu Runner Disk space (trial 2)
* Fix Transaction Fee display
* Save transaction history
* Enhance loading time for erc20 tokens transactions
* Minor Fixes and Enhancements
* Fix sending erc20
fix block explorer issue
* Fix int overflow
* Fix transaction amount conversions
* Minor: `slow` -> `Slow` [skip-ci]
* initial changes
* more base config stuff
* config changes
* successfully builds!
* save
* successfully add nano wallet
* save
* seed generation
* receive screen + node screen working
* tx history working and fiat fixes
* balance working
* derivation updates
* nano-unfinished
* sends working
* remove fees from send screen, send and receive transactions working
* fixes + auto receive incoming txs
* fix for scanning QR codes
* save
* update translations
* fixes
* more fixes
* more strings
* small fix
* fix github actions workflow
* potential fix
* potential fix
* ci/cd fix
* change rep working
* seed generation fixes
* fixes
* save
* change rep screen functional
* save
* banano changes
* fixes, start adding ui for PoW
* pow node changes
* update translations
* fix
* account changing barely working
* save
* disable account generation
* small fix
* save
* UI work
* save
* fixes after merge main
* fixes
* remove monero stuff, work on derivation ui
* lots of fixes + finish up seed derivation
* last minute fixes
* node related fixes
* more fixes
* small fix
* more fixes
* fixes
* pretty big refactor for pow, still some bugs
* finally works!
* get transactions after send
* fix
* merge conflict fixes
* save
* fix pow node showing up twice
* done
* initial changes
* small fix
* more merge fixes
* fixes
* more fixes
* fix
* save
* fix manage pow nodes setting appearing on other wallets
* fix contact bug
* fixes
* fiat fixes
* save
* save
* save
* save
* updates
* cleanup
* restore fix
* fixes
* remove deprecated alert
* fix
* small fix
* remove outdated warning
* electrum restore fixes
* fixes
* fixes
* fix
* derivation fixes
* nano fixes pt.1
* nano fixes pt.2
* bip39 fixes
* pownode refactor
* nodes pages fixes
* observer fix
* ssl fix
* remove old references
* remove unused imports
* code cleanup
* small fix
* small potential fix
* save
* derivation fixes
* deterministic fix
* fix pt.2
* derivation class fixes
* review fixes from nano that also apply here
* formatting
* stuff that should've stayed deleted
* post merge fixes
* remove problematic imports and duplicate changes
* Delete lib/nano/nano.dart
* move wallet restore page proxy code to the view model
* fix dashboard page indicators being the same color
* debatably better refactoring of derivationInfo, migration needed
* additional refactor improvements
* blanket comment some stuff out to narrow down this issue
* refactor fixes
* fix nano exchange
* fix , bug, i.e. replace , with . when making a nano transaction
* fix nano sending, update restore page wording, and other minor fixes
* write migration for existing bitcoin and nano wallets
* merge fixes
* minor fixes
* use default derivation type when restoring from qr code
* fixes for restoring
* fixes
* fixes
* merge fix
* Fix issues with Creating Electrum and Restoring Bip39
* updates & fixes
* Add missing case for no transactions BIP39 wallet restore
* Make the default BIP39 the 84 derivation path
* Add Samourai Deposit
* litecoin mnemonic error fix
* Bip39 passphrase support (#1412)
* save
* passphrase working
* fix for when loading wallets + translation update
* minor fix
* Fix Nano
* minor fix [skip ci]
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
* change error state seed conditions into throwables [skip ci]
* litecoin fixes
* Bip39 minor enhancements (#1416)
* minor enhancements
* rename bitcoin_derivations -> electrum_derivations
* Remove duplicate derivations
handle default case
* minor fix
* Enable passphrase for Litecoin
* obscure text of passphrase
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Justin Ehrenhofer <justin.ehrenhofer@gmail.com>
Co-authored-by: fossephate <fosse@book.local>
2024-04-30 00:49:56 +00:00
|
|
|
String? passphrase,
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
String? addressPageType,
|
|
|
|
List<BitcoinAddressRecord>? initialAddresses,
|
|
|
|
ElectrumBalance? initialBalance,
|
|
|
|
Map<String, int>? initialRegularAddressIndex,
|
|
|
|
Map<String, int>? initialChangeAddressIndex}) async {
|
Bitcoin derivations (#1089)
* - Update and Fix Conflicts with main
* Add Balances for ERC20 tokens
* Fix conflicts with main
* Add erc20 abi json
* Add send erc20 tokens initial function
* add missing getHeightByDate in Haven [skip ci]
* Allow contacts and wallets from the same tag
* Add Shiba Inu icon
* Add send ERC-20 tokens initial flow
* Add missing import in generated file
* Add initial approach for transaction sending for ERC-20 tokens
* Refactor signing/sending transactions
* Add initial flow for transactions subscription
* Refactor signing/sending transactions
* Add home settings icon
* Fix conflicts with main
* Initial flow for home settings
* Add logic flow for adding erc20 tokens
* Fix initial UI
* Finalize UI for Tokens
* Integrate UI with Ethereum flow
* Add "Enable/Disable" feature for ERC20 tokens
* Add initial Erc20 tokens
* Add Sorting and Pin Native Token features
* Fix price sorting
* Sort tokens list as well when Sort criteria changes
* - Improve sorting balances flow
- Add initial add token from search bar flow
* Fix Accounts Popup UI
* Fix Pin native token
* Fix Enabling/Disabling tokens
Fix sorting by fiat once app is opened
Improve token availability mechanism
* Fix deleting token
Fix renaming tokens
* Fix issue with search
* Add more tokens
* - Fix scroll issue
- Add ERC20 tokens placeholder image in picker
* - Separate and organize default erc20 tokens
- Fix scrolling
- Add token placeholder images in picker
- Sort disabled tokens alphabetically
* Change BNB token initial availability [skip ci]
* Fix Conflicts with main
* Fix Conflicts with main
* Add Verse ERC20 token to the initial tokens list
* Add rename wallet to Ethereum
* Integrate EtherScan API for fetching address transactions
Generate Ethereum specific secrets in Ethereum package
* Adjust transactions fiat price for ERC20 tokens
* Free Up GitHub Actions Ubuntu Runner Disk Space
* Free Up GitHub Actions Ubuntu Runner Disk space (trial 2)
* Fix Transaction Fee display
* Save transaction history
* Enhance loading time for erc20 tokens transactions
* Minor Fixes and Enhancements
* Fix sending erc20
fix block explorer issue
* Fix int overflow
* Fix transaction amount conversions
* Minor: `slow` -> `Slow` [skip-ci]
* initial changes
* more base config stuff
* config changes
* successfully builds!
* save
* successfully add nano wallet
* save
* seed generation
* receive screen + node screen working
* tx history working and fiat fixes
* balance working
* derivation updates
* nano-unfinished
* sends working
* remove fees from send screen, send and receive transactions working
* fixes + auto receive incoming txs
* fix for scanning QR codes
* save
* update translations
* fixes
* more fixes
* more strings
* small fix
* fix github actions workflow
* potential fix
* potential fix
* ci/cd fix
* change rep working
* seed generation fixes
* fixes
* save
* change rep screen functional
* save
* banano changes
* fixes, start adding ui for PoW
* pow node changes
* update translations
* fix
* account changing barely working
* save
* disable account generation
* small fix
* save
* UI work
* save
* fixes after merge main
* fixes
* remove monero stuff, work on derivation ui
* lots of fixes + finish up seed derivation
* last minute fixes
* node related fixes
* more fixes
* small fix
* more fixes
* fixes
* pretty big refactor for pow, still some bugs
* finally works!
* get transactions after send
* fix
* merge conflict fixes
* save
* fix pow node showing up twice
* done
* initial changes
* small fix
* more merge fixes
* fixes
* more fixes
* fix
* save
* fix manage pow nodes setting appearing on other wallets
* fix contact bug
* fixes
* fiat fixes
* save
* save
* save
* save
* updates
* cleanup
* restore fix
* fixes
* remove deprecated alert
* fix
* small fix
* remove outdated warning
* electrum restore fixes
* fixes
* fixes
* fix
* derivation fixes
* nano fixes pt.1
* nano fixes pt.2
* bip39 fixes
* pownode refactor
* nodes pages fixes
* observer fix
* ssl fix
* remove old references
* remove unused imports
* code cleanup
* small fix
* small potential fix
* save
* derivation fixes
* deterministic fix
* fix pt.2
* derivation class fixes
* review fixes from nano that also apply here
* formatting
* stuff that should've stayed deleted
* post merge fixes
* remove problematic imports and duplicate changes
* Delete lib/nano/nano.dart
* move wallet restore page proxy code to the view model
* fix dashboard page indicators being the same color
* debatably better refactoring of derivationInfo, migration needed
* additional refactor improvements
* blanket comment some stuff out to narrow down this issue
* refactor fixes
* fix nano exchange
* fix , bug, i.e. replace , with . when making a nano transaction
* fix nano sending, update restore page wording, and other minor fixes
* write migration for existing bitcoin and nano wallets
* merge fixes
* minor fixes
* use default derivation type when restoring from qr code
* fixes for restoring
* fixes
* fixes
* merge fix
* Fix issues with Creating Electrum and Restoring Bip39
* updates & fixes
* Add missing case for no transactions BIP39 wallet restore
* Make the default BIP39 the 84 derivation path
* Add Samourai Deposit
* litecoin mnemonic error fix
* Bip39 passphrase support (#1412)
* save
* passphrase working
* fix for when loading wallets + translation update
* minor fix
* Fix Nano
* minor fix [skip ci]
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
* change error state seed conditions into throwables [skip ci]
* litecoin fixes
* Bip39 minor enhancements (#1416)
* minor enhancements
* rename bitcoin_derivations -> electrum_derivations
* Remove duplicate derivations
handle default case
* minor fix
* Enable passphrase for Litecoin
* obscure text of passphrase
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Justin Ehrenhofer <justin.ehrenhofer@gmail.com>
Co-authored-by: fossephate <fosse@book.local>
2024-04-30 00:49:56 +00:00
|
|
|
late Uint8List seedBytes;
|
|
|
|
|
|
|
|
switch (walletInfo.derivationInfo?.derivationType) {
|
|
|
|
case DerivationType.bip39:
|
|
|
|
seedBytes = await bip39.mnemonicToSeed(
|
|
|
|
mnemonic,
|
|
|
|
passphrase: passphrase ?? "",
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case DerivationType.electrum:
|
|
|
|
default:
|
|
|
|
seedBytes = await mnemonicToSeedBytes(mnemonic);
|
|
|
|
break;
|
|
|
|
}
|
2022-10-12 17:09:57 +00:00
|
|
|
return LitecoinWallet(
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
|
|
|
initialAddresses: initialAddresses,
|
|
|
|
initialBalance: initialBalance,
|
Bitcoin derivations (#1089)
* - Update and Fix Conflicts with main
* Add Balances for ERC20 tokens
* Fix conflicts with main
* Add erc20 abi json
* Add send erc20 tokens initial function
* add missing getHeightByDate in Haven [skip ci]
* Allow contacts and wallets from the same tag
* Add Shiba Inu icon
* Add send ERC-20 tokens initial flow
* Add missing import in generated file
* Add initial approach for transaction sending for ERC-20 tokens
* Refactor signing/sending transactions
* Add initial flow for transactions subscription
* Refactor signing/sending transactions
* Add home settings icon
* Fix conflicts with main
* Initial flow for home settings
* Add logic flow for adding erc20 tokens
* Fix initial UI
* Finalize UI for Tokens
* Integrate UI with Ethereum flow
* Add "Enable/Disable" feature for ERC20 tokens
* Add initial Erc20 tokens
* Add Sorting and Pin Native Token features
* Fix price sorting
* Sort tokens list as well when Sort criteria changes
* - Improve sorting balances flow
- Add initial add token from search bar flow
* Fix Accounts Popup UI
* Fix Pin native token
* Fix Enabling/Disabling tokens
Fix sorting by fiat once app is opened
Improve token availability mechanism
* Fix deleting token
Fix renaming tokens
* Fix issue with search
* Add more tokens
* - Fix scroll issue
- Add ERC20 tokens placeholder image in picker
* - Separate and organize default erc20 tokens
- Fix scrolling
- Add token placeholder images in picker
- Sort disabled tokens alphabetically
* Change BNB token initial availability [skip ci]
* Fix Conflicts with main
* Fix Conflicts with main
* Add Verse ERC20 token to the initial tokens list
* Add rename wallet to Ethereum
* Integrate EtherScan API for fetching address transactions
Generate Ethereum specific secrets in Ethereum package
* Adjust transactions fiat price for ERC20 tokens
* Free Up GitHub Actions Ubuntu Runner Disk Space
* Free Up GitHub Actions Ubuntu Runner Disk space (trial 2)
* Fix Transaction Fee display
* Save transaction history
* Enhance loading time for erc20 tokens transactions
* Minor Fixes and Enhancements
* Fix sending erc20
fix block explorer issue
* Fix int overflow
* Fix transaction amount conversions
* Minor: `slow` -> `Slow` [skip-ci]
* initial changes
* more base config stuff
* config changes
* successfully builds!
* save
* successfully add nano wallet
* save
* seed generation
* receive screen + node screen working
* tx history working and fiat fixes
* balance working
* derivation updates
* nano-unfinished
* sends working
* remove fees from send screen, send and receive transactions working
* fixes + auto receive incoming txs
* fix for scanning QR codes
* save
* update translations
* fixes
* more fixes
* more strings
* small fix
* fix github actions workflow
* potential fix
* potential fix
* ci/cd fix
* change rep working
* seed generation fixes
* fixes
* save
* change rep screen functional
* save
* banano changes
* fixes, start adding ui for PoW
* pow node changes
* update translations
* fix
* account changing barely working
* save
* disable account generation
* small fix
* save
* UI work
* save
* fixes after merge main
* fixes
* remove monero stuff, work on derivation ui
* lots of fixes + finish up seed derivation
* last minute fixes
* node related fixes
* more fixes
* small fix
* more fixes
* fixes
* pretty big refactor for pow, still some bugs
* finally works!
* get transactions after send
* fix
* merge conflict fixes
* save
* fix pow node showing up twice
* done
* initial changes
* small fix
* more merge fixes
* fixes
* more fixes
* fix
* save
* fix manage pow nodes setting appearing on other wallets
* fix contact bug
* fixes
* fiat fixes
* save
* save
* save
* save
* updates
* cleanup
* restore fix
* fixes
* remove deprecated alert
* fix
* small fix
* remove outdated warning
* electrum restore fixes
* fixes
* fixes
* fix
* derivation fixes
* nano fixes pt.1
* nano fixes pt.2
* bip39 fixes
* pownode refactor
* nodes pages fixes
* observer fix
* ssl fix
* remove old references
* remove unused imports
* code cleanup
* small fix
* small potential fix
* save
* derivation fixes
* deterministic fix
* fix pt.2
* derivation class fixes
* review fixes from nano that also apply here
* formatting
* stuff that should've stayed deleted
* post merge fixes
* remove problematic imports and duplicate changes
* Delete lib/nano/nano.dart
* move wallet restore page proxy code to the view model
* fix dashboard page indicators being the same color
* debatably better refactoring of derivationInfo, migration needed
* additional refactor improvements
* blanket comment some stuff out to narrow down this issue
* refactor fixes
* fix nano exchange
* fix , bug, i.e. replace , with . when making a nano transaction
* fix nano sending, update restore page wording, and other minor fixes
* write migration for existing bitcoin and nano wallets
* merge fixes
* minor fixes
* use default derivation type when restoring from qr code
* fixes for restoring
* fixes
* fixes
* merge fix
* Fix issues with Creating Electrum and Restoring Bip39
* updates & fixes
* Add missing case for no transactions BIP39 wallet restore
* Make the default BIP39 the 84 derivation path
* Add Samourai Deposit
* litecoin mnemonic error fix
* Bip39 passphrase support (#1412)
* save
* passphrase working
* fix for when loading wallets + translation update
* minor fix
* Fix Nano
* minor fix [skip ci]
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
* change error state seed conditions into throwables [skip ci]
* litecoin fixes
* Bip39 minor enhancements (#1416)
* minor enhancements
* rename bitcoin_derivations -> electrum_derivations
* Remove duplicate derivations
handle default case
* minor fix
* Enable passphrase for Litecoin
* obscure text of passphrase
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Justin Ehrenhofer <justin.ehrenhofer@gmail.com>
Co-authored-by: fossephate <fosse@book.local>
2024-04-30 00:49:56 +00:00
|
|
|
seedBytes: seedBytes,
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
initialRegularAddressIndex: initialRegularAddressIndex,
|
|
|
|
initialChangeAddressIndex: initialChangeAddressIndex,
|
|
|
|
addressPageType: addressPageType,
|
|
|
|
);
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
static Future<LitecoinWallet> open({
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
|
|
|
required WalletInfo walletInfo,
|
|
|
|
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
|
|
|
required String password,
|
2024-07-22 17:08:19 +00:00
|
|
|
required bool alwaysScan,
|
2021-12-24 12:52:08 +00:00
|
|
|
}) async {
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
final snp =
|
|
|
|
await ElectrumWalletSnapshot.load(name, walletInfo.type, password, LitecoinNetwork.mainnet);
|
2021-12-24 12:52:08 +00:00
|
|
|
return LitecoinWallet(
|
2024-05-05 01:44:50 +00:00
|
|
|
mnemonic: snp.mnemonic!,
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
|
|
|
initialAddresses: snp.addresses,
|
|
|
|
initialBalance: snp.balance,
|
2024-05-05 01:44:50 +00:00
|
|
|
seedBytes: await mnemonicToSeedBytes(snp.mnemonic!),
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
initialRegularAddressIndex: snp.regularAddressIndex,
|
|
|
|
initialChangeAddressIndex: snp.changeAddressIndex,
|
|
|
|
addressPageType: snp.addressPageType,
|
2024-07-22 17:08:19 +00:00
|
|
|
alwaysScan: alwaysScan,
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-20 23:20:52 +00:00
|
|
|
@action
|
|
|
|
@override
|
|
|
|
Future<void> startSync() async {
|
2024-07-19 06:37:29 +00:00
|
|
|
if (!mwebEnabled) {
|
|
|
|
syncStatus = SyncronizingSyncStatus();
|
|
|
|
await subscribeForUpdates();
|
|
|
|
await updateTransactions();
|
|
|
|
syncStatus = SyncedSyncStatus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await subscribeForUpdates();
|
|
|
|
await updateTransactions();
|
|
|
|
await updateFeeRates();
|
|
|
|
|
|
|
|
Timer.periodic(const Duration(minutes: 1), (timer) async => await updateFeeRates());
|
|
|
|
|
2024-07-17 16:27:31 +00:00
|
|
|
_stub = await CwMweb.stub();
|
2024-05-29 15:54:50 +00:00
|
|
|
_syncTimer?.cancel();
|
|
|
|
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
|
|
|
if (syncStatus is FailedSyncStatus) return;
|
|
|
|
final height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
2024-07-11 17:54:44 +00:00
|
|
|
final resp = await _stub.status(StatusRequest());
|
2024-05-29 15:54:50 +00:00
|
|
|
if (resp.blockHeaderHeight < height) {
|
|
|
|
int h = resp.blockHeaderHeight;
|
|
|
|
syncStatus = SyncingSyncStatus(height - h, h / height);
|
|
|
|
} else if (resp.mwebHeaderHeight < height) {
|
|
|
|
int h = resp.mwebHeaderHeight;
|
|
|
|
syncStatus = SyncingSyncStatus(height - h, h / height);
|
|
|
|
} else if (resp.mwebUtxosHeight < height) {
|
|
|
|
syncStatus = SyncingSyncStatus(1, 0.999);
|
|
|
|
} else {
|
|
|
|
// prevent unnecessary reaction triggers:
|
|
|
|
if (syncStatus is! SyncedSyncStatus) {
|
2024-04-21 11:19:44 +00:00
|
|
|
syncStatus = SyncedSyncStatus();
|
2024-05-29 15:54:50 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 21:59:25 +00:00
|
|
|
if (resp.mwebUtxosHeight > mwebUtxosHeight) {
|
|
|
|
mwebUtxosHeight = resp.mwebUtxosHeight;
|
|
|
|
await checkMwebUtxosSpent();
|
|
|
|
// update the confirmations for each transaction:
|
|
|
|
for (final transaction in transactionHistory.transactions.values) {
|
|
|
|
if (transaction.isPending) continue;
|
|
|
|
final confirmations = mwebUtxosHeight - transaction.height + 1;
|
|
|
|
if (transaction.confirmations == confirmations) continue;
|
|
|
|
transaction.confirmations = confirmations;
|
|
|
|
transactionHistory.addOne(transaction);
|
|
|
|
}
|
|
|
|
await transactionHistory.save();
|
|
|
|
}
|
2024-05-29 15:54:50 +00:00
|
|
|
}
|
|
|
|
});
|
2024-07-19 07:06:23 +00:00
|
|
|
updateUnspent();
|
2024-07-19 16:15:28 +00:00
|
|
|
// this runs in the background and processes new utxos as they come in:
|
|
|
|
processMwebUtxos();
|
2024-04-22 23:26:34 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 16:27:31 +00:00
|
|
|
@action
|
|
|
|
@override
|
|
|
|
Future<void> stopSync() async {
|
|
|
|
_syncTimer?.cancel();
|
2024-07-17 21:32:07 +00:00
|
|
|
_utxoStream?.cancel();
|
2024-07-17 16:27:31 +00:00
|
|
|
await CwMweb.stop();
|
|
|
|
}
|
|
|
|
|
2024-06-08 12:26:48 +00:00
|
|
|
Future<void> initMwebUtxosBox() async {
|
|
|
|
final boxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
|
|
|
|
|
|
|
|
mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(boxName);
|
|
|
|
}
|
|
|
|
|
2024-07-19 06:37:29 +00:00
|
|
|
@override
|
|
|
|
Future<void> renameWalletFiles(String newWalletName) async {
|
|
|
|
// rename the hive box:
|
|
|
|
final oldBoxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
|
|
|
|
final newBoxName = "${newWalletName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
|
|
|
|
|
|
|
|
final oldBox = await Hive.openBox<MwebUtxo>(oldBoxName);
|
|
|
|
mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
|
|
|
|
for (final key in oldBox.keys) {
|
|
|
|
await mwebUtxosBox.put(key, oldBox.get(key)!);
|
|
|
|
}
|
|
|
|
|
|
|
|
await super.renameWalletFiles(newWalletName);
|
|
|
|
}
|
|
|
|
|
2024-06-28 16:16:54 +00:00
|
|
|
@action
|
|
|
|
@override
|
|
|
|
Future<void> rescan({
|
|
|
|
required int height,
|
|
|
|
int? chainTip,
|
|
|
|
ScanData? scanData,
|
|
|
|
bool? doSingleScan,
|
|
|
|
bool? usingElectrs,
|
|
|
|
}) async {
|
|
|
|
await mwebUtxosBox.clear();
|
2024-07-01 16:00:41 +00:00
|
|
|
transactionHistory.clear();
|
2024-06-28 16:16:54 +00:00
|
|
|
mwebUtxosHeight = height;
|
2024-07-01 17:05:07 +00:00
|
|
|
await walletInfo.updateRestoreHeight(height);
|
|
|
|
print("STARTING SYNC");
|
2024-07-01 16:00:41 +00:00
|
|
|
await startSync();
|
2024-06-28 16:16:54 +00:00
|
|
|
}
|
|
|
|
|
2024-06-08 12:26:48 +00:00
|
|
|
@override
|
|
|
|
Future<void> init() async {
|
2024-07-01 17:05:07 +00:00
|
|
|
await super.init();
|
2024-06-08 12:26:48 +00:00
|
|
|
await initMwebUtxosBox();
|
|
|
|
}
|
2024-04-22 23:26:34 +00:00
|
|
|
|
2024-07-01 17:05:07 +00:00
|
|
|
Future<void> handleIncoming(MwebUtxo utxo, RpcClient stub) async {
|
|
|
|
final status = await stub.status(StatusRequest());
|
|
|
|
var date = DateTime.now();
|
|
|
|
var confirmations = 0;
|
|
|
|
if (utxo.height > 0) {
|
|
|
|
date = DateTime.fromMillisecondsSinceEpoch(utxo.blockTime * 1000);
|
|
|
|
confirmations = status.blockHeaderHeight - utxo.height + 1;
|
|
|
|
}
|
|
|
|
var tx = transactionHistory.transactions.values
|
|
|
|
.firstWhereOrNull((tx) => tx.outputAddresses?.contains(utxo.outputId) ?? false);
|
|
|
|
|
|
|
|
if (tx == null) {
|
|
|
|
tx = ElectrumTransactionInfo(
|
|
|
|
WalletType.litecoin,
|
|
|
|
id: utxo.outputId,
|
|
|
|
height: utxo.height,
|
|
|
|
amount: utxo.value.toInt(),
|
|
|
|
fee: 0,
|
|
|
|
direction: TransactionDirection.incoming,
|
|
|
|
isPending: utxo.height == 0,
|
|
|
|
date: date,
|
|
|
|
confirmations: confirmations,
|
|
|
|
inputAddresses: [],
|
|
|
|
outputAddresses: [utxo.outputId],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNew = transactionHistory.transactions[tx.id] == null;
|
|
|
|
|
2024-07-19 06:37:29 +00:00
|
|
|
// don't update the confirmations if the tx is updated by electrum:
|
|
|
|
if (tx.confirmations == 0 || utxo.height != 0) {
|
|
|
|
tx.height = utxo.height;
|
|
|
|
tx.isPending = utxo.height == 0;
|
|
|
|
tx.confirmations = confirmations;
|
|
|
|
}
|
|
|
|
|
2024-07-01 17:05:07 +00:00
|
|
|
if (!(tx.outputAddresses?.contains(utxo.address) ?? false)) {
|
|
|
|
tx.outputAddresses?.add(utxo.address);
|
|
|
|
isNew = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNew) {
|
|
|
|
final addressRecord = walletAddresses.allAddresses
|
|
|
|
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);
|
|
|
|
if (addressRecord == null) {
|
|
|
|
return;
|
|
|
|
}
|
2024-07-11 22:55:37 +00:00
|
|
|
if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) {
|
|
|
|
addressRecord.txCount++;
|
2024-07-17 20:45:47 +00:00
|
|
|
// print("COUNT UPDATED HERE 2!!!!! ${addressRecord.txCount}");
|
2024-07-11 22:55:37 +00:00
|
|
|
}
|
2024-07-01 17:05:07 +00:00
|
|
|
addressRecord.balance += utxo.value.toInt();
|
|
|
|
addressRecord.setAsUsed();
|
2024-07-10 19:45:30 +00:00
|
|
|
|
|
|
|
// update the unconfirmed balance when a new tx is added:
|
|
|
|
await updateBalance();
|
2024-07-01 17:05:07 +00:00
|
|
|
}
|
|
|
|
transactionHistory.addOne(tx);
|
|
|
|
}
|
|
|
|
|
2024-04-22 23:26:34 +00:00
|
|
|
Future<void> processMwebUtxos() async {
|
2024-04-22 16:18:18 +00:00
|
|
|
final scanSecret = mwebHd.derive(0x80000000).privKey!;
|
2024-06-28 16:16:54 +00:00
|
|
|
int restoreHeight = walletInfo.restoreHeight;
|
|
|
|
print("SCANNING FROM HEIGHT: $restoreHeight");
|
|
|
|
final req = UtxosRequest(scanSecret: hex.decode(scanSecret), fromHeight: restoreHeight);
|
2024-06-24 19:48:42 +00:00
|
|
|
|
2024-07-12 20:40:37 +00:00
|
|
|
// process old utxos:
|
2024-06-24 19:48:42 +00:00
|
|
|
for (final utxo in mwebUtxosBox.values) {
|
|
|
|
if (utxo.address.isEmpty) {
|
|
|
|
continue;
|
2024-04-24 10:53:43 +00:00
|
|
|
}
|
2024-04-22 23:26:34 +00:00
|
|
|
|
2024-07-15 19:59:20 +00:00
|
|
|
// if (walletInfo.restoreHeight > utxo.height) {
|
|
|
|
// continue;
|
|
|
|
// }
|
2024-06-24 19:48:42 +00:00
|
|
|
|
2024-07-11 17:54:44 +00:00
|
|
|
await handleIncoming(utxo, _stub);
|
2024-06-24 19:48:42 +00:00
|
|
|
|
|
|
|
if (utxo.height > walletInfo.restoreHeight) {
|
|
|
|
walletInfo.updateRestoreHeight(utxo.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-12 20:40:37 +00:00
|
|
|
// process new utxos as they come in:
|
2024-07-17 21:32:07 +00:00
|
|
|
_utxoStream?.cancel();
|
|
|
|
_utxoStream = _stub.utxos(req).listen((Utxo sUtxo) async {
|
2024-06-24 19:48:42 +00:00
|
|
|
final utxo = MwebUtxo(
|
|
|
|
address: sUtxo.address,
|
|
|
|
blockTime: sUtxo.blockTime,
|
|
|
|
height: sUtxo.height,
|
|
|
|
outputId: sUtxo.outputId,
|
|
|
|
value: sUtxo.value.toInt(),
|
|
|
|
);
|
|
|
|
|
2024-07-17 21:32:07 +00:00
|
|
|
if (mwebUtxosBox.containsKey(utxo.outputId)) {
|
|
|
|
// we've already stored this utxo, skip it:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (utxo.address.isEmpty) {
|
|
|
|
// await updateUnspent();
|
|
|
|
// await updateBalance();
|
|
|
|
// initDone = true;
|
2024-07-15 19:59:20 +00:00
|
|
|
// }
|
2024-07-11 22:55:37 +00:00
|
|
|
|
2024-07-17 21:32:07 +00:00
|
|
|
await updateUnspent();
|
|
|
|
await updateBalance();
|
2024-06-24 19:48:42 +00:00
|
|
|
|
|
|
|
final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs;
|
|
|
|
|
2024-07-12 20:40:37 +00:00
|
|
|
// don't process utxos with addresses that are not in the mwebAddrs list:
|
2024-07-12 00:22:35 +00:00
|
|
|
if (utxo.address.isNotEmpty && !mwebAddrs.contains(utxo.address)) {
|
2024-07-17 21:32:07 +00:00
|
|
|
return;
|
2024-06-24 19:48:42 +00:00
|
|
|
}
|
2024-07-09 23:14:53 +00:00
|
|
|
|
2024-06-24 19:48:42 +00:00
|
|
|
await mwebUtxosBox.put(utxo.outputId, utxo);
|
2024-07-09 23:14:53 +00:00
|
|
|
|
2024-07-11 17:54:44 +00:00
|
|
|
await handleIncoming(utxo, _stub);
|
2024-07-17 21:32:07 +00:00
|
|
|
});
|
2024-04-20 23:20:52 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 23:26:34 +00:00
|
|
|
Future<void> checkMwebUtxosSpent() async {
|
2024-04-27 13:26:43 +00:00
|
|
|
while ((await Future.wait(transactionHistory.transactions.values
|
2024-05-29 15:54:50 +00:00
|
|
|
.where((tx) => tx.direction == TransactionDirection.outgoing && tx.isPending)
|
|
|
|
.map(checkPendingTransaction)))
|
|
|
|
.any((x) => x));
|
|
|
|
final outputIds =
|
2024-06-24 19:48:42 +00:00
|
|
|
mwebUtxosBox.values.where((utxo) => utxo.height > 0).map((utxo) => utxo.outputId).toList();
|
2024-06-19 02:07:13 +00:00
|
|
|
|
2024-07-11 17:54:44 +00:00
|
|
|
final resp = await _stub.spent(SpentRequest(outputId: outputIds));
|
2024-04-22 23:26:34 +00:00
|
|
|
final spent = resp.outputId;
|
|
|
|
if (spent.isEmpty) return;
|
2024-07-11 17:54:44 +00:00
|
|
|
final status = await _stub.status(StatusRequest());
|
2024-04-22 23:26:34 +00:00
|
|
|
final height = await electrumClient.getCurrentBlockChainTip();
|
2024-04-24 10:53:43 +00:00
|
|
|
if (height == null || status.blockHeaderHeight != height) return;
|
|
|
|
if (status.mwebUtxosHeight != height) return;
|
2024-04-22 23:26:34 +00:00
|
|
|
int amount = 0;
|
|
|
|
Set<String> inputAddresses = {};
|
|
|
|
var output = AccumulatorSink<Digest>();
|
|
|
|
var input = sha256.startChunkedConversion(output);
|
|
|
|
for (final outputId in spent) {
|
2024-06-19 02:07:13 +00:00
|
|
|
final utxo = mwebUtxosBox.get(outputId);
|
2024-06-24 19:48:42 +00:00
|
|
|
await mwebUtxosBox.delete(outputId);
|
2024-04-27 13:26:43 +00:00
|
|
|
if (utxo == null) continue;
|
2024-05-29 15:54:50 +00:00
|
|
|
final addressRecord = walletAddresses.allAddresses
|
|
|
|
.firstWhere((addressRecord) => addressRecord.address == utxo.address);
|
2024-07-12 20:40:37 +00:00
|
|
|
if (!inputAddresses.contains(utxo.address)) {
|
|
|
|
addressRecord.txCount++;
|
2024-07-17 20:45:47 +00:00
|
|
|
// print("COUNT UPDATED HERE 3!!!!! ${addressRecord.address} ${addressRecord.txCount} !!!!!!");
|
2024-07-12 20:40:37 +00:00
|
|
|
}
|
2024-04-23 17:31:30 +00:00
|
|
|
addressRecord.balance -= utxo.value.toInt();
|
|
|
|
amount += utxo.value.toInt();
|
|
|
|
inputAddresses.add(utxo.address);
|
2024-04-27 13:26:43 +00:00
|
|
|
input.add(hex.decode(outputId));
|
2024-04-22 23:26:34 +00:00
|
|
|
}
|
2024-04-27 13:26:43 +00:00
|
|
|
if (inputAddresses.isEmpty) return;
|
2024-04-22 23:26:34 +00:00
|
|
|
input.close();
|
|
|
|
var digest = output.events.single;
|
2024-07-09 23:14:53 +00:00
|
|
|
final tx = ElectrumTransactionInfo(
|
|
|
|
WalletType.litecoin,
|
|
|
|
id: digest.toString(),
|
|
|
|
height: height,
|
|
|
|
amount: amount,
|
|
|
|
fee: 0,
|
|
|
|
direction: TransactionDirection.outgoing,
|
|
|
|
isPending: false,
|
|
|
|
date: DateTime.fromMillisecondsSinceEpoch(status.blockTime * 1000),
|
|
|
|
confirmations: 1,
|
|
|
|
inputAddresses: inputAddresses.toList(),
|
|
|
|
outputAddresses: [],
|
|
|
|
);
|
2024-06-24 19:48:42 +00:00
|
|
|
print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@2");
|
|
|
|
|
2024-04-22 23:26:34 +00:00
|
|
|
transactionHistory.addOne(tx);
|
|
|
|
await transactionHistory.save();
|
|
|
|
}
|
|
|
|
|
2024-04-27 13:26:43 +00:00
|
|
|
Future<bool> checkPendingTransaction(ElectrumTransactionInfo tx) async {
|
|
|
|
if (!tx.isPending) return false;
|
|
|
|
final outputId = <String>[], target = <String>{};
|
|
|
|
final isHash = RegExp(r'^[a-f0-9]{64}$').hasMatch;
|
|
|
|
final spendingOutputIds = tx.inputAddresses?.where(isHash) ?? [];
|
|
|
|
final payingToOutputIds = tx.outputAddresses?.where(isHash) ?? [];
|
|
|
|
outputId.addAll(spendingOutputIds);
|
|
|
|
outputId.addAll(payingToOutputIds);
|
|
|
|
target.addAll(spendingOutputIds);
|
|
|
|
for (final outputId in payingToOutputIds) {
|
2024-05-29 15:54:50 +00:00
|
|
|
final spendingTx = transactionHistory.transactions.values
|
|
|
|
.firstWhereOrNull((tx) => tx.inputAddresses?.contains(outputId) ?? false);
|
2024-07-09 23:14:53 +00:00
|
|
|
if (spendingTx != null && !spendingTx.isPending) {
|
|
|
|
target.add(outputId);
|
|
|
|
}
|
2024-04-27 13:26:43 +00:00
|
|
|
}
|
2024-07-11 17:54:44 +00:00
|
|
|
if (outputId.isEmpty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final resp = await _stub.spent(SpentRequest(outputId: outputId));
|
2024-04-27 16:40:47 +00:00
|
|
|
if (!setEquals(resp.outputId.toSet(), target)) return false;
|
2024-07-11 17:54:44 +00:00
|
|
|
final status = await _stub.status(StatusRequest());
|
2024-04-27 13:26:43 +00:00
|
|
|
if (!tx.isPending) return false;
|
|
|
|
tx.height = status.mwebUtxosHeight;
|
|
|
|
tx.confirmations = 1;
|
|
|
|
tx.isPending = false;
|
2024-04-28 10:17:28 +00:00
|
|
|
await transactionHistory.save();
|
2024-04-27 13:26:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-23 12:37:44 +00:00
|
|
|
@override
|
2024-05-30 02:08:33 +00:00
|
|
|
Future<void> updateUnspent() async {
|
|
|
|
await super.updateUnspent();
|
2024-04-23 12:37:44 +00:00
|
|
|
await checkMwebUtxosSpent();
|
2024-07-11 17:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
Future<void> updateAllUnspents() async {
|
|
|
|
List<BitcoinUnspent> updatedUnspentCoins = [];
|
|
|
|
|
|
|
|
await Future.wait(walletAddresses.allAddresses.map((address) async {
|
|
|
|
updatedUnspentCoins.addAll(await fetchUnspent(address));
|
|
|
|
}));
|
|
|
|
|
2024-07-19 06:37:29 +00:00
|
|
|
if (mwebEnabled) {
|
|
|
|
// update mweb unspents:
|
|
|
|
final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs;
|
|
|
|
mwebUtxosBox.keys.forEach((dynamic oId) {
|
|
|
|
final String outputId = oId as String;
|
|
|
|
final utxo = mwebUtxosBox.get(outputId);
|
|
|
|
if (utxo == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (utxo.address.isEmpty) {
|
|
|
|
// not sure if a bug or a special case but we definitely ignore these
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final addressRecord = walletAddresses.allAddresses
|
|
|
|
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);
|
2024-06-24 19:48:42 +00:00
|
|
|
|
2024-07-19 06:37:29 +00:00
|
|
|
if (addressRecord == null) {
|
|
|
|
print("utxo contains an address that is not in the wallet: ${utxo.address}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final unspent = BitcoinUnspent(
|
|
|
|
addressRecord,
|
|
|
|
outputId,
|
|
|
|
utxo.value.toInt(),
|
|
|
|
mwebAddrs.indexOf(utxo.address),
|
|
|
|
);
|
|
|
|
if (unspent.vout == 0) {
|
|
|
|
unspent.isChange = true;
|
|
|
|
}
|
|
|
|
updatedUnspentCoins.add(unspent);
|
|
|
|
});
|
|
|
|
}
|
2024-07-11 17:54:44 +00:00
|
|
|
|
2024-07-19 16:15:28 +00:00
|
|
|
// print(unspentCoins);
|
|
|
|
// print(updatedUnspentCoins);
|
|
|
|
// print(updatedUnspentCoins.length);
|
2024-07-19 07:06:23 +00:00
|
|
|
|
|
|
|
// print(updatedUnspentCoins[2].address);
|
|
|
|
|
2024-07-11 17:54:44 +00:00
|
|
|
unspentCoins = updatedUnspentCoins;
|
2024-04-23 12:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-04-23 16:16:47 +00:00
|
|
|
Future<ElectrumBalance> fetchBalances() async {
|
|
|
|
final balance = await super.fetchBalances();
|
|
|
|
var confirmed = balance.confirmed;
|
|
|
|
var unconfirmed = balance.unconfirmed;
|
2024-06-19 02:07:13 +00:00
|
|
|
mwebUtxosBox.values.forEach((utxo) {
|
|
|
|
if (utxo.height > 0) {
|
2024-04-23 12:37:44 +00:00
|
|
|
confirmed += utxo.value.toInt();
|
2024-06-19 02:07:13 +00:00
|
|
|
} else {
|
2024-04-23 12:37:44 +00:00
|
|
|
unconfirmed += utxo.value.toInt();
|
2024-06-19 02:07:13 +00:00
|
|
|
}
|
2024-04-23 12:37:44 +00:00
|
|
|
});
|
2024-07-11 18:49:14 +00:00
|
|
|
|
|
|
|
// update unspent balances:
|
|
|
|
|
2024-07-12 00:22:35 +00:00
|
|
|
// reset coin balances and txCount to 0:
|
2024-07-11 18:49:14 +00:00
|
|
|
unspentCoins.forEach((coin) {
|
|
|
|
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
|
|
|
|
coin.bitcoinAddressRecord.balance = 0;
|
2024-07-11 22:55:37 +00:00
|
|
|
coin.bitcoinAddressRecord.txCount = 0;
|
2024-07-11 18:49:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
unspentCoins.forEach((coin) {
|
|
|
|
final coinInfoList = unspentCoinsInfo.values.where(
|
|
|
|
(element) =>
|
|
|
|
element.walletId.contains(id) &&
|
|
|
|
element.hash.contains(coin.hash) &&
|
|
|
|
element.vout == coin.vout,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (coinInfoList.isNotEmpty) {
|
|
|
|
final coinInfo = coinInfoList.first;
|
|
|
|
|
|
|
|
coin.isFrozen = coinInfo.isFrozen;
|
|
|
|
coin.isSending = coinInfo.isSending;
|
|
|
|
coin.note = coinInfo.note;
|
|
|
|
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
|
|
|
|
coin.bitcoinAddressRecord.balance += coinInfo.value;
|
|
|
|
} else {
|
|
|
|
super.addCoinInfo(coin);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-07-12 00:22:35 +00:00
|
|
|
// update the txCount for each address:
|
|
|
|
for (var tx in transactionHistory.transactions.values) {
|
|
|
|
if (tx.isPending) continue;
|
|
|
|
final txAddresses = tx.inputAddresses! + tx.outputAddresses!;
|
|
|
|
for (var address in txAddresses) {
|
|
|
|
final addressRecord = walletAddresses.allAddresses
|
|
|
|
.firstWhereOrNull((addressRecord) => addressRecord.address == address);
|
|
|
|
if (addressRecord == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
addressRecord.txCount++;
|
2024-07-17 20:45:47 +00:00
|
|
|
// print("COUNT UPDATED HERE 0!!!!! ${addressRecord.address} ${addressRecord.txCount} !!!!!!");
|
2024-07-12 00:22:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-19 07:06:23 +00:00
|
|
|
await updateUnspent();
|
|
|
|
|
2024-05-29 15:54:50 +00:00
|
|
|
return ElectrumBalance(confirmed: confirmed, unconfirmed: unconfirmed, frozen: balance.frozen);
|
2024-04-23 16:16:47 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
|
|
|
int feeRate(TransactionPriority priority) {
|
|
|
|
if (priority is LitecoinTransactionPriority) {
|
|
|
|
switch (priority) {
|
|
|
|
case LitecoinTransactionPriority.slow:
|
|
|
|
return 1;
|
|
|
|
case LitecoinTransactionPriority.medium:
|
|
|
|
return 2;
|
|
|
|
case LitecoinTransactionPriority.fast:
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2024-04-25 14:23:01 +00:00
|
|
|
|
|
|
|
@override
|
2024-05-29 16:18:21 +00:00
|
|
|
Future<int> calcFee({
|
|
|
|
required List<UtxoWithAddress> utxos,
|
|
|
|
required List<BitcoinBaseOutput> outputs,
|
|
|
|
required BasedUtxoNetwork network,
|
|
|
|
String? memo,
|
|
|
|
required int feeRate,
|
|
|
|
List<ECPrivateInfo>? inputPrivKeyInfos,
|
|
|
|
List<Outpoint>? vinOutpoints,
|
|
|
|
}) async {
|
2024-04-25 22:13:41 +00:00
|
|
|
final spendsMweb = utxos.any((utxo) => utxo.utxo.scriptType == SegwitAddresType.mweb);
|
2024-05-29 15:54:50 +00:00
|
|
|
final paysToMweb = outputs
|
|
|
|
.any((output) => output.toOutput.scriptPubKey.getAddressType() == SegwitAddresType.mweb);
|
2024-04-25 22:13:41 +00:00
|
|
|
if (!spendsMweb && !paysToMweb) {
|
2024-05-29 16:18:21 +00:00
|
|
|
return await super.calcFee(
|
|
|
|
utxos: utxos,
|
|
|
|
outputs: outputs,
|
|
|
|
network: network,
|
|
|
|
memo: memo,
|
|
|
|
feeRate: feeRate,
|
|
|
|
inputPrivKeyInfos: inputPrivKeyInfos,
|
|
|
|
vinOutpoints: vinOutpoints,
|
|
|
|
);
|
2024-04-25 22:13:41 +00:00
|
|
|
}
|
2024-04-26 00:07:58 +00:00
|
|
|
if (outputs.length == 1 && outputs[0].toOutput.amount == BigInt.zero) {
|
2024-05-29 15:54:50 +00:00
|
|
|
outputs = [
|
|
|
|
BitcoinScriptOutput(
|
|
|
|
script: outputs[0].toOutput.scriptPubKey, value: utxos.sumOfUtxosValue())
|
|
|
|
];
|
2024-04-26 00:07:58 +00:00
|
|
|
}
|
2024-05-29 15:54:50 +00:00
|
|
|
final preOutputSum =
|
|
|
|
outputs.fold<BigInt>(BigInt.zero, (acc, output) => acc + output.toOutput.amount);
|
2024-04-26 10:19:40 +00:00
|
|
|
final fee = utxos.sumOfUtxosValue() - preOutputSum;
|
2024-05-29 15:54:50 +00:00
|
|
|
final txb =
|
|
|
|
BitcoinTransactionBuilder(utxos: utxos, outputs: outputs, fee: fee, network: network);
|
2024-07-11 17:54:44 +00:00
|
|
|
final resp = await _stub.create(CreateRequest(
|
2024-04-25 14:23:01 +00:00
|
|
|
rawTx: txb.buildTransaction((a, b, c, d) => '').toBytes(),
|
2024-04-26 11:32:38 +00:00
|
|
|
scanSecret: hex.decode(mwebHd.derive(0x80000000).privKey!),
|
|
|
|
spendSecret: hex.decode(mwebHd.derive(0x80000001).privKey!),
|
2024-04-25 14:23:01 +00:00
|
|
|
feeRatePerKb: Int64(feeRate * 1000),
|
|
|
|
dryRun: true));
|
|
|
|
final tx = BtcTransaction.fromRaw(hex.encode(resp.rawTx));
|
2024-05-29 15:54:50 +00:00
|
|
|
final posUtxos = utxos
|
|
|
|
.where((utxo) => tx.inputs
|
|
|
|
.any((input) => input.txId == utxo.utxo.txHash && input.txIndex == utxo.utxo.vout))
|
|
|
|
.toList();
|
2024-04-25 14:23:01 +00:00
|
|
|
final posOutputSum = tx.outputs.fold<int>(0, (acc, output) => acc + output.amount.toInt());
|
|
|
|
final mwebInputSum = utxos.sumOfUtxosValue() - posUtxos.sumOfUtxosValue();
|
2024-04-26 10:19:40 +00:00
|
|
|
final expectedPegin = max(0, (preOutputSum - mwebInputSum).toInt());
|
|
|
|
var feeIncrease = posOutputSum - expectedPegin;
|
2024-04-28 10:17:28 +00:00
|
|
|
if (expectedPegin > 0 && fee == BigInt.zero) {
|
2024-05-29 15:54:50 +00:00
|
|
|
feeIncrease += await super.calcFee(
|
|
|
|
utxos: posUtxos,
|
|
|
|
outputs: tx.outputs
|
|
|
|
.map((output) =>
|
|
|
|
BitcoinScriptOutput(script: output.scriptPubKey, value: output.amount))
|
|
|
|
.toList(),
|
|
|
|
network: network,
|
|
|
|
memo: memo,
|
|
|
|
feeRate: feeRate) +
|
|
|
|
feeRate * 41;
|
2024-04-25 14:23:01 +00:00
|
|
|
}
|
2024-04-26 10:19:40 +00:00
|
|
|
return fee.toInt() + feeIncrease;
|
2024-04-25 14:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<PendingTransaction> createTransaction(Object credentials) async {
|
2024-06-24 19:48:42 +00:00
|
|
|
try {
|
2024-07-19 06:37:29 +00:00
|
|
|
var tx = await super.createTransaction(credentials) as PendingBitcoinTransaction;
|
|
|
|
tx.isMweb = mwebEnabled;
|
|
|
|
|
|
|
|
if (!mwebEnabled) {
|
|
|
|
return tx;
|
|
|
|
}
|
2024-06-28 16:16:54 +00:00
|
|
|
|
2024-07-11 17:54:44 +00:00
|
|
|
final resp = await _stub.create(CreateRequest(
|
2024-04-26 11:32:38 +00:00
|
|
|
rawTx: hex.decode(tx.hex),
|
|
|
|
scanSecret: hex.decode(mwebHd.derive(0x80000000).privKey!),
|
|
|
|
spendSecret: hex.decode(mwebHd.derive(0x80000001).privKey!),
|
2024-06-24 19:48:42 +00:00
|
|
|
feeRatePerKb: Int64.parseInt(tx.feeRate) * 1000,
|
|
|
|
));
|
|
|
|
final tx2 = BtcTransaction.fromRaw(hex.encode(resp.rawTx));
|
|
|
|
tx.hexOverride = tx2
|
|
|
|
.copyWith(
|
|
|
|
witnesses: tx2.inputs.asMap().entries.map((e) {
|
|
|
|
final utxo = unspentCoins
|
|
|
|
.firstWhere((utxo) => utxo.hash == e.value.txId && utxo.vout == e.value.txIndex);
|
|
|
|
final key = generateECPrivate(
|
|
|
|
hd: utxo.bitcoinAddressRecord.isHidden
|
|
|
|
? walletAddresses.sideHd
|
|
|
|
: walletAddresses.mainHd,
|
|
|
|
index: utxo.bitcoinAddressRecord.index,
|
|
|
|
network: network);
|
|
|
|
final digest = tx2.getTransactionSegwitDigit(
|
2024-05-29 15:54:50 +00:00
|
|
|
txInIndex: e.key,
|
|
|
|
script: key.getPublic().toP2pkhAddress().toScriptPubKey(),
|
2024-06-24 19:48:42 +00:00
|
|
|
amount: BigInt.from(utxo.value),
|
|
|
|
);
|
|
|
|
return TxWitnessInput(stack: [key.signInput(digest), key.getPublic().toHex()]);
|
|
|
|
}).toList())
|
|
|
|
.toHex();
|
|
|
|
tx.outputs = resp.outputId;
|
|
|
|
return tx
|
|
|
|
..addListener((transaction) async {
|
2024-07-16 04:58:11 +00:00
|
|
|
final addresses = <String>{};
|
|
|
|
transaction.inputAddresses?.forEach((id) async {
|
|
|
|
final utxo = mwebUtxosBox.get(id);
|
|
|
|
await mwebUtxosBox.delete(id);
|
|
|
|
if (utxo == null) return;
|
2024-07-17 21:03:47 +00:00
|
|
|
final addressRecord = walletAddresses.allAddresses
|
|
|
|
.firstWhere((addressRecord) => addressRecord.address == utxo.address);
|
2024-07-16 04:58:11 +00:00
|
|
|
if (!addresses.contains(utxo.address)) {
|
|
|
|
addresses.add(utxo.address);
|
|
|
|
}
|
2024-07-17 21:03:47 +00:00
|
|
|
addressRecord.balance -= utxo.value.toInt();
|
2024-07-16 04:58:11 +00:00
|
|
|
});
|
|
|
|
transaction.inputAddresses?.addAll(addresses);
|
2024-07-12 20:40:37 +00:00
|
|
|
|
2024-07-16 04:56:20 +00:00
|
|
|
transactionHistory.addOne(transaction);
|
2024-06-24 19:48:42 +00:00
|
|
|
await updateUnspent();
|
|
|
|
await updateBalance();
|
2024-05-29 15:54:50 +00:00
|
|
|
});
|
2024-06-24 19:48:42 +00:00
|
|
|
} catch (e, s) {
|
|
|
|
print(e);
|
|
|
|
print(s);
|
2024-07-17 20:45:47 +00:00
|
|
|
if (e.toString().contains("commit failed")) {
|
|
|
|
throw Exception("Transaction commit failed (no peers responded), please try again.");
|
|
|
|
}
|
2024-06-24 19:48:42 +00:00
|
|
|
rethrow;
|
|
|
|
}
|
2024-04-25 14:23:01 +00:00
|
|
|
}
|
2024-06-08 12:26:48 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> save() async {
|
|
|
|
await super.save();
|
|
|
|
}
|
2024-07-17 16:41:26 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> close() async {
|
|
|
|
await super.close();
|
|
|
|
await mwebUtxosBox.close();
|
|
|
|
_syncTimer?.cancel();
|
2024-07-19 16:15:28 +00:00
|
|
|
_utxoStream?.cancel();
|
2024-07-17 16:41:26 +00:00
|
|
|
}
|
2024-07-19 06:37:29 +00:00
|
|
|
|
|
|
|
void setMwebEnabled(bool enabled) {
|
|
|
|
if (!mwebEnabled && enabled) {
|
|
|
|
mwebEnabled = enabled;
|
|
|
|
startSync();
|
|
|
|
}
|
|
|
|
mwebEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|