mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 10:15:52 +00:00
Migrate usages of spongycastle Hex.encode/decode to Utils.HEX.encode/decode(), which in turn uses Guava's Base16 encoding.
This commit is contained in:
parent
da868973df
commit
638e921e53
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2011 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -20,7 +21,6 @@ import com.google.bitcoin.params.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import com.google.bitcoin.script.ScriptOpCodes;
|
||||
import com.google.common.base.Objects;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -48,7 +48,7 @@ public abstract class NetworkParameters implements Serializable {
|
||||
/**
|
||||
* The alert signing key originally owned by Satoshi, and now passed on to Gavin along with a few others.
|
||||
*/
|
||||
public static final byte[] SATOSHI_KEY = Hex.decode("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
|
||||
public static final byte[] SATOSHI_KEY = Utils.HEX.decode("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
|
||||
|
||||
/** The string returned by getId() for the main, production network where people trade things. */
|
||||
public static final String ID_MAINNET = "org.bitcoin.production";
|
||||
@ -103,11 +103,11 @@ public abstract class NetworkParameters implements Serializable {
|
||||
// A script containing the difficulty bits and the following message:
|
||||
//
|
||||
// "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
|
||||
byte[] bytes = Hex.decode
|
||||
byte[] bytes = Utils.HEX.decode
|
||||
("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73");
|
||||
t.addInput(new TransactionInput(n, t, bytes));
|
||||
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
|
||||
Script.writeBytes(scriptPubKeyBytes, Hex.decode
|
||||
Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode
|
||||
("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
|
||||
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
|
||||
t.addOutput(new TransactionOutput(n, t, FIFTY_COINS, scriptPubKeyBytes.toByteArray()));
|
||||
|
@ -18,7 +18,6 @@
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -53,7 +52,7 @@ public class Sha256Hash implements Serializable, Comparable<Sha256Hash> {
|
||||
*/
|
||||
public Sha256Hash(String hexString) {
|
||||
checkArgument(hexString.length() == 64);
|
||||
this.bytes = Hex.decode(hexString);
|
||||
this.bytes = Utils.HEX.decode(hexString);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.UnsignedLongs;
|
||||
|
||||
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -456,7 +455,7 @@ public class Utils {
|
||||
*/
|
||||
public static byte[] parseAsHexOrBase58(String data) {
|
||||
try {
|
||||
return Hex.decode(data);
|
||||
return HEX.decode(data);
|
||||
} catch (Exception e) {
|
||||
// Didn't decode as hex, try base58.
|
||||
try {
|
||||
|
@ -44,7 +44,6 @@ import org.bitcoinj.wallet.Protos.Wallet.EncryptionType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
@ -1555,9 +1554,9 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
// so the exact nature of the mutation can be examined.
|
||||
log.warn("Saw two pending transactions double spend each other");
|
||||
log.warn(" offending input is input {}", tx.getInputs().indexOf(input));
|
||||
log.warn("{}: {}", tx.getHash(), new String(Hex.encode(tx.unsafeBitcoinSerialize())));
|
||||
log.warn("{}: {}", tx.getHash(), Utils.HEX.encode(tx.unsafeBitcoinSerialize()));
|
||||
Transaction other = input.getConnectedOutput().getSpentBy().getParentTransaction();
|
||||
log.warn("{}: {}", other.getHash(), new String(Hex.encode(tx.unsafeBitcoinSerialize())));
|
||||
log.warn("{}: {}", other.getHash(), Utils.HEX.encode(tx.unsafeBitcoinSerialize()));
|
||||
}
|
||||
} else if (result == TransactionInput.ConnectionResult.SUCCESS) {
|
||||
// Otherwise we saw a transaction spend our coins, but we didn't try and spend them ourselves yet.
|
||||
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2013 Matija Mazi.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -19,13 +20,13 @@ import com.google.bitcoin.core.*;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.math.ec.ECPoint;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
/**
|
||||
@ -422,7 +423,7 @@ public class DeterministicKey extends ECKey {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("pub:%s chaincode:%s path:%s", new String(Hex.encode(getPubKey())),
|
||||
new String(Hex.encode(getChainCode())), getPathAsString());
|
||||
return String.format("pub:%s chaincode:%s path:%s", new String(HEX.encode(getPubKey())),
|
||||
new String(HEX.encode(getChainCode())), getPathAsString());
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package com.google.bitcoin.crypto;
|
||||
|
||||
import com.google.bitcoin.core.Sha256Hash;
|
||||
import com.google.common.base.Joiner;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -31,6 +30,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
|
||||
/**
|
||||
* A MnemonicCode object may be used to convert between binary seed values and
|
||||
* lists of words per <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki">the BIP 39
|
||||
@ -77,7 +78,7 @@ public class MnemonicCode {
|
||||
// If a wordListDigest is supplied check to make sure it matches.
|
||||
if (wordListDigest != null) {
|
||||
byte[] digest = md.digest();
|
||||
String hexdigest = new String(Hex.encode(digest));
|
||||
String hexdigest = new String(HEX.encode(digest));
|
||||
if (!hexdigest.equals(wordListDigest))
|
||||
throw new IllegalArgumentException("wordlist digest mismatch");
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -18,7 +19,6 @@ package com.google.bitcoin.params;
|
||||
|
||||
import com.google.bitcoin.core.NetworkParameters;
|
||||
import com.google.bitcoin.core.Utils;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
@ -47,7 +47,7 @@ public class TestNet3Params extends NetworkParameters {
|
||||
subsidyDecreaseBlockCount = 210000;
|
||||
String genesisHash = genesisBlock.getHashAsString();
|
||||
checkState(genesisHash.equals("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
|
||||
alertSigningKey = Hex.decode("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
|
||||
alertSigningKey = Utils.HEX.decode("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
|
||||
|
||||
dnsSeeds = new String[] {
|
||||
"testnet-seed.bitcoin.petertodd.org",
|
||||
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2014 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -19,12 +20,12 @@ package com.google.bitcoin.wallet;
|
||||
import com.google.bitcoin.crypto.*;
|
||||
import org.bitcoinj.wallet.Protos;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
@ -92,7 +93,7 @@ public class DeterministicSeed implements EncryptableItem {
|
||||
@Nullable
|
||||
public String toHexString() {
|
||||
if (unencryptedSeed != null)
|
||||
return new String(Hex.encode(unencryptedSeed));
|
||||
return new String(HEX.encode(unencryptedSeed));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ import com.google.bitcoin.params.MainNetParams;
|
||||
import com.google.bitcoin.params.TestNet3Params;
|
||||
import com.google.bitcoin.script.ScriptBuilder;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AddressTest {
|
||||
@ -34,11 +34,11 @@ public class AddressTest {
|
||||
@Test
|
||||
public void stringification() throws Exception {
|
||||
// Test a testnet address.
|
||||
Address a = new Address(testParams, Hex.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
|
||||
Address a = new Address(testParams, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
|
||||
assertEquals("n4eA2nbYqErp7H6jebchxAN59DmNpksexv", a.toString());
|
||||
assertFalse(a.isP2SHAddress());
|
||||
|
||||
Address b = new Address(mainParams, Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
|
||||
Address b = new Address(mainParams, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
|
||||
assertEquals("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL", b.toString());
|
||||
assertFalse(b.isP2SHAddress());
|
||||
}
|
||||
@ -112,10 +112,10 @@ public class AddressTest {
|
||||
assertEquals(TestNet3Params.get().getId(), testNetParams.getId());
|
||||
|
||||
// Test that we can convert them from hashes
|
||||
byte[] hex = Hex.decode("2ac4b0b501117cc8119c5797b519538d4942e90e");
|
||||
byte[] hex = HEX.decode("2ac4b0b501117cc8119c5797b519538d4942e90e");
|
||||
Address a = Address.fromP2SHHash(mainParams, hex);
|
||||
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", a.toString());
|
||||
Address b = Address.fromP2SHHash(testParams, Hex.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
|
||||
Address b = Address.fromP2SHHash(testParams, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
|
||||
assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString());
|
||||
Address c = Address.fromP2SHScript(mainParams, ScriptBuilder.createP2SHOutputScript(hex));
|
||||
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString());
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -19,13 +20,13 @@ package com.google.bitcoin.core;
|
||||
import com.google.bitcoin.params.UnitTestParams;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AlertMessageTest {
|
||||
private static final byte[] TEST_KEY_PRIV = Hex.decode("6421e091445ade4b24658e96aa60959ce800d8ea9e7bd8613335aa65ba8d840b");
|
||||
private static final byte[] TEST_KEY_PRIV = HEX.decode("6421e091445ade4b24658e96aa60959ce800d8ea9e7bd8613335aa65ba8d840b");
|
||||
private NetworkParameters params;
|
||||
|
||||
@Before
|
||||
@ -43,7 +44,7 @@ public class AlertMessageTest {
|
||||
public void deserialize() throws Exception {
|
||||
// A CAlert taken from the reference implementation.
|
||||
// TODO: This does not check the subVer or set fields. Support proper version matching.
|
||||
final byte[] payload = Hex.decode("5c010000004544eb4e000000004192ec4e00000000eb030000e9030000000000000048ee00000088130000002f43416c6572742073797374656d20746573743a2020202020202020207665722e302e352e3120617661696c61626c6500473045022100ec799908c008b272d5e5cd5a824abaaac53d210cc1fa517d8e22a701ecdb9e7002206fa1e7e7c251d5ba0d7c1fe428fc1870662f2927531d1cad8d4581b45bc4f8a7");
|
||||
final byte[] payload = HEX.decode("5c010000004544eb4e000000004192ec4e00000000eb030000e9030000000000000048ee00000088130000002f43416c6572742073797374656d20746573743a2020202020202020207665722e302e352e3120617661696c61626c6500473045022100ec799908c008b272d5e5cd5a824abaaac53d210cc1fa517d8e22a701ecdb9e7002206fa1e7e7c251d5ba0d7c1fe428fc1870662f2927531d1cad8d4581b45bc4f8a7");
|
||||
AlertMessage alert = new AlertMessage(params, payload);
|
||||
assertEquals(1324041285, alert.getRelayUntil().getTime() / 1000);
|
||||
assertEquals(1324126785, alert.getExpiration().getTime() / 1000);
|
||||
|
@ -19,38 +19,38 @@ package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.params.MainNetParams;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BitcoinSerializerTest {
|
||||
private final byte[] addrMessage = Hex.decode("f9beb4d96164647200000000000000001f000000" +
|
||||
private final byte[] addrMessage = HEX.decode("f9beb4d96164647200000000000000001f000000" +
|
||||
"ed52399b01e215104d010000000000000000000000000000000000ffff0a000001208d");
|
||||
|
||||
private final byte[] txMessage = Hex.decode(
|
||||
"F9 BE B4 D9 74 78 00 00 00 00 00 00 00 00 00 00" +
|
||||
"02 01 00 00 E2 93 CD BE 01 00 00 00 01 6D BD DB" +
|
||||
"08 5B 1D 8A F7 51 84 F0 BC 01 FA D5 8D 12 66 E9" +
|
||||
"B6 3B 50 88 19 90 E4 B4 0D 6A EE 36 29 00 00 00" +
|
||||
"00 8B 48 30 45 02 21 00 F3 58 1E 19 72 AE 8A C7" +
|
||||
"C7 36 7A 7A 25 3B C1 13 52 23 AD B9 A4 68 BB 3A" +
|
||||
"59 23 3F 45 BC 57 83 80 02 20 59 AF 01 CA 17 D0" +
|
||||
"0E 41 83 7A 1D 58 E9 7A A3 1B AE 58 4E DE C2 8D" +
|
||||
"35 BD 96 92 36 90 91 3B AE 9A 01 41 04 9C 02 BF" +
|
||||
"C9 7E F2 36 CE 6D 8F E5 D9 40 13 C7 21 E9 15 98" +
|
||||
"2A CD 2B 12 B6 5D 9B 7D 59 E2 0A 84 20 05 F8 FC" +
|
||||
"4E 02 53 2E 87 3D 37 B9 6F 09 D6 D4 51 1A DA 8F" +
|
||||
"14 04 2F 46 61 4A 4C 70 C0 F1 4B EF F5 FF FF FF" +
|
||||
"FF 02 40 4B 4C 00 00 00 00 00 19 76 A9 14 1A A0" +
|
||||
"CD 1C BE A6 E7 45 8A 7A BA D5 12 A9 D9 EA 1A FB" +
|
||||
"22 5E 88 AC 80 FA E9 C7 00 00 00 00 19 76 A9 14" +
|
||||
"0E AB 5B EA 43 6A 04 84 CF AB 12 48 5E FD A0 B7" +
|
||||
"8B 4E CC 52 88 AC 00 00 00 00");
|
||||
private final byte[] txMessage = HEX.withSeparator(" ", 2).decode(
|
||||
"f9 be b4 d9 74 78 00 00 00 00 00 00 00 00 00 00" +
|
||||
"02 01 00 00 e2 93 cd be 01 00 00 00 01 6d bd db" +
|
||||
"08 5b 1d 8a f7 51 84 f0 bc 01 fa d5 8d 12 66 e9" +
|
||||
"b6 3b 50 88 19 90 e4 b4 0d 6a ee 36 29 00 00 00" +
|
||||
"00 8b 48 30 45 02 21 00 f3 58 1e 19 72 ae 8a c7" +
|
||||
"c7 36 7a 7a 25 3b c1 13 52 23 ad b9 a4 68 bb 3a" +
|
||||
"59 23 3f 45 bc 57 83 80 02 20 59 af 01 ca 17 d0" +
|
||||
"0e 41 83 7a 1d 58 e9 7a a3 1b ae 58 4e de c2 8d" +
|
||||
"35 bd 96 92 36 90 91 3b ae 9a 01 41 04 9c 02 bf" +
|
||||
"c9 7e f2 36 ce 6d 8f e5 d9 40 13 c7 21 e9 15 98" +
|
||||
"2a cd 2b 12 b6 5d 9b 7d 59 e2 0a 84 20 05 f8 fc" +
|
||||
"4e 02 53 2e 87 3d 37 b9 6f 09 d6 d4 51 1a da 8f" +
|
||||
"14 04 2f 46 61 4a 4c 70 c0 f1 4b ef f5 ff ff ff" +
|
||||
"ff 02 40 4b 4c 00 00 00 00 00 19 76 a9 14 1a a0" +
|
||||
"cd 1c be a6 e7 45 8a 7a ba d5 12 a9 d9 ea 1a fb" +
|
||||
"22 5e 88 ac 80 fa e9 c7 00 00 00 00 19 76 a9 14" +
|
||||
"0e ab 5b ea 43 6a 04 84 cf ab 12 48 5e fd a0 b7" +
|
||||
"8b 4e cc 52 88 ac 00 00 00 00");
|
||||
|
||||
@Test
|
||||
public void testAddr() throws Exception {
|
||||
@ -156,7 +156,7 @@ public class BitcoinSerializerTest {
|
||||
public void testHeaders1() throws Exception {
|
||||
BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get());
|
||||
|
||||
HeadersMessage hm = (HeadersMessage) bs.deserialize(ByteBuffer.wrap(Hex.decode("f9beb4d9686561" +
|
||||
HeadersMessage hm = (HeadersMessage) bs.deserialize(ByteBuffer.wrap(HEX.decode("f9beb4d9686561" +
|
||||
"646572730000000000520000005d4fab8101010000006fe28c0ab6f1b372c1a6a246ae6" +
|
||||
"3f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677b" +
|
||||
"a1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e3629900")));
|
||||
@ -181,7 +181,7 @@ public class BitcoinSerializerTest {
|
||||
public void testHeaders2() throws Exception {
|
||||
BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get());
|
||||
|
||||
HeadersMessage hm = (HeadersMessage) bs.deserialize(ByteBuffer.wrap(Hex.decode("f9beb4d96865616465" +
|
||||
HeadersMessage hm = (HeadersMessage) bs.deserialize(ByteBuffer.wrap(HEX.decode("f9beb4d96865616465" +
|
||||
"72730000000000e701000085acd4ea06010000006fe28c0ab6f1b372c1a6a246ae63f74f931e" +
|
||||
"8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1c" +
|
||||
"db606e857233e0e61bc6649ffff001d01e3629900010000004860eb18bf1b1620e37e9490fc8a" +
|
||||
@ -228,7 +228,7 @@ public class BitcoinSerializerTest {
|
||||
}
|
||||
|
||||
// Message with a Message size which is 1 too big, in little endian format.
|
||||
byte[] wrongMessageLength = Hex.decode("000000000000000000000000010000020000000000");
|
||||
byte[] wrongMessageLength = HEX.decode("000000000000000000000000010000020000000000");
|
||||
try {
|
||||
new BitcoinSerializer.BitcoinPacketHeader(ByteBuffer.wrap(wrongMessageLength));
|
||||
fail();
|
||||
@ -240,7 +240,7 @@ public class BitcoinSerializerTest {
|
||||
@Test
|
||||
public void testSeekPastMagicBytes() {
|
||||
// Fail in another way, there is data in the stream but no magic bytes.
|
||||
byte[] brokenMessage = Hex.decode("000000");
|
||||
byte[] brokenMessage = HEX.decode("000000");
|
||||
try {
|
||||
new BitcoinSerializer(MainNetParams.get()).seekPastMagicBytes(ByteBuffer.wrap(brokenMessage));
|
||||
fail();
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,11 +1,28 @@
|
||||
/*
|
||||
* Copyright 2012 Matt Corallo
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.params.MainNetParams;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BloomFilterTest {
|
||||
@ -13,38 +30,38 @@ public class BloomFilterTest {
|
||||
public void insertSerializeTest() {
|
||||
BloomFilter filter = new BloomFilter(3, 0.01, 0, BloomFilter.BloomUpdate.UPDATE_ALL);
|
||||
|
||||
filter.insert(Hex.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8"));
|
||||
assertTrue (filter.contains(Hex.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
filter.insert(HEX.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8"));
|
||||
assertTrue (filter.contains(HEX.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
// One bit different in first byte
|
||||
assertFalse(filter.contains(Hex.decode("19108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
assertFalse(filter.contains(HEX.decode("19108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
|
||||
filter.insert(Hex.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"));
|
||||
assertTrue(filter.contains(Hex.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")));
|
||||
filter.insert(HEX.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"));
|
||||
assertTrue(filter.contains(HEX.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")));
|
||||
|
||||
filter.insert(Hex.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5"));
|
||||
assertTrue(filter.contains(Hex.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
filter.insert(HEX.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5"));
|
||||
assertTrue(filter.contains(HEX.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
|
||||
// Value generated by the reference client
|
||||
assertTrue(Arrays.equals(Hex.decode("03614e9b050000000000000001"), filter.bitcoinSerialize()));
|
||||
assertTrue(Arrays.equals(HEX.decode("03614e9b050000000000000001"), filter.bitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertSerializeTestWithTweak() {
|
||||
BloomFilter filter = new BloomFilter(3, 0.01, 2147483649L);
|
||||
|
||||
filter.insert(Hex.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8"));
|
||||
assertTrue (filter.contains(Hex.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
filter.insert(HEX.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8"));
|
||||
assertTrue (filter.contains(HEX.decode("99108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
// One bit different in first byte
|
||||
assertFalse(filter.contains(Hex.decode("19108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
assertFalse(filter.contains(HEX.decode("19108ad8ed9bb6274d3980bab5a85c048f0950c8")));
|
||||
|
||||
filter.insert(Hex.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"));
|
||||
assertTrue(filter.contains(Hex.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")));
|
||||
filter.insert(HEX.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"));
|
||||
assertTrue(filter.contains(HEX.decode("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")));
|
||||
|
||||
filter.insert(Hex.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5"));
|
||||
assertTrue(filter.contains(Hex.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
filter.insert(HEX.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5"));
|
||||
assertTrue(filter.contains(HEX.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
|
||||
// Value generated by the reference client
|
||||
assertTrue(Arrays.equals(Hex.decode("03ce4299050000000100008002"), filter.bitcoinSerialize()));
|
||||
assertTrue(Arrays.equals(HEX.decode("03ce4299050000000100008002"), filter.bitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -59,8 +76,8 @@ public class BloomFilterTest {
|
||||
Wallet wallet = new Wallet(params);
|
||||
wallet.importKey(privKey.getKey());
|
||||
// Add a random key which happens to have been used in a recent generation
|
||||
wallet.importKey(ECKey.fromPublicOnly(Hex.decode("03cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99")));
|
||||
wallet.commitTx(new Transaction(params, Hex.decode("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0d038754030114062f503253482fffffffff01c05e559500000000232103cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99ac00000000")));
|
||||
wallet.importKey(ECKey.fromPublicOnly(HEX.decode("03cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99")));
|
||||
wallet.commitTx(new Transaction(params, HEX.decode("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0d038754030114062f503253482fffffffff01c05e559500000000232103cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99ac00000000")));
|
||||
|
||||
// We should have 2 per pubkey, and one for the pay-2-pubkey output we have
|
||||
assertEquals(5, wallet.getBloomFilterElementCount());
|
||||
@ -68,6 +85,6 @@ public class BloomFilterTest {
|
||||
BloomFilter filter = wallet.getBloomFilter(wallet.getBloomFilterElementCount(), 0.001, 0);
|
||||
|
||||
// Value generated by the reference client
|
||||
assertTrue(Arrays.equals(Hex.decode("082ae5edc8e51d4a03080000000000000002"), filter.bitcoinSerialize()));
|
||||
assertTrue(Arrays.equals(HEX.decode("082ae5edc8e51d4a03080000000000000002"), filter.bitcoinSerialize()));
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,6 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.util.encoders.DecoderException;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
@ -51,6 +49,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static com.google.bitcoin.core.Utils.reverseBytes;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
@ -108,20 +107,20 @@ public class ECKeyTest {
|
||||
public void testSignatures() throws Exception {
|
||||
// Test that we can construct an ECKey from a private key (deriving the public from the private), then signing
|
||||
// a message with it.
|
||||
BigInteger privkey = new BigInteger(1, Hex.decode("180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19"));
|
||||
BigInteger privkey = new BigInteger(1, HEX.decode("180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19"));
|
||||
ECKey key = ECKey.fromPrivate(privkey);
|
||||
byte[] output = key.sign(Sha256Hash.ZERO_HASH).encodeToDER();
|
||||
assertTrue(key.verify(Sha256Hash.ZERO_HASH.getBytes(), output));
|
||||
|
||||
// Test interop with a signature from elsewhere.
|
||||
byte[] sig = Hex.decode(
|
||||
byte[] sig = HEX.decode(
|
||||
"3046022100dffbc26774fc841bbe1c1362fd643609c6e42dcb274763476d87af2c0597e89e022100c59e3c13b96b316cae9fa0ab0260612c7a133a6fe2b3445b6bf80b3123bf274d");
|
||||
assertTrue(key.verify(Sha256Hash.ZERO_HASH.getBytes(), sig));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASN1Roundtrip() throws Exception {
|
||||
byte[] privkeyASN1 = Hex.decode(
|
||||
byte[] privkeyASN1 = HEX.decode(
|
||||
"3082011302010104205c0b98e524ad188ddef35dc6abba13c34a351a05409e5d285403718b93336a4aa081a53081a2020101302c06072a8648ce3d0101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f300604010004010704410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020101a144034200042af7a2aafe8dafd7dc7f9cfb58ce09bda7dce28653ab229b98d1d3d759660c672dd0db18c8c2d76aa470448e876fc2089ab1354c01a6e72cefc50915f4a963ee");
|
||||
ECKey decodedKey = ECKey.fromASN1(privkeyASN1);
|
||||
|
||||
@ -132,18 +131,18 @@ public class ECKeyTest {
|
||||
assertArrayEquals(decodedKey.getPrivKeyBytes(), roundtripKey.getPrivKeyBytes());
|
||||
|
||||
for (ECKey key : new ECKey[] {decodedKey, roundtripKey}) {
|
||||
byte[] message = reverseBytes(Hex.decode(
|
||||
byte[] message = reverseBytes(HEX.decode(
|
||||
"11da3761e86431e4a54c176789e41f1651b324d240d599a7067bee23d328ec2a"));
|
||||
byte[] output = key.sign(new Sha256Hash(message)).encodeToDER();
|
||||
assertTrue(key.verify(message, output));
|
||||
|
||||
output = Hex.decode(
|
||||
output = HEX.decode(
|
||||
"304502206faa2ebc614bf4a0b31f0ce4ed9012eb193302ec2bcaccc7ae8bb40577f47549022100c73a1a1acc209f3f860bf9b9f5e13e9433db6f8b7bd527a088a0e0cd0a4c83e9");
|
||||
assertTrue(key.verify(message, output));
|
||||
}
|
||||
|
||||
// Try to sign with one key and verify with the other.
|
||||
byte[] message = reverseBytes(Hex.decode(
|
||||
byte[] message = reverseBytes(HEX.decode(
|
||||
"11da3761e86431e4a54c176789e41f1651b324d240d599a7067bee23d328ec2a"));
|
||||
assertTrue(roundtripKey.verify(message, decodedKey.sign(new Sha256Hash(message)).encodeToDER()));
|
||||
assertTrue(decodedKey.verify(message, roundtripKey.sign(new Sha256Hash(message)).encodeToDER()));
|
||||
@ -151,7 +150,7 @@ public class ECKeyTest {
|
||||
|
||||
@Test
|
||||
public void testKeyPairRoundtrip() throws Exception {
|
||||
byte[] privkeyASN1 = Hex.decode(
|
||||
byte[] privkeyASN1 = HEX.decode(
|
||||
"3082011302010104205c0b98e524ad188ddef35dc6abba13c34a351a05409e5d285403718b93336a4aa081a53081a2020101302c06072a8648ce3d0101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f300604010004010704410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020101a144034200042af7a2aafe8dafd7dc7f9cfb58ce09bda7dce28653ab229b98d1d3d759660c672dd0db18c8c2d76aa470448e876fc2089ab1354c01a6e72cefc50915f4a963ee");
|
||||
ECKey decodedKey = ECKey.fromASN1(privkeyASN1);
|
||||
|
||||
@ -161,18 +160,18 @@ public class ECKeyTest {
|
||||
ECKey.fromPrivateAndPrecalculatedPublic(decodedKey.getPrivKey(), decodedKey.getPubKeyPoint());
|
||||
|
||||
for (ECKey key : new ECKey[] {decodedKey, roundtripKey}) {
|
||||
byte[] message = reverseBytes(Hex.decode(
|
||||
byte[] message = reverseBytes(HEX.decode(
|
||||
"11da3761e86431e4a54c176789e41f1651b324d240d599a7067bee23d328ec2a"));
|
||||
byte[] output = key.sign(new Sha256Hash(message)).encodeToDER();
|
||||
assertTrue(key.verify(message, output));
|
||||
|
||||
output = Hex.decode(
|
||||
output = HEX.decode(
|
||||
"304502206faa2ebc614bf4a0b31f0ce4ed9012eb193302ec2bcaccc7ae8bb40577f47549022100c73a1a1acc209f3f860bf9b9f5e13e9433db6f8b7bd527a088a0e0cd0a4c83e9");
|
||||
assertTrue(key.verify(message, output));
|
||||
}
|
||||
|
||||
// Try to sign with one key and verify with the other.
|
||||
byte[] message = reverseBytes(Hex.decode(
|
||||
byte[] message = reverseBytes(HEX.decode(
|
||||
"11da3761e86431e4a54c176789e41f1651b324d240d599a7067bee23d328ec2a"));
|
||||
assertTrue(roundtripKey.verify(message, decodedKey.sign(new Sha256Hash(message)).encodeToDER()));
|
||||
assertTrue(decodedKey.verify(message, roundtripKey.sign(new Sha256Hash(message)).encodeToDER()));
|
||||
@ -388,7 +387,7 @@ public class ECKeyTest {
|
||||
while (in.available() > 0 && (c = in.read()) != '"')
|
||||
sig.append((char)c);
|
||||
|
||||
assertTrue(TransactionSignature.isEncodingCanonical(Hex.decode(sig.toString())));
|
||||
assertTrue(TransactionSignature.isEncodingCanonical(HEX.decode(sig.toString())));
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
@ -411,8 +410,8 @@ public class ECKeyTest {
|
||||
|
||||
try {
|
||||
final String sigStr = sig.toString();
|
||||
assertFalse(TransactionSignature.isEncodingCanonical(Hex.decode(sigStr)));
|
||||
} catch (DecoderException e) {
|
||||
assertFalse(TransactionSignature.isEncodingCanonical(HEX.decode(sigStr)));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected for non-hex strings in the JSON that we should ignore
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -23,44 +23,44 @@ import com.google.bitcoin.store.BlockStore;
|
||||
import com.google.bitcoin.store.MemoryBlockStore;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.bitcoin.core.Coin.*;
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
|
||||
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class LazyParseByteCacheTest {
|
||||
|
||||
private final byte[] txMessage = Hex.decode(
|
||||
"F9 BE B4 D9 74 78 00 00 00 00 00 00 00 00 00 00" +
|
||||
"02 01 00 00 E2 93 CD BE 01 00 00 00 01 6D BD DB" +
|
||||
"08 5B 1D 8A F7 51 84 F0 BC 01 FA D5 8D 12 66 E9" +
|
||||
"B6 3B 50 88 19 90 E4 B4 0D 6A EE 36 29 00 00 00" +
|
||||
"00 8B 48 30 45 02 21 00 F3 58 1E 19 72 AE 8A C7" +
|
||||
"C7 36 7A 7A 25 3B C1 13 52 23 AD B9 A4 68 BB 3A" +
|
||||
"59 23 3F 45 BC 57 83 80 02 20 59 AF 01 CA 17 D0" +
|
||||
"0E 41 83 7A 1D 58 E9 7A A3 1B AE 58 4E DE C2 8D" +
|
||||
"35 BD 96 92 36 90 91 3B AE 9A 01 41 04 9C 02 BF" +
|
||||
"C9 7E F2 36 CE 6D 8F E5 D9 40 13 C7 21 E9 15 98" +
|
||||
"2A CD 2B 12 B6 5D 9B 7D 59 E2 0A 84 20 05 F8 FC" +
|
||||
"4E 02 53 2E 87 3D 37 B9 6F 09 D6 D4 51 1A DA 8F" +
|
||||
"14 04 2F 46 61 4A 4C 70 C0 F1 4B EF F5 FF FF FF" +
|
||||
"FF 02 40 4B 4C 00 00 00 00 00 19 76 A9 14 1A A0" +
|
||||
"CD 1C BE A6 E7 45 8A 7A BA D5 12 A9 D9 EA 1A FB" +
|
||||
"22 5E 88 AC 80 FA E9 C7 00 00 00 00 19 76 A9 14" +
|
||||
"0E AB 5B EA 43 6A 04 84 CF AB 12 48 5E FD A0 B7" +
|
||||
"8B 4E CC 52 88 AC 00 00 00 00");
|
||||
private final byte[] txMessage = HEX.withSeparator(" ", 2).decode(
|
||||
"f9 be b4 d9 74 78 00 00 00 00 00 00 00 00 00 00" +
|
||||
"02 01 00 00 e2 93 cd be 01 00 00 00 01 6d bd db" +
|
||||
"08 5b 1d 8a f7 51 84 f0 bc 01 fa d5 8d 12 66 e9" +
|
||||
"b6 3b 50 88 19 90 e4 b4 0d 6a ee 36 29 00 00 00" +
|
||||
"00 8b 48 30 45 02 21 00 f3 58 1e 19 72 ae 8a c7" +
|
||||
"c7 36 7a 7a 25 3b c1 13 52 23 ad b9 a4 68 bb 3a" +
|
||||
"59 23 3f 45 bc 57 83 80 02 20 59 af 01 ca 17 d0" +
|
||||
"0e 41 83 7a 1d 58 e9 7a a3 1b ae 58 4e de c2 8d" +
|
||||
"35 bd 96 92 36 90 91 3b ae 9a 01 41 04 9c 02 bf" +
|
||||
"c9 7e f2 36 ce 6d 8f e5 d9 40 13 c7 21 e9 15 98" +
|
||||
"2a cd 2b 12 b6 5d 9b 7d 59 e2 0a 84 20 05 f8 fc" +
|
||||
"4e 02 53 2e 87 3d 37 b9 6f 09 d6 d4 51 1a da 8f" +
|
||||
"14 04 2f 46 61 4a 4c 70 c0 f1 4b ef f5 ff ff ff" +
|
||||
"ff 02 40 4b 4c 00 00 00 00 00 19 76 a9 14 1a a0" +
|
||||
"cd 1c be a6 e7 45 8a 7a ba d5 12 a9 d9 ea 1a fb" +
|
||||
"22 5e 88 ac 80 fa e9 c7 00 00 00 00 19 76 a9 14" +
|
||||
"0e ab 5b ea 43 6a 04 84 cf ab 12 48 5e fd a0 b7" +
|
||||
"8b 4e cc 52 88 ac 00 00 00 00");
|
||||
|
||||
private final byte[] txMessagePart = Hex.decode(
|
||||
"08 5B 1D 8A F7 51 84 F0 BC 01 FA D5 8D 12 66 E9" +
|
||||
"B6 3B 50 88 19 90 E4 B4 0D 6A EE 36 29 00 00 00" +
|
||||
"00 8B 48 30 45 02 21 00 F3 58 1E 19 72 AE 8A C7" +
|
||||
"C7 36 7A 7A 25 3B C1 13 52 23 AD B9 A4 68 BB 3A");
|
||||
private final byte[] txMessagePart = HEX.withSeparator(" ", 2).decode(
|
||||
"08 5b 1d 8a f7 51 84 f0 bc 01 fa d5 8d 12 66 e9" +
|
||||
"b6 3b 50 88 19 90 e4 b4 0d 6a ee 36 29 00 00 00" +
|
||||
"00 8b 48 30 45 02 21 00 f3 58 1e 19 72 ae 8a c7" +
|
||||
"c7 36 7a 7a 25 3b c1 13 52 23 ad b9 a4 68 bb 3a");
|
||||
|
||||
private Wallet wallet;
|
||||
private BlockStore blockStore;
|
||||
|
@ -19,10 +19,10 @@ package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.params.MainNetParams;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PeerAddressTest
|
||||
@ -32,7 +32,7 @@ public class PeerAddressTest
|
||||
// copied verbatim from https://en.bitcoin.it/wiki/Protocol_specification#Network_address
|
||||
String fromSpec = "010000000000000000000000000000000000ffff0a000001208d";
|
||||
PeerAddress pa = new PeerAddress(MainNetParams.get(),
|
||||
Hex.decode(fromSpec), 0, 0);
|
||||
HEX.decode(fromSpec), 0, 0);
|
||||
String reserialized = Utils.HEX.encode(pa.bitcoinSerialize());
|
||||
assertEquals(reserialized,fromSpec );
|
||||
}
|
||||
|
@ -1,9 +1,26 @@
|
||||
/*
|
||||
* Copyright 2012 Matt Corallo
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.params.UnitTestParams;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class VersionMessageTest {
|
||||
@ -12,22 +29,22 @@ public class VersionMessageTest {
|
||||
public void testDecode() throws Exception {
|
||||
NetworkParameters params = UnitTestParams.get();
|
||||
|
||||
VersionMessage ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f0004000000"));
|
||||
VersionMessage ver = new VersionMessage(params, HEX.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f0004000000"));
|
||||
assertTrue(!ver.relayTxesBeforeFilter);
|
||||
assertTrue(ver.bestHeight == 1024);
|
||||
assertTrue(ver.subVer.equals("/BitCoinJ:0.7-SNAPSHOT/"));
|
||||
|
||||
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f00040000"));
|
||||
ver = new VersionMessage(params, HEX.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f00040000"));
|
||||
assertTrue(ver.relayTxesBeforeFilter);
|
||||
assertTrue(ver.bestHeight == 1024);
|
||||
assertTrue(ver.subVer.equals("/BitCoinJ:0.7-SNAPSHOT/"));
|
||||
|
||||
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f"));
|
||||
ver = new VersionMessage(params, HEX.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f"));
|
||||
assertTrue(ver.relayTxesBeforeFilter);
|
||||
assertTrue(ver.bestHeight == 0);
|
||||
assertTrue(ver.subVer.equals("/BitCoinJ:0.7-SNAPSHOT/"));
|
||||
|
||||
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000"));
|
||||
ver = new VersionMessage(params, HEX.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000"));
|
||||
assertTrue(ver.relayTxesBeforeFilter);
|
||||
assertTrue(ver.bestHeight == 0);
|
||||
assertTrue(ver.subVer.equals(""));
|
||||
|
@ -41,7 +41,6 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -58,6 +57,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.google.bitcoin.core.Coin.*;
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static com.google.bitcoin.testing.FakeTxBuilder.*;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
@ -108,7 +108,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void basicSpendingToP2SH() throws Exception {
|
||||
Address destination = new Address(params, params.getP2SHHeader(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
|
||||
Address destination = new Address(params, params.getP2SHHeader(), HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
|
||||
basicSpendingCommon(wallet, myAddress, destination, false);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2013 Matija Mazi.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -24,11 +25,11 @@ import com.google.common.collect.Iterables;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@ -127,7 +128,7 @@ public class BIP32Test {
|
||||
private void testVector(int testCase) throws AddressFormatException {
|
||||
log.info("======= Test vector {}", testCase);
|
||||
HDWTestVector tv = tvs[testCase];
|
||||
DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(Hex.decode(tv.seed));
|
||||
DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(HEX.decode(tv.seed));
|
||||
assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58()));
|
||||
assertEquals(testEncode(tv.pub), testEncode(masterPrivateKey.serializePubB58()));
|
||||
DeterministicHierarchy dh = new DeterministicHierarchy(masterPrivateKey);
|
||||
@ -143,7 +144,7 @@ public class BIP32Test {
|
||||
}
|
||||
|
||||
private String testEncode(String what) throws AddressFormatException {
|
||||
return new String(Hex.encode(Base58.decodeChecked(what)));
|
||||
return new String(HEX.encode(Base58.decodeChecked(what)));
|
||||
}
|
||||
|
||||
static class HDWTestVector {
|
||||
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2013 Matija Mazi.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -20,8 +21,8 @@ import com.google.bitcoin.core.ECKey;
|
||||
import com.google.bitcoin.core.Sha256Hash;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@ -50,9 +51,9 @@ public class ChildKeyDerivationTest {
|
||||
};
|
||||
|
||||
for(int i = 0; i < 1; i++) {
|
||||
byte[] priv = Hex.decode(ckdTestVectors[3 * i]);
|
||||
byte[] pub = Hex.decode(ckdTestVectors[3 * i + 1]);
|
||||
byte[] chain = Hex.decode(ckdTestVectors[3 * i + 2]); // chain code
|
||||
byte[] priv = HEX.decode(ckdTestVectors[3 * i]);
|
||||
byte[] pub = HEX.decode(ckdTestVectors[3 * i + 1]);
|
||||
byte[] chain = HEX.decode(ckdTestVectors[3 * i + 2]); // chain code
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Start with an extended PRIVATE key
|
||||
@ -184,10 +185,6 @@ public class ChildKeyDerivationTest {
|
||||
}
|
||||
|
||||
private static String hexEncodePub(DeterministicKey pubKey) {
|
||||
return hexEncode(pubKey.getPubKey());
|
||||
}
|
||||
|
||||
private static String hexEncode(byte[] bytes) {
|
||||
return new String(Hex.encode(bytes));
|
||||
return HEX.encode(pubKey.getPubKey());
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,26 @@
|
||||
/*
|
||||
* Copyright 2013 Matija Mazi
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.bitcoin.crypto;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
|
||||
/**
|
||||
* @author Matija Mazi <br/>
|
||||
@ -98,12 +116,12 @@ public class HDUtilsTest {
|
||||
}
|
||||
|
||||
private static byte[] getBytes(String[] hmacTestVectors, int i) {
|
||||
return Hex.decode(hmacTestVectors[i]);
|
||||
return HEX.decode(hmacTestVectors[i]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongToByteArray() throws Exception {
|
||||
byte[] bytes = HDUtils.longTo4ByteArray(1026);
|
||||
Assert.assertEquals("00000402", new String(Hex.encode(bytes)));
|
||||
Assert.assertEquals("00000402", new String(HEX.encode(bytes)));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Ken Sedgwick
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -19,13 +20,13 @@ package com.google.bitcoin.crypto;
|
||||
import com.google.common.base.Joiner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class MnemonicCodeTest {
|
||||
@ -164,19 +165,19 @@ public class MnemonicCodeTest {
|
||||
String vecCode = vectors[ii+1];
|
||||
String vecSeed = vectors[ii+2];
|
||||
|
||||
List<String> code = mc.toMnemonic(Hex.decode(vecData));
|
||||
List<String> code = mc.toMnemonic(HEX.decode(vecData));
|
||||
byte[] seed = MnemonicCode.toSeed(code, "TREZOR");
|
||||
byte[] entropy = mc.toEntropy(split(vecCode));
|
||||
|
||||
assertEquals(vecData, new String(Hex.encode(entropy)));
|
||||
assertEquals(vecData, new String(HEX.encode(entropy)));
|
||||
assertEquals(vecCode, Joiner.on(' ').join(code));
|
||||
assertEquals(vecSeed, new String(Hex.encode(seed)));
|
||||
assertEquals(vecSeed, new String(HEX.encode(seed)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = MnemonicException.MnemonicLengthException.class)
|
||||
public void testBadEntropyLength() throws Exception {
|
||||
byte[] entropy = Hex.decode("7f7f7f7f7f7f7f7f7f7f7f7f7f7f");
|
||||
byte[] entropy = HEX.decode("7f7f7f7f7f7f7f7f7f7f7f7f7f7f");
|
||||
mc.toMnemonic(entropy);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ import org.hamcrest.core.IsEqual;
|
||||
import org.hamcrest.core.IsNot;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
@ -41,6 +40,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.bitcoin.core.Utils.HEX;
|
||||
import static com.google.bitcoin.script.ScriptOpCodes.OP_INVALIDOPCODE;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -56,7 +56,7 @@ public class ScriptTest {
|
||||
|
||||
@Test
|
||||
public void testScriptSig() throws Exception {
|
||||
byte[] sigProgBytes = Hex.decode(sigProg);
|
||||
byte[] sigProgBytes = HEX.decode(sigProg);
|
||||
Script script = new Script(sigProgBytes);
|
||||
// Test we can extract the from address.
|
||||
byte[] hash160 = Utils.sha256hash160(script.getPubKey());
|
||||
@ -67,7 +67,7 @@ public class ScriptTest {
|
||||
@Test
|
||||
public void testScriptPubKey() throws Exception {
|
||||
// Check we can extract the to address
|
||||
byte[] pubkeyBytes = Hex.decode(pubkeyProg);
|
||||
byte[] pubkeyBytes = HEX.decode(pubkeyProg);
|
||||
Script pubkey = new Script(pubkeyBytes);
|
||||
assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString());
|
||||
Address toAddr = new Address(params, pubkey.getPubKeyHash());
|
||||
@ -104,7 +104,7 @@ public class ScriptTest {
|
||||
|
||||
@Test
|
||||
public void testIp() throws Exception {
|
||||
byte[] bytes = Hex.decode("41043e96222332ea7848323c08116dddafbfa917b8e37f0bdf63841628267148588a09a43540942d58d49717ad3fabfe14978cf4f0a8b84d2435dad16e9aa4d7f935ac");
|
||||
byte[] bytes = HEX.decode("41043e96222332ea7848323c08116dddafbfa917b8e37f0bdf63841628267148588a09a43540942d58d49717ad3fabfe14978cf4f0a8b84d2435dad16e9aa4d7f935ac");
|
||||
Script s = new Script(bytes);
|
||||
assertTrue(s.isSentToRawPubKey());
|
||||
}
|
||||
@ -116,7 +116,7 @@ public class ScriptTest {
|
||||
ECKey key2 = new DumpedPrivateKey(params, "cTine92s8GLpVqvebi8rYce3FrUYq78ZGQffBYCS1HmDPJdSTxUo").getKey();
|
||||
ECKey key3 = new DumpedPrivateKey(params, "cVHwXSPRZmL9adctwBwmn4oTZdZMbaCsR5XF6VznqMgcvt1FDDxg").getKey();
|
||||
Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key1, key2, key3));
|
||||
byte[] bytes = Hex.decode("01000000013df681ff83b43b6585fa32dd0e12b0b502e6481e04ee52ff0fdaf55a16a4ef61000000006b483045022100a84acca7906c13c5895a1314c165d33621cdcf8696145080895cbf301119b7cf0220730ff511106aa0e0a8570ff00ee57d7a6f24e30f592a10cae1deffac9e13b990012102b8d567bcd6328fd48a429f9cf4b315b859a58fd28c5088ef3cb1d98125fc4e8dffffffff02364f1c00000000001976a91439a02793b418de8ec748dd75382656453dc99bcb88ac40420f000000000017a9145780b80be32e117f675d6e0ada13ba799bf248e98700000000");
|
||||
byte[] bytes = HEX.decode("01000000013df681ff83b43b6585fa32dd0e12b0b502e6481e04ee52ff0fdaf55a16a4ef61000000006b483045022100a84acca7906c13c5895a1314c165d33621cdcf8696145080895cbf301119b7cf0220730ff511106aa0e0a8570ff00ee57d7a6f24e30f592a10cae1deffac9e13b990012102b8d567bcd6328fd48a429f9cf4b315b859a58fd28c5088ef3cb1d98125fc4e8dffffffff02364f1c00000000001976a91439a02793b418de8ec748dd75382656453dc99bcb88ac40420f000000000017a9145780b80be32e117f675d6e0ada13ba799bf248e98700000000");
|
||||
Transaction transaction = new Transaction(params, bytes);
|
||||
TransactionOutput output = transaction.getOutput(1);
|
||||
Transaction spendTx = new Transaction(params);
|
||||
@ -170,7 +170,7 @@ public class ScriptTest {
|
||||
Script.writeBytes(out, Utils.reverseBytes(Utils.encodeMPI(BigInteger.valueOf(val), false)));
|
||||
} else if (w.matches("^0x[0-9a-fA-F]*$")) {
|
||||
// Raw hex data, inserted NOT pushed onto stack:
|
||||
out.write(Hex.decode(w.substring(2)));
|
||||
out.write(HEX.decode(w.substring(2).toLowerCase()));
|
||||
} else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) {
|
||||
// Single-quoted string, pushed as data. NOTE: this is poor-man's
|
||||
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
|
||||
@ -383,12 +383,11 @@ public class ScriptTest {
|
||||
String hash = input.list.get(0).string;
|
||||
int index = input.list.get(1).integer;
|
||||
String script = input.list.get(2).string;
|
||||
Sha256Hash sha256Hash = new Sha256Hash(Hex.decode(hash.getBytes(Charset.forName("UTF-8"))));
|
||||
Sha256Hash sha256Hash = new Sha256Hash(HEX.decode(hash));
|
||||
scriptPubKeys.put(new TransactionOutPoint(params, index, sha256Hash), parseScriptString(script));
|
||||
}
|
||||
|
||||
byte[] bytes = tx.get(0).list.get(1).string.getBytes(Charset.forName("UTF-8"));
|
||||
transaction = new Transaction(params, Hex.decode(bytes));
|
||||
transaction = new Transaction(params, HEX.decode(tx.get(0).list.get(1).string.toLowerCase()));
|
||||
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
|
||||
assertTrue(tx.get(0).list.get(2).isBoolean());
|
||||
|
||||
@ -440,12 +439,11 @@ public class ScriptTest {
|
||||
String hash = input.list.get(0).string;
|
||||
int index = input.list.get(1).integer;
|
||||
String script = input.list.get(2).string;
|
||||
Sha256Hash sha256Hash = new Sha256Hash(Hex.decode(hash.getBytes(Charset.forName("UTF-8"))));
|
||||
Sha256Hash sha256Hash = new Sha256Hash(HEX.decode(hash));
|
||||
scriptPubKeys.put(new TransactionOutPoint(params, index, sha256Hash), parseScriptString(script));
|
||||
}
|
||||
|
||||
byte[] bytes = tx.get(0).list.get(1).string.getBytes(Charset.forName("UTF-8"));
|
||||
Transaction transaction = new Transaction(params, Hex.decode(bytes));
|
||||
Transaction transaction = new Transaction(params, HEX.decode(tx.get(0).list.get(1).string));
|
||||
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
|
||||
assertTrue(tx.get(0).list.get(2).isBoolean());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user