Notify EventBus with NewTransactionEvent in Controller.onNewTransaction

This commit is contained in:
catbref 2020-12-01 17:23:10 +00:00
parent 7562d9bbf8
commit b651eae258

View File

@ -1036,12 +1036,27 @@ public class Controller extends Thread {
} }
} }
public static class NewTransactionEvent implements Event {
private final TransactionData transactionData;
public NewTransactionEvent(TransactionData transactionData) {
this.transactionData = transactionData;
}
public TransactionData getTransactionData() {
return this.transactionData;
}
}
/** Callback for when we've received a new transaction via API or peer. */ /** Callback for when we've received a new transaction via API or peer. */
public void onNewTransaction(TransactionData transactionData, Peer peer) { public void onNewTransaction(TransactionData transactionData, Peer peer) {
this.callbackExecutor.execute(() -> { this.callbackExecutor.execute(() -> {
// Notify all peers (except maybe peer that sent it to us if applicable) // Notify all peers (except maybe peer that sent it to us if applicable)
Network.getInstance().broadcast(broadcastPeer -> broadcastPeer == peer ? null : new TransactionSignaturesMessage(Arrays.asList(transactionData.getSignature()))); Network.getInstance().broadcast(broadcastPeer -> broadcastPeer == peer ? null : new TransactionSignaturesMessage(Arrays.asList(transactionData.getSignature())));
// Notify listeners
EventBus.INSTANCE.notify(new NewTransactionEvent(transactionData));
// If this is a CHAT transaction, there may be extra listeners to notify // If this is a CHAT transaction, there may be extra listeners to notify
if (transactionData.getType() == TransactionType.CHAT) if (transactionData.getType() == TransactionType.CHAT)
ChatNotifier.getInstance().onNewChatTransaction((ChatTransactionData) transactionData); ChatNotifier.getInstance().onNewChatTransaction((ChatTransactionData) transactionData);