From ee41f8c41291addc1e71b9d9eda2a6262c6aaccc Mon Sep 17 00:00:00 2001
From: Hans Moog <hm@mkjc.net>
Date: Mon, 17 Feb 2020 16:51:13 +0100
Subject: [PATCH] Feat: first compiling version of new ontologoies merge

---
 go.mod                                |  2 +-
 go.sum                                |  2 ++
 packages/binary/tangle/tangle.go      | 11 ++++++-----
 packages/binary/tangle/tangle_test.go | 12 ++++++++++--
 plugins/config/plugin.go              |  1 +
 plugins/logger/plugin.go              |  1 +
 plugins/tangle/tangle.go              |  3 ++-
 7 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/go.mod b/go.mod
index c51b84bd..d8ea9480 100644
--- a/go.mod
+++ b/go.mod
@@ -13,7 +13,7 @@ require (
 	github.com/googollee/go-engine.io v1.4.3-0.20190924125625-798118fc0dd2
 	github.com/googollee/go-socket.io v1.4.3-0.20191204093753-683f8725b6d0
 	github.com/gorilla/websocket v1.4.1
-	github.com/iotaledger/hive.go v0.0.0-20200212114128-1460dba4a6b0
+	github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085
 	github.com/iotaledger/iota.go v1.0.0-beta.14
 	github.com/labstack/echo v3.3.10+incompatible
 	github.com/labstack/gommon v0.3.0 // indirect
diff --git a/go.sum b/go.sum
index a72469bc..ccf7ed45 100644
--- a/go.sum
+++ b/go.sum
@@ -125,6 +125,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
 github.com/iotaledger/hive.go v0.0.0-20200212114128-1460dba4a6b0 h1:AXUiVkx3QWQPzEIpmHJEAjMmZCzx8VKF342+vouRbic=
 github.com/iotaledger/hive.go v0.0.0-20200212114128-1460dba4a6b0/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64=
+github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085 h1:gkxkCRUlAszGx1qgN+QxnVI5VvX7bxH0/2hqz8l8lSo=
+github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64=
 github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
 github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A=
 github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
diff --git a/packages/binary/tangle/tangle.go b/packages/binary/tangle/tangle.go
index 9033cfdd..876c0d37 100644
--- a/packages/binary/tangle/tangle.go
+++ b/packages/binary/tangle/tangle.go
@@ -4,6 +4,7 @@ import (
 	"container/list"
 	"time"
 
+	"github.com/dgraph-io/badger/v2"
 	"github.com/iotaledger/hive.go/types"
 
 	"github.com/iotaledger/goshimmer/packages/binary/storageprefix"
@@ -37,13 +38,13 @@ type Tangle struct {
 }
 
 // Constructor for the tangle.
-func New(storageId []byte) (result *Tangle) {
+func New(badgerInstance *badger.DB, storageId []byte) (result *Tangle) {
 	result = &Tangle{
 		storageId:                  storageId,
-		transactionStorage:         objectstorage.New(append(storageId, storageprefix.TangleTransaction...), transaction.FromStorage),
-		transactionMetadataStorage: objectstorage.New(append(storageId, storageprefix.TangleTransactionMetadata...), transactionmetadata.FromStorage),
-		approverStorage:            objectstorage.New(append(storageId, storageprefix.TangleApprovers...), approver.FromStorage, objectstorage.PartitionKey(transaction.IdLength, transaction.IdLength)),
-		missingTransactionsStorage: objectstorage.New(append(storageId, storageprefix.TangleMissingTransaction...), missingtransaction.FromStorage),
+		transactionStorage:         objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleTransaction...), transaction.FromStorage),
+		transactionMetadataStorage: objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleTransactionMetadata...), transactionmetadata.FromStorage),
+		approverStorage:            objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleApprovers...), approver.FromStorage, objectstorage.PartitionKey(transaction.IdLength, transaction.IdLength)),
+		missingTransactionsStorage: objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleMissingTransaction...), missingtransaction.FromStorage),
 
 		Events: *newEvents(),
 	}
