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


Java MainNetParams.get方法代码示例

本文整理汇总了Java中org.bitcoinj.params.MainNetParams.get方法的典型用法代码示例。如果您正苦于以下问题:Java MainNetParams.get方法的具体用法?Java MainNetParams.get怎么用?Java MainNetParams.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.params.MainNetParams的用法示例。


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

示例1: testVector

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
private void testVector(int testCase) {
    log.info("=======  Test vector {}", testCase);
    HDWTestVector tv = tvs[testCase];
    NetworkParameters params = MainNetParams.get();
    DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(HEX.decode(tv.seed));
    assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58(params)));
    assertEquals(testEncode(tv.pub), testEncode(masterPrivateKey.serializePubB58(params)));
    DeterministicHierarchy dh = new DeterministicHierarchy(masterPrivateKey);
    for (int i = 0; i < tv.derived.size(); i++) {
        HDWTestVector.DerivedTestCase tc = tv.derived.get(i);
        log.info("{}", tc.name);
        assertEquals(tc.name, String.format(Locale.US, "Test%d %s", testCase + 1, tc.getPathDescription()));
        int depth = tc.path.length - 1;
        DeterministicKey ehkey = dh.deriveChild(Arrays.asList(tc.path).subList(0, depth), false, true, tc.path[depth]);
        assertEquals(testEncode(tc.priv), testEncode(ehkey.serializePrivB58(params)));
        assertEquals(testEncode(tc.pub), testEncode(ehkey.serializePubB58(params)));
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:19,代码来源:BIP32Test.java

示例2: walletTest

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void walletTest() throws Exception {
    NetworkParameters params = MainNetParams.get();
    Context.propagate(new Context(params));

    DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(params, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");

    Address addr = privKey.getKey().toAddress(params);
    assertTrue(addr.toString().equals("17Wx1GQfyPTNWpQMHrTwRSMTCAonSiZx9e"));

    KeyChainGroup group = new KeyChainGroup(params);
    // Add a random key which happens to have been used in a recent generation
    group.importKeys(ECKey.fromPublicOnly(privKey.getKey().getPubKeyPoint()), ECKey.fromPublicOnly(HEX.decode("03cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99")));
    Wallet wallet = new Wallet(params, group);
    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());
    
    BloomFilter filter = wallet.getBloomFilter(wallet.getBloomFilterElementCount(), 0.001, 0);
    
    // Value generated by Bitcoin Core
    assertTrue(Arrays.equals(HEX.decode("082ae5edc8e51d4a03080000000000000002"), filter.unsafeBitcoinSerialize()));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:25,代码来源:BloomFilterTest.java

示例3: testAddr

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void testAddr() throws Exception {
    final NetworkParameters params = MainNetParams.get();
    MessageSerializer serializer = params.getDefaultSerializer();
    // the actual data from https://en.bitcoin.it/wiki/Protocol_specification#addr
    AddressMessage addressMessage = (AddressMessage) serializer.deserialize(ByteBuffer.wrap(ADDRESS_MESSAGE_BYTES));
    assertEquals(1, addressMessage.getAddresses().size());
    PeerAddress peerAddress = addressMessage.getAddresses().get(0);
    assertEquals(8333, peerAddress.getPort());
    assertEquals("10.0.0.1", peerAddress.getAddr().getHostAddress());
    ByteArrayOutputStream bos = new ByteArrayOutputStream(ADDRESS_MESSAGE_BYTES.length);
    serializer.serialize(addressMessage, bos);

    assertEquals(31, addressMessage.getMessageSize());
    addressMessage.addAddress(new PeerAddress(params, InetAddress.getLocalHost()));
    assertEquals(61, addressMessage.getMessageSize());
    addressMessage.removeAddress(0);
    assertEquals(31, addressMessage.getMessageSize());

    //this wont be true due to dynamic timestamps.
    //assertTrue(LazyParseByteCacheTest.arrayContains(bos.toByteArray(), addrMessage));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:23,代码来源:BitcoinSerializerTest.java

示例4: testFirst100KBlocks

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void testFirst100KBlocks() throws Exception {
    NetworkParameters params = MainNetParams.get();
    Context context = new Context(params);
    File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile());
    BlockFileLoader loader = new BlockFileLoader(params, Arrays.asList(blockFile));
    
    store = createStore(params, 10);
    resetStore(store);
    chain = new FullPrunedBlockChain(context, store);
    for (Block block : loader)
        chain.add(block);
    try {
        store.close();
    } catch (Exception e) {}
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:17,代码来源:AbstractFullPrunedBlockChainTest.java

示例5: main

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
public static void main(String[] args) {
    BriefLogFormatter.init();
    NetworkParameters params = MainNetParams.get();
    PeerGroup peerGroup = new PeerGroup(params);
    peerGroup.addPeerDiscovery(new DnsDiscovery(params));
    peerGroup.addEventListener(new AbstractPeerEventListener() {
        @Override
        public void onTransaction(Peer peer, Transaction tx) {
            try {
                if (tx.getOutputs().size() != 1) return;
                if (!tx.getOutput(0).getScriptPubKey().isSentToRawPubKey()) return;
                log.info("Saw raw pay to pubkey {}", tx);
            } catch (ScriptException e) {
                e.printStackTrace();
            }
        }
    });
    peerGroup.startAsync();
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:20,代码来源:WatchMempool.java

示例6: p2shAddress

import org.bitcoinj.params.MainNetParams; //导入方法依赖的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,项目名称:namecoinj,代码行数:26,代码来源:AddressTest.java

示例7: getInstance

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
/**
 * Return instance for a watch only wallet. No seed, no private keys.
 *
 * @param  Context ctx app context
 * @param  String[] xpub restore these accounts only
 *
 * @return WalletFactory
 *
 */
public static WalletFactory getInstance(String[] xpub) throws AddressFormatException {

	if(instance == null) {
		locale = new Locale("en", "US");
		wallets = new ArrayList<Wallet>();
		instance = new WalletFactory();
	}

	if(watch_only_wallet == null) {
		watch_only_wallet = new Wallet(MainNetParams.get(), xpub);
	}

	return instance;
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:24,代码来源:WalletFactory.java

示例8: newWallet

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
/**
 * Create new wallet.
 *
 * @param  int nbWords number of words in menmonic
 * @param  String passphrase optional BIP39 passphrase
 * @param  int nbAccounts create this number of accounts
 *
 * @return Wallet
 *
 */
public Wallet newWallet(int nbWords, String passphrase, int nbAccounts) throws IOException, MnemonicException.MnemonicLengthException   {

	Wallet hdw = null;

	if((nbWords % 3 != 0) || (nbWords < 12 || nbWords > 24)) {
		nbWords = 12;
	}

	// len == 16 (12 words), len == 24 (18 words), len == 32 (24 words)
	int len = (nbWords / 3) * 4;

	if(passphrase == null) {
		passphrase = "";
	}

	NetworkParameters params = MainNetParams.get();

	SecureRandom random = new SecureRandom();
	byte seed[] = new byte[len];
	random.nextBytes(seed);

	MnemonicCode mc = new MnemonicCode();
	hdw = new Wallet(mc, params, seed, passphrase);

	wallets.clear();
	wallets.add(hdw);

	return hdw;
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:40,代码来源:WalletFactory.java

示例9: restoreWalletFromJSON

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
public Wallet restoreWalletFromJSON(JSONObject obj, String passPhrase) throws Exception {
	NetworkParameters params = MainNetParams.get();
	Wallet wallet = new Wallet(obj, passPhrase, params);

	log("mnemonics: " + wallet.getMnemonic());
	log("address: " + wallet.getAddress().getAddressString());
	
	wallets.clear();
	wallets.add(wallet);

	return wallet;
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:13,代码来源:WalletFactory.java

示例10: testWallet

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void testWallet() throws UnreadableWalletException {
	long creationTimeSeconds = System.currentTimeMillis() / 1000;
	NetworkParameters params = MainNetParams.get();
	String [] MNEMONIC = new String [] {"sword","acquire","little","despair","wave","swear","during","expect","target","science","banana","eyebrow"};
	String RECEIVE_ADDRESS = "13w74gmmSjb2DWit5iRQbCKPZj89FkCidH";
	String CHANGE_ADDRESS = "1hF37FtrcSyEFkyxo2Q3541aGfWRqsuLV";
	
	List<String> fixedMnemonic = toMnemonic(MNEMONIC);
	printMnemonic(fixedMnemonic);
	
	DeterministicSeed ds2 = new DeterministicSeed(fixedMnemonic, null, "", creationTimeSeconds);
	
	KeyChainGroup fixedKeyChainFromSeed = new KeyChainGroup(params, ds2);
	Wallet fixedWallet = new Wallet(params, fixedKeyChainFromSeed);
	
	String fixedReceiveAddress = fixedWallet.currentReceiveAddress().toString();
	String fixedChangeAddress = fixedWallet.currentChangeAddress().toString();

	Assert.assertEquals(RECEIVE_ADDRESS, fixedReceiveAddress);
	Assert.assertEquals(CHANGE_ADDRESS, fixedChangeAddress);
	
	printAddress(fixedKeyChainFromSeed.currentAddress(KeyPurpose.AUTHENTICATION), "current auth address");
	printAddress(fixedKeyChainFromSeed.currentAddress(KeyPurpose.CHANGE), "current change address");
	printAddress(fixedKeyChainFromSeed.currentAddress(KeyPurpose.RECEIVE_FUNDS), "current receive address");
	printAddress(fixedKeyChainFromSeed.currentAddress(KeyPurpose.REFUND), "current refund address");
	
	for(int i = 0; i < 10; i++) {
		System.out.println("address[" + i + "]: "+ fixedKeyChainFromSeed.freshAddress(KeyPurpose.RECEIVE_FUNDS).toString());
	}
	
	System.out.println("---------------");
	
	String MNEMONIC_STRING = "sword acquire little despair wave swear during expect target science banana eyebrow";
	DeterministicSeed seed = new DeterministicSeed(MNEMONIC_STRING, null, "", creationTimeSeconds);
	Wallet wallet = Wallet.fromSeed(params, seed);
	
	System.out.println("wallet receive address: " + wallet.currentReceiveAddress().toString());
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:40,代码来源:BitcoinjTest.java

示例11: testWalletFromSeed

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void testWalletFromSeed() throws Exception {
	NetworkParameters params = MainNetParams.get();
	MnemonicCode mc = new MnemonicCode();
	Wallet wallet = new Wallet(mc, params, WALLET_SEED_BYTES, WALLET_PASS_PHRASE);
	
	assertEquals(WALLET_SEED, wallet.getSeedHex());
	assertArrayEquals(WALLET_SEED_BYTES, wallet.getSeed());
	assertEquals(WALLET_MNEMONIC, wallet.getMnemonic());
	assertEquals(WALLET_PASS_PHRASE, wallet.getPassphrase());		
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:12,代码来源:WalletTest.java

示例12: testDummyFromMnemonics

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void testDummyFromMnemonics() throws IOException, MnemonicLengthException, MnemonicWordException, MnemonicChecksumException {
	String words = "sword acquire little despair wave swear during expect target science banana eyebrow";
	NetworkParameters params = MainNetParams.get();
	MnemonicCode mc = new MnemonicCode();
	words = words.replaceAll("[^a-z]+", " "); // assume BIP39 English
	List<String> mnemonic =  Arrays.asList(words.trim().split("\\s+"));
       byte [] seed = mc.toEntropy(mnemonic);
	
	Wallet wallet = new Wallet(mc, params, seed, WALLET_PASS_PHRASE);
	log("wallet in json format:\n%s", wallet.toJSON().toString(2));
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:13,代码来源:WalletTest.java

示例13: testWalletFromMnemonics

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
@Test
public void testWalletFromMnemonics() throws Exception {
	NetworkParameters params = MainNetParams.get();
	MnemonicCode mc = new MnemonicCode();
	List<String> mnemonic = toList(WALLET_MNEMONIC);
	Wallet wallet = new Wallet(mc, params, mnemonic, WALLET_PASS_PHRASE);
	
	assertEquals(WALLET_SEED, wallet.getSeedHex());
	assertArrayEquals(WALLET_SEED_BYTES, wallet.getSeed());
	assertEquals(WALLET_MNEMONIC, wallet.getMnemonic());
	assertEquals(WALLET_PASS_PHRASE, wallet.getPassphrase());		
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:13,代码来源:WalletTest.java

示例14: parsePaymentRequest

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
private void parsePaymentRequest(Protos.PaymentRequest request) throws PaymentProtocolException {
    try {
        if (request == null)
            throw new PaymentProtocolException("request cannot be null");
        if (request.getPaymentDetailsVersion() != 1)
            throw new PaymentProtocolException.InvalidVersion("Version 1 required. Received version " + request.getPaymentDetailsVersion());
        paymentRequest = request;
        if (!request.hasSerializedPaymentDetails())
            throw new PaymentProtocolException("No PaymentDetails");
        paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build();
        if (paymentDetails == null)
            throw new PaymentProtocolException("Invalid PaymentDetails");
        if (!paymentDetails.hasNetwork())
            params = MainNetParams.get();
        else
            params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork());
        if (params == null)
            throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork());
        if (paymentDetails.getOutputsCount() < 1)
            throw new PaymentProtocolException.InvalidOutputs("No outputs");
        for (Protos.Output output : paymentDetails.getOutputsList()) {
            if (output.hasAmount())
                totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
        }
        // This won't ever happen in practice. It would only happen if the user provided outputs
        // that are obviously invalid. Still, we don't want to silently overflow.
        if (params.hasMaxMoney() && totalValue.compareTo(params.getMaxMoney()) > 0)
            throw new PaymentProtocolException.InvalidOutputs("The outputs are way too big.");
    } catch (InvalidProtocolBufferException e) {
        throw new PaymentProtocolException(e);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:33,代码来源:PaymentSession.java

示例15: checkUpgrade

import org.bitcoinj.params.MainNetParams; //导入方法依赖的package包/类
public void checkUpgrade(Context context, NetworkParameters params) {
    if (checkDone) {
        // skip if already done
        return;
    }

    String appVersion = SharedPrefUtils.getAppVersion(context);
    if (appVersion == null) {
        // first start - no app version yet.
        Log.d(TAG, "No appVersion yet - first launch");
    } else if (appVersion.equals(BuildConfig.VERSION_NAME)) {
        Log.d(TAG, "appVersion '" + appVersion + "' equals current version - no action required");
    } else {
        // add upgrade instructions as needed.
    }

    if(migrateFrom_v1_0_262(context)) {
        Log.d(TAG, "Migrate from v1.0.262 / 2of2 multisig (CeBIT) to CLTV");
        /* special case: migrate from objectstore and 2of2 multisig wallet
         * - migrate from early version v1.0.262 (CeBIT)
         * - enable transfer of funds to new address (2of2 multisig to cltv)
         */
        try {
            // migration is done for mainnet and testnet regardless of the current network setting of the app!
            NetworkParameters[] cltvMigrationParams = new NetworkParameters[]{MainNetParams.get(), TestNet3Params.get()};
            for (NetworkParameters migrationParams : cltvMigrationParams) {
                doMigrateFrom_v1_0_262(context, migrationParams);
            }
        } catch (Exception e) {
            Log.e(TAG, "Migration failed: ", e);
        }
    }


    SharedPrefUtils.setAppVersion(context, BuildConfig.VERSION_NAME);
    checkDone = true;
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:38,代码来源:UpgradeUtils.java


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