Java Code Examples for org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt

The following examples show how to use org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt. 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: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
private static <T extends Contract> T create(
        T contract, String binary, String encodedConstructor, BigInteger value)
        throws IOException, TransactionException {

    TransactionReceipt transactionReceipt =
            contract.executeTransaction(binary + encodedConstructor, value, FUNC_DEPLOY);

    String contractAddress = transactionReceipt.getContractAddress();
    if (contractAddress == null) {
        throw new RuntimeException("Empty contract address returned");
    }
    contract.setContractAddress(contractAddress);
    contract.setTransactionReceipt(transactionReceipt);

    return contract;
}
 
Example 2
Source Project: WeBASE-Front   Source File: TransController.java    License: Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "send signed transaction ")
@ApiImplicitParam(name = "reqSignedTransHandle", value = "transaction info", required = true, dataType = "ReqSignedTransHandle")
@PostMapping("/signed-transaction")
public TransactionReceipt sendSignedTransaction(@Valid @RequestBody ReqSignedTransHandle reqSignedTransHandle, BindingResult result) throws Exception {
    log.info("transHandleLocal start. ReqSignedTransHandle:[{}]", JsonUtils.toJSONString(reqSignedTransHandle));

    Instant startTime = Instant.now();
    log.info("transHandleLocal start startTime:{}", startTime.toEpochMilli());

    checkParamResult(result);
    String signedStr = reqSignedTransHandle.getSignedStr();
    if (StringUtils.isBlank(signedStr)) {
        throw new FrontException(ENCODE_STR_CANNOT_BE_NULL);
    }
    TransactionReceipt receipt =  transServiceImpl.sendSignedTransaction(signedStr, reqSignedTransHandle.getSync(),reqSignedTransHandle.getGroupId());
    log.info("transHandleLocal end  useTime:{}", Duration.between(startTime, Instant.now()).toMillis());
    return receipt;
}
 
Example 3
Source Project: WeBASE-Front   Source File: TransService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * execTransaction through common contract
 *
 * @param function function
 * @param commonContract contract
 */
public static TransactionReceipt execTransaction(Function function,
        CommonContract commonContract) throws FrontException {
    TransactionReceipt transactionReceipt = null;
    Instant startTime = Instant.now();
    log.info("execTransaction start startTime:{}", startTime.toEpochMilli());
    try {
        transactionReceipt = commonContract.execTransaction(function);
    } catch (IOException | TransactionException | ContractCallException e) {
        log.error("execTransaction failed.", e);
        throw new FrontException(ConstantCode.TRANSACTION_SEND_FAILED.getCode(),
                e.getMessage());
    }
    log.info("execTransaction end  useTime:{}",
            Duration.between(startTime, Instant.now()).toMillis());
    return transactionReceipt;
}
 
