fftypes

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 24 Imported by: 50

Documentation

Index

Constants

View Source
const FFStringArrayStandardMax = 1024

FFStringArrayStandardMax is the standard length we set as a VARCHAR max in tables for a string array

View Source
const FFStringNameItemsMax = 15

Because each FFName has a max length of 64, 15 names (plus comma delimeters) is a safe max to pack into a string column of length 1024

View Source
const MaxFFBigIntHexLength = 65
View Source
const (
	NullString = "null"
)
View Source
const (
	// ShortIDalphabet is designed for easy double-click select
	ShortIDalphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
)

Variables

View Source
var (
	// HashMismatch sentinel error
	HashMismatch = i18n.NewError(context.Background(), i18n.MsgHashMismatch)
	// IDMismatch sentinel error
	IDMismatch = i18n.NewError(context.Background(), i18n.MsgIDMismatch)
	// DeleteRecordNotFound sentinel error
	DeleteRecordNotFound = i18n.NewError(context.Background(), i18n.Msg404NotFound)
)

Functions

func FFEnumValid added in v1.4.0

func FFEnumValid(ctx context.Context, t string, val FFEnum) bool

func FFEnumValues added in v0.1.7

func FFEnumValues(t string) []interface{}

func IsNil added in v1.4.0

func IsNil(v interface{}) bool

Safe nil checking on an interface, that does not panic

func JSONScan added in v1.4.0

func JSONScan(src, target interface{}) error

func JSONValue added in v1.4.0

func JSONValue(target interface{}) (driver.Value, error)

func NewFFISchemaCompiler added in v0.1.11

func NewFFISchemaCompiler() *jsonschema.Compiler

func NewNamespacedUUIDString added in v1.2.6

func NewNamespacedUUIDString(_ context.Context, namespace string, uuid *UUID) string

func ParseToByteSize

func ParseToByteSize(byteString string) int64

ParseToByteSize is a standard handling of a number of bytes, in config or API options

func ParseToDuration

func ParseToDuration(durationString string) time.Duration

ParseToDuration is a standard handling of any duration string, in config or API options

func SafeHashCompare

func SafeHashCompare(h1 *Bytes32, h2 *Bytes32) bool

func ShortID

func ShortID() string

func ToStringArray

func ToStringArray(unknown interface{}) ([]string, bool)

func TypeNamespaceNameTopicHash added in v0.1.11

func TypeNamespaceNameTopicHash(objType string, ns string, name string) string

func ValidateFFNameField added in v0.1.11

func ValidateFFNameField(ctx context.Context, str string, fieldName string) error

func ValidateFFNameFieldNoUUID added in v0.1.11

func ValidateFFNameFieldNoUUID(ctx context.Context, str string, fieldName string) error

func ValidateLength added in v0.1.11

func ValidateLength(ctx context.Context, str string, fieldName string, max int) error

func ValidateSafeCharsOnly added in v0.1.11

func ValidateSafeCharsOnly(ctx context.Context, str string, fieldName string) error

Types

type AuthReq added in v0.1.14

type AuthReq struct {
	Method    string
	URL       *url.URL
	Header    http.Header
	Namespace string
}

type BaseFFIParamValidator added in v0.1.11

type BaseFFIParamValidator struct{}

func (BaseFFIParamValidator) Compile added in v0.1.11

func (v BaseFFIParamValidator) Compile(_ jsonschema.CompilerContext, _ map[string]interface{}) (jsonschema.ExtSchema, error)

func (*BaseFFIParamValidator) GetExtensionName added in v0.1.11

func (v *BaseFFIParamValidator) GetExtensionName() string

func (*BaseFFIParamValidator) GetMetaSchema added in v0.1.11

func (v *BaseFFIParamValidator) GetMetaSchema() *jsonschema.Schema

type Bytes32

type Bytes32 [32]byte

Bytes32 is a holder of a hash, that can be used to correlate onchain data with off-chain data.

func HashResult

func HashResult(hash hash.Hash) *Bytes32

func HashString

func HashString(s string) *Bytes32

func MustParseBytes32

