types

package
v0.0.0-...-cb7fc92 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinIOUExponent  = -96
	MaxIOUExponent  = 80
	MaxIOUPrecision = 16
	MinIOUMantissa  = 1000000000000000
	MaxIOUMantissa  = 9999999999999999

	NotXRPBitMask            = 0x80
	PosSignBitMask           = 0x4000000000000000
	ZeroCurrencyAmountHex    = 0x8000000000000000
	NativeAmountByteLength   = 8
	CurrencyAmountByteLength = 48

	MinXRP   = 1e-6
	MaxDrops = 1e17 // 100 billion XRP in drops aka 10^17

	IOUCodeRegex = `[0-9A-Za-z?!@#$%^&*<>(){}\[\]|]{3}`
)
View Source
const (
	ArrayEndMarker  = 0xF1
	ObjectEndMarker = 0xE1
)
View Source
const HashLengthBytes = 32

Variables

View Source
var (
	ErrInvalidXRPValue     = errors.New("invalid XRP value")
	ErrInvalidCurrencyCode = errors.New("invalid currency code")
)
View Source
var (
	ErrNoLengthPrefix  error = errors.New("no length prefix size given")
	ErrInvalidBlobType error = errors.New("invalid type for Blob")
)

ErrNoLengthPrefix error is raised when no length prefix size is given.

View Source
var (
	ErrInvalidUInt64String error = errors.New("invalid UInt64 string, value should be hex encoded")
	ErrInvalidUInt64Value  error = errors.New("invalid UInt64 value, value should be an uint or a hex encoded string")
)
View Source
var (
	ErrInvalidAccountID = errors.New("invalid account ID type")
)
View Source
var (
	ErrInvalidHashType = errors.New("invalid type for Hash, expected string")
)
View Source
var ErrInvalidPathSet error = errors.New("invalid type to construct PathSet from. Expected []any of []any")

ErrInvalidPathSet is an error that's thrown when an invalid path set is provided.

View Source
var ErrInvalidUInt32 = errors.New("invalid type for UInt32")
View Source
var ErrNotSTObjectInSTArray = errors.New("not STObject in STArray. Array fields must be STObjects")
View Source
var UINT64_HEX_REGEX = regexp.MustCompile("^[0-9a-fA-F]{1,16}$")

Functions

This section is empty.

Types

type AccountID

type AccountID struct{}

AccountID struct represents an account ID.

func (*AccountID) FromJson

func (a *AccountID) FromJson(value any) ([]byte, error)

FromJson is a method for the AccountID type that takes a value as a parameter, serializes it to a byte slice representing an AccountID. Decodes the ClassicAddress to an AccountID and returns the byte representation. AccountIDs that appear as stand-alone fields (such as Account and Destination) are length-prefixed despite being a fixed 160 bits in length. As a result, the length indicator for these fields is always the byte 0x14. AccountIDs that appear as children of special fields (Amount issuer and PathSet account) are not length-prefixed. So in Amount and PathSet fields, don't use the length indicator 0x14.

func (*AccountID) ToJson

func (a *AccountID) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson is a method for the AccountID type that deserializes a byte slice representation of an AccountID into a JSON value. It takes a binary parser and an optional length prefix size as arguments. The method reads the bytes using the binary parser, then encodes the result to an AccountID format. If no length prefix size is given, it returns an ErrNoLengthPrefix error.

type Amount

type Amount struct{}

Amount is a struct that represents an XRPL Amount.

func (*Amount) FromJson

func (a *Amount) FromJson(value any) ([]byte, error)

FromJson serializes an issued currency amount to its bytes representation from JSON.

func (*Amount) ToJson

func (a *Amount) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson deserializes a binary-encoded Amount object from a BinaryParser into a JSON representation.

type Blob

type Blob struct{}

Blob struct is used for manipulating hexadecimal data.

func (*Blob) FromJson

func (b *Blob) FromJson(json any) ([]byte, error)

FromJson method for Blob converts a hexadecimal string from JSON to a byte array.

func (*Blob) ToJson

func (b *Blob) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson method for Blob reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. It returns an error if no length prefix is specified or if the read operation fails.

type ErrInvalidHashLength

type ErrInvalidHashLength struct {
	Expected int
}

ErrInvalidHashLength struct is used when the hash length does not meet the expected value.

func (*ErrInvalidHashLength) Error

func (e *ErrInvalidHashLength) Error() string

Error method for ErrInvalidHashLength formats the error message.

type ErrInvalidVector256Type

type ErrInvalidVector256Type struct {
	Got string
}