Example 4
Source Project: evidenceSample   Source File: Evidence.java    License: Apache License 2.0 6 votes vote down vote up
public List<ErrorAddSignaturesEventEventResponse> getErrorAddSignaturesEventEvents(TransactionReceipt transactionReceipt) {
    List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(ERRORADDSIGNATURESEVENT_EVENT, transactionReceipt);
    ArrayList<ErrorAddSignaturesEventEventResponse> responses = new ArrayList<ErrorAddSignaturesEventEventResponse>(valueList.size());
    for (Contract.EventValuesWithLog eventValues : valueList) {
        ErrorAddSignaturesEventEventResponse typedResponse = new ErrorAddSignaturesEventEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse.evi = (String) eventValues.getNonIndexedValues().get(0).getValue();
        typedResponse.info = (String) eventValues.getNonIndexedValues().get(1).getValue();
        typedResponse.id = (String) eventValues.getNonIndexedValues().get(2).getValue();
        typedResponse.v = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
        typedResponse.r = (byte[]) eventValues.getNonIndexedValues().get(4).getValue();
        typedResponse.s = (byte[]) eventValues.getNonIndexedValues().get(5).getValue();
        typedResponse.addr = (String) eventValues.getNonIndexedValues().get(6).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 5
Source Project: web3sdk   Source File: NewSolTest.java    License: Apache License 2.0 6 votes vote down vote up
public List<OwnershipTransferredEventResponse> getOwnershipTransferredEvents(
        TransactionReceipt transactionReceipt) {
    List<EventValuesWithLog> valueList =
            extractEventParametersWithLog(OWNERSHIPTRANSFERRED_EVENT, transactionReceipt);
    ArrayList<OwnershipTransferredEventResponse> responses =
            new ArrayList<OwnershipTransferredEventResponse>(valueList.size());
    for (EventValuesWithLog eventValues : valueList) {
        OwnershipTransferredEventResponse typedResponse =
                new OwnershipTransferredEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 6
Source Project: WeEvent   Source File: FiscoBcos2.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get a TransactionReceipt request from a transaction Hash.
 *
 * @param transactionHash the transactionHash value
 * @return the transactionReceipt wrapper
 */
private Optional<TransactionReceipt> getTransactionReceiptRequest(String transactionHash) {
    Optional<TransactionReceipt> receiptOptional = Optional.empty();

    try {
        for (int i = 0; i < WeEventConstants.POLL_TRANSACTION_ATTEMPTS; i++) {
            receiptOptional = web3j.getTransactionReceipt(transactionHash).send().getTransactionReceipt();
            if (!receiptOptional.isPresent()) {
                Thread.sleep(this.fiscoConfig.getConsumerIdleTime());
            } else {
                return receiptOptional;
            }
        }
    } catch (IOException | InterruptedException e) {
        log.error("get transactionReceipt failed.", e);
    }
    return receiptOptional;
}
 
Example 7
Source Project: web3sdk   Source File: EvidenceVerify.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<TransactionReceipt> insertEvidence(
        String evi,
        String info,
        String id,
        String signAddr,
        byte[] message,
        BigInteger v,
        byte[] r,
        byte[] s) {
    final Function function =
            new Function(
                    FUNC_INSERTEVIDENCE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(evi),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(info),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(id),
                            new org.fisco.bcos.web3j.abi.datatypes.Address(signAddr),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(message),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint8(v),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(r),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(s)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 8
public Tuple4<String, String, String, String> getUpdate_group_sig_dataInput(
        TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function =
            new Function(
                    FUNC_UPDATE_GROUP_SIG_DATA,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple4<String, String, String, String>(
            (String) results.get(0).getValue(),
            (String) results.get(1).getValue(),
            (String) results.get(2).getValue(),
            (String) results.get(3).getValue());
}
 
Example 9
Source Project: WeBASE-Transaction   Source File: ContractAbiUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * receiptParse.
 * 
 * @param receipt info
 * @param abiList info
 * @return
 */
public static Object receiptParse(TransactionReceipt receipt, List<AbiDefinition> abiList)
        throws BaseException {
    Map<String, Object> resultMap = new HashMap<>();
    List<Log> logList = receipt.getLogs();
    for (AbiDefinition abiDefinition : abiList) {
        String eventName = abiDefinition.getName();
        List<String> funcInputTypes = getFuncInputType(abiDefinition);
        List<TypeReference<?>> finalOutputs = outputFormat(funcInputTypes);
        Event event = new Event(eventName, finalOutputs);
        Object result = null;
        for (Log logInfo : logList) {
            EventValues eventValues = Contract.staticExtractEventParameters(event, logInfo);
            if (eventValues != null) {
                result = callResultParse(funcInputTypes, eventValues.getNonIndexedValues());
                break;
            }
        }
        if (result != null) {
            resultMap.put(eventName, result);
        }
    }
    return resultMap;
}
 
Example 10
Source Project: evidenceSample   Source File: Evidence.java    License: Apache License 2.0 6 votes vote down vote up
public List<AddSignaturesEventEventResponse> getAddSignaturesEventEvents(TransactionReceipt transactionReceipt) {
    List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(ADDSIGNATURESEVENT_EVENT, transactionReceipt);
    ArrayList<AddSignaturesEventEventResponse> responses = new ArrayList<AddSignaturesEventEventResponse>(valueList.size());
    for (Contract.EventValuesWithLog eventValues : valueList) {
        AddSignaturesEventEventResponse typedResponse = new AddSignaturesEventEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse.evi = (String) eventValues.getNonIndexedValues().get(0).getValue();
        typedResponse.info = (String) eventValues.getNonIndexedValues().get(1).getValue();
        typedResponse.id = (String) eventValues.getNonIndexedValues().get(2).getValue();
        typedResponse.v = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
        typedResponse.r = (byte[]) eventValues.getNonIndexedValues().get(4).getValue();
        typedResponse.s = (byte[]) eventValues.getNonIndexedValues().get(5).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 11
Source Project: WeBASE-Node-Manager   Source File: TransHashController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * get transaction receipt.
 */
@GetMapping("/transactionReceipt/{groupId}/{transHash}")
public BaseResponse getTransReceipt(@PathVariable("groupId") Integer groupId,
    @PathVariable("transHash") String transHash)
    throws NodeMgrException {
    Instant startTime = Instant.now();
    log.info("start getTransReceipt startTime:{} groupId:{} transaction:{}",
        startTime.toEpochMilli(), groupId, transHash);
    BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS);
    TransactionReceipt transReceipt = transHashService.getTransReceipt(groupId, transHash);
    baseResponse.setData(transReceipt);
    log.info("end getTransReceipt useTime:{} result:{}",
        Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse));
    return baseResponse;
}
 
Example 12
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple1<BigInteger> getAddOperatorOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function = new Function(FUNC_ADDOPERATOR, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());;
    return new Tuple1<BigInteger>(

            (BigInteger) results.get(0).getValue()
            );
}
 
Example 13
Source Project: WeBASE-Front   Source File: TransService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * send message to node.
 *
 * @param signMsg signMsg
 * @param future future
 */
public void sendMessage(Web3j web3j, String signMsg,
        final CompletableFuture<TransactionReceipt> future) throws IOException {
    Request<?, SendTransaction> request = web3j.sendRawTransaction(signMsg);
    request.setNeedTransCallback(true);
    request.setTransactionSucCallback(new TransactionSucCallback() {
        @Override
        public void onResponse(TransactionReceipt receipt) {
            log.info("onResponse receipt:{}", receipt);
            future.complete(receipt);
            return;
        }
    });
    request.send();
}
 
Example 14
Source Project: web3sdk   Source File: SolidityFunctionWrapper.java    License: Apache License 2.0 5 votes vote down vote up
private void buildTransactionFunction(
        AbiDefinition functionDefinition, MethodSpec.Builder methodBuilder, String inputParams)
        throws ClassNotFoundException {

    if (functionDefinition.hasOutputs()) {
        // CHECKSTYLE:OFF
        reporter.report(
                String.format(
                        "Definition of the function %s returns a value but is not defined as a view function. "
                                + "Please ensure it contains the view modifier if you want to read the return value",
                        functionDefinition.getName()));
        // CHECKSTYLE:ON
    }

    if (functionDefinition.isPayable()) {
        methodBuilder.addParameter(BigInteger.class, WEI_VALUE);
    }

    String functionName = functionDefinition.getName();

    methodBuilder.returns(buildRemoteCall(TypeName.get(TransactionReceipt.class)));

    methodBuilder.addStatement(
            "final $T function = new $T(\n$N, \n$T.<$T>asList($L), \n$T"
                    + ".<$T<?>>emptyList())",
            Function.class,
            Function.class,
            funcNameToConst(functionName),
            Arrays.class,
            Type.class,
            inputParams,
            Collections.class,
            TypeReference.class);
    if (functionDefinition.isPayable()) {
        methodBuilder.addStatement(
                "return executeRemoteCallTransaction(function, $N)", WEI_VALUE);
    } else {
        methodBuilder.addStatement("return executeRemoteCallTransaction(function)");
    }
}
 
Example 15
Source Project: web3sdk   Source File: TableTestClient.java    License: Apache License 2.0 5 votes vote down vote up
private static void create(TableTest tabletest) throws Exception {
    TransactionReceipt receipt = tabletest.create().send();
    List<CreateResultEventResponse> createResultEvents =
            tabletest.getCreateResultEvents(receipt);
    if (createResultEvents.size() == 0) {
        System.out.println("create t_test table failed.");
        return;
    }
    CreateResultEventResponse createResultEventResponse = createResultEvents.get(0);
    int createCount = createResultEventResponse.count.intValue();
    System.out.println("create table ret:" + createCount);
    switch (createCount) {
        case PrecompiledCommon.PermissionDenied:
            System.out.println("non-authorized to create t_test table.");
            break;
        case PrecompiledCommon.PermissionDenied_RC3:
            System.out.println("non-authorized to create t_test table.");
            break;
        case PrecompiledCommon.TableExist:
            System.out.println("t_test table already exist.");
            break;
        case PrecompiledCommon.Success:
            System.out.println("create t_test table success.");
            break;
        default:
            System.out.println("unknown return value:" + createCount);
            break;
    }
}
 
Example 16
Source Project: web3sdk   Source File: NewSolTest.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> transferAnyERC20Token(
        String tokenAddress, BigInteger tokens) {
    final Function function =
            new Function(
                    FUNC_TRANSFERANYERC20TOKEN,
                    Arrays.<Type>asList(new Address(tokenAddress), new Uint256(tokens)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 17
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> insert(
        String name, BigInteger item_id, String item_name) {
    final Function function =
            new Function(
                    FUNC_INSERT,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(name),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Int256(item_id),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(item_name)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 18
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Given the duration required to execute a transaction.
 *
 * @param data to send in transaction
 * @param weiValue in Wei to send in transaction
 * @return {@link Optional} containing our transaction receipt
 * @throws IOException if the call to the node fails
 * @throws TransactionException if the transaction was not mined while waiting
 */
protected TransactionReceipt executeTransaction(
        String data, BigInteger weiValue, String funcName)
        throws TransactionException, IOException {

    Callback callback = new Callback();

    asyncExecuteTransaction(data, funcName, callback);
    try {
        callback.semaphore.acquire(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }

    TransactionReceipt receipt = callback.receipt;
    if (!receipt.isStatusOK()) {
        String status = receipt.getStatus();
        BigInteger gasUsed = receipt.getGasUsed();

        String message = StatusCode.getStatusMessage(receipt.getStatus(), receipt.getMessage());

        logger.trace(
                " execute transaction not successfully, hash: {}, status: {}, message: {}, gasUsed: {}",
                receipt.getTransactionHash(),
                receipt.getStatus(),
                receipt.getMessage(),
                receipt.getGasUsed());

        throw new TransactionException(message, status, gasUsed, receipt.getTransactionHash());
    }

    return receipt;
}
 
Example 19
Source Project: web3sdk   Source File: TestTxDecode.java    License: Apache License 2.0 5 votes vote down vote up
public static TransactionReceipt sentTx() throws Exception {
    // init the Service
    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    ECKeyPair keyPair = Keys.createEcKeyPair();
    Credentials credentials = Credentials.create(keyPair);
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    service.setGroupId(1);
    Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());

    RemoteCall<TableTest> deploy =
            TableTest.deploy(
                    web3j,
                    credentials,
                    new StaticGasProvider(
                            new BigInteger("30000000"), new BigInteger("30000000")));
    TableTest tableTest = deploy.send();
    tableTest.create().send();

    String name = "fruit";
    int item_id = 1;
    String item_name = "apple";

    RemoteCall<TransactionReceipt> insert =
            tableTest.insert(name, BigInteger.valueOf(item_id), item_name);
    TransactionReceipt txReceipt = insert.send();

    return txReceipt;
}
 
Example 20
Source Project: web3sdk   Source File: Permission.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple1<BigInteger> getInsertOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function =
            new Function(
                    FUNC_INSERT,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) results.get(0).getValue());
}
 
Example 21
Source Project: WeEvent   Source File: FiscoBcos2.java    License: Apache License 2.0 5 votes vote down vote up
public CompletableFuture<SendResult> sendRawTransaction(String topicName, String transactionHex) {
    return web3j.sendRawTransaction(transactionHex).sendAsync().thenApplyAsync(ethSendTransaction -> {
        SendResult sendResult = new SendResult();
        sendResult.setTopic(topicName);

        Optional<TransactionReceipt> receiptOptional = getTransactionReceiptRequest(ethSendTransaction.getTransactionHash());
        if (receiptOptional.isPresent()) {
            List<TypeReference<?>> referencesList = Collections.singletonList(new TypeReference<Uint256>() {
            });
            List<Type> returnList = FunctionReturnDecoder.decode(
                    String.valueOf(receiptOptional.get().getOutput()),
                    Utils.convert(referencesList));

            int sequence = ((BigInteger) returnList.get(0).getValue()).intValue();
            if (sequence == 0) {
                log.error("this FISCO-BCOS account has no permission to publish event");
                sendResult.setStatus(SendResult.SendResultStatus.NO_PERMISSION);
            } else {
                sendResult.setStatus(SendResult.SendResultStatus.SUCCESS);
                sendResult.setEventId(DataTypeUtils.encodeEventId(topicName,
                        receiptOptional.get().getBlockNumber().intValue(),
                        sequence));
            }
        } else {
            sendResult.setStatus(SendResult.SendResultStatus.ERROR);
        }

        return sendResult;
    });
}
 
Example 22
Source Project: WeBASE-Front   Source File: PrecompiledWithSignService.java    License: Apache License 2.0 5 votes vote down vote up
public String contractUnfreeze(int groupId, String signUserId, String contractAddress)
        throws Exception {
    // trans
    List<Object> funcParams = new ArrayList<>();
    funcParams.add(contractAddress);
    TransactionReceipt receipt =
            (TransactionReceipt) transService.transHandleWithSignForPrecompile(groupId,
                    signUserId, PrecompiledTypes.CSM, FUNC_UNFREEZE, funcParams);
    return PrecompiledCommon.handleTransactionReceipt(receipt,
            web3ApiService.getWeb3j(groupId));
}
 
Example 23
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> trans(BigInteger num) {
    final Function function =
            new Function(
                    FUNC_TRANS,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(num)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 24
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
public List<InsertResultEventResponse> getInsertResultEvents(
        TransactionReceipt transactionReceipt) {
    List<Contract.EventValuesWithLog> valueList =
            extractEventParametersWithLog(INSERTRESULT_EVENT, transactionReceipt);
    ArrayList<InsertResultEventResponse> responses =
            new ArrayList<InsertResultEventResponse>(valueList.size());
    for (Contract.EventValuesWithLog eventValues : valueList) {
        InsertResultEventResponse typedResponse = new InsertResultEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse.count = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 25
Source Project: web3sdk   Source File: PerformanceDTCallback.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(TransactionReceipt receipt) {
    Long cost = System.currentTimeMillis() - startTime;

    try {
        if (receipt.isStatusOK()) {
            String output = receipt.getOutput();
            if (!output.isEmpty()) {
                int code = new BigInteger(output.substring(2, output.length()), 16).intValue();
                logger.debug(" output is {}, code is {} ", output, code);
                if (0 == code) {
                    if (callBackType.compareTo("add") == 0) { // add test
                        dagUserMgr.addUser(user);
                    } else if (callBackType.compareTo("transfer") == 0) { // transfer test
                        fromUser.decrease(amount);
                        toUser.increase(amount);
                    }
                } else {
                    logger.error(" invalid return: code is " + code);
                }
            } else {
                logger.error(" empty return ");
            }
        }
        collector.onMessage(receipt, cost);
    } catch (Exception e) {
        logger.error("onMessage error: ", e);
    }
}
 
Example 26
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple2<String, String> getAddOperatorInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_ADDOPERATOR, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Address>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());;
    return new Tuple2<String, String>(

            (String) results.get(0).getValue(), 
            (String) results.get(1).getValue()
            );
}
 
Example 27
Source Project: web3sdk   Source File: EvidenceVerify.java    License: Apache License 2.0 5 votes vote down vote up
public List<NewEvidenceEventEventResponse> getNewEvidenceEventEvents(
        TransactionReceipt transactionReceipt) {
    List<Contract.EventValuesWithLog> valueList =
            extractEventParametersWithLog(NEWEVIDENCEEVENT_EVENT, transactionReceipt);
    ArrayList<NewEvidenceEventEventResponse> responses =
            new ArrayList<NewEvidenceEventEventResponse>(valueList.size());
    for (Contract.EventValuesWithLog eventValues : valueList) {
        NewEvidenceEventEventResponse typedResponse = new NewEvidenceEventEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse.addr = (String) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 28
Source Project: WeBASE-Front   Source File: EvidenceSignersData.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple1<String> getNewEvidenceOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function = new Function(FUNC_NEWEVIDENCE, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());;
    return new Tuple1<String>(

            (String) results.get(0).getValue()
            );
}
 
Example 29
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> delOperator(String topicName, String operatorAddress) {
    final Function function = new Function(
            FUNC_DELOPERATOR, 
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(topicName), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(operatorAddress)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 30
Source Project: web3sdk   Source File: CRUD.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> update(
        String tableName, String key, String entry, String condition, String optional) {
    final Function function =
            new Function(
                    FUNC_UPDATE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(tableName),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(key),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(entry),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(condition),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(optional)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}