func MustParseBytes32(hexStr string) *Bytes32

func NewRandB32

func NewRandB32() *Bytes32

func ParseBytes32

func ParseBytes32(_ context.Context, hexStr string) (*Bytes32, error)

func UUIDBytes

func UUIDBytes(u *UUID) *Bytes32

UUIDBytes returns the bytes of a UUID as a compressed hex string

func (*Bytes32) Equals

func (b32 *Bytes32) Equals(b2 *Bytes32) bool

func (Bytes32) MarshalText

func (b32 Bytes32) MarshalText() ([]byte, error)

func (*Bytes32) Scan

func (b32 *Bytes32) Scan(src interface{}) error

Scan implements sql.Scanner

func (*Bytes32) String

func (b32 *Bytes32) String() string

func (*Bytes32) UnmarshalText

func (b32 *Bytes32) UnmarshalText(b []byte) error

func (*Bytes32) Value

func (b32 *Bytes32) Value() (driver.Value, error)

Value implements sql.Valuer

type ConfigRecord

type ConfigRecord struct {
	Key   string   `json:"key,omitempty"`
	Value *JSONAny `json:"value,omitempty"`
}

type FFBigInt

type FFBigInt big.Int

FFBigInt is a wrapper on a Go big.Int that standardizes JSON and DB serialization

func NewFFBigInt

func NewFFBigInt(x int64) *FFBigInt

func (*FFBigInt) Equals

func (i *FFBigInt) Equals(i2 *FFBigInt) bool

func (*FFBigInt) Int

func (i *FFBigInt) Int() *big.Int

func (*FFBigInt) Int64

func (i *FFBigInt) Int64() int64

func (FFBigInt) MarshalText

func (i FFBigInt) MarshalText() ([]byte, error)

func (*FFBigInt) Scan

func (i *FFBigInt) Scan(src interface{}) error

func (*FFBigInt) String added in v0.1.17

func (i *FFBigInt) String() string

func (*FFBigInt) Uint64

func (i *FFBigInt) Uint64() uint64

func (*FFBigInt) UnmarshalJSON

func (i *FFBigInt) UnmarshalJSON(b []byte) error

func (FFBigInt) Value

func (i FFBigInt) Value() (driver.Value, error)

type FFDuration

type FFDuration time.Duration

FFDuration is serialized to JSON in the string format of time.Duration It can be unmarshalled from a number, or a string. - If it is a string in time.Duration format, that will be used - If it is a string that can be parsed as an int64, that will be used in Milliseconds - If it is a number, that will be used in Milliseconds

func ParseDurationString

func ParseDurationString(durationString string, def time.Duration) (FFDuration, error)

ParseDurationString is a standard handling of any duration string, in config or API options

func (*FFDuration) MarshalJSON

func (fd *FFDuration) MarshalJSON() ([]byte, error)

func (*FFDuration) Scan

func (fd *FFDuration) Scan(src interface{}) error

Scan implements sql.Scanner

func (*FFDuration) String

func (fd *FFDuration) String() string

func (*FFDuration) UnmarshalJSON

func (fd *FFDuration) UnmarshalJSON(b []byte) error

func (*FFDuration) Value

func (fd *FFDuration) Value() (driver.Value, error)

Value implements sql.Valuer

type FFEnum added in v0.1.7

type FFEnum string

func FFEnumParseString added in v1.1.2

func FFEnumParseString(ctx context.Context, t, val string) (FFEnum, error)

func FFEnumValue added in v0.1.7

func FFEnumValue(t string, val string) FFEnum

func (FFEnum) Equals added in v0.1.7

func (ts FFEnum) Equals(ts2 FFEnum) bool

func (FFEnum) Lower added in v0.1.7

func (ts FFEnum) Lower() FFEnum

func (FFEnum) String added in v0.1.7

func (ts FFEnum) String() string

func (*FFEnum) UnmarshalText added in v0.1.7

func (ts *FFEnum) UnmarshalText(b []byte) error

func (FFEnum) Value added in v0.1.7

func (ts FFEnum) Value() (driver.Value, error)

