Skip to content

Commit

Permalink
bitcoin/json/conversion: add comments and TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
msgilligan committed Jul 26, 2023
1 parent 47689a0 commit 34f8e1c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import java.io.IOException;
import java.nio.ByteBuffer;

// TODO: In (planned) bitcoinj 0.17-alpha2 Network/NetworkParameters is no longer needed to construct blocks
/**
*
* Deserializes a hex string as a Bitcoin {@link Block}
*/
public class BlockHexDeserializer extends JsonDeserializer<Block> {
private final NetworkParameters netParams;
Expand All @@ -36,6 +37,7 @@ public Block deserialize(JsonParser p, DeserializationContext ctxt) throws IOExc
case VALUE_STRING:
try {
byte[] payload = HexUtil.hexStringToByteArray(p.getValueAsString()); // convert to hex
// TODO: return Block.read(ByteBuffer.wrap(payload));
return netParams.getDefaultSerializer().makeBlock(ByteBuffer.wrap(payload));
} catch (ProtocolException e) {
throw new InvalidFormatException(p, "Invalid Block", p.getValueAsString(), Block.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.bitcoinj.base.Sha256Hash;
import org.bitcoinj.core.Transaction;

// TODO: In (planned) bitcoinj 0.17-alpha2 Network/NetworkParameters is no longer needed to construct this class
// TODO: After bitcoinj 0.17-alpha2 maybe merge RpcClientModule and RpcServerModule (though there are currently conflicting serializers for Transaction)
/**
*
* Jackson Module with serializers and deserializers for JSON-RPC clients.
*/
public class RpcClientModule extends SimpleModule {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.bitcoinj.script.Script;

/**
*
* Jackson Module with serializers and deserializers for JSON-RPC servers.
*/
public class RpcServerModule extends SimpleModule {
public RpcServerModule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.io.IOException;

/**
*
* Serialize a transaction as a hex-encoded binary string.
*/
public class TransactionHexSerializer extends JsonSerializer<Transaction> {
@Override
Expand Down

0 comments on commit 34f8e1c

Please sign in to comment.