mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
EXTRACT FUNCTION FOR PARSING BLINDED PAYMENT CODE FROM A TRANSACTION
This commit is contained in:
parent
95d1f3c17e
commit
6a0673bec5
2 changed files with 30 additions and 15 deletions
|
@ -16,6 +16,7 @@ import 'package:stackwallet/exceptions/wallet/insufficient_balance_exception.dar
|
||||||
import 'package:stackwallet/exceptions/wallet/paynym_send_exception.dart';
|
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/utilities/bip32_utils.dart';
|
import 'package:stackwallet/utilities/bip32_utils.dart';
|
||||||
|
import 'package:stackwallet/utilities/bip47_utils.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/enums/derive_path_type_enum.dart';
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
|
@ -696,21 +697,8 @@ mixin PaynymWalletInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uint8List? blindedCodeBytes;
|
final blindedCodeBytes =
|
||||||
|
Bip47Utils.getBlindedPaymentCodeBytesFrom(transaction);
|
||||||
for (int i = 0; i < transaction.outputs.length; i++) {
|
|
||||||
List<String>? scriptChunks =
|
|
||||||
transaction.outputs.elementAt(1).scriptPubKeyAsm?.split(" ");
|
|
||||||
if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") {
|
|
||||||
final blindedPaymentCode = scriptChunks![1];
|
|
||||||
final bytes = blindedPaymentCode.fromHex;
|
|
||||||
|
|
||||||
// https://en.bitcoin.it/wiki/BIP_0047#Sending
|
|
||||||
if (bytes.length == 80 && bytes.first == 1) {
|
|
||||||
blindedCodeBytes = bytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// transaction does not contain a payment code
|
// transaction does not contain a payment code
|
||||||
if (blindedCodeBytes == null) {
|
if (blindedCodeBytes == null) {
|
||||||
|
|
27
lib/utilities/bip47_utils.dart
Normal file
27
lib/utilities/bip47_utils.dart
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:bip47/src/util.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
|
||||||
|
|
||||||
|
abstract class Bip47Utils {
|
||||||
|
/// looks at tx outputs and returns a blinded payment code if found
|
||||||
|
static Uint8List? getBlindedPaymentCodeBytesFrom(Transaction transaction) {
|
||||||
|
Uint8List? blindedCodeBytes;
|
||||||
|
|
||||||
|
for (int i = 0; i < transaction.outputs.length; i++) {
|
||||||
|
List<String>? scriptChunks =
|
||||||
|
transaction.outputs.elementAt(i).scriptPubKeyAsm?.split(" ");
|
||||||
|
if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") {
|
||||||
|
final blindedPaymentCode = scriptChunks![1];
|
||||||
|
final bytes = blindedPaymentCode.fromHex;
|
||||||
|
|
||||||
|
// https://en.bitcoin.it/wiki/BIP_0047#Sending
|
||||||
|
if (bytes.length == 80 && bytes.first == 1) {
|
||||||
|
blindedCodeBytes = bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return blindedCodeBytes;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue