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

264 lines
6.7 KiB
Dart
Raw Permalink Normal View History

2024-05-09 22:44:49 +00:00
import 'package:coinlib/src/network.dart';
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
2024-05-27 23:56:22 +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-05-09 22:44:49 +00:00
2024-05-15 21:20:45 +00:00
class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
2024-05-09 22:44:49 +00:00
Peercoin(super.network) {
2024-05-15 21:20:45 +00:00
_idMain = "peercoin";
_uriScheme = "peercoin";
2024-05-09 22:44:49 +00:00
switch (network) {
case CryptoCurrencyNetwork.main:
2024-05-15 21:20:45 +00:00
_id = "peercoin";
_name = "Peercoin";
_ticker = "PPC";
2024-05-09 22:44:49 +00:00
case CryptoCurrencyNetwork.test:
2024-05-15 21:20:45 +00:00
_id = "peercoinTestNet";
_name = "tPeercoin";
_ticker = "tPPC";
2024-05-09 22:44:49 +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-05-09 22:44:49 +00:00
@override
int get minConfirms => 1;
@override
bool get torSupport => true;
@override
2024-05-10 16:39:34 +00:00
String constructDerivePath({
required DerivePathType derivePathType,
int account = 0,
required int chain,
required int index,
}) {
2024-05-09 22:44:49 +00:00
String coinType;
switch (networkParams.wifPrefix) {
case 183: // PPC mainnet wif.
coinType =
"6"; // according to https://github.com/satoshilabs/slips/blob/master/slip-0044.md
break;
case 239: // PPC testnet wif.
coinType = "1";
2024-05-09 22:44:49 +00:00
break;
default:
throw Exception("Invalid Peercoin network wif used!");
}
int purpose;
switch (derivePathType) {
case DerivePathType.bip44:
purpose = 44;
break;
case DerivePathType.bip84:
purpose = 84;
break;
default:
throw Exception("DerivePathType $derivePathType not supported");
}
return "m/$purpose'/$coinType'/$account'/$chain/$index";
}
@override
NodeModel get defaultNode {
switch (network) {
case CryptoCurrencyNetwork.main:
2024-05-15 21:20:45 +00:00
return NodeModel(
host: "electrum.peercoinexplorer.net",
port: 50002,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
);
2024-05-09 22:44:49 +00:00
case CryptoCurrencyNetwork.test:
2024-05-15 21:20:45 +00:00
return NodeModel(
host: "testnet-electrum.peercoinexplorer.net",
port: 50002,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
);
2024-05-09 22:44:49 +00:00
default:
throw UnimplementedError();
}
}
@override
Amount get dustLimit => Amount(
2024-05-15 21:20:45 +00:00
// TODO should this be 10000 instead of 294 for peercoin?
2024-05-09 22:44:49 +00:00
rawValue: BigInt.from(294),
2024-05-15 21:20:45 +00:00
fractionDigits: fractionDigits,
2024-05-09 22:44:49 +00:00
);
@override
String get genesisHash {
switch (network) {
case CryptoCurrencyNetwork.main:
return "0000000032fe677166d54963b62a4677d8957e87c508eaa4fd7eb1c880cd27e3";
case CryptoCurrencyNetwork.test:
return "00000001f757bb737f6596503e17cd17b0658ce630cc727c0cca81aec47c9f06";
default:
throw Exception("Unsupported network: $network");
}
}
@override
2024-05-27 23:56:22 +00:00
({coinlib.Address address, AddressType addressType}) getAddressForPublicKey({
required coinlib.ECPublicKey publicKey,
required DerivePathType derivePathType,
}) {
2024-05-09 22:44:49 +00:00
switch (derivePathType) {
// case DerivePathType.bip16:
case DerivePathType.bip44:
final addr = coinlib.P2PKHAddress.fromPublicKey(
publicKey,
version: networkParams.p2pkhPrefix,
);
return (address: addr, addressType: AddressType.p2pkh);
case DerivePathType.bip49:
final p2wpkhScript = coinlib.P2WPKHAddress.fromPublicKey(
publicKey,
hrp: networkParams.bech32Hrp,
).program.script;
final addr = coinlib.P2SHAddress.fromRedeemScript(
p2wpkhScript,
version: networkParams.p2shPrefix,
);
return (address: addr, addressType: AddressType.p2sh);
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
coinlib.Network get networkParams {
switch (network) {
case CryptoCurrencyNetwork.main:
return Network.mainnet;
case CryptoCurrencyNetwork.test:
return Network.testnet;
default:
throw Exception("Unsupported network: $network");
}
}
@override
List<DerivePathType> get supportedDerivationPathTypes => [
DerivePathType.bip44,
2024-05-10 16:39:34 +00:00
DerivePathType.bip84,
2024-05-09 22:44:49 +00:00
];
@override
bool validateAddress(String address) {
try {
coinlib.Address.fromString(address, networkParams);
return true;
} catch (_) {
return false;
}
}
@override
2024-05-15 21:20:45 +00:00
int get defaultSeedPhraseLength => 12;
2024-05-09 22:44:49 +00:00
@override
2024-05-15 21:20:45 +00:00
int get fractionDigits => 6;
@override
bool get hasBuySupport => false;
@override
bool get hasMnemonicPassphraseSupport => true;
@override
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(1000000); // 1*10^6.
@override
int get targetBlockTimeSeconds => 600;
@override
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://chainz.cryptoid.info/ppc/tx.dws?$txid.htm");
case CryptoCurrencyNetwork.test:
return Uri.parse(
"https://chainz.cryptoid.info/ppc-test/search.dws?q=$txid.htm",
);
default:
throw Exception(
"Unsupported network for defaultBlockExplorer(): $network",
);
}
}
@override
int get transactionVersion => 3;
@override
BigInt get defaultFeeRate => BigInt.from(5000);
2024-05-09 22:44:49 +00:00
}