Skip to content

Commit

Permalink
Merge pull request #78 from twostack/p2pkh-builder-update
Browse files Browse the repository at this point in the history
Updated P2PKH Builder fromScript() constructor
  • Loading branch information
stephanfeb authored Oct 20, 2023
2 parents 6319ed1 + e6109e5 commit 31fa906
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/transaction/p2pkh_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ class P2PKHLockBuilder extends LockingScriptBuilder {

Address? address;
List<int>? 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() {
Expand Down Expand Up @@ -60,6 +62,7 @@ class P2PKHLockBuilder extends LockingScriptBuilder {
}

pubkeyHash = chunkList[2].buf;
address = Address.fromPubkeyHash(HEX.encode(pubkeyHash ?? []), networkType ?? NetworkType.MAIN);
}
}

Expand Down

0 comments on commit 31fa906

Please sign in to comment.