type FFI added in v0.1.11

type FFI struct {
	ID          *UUID        `ffstruct:"FFI" json:"id,omitempty" ffexcludeinput:"true"`
	Message     *UUID        `ffstruct:"FFI" json:"message,omitempty" ffexcludeinput:"true"`
	Namespace   string       `ffstruct:"FFI" json:"namespace,omitempty" ffexcludeinput:"true"`
	Name        string       `ffstruct:"FFI" json:"name"`
	NetworkName string       `ffstruct:"FFI" json:"networkName,omitempty"`
	Description string       `ffstruct:"FFI" json:"description"`
	Version     string       `ffstruct:"FFI" json:"version"`
	Methods     []*FFIMethod `ffstruct:"FFI" json:"methods,omitempty"`
	Events      []*FFIEvent  `ffstruct:"FFI" json:"events,omitempty"`
	Errors      []*FFIError  `ffstruct:"FFI" json:"errors,omitempty"`
	Published   bool         `ffstruct:"FFI" json:"published" ffexcludeinput:"true"`
}

func (*FFI) SetBroadcastMessage added in v0.1.11

func (f *FFI) SetBroadcastMessage(msgID *UUID)

func (*FFI) Topic added in v0.1.11

func (f *FFI) Topic() string

func (*FFI) Validate added in v0.1.11

func (f *FFI) Validate(ctx context.Context) (err error)

type FFIError added in v1.1.6

type FFIError struct {
	ID        *UUID  `ffstruct:"FFIError" json:"id,omitempty" ffexcludeinput:"true"`
	Interface *UUID  `ffstruct:"FFIError" json:"interface,omitempty" ffexcludeinput:"true"`
	Namespace string `ffstruct:"FFIError" json:"namespace,omitempty" ffexcludeinput:"true"`
	Pathname  string `ffstruct:"FFIError" json:"pathname,omitempty" ffexcludeinput:"true"`
	Signature string `ffstruct:"FFIError" json:"signature" ffexcludeinput:"true"`
	FFIErrorDefinition
}

type FFIErrorDefinition added in v1.1.6

type FFIErrorDefinition struct {
	Name        string    `ffstruct:"FFIError" json:"name"`
	Description string    `ffstruct:"FFIError" json:"description"`
	Params      FFIParams `ffstruct:"FFIError" json:"params"`
}

type FFIEvent added in v0.1.11

type FFIEvent struct {
	ID        *UUID  `ffstruct:"FFIEvent" json:"id,omitempty" ffexcludeinput:"true"`
	Interface *UUID  `ffstruct:"FFIEvent" json:"interface,omitempty" ffexcludeinput:"true"`
	Namespace string `ffstruct:"FFIEvent" json:"namespace,omitempty" ffexcludeinput:"true"`
	Pathname  string `ffstruct:"FFIEvent" json:"pathname,omitempty" ffexcludeinput:"true"`
	Signature string `ffstruct:"FFIEvent" json:"signature" ffexcludeinput:"true"`
	FFIEventDefinition
}

type FFIEventDefinition added in v0.1.11

type FFIEventDefinition struct {
	Name        string     `ffstruct:"FFIEvent" json:"name"`
	Description string     `ffstruct:"FFIEvent" json:"description"`
	Params      FFIParams  `ffstruct:"FFIEvent" json:"params"`
	Details     JSONObject `ffstruct:"FFIEvent" json:"details,omitempty"`
}

type FFIGenerationRequest added in v0.1.11

type FFIGenerationRequest struct {
	Namespace   string   `ffstruct:"FFIGenerationRequest" json:"namespace,omitempty"`
	Name        string   `ffstruct:"FFIGenerationRequest" json:"name"`
	Description string   `ffstruct:"FFIGenerationRequest" json:"description"`
	Version     string   `ffstruct:"FFIGenerationRequest" json:"version"`
	Input       *JSONAny `ffstruct:"FFIGenerationRequest" json:"input"`
}

type FFIMethod added in v0.1.11

