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


Java BlockchainNetConfig类代码示例

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


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

示例1: isFreeBridgeTx

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
public static boolean isFreeBridgeTx(SystemProperties config, Transaction rskTx, long blockNumber) {
    BlockchainNetConfig blockchainConfig = config.getBlockchainConfig();
    RskAddress receiveAddress = rskTx.getReceiveAddress();
    if (receiveAddress.equals(RskAddress.nullAddress())) {
        return false;
    }

    BridgeConstants bridgeConstants = blockchainConfig.getCommonConstants().getBridgeConstants();

    // Temporary assumption: if areBridgeTxsFree() is true then the current federation
    // must be the genesis federation.
    // Once the original federation changes, txs are always paid.
    return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) &&
           blockchainConfig.getConfigForBlock(blockNumber).areBridgeTxsFree() &&
           rskTx.acceptTransactionSignature(config.getBlockchainConfig().getCommonConstants().getChainId()) &&
           (
                   isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) ||
                   isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) ||
                   isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) ||
                   isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants)
           );
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:BridgeUtils.java

示例2: getGasForDataFreeTx

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void getGasForDataFreeTx() {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new UnitTestBlockchainNetConfig());

    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);

    org.ethereum.core.Transaction rskTx = CallTransaction.createCallTransaction(
            ConfigHelper.CONFIG, 0,
            1,
            1,
            PrecompiledContracts.BRIDGE_ADDR,
            0,
            Bridge.UPDATE_COLLECTIONS);
    rskTx.sign(((BridgeRegTestConstants)bridgeConstants).getFederatorPrivateKeys().get(0).getPrivKeyBytes());

    Block rskExecutionBlock = BlockGenerator.getInstance().createChildBlock(Genesis.getInstance(ConfigHelper.CONFIG));
    bridge.init(rskTx, rskExecutionBlock, null, null, null, null);
    Assert.assertEquals(0, bridge.getGasForData(rskTx.getData()));

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:BridgeTest.java

示例3: isFreeBridgeTx

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
private void isFreeBridgeTx(boolean expected, RskAddress destinationAddress, BlockchainNetConfig config, byte[] privKeyBytes) {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(config);

    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);

    org.ethereum.core.Transaction rskTx = CallTransaction.createCallTransaction(
            ConfigHelper.CONFIG, 0,
            1,
            1,
            destinationAddress,
            0,
            Bridge.UPDATE_COLLECTIONS);
    rskTx.sign(privKeyBytes);

    Block rskExecutionBlock = BlockGenerator.getInstance().createChildBlock(Genesis.getInstance(ConfigHelper.CONFIG));
    bridge.init(rskTx, rskExecutionBlock, null, null, null, null);
    Assert.assertEquals(expected, BridgeUtils.isFreeBridgeTx(ConfigHelper.CONFIG, rskTx, rskExecutionBlock.getNumber()));

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:BridgeUtilsTest.java

示例4: testInitialChainHeadWithoutBtcCheckpoints

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void testInitialChainHeadWithoutBtcCheckpoints() throws Exception {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new RegTestConfig());
    NetworkParameters _networkParameters = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants().getBtcParams();

    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG);
    Repository track = repository.startTracking();

    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, track, mock(BridgeEventLogger.class), provider, null);
    Assert.assertEquals(0, bridgeSupport.getBtcBlockStore().getChainHead().getHeight());
    Assert.assertEquals(_networkParameters.getGenesisBlock(), bridgeSupport.getBtcBlockStore().getChainHead().getHeader());

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:BridgeSupportTest.java

