44import org .nervos .ckb .sign .ScriptGroup ;
55import org .nervos .ckb .sign .signer .Secp256k1Blake160MultisigAllSigner ;
66import org .nervos .ckb .transaction .AbstractTransactionBuilder ;
7- import org .nervos .ckb .type .CellDep ;
8- import org .nervos .ckb .type .OutPoint ;
9- import org .nervos .ckb .type .Script ;
10- import org .nervos .ckb .type .WitnessArgs ;
7+ import org .nervos .ckb .type .*;
118import org .nervos .ckb .utils .Numeric ;
129
1310import java .util .Arrays ;
1613public class Secp256k1Blake160MultisigAllScriptHandler implements ScriptHandler {
1714 private List <CellDep > cellDeps ;
1815 private byte [] codeHash ;
16+ private Script .HashType hashType ;
17+ private MultisigVersion multisigVersion ;
1918
20- public Secp256k1Blake160MultisigAllScriptHandler () {
19+ public Secp256k1Blake160MultisigAllScriptHandler (MultisigVersion multisigVersion ) {
2120 }
2221
2322 public List <CellDep > getCellDeps () {
@@ -36,30 +35,67 @@ public void setCodeHash(byte[] codeHash) {
3635 this .codeHash = codeHash ;
3736 }
3837
38+ public Script .HashType getHashType () {
39+ return hashType ;
40+ }
41+
42+ public void setHashType (Script .HashType hashType ) {
43+ this .hashType = hashType ;
44+ }
45+
46+ public MultisigVersion getMultisigVersion () {
47+ return multisigVersion ;
48+ }
49+
50+ public void setMultisigVersion (MultisigVersion multisigVersion ) {
51+ this .multisigVersion = multisigVersion ;
52+ }
53+
3954 @ Override
4055 public void init (Network network ) {
4156 OutPoint outPoint = new OutPoint ();
4257 if (network == Network .MAINNET ) {
43- outPoint .txHash = Numeric .hexStringToByteArray ("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c" );
44- outPoint .index = 1 ;
58+ switch (this .multisigVersion ) {
59+ case Legacy :
60+ outPoint .txHash = Numeric .hexStringToByteArray ("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c" );
61+ outPoint .index = 1 ;
62+ break ;
63+ case V2 :
64+ outPoint .txHash = Numeric .hexStringToByteArray ("0x6888aa39ab30c570c2c30d9d5684d3769bf77265a7973211a3c087fe8efbf738" );
65+ outPoint .index = 0 ;
66+ break ;
67+ default :
68+ throw new IllegalArgumentException ("Unsupported multisig version" );
69+ }
4570 } else if (network == Network .TESTNET ) {
46- outPoint .txHash = Numeric .hexStringToByteArray ("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37" );
47- outPoint .index = 1 ;
71+ switch (this .multisigVersion ) {
72+ case Legacy :
73+ outPoint .txHash = Numeric .hexStringToByteArray ("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37" );
74+ outPoint .index = 1 ;
75+ break ;
76+ case V2 :
77+ outPoint .txHash = Numeric .hexStringToByteArray ("0x2eefdeb21f3a3edf697c28a52601b4419806ed60bb427420455cc29a090b26d5" );
78+ outPoint .index = 0 ;
79+ break ;
80+ default :
81+ throw new IllegalArgumentException ("Unsupported multisig version" );
82+ }
4883 } else {
4984 throw new IllegalArgumentException ("Unsupported network" );
5085 }
5186 CellDep cellDep = new CellDep ();
5287 cellDep .outPoint = outPoint ;
5388 cellDep .depType = CellDep .DepType .DEP_GROUP ;
5489 cellDeps = Arrays .asList (cellDep );
55- this .codeHash = Script .SECP256K1_BLAKE160_MULTISIG_ALL_CODE_HASH ;
90+ this .codeHash = this .multisigVersion .codeHash ();
91+ this .hashType = this .multisigVersion .hashType ();
5692 }
5793
5894 private boolean isMatched (Script script ) {
5995 if (script == null ) {
6096 return false ;
6197 }
62- return Arrays .equals (script .codeHash , codeHash );
98+ return Arrays .equals (script .codeHash , codeHash ) && script . hashType == hashType ;
6399 }
64100
65101 @ Override
0 commit comments