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


Java ByteUtil.EMPTY_BYTE_ARRAY属性代码示例

本文整理汇总了Java中org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java ByteUtil.EMPTY_BYTE_ARRAY属性的具体用法?Java ByteUtil.EMPTY_BYTE_ARRAY怎么用?Java ByteUtil.EMPTY_BYTE_ARRAY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.ethereum.util.ByteUtil的用法示例。


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

示例1: assign

public void assign(byte[] data) {
    if (data == null) {
        this.data = ByteUtil.EMPTY_BYTE_ARRAY;
    } else if (data.length == 32) {
        this.data = data;
    }
    else if (data.length <= 32) {
        if (this.data==null) {
            newZeroData();
        } else {
            zero();  // first clear
        }
        System.arraycopy(data, 0, this.data, 32 - data.length, data.length);
    }else {
        throw new RuntimeException("Data word can't exceed 32 bytes: " + data);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:DataWord.java

示例2: CallCreate

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 = TestCase.toBigInt(gasLimit).longValueExact();
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:16,代码来源:CallCreate.java

示例3: build

public static Block build(Env env){

        Block block = new Block(
                ByteUtil.EMPTY_BYTE_ARRAY,
                ByteUtil.EMPTY_BYTE_ARRAY,
                env.getCurrentCoinbase(),
                ByteUtil.EMPTY_BYTE_ARRAY,
                env.getCurrentDifficulty(),
                byteArrayToLong(env.getCurrentNumber()),
                env.getCurrentGasLimit(),
                0L,
                byteArrayToLong(env.getCurrentTimestamp()),
                new byte[32],
                ZERO_BYTE_ARRAY,
                ZERO_BYTE_ARRAY,
                ZERO_BYTE_ARRAY,
                ZERO_BYTE_ARRAY,
                ZERO_BYTE_ARRAY,
                EMPTY_TRIE_HASH,
                EMPTY_TRIE_HASH,
                EMPTY_TRIE_HASH,
                null, null, null);

        return block;
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BlockBuilder.java

示例4: CallCreate

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 = Utils.parseData(data);
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.destination = Utils.parseData(destination);
        this.gasLimit = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasLimit));
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:16,代码来源:CallCreate.java

示例5: getGasForData

@Override
public long getGasForData(byte[] data) {
    byte[] safeData = data==null?EMPTY_BYTE_ARRAY:data;

    int baseLen = parseLen(safeData, BASE);
    int expLen = parseLen(safeData, EXPONENT);
    int modLen = parseLen(safeData, MODULUS);

    long multComplexity = getMultComplexity(Math.max(baseLen, modLen));

    byte[] expHighBytes;
    try {
        int offset = Math.addExact(ARGS_OFFSET, baseLen);
        expHighBytes = parseBytes(safeData, offset, Math.min(expLen, 32));
    }
    catch (ArithmeticException e) {
        expHighBytes = ByteUtil.EMPTY_BYTE_ARRAY;
    }

    long adjExpLen = getAdjustedExponentLength(expHighBytes, expLen);

    // use big numbers to stay safe in case of overflow
    BigInteger gas = BigInteger.valueOf(multComplexity)
            .multiply(BigInteger.valueOf(Math.max(adjExpLen, 1)))
            .divide(GQUAD_DIVISOR);


    return gas.min(BigInteger.valueOf(Long.MAX_VALUE)).longValueExact();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:29,代码来源:PrecompiledContracts.java

示例6: execute

@Override
public byte[] execute(byte[] data) {

    if (data == null) {
        return EMPTY_BYTE_ARRAY;
    }

    try {
        int baseLen = parseLen(data, BASE);
        int expLen = parseLen(data, EXPONENT);
        int modLen = parseLen(data, MODULUS);

        int expOffset = Math.addExact(ARGS_OFFSET, baseLen);
        int modOffset = Math.addExact(expOffset, expLen);

        // whenever an offset gets too big we will get BigInteger.ZERO back
        BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
        BigInteger exp = parseArg(data, expOffset, expLen);
        BigInteger mod = parseArg(data, modOffset, modLen);

        if (mod.equals(BigInteger.ZERO)) {
            // Modulo 0 is undefined, return zero
            return ByteUtil.leftPadBytes(ByteUtil.EMPTY_BYTE_ARRAY, modLen);
        }

        byte[] res = stripLeadingZeroes(base.modPow(exp, mod).toByteArray());
        return ByteUtil.leftPadBytes(res, modLen);
    } catch (ArithmeticException e) {
        return ByteUtil.EMPTY_BYTE_ARRAY;
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:31,代码来源:PrecompiledContracts.java

示例7: assignDataRange

public void assignDataRange(byte[] data,int ofs,int len) {
    if (data == null) {
        this.data = ByteUtil.EMPTY_BYTE_ARRAY;
    } else if (len <= 32) {
        //if there is not enough data
        // trailing zeros are assumed (this is required  for PUSH opcode semantic
        Arrays.fill(this.data, (byte) 0); // first clear
        int dlen =Integer.min(len,data.length-ofs);
        System.arraycopy(data, ofs, this.data, 32 - len ,dlen );

    } else {
        throw new RuntimeException("Data word can't exceed 32 bytes: " + data);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:14,代码来源:DataWord.java

示例8: assignData

public void assignData(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 exceed 32 bytes: " + data);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:9,代码来源:DataWord.java

示例9: sha256Test2

@Test
public void sha256Test2() {

    DataWord addr = new DataWord("0000000000000000000000000000000000000000000000000000000000000002");
    PrecompiledContract contract = PrecompiledContracts.getContractForAddress(ConfigHelper.CONFIG, addr);
    byte[] data = ByteUtil.EMPTY_BYTE_ARRAY;
    String expected = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";

    byte[] result = contract.execute(data);

    assertEquals(expected, Hex.toHexString(result));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:12,代码来源:PrecompiledContractTest.java

示例10: AccountState

public AccountState(byte[] address, JSONObject accountState) {

        this.address = address;
        String balance = accountState.get("balance").toString();
        String code = (String) accountState.get("code");
        String nonce = accountState.get("nonce").toString();

        JSONObject store = (JSONObject) accountState.get("storage");

        this.balance = TestCase.toBigInt(balance).toByteArray();

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

        this.nonce = TestCase.toBigInt(nonce).toByteArray();

        int size = store.keySet().size();
        Object[] keys = store.keySet().toArray();
        for (int i = 0; i < size; ++i) {

            String keyS = keys[i].toString();
            String valS = store.get(keys[i]).toString();

            byte[] key = Utils.parseData(keyS);
            byte[] value = Utils.parseData(valS);
            storage.put(new DataWord(key), new DataWord(value));
        }
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:30,代码来源:AccountState.java

示例11: AccountState

public AccountState(byte[] address, JSONObject accountState) {

        this.address = address;
        String balance = accountState.get("balance").toString();
        String code = (String) accountState.get("code");
        String nonce = accountState.get("nonce").toString();

        JSONObject store = (JSONObject) accountState.get("storage");

        this.balance = TestCase.toBigInt(balance).toByteArray();

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

        this.nonce = TestCase.toBigInt(nonce).toByteArray();

        int size = store.keySet().size();
        Object[] keys = store.keySet().toArray();
        for (int i = 0; i < size; ++i) {

            String keyS = keys[i].toString();
            String valS = store.get(keys[i]).toString();

            byte[] key = org.ethereum.json.Utils.parseData(keyS);
            byte[] value = org.ethereum.json.Utils.parseData(valS);
            storage.put(new DataWord(key), new DataWord(value));
        }
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:AccountState.java

示例12: Exec

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(TestCase.toBigInt(gas));
        this.gasPrice = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasPrice));

        this.origin = Hex.decode(origin);
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:33,代码来源:Exec.java

示例13: validate

@Override
public ValidationResult validate(BlockHeader header) {
    final byte[] extraData = header.getExtraData() != null ? header.getExtraData() : ByteUtil.EMPTY_BYTE_ARRAY;
    final boolean extraDataMatches = FastByteComparisons.equal(extraData, data);

    if (required && !extraDataMatches) {
        return fault("Block " + header.getNumber() + " is no-fork. Expected presence of: " +
                Hex.toHexString(data) + ", in extra data: " + Hex.toHexString(extraData));
    } else if (!required && extraDataMatches) {
        return fault("Block " + header.getNumber() + " is pro-fork. Expected no: " +
                Hex.toHexString(data) + ", in extra data: " + Hex.toHexString(extraData));
    }
    return Success;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:14,代码来源:ExtraDataPresenceRule.java

示例14: Exec

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 = Utils.parseData(address);
        this.caller = Utils.parseData(caller);

        if (code != null && code.length() > 2)
            this.code = Utils.parseData(code);
        else
            this.code = ByteUtil.EMPTY_BYTE_ARRAY;

        if (data != null && data.length() > 2)
            this.data = Utils.parseData(data);
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.gas = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gas));
        this.gasPrice = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasPrice));

        this.origin = Utils.parseData(origin);
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:Exec.java

示例15: DataWord

public DataWord(byte[] data) {
    if (data == null)
        this.data = ByteUtil.EMPTY_BYTE_ARRAY;
    else if (data.length == 32)
        this.data = data;
    else if (data.length <= 32)
        System.arraycopy(data, 0, this.data, 32 - data.length, data.length);
    else
        throw new RuntimeException("Data word can't exceed 32 bytes: " + data);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:10,代码来源:DataWord.java


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