当前位置: 首页>>代码示例>>Java>>正文


Java TestNet3Params类代码示例

本文整理汇总了Java中com.google.bitcoin.params.TestNet3Params的典型用法代码示例。如果您正苦于以下问题:Java TestNet3Params类的具体用法?Java TestNet3Params怎么用?Java TestNet3Params使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TestNet3Params类属于com.google.bitcoin.params包,在下文中一共展示了TestNet3Params类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAndWait();
    PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
    peerGroup.addAddress(addr);
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash blockHash = new Sha256Hash(args[0]);
    Future<Block> future = peer.getBlock(blockHash);
    System.out.println("Waiting for node to send us the requested block: " + blockHash);
    Block block = future.get();
    System.out.println(block);
    peerGroup.stop();
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:22,代码来源:FetchBlock.java

示例2: p2shAddress

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void p2shAddress() throws Exception {
    // Test that we can construct P2SH addresses
    Address mainNetP2SHAddress = new Address(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
    assertEquals(mainNetP2SHAddress.version, MainNetParams.get().p2shHeader);
    assertTrue(mainNetP2SHAddress.isP2SHAddress());
    Address testNetP2SHAddress = new Address(TestNet3Params.get(), "2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe");
    assertEquals(testNetP2SHAddress.version, TestNet3Params.get().p2shHeader);
    assertTrue(testNetP2SHAddress.isP2SHAddress());

    // Test that we can determine what network a P2SH address belongs to
    NetworkParameters mainNetParams = Address.getParametersFromAddress("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
    assertEquals(MainNetParams.get().getId(), mainNetParams.getId());
    NetworkParameters testNetParams = Address.getParametersFromAddress("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe");
    assertEquals(TestNet3Params.get().getId(), testNetParams.getId());

    // Test that we can convert them from hashes
    byte[] hex = Hex.decode("2ac4b0b501117cc8119c5797b519538d4942e90e");
    Address a = Address.fromP2SHHash(mainParams, hex);
    assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", a.toString());
    Address b = Address.fromP2SHHash(testParams, Hex.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
    assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString());
    Address c = Address.fromP2SHScript(mainParams, ScriptBuilder.createP2SHOutputScript(hex));
    assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:26,代码来源:AddressTest.java

示例3: run

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
public void run() throws Exception {
    NetworkParameters params = TestNet3Params.get();

    // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we
    // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so
    // the plugin that knows how to parse all the additional data is present during the load.
    appKit = new WalletAppKit(params, new File("."), "payment_channel_example_server") {
        @Override
        protected void addWalletExtensions() {
            // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting
            // the refund transaction if its lock time has expired. It also persists channels so we can resume them
            // after a restart.
            storedStates = new StoredPaymentChannelServerStates(wallet(), peerGroup());
            wallet().addExtension(storedStates);
        }
    };
    appKit.startAndWait();

    System.out.println(appKit.wallet());

    // We provide a peer group, a wallet, a timeout in seconds, the amount we require to start a channel and
    // an implementation of HandlerFactory, which we just implement ourselves.
    final int MILLI = 100000;
    new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), 15, BigInteger.valueOf(MILLI), this).bindAndStart(4242);
}
 
开发者ID:cannabiscoindev,项目名称:cannabiscoinj,代码行数:26,代码来源:ExamplePaymentChannelServer.java

示例4: run

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
public void run() throws Exception {
    NetworkParameters params = TestNet3Params.get();

    // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we
    // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so
    // the plugin that knows how to parse all the additional data is present during the load.
    appKit = new WalletAppKit(params, new File("."), "payment_channel_example_server") {
        @Override
        protected void addWalletExtensions() {
            // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting
            // the refund transaction if its lock time has expired. It also persists channels so we can resume them
            // after a restart.
            storedStates = new StoredPaymentChannelServerStates(wallet(), peerGroup());
            wallet().addExtension(storedStates);
        }
    };
    appKit.startAsync();
    appKit.awaitRunning();

    System.out.println(appKit.wallet());

    // We provide a peer group, a wallet, a timeout in seconds, the amount we require to start a channel and
    // an implementation of HandlerFactory, which we just implement ourselves.
    final int MILLI = 100000;
    new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), 15, BigInteger.valueOf(MILLI), this).bindAndStart(4242);
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:27,代码来源:ExamplePaymentChannelServer.java

