Java 类org.bitcoinj.core.CoinDefinition 实例源码

项目:namecoinj    文件:UnitTestParams.java   
public UnitTestParams() {
    super();
    id = ID_UNITTESTNET;
    packetMagic = 0x0b110907;
    addressHeader = CoinDefinition.testnetAddressHeader;
    p2shHeader = CoinDefinition.testnetp2shHeader;
    acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
    maxTarget = new BigInteger("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16);
    genesisBlock.setTime(System.currentTimeMillis() / 1000);
    genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET);
    //genesisBlock.solve();
    port = CoinDefinition.TestPort;
    interval = 10;
    dumpedPrivateKeyHeader = 128 + CoinDefinition.testnetAddressHeader;
    targetTimespan = 200000000;  // 6 years. Just a very big number.
    spendableCoinbaseDepth = 5;
    subsidyDecreaseBlockCount = 100;
    dnsSeeds = null;
}
项目:namecoinj    文件:TestNet2Params.java   
public TestNet2Params() {
    super();
    id = ID_TESTNET;
    packetMagic = 0xfabfb5daL;

    port = CoinDefinition.TestPort;
    addressHeader = CoinDefinition.testnetAddressHeader;
    p2shHeader = CoinDefinition.testnetp2shHeader;
    acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
    interval = INTERVAL;
    targetTimespan = TARGET_TIMESPAN;

    maxTarget = CoinDefinition.proofOfWorkLimit;
    dumpedPrivateKeyHeader = 128 + CoinDefinition.testnetAddressHeader;

    genesisBlock.setTime(1296688602L);
    genesisBlock.setDifficultyTarget(0x1d07fff8L);
    genesisBlock.setNonce(384568319);
    spendableCoinbaseDepth = CoinDefinition.spendableCoinbaseDepth;
    subsidyDecreaseBlockCount = CoinDefinition.subsidyDecreaseBlockCount;
    String genesisHash = genesisBlock.getHashAsString();
    //checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"));
    dnsSeeds = null;
}
项目:digibytej-alice    文件:NetworkParameters.java   
private static Block createGenesis(NetworkParameters n) {
    Block genesisBlock = new Block(n);
    Transaction t = new Transaction(n);
    try {
        // A script containing the difficulty bits and the following message:
        //

        //   coin dependent
        byte[] bytes = Hex.decode(CoinDefinition.genesisTxInBytes);
        //byte[] bytes = Hex.decode("04ffff001d0104294469676974616c636f696e2c20412043757272656e637920666f722061204469676974616c20416765");
        t.addInput(new TransactionInput(n, t, bytes));
        ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
        Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genesisTxOutBytes));
                //("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
        scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
        t.addOutput(new TransactionOutput(n, t, Coin.valueOf(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
    } catch (Exception e) {
        // Cannot happen.
        throw new RuntimeException(e);
    }
    genesisBlock.addTransaction(t);
    return genesisBlock;
}
项目:namecoinj    文件:TestNet3Params.java   
public TestNet3Params() {
    super();
    id = ID_TESTNET;

    // Genesis hash is 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943

    packetMagic = CoinDefinition.testnetPacketMagic;
    interval = INTERVAL;
    targetTimespan = TARGET_TIMESPAN;
    maxTarget = CoinDefinition.proofOfWorkLimit;
    port = 18333;
    addressHeader = CoinDefinition.testnetAddressHeader;
    p2shHeader = CoinDefinition.testnetp2shHeader;
    acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
    dumpedPrivateKeyHeader = 128 + CoinDefinition.testnetAddressHeader;
    genesisBlock.setTime(CoinDefinition.testnetGenesisBlockTime);
    genesisBlock.setDifficultyTarget(CoinDefinition.testnetGenesisBlockDifficultyTarget);
    genesisBlock.setNonce(CoinDefinition.testnetGenesisBlockNonce);
    spendableCoinbaseDepth = CoinDefinition.spendableCoinbaseDepth;
    subsidyDecreaseBlockCount = CoinDefinition.subsidyDecreaseBlockCount;
    //genesisBlock.setMerkleRoot(new Sha256Hash(CoinDefinition.genesisMerkleRoot));
    String genesisHash = genesisBlock.getHashAsString();

    if(CoinDefinition.supportsTestNet)
        checkState(genesisHash.equals(CoinDefinition.testnetGenesisHash));
    alertSigningKey = Utils.HEX.decode(CoinDefinition.TESTNET_SATOSHI_KEY);

    dnsSeeds = CoinDefinition.testnetDnsSeeds;


}
项目:namecoinj    文件:LitecoinPeerDBDiscovery.java   
@Override
public Message onPreMessageReceived(Peer p, Message m) {
    if (m instanceof AddressMessage) {
        AddressMessage newMessage = new AddressMessage(params);
        for (PeerAddress addr : ((AddressMessage) m).getAddresses())
            if (!CoinDefinition.supportsBloomFiltering || addr.getServices().and(BigInteger.valueOf(1 << 1)).equals(BigInteger.valueOf(1 << 1)))
                newMessage.addAddress(addr);
        return parent.onPreMessageReceived(p, newMessage);
    }
    return m;
}
项目:namecoinj    文件:LitecoinPeerDBDiscovery.java   
@Override
public void onPeerConnected(Peer p, int peerCount) {
    if (!CoinDefinition.supportsBloomFiltering || ((p.getPeerVersionMessage().localServices & (1<<1)) == (1<<1) &&
            p.getPeerVersionMessage().clientVersion >= 70002))
        parent.onPeerConnected(p, peerCount);
    else
        p.close();
}
项目:namecoinj    文件:BitcoinURITest.java   
@Test
public void testConvertToBitcoinURI() throws Exception {
    Address goodAddress = new Address(MainNetParams.get(), MAINNET_GOOD_ADDRESS);

    // simple example
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello&message=AMessage", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", "AMessage"));

    // example with spaces, ampersand and plus
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello%20World&message=Mess%20%26%20age%20%2B%20hope", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello World", "Mess & age + hope"));


    // no amount, label present, message present
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?label=Hello&message=glory", BitcoinURI.convertToBitcoinURI(goodAddress, null, "Hello", "glory"));

    // amount present, no label, message present

    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=0.1&message=glory", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("0.1"), null, "glory"));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=0.1&message=glory", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("0.1"), "", "glory"));

    // amount present, label present, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", null));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", ""));

    // amount present, no label, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=1000", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("1000"), null, null));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=1000", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("1000"), "", ""));


    // no amount, label present, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?label=Hello", BitcoinURI.convertToBitcoinURI(goodAddress, null, "Hello", null));

    // no amount, no label, message present
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?message=Agatha", BitcoinURI.convertToBitcoinURI(goodAddress, null, null, "Agatha"));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?message=Agatha", BitcoinURI.convertToBitcoinURI(goodAddress, null, "", "Agatha"));

    // no amount, no label, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS, BitcoinURI.convertToBitcoinURI(goodAddress, null, null, null));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS, BitcoinURI.convertToBitcoinURI(goodAddress, null, "", ""));
}
项目:namecoinj    文件:BitcoinURITest.java   
/**
 * Handles various well-formed combinations
 * 
 * @throws BitcoinURIParseException
 *             If something goes wrong
 */
