diff --git a/dapps/valuetransfers/dapp.go b/dapps/valuetransfers/dapp.go index 7964e47159906f81943a9410a9af87b603daffc8..3ecc38c57094475b9f991f365b5d1129166a7c2a 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 c8a63f48fe5b365c0ffd61b4c84304a702103879..78fe895974304f020a68a2c09131d256a28e62ce 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 f38b7677ec2d8b219d30345454f4d81349d09cab..2e47c4c02938840a68a6d401ab6b745a1f97adb7 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),