Skip to content

Commit

Permalink
fix: Check for empty script in pay-to-pubkey-hash transactions.
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Sabadello <markus@danubetech.com>
  • Loading branch information
peacekeeper committed May 11, 2020
1 parent b9c80a8 commit 0dbcc81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) throws IOException
if (scriptSig == null) continue;

String asm = (String) scriptSig.get("asm");
if (asm == null) continue;
if (asm == null || asm.trim().isEmpty()) continue;

Matcher matcher = patternAsmInputScriptPubKey.matcher(asm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -117,7 +118,12 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) {

if (in.scriptSig() != null && in.scriptSig().get("asm") != null) {

Matcher matcher = patternAsmInputScriptPubKey.matcher((String) in.scriptSig().get("asm"));
Map<String, Object> scriptSig = in.scriptSig();

String asm = (String) scriptSig.get("asm");
if (asm == null || asm.trim().isEmpty()) continue;

Matcher matcher = patternAsmInputScriptPubKey.matcher(asm);

if (log.isDebugEnabled()) log.debug("IN: " + in.scriptSig().get("asm") + " (MATCHES: " + matcher.matches() + ")");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) throws IOException
for (Iterator<JsonElement> i = ((JsonArray) txData.get("inputs")).iterator(); i.hasNext(); ) {

JsonObject input = i.next().getAsJsonObject();
JsonElement script = input.get("script");
JsonElement scriptType = input.get("script_type");
if (script == null || ! script.isJsonPrimitive()) continue;
if (scriptType == null || ! scriptType.isJsonPrimitive()) continue;

if ("pay-to-pubkey-hash".equals(scriptType.getAsString())) {

JsonElement script = input.get("script");
if (script == null || ! script.isJsonPrimitive()) continue;

Script payToPubKeyHashScript;

try {
Expand All @@ -116,6 +117,9 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) throws IOException

inputScriptPubKey = Hex.encodeHexString(payToPubKeyHashScript.getChunks().get(1).data);
break;
} else {

throw new IOException("Script type " + scriptType.getAsString() + " not supported.");
}
}

Expand Down

0 comments on commit 0dbcc81

Please sign in to comment.