Skip to content
Snippets Groups Projects
Select Git revision
  • f69d4bc80ccd5e984506442c38c52a040d11a97d
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • user avatar
    capossele authored
    bc791bd8
    History
    plugin.go 1.73 KiB
    package drng
    
    import (
    	"sync"
    
    	"github.com/iotaledger/goshimmer/packages/binary/drng"
    	"github.com/iotaledger/goshimmer/packages/binary/drng/payload"
    	"github.com/iotaledger/goshimmer/packages/binary/drng/payload/header"
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/tangle"
    	"github.com/iotaledger/goshimmer/plugins/messagelayer"
    	"github.com/iotaledger/hive.go/events"
    	"github.com/iotaledger/hive.go/logger"
    	"github.com/iotaledger/hive.go/marshalutil"
    	"github.com/iotaledger/hive.go/node"
    )
    
    // PluginName is the name of the DRNG plugin.
    const PluginName = "DRNG"
    
    var (
    	// Plugin is the plugin instance of the DRNG plugin.
    	Plugin   = node.NewPlugin(PluginName, node.Enabled, configure, run)
    	instance *drng.DRNG
    	once     sync.Once
    	log      *logger.Logger
    )
    
    func configure(_ *node.Plugin) {
    	configureEvents()
    }
    
    func run(*node.Plugin) {}
    
    func configureEvents() {
    	instance := Instance()
    	messagelayer.Tangle.Events.MessageSolid.Attach(events.NewClosure(func(cachedMessage *message.CachedMessage, cachedMessageMetadata *tangle.CachedMessageMetadata) {
    		cachedMessageMetadata.Release()
    
    		cachedMessage.Consume(func(msg *message.Message) {
    			if msg.Payload().Type() != payload.Type {
    				return
    			}
    			if len(msg.Payload().Bytes()) < header.Length {
    				return
    			}
    			marshalUtil := marshalutil.New(msg.Payload().Bytes())
    			parsedPayload, err := payload.Parse(marshalUtil)
    			if err != nil {
    				//TODO: handle error
    				log.Info(err)
    				return
    			}
    			if err := instance.Dispatch(msg.IssuerPublicKey(), msg.IssuingTime(), parsedPayload); err != nil {
    				//TODO: handle error
    				log.Info(err)
    				return
    			}
    			log.Info(instance.State.Randomness())
    		})
    	}))
    }