transactions

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 10 Imported by: 0

README

Notes

CreateIssue: Amount in TX cannot be a uint64, has to be bytes and masked. For now, leave as is.

CreateIssue: Need a way to have multiple commitments for one proof - Suggestion: for n outputs, have the commitments be present in each. For the n-1 commitment,include rangeprooof <- This needs reviewing. Verifier would aggregate each proof into one for single proofs. Aggregate case for prover, may leak privacy. For now, let's stick with one proof, one commitment

CreateIssue: For now, in a bidding tx, the amount is in clear text. Will need to be changed to a commitment to D

CreateIssue: R cannot be used as the TxID, if a tx has more than one output, then it is ambiguous

CreateIssue: Is the sort in the Inputs slice needed, before comparing them? Contextual question

CreateIssue: We should have a limit for the number of inputs and outputs that are allowed, although Fees can mitigate an attacker having large amounts of inputs/outputs, an attacker with a lot of money can hold up a lot of resources like this. A conservative number like 250 inputs and 100 outputs seems fair for example, or in the right ball-park for those who want to pay out employees.

CreateIssue: Specs for the coinbase tx is a bit unclear.

CreateIssue: We can generalise equals method;

Take in an equal interface, then swtich on the type, if types are not the same then we return false
If they are, we carry on with our checks

Documentation

Index

Constants

View Source
const MaxLockTime = 250000
View Source
const TimeLockBlockZero = 0x8000000000000000

TimeLockBlockZero is the integer that represents the blockHeight of zero for a timelock transaction

Variables

This section is empty.

Functions

This section is empty.

Types

type Bid

type Bid struct {
	TimeLock
	// M represents the pre-image of the secret value k.
	// M = H(K)
	M []byte // 32 Byte
}

Bid represents the bidding transaction that is used within the blindbid procedure What does the TimeLock represent? In a `Bidding TX` it means that the outputs are locked until after the specified time

func NewBid

func NewBid(ver uint8, lock, fee uint64, R, M []byte) (*Bid, error)

NewBid will return a Bid transaction Given the tx version, the locktime,the fee and M

func (*Bid) CalculateHash

func (b *Bid) CalculateHash() ([]byte, error)

CalculateHash hashes all of the encoded fields in a tx, if this has not been done already. The resulting byte array is also it's identifier Implements merkletree.Payload interface

func (*Bid) Decode

func (b *Bid) Decode(r io.Reader) error

Decode implements the Decoder interface

func (*Bid) Encode

func (b *Bid) Encode(w io.Writer) error

Encode implements the Encoder interface

func (*Bid) Equals

func (b *Bid) Equals(t Transaction) bool

Equals returns true if two Bid tx's are the same

func (Bid) StandardTX

func (b Bid) StandardTX() Standard

StandardTX returns the embedded standard tx Implements Transaction interface.

type Coinbase

type Coinbase struct {
	// TxType represents the transaction type
	TxType TxType
	// TxID is the transaction identifier for the current transaction
	TxID    []byte
	R       []byte
	Score   []byte
	Proof   []byte
	Rewards Outputs
}

Coinbase transaction is the transaction that the block generator will create in order to be rewarded for their efforts.

func NewCoinbase

func NewCoinbase(proof, score, R []byte) *Coinbase

NewCoinbase will return a Coinbase transaction given the zkproof, ephemeral key and the block generators Address.

func (*Coinbase) AddReward

func (c *Coinbase) AddReward(output *Output)

AddReward will add an Output to the Coinbase struct Rewards array.

func (*Coinbase) CalculateHash

func (c *Coinbase) CalculateHash() ([]byte, error)

CalculateHash hashes all of the encoded fields in a tx, if this has not been done already. The resulting byte array is also it's identifier Implements merkletree.Payload interface

func (*Coinbase) Decode

func (c *Coinbase) Decode(r io.Reader) error

Decode implements the Decoder interface

func (*Coinbase) Encode

func (c *Coinbase) Encode(w io.Writer) error

Encode implements the Encoder interface

func (*Coinbase) Equals

func (c *Coinbase) Equals(t Transaction) bool

Equals returns true, if two coinbase tx's are equal

func (*Coinbase) StandardTX

func (c *Coinbase) StandardTX() Standard

StandardTX implements the transaction interface

func (*Coinbase) Type

func (c *Coinbase) Type() TxType

Type returns the transaction type Implements the TypeInfo interface

type Decoder

type Decoder interface {
	Decode(io.Reader) error
}

Decoder decodes a given io.Reader into a struct

type Encoder

type Encoder interface {
	Encode(io.Writer) error
}

Encoder encodes a given struct into an io.writer

type Input

type Input struct {
	// KeyImage is the image of the key that is being used to
	// sign the transaction
	KeyImage []byte // 32 bytes
	// PubKey is the one-time public key that this output was created with.
	// It acts as a output identifer because they can only be used once
	PubKey []byte // 32 bytes
	// PseudoCommitment acts as the dummy commitment used to construct the
	// intermediate ring signatures
	PseudoCommitment []byte // 32 bytes
	// Signature is the ring signature that is used
	// to sign the transaction
	Signature []byte // ~2500 bytes
}

