github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/init/handle_dryrun.go (about) 1 package initPkg 2 3 import ( 4 "errors" 5 "fmt" 6 "path/filepath" 7 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/history" 11 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" 12 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest" 13 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 14 ) 15 16 func (opts *InitOptions) HandleDryRun(rCtx *output.RenderCtx) error { 17 chain := opts.Globals.Chain 18 19 remoteManifest, err := manifest.LoadManifest(chain, opts.PublisherAddr, manifest.TempContract) 20 if err != nil { 21 return err 22 } 23 historyFile := filepath.Join(config.PathToRootConfig(), "unchained.txt") 24 saved := history.FromHistory(historyFile, "headerVersion") 25 defer func() { 26 _ = history.ToHistory(historyFile, "headerVersion", saved) 27 }() 28 _ = history.ToHistory(historyFile, "headerVersion", remoteManifest.Version) 29 logger.InfoTable("Existing version:", saved) 30 logger.InfoTable("Remote version:", remoteManifest.Version) 31 32 if remoteManifest.Chain != chain { 33 msg := fmt.Sprintf("The chain value found in the downloaded manifest (%s) does not match the manifest on the command line (%s).", remoteManifest.Chain, chain) 34 return errors.New(msg) 35 } 36 37 // Get the list of things we need to download 38 _, nToDownload, nDeleted, err := opts.prepareDownloadList(chain, remoteManifest, []base.Blknum{}) 39 if err != nil { 40 return err 41 } 42 43 spec := manifest.Specification() 44 if opts.Globals.TestMode { 45 nToDownload = base.Min(10, nToDownload) 46 spec = "--testing-hash--" 47 } 48 49 // Tell the user what we're doing 50 logger.InfoTable("Unchained Index:", config.GetUnchained().SmartContract) 51 logger.InfoTable("PreferredPublisher:", opts.Publisher) 52 logger.InfoTable("Specification:", spec) 53 logger.InfoTable("Config Folder:", config.MustGetPathToChainConfig(chain)) 54 logger.InfoTable("Index Folder:", config.PathToIndex(chain)) 55 logger.InfoTable("Chunks in manifest:", fmt.Sprintf("%d", len(remoteManifest.Chunks))) 56 logger.InfoTable("Files that would be deleted:", fmt.Sprintf("%d", nDeleted)) 57 logger.InfoTable("Files that would be downloaded:", fmt.Sprintf("%d", nToDownload)) 58 59 if nDeleted+nToDownload > 0 { 60 logger.Warn("") 61 logger.Warn("DryRun: The process would have modified both the manifest and the index. In that case, you would have") 62 logger.Warn("DryRun: had to invalidate your monitor cache by removing it.") 63 logger.Warn("") 64 logger.Warn("DryRun: No files were modified.") 65 } 66 67 return nil 68 }