Skip to content

Commit

Permalink
fix p2wpkh for bitcoind
Browse files Browse the repository at this point in the history
  • Loading branch information
cihanss committed May 13, 2020
1 parent f12cd20 commit 2641188
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@
<version>1.13</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.4</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package info.weboftrust.btctxlookup.bitcoinconnection;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
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;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import info.weboftrust.btctxlookup.Chain;
import info.weboftrust.btctxlookup.ChainAndLocationData;
import info.weboftrust.btctxlookup.ChainAndTxid;
import info.weboftrust.btctxlookup.DidBtcrData;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient;
import wf.bitcoin.javabitcoindrpcclient.BitcoindRpcClient;
import wf.bitcoin.javabitcoindrpcclient.BitcoindRpcClient.Block;
import wf.bitcoin.javabitcoindrpcclient.BitcoindRpcClient.RawTransaction;
import wf.bitcoin.javabitcoindrpcclient.BitcoindRpcClient.RawTransaction.In;
import wf.bitcoin.javabitcoindrpcclient.BitcoindRpcClient.RawTransaction.Out;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
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;

public class BitcoindRPCBitcoinConnection extends AbstractBitcoinConnection implements BitcoinConnection {

private static final BitcoindRPCBitcoinConnection instance = new BitcoindRPCBitcoinConnection();
Expand Down Expand Up @@ -107,6 +108,8 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) throws IOException
RawTransaction rawTransaction = bitcoindRpcClient.getRawTransaction(chainAndTxid.getTxid());
if (rawTransaction == null) return null;

final ObjectMapper mapper = new ObjectMapper();

// find input script pub key

String inputScriptPubKey = null;
Expand All @@ -120,7 +123,9 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) throws IOException
if (scriptSig == null) continue;

String asm = (String) scriptSig.get("asm");
List<String> txinwitness = null; // TODO: How to get this with bitcoind ?

Map<String, Object> mIn = mapper.convertValue(in, new TypeReference<Map<String, Object>>() {});
List<String> txinwitness = (List<String>) ((Map) mIn.get("m")).get("txinwitness");

if (asm != null && ! asm.trim().isEmpty()) {

Expand All @@ -135,8 +140,9 @@ public DidBtcrData getDidBtcrData(ChainAndTxid chainAndTxid) throws IOException
inputScriptPubKey = matcher.group(1);
break;
}
} else if (txinwitness != null && txinwitness.size() > 0) {
} else if (txinwitness != null && txinwitness.size() == 2) {

//Get the second witness push -> pubKey
inputScriptPubKey = txinwitness.get(1);
break;
} else {
Expand Down

0 comments on commit 2641188

Please sign in to comment.