mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 19:39:22 +00:00
add support to make adding segwit paynym support simple once implemented
This commit is contained in:
parent
79db4f048c
commit
9c44dc6c6b
7 changed files with 129 additions and 80 deletions
|
@ -12,6 +12,7 @@ import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.da
|
|||
import 'package:stackwallet/services/coins/coin_paynym_extension.dart';
|
||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
@ -168,7 +169,8 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
|
|||
if (shouldCancel) return;
|
||||
|
||||
// get payment code
|
||||
final pCode = await wallet.getPaymentCode();
|
||||
final pCode = await wallet.getPaymentCode(
|
||||
DerivePathTypeExt.primaryFor(wallet.coin));
|
||||
|
||||
if (shouldCancel) return;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:stackwallet/services/coins/coin_paynym_extension.dart';
|
|||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
|
@ -120,7 +121,8 @@ class _WalletNavigationBarState extends State<WalletNavigationBar> {
|
|||
.getManager(widget.walletId)
|
||||
.wallet as DogecoinWallet);
|
||||
|
||||
final code = await wallet.getPaymentCode();
|
||||
final code = await wallet.getPaymentCode(
|
||||
DerivePathTypeExt.primaryFor(wallet.coin));
|
||||
|
||||
final account = await ref
|
||||
.read(paynymAPIProvider)
|
||||
|
|
|
@ -31,6 +31,7 @@ import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart
|
|||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
|
@ -304,7 +305,8 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
.getManager(widget.walletId)
|
||||
.wallet as DogecoinWallet);
|
||||
|
||||
final code = await wallet.getPaymentCode();
|
||||
final code =
|
||||
await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(wallet.coin));
|
||||
|
||||
final account = await ref.read(paynymAPIProvider).nym(code.toString());
|
||||
|
||||
|
|
|
@ -14,12 +14,11 @@ import 'package:stackwallet/exceptions/wallet/paynym_send_exception.dart';
|
|||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||
import 'package:stackwallet/utilities/bip32_utils.dart';
|
||||
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
import '../../utilities/enums/derive_path_type_enum.dart';
|
||||
|
||||
const kPaynymDerivePath = "m/47'/0'/0'";
|
||||
|
||||
extension PayNym on DogecoinWallet {
|
||||
|
@ -66,8 +65,10 @@ extension PayNym on DogecoinWallet {
|
|||
}
|
||||
|
||||
Future<Future<Map<String, dynamic>>> preparePaymentCodeSend(
|
||||
PaymentCode paymentCode, int satoshiAmount) async {
|
||||
if (!(await hasConnected(paymentCode.notificationAddress()))) {
|
||||
{required PaymentCode paymentCode,
|
||||
required int satoshiAmount,
|
||||
Map<String, dynamic>? args}) async {
|
||||
if (!(await hasConnected(paymentCode.notificationAddressP2PKH()))) {
|
||||
throw PaynymSendException(
|
||||
"No notification transaction sent to $paymentCode");
|
||||
} else {
|
||||
|
@ -360,7 +361,8 @@ extension PayNym on DogecoinWallet {
|
|||
txPointIndex,
|
||||
);
|
||||
|
||||
txb.addOutput(targetPaymentCode.notificationAddress(), DUST_LIMIT);
|
||||
// todo: modify address once segwit support is in our bip47
|
||||
txb.addOutput(targetPaymentCode.notificationAddressP2PKH(), DUST_LIMIT);
|
||||
txb.addOutput(opReturnScript, 0);
|
||||
|
||||
// TODO: add possible change output and mark output as dangerous
|
||||
|
@ -420,8 +422,8 @@ extension PayNym on DogecoinWallet {
|
|||
|
||||
// TODO optimize
|
||||
Future<bool> hasConnected(String paymentCodeString) async {
|
||||
final myCode = await getPaymentCode(DerivePathType.bip44);
|
||||
final myNotificationAddress = myCode.notificationAddress();
|
||||
final myNotificationAddress =
|
||||
await getMyNotificationAddress(DerivePathTypeExt.primaryFor(coin));
|
||||
|
||||
final txns = await db
|
||||
.getTransactions(walletId)
|
||||
|
@ -431,13 +433,13 @@ extension PayNym on DogecoinWallet {
|
|||
|
||||
for (final tx in txns) {
|
||||
// quick check that may cause problems?
|
||||
if (tx.address.value?.value == myNotificationAddress) {
|
||||
if (tx.address.value?.value == myNotificationAddress.value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final unBlindedPaymentCode = await unBlindedPaymentCodeFromTransaction(
|
||||
transaction: tx,
|
||||
myCode: myCode,
|
||||
myNotificationAddress: myNotificationAddress,
|
||||
);
|
||||
|
||||
if (paymentCodeString == unBlindedPaymentCode.toString()) {
|
||||
|
@ -451,10 +453,10 @@ extension PayNym on DogecoinWallet {
|
|||
|
||||
Future<PaymentCode?> unBlindedPaymentCodeFromTransaction({
|
||||
required Transaction transaction,
|
||||
required PaymentCode myCode,
|
||||
required Address myNotificationAddress,
|
||||
}) async {
|
||||
if (transaction.address.value != null &&
|
||||
transaction.address.value!.value != myCode.notificationAddress()) {
|
||||
transaction.address.value!.value != myNotificationAddress.value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -498,7 +500,8 @@ extension PayNym on DogecoinWallet {
|
|||
|
||||
Future<List<PaymentCode>>
|
||||
getAllPaymentCodesFromNotificationTransactions() async {
|
||||
final myCode = await getPaymentCode(DerivePathType.bip44);
|
||||
final myAddress =
|
||||
await getMyNotificationAddress(DerivePathTypeExt.primaryFor(coin));
|
||||
final txns = await db
|
||||
.getTransactions(walletId)
|
||||
.filter()
|
||||
|
@ -510,7 +513,7 @@ extension PayNym on DogecoinWallet {
|
|||
for (final tx in txns) {
|
||||
final unBlinded = await unBlindedPaymentCodeFromTransaction(
|
||||
transaction: tx,
|
||||
myCode: myCode,
|
||||
myNotificationAddress: myAddress,
|
||||
);
|
||||
if (unBlinded != null) {
|
||||
unBlindedList.add(unBlinded);
|
||||
|
@ -603,32 +606,34 @@ extension PayNym on DogecoinWallet {
|
|||
btc_dart.P2PKH(data: data, network: network).data.address!;
|
||||
break;
|
||||
|
||||
// The following doesn't apply to doge currently
|
||||
case DerivePathType.bip49:
|
||||
addressString = btc_dart
|
||||
.P2SH(
|
||||
data: btc_dart.PaymentData(
|
||||
redeem: btc_dart
|
||||
.P2WPKH(
|
||||
data: data,
|
||||
network: network,
|
||||
)
|
||||
.data),
|
||||
network: network,
|
||||
)
|
||||
.data
|
||||
.address!;
|
||||
break;
|
||||
|
||||
case DerivePathType.bip84:
|
||||
addressString = btc_dart
|
||||
.P2WPKH(
|
||||
network: network,
|
||||
data: data,
|
||||
)
|
||||
.data
|
||||
.address!;
|
||||
break;
|
||||
// The following doesn't apply currently
|
||||
// case DerivePathType.bip49:
|
||||
// addressString = btc_dart
|
||||
// .P2SH(
|
||||
// data: btc_dart.PaymentData(
|
||||
// redeem: btc_dart
|
||||
// .P2WPKH(
|
||||
// data: data,
|
||||
// network: network,
|
||||
// )
|
||||
// .data),
|
||||
// network: network,
|
||||
// )
|
||||
// .data
|
||||
// .address!;
|
||||
// break;
|
||||
//
|
||||
// case DerivePathType.bip84:
|
||||
// addressString = btc_dart
|
||||
// .P2WPKH(
|
||||
// network: network,
|
||||
// data: data,
|
||||
// )
|
||||
// .data
|
||||
// .address!;
|
||||
// break;
|
||||
default:
|
||||
throw UnimplementedError("segwit paynyms not implemented yet");
|
||||
}
|
||||
|
||||
final address = Address(
|
||||
|
@ -666,34 +671,36 @@ extension PayNym on DogecoinWallet {
|
|||
addrType = AddressType.p2pkh;
|
||||
break;
|
||||
|
||||
// The following doesn't apply to doge currently
|
||||
case DerivePathType.bip49:
|
||||
addressString = btc_dart
|
||||
.P2SH(
|
||||
data: btc_dart.PaymentData(
|
||||
redeem: btc_dart
|
||||
.P2WPKH(
|
||||
data: data,
|
||||
network: network,
|
||||
)
|
||||
.data),
|
||||
network: network,
|
||||
)
|
||||
.data
|
||||
.address!;
|
||||
addrType = AddressType.p2sh;
|
||||
break;
|
||||
|
||||
case DerivePathType.bip84:
|
||||
addressString = btc_dart
|
||||
.P2WPKH(
|
||||
network: network,
|
||||
data: data,
|
||||
)
|
||||
.data
|
||||
.address!;
|
||||
addrType = AddressType.p2wpkh;
|
||||
break;
|
||||
// The following doesn't apply currently
|
||||
// case DerivePathType.bip49:
|
||||
// addressString = btc_dart
|
||||
// .P2SH(
|
||||
// data: btc_dart.PaymentData(
|
||||
// redeem: btc_dart
|
||||
// .P2WPKH(
|
||||
// data: data,
|
||||
// network: network,
|
||||
// )
|
||||
// .data),
|
||||
// network: network,
|
||||
// )
|
||||
// .data
|
||||
// .address!;
|
||||
// addrType = AddressType.p2sh;
|
||||
// break;
|
||||
//
|
||||
// case DerivePathType.bip84:
|
||||
// addressString = btc_dart
|
||||
// .P2WPKH(
|
||||
// network: network,
|
||||
// data: data,
|
||||
// )
|
||||
// .data
|
||||
// .address!;
|
||||
// addrType = AddressType.p2wpkh;
|
||||
// break;
|
||||
default:
|
||||
throw UnimplementedError("segwit paynyms not implemented yet");
|
||||
}
|
||||
|
||||
final address = Address(
|
||||
|
@ -712,6 +719,9 @@ extension PayNym on DogecoinWallet {
|
|||
Future<Address> getMyNotificationAddress(
|
||||
DerivePathType derivePathType,
|
||||
) async {
|
||||
// TODO: fix when segwit is here
|
||||
derivePathType = DerivePathType.bip44;
|
||||
|
||||
AddressType type;
|
||||
switch (derivePathType) {
|
||||
case DerivePathType.bip44:
|
||||
|
@ -748,14 +758,44 @@ extension PayNym on DogecoinWallet {
|
|||
);
|
||||
|
||||
String addressString;
|
||||
final data =
|
||||
btc_dart.PaymentData(pubkey: paymentCode.notificationPublicKey());
|
||||
switch (derivePathType) {
|
||||
case DerivePathType.bip44:
|
||||
addressString = paymentCode.notificationAddress();
|
||||
addressString = btc_dart
|
||||
.P2PKH(
|
||||
data: data,
|
||||
network: network,
|
||||
)
|
||||
.data
|
||||
.address!;
|
||||
break;
|
||||
case DerivePathType.bip49:
|
||||
throw Exception("DerivePathType not supported.");
|
||||
case DerivePathType.bip84:
|
||||
throw Exception("DerivePathType not supported.");
|
||||
// case DerivePathType.bip49:
|
||||
// addressString = btc_dart
|
||||
// .P2SH(
|
||||
// data: btc_dart.PaymentData(
|
||||
// redeem: btc_dart
|
||||
// .P2WPKH(
|
||||
// data: data,
|
||||
// network: network,
|
||||
// )
|
||||
// .data),
|
||||
// network: network,
|
||||
// )
|
||||
// .data
|
||||
// .address!;
|
||||
// break;
|
||||
// case DerivePathType.bip84:
|
||||
// addressString = btc_dart
|
||||
// .P2WPKH(
|
||||
// network: network,
|
||||
// data: data,
|
||||
// )
|
||||
// .data
|
||||
// .address!;
|
||||
// break;
|
||||
default:
|
||||
throw UnimplementedError("segwit paynyms not implemented yet");
|
||||
}
|
||||
|
||||
final address = Address(
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.da
|
|||
import 'package:stackwallet/services/coins/coin_paynym_extension.dart';
|
||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||
|
@ -67,7 +68,8 @@ class _PaynymFollowToggleButtonState
|
|||
.read(paynymAPIProvider)
|
||||
.nym(widget.paymentCodeStringToFollow, true);
|
||||
|
||||
final myPCode = await wallet.getPaymentCode();
|
||||
final myPCode =
|
||||
await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(wallet.coin));
|
||||
|
||||
PaynymResponse<String> token =
|
||||
await ref.read(paynymAPIProvider).token(myPCode.toString());
|
||||
|
@ -167,7 +169,8 @@ class _PaynymFollowToggleButtonState
|
|||
.read(paynymAPIProvider)
|
||||
.nym(widget.paymentCodeStringToFollow, true);
|
||||
|
||||
final myPCode = await wallet.getPaymentCode();
|
||||
final myPCode =
|
||||
await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(wallet.coin));
|
||||
|
||||
PaynymResponse<String> token =
|
||||
await ref.read(paynymAPIProvider).token(myPCode.toString());
|
||||
|
|
|
@ -100,8 +100,8 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "2d800225329498841affa1386d96d2696c62b713"
|
||||
resolved-ref: "2d800225329498841affa1386d96d2696c62b713"
|
||||
ref: "87bb760be323228aed6ca7bd4532a709a4f10690"
|
||||
resolved-ref: "87bb760be323228aed6ca7bd4532a709a4f10690"
|
||||
url: "https://github.com/cypherstack/bip47.git"
|
||||
source: git
|
||||
version: "1.0.0"
|
||||
|
|
|
@ -59,7 +59,7 @@ dependencies:
|
|||
bip47:
|
||||
git:
|
||||
url: https://github.com/cypherstack/bip47.git
|
||||
ref: 2d800225329498841affa1386d96d2696c62b713
|
||||
ref: 87bb760be323228aed6ca7bd4532a709a4f10690
|
||||
|
||||
# Utility plugins
|
||||
# provider: ^6.0.1
|
||||
|
|
Loading…
Reference in a new issue