context

package
v0.0.0-...-9fb79c9 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Context package defines primitives for generic context handling during execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {

	// Throttled Rate Limiter
	HttpRateLimiter throttled.HTTPRateLimiter

	// Throttled Rate Limiter Store
	Store throttled.GCRAStore

	// SequenceMutex stores the current last sequence number of the account on the testnet
	SequenceMutex sync.Mutex
	// AccountNumberMutex stores the account number on the testnet for the respective wallet
	AccountNumberMutex sync.Mutex
	// BrokenFlagMutex stores if the last execution of the application was successful (tokens were sent)
	BrokenFlagMutex sync.Mutex

	// Deprecated: We only need to read AccountNumber once at startup, we store it for subsequent use
	AccountNumber int64

	// TestnetName returned from the full node
	TestnetName string

	// Application configuration
	Cfg *config.Config

	// Disable rate limiter for testing
	DisableLimiter bool

	// Disable sending of transaction to the network
	DisableSend bool

	// Disable ReCaptcha check for testing
	DisableRecaptcha bool

	// Amino MarshalBinary for transaction broadcast on blockchain network
	Cdc *wire.Codec

	// The new CLIContext for connecting to a network
	CLIContext *sdkCtx.CLIContext

	// The new TxContext for sending a transaction on the network
	TxContest *authctx.TxContext
}

Context holds current execution details.

func New

func New() *Context

New creates a fresh Context.

func (*Context) CheckAndFixAccountDetails

func (ctx *Context) CheckAndFixAccountDetails() (err error)

CheckAndFixAccountDetails checks, if the last run was unsuccessful (node down, wrong parameters) and tries to fix the values from the testnet.

func (*Context) GetTestnetName

func (ctx *Context) GetTestnetName() (err error)

GetTestnetName returns the testnet name from the node

func (*Context) RaiseBrokenAccountDetails

func (ctx *Context) RaiseBrokenAccountDetails(message string)

RaiseBrokenAccountDetails raises the flag that the configuration is broken (parameter change, node timeout).

type ErrorMessage

type ErrorMessage struct {
	Message string `json:"message"`
}

ErrorMessage defines the message structure returned when an error happens.

type Handler

type Handler struct {
	C *Context
	H func(*Context, http.ResponseWriter, *http.Request) (int, error)
}

Handler is an abstraction layer to standardize web API returns, if an error happens.

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is a wrapper around web API calls, that adds a default Content-Type and formats outgoing error messages.

type InitialContext

type InitialContext struct {
	// --no-rdb disable RedisDB database usage
	DisableRDb bool

	// --send Send to a wallet locally
	Send string

	// --ip IP address of local webserver
	WebserverIp string

	// --port Port number of local webserver
	WebserverPort uint

	// --config Config file for local execution
	ConfigFile string

	// --webserver or --send was set
	LocalExecution bool

	// --no-limit Disable rate limiter
	DisableLimiter bool

	// --no-send Disable transaction send to the testnet (dry-run)
	DisableSend bool

	// --no-recaptcha Disable recaptcha
	DisableRecaptcha bool
}

InitialContext holds the input parameter details at the start of execution.

func NewInitialContext

func NewInitialContext() *InitialContext

NewInitialContext creates a fresh InitialContext.

Jump to

Keyboard shortcuts

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