common

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 18 Imported by: 4

Documentation

Overview

Copyright (c) of parts are held by the various contributors (see the CLA) Licensed under the MIT License. See LICENSE file in the project root for full license information.

Copyright (c) of parts are held by the various contributors (see the CLA) Licensed under the MIT License. See LICENSE file in the project root for full

Copyright (c) of parts are held by the various contributors (see the CLA) Licensed under the MIT License. See LICENSE file in the project root for full license information.

Copyright (c) of parts are held by the various contributors (see the CLA) Licensed under the MIT License. See LICENSE file in the project root for full license information.

Index

Constants

View Source
const (
	DefaultInitialInterval     = 500 * time.Millisecond
	DefaultRandomizationFactor = 0.5
	DefaultMultiplier          = 1.5
	DefaultMaxInterval         = 2 * time.Second
	DefaultMaxElapsedTime      = 10 * time.Second // max 10 seconds
)

Default values for PegExponentialBackOff.

View Source
const (
	MainNetwork     = "MainNet"
	TestNetwork     = "TestNet-pM2"
	UnitTestNetwork = "unit-test" // Only used for unit tests

	MainNetworkRCD = MainNetwork + "RCD"
	TestNetworkRCD = TestNetwork + "RCD"
)
View Source
const (
	TransactionChainTag = "Transactions"
	MinerChainTag       = "Miners"
	OPRChainTag         = "OraclePriceRecords"
)
View Source
const (
	ConfigCoordinatorListen            = "Miner.MiningCoordinatorPort"
	ConfigCoordinatorLocation          = "Miner.MiningCoordinatorHost"
	ConfigCoordinatorSecret            = "Miner.CoordinatorSecret"
	ConfigCoordinatorUseAuthentication = "Miner.UseCoordinatorAuthentication"
	ConfigSubmissionCutOff             = "Miner.SubmissionCutOff"

	ConfigMinerDBPath      = "Database.MinerDatabase"
	ConfigMinerDBType      = "Database.MinerDatabaseType"
	ConfigPegnetNodeDBPath = "Database.NodeDatabase"

	ConfigAPIPort          = "API.APIPort"
	ConfigControlPanelPort = "API.ControlPanelPort"

	ConfigCoinbaseAddress = "Miner.CoinbaseAddress"
	ConfigPegnetNetwork   = "Miner.Network"

	ConfigCoinMarketCapKey = "Oracle.CoinMarketCapKey"
	Config1ForgeKey        = "Oracle.1ForgeKey"

	// ConfigStaleDuration determines how old a quote is allowed to be and still be
	// acceptable
	ConfigStaleDuration = "Oracle.StaleQuoteDuration"
)

Config names

View Source
const (
	ZeroHash = "0000000000000000000000000000000000000000000000000000000000000000"
)

Variables

