Java Code Examples for org.ethereum.util.ByteUtil#EMPTY_BYTE_ARRAY

The following examples show how to use org.ethereum.util.ByteUtil#EMPTY_BYTE_ARRAY . 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: CallCreate.java    From ethereumj with MIT License 6 votes vote down vote up
public CallCreate(JSONObject callCreateJSON) {

        String data        = callCreateJSON.get("data").toString();
        String destination = callCreateJSON.get("destination").toString();
        String gasLimit    = callCreateJSON.get("gasLimit").toString();
        String value       = callCreateJSON.get("value").toString();

        if (data != null && data.length() > 2)
            this.data    = Hex.decode(data.substring(2));
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.destination = Hex.decode(destination);
        this.gasLimit    = ByteUtil.bigIntegerToBytes(new BigInteger(gasLimit));
        this.value       = ByteUtil.bigIntegerToBytes(new BigInteger(value));
    }
 
Example 2
Source File: Transaction.java    From wkcwallet-java with Apache License 2.0 5 votes vote down vote up
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data) {
    this.parsed = false;
    this.nonce = nonce;
    this.gasPrice = gasPrice;
    this.gasLimit = gasLimit;
    this.receiveAddress = receiveAddress;
    this.value = value;
    this.data = data;
    if(receiveAddress == null) {
        this.receiveAddress = ByteUtil.EMPTY_BYTE_ARRAY;
    }

    this.parsed = true;
}
 
Example 3
Source File: Program.java    From ethereumj with MIT License 5 votes vote down vote up
public Program(byte[] ops, ProgramInvoke invokeData) {
	
    if (ops == null) ops = ByteUtil.EMPTY_BYTE_ARRAY;
    this.ops = ops;
    
    if (invokeData != null) {
        this.invokeData = invokeData;
        this.programAddress = invokeData.getOwnerAddress();
    	this.invokeHash = invokeData.hashCode();
        this.result.setRepository(invokeData.getRepository());
    }
}
 
Example 4
Source File: DataWord.java    From ethereumj with MIT License 5 votes vote down vote up
public DataWord(byte[] data) {
	if (data == null)
		this.data = ByteUtil.EMPTY_BYTE_ARRAY;
	else if (data.length <= 32)
		System.arraycopy(data, 0, this.data, 32 - data.length, data.length);
	else
		throw new RuntimeException("Data word can't exit 32 bytes: " + data);        	
}
 
Example 5
Source File: Exec.java    From ethereumj with MIT License 5 votes vote down vote up
public Exec(JSONObject exec) {

        String address  = exec.get("address").toString();
        String caller   = exec.get("caller").toString();

        String code  = exec.get("code").toString();
        String data  = exec.get("data").toString();

        String gas      = exec.get("gas").toString();
        String gasPrice = exec.get("gasPrice").toString();
        String origin   = exec.get("origin").toString();

        String value    = exec.get("value").toString();

        this.address = Hex.decode(address);
        this.caller  = Hex.decode(caller);

        if (code != null && code.length() > 2)
            this.code    = Hex.decode(code.substring(2));
        else
            this.code = ByteUtil.EMPTY_BYTE_ARRAY;

        if (data != null && data.length() > 2)
            this.data    = Hex.decode(data.substring(2));
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.gas      = ByteUtil.bigIntegerToBytes(new BigInteger(gas));
        this.gasPrice = ByteUtil.bigIntegerToBytes(new BigInteger(gasPrice));

        this.origin  = Hex.decode(origin);
        this.value   = ByteUtil.bigIntegerToBytes(new BigInteger(value));
    }
 
Example 6
Source File: TrieImpl.java    From ethereumj with MIT License 5 votes vote down vote up
@Override
public byte[] getRootHash() {
    if (root == null
            || (root instanceof byte[] && ((byte[]) root).length == 0)
            || (root instanceof String && "".equals((String) root))) {
        return ByteUtil.EMPTY_BYTE_ARRAY;
    } else if (root instanceof byte[]) {
        return (byte[]) this.getRoot();
    } else {
        Value rootValue = new Value(this.getRoot());
        byte[] val = rootValue.encode();
        return HashUtil.sha3(val);
    }
}
 
Example 7
Source File: Transaction.java    From ethereumj with MIT License 5 votes vote down vote up
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data) {
    this.nonce = nonce;
    this.gasPrice = gasPrice;
    this.gasLimit = gasLimit;
    this.receiveAddress = receiveAddress;
    this.value = value;
    this.data = data;

    if(receiveAddress == null) {
        this.receiveAddress = ByteUtil.EMPTY_BYTE_ARRAY;
    }
    parsed = true;
}
 
Example 8
Source File: RepositoryImpl.java    From nuls-v2 with MIT License 4 votes vote down vote up
@Override
public synchronized byte[] getCode(byte[] addr) {
    byte[] codeHash = getCodeHash(addr);
    return codeHash == null || FastByteComparisons.equal(codeHash, HashUtil.EMPTY_DATA_HASH) ?
            ByteUtil.EMPTY_BYTE_ARRAY : codeCache.get(codeKey(codeHash, addr));
}
 
Example 9
Source File: RepositoryImpl.java    From nuls with MIT License 4 votes vote down vote up
@Override
public synchronized byte[] getCode(byte[] addr) {
    byte[] codeHash = getCodeHash(addr);
    return codeHash == null || FastByteComparisons.equal(codeHash, HashUtil.EMPTY_DATA_HASH) ?
            ByteUtil.EMPTY_BYTE_ARRAY : codeCache.get(codeKey(codeHash, addr));
}
 
Example 10
Source File: Program.java    From ethereumj with MIT License 4 votes vote down vote up
public byte[] getDataCopy(DataWord offset, DataWord length) {
    if (invokeData == null) return ByteUtil.EMPTY_BYTE_ARRAY;
    return invokeData.getDataCopy(offset, length);
}
 
Example 11
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;
    }
 
Example 12
Source File: Transaction.java    From ethereumj with MIT License 4 votes vote down vote up
public boolean isContractCreation() {
    if (!parsed) rlpParse();
    return this.receiveAddress == null || this.receiveAddress == ByteUtil.EMPTY_BYTE_ARRAY;
}
 
Example 13
Source File: ProgramMemoryTest.java    From ethereumj with MIT License 4 votes vote down vote up
@Before
public void createProgram() {
	program = new Program(ByteUtil.EMPTY_BYTE_ARRAY, pi);
}