示例5: parseGenesis

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
public static Genesis parseGenesis(BlockchainNetConfig blockchainNetConfig, GenesisJson genesisJson) throws RuntimeException {
    try {
        Genesis genesis = createBlockForJson(genesisJson);

        genesis.setPremine(generatePreMine(blockchainNetConfig, genesisJson.getAlloc()));

        byte[] rootHash = generateRootHash(genesis.getPremine());
        genesis.setStateRoot(rootHash);

        return genesis;
    } catch (Exception e) {
        e.printStackTrace();
        Utils.showErrorAndExit("Problem parsing genesis", e.getMessage());
    }
    return null;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:GenesisLoader.java

示例6: brigdeTxTest

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void brigdeTxTest() {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new RegTestConfig());

    List<Transaction> txs = new LinkedList<>();
    //Bridge Tx
    txs.add(createBridgeTx(1, 0, 1, 0, 0, 6, hashes));

    Map<String, TxTimestamp> times;
    Map<RskAddress, TxsPerAccount> txmap;
    Repository repository = Mockito.mock(Repository.class);
    final long blockGasLimit = 100000;
    WorldManager worldManager = Mockito.mock(WorldManager.class);
    Blockchain blockchain = Mockito.mock(Blockchain.class);
    Block block = Mockito.mock(Block.class);
    Mockito.when(worldManager.getBlockchain()).thenReturn(blockchain);
    Mockito.when(blockchain.getBestBlock()).thenReturn(block);
    Mockito.when(block.getGasLimit()).thenReturn(BigInteger.valueOf(blockGasLimit).toByteArray());
    Mockito.when(block.getMinimumGasPrice()).thenReturn(BigInteger.valueOf(1).toByteArray());
    createAccountState(txs.get(0), repository, 0, 0);
    times = new HashMap<>();
    txmap = new HashMap<>();

    TxValidator txValidator = new TxValidator(ConfigHelper.CONFIG, repository, worldManager.getBlockchain());
    List<Transaction> result = txValidator.filterTxs(txs, times, txmap);
    Assert.assertTrue(result.size() == 1);

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:31,代码来源:TxValidatorTest.java

示例7: getGasForDataPaidTx

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
private void getGasForDataPaidTx(int expected, CallTransaction.Function function, Object... funcArgs) {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new UnitTestBlockchainNetConfig());

    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    org.ethereum.core.Transaction rskTx;
    if (function==null) {
        rskTx = CallTransaction.createRawTransaction(
                ConfigHelper.CONFIG, 0,
                1,
                1,
                PrecompiledContracts.BRIDGE_ADDR,
                0,
                new byte[]{1,2,3});
    } else {
        rskTx = CallTransaction.createCallTransaction(
                ConfigHelper.CONFIG, 0,
                1,
                1,
                PrecompiledContracts.BRIDGE_ADDR,
                0,
                function,
                funcArgs);
    }

    rskTx.sign(((BridgeRegTestConstants)bridgeConstants).getFederatorPrivateKeys().get(0).getPrivKeyBytes());

    Block rskExecutionBlock = BlockGenerator.getInstance().createChildBlock(Genesis.getInstance(ConfigHelper.CONFIG));
    for (int i = 0; i < 20; i++) {
        rskExecutionBlock = BlockGenerator.getInstance().createChildBlock(rskExecutionBlock);
    }
    bridge.init(rskTx, rskExecutionBlock, null, null, null, null);
    Assert.assertEquals(expected, bridge.getGasForData(rskTx.getData()));

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:37,代码来源:BridgeTest.java

示例8: testInitialChainHeadWithBtcCheckpoints

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void testInitialChainHeadWithBtcCheckpoints() throws Exception {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new TestNetConfig());

    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG);
    Repository track = repository.startTracking();

    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, track, mock(BridgeEventLogger.class), provider, null);
    Assert.assertEquals(1229760, bridgeSupport.getBtcBlockStore().getChainHead().getHeight());

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:BridgeSupportTest.java

