currency

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 37

Documentation

Overview

Package currency provides information on the price of ETH.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GWei2Wei

func GWei2Wei(amountGWei *big.Float) *big.Int

GWei2Wei converts the wei unit into a GWei for display.

func Wei2GWei

func Wei2GWei(amountWei *big.Int) *big.Float

Wei2GWei converts the wei unit into a GWei for display.

Types

type BalanceDiff

type BalanceDiff struct {
	BeforeGWei string
	AfterGWei  string
	DiffGWei   string
	DiffUSD    string
}

BalanceDiff performs calculations on the starting and ending balance.

type Converter

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

Converter maintains the information required for ETH conversions.

func NewConverter

func NewConverter(abiMetaData string, coinMarketCapKey string) (*Converter, error)

NewConverter constructs a conversion for working with ETH and USD.

func NewDefaultConverter

func NewDefaultConverter(abiMetaData string) *Converter

NewDefaultConverter can be used if the API is failing to set reasonable defaults. Also good for tests.

func (*Converter) CalculateBalanceDiff

func (c *Converter) CalculateBalanceDiff(startingBalance *big.Int, endingBalance *big.Int) (BalanceDiff, error)

CalculateBalanceDiff performs calculations on the starting and ending balance.

func (*Converter) CalculateReceiptDetails

func (c *Converter) CalculateReceiptDetails(receipt *types.Receipt, gasPrice *big.Int) ReceiptDetails

CalculateReceiptDetails performs calculations on the receipt.

func (*Converter) CalculateTransactionDetails

func (c *Converter) CalculateTransactionDetails(tx *types.Transaction) TransactionDetails

CalculateTransactionDetails performs calculations on the transaction.

func (*Converter) FmtBalanceSheet

func (c *Converter) FmtBalanceSheet(startingBalance *big.Int, endingBalance *big.Int) string

FmtBalanceSheet produces a easy to read format of the starting and ending balance for the connected account.

func (*Converter) FmtTransaction

func (c *Converter) FmtTransaction(tx *types.Transaction) string

FmtTransaction produces a easy to read format of the specified transaction.

func (*Converter) FmtTransactionReceipt

func (c *Converter) FmtTransactionReceipt(receipt *types.Receipt, gasPrice *big.Int) string

FmtTransactionReceipt produces a easy to read format of the specified receipt.

func (*Converter) GWei2USD

func (c *Converter) GWei2USD(amountGWei *big.Float) string

GWei2USD converts GWei to USD.

func (*Converter) USD2GWei

func (c *Converter) USD2GWei(amountUSD *big.Float) *big.Float

USD2GWei converts USD to GWei.

func (*Converter) USD2Wei

func (c *Converter) USD2Wei(amountUSD *big.Float) *big.Int

USD2Wei converts USD to Wei.

func (*Converter) Values

func (c *Converter) Values() (oneETHToUSD *big.Float, oneUSDToETH *big.Float)

Values returns the currency values being used.

func (*Converter) Wei2USD

func (c *Converter) Wei2USD(amountWei *big.Int) string

Wei2USD converts Wei to USD.

type DataETH

type DataETH struct {
	Symbol      string `json:"symbol"`
	Amount      int    `json:"amount"`
	LastUpdated string `json:"last_updated"`
	Quote       struct {
		ETH struct {
			Price       float64 `json:"price"`
			LastUpdated string  `json:"last_updated"`
		} `json:"ETH"`
	} `json:"quote"`
}

DataETH represents the data provided when asking for ETH.

type DataUSD

type DataUSD struct {
	Symbol      string `json:"symbol"`
	Amount      int    `json:"amount"`
	LastUpdated string `json:"last_updated"`
	Quote       struct {
		USD struct {
			Price       float64 `json:"price"`
			LastUpdated string  `json:"last_updated"`
		} `json:"USD"`
	} `json:"quote"`
}

DataUSD represents the data provided when asking for USD.

type LogData added in v0.8.0

type LogData struct {
	EventName string
	Data      map[string]interface{}
}

LogData represents data we can pull from events in the receipt logs.

func ExtractLogData added in v0.8.0

func ExtractLogData(abiMetaData string, receipt *types.Receipt) ([]LogData, error)

ExtractLogData can extra the information in the receipt logs from the receipt.

type ReceiptDetails

type ReceiptDetails struct {
	Status        uint64
	GasUsed       uint64
	GasPriceGWei  string
	GasPriceUSD   string
	FinalCostGWei string
	FinalCostUSD  string
}

ReceiptDetails provides details about a receipt and it's cost.

type ResponseETH2USD

type ResponseETH2USD struct {
	Status Status    `json:"status"`
	Data   []DataUSD `json:"data"`
}

ResponseETH2USD represents the complete response when converting ETH to USD.

type ResponseUSD2ETH

type ResponseUSD2ETH struct {
	Status Status    `json:"status"`
	Data   []DataETH `json:"data"`
}

ResponseUSD2ETH represents the complete response when converting USD to ETH.

type Status

type Status struct {
	TimeStamp    string `json:"timestamp"`
	ErrorCode    int    `json:"error_code"`
	ErrorMessage string `json:"error_message"`
	Elapsed      int    `json:"elapsed"`
	CreditCount  int    `json:"credit_count"`
}

Status represents the information about the call.

type TransactionDetails

type TransactionDetails struct {
	Hash              string
	Nonce             uint64
	GasLimit          uint64
	GasOfferPriceGWei string
	Value             string
	MaxGasPriceGWei   string
	MaxGasPriceUSD    string
}

TransactionDetails provides details about a transaction and it's cost.

Jump to

Keyboard shortcuts

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