Java Code Examples for org.fisco.bcos.web3j.protocol.Web3j

The following examples show how to use org.fisco.bcos.web3j.protocol.Web3j. These examples are extracted from open source projects. 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 Project: WeBASE-Front   Source File: TransService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * send tx with sign for precomnpiled contract
 * 
 * @param precompiledType enum of precompiled contract
 * @param funcName precompiled contract function name
 */
public Object transHandleWithSignForPrecompile(int groupId, String signUserId,
        PrecompiledTypes precompiledType, String funcName, List<Object> funcParams)
        throws Exception {
    // check groupId
    Web3j web3j = web3ApiService.getWeb3j(groupId);
    // get address and abi of precompiled contract
    String contractAddress = PrecompiledCommonInfo.getAddress(precompiledType);
    String abiStr = PrecompiledCommonInfo.getAbi(precompiledType);
    List<Object> contractAbi = JsonUtils.toJavaObjectList(abiStr, Object.class);
    // check function param and get function param from abi
    ContractFunction contractFunction =
            buildContractFunctionWithAbi(contractAbi, funcName, funcParams);
    // encode function
    Function function = new Function(funcName, contractFunction.getFinalInputs(),
            contractFunction.getFinalOutputs());
    // trans handle
    return handleTransByFunction(groupId, web3j, signUserId, contractAddress, function,
            contractFunction);
}
 
Example 2
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
@Deprecated
protected static <T extends Contract> T deploy(
        Class<T> type,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String binary,
        String encodedConstructor,
        BigInteger value)
        throws RuntimeException, TransactionException {

    return deploy(
            type,
            web3j,
            credentials,
            new StaticGasProvider(gasPrice, gasLimit),
            binary,
            encodedConstructor,
            value);
}
 
Example 3
Source Project: WeEvent   Source File: Web3SDK2Wrapper.java    License: Apache License 2.0 6 votes vote down vote up
private static Map<String, Map<String, String>> getBlockNums(Web3j web3j) throws IOException {
    JsonNode jsonObj = JsonHelper.getObjectMapper().readTree(web3j.getSyncStatus().sendForReturnString());
    Map<String, Map<String, String>> nodeBlockNums = new HashMap<>();

    Map<String, String> map = new HashMap<>();
    jsonObj.fields().forEachRemaining(entry -> {
        if (BLOCK_NUMBER.equals(entry.getKey()) || NODE_ID.equals(entry.getKey())) {
            map.put(entry.getKey(), entry.getValue().asText());
        }
        if (PEERS.equals(entry.getKey())) {
            convertJsonArrayToList(nodeBlockNums, entry.getValue());
        }
    });
    nodeBlockNums.put(jsonObj.get(NODE_ID).asText(), map);
    return nodeBlockNums;
}
 
Example 4
Source Project: web3sdk   Source File: MockBlockTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void getBlockNumber() throws IOException {

    BcosBlock block = objectMapper.readValue(rawResponse, BcosBlock.class);
    block.setRawResponse(rawResponse);

    Web3j web3j = Web3j.build(web3jService);
    when(web3jService.send(any(Request.class), eq(BcosBlock.class))).thenReturn(block);

    BcosBlock mockBlocks =
            web3j.getBlockByNumber(DefaultBlockParameter.valueOf(new BigInteger("1")), true)
                    .send();
    BcosBlock.Block mockBlock = mockBlocks.getBlock();
    assertEquals(mockBlock.getNonce(), new BigInteger("0"));
    assertTrue(mockBlock.getNumber().intValue() == 1);
}
 
Example 5
public static RemoteCall<TestGroupSig> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider,
        String _sig,
        String _message,
        String _gpk_info,
        String _pbc_param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_gpk_info),
                            new Utf8String(_pbc_param_info)));
    return deployRemoteCall(
            TestGroupSig.class,
            web3j,
            transactionManager,
            contractGasProvider,
            BINARY,
            encodedConstructor);
}
 
