本文整理汇总了Java中org.ethereum.core.genesis.GenesisLoader类的典型用法代码示例。如果您正苦于以下问题:Java GenesisLoader类的具体用法?Java GenesisLoader怎么用?Java GenesisLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenesisLoader类属于org.ethereum.core.genesis包,在下文中一共展示了GenesisLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendStatus
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
/*************************
* Message Sending *
*************************/
@Override
public void sendStatus() {
byte protocolVersion = version.getCode();
int networkId = config.networkId();
BlockChainStatus blockChainStatus = this.blockchain.getStatus();
Block bestBlock = blockChainStatus.getBestBlock();
BigInteger totalDifficulty = blockChainStatus.getTotalDifficulty();
// Original status
Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), true);
org.ethereum.net.eth.message.StatusMessage msg = new org.ethereum.net.eth.message.StatusMessage(protocolVersion, networkId,
ByteUtil.bigIntegerToBytes(totalDifficulty), bestBlock.getHash(), genesis.getHash());
sendMessage(msg);
// RSK new protocol send status
Status status = new Status(bestBlock.getNumber(), bestBlock.getHash(), bestBlock.getParentHash(), totalDifficulty);
RskMessage rskmessage = new RskMessage(config, new StatusMessage(status));
loggerNet.trace("Sending status best block {} to {}", status.getBestBlockNumber(), this.messageSender.getPeerNodeID().toString());
sendMessage(rskmessage);
ethState = EthState.STATUS_SENT;
}
示例2: importBlocks
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
@Test
@Ignore
public void importBlocks() throws Exception {
Logger logger = LoggerFactory.getLogger("VM");
logger.info("#######################################");
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/frontier.json")));
Scanner scanner = new Scanner(new FileInputStream("D:\\ws\\ethereumj\\work\\blocks-rec.dmp"));
while (scanner.hasNext()) {
String blockHex = scanner.next();
Block block = new Block(Hex.decode(blockHex));
ImportResult result = blockchain.tryToConnect(block);
if (result != ImportResult.EXIST && result != ImportResult.IMPORTED_BEST) {
throw new RuntimeException(result + ": " + block + "");
}
System.out.println("Imported " + block.getShortDescr());
}
}
示例3: invalidBlockTotalDiff
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
@Test
public void invalidBlockTotalDiff() throws Exception {
// Check that importing invalid block doesn't affect totalDifficulty
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
blockchain.setMinerCoinbase(Hex.decode("ee0250c19ad59305b2bdb61f34b45b72fe37154f"));
Block parent = blockchain.getBestBlock();
System.out.println("Mining #1 ...");
BigInteger totalDifficulty = blockchain.getTotalDifficulty();
Block b1 = blockchain.createNewBlock(parent, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
b1.setStateRoot(new byte[32]);
Ethash.getForBlock(SystemProperties.getDefault(), b1.getNumber()).mineLight(b1).get();
ImportResult importResult = blockchain.tryToConnect(b1);
Assert.assertTrue(importResult == ImportResult.INVALID_BLOCK);
Assert.assertEquals(totalDifficulty, blockchain.getTotalDifficulty());
}
示例4: processStatus
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
/*************************
* Message Processing *
*************************/
protected void processStatus(org.ethereum.net.eth.message.StatusMessage msg, ChannelHandlerContext ctx) throws InterruptedException {
try {
Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), true);
if (!Arrays.equals(msg.getGenesisHash(), genesis.getHash())
|| msg.getProtocolVersion() != version.getCode()) {
loggerNet.info("Removing EthHandler for {} due to protocol incompatibility", ctx.channel().remoteAddress());
ethState = EthState.STATUS_FAILED;
recordEvent(EventType.INCOMPATIBLE_PROTOCOL);
disconnect(ReasonCode.INCOMPATIBLE_PROTOCOL);
ctx.pipeline().remove(this); // Peer is not compatible for the 'eth' sub-protocol
return;
}
if (msg.getNetworkId() != config.networkId()) {
ethState = EthState.STATUS_FAILED;
recordEvent(EventType.INVALID_NETWORK);
disconnect(ReasonCode.NULL_IDENTITY);
return;
}
// basic checks passed, update statistics
channel.getNodeStatistics().ethHandshake(msg);
ethereumListener.onEthStatusUpdated(channel, msg);
if (peerDiscoveryMode) {
loggerNet.debug("Peer discovery mode: STATUS received, disconnecting...");
disconnect(ReasonCode.REQUESTED);
ctx.close().sync();
ctx.disconnect().sync();
return;
}
} catch (NoSuchElementException e) {
loggerNet.debug("EthHandler already removed");
}
}
示例5: replaceCodeTest2
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
@Test
public void replaceCodeTest2() throws IOException, InterruptedException {
// We test code replacement during initialization: this is forbitten.
BigInteger nonce = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getInitialNonce();
BlockChainImpl blockchain = org.ethereum.core.ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(ConfigHelper.CONFIG, nonce,
getClass().getResourceAsStream("/genesis/genesis-light.json"), false));
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
System.out.println("address: " + Hex.toHexString(sender.getAddress()));
String asm =
"HEADER !0x01 !0x01 !0x00 "+ // (4b) header script v1
"0x01 0x00 CODEREPLACE "+ // (5b) we attempt to replace the code
"0x01 0x15 0x00 CODECOPY " + // (7b) Extract real code into address 0, skip first 12 bytes, copy 1 bytes
"0x01 0x00 RETURN " + // (5b) offset 0, size 0x01, now return the first code
"STOP "; // (1b) REAL code to install
EVMAssembler assembler = new EVMAssembler();
byte[] code = assembler.assemble(asm);
// Creates a contract
Transaction tx1 = createTx(blockchain, sender, new byte[0], code);
TransactionExecutor executor1 = executeTransaction(blockchain, tx1);
// Now we can directly check the store and see the new code.
Assert.assertTrue(executor1.getResult().getException() != null);
}
示例6: getGenesisBlock
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
public static Block getGenesisBlock(BlockChainImpl blockChain) {
Repository repository = blockChain.getRepository();
Genesis genesis = GenesisLoader.loadGenesis(ConfigHelper.CONFIG, "rsk-unittests.json", BigInteger.ZERO, true);
for (ByteArrayWrapper key : genesis.getPremine().keySet()) {
repository.createAccount(key.getData());
repository.addBalance(key.getData(), genesis.getPremine().get(key).getAccountState().getBalance());
}
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
return genesis;
}
示例7: withAccountBalance
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
public StandaloneBlockchain withAccountBalance(byte[] address, BigInteger weis) {
AccountState state = new AccountState(BigInteger.ZERO, weis);
genesis.addPremine(wrap(address), state);
genesis.setStateRoot(GenesisLoader.generateRootHash(genesis.getPremine()));
return this;
}
示例8: testGenesisFromRLP
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
@Test
public void testGenesisFromRLP() {
// from RLP encoding
byte[] genesisBytes = Hex.decode(GENESIS_RLP);
Block genesisFromRLP = new Block(genesisBytes);
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json"));
assertEquals(Hex.toHexString(genesis.getHash()), Hex.toHexString(genesisFromRLP.getHash()));
assertEquals(Hex.toHexString(genesis.getParentHash()), Hex.toHexString(genesisFromRLP.getParentHash()));
assertEquals(Hex.toHexString(genesis.getStateRoot()), Hex.toHexString(genesisFromRLP.getStateRoot()));
}
示例9: loadGenesisFromFile
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
private Block loadGenesisFromFile(String resPath) {
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream(resPath));
logger.info(genesis.toString());
logger.info("genesis hash: [{}]", Hex.toHexString(genesis.getHash()));
logger.info("genesis rlp: [{}]", Hex.toHexString(genesis.getEncoded()));
return genesis;
}
示例10: getInstance
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
public static Block getInstance(RskSystemProperties config) {
return GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), false);
}
示例11: replaceCodeTest1
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
@Test
public void replaceCodeTest1() throws IOException, InterruptedException {
BigInteger nonce = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getInitialNonce();
BlockChainImpl blockchain = org.ethereum.core.ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(ConfigHelper.CONFIG, nonce,
getClass().getResourceAsStream("/genesis/genesis-light.json"), false));
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
System.out.println("address: " + Hex.toHexString(sender.getAddress()));
String asm ="0x14 0x0C 0x00 CODECOPY " + // (7b) Extract real code into address 0, skip first 12 bytes, copy 20 bytes
"0x14 0x00 RETURN " + // (5b) offset 0, size 0x14, now return the first code
"HEADER !0x01 !0x01 !0x00 "+ // (4b) header script v1
"0x00 CALLDATALOAD " + // (3b) store at offset 0, read data from offset 0. Transfer 32 bytes
"0x00 MSTORE " + // (3b) store the data at address 0
// We replace TWO TIMES to make sure that only the last replacement takes place
"0x01 0x00 CODEREPLACE " + // (5b) set new code: offset 0, size 1 bytes.
// This is the good one.
"0x10 0x00 CODEREPLACE"; // (5b) set new code: offset 0, size 16 bytes.
EVMAssembler assembler = new EVMAssembler();
byte[] code = assembler.assemble(asm);
// Creates a contract
Transaction tx1 = createTx(blockchain, sender, new byte[0], code);
executeTransaction(blockchain, tx1);
// Now we can directly check the store and see the new code.
byte[] createdContract = tx1.getContractAddress().getBytes();
byte[] expectedCode = Arrays.copyOfRange(code, 12, 12+20);
byte[] installedCode = blockchain.getRepository().getContractDetails(createdContract).getCode();
// assert the contract has been created
Assert.assertTrue(Arrays.equals(expectedCode, installedCode));
// Note that this code does not have a header, then its version == 0
String asm2 =
"0xFF 0x00 MSTORE "+ // (5b) Store at address 0x00, the value 0xFF
"0x01 0x1F RETURN " + // (5b) And return such value 0xFF, at offset 0x1F
// fill with nops to make it 16 bytes in length
"STOP STOP STOP STOP STOP STOP"; // 16
byte[] code2 = assembler.assemble(asm2);
// The second transaction changes the contract code
Transaction tx2 = createTx(blockchain, sender, tx1.getContractAddress().getBytes(), code2);
TransactionExecutor executor2 = executeTransaction(blockchain, tx2);
byte[] installedCode2 = blockchain.getRepository().getContractDetails(createdContract).getCode();
// assert the contract code has been created
Assert.assertTrue(Arrays.equals(installedCode2, code2));
Assert.assertEquals(1, executor2.getResult().getCodeChanges().size()); // there is one code change
// We could add a third tx to execute the new code
Transaction tx3 = createTx(blockchain, sender, tx1.getContractAddress().getBytes(), new byte[0]);
TransactionExecutor executor3 = executeTransaction(blockchain, tx3);
// check return code from contract call
Assert.assertArrayEquals(Hex.decode("FF"), executor3.getResult().getHReturn());
}
示例12: dontLogWhenReverting
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
@Test
public void dontLogWhenReverting() throws IOException, InterruptedException {
/*
Original contracts
pragma solidity ^0.4.0;
contract TestEventInvoked {
event internalEvent();
function doIt() {
internalEvent();
throw;
}
}
contract TestEventInvoker {
event externalEvent();
function doIt(address invokedAddress) {
externalEvent();
invokedAddress.call.gas(50000)(0xb29f0835);
}
}
*/
BigInteger nonce = ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getInitialNonce();
Blockchain blockchain = ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(ConfigHelper.CONFIG, nonce,
getClass().getResourceAsStream("/genesis/genesis-light.json"), false));
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
System.out.println("address: " + Hex.toHexString(sender.getAddress()));
// First contract code TestEventInvoked
String code1 = "6060604052341561000f57600080fd5b5b60ae8061001e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063b29f083514603d575b600080fd5b3415604757600080fd5b604d604f565b005b7f95481a538d62f8458d3cecac82408d5ff2630d8335962b1cdbac16f1a9b910e760405160405180910390a1600080fd5b5600a165627a7a723058207d93861daff7f4a0479d7f3eb0ca7ef5cef7e2bbf2c4637ab4f021ecc5afa7ad0029";
// Second contract code TestEventInvoker
String code2 = "6060604052341561000f57600080fd5b5b6101358061001f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e25fd8a71461003e575b600080fd5b341561004957600080fd5b610075600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610077565b005b7f4cd6f2e769273405c20f3a0c098c9045749deec145502c4838b54206ec5c542860405160405180910390a18073ffffffffffffffffffffffffffffffffffffffff1661c35063b29f0835906040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160006040518083038160008887f19350505050505b505600a165627a7a7230582019096fd773ebc5581ba378acd64cb1acb450b4eb4866d710f3e3f4e33d635a4b0029";
// Second contract ABI
String abi2 = "[{\"constant\":false,\"inputs\":[{\"name\":\"invokedAddress\",\"type\":\"address\"}],\"name\":\"doIt\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"externalEvent\",\"type\":\"event\"}]";
Transaction tx1 = createTx(blockchain, sender, new byte[0], Hex.decode(code1));
executeTransaction(blockchain, tx1);
Transaction tx2 = createTx(blockchain, sender, new byte[0], Hex.decode(code2));
executeTransaction(blockchain, tx2);
CallTransaction.Contract contract2 = new CallTransaction.Contract(abi2);
byte[] data = contract2.getByName("doIt").encode(Hex.toHexString(tx1.getContractAddress().getBytes()));
Transaction tx3 = createTx(blockchain, sender, tx2.getContractAddress().getBytes(), data);
TransactionExecutor executor = executeTransaction(blockchain, tx3);
Assert.assertEquals(1, executor.getResult().getLogInfoList().size());
Assert.assertEquals(false, executor.getResult().getLogInfoList().get(0).isRejected());
Assert.assertEquals(1, executor.getVMLogs().size());
}
示例13: getGenesisJson
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
private GenesisJson getGenesisJson() {
if (genesisJson == null) {
genesisJson = GenesisLoader.loadGenesisJson(this, classLoader);
}
return genesisJson;
}
示例14: getGenesis
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
public Genesis getGenesis() {
if (genesis == null) {
genesis = GenesisLoader.parseGenesis(getBlockchainConfig(), getGenesisJson());
}
return genesis;
}
示例15: useGenesis
import org.ethereum.core.genesis.GenesisLoader; //导入依赖的package包/类
/**
* Method used in StandaloneBlockchain.
*/
public Genesis useGenesis(InputStream inputStream) {
genesisJson = GenesisLoader.loadGenesisJson(inputStream);
genesis = GenesisLoader.parseGenesis(getBlockchainConfig(), getGenesisJson());
return genesis;
}