2024-03-04 19:42:57 +00:00
|
|
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
2022-01-27 09:20:51 +00:00
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
String addressFromOutputScript(Script script, BasedUtxoNetwork network) {
|
2022-01-27 09:20:51 +00:00
|
|
|
try {
|
2024-03-04 19:42:57 +00:00
|
|
|
switch (script.getAddressType()) {
|
|
|
|
case P2pkhAddressType.p2pkh:
|
|
|
|
return P2pkhAddress.fromScriptPubkey(script: script).toAddress(network);
|
|
|
|
case P2shAddressType.p2pkInP2sh:
|
|
|
|
return P2shAddress.fromScriptPubkey(script: script).toAddress(network);
|
|
|
|
case SegwitAddresType.p2wpkh:
|
|
|
|
return P2wpkhAddress.fromScriptPubkey(script: script).toAddress(network);
|
|
|
|
case P2shAddressType.p2pkhInP2sh:
|
|
|
|
return P2shAddress.fromScriptPubkey(script: script).toAddress(network);
|
|
|
|
case SegwitAddresType.p2wsh:
|
|
|
|
return P2wshAddress.fromScriptPubkey(script: script).toAddress(network);
|
|
|
|
case SegwitAddresType.p2tr:
|
|
|
|
return P2trAddress.fromScriptPubkey(script: script).toAddress(network);
|
|
|
|
default:
|
|
|
|
}
|
2022-01-27 09:20:51 +00:00
|
|
|
} catch (_) {}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
return '';
|
2024-03-04 19:42:57 +00:00
|
|
|
}
|