Search in sources :

Example 1 with TransactionMessage

use of org.tron.core.net.message.TransactionMessage in project java-tron by tronprotocol.

the class Wallet method broadcastTransaction.

/**
 * Broadcast a transaction.
 */
public boolean broadcastTransaction(Transaction signaturedTransaction) {
    TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
    try {
        if (trx.validateSignature()) {
            Message message = new TransactionMessage(signaturedTransaction);
            dbManager.pushTransactions(trx);
            p2pnode.broadcast(message);
            return true;
        }
    } catch (ValidateSignatureException e) {
        logger.debug(e.getMessage(), e);
    } catch (ContractValidateException e) {
        logger.debug(e.getMessage(), e);
    } catch (ContractExeException e) {
        logger.debug(e.getMessage(), e);
    } catch (Exception e) {
        logger.debug(e.getMessage(), e);
    }
    return false;
}
Also used : TransactionCapsule(org.tron.core.capsule.TransactionCapsule) TransactionMessage(org.tron.core.net.message.TransactionMessage) NumberMessage(org.tron.api.GrpcAPI.NumberMessage) TransactionMessage(org.tron.core.net.message.TransactionMessage) Message(org.tron.common.overlay.message.Message) ValidateSignatureException(org.tron.core.exception.ValidateSignatureException) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractExeException(org.tron.core.exception.ContractExeException) ValidateSignatureException(org.tron.core.exception.ValidateSignatureException) ContractExeException(org.tron.core.exception.ContractExeException)

Example 2 with TransactionMessage

use of org.tron.core.net.message.TransactionMessage in project java-tron by tronprotocol.

the class NodeImpl method broadcast.

/**
 * broadcast msg.
 *
 * @param msg msg to bradcast
 */
public void broadcast(Message msg) {
    InventoryType type;
    if (msg instanceof BlockMessage) {
        logger.info("Ready to broadcast a block, Its hash is " + msg.getMessageId());
        freshBlockId.offer(((BlockMessage) msg).getBlockId());
        blockToAdvertise.add(((BlockMessage) msg).getBlockId());
        type = InventoryType.BLOCK;
    } else if (msg instanceof TransactionMessage) {
        trxToAdvertise.add(msg.getMessageId());
        type = InventoryType.TRX;
    } else {
        return;
    }
    // TODO: here need to cache fresh message to let peer fetch these data not from DB
    advObjToSpread.put(msg.getMessageId(), type);
}
Also used : BlockMessage(org.tron.core.net.message.BlockMessage) TransactionMessage(org.tron.core.net.message.TransactionMessage) InventoryType(org.tron.protos.Protocol.Inventory.InventoryType)

Aggregations

TransactionMessage (org.tron.core.net.message.TransactionMessage)2 NumberMessage (org.tron.api.GrpcAPI.NumberMessage)1 Message (org.tron.common.overlay.message.Message)1 TransactionCapsule (org.tron.core.capsule.TransactionCapsule)1 ContractExeException (org.tron.core.exception.ContractExeException)1 ContractValidateException (org.tron.core.exception.ContractValidateException)1 ValidateSignatureException (org.tron.core.exception.ValidateSignatureException)1 BlockMessage (org.tron.core.net.message.BlockMessage)1 InventoryType (org.tron.protos.Protocol.Inventory.InventoryType)1