cake_wallet/cw_bitcoin/lib/address_from_output.dart

23 lines
568 B
Dart
Raw Normal View History

import 'dart:typed_data';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
String addressFromOutput(Uint8List script, bitcoin.NetworkType networkType) {
try {
return bitcoin.P2PKH(
data: PaymentData(output: script),
network: networkType)
.data
2022-10-12 17:09:57 +00:00
.address!;
} catch (_) {}
try {
return bitcoin.P2WPKH(
data: PaymentData(output: script),
network: networkType)
.data
2022-10-12 17:09:57 +00:00
.address!;
} catch(_) {}
2022-10-12 17:09:57 +00:00
return '';
}