@Test
public void testGood_Combinations() throws BitcoinURIParseException {
    testObject = new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
            + "?amount=6543210&label=Hello%20World&message=Be%20well");
    assertEquals(
            "BitcoinURI['amount'='654321000000000','label'='Hello World','message'='Be well','address'='"+CoinDefinition.UNITTEST_ADDRESS+"']",
            testObject.toString());
}
项目:namecoinj    文件:BitcoinURITest.java   
@Test
public void brokenURIs() throws BitcoinURIParseException {
    // Check we can parse the incorrectly formatted URIs produced by blockchain.info and its iPhone app.
    String str = CoinDefinition.coinURIScheme + "://"+CoinDefinition.UNITTEST_ADDRESS+"?amount=0.01000000";
    BitcoinURI uri = new BitcoinURI(str);

    assertEquals(CoinDefinition.UNITTEST_ADDRESS, uri.getAddress().toString());
    assertEquals(CENT, uri.getAmount());

}
项目:namecoinj    文件:BitcoinURITest.java   
@Test
public void testPaymentProtocolReq() throws Exception {
    // Non-backwards compatible form ...
    BitcoinURI uri = new BitcoinURI(TestNet3Params.get(), CoinDefinition.coinURIScheme + ":?r=https%3A%2F%2Fbitcoincore.org%2F%7Egavin%2Ff.php%3Fh%3Db0f02e7cea67f168e25ec9b9f9d584f9");
    assertEquals("https://bitcoincore.org/~gavin/f.php?h=b0f02e7cea67f168e25ec9b9f9d584f9", uri.getPaymentRequestUrl());
    assertEquals(ImmutableList.of("https://bitcoincore.org/~gavin/f.php?h=b0f02e7cea67f168e25ec9b9f9d584f9"),
            uri.getPaymentRequestUrls());
    assertNull(uri.getAddress());
}
项目:digibytej-alice    文件:MainNetParams.java   
public MainNetParams() {
      super();
      interval = INTERVAL;
      targetTimespan = TARGET_TIMESPAN;
      maxTarget = CoinDefinition.proofOfWorkLimit;
      dumpedPrivateKeyHeader = 128;
      addressHeader = CoinDefinition.AddressHeader;
      p2shHeader = CoinDefinition.p2shHeader;
      acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
      port = CoinDefinition.Port;
      packetMagic = CoinDefinition.PacketMagic;
      bip32HeaderPub = 0x0488B21E; //The 4 byte header that serializes in base58 to "xpub".
      bip32HeaderPriv = 0x0488ADE4; //The 4 byte header that serializes in base58 to "xprv"

      genesisBlock.setDifficultyTarget(CoinDefinition.genesisBlockDifficultyTarget);
      genesisBlock.setTime(CoinDefinition.genesisBlockTime);
      genesisBlock.setNonce(CoinDefinition.genesisBlockNonce);
      id = ID_MAINNET;
      subsidyDecreaseBlockCount = CoinDefinition.subsidyDecreaseBlockCount;
      spendableCoinbaseDepth = CoinDefinition.spendableCoinbaseDepth;
      genesisBlock.setMerkleRoot(new Sha256Hash(CoinDefinition.genesisMerkleRoot));
      String genesisHash = genesisBlock.getHashAsString();      
      checkState(genesisHash.equals(CoinDefinition.genesisHash),
              genesisHash);

      // This contains (at a minimum) the blocks which are not BIP30 compliant. BIP30 changed how duplicate
      // transactions are handled. Duplicated transactions could occur in the case where a coinbase had the same
      // extraNonce and the same outputs but appeared at different heights, and greatly complicated re-org handling.
      // Having these here simplifies block connection logic considerably.
      CoinDefinition.initCheckpoints(checkpoints);

dnsSeeds = CoinDefinition.dnsSeeds;
  }
