txs

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

README

tendermint/block

Block

TODO: document

Header
Validation
Data

PartSet

PartSet is used to split a byteslice of data into parts (pieces) for transmission. By splitting data into smaller parts and computing a Merkle root hash on the list, you can verify that a part is legitimately part of the complete data, and the part can be forwarded to other peers before all the parts are known. In short, it's a fast way to propagate a large file over a gossip network.

PartSet was inspired by the LibSwift project.

Usage:

data := RandBytes(2 << 20) // Something large

partSet := NewPartSetFromData(data)
partSet.Total()     // Total number of 4KB parts
partSet.Count()     // Equal to the Total, since we already have all the parts
partSet.Hash()      // The Merkle root hash
partSet.BitArray()  // A BitArray of partSet.Total() 1's

header := partSet.Header() // Send this to the peer
header.Total        // Total number of parts
header.Hash         // The merkle root hash

// Now we'll reconstruct the data from the parts
partSet2 := NewPartSetFromHeader(header)
partSet2.Total()    // Same total as partSet.Total()
partSet2.Count()    // Zero, since this PartSet doesn't have any parts yet.
partSet2.Hash()     // Same hash as in partSet.Hash()
partSet2.BitArray() // A BitArray of partSet.Total() 0's

// In a gossip network the parts would arrive in arbitrary order, perhaps
// in response to explicit requests for parts, or optimistically in response
// to the receiving peer's partSet.BitArray().
for !partSet2.IsComplete() {
    part := receivePartFromGossipNetwork()
    added, err := partSet2.AddPart(part)
    if err != nil {
		// A wrong part,
        // the merkle trail does not hash to partSet2.Hash()
    } else if !added {
        // A duplicate part already received
    }
}

data2, _ := ioutil.ReadAll(partSet2.GetReader())
bytes.Equal(data, data2) // true

Documentation

Index

Constants

View Source
const (
	EventDataTypeNewBlock       = byte(0x01)
	EventDataTypeFork           = byte(0x02)
	EventDataTypeTx             = byte(0x03)
	EventDataTypeCall           = byte(0x04)
	EventDataTypeLog            = byte(0x05)
	EventDataTypeNewBlockHeader = byte(0x06)

	EventDataTypeRoundState = byte(0x11)
	EventDataTypeVote       = byte(0x12)
)
View Source
const (
	// Account transactions
	TxTypeSend = byte(0x01)
	TxTypeCall = byte(0x02)
	TxTypeName = byte(0x03)

	// Validation transactions
	TxTypeBond    = byte(0x11)
	TxTypeUnbond  = byte(0x12)
	TxTypeRebond  = byte(0x13)
	TxTypeDupeout = byte(0x14)

	// Admin transactions
	TxTypePermissions = byte(0x20)
)

Types of Tx implementations

Variables

View Source
var (
	MinNameRegistrationPeriod int = 5

	// cost for storing a name for a block is
	// CostPerBlock*CostPerByte*(len(data) + 32)
	NameByteCostMultiplier  int64 = 1
	NameBlockCostMultiplier int64 = 1

	MaxNameLength = 64
	MaxDataLength = 1 << 16
)
View Source
var (
	ErrTxInvalidAddress       = errors.New("Error invalid address")
	ErrTxDuplicateAddress     = errors.New("Error duplicate address")
	ErrTxInvalidAmount        = errors.New("Error invalid amount")
	ErrTxInsufficientFunds    = errors.New("Error insufficient funds")
	ErrTxInsufficientGasPrice = errors.New("Error insufficient gas price")
	ErrTxUnknownPubKey        = errors.New("Error unknown pubkey")
	ErrTxInvalidPubKey        = errors.New("Error invalid pubkey")
	ErrTxInvalidSignature     = errors.New("Error invalid signature")
	ErrTxPermissionDenied     = errors.New("Error permission denied")
)

Functions

func EncodeTx

func EncodeTx(tx Tx) ([]byte, error)

func EventStringAccCall

func EventStringAccCall(addr []byte) string

func EventStringAccInput

func EventStringAccInput(addr []byte) string

func EventStringAccOutput