示例5: main

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAsync();
    peerGroup.awaitRunning();
    PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
    peerGroup.addAddress(addr);
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash blockHash = new Sha256Hash(args[0]);
    Future<Block> future = peer.getBlock(blockHash);
    System.out.println("Waiting for node to send us the requested block: " + blockHash);
    Block block = future.get();
    System.out.println(block);
    peerGroup.stopAsync();
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:23,代码来源:FetchBlock.java

示例6: main

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAndWait();
    peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash txHash = new Sha256Hash(args[0]);
    ListenableFuture<Transaction> future = peer.getPeerMempoolTransaction(txHash);
    System.out.println("Waiting for node to send us the requested transaction: " + txHash);
    Transaction tx = future.get();
    System.out.println(tx);

    System.out.println("Waiting for node to send us the dependencies ...");
    List<Transaction> deps = peer.downloadDependencies(tx).get();
    for (Transaction dep : deps) {
        System.out.println("Got dependency " + dep.getHashAsString());
    }

    System.out.println("Done.");
    peerGroup.stopAndWait();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:29,代码来源:FetchTransactions.java

示例7: testBad_IncorrectAddressType

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
/**
 * Test a broken URI (bad address type)
 */
@Test
public void testBad_IncorrectAddressType() {
    try {
        testObject = new BitcoinURI(TestNet3Params.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS);
        fail("Expecting BitcoinURIParseException");
    } catch (BitcoinURIParseException e) {
        assertTrue(e.getMessage().contains("Bad address"));
    }
}
 
开发者ID:keremhd,项目名称:mintcoinj,代码行数:13,代码来源:BitcoinURITest.java

示例8: dataDrivenValidScripts

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void dataDrivenValidScripts() throws Exception {
    BufferedReader in = new BufferedReader(new InputStreamReader(
            getClass().getResourceAsStream("script_valid.json"), Charset.forName("UTF-8")));

    NetworkParameters params = TestNet3Params.get();
    
    // Poor man's JSON parser (because pulling in a lib for this is overkill)
    String script = "";
    while (in.ready()) {
        String line = in.readLine();
        if (line == null || line.equals("")) continue;
        script += line;
        if (line.equals("]") && script.equals("]") && !in.ready())
            break; // ignore last ]
        if (line.trim().endsWith("],") || line.trim().endsWith("]")) {
            String[] scripts = script.split(",");

            scripts[0] = scripts[0].replaceAll("[\"\\[\\]]", "").trim();
            scripts[1] = scripts[1].replaceAll("[\"\\[\\]]", "").trim();
            Script scriptSig = parseScriptString(scripts[0]);
            Script scriptPubKey = parseScriptString(scripts[1]);

            try {
                scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, true);
            } catch (ScriptException e) {
                System.err.println("scriptSig: " + scripts[0]);
                System.err.println("scriptPubKey: " + scripts[1]);
                System.err.flush();
                throw e;
            }
            script = "";
        }
    }
    in.close();
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:37,代码来源:ScriptTest.java

示例9: dataDrivenInvalidScripts

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void dataDrivenInvalidScripts() throws Exception {
    BufferedReader in = new BufferedReader(new InputStreamReader(
            getClass().getResourceAsStream("script_invalid.json"), Charset.forName("UTF-8")));

    NetworkParameters params = TestNet3Params.get();
    
    // Poor man's JSON parser (because pulling in a lib for this is overkill)
    String script = "";
    while (in.ready()) {
        String line = in.readLine();
        if (line == null || line.equals("")) continue;
        script += line;
        if (line.equals("]") && script.equals("]") && !in.ready())
            break; // ignore last ]
        if (line.trim().endsWith("],") || line.trim().equals("]")) {
            String[] scripts = script.split(",");
            try {                    
                scripts[0] = scripts[0].replaceAll("[\"\\[\\]]", "").trim();
                scripts[1] = scripts[1].replaceAll("[\"\\[\\]]", "").trim();
                Script scriptSig = parseScriptString(scripts[0]);
                Script scriptPubKey = parseScriptString(scripts[1]);

                scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, true);
                System.err.println("scriptSig: " + scripts[0]);
                System.err.println("scriptPubKey: " + scripts[1]);
                System.err.flush();
                fail();
            } catch (VerificationException e) {
                // Expected.
            }
            script = "";
        }
    }
    in.close();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:37,代码来源:ScriptTest.java