示例9: testGetBtcBlockchainBlockLocatorWithoutBtcCheckpoints

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void testGetBtcBlockchainBlockLocatorWithoutBtcCheckpoints() throws Exception {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new RegTestConfig());
    NetworkParameters _networkParameters = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants().getBtcParams();

    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG);
    Repository track = repository.startTracking();

    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, track, mock(BridgeEventLogger.class), provider, null);
    Assert.assertEquals(0, bridgeSupport.getBtcBlockStore().getChainHead().getHeight());
    Assert.assertEquals(_networkParameters.getGenesisBlock(), bridgeSupport.getBtcBlockStore().getChainHead().getHeader());

    List<Sha256Hash> locator = bridgeSupport.getBtcBlockchainBlockLocator();
    Assert.assertEquals(1, locator.size());
    Assert.assertEquals(_networkParameters.getGenesisBlock().getHash(), locator.get(0));

    List<BtcBlock> blocks = createBtcBlocks(_networkParameters, _networkParameters.getGenesisBlock(), 10);
    bridgeSupport.receiveHeaders(blocks.toArray(new BtcBlock[]{}));
    locator = bridgeSupport.getBtcBlockchainBlockLocator();
    Assert.assertEquals(6, locator.size());
    Assert.assertEquals(blocks.get(9).getHash(), locator.get(0));
    Assert.assertEquals(blocks.get(8).getHash(), locator.get(1));
    Assert.assertEquals(blocks.get(7).getHash(), locator.get(2));
    Assert.assertEquals(blocks.get(5).getHash(), locator.get(3));
    Assert.assertEquals(blocks.get(1).getHash(), locator.get(4));
    Assert.assertEquals(_networkParameters.getGenesisBlock().getHash(), locator.get(5));

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:32,代码来源:BridgeSupportTest.java

示例10: testGetBtcBlockchainBlockLocatorWithBtcCheckpoints

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void testGetBtcBlockchainBlockLocatorWithBtcCheckpoints() throws Exception {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new RegTestConfig());
    NetworkParameters _networkParameters = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants().getBtcParams();

    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG);
    Repository track = repository.startTracking();

    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    List<BtcBlock> checkpoints = createBtcBlocks(_networkParameters, _networkParameters.getGenesisBlock(), 10);
    BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, track, mock(BridgeEventLogger.class), provider, null) {
        @Override
        InputStream getCheckPoints() {
            return getCheckpoints(_networkParameters, checkpoints);
        }
    };
    Assert.assertEquals(10, bridgeSupport.getBtcBlockStore().getChainHead().getHeight());
    Assert.assertEquals(checkpoints.get(9), bridgeSupport.getBtcBlockStore().getChainHead().getHeader());

    List<Sha256Hash> locator = bridgeSupport.getBtcBlockchainBlockLocator();
    Assert.assertEquals(1, locator.size());
    Assert.assertEquals(checkpoints.get(9).getHash(), locator.get(0));

    List<BtcBlock> blocks = createBtcBlocks(_networkParameters, checkpoints.get(9), 10);
    bridgeSupport.receiveHeaders(blocks.toArray(new BtcBlock[]{}));
    locator = bridgeSupport.getBtcBlockchainBlockLocator();
    Assert.assertEquals(6, locator.size());
    Assert.assertEquals(blocks.get(9).getHash(), locator.get(0));
    Assert.assertEquals(blocks.get(8).getHash(), locator.get(1));
    Assert.assertEquals(blocks.get(7).getHash(), locator.get(2));
    Assert.assertEquals(blocks.get(5).getHash(), locator.get(3));
    Assert.assertEquals(blocks.get(1).getHash(), locator.get(4));
    Assert.assertEquals(checkpoints.get(9).getHash(), locator.get(5));

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:38,代码来源:BridgeSupportTest.java