项目:dashj    文件:TestNet2Params.java   
public TestNet2Params() {
    super();
    id = ID_TESTNET;
    packetMagic = 0xfabfb5daL;

    port = CoinDefinition.TestPort;
    addressHeader = CoinDefinition.testnetAddressHeader;
    p2shHeader = CoinDefinition.testnetp2shHeader;
    acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
    interval = INTERVAL;
    targetTimespan = TARGET_TIMESPAN;
    maxTarget = CoinDefinition.proofOfWorkLimit;
    dumpedPrivateKeyHeader = 128 + CoinDefinition.testnetAddressHeader;

    genesisBlock.setTime(CoinDefinition.testnetGenesisBlockTime);
    genesisBlock.setDifficultyTarget(CoinDefinition.testnetGenesisBlockDifficultyTarget);
    genesisBlock.setNonce(CoinDefinition.testnetGenesisBlockNonce);
    spendableCoinbaseDepth = CoinDefinition.spendableCoinbaseDepth;
    subsidyDecreaseBlockCount = CoinDefinition.subsidyDecreaseBlockCount;
    String genesisHash = genesisBlock.getHashAsString();
    if(CoinDefinition.supportsTestNet)
        checkState(genesisHash.equals(CoinDefinition.testnetGenesisHash));
    //checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"));
    dnsSeeds = null;
    addrSeeds = null;
    bip32HeaderPub = 0x043587CF;
    bip32HeaderPriv = 0x04358394;

    majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
    majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
    majorityWindow = TESTNET_MAJORITY_WINDOW;

    DIP0001BlockHeight = 15000;

}
项目:dashj    文件:BitcoinURITest.java   
/**
 * Handles various well-formed combinations
 * 
 * @throws BitcoinURIParseException
 *             If something goes wrong
 */
