nameindexer

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

nameindexer

GitHub license GoDoc Go Report Card

This repository is responsible for creating and managing indexable names for objects.

The index string format is:

subject + date + time + primaryFiller + source + dataType + secondaryFiller + producer + optional

where:

  • subject is the NFTDID of the data's subject
    • chainId + contractAddress + tokenID
    • chainId is a 16-character hexadecimal string representing the uint64 chain ID
    • contractAddress is a 40-character hexadecimal string representing the contract address
    • tokenID is an 8-character hexadecimal string representing the uint32 token ID
  • date is calculated as 999999 - (*10000 + *100 + )
  • time is the time in UTC in the format HHMMSS
  • primaryFiller is a constant string of length 2
  • source is a 40-character hexadecimal string representing the source address
  • dataType is the data type left-padded with ! or truncated to 20 characters
  • secondaryFiller is a constant string of length 2
  • producer is the NFTDID of the data's producer
    • chainId + contractAddress + tokenID
    • chainId is a 16-character hexadecimal string representing the uint64 chain ID
    • contractAddress is a 40-character hexadecimal string representing the contract address
    • tokenID is an 8-character hexadecimal string representing the uint32 token ID
  • optional is an optional string that can be appended to the index

Development

Use make to manage the project building, testing, and linting.

> make help

Specify a subcommand:

  build                Build the code
  clean                Clean the project binaries
  tidy                 tidy the go modules
  test                 Run the all tests
  lint                 Run the linter
  format               Run the linter with fix
  migration            Generate migration file specify name with name=your_migration_name
  tools                Install all tools
  tools-golangci-lint  Install golangci-lint
  tools-migration      Install migration tool

License

Apache 2.0

Documentation

Overview

Package nameindexer provides utilities for creating, decoding, storing, and searching indexable names.

Index

Constants

View Source
const (
	// FillerStatus is the filler value for status type cloud events.
	FillerStatus = "A"
	// FillerFingerprint is the filler value for fingerprint type cloud events.
	FillerFingerprint = "E"
	// FillerVerifiableCredential is the filler value for verifiable credential type cloud events.
	FillerVerifiableCredential = "V"
	// FillerUnknown is the filler value for unknown type cloud events.
	FillerUnknown = "U"
)
View Source
const (
	// DateLength is the length of the date part of an index string.
	DateLength = 6
	// FillerLength is the length of the filler parts of an index string.
	FillerLength = 2
	// DataTypeLength is the length of the data type part of an index string.
	DataTypeLength = 20
	// DIDLength is the length of the DID part of an index string.
	DIDLength = 64
	// TimeLength is the length of the time part of an index string.
	TimeLength = 6
	// AddressLength is the length of an ethereum address part of an index string.
	AddressLength = 40

	// TotalLength is the total length of an index string.
	TotalLength = DIDLength + DateLength + FillerLength + DataTypeLength + TimeLength + AddressLength + DIDLength + FillerLength

	// DateMax is the maximum value used for date calculations in the index.
	DateMax = 999999
	// HhmmssFormat is the time format used in the index string.
	HhmmssFormat = "150405"

	// DefaultPrimaryFiller is the default filler value between the date and data type.
	DefaultPrimaryFiller = "MM"
	// DefaultSecondaryFiller is the default filler value between the subject and time.
	DefaultSecondaryFiller = "00"

	DataTypePadding = "!"
)

Variables

This section is empty.

Functions

func CloudEventToIndexKey added in v0.1.0

func CloudEventToIndexKey(cloudHdr *cloudevent.CloudEventHeader) string

CloudEventToIndex converts a CloudEventHeader to a Index.

func CloudTypeToFiller added in v0.0.8

func CloudTypeToFiller(eventTypes string) string

CloudTypeToFiller converts a cloud event type to a filler string.

func DecodeAddress added in v0.0.8

func DecodeAddress(encodedAddress string) (common.Address, error)

DecodeAddress decodes an ethereum address from a string without the 0x prefix.

func DecodeDataType added in v0.0.8

func DecodeDataType(dataType string) string

DecodeDataType decodes a data type string by removing padding.

func DecodeDateAndTime added in v0.0.8

func DecodeDateAndTime(datePart string, timePart string) (time.Time, error)

func DecodeNFTDIDIndex added in v0.0.8

func DecodeNFTDIDIndex(indexNFTDID string) (cloudevent.NFTDID, error)

DecodeNFTDIDIndex decodes an NFTDID string into a cloudevent.NFTDID struct.

func DecodePrimaryFiller added in v0.0.8

func DecodePrimaryFiller(primaryFiller string) string

DecodePrimaryFiller decodes a primary filler string by removing padding.

func DecodeProducer added in v0.0.8

func DecodeProducer(producer string) string

DecodeProducer decodes a producer string by removing padding.

func DecodeSecondaryFiller added in v0.0.8

func DecodeSecondaryFiller(secondaryFiller string) string

DecodeSecondaryFiller decodes a secondary filler string by removing padding.

func DecodeSource added in v0.0.8

func DecodeSource(source string) string

DecodeSource decodes a source string by removing padding

func DecodeSubject

func DecodeSubject(subject string) string

DecodeSubject decodes a subject string by removing padding.

func EncodeAddress added in v0.0.8

func EncodeAddress(address common.Address) string

EncodeAddress encodes an ethereum address without the 0x prefix.

func EncodeDataType added in v0.0.8

func EncodeDataType(dataType string) string

EncodeDataType pads the data type with `*` if shorter than required. It truncates the data type if longer than required.

func EncodeDate added in v0.0.8

func EncodeDate(date time.Time) (string, error)

EncodeDate encodes a time.Time into a string.

func EncodeIndex

