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
|
|
|
|
2024-05-23 00:37:06 +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-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;
|
|
|
|
|
2024-04-16 22:42:51 +00:00
|
|
|
@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
|
|
|
|
|
|
|
default:
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get genesisHash {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";
|
|
|
|
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
|
|
|
|
String pubKeyToScriptHash({required Uint8List pubKey}) {
|
|
|
|
try {
|
|
|
|
return Bip39HDCurrency.convertBytesToScriptHash(pubKey);
|
|
|
|
} 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:
|
|
|
|
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
|
|
|
}
|
2024-04-17 18:04:10 +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 primaryAddressType => AddressType.frostMS;
|
|
|
|
|
|
|
|
@override
|
|
|
|
BigInt get satsPerCoin => BigInt.from(100000000);
|
2024-04-17 18:04:10 +00:00
|
|
|
|
|
|
|
@override
|
2024-05-15 21:20:45 +00:00
|
|
|
int get targetBlockTimeSeconds => 600;
|
|
|
|
|
|
|
|
@override
|
|
|
|
DerivePathType get primaryDerivePathType => throw UnsupportedError(
|
|
|
|
"$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");
|
|
|
|
default:
|
|
|
|
throw Exception(
|
|
|
|
"Unsupported network for defaultBlockExplorer(): $network",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 23:47:06 +00:00
|
|
|
}
|