示例11: registerBtcTransactionOfTransactionInMerkleTreeWithNotEnoughtHeight

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
@Test
public void registerBtcTransactionOfTransactionInMerkleTreeWithNotEnoughtHeight() throws BlockStoreException, AddressFormatException, IOException {
    BlockchainNetConfig blockchainNetConfigOriginal = ConfigHelper.CONFIG.getBlockchainConfig();
    ConfigHelper.CONFIG.setBlockchainConfig(new RegTestConfig());
    NetworkParameters _networkParameters = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants().getBtcParams();

    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG);
    Repository track = repository.startTracking();

    BtcTransaction tx = createTransaction();
    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants());

    BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, track, mock(BridgeEventLogger.class), provider, null);

    byte[] bits = new byte[1];
    bits[0] = 0x01;
    List<Sha256Hash> hashes = new ArrayList<>();
    hashes.add(tx.getHash());

    PartialMerkleTree pmt = new PartialMerkleTree(_networkParameters, bits, hashes, 1);

    bridgeSupport.registerBtcTransaction(mock(Transaction.class), tx, 1, pmt);
    bridgeSupport.save();

    track.commit();

    BridgeStorageProvider provider2 = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getBridgeConstants());

    Assert.assertTrue(provider2.getNewFederationBtcUTXOs().isEmpty());
    Assert.assertEquals(0, provider2.getReleaseRequestQueue().getEntries().size());
    Assert.assertEquals(0, provider2.getReleaseTransactionSet().getEntries().size());
    Assert.assertTrue(provider2.getRskTxsWaitingForSignatures().isEmpty());
    Assert.assertTrue(provider2.getBtcTxHashesAlreadyProcessed().isEmpty());

    ConfigHelper.CONFIG.setBlockchainConfig(blockchainNetConfigOriginal);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:37,代码来源:BridgeSupportTest.java

示例12: generatePreMine

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
private static Map<ByteArrayWrapper, PremineAccount> generatePreMine(BlockchainNetConfig blockchainNetConfig, Map<String, GenesisJson.AllocatedAccount> allocs){

        final Map<ByteArrayWrapper, PremineAccount> premine = new HashMap<>();

        for (String key : allocs.keySet()){

            final byte[] address = hexStringToBytes(key);
            final GenesisJson.AllocatedAccount alloc = allocs.get(key);
            final PremineAccount state = new PremineAccount();
            AccountState accountState = new AccountState(
                    blockchainNetConfig.getCommonConstants().getInitialNonce(), parseHexOrDec(alloc.balance));

            if (alloc.nonce != null) {
                accountState = accountState.withNonce(parseHexOrDec(alloc.nonce));
            }

            if (alloc.code != null) {
                final byte[] codeBytes = hexStringToBytes(alloc.code);
                accountState = accountState.withCodeHash(HashUtil.sha3(codeBytes));
                state.code = codeBytes;
            }

            state.accountState = accountState;
            premine.put(wrap(address), state);
        }

        return premine;
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:29,代码来源:GenesisLoader.java

示例13: getConfig

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
public BlockchainNetConfig getConfig() {
    switch (this) {

        case Frontier:  return new FrontierConfig();
        case Homestead: return new HomesteadConfig();
        case EIP150:    return new Eip150HFConfig(new DaoHFConfig());
        case EIP158:    return new Eip160HFConfig(new DaoHFConfig());
        case Byzantium:    return new ByzantiumConfig(new DaoHFConfig());

        case FrontierToHomesteadAt5: return new BaseNetConfig() {{
            add(0, new FrontierConfig());
            add(5, new HomesteadConfig());
        }};

        case HomesteadToDaoAt5: return new BaseNetConfig() {{
            add(0, new HomesteadConfig());
            add(5, new DaoHFConfig(new HomesteadConfig(), 5));
        }};

        case HomesteadToEIP150At5: return new BaseNetConfig() {{
            add(0, new HomesteadConfig());
            add(5, new Eip150HFConfig(new HomesteadConfig()));
        }};

        case EIP158ToByzantiumAt5: return new BaseNetConfig() {{
            add(0, new Eip160HFConfig(new HomesteadConfig()));
            add(5, new ByzantiumConfig(new HomesteadConfig()));
        }};

        default: throw new IllegalArgumentException("Unknown network value: " + this.name());
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:GitHubJSONTestSuite.java

示例14: withNetConfig

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
public StandaloneBlockchain withNetConfig(BlockchainNetConfig netConfig) {
    this.netConfig = netConfig;
    return this;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:5,代码来源:StandaloneBlockchain.java

示例15: calcDifficulty

import org.ethereum.config.BlockchainNetConfig; //导入依赖的package包/类
public BigInteger calcDifficulty(BlockchainNetConfig config, BlockHeader parent) {
    return config.getConfigForBlock(getNumber()).
            calcDifficulty(this, parent);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:5,代码来源:BlockHeader.java


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