本文整理匯總了Golang中github.com/NebulousLabs/Sia/persist.SaveFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang SaveFile函數的具體用法?Golang SaveFile怎麽用?Golang SaveFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SaveFile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: save
func (g *Gateway) save() error {
var nodes []modules.NetAddress
for node := range g.nodes {
nodes = append(nodes, node)
}
return persist.SaveFile(persistMetadata, nodes, filepath.Join(g.persistDir, "nodes.json"))
}
示例2: save
// save stores the current renter data to disk.
func (r *Renter) save() error {
var files []file
for _, file := range r.files {
files = append(files, *file)
}
return persist.SaveFile(saveMetadata, files, filepath.Join(r.saveDir, PersistFilename))
}
示例3: save
// save stores all of the persist data to disk.
func (h *Host) save() error {
p := persistence{
// RPC Metrics.
ErroredCalls: atomic.LoadUint64(&h.atomicErroredCalls),
UnrecognizedCalls: atomic.LoadUint64(&h.atomicUnrecognizedCalls),
DownloadCalls: atomic.LoadUint64(&h.atomicDownloadCalls),
RenewCalls: atomic.LoadUint64(&h.atomicRenewCalls),
ReviseCalls: atomic.LoadUint64(&h.atomicReviseCalls),
SettingsCalls: atomic.LoadUint64(&h.atomicSettingsCalls),
UploadCalls: atomic.LoadUint64(&h.atomicUploadCalls),
// Consensus Tracking.
BlockHeight: h.blockHeight,
RecentChange: h.recentChange,
// Host Identity.
NetAddress: h.netAddress,
PublicKey: h.publicKey,
SecretKey: h.secretKey,
// File Management.
Obligations: h.getObligations(),
// Statistics.
FileCounter: h.fileCounter,
LostRevenue: h.lostRevenue,
Revenue: h.revenue,
// Utilities.
Settings: h.settings,
}
return persist.SaveFile(persistMetadata, p, filepath.Join(h.persistDir, settingsFile))
}
示例4: TestPersistCompat04
// TestPersistCompat04 checks that the compatibility loader for version 0.4.x
// obligations is functioning.
func TestPersistCompat04(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ht, err := newHostTester("TestPersistCompat04")
if err != nil {
t.Fatal(err)
}
// Upload a file and then save the host as a compatibility host.
_, err = ht.uploadFile("TestPersistCompat04 - 1", renewDisabled)
if err != nil {
t.Fatal(err)
}
// Mine a block so that the file contract ends up in the blockchain.
_, err = ht.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
err = ht.host.Close()
if err != nil {
t.Fatal(err)
}
c04h := ht.buildCompat04Host()
if err != nil {
t.Fatal(err)
}
// Save the compatibility file, replacing the usual file with an old
// format.
err = persist.SaveFile(compat04Metadata, c04h, filepath.Join(ht.host.persistDir, settingsFile))
if err != nil {
t.Fatal(err)
}
// Re-open the host, which will be loading from the compatibility file.
rebootHost, err := New(ht.cs, ht.tpool, ht.wallet, ":0", filepath.Join(ht.persistDir, modules.HostDir))
if err != nil {
t.Fatal(err)
}
if len(rebootHost.obligationsByID) != 1 {
t.Fatal(len(rebootHost.obligationsByID))
}
// Mine until the storage proof goes through, and the obligation gets
// cleared.
for i := types.BlockHeight(0); i <= testUploadDuration+confirmationRequirement+defaultWindowSize; i++ {
_, err := ht.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
}
if len(rebootHost.obligationsByID) != 0 {
t.Error("obligations did not clear")
}
if rebootHost.revenue.IsZero() {
t.Error("host is reporting no revenue after doing a compatibility storage proof")
}
}
示例5: save
// save saves the hostdb persistence data to disk.
func (hdb *HostDB) save() error {
var data struct {
Contracts []hostContract
}
for _, hc := range hdb.contracts {
data.Contracts = append(data.Contracts, hc)
}
return persist.SaveFile(saveMetadata, data, filepath.Join(hdb.persistDir, persistFilename))
}
示例6: save
// save stores the current renter data to disk.
func (r *Renter) save() error {
data := struct {
Contracts map[string]types.FileContract
Entropy [32]byte
}{make(map[string]types.FileContract), r.entropy}
// Convert renter's contract map to a JSON-friendly type.
for id, fc := range r.contracts {
b, _ := id.MarshalJSON()
data.Contracts[string(b)] = fc
}
return persist.SaveFile(saveMetadata, data, filepath.Join(r.persistDir, PersistFilename))
}
示例7: recoverSeed
// recoverSeed integrates a recovery seed into the wallet.
func (w *Wallet) recoverSeed(masterKey crypto.TwofishKey, seed modules.Seed) error {
// Check that the seed is not already known.
for _, wSeed := range w.seeds {
if seed == wSeed {
return errKnownSeed
}
}
// Encrypt the seed and save the seed file.
var sfuid SeedFileUID
_, err := rand.Read(sfuid[:])
if err != nil {
return err
}
sek := seedFileEncryptionKey(masterKey, sfuid)
plaintextVerification := make([]byte, encryptionVerificationLen)
encryptionVerification, err := sek.EncryptBytes(plaintextVerification)
if err != nil {
return err
}
cryptSeed, err := sek.EncryptBytes(seed[:])
if err != nil {
return err
}
seedFilename := filepath.Join(w.persistDir, seedFilePrefix+persist.RandomSuffix()+seedFileSuffix)
seedFile := SeedFile{
SeedFileUID: sfuid,
EncryptionVerification: encryptionVerification,
Seed: cryptSeed,
}
err = persist.SaveFile(seedMetadata, seedFile, seedFilename)
if err != nil {
return err
}
// Add the seed file to the wallet's set of tracked seeds and save the
// wallet settings.
w.settings.AuxiliarySeedFiles = append(w.settings.AuxiliarySeedFiles, seedFile)
err = w.saveSettings()
if err != nil {
return err
}
w.integrateSeed(seed)
return nil
}
示例8: save
func (h *Host) save() error {
sHost := savedHost{
SpaceRemaining: h.spaceRemaining,
FileCounter: h.fileCounter,
Profit: h.profit,
HostSettings: h.HostSettings,
Obligations: make([]contractObligation, 0, len(h.obligationsByID)),
SecretKey: h.secretKey,
PublicKey: h.publicKey,
}
for _, ob := range h.obligationsByID {
// to avoid race conditions involving the obligation's mutex, copy it
// manually into a new object
obcopy := contractObligation{ID: ob.ID, FileContract: ob.FileContract, LastRevisionTxn: ob.LastRevisionTxn}
sHost.Obligations = append(sHost.Obligations, obcopy)
}
return persist.SaveFile(persistMetadata, sHost, filepath.Join(h.persistDir, "settings.json"))
}
示例9: createSeed
// createSeed creates a wallet seed and encrypts it using a key derived from
// the master key, then addds it to the wallet as the primary seed, while
// making a disk backup.
func (w *Wallet) createSeed(masterKey crypto.TwofishKey, seed modules.Seed) error {
// Derive the key used to encrypt the seed file, and create the encryption
// verification object.
var sfuid SeedFileUID
_, err := rand.Read(sfuid[:])
if err != nil {
return err
}
sfek := seedFileEncryptionKey(masterKey, sfuid)
plaintextVerification := make([]byte, encryptionVerificationLen)
encryptionVerification, err := sfek.EncryptBytes(plaintextVerification)
if err != nil {
return err
}
// Encrypt the seed and save the seed file.
seedName := seedFilePrefix + persist.RandomSuffix() + seedFileSuffix
filename := filepath.Join(w.persistDir, seedName)
cryptSeed, err := sfek.EncryptBytes(seed[:])
if err != nil {
return err
}
w.primarySeed = seed
w.settings.PrimarySeedFile = SeedFile{
SeedFileUID: sfuid,
EncryptionVerification: encryptionVerification,
Seed: cryptSeed,
}
w.settings.PrimarySeedProgress = 0
err = persist.SaveFile(seedMetadata, &w.settings.PrimarySeedFile, filename)
if err != nil {
return err
}
err = w.saveSettings()
if err != nil {
return err
}
return nil
}
示例10: encryptAndSaveSeedFile
// encryptAndSaveSeedFile encrypts and saves a seed file.
func (w *Wallet) encryptAndSaveSeedFile(masterKey crypto.TwofishKey, seed modules.Seed) (SeedFile, error) {
var sf SeedFile
_, err := rand.Read(sf.UID[:])
if err != nil {
return SeedFile{}, err
}
sek := uidEncryptionKey(masterKey, sf.UID)
plaintextVerification := make([]byte, encryptionVerificationLen)
sf.EncryptionVerification, err = sek.EncryptBytes(plaintextVerification)
if err != nil {
return SeedFile{}, err
}
sf.Seed, err = sek.EncryptBytes(seed[:])
if err != nil {
return SeedFile{}, err
}
seedFilename := filepath.Join(w.persistDir, seedFilePrefix+persist.RandomSuffix()+seedFileSuffix)
err = persist.SaveFile(seedMetadata, sf, seedFilename)
if err != nil {
return SeedFile{}, err
}
return sf, nil
}
示例11: save
func (p *stdPersist) save(data contractorPersist) error {
return persist.SaveFile(p.meta, data, p.filename)
}
示例12: saveSettings
// saveSettings writes the wallet's settings to the wallet's settings file,
// replacing the existing file.
func (w *Wallet) saveSettings() error {
return persist.SaveFile(settingsMetadata, w.persist, filepath.Join(w.persistDir, settingsFile))
}
示例13: save
// save stores all of the persistent data of the storage manager to disk.
func (sm *StorageManager) save() error {
return persist.SaveFile(persistMetadata, sm.persistData(), filepath.Join(sm.persistDir, settingsFile))
}
示例14: createBackup
// createBackup creates a backup file at the desired filepath.
func (w *Wallet) createBackup(backupFilepath string) error {
return persist.SaveFile(settingsMetadata, w.persist, backupFilepath)
}
示例15: save
// save stores the current renter data to disk.
func (r *Renter) save() error {
data := struct {
Tracking map[string]trackedFile
}{r.tracking}
return persist.SaveFile(saveMetadata, data, filepath.Join(r.persistDir, PersistFilename))
}