mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 20:09:23 +00:00
implement more namecoin methods
This commit is contained in:
parent
621aff4796
commit
0230575575
2 changed files with 123 additions and 25 deletions
|
@ -19,18 +19,43 @@ class Namecoin extends Bip39HDCurrency {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement minConfirms
|
// See https://github.com/cypherstack/stack_wallet/blob/621aff47969761014e0a6c4e699cb637d5687ab3/lib/services/coins/namecoin/namecoin_wallet.dart#L58
|
||||||
int get minConfirms => throw UnimplementedError();
|
int get minConfirms => 2;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
// See https://github.com/cypherstack/stack_wallet/blob/621aff47969761014e0a6c4e699cb637d5687ab3/lib/services/coins/namecoin/namecoin_wallet.dart#L80
|
||||||
String constructDerivePath({
|
String constructDerivePath({
|
||||||
required DerivePathType derivePathType,
|
required DerivePathType derivePathType,
|
||||||
int account = 0,
|
int account = 0,
|
||||||
required int chain,
|
required int chain,
|
||||||
required int index,
|
required int index,
|
||||||
}) {
|
}) {
|
||||||
// TODO: implement constructDerivePath
|
String coinType;
|
||||||
throw UnimplementedError();
|
switch (networkParams.wifPrefix) {
|
||||||
|
case 0xb4: // NMC mainnet wif.
|
||||||
|
coinType = "7"; // NMC mainnet.
|
||||||
|
break;
|
||||||
|
// TODO: [prio=low] Add testnet support.
|
||||||
|
default:
|
||||||
|
throw Exception("Invalid Namecoin network wif used!");
|
||||||
|
}
|
||||||
|
|
||||||
|
int purpose;
|
||||||
|
switch (derivePathType) {
|
||||||
|
case DerivePathType.bip44:
|
||||||
|
purpose = 44;
|
||||||
|
break;
|
||||||
|
case DerivePathType.bip49:
|
||||||
|
purpose = 49;
|
||||||
|
break;
|
||||||
|
case DerivePathType.bip84:
|
||||||
|
purpose = 84;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw Exception("DerivePathType $derivePathType not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "m/$purpose'/$coinType'/$account'/$chain/$index";
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -48,40 +73,97 @@ class Namecoin extends Bip39HDCurrency {
|
||||||
isFailover: true,
|
isFailover: true,
|
||||||
isDown: false,
|
isDown: false,
|
||||||
);
|
);
|
||||||
|
// case CryptoCurrencyNetwork.test:
|
||||||
|
// TODO: [prio=low] Add testnet support.
|
||||||
default:
|
default:
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement dustLimit
|
// See https://github.com/cypherstack/stack_wallet/blob/621aff47969761014e0a6c4e699cb637d5687ab3/lib/services/coins/namecoin/namecoin_wallet.dart#L60
|
||||||
Amount get dustLimit => throw UnimplementedError();
|
Amount get dustLimit =>
|
||||||
|
Amount(rawValue: BigInt.from(546), fractionDigits: Coin.particl.decimals);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement genesisHash
|
// See https://github.com/cypherstack/stack_wallet/blob/621aff47969761014e0a6c4e699cb637d5687ab3/lib/services/coins/namecoin/namecoin_wallet.dart#L6
|
||||||
String get genesisHash => throw UnimplementedError();
|
String get genesisHash {
|
||||||
|
switch (network) {
|
||||||
|
case CryptoCurrencyNetwork.main:
|
||||||
|
return "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770";
|
||||||
|
case CryptoCurrencyNetwork.test:
|
||||||
|
return "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008";
|
||||||
|
default:
|
||||||
|
throw Exception("Unsupported network: $network");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
({coinlib.Address address, AddressType addressType}) getAddressForPublicKey(
|
({coinlib.Address address, AddressType addressType}) getAddressForPublicKey(
|
||||||
{required coinlib.ECPublicKey publicKey,
|
{required coinlib.ECPublicKey publicKey,
|
||||||
required DerivePathType derivePathType}) {
|
required DerivePathType derivePathType}) {
|
||||||
// TODO: implement getAddressForPublicKey
|
switch (derivePathType) {
|
||||||
throw UnimplementedError();
|
// case DerivePathType.bip16: // TODO: [prio=low] Add P2SH support.
|
||||||
|
|
||||||
|
case DerivePathType.bip44:
|
||||||
|
final addr = coinlib.P2PKHAddress.fromPublicKey(
|
||||||
|
publicKey,
|
||||||
|
version: networkParams.p2pkhPrefix,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (address: addr, addressType: AddressType.p2pkh);
|
||||||
|
|
||||||
|
// case DerivePathType.bip49:
|
||||||
|
|
||||||
|
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
|
@override
|
||||||
// TODO: implement networkParams
|
// See https://github.com/cypherstack/stack_wallet/blob/621aff47969761014e0a6c4e699cb637d5687ab3/lib/services/coins/namecoin/namecoin_wallet.dart#L3474
|
||||||
coinlib.NetworkParams get networkParams => throw UnimplementedError();
|
coinlib.NetworkParams get networkParams {
|
||||||
|
switch (network) {
|
||||||
|
case CryptoCurrencyNetwork.main:
|
||||||
|
return const coinlib.NetworkParams(
|
||||||
|
wifPrefix: 0xb4, // From 180.
|
||||||
|
p2pkhPrefix: 0x34, // From 52.
|
||||||
|
p2shPrefix: 0x0d, // From 13.
|
||||||
|
privHDPrefix: 0x0488ade4,
|
||||||
|
pubHDPrefix: 0x0488b21e,
|
||||||
|
bech32Hrp: "nc",
|
||||||
|
messagePrefix: '\x18Namecoin Signed Message:\n',
|
||||||
|
);
|
||||||
|
// case CryptoCurrencyNetwork.test:
|
||||||
|
// TODO: [prio=low] Add testnet support.
|
||||||
|
default:
|
||||||
|
throw Exception("Unsupported network: $network");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement supportedDerivationPathTypes
|
List<DerivePathType> get supportedDerivationPathTypes => [
|
||||||
List<DerivePathType> get supportedDerivationPathTypes =>
|
// DerivePathType.bip16, // TODO: [prio=low] Add P2SH support.
|
||||||
throw UnimplementedError();
|
DerivePathType.bip44,
|
||||||
|
// DerivePathType.bip49,
|
||||||
|
DerivePathType.bip84,
|
||||||
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool validateAddress(String address) {
|
bool validateAddress(String address) {
|
||||||
// TODO: implement validateAddress
|
try {
|
||||||
throw UnimplementedError();
|
coinlib.Address.fromString(address, networkParams);
|
||||||
|
return true;
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
|
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/coin_control_interface.dart';
|
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/coin_control_interface.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart';
|
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class NamecoinWallet extends Bip39HDWallet
|
class NamecoinWallet extends Bip39HDWallet
|
||||||
with ElectrumXInterface, CoinControlInterface {
|
with ElectrumXInterface, CoinControlInterface {
|
||||||
|
@ -46,9 +47,9 @@ class NamecoinWallet extends Bip39HDWallet
|
||||||
@override
|
@override
|
||||||
Future<({bool blocked, String? blockedReason, String? utxoLabel})>
|
Future<({bool blocked, String? blockedReason, String? utxoLabel})>
|
||||||
checkBlockUTXO(Map<String, dynamic> jsonUTXO, String? scriptPubKeyHex,
|
checkBlockUTXO(Map<String, dynamic> jsonUTXO, String? scriptPubKeyHex,
|
||||||
Map<String, dynamic> jsonTX, String? utxoOwnerAddress) {
|
Map<String, dynamic> jsonTX, String? utxoOwnerAddress) async {
|
||||||
// TODO: implement checkBlockUTXO
|
// Namecoin doesn't have special outputs like tokens, ordinals, etc.
|
||||||
throw UnimplementedError();
|
return (blocked: false, blockedReason: null, utxoLabel: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -56,7 +57,7 @@ class NamecoinWallet extends Bip39HDWallet
|
||||||
return vSize * (feeRatePerKB / 1000).ceil();
|
return vSize * (feeRatePerKB / 1000).ceil();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: [prio=low] Check if this is the correct formula for namecoin. ECF
|
// TODO: Check if this is the correct formula for namecoin.
|
||||||
@override
|
@override
|
||||||
Amount roughFeeEstimate(int inputCount, int outputCount, int feeRatePerKB) {
|
Amount roughFeeEstimate(int inputCount, int outputCount, int feeRatePerKB) {
|
||||||
return Amount(
|
return Amount(
|
||||||
|
@ -68,8 +69,23 @@ class NamecoinWallet extends Bip39HDWallet
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateTransactions() {
|
Future<void> updateTransactions() async {
|
||||||
// TODO: implement updateTransactions
|
final currentChainHeight = await fetchChainHeight();
|
||||||
throw UnimplementedError();
|
|
||||||
|
// TODO: [prio=a] switch to V2 transactions
|
||||||
|
final data = await fetchTransactionsV1(
|
||||||
|
addresses: await fetchAddressesForElectrumXScan(),
|
||||||
|
currentChainHeight: currentChainHeight,
|
||||||
|
);
|
||||||
|
|
||||||
|
await mainDB.addNewTransactionData(
|
||||||
|
data
|
||||||
|
.map((e) => Tuple2(
|
||||||
|
e.transaction,
|
||||||
|
e.address,
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
walletId,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue