util

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 27 Imported by: 2

README

Koinos Util Golang

A utility library used by Koinos Golang applications

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidNonce is the error returned when a nonce is invalid
	ErrInvalidNonce = errors.New("invalid nonce")
)

Functions

func BlockString

func BlockString(block *protocol.Block) string

BlockString returns a string containing the given block's height and ID

func BlockTopologyString

func BlockTopologyString(topo *koinos.BlockTopology) string

BlockTopologyString returns a string representation of the BlockTopologyCmp

func CalculateMerkleRoot

func CalculateMerkleRoot(nodes [][]byte) ([]byte, error)

CalculateMerkleRoot calculates the merkle root for given leafs

func CheckIsValidAddress added in v1.1.0

func CheckIsValidAddress(s string) bool

CheckIsValidAddress takes a string and returns a boolean if it is potentially valid Uses P2PKH (original bitcoin spec) 33-35 alphanumeric characters beginning with the number 1, random digits, upper/lower case characters exceptions: uppercase letter O, uppercase letter I, lowercase letter l, and the number 0

func DecimalToSatoshi

func DecimalToSatoshi(d *decimal.Decimal, precision int) (uint64, error)

DecimalToSatoshi converts the given decimal to a satoshi value

func DecodeWIF

func DecodeWIF(wif string) ([]byte, error)

DecodeWIF decodes a WIF format string into bytes

func DisplayAddress

func DisplayAddress(addressBytes []byte) string

DisplayAddress takes address bytes and returns a properly formatted human-readable string

func EncodeWIF

func EncodeWIF(privKey []byte, compress bool, netID byte) string

EncodeWIF encodes a private key into a WIF format string

func EnsureDir

func EnsureDir(dir string) error

EnsureDir checks for existence of a directory and recursively creates it if needed

func GenerateBase58ID

func GenerateBase58ID(length int) string

GenerateBase58ID generates a random seed string

func GetAppDir

func GetAppDir(baseDir string, appName string) string

GetAppDir forms the application data directory from the given input

func GetBoolOption

func GetBoolOption(key string, defaultValue bool, cliArg bool, configs ...map[string]interface{}) bool

GetBoolOption fetches a bool cli value, respecting values in a given config

func GetHomeDir

func GetHomeDir() string

GetHomeDir gets the user's home directory with special casing for windows

func GetIntOption

func GetIntOption(key string, defaultValue int, cliArg int, configs ...map[string]interface{}) int

GetIntOption fetches an int value, respecting values in a given config

func GetStringOption

func GetStringOption(key string, defaultValue string, cliArg string, configs ...map[string]interface{}) string

GetStringOption fetches a string cli value, respecting values in a given config

func GetStringSliceOption

func GetStringSliceOption(key string, cliArg []string, configs ...map[string]interface{}) []string

GetStringSliceOption fetches a string slicecli value, respecting values in a given config

func HashMessage

func HashMessage(message proto.Message) ([]byte, error)

HashMessage takes a protobuf message and returns the multihash of the message

func HexStringToBytes

func HexStringToBytes(s string) ([]byte, error)

HexStringToBytes decodes a hex string to a byte slice

func InitBaseDir

func InitBaseDir(baseDir string) (string, error)

InitBaseDir creates the base directory

func MultihashString

func MultihashString(hash []byte) string

MultihashString returns a hex string representation of the given multihash

func NonceBytesToUInt64

func NonceBytesToUInt64(nonceBytes []byte) (uint64, error)

NonceBytesToUInt64 converts the given nonce bytes to a UInt64

func SatoshiToDecimal

func SatoshiToDecimal(balance uint64, precision int) (*decimal.Decimal, error)

SatoshiToDecimal converts the given UInt64 value to a decimals with the given precision

func SignTransaction

func SignTransaction(key []byte, tx *protocol.Transaction) error

SignTransaction signs the transaction with the given key

func TransactionString

func TransactionString(transaction *protocol.Transaction) string

TransactionString returns a string containing the given transaction's ID

func UInt64ToNonceBytes

func UInt64ToNonceBytes(value uint64) ([]byte, error)

UInt64ToNonceBytes converts the given nonce uint64 to nonce bytes

Types

type KoinosKey

type KoinosKey struct {
	PrivateKey *ecdsa.PrivateKey
}

KoinosKey represents a set of keys

func GenerateKoinosKey

func GenerateKoinosKey() (*KoinosKey, error)

GenerateKoinosKey generates a new set of keys

func NewKoinosKeyFromBytes added in v1.1.0

func NewKoinosKeyFromBytes(private []byte) (*KoinosKey, error)

NewKoinosKeyFromBytes creates a new key set from a private key byte slice

func (*KoinosKey) AddressBytes

func (keys *KoinosKey) AddressBytes() []byte

AddressBytes fetches the byte address associated with this key set

func (*KoinosKey) Private

func (keys *KoinosKey) Private() string

Private gets the private key in WIF format

func (*KoinosKey) PrivateBytes

func (keys *KoinosKey) PrivateBytes() []byte

PrivateBytes gets the private key bytes

func (*KoinosKey) Public

func (keys *KoinosKey) Public() string

Public gets the compressed public key in base58

func (*KoinosKey) PublicBytes

func (keys *KoinosKey) PublicBytes() []byte

PublicBytes get the public key bytes

type Void

type Void struct{}

Void is an empty struct whose main use is making maps act like sets

type YamlConfig

type YamlConfig struct {
	Global            map[string]interface{} `yaml:"global,omitempty"`
	P2P               map[string]interface{} `yaml:"p2p,omitempty"`
	BlockStore        map[string]interface{} `yaml:"block_store,omitempty"`
	JSONRPC           map[string]interface{} `yaml:"jsonrpc,omitempty"`
	TransactionStore  map[string]interface{} `yaml:"transaction_store,omitempty"`
	ContractMetaStore map[string]interface{} `yaml:"contract_meta_store,omitempty"`
}

YamlConfig represents the koinos yaml application config values

func InitYamlConfig

func InitYamlConfig(baseDir string) *YamlConfig

InitYamlConfig initializes a yaml config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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