type FFIMethod struct {
	ID          *UUID      `ffstruct:"FFIMethod" json:"id,omitempty" ffexcludeinput:"true"`
	Interface   *UUID      `ffstruct:"FFIMethod" json:"interface,omitempty" ffexcludeinput:"true"`
	Name        string     `ffstruct:"FFIMethod" json:"name"`
	Namespace   string     `ffstruct:"FFIMethod" json:"namespace,omitempty" ffexcludeinput:"true"`
	Pathname    string     `ffstruct:"FFIMethod" json:"pathname" ffexcludeinput:"true"`
	Description string     `ffstruct:"FFIMethod" json:"description"`
	Params      FFIParams  `ffstruct:"FFIMethod" json:"params"`
	Returns     FFIParams  `ffstruct:"FFIMethod" json:"returns"`
	Details     JSONObject `ffstruct:"FFIMethod" json:"details,omitempty"`
}

type FFIParam added in v0.1.11

type FFIParam struct {
	Name   string   `ffstruct:"FFIParam" json:"name"`
	Schema *JSONAny `ffstruct:"FFIParam" json:"schema,omitempty"`
}

type FFIParamValidator added in v0.1.11

type FFIParamValidator interface {
	Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error)
	GetMetaSchema() *jsonschema.Schema
	GetExtensionName() string
}

type FFIParams added in v0.1.11

type FFIParams []*FFIParam

func (*FFIParams) Scan added in v0.1.11

func (p *FFIParams) Scan(src interface{}) error

Scan implements sql.Scanner

func (FFIParams) Value added in v0.1.11

func (p FFIParams) Value() (driver.Value, error)

type FFIReference added in v0.1.11

type FFIReference struct {
	ID      *UUID  `ffstruct:"FFIReference" json:"id,omitempty"`
	Name    string `ffstruct:"FFIReference" json:"name,omitempty"`
	Version string `ffstruct:"FFIReference" json:"version,omitempty"`
}

type FFStringArray added in v1.1.5

type FFStringArray []string

FFStringArray is an array of strings, each conforming to the requirements of a FireFly name

func NewFFStringArray added in v1.1.5

func NewFFStringArray(initialContent ...string) FFStringArray

func (FFStringArray) AddToSortedSet added in v1.1.5

func (sa FFStringArray) AddToSortedSet(newValues ...string) (res FFStringArray, changed bool)

AddToSortedSet determines if the new string is already in the set of strings (case insensitive), and if not it adds it to the list (lower case) and returns a new slice of alphabetically sorted strings reference and true. If no change is made, the original reference is returned and false.

func (*FFStringArray) Scan added in v1.1.5

func (sa *FFStringArray) Scan(src interface{}) error

func (FFStringArray) String added in v1.1.5

func (sa FFStringArray) String() string

func (FFStringArray) Validate added in v1.1.5

func (sa FFStringArray) Validate(ctx context.Context, fieldName string, isName bool, maxItems int) error

func (FFStringArray) Value added in v1.1.5

func (sa FFStringArray) Value() (driver.Value, error)

type FFTime

type FFTime time.Time

FFTime is serialized to JSON on the API in RFC3339 nanosecond UTC time (noting that JavaScript can parse this format happily into millisecond time with Date.pase()). It is persisted as a nanosecond resolution timestamp in the database. It can be parsed from RFC3339, or unix timestamps (second, millisecond or nanosecond resolution)

func Now

func Now() *FFTime

func ParseTimeString

func ParseTimeString(str string) (*FFTime, error)

func UnixTime

func UnixTime(unixTime int64) *FFTime

func ZeroTime

func ZeroTime() FFTime

func (*FFTime) Equal

func (ft *FFTime) Equal(ft2 *FFTime) bool

func (*FFTime) MarshalJSON

func (ft *FFTime) MarshalJSON() ([]byte, error)

func (*FFTime) Scan

func (ft *FFTime) Scan(src interface{}) error

Scan implements sql.Scanner

func (FFTime) String

func (ft FFTime) String() string

func (*FFTime) Time

func (ft *FFTime) Time() *time.Time

func (*FFTime) UnixNano