@Test
public void testGood_Combinations() throws BitcoinURIParseException {
    testObject = new BitcoinURI(MAINNET, BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
            + "?amount=6543210&label=Hello%20World&message=Be%20well");
    assertEquals(
            "BitcoinURI['amount'='654321000000000','label'='Hello World','message'='Be well','address'='"+CoinDefinition.UNITTEST_ADDRESS+"']",
            testObject.toString());
}
项目:dashj    文件:BitcoinURITest.java   
@Test
public void brokenURIs() throws BitcoinURIParseException {
    // Check we can parse the incorrectly formatted URIs produced by blockchain.info and its iPhone app.
    String str = CoinDefinition.coinURIScheme + "://"+CoinDefinition.UNITTEST_ADDRESS+"?amount=0.01000000";
    BitcoinURI uri = new BitcoinURI(str);
    assertEquals(CoinDefinition.UNITTEST_ADDRESS, uri.getAddress().toString());
    assertEquals(CENT, uri.getAmount());
}
项目:dashj    文件:BitcoinURITest.java   
@Test
public void testPaymentProtocolReq() throws Exception {
    // Non-backwards compatible form ...
    BitcoinURI uri = new BitcoinURI(TestNet3Params.get(), CoinDefinition.coinURIScheme + ":?r=https%3A%2F%2Fbitcoincore.org%2F%7Egavin%2Ff.php%3Fh%3Db0f02e7cea67f168e25ec9b9f9d584f9");
    assertEquals("https://bitcoincore.org/~gavin/f.php?h=b0f02e7cea67f168e25ec9b9f9d584f9", uri.getPaymentRequestUrl());
    assertEquals(ImmutableList.of("https://bitcoincore.org/~gavin/f.php?h=b0f02e7cea67f168e25ec9b9f9d584f9"),
            uri.getPaymentRequestUrls());
    assertNull(uri.getAddress());
}
项目:namecoinj    文件:Threading.java   
public UserThread() {
    super(CoinDefinition.coinURIScheme + "j user thread");      //Modified for CoinDefinition
    setDaemon(true);
    tasks = new LinkedBlockingQueue<Runnable>();
    start();
}
项目:namecoinj    文件:LitecoinPeerDBDiscovery.java   
@Override
public void onPeerDisconnected(Peer p, int peerCount) {
    if (!CoinDefinition.supportsBloomFiltering || (p.getPeerVersionMessage() != null && (p.getPeerVersionMessage().localServices & (1<<1)) == (1<<1)))
        parent.onPeerDisconnected(p, peerCount);
}
项目:namecoinj    文件:BitcoinURITest.java   
@Test(expected = BitcoinURIParseException.class)
public void testBad_TooLargeAmount() throws BitcoinURIParseException {
    new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
            + "?amount="+(CoinDefinition.MAX_COINS * 5));
}
项目:digibytej-alice    文件:Threading.java   
public UserThread() {
    super(CoinDefinition.coinURIScheme + "j user thread"); 
    setDaemon(true);
    tasks = new LinkedBlockingQueue<Runnable>();
    start();
}
项目:dashj    文件:Threading.java   
public UserThread() {
    super(CoinDefinition.coinURIScheme + "j user thread");      //Modified for CoinDefinition
    setDaemon(true);
    tasks = new LinkedBlockingQueue<Runnable>();
    start();
}
项目:dashj    文件:BitcoinURITest.java   
@Test
public void testConvertToBitcoinURI() throws Exception {
    Address goodAddress = Address.fromBase58(MAINNET, MAINNET_GOOD_ADDRESS);

    // simple example
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello&message=AMessage", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", "AMessage"));

    // example with spaces, ampersand and plus
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello%20World&message=Mess%20%26%20age%20%2B%20hope", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello World", "Mess & age + hope"));

    // no amount, label present, message present
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?label=Hello&message=glory", BitcoinURI.convertToBitcoinURI(goodAddress, null, "Hello", "glory"));

    // amount present, no label, message present
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=0.1&message=glory", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("0.1"), null, "glory"));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=0.1&message=glory", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("0.1"), "", "glory"));

    // amount present, label present, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", null));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", ""));

    // amount present, no label, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=1000", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("1000"), null, null));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?amount=1000", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("1000"), "", ""));

    // no amount, label present, no message
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?label=Hello", BitcoinURI.convertToBitcoinURI(goodAddress, null, "Hello", null));

    // no amount, no label, message present
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?message=Agatha", BitcoinURI.convertToBitcoinURI(goodAddress, null, null, "Agatha"));
    assertEquals(CoinDefinition.coinURIScheme + ":" + MAINNET_GOOD_ADDRESS + "?message=Agatha", BitcoinURI.convertToBitcoinURI(goodAddress, null, "", "Agatha"));

    // no amount, no label, no message
    assertEquals("dash:" + MAINNET_GOOD_ADDRESS, BitcoinURI.convertToBitcoinURI(goodAddress, null, null, null));
    assertEquals("dash:" + MAINNET_GOOD_ADDRESS, BitcoinURI.convertToBitcoinURI(goodAddress, null, "", ""));

    // different scheme
    final NetworkParameters alternativeParameters = new MainNetParams() {
        @Override
        public String getUriScheme() {
            return "test";
        }
    };

    assertEquals("test:" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello&message=AMessage",
         BitcoinURI.convertToBitcoinURI(Address.fromBase58(alternativeParameters, MAINNET_GOOD_ADDRESS), parseCoin("12.34"), "Hello", "AMessage"));
}