diff --git a/packages/binary/tangle/tangle_test.go b/packages/binary/tangle/tangle_test.go
index 33420e87..f40da0a9 100644
--- a/packages/binary/tangle/tangle_test.go
+++ b/packages/binary/tangle/tangle_test.go
@@ -5,16 +5,24 @@ import (
 	"testing"
 	"time"
 
+	"github.com/dgraph-io/badger/v2"
 	"github.com/iotaledger/hive.go/events"
 
 	"github.com/iotaledger/goshimmer/packages/binary/identity"
 	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction"
 	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction/payload/data"
 	"github.com/iotaledger/goshimmer/packages/binary/tangle/model/transactionmetadata"
+	"github.com/iotaledger/goshimmer/packages/database"
 )
 
+var testDatabase *badger.DB
+
+func init() {
+	testDatabase = database.GetBadgerInstance()
+}
+
 func BenchmarkTangle_AttachTransaction(b *testing.B) {
-	tangle := New([]byte("TEST_BINARY_TANGLE"))
+	tangle := New(testDatabase, []byte("TEST_BINARY_TANGLE"))
 	if err := tangle.Prune(); err != nil {
 		b.Error(err)
 
@@ -39,7 +47,7 @@ func BenchmarkTangle_AttachTransaction(b *testing.B) {
 }
 
 func TestTangle_AttachTransaction(t *testing.T) {
-	tangle := New([]byte("TEST_BINARY_TANGLE"))
+	tangle := New(testDatabase, []byte("TEST_BINARY_TANGLE"))
 	if err := tangle.Prune(); err != nil {
 		t.Error(err)
 
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go
index 1dcccb49..0626fa17 100644
--- a/plugins/config/plugin.go
+++ b/plugins/config/plugin.go
@@ -4,6 +4,7 @@ import (
 	"github.com/iotaledger/hive.go/node"
 )
 
+// define the plugin as a placeholder, so the init methods get executed accordingly
 var PLUGIN = node.NewPlugin("Config", node.Enabled, run)
 
 func run(ctx *node.Plugin) {
diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go
index 8dde3221..c2564690 100644
--- a/plugins/logger/plugin.go
+++ b/plugins/logger/plugin.go
@@ -4,6 +4,7 @@ import (
 	"github.com/iotaledger/hive.go/node"
 )
 
+// define the plugin as a placeholder, so the init methods get executed accordingly
 var PLUGIN = node.NewPlugin("Logger", node.Enabled, run)
 
 func run(ctx *node.Plugin) {
diff --git a/plugins/tangle/tangle.go b/plugins/tangle/tangle.go
index 6862e9aa..23edfe1f 100644
--- a/plugins/tangle/tangle.go
+++ b/plugins/tangle/tangle.go
@@ -7,6 +7,7 @@ import (
 	"github.com/iotaledger/goshimmer/packages/binary/tangle/tipselector"
 	"github.com/iotaledger/goshimmer/packages/binary/tangle/transactionparser"
 	"github.com/iotaledger/goshimmer/packages/binary/tangle/transactionrequester"
+	"github.com/iotaledger/goshimmer/packages/database"
 	"github.com/iotaledger/goshimmer/packages/shutdown"
 	"github.com/iotaledger/hive.go/daemon"
 	"github.com/iotaledger/hive.go/events"
@@ -36,7 +37,7 @@ func configure(*node.Plugin) {
 	TransactionParser = transactionparser.New()
 	TransactionRequester = transactionrequester.New()
 	TipSelector = tipselector.New()
-	Instance = tangle.New(storageprefix.Mainnet)
+	Instance = tangle.New(database.GetBadgerInstance(), storageprefix.Mainnet)
 
 	// setup TransactionParser
 	TransactionParser.Events.TransactionParsed.Attach(events.NewClosure(func(transaction *transaction.Transaction) {
-- 
GitLab