View Source
var (
	// ActivationHeights signals the network is active and all miners can begin.
	// This is the signal that pegnet has launched.
	ActivationHeights = map[string]int64{

		MainNetwork: 206422,
		TestNetwork: 0,
	}

	// GradingHeights indicates the OPR version, which dictates the grading and OPR format.
	// When we switch formats. The activation height indicates the block that grading changes.
	// So if the grading change is on block 100, then the entries in block 100 will be using the
	// new grading format.
	GradingHeights = map[string]func(height int64) uint8{
		MainNetwork: func(height int64) uint8 {

			if height < V2GradingActivation {
				return 1
			}
			if height < FloatingPegPriceActivation {
				return 2
			}
			if height < V4HeightActivation {
				return 3
			}
			return 4
		},
		TestNetwork: func(height int64) uint8 {
			if height < 96145 {
				return 1
			}

			return 2
		},
	}

	V2GradingActivation int64 = 210330

	// FloatingPegPriceActivation indicates when to place the PEG price into
	// the opr record from the floating exchange price.
	// Estimated to be  Dec 9, 2019, 17:00 UTC
	FloatingPegPriceActivation int64 = 222270

	// V4HeightActivation indicates the activation of additional currencies and ecdsa keys.
	// Estimated to be  Feb 12, 2020, 18:00 UTC
	V4HeightActivation int64 = 231620
)
View Source
var (
	PEGAsset = []string{
		"PEG",
	}

	CurrencyAssets = []string{
		"USD",
		"EUR",
		"JPY",
		"GBP",
		"CAD",
		"CHF",
		"INR",
		"SGD",
		"CNY",
		"HKD",

		"KRW",

		"BRL",
		"PHP",
		"MXN",
	}

	CommodityAssets = []string{
		"XAU",
		"XAG",
		"XPD",
		"XPT",
	}

	CryptoAssets = []string{
		"XBT",
		"ETH",
		"LTC",
		"RVN",
		"XBC",
		"FCT",
		"BNB",
		"XLM",
		"ADA",
		"XMR",
		"DASH",
		"ZEC",
		"DCR",
	}

	V4CurrencyAdditions = []string{
		"AUD",
		"NZD",
		"SEK",
		"NOK",
		"RUB",
		"ZAR",
		"TRY",
	}

	V4CryptoAdditions = []string{
		"EOS",
		"LINK",
		"ATOM",
		"BAT",
		"XTZ",
	}

	AllAssets = MergeLists(PEGAsset, CurrencyAssets, CommodityAssets, CryptoAssets, V4CurrencyAdditions, V4CryptoAdditions)
	AssetsV1  = MergeLists(PEGAsset, CurrencyAssets, CommodityAssets, CryptoAssets)
	// This is with the PNT instead of PEG. Should never be used unless absolutely necessary.
	//
	// Deprecated: Was used for version 1 before PNT -> PEG
	AssetsV1WithPNT = MergeLists([]string{"PNT"}, SubtractFromSet(AssetsV1, "PEG"))
	// Version One, subtract 2 assets
	AssetsV2 = SubtractFromSet(AssetsV1, "XPD", "XPT")

	// Additional assets to V2 set
	AssetsV4 = MergeLists(AssetsV2, V4CurrencyAdditions, V4CryptoAdditions)
)
View Source
var (
	// Pegnet Burn Addresses
	BurnAddresses = map[string]string{
		MainNetwork:    "EC2BURNFCT2PEGNETooo1oooo1oooo1oooo1oooo1oooo19wthin",
		TestNetwork:    "EC2BURNFCT2TESTxoooo1oooo1oooo1oooo1oooo1oooo1EoyM6d",
		MainNetworkRCD: "37399721298d77984585040ea61055377039a4c3f3e2cd48c46ff643d50fd64f",
		TestNetworkRCD: "37399721298d8b92934b4f767a56be38ad8a30cf0b7ed9d9fd2eb0919905c4af",
	}
)
View Source
var DebugFCTaddresses [][]string = [][]string{
	{"Fs33uWZaASt8iUqDRJZBkgBFykpwajzuPAj6gUEdReqHoCSk3WCt", "FA291Sdfzz57f3RTv8kmi9g1HrZ4Y1BnYXwVNhSDkf9Nyfta1f4o"},
	{"Fs23XpqaDHWLcDQe7sFovB3CqqK7VLG96qVRpVEXZ52ZutGCVZU7", "FA2Bbn2qvSXcgeSLLsevWg1oNZjHn39Xo1Rn2iyZDLuzC6SfFhj6"},
	{"Fs2enTYpkUH4EGbwtq3qJDfEQTfkYraHr8hZ1swPsC3Sumg1FAaz", "FA2C3nch6NiGURuh3j4GaKeawHGmMmaTTe6r4xSmpp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Rk2fqfRdUQqriBW", "FA2yhhCMxa2v6Y5kPU1P9djbFwQdTPcBLkGvvF5U2pmqf5cqkV21"},
	{"Fs2psHU64RphmcL6AzZAQXhQGKzM1xCiHxsj6BtDUE3fKY22u6yc", "FA31sttHRuVrgUxE5Ck69dZf1Mo4XmeAEYyq5TPQHrvbYEgrVpSz"},
	{"Fs2FoqwVtpi3X5N5w9yKsELg6KwWq1Vr3Vo1CxsKekspavXaWVUz", "FA3B4YAssKzQitEXDDzBqow2y9MfVgdvUF2znKWx2DJALXuJefX9"},
	{"Fs1zuNwQYBS6eQdj3ZYSLMjPu9j2xZG3X3auC8BuKKsJj9yt31nn", "FA3CjY8UW8H2Chui5HDhEALR1eBDLcyHCMBCvpW39U2nczikNvNF"},
	{"Fs2y7HDD1mnEX4hBeU87kUpJuE7WTrdEhTEHdMiQMQgj49a6uqQs", "FA3NYYvFVTCaiA8XpARXvFwZfvxnVhJ4FrxVVmCHNjXiaqZUYc28"},
	{"Fs2dFa1noAxL8Zb4GReRsHuf1o4xnbPDrvMRfoKu9cFUELiuEVpP", "FA3P45WgAxNhtzQ1mWEooCaLzVp8qXSFV5MZH74PLupjL6HZsGaV"},
	{"Fs2kmMon4z5UKu6vbgcABp3PA8ZBSQMiD7e4X4EQHpafdZUD6q76", "FA3inqojrQ1hPh6WWZQDegabBA49cu4R25p6XaKKvVYFmbCqyvRS"},
	{"Fs1X5uzwEtNtjX6xoDnhcsfmSfurDk8A8rV49FbAe9QsJeHEeee5", "FA3qqDA1wzyhZ1ppNgjyfvFrEDw9RtKoDHofUDrqJe7Y7r5xqEBD"}}
