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