stack_wallet/lib/wallets/crypto_currency/coins/bitcoin_frost.dart

243 lines
6.6 KiB
Dart
Raw Normal View History

2024-01-18 23:47:06 +00:00
import 'dart:typed_data';
2024-05-15 21:20:45 +00:00
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
2024-06-07 14:45:56 +00:00
import '../../../models/isar/models/blockchain_data/address.dart';
import '../../../models/node_model.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/default_nodes.dart';
import '../../../utilities/enums/derive_path_type_enum.dart';
import '../crypto_currency.dart';
import '../intermediate/bip39_hd_currency.dart';
import '../intermediate/frost_currency.dart';
2024-01-18 23:47:06 +00:00
class BitcoinFrost extends FrostCurrency {
BitcoinFrost(super.network) {
2024-05-15 21:20:45 +00:00
_idMain = "bitcoinFrost";
_uriScheme = "bitcoin";
2024-01-18 23:47:06 +00:00
switch (network) {
case CryptoCurrencyNetwork.main:
2024-05-15 21:20:45 +00:00
_id = _idMain;
_name = "Bitcoin Frost";
_ticker = "BTC";
2024-01-18 23:47:06 +00:00
case CryptoCurrencyNetwork.test:
2024-05-15 21:20:45 +00:00
_id = "bitcoinFrostTestNet";
_name = "tBitcoin Frost";
_ticker = "tBTC";
2024-06-19 15:15:49 +00:00
case CryptoCurrencyNetwork.test4:
_id = "bitcoinFrostTestNet4";
_name = "t4Bitcoin Frost";
_ticker = "t4BTC";
2024-01-18 23:47:06 +00:00
default:
throw Exception("Unsupported network: $network");
}
}
2024-05-15 21:20:45 +00:00
late final String _id;
@override
String get identifier => _id;
late final String _idMain;
@override
String get mainNetId => _idMain;
late final String _name;
@override
String get prettyName => _name;
late final String _uriScheme;
@override
String get uriScheme => _uriScheme;
late final String _ticker;
@override
String get ticker => _ticker;
2024-01-18 23:47:06 +00:00
@override
int get minConfirms => 1;
@override
bool get torSupport => true;
2024-01-18 23:47:06 +00:00
@override
NodeModel get defaultNode {
switch (network) {
case CryptoCurrencyNetwork.main:
2024-05-15 21:20:45 +00:00
return NodeModel(
host: "bitcoin.stackwallet.com",
port: 50002,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
);
2024-01-18 23:47:06 +00:00
case CryptoCurrencyNetwork.test:
2024-05-15 21:20:45 +00:00
return NodeModel(
host: "bitcoin-testnet.stackwallet.com",
port: 51002,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
);
2024-01-18 23:47:06 +00:00
2024-06-19 15:15:49 +00:00
case CryptoCurrencyNetwork.test4:
return NodeModel(
host: "bitcoin-testnet4.stackwallet.com",
port: 50002,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
);
2024-01-18 23:47:06 +00:00
default:
throw UnimplementedError();
}
}
@override
String get genesisHash {
switch (network) {
case CryptoCurrencyNetwork.main:
return "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
case CryptoCurrencyNetwork.test:
return "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";
2024-06-19 15:15:49 +00:00
case CryptoCurrencyNetwork.test4:
return "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043";
2024-01-18 23:47:06 +00:00
default:
throw Exception("Unsupported network: $network");
}
}
2024-01-19 21:42:38 +00:00
@override
Amount get dustLimit => Amount(
rawValue: BigInt.from(294),
fractionDigits: fractionDigits,
);
2024-01-18 23:47:06 +00:00
@override
2024-07-17 16:17:54 +00:00
Uint8List addressToPubkey({required String address}) {
2024-01-18 23:47:06 +00:00
try {
2024-07-17 16:17:54 +00:00
final addr = coinlib.Address.fromString(address, networkParams);
return addr.program.script.compiled;
} catch (e) {
rethrow;
}
}
@override
String addressToScriptHash({required String address}) {
try {
return Bip39HDCurrency.convertBytesToScriptHash(
addressToPubkey(address: address),
);
2024-01-18 23:47:06 +00:00
} catch (e) {
rethrow;
}
}
2024-05-15 21:20:45 +00:00
coinlib.Network get networkParams {
switch (network) {
case CryptoCurrencyNetwork.main:
return coinlib.Network(
wifPrefix: 0x80,
p2pkhPrefix: 0x00,
p2shPrefix: 0x05,
privHDPrefix: 0x0488ade4,
pubHDPrefix: 0x0488b21e,
bech32Hrp: "bc",
messagePrefix: '\x18Bitcoin Signed Message:\n',
2024-06-07 14:45:56 +00:00
minFee: BigInt.from(1), // Not used in stack wallet currently
minOutput: dustLimit.raw, // Not used in stack wallet currently
feePerKb: BigInt.from(1), // Not used in stack wallet currently
2024-05-15 21:20:45 +00:00
);
case CryptoCurrencyNetwork.test:
2024-06-19 15:15:49 +00:00
case CryptoCurrencyNetwork.test4:
2024-05-15 21:20:45 +00:00
return coinlib.Network(
wifPrefix: 0xef,
p2pkhPrefix: 0x6f,
p2shPrefix: 0xc4,
privHDPrefix: 0x04358394,
pubHDPrefix: 0x043587cf,
bech32Hrp: "tb",
messagePrefix: "\x18Bitcoin Signed Message:\n",
2024-06-07 14:45:56 +00:00
minFee: BigInt.from(1), // Not used in stack wallet currently
minOutput: dustLimit.raw, // Not used in stack wallet currently
feePerKb: BigInt.from(1), // Not used in stack wallet currently
2024-05-15 21:20:45 +00:00
);
default:
throw Exception("Unsupported network: $network");
}
}
2024-01-18 23:47:06 +00:00
@override
bool validateAddress(String address) {
2024-05-15 21:20:45 +00:00
try {
coinlib.Address.fromString(address, networkParams);
return true;
} catch (_) {
return false;
}
2024-01-18 23:47:06 +00:00
}
@override
2024-05-15 21:20:45 +00:00
int get defaultSeedPhraseLength => 0;
@override
int get fractionDigits => 8;
@override
bool get hasBuySupport => false;
@override
bool get hasMnemonicPassphraseSupport => false;
@override
List<int> get possibleMnemonicLengths => [];
@override
AddressType get defaultAddressType => AddressType.frostMS;
2024-05-15 21:20:45 +00:00
@override
BigInt get satsPerCoin => BigInt.from(100000000);
@override
2024-05-15 21:20:45 +00:00
int get targetBlockTimeSeconds => 600;
@override
DerivePathType get defaultDerivePathType => throw UnsupportedError(
2024-05-15 21:20:45 +00:00
"$runtimeType does not use bitcoin style derivation paths",
);
@override
Uri defaultBlockExplorer(String txid) {
switch (network) {
case CryptoCurrencyNetwork.main:
return Uri.parse("https://mempool.space/tx/$txid");
case CryptoCurrencyNetwork.test:
return Uri.parse("https://mempool.space/testnet/tx/$txid");
2024-06-19 15:15:49 +00:00
case CryptoCurrencyNetwork.test4:
return Uri.parse("https://mempool.space/testnet4/tx/$txid");
2024-05-15 21:20:45 +00:00
default:
throw Exception(
"Unsupported network for defaultBlockExplorer(): $network",
);
}
}
// @override
BigInt get defaultFeeRate => BigInt.from(1000);
// https://github.com/bitcoin/bitcoin/blob/feab35189bc00bc4cf15e9dcb5cf6b34ff3a1e91/test/functional/mempool_limit.py#L259
2024-01-18 23:47:06 +00:00
}