{"modulePath":"github.com/GoPlugin/pluginV2Lib/pluginV2-relay","version":"v0.0.0-20230622090102-3f0f60f3c385","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package mercury\n\n## Variables\n\n```go\nvar File_mercury_config_proto protoreflect.FileDescriptor\n```\n\n```go\nvar File_mercury_observation_proto protoreflect.FileDescriptor\n```\n\n## Functions\n\n```go\nfunc DecodeValueInt192(s []byte) (*big.Int, error)\n```\nDecodes a value using 24-byte big endian two's complement representation. This function never panics.\n\n```go\nfunc EncodeValueInt192(i *big.Int) ([]byte, error)\n```\nEncodes a value using 24-byte big endian two's complement representation. This function never panics.\n\n```go\nfunc GetConsensusAsk(paos []ParsedAttributedObservation, f int) (*big.Int, error)\n```\nGetConsensusAsk gets the median ask\n\n```go\nfunc GetConsensusBenchmarkPrice(paos []ParsedAttributedObservation, f int) (*big.Int, error)\n```\nGetConsensusBenchmarkPrice gets the median benchmark price\n\n```go\nfunc GetConsensusBid(paos []ParsedAttributedObservation, f int) (*big.Int, error)\n```\nGetConsensusBid gets the median bid\n\n```go\nfunc GetConsensusCurrentBlock(paos []ParsedAttributedObservation, f int) (hash []byte, num int64, ts uint64, err error)\n```\nGetConsensusCurrentBlock gets the most common (mode) block hash/number/timestamps. In the event of a tie, use the lowest numerical value\n\n```go\nfunc GetConsensusMaxFinalizedBlockNum(paos []ParsedAttributedObservation, f int) (int64, error)\n```\nGetConsensusMaxFinalizedBlockNum gets the most common (mode) ConsensusMaxFinalizedBlockNum In the event of a tie, the lower number is chosen\n\n```go\nfunc GetConsensusTimestamp(paos []ParsedAttributedObservation) uint32\n```\nGetConsensusTimestamp gets the median timestamp\n\n```go\nfunc MustEncodeValueInt192(i *big.Int) []byte\n```\n\n```go\nfunc ValidateAsk(paos []ParsedAttributedObservation, f int, min, max *big.Int) error\n```\n\n```go\nfunc ValidateBenchmarkPrice(paos []ParsedAttributedObservation, f int, min, max *big.Int) error\n```\n\n```go\nfunc ValidateBid(paos []ParsedAttributedObservation, f int, min, max *big.Int) error\n```\n\n```go\nfunc ValidateCurrentBlock(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) error\n```\n\n## Types\n\n```go\ntype DataSource interface {\n\t// Observe queries the data source. Returns a value or an error. Once the\n\t// context is expires, Observe may still do cheap computations and return a\n\t// result, but should return as quickly as possible.\n\t//\n\t// More details: In the current implementation, the context passed to\n\t// Observe will time out after MaxDurationObservation. However, Observe\n\t// should *not* make any assumptions about context timeout behavior. Once\n\t// the context times out, Observe should prioritize returning as quickly as\n\t// possible, but may still perform fast computations to return a result\n\t// rather than error. For example, if Observe medianizes a number of data\n\t// sources, some of which already returned a result to Observe prior to the\n\t// context's expiry, Observe might still compute their median, and return it\n\t// instead of an error.\n\t//\n\t// Important: Observe should not perform any potentially time-consuming\n\t// actions like database access, once the context passed has expired.\n\tObserve(ctx context.Context, repts ocrtypes.ReportTimestamp, fetchMaxFinalizedBlockNum bool) (Observation, error)\n}\n```\nDataSource implementations must be thread-safe. Observe may be called by many different threads concurrently.\n\n```go\ntype Factory struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewFactory(ds DataSource, lggr logger.Logger, occ OnchainConfigCodec, rc ReportCodec) Factory\n```\n\n```go\nfunc (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error)\n```\n\n```go\ntype Fetcher interface {\n\t// FetchInitialMaxFinalizedBlockNumber should fetch the initial max\n\t// finalized block number from the mercury server.\n\tFetchInitialMaxFinalizedBlockNumber(context.Context) (*int64, error)\n}\n```\n\n```go\ntype MercuryConfigProto struct {\n\t// contains filtered or unexported fields\n}\n```\nEmpty for now; might add in future\n\n```go\nfunc (*MercuryConfigProto) Descriptor() ([]byte, []int)\n```\nDeprecated: Use MercuryConfigProto.ProtoReflect.Descriptor instead.\n\n```go\nfunc (*MercuryConfigProto) ProtoMessage()\n```\n\n```go\nfunc (x *MercuryConfigProto) ProtoReflect() protoreflect.Message\n```\n\n```go\nfunc (x *MercuryConfigProto) Reset()\n```\n\n```go\nfunc (x *MercuryConfigProto) String() string\n```\n\n```go\ntype MercuryObservationProto struct {\n\tTimestamp uint32 `protobuf:\"varint,1,opt,name=timestamp,proto3\" json:\"timestamp,omitempty\"`\n\t// Prices\n\tBenchmarkPrice []byte `protobuf:\"bytes,2,opt,name=benchmarkPrice,proto3\" json:\"benchmarkPrice,omitempty\"`\n\tBid            []byte `protobuf:\"bytes,3,opt,name=bid,proto3\" json:\"bid,omitempty\"`\n\tAsk            []byte `protobuf:\"bytes,4,opt,name=ask,proto3\" json:\"ask,omitempty\"`\n\t// All three prices must be valid, or none are (they all should come from one API query and hold invariant bid \u003c= bm \u003c= ask)\n\tPricesValid bool `protobuf:\"varint,5,opt,name=pricesValid,proto3\" json:\"pricesValid,omitempty\"`\n\t// Current block\n\tCurrentBlockNum       int64  `protobuf:\"varint,6,opt,name=currentBlockNum,proto3\" json:\"currentBlockNum,omitempty\"`\n\tCurrentBlockHash      []byte `protobuf:\"bytes,7,opt,name=currentBlockHash,proto3\" json:\"currentBlockHash,omitempty\"`\n\tCurrentBlockTimestamp uint64 `protobuf:\"varint,8,opt,name=currentBlockTimestamp,proto3\" json:\"currentBlockTimestamp,omitempty\"`\n\t// All three block observations must be valid, or none are (they all come from the same block)\n\tCurrentBlockValid bool `protobuf:\"varint,9,opt,name=currentBlockValid,proto3\" json:\"currentBlockValid,omitempty\"`\n\t// MaxFinalizedBlockNumber comes from previous report when present and is\n\t// only observed from mercury server when previous report is nil\n\tMaxFinalizedBlockNumber      int64 `protobuf:\"varint,10,opt,name=maxFinalizedBlockNumber,proto3\" json:\"maxFinalizedBlockNumber,omitempty\"`\n\tMaxFinalizedBlockNumberValid bool  `protobuf:\"varint,11,opt,name=maxFinalizedBlockNumberValid,proto3\" json:\"maxFinalizedBlockNumberValid,omitempty\"`\n\t// contains filtered or unexported fields\n}\n```\nTODO: what about different report formats for different clients?\n\n```go\nfunc (*MercuryObservationProto) Descriptor() ([]byte, []int)\n```\nDeprecated: Use MercuryObservationProto.ProtoReflect.Descriptor instead.\n\n```go\nfunc (x *MercuryObservationProto) GetAsk() []byte\n```\n\n```go\nfunc (x *MercuryObservationProto) GetBenchmarkPrice() []byte\n```\n\n```go\nfunc (x *MercuryObservationProto) GetBid() []byte\n```\n\n```go\nfunc (x *MercuryObservationProto) GetCurrentBlockHash() []byte\n```\n\n```go\nfunc (x *MercuryObservationProto) GetCurrentBlockNum() int64\n```\n\n```go\nfunc (x *MercuryObservationProto) GetCurrentBlockTimestamp() uint64\n```\n\n```go\nfunc (x *MercuryObservationProto) GetCurrentBlockValid() bool\n```\n\n```go\nfunc (x *MercuryObservationProto) GetMaxFinalizedBlockNumber() int64\n```\n\n```go\nfunc (x *MercuryObservationProto) GetMaxFinalizedBlockNumberValid() bool\n```\n\n```go\nfunc (x *MercuryObservationProto) GetPricesValid() bool\n```\n\n```go\nfunc (x *MercuryObservationProto) GetTimestamp() uint32\n```\n\n```go\nfunc (*MercuryObservationProto) ProtoMessage()\n```\n\n```go\nfunc (x *MercuryObservationProto) ProtoReflect() protoreflect.Message\n```\n\n```go\nfunc (x *MercuryObservationProto) Reset()\n```\n\n```go\nfunc (x *MercuryObservationProto) String() string\n```\n\n```go\ntype ObsResult[T any] struct {\n\tVal T\n\tErr error\n}\n```\n\n```go\ntype Observation struct {\n\tBenchmarkPrice        ObsResult[*big.Int]\n\tBid                   ObsResult[*big.Int]\n\tAsk                   ObsResult[*big.Int]\n\tCurrentBlockNum       ObsResult[int64]\n\tCurrentBlockHash      ObsResult[[]byte]\n\tCurrentBlockTimestamp ObsResult[uint64]\n\t// MaxFinalizedBlockNumber comes from previous report when present and is\n\t// only observed from mercury server when previous report is nil\n\tMaxFinalizedBlockNumber ObsResult[int64]\n}\n```\n\n```go\ntype OffchainConfig struct{}\n```\n\n```go\nfunc DecodeOffchainConfig(b []byte) (o OffchainConfig, err error)\n```\n\n```go\nfunc (c OffchainConfig) Encode() []byte\n```\n\n```go\ntype OnchainConfig struct {\n\t// applies to all values: price, bid and ask\n\tMin *big.Int\n\tMax *big.Int\n}\n```\n\n```go\ntype OnchainConfigCodec interface {\n\tEncode(OnchainConfig) ([]byte, error)\n\tDecode([]byte) (OnchainConfig, error)\n}\n```\n\n```go\ntype ParsedAttributedObservation struct {\n\tTimestamp uint32\n\tObserver  commontypes.OracleID\n\n\tBenchmarkPrice *big.Int\n\tBid            *big.Int\n\tAsk            *big.Int\n\t// All three prices must be valid, or none are (they all should come from one API query and hold invariant bid \u003c= bm \u003c= ask)\n\tPricesValid bool\n\n\tCurrentBlockNum       int64 // inclusive; current block\n\tCurrentBlockHash      []byte\n\tCurrentBlockTimestamp uint64\n\t// All three block observations must be valid, or none are (they all come from the same block)\n\tCurrentBlockValid bool\n\n\t// MaxFinalizedBlockNumber comes from previous report when present and is\n\t// only observed from mercury server when previous report is nil\n\t//\n\t// MaxFinalizedBlockNumber will be -1 if there is none\n\tMaxFinalizedBlockNumber      int64\n\tMaxFinalizedBlockNumberValid bool\n}\n```\n\n```go\ntype ReportCodec interface {\n\t// BuildReport Implementers may assume that there is at most one\n\t// ParsedAttributedObservation per observer, and that all observers are\n\t// valid. However, observation values, timestamps, etc... should all be\n\t// treated as untrusted.\n\tBuildReport(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) (ocrtypes.Report, error)\n\n\t// MaxReportLength Returns the maximum length of a report based on n, the number of oracles.\n\t// The output of BuildReport must respect this maximum length.\n\tMaxReportLength(n int) (int, error)\n\n\t// CurrentBlockNumFromReport returns the median current block number from a report\n\tCurrentBlockNumFromReport(types.Report) (int64, error)\n}\n```\nReportCodec All functions on ReportCodec should be pure and thread-safe. Be careful validating and parsing any data passed.\n\n```go\ntype StandardOnchainConfigCodec struct{}\n```\nStandardOnchainConfigCodec provides a mercury-specific implementation of OnchainConfigCodec.\n\nAn encoded onchain config is expected to be in the format \\\u003cversion\u003e\\\u003cmin\u003e\\\u003cmax\u003e where version is a uint8 and min and max are in the format returned by EncodeValueInt192.\n\n```go\nfunc (StandardOnchainConfigCodec) Decode(b []byte) (OnchainConfig, error)\n```\n\n```go\nfunc (StandardOnchainConfigCodec) Encode(c OnchainConfig) ([]byte, error)\n```\n\n```go\ntype Transmitter interface {\n\tFetcher\n\t// NOTE: Mercury doesn't actually transmit on-chain, so there is no\n\t// \"contract\" involved with the transmitter.\n\t// - Transmit should be implemented and send to Mercury server\n\t// - LatestConfigDigestAndEpoch is a stub method, does not need to do anything\n\t// - FromAccount() should return CSA public key\n\tocrtypes.ContractTransmitter\n}\n```\n\n","path":"github.com/GoPlugin/pluginV2Lib/pluginV2-relay/pkg/reportingplugins/mercury","name":"mercury","synopsis":"","isRedistributable":true}
