util

package
v0.5.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2024 License: Apache-2.0, MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const BatchSize = 100

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

func ChunkMapKeys added in v0.3.0

func ChunkMapKeys[T1 comparable, T2 any](m map[T1]T2, chunkSize int) [][]T1

ChunkMapKeys is a generic function that takes a map with keys of any comparable type and values of any type, and an integer as input. It divides the keys of the input map into packJobs of size 'chunkSize' and returns a 2D slice of keys. It uses the ChunkSlice function to divide the keys into packJobs.

Parameters:

  • m: A map with keys of any comparable type and values of any type. The keys of this map will be chunked.
  • chunkSize: The size of each packJob. Must be a positive integer.

Returns:

  • A 2D slice where each inner slice is of length 'chunkSize'. The last inner slice may be shorter if the number of keys in 'm' is not a multiple of 'chunkSize'.

func ChunkSlice added in v0.3.0

func ChunkSlice[T any](slice []T, chunkSize int) [][]T

ChunkSlice is a generic function that takes a slice of any type and an integer as input. It divides the input slice into packJobs of size 'chunkSize' and returns a 2D slice. If 'chunkSize' is less than or equal to zero, it returns an empty 2D slice.

Parameters:

  • slice: A slice of any type that needs to be chunked.
  • chunkSize: The size of each packJob. Must be a positive integer.

Returns:

  • A 2D slice where each inner slice is of length 'chunkSize'. The last inner slice may be shorter if the length of 'slice' is not a multiple of 'chunkSize'.

func GenerateCarHeader added in v0.4.0

func GenerateCarHeader(root cid.Cid) ([]byte, error)

GenerateCarHeader generates the CAR (Content Addressable aRchive) format header based on the given root CID (Content Identifier).

Parameters:

  • root: The root CID of the MerkleDag that the CAR file represents.

Returns:

  • []byte: The byte representation of the CAR header.
  • error: An error that can occur during the header generation process, or nil if successful.

func GenerateNewPeer added in v0.3.0

func GenerateNewPeer() ([]byte, []byte, peer.ID, error)

GenerateNewPeer is a function that generates a new peer for the IPFS network. It generates a new Ed25519 key pair using a secure random source and derives a peer ID from the public key. It then marshals the private and public keys into byte slices.

Returns:

The private key as a byte slice, the public key as a byte slice, the peer ID, and an error if the operation failed.
If any of the operations (key generation, peer ID derivation, key marshalling) fail, it returns an error wrapped with a descriptive message.

func GetLotusHeadTime added in v0.3.0

func GetLotusHeadTime(ctx context.Context, lotusAPI string, lotusToken string) (time.Time, error)

GetLotusHeadTime retrieves the timestamp of the latest block in the Lotus API and returns it as a time.Time value.

func InitHost

func InitHost(opts []libp2p.Option, listenAddrs ...multiaddr.Multiaddr) (host.Host, error)

InitHost initializes a new libp2p host with the provided options and listen addresses.

Parameters:

  • opts: A slice of libp2p options to configure the host.
  • listenAddrs: A variadic list of multiaddresses for the host to listen on.

Returns:

  1. A libp2p host instance that represents the initialized host.
  2. An error, which will be non-nil if any error occurred during host initialization.

func IsAllDigits added in v0.4.0

func IsAllDigits(s string) bool

IsAllDigits is a function that checks if a string contains only digits.

func IsDuplicateKeyError added in v0.4.0

func IsDuplicateKeyError(err error) bool

func NewLotusClient added in v0.2.21

func NewLotusClient(lotusAPI string, lotusToken string) jsonrpc.RPCClient

NewLotusClient is a function that creates a new JSON-RPC client for interacting with a Lotus node. It takes the Lotus API endpoint and an optional Lotus token as input. If the Lotus token is provided, it is included in the 'Authorization' header of the JSON-RPC requests.

Parameters:

  • lotusAPI: The Lotus API endpoint. Must be a valid URL.
  • lotusToken: An optional Lotus token. If provided, it is included in the 'Authorization' header of the JSON-RPC requests.

Returns:

A JSON-RPC client configured to interact with the specified Lotus node. If a Lotus token is provided, the client includes it in the 'Authorization' header of its requests.

func NextPowerOfTwo

func NextPowerOfTwo(x uint64) uint64

NextPowerOfTwo calculates the smallest power of two that is greater than or equal to x. If x is already a power of two, it returns x. For x equal to 0, the result is 1.

Parameters:

  • x: The input value for which the next power of two needs to be calculated.

Returns: The smallest power of two that is greater than or equal to x.

func RandomName added in v0.4.0

func RandomName() string

Types

type AggregateError added in v0.3.0

type AggregateError struct {
	Errors []error
}

func (AggregateError) As added in v0.4.0

func (a AggregateError) As(err interface{}) bool

func (AggregateError) Error added in v0.3.0

func (a AggregateError) Error() string

func (AggregateError) Format added in v0.4.0

func (a AggregateError) Format(s fmt.State, verb rune)

func (AggregateError) Is added in v0.4.0

func (a AggregateError) Is(err error) bool

func (AggregateError) Unwrap added in v0.4.0

func (a AggregateError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL