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


Java Numeric.cleanHexPrefix方法代码示例

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


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

示例1: isValid

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
/**
 * Check that the contract deployed at the address associated with this smart contract wrapper
 * is in fact the contract you believe it is.
 *
 * <p>This method uses the
 * <a href="https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode">eth_getCode</a> method
 * to get the contract byte code and validates it against the byte code stored in this smart
 * contract wrapper.
 *
 * @return true if the contract is valid
 * @throws IOException if unable to connect to web3j node
 */
public boolean isValid() throws IOException {
    if (contractAddress.equals("")) {
        throw new UnsupportedOperationException(
                "Contract binary not present, you will need to regenerate your smart "
                        + "contract wrapper with web3j v2.2.0+");
    }

    EthGetCode ethGetCode = web3j
            .ethGetCode(contractAddress, DefaultBlockParameterName.LATEST)
            .send();
    if (ethGetCode.hasError()) {
        return false;
    }

    String code = Numeric.cleanHexPrefix(ethGetCode.getCode());
    // There may be multiple contracts in the Solidity bytecode, hence we only check for a
    // match with a subset
    return !code.isEmpty() && contractBinary.contains(code);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:32,代码来源:Contract.java

示例2: getContractCode

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static String getContractCode(Web3j web3j, String contractAddress) throws IOException {
    EthGetCode ethGetCode = web3j
        .ethGetCode(contractAddress, DefaultBlockParameterName.LATEST)
        .send();

    if (ethGetCode.hasError()) {
        throw new IllegalStateException("Failed to get code for " + contractAddress + ": " + ethGetCode.getError().getMessage());
    }

    return Numeric.cleanHexPrefix(ethGetCode.getCode());
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:12,代码来源:CryptoUtil.java

示例3: decode

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
/**
 * Decode ABI encoded return values from smart contract function call.
 *
 * @param rawInput ABI encoded input
 * @param outputParameters list of return types as {@link TypeReference}
 * @return {@link List} of values returned by function, {@link Collections#emptyList()} if
 *         invalid response
 */
public static List<Type> decode(
        String rawInput, List<TypeReference<Type>> outputParameters) {
    String input = Numeric.cleanHexPrefix(rawInput);

    if (input.isEmpty()) {
        return Collections.emptyList();
    } else {
        return build(input, outputParameters);
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:19,代码来源:FunctionReturnDecoder.java

示例4: RawTransaction

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
private RawTransaction(BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, String to,
                       BigInteger value, String data) {
    this.nonce = nonce;
    this.gasPrice = gasPrice;
    this.gasLimit = gasLimit;
    this.to = to;
    this.value = value;

    if (data != null) {
        this.data = Numeric.cleanHexPrefix(data);
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:RawTransaction.java

示例5: getAddress

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static String getAddress(String publicKey) {
    String publicKeyNoPrefix = Numeric.cleanHexPrefix(publicKey);

    if (publicKeyNoPrefix.length() < PUBLIC_KEY_LENGTH_IN_HEX) {
        publicKeyNoPrefix = Strings.zeros(
                PUBLIC_KEY_LENGTH_IN_HEX - publicKeyNoPrefix.length())
                + publicKeyNoPrefix;
    }
    String hash = Hash.sha3(publicKeyNoPrefix);
    return hash.substring(hash.length() - ADDRESS_LENGTH_IN_HEX);  // right most 160 bits
}
 
开发者ID:web3j,项目名称:web3j,代码行数:12,代码来源:Keys.java

示例6: isValidAddress

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static boolean isValidAddress(String input) {
    String cleanInput = Numeric.cleanHexPrefix(input);

    try {
        Numeric.toBigIntNoPrefix(cleanInput);
    } catch (NumberFormatException e) {
        return false;
    }

    return cleanInput.length() == ADDRESS_LENGTH_IN_HEX;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:12,代码来源:WalletUtils.java

示例7: decodeIndexedValue

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
/**
 * <p>Decodes an indexed parameter associated with an event. Indexed parameters are individually
 * encoded, unlike non-indexed parameters which are encoded as per ABI-encoded function
 * parameters and return values.</p>
 *
 * <p>If any of the following types are indexed, the Keccak-256 hashes of the values are
 * returned instead. These are returned as a bytes32 value.</p>
 *
 * <ul>
 *     <li>Arrays</li>
 *     <li>Strings</li>
 *     <li>Bytes</li>
 * </ul>
 *
 * <p>See the
 * <a href="http://solidity.readthedocs.io/en/latest/contracts.html#events">
 * Solidity documentation</a> for further information.</p>
 *
 * @param rawInput ABI encoded input
 * @param typeReference of expected result type
 * @param <T> type of TypeReference
 * @return the decode value
 */
@SuppressWarnings("unchecked")
public static <T extends Type> Type decodeIndexedValue(
        String rawInput, TypeReference<T> typeReference) {
    String input = Numeric.cleanHexPrefix(rawInput);

    try {
        Class<T> type = typeReference.getClassType();

        if (Bytes.class.isAssignableFrom(type)) {
            return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName()));
        } else if (Array.class.isAssignableFrom(type)
                || BytesType.class.isAssignableFrom(type)
                || Utf8String.class.isAssignableFrom(type)) {
            return TypeDecoder.decodeBytes(input, Bytes32.class);
        } else {
            return TypeDecoder.decode(input, type);
        }
    } catch (ClassNotFoundException e) {
        throw new UnsupportedOperationException("Invalid class reference provided", e);
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:45,代码来源:FunctionReturnDecoder.java

示例8: isValidPrivateKey

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static boolean isValidPrivateKey(String privateKey) {
    String cleanPrivateKey = Numeric.cleanHexPrefix(privateKey);
    return cleanPrivateKey.length() == PRIVATE_KEY_LENGTH_IN_HEX;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:5,代码来源:WalletUtils.java


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