ErrInvalidVector256Type represents an error when a Vector256 is constructed from an unexpected type.

func (*ErrInvalidVector256Type) Error

func (e *ErrInvalidVector256Type) Error() string

Error implements the error interface, providing a descriptive error message for ErrInvalidVector256Type.

type FieldMutation

type FieldMutation func(any) any

FieldMutation allows values to mutated before being serialized.

func Zero

func Zero() FieldMutation

Zero returns a FieldMutation that sets the value to its zero value.

type Hash128

type Hash128 struct {
}

Hash128 struct represents a 128-bit hash.

func NewHash128

func NewHash128() *Hash128

NewHash128 is a constructor for creating a new 128-bit hash.

func (*Hash128) FromJson

func (h *Hash128) FromJson(json any) ([]byte, error)

FromJson method for hash converts a hexadecimal string from JSON to a byte array. It returns an error if the conversion fails or the length of the decoded byte array is not as expected.

func (*Hash128) ToJson

func (h *Hash128) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. It returns an error if the read operation fails.

type Hash160

type Hash160 struct {
}

Hash160 struct represents a 160-bit hash.

func NewHash160

func NewHash160() *Hash160

NewHash160 is a constructor for creating a new 160-bit hash.

func (*Hash160) FromJson

func (h *Hash160) FromJson(json any) ([]byte, error)

FromJson method for hash converts a hexadecimal string from JSON to a byte array. It returns an error if the conversion fails or the length of the decoded byte array is not as expected.

func (*Hash160) ToJson

func (h *Hash160) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. It returns an error if the read operation fails.

type Hash256

type Hash256 struct {
}

Hash256 struct represents a 256-bit hash.

func NewHash256

func NewHash256() *Hash256

NewHash256 is a constructor for creating a new 256-bit hash.

func (*Hash256) FromJson

func (h *Hash256) FromJson(json any) ([]byte, error)

func (*Hash256) ToJson

func (h *Hash256) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. It returns an error if the read operation fails.

type InvalidAmountError

type InvalidAmountError struct {
	Amount types.XRPCurrencyAmount
}

InvalidAmountError is a custom error type for invalid amounts.

func (*InvalidAmountError) Error

func (e *InvalidAmountError) Error() string

Error method for InvalidAmountError returns a formatted error string.

type InvalidCodeError

type InvalidCodeError struct {
	Disallowed string
}

InvalidCodeError is a custom error type for invalid currency codes.

func (*InvalidCodeError) Error

func (e *InvalidCodeError) Error() string

Error method for InvalidCodeError returns a formatted error string.

type OutOfRangeError

type OutOfRangeError struct {
	Type string
}

OutOfRangeError is a custom error type for out-of-range values.

func (*OutOfRangeError) Error

func (e *OutOfRangeError) Error() string

Error method for OutOfRangeError returns a formatted error string.

type PathSet

type PathSet struct{}

PathSet type declaration

func (PathSet) FromJson

func (p PathSet) FromJson(data any) ([]byte, error)

FromJson attempts to serialize a path set from a JSON representation of a slice of paths to a byte array. It returns the byte array representation of the path set, or an error if the provided json does not represent a valid path set.

func (PathSet) ToJson

func (p PathSet) ToJson(parser *serdes.BinaryParser, opts ...int) (any, error)

ToJson decodes a path set from a binary representation using a provided binary parser, then translates it to a JSON representation. It returns a slice representing the JSON format of the path set, or an error if the path set could not be decoded or if an invalid step is encountered.

type STArray

type STArray struct{}

STArray represents an array of STObject instances.

func (*STArray) FromJson

func (t *STArray) FromJson(json any) ([]byte, error)

FromJson is a method that takes a JSON value (which should be a slice of JSON objects), and converts it to a byte slice, representing the serialized form of the STArray. It loops through the JSON slice, and for each element, calls the FromJson method of an STObject, appending the resulting byte slice to a "sink" slice. The method returns an error if the JSON value is not a slice.

func (*STArray) ToJson

func (t *STArray) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson is a method that takes a BinaryParser and optional parameters, and converts the serialized byte data back to a JSON value. The method loops until the BinaryParser has no more data, and for each loop, it calls the ToJson method of an STObject, appending the resulting JSON value to a "value" slice.

type STObject

type STObject struct {
	OnlySigning bool
	Mutations   map[string]FieldMutation
}

STObject represents a map of serialized field instances, where each key is a field name and the associated value is the field's value. This structure allows us to represent nested and complex structures of the Ripple protocol.

