From e2e57d92cd76f33b23e91726f2572d4c1b14b1b3 Mon Sep 17 00:00:00 2001
From: Luca Moser <moser.luca@gmail.com>
Date: Fri, 12 Jun 2020 09:26:56 +0200
Subject: [PATCH] adds snapshot type

---
 dapps/valuetransfers/dapp.go                   | 9 +++++++++
 dapps/valuetransfers/packages/tangle/tangle.go | 5 ++++-
 plugins/testsnapshots/plugin.go                | 3 ++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dapps/valuetransfers/dapp.go b/dapps/valuetransfers/dapp.go
index 7964e471..3ecc38c5 100644
--- a/dapps/valuetransfers/dapp.go
+++ b/dapps/valuetransfers/dapp.go
@@ -4,6 +4,8 @@ import (
 	"sync"
 	"time"
 
+	flag "github.com/spf13/pflag"
+
 	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/consensus"
 	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
 	valuepayload "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
@@ -27,8 +29,15 @@ const (
 
 	// AverageNetworkDelay contains the average time it takes for a network to propagate through gossip.
 	AverageNetworkDelay = 5 * time.Second
+
+	// CfgValueLayerSnapshotFile is the path to the snapshot file.
+	CfgValueLayerSnapshotFile = "valueLayer.snapshot.file"
 )
 
+func init() {
+	flag.String(CfgValueLayerSnapshotFile, "./snapshot.json", "the path to the snapshot file")
+}
+
 var (
 	// App is the "plugin" instance of the value-transfers application.
 	App = node.NewPlugin(PluginName, node.Enabled, configure, run)
diff --git a/dapps/valuetransfers/packages/tangle/tangle.go b/dapps/valuetransfers/packages/tangle/tangle.go
index c8a63f48..78fe8959 100644
--- a/dapps/valuetransfers/packages/tangle/tangle.go
+++ b/dapps/valuetransfers/packages/tangle/tangle.go
@@ -164,8 +164,11 @@ func (tangle *Tangle) BranchManager() *branchmanager.BranchManager {
 	return tangle.branchManager
 }
 
+// Snapshot defines a snapshot of the ledger state.
+type Snapshot map[transaction.ID]map[address.Address][]*balance.Balance
+
 // LoadSnapshot creates a set of outputs in the value tangle, that are forming the genesis for future transactions.
-func (tangle *Tangle) LoadSnapshot(snapshot map[transaction.ID]map[address.Address][]*balance.Balance) {
+func (tangle *Tangle) LoadSnapshot(snapshot Snapshot) {
 	for transactionID, addressBalances := range snapshot {
 		for outputAddress, balances := range addressBalances {
 			input := NewOutput(outputAddress, transactionID, branchmanager.MasterBranchID, balances)
diff --git a/plugins/testsnapshots/plugin.go b/plugins/testsnapshots/plugin.go
index f38b7677..2e47c4c0 100644
--- a/plugins/testsnapshots/plugin.go
+++ b/plugins/testsnapshots/plugin.go
@@ -4,6 +4,7 @@ import (
 	"github.com/iotaledger/goshimmer/dapps/valuetransfers"
 	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
 	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
+	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/tangle"
 	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
 	"github.com/iotaledger/hive.go/logger"
 	"github.com/iotaledger/hive.go/node"
@@ -26,7 +27,7 @@ var (
 func configure(_ *node.Plugin) {
 	log = logger.NewLogger(PluginName)
 
-	valuetransfers.Tangle.LoadSnapshot(map[transaction.ID]map[address.Address][]*balance.Balance{
+	valuetransfers.Tangle.LoadSnapshot(tangle.Snapshot{
 		transaction.GenesisID: {
 			address0: []*balance.Balance{
 				balance.New(balance.ColorIOTA, 10000000),
-- 
GitLab