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


Java Numeric.hexStringToByteArray方法代码示例

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


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

示例1: createTokenTransferData

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static byte[] createTokenTransferData(String to, BigInteger tokenAmount) {
    List<Type> params = Arrays.asList(new Address(to), new Uint256(tokenAmount));

    List<TypeReference<?>> returnTypes = Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {
    });

    Function function = new Function("transfer", params, returnTypes);
    String encodedFunction = FunctionEncoder.encode(function);
    return Numeric.hexStringToByteArray(Numeric.cleanHexPrefix(encodedFunction));
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:11,代码来源:TokenRepository.java

示例2: decodeNumeric

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
static <T extends NumericType> T decodeNumeric(String input, Class<T> type) {
    try {
        byte[] inputByteArray = Numeric.hexStringToByteArray(input);
        int typeLengthAsBytes = getTypeLengthInBytes(type);

        byte[] resultByteArray = new byte[typeLengthAsBytes + 1];

        if (Int.class.isAssignableFrom(type) || Fixed.class.isAssignableFrom(type)) {
            resultByteArray[0] = inputByteArray[0];  // take MSB as sign bit
        }

        int valueOffset = Type.MAX_BYTE_LENGTH - typeLengthAsBytes;
        System.arraycopy(inputByteArray, valueOffset, resultByteArray, 1, typeLengthAsBytes);

        BigInteger numericValue = new BigInteger(resultByteArray);
        return type.getConstructor(BigInteger.class).newInstance(numericValue);

    } catch (NoSuchMethodException | SecurityException
            | InstantiationException | IllegalAccessException
            | IllegalArgumentException | InvocationTargetException e) {
        throw new UnsupportedOperationException(
                "Unable to create instance of " + type.getName(), e);
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:25,代码来源:TypeDecoder.java

示例3: decodeBytes

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
static <T extends Bytes> T decodeBytes(String input, int offset, Class<T> type) {
    try {
        String simpleName = type.getSimpleName();
        String[] splitName = simpleName.split(Bytes.class.getSimpleName());
        int length = Integer.parseInt(splitName[1]);
        int hexStringLength = length << 1;

        byte[] bytes = Numeric.hexStringToByteArray(
                input.substring(offset, offset + hexStringLength));
        return type.getConstructor(byte[].class).newInstance(bytes);
    } catch (NoSuchMethodException | SecurityException
            | InstantiationException | IllegalAccessException
            | IllegalArgumentException | InvocationTargetException e) {
        throw new UnsupportedOperationException(
                "Unable to create instance of " + type.getName(), e);
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:18,代码来源:TypeDecoder.java

示例4: decodeDynamicBytes

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
static DynamicBytes decodeDynamicBytes(String input, int offset) {
    int encodedLength = decodeUintAsInt(input, offset);
    int hexStringEncodedLength = encodedLength << 1;

    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;

    String data = input.substring(valueOffset,
            valueOffset + hexStringEncodedLength);
    byte[] bytes = Numeric.hexStringToByteArray(data);

    return new DynamicBytes(bytes);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:TypeDecoder.java

示例5: testDecodeIndexedBytes32Value

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
@Test
public void testDecodeIndexedBytes32Value() {
    String rawInput = "0x1234567890123456789012345678901234567890123456789012345678901234";
    byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput);

    assertThat(FunctionReturnDecoder.decodeIndexedValue(
            rawInput,
            new TypeReference<Bytes32>(){}),
            equalTo(new Bytes32(rawInputBytes)));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:11,代码来源:FunctionReturnDecoderTest.java

示例6: testDecodeIndexedBytes16Value

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
@Test
public void testDecodeIndexedBytes16Value() {
    String rawInput = "0x1234567890123456789012345678901200000000000000000000000000000000";
    byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput.substring(0, 34));

    assertThat(FunctionReturnDecoder.decodeIndexedValue(
            rawInput,
            new TypeReference<Bytes16>(){}),
            equalTo(new Bytes16(rawInputBytes)));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:11,代码来源:FunctionReturnDecoderTest.java

示例7: asRlpValues

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
static List<RlpType> asRlpValues(
        RawTransaction rawTransaction, Sign.SignatureData signatureData) {
    List<RlpType> result = new ArrayList<>();

    result.add(RlpString.create(rawTransaction.getNonce()));
    result.add(RlpString.create(rawTransaction.getGasPrice()));
    result.add(RlpString.create(rawTransaction.getGasLimit()));

    // an empty to address (contract creation) should not be encoded as a numeric 0 value
    String to = rawTransaction.getTo();
    if (to != null && to.length() > 0) {
        // addresses that start with zeros should be encoded with the zeros included, not
        // as numeric values
        result.add(RlpString.create(Numeric.hexStringToByteArray(to)));
    } else {
        result.add(RlpString.create(""));
    }

    result.add(RlpString.create(rawTransaction.getValue()));

    // value field will already be hex encoded, so we need to convert into binary first
    byte[] data = Numeric.hexStringToByteArray(rawTransaction.getData());
    result.add(RlpString.create(data));

    if (signatureData != null) {
        result.add(RlpString.create(signatureData.getV()));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getR())));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getS())));
    }

    return result;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:33,代码来源:TransactionEncoder.java

示例8: testSignMessage

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
@Test
public void testSignMessage() {
    Sign.SignatureData signatureData = Sign.signMessage(TEST_MESSAGE, SampleKeys.KEY_PAIR);

    Sign.SignatureData expected = new Sign.SignatureData(
            (byte) 27,
            Numeric.hexStringToByteArray(
                    "0x9631f6d21dec448a213585a4a41a28ef3d4337548aa34734478b563036163786"),
            Numeric.hexStringToByteArray(
                    "0x2ff816ee6bbb82719e983ecd8a33a4b45d32a4b58377ef1381163d75eedc900b")
    );

    assertThat(signatureData, is(expected));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:15,代码来源:SignTest.java

示例9: parse

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
@Override
public byte[] parse(String value) {
    return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Numeric.hexStringToByteArray(value);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:5,代码来源:ByteArrayCodec.java

示例10: hexToByte

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static byte[] hexToByte(String hex) {
    if (Utils.isEmpty(hex)) {
        return null;
    }
    return Numeric.hexStringToByteArray(hex);
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:7,代码来源:Utils.java

示例11: sha3

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
/**
 * Keccak-256 hash function.
 *
 * @param hexInput hex encoded input data with optional 0x prefix
 * @return hash value as hex encoded string
 */
public static String sha3(String hexInput) {
    byte[] bytes = Numeric.hexStringToByteArray(hexInput);
    byte[] result = sha3(bytes);
    return Numeric.toHexString(result);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:12,代码来源:Hash.java


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