utils

package
v0.0.0-...-64a03b9 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONEventSideBlock     = "side_block"
	JSONEventFoundBlock    = "found_block"
	JSONEventOrphanedBlock = "orphaned_block"
	JSONEventPayout        = "payout"
)
View Source
const (
	SiteKeyP2PoolIo = siteKey(iota)
	SiteKeyLocalMonero
	SiteKeyExploreMonero
	SiteKeyMoneroCom
	SiteKeyP2PoolObserver
	SiteKeyP2PoolObserverMini
	SiteKeyP2PoolObserverOld
	SiteKeyP2PoolObserverOldMini
	SiteKeyGitGammaspectraLive
	SiteKeyXmrChainNet
	SiteKeySethForPrivacy
	SiteKeyXmrVsBeast
)

Variables

View Source
var (
	DiscordColorGreen     uint64 = 5763719
	DiscordColorDarkGreen uint64 = 2067276
	DiscordColorOrange    uint64 = 15105570
)
View Source
var WebHookClient = http.Client{
	Timeout: 10 * time.Second,
	CheckRedirect: func(req *http.Request, via []*http.Request) error {
		return http.ErrUseLastResponse
	},
}
View Source
var WebHookHost string
View Source
var WebHookRateLimit = time.NewTicker(time.Second / 20)
View Source
var WebHookUserAgent string
View Source
var WebHookVersion = fmt.Sprintf("%d.%d", types.CurrentSoftwareVersion.Major(), types.CurrentSoftwareVersion.Minor())

Functions

func CanSendToHook

func CanSendToHook(w *index.MinerWebHook, key string) bool

func DecodeBinaryNumber

func DecodeBinaryNumber(i string) uint64

func DecodeHexBinaryNumber

func DecodeHexBinaryNumber(i string) string

func EncodeBinaryNumber

func EncodeBinaryNumber(n uint64) string

func EncodeHexBinaryNumber

func EncodeHexBinaryNumber(v2 string) string

func EncodeSliceBinaryNumber

func EncodeSliceBinaryNumber(dst, src []byte) []byte

func Factorial

func Factorial(n uint64) (result uint64)

Factorial Valid for small n

func FindAndInsertMainHeader

func FindAndInsertMainHeader(h daemon.BlockHeader, indexDb *index.Index, storeFunc func(b *sidechain.PoolBlock), client *client.Client, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId sidechain.GetByTemplateIdFunc, getByMainId sidechain.GetByMainIdFunc, getByMainHeight sidechain.GetByMainHeightFunc, processBlock func(b *sidechain.PoolBlock) error) error

func FindAndInsertMainHeaderOutputs

func FindAndInsertMainHeaderOutputs(mb *index.MainBlock, indexDb *index.Index, client *client.Client, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId sidechain.GetByTemplateIdFunc, getByMainId sidechain.GetByMainIdFunc, getByMainHeight sidechain.GetByMainHeightFunc, processBlock func(b *sidechain.PoolBlock) error) error

func GetMainBlock

func GetMainBlock(id types.Hash, client *client.Client) (*block.Block, error)

func GetSiteUrl

func GetSiteUrl(k siteKey, tryOnion bool) string

func GetSiteUrlByHost

func GetSiteUrlByHost(host string, tryOnion bool) string

func LookupTransactions

func LookupTransactions(requestOther func(ctx context.Context, indices []uint64) []*index.MatchedOutput, indexDb *index.Index, ctx context.Context, inputThreshold int, ids ...types.Hash) (results []index.TransactionInputQueryResults)

func ProbabilityEffort

func ProbabilityEffort(effort float64) float64

func ProbabilityMode

func ProbabilityMode(i ...float64) (n float64)

func ProbabilityNShares

func ProbabilityNShares(shares uint64, effort float64) float64

func ProcessFullBlock

func ProcessFullBlock(b *index.MainBlock, indexDb *index.Index) error

func SendFoundBlock

func SendFoundBlock(w *index.MinerWebHook, ts int64, source *address.Address, block *index.FoundBlock, outputs index.MainCoinbaseOutputs) error

func SendJsonPost

func SendJsonPost(w *index.MinerWebHook, ts int64, source *address.Address, data any) error

func SendOrphanedBlock

func SendOrphanedBlock(w *index.MinerWebHook, ts int64, source *address.Address, block *index.SideBlock) error