Example 6
@Deprecated
public static RemoteCall<TestGroupSig> deploy(
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String _sig,
        String _message,
        String _gpk_info,
        String _pbc_param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_gpk_info),
                            new Utf8String(_pbc_param_info)));
    return deployRemoteCall(
            TestGroupSig.class,
            web3j,
            credentials,
            gasPrice,
            gasLimit,
            BINARY,
            encodedConstructor);
}
 
Example 7
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
@Deprecated
protected Contract(
        String contractBinary,
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    this(
            contractBinary,
            contractAddress,
            web3j,
            getTheTransactionManager(web3j, credentials),
            gasPrice,
            gasLimit);
}
 
Example 8
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends Contract> RemoteCall<T> deployRemoteCall(
        Class<T> type,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider,
        String binary,
        String encodedConstructor,
        BigInteger value) {
    return new RemoteCall<>(
            () ->
                    deploy(
                            type,
                            web3j,
                            credentials,
                            contractGasProvider,
                            binary,
                            encodedConstructor,
                            value));
}
 
Example 9
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
protected TableTest(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
 
Example 10
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected TableTest(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 11
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
protected TableTest(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
 
Example 12
Source Project: web3sdk   Source File: RawTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public RawTransactionManager(Web3j web3j, Credentials credentials, byte chainId) {
    super(web3j, credentials);
    this.web3j = web3j;
    this.credentials = credentials;

    this.chainId = chainId;
}
 
Example 13
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected Ok(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 14
@Deprecated
protected TestRingSig(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
 
Example 15
Source Project: web3sdk   Source File: OkD.java    License: Apache License 2.0 5 votes vote down vote up
protected OkD(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
 
Example 16
@Deprecated
protected TestRingSig(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 17
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
public static Ok load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    return new Ok(contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 18
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
public static TableTest load(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider) {
    return new TableTest(contractAddress, web3j, transactionManager, contractGasProvider);
}
 
Example 19
Source Project: web3sdk   Source File: ContractLifeCyclePrecompiled.java    License: Apache License 2.0 5 votes vote down vote up
protected ContractLifeCyclePrecompiled(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 20
Source Project: web3sdk   Source File: ExtendedRawTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
public ExtendedRawTransactionManager(
        Web3j web3j, Credentials credentials, BigInteger groupId, BigInteger fiscoChainId) {
    super(web3j, credentials);
    this.web3j = web3j;
    this.credentials = credentials;
    this.groupId = groupId;
    this.fiscoChainId = fiscoChainId;
    this.chainId = ChainId.NONE;
}
 
Example 21
Source Project: web3sdk   Source File: CNS.java    License: Apache License 2.0 5 votes vote down vote up
protected CNS(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 22
Source Project: web3sdk   Source File: Permission.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static Permission load(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new Permission(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
 
Example 23
Source Project: web3sdk   Source File: CNS.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static CNS load(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new CNS(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
 
Example 24
Source Project: web3sdk   Source File: OkD.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static OkD load(
        String contractAddress,
        Web3j web3j,
        TransactionManager transactionManager,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new OkD(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
 
Example 25
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static Ok load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new Ok(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 26
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
public static RemoteCall<Ok> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider) {
    return deployRemoteCall(
            Ok.class, web3j, transactionManager, contractGasProvider, BINARY, "");
}
 
Example 27
Source Project: web3sdk   Source File: TableFactory.java    License: Apache License 2.0 5 votes vote down vote up
protected TableFactory(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 28
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
public static Ok load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    return new Ok(contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 29
Source Project: web3sdk   Source File: DagTransfer.java    License: Apache License 2.0 5 votes vote down vote up
protected DagTransfer(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(getBinary(), contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 30
Source Project: web3sdk   Source File: ParallelOk.java    License: Apache License 2.0 5 votes vote down vote up
public static RemoteCall<ParallelOk> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider) {
    return deployRemoteCall(
            ParallelOk.class, web3j, transactionManager, contractGasProvider, getBinary(), "");
}