types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChainAlreadyExists - error definition describing a given chain that has already been registered in the coordinationChain
	ErrChainAlreadyExists = errors.New("chain already exists for given account")

	// ErrGenesisAlreadyExists - error definition describing a given chain with an existing genesis block
	ErrGenesisAlreadyExists = errors.New("chain already has existing genesis")

	// ErrIrrelevantTransaction - error definition describing a transaction outside the scope of the given chain
	ErrIrrelevantTransaction = errors.New("irrelevant transaction")

	// ErrInsufficientBalance - error definition describing a transaction worth less than the sender's balance
	ErrInsufficientBalance = errors.New("insufficient transaction sender balance")
)
View Source
var (
	// ErrNilAddress - error definition describing an input of addresses of length 0
	ErrNilAddress = errors.New("nil address")

	// ErrNilNode - error definition describing a coordinationNode input of nil value
	ErrNilNode = errors.New("nil node")

	// ErrNilCoordinationChain - error definition describing a coordination chain that is nil in value
	ErrNilCoordinationChain = errors.New("nil coordination chain")

	// ErrClientOutOfDate - error definition describing a client that is out of date
	ErrClientOutOfDate = errors.New("client out of date (must upgrade client)")
)
View Source
var (
	// ErrAlreadySigned - error definition stating transaction has already been signed
	ErrAlreadySigned = errors.New("transaction already signed")

	// ErrNilSignature - error definition describing nil tx signature
	ErrNilSignature = errors.New("nil signature")

	// ErrInvalidSignature - error definition describing invalid tx signature (doesn't match public key)
	ErrInvalidSignature = errors.New("invalid signature")
)
View Source
var (
	// ErrInvalidPublicKey - error definition describing a public key input not equal to transaction sender address
	ErrInvalidPublicKey = errors.New("signing public key does not match transaction public key")

	// ErrCannotWitnessSelf - error definition describing a transaction that has already been signed by an attempted witness
	ErrCannotWitnessSelf = errors.New("cannot witness self-signed transaction")
)
View Source
var (
	// ErrBadChain - error describing input chain with tx length shorter than current
	ErrBadChain = errors.New("chain out of date")
)

Functions

func HandleReceivedChain

func HandleReceivedChain(b []byte) error

HandleReceivedChain - handle received chain

func HandleReceivedCoordinationChainRequest

func HandleReceivedCoordinationChainRequest() ([]byte, error)

HandleReceivedCoordinationChainRequest - handle received byte value for coordination chain request

func HandleReceivedCoordinationNode

func HandleReceivedCoordinationNode(b []byte) error

HandleReceivedCoordinationNode - handle received node

func HandleReceivedTransaction

func HandleReceivedTransaction(b []byte) error

HandleReceivedTransaction - handle received transaction

func JoinNetwork

func JoinNetwork(bootstrapNode string, archivalNode bool) error

JoinNetwork - join given network with bootstrap node address

func RegisterArchivalNode

func RegisterArchivalNode() error

RegisterArchivalNode - register archival node on network

func SignTransaction

func SignTransaction(transaction *Transaction, privateKey *ecdsa.PrivateKey) error

SignTransaction - sign given transaction

func SyncNetwork

func SyncNetwork(archival bool) error

SyncNetwork - download all chains

func VerifyTransactionSignature

func VerifyTransactionSignature(transaction *Transaction) (bool, error)

VerifyTransactionSignature - verify given transaction signature, returning false if signature invalid

Types

type Chain

type Chain struct {
	Account common.Address `json:"account"` // Chain account

	Transactions []*Transaction `json:"transactions"` // Transactions in chain

	Genesis common.Hash `json:"genesis"` // Genesis block hash

	NetworkID uint        `json:"network"` // Network ID (mainnet: 0, testnet: 1, etc...)
	ID        common.Hash `json:"ID"`      // Chain ID
}

Chain - account transactions chain

func FromBytes

func FromBytes(b []byte) (*Chain, error)

FromBytes - decode given byte array to chain

func HandleReceivedChainRequest

func HandleReceivedChainRequest(b []byte) (*Chain, error)

HandleReceivedChainRequest - handle chain request