View Source
var GlobalExitHandler = NewExitHandler()
View Source
var PegAssetNames []string
View Source
var PointMultiple float64 = 100000000
View Source
var TestPegAssetNames []string

Functions

func Abs added in v0.1.0

func Abs(v int) int

func AssetListContains added in v0.1.0

func AssetListContains(assetList []string, asset string) bool

func AssetListContainsCaseInsensitive added in v0.1.0

func AssetListContainsCaseInsensitive(assetList []string, asset string) bool

AssetListContainsCaseInsensitive is for when using user input. It's helpful for the cmd line.

func CheckAndPanic added in v0.1.0

func CheckAndPanic(e error)

func CheckPrefix added in v0.1.0

func CheckPrefix(name string) bool

CheckPrefix() Check the prefix for either network type.

func ComputeChainIDFromFields added in v0.1.0

func ComputeChainIDFromFields(fields [][]byte) []byte

ComputeChainIDFromFields Takes the binary fields that define a chainID and hashes them together to create the ChainID expected by the APIs. These fields are treated as binary, but could be simple text, like: "Bob's" "Favorite" "Chain"

func ComputeChainIDFromStrings added in v0.1.0

func ComputeChainIDFromStrings(fields []string) []byte

ComputeChainIDFromStrings Take a set of strings, and compute the chainID. If you have binary fields, you can call factom.ComputeChainIDFromFields directly.

func ConvertAnyFactomAdrToRaw added in v0.1.0

func ConvertAnyFactomAdrToRaw(userFAddr string) ([]byte, error)

Convert a User facing Factoid or Entry Credit address or their Private Key representations to the regular form. Note validation must be done separately!

func ConvertFCTtoAllPegNetAssets added in v0.1.0

func ConvertFCTtoAllPegNetAssets(userFctAddr string) (assets []string, err error)

Convert a User facing FCT address to all of its PegNet asset token User facing forms.

func ConvertFCTtoPegNetAsset added in v0.1.0

func ConvertFCTtoPegNetAsset(network string, asset string, userFAdr string) (PegNetAsset string, err error)

func ConvertFCTtoRaw added in v0.1.0