示例10: base58Encoding_stress

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void base58Encoding_stress() throws Exception {
    // Replace the loop bound with 1000 to get some keys with leading zero byte
    for (int i = 0 ; i < 20 ; i++) {
        ECKey key = new ECKey();
        ECKey key1 = new DumpedPrivateKey(TestNet3Params.get(),
                key.getPrivateKeyEncoded(TestNet3Params.get()).toString()).getKey();
        assertEquals(Utils.bytesToHexString(key.getPrivKeyBytes()),
                Utils.bytesToHexString(key1.getPrivKeyBytes()));
    }
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:12,代码来源:ECKeyTest.java

示例11: testPaymentProtocolReq

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@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());
    assertNull(uri.getAddress());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:8,代码来源:BitcoinURITest.java

示例12: base58Encoding

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void base58Encoding() throws Exception {
    String addr = "mqAJmaxMcG5pPHHc3H3NtyXzY7kGbJLuMF";
    String privkey = "92shANodC6Y4evT5kFzjNFQAdjqTtHAnDTLzqBBq4BbKUPyx6CD";
    ECKey key = new DumpedPrivateKey(TestNet3Params.get(), privkey).getKey();
    assertEquals(privkey, key.getPrivateKeyEncoded(TestNet3Params.get()).toString());
    assertEquals(addr, key.toAddress(TestNet3Params.get()).toString());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:9,代码来源:ECKeyTest.java

示例13: base58Encoding_leadingZero

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void base58Encoding_leadingZero() throws Exception {
    String privkey = "91axuYLa8xK796DnBXXsMbjuc8pDYxYgJyQMvFzrZ6UfXaGYuqL";
    ECKey key = new DumpedPrivateKey(TestNet3Params.get(), privkey).getKey();
    assertEquals(privkey, key.getPrivateKeyEncoded(TestNet3Params.get()).toString());
    assertEquals(0, key.getPrivKeyBytes()[0]);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:8,代码来源:ECKeyTest.java

示例14: getParameters

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
/**
 * Examines the version byte of the address and attempts to find a matching NetworkParameters. If you aren't sure
 * which network the address is intended for (eg, it was provided by a user), you can use this to decide if it is
 * compatible with the current wallet. You should be able to handle a null response from this method. Note that the
 * parameters returned is not necessarily the same as the one the Address was created with.
 *
 * @return a NetworkParameters representing the network the address is intended for, or null if unknown.
 */
@Nullable
public NetworkParameters getParameters() {
    // TODO: There should be a more generic way to get all supported networks.
    NetworkParameters[] networks = { TestNet3Params.get(), MainNetParams.get() };
    for (NetworkParameters params : networks) {
        if (isAcceptableVersion(params, version)) {
            return params;
        }
    }
    return null;
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:20,代码来源:Address.java

示例15: getNetwork

import com.google.bitcoin.params.TestNet3Params; //导入依赖的package包/类
@Test
public void getNetwork() throws Exception {
    NetworkParameters params = Address.getParametersFromAddress(CoinDefinition.UNITTEST_ADDRESS);
    assertEquals(MainNetParams.get().getId(), params.getId());
    if(CoinDefinition.supportsTestNet)
    {
        params = Address.getParametersFromAddress("n4eA2nbYqErp7H6jebchxAN59DmNpksexv");
        assertEquals(TestNet3Params.get().getId(), params.getId());
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:11,代码来源:AddressTest.java


注:本文中的com.google.bitcoin.params.TestNet3Params类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。