Search in sources :

Example 21 with TransactionReceipt

use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.

the class Service method onReceiveTransactionMessage.

public void onReceiveTransactionMessage(ChannelHandlerContext ctx, BcosMessage message) {
    TransactionReceipt receipt = null;
    try {
        receipt = ObjectMapperFactory.getObjectMapper().readValue(message.getData(), TransactionReceipt.class);
    } catch (Exception e) {
        receipt = new TransactionReceipt();
        receipt.setStatus(String.valueOf(ChannelMessageError.MESSAGE_DECODE_ERROR.getError()));
        // error
        receipt.setMessage("Decode receipt error: " + e.getLocalizedMessage());
    }
    onReceiveTransactionMessage(message.getSeq(), receipt);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 22 with TransactionReceipt

use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.

the class ConsensusService method removeNode.

public String removeNode(String nodeId) throws Exception {
    List<String> groupPeers = web3j.getGroupPeers().send().getResult();
    if (!groupPeers.contains(nodeId)) {
        return PrecompiledCommon.transferToJson(PrecompiledCommon.GroupPeers);
    }
    TransactionReceipt receipt = null;
    try {
        receipt = removeNodeAndRetReceipt(nodeId);
    } catch (RuntimeException e) {
        // because the exception is throwed by getTransactionReceipt, we need ignore it.
        if (e.getMessage().contains("Don't send requests to this group")) {
            return PrecompiledCommon.transferToJson(0);
        } else {
            throw e;
        }
    }
    return PrecompiledCommon.handleTransactionReceipt(receipt, web3j);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)

Example 23 with TransactionReceipt

use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.

the class CRUDService method remove.

public int remove(Table table, Condition condition) throws Exception {
    if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) {
        throw new PrecompileMessageException("The value of the table key exceeds the maximum limit(" + PrecompiledCommon.TABLE_KEY_MAX_LENGTH + ").");
    }
    String conditionStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(condition.getConditions());
    TransactionReceipt receipt = crud.remove(table.getTableName(), table.getKey(), conditionStr, table.getOptional()).send();
    return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) PrecompileMessageException(org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException)

Example 24 with TransactionReceipt

use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.

the class CRUDService method insert.

public int insert(Table table, Entry entry) throws Exception {
    if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) {
        throw new PrecompileMessageException("The value of the table key exceeds the maximum limit(" + PrecompiledCommon.TABLE_KEY_MAX_LENGTH + ").");
    }
    String entryJsonStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(entry.getFields());
    TransactionReceipt receipt = crud.insert(table.getTableName(), table.getKey(), entryJsonStr, table.getOptional()).send();
    return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) PrecompileMessageException(org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException)

Example 25 with TransactionReceipt

use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.

the class CRUDService method update.

public int update(Table table, Entry entry, Condition condition) throws Exception {
    if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) {
        throw new PrecompileMessageException("The value of the table key exceeds the maximum limit(" + PrecompiledCommon.TABLE_KEY_MAX_LENGTH + ").");
    }
    String entryJsonStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(entry.getFields());
    String conditionStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(condition.getConditions());
    TransactionReceipt receipt = crud.update(table.getTableName(), table.getKey(), entryJsonStr, conditionStr, table.getOptional()).send();
    return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) PrecompileMessageException(org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException)

Aggregations

TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)41 BigInteger (java.math.BigInteger)18 Service (org.fisco.bcos.channel.client.Service)10 Credentials (org.fisco.bcos.web3j.crypto.Credentials)10 Web3j (org.fisco.bcos.web3j.protocol.Web3j)10 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)10 ApplicationContext (org.springframework.context.ApplicationContext)10 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 RateLimiter (com.google.common.util.concurrent.RateLimiter)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)9 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)9 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 Random (java.util.Random)6 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)5 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)5 List (java.util.List)4 PrecompileMessageException (org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException)3 Test (org.junit.Test)3 IOException (java.io.IOException)2