valuerenderer

package
v0.0.0-...-c3ff555 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoinMetadataQueryFn

type CoinMetadataQueryFn func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error)

CoinMetadataQueryFn defines a function that queries state for the coin denom metadata. It is meant to be passed as an argument into `NewTextual`.

type Screen

type Screen struct {
	// Text is the text to display - a sequence of Unicode code points.
	Text string

	// Indent is the indentation level of the screen.
	// Zero indicates top-level. Should be less than 16.
	Indent int

	// Expert indicates that the screen should only be displayed
	// via an opt-in from the user.
	Expert bool
}

Screen is the abstract unit of Textual rendering.

type Textual

type Textual struct {
	// contains filtered or unexported fields
}

Textual holds the configuration for dispatching to specific value renderers for SIGN_MODE_TEXTUAL.

func NewTextual

func NewTextual(q CoinMetadataQueryFn) Textual

NewTextual returns a new Textual which provides value renderers.

func (*Textual) DefineScalar

func (r *Textual) DefineScalar(scalar string, vr ValueRenderer)

DefineScalar adds a value renderer to the given Cosmos scalar.

func (Textual) GetValueRenderer

func (r Textual) GetValueRenderer(fd protoreflect.FieldDescriptor) (ValueRenderer, error)

GetValueRenderer returns the value renderer for the given FieldDescriptor.

type ValueRenderer

type ValueRenderer interface {
	// Format should render the value to a text plus annotation.
	Format(context.Context, protoreflect.Value) ([]Screen, error)

	// Parse should be the inverse of Format.
	Parse(context.Context, []Screen) (protoreflect.Value, error)
}

ValueRenderer defines an interface to produce formatted output for all protobuf types as well as parse a string into those protobuf types.

The notion of "value renderer" is defined in ADR-050, and that ADR provides a default spec for value renderers. However, we define it as an interface here, so that optionally more value renderers could be built, for example, a separate one for a different language.

func NewBytesValueRenderer

func NewBytesValueRenderer() ValueRenderer

NewBytesValueRenderer returns a ValueRenderer for Protobuf bytes, which are encoded as capital-letter hexadecimal, without the '0x' prefix.

func NewCoinsValueRenderer

func NewCoinsValueRenderer(q CoinMetadataQueryFn) ValueRenderer

NewCoinsValueRenderer returns a ValueRenderer for SDK Coin and Coins.

func NewDecValueRenderer

func NewDecValueRenderer() ValueRenderer

NewDecValueRenderer returns a ValueRenderer for encoding sdk.Dec cosmos scalars.

func NewDurationValueRenderer

func NewDurationValueRenderer() ValueRenderer

NewDurationValueRenderer returns a ValueRenderer for protocol buffer Duration messages. It renders durations by grouping seconds into units of days (86400s), hours (3600s), and minutes(60s), plus the total seconds elapsed. E.g. a duration of 1483530s is formatted as "17 days, 4 hours, 5 minutes, 30 seconds". Note that the days are always 24 hours regardless of daylight savings changes.

func NewIntValueRenderer

func NewIntValueRenderer() ValueRenderer

NewIntValueRenderer returns a ValueRenderer for uint32, uint64, int32 and int64, and sdk.Int scalars.

func NewMessageValueRenderer

func NewMessageValueRenderer(t *Textual, msgDesc protoreflect.MessageDescriptor) ValueRenderer

func NewStringValueRenderer

func NewStringValueRenderer() ValueRenderer

NewStringValueRenderer returns a ValueRenderer for protocol buffer string values. It renders the string as-is without quotation.

func NewTimestampValueRenderer

func NewTimestampValueRenderer() ValueRenderer

NewTimestampValueRenderer returns a ValueRenderer for protocol buffer Timestamp messages. It renders timestamps using the RFC 3339 format, always using UTC as the timezone. Fractional seconds are only rendered if nonzero.

Jump to

Keyboard shortcuts

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