Documentation ¶
Index ¶
- Constants
- Variables
- type AccountID
- type Amount
- type Blob
- type ErrInvalidHashLength
- type ErrInvalidVector256Type
- type FieldMutation
- type Hash128
- type Hash160
- type Hash256
- type InvalidAmountError
- type InvalidCodeError
- type OutOfRangeError
- type PathSet
- type STArray
- type STObject
- type SerializedType
- type UInt16
- type UInt32
- type UInt64
- type UInt8
- type Vector256
Constants ¶
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}` )
const ( ArrayEndMarker = 0xF1 ObjectEndMarker = 0xE1 )
const HashLengthBytes = 32
Variables ¶
var ( ErrInvalidXRPValue = errors.New("invalid XRP value") ErrInvalidCurrencyCode = errors.New("invalid currency code") )
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.
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") )
var (
ErrInvalidAccountID = errors.New("invalid account ID type")
)
var (
ErrInvalidHashType = errors.New("invalid type for Hash, expected string")
)
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.
var ErrInvalidUInt32 = errors.New("invalid type for UInt32")
var ErrNotSTObjectInSTArray = errors.New("not STObject in STArray. Array fields must be STObjects")
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 ¶
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 ¶
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.
type Blob ¶
type Blob struct{}
Blob struct is used for manipulating hexadecimal data.
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 ¶
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.
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.
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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.
type UInt32 ¶
type UInt32 struct{}
UInt32 represents a 32-bit unsigned integer.
func (*UInt32) FromJson ¶
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.
type UInt64 ¶
type UInt64 struct{}
UInt64 represents a 64-bit unsigned integer.
func (*UInt64) FromJson ¶
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.
type UInt8 ¶
type UInt8 struct{}
UInt8 represents an 8-bit unsigned integer.
func (*UInt8) FromJson ¶
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.
type Vector256 ¶
type Vector256 struct{}
Vector256 represents a 256 bit vector.
func (*Vector256) FromJson ¶
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.