Input defines an input in a standard transaction.

func NewInput

func NewInput(keyImage []byte, pubKey, pseudoComm, sig []byte) (*Input, error)

NewInput constructs a new Input from the passed parameters.

func (*Input) Decode

func (i *Input) Decode(r io.Reader) error

Decode an Input object from a io.reader.

func (*Input) Encode

func (i *Input) Encode(w io.Writer) error

Encode an Input object into an io.Writer.

func (*Input) Equals

func (i *Input) Equals(in *Input) bool

Equals returns true if two inputs are the same

type Inputs

type Inputs []*Input

Inputs is a slice of pointers to a set of `input`'s

func (Inputs) Equals

func (in Inputs) Equals(other Inputs) bool

Equals returns true, if two slices of inputs are the same

func (Inputs) HasDuplicates

func (in Inputs) HasDuplicates() bool

HasDuplicates checks whether any of the inputs contain duplciates This is done by checking their keyImages

func (Inputs) Len

func (in Inputs) Len() int

Len implements the sort interface

func (Inputs) Less

func (in Inputs) Less(i, j int) bool

Less implements the sort interface

func (Inputs) Swap

func (in Inputs) Swap(i, j int)

Swap implements the sort interface

type Output

type Output struct {
	// Commitment is the pedersen commitment to the underlying amount
	// In a bidding transaction, it is the amount in cleartext
	// For this reason, the size is varied. Once bidding transactions use Commitments,
	// The size will be changed to a fixed 32 bytes
	Commitment []byte // Variable size
	// DestKey is the one-time public key of the address that
	// the funds should be sent to.
	DestKey                        []byte // 32 bytes
	EncryptedAmount, EncryptedMask []byte
}

Output defines an output in a transaction.

func NewOutput

func NewOutput(comm []byte, dest []byte) (*Output, error)

NewOutput constructs a new Output from the passed parameters. This function is placed here for consistency with the rest of the API.

func (*Output) Decode

func (o *Output) Decode(r io.Reader) error

Decode an Output object from r into an output struct.

func (*Output) Encode

func (o *Output) Encode(w io.Writer) error

Encode an Output struct and write to w.

func (*Output) Equals

func (o *Output) Equals(out *Output) bool

Equals returns true if two outputs are the same

type Outputs

type Outputs []*Output

Outputs is a slice of pointers to a set of `input`'s

func (Outputs) Equals

func (out Outputs) Equals(other Outputs) bool

Equals returns true, if two slices of Outputs are the same

func (Outputs) HasDuplicates

func (out Outputs) HasDuplicates() bool

HasDuplicates checks whether an output contains a duplicate This is done by checking that there are no matching Destination keys

func (Outputs) Len

func (out Outputs) Len() int

Len implements the sort interface

func (Outputs) Less

func (out Outputs) Less(i, j int) bool

Less implements the sort interface

func (Outputs) Swap

func (out Outputs) Swap(i, j int)

Swap implements the sort interface

type Stake

type Stake struct {
	TimeLock
	PubKeyEd  []byte // 32 bytes
	PubKeyBLS []byte // 33 bytes
}

Stake transactions are time lock transactions that are used by nodes to allow them to become provisioners, and participate in the consensus protocol. What does the TimeLock represent? In a `Stake TX` it means that the Outputs, or the node's stake is locked until after the specified time. After this time, they will also no longer be a provisioner, and must re-stake to participate again.

func NewStake

func NewStake(ver uint8, lock, fee uint64, R, pubKeyEd, pubKeyBLS []byte) (*Stake, error)

NewStake will return a Stake transaction Given the tx version, the locktime,the fee and M

func (*Stake) CalculateHash

func (s *Stake) CalculateHash() ([]byte, error)

CalculateHash hashes all of the encoded fields in a tx, if this has not been done already. The resulting byte array is also it's identifier Implements merkletree.Payload interface

func (*Stake) Decode

func (s *Stake) Decode(r io.Reader) error

Decode implements the Decoder interface

func (*Stake) Encode

func (s *Stake) Encode(w io.Writer) error

Encode implements the Encoder interface

func (*Stake) Equals

func (s *Stake) Equals(t Transaction) bool

Equals returns true if two Stake tx's are the same

func (*Stake) GetOutputAmount

func (s *Stake) GetOutputAmount() uint64

func (Stake) StandardTX

func (s Stake) StandardTX() Standard

StandardTX returns the embedded standard tx Implements Transaction interface.

type Standard

