go-blockchain/chain/blockdata.go
Claude 41e0e58706
Some checks failed
Security Scan / security (push) Successful in 12s
Test / Test (push) Failing after 35s
feat: complete all 10 RFC request items
3. config/file.go — YAML/env config loading with defaults
5. entitlement.go — SyncTask for PerformAsync progress tracking
6. chain/blockdata.go — atomic file writes for block storage
7. entitlement.go — EntitlementMiddleware + CheckEntitlement stubs
8. dns.go — DNS record DTOs for go-lns bridge
10. crypto/doc.go — CGo patterns documented (until go-cgo ships)

Items 1,2,4,9 were already done. All 10/10 RFC items implemented.

Ready to consume go-lns when it lands:
- HSD client tested (hsd/client.go)
- DNS DTOs defined (dns.go)
- Config supports HSD URL + key (config/file.go)
- Entitlement gating ready for dns.resolve actions

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 01:48:31 +01:00

36 lines
981 B
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-License-Identifier: EUPL-1.2
package chain
import (
"os"
"dappco.re/go/core"
coreerr "dappco.re/go/core/log"
)
// WriteAtomic writes data to a file atomically (temp → rename).
// Safe for block/tx storage — no partial writes on crash.
//
// chain.WriteAtomic("/data/blocks/11000.bin", blockBytes)
func WriteAtomic(path string, data []byte) error {
tmp := path + ".tmp"
if err := os.WriteFile(tmp, data, 0644); err != nil {
return coreerr.E("WriteAtomic", core.Sprintf("write temp %s", tmp), err)
}
if err := os.Rename(tmp, path); err != nil {
os.Remove(tmp)
return coreerr.E("WriteAtomic", core.Sprintf("rename %s → %s", tmp, path), err)
}
return nil
}
// EnsureDir creates a directory and all parents if needed.
//
// chain.EnsureDir("/data/blocks")
func EnsureDir(path string) error {
return os.MkdirAll(path, 0755)
}