From 6a6bf42f0a8465d6f542f5c3cdada415246ba6c5 Mon Sep 17 00:00:00 2001
From: capossele <angelocapossele@gmail.com>
Date: Mon, 30 Mar 2020 15:19:00 +0100
Subject: [PATCH] :construction: WIP

---
 go.sum                                           |  4 ++++
 packages/binary/drng/dispatcher.go               |  4 ++--
 packages/binary/drng/dispatcher_test.go          |  8 ++++----
 packages/binary/drng/payload/payload.go          |  2 +-
 packages/binary/drng/state/state.go              |  4 ++--
 packages/binary/drng/state/state_test.go         |  6 +++---
 .../collectiveBeacon/collective_beacon.go        |  4 ++--
 .../collectiveBeacon/collective_beacon_test.go   |  8 ++++----
 .../subtypes/collectiveBeacon/events/events.go   |  4 ++--
 .../subtypes/collectiveBeacon/payload/payload.go |  2 +-
 plugins/drng/plugin.go                           | 16 ++++++++--------
 11 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/go.sum b/go.sum
index 1da9fea9..a2c19ed8 100644
--- a/go.sum
+++ b/go.sum
@@ -215,6 +215,10 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
 github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
 github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
 github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
+github.com/nikkolasg/hexjson v0.0.0-20181101101858-78e39397e00c h1:5bFTChQxSKNwy8ALwOebjekYExl9HTT9urdawqC95tA=
+github.com/nikkolasg/hexjson v0.0.0-20181101101858-78e39397e00c/go.mod h1:7qN3Y0BvzRUf4LofcoJplQL10lsFDb4PYlePTVwrP28=
+github.com/nikkolasg/slog v0.0.0-20170921200349-3c8d441d7a1e h1:07zdEcJ4Fble5uWsqKpjW19699kQWRLXP+RZh1a6ZRg=
+github.com/nikkolasg/slog v0.0.0-20170921200349-3c8d441d7a1e/go.mod h1:79GLCU4P87rYvYYACbNwVyc1WmRvkwQbYnybpCmRXzg=
 github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
diff --git a/packages/binary/drng/dispatcher.go b/packages/binary/drng/dispatcher.go
index 52ce355b..15a7826f 100644
--- a/packages/binary/drng/dispatcher.go
+++ b/packages/binary/drng/dispatcher.go
@@ -9,11 +9,11 @@ import (
 	"github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/events"
 	cb "github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/payload"
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 	"github.com/iotaledger/hive.go/marshalutil"
 )
 