func (ft *FFTime) UnixNano() int64

func (*FFTime) UnmarshalText

func (ft *FFTime) UnmarshalText(b []byte) error

func (*FFTime) Value

func (ft *FFTime) Value() (driver.Value, error)

Value implements sql.Valuer

type FFint64 added in v0.1.17

type FFint64 int64

FFint64 on the API are serialized as Base10 strings, and can be parsed from multiple bases (very similar to fftypes.FFBigInt, but limited to a 64bit signed integer)

func (*FFint64) Int64 added in v0.1.17

func (i *FFint64) Int64() int64

func (FFint64) MarshalText added in v0.1.17

func (i FFint64) MarshalText() ([]byte, error)

func (*FFint64) UnmarshalJSON added in v0.1.17

func (i *FFint64) UnmarshalJSON(b []byte) error

type FFuint64 added in v0.1.17

type FFuint64 uint64

FFuint64 on the API are serialized as Base10 strings, and can be parsed from multiple bases (very similar to fftypes.FFBigInt, but limited to a 64bit unsigned integer)

func (FFuint64) MarshalText added in v0.1.17

func (i FFuint64) MarshalText() ([]byte, error)

func (*FFuint64) Uint64 added in v0.1.17

func (i *FFuint64) Uint64() uint64

func (*FFuint64) UnmarshalJSON added in v0.1.17

func (i *FFuint64) UnmarshalJSON(b []byte) error

type HexUUID

type HexUUID = Bytes32

HexUUID is 32 character ASCII string containing the hex representation of UUID, with the dashes of the canonical representation removed

type JSONAny

type JSONAny string

JSONAny uses raw encode/decode to preserve field order, and can handle any types of field. It validates the JSON can be unmarshalled, but does not change the order. It does however trim out whitespace

func JSONAnyPtr

func JSONAnyPtr(str string) *JSONAny

func JSONAnyPtrBytes

func JSONAnyPtrBytes(b []byte) *JSONAny

func (*JSONAny) AsString added in v1.4.0

func (h *JSONAny) AsString() string

Attempts to unmarshal the JSONAny as a string and return it

func (*JSONAny) Bytes

func (h *JSONAny) Bytes() []byte

func (*JSONAny) Hash

func (h *JSONAny) Hash() *Bytes32

func (*JSONAny) IsNil

func (h *JSONAny) IsNil() bool

func (*JSONAny) JSONObject

func (h *JSONAny) JSONObject() JSONObject

JSONObject attempts to de-serialize the contained structure as a JSON Object (map) Safe and will never return nil Will return an empty object if the type is array, string, bool, number etc.

func (*JSONAny) JSONObjectArray added in v0.1.6

func (h *JSONAny) JSONObjectArray() JSONObjectArray

JSONObject attempts to de-serialize the contained structure an array of JSON objects

func (*JSONAny) JSONObjectArrayOk added in v0.1.6

func (h *JSONAny) JSONObjectArrayOk(noWarn ...bool) (JSONObjectArray, bool)

func (*JSONAny) JSONObjectNowarn

func (h *JSONAny) JSONObjectNowarn() JSONObject

JSONObjectNowarn acts the same as JSONObject, but does not warn if the value cannot be parsed as an object

func (*JSONAny) JSONObjectOk

func (h *JSONAny) JSONObjectOk(noWarn ...bool) (JSONObject, bool)

func (*JSONAny) Length

func (h *JSONAny) Length() int64

func (JSONAny) MarshalJSON

func (h JSONAny) MarshalJSON() ([]byte, error)

func (*JSONAny) Scan

func (h *JSONAny) Scan(src interface{}) error

Scan implements sql.Scanner

func (*JSONAny) String

func (h *JSONAny) String() string

Returns the raw JSON as a string without unmarshaling

func (*JSONAny) Unmarshal

func (h *JSONAny) Unmarshal(ctx context.Context, v interface{}) error

func (*JSONAny) UnmarshalJSON

func (h *JSONAny) UnmarshalJSON(b []byte) error

Unmarshals a byte array and sets h as a pointer to the result

