Documentation ¶
Index ¶
- Constants
- Variables
- func AtTip(tipDelay int64, blockTimestamp int64) bool
- func BigPow10(e int32) *big.Float
- func BtoMb(b float64) float64
- func CheckNetworkSupported(ctx context.Context, networkIdentifier *types.NetworkIdentifier, ...) (*types.NetworkStatusResponse, error)
- func CheckNetworkTip(ctx context.Context, network *types.NetworkIdentifier, tipDelay int64, ...) (bool, *types.BlockIdentifier, error)
- func CheckStorageTip(ctx context.Context, network *types.NetworkIdentifier, tipDelay int64, ...) (bool, *types.BlockIdentifier, error)
- func ContainsAccountIdentifier(arr []*types.AccountIdentifier, s *types.AccountIdentifier) bool
- func ContainsString(arr []string, s string) bool
- func ContextSleep(ctx context.Context, duration time.Duration) error
- func CreateCommandPath(dataDirectory string, cmd string, network *types.NetworkIdentifier) (string, error)
- func CreateTempDir() (string, error)
- func CurrencyBalance(ctx context.Context, network *types.NetworkIdentifier, helper FetcherHelper, ...) (*types.Amount, *types.BlockIdentifier, error)
- func EnsurePathExists(path string) error
- func Equal(a interface{}, b interface{}) bool
- func LoadAndParse(filePath string, output interface{}) error
- func Milliseconds() int64
- func PrettyAmount(amount *big.Int, currency *types.Currency) string
- func RandomNumber(minimum *big.Int, maximum *big.Int) (*big.Int, error)
- func RemoveTempDir(dir string)
- func SerializeAndWrite(filePath string, object interface{}) error
- func SizeOf(v interface{}) int
- func TimeToTip(blocksPerSecond float64, lastSyncedIndex int64, tipIndex int64) time.Duration
- func Zero() *big.Float
- type AccountBalance
- type AccountBalanceRequest
- type AccountCoinsRequest
- type AccountCoinsResponse
- type BST
- type BlockStorageHelper
- type FetcherHelper
- type MemoryUsage
- type MutexMap
- type Node
- type PriorityMutex
- type ShardedMap
Constants ¶
const ( // DefaultFilePermissions specifies that the user can // read and write the file. DefaultFilePermissions = 0600 // AllFilePermissions specifies anyone can do anything // to the file. AllFilePermissions = 0777 // NanosecondsInMillisecond is the number // of nanoseconds in a millisecond. NanosecondsInMillisecond = 1000000 // MillisecondsInSecond is the number // of milliseconds in a second. MillisecondsInSecond = 1000 // OneHundred is the number 100. OneHundred = 100 // MaxEntrySizePerTxn is the maximum number of entries // in one transaction object. This is used for bootstrap // balances process to avoid TxnTooBig error when memory_limit_disabled=false // as well as reduce the running time. MaxEntrySizePerTxn = 600 )
const ( // DefaultShards is the default number of shards // to use in ShardedMap. DefaultShards = 256 )
Variables ¶
var ( // ErrNetworkNotSupported is returned when the network // you are attempting to connect to is not supported. ErrNetworkNotSupported = errors.New("network not supported") // OneHundredInt is a big.Int of value 100. OneHundredInt = big.NewInt(OneHundred) // ZeroInt is a big.Int of value 0. ZeroInt = big.NewInt(0) )
Functions ¶
func AtTip ¶
AtTip returns a boolean indicating if a block timestamp is within tipDelay from the current time.
func BigPow10 ¶
BigPow10 computes the value of 10^e. Inspired by: https://steemit.com/tutorial/@gopher23/power-and-root-functions-using-big-float-in-golang
func CheckNetworkSupported ¶
func CheckNetworkSupported( ctx context.Context, networkIdentifier *types.NetworkIdentifier, helper FetcherHelper, ) (*types.NetworkStatusResponse, error)
CheckNetworkSupported checks if a Rosetta implementation supports a given *types.NetworkIdentifier. If it does, the current network status is returned.
func CheckNetworkTip ¶
func CheckNetworkTip(ctx context.Context, network *types.NetworkIdentifier, tipDelay int64, f FetcherHelper, ) (bool, *types.BlockIdentifier, error)
CheckNetworkTip returns a boolean indicating if the block returned by network/status is at tip. It also returns the block identifier returned by network/status. Note that the tipDelay param takes tip delay in seconds. Block returned by network/status is considered to be at tip if one of the following two conditions is met: (1) the block was produced within tipDelay of current time (i.e. block timestamp >= current time - tipDelay) (2) the network/status endpoint returns a SyncStatus with Synced = true.
func CheckStorageTip ¶
func CheckStorageTip(ctx context.Context, network *types.NetworkIdentifier, tipDelay int64, f FetcherHelper, b BlockStorageHelper, ) (bool, *types.BlockIdentifier, error)
CheckStorageTip returns a boolean indicating if the current block returned by block storage helper is at tip. It also returns the block identifier of the current storage block. Note that the tipDelay param takes tip delay in seconds. A block in storage is considered to be at tip if one of the following two conditions is met: (1) the block was produced within tipDelay of current time (i.e. block timestamp >= current time - tipDelay) (2) CheckNetworkTip returns true and the block it returns is same as the current block in storage
func ContainsAccountIdentifier ¶
func ContainsAccountIdentifier(arr []*types.AccountIdentifier, s *types.AccountIdentifier) bool
ContainsAccountIdentifier returns a boolean indicating whether the struct s is in arr.
func ContainsString ¶
ContainsString returns a boolean indicating whether the string s is in arr.
func ContextSleep ¶
ContextSleep sleeps for the provided duration and returns an error if context is canceled.
func CreateCommandPath ¶
func CreateCommandPath( dataDirectory string, cmd string, network *types.NetworkIdentifier, ) (string, error)
CreateCommandPath creates a unique path for a command and network within a data directory. This is used to avoid collision when using multiple commands on multiple networks when the same storage resources are used. If the derived path does not exist, we run os.MkdirAll on the path.
func CreateTempDir ¶
CreateTempDir creates a directory in /tmp for usage within testing.
func CurrencyBalance ¶
func CurrencyBalance( ctx context.Context, network *types.NetworkIdentifier, helper FetcherHelper, account *types.AccountIdentifier, currency *types.Currency, index int64, ) (*types.Amount, *types.BlockIdentifier, error)
CurrencyBalance returns the balance of an account for a particular currency at a particular height. It is up to the caller to determine if the retrieved block has the expected hash for the requested index.
func EnsurePathExists ¶
EnsurePathExists creates directories along a path if they do not exist.
func Equal ¶
func Equal(a interface{}, b interface{}) bool
Equal returns a boolean indicating if two interfaces are equal.
func LoadAndParse ¶
LoadAndParse reads the file at the provided path and attempts to unmarshal it into output.
func PrettyAmount ¶
PrettyAmount returns a currency amount in native format with its symbol.
func RandomNumber ¶
RandomNumber returns some number in the range [minimum, maximum). Source: https://golang.org/pkg/crypto/rand/#Int
func RemoveTempDir ¶
func RemoveTempDir(dir string)
RemoveTempDir deletes a directory at a provided path for usage within testing.
func SerializeAndWrite ¶
SerializeAndWrite attempts to serialize the provided object into a file at filePath.
func SizeOf ¶
func SizeOf(v interface{}) int
SizeOf returns the size of 'v' in bytes. If there is an error during calculation, Of returns -1.
Types ¶
type AccountBalance ¶
type AccountBalance struct { Account *types.AccountIdentifier Amount *types.Amount Coins []*types.Coin Block *types.BlockIdentifier }
AccountBalance defines an account's balance, including either balance or coins, as well as the block which this balance was fetched at.
func GetAccountBalances ¶
func GetAccountBalances( ctx context.Context, fetcher FetcherHelper, balanceRequests []*AccountBalanceRequest, ) ([]*AccountBalance, error)
GetAccountBalances returns an array of AccountBalances for an array of AccountBalanceRequests
type AccountBalanceRequest ¶
type AccountBalanceRequest struct { Account *types.AccountIdentifier Network *types.NetworkIdentifier Currency *types.Currency }
AccountBalanceRequest defines the required information to get an account's balance.
type AccountCoinsRequest ¶
type AccountCoinsRequest struct { Account *types.AccountIdentifier Network *types.NetworkIdentifier Currencies []*types.Currency IncludeMempool bool }
AccountCoinsRequest defines the required information to get an account's coins.
type AccountCoinsResponse ¶
AccountCoins defines an account's coins info at tip.
func GetAccountCoins ¶
func GetAccountCoins( ctx context.Context, fetcher FetcherHelper, acctCoinsReqs []*AccountCoinsRequest, ) ([]*AccountCoinsResponse, error)
GetAccountCoins calls /account/coins endpoint and returns an array of coins at tip.
type BST ¶
type BST struct {
// contains filtered or unexported fields
}
BST is an implementation of a binary search tree.
type BlockStorageHelper ¶
type BlockStorageHelper interface { GetBlockLazy( ctx context.Context, blockIdentifier *types.PartialBlockIdentifier, ) (*types.BlockResponse, error) }
type FetcherHelper ¶
type FetcherHelper interface { NetworkList( ctx context.Context, metadata map[string]interface{}, ) (*types.NetworkListResponse, *fetcher.Error) NetworkStatusRetry( ctx context.Context, network *types.NetworkIdentifier, metadata map[string]interface{}, ) (*types.NetworkStatusResponse, *fetcher.Error) AccountBalanceRetry( ctx context.Context, network *types.NetworkIdentifier, account *types.AccountIdentifier, block *types.PartialBlockIdentifier, currencies []*types.Currency, ) (*types.BlockIdentifier, []*types.Amount, map[string]interface{}, *fetcher.Error) AccountCoinsRetry( ctx context.Context, network *types.NetworkIdentifier, acct *types.AccountIdentifier, includeMempool bool, currencies []*types.Currency, ) (*types.BlockIdentifier, []*types.Coin, map[string]interface{}, *fetcher.Error) }
FetcherHelper is used by util functions to mock Fetcher
type MemoryUsage ¶
type MemoryUsage struct { Heap float64 `json:"heap"` Stack float64 `json:"stack"` OtherSystem float64 `json:"other_system"` System float64 `json:"system"` GarbageCollections uint32 `json:"garbage_collections"` }
MemoryUsage contains memory usage stats converted to MBs.
func MonitorMemoryUsage ¶
func MonitorMemoryUsage( ctx context.Context, maxHeapUsage int, ) *MemoryUsage
MonitorMemoryUsage returns a collection of memory usage stats in MB. It will also run garbage collection if the heap is greater than maxHeapUsage in MB.
type MutexMap ¶
type MutexMap struct {
// contains filtered or unexported fields
}
MutexMap is a struct that allows for acquiring a *PriorityMutex via a string identifier or for acquiring a global mutex that blocks the acquisition of any identifier mutexes.
This is useful for coordinating concurrent, non-overlapping writes in the storage package.
func (*MutexMap) GLock ¶
func (m *MutexMap) GLock()
GLock acquires an exclusive lock across an entire *MutexMap.
func (*MutexMap) GUnlock ¶
func (m *MutexMap) GUnlock()
GUnlock releases an exclusive lock held for an entire *MutexMap.
type PriorityMutex ¶
type PriorityMutex struct {
// contains filtered or unexported fields
}
PriorityMutex is a special type of mutex that allows callers to request priority over other callers. This can be useful if there is a "hot path" in an application that requires lock access.
WARNING: It is possible to cause lock starvation if not careful (i.e. only high priority callers ever do work).
func (*PriorityMutex) Lock ¶
func (m *PriorityMutex) Lock(priority bool)
Lock attempts to acquire either a high or low priority mutex. When priority is true, a lock will be granted before other low priority callers.
func (*PriorityMutex) Unlock ¶
func (m *PriorityMutex) Unlock()
Unlock selects the next highest priority lock to grant. If there are no locks to grant, it sets the value of m.lock to false.
type ShardedMap ¶
type ShardedMap struct {
// contains filtered or unexported fields
}
ShardedMap allows concurrent writes to a map by sharding the map into some number of independently locked subsections.
func NewShardedMap ¶
func NewShardedMap(shards int) *ShardedMap
NewShardedMap creates a new *ShardedMap with some number of shards. The larger the number provided for shards, the less lock contention there will be.
As a rule of thumb, shards should usually be set to the concurrency of the caller.
func (*ShardedMap) Lock ¶
func (m *ShardedMap) Lock(key string, priority bool) map[string]interface{}
Lock acquires the lock for a shard that could contain the key. This syntax allows the caller to perform multiple operations while holding the lock for a single shard.
func (*ShardedMap) Unlock ¶
func (m *ShardedMap) Unlock(key string)
Unlock releases the lock for a shard that could contain the key.