func ConvertFCTtoRaw(userFAddr string) (raw []byte, err error)

Convert a User facing Factoid address to the raw form. We do what validation we can here, and return an error if the Factoid address is not valid

func ConvertPegNetAssetToRaw added in v0.1.0

func ConvertPegNetAssetToRaw(adr string) (prefix string, rawAdr []byte, err error)

ConvertPegTAddrToRaw() Convert a human/wallet address to the raw underlying address. Verifies the checksum and the validity of the prefix. Returns the prefix, the raw address, and error.

func ConvertRawToEC added in v0.1.0

func ConvertRawToEC(addr []byte) string

Convert Factoid and Entry Credit addresses to their more user friendly and human readable formats.

Creates the binary form. Just needs the conversion to base58 for display.

func ConvertRawToFCT added in v0.1.0

func ConvertRawToFCT(addr []byte) string

Convert Factoid and Entry Credit addresses to their more user friendly and human readable formats.

Creates the binary form. Just needs the conversion to base58 for display.

func ConvertRawToPegNetAsset added in v0.1.0

func ConvertRawToPegNetAsset(prefix string, adr []byte) (string, error)

ConvertRawToPegNetAsset() Converts a raw RCD1 address into a wallet friendly address that can be used to convert assets, check balances, and send tokens. While the underlying private key can be used to hold Factoids or any token in the PegNet, users need addresses that create a barrier to mistakes that can lead to sending the wrong tokens to the wrong addresses

func DetailError added in v0.1.0

func DetailError(e error) error

func FindIndexInStringArray added in v0.1.0

func FindIndexInStringArray(haystack []string, needle string) int

func FormatDiff added in v0.1.0

func FormatDiff(diff uint64, precision uint) string

FormatDiff returns a human readable string in scientific notation

func FormatGrade added in v0.1.0

func FormatGrade(grade float64, precision uint) string

FormatGrade returns a human readable string in scientific notation

func GetNetwork added in v0.1.0

func GetNetwork(network string) (string, error)

func GetPrefix added in v0.1.0

func GetPrefix(address string) (length int, prefix string)

func LoadConfigNetwork added in v0.1.0

func LoadConfigNetwork(c *config.Config) (string, error)

LoadConfigNetwork handles the different casings of `MainNet`.

So: `mainnet`, `Mainnet`, and other stuff is all valid

func MergeLists added in v0.1.0

func MergeLists(assets ...[]string) []string

func NetworkActive added in v0.1.0

func NetworkActive(network string, height int64) bool

NetworkActive returns true if the network height is above the activation height. If we are below it, the network is not yet active.

func NewUnitTestConfig added in v0.1.0

func NewUnitTestConfig() *config.Config

func OPRVersion added in v0.2.0

func OPRVersion(network string, height int64) uint8

OPRVersion returns the OPR version for a given height and network. If an OPR has a different version, it is invalid. The version dictates the grading algo to use and the OPR format.

func PegExponentialBackOff added in v0.1.0

func PegExponentialBackOff() *backoff.ExponentialBackOff

PegExponentialBackOff creates an instance of ExponentialBackOff

func PegnetBurnAddress added in v0.1.0

func PegnetBurnAddress(network string) string

func PullValue added in v0.1.0

func PullValue(line string, howMany int) string

func RandomByteSliceOfLen added in v0.1.0

func RandomByteSliceOfLen(sliceLen int) []byte

RandomByteSliceOfLen() Returns a random set of bytes of a given length

func SetTestingVersion added in v0.2.0

func SetTestingVersion(version uint8)

SetTestingHeight is used for unit test

func ShortenPegnetFilePath added in v0.1.0

func ShortenPegnetFilePath(path, acc string, depth int) (trimmed string)

ShortenPegnetFilePath takes a long path url to pegnet, and shortens it:

"/home/billy/go/src/github.com/pegnet/pegnet/opr.go" -> "pegnet/opr.go"
This is nice for errors that print the file + line number

	!! Only use for error printing !!

