Search in sources :

Example 1 with EventBroadcaster

use of io.nuls.event.bus.service.intf.EventBroadcaster in project nuls by nuls-io.

the class UtxoTransactionTool method sendNotice.

private void sendNotice(Balance oldBalance, Balance balance, String address) {
    long oldNa = oldBalance.getBalance().getValue();
    long change = balance.getBalance().getValue() - oldNa;
    if (NulsContext.LOCAL_ADDRESS_LIST != null && NulsContext.LOCAL_ADDRESS_LIST.contains(address)) {
        if (change == 0) {
            return;
        }
        BalanceChangeNotice notice = new BalanceChangeNotice();
        BalanceChangeData data = new BalanceChangeData();
        data.setAddress(address);
        data.setStatus(1);
        if (change < 0) {
            data.setType(1);
            data.setAmount(Na.valueOf(0 - change));
        } else {
            data.setType(0);
            data.setAmount(Na.valueOf(change));
        }
        notice.setEventBody(data);
        if (eventBroadcaster == null) {
            eventBroadcaster = NulsContext.getServiceBean(EventBroadcaster.class);
        }
        eventBroadcaster.publishToLocal(notice);
    }
}
Also used : EventBroadcaster(io.nuls.event.bus.service.intf.EventBroadcaster) BalanceChangeNotice(io.nuls.ledger.event.notice.BalanceChangeNotice) BalanceChangeData(io.nuls.ledger.event.notice.BalanceChangeData)

Aggregations

EventBroadcaster (io.nuls.event.bus.service.intf.EventBroadcaster)1 BalanceChangeData (io.nuls.ledger.event.notice.BalanceChangeData)1 BalanceChangeNotice (io.nuls.ledger.event.notice.BalanceChangeNotice)1