pldtypes

package
v0.0.0-...-7653185 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

* Copyright © 2024 Kaleido, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const DefaultNameMaxLen = 128
View Source
const MAX_SAFE_INT64 = 0x7fffffffffffffff
View Source
const (
	// ShortIDalphabet is designed for easy double-click select
	ShortIDalphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
)

Variables

This section is empty.

Functions

func ABIBySolDefinition

func ABIBySolDefinition(ctx context.Context, a abi.ABI) (map[string]*abi.Entry, error)

func ABIInferenceFromJSON

func ABIInferenceFromJSON(ctx context.Context, inputData RawJSON) (abi.ParameterArray, error)

Takes arbitrary JSON data and attempts to infer an ABI from it. Is not a complete system for all JSON. Current capability set: - Requires top-level JSON to be an object - Does NOT preserve order of properties in a JSON object (Preserving JSON order in Go requires much more complex json.Token based code, or a swap-in library)

- Supports simple types, objects, and arrays of same-typed values - Maps:

  • strings -> string
  • number -> int256 (as long as input number is whole)
  • boolean -> boolean

func ABIsMustMatch

func ABIsMustMatch(ctx context.Context, a, b abi.ABI, subMatch ...abi.EntryType) error

Validates that two ABIs contains exactly the same entires - Includes names of types - Includes indexing and other modifiers - Allows any order of entries

func Int256To65CharDBSafeSortableString

func Int256To65CharDBSafeSortableString(bi *big.Int) string

func MapEnum

func MapEnum[O EnumStringOptions, T any](p Enum[O], mapped map[O]T) (ret T, err error)

func PadHexBigIntTwosComplement

func PadHexBigIntTwosComplement(bi *big.Int, buff []byte) []byte

PadHexBigIntTwosComplement returns the supplied buffer, with all the bytes to the left of the two's complement formatted string set to 0

func PadHexBigUint

func PadHexBigUint(bi *big.Int, buff []byte) []byte

PadHexBigUint returns the supplied buffer, with all the bytes to the left of the integer set to '0'

func RandBytes

func RandBytes(count int) []byte

func RandHex

func RandHex(count int) string

func ShortID

func ShortID() string

func StandardABISerializer

func StandardABISerializer() *abi.Serializer

The serializer we should use in all places that go from ABI validated data, back down to JSON that might be: 1) Passed to end-users over a JSON/RPC API 2) Passed to domain plugins over a gRPC API

func StrOrEmpty

func StrOrEmpty(s *string) string

func ValidateSafeCharsStartEndAlphaNum

func ValidateSafeCharsStartEndAlphaNum(ctx context.Context, val string, maxLen int, fieldName string) error

Types

type Bytes32

type Bytes32 [32]byte

Bytes32 is a 32 byte value, with DB storage serialization

func ABISolDefinitionHash

func ABISolDefinitionHash(ctx context.Context, a abi.ABI, subMatch ...abi.EntryType) (*Bytes32, error)

func Bytes32Keccak

func Bytes32Keccak(b []byte) Bytes32

func Bytes32UUIDFirst16

func Bytes32UUIDFirst16(u uuid.UUID) Bytes32

func MustParseBytes32

func MustParseBytes32(s string) Bytes32

func NewBytes32FromSlice

func NewBytes32FromSlice(bytes []byte) Bytes32

No checking in this function on length

func ParseBytes32

func ParseBytes32(s string) (Bytes32, error)

func ParseBytes32Ctx

func ParseBytes32Ctx(ctx context.Context, s string) (Bytes32, error)

Parse a string

func RandBytes32

func RandBytes32() Bytes32

func (Bytes32) Bytes

func (id Bytes32) Bytes() []byte

Get bytes - or nil

func (*Bytes32) Equals

func (id *Bytes32) Equals(id2 *Bytes32) bool

func (Bytes32) HexString

func (id Bytes32) HexString() string

Get string (without 0x prefix) - nil is all zeros

func (Bytes32) HexString0xPrefix

func (id Bytes32) HexString0xPrefix() string

Get string with 0x prefix - nil is all zeros

func (Bytes32) IsZero

func (id Bytes32) IsZero() bool

Returns true for either nil, or all-zeros value

func (Bytes32) MarshalText

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

JSON representation is lower case hex, with 0x prefix

func (*Bytes32) Scan

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

func (Bytes32) String

func (id Bytes32) String() string

Natural string representation is HexString0xPrefix() if non-nil, or empty string if ""

func (Bytes32) UUIDFirst16

func (id Bytes32) UUIDFirst16() (u uuid.UUID)

Return the first 16 bytes as a UUID

func (*Bytes32) UnmarshalText

