2024-01-04 19:17:00 +00:00
|
|
|
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
|
2024-06-05 22:19:33 +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 '../interfaces/electrumx_currency_interface.dart';
|
|
|
|
import '../intermediate/bip39_hd_currency.dart';
|
2024-01-04 19:17:00 +00:00
|
|
|
|
2024-05-15 21:20:45 +00:00
|
|
|
class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
2024-01-04 19:17:00 +00:00
|
|
|
Litecoin(super.network) {
|
2024-05-15 21:20:45 +00:00
|
|
|
_idMain = "litecoin";
|
|
|
|
_uriScheme = "litecoin";
|
2024-01-04 19:17:00 +00:00
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
2024-05-15 21:20:45 +00:00
|
|
|
_id = _idMain;
|
|
|
|
_name = "Litecoin";
|
|
|
|
_ticker = "LTC";
|
2024-01-04 19:17:00 +00:00
|
|
|
case CryptoCurrencyNetwork.test:
|
2024-05-15 21:20:45 +00:00
|
|
|
_id = "litecoinTestNet";
|
|
|
|
_name = "tLitecoin";
|
|
|
|
_ticker = "tLTC";
|
2024-01-04 19:17:00 +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-04 19:17:00 +00:00
|
|
|
@override
|
|
|
|
// change this to change the number of confirms a tx needs in order to show as confirmed
|
|
|
|
int get minConfirms => 1;
|
|
|
|
|
2024-04-16 22:42:51 +00:00
|
|
|
@override
|
|
|
|
bool get torSupport => true;
|
|
|
|
|
2024-01-04 19:17:00 +00:00
|
|
|
@override
|
|
|
|
List<DerivePathType> get supportedDerivationPathTypes => [
|
|
|
|
DerivePathType.bip44,
|
2024-01-11 19:36:53 +00:00
|
|
|
DerivePathType.bip49,
|
2024-01-04 19:17:00 +00:00
|
|
|
DerivePathType.bip84,
|
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get genesisHash {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return "12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2";
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return "4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0";
|
|
|
|
default:
|
|
|
|
throw Exception("Unsupported network: $network");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Amount get dustLimit => Amount(
|
|
|
|
rawValue: BigInt.from(294),
|
|
|
|
fractionDigits: fractionDigits,
|
|
|
|
);
|
|
|
|
|
|
|
|
Amount get dustLimitP2PKH => Amount(
|
|
|
|
rawValue: BigInt.from(546),
|
|
|
|
fractionDigits: fractionDigits,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
2024-03-22 21:19:48 +00:00
|
|
|
coinlib.Network get networkParams {
|
2024-01-04 19:17:00 +00:00
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
2024-03-22 21:19:48 +00:00
|
|
|
return coinlib.Network(
|
2024-01-04 19:17:00 +00:00
|
|
|
wifPrefix: 0xb0,
|
|
|
|
p2pkhPrefix: 0x30,
|
|
|
|
p2shPrefix: 0x32,
|
|
|
|
privHDPrefix: 0x0488ade4,
|
|
|
|
pubHDPrefix: 0x0488b21e,
|
|
|
|
bech32Hrp: "ltc",
|
|
|
|
messagePrefix: '\x19Litecoin 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-01-04 19:17:00 +00:00
|
|
|
);
|
|
|
|
case CryptoCurrencyNetwork.test:
|
2024-03-22 21:19:48 +00:00
|
|
|
return coinlib.Network(
|
2024-01-04 19:17:00 +00:00
|
|
|
wifPrefix: 0xef,
|
|
|
|
p2pkhPrefix: 0x6f,
|
|
|
|
p2shPrefix: 0x3a,
|
|
|
|
privHDPrefix: 0x04358394,
|
|
|
|
pubHDPrefix: 0x043587cf,
|
|
|
|
bech32Hrp: "tltc",
|
|
|
|
messagePrefix: "\x19Litecoin 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-01-04 19:17:00 +00:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
throw Exception("Unsupported network: $network");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String constructDerivePath({
|
|
|
|
required DerivePathType derivePathType,
|
|
|
|
int account = 0,
|
|
|
|
required int chain,
|
|
|
|
required int index,
|
|
|
|
}) {
|
|
|
|
String coinType;
|
|
|
|
|
|
|
|
switch (networkParams.wifPrefix) {
|
|
|
|
case 0xb0: // ltc mainnet wif
|
|
|
|
coinType = "2"; // ltc mainnet
|
|
|
|
break;
|
|
|
|
case 0xef: // ltc testnet wif
|
|
|
|
coinType = "1"; // ltc testnet
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw Exception("Invalid Bitcoin network wif used!");
|
|
|
|
}
|
|
|
|
|
|
|
|
final int purpose;
|
|
|
|
switch (derivePathType) {
|
|
|
|
case DerivePathType.bip44:
|
|
|
|
purpose = 44;
|
|
|
|
break;
|
2024-01-11 19:36:53 +00:00
|
|
|
case DerivePathType.bip49:
|
|
|
|
purpose = 49;
|
|
|
|
break;
|
2024-01-04 19:17:00 +00:00
|
|
|
case DerivePathType.bip84:
|
|
|
|
purpose = 84;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw Exception("DerivePathType $derivePathType not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
return "m/$purpose'/$coinType'/$account'/$chain/$index";
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
({coinlib.Address address, AddressType addressType}) getAddressForPublicKey({
|
|
|
|
required coinlib.ECPublicKey publicKey,
|
|
|
|
required DerivePathType derivePathType,
|
|
|
|
}) {
|
|
|
|
switch (derivePathType) {
|
|
|
|
case DerivePathType.bip44:
|
|
|
|
final addr = coinlib.P2PKHAddress.fromPublicKey(
|
|
|
|
publicKey,
|
|
|
|
version: networkParams.p2pkhPrefix,
|
|
|
|
);
|
|
|
|
|
|
|
|
return (address: addr, addressType: AddressType.p2pkh);
|
|
|
|
|
2024-01-11 19:36:53 +00:00
|
|
|
case DerivePathType.bip49:
|
|
|
|
final p2wpkhScript = coinlib.P2WPKHAddress.fromPublicKey(
|
|
|
|
publicKey,
|
|
|
|
hrp: networkParams.bech32Hrp,
|
|
|
|
).program.script;
|
|
|
|
|
2024-03-22 21:19:57 +00:00
|
|
|
final addr = coinlib.P2SHAddress.fromRedeemScript(
|
2024-01-11 19:36:53 +00:00
|
|
|
p2wpkhScript,
|
|
|
|
version: networkParams.p2shPrefix,
|
|
|
|
);
|
|
|
|
|
|
|
|
return (address: addr, addressType: AddressType.p2sh);
|
2024-01-04 19:17:00 +00:00
|
|
|
|
|
|
|
case DerivePathType.bip84:
|
|
|
|
final addr = coinlib.P2WPKHAddress.fromPublicKey(
|
|
|
|
publicKey,
|
|
|
|
hrp: networkParams.bech32Hrp,
|
|
|
|
);
|
|
|
|
|
|
|
|
return (address: addr, addressType: AddressType.p2wpkh);
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw Exception("DerivePathType $derivePathType not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool validateAddress(String address) {
|
|
|
|
try {
|
|
|
|
coinlib.Address.fromString(address, networkParams);
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
NodeModel get defaultNode {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return NodeModel(
|
|
|
|
host: "litecoin.stackwallet.com",
|
|
|
|
port: 20063,
|
|
|
|
name: DefaultNodes.defaultName,
|
2024-05-15 21:20:45 +00:00
|
|
|
id: DefaultNodes.buildId(this),
|
2024-01-04 19:17:00 +00:00
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
2024-05-15 21:20:45 +00:00
|
|
|
coinName: identifier,
|
2024-01-04 19:17:00 +00:00
|
|
|
isFailover: true,
|
|
|
|
isDown: false,
|
|
|
|
);
|
|
|
|
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return NodeModel(
|
|
|
|
host: "litecoin.stackwallet.com",
|
|
|
|
port: 51002,
|
|
|
|
name: DefaultNodes.defaultName,
|
2024-05-15 21:20:45 +00:00
|
|
|
id: DefaultNodes.buildId(this),
|
2024-01-04 19:17:00 +00:00
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
2024-05-15 21:20:45 +00:00
|
|
|
coinName: identifier,
|
2024-01-04 19:17:00 +00:00
|
|
|
isFailover: true,
|
|
|
|
isDown: false,
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
|
|
|
}
|
2024-04-17 18:04:10 +00:00
|
|
|
|
|
|
|
@override
|
2024-05-15 21:20:45 +00:00
|
|
|
int get defaultSeedPhraseLength => 12;
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get fractionDigits => 8;
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get hasBuySupport => true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get hasMnemonicPassphraseSupport => true;
|
2024-04-17 18:04:10 +00:00
|
|
|
|
|
|
|
@override
|
2024-05-15 21:20:45 +00:00
|
|
|
List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength, 24];
|
|
|
|
|
|
|
|
@override
|
2024-06-20 16:16:12 +00:00
|
|
|
AddressType get defaultAddressType => defaultDerivePathType.getAddressType();
|
2024-05-15 21:20:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
BigInt get satsPerCoin => BigInt.from(100000000);
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get targetBlockTimeSeconds => 150;
|
|
|
|
|
|
|
|
@override
|
2024-06-20 16:16:12 +00:00
|
|
|
DerivePathType get defaultDerivePathType => DerivePathType.bip84;
|
2024-05-15 21:20:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Uri defaultBlockExplorer(String txid) {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return Uri.parse("https://chain.so/tx/LTC/$txid");
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return Uri.parse("https://chain.so/tx/LTCTEST/$txid");
|
|
|
|
default:
|
|
|
|
throw Exception(
|
|
|
|
"Unsupported network for defaultBlockExplorer(): $network",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-06-05 22:19:33 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
int get transactionVersion => 1;
|
2024-06-07 20:56:57 +00:00
|
|
|
|
|
|
|
@override
|
2024-06-07 22:04:42 +00:00
|
|
|
BigInt get defaultFeeRate => BigInt.from(1000);
|
2024-01-04 19:17:00 +00:00
|
|
|
}
|