use of org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction in project web3sdk by FISCO-BCOS.
the class ChannelEthereumService method sendOnly.
@Override
public void sendOnly(Request request) throws IOException {
byte[] payload = objectMapper.writeValueAsBytes(request);
BcosRequest fiscoRequest = new BcosRequest();
fiscoRequest.setKeyID(channelService.getOrgID());
fiscoRequest.setBankNO("");
fiscoRequest.setContent(new String(payload));
fiscoRequest.setMessageID(channelService.newSeq());
if (timeout != 0) {
fiscoRequest.setTimeout(timeout);
}
if (!request.isNeedTransCallback()) {
channelService.asyncSendEthereumMessage(fiscoRequest, new BcosResponseCallback() {
@Override
public void onResponse(BcosResponse response) {
try {
logger.debug("fisco Request:{} {}", fiscoRequest.getMessageID(), objectMapper.writeValueAsString(request));
logger.debug("fisco Response:{} {} {}", fiscoRequest.getMessageID(), response.getErrorCode(), response.getContent());
if (response.getErrorCode() != 0) {
logger.error("Error: " + response.getErrorCode());
}
} catch (Exception e) {
logger.error("Error: ", e);
}
}
});
} else {
channelService.asyncSendEthereumMessage(fiscoRequest, new BcosResponseCallback() {
@Override
public void onResponse(BcosResponse response) {
try {
logger.debug("fisco Request:{} {}", fiscoRequest.getMessageID(), objectMapper.writeValueAsString(request));
logger.debug("fisco Response:{} {} {}", fiscoRequest.getMessageID(), response.getErrorCode(), response.getContent());
if (response.getErrorCode() == 0) {
// SendTransaction
SendTransaction sendTransaction = objectMapper.readValue(response.getContent(), SendTransaction.class);
if (sendTransaction.getError() == null) {
logger.debug("sendRawTransaction response ok, transaction hash: {} ", sendTransaction.getResult());
} else {
TransactionReceipt receipt = new TransactionReceipt();
receipt.setStatus(String.valueOf(sendTransaction.getError().getCode()));
receipt.setMessage(sendTransaction.getError().getMessage());
// optional code
if (channelService.getThreadPool() == null) {
channelService.onReceiveTransactionMessage(fiscoRequest.getMessageID(), receipt);
} else {
// Execute the callback function in the thread pool
channelService.getThreadPool().execute(new Runnable() {
@Override
public void run() {
channelService.onReceiveTransactionMessage(fiscoRequest.getMessageID(), receipt);
}
});
}
logger.debug(" sendRawTransaction response not ok, code: {}, message: {} ", receipt.getStatus(), receipt.getMessage());
}
}
} catch (Exception e) {
logger.error("Error: ", e);
}
}
}, request.getTransactionSucCallback());
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction in project web3sdk by FISCO-BCOS.
the class ExtendedRawTransactionManager method signAndSend.
public SendTransaction signAndSend(ExtendedRawTransaction rawTransaction) throws IOException {
String signedTransaction = sign(rawTransaction);
SendTransaction result = sendTransaction(signedTransaction);
return result;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction in project web3sdk by FISCO-BCOS.
the class ExtendedRawTransactionManager method sendTransaction.
@Override
public SendTransaction sendTransaction(String signedTransaction) throws IOException, TxHashMismatchException {
SendTransaction sendTransaction = web3j.sendRawTransaction(signedTransaction).send();
if (sendTransaction != null && !sendTransaction.hasError()) {
String txHashLocal = Hash.sha3(signedTransaction);
String txHashRemote = sendTransaction.getTransactionHash();
if (!txHashVerifier.verify(txHashLocal, txHashRemote)) {
throw new TxHashMismatchException(txHashLocal, txHashRemote);
}
}
return sendTransaction;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction in project web3sdk by FISCO-BCOS.
the class ManagedTransactionTester method prepareTransactionRequest.
@SuppressWarnings("unchecked")
void prepareTransactionRequest() throws IOException {
SendTransaction sendTransaction = new SendTransaction();
sendTransaction.setResult(TRANSACTION_HASH);
Request<?, SendTransaction> rawTransactionRequest = mock(Request.class);
when(rawTransactionRequest.send()).thenReturn(sendTransaction);
when(web3j.sendRawTransaction(any(String.class))).thenReturn((Request) rawTransactionRequest);
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction in project web3sdk by FISCO-BCOS.
the class ExtendedRawTransactionManager method signAndSend.
public SendTransaction signAndSend(ExtendedRawTransaction rawTransaction, TransactionSucCallback callback) throws IOException {
String signedTransaction = sign(rawTransaction);
SendTransaction result = sendTransaction(signedTransaction, callback);
return result;
}
Aggregations