func (id *Bytes32) UnmarshalText(text []byte) error

Parses with/without 0x in any case

func (Bytes32) Value

func (id Bytes32) Value() (driver.Value, error)

type Enum

type Enum[O EnumStringOptions] string

Enum is a persistence wrapper for an enum with a set of options

func (Enum[O]) MapToString

func (p Enum[O]) MapToString() (string, error)

Case insensitive validation, with default, returning a string value

func (Enum[O]) Options

func (p Enum[O]) Options() []string

func (*Enum[O]) Scan

func (p *Enum[O]) Scan(src interface{}) error

SQL scanner handles strings, bytes, and nil - where nil will be set to the default

func (Enum[O]) V

func (p Enum[O]) V() O

func (Enum[O]) Validate

func (p Enum[O]) Validate() (O, error)

Case insensitive validation, with default

func (Enum[O]) Value

func (p Enum[O]) Value() (driver.Value, error)

SQL valuer returns a string, and only allows the possible values

type EnumStringDefault

type EnumStringDefault interface {
	Default() string
}

type EnumStringOptions

type EnumStringOptions interface {
	~string
	Options() []string
}

type EthAddress

type EthAddress [20]byte

EthAddress is an SQL serializable version of ethtypes.Address0xHex

func EthAddressBytes

func EthAddressBytes(b []byte) *EthAddress

func MustEthAddress

func MustEthAddress(s string) *EthAddress

func ParseEthAddress

func ParseEthAddress(s string) (*EthAddress, error)

func RandAddress

func RandAddress() *EthAddress

func (*EthAddress) Address0xHex

func (a *EthAddress) Address0xHex() *ethtypes.Address0xHex

func (*EthAddress) Checksummed

func (a *EthAddress) Checksummed() string

func (*EthAddress) Equals

func (a *EthAddress) Equals(b *EthAddress) bool

func (EthAddress) HexString

func (a EthAddress) HexString() string

func (*EthAddress) IsZero

func (a *EthAddress) IsZero() bool

func (EthAddress) MarshalJSON

func (a EthAddress) MarshalJSON() ([]byte, error)

func (*EthAddress) Scan

func (a *EthAddress) Scan(src interface{}) error

Scan implements sql.Scanner

func (EthAddress) String

func (a EthAddress) String() string

func (*EthAddress) UnmarshalJSON

func (a *EthAddress) UnmarshalJSON(b []byte) error

func (EthAddress) Value

func (a EthAddress) Value() (driver.Value, error)

Value implements sql.Valuer

type HexBytes

type HexBytes []byte

HexBytes is byte slice that is formatted in JSON with an 0x prefix, and stored in the DB as hex

func MustParseHexBytes

func MustParseHexBytes(s string) HexBytes

func ParseHexBytes

func ParseHexBytes(ctx context.Context, s string) (HexBytes, error)

Parse a string

func (HexBytes) Equals

func (id HexBytes) Equals(id2 HexBytes) bool

func (HexBytes) HexString

func (id HexBytes) HexString() string

Get string (without 0x prefix) - nil is all zeros

func (HexBytes) HexString0xPrefix

func (id HexBytes) HexString0xPrefix() string

Get string with 0x prefix - nil is all zeros

func (HexBytes) MarshalText

func (id HexBytes) MarshalText() ([]byte, error)

JSON representation is lower case hex, with 0x prefix

func (*HexBytes) Scan

func (id *HexBytes) Scan(src interface{}) error

func (HexBytes) String

func (id HexBytes) String() string

Natural string representation is HexString0xPrefix() if non-nil, or empty string if ""

func (*HexBytes) UnmarshalText

func (id *HexBytes) UnmarshalText(text []byte) error

Parses with/without 0x in any case

func (HexBytes) Value

func (id HexBytes) Value() (driver.Value, error)

type HexInt256

type HexInt256 big.Int

HexInt256 is any integer (signed or unsigned) up to 256 bits in size, serialized to the DB using a 65 sortable string (a 0/1 sign character, followed by 32 hex bytes)

func MustParseHexInt256

func MustParseHexInt256(s string) *HexInt256

func ParseHexInt256

func ParseHexInt256(ctx context.Context, s string) (*HexInt256, error)

Parse a string

func (*HexInt256) HexString

func (hi *HexInt256) HexString() string

Get string (without 0x prefix) - nil is all zeros

func (*HexInt256) HexString0xPrefix

func (hi *HexInt256) HexString0xPrefix() string

Get string with 0x prefix - nil is all zeros

func (*HexInt256) Int

func (hi *HexInt256) Int() *big.Int

func (*HexInt256) MarshalJSON