func EventStringAccOutput(addr []byte) string

func EventStringBond

func EventStringBond() string

func EventStringCompleteProposal

func EventStringCompleteProposal() string

func EventStringDupeout

func EventStringDupeout() string

func EventStringFork

func EventStringFork() string

func EventStringLock

func EventStringLock() string

func EventStringLogEvent

func EventStringLogEvent(addr []byte) string

func EventStringNameReg

func EventStringNameReg(name string) string

func EventStringNewBlock

func EventStringNewBlock() string

func EventStringNewRound

func EventStringNewRound() string

func EventStringPermissions

func EventStringPermissions(name string) string

func EventStringPolka

func EventStringPolka() string

func EventStringRebond

func EventStringRebond() string

func EventStringRelock

func EventStringRelock() string

func EventStringTimeoutPropose

func EventStringTimeoutPropose() string

func EventStringTimeoutWait

func EventStringTimeoutWait() string

func EventStringUnbond

func EventStringUnbond() string

func EventStringUnlock

func EventStringUnlock() string

func EventStringVote

func EventStringVote() string

func NameBaseCost

func NameBaseCost(name, data string) int64

base cost is "effective" number of bytes

func NameCostPerBlock

func NameCostPerBlock(baseCost int64) int64

func NewContractAddress

func NewContractAddress(caller []byte, nonce int) []byte

func TxHash

func TxHash(chainID string, tx Tx) []byte

Types

type AccountGetter

type AccountGetter interface {
	GetAccount(addr []byte) *acm.Account
}

type BondTx

type BondTx struct {
	PubKey    crypto.PubKeyEd25519    `json:"pub_key"` // NOTE: these don't have type byte
	Signature crypto.SignatureEd25519 `json:"signature"`
	Inputs    []*TxInput              `json:"inputs"`
	UnbondTo  []*TxOutput             `json:"unbond_to"`
}

func NewBondTx

func NewBondTx(pubkey crypto.PubKey) (*BondTx, error)

func (*BondTx) AddInput

func (tx *BondTx) AddInput(st AccountGetter, pubkey crypto.PubKey, amt int64) error

func (*BondTx) AddInputWithNonce

func (tx *BondTx) AddInputWithNonce(pubkey crypto.PubKey, amt int64, nonce int) error

func (*BondTx) AddOutput

func (tx *BondTx) AddOutput(addr []byte, amt int64) error

func (*BondTx) SignBond

func (tx *BondTx) SignBond(chainID string, privAccount *acm.PrivAccount) error

func (*BondTx) SignInput