func SubtractFromSet added in v0.2.0

func SubtractFromSet(set []string, sub ...string) []string

func ValidIdentity added in v0.2.0

func ValidIdentity(identity string) error

func ValidatePegNetAssetAddress added in v0.1.0

func ValidatePegNetAssetAddress(adr string) error

ValidatePegNetAssetAddress() Check that the given human/wallet PegNet address is valid.

Types

type DefaultConfigOptions added in v0.1.0

type DefaultConfigOptions struct {
}

DefaultConfigOptions gives us the ability to add configurable settings that really should not be tinkered with often. Making the config file long and overly complex is just daunting to new users. Many of the settings that will likely never be touched can be inclued in here.

func NewDefaultConfigOptionsProvider added in v0.1.0

func NewDefaultConfigOptionsProvider() *DefaultConfigOptions

func (*DefaultConfigOptions) Load added in v0.1.0

func (c *DefaultConfigOptions) Load() (map[string]string, error)

type ExitHandler added in v0.2.0

type ExitHandler struct {
	ClosingFunctions []func() error
}

func NewExitHandler added in v0.2.0

func NewExitHandler() *ExitHandler

func (*ExitHandler) AddCancel added in v0.2.0

func (e *ExitHandler) AddCancel(cancel context.CancelFunc)

func (*ExitHandler) AddExit added in v0.2.0

func (e *ExitHandler) AddExit(f func() error)

func (*ExitHandler) Close added in v0.2.0

func (e *ExitHandler) Close()

type FakeMonitor added in v0.1.0

type FakeMonitor struct {
	*Monitor
}

FakeMonitor can be used in unit tests

func NewFakeMonitor added in v0.1.0

func NewFakeMonitor() *FakeMonitor

func (*FakeMonitor) FakeNotify added in v0.1.0

func (f *FakeMonitor) FakeNotify(dbht int, minute int)

func (*FakeMonitor) FakeNotifyEvt added in v0.1.0

func (f *FakeMonitor) FakeNotifyEvt(fds MonitorEvent)

type IMonitor added in v0.1.0

type IMonitor interface {
	NewListener() <-chan MonitorEvent
	NewErrorListener() <-chan error
	SetTimeout(timeout time.Duration)
}

type Monitor added in v0.1.0

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

Monitor polls a factomd node and sends alerts whenever the block height or minute changes

func GetMonitor added in v0.1.0

func GetMonitor() *Monitor

GetMonitor returns the singleton instance of the Factomd Monitor

func (*Monitor) NewErrorListener added in v0.1.0

func (f *Monitor) NewErrorListener() <-chan error

NewErrorListener spawns a new listening channel that will receive errors that have occurred

func (*Monitor) NewListener added in v0.1.0

func (f *Monitor) NewListener() <-chan MonitorEvent

NewListener spawns a new listening channel that will receive updates of height or minute changes

func (*Monitor) SetTimeout added in v0.1.0

func (f *Monitor) SetTimeout(timeout time.Duration)

SetTimeout sets a new timeout duration. If the monitor is unable to connect to the factomd node within the duration, an error is sent to all error listeners.

type MonitorEvent added in v0.1.0

type MonitorEvent struct {
	Minute int64 `json:"minute"`
	Dbht   int32 `json:"dbht"`
}

MonitorEvent is the Data sent to all listeners when being notified

type NetworkType added in v0.1.0

type NetworkType string

type UnitTestConfigProvider added in v0.1.0

type UnitTestConfigProvider struct {
	Data string
}

UnitTestConfigProvider is only used in unit tests.

This way we don't have to deal with pathing to find the
`defaultconfig.ini`.

func NewUnitTestConfigProvider added in v0.1.0

func NewUnitTestConfigProvider() *UnitTestConfigProvider

func (*UnitTestConfigProvider) Load added in v0.1.0

func (this *UnitTestConfigProvider) Load() (map[string]string, error)

Jump to

Keyboard shortcuts

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