func EncodeIndex(origIndex *Index) (string, error)

EncodeIndex creates an indexable name string from the Index struct. This function will modify the index to have correctly padded values. The index string format is:

subject + date + time + primaryFiller + source + dataType + secondaryFiller + producer + optional

where:

  • subject is the NFTDID of the data's subject -- chainId + contractAddress + tokenID -- chainId is a 16-character hexadecimal string representing the uint64 chain ID -- contractAddress is a 40-character hexadecimal string representing the contract address -- tokenID is an 8-character hexadecimal string representing the uint32 token ID
  • date is calculated as 999999 - (<two-digit-year>*10000 + <two-digit-month>*100 + <two-digit-day>)
  • time is the time in UTC in the format HHMMSS
  • primaryFiller is a constant string of length 2
  • source is a 40-character hexadecimal string representing the source address
  • dataType is the data type left-padded with `!` or truncated to 20 characters
  • secondaryFiller is a constant string of length 2
  • producer is the NFTDID of the data's producer -- chainId + contractAddress + tokenID -- chainId is a 16-character hexadecimal string representing the uint64 chain ID -- contractAddress is a 40-character hexadecimal string representing the contract address -- tokenID is an 8-character hexadecimal string representing the uint32 token ID
  • optional is an optional string that can be appended to the index

func EncodeNFTDID added in v0.0.8

func EncodeNFTDID(did cloudevent.NFTDID) string

EncodeNFTDID encodes an NFTDID struct into an indexable string. This format is different from the standard NFTDID.

func EncodePrimaryFiller added in v0.0.8

func EncodePrimaryFiller(primaryFiller string) string

EncodePrimaryFiller pads the primary filler with `M` if shorter than required. It truncates the primary filler if longer than required.

func EncodeProducer added in v0.0.8

func EncodeProducer(producer string) string

EncodeProducer pads the producer with `!` if shorter than required. It truncates the producer if longer than required.

func EncodeSecondaryFiller added in v0.0.8

func EncodeSecondaryFiller(secondaryFiller string) string

EncodeSecondaryFiller pads the secondary filler with `0` if shorter than required. It truncates the secondary filler if longer than required.

func EncodeSource added in v0.0.8

func EncodeSource(source string) string

EncodeSource pads the source with `!` if shorter than required. It truncates the source if longer than required.

func EncodeSubject added in v0.0.8

func EncodeSubject(subject string) string

EncodeSubject pads the subject with `!` if shorter than required. It truncates the subject if longer than required.

func EncodeTime added in v0.0.8

func EncodeTime(ts time.Time) string

EncodeTime encodes a time.Time into a string.

func FillerToCloudType added in v0.0.8

func FillerToCloudType(filler string) string

FillerToCloudType converts a filler string to a cloud event type.

func ValidateDate added in v0.0.8

func ValidateDate(date time.Time) error

ValidateDate validates the year of a timestamp is between 2000 and 2099.

Types

type Index

type Index struct {
	// Subject is the subject of the data represented by the index.
	Subject string
	// Timestamp is the full timestamp used for date and time.
	Timestamp time.Time
	// PrimaryFiller is the filler value between the date and data type, typically "MM". If empty, defaults to "MM".
	PrimaryFiller string
	// DataType is the type of data, left-padded with @ or truncated to 20 characters.
	DataType string
	// Source is the source of the data represented by the index.
	Source string `json:"source"`
	// Producer is the producer of the data represented by the index.
	Producer string `json:"producer"`
	// SecondaryFiller is the filler value between the subject and time, typically "00". If empty, defaults to "00".
	SecondaryFiller string
	// Optional data for additional metadata
	Optional string `json:"optional"`
}

Index represents the components of a decoded index.

func DecodeIndex

func DecodeIndex(index string) (*Index, error)

DecodeIndex decodes an index string into its constituent parts. It returns an Index struct containing the decoded components. The index string format is expected to be:

subject + date + time + primaryFiller + source + dataType + secondaryFiller  + producer + optional

where:

  • subject is the NFTDID of the data's subject -- chainId + contractAddress + tokenID -- chainId is a 16-character hexadecimal string representing the uint64 chain ID -- contractAddress is a 40-character hexadecimal string representing the contract address -- tokenID is an 8-character hexadecimal string representing the uint32 token ID
  • date is calculated as 999999 - (<two-digit-year>*10000 + <two-digit-month>*100 + <two-digit-day>)
  • time is the time in UTC in the format HHMMSS
  • primaryFiller is a constant string of length 2
  • source is a 40-character hexadecimal string representing the source address
  • dataType is the data type left-padded with `!` or truncated to 20 characters
  • secondaryFiller is a constant string of length 2
  • producer is the NFTDID of the data's producer -- chainId + contractAddress + tokenID -- chainId is a 16-character hexadecimal string representing the uint64 chain ID -- contractAddress is a 40-character hexadecimal string representing the contract address -- tokenID is an 8-character hexadecimal string representing the uint32 token ID
  • optional is an optional string that can be appended to the index

func (Index) WithEncodedParts added in v0.0.8

func (i Index) WithEncodedParts() Index

type InvalidError

type InvalidError string

InvalidError represents an error type for invalid arguments.

func (InvalidError) Error

func (e InvalidError) Error() string

Error implements the error interface for InvalidError.

Directories

Path Synopsis
cmd
pkg
clickhouse/indexrepo
Package indexrepo contains service code for gettting and managing indexed objects.
Package indexrepo contains service code for gettting and managing indexed objects.
clickhouse/migrations
Code generated by "clickhouse-infra" DO NOT EDIT.
Code generated by "clickhouse-infra" DO NOT EDIT.

Jump to

Keyboard shortcuts

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