mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 19:55:52 +00:00
WIP: Add Ethereum
This commit is contained in:
parent
eca8ca21bc
commit
6370e927a2
5 changed files with 85 additions and 23 deletions
|
@ -31,7 +31,7 @@ import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||||
import 'package:stackwallet/widgets/stack_text_field.dart';
|
import 'package:stackwallet/widgets/stack_text_field.dart';
|
||||||
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
import 'package:web3dart/web3dart.dart';
|
// import 'package:web3dart/web3dart.dart';
|
||||||
|
|
||||||
enum AddEditNodeViewType { add, edit }
|
enum AddEditNodeViewType { add, edit }
|
||||||
|
|
||||||
|
@ -166,11 +166,11 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Coin.ethereum:
|
case Coin.ethereum:
|
||||||
final client = Web3Client(
|
// final client = Web3Client(
|
||||||
"https://mainnet.infura.io/v3/22677300bf774e49a458b73313ee56ba",
|
// "https://mainnet.infura.io/v3/22677300bf774e49a458b73313ee56ba",
|
||||||
Client());
|
// Client());
|
||||||
try {
|
try {
|
||||||
await client.getSyncStatus();
|
// await client.getSyncStatus();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'package:bip39/bip39.dart' as bip39;
|
import 'package:bip39/bip39.dart' as bip39;
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
|
import 'package:stack_wallet_backup/generate_password.dart';
|
||||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||||
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
||||||
import 'package:stackwallet/services/price.dart';
|
import 'package:stackwallet/services/price.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:string_to_hex/string_to_hex.dart';
|
import 'package:string_to_hex/string_to_hex.dart';
|
||||||
import 'package:web3dart/credentials.dart';
|
|
||||||
import 'package:web3dart/web3dart.dart';
|
import 'package:web3dart/web3dart.dart';
|
||||||
|
// import 'package:string_to_hex/string_to_hex.dart';
|
||||||
|
// import 'package:web3dart/credentials.dart';
|
||||||
|
// import 'package:web3dart/web3dart.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
import 'package:stackwallet/hive/db.dart';
|
import 'package:stackwallet/hive/db.dart';
|
||||||
|
@ -20,9 +24,7 @@ const int MINIMUM_CONFIRMATIONS = 1;
|
||||||
const int DUST_LIMIT = 294;
|
const int DUST_LIMIT = 294;
|
||||||
|
|
||||||
const String GENESIS_HASH_MAINNET =
|
const String GENESIS_HASH_MAINNET =
|
||||||
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
|
"0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa";
|
||||||
const String GENESIS_HASH_TESTNET =
|
|
||||||
"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";
|
|
||||||
|
|
||||||
class EthereumWallet extends CoinServiceAPI {
|
class EthereumWallet extends CoinServiceAPI {
|
||||||
@override
|
@override
|
||||||
|
@ -50,6 +52,10 @@ class EthereumWallet extends CoinServiceAPI {
|
||||||
late SecureStorageInterface _secureStore;
|
late SecureStorageInterface _secureStore;
|
||||||
|
|
||||||
late PriceAPI _priceAPI;
|
late PriceAPI _priceAPI;
|
||||||
|
final _prefs = Prefs.instance;
|
||||||
|
final _client = Web3Client(
|
||||||
|
"https://mainnet.infura.io/v3/22677300bf774e49a458b73313ee56ba",
|
||||||
|
Client());
|
||||||
|
|
||||||
EthereumWallet(
|
EthereumWallet(
|
||||||
{required String walletId,
|
{required String walletId,
|
||||||
|
@ -130,15 +136,56 @@ class EthereumWallet extends CoinServiceAPI {
|
||||||
bool get hasCalledExit => throw UnimplementedError();
|
bool get hasCalledExit => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> initializeExisting() {
|
Future<void> initializeExisting() async {
|
||||||
// TODO: implement initializeExisting
|
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||||
throw UnimplementedError();
|
level: LogLevel.Info);
|
||||||
|
|
||||||
|
if ((DB.instance.get<dynamic>(boxName: walletId, key: "id")) == null) {
|
||||||
|
throw Exception(
|
||||||
|
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||||
|
}
|
||||||
|
await _prefs.init();
|
||||||
|
final data =
|
||||||
|
DB.instance.get<dynamic>(boxName: walletId, key: "latest_tx_model")
|
||||||
|
as TransactionData?;
|
||||||
|
if (data != null) {
|
||||||
|
_transactionData = Future(() => data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> initializeNew() {
|
Future<void> initializeNew() async {
|
||||||
// TODO: implement initializeNew
|
await _prefs.init();
|
||||||
throw UnimplementedError();
|
final String mnemonic = bip39.generateMnemonic(strength: 256);
|
||||||
|
final credentials =
|
||||||
|
EthPrivateKey.fromHex(StringToHex.toHexString(mnemonic));
|
||||||
|
|
||||||
|
final String password = generatePassword();
|
||||||
|
var rng = Random.secure();
|
||||||
|
Wallet wallet = Wallet.createNew(credentials, password, rng);
|
||||||
|
|
||||||
|
await _secureStore.write(key: '${_walletId}_mnemonic', value: mnemonic);
|
||||||
|
|
||||||
|
await DB.instance
|
||||||
|
.put<dynamic>(boxName: walletId, key: "id", value: _walletId);
|
||||||
|
await DB.instance.put<dynamic>(
|
||||||
|
boxName: walletId, key: 'receivingAddresses', value: ["0"]);
|
||||||
|
await DB.instance
|
||||||
|
.put<dynamic>(boxName: walletId, key: "receivingIndex", value: 0);
|
||||||
|
await DB.instance
|
||||||
|
.put<dynamic>(boxName: walletId, key: "changeIndex", value: 0);
|
||||||
|
await DB.instance.put<dynamic>(
|
||||||
|
boxName: walletId,
|
||||||
|
key: 'blocked_tx_hashes',
|
||||||
|
value: ["0xdefault"],
|
||||||
|
); // A list of transaction hashes to represent frozen utxos in wallet
|
||||||
|
// initialize address book entries
|
||||||
|
await DB.instance.put<dynamic>(
|
||||||
|
boxName: walletId,
|
||||||
|
key: 'addressBookEntries',
|
||||||
|
value: <String, String>{});
|
||||||
|
await DB.instance
|
||||||
|
.put<dynamic>(boxName: walletId, key: "isFavorite", value: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -154,8 +201,17 @@ class EthereumWallet extends CoinServiceAPI {
|
||||||
Future<int> get maxFee => throw UnimplementedError();
|
Future<int> get maxFee => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement mnemonic
|
Future<List<String>> get mnemonic => _getMnemonicList();
|
||||||
Future<List<String>> get mnemonic => throw UnimplementedError();
|
|
||||||
|
Future<List<String>> _getMnemonicList() async {
|
||||||
|
final mnemonicString =
|
||||||
|
await _secureStore.read(key: '${_walletId}_mnemonic');
|
||||||
|
if (mnemonicString == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
final List<String> data = mnemonicString.split(' ');
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement pendingBalance
|
// TODO: implement pendingBalance
|
||||||
|
@ -206,8 +262,11 @@ class EthereumWallet extends CoinServiceAPI {
|
||||||
Future<Decimal> get totalBalance => throw UnimplementedError();
|
Future<Decimal> get totalBalance => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement transactionData
|
Future<TransactionData> get transactionData =>
|
||||||
Future<TransactionData> get transactionData => throw UnimplementedError();
|
_transactionData ??= _fetchTransactionData();
|
||||||
|
Future<TransactionData>? _transactionData;
|
||||||
|
|
||||||
|
TransactionData? cachedTxData;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement unspentOutputs
|
// TODO: implement unspentOutputs
|
||||||
|
@ -231,6 +290,10 @@ class EthereumWallet extends CoinServiceAPI {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<TransactionData> _fetchTransactionData() async {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get walletId => _walletId;
|
String get walletId => _walletId;
|
||||||
late String _walletId;
|
late String _walletId;
|
||||||
|
|
|
@ -87,7 +87,7 @@ class PriceAPI {
|
||||||
Map<Coin, Tuple2<Decimal, double>> result = {};
|
Map<Coin, Tuple2<Decimal, double>> result = {};
|
||||||
try {
|
try {
|
||||||
final uri = Uri.parse(
|
final uri = Uri.parse(
|
||||||
"https://api.coingecko.com/api/v3/coins/markets?vs_currency=${baseCurrency.toLowerCase()}&ids=monero,bitcoin,litecoin,epic-cash,zcoin,dogecoin,bitcoin-cash,namecoin,wownero&order=market_cap_desc&per_page=10&page=1&sparkline=false");
|
"https://api.coingecko.com/api/v3/coins/markets?vs_currency=${baseCurrency.toLowerCase()}&ids=monero,bitcoin,litecoin,epic-cash,zcoin,dogecoin,bitcoin-cash,namecoin,wownero,ethereum&order=market_cap_desc&per_page=10&page=1&sparkline=false");
|
||||||
// final uri = Uri.parse(
|
// final uri = Uri.parse(
|
||||||
// "https://api.coingecko.com/api/v3/coins/markets?vs_currency=${baseCurrency.toLowerCase()}&ids=monero%2Cbitcoin%2Cepic-cash%2Czcoin%2Cdogecoin&order=market_cap_desc&per_page=10&page=1&sparkline=false");
|
// "https://api.coingecko.com/api/v3/coins/markets?vs_currency=${baseCurrency.toLowerCase()}&ids=monero%2Cbitcoin%2Cepic-cash%2Czcoin%2Cdogecoin&order=market_cap_desc&per_page=10&page=1&sparkline=false");
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:convert';
|
||||||
|
|
||||||
import 'package:stackwallet/models/node_model.dart';
|
import 'package:stackwallet/models/node_model.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:web3dart/browser.dart';
|
// import 'package:web3dart/browser.dart';
|
||||||
|
|
||||||
abstract class DefaultNodes {
|
abstract class DefaultNodes {
|
||||||
static const String defaultNodeIdPrefix = "default_";
|
static const String defaultNodeIdPrefix = "default_";
|
||||||
|
|
|
@ -89,8 +89,7 @@ dependencies:
|
||||||
bs58check: ^1.0.2
|
bs58check: ^1.0.2
|
||||||
|
|
||||||
# Eth Plugins
|
# Eth Plugins
|
||||||
web3dart:
|
web3dart: 2.3.5
|
||||||
2.3.5
|
|
||||||
string_to_hex: 0.2.2
|
string_to_hex: 0.2.2
|
||||||
|
|
||||||
# Storage plugins
|
# Storage plugins
|
||||||
|
|
Loading…
Reference in a new issue