func (*STObject) FromJson

func (t *STObject) FromJson(data any) ([]byte, error)

FromJson converts a JSON object into a serialized byte slice. It works by converting the JSON object into a map of field instances (which include the field definition and value), and then serializing each field instance. This method returns an error if the JSON input is not a valid object.

func (*STObject) ToJson

func (t *STObject) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson takes a BinaryParser and optional parameters, and converts the serialized byte data back to a JSON value. It will continue parsing until it encounters an end marker for an object or an array, or until the parser has no more data.

type SerializedType

type SerializedType interface {
	FromJson(json any) ([]byte, error)
	ToJson(parser *serdes.BinaryParser, opts ...int) (any, error)
}

SerializedType is an interface representing any type that can be serialized and deserialized to and from JSON. The FromJson method takes a JSON value and converts it to a byte slice. The ToJson method takes a BinaryParser and optional parameters, and converts the serialized byte data back to a JSON value.

func GetSerializedType

func GetSerializedType(t string) SerializedType

GetSerializedType is a function that returns the correct SerializedType instance based on the string parameter. It creates a new instance of the type described by the parameter, allowing the appropriate methods of that type to be called. If the input string does not match a known type, the function returns nil.

type UInt16

type UInt16 struct{}

UInt16 represents a 16-bit unsigned integer.

func (*UInt16) FromJson

func (u *UInt16) FromJson(value any) ([]byte, error)

FromJson converts a JSON value into a serialized byte slice representing a 16-bit unsigned integer. If the input value is a string, it's assumed to be a transaction type or ledger entry type name, and the method will attempt to convert it into a corresponding type code. If the conversion fails, an error is returned.

func (*UInt16) ToJson

func (u *UInt16) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson takes a BinaryParser and optional parameters, and converts the serialized byte data back into a JSON integer value. This method assumes the parser contains data representing a 16-bit unsigned integer. If the parsing fails, an error is returned.

type UInt32

type UInt32 struct{}

UInt32 represents a 32-bit unsigned integer.

func (*UInt32) FromJson

func (u *UInt32) FromJson(value any) ([]byte, error)

FromJson converts a JSON value into a serialized byte slice representing a 32-bit unsigned integer. The input value is assumed to be an integer. If the serialization fails, an error is returned.

func (*UInt32) ToJson

func (u *UInt32) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson takes a BinaryParser and optional parameters, and converts the serialized byte data back into a JSON integer value. This method assumes the parser contains data representing a 32-bit unsigned integer. If the parsing fails, an error is returned.

type UInt64

type UInt64 struct{}

UInt64 represents a 64-bit unsigned integer.

func (*UInt64) FromJson

func (u *UInt64) FromJson(value any) ([]byte, error)

FromJson converts a JSON value into a serialized byte slice representing a 64-bit unsigned integer. The input value is assumed to be a string representation of an integer. If the serialization fails, an error is returned.

func (*UInt64) ToJson

func (u *UInt64) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson takes a BinaryParser and optional parameters, and converts the serialized byte data back into a JSON string value. This method assumes the parser contains data representing a 64-bit unsigned integer. If the parsing fails, an error is returned.

type UInt8

type UInt8 struct{}

UInt8 represents an 8-bit unsigned integer.

func (*UInt8) FromJson

func (u *UInt8) FromJson(value any) ([]byte, error)

FromJson converts a JSON value into a serialized byte slice representing an 8-bit unsigned integer. If the input value is a string, it's assumed to be a transaction result name, and the method will attempt to convert it into a transaction result type code. If the conversion fails, an error is returned.

func (*UInt8) ToJson

func (u *UInt8) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson takes a BinaryParser and optional parameters, and converts the serialized byte data back into a JSON integer value. This method assumes the parser contains data representing an 8-bit unsigned integer. If the parsing fails, an error is returned.

type Vector256

type Vector256 struct{}

Vector256 represents a 256 bit vector.

func (*Vector256) FromJson

func (v *Vector256) FromJson(json any) ([]byte, error)

FromJson converts a JSON value into a serialized byte slice representing a Vector256. The input value is assumed to be an array of strings representing Hash256 values. If the serialization fails, an error is returned.

func (*Vector256) ToJson

func (v *Vector256) ToJson(p *serdes.BinaryParser, opts ...int) (any, error)

ToJson takes a BinaryParser and optional parameters, and converts the serialized byte data back into an array of JSON string values representing Hash256 values. If the parsing fails, an error is returned.

Jump to

Keyboard shortcuts

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