func (*JSONAny) Value

func (h *JSONAny) Value() (driver.Value, error)

Value ensures we write null to the DB for null values

type JSONObject

type JSONObject map[string]interface{}

JSONObject is a holder of a hash, that can be used to correlate onchain data with off-chain data.

func (JSONObject) GetBool

func (jd JSONObject) GetBool(key string) bool

func (JSONObject) GetInt64

func (jd JSONObject) GetInt64(key string) int64

func (JSONObject) GetInteger

func (jd JSONObject) GetInteger(key string) *big.Int

func (JSONObject) GetObject

func (jd JSONObject) GetObject(key string) JSONObject

func (JSONObject) GetObjectArray

func (jd JSONObject) GetObjectArray(key string) JSONObjectArray

func (JSONObject) GetObjectArrayOk

func (jd JSONObject) GetObjectArrayOk(key string) (JSONObjectArray, bool)

func (JSONObject) GetObjectOk

func (jd JSONObject) GetObjectOk(key string) (JSONObject, bool)

func (JSONObject) GetString

func (jd JSONObject) GetString(key string) string

func (JSONObject) GetStringArray

func (jd JSONObject) GetStringArray(key string) []string

func (JSONObject) GetStringArrayOk

func (jd JSONObject) GetStringArrayOk(key string) ([]string, bool)

func (JSONObject) GetStringOk

func (jd JSONObject) GetStringOk(key string) (string, bool)

func (JSONObject) Hash

func (jd JSONObject) Hash(jsonDesc string) (*Bytes32, error)

func (*JSONObject) Scan

func (jd *JSONObject) Scan(src interface{}) error

Scan implements sql.Scanner

func (JSONObject) String

func (jd JSONObject) String() string

func (JSONObject) Value

func (jd JSONObject) Value() (driver.Value, error)

Value implements sql.Valuer

type JSONObjectArray

type JSONObjectArray []JSONObject

JSONObjectArray is an array of JSONObject

func ToJSONObjectArray

func ToJSONObjectArray(unknown interface{}) (JSONObjectArray, bool)

func (JSONObjectArray) Hash

func (jd JSONObjectArray) Hash(jsonDesc string) (*Bytes32, error)

func (*JSONObjectArray) Scan

func (jd *JSONObjectArray) Scan(src interface{}) error

Scan implements sql.Scanner

func (JSONObjectArray) String

func (jd JSONObjectArray) String() string

func (JSONObjectArray) Value

func (jd JSONObjectArray) Value() (driver.Value, error)

type RESTError

type RESTError struct {
	Error string `json:"error"`
}

type UUID

type UUID uuid.UUID

UUID is a wrapper on a UUID implementation, ensuring Value handles nil

func MustParseUUID

func MustParseUUID(uuidStr string) *UUID

func NewUUID

func NewUUID() *UUID

func ParseNamespacedUUID added in v1.2.6

func ParseNamespacedUUID(ctx context.Context, nsIDStr string) (namespace string, uuid *UUID, err error)

func ParseUUID

func ParseUUID(ctx context.Context, uuidStr string) (*UUID, error)

func (*UUID) Equals

func (u *UUID) Equals(u2 *UUID) bool

func (*UUID) HashBucket

func (u *UUID) HashBucket(buckets int) int

func (UUID) MarshalBinary

func (u UUID) MarshalBinary() ([]byte, error)

func (UUID) MarshalText

func (u UUID) MarshalText() ([]byte, error)

func (*UUID) Scan

func (u *UUID) Scan(src interface{}) error

func (*UUID) String

func (u *UUID) String() string

func (*UUID) UnmarshalBinary

func (u *UUID) UnmarshalBinary(b []byte) error

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(b []byte) error

func (*UUID) Value

func (u *UUID) Value() (driver.Value, error)

type UpsertOptimization added in v1.1.5

type UpsertOptimization int
const (
	UpsertOptimizationSkip UpsertOptimization = iota
	UpsertOptimizationNew
	UpsertOptimizationExisting
)

Jump to

Keyboard shortcuts

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