func (hi *HexInt256) MarshalJSON() ([]byte, error)

JSON representation is lower case hex, with 0x prefix

func (*HexInt256) NilOrZero

func (hi *HexInt256) NilOrZero() bool

func (*HexInt256) Scan

func (hi *HexInt256) Scan(src interface{}) error

func (*HexInt256) String

func (hi *HexInt256) String() string

Natural string representation is HexString0xPrefix() if non-nil, or empty string if ""

func (*HexInt256) UnmarshalJSON

func (hi *HexInt256) UnmarshalJSON(b []byte) error

Parses with/without 0x in any case

func (*HexInt256) Value

func (hi *HexInt256) Value() (driver.Value, error)

type HexUint256

type HexUint256 big.Int

HexUint256 is any integer (signed or unsigned) up to 256 bits in size, serialized to the DB using a 65 sortable string (a 0/1 sign character, followed by 32 hex bytes)

func Int64ToInt256

func Int64ToInt256(v int64) *HexUint256

func MustParseHexUint256

func MustParseHexUint256(s string) *HexUint256

func ParseHexUint256

func ParseHexUint256(ctx context.Context, s string) (*HexUint256, error)

Parse a string

func Uint64ToUint256

func Uint64ToUint256(v uint64) *HexUint256

func (*HexUint256) HexString

func (hi *HexUint256) HexString() string

Get string (without 0x prefix) - nil is all zeros

func (*HexUint256) HexString0xPrefix

func (hi *HexUint256) HexString0xPrefix() string

Get string with 0x prefix - nil is all zeros

func (*HexUint256) Int

func (hi *HexUint256) Int() *big.Int

func (*HexUint256) MarshalJSON

func (hi *HexUint256) MarshalJSON() ([]byte, error)

JSON representation is lower case hex, with 0x prefix

func (*HexUint256) NilOrZero

func (hi *HexUint256) NilOrZero() bool

func (*HexUint256) Scan

func (hi *HexUint256) Scan(src interface{}) error

func (*HexUint256) String

func (hi *HexUint256) String() string

Natural string representation is HexString0xPrefix() if non-nil, or empty string if ""

func (*HexUint256) UnmarshalJSON

func (hi *HexUint256) UnmarshalJSON(b []byte) error

Parses with/without 0x in any case

func (*HexUint256) Value

func (hi *HexUint256) Value() (driver.Value, error)

type HexUint64

type HexUint64 uint64

HexUint64 is an unsigned integer that is serialized in JSON as hex

func MustParseHexUint64

func MustParseHexUint64(s string) HexUint64

func ParseHexUint64

func ParseHexUint64(ctx context.Context, s string) (HexUint64, error)

Parse a string

func (HexUint64) HexString

func (hi HexUint64) HexString() string

Get string (without 0x prefix) - nil is all zeros

func (HexUint64) HexString0xPrefix

func (hi HexUint64) HexString0xPrefix() string

Get string with 0x prefix - nil is all zeros

func (HexUint64) MarshalJSON

func (hi HexUint64) MarshalJSON() ([]byte, error)

JSON representation is lower case hex, with 0x prefix

func (*HexUint64) Scan

func (id *HexUint64) Scan(src interface{}) error

func (HexUint64) String

func (hi HexUint64) String() string

Natural string representation is HexString0xPrefix() if non-nil, or empty string if ""

func (HexUint64) Uint64

func (hi HexUint64) Uint64() uint64

func (*HexUint64) UnmarshalJSON

func (hi *HexUint64) UnmarshalJSON(b []byte) error

Parses with/without 0x in any case

func (HexUint64) Value

func (hi HexUint64) Value() (driver.Value, error)

type HexUint64OrString

type HexUint64OrString string

HexUint64OrString is used for things like block numbers, where you can provide a number or a string like "latest".

func (HexUint64OrString) MarshalJSON

func (his HexUint64OrString) MarshalJSON() ([]byte, error)

func (HexUint64OrString) String

func (his HexUint64OrString) String() string

func (*HexUint64OrString) UnmarshalJSON

func (his *HexUint64OrString) UnmarshalJSON(b []byte) error

Parses with/without 0x in any case

type JSONFormatOptions

type JSONFormatOptions string
const DefaultJSONFormatOptions JSONFormatOptions = ""

func (JSONFormatOptions) GetABISerializer

func (jfo JSONFormatOptions) GetABISerializer(ctx context.Context) (serializer *abi.Serializer, err error)

func (JSONFormatOptions) GetABISerializerIgnoreErrors

func (jfo JSONFormatOptions) GetABISerializerIgnoreErrors(ctx context.Context) *abi.Serializer

type LibraryType