func SendPayout

func SendPayout(w *index.MinerWebHook, ts int64, source *address.Address, payout *index.Payout) error

func SendSideBlock

func SendSideBlock(w *index.MinerWebHook, ts int64, source *address.Address, block *index.SideBlock) error

func SetWebHookProxy

func SetWebHookProxy(hostPort string)

func Shorten

func Shorten(value string, n int) string

func ShortenSlice

func ShortenSlice(value []byte, n int) []byte

Types

type JSONEvent

type JSONEvent struct {
	Type                string                    `json:"type"`
	SideBlock           *index.SideBlock          `json:"side_block,omitempty"`
	FoundBlock          *index.FoundBlock         `json:"found_block,omitempty"`
	MainCoinbaseOutputs index.MainCoinbaseOutputs `json:"main_coinbase_outputs,omitempty"`
	Payout              *index.Payout             `json:"payout,omitempty"`
}

type JSONWebHookDiscord

type JSONWebHookDiscord struct {
	Username        string                           `json:"username,omitempty"`
	AvatarUrl       string                           `json:"avatar_url,omitempty"`
	Content         string                           `json:"content,omitempty"`
	Embeds          []JSONWebHookDiscordEmbed        `json:"embeds,omitempty"`
	Components      []JSONWebHookDiscordComponentRow `json:"components,omitempty"`
	TTS             bool                             `json:"tts,omitempty"`
	AllowedMentions *struct {
		Parse []string `json:"parse,omitempty"`
		Users []string `json:"users,omitempty"`
		Roles []string `json:"roles,omitempty"`
	} `json:"allowed_mentions,omitempty"`
}

type JSONWebHookDiscordComponentButton

type JSONWebHookDiscordComponentButton struct {
	Type  int    `json:"type"`
	Style int    `json:"style"`
	Label string `json:"label,omitempty"`
	Url   string `json:"url,omitempty"`
}

func NewJSONWebHookDiscordComponentButton

func NewJSONWebHookDiscordComponentButton(label, url string) JSONWebHookDiscordComponentButton

type JSONWebHookDiscordComponentRow

type JSONWebHookDiscordComponentRow struct {
	Type       int                                 `json:"type"`
	Components []JSONWebHookDiscordComponentButton `json:"components"`
}

type JSONWebHookDiscordEmbed

type JSONWebHookDiscordEmbed struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Url         string `json:"url,omitempty"`
	// Timestamp Time in time.RFC3339 YYYY-MM-DDTHH:MM:SS.MSSZ format
	Timestamp string  `json:"timestamp,omitempty"`
	Color     *uint64 `json:"color,omitempty"`

	Footer *struct {
		Text string `json:"text,omitempty"`
	} `json:"footer,omitempty"`

	Image *struct {
		Url string `json:"url,omitempty"`
	} `json:"image,omitempty"`
	Thumbnail *struct {
		Url string `json:"url,omitempty"`
	} `json:"thumbnail,omitempty"`

	Provider *struct {
		Name    string `json:"name,omitempty"`
		IconUrl string `json:"icon_url,omitempty"`
	} `json:"provider,omitempty"`

	Author *struct {
		Name    string `json:"name,omitempty"`
		Url     string `json:"url,omitempty"`
		IconUrl string `json:"icon_url,omitempty"`
	} `json:"author,omitempty"`

	Fields []JSONWebHookDiscordEmbedField `json:"fields,omitempty"`
}

type JSONWebHookDiscordEmbedField

type JSONWebHookDiscordEmbedField struct {
	Name   string `json:"name,omitempty"`
	Value  string `json:"value,omitempty"`
	Inline bool   `json:"inline,omitempty"`
}

type MinerInfoBlockData

type MinerInfoBlockData struct {
	ShareCount      uint64 `json:"shares"`
	UncleCount      uint64 `json:"uncles"`
	LastShareHeight uint64 `json:"last_height"`
}

type MinerInfoResult

type MinerInfoResult struct {
	Id                 uint64                                   `json:"id"`
	Address            *address.Address                         `json:"address"`
	Alias              string                                   `json:"alias,omitempty"`
	Shares             [index.InclusionCount]MinerInfoBlockData `json:"shares"`
	LastShareHeight    uint64                                   `json:"last_share_height"`
	LastShareTimestamp uint64                                   `json:"last_share_timestamp"`
}

