Java Code Examples for org.ethereum.core.Block#getHash()

The following examples show how to use org.ethereum.core.Block#getHash() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBlockstore.java    From nuls-v2 with MIT License 5 votes vote down vote up
@Override
public byte[] getBlockHashByNumber(long blockNumber, byte[] branchBlockHash) {
    Block branchBlock = getBlockByHash(branchBlockHash);
    if (branchBlock.getNumber() < blockNumber) {
        throw new IllegalArgumentException("Requested block number > branch hash number: " + blockNumber + " < " + branchBlock.getNumber());
    }
    while (branchBlock.getNumber() > blockNumber) {
        branchBlock = getBlockByHash(branchBlock.getParentHash());
    }
    return branchBlock.getHash();
}
 
Example 2
Source File: AbstractBlockstore.java    From nuls with MIT License 5 votes vote down vote up
@Override
public byte[] getBlockHashByNumber(long blockNumber, byte[] branchBlockHash) {
    Block branchBlock = getBlockByHash(branchBlockHash);
    if (branchBlock.getNumber() < blockNumber) {
        throw new IllegalArgumentException("Requested block number > branch hash number: " + blockNumber + " < " + branchBlock.getNumber());
    }
    while (branchBlock.getNumber() > blockNumber) {
        branchBlock = getBlockByHash(branchBlock.getParentHash());
    }
    return branchBlock.getHash();
}
 
Example 3
Source File: ChainItem.java    From nuls-v2 with MIT License 4 votes vote down vote up
ChainItem(Block block) {
    this.number = block.getNumber();
    this.hash = block.getHash();
    this.parentHash = block.getParentHash();
}
 
Example 4
Source File: IndexedBlockStore.java    From nuls-v2 with MIT License 4 votes vote down vote up
@Override
public synchronized byte[] getBlockHashByNumber(long blockNumber) {
    Block chainBlock = getChainBlockByNumber(blockNumber);
    return chainBlock == null ? null : chainBlock.getHash(); // FIXME: can be improved by accessing the hash directly in the index
}
 
Example 5
Source File: ChainItem.java    From nuls with MIT License 4 votes vote down vote up
ChainItem(Block block) {
    this.number = block.getNumber();
    this.hash = block.getHash();
    this.parentHash = block.getParentHash();
}
 
Example 6
Source File: IndexedBlockStore.java    From nuls with MIT License 4 votes vote down vote up
@Override
public synchronized byte[] getBlockHashByNumber(long blockNumber) {
    Block chainBlock = getChainBlockByNumber(blockNumber);
    return chainBlock == null ? null : chainBlock.getHash(); // FIXME: can be improved by accessing the hash directly in the index
}
 
Example 7
Source File: ProgramInvokeFactory.java    From ethereumj with MIT License 4 votes vote down vote up
public static ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository) {

        // https://ethereum.etherpad.mozilla.org/26
        Block lastBlock = WorldManager.getInstance().getBlockchain().getLastBlock();

        /***         ADDRESS op       ***/
        // YP: Get address of currently executing account.
        byte[] address  =  tx.isContractCreation() ? tx.getContractAddress(): tx.getReceiveAddress();

        /***         ORIGIN op       ***/
        // YP: This is the sender of original transaction; it is never a contract.
        byte[] origin  = tx.getSender();

        /***         CALLER op       ***/
        // YP: This is the address of the account that is directly responsible for this execution.
        byte[] caller = tx.getSender();

        /***         BALANCE op       ***/
        byte[] balance = repository.getBalance(address).toByteArray();

        /***         GASPRICE op       ***/
        byte[] gasPrice = tx.getGasPrice();

        /*** GAS op ***/
        byte[] gas = tx.getGasLimit();

        /***        CALLVALUE op      ***/
        byte[] callValue = tx.getValue() == null ? new byte[]{0} : tx.getValue();

        /***     CALLDATALOAD  op   ***/
        /***     CALLDATACOPY  op   ***/
        /***     CALLDATASIZE  op   ***/
        byte[] data = tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData();

        /***    PREVHASH  op  ***/
        byte[] lastHash = lastBlock.getHash();

        /***   COINBASE  op ***/
        byte[] coinbase = block.getCoinbase();

        /*** TIMESTAMP  op  ***/
        long timestamp = block.getTimestamp();

        /*** NUMBER  op  ***/
        long number = block.getNumber();

        /*** DIFFICULTY  op  ***/
        byte[] difficulty = block.getDifficulty();

        /*** GASLIMIT op ***/
        long gaslimit = block.getGasLimit();

        if (logger.isInfoEnabled()) {
            logger.info("Top level call: \n" +
                    "address={}\n" +
                    "origin={}\n"  +
                    "caller={}\n"  +
                    "balance={}\n" +
                    "gasPrice={}\n" +
                    "gas={}\n" +
                    "callValue={}\n" +
                    "data={}\n" +
                    "lastHash={}\n" +
                    "coinbase={}\n" +
                    "timestamp={}\n" +
                    "blockNumber={}\n" +
                    "difficulty={}\n" +
                    "gaslimit={}\n",

                    Hex.toHexString(address),
                    Hex.toHexString(origin),
                    Hex.toHexString(caller),
                    new BigInteger(balance).longValue(),
                    new BigInteger(gasPrice).longValue(),
                    new BigInteger(gas).longValue(),
                    new BigInteger(callValue).longValue(),
                    Hex.toHexString(data),
                    Hex.toHexString(lastHash),
                    Hex.toHexString(coinbase),
                    timestamp,
                    number,
                    Hex.toHexString(difficulty),
                    gaslimit);
        }

        ProgramInvoke programInvoke =
            new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data,
                    lastHash,  coinbase,  timestamp,  number,  difficulty,  gaslimit,
                    repository);

        return programInvoke;
    }