type LibraryType string
const (
	LibraryTypeCShared LibraryType = "c-shared"
	LibraryTypeJar     LibraryType = "jar"
)

func (LibraryType) Enum

func (lt LibraryType) Enum() Enum[LibraryType]

func (LibraryType) Options

func (pl LibraryType) Options() []string

type OnChainLocation

type OnChainLocation struct {
	Type             OnChainLocationType
	TransactionHash  Bytes32
	BlockNumber      int64
	TransactionIndex int64
	LogIndex         int64       // non-zero only for events
	Source           *EthAddress // non-nil only for events
}

func (*OnChainLocation) Compare

func (occ *OnChainLocation) Compare(occ2 *OnChainLocation) int

type OnChainLocationType

type OnChainLocationType int
const (
	// Note numeric order of these is important for sorting
	NotOnChain         OnChainLocationType = 0 // transactions that did not make it on chain
	OnChainTransaction OnChainLocationType = 1 // the transaction is the location
	OnChainEvent       OnChainLocationType = 2 // an individual event within the transaction is the location
)

type OnChainLocations

type OnChainLocations []*OnChainLocation

func (OnChainLocations) Len

func (l OnChainLocations) Len() int

func (OnChainLocations) Less

func (l OnChainLocations) Less(i, j int) bool

func (OnChainLocations) Swap

func (l OnChainLocations) Swap(i, j int)

type PrivateIdentityLocator

type PrivateIdentityLocator string

The locator for private identities is split into two parts separate by an `@` symbol - A lookup for the identity, which can only be resolved by the node that owns that identity - A lookup for the node, which will be resolved locally to determine which node can resolve the identity

func (PrivateIdentityLocator) FullyQualified

func (pil PrivateIdentityLocator) FullyQualified(ctx context.Context, defaultNode string) (PrivateIdentityLocator, error)

func (PrivateIdentityLocator) Identity

func (pil PrivateIdentityLocator) Identity(ctx context.Context) (string, error)

func (PrivateIdentityLocator) Node

func (pil PrivateIdentityLocator) Node(ctx context.Context, allowEmptyNode bool) (string, error)

func (PrivateIdentityLocator) String

func (pil PrivateIdentityLocator) String() string

func (PrivateIdentityLocator) Validate

func (pil PrivateIdentityLocator) Validate(ctx context.Context, defaultNode string, allowEmptyNode bool) (identity string, node string, err error)

type RawJSON

type RawJSON []byte

Just like pldtypes.RawJSON, but with ability to SQL serialize to string as well

func JSONString

func JSONString(s any) RawJSON

func (RawJSON) Bytes

func (m RawJSON) Bytes() []byte

func (RawJSON) BytesOrNull

func (m RawJSON) BytesOrNull() []byte

func (RawJSON) IsNil

func (m RawJSON) IsNil() bool

func (RawJSON) MarshalJSON

func (m RawJSON) MarshalJSON() ([]byte, error)

func (RawJSON) Pretty

func (m RawJSON) Pretty() string

func (*RawJSON) Scan

func (m *RawJSON) Scan(src interface{}) error

func (RawJSON) String

func (m RawJSON) String() string

func (RawJSON) StringValue

func (m RawJSON) StringValue() string

func (RawJSON) ToMap

func (m RawJSON) ToMap() (jm map[string]any)

func (*RawJSON) UnmarshalJSON

func (m *RawJSON) UnmarshalJSON(data []byte) error

func (RawJSON) Value

func (m RawJSON) Value() driver.Value

func (RawJSON) YAML

func (m RawJSON) YAML() string

type Timestamp

type Timestamp int64

Timestamp stores a Unix timestamp with nanoseconds. Timestamp 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 MustParseTimeString

func MustParseTimeString(str string) Timestamp

func ParseTimeString

func ParseTimeString(str string) (Timestamp, error)

func TimestampFromUnix

func TimestampFromUnix(unixTime int64) Timestamp

func TimestampNow

func TimestampNow() Timestamp

func (*Timestamp) Equal

func (ts *Timestamp) Equal(ts2 *Timestamp) bool

func (*Timestamp) MarshalJSON

func (ts *Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) Scan

func (ts *Timestamp) Scan(src interface{}) error

Scan implements sql.Scanner

func (Timestamp) String

func (ts Timestamp) String() string

func (Timestamp) Time

func (ts Timestamp) Time() time.Time

func (Timestamp) UnixNano

func (ts Timestamp) UnixNano() int64

func (*Timestamp) UnmarshalJSON

func (ts *Timestamp) UnmarshalJSON(b []byte) error

func (Timestamp) Value

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

Value implements sql.Valuer

Jump to

Keyboard shortcuts

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