type PoolInfoResult

type PoolInfoResult struct {
	SideChain PoolInfoResultSideChain `json:"sidechain"`
	MainChain PoolInfoResultMainChain `json:"mainchain"`
	Versions  struct {
		P2Pool VersionInfo `json:"p2pool"`
		Monero VersionInfo `json:"monero"`
	} `json:"versions"`
}

type PoolInfoResultMainChain

type PoolInfoResultMainChain struct {
	Consensus  PoolInfoResultMainChainConsensus `json:"consensus"`
	Id         types.Hash                       `json:"id"`
	CoinbaseId types.Hash                       `json:"coinbase_id"`
	Height     uint64                           `json:"height"`
	Difficulty types.Difficulty                 `json:"difficulty"`
	Reward     uint64                           `json:"reward"`
	BaseReward uint64                           `json:"base_reward"`

	NextDifficulty types.Difficulty `json:"next_difficulty"`

	// BlockTime included in Consensus
	// Deprecated
	BlockTime int `json:"block_time"`
}

type PoolInfoResultMainChainConsensus

type PoolInfoResultMainChainConsensus struct {
	BlockTime             uint64 `json:"block_time"`
	TransactionUnlockTime uint64 `json:"transaction_unlock_time"`
	MinerRewardUnlockTime uint64 `json:"miner_reward_unlock_time"`

	// HardForkSupportedVersion
	HardForkSupportedVersion uint8 `json:"hard_fork_supported_version"`
	// HardForks HardFork information for Monero known hardfork by backing p2pool
	HardForks []monero.HardFork `json:"hard_forks,omitempty"`
}

type PoolInfoResultSideChain

type PoolInfoResultSideChain struct {
	// Consensus Specifies the consensus parameters for the backing p2pool instance
	Consensus *sidechain.Consensus `json:"consensus"`

	// LastBlock Last sidechain block on database
	LastBlock *index.SideBlock `json:"last_block"`

	// SecondsSinceLastBlock
	// Prefer using max(0, time.Now().Unix()-int64(LastBlock .Timestamp)) instead
	SecondsSinceLastBlock int64 `json:"seconds_since_last_block"`

	// LastFound Last sidechain block on database found and accepted on Monero network
	LastFound *index.FoundBlock `json:"last_found"`

	Effort PoolInfoResultSideChainEffort `json:"effort"`
	Window PoolInfoResultSideChainWindow `json:"window"`

	// Found Total count of found blocks in database
	Found uint64 `json:"found"`
	// Miners Total count of miners in database
	Miners uint64 `json:"miners"`

	// Id Available on LastBlock .TemplateId
	// Deprecated
	Id types.Hash `json:"id"`

	// Height Available on LastBlock .SideHeight
	// Deprecated
	Height uint64 `json:"height"`

	// Version Available via sidechain.P2PoolShareVersion
	// Deprecated
	Version sidechain.ShareVersion `json:"version"`

	// Difficulty Available on LastBlock .Difficulty
	// Deprecated
	Difficulty types.Difficulty `json:"difficulty"`

	// CumulativeDifficulty Available on LastBlock .CumulativeDifficulty
	// Deprecated
	CumulativeDifficulty types.Difficulty `json:"cumulative_difficulty"`

	// Timestamp Available on LastBlock .Timestamp
	// Deprecated
	Timestamp uint64 `json:"timestamp"`

	// WindowSize Available on Window .Blocks
	// Deprecated
	WindowSize int `json:"window_size"`

	// MaxWindowSize Available on Consensus
	// Deprecated
	MaxWindowSize int `json:"max_window_size"`

	// BlockTime Available on Consensus
	// Deprecated
	BlockTime int `json:"block_time"`

	// UnclePenalty Available on Consensus
	// Deprecated
	UnclePenalty int `json:"uncle_penalty"`
}

type PoolInfoResultSideChainEffort

type PoolInfoResultSideChainEffort struct {
	Current    float64                                  `json:"current"`
	Average10  float64                                  `json:"average10"`
	Average50  float64                                  `json:"average"`
	Average200 float64                                  `json:"average200"`
	Last       []PoolInfoResultSideChainEffortLastEntry `json:"last"`
}

type PoolInfoResultSideChainEffortLastEntry

type PoolInfoResultSideChainEffortLastEntry struct {
	Id     types.Hash `json:"id"`
	Effort float64    `json:"effort"`
}

