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


Java NetworkParameters类代码示例

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


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

示例1: init

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
private void init(NetworkParameters params, byte[] seed, String passphrase) {
	this.params = params;
	this.seed = seed;
	strPassphrase = passphrase;
       byte[] hd_seed = MnemonicCode.toSeed(wordList, "");
	dkKey = HDKeyDerivation.createMasterPrivateKey(hd_seed);
	DeterministicKey dKey = HDKeyDerivation.deriveChildKey(dkKey, 44 | ChildNumber.HARDENED_BIT);
	dkRoot = HDKeyDerivation.deriveChildKey(dKey, ChildNumber.HARDENED_BIT);

	int nbAccounts = 1;
	accounts = new ArrayList<Account>();
	for(int i = 0; i < nbAccounts; i++) {
		accounts.add(new Account(params, dkRoot, i));
	}

	strPath = dKey.getPathAsString();
}
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:18,代码来源:Wallet.java

示例2: select

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
@Override
public CoinSelection select(Coin target, List<TransactionOutput> candidates) {
    ArrayList<TransactionOutput> selected = new ArrayList<>();
    // Sort the inputs by age*value so we get the highest "coindays" spent.
    // TODO: Consider changing the wallets internal format to track just outputs and keep them ordered.
    ArrayList<TransactionOutput> sortedOutputs = new ArrayList<>(candidates);
    // When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting
    // them in order to improve performance.
    // TODO: Take in network parameters when instanatiated, and then test against the current network. Or just have a boolean parameter for "give me everything"
    if (!target.equals(NetworkParameters.MAX_MONEY)) {
        sortOutputs(sortedOutputs);
    }
    // Now iterate over the sorted outputs until we have got as close to the target as possible or a little
    // bit over (excessive value will be change).
    long total = 0;
    for (TransactionOutput output : sortedOutputs) {
        if (total >= target.value) break;
        // Only pick chain-included transactions, or transactions that are ours and pending.
        if (!shouldSelect(output.getParentTransaction())) continue;
        selected.add(output);
        total += output.getValue().value;
    }
    // Total may be lower than target here, if the given candidates were insufficient to create to requested
    // transaction.
    return new CoinSelection(Coin.valueOf(total), selected);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:27,代码来源:DefaultCoinSelector.java

示例3: restoreWalletFromProtobufOrBase58

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public static Wallet restoreWalletFromProtobufOrBase58(final InputStream is,
        final NetworkParameters expectedNetworkParameters) throws IOException {
    is.mark((int) Constants.BACKUP_MAX_CHARS);

    try {
        return restoreWalletFromProtobuf(is, expectedNetworkParameters);
    } catch (final IOException x) {
        try {
            is.reset();
            return restorePrivateKeysFromBase58(is, expectedNetworkParameters);
        } catch (final IOException x2) {
            throw new IOException(
                    "cannot read protobuf (" + x.getMessage() + ") or base58 (" + x2.getMessage() + ")", x);
        }
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:17,代码来源:WalletUtils.java

示例4: getUserExternalAddress

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public static Address getUserExternalAddress(final String pubKey, final NetworkParameters networkParameters,
		final long userIndex) {
	
	DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
	DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
	
	List<ChildNumber> child = null;
	if (deterministicKey.getDepth() == 2) {
		
		/* M/44'/0' node tpub */
		child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(1/*user*/, false),
				new ChildNumber(0/*external*/, false), new ChildNumber((int)userIndex, false));
	
	} else if (deterministicKey.getDepth() == 3) {
		
		/* M/44'/0'/X context tpub */
		child = ImmutableList.of(new ChildNumber(1/*user*/, false),
				new ChildNumber(0/*external*/, false), new ChildNumber((int)userIndex, false));
	}

	DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
	return imprintingKey.toAddress(networkParameters);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java

示例5: getUserInternalAddress

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public static Address getUserInternalAddress(final String pubKey, final NetworkParameters networkParameters,
		final long userIndex) {
	
	DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
	DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
	
	List<ChildNumber> child = null;
	if (deterministicKey.getDepth() == 2) {
		
		/* M/44'/0' node tpub */
		child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(1/*user*/, false),
				new ChildNumber(1/*internal*/, false), new ChildNumber((int)userIndex, false));
	
	} else if (deterministicKey.getDepth() == 3) {
		
		/* M/44'/0'/X context tpub */
		child = ImmutableList.of(new ChildNumber(1/*user*/, false),
				new ChildNumber(1/*internal*/, false), new ChildNumber((int)userIndex, false));
	}

	DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
	return imprintingKey.toAddress(networkParameters);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java

示例6: getProviderExternalAddress

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public static Address getProviderExternalAddress(final String pubKey, final NetworkParameters networkParameters,
		final long providerIndex) {
	
	DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
	DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
	
	List<ChildNumber> child = null;
	if (deterministicKey.getDepth() == 2) {
		
		/* M/44'/0' node tpub */
		child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(0/*provider*/, false),
				new ChildNumber(/*external*/0, false), new ChildNumber((int)providerIndex, false));
	
	} else if (deterministicKey.getDepth() == 3) {
		
		/* M/44'/0'/X context tpub */
		child = ImmutableList.of(new ChildNumber(0/*provider*/, false),
				new ChildNumber(/*external*/0, false), new ChildNumber((int)providerIndex, false));
	}

	DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
	return imprintingKey.toAddress(networkParameters);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java

示例7: getProviderInternalAddress

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public static Address getProviderInternalAddress(final String pubKey, final NetworkParameters networkParameters,
		final long providerIndex) {
	
	DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
	DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
	
	List<ChildNumber> child = null;
	if (deterministicKey.getDepth() == 2) {
		
		/* M/44'/0' node tpub */
		child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(0/*provider*/, false),
				new ChildNumber(1/*internal*/, false), new ChildNumber((int)providerIndex, false));
	
	} else if (deterministicKey.getDepth() == 3) {
		
		/* M/44'/0'/X context tpub */
		child = ImmutableList.of(new ChildNumber(0/*provider*/, false),
				new ChildNumber(1/*internal*/, false), new ChildNumber((int)providerIndex, false));
	}

	DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
	return imprintingKey.toAddress(networkParameters);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java

示例8: SQLiteBlockStore

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public SQLiteBlockStore(NetworkParameters params, Context context) throws BlockStoreException {
    this.params = params;
    blocksDataSource = new BlocksDataSource(context);

    blocksDataSource.open();
    if (blocksDataSource.count()==0){
        createNewBlockStore(params);
    } else{
        try {
            DBBlock block = blocksDataSource.getLast();
            Block b = new Block(params, block.getHeader());
            StoredBlock s = build(b);
            this.chainHead = s.getHeader().getHash();
        } catch (Exception e) {
            throw new BlockStoreException("Invalid BlockStore chainHead");
        }
    }
    blocksDataSource.close();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:20,代码来源:SQLiteBlockStore.java

示例9: isValidImprintingTransaction

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
/**
 * Return true if the transaction in input is a valid imprinting transaction and contains the specified address in
 * one of its output, otherwise false.
 * @param tx the transaction to check if is valid imprinting
 * @param networkParameters the {@link NetworkParameters}
 * @param imprintingAddress the address to check for
 * @return true if it's an imprinting transaction otherwise false
 */
public static boolean isValidImprintingTransaction(Transaction tx, NetworkParameters networkParameters, Address imprintingAddress) {
	// Retrieve sender
	String sender = tx.getInput(0).getFromAddress().toBase58();

	// Check output
	List<TransactionOutput> transactionOutputs = tx.getOutputs();
	for (TransactionOutput to : transactionOutputs) {
		Address address = to.getAddressFromP2PKHScript(networkParameters);
		if (address != null && address.equals(imprintingAddress)) {
			return true;
		}
	}

	return false;
}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:24,代码来源:UniquidNodeStateUtils.java

示例10: toString

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public String toString(boolean includePrivateKeys, @Nullable KeyParameter aesKey, NetworkParameters params) {
    final DeterministicKey watchingKey = getWatchingKey();
    final StringBuilder builder = new StringBuilder();
    if (seed != null) {
        if (includePrivateKeys) {
            DeterministicSeed decryptedSeed = seed.isEncrypted()
                    ? seed.decrypt(getKeyCrypter(), DEFAULT_PASSPHRASE_FOR_MNEMONIC, aesKey) : seed;
            final List<String> words = decryptedSeed.getMnemonicCode();
            builder.append("Seed as words: ").append(Utils.SPACE_JOINER.join(words)).append('\n');
            builder.append("Seed as hex:   ").append(decryptedSeed.toHexString()).append('\n');
        } else {
            if (seed.isEncrypted())
                builder.append("Seed is encrypted\n");
        }
        builder.append("Seed birthday: ").append(seed.getCreationTimeSeconds()).append("  [")
                .append(Utils.dateTimeFormat(seed.getCreationTimeSeconds() * 1000)).append("]\n");
    } else {
        builder.append("Key birthday:  ").append(watchingKey.getCreationTimeSeconds()).append("  [")
                .append(Utils.dateTimeFormat(watchingKey.getCreationTimeSeconds() * 1000)).append("]\n");
    }
    builder.append("Key to watch:  ").append(watchingKey.serializePubB58(params)).append('\n');
    formatAddresses(includePrivateKeys, aesKey, params, builder);
    return builder.toString();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:DeterministicKeyChain.java

示例11: LevelDBFullPrunedBlockStore

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
public LevelDBFullPrunedBlockStore(NetworkParameters params, String filename, int blockCount, long leveldbReadCache,
        int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock) {
    this.params = params;
    fullStoreDepth = blockCount;
    this.instrument = instrument;
    this.exitBlock = exitBlock;
    methodStartTime = new HashMap<>();
    methodCalls = new HashMap<>();
    methodTotalTime = new HashMap<>();

    this.filename = filename;
    this.leveldbReadCache = leveldbReadCache;
    this.leveldbWriteCache = leveldbWriteCache;
    this.openOutCache = openOutCache;
    bloom = new BloomFilter();
    totalStopwatch = Stopwatch.createStarted();
    openDB();
    bloom.reloadCache(db);

    // Reset after bloom filter loaded
    totalStopwatch = Stopwatch.createStarted();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:23,代码来源:LevelDBFullPrunedBlockStore.java

示例12: testBuild

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
@Test
public void testBuild() throws Exception {
	
	UniquidWatchingNodeImpl.WatchingNodeBuilder builder = new UniquidWatchingNodeImpl.WatchingNodeBuilder();
	
	NetworkParameters parameters = UniquidRegTest.get();
	File providerFile = File.createTempFile("provider", ".wallet");
	File userFile = File.createTempFile("user", ".wallet");
	File chainFile = File.createTempFile("chain", ".chain");
	File userChainFile = File.createTempFile("userchain", ".chain");
	RegisterFactory dummyRegister = new DummyRegisterFactory(null, null, new DummyTransactionManager());
	String machineName = "machineName";

	builder.setNetworkParameters(parameters);
	builder.setProviderFile(providerFile);
	builder.setUserFile(userFile);
	builder.setProviderChainFile(chainFile);
	builder.setUserChainFile(userChainFile);
	builder.setRegisterFactory(dummyRegister);
	builder.setNodeName(machineName);
	
	UniquidWatchingNodeImpl uniquidNode = builder.buildFromXpub("tpubDAnD549eCz2j2w21P6sx9NvXJrEoWzVevpbvXDpwQzKTC9xWsr8emiEdJ64h1qXbYE4SbDJNbZ7imotNPsGD8RvHQvh6xtgMJTczb8WW8X8", 123456789);
	
	Assert.assertNotNull(uniquidNode);
	
}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:27,代码来源:UniquidWatchingNodeImplBuilderTest.java

示例13: analyzeIsStandard

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
private Result analyzeIsStandard() {
    // The IsStandard rules don't apply on testnet, because they're just a safety mechanism and we don't want to
    // crush innovation with valueless test coins.
    if (wallet != null && !wallet.getNetworkParameters().getId().equals(NetworkParameters.ID_MAINNET))
        return Result.OK;

    RuleViolation ruleViolation = isStandard(tx);
    if (ruleViolation != RuleViolation.NONE) {
        nonStandard = tx;
        return Result.NON_STANDARD;
    }

    for (Transaction dep : dependencies) {
        ruleViolation = isStandard(dep);
        if (ruleViolation != RuleViolation.NONE) {
            nonStandard = dep;
            return Result.NON_STANDARD;
        }
    }

    return Result.OK;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:23,代码来源:DefaultRiskAnalysis.java

示例14: Account

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
/**
 * Constructor for account.
 *
 * @param NetworkParameters params
 * @param DeterministicKey mwey deterministic key for this account
 * @param int child id within the wallet for this account
 *
 */
public Account(NetworkParameters params, DeterministicKey wKey, int child) {

    this.params = params;
    aID = child;

    // L0PRV & STDVx: private derivation.
    int childnum = child;
    childnum |= ChildNumber.HARDENED_BIT;
    aKey = HDKeyDerivation.deriveChildKey(wKey, childnum);

    strXPUB = aKey.serializePubB58(params);

    chains = new ArrayList<Chain>();
    chains.add(new Chain(params, aKey, true));
    chains.add(new Chain(params, aKey, false));

    strPath = aKey.getPathAsString();

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

示例15: forServices

import org.bitcoinj.core.NetworkParameters; //导入依赖的package包/类
/**
 * Builds a suitable set of peer discoveries. Will query them in parallel before producing a merged response.
 * If specific services are required, DNS is not used as the protocol can't handle it.
 * @param params Network to use.
 * @param services Required services as a bitmask, e.g. {@link VersionMessage#NODE_NETWORK}.
 */
public static MultiplexingDiscovery forServices(NetworkParameters params, long services) {
    List<PeerDiscovery> discoveries = Lists.newArrayList();
    HttpDiscovery.Details[] httpSeeds = params.getHttpSeeds();
    if (httpSeeds != null) {
        OkHttpClient httpClient = new OkHttpClient();
        for (HttpDiscovery.Details httpSeed : httpSeeds)
            discoveries.add(new HttpDiscovery(params, httpSeed, httpClient));
    }
    // Also use DNS seeds if there is no specific service requirement
    if (services == 0) {
        String[] dnsSeeds = params.getDnsSeeds();
        if (dnsSeeds != null)
            for (String dnsSeed : dnsSeeds)
                discoveries.add(new DnsSeedDiscovery(params, dnsSeed));
    }
    return new MultiplexingDiscovery(params, discoveries);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:MultiplexingDiscovery.java


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