func NewChain

func NewChain(account common.Address) (*Chain, error)

NewChain - initialize new chain

func ReadChainFromMemory

func ReadChainFromMemory(address common.Address) (*Chain, error)

ReadChainFromMemory - read chain from memory

func (*Chain) AddTransaction

func (chain *Chain) AddTransaction(transaction *Transaction) error

AddTransaction - append given transaction to chain

func (*Chain) Bytes

func (chain *Chain) Bytes() []byte

Bytes - convert given chain to byte array

func (*Chain) CalculateBalance

func (chain *Chain) CalculateBalance() float64

CalculateBalance - iterate through tx set, return balance

func (*Chain) MakeEncodingSafe

func (chain *Chain) MakeEncodingSafe() error

MakeEncodingSafe - make all transactions in chain encoding safe

func (*Chain) RecoverSafeEncoding

func (chain *Chain) RecoverSafeEncoding() error

RecoverSafeEncoding - recover chain from safely encoded

func (*Chain) String

func (chain *Chain) String() string

String - convert given chain to string

func (*Chain) WriteToMemory

func (chain *Chain) WriteToMemory() error

WriteToMemory - write given chain to memory

type CoordinationChain

type CoordinationChain struct {
	Nodes []*CoordinationNode `json:"nodes"` // List of coordination nodes holding metadata regarding a specific address-space (e.g. 0x000-0x123)

	NetworkID uint        `json:"network"` // Network ID (e.g. mainnet: 0, testnet: 1, etc...)
	ChainID   common.Hash `json:"ID"`      // Chain ID
}

CoordinationChain - "master" chain holding metadata regarding all address-spaces

func CoordinationChainFromBytes

func CoordinationChainFromBytes(b []byte) (*CoordinationChain, error)

CoordinationChainFromBytes - decode coordination chain from given byte array

func NewCoordinationChain

func NewCoordinationChain() (*CoordinationChain, error)

NewCoordinationChain - initialize new CoordinationChain

func ReadCoordinationChainFromMemory

func ReadCoordinationChainFromMemory() (*CoordinationChain, error)

ReadCoordinationChainFromMemory - read coordinationChain from memory

func (*CoordinationChain) AddNode

func (coordinationChain *CoordinationChain) AddNode(coordinationNode *CoordinationNode, updateRemote bool) error

AddNode - append given coordination node to coordinationChain

func (*CoordinationChain) Bytes

func (coordinationChain *CoordinationChain) Bytes() []byte

Bytes - convert given coordinationChain to byte array

func (*CoordinationChain) GetBalance

func (coordinationChain *CoordinationChain) GetBalance(address common.Address) (float64, error)

GetBalance - attempt to get balance of account

func (*CoordinationChain) GetGenesis

func (coordinationChain *CoordinationChain) GetGenesis() (*CoordinationNode, error)

GetGenesis - iterate through coordination nodes, return genesis node

func (*CoordinationChain) PushNode

func (coordinationChain *CoordinationChain) PushNode(coordinationNode *CoordinationNode) error

PushNode - send new node to addresses in coordination chain

func (*CoordinationChain) QueryAddress

func (coordinationChain *CoordinationChain) QueryAddress(queryAddress common.Address) (*CoordinationNode, error)

QueryAddress - query for address in coordination chain

func (*CoordinationChain) QueryAllArchivalNodes

func (coordinationChain *CoordinationChain) QueryAllArchivalNodes() ([]string, error)

QueryAllArchivalNodes - get all archival nodes in coordination chain

func (*CoordinationChain) QueryArchivalNode

func (coordinationChain *CoordinationChain) QueryArchivalNode(address string) ([]*CoordinationNode, error)

QueryArchivalNode - query for archival node address in coordination chain

func (*CoordinationChain) QueryNode

func (coordinationChain *CoordinationChain) QueryNode(address string) (*CoordinationNode, error)

QueryNode - query for node address in coordination chain

func (*CoordinationChain) String

func (coordinationChain *CoordinationChain) String() string

String - convert given coordinationChain to string

func (*CoordinationChain) WriteToMemory

func (coordinationChain *CoordinationChain) WriteToMemory() error