type PoolInfoResultSideChainWindow

type PoolInfoResultSideChainWindow struct {
	// Miners Unique miners found in window
	Miners int `json:"miners"`
	// Blocks total count of blocks in the window, including uncles
	Blocks int `json:"blocks"`
	Uncles int `json:"uncles"`

	// Top TemplateId of the window tip
	Top types.Hash `json:"top"`
	// Bottom TemplateId of the last non-uncle block in the window
	Bottom types.Hash `json:"bottom"`

	// BottomUncles TemplateId of the uncles included under the last block, if any
	BottomUncles []types.Hash `json:"bottom_uncles,omitempty"`

	Weight   types.Difficulty        `json:"weight"`
	Versions []SideChainVersionEntry `json:"versions"`
}

type PositionChart

type PositionChart struct {
	// contains filtered or unexported fields
}

func NewPositionChart

func NewPositionChart(size uint64, totalItems uint64) *PositionChart

func (*PositionChart) Add

func (p *PositionChart) Add(index int, value uint64)

func (*PositionChart) Resolution

func (p *PositionChart) Resolution() uint64

func (*PositionChart) SetIdle

func (p *PositionChart) SetIdle(idleChar byte)

func (*PositionChart) Size

func (p *PositionChart) Size() uint64

func (*PositionChart) String

func (p *PositionChart) String() string

func (*PositionChart) StringWithSeparator

func (p *PositionChart) StringWithSeparator(index int) string

func (*PositionChart) StringWithoutDelimiters

func (p *PositionChart) StringWithoutDelimiters() string

func (*PositionChart) Total

func (p *PositionChart) Total() (result uint64)

type ReleaseDataJson

type ReleaseDataJson struct {
	TagName         string    `json:"tag_name"`
	TargetCommitish string    `json:"target_commitish"`
	Name            string    `json:"name"`
	PublishedAt     time.Time `json:"published_at"`
}

type SideChainVersionEntry

type SideChainVersionEntry struct {
	Weight          types.Difficulty            `json:"weight"`
	Share           float64                     `json:"share"`
	Count           int                         `json:"count"`
	SoftwareId      p2pooltypes.SoftwareId      `json:"software_id"`
	SoftwareVersion p2pooltypes.SoftwareVersion `json:"software_version"`
	SoftwareString  string                      `json:"software_string"`
}

type SignedAction

type SignedAction struct {
	Action string              `json:"action"`
	Data   []SignedActionEntry `json:"data"`
	Realm  string              `json:"realm"`
}

func SignedActionAddWebHook

func SignedActionAddWebHook(realm, webhookType, webhookUrl string, other ...SignedActionEntry) *SignedAction

func SignedActionRemoveWebHook

func SignedActionRemoveWebHook(realm, webhookType, webhookUrlHash string, other ...SignedActionEntry) *SignedAction

func SignedActionSetMinerAlias

func SignedActionSetMinerAlias(realm, alias string) *SignedAction

func SignedActionUnsetMinerAlias

func SignedActionUnsetMinerAlias(realm string) *SignedAction

func (*SignedAction) Get

func (a *SignedAction) Get(key string) (string, bool)

func (*SignedAction) String

func (a *SignedAction) String() string

String Creates a consistent string for signing

func (*SignedAction) Verify

func (a *SignedAction) Verify(realm string, addr address.Interface, signature string) address.SignatureVerifyResult

func (*SignedAction) VerifyFallbackToZero

func (a *SignedAction) VerifyFallbackToZero(realm string, addr address.Interface, signature string) address.SignatureVerifyResult

type SignedActionEntry

type SignedActionEntry struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type TransactionLookupResult

type TransactionLookupResult struct {
	Id     types.Hash                                `json:"id"`
	Inputs index.TransactionInputQueryResults        `json:"inputs"`
	Outs   []client.Output                           `json:"outs"`
	Match  []index.TransactionInputQueryResultsMatch `json:"matches"`
}

type VersionInfo

type VersionInfo struct {
	Version          string `json:"version"`
	Timestamp        int64  `json:"timestamp"`
	Link             string `json:"link"`
	CheckedTimestamp int64  `json:"-"`
}

func (VersionInfo) ShortVersion

func (v VersionInfo) ShortVersion() p2pooltypes.SemanticVersion

Jump to

Keyboard shortcuts

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