mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 01:56:44 +00:00
support parsing of op_checksigadd and taproot control block
This commit is contained in:
parent
d2621eb87d
commit
0e1766a709
2 changed files with 14 additions and 2 deletions
|
@ -11,6 +11,7 @@ import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static com.sparrowwallet.drongo.protocol.ScriptOpCodes.*;
|
import static com.sparrowwallet.drongo.protocol.ScriptOpCodes.*;
|
||||||
|
|
||||||
|
@ -150,7 +151,7 @@ public class ScriptChunk {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isSignature() || isPubKey()) {
|
if(isSignature() || isPubKey() || isTaprootControlBlock()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +181,22 @@ public class ScriptChunk {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ECKey.isPubKeyCanonical(data);
|
return ECKey.isPubKeyCanonical(data) && !IntStream.range(0, data.length).mapToObj(i -> data[i]).allMatch(b -> b == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ECKey getPubKey() {
|
public ECKey getPubKey() {
|
||||||
return ECKey.fromPublicOnly(data);
|
return ECKey.fromPublicOnly(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTaprootControlBlock() {
|
||||||
|
if(data == null || data.length == 0 || (data.length - 1) % 32 != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Test for BIP341 leaf version and both parity options
|
||||||
|
return ((data[0] & 0xff) == 0xc0 || (data[0] & 0xff) == 0xc1);
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] toByteArray() {
|
public byte[] toByteArray() {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -161,6 +161,7 @@ public class ScriptOpCodes {
|
||||||
public static final int OP_NOP8 = 0xb7;
|
public static final int OP_NOP8 = 0xb7;
|
||||||
public static final int OP_NOP9 = 0xb8;
|
public static final int OP_NOP9 = 0xb8;
|
||||||
public static final int OP_NOP10 = 0xb9;
|
public static final int OP_NOP10 = 0xb9;
|
||||||
|
public static final int OP_CHECKSIGADD = 0xba;
|
||||||
public static final int OP_INVALIDOPCODE = 0xff;
|
public static final int OP_INVALIDOPCODE = 0xff;
|
||||||
|
|
||||||
private static final Map<Integer, String> opCodeNameMap;
|
private static final Map<Integer, String> opCodeNameMap;
|
||||||
|
@ -269,6 +270,7 @@ public class ScriptOpCodes {
|
||||||
opCodeNameMap.put(OP_CHECKSIGVERIFY, "CHECKSIGVERIFY");
|
opCodeNameMap.put(OP_CHECKSIGVERIFY, "CHECKSIGVERIFY");
|
||||||
opCodeNameMap.put(OP_CHECKMULTISIG, "CHECKMULTISIG");
|
opCodeNameMap.put(OP_CHECKMULTISIG, "CHECKMULTISIG");
|
||||||
opCodeNameMap.put(OP_CHECKMULTISIGVERIFY, "CHECKMULTISIGVERIFY");
|
opCodeNameMap.put(OP_CHECKMULTISIGVERIFY, "CHECKMULTISIGVERIFY");
|
||||||
|
opCodeNameMap.put(OP_CHECKSIGADD, "CHECKSIGADD");
|
||||||
opCodeNameMap.put(OP_NOP1, "NOP1");
|
opCodeNameMap.put(OP_NOP1, "NOP1");
|
||||||
opCodeNameMap.put(OP_CHECKLOCKTIMEVERIFY, "CHECKLOCKTIMEVERIFY");
|
opCodeNameMap.put(OP_CHECKLOCKTIMEVERIFY, "CHECKLOCKTIMEVERIFY");
|
||||||
opCodeNameMap.put(OP_CHECKSEQUENCEVERIFY, "CHECKSEQUENCEVERIFY");
|
opCodeNameMap.put(OP_CHECKSEQUENCEVERIFY, "CHECKSEQUENCEVERIFY");
|
||||||
|
|
Loading…
Reference in a new issue