https://github.com/ipfs/go-ipfs
Raw File
Tip revision: 958e586ca7ac4580bbe3789bc7ea1a2c87bd33ec authored by Piotr Galar on 05 April 2023, 16:14:13 UTC
Merge pull request #9791 from ipfs/release-v0.19.1
Tip revision: 958e586
common.go
package ipns

import (
	"context"

	nsys "github.com/ipfs/go-namesys"
	path "github.com/ipfs/go-path"
	ft "github.com/ipfs/go-unixfs"
	"github.com/ipfs/kubo/core"
	ci "github.com/libp2p/go-libp2p/core/crypto"
)

// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
	ctx, cancel := context.WithCancel(n.Context())
	defer cancel()

	emptyDir := ft.EmptyDirNode()

	err := n.Pinning.Pin(ctx, emptyDir, false)
	if err != nil {
		return err
	}

	err = n.Pinning.Flush(ctx)
	if err != nil {
		return err
	}

	pub := nsys.NewIpnsPublisher(n.Routing, n.Repo.Datastore())

	return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}
back to top