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

260 lines
6.7 KiB
Dart
Raw Normal View History

2023-11-06 21:55:34 +00:00
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
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 {
Dogecoin(super.network) {
2024-05-15 21:20:45 +00:00
_idMain = "dogecoin";
_uriScheme = "dogecoin";
switch (network) {
case CryptoCurrencyNetwork.main:
2024-05-15 21:20:45 +00:00
_id = _idMain;
_name = "Dogecoin";
_ticker = "DOGE";
case CryptoCurrencyNetwork.test:
2024-05-15 21:20:45 +00:00
_id = "dogecoinTestNet";
_name = "tDogecoin";
_ticker = "tDOGE";
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;
@override
bool get torSupport => true;
@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
coinlib.Network get networkParams {
2023-11-06 21:55:34 +00:00
switch (network) {
case CryptoCurrencyNetwork.main:
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-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
2023-11-06 21:55:34 +00:00
);
case CryptoCurrencyNetwork.test:
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-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
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;
}
}
@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),
useSSL: true,
enabled: true,
2024-05-15 21:20:45 +00:00
coinName: identifier,
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),
useSSL: true,
enabled: true,
2024-05-15 21:20:45 +00:00
coinName: identifier,
isFailover: true,
isDown: false,
);
default:
throw UnimplementedError();
}
}
@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;
@override
2024-05-15 21:20:45 +00:00
List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength, 24];
@override
AddressType get defaultAddressType => defaultDerivePathType.getAddressType();
2024-05-15 21:20:45 +00:00
@override
BigInt get satsPerCoin => BigInt.from(100000000);
@override
int get targetBlockTimeSeconds => 60;
@override
DerivePathType get defaultDerivePathType => DerivePathType.bip44;
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/DOGE/$txid");
case CryptoCurrencyNetwork.test:
return Uri.parse("https://chain.so/tx/DOGETEST/$txid");
default:
throw Exception(
"Unsupported network for defaultBlockExplorer(): $network",
);
}
}
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(1000000);
// https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md
2023-11-06 21:55:34 +00:00
}