fat2

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 8 Imported by: 5

Documentation

Overview

Package fat2 provides data types corresponding to valid FAT-2 entries for PegNet Transactions and Conversions as well as methods for validating the structure and content of the factom entry.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Fat2RCDEActivation is when rcd type 0x0e is valid and accepted.
	// Estimated to be  Feb 12, 2020, 18:00 UTC
	Fat2RCDEActivation uint32 = 231620
)

Functions

This section is empty.

Types

type AddressAmountTuple

type AddressAmountTuple struct {
	Address factom.FAAddress `json:"address"`
	Amount  uint64           `json:"amount"`
}

TypedAddressAmountTuple represents a tuple of a Factoid address sending or receiving an Amount of funds of a type that is inferred based on outside context

func (*AddressAmountTuple) UnmarshalJSON

func (t *AddressAmountTuple) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the bytes of JSON into a AddressAmountTuple ensuring that there are no duplicate JSON keys.

type PTicker

type PTicker int

PPTicker is an internal representation of a PegNet asset type

const (
	PTickerInvalid PTicker = iota
	PTickerPEG
	PTickerUSD
	PTickerEUR
	PTickerJPY
	PTickerGBP
	PTickerCAD
	PTickerCHF
	PTickerINR
	PTickerSGD
	PTickerCNY
	PTickerHKD
	PTickerKRW
	PTickerBRL
	PTickerPHP
	PTickerMXN
	PTickerXAU
	PTickerXAG
	PTickerXBT
	PTickerETH
	PTickerLTC
	PTickerRVN
	PTickerXBC
	PTickerFCT
	PTickerBNB
	PTickerXLM
	PTickerADA
	PTickerXMR
	PTickerDASH
	PTickerZEC
	PTickerDCR
	// V4 Additions
	PTickerAUD
	PTickerNZD
	PTickerSEK
	PTickerNOK
	PTickerRUB
	PTickerZAR
	PTickerTRY
	PTickerEOS
	PTickerLINK
	PTickerATOM
	PTickerBAT
	PTickerXTZ
	PTickerMax
)

func StringToTicker

func StringToTicker(str string) PTicker

func (PTicker) MarshalJSON

func (t PTicker) MarshalJSON() ([]byte, error)

MarshalJSON marshals the PTicker into the bytes that represent it in JSON

func (PTicker) String

func (t PTicker) String() string

String returns the string representation of this PTicker

func (*PTicker) UnmarshalJSON

func (t *PTicker) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the bytes into a PTicker and returns an error if the ticker is invalid

type Transaction

type Transaction struct {
	Input      TypedAddressAmountTuple `json:"input"`
	Transfers  []AddressAmountTuple    `json:"transfers,omitempty"`
	Conversion PTicker                 `json:"conversion,omitempty"`
	Metadata   interface{}             `json:"metadata,omitempty"`
}

Transaction represents a fat2 transaction, which can be a value transfer or a conversion depending on present fields

func (*Transaction) IsConversion

func (t *Transaction) IsConversion() bool

IsConversion returns true if this transaction has zero transfers and a valid conversion PTicker

func (*Transaction) IsPEGRequest added in v0.4.0

func (t *Transaction) IsPEGRequest() bool

IsConversion returns true if this transaction has zero transfers and a valid conversion into PEG

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the bytes of JSON into a Transaction ensuring that there are no duplicate JSON keys.

func (*Transaction) Validate

func (t *Transaction) Validate() error

Validate performs all validation checks and returns nil if t is a valid Transaction

type TransactionBatch

type TransactionBatch struct {
	Version      uint          `json:"version"`
	Transactions []Transaction `json:"transactions"`

	Metadata json.RawMessage `json:"metadata,omitempty"`
	Entry    factom.Entry    `json:"-"`
}

TransactionBatch represents a fat2 entry, which can be a list of one or more transactions to be executed in order

func NewTransactionBatch

func NewTransactionBatch(entry factom.Entry, height int32) (*TransactionBatch, error)

NewTransactionBatch returns a TransactionBatch initialized with the given entry. The height is for validation purposes. For certain heights, only certain rcd types are valid. If the height -1 is passed in, then all rcd types are valid. This is helpful when making a tx.

func (*TransactionBatch) HasConversions

func (t *TransactionBatch) HasConversions() bool

HasConversions returns true if this batch contains at least one transaction with a conversion input/output pair. This function assumes that TransactionBatch.Valid() returns nil

func (*TransactionBatch) HasPEGRequest added in v0.4.0

func (t *TransactionBatch) HasPEGRequest() bool

HasPEGRequest returns if the tx batch has a conversion request into PEG

func (TransactionBatch) MarshalJSON

func (t TransactionBatch) MarshalJSON() ([]byte, error)

MarshalJSON marshals the TransactionBatch content field as JSON, but will raise an error if the batch fails the checks in ValidData()

func (TransactionBatch) Sign added in v0.5.0

func (t TransactionBatch) Sign(signingSet ...factom.RCDSigner) (factom.Entry, error)

func (TransactionBatch) String

func (t TransactionBatch) String() string

func (*TransactionBatch) UnmarshalJSON

func (t *TransactionBatch) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the bytes of JSON into a TransactionBatch ensuring that there are no duplicate JSON keys.

func (*TransactionBatch) ValidData

func (t *TransactionBatch) ValidData() error

ValidData validates all Transaction data included in the batch and returns nil if it is valid. This function assumes that the entry content (or an independent JSON object) has been unmarshaled.

func (TransactionBatch) ValidExtIDs

func (t TransactionBatch) ValidExtIDs(height int32) error

ValidExtIDs validates the structure of the external IDs of the entry to make sure that it has the correct number of RCD/signature pairs. If no errors are found, it will then validate the content of the RCD/signature pair. This function assumes that the entry content has been unmarshaled and that ValidData returns nil.

func (*TransactionBatch) Validate

func (t *TransactionBatch) Validate(height int32) error

Validate performs all validation checks and returns nil if it is a valid batch. This function assumes the struct's entry field is populated. Validate requires a height for rcd signature validation. Not all rcd types are valid for all heights

type TypedAddressAmountTuple

type TypedAddressAmountTuple struct {
	Address factom.FAAddress `json:"address"`
	Amount  uint64           `json:"amount"`
	Type    PTicker          `json:"type"`
}

TypedAddressAmountTuple represents a 3-tuple of a Factoid address sending or receiving an Amount of funds of a given Type

func (*TypedAddressAmountTuple) UnmarshalJSON

func (t *TypedAddressAmountTuple) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the bytes of JSON into a TypedAddressAmountTuple ensuring that there are no duplicate JSON keys.

Jump to

Keyboard shortcuts

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