From e6109e5689ec80ae7544e8451f55b8880cce2bea Mon Sep 17 00:00:00 2001 From: Stephan February Date: Fri, 20 Oct 2023 14:12:05 +0800 Subject: [PATCH] Updated P2PKH Builder fromScript() constructor - The fromScript() constructor did not previously rebuild the internal address, because we lacked a Address.fromPubkeyHash(). Fixed now. --- lib/src/transaction/p2pkh_builder.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/transaction/p2pkh_builder.dart b/lib/src/transaction/p2pkh_builder.dart index c1d46e0..7c08839 100644 --- a/lib/src/transaction/p2pkh_builder.dart +++ b/lib/src/transaction/p2pkh_builder.dart @@ -9,18 +9,20 @@ class P2PKHLockBuilder extends LockingScriptBuilder { Address? address; List? pubkeyHash; + NetworkType? networkType; P2PKHLockBuilder.fromAddress(Address address){ this.address = address; + this.networkType = address.networkType; pubkeyHash = HEX.decode(address.pubkeyHash160); } - P2PKHLockBuilder.fromPublicKey(SVPublicKey publicKey, {NetworkType networkType = NetworkType.MAIN}){ - this.address = publicKey.toAddress(networkType); + P2PKHLockBuilder.fromPublicKey(SVPublicKey publicKey, {this.networkType = NetworkType.MAIN}){ + this.address = publicKey.toAddress(networkType ?? NetworkType.MAIN); pubkeyHash = HEX.decode(address!.pubkeyHash160); } - P2PKHLockBuilder.fromScript(SVScript script) : super.fromScript(script); + P2PKHLockBuilder.fromScript(SVScript script, {this.networkType = NetworkType.MAIN}) : super.fromScript(script); @override SVScript getScriptPubkey() { @@ -60,6 +62,7 @@ class P2PKHLockBuilder extends LockingScriptBuilder { } pubkeyHash = chunkList[2].buf; + address = Address.fromPubkeyHash(HEX.encode(pubkeyHash ?? []), networkType ?? NetworkType.MAIN); } }