本文整理汇总了Java中org.bitcoinj.params.MainNetParams类的典型用法代码示例。如果您正苦于以下问题:Java MainNetParams类的具体用法?Java MainNetParams怎么用?Java MainNetParams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MainNetParams类属于org.bitcoinj.params包,在下文中一共展示了MainNetParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RegisteringWot
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
/**
* Creates new form RegisteringWot
*/
public RegisteringWot() {
BitcoinWot.REGISTERING_WOT = this;
initComponents();
BitcoinWot.centreWindow(this);
setCursor(new Cursor(Cursor.WAIT_CURSOR));
new Thread(new Runnable() {
@Override
public void run() {
BitcoinWot.BOT.joinChannel("#gribble");
Address address = new Address(new MainNetParams(),
BitcoinWot.KEY.getPubKeyHash());
BitcoinWot.BOT.sendMessage("gribble", ";;bcregister "
+ BitcoinWot.LOGIN.getjTextField1().getText() + " "
+ address.toString());
}
}).start();
}
示例2: 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)));
}
}
示例3: 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()));
}
示例4: 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));
}
示例5: testHeaders1
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
/**
* Get 1 header of the block number 1 (the first one is 0) in the chain
*/
@Test
public void testHeaders1() throws Exception {
MessageSerializer serializer = MainNetParams.get().getDefaultSerializer();
byte[] headersMessageBytes = HEX.decode("f9beb4d9686561" +
"646572730000000000520000005d4fab8101010000006fe28c0ab6f1b372c1a6a246ae6" +
"3f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677b" +
"a1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e3629900");
HeadersMessage headersMessage = (HeadersMessage) serializer.deserialize(ByteBuffer.wrap(headersMessageBytes));
// The first block after the genesis
// http://blockexplorer.com/b/1
Block block = headersMessage.getBlockHeaders().get(0);
assertEquals("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048", block.getHashAsString());
assertNotNull(block.transactions);
assertEquals("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", Utils.HEX.encode(block.getMerkleRoot().getBytes()));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
serializer.serialize(headersMessage, byteArrayOutputStream);
byte[] serializedBytes = byteArrayOutputStream.toByteArray();
assertArrayEquals(headersMessageBytes, serializedBytes);
}
示例6: 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) {}
}
示例7: p2shAddress
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
@Test
public void p2shAddress() throws Exception {
// Test that we can construct P2SH addresses
Address mainNetP2SHAddress = Address.fromBase58(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
assertEquals(mainNetP2SHAddress.version, MainNetParams.get().p2shHeader);
assertTrue(mainNetP2SHAddress.isP2SHAddress());
Address testNetP2SHAddress = Address.fromBase58(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());
}
示例8: testAddr
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
@Test
public void testAddr() throws Exception {
BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get());
// the actual data from https://en.bitcoin.it/wiki/Protocol_specification#addr
AddressMessage a = (AddressMessage)bs.deserialize(ByteBuffer.wrap(addrMessage));
assertEquals(1, a.getAddresses().size());
PeerAddress pa = a.getAddresses().get(0);
assertEquals(8333, pa.getPort());
assertEquals("10.0.0.1", pa.getAddr().getHostAddress());
ByteArrayOutputStream bos = new ByteArrayOutputStream(addrMessage.length);
bs.serialize(a, bos);
assertEquals(31, a.getMessageSize());
a.addAddress(new PeerAddress(InetAddress.getLocalHost()));
assertEquals(61, a.getMessageSize());
a.removeAddress(0);
assertEquals(31, a.getMessageSize());
//this wont be true due to dynamic timestamps.
//assertTrue(LazyParseByteCacheTest.arrayContains(bos.toByteArray(), addrMessage));
}
示例9: pshTx
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
@Test
public void pshTx() {
final List<TransactionInput> inputs = tx1.getInputs();
for (TransactionInput input : inputs) {
try {
Address current = input.getScriptSig().getFromAddress(MainNetParams.get());
System.out.println(current.toString());
} catch (ScriptException e) {
System.out.println("exception");
}
}
}
示例10: testHeaders1
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
/**
* Get 1 header of the block number 1 (the first one is 0) in the chain
*/
@Test
public void testHeaders1() throws Exception {
BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get());
HeadersMessage hm = (HeadersMessage) bs.deserialize(ByteBuffer.wrap(HEX.decode("f9beb4d9686561" +
"646572730000000000520000005d4fab8101010000006fe28c0ab6f1b372c1a6a246ae6" +
"3f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677b" +
"a1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e3629900")));
// The first block after the genesis
// http://blockexplorer.com/b/1
Block block = hm.getBlockHeaders().get(0);
String hash = block.getHashAsString();
assertEquals(hash, "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048");
assertNull(block.transactions);
assertEquals(Utils.HEX.encode(block.getMerkleRoot().getBytes()),
"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098");
}
示例11: testGood_Amount
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
/**
* Handles a simple amount
*
* @throws BitcoinURIParseException
* If something goes wrong
*/
@Test
public void testGood_Amount() throws BitcoinURIParseException {
// Test the decimal parsing
testObject = new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
+ "?amount=6543210.12345678");
assertEquals("654321012345678", testObject.getAmount().toString());
// Test the decimal parsing
testObject = new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
+ "?amount=.12345678");
assertEquals("12345678", testObject.getAmount().toString());
// Test the integer parsing
testObject = new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
+ "?amount=6543210");
assertEquals("654321000000000", testObject.getAmount().toString());
}
示例12: walletTest
import org.bitcoinj.params.MainNetParams; //导入依赖的package包/类
@Test
public void walletTest() throws Exception {
NetworkParameters params = MainNetParams.get();
DumpedPrivateKey privKey = new DumpedPrivateKey(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(privKey.getKey(), 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 the reference client
assertTrue(Arrays.equals(HEX.decode("082ae5edc8e51d4a03080000000000000002"), filter.bitcoinSerialize()));
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}