utils

package
v1.4.5-hsc Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SegmentSize is the chunk size that is used when taking the Merkle root
	// of a file. 64 is chosen because bandwidth is scarce and it optimizes for
	// the smallest possible storage proofs. Using a larger base, even 256
	// bytes, would result in substantially faster hashing, but the bandwidth
	// tradeoff was deemed to be more important, as blockchain space is scarce.
	SegmentSize = 64
)

Variables

This section is empty.

Functions

func AddContext

func AddContext(err error, ctx string) error

AddContext wraps an error in a context.

func CalculateLeaves

func CalculateLeaves(dataSize uint64) uint64

CalculateLeaves calculates the number of leaves that would be pushed from data of size 'dataSize'.

func ComposeErrors

func ComposeErrors(errs ...error) error

ComposeErrors combines several errors in one.

func ContainsError

func ContainsError(base, target error) bool

ContainsError checks if one error contains the other.

func DecodePriceTable

func DecodePriceTable(pt *rhpv3.HostPriceTable, d *types.Decoder)

DecodePriceTable decodes the host's price table.

func DecodeSettings

func DecodeSettings(hs *rhpv2.HostSettings, d *types.Decoder)

DecodeSettings decodes the host's settings.

func EncodePriceTable

func EncodePriceTable(pt *rhpv3.HostPriceTable, e *types.Encoder)

EncodePriceTable encodes the host's price table.

func EncodeSettings

func EncodeSettings(hs *rhpv2.HostSettings, e *types.Encoder)

EncodeSettings encodes the host's settings.

func EqualIPNets

func EqualIPNets(ipNetsA, ipNetsB []string) bool

EqualIPNets checks if two slices of IP subnets contain the same subnets.

func FromFloat

func FromFloat(f float64) types.Currency

FromFloat converts f Siacoins to a types.Currency value.

func IsLocal

func IsLocal(addr string) bool

IsLocal returns true if the input IP address belongs to a local address range such as 192.168.x.x or 127.x.x.x.

func IsLoopback

func IsLoopback(addr string) bool

IsLoopback returns true for IP addresses that are on the same machine.

func IsStdValid

func IsStdValid(addr string) error

IsStdValid returns an error if the NetAddress is invalid. A valid NetAddress is of the form "host:port", such that "host" is either a valid IPv4/IPv6 address or a valid hostname, and "port" is an integer in the range [1,65535]. Valid IPv4 addresses, IPv6 addresses, and hostnames are detailed in RFCs 791, 2460, and 952, respectively. Loopback addresses are allowed.

func IsValid

func IsValid(addr string) error

IsValid is an extension to IsStdValid that also forbids the loopback address.

NOTE: IsValid is being phased out in favor of allowing the loopback address but verifying through other means that the connection is not to yourself (which is the original reason that the loopback address was banned).

func LookupIPNets

func LookupIPNets(addr string) (ipNets []string, err error)

LookupIPNets returns string representations of the CIDR subnets.

func MulFloat

func MulFloat(c types.Currency, f float64) types.Currency

MulFloat multiplies a types.Currency by a float64 value.

func PeekErr

func PeekErr(errChan <-chan error) (err error)

PeekErr checks if a chan error has an error waiting to be returned. If it has it will return that error. Otherwise it returns 'nil'.

func VerifyRangeProof

func VerifyRangeProof(segments []byte, proof []types.Hash256, start, end int, root types.Hash256) bool

VerifyRangeProof verifies a proof produced by MerkleRangeProof.

VerifyRangeProof for a single segment is NOT equivalent to VerifySegment.

func VerifySegment

func VerifySegment(base []byte, hashSet []types.Hash256, numSegments, proofIndex uint64, root types.Hash256) bool

VerifySegment will verify that a segment, given the proof, is a part of a Merkle root.

Types

type MerkleTree

type MerkleTree struct {
	merkletree.Tree
}

MerkleTree wraps merkletree.Tree, changing some of the function definitions to assume sia-specific constants and return sia-specific types.

func NewTree

func NewTree() *MerkleTree

NewTree returns a MerkleTree, which can be used for getting Merkle roots and Merkle proofs on data. See merkletree.Tree for more details.

func (*MerkleTree) PushObject

func (t *MerkleTree) PushObject(obj types.EncoderTo)

PushObject encodes and adds the hash of the encoded object to the tree as a leaf.

func (*MerkleTree) Root

func (t *MerkleTree) Root() (h types.Hash256)

Root is a redefinition of merkletree.Tree.Root, returning a types.Hash256 instead of a []byte.

Jump to

Keyboard shortcuts

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