WriteToMemory - write given coordination chain to memory

type CoordinationNode

type CoordinationNode struct {
	Address   common.Address `json:"address"`   // Address
	Addresses []string       `json:"addresses"` // Node addresses in coordination node

	Origin time.Time `json:"origin"` // Time at initialization of coordination node

	Genesis bool `json:"genesis"` // Has genesis

	ID common.Hash `json:"id"` // Node ID
}

CoordinationNode - node holding metadata regarding a certain address-space

func CoordinationNodeFromBytes

func CoordinationNodeFromBytes(b []byte) (*CoordinationNode, error)

CoordinationNodeFromBytes - convert byte array to coordinationNode

func NewCoordinationNode

func NewCoordinationNode(address common.Address, foundingAddresses []string) (*CoordinationNode, error)

NewCoordinationNode - initialize new coordinationNode

func (*CoordinationNode) Bytes

func (coordinationNode *CoordinationNode) Bytes() []byte

Bytes - convert given coordinationNode to byte array

func (*CoordinationNode) String

func (coordinationNode *CoordinationNode) String() string

String - convert given coordinationNode to string

type Signature

type Signature struct {
	PublicKey           *ecdsa.PublicKey `json:"-"` // Public key
	SerializedPublicKey []byte           // Serialized public key

	V []byte   // Hash signature value
	R *big.Int // Signature R
	S *big.Int // Signature S
}

Signature - struct containing signature values

func (*Signature) Bytes

func (signature *Signature) Bytes() []byte

Bytes - convert given signature to byte array

func (*Signature) String

func (signature *Signature) String() string

String - convert given signature to string

type Transaction

type Transaction struct {
	AccountNonce uint64 `json:"nonce"` // Nonce in set of account transactions

	Sender    *common.Address `json:"sender"`    // Transaction sender
	Recipient *common.Address `json:"recipient"` // Transaction recipient

	Amount float64 `json:"amount"` // Amount of coins sent in transaction

	Payload []byte `json:"payload"` // Misc. data transported with transaction

	Signature *Signature `json:"signature"` // Transaction signature meta

	ParentTx *Transaction `json:"-"` // Parent transaction

	Timestamp time.Time `json:"time"` // Transaction timestamp

	Genesis bool `json:"genesis"` // Genesis

	Hash *common.Hash `json:"hash"` // Transaction hash
}

Transaction - primitive transaction type

func NewTransaction

func NewTransaction(nonce uint64, parentTx *Transaction, sender *common.Address, destination *common.Address, amount float64, payload []byte) (*Transaction, error)

NewTransaction - attempt to initialize transaction primitive

func ReadTransactionFromMemory

func ReadTransactionFromMemory(hash common.Hash) (*Transaction, error)

ReadTransactionFromMemory - read transaction from memory

func TransactionFromBytes

func TransactionFromBytes(b []byte) (*Transaction, error)

TransactionFromBytes - serialize transaction from byte array

func (*Transaction) Bytes

func (transaction *Transaction) Bytes() []byte

Bytes - convert given transaction to byte array

func (*Transaction) MakeEncodingSafe

func (transaction *Transaction) MakeEncodingSafe() error

MakeEncodingSafe - encode transaction to safe format

func (*Transaction) Publish

func (transaction *Transaction) Publish() error

Publish - publish given transaction

func (*Transaction) RecoverSafeEncoding

func (transaction *Transaction) RecoverSafeEncoding() error

RecoverSafeEncoding - recover transaction from safe encoding

func (*Transaction) String

func (transaction *Transaction) String() string

String - convert given transaction to string

func (*Transaction) WriteToMemory

func (transaction *Transaction) WriteToMemory() error

WriteToMemory - write given transaction to memory

type Witness

type Witness struct {
	Signature *Signature // Witness signature

	Address common.Address // Witnessing address

	Weight float64 // Witness weight (stake)
}

Witness - struct containing transaction witness values

func (*Witness) Bytes

func (witness *Witness) Bytes() []byte

Bytes - convert given witness to byte array

func (*Witness) String

func (witness *Witness) String() string

String - convert given witness to string

Jump to

Keyboard shortcuts

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