Documentation ¶
Overview ¶
Package types provides core primitives for the operation of the Polaris protocol.
Package types provides core primitives for the operation of the Polaris protocol.
Package types provides core primitives for the operation of the Polaris protocol.
Package types provides core primitives for the operation of the Polaris protocol.
Package types provides core primitives for the operation of the Polaris protocol.
Index ¶
- Variables
- func SignTransaction(transaction *Transaction, privateKey *ecdsa.PrivateKey) error
- type Dag
- func (dag *Dag) AddTransaction(transaction *Transaction) error
- func (dag *Dag) Bytes() []byte
- func (dag *Dag) CalculateAddressBalance(address *common.Address) (*big.Float, error)
- func (dag *Dag) Close() error
- func (dag *Dag) GetBestTransaction() (*Transaction, error)
- func (dag *Dag) GetTransactionByHash(transactionHash common.Hash) (*Transaction, error)
- func (dag *Dag) GetTransactionChildren(transactionHash common.Hash) ([]*Transaction, error)
- func (dag *Dag) GetTransactionsByAddress(address *common.Address) ([]*Transaction, error)
- func (dag *Dag) GetTransactionsBySender(sender *common.Address) ([]*Transaction, error)
- func (dag *Dag) MakeGenesis() ([]*Transaction, error)
- func (dag *Dag) WriteToMemory() error
- type Signature
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ( // WorkingDagDB represents the current opened dag database. WorkingDagDB *bolt.DB // ErrDagAlreadyExists represents an error describing // the attempted overwriting of an existing DAG. ErrDagAlreadyExists = errors.New("dag already exists") // ErrDagDbNotOpened represents an error describing the attempted appending of a data set // to the working dag, despite the fact that the dag db has not yet been opened. ErrDagDbNotOpened = errors.New("dag db has not been opened") // ErrNilTransaction represents an error describing a transaction pointer of nil value. ErrNilTransaction = errors.New("transaction pointer is nil") // ErrNilTransactionAtHash represents an error describing a transaction pointer of nil value discovered through the // querying of the working db for an invalid hash. ErrNilTransactionAtHash = errors.New("no transaction exists in the dag with given hash") // ErrNilGenesis represents an error describing a genesis value of nil. ErrNilGenesis = errors.New("dag does not have a valid genesis") // ErrNilSignature represents an error describing a transaction lacking a signature. ErrNilSignature = errors.New("transaction has no signature") // ErrDuplicateTransaction represents an error describing a duplicate transaction entry in the given working dag db. ErrDuplicateTransaction = errors.New("transaction already exists in dag") // ErrInvalidSignature represents an error describing an ErrInvalidSignature = errors.New("signature invalid") )
var ( // ErrNoWorkingHost represents an error describing a p2p.WorkingHost value of nil. ErrNoWorkingHost = errors.New("no valid global host was found") // BestTransactionRequest represents the global best transaction request message byte value. BestTransactionRequest = []byte("best_transaction_request") // TransactionRequest represents the global transaction request message byte value. TransactionRequest = []byte("transaction_request") // GenesisHashRequest represents the global genesis transaction request message byte value. GenesisHashRequest = []byte("genesis_hash_request") )
var ( // ErrAlreadySigned defines an error describing a situation in which a message has already been signed. ErrAlreadySigned = errors.New("already signed") // ErrNilHash defines an error describing a situation in which a message has no hash. ErrNilHash = errors.New("hash not set") )
Functions ¶
func SignTransaction ¶
func SignTransaction(transaction *Transaction, privateKey *ecdsa.PrivateKey) error
SignTransaction signs a given transaction via ecdsa, and sets the transaction signature to the new signature. Returns a new signature composed of v, r, s values. If the transaction has already been signed, returns an ErrAlreadySigned error, as well as a nil signature pointer. If the transaction has no hash, returns an ErrNilHash error, as well as a nil signature pointer.
Types ¶
type Dag ¶
type Dag struct { DagConfig *config.DagConfig `json:"config"` // Dag config Genesis common.Hash `json:"genesis"` // Dag genesis LastTransaction common.Hash `json:"last_tx"` // Last transaction hash }
Dag is a simple struct used to abstract db reading and writing methods.
func NewDag ¶
NewDag creates a new dag with the given config, and writes the dag db to memory. The newly opened dag db is stored in the WorkingDagDB variable.
func (*Dag) AddTransaction ¶
func (dag *Dag) AddTransaction(transaction *Transaction) error
AddTransaction appends a given transaction to the working dag. Returns an ErrDagDbNotOpened error if the working dag db is nil (has been not opened). Return an ErrNilTransaction error if the given transaction pointer is nil. Returns an ErrDuplicateTransaction error if the transaction already exists in the working dag db. Returns an ErrNilSignature error if the transaction has not been signed. Return an ErrInvalidSignature error if the transaction's signature is invalid.
func (*Dag) CalculateAddressBalance ¶
CalculateAddressBalance calculates the total balance of an address from genesis to latest tx.
func (*Dag) GetBestTransaction ¶
func (dag *Dag) GetBestTransaction() (*Transaction, error)
GetBestTransaction gets the last transaction in the dag. If more than one last child exists, the child with the latest timestamp is returned.
func (*Dag) GetTransactionByHash ¶
func (dag *Dag) GetTransactionByHash(transactionHash common.Hash) (*Transaction, error)
GetTransactionByHash attempts to query the working dag db by the given transaction hash. If no transaction exists at this hash, an
func (*Dag) GetTransactionChildren ¶
func (dag *Dag) GetTransactionChildren(transactionHash common.Hash) ([]*Transaction, error)
GetTransactionChildren iterates through the dag's transactions, and finds transactions with the given hash as a parent.
func (*Dag) GetTransactionsByAddress ¶
func (dag *Dag) GetTransactionsByAddress(address *common.Address) ([]*Transaction, error)
GetTransactionsByAddress attempts to filter the dag by a given sending or receiving address.
func (*Dag) GetTransactionsBySender ¶
func (dag *Dag) GetTransactionsBySender(sender *common.Address) ([]*Transaction, error)
GetTransactionsBySender attempts to filter the dag by a given sending address.
func (*Dag) MakeGenesis ¶
func (dag *Dag) MakeGenesis() ([]*Transaction, error)
MakeGenesis makes the dag's genesis transaction set. If the dag already has a genesis transaction, an ErrDuplicateTransaction error is returned.
func (*Dag) WriteToMemory ¶
WriteToMemory writes the dag header to persistent memory.
type Signature ¶
type Signature struct { MarshaledPublicKey []byte `json:"pub" gencodec:"required"` // Signature public key V []byte `json:"v" gencodec:"required"` // Signature message R *big.Int `json:"r" gencodec:"required"` // Signature retrieval S *big.Int `json:"s" gencodec:"required"` // Signature retrieval }
Signature is a data type representing a verifiable ECDSA signature--that of which is not necessarily a transaction signature.
func SignMessage ¶
SignMessage signs a given message hash via ecdsa, and returns a new signature
type Transaction ¶
type Transaction struct { AccountNonce uint64 `json:"nonce" gencodec:"required"` // Index in account transaction list Amount *big.Float `json:"amount" gencodec:"required"` // Transaction value Sender *common.Address `json:"sender" gencodec:"required"` // Transaction sender Recipient *common.Address `json:"recipient" gencodec:"required"` // Transaction recipient ParentTransactions []common.Hash `json:"parent" gencodec:"required"` // Parent hash GasPrice *big.Int `json:"gas_price" gencodec:"required"` // Gas price in units equivalent to 0.000000001 of a single unit GasLimit uint64 `json:"gas_limit" gencodec:"required"` // Value of gas price willing to pay for transaction Payload []byte `json:"payload" gencodec:"required"` // Data sent with transaction (i.e. contract bytecode, message, etc...) Signature *Signature `json:"signature" gencodec:"required"` // ECDSA transaction signature Timestamp time.Time `json:"timestamp" gencodec:"required"` // Transaction timestamp Hash common.Hash `json:"hash" gencodec:"required"` // Transaction hash }
Transaction is a data type representing a transfer of monetary value between addresses. A transactions does not necessarily imply the transfer of value between human peers, but also contracts.
func NewTransaction ¶
func NewTransaction(accountNonce uint64, amount *big.Float, sender, recipient *common.Address, parentTransactions []common.Hash, gasLimit uint64, gasPrice *big.Int, payload []byte) *Transaction
NewTransaction creates a new transaction with the given account nonce, value, sender, recipient, gas price, gas limit, and payload.
func TransactionFromBytes ¶
func TransactionFromBytes(b []byte) *Transaction
TransactionFromBytes deserializes a transaction from a given byte array.
func (*Transaction) Bytes ¶
func (transaction *Transaction) Bytes() []byte
Bytes serializes a given transaction to a byte array via json.
func (*Transaction) CalculateTotalValue ¶
func (transaction *Transaction) CalculateTotalValue() *big.Float
CalculateTotalValue calculates the total value of a transaction, including both its amount and total gas.
func (*Transaction) String ¶
func (transaction *Transaction) String() string
String serializes a given transaction to a string via json.