type Standard struct {
	// TxType represents the transaction type
	TxType TxType
	// R is the Transaction Public Key
	R []byte
	// Version is the transaction version. It does not use semver.
	// A new transaction version denotes a modification of the previous structure
	Version uint8 // 1 byte
	// TxID is the hash of the transaction fields.
	TxID []byte // TxID (32 bytes)
	// Inputs represent a list of inputs to the transaction.
	Inputs Inputs
	// Outputs represent a list of outputs to the transaction
	Outputs Outputs
	// Fee is the assosciated fee attached to the transaction. This is in cleartext.
	Fee uint64
	// RangeProof is the bulletproof rangeproof that proves that the hidden amount
	// is between 0 and 2^64
	RangeProof []byte // Variable size
}

Standard is a generic transaction. It can also be seen as a stealth transaction. It is used to make basic payments on the dusk network.

func NewStandard

func NewStandard(ver uint8, fee uint64, R []byte) *Standard

NewStandard will return a Standard transaction given the tx version and the fee atached

func (*Standard) AddInput

func (s *Standard) AddInput(input *Input)

AddInput will add an input to the list of inputs in the transaction.

func (*Standard) AddOutput

func (s *Standard) AddOutput(output *Output)

AddOutput will add an output to the list of outputs in the transaction.

func (*Standard) CalculateHash

func (s *Standard) CalculateHash() ([]byte, error)

CalculateHash hashes all of the encoded fields in a tx, if this has not been done already. The resulting byte array is also it's identifier // Implements merkletree.Payload interface

func (*Standard) Decode

func (s *Standard) Decode(r io.Reader) error

Decode a reader into a standard transaction struct.

func (*Standard) Encode

func (s *Standard) Encode(w io.Writer) error

Encode a Standard transaction and write it to an io.Writer

func (*Standard) Equals

func (s *Standard) Equals(t Transaction) bool

Equals returns true if two standard tx's are the same

func (Standard) StandardTX

func (s Standard) StandardTX() Standard

StandardTX returns the standard struct Implements Transaction interface.

func (*Standard) Type

func (s *Standard) Type() TxType

Type returns the associated TxType for the Standard struct. Implements the TypeInfo interface

type TimeLock

type TimeLock struct {
	Standard
	// Lock represents the value for the timelock.
	// There are 2^64 possible values.
	// The Lock can be specified in either blockheight or unix timestamp
	// 0 to 0x8000000000000000 will represent the unixtimestamp in seconds
	// >= 0x8000000000000000 will represnt a blockheight
	// This means that block zero can be represented as 0x8000000000000000
	// And max blockheight for time-lock is `2^64-0x8000000000000000`
	Lock uint64
}

TimeLock represents a standard transaction that has an additional time restriction What does the time-lock represent? For a `Standard TimeLock`; that the TX can only become valid after the time stated. This is not the case for others, please check each transaction for the significance of the timelock

func NewTimeLock

func NewTimeLock(ver uint8, lock, fee uint64, R []byte) *TimeLock

NewTimeLock will return a TimeLock transaction Given the tx version, the locktime and the fee

func (*TimeLock) CalculateHash

func (t *TimeLock) CalculateHash() ([]byte, error)

CalculateHash hashes all of the encoded fields in a tx, if this has not been done already. The resulting byte array is also it's identifier // Implements merkletree.Payload interface

func (*TimeLock) Decode

func (t *TimeLock) Decode(r io.Reader) error

Decode implements the Decoder interface

func (*TimeLock) Encode

func (t *TimeLock) Encode(w io.Writer) error

Encode implements the Encoder interface

func (*TimeLock) Equals

func (t *TimeLock) Equals(tr Transaction) bool

Equals returns true if two timelocks tx's are the same

func (TimeLock) StandardTX

func (t TimeLock) StandardTX() Standard

StandardTX returns the embedded standard tx Implements Transaction interface.

type Transaction

type Transaction interface {
	Encoder
	Decoder
	TypeInfo
	merkletree.Payload
	Equals(Transaction) bool
	StandardTX() Standard
}

Transaction represents all transaction structures All transactions will embed the standard transaction. Returning Standard() allows the caller to fetch the inputs/outputs/fees without type casting the Transaction interface to a specific type

func FromReader

func FromReader(r io.Reader, numOfTXs uint64) ([]Transaction, error)

FromReader will decode into a slice of transactions

type TxType

type TxType uint8

TxType defines a transaction type identifier.

const (
	// CoinbaseType is the identifier for a block coinbase
	CoinbaseType TxType = 0x00

	// BidType is the identifier for a blind bid
	BidType TxType = 0x01

	// StakeType is the identifier for a stake
	StakeType TxType = 0x02

	// StandardType is the identifier for a standard transaction
	StandardType TxType = 0x03

	// TimelockType is the identifier for a standard time-locked transaction
	TimelockType TxType = 0x04

	// ContractType is the identifier for a smart contract transaction
	ContractType TxType = 0x05
)

type TypeInfo

type TypeInfo interface {
	Type() TxType
}

TypeInfo returns the underlying type of the transaction This allows the caller to type cast to a TypeInfo and switch on the Types in order to Decode into a TX

Jump to

Keyboard shortcuts

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