2023-11-06 21:55:34 +00:00
|
|
|
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
|
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';
|
2023-11-06 21:55:34 +00:00
|
|
|
|
2024-05-15 21:20:45 +00:00
|
|
|
class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
2023-11-07 18:19:42 +00:00
|
|
|
Dogecoin(super.network) {
|
2024-05-15 21:20:45 +00:00
|
|
|
_idMain = "dogecoin";
|
|
|
|
_uriScheme = "dogecoin";
|
2023-11-07 18:19:42 +00:00
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
2024-05-15 21:20:45 +00:00
|
|
|
_id = _idMain;
|
|
|
|
_name = "Dogecoin";
|
|
|
|
_ticker = "DOGE";
|
2023-11-07 18:19:42 +00:00
|
|
|
case CryptoCurrencyNetwork.test:
|
2024-05-15 21:20:45 +00:00
|
|
|
_id = "dogecoinTestNet";
|
|
|
|
_name = "tDogecoin";
|
|
|
|
_ticker = "tDOGE";
|
2023-11-07 18:19:42 +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-04-16 22:42:51 +00:00
|
|
|
@override
|
|
|
|
bool get torSupport => true;
|
|
|
|
|
2023-11-07 18:19:42 +00:00
|
|
|
@override
|
|
|
|
List<DerivePathType> get supportedDerivationPathTypes => [
|
|
|
|
DerivePathType.bip44,
|
|
|
|
];
|
2023-11-06 21:55:34 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String constructDerivePath({
|
|
|
|
required DerivePathType derivePathType,
|
|
|
|
int account = 0,
|
|
|
|
required int chain,
|
|
|
|
required int index,
|
|
|
|
}) {
|
|
|
|
String coinType;
|
|
|
|
|
|
|
|
switch (networkParams.wifPrefix) {
|
|
|
|
case 0x9e: // doge mainnet wif
|
|
|
|
coinType = "3"; // doge mainnet
|
|
|
|
break;
|
|
|
|
case 0xf1: // doge testnet wif
|
|
|
|
coinType = "1"; // doge testnet
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw Exception("Invalid Dogecoin network wif used!");
|
|
|
|
}
|
|
|
|
|
|
|
|
int purpose;
|
|
|
|
switch (derivePathType) {
|
|
|
|
case DerivePathType.bip44:
|
|
|
|
purpose = 44;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw Exception("DerivePathType $derivePathType not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
return "m/$purpose'/$coinType'/$account'/$chain/$index";
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Amount get dustLimit => Amount(
|
|
|
|
rawValue: BigInt.from(1000000),
|
2024-05-15 21:20:45 +00:00
|
|
|
fractionDigits: fractionDigits,
|
2023-11-06 21:55:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get genesisHash {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return "1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691";
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e";
|
|
|
|
default:
|
|
|
|
throw Exception("Unsupported network: $network");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw Exception("DerivePathType $derivePathType not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get minConfirms => 1;
|
|
|
|
|
|
|
|
@override
|
2024-03-22 21:19:48 +00:00
|
|
|
coinlib.Network get networkParams {
|
2023-11-06 21:55:34 +00:00
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
2024-03-22 21:19:48 +00:00
|
|
|
return coinlib.Network(
|
2023-11-06 21:55:34 +00:00
|
|
|
wifPrefix: 0x9e,
|
|
|
|
p2pkhPrefix: 0x1e,
|
|
|
|
p2shPrefix: 0x16,
|
|
|
|
privHDPrefix: 0x02fac398,
|
|
|
|
pubHDPrefix: 0x02facafd,
|
|
|
|
bech32Hrp: "doge",
|
|
|
|
messagePrefix: '\x18Dogecoin Signed Message:\n',
|
2024-03-22 21:19:48 +00:00
|
|
|
minFee: BigInt.from(1), // TODO [prio=high].
|
2024-04-15 19:22:30 +00:00
|
|
|
minOutput: dustLimit.raw, // TODO.
|
2024-03-22 21:19:48 +00:00
|
|
|
feePerKb: BigInt.from(1), // TODO.
|
2023-11-06 21:55:34 +00:00
|
|
|
);
|
|
|
|
case CryptoCurrencyNetwork.test:
|
2024-03-22 21:19:48 +00:00
|
|
|
return coinlib.Network(
|
2023-11-06 21:55:34 +00:00
|
|
|
wifPrefix: 0xf1,
|
|
|
|
p2pkhPrefix: 0x71,
|
|
|
|
p2shPrefix: 0xc4,
|
|
|
|
privHDPrefix: 0x04358394,
|
|
|
|
pubHDPrefix: 0x043587cf,
|
|
|
|
bech32Hrp: "tdge",
|
|
|
|
messagePrefix: "\x18Dogecoin Signed Message:\n",
|
2024-03-22 21:19:48 +00:00
|
|
|
minFee: BigInt.from(1), // TODO [prio=high].
|
2024-04-15 19:22:30 +00:00
|
|
|
minOutput: dustLimit.raw, // TODO.
|
2024-03-22 21:19:48 +00:00
|
|
|
feePerKb: BigInt.from(1), // TODO.
|
2023-11-06 21:55:34 +00:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
throw Exception("Unsupported network: $network");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool validateAddress(String address) {
|
|
|
|
try {
|
|
|
|
coinlib.Address.fromString(address, networkParams);
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-11-17 01:44:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
NodeModel get defaultNode {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return NodeModel(
|
|
|
|
host: "dogecoin.stackwallet.com",
|
|
|
|
port: 50022,
|
|
|
|
name: DefaultNodes.defaultName,
|
2024-05-15 21:20:45 +00:00
|
|
|
id: DefaultNodes.buildId(this),
|
2023-11-17 01:44:17 +00:00
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
2024-05-15 21:20:45 +00:00
|
|
|
coinName: identifier,
|
2023-11-17 01:44:17 +00:00
|
|
|
isFailover: true,
|
|
|
|
isDown: false,
|
|
|
|
);
|
|
|
|
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return NodeModel(
|
|
|
|
host: "dogecoin-testnet.stackwallet.com",
|
|
|
|
port: 50022,
|
|
|
|
name: DefaultNodes.defaultName,
|
2024-05-15 21:20:45 +00:00
|
|
|
id: DefaultNodes.buildId(this),
|
2023-11-17 01:44:17 +00:00
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
2024-05-15 21:20:45 +00:00
|
|
|
coinName: identifier,
|
2023-11-17 01:44:17 +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
|
|
|
|
AddressType get primaryAddressType => AddressType.p2pkh;
|
|
|
|
|
|
|
|
@override
|
|
|
|
BigInt get satsPerCoin => BigInt.from(100000000);
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get targetBlockTimeSeconds => 60;
|
|
|
|
|
|
|
|
@override
|
|
|
|
DerivePathType get primaryDerivePathType => DerivePathType.bip44;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Uri defaultBlockExplorer(String txid) {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return Uri.parse("https://chain.so/tx/DOGE/$txid");
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return Uri.parse("https://chain.so/tx/DOGETEST/$txid");
|
|
|
|
default:
|
|
|
|
throw Exception(
|
|
|
|
"Unsupported network for defaultBlockExplorer(): $network",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 21:55:34 +00:00
|
|
|
}
|