2023-11-16 21:30:01 +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';
|
2024-06-05 22:19:33 +00:00
|
|
|
import '../../wallet/wallet_mixin_interfaces/spark_interface.dart';
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../crypto_currency.dart';
|
|
|
|
import '../interfaces/electrumx_currency_interface.dart';
|
|
|
|
import '../intermediate/bip39_hd_currency.dart';
|
2023-11-16 21:30:01 +00:00
|
|
|
|
2024-05-15 21:20:45 +00:00
|
|
|
class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
2023-11-16 21:30:01 +00:00
|
|
|
Firo(super.network) {
|
2024-05-15 21:20:45 +00:00
|
|
|
_idMain = "firo";
|
|
|
|
_uriScheme = "firo";
|
2023-11-16 21:30:01 +00:00
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
2024-05-15 21:20:45 +00:00
|
|
|
_id = _idMain;
|
|
|
|
_name = "Firo";
|
|
|
|
_ticker = "FIRO";
|
2023-11-16 21:30:01 +00:00
|
|
|
case CryptoCurrencyNetwork.test:
|
2024-05-15 21:20:45 +00:00
|
|
|
_id = "firoTestNet";
|
|
|
|
_name = "tFiro";
|
|
|
|
_ticker = "tFIRO";
|
2023-11-16 21:30:01 +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;
|
|
|
|
|
2023-11-16 21:30:01 +00:00
|
|
|
@override
|
|
|
|
int get minConfirms => 1;
|
|
|
|
|
2024-04-16 22:42:51 +00:00
|
|
|
@override
|
|
|
|
bool get torSupport => true;
|
|
|
|
|
2023-11-16 21:30:01 +00:00
|
|
|
@override
|
|
|
|
List<DerivePathType> get supportedDerivationPathTypes => [
|
|
|
|
DerivePathType.bip44,
|
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get genesisHash {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return "4381deb85b1b2c9843c222944b616d997516dcbd6a964e1eaf0def0830695233";
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return "aa22adcc12becaf436027ffe62a8fb21b234c58c23865291e5dc52cf53f64fca";
|
|
|
|
default:
|
|
|
|
throw Exception("Unsupported network: $network");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Amount get dustLimit => Amount(
|
|
|
|
rawValue: BigInt.from(1000),
|
|
|
|
fractionDigits: fractionDigits,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
2024-03-22 21:19:48 +00:00
|
|
|
coinlib.Network get networkParams {
|
2023-11-16 21:30:01 +00:00
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
2024-03-22 21:19:48 +00:00
|
|
|
return coinlib.Network(
|
2023-11-16 21:30:01 +00:00
|
|
|
wifPrefix: 0xd2,
|
|
|
|
p2pkhPrefix: 0x52,
|
|
|
|
p2shPrefix: 0x07,
|
|
|
|
privHDPrefix: 0x0488ade4,
|
|
|
|
pubHDPrefix: 0x0488b21e,
|
|
|
|
bech32Hrp: "bc",
|
|
|
|
messagePrefix: '\x18Zcoin 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-16 21:30:01 +00:00
|
|
|
);
|
|
|
|
case CryptoCurrencyNetwork.test:
|
2024-03-22 21:19:48 +00:00
|
|
|
return coinlib.Network(
|
2023-11-16 21:30:01 +00:00
|
|
|
wifPrefix: 0xb9,
|
|
|
|
p2pkhPrefix: 0x41,
|
|
|
|
p2shPrefix: 0xb2,
|
|
|
|
privHDPrefix: 0x04358394,
|
|
|
|
pubHDPrefix: 0x043587cf,
|
|
|
|
bech32Hrp: "tb",
|
|
|
|
messagePrefix: "\x18Zcoin 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-16 21:30:01 +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 0xd2: // firo mainnet wif
|
|
|
|
coinType = "136"; // firo mainnet
|
|
|
|
break;
|
|
|
|
case 0xb9: // firo testnet wif
|
|
|
|
coinType = "1"; // firo testnet
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw Exception("Invalid Firo network wif used!");
|
|
|
|
}
|
|
|
|
|
|
|
|
final 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
|
|
|
|
({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
|
|
|
|
bool validateAddress(String address) {
|
|
|
|
try {
|
|
|
|
coinlib.Address.fromString(address, networkParams);
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
2023-12-19 15:20:50 +00:00
|
|
|
return validateSparkAddress(address);
|
2023-11-16 21:30:01 +00:00
|
|
|
}
|
2023-12-19 15:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool validateSparkAddress(String address) {
|
|
|
|
return SparkInterface.validateSparkAddress(
|
|
|
|
address: address,
|
|
|
|
isTestNet: network == CryptoCurrencyNetwork.test,
|
|
|
|
);
|
2023-11-16 21:30:01 +00:00
|
|
|
}
|
2023-11-17 01:44:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
NodeModel get defaultNode {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return NodeModel(
|
|
|
|
host: "firo.stackwallet.com",
|
|
|
|
port: 50002,
|
|
|
|
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:
|
|
|
|
// NodeModel(
|
|
|
|
// host: "firo-testnet.stackwallet.com",
|
|
|
|
// port: 50002,
|
|
|
|
// name: DefaultNodes.defaultName,
|
|
|
|
// id: _nodeId(Coin.firoTestNet),
|
|
|
|
// useSSL: true,
|
|
|
|
// enabled: true,
|
|
|
|
// coinName: Coin.firoTestNet.name,
|
|
|
|
// isFailover: true,
|
|
|
|
// isDown: false,
|
|
|
|
// );
|
|
|
|
|
|
|
|
// TODO revert to above eventually
|
|
|
|
return NodeModel(
|
|
|
|
host: "95.179.164.13",
|
|
|
|
port: 51002,
|
|
|
|
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 => false;
|
|
|
|
|
|
|
|
@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 => 150;
|
|
|
|
|
|
|
|
@override
|
|
|
|
DerivePathType get primaryDerivePathType => DerivePathType.bip44;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Uri defaultBlockExplorer(String txid) {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
return Uri.parse("https://explorer.firo.org/tx/$txid");
|
|
|
|
case CryptoCurrencyNetwork.test:
|
|
|
|
return Uri.parse("https://testexplorer.firo.org/tx/$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
|
|
|
|
int get defaultFeeRate => 1000;
|
2023-11-16 21:30:01 +00:00
|
|
|
}
|