99
1010import java .util .Arrays ;
1111import java .util .List ;
12+ import java .util .Optional ;
1213
1314public class Secp256k1Blake160MultisigAllScriptHandler implements ScriptHandler {
14- private List <CellDep > cellDeps ;
15- private byte [] codeHash ;
16- private Script .HashType hashType ;
17- private MultisigVersion multisigVersion ;
15+ private Network network ;
1816
19- public Secp256k1Blake160MultisigAllScriptHandler (MultisigVersion multisigVersion ) {
20- this .multisigVersion = multisigVersion ;
17+ public Secp256k1Blake160MultisigAllScriptHandler () {
2118 }
2219
23- public List <CellDep > getCellDeps () {
24- return cellDeps ;
25- }
26-
27- public void setCellDeps (List <CellDep > cellDeps ) {
28- this .cellDeps = cellDeps ;
29- }
30-
31- public byte [] getCodeHash () {
32- return codeHash ;
33- }
34-
35- public void setCodeHash (byte [] codeHash ) {
36- this .codeHash = codeHash ;
37- }
38-
39- public Script .HashType getHashType () {
40- return hashType ;
41- }
42-
43- public void setHashType (Script .HashType hashType ) {
44- this .hashType = hashType ;
45- }
46-
47- public MultisigVersion getMultisigVersion () {
48- return multisigVersion ;
49- }
50-
51- public void setMultisigVersion (MultisigVersion multisigVersion ) {
52- this .multisigVersion = multisigVersion ;
53- }
54-
55- @ Override
56- public void init (Network network ) {
20+ public List <CellDep > getCellDeps (MultisigVersion multisigVersion ) {
5721 OutPoint outPoint = new OutPoint ();
58- if (network == Network .MAINNET ) {
59- switch (this . multisigVersion ) {
22+ if (this . network == Network .MAINNET ) {
23+ switch (multisigVersion ) {
6024 case Legacy :
6125 outPoint .txHash = Numeric .hexStringToByteArray ("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c" );
6226 outPoint .index = 1 ;
@@ -68,8 +32,8 @@ public void init(Network network) {
6832 default :
6933 throw new IllegalArgumentException ("Unsupported multisig version" );
7034 }
71- } else if (network == Network .TESTNET ) {
72- switch (this . multisigVersion ) {
35+ } else if (this . network == Network .TESTNET ) {
36+ switch (multisigVersion ) {
7337 case Legacy :
7438 outPoint .txHash = Numeric .hexStringToByteArray ("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37" );
7539 outPoint .index = 1 ;
@@ -87,23 +51,41 @@ public void init(Network network) {
8751 CellDep cellDep = new CellDep ();
8852 cellDep .outPoint = outPoint ;
8953 cellDep .depType = CellDep .DepType .DEP_GROUP ;
90- cellDeps = Arrays .asList (cellDep );
91- this .codeHash = this .multisigVersion .codeHash ();
92- this .hashType = this .multisigVersion .hashType ();
54+ return Arrays .asList (cellDep );
55+ }
56+
57+
58+ @ Override
59+ public void init (Network network ) {
60+ this .network = network ;
9361 }
9462
95- private boolean isMatched (Script script ) {
63+ private Optional < MultisigVersion > isMatched (Script script ) {
9664 if (script == null ) {
97- return false ;
65+ return Optional .empty ();
66+ }
67+
68+ if (Arrays .equals (script .codeHash , MultisigVersion .Legacy .codeHash ()) && script .hashType == MultisigVersion .Legacy .hashType ()) {
69+ return Optional .of (MultisigVersion .Legacy );
70+ } else if (Arrays .equals (script .codeHash , MultisigVersion .V2 .codeHash ()) && script .hashType == MultisigVersion .V2 .hashType ()) {
71+ return Optional .of (MultisigVersion .V2 );
72+ } else {
73+ return Optional .empty ();
9874 }
99- return Arrays .equals (script .codeHash , codeHash ) && script .hashType == hashType ;
10075 }
10176
10277 @ Override
10378 public boolean buildTransaction (AbstractTransactionBuilder txBuilder , ScriptGroup scriptGroup , Object context ) {
104- if (scriptGroup == null || ! isMatched ( scriptGroup . getScript ()) ) {
79+ if (scriptGroup == null ) {
10580 return false ;
10681 }
82+ Optional <MultisigVersion > multisigVersion = isMatched (scriptGroup .getScript ());
83+ if (!multisigVersion .isPresent ()) {
84+ return false ;
85+ }
86+
87+ List <CellDep > cellDeps = this .getCellDeps (multisigVersion .get ());
88+
10789 Secp256k1Blake160MultisigAllSigner .MultisigScript multisigScript ;
10890 if (context instanceof Secp256k1Blake160MultisigAllSigner .MultisigScript ) {
10991 multisigScript = (Secp256k1Blake160MultisigAllSigner .MultisigScript ) context ;
0 commit comments