Java Code Examples for org.ethereum.util.ByteUtil#bigIntegerToBytes()

The following examples show how to use org.ethereum.util.ByteUtil#bigIntegerToBytes() . 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: EthereumImpl.java    From ethereumj with MIT License 6 votes vote down vote up
@Override
public Transaction createTransaction(BigInteger nonce,
                                     BigInteger gasPrice,
                                     BigInteger gas,
                                     byte[] recieveAddress,
                                     BigInteger value, byte[] data ){

    byte[] nonceBytes    =  ByteUtil.bigIntegerToBytes(nonce);
    byte[] gasPriceBytes =  ByteUtil.bigIntegerToBytes(gasPrice);
    byte[] gasBytes      =  ByteUtil.bigIntegerToBytes(gas);
    byte[] valueBytes    =  ByteUtil.bigIntegerToBytes(value);

    Transaction tx = new Transaction(nonceBytes, gasPriceBytes, gasBytes,
            recieveAddress, valueBytes, data);

    return tx;
}
 
Example 3
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 4
Source File: EthHandler.java    From ethereumj with MIT License 5 votes vote down vote up
private void sendStatus(){
    Blockchain blockChain= WorldManager.getInstance().getBlockchain();
    byte protocolVersion = EthHandler.VERSION, networkId = EthHandler.NETWORK_ID;
    BigInteger totalDifficulty = blockChain.getTotalDifficulty();
    byte[] bestHash = blockChain.getLatestBlockHash();
    StatusMessage msg = new StatusMessage(protocolVersion, networkId,
            ByteUtil.bigIntegerToBytes(totalDifficulty), bestHash, Blockchain.GENESIS_HASH);
    msgQueue.sendMessage(msg);
}