2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-01-25 16:08:27 +00:00
|
|
|
import 'package:bip32/bip32.dart' as bip32;
|
|
|
|
import 'package:bip39/bip39.dart' as bip39;
|
2023-03-30 20:50:58 +00:00
|
|
|
import 'package:decimal/decimal.dart';
|
2023-01-25 16:08:27 +00:00
|
|
|
import "package:hex/hex.dart";
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../wallets/crypto_currency/crypto_currency.dart';
|
2023-01-20 17:24:19 +00:00
|
|
|
|
2023-01-26 18:08:12 +00:00
|
|
|
class GasTracker {
|
2023-03-30 20:50:58 +00:00
|
|
|
final Decimal average;
|
|
|
|
final Decimal fast;
|
|
|
|
final Decimal slow;
|
|
|
|
|
|
|
|
final int numberOfBlocksFast;
|
|
|
|
final int numberOfBlocksAverage;
|
|
|
|
final int numberOfBlocksSlow;
|
|
|
|
|
2023-04-11 21:34:17 +00:00
|
|
|
final String lastBlock;
|
2023-01-26 18:08:12 +00:00
|
|
|
|
|
|
|
const GasTracker({
|
2023-01-27 12:32:05 +00:00
|
|
|
required this.average,
|
|
|
|
required this.fast,
|
|
|
|
required this.slow,
|
2023-03-30 20:50:58 +00:00
|
|
|
required this.numberOfBlocksFast,
|
|
|
|
required this.numberOfBlocksAverage,
|
|
|
|
required this.numberOfBlocksSlow,
|
2023-04-11 21:34:17 +00:00
|
|
|
required this.lastBlock,
|
2023-01-26 18:08:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
factory GasTracker.fromJson(Map<String, dynamic> json) {
|
2024-05-15 21:20:45 +00:00
|
|
|
final targetTime =
|
|
|
|
Ethereum(CryptoCurrencyNetwork.main).targetBlockTimeSeconds;
|
2023-01-26 18:08:12 +00:00
|
|
|
return GasTracker(
|
2023-04-11 21:34:17 +00:00
|
|
|
fast: Decimal.parse(json["FastGasPrice"].toString()),
|
|
|
|
average: Decimal.parse(json["ProposeGasPrice"].toString()),
|
|
|
|
slow: Decimal.parse(json["SafeGasPrice"].toString()),
|
|
|
|
// TODO fix hardcoded
|
|
|
|
numberOfBlocksFast: 30 ~/ targetTime,
|
|
|
|
numberOfBlocksAverage: 180 ~/ targetTime,
|
|
|
|
numberOfBlocksSlow: 240 ~/ targetTime,
|
|
|
|
lastBlock: json["LastBlock"] as String,
|
2023-01-26 18:08:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-14 17:43:48 +00:00
|
|
|
const hdPathEthereum = "m/44'/60'/0'/0";
|
2023-01-25 16:08:27 +00:00
|
|
|
|
2023-03-27 14:43:35 +00:00
|
|
|
// equal to "0x${keccak256("Transfer(address,address,uint256)".toUint8ListFromUtf8).toHex}";
|
|
|
|
const kTransferEventSignature =
|
|
|
|
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
|
|
|
2023-02-14 17:43:48 +00:00
|
|
|
String getPrivateKey(String mnemonic, String mnemonicPassphrase) {
|
2023-01-25 16:08:27 +00:00
|
|
|
final isValidMnemonic = bip39.validateMnemonic(mnemonic);
|
|
|
|
if (!isValidMnemonic) {
|
|
|
|
throw 'Invalid mnemonic';
|
2023-01-20 17:24:19 +00:00
|
|
|
}
|
2023-01-25 16:08:27 +00:00
|
|
|
|
2023-02-14 17:43:48 +00:00
|
|
|
final seed = bip39.mnemonicToSeed(mnemonic, passphrase: mnemonicPassphrase);
|
2023-01-25 16:08:27 +00:00
|
|
|
final root = bip32.BIP32.fromSeed(seed);
|
|
|
|
const index = 0;
|
2023-02-14 17:43:48 +00:00
|
|
|
final addressAtIndex = root.derivePath("$hdPathEthereum/$index");
|
2023-01-25 16:08:27 +00:00
|
|
|
|
|
|
|
return HEX.encode(addressAtIndex.privateKey as List<int>);
|
2023-01-20 17:24:19 +00:00
|
|
|
}
|