-func (drng *Instance) Dispatch(issuer ed25119.PublicKey, timestamp time.Time, payload *payload.Payload) error {
+func (drng *Instance) Dispatch(issuer ed25519.PublicKey, timestamp time.Time, payload *payload.Payload) error {
 	switch payload.SubType() {
 	case header.CollectiveBeaconType():
 		// parse as CollectiveBeaconType
diff --git a/packages/binary/drng/dispatcher_test.go b/packages/binary/drng/dispatcher_test.go
index 8c9acaa6..19479799 100644
--- a/packages/binary/drng/dispatcher_test.go
+++ b/packages/binary/drng/dispatcher_test.go
@@ -11,7 +11,7 @@ import (
 	"github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/events"
 	cbPayload "github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/payload"
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 	"github.com/iotaledger/hive.go/marshalutil"
 	"github.com/stretchr/testify/require"
 )
@@ -21,7 +21,7 @@ var (
 	prevSignatureTest []byte
 	signatureTest     []byte
 	dpkTest           []byte
-	issuerPK          ed25119.PublicKey
+	issuerPK          ed25519.PublicKey
 	committeeTest     *state.Committee
 	timestampTest     time.Time
 	randomnessTest    *state.Randomness
@@ -40,13 +40,13 @@ func init() {
 		Timestamp:  timestampTest,
 	}
 
-	kp := ed25119.GenerateKeyPair()
+	kp := ed25519.GenerateKeyPair()
 	issuerPK = kp.PublicKey
 
 	committeeTest = &state.Committee{
 		InstanceID:    1,
 		Threshold:     3,
-		Identities:    []ed25119.PublicKey{issuerPK},
+		Identities:    []ed25519.PublicKey{issuerPK},
 		DistributedPK: dpkTest,
 	}
 }
diff --git a/packages/binary/drng/payload/payload.go b/packages/binary/drng/payload/payload.go
index 0c6117c5..b61f0f23 100644
--- a/packages/binary/drng/payload/payload.go
+++ b/packages/binary/drng/payload/payload.go
@@ -4,7 +4,7 @@ import (
 	"sync"
 
 	"github.com/iotaledger/goshimmer/packages/binary/drng/payload/header"
-	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/message/payload"
+	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
 	"github.com/iotaledger/hive.go/marshalutil"
 	"github.com/iotaledger/hive.go/stringify"
 )
diff --git a/packages/binary/drng/state/state.go b/packages/binary/drng/state/state.go
index f29f2253..595fd91d 100644
--- a/packages/binary/drng/state/state.go
+++ b/packages/binary/drng/state/state.go
@@ -5,7 +5,7 @@ import (
 	"sync"
 	"time"
 
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 )
 
 type Randomness struct {
@@ -22,7 +22,7 @@ func (r Randomness) Float64() float64 {
 type Committee struct {
 	InstanceID    uint32
 	Threshold     uint8
-	Identities    []ed25119.PublicKey
+	Identities    []ed25519.PublicKey
 	DistributedPK []byte
 }
 type State struct {
diff --git a/packages/binary/drng/state/state_test.go b/packages/binary/drng/state/state_test.go
index ac8c881b..64a7a8cd 100644
--- a/packages/binary/drng/state/state_test.go
+++ b/packages/binary/drng/state/state_test.go
@@ -4,7 +4,7 @@ import (
 	"testing"
 	"time"
 
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 	"github.com/stretchr/testify/require"
 )
 
@@ -19,7 +19,7 @@ func dummyCommittee() *Committee {
 	return &Committee{
 		InstanceID:    0,
 		Threshold:     0,
-		Identities:    []ed25119.PublicKey{},
+		Identities:    []ed25519.PublicKey{},
 		DistributedPK: []byte{},
 	}
 }
@@ -31,7 +31,7 @@ func TestState(t *testing.T) {
 	require.Equal(t, *dummyCommittee(), stateTest.Committee())
 
 	// committee setters - getters
-	newCommittee := &Committee{1, 1, []ed25119.PublicKey{}, []byte{11}}
+	newCommittee := &Committee{1, 1, []ed25519.PublicKey{}, []byte{11}}
 	stateTest.SetCommittee(newCommittee)
 	require.Equal(t, *newCommittee, stateTest.Committee())
 
diff --git a/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon.go b/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon.go
index 3e5d8fa0..d6734b76 100644
--- a/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon.go
+++ b/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon.go
@@ -9,7 +9,7 @@ import (
 	"github.com/drand/drand/key"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/state"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/events"
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 )
 
 // ProcessTransaction performs the following tasks:
@@ -68,7 +68,7 @@ func VerifyCollectiveBeacon(state *state.State, data *events.CollectiveBeaconEve
 }
 
 // verifyIssuer checks the given issuer is a member of the committee
-func verifyIssuer(state *state.State, issuer ed25119.PublicKey) error {
+func verifyIssuer(state *state.State, issuer ed25519.PublicKey) error {
 	for _, member := range state.Committee().Identities {
 		if member == issuer {
 			return nil
diff --git a/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon_test.go b/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon_test.go
index 749a161b..bb46da73 100644
--- a/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon_test.go
+++ b/packages/binary/drng/subtypes/collectiveBeacon/collective_beacon_test.go
@@ -6,7 +6,7 @@ import (
 
 	"github.com/iotaledger/goshimmer/packages/binary/drng/state"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/events"
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 	"github.com/stretchr/testify/require"
 )
 
@@ -15,7 +15,7 @@ var (
 	prevSignatureTest []byte
 	signatureTest     []byte
 	dpkTest           []byte
-	issuerPK          ed25119.PublicKey
+	issuerPK          ed25519.PublicKey
 	stateTest         *state.State
 )
 
@@ -23,7 +23,7 @@ func init() {
 	prevSignatureTest, _ = hex.DecodeString("ae9ba6d1445bffea8e66cb7d28fe5924e0a8d31b11b62a8710204e56e1ba84bc3694a3033e5793fcee6e75e956e5da3016cd0e22aa46fa419cd06343a7ff9d1e9c5c08f660f0bdec099e97ef99f470bb8c607ce9667a165e9caa474710f62ffd")
 	signatureTest, _ = hex.DecodeString("8dee56fae60dcad960f7176d0813d5415b930cf6e20c299ec2c2dfc5f2ad4903916fd462ba1abf5c32a5bfd94dcc8eba062d011a548d99df7fa1e3bbbc9a0455663d60f6ccc736c1d5b6de727dbe4427e21fb660925518be386265913f447c94")
 	dpkTest, _ = hex.DecodeString("a02fcd15edd52c8e134027491a43b597505b466d1679e88f70f927e57c45a93ae0765ff02fc2d015e3a02fd8748e2103")
-	kp := ed25119.GenerateKeyPair()
+	kp := ed25519.GenerateKeyPair()
 	issuerPK = kp.PublicKey
 
 	eventTest = &events.CollectiveBeaconEvent{
@@ -39,7 +39,7 @@ func init() {
 		&state.Committee{
 			InstanceID:    1,
 			Threshold:     3,
-			Identities:    []ed25119.PublicKey{issuerPK},
+			Identities:    []ed25519.PublicKey{issuerPK},
 			DistributedPK: dpkTest,
 		}))
 }
diff --git a/packages/binary/drng/subtypes/collectiveBeacon/events/events.go b/packages/binary/drng/subtypes/collectiveBeacon/events/events.go
index bb05a6d1..c14e637b 100644
--- a/packages/binary/drng/subtypes/collectiveBeacon/events/events.go
+++ b/packages/binary/drng/subtypes/collectiveBeacon/events/events.go
@@ -3,7 +3,7 @@ package events
 import (
 	"time"
 
-	"github.com/iotaledger/goshimmer/packages/binary/signature/ed25119"
+	"github.com/iotaledger/hive.go/crypto/ed25519"
 	"github.com/iotaledger/hive.go/events"
 )
 
@@ -14,7 +14,7 @@ func NewCollectiveBeaconEvent() *events.Event {
 }
 
 type CollectiveBeaconEvent struct {
-	IssuerPublicKey ed25119.PublicKey // public key of the issuer
+	IssuerPublicKey ed25519.PublicKey // public key of the issuer
 	Timestamp       time.Time         // timestamp when the beacon was issued
 	InstanceID      uint32            // instanceID of the beacon
 	Round           uint64            // round of the current beacon
diff --git a/packages/binary/drng/subtypes/collectiveBeacon/payload/payload.go b/packages/binary/drng/subtypes/collectiveBeacon/payload/payload.go
index 02463d9b..97e1b455 100644
--- a/packages/binary/drng/subtypes/collectiveBeacon/payload/payload.go
+++ b/packages/binary/drng/subtypes/collectiveBeacon/payload/payload.go
@@ -7,7 +7,7 @@ import (
 
 	drngPayload "github.com/iotaledger/goshimmer/packages/binary/drng/payload"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/payload/header"
-	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/message/payload"
+	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
 	"github.com/iotaledger/hive.go/marshalutil"
 )
 
diff --git a/plugins/drng/plugin.go b/plugins/drng/plugin.go
index 3e732c13..30cf1239 100644
--- a/plugins/drng/plugin.go
+++ b/plugins/drng/plugin.go
@@ -3,9 +3,9 @@ package drng
 import (
 	"github.com/iotaledger/goshimmer/packages/binary/drng"
 	"github.com/iotaledger/goshimmer/packages/binary/drng/payload"
-	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/message"
-	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/transactionmetadata"
-	"github.com/iotaledger/goshimmer/plugins/tangle"
+	"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/marshalutil"
 	"github.com/iotaledger/hive.go/node"
@@ -25,17 +25,17 @@ func configure(*node.Plugin) {
 func run(*node.Plugin) {}
 
 func configureEvents() {
-	tangle.Instance.Events.TransactionSolid.Attach(events.NewClosure(func(cachedTransaction *message.CachedTransaction, cachedTransactionMetadata *transactionmetadata.CachedTransactionMetadata) {
-		cachedTransactionMetadata.Release()
+	messagelayer.Tangle.Events.TransactionSolid.Attach(events.NewClosure(func(cachedMessage *message.CachedMessage, cachedMessageMetadata *tangle.CachedMessageMetadata) {
+		cachedMessageMetadata.Release()
 
-		cachedTransaction.Consume(func(transaction *message.Transaction) {
-			marshalUtil := marshalutil.New(transaction.GetPayload().Bytes())
+		cachedMessage.Consume(func(msg *message.Message) {
+			marshalUtil := marshalutil.New(msg.GetPayload().Bytes())
 			parsedPayload, err := payload.Parse(marshalUtil)
 			if err != nil {
 				//TODO: handle error
 				return
 			}
-			if err := Instance.Dispatch(transaction.IssuerPublicKey(), transaction.IssuingTime(), parsedPayload); err != nil {
+			if err := Instance.Dispatch(msg.IssuerPublicKey(), msg.IssuingTime(), parsedPayload); err != nil {
 				//TODO: handle error
 			}
 		})
-- 
GitLab