func (tx *BondTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error

func (*BondTx) String

func (tx *BondTx) String() string

func (*BondTx) WriteSignBytes

func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type CallData

type CallData struct {
	Caller []byte `json:"caller"`
	Callee []byte `json:"callee"`
	Data   []byte `json:"data"`
	Value  int64  `json:"value"`
	Gas    int64  `json:"gas"`
}

type CallTx

type CallTx struct {
	Input    *TxInput `json:"input"`
	Address  []byte   `json:"address"`
	GasLimit int64    `json:"gas_limit"`
	Fee      int64    `json:"fee"`
	Data     []byte   `json:"data"`
}

func NewCallTx

func NewCallTx(st AccountGetter, from crypto.PubKey, to, data []byte, amt, gasLimit, fee int64) (*CallTx, error)

func NewCallTxWithNonce

func NewCallTxWithNonce(from crypto.PubKey, to, data []byte, amt, gasLimit, fee int64, nonce int) *CallTx

func (*CallTx) Sign

func (tx *CallTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*CallTx) String

func (tx *CallTx) String() string

func (*CallTx) WriteSignBytes

func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type DupeoutTx

type DupeoutTx struct {
	Address []byte                `json:"address"`
	VoteA   tendermint_types.Vote `json:"vote_a"`
	VoteB   tendermint_types.Vote `json:"vote_b"`
}

func (*DupeoutTx) String

func (tx *DupeoutTx) String() string

func (*DupeoutTx) WriteSignBytes

func (tx *DupeoutTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type ErrTxInvalidSequence

type ErrTxInvalidSequence struct {
	Got      int
	Expected int
}

func (ErrTxInvalidSequence) Error

func (e ErrTxInvalidSequence) Error() string

type ErrTxInvalidString

type ErrTxInvalidString struct {
	Msg string
}

func (ErrTxInvalidString) Error

func (e ErrTxInvalidString) Error() string

type EventData

type EventData interface {
	AssertIsEventData()
}

type EventDataCall

type EventDataCall struct {
	CallData  *CallData `json:"call_data"`
	Origin    []byte    `json:"origin"`
	TxID      []byte    `json:"tx_id"`
	Return    []byte    `json:"return"`
	Exception string    `json:"exception"`
}

EventDataCall fires when we call a contract, and when a contract calls another contract

func (EventDataCall) AssertIsEventData

func (_ EventDataCall) AssertIsEventData()

type EventDataLog

type EventDataLog struct {
	Address Word256   `json:"address"`
	Topics  []Word256 `json:"topics"`
	Data    []byte    `json:"data"`
	Height  int64     `json:"height"`
}

EventDataLog fires when a contract executes the LOG opcode

func (EventDataLog) AssertIsEventData

func (_ EventDataLog) AssertIsEventData()

type EventDataNewBlock

type EventDataNewBlock struct {
	Block *tm_types.Block `json:"block"`
}

func (EventDataNewBlock) AssertIsEventData

func (_ EventDataNewBlock) AssertIsEventData()

type EventDataNewBlockHeader

type EventDataNewBlockHeader struct {
	Header *tm_types.Header `json:"header"`
}

func (EventDataNewBlockHeader) AssertIsEventData

func (_ EventDataNewBlockHeader) AssertIsEventData()

type EventDataRoundState

type EventDataRoundState struct {
	CurrentTime time.Time `json:"current_time"`

	Height        int                `json:"height"`
	Round         int                `json:"round"`
	Step          string             `json:"step"`
	StartTime     time.Time          `json:"start_time"`
	CommitTime    time.Time          `json:"commit_time"`
	Proposal      *tm_types.Proposal `json:"proposal"`
	ProposalBlock *tm_types.Block    `json:"proposal_block"`
	LockedRound   int                `json:"locked_round"`
	LockedBlock   *tm_types.Block    `json:"locked_block"`
	POLRound      int                `json:"pol_round"`
}

We fire the most recent round state that led to the event (ie. NewRound will have the previous rounds state)

func (EventDataRoundState) AssertIsEventData

func (_ EventDataRoundState) AssertIsEventData()

type EventDataTx

type EventDataTx struct {
	Tx        Tx     `json:"tx"`
	Return    []byte `json:"return"`
	Exception string `json:"exception"`
}

All txs fire EventDataTx, but only CallTx might have Return or Exception

func (EventDataTx) AssertIsEventData

func (_ EventDataTx) AssertIsEventData()

type EventDataVote

type EventDataVote struct {
	Index   int
	Address []byte
	Vote    *tm_types.Vote
}

func (EventDataVote) AssertIsEventData

func (_ EventDataVote) AssertIsEventData()

type NameTx

type NameTx struct {
	Input *TxInput `json:"input"`
	Name  string   `json:"name"`
	Data  string   `json:"data"`
	Fee   int64    `json:"fee"`
}

func NewNameTx

func NewNameTx(st AccountGetter, from crypto.PubKey, name, data string, amt, fee int64) (*NameTx, error)

func NewNameTxWithNonce

func NewNameTxWithNonce(from crypto.PubKey, name, data string, amt, fee int64, nonce int) *NameTx

func (*NameTx) Sign

func (tx *NameTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*NameTx) String

func (tx *NameTx) String() string

func (*NameTx) ValidateStrings

func (tx *NameTx) ValidateStrings() error

func (*NameTx) WriteSignBytes

func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type PermissionsTx

type PermissionsTx struct {
	Input    *TxInput        `json:"input"`
	PermArgs ptypes.PermArgs `json:"args"`
}

func NewPermissionsTx

func NewPermissionsTx(st AccountGetter, from crypto.PubKey, args ptypes.PermArgs) (*PermissionsTx, error)

func NewPermissionsTxWithNonce

func NewPermissionsTxWithNonce(from crypto.PubKey, args ptypes.PermArgs, nonce int) *PermissionsTx

func (*PermissionsTx) Sign

func (tx *PermissionsTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*PermissionsTx) String

func (tx *PermissionsTx) String() string

func (*PermissionsTx) WriteSignBytes

func (tx *PermissionsTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type RebondTx

type RebondTx struct {
	Address   []byte                  `json:"address"`
	Height    int                     `json:"height"`
	Signature crypto.SignatureEd25519 `json:"signature"`
}

func NewRebondTx

func NewRebondTx(addr []byte, height int) *RebondTx

func (*RebondTx) Sign

func (tx *RebondTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*RebondTx) String

func (tx *RebondTx) String() string

func (*RebondTx) WriteSignBytes

func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type Receipt

type Receipt struct {
	TxHash          []byte `json:"tx_hash"`
	CreatesContract uint8  `json:"creates_contract"`
	ContractAddr    []byte `json:"contract_addr"`
}

BroadcastTx or Transact

func GenerateReceipt

func GenerateReceipt(chainId string, tx Tx) Receipt

type ResultListNames

type ResultListNames struct {
	BlockHeight int                        `json:"block_height"`
	Names       []*core_types.NameRegEntry `json:"names"`
}

XXX: vestige of an older time

type SendTx

type SendTx struct {
	Inputs  []*TxInput  `json:"inputs"`
	Outputs []*TxOutput `json:"outputs"`
}

func NewSendTx

func NewSendTx() *SendTx

func (*SendTx) AddInput

func (tx *SendTx) AddInput(st AccountGetter, pubkey crypto.PubKey, amt int64) error

func (*SendTx) AddInputWithNonce

func (tx *SendTx) AddInputWithNonce(pubkey crypto.PubKey, amt int64, nonce int) error

func (*SendTx) AddOutput

func (tx *SendTx) AddOutput(addr []byte, amt int64) error

func (*SendTx) SignInput

func (tx *SendTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error

func (*SendTx) String

func (tx *SendTx) String() string

func (*SendTx) WriteSignBytes

func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type Tx

type Tx interface {
	WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
}

func DecodeTx

func DecodeTx(txBytes []byte) (Tx, error)

panic on err

type TxInput

type TxInput struct {
	Address   []byte           `json:"address"`   // Hash of the PubKey
	Amount    int64            `json:"amount"`    // Must not exceed account balance
	Sequence  int              `json:"sequence"`  // Must be 1 greater than the last committed TxInput
	Signature crypto.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
	PubKey    crypto.PubKey    `json:"pub_key"`   // Must not be nil, may be nil
}

func (*TxInput) String

func (txIn *TxInput) String() string

func (*TxInput) ValidateBasic

func (txIn *TxInput) ValidateBasic() error

func (*TxInput) WriteSignBytes

func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int, err *error)

type TxOutput

type TxOutput struct {
	Address []byte `json:"address"` // Hash of the PubKey
	Amount  int64  `json:"amount"`  // The sum of all outputs must not exceed the inputs.
}

func (*TxOutput) String

func (txOut *TxOutput) String() string

func (*TxOutput) ValidateBasic

func (txOut *TxOutput) ValidateBasic() error

func (*TxOutput) WriteSignBytes

func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int, err *error)

type UnbondTx

type UnbondTx struct {
	Address   []byte                  `json:"address"`
	Height    int                     `json:"height"`
	Signature crypto.SignatureEd25519 `json:"signature"`
}

func NewUnbondTx

func NewUnbondTx(addr []byte, height int) *UnbondTx

func (*UnbondTx) Sign

func (tx *UnbondTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*UnbondTx) String

func (tx *UnbondTx) String() string

func (*UnbondTx) WriteSignBytes

func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type UnconfirmedTxs

type UnconfirmedTxs struct {
	Txs []Tx `json:"txs"`
}

UnconfirmedTxs

Jump to

Keyboard shortcuts

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