bc

package
v0.0.0-...-ff6bfbe Latest Latest
Warning

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

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

Documentation

Overview

Package bc is a generated protocol buffer package.

It is generated from these files:

bc.proto

It has these top-level messages:

Hash
Predicate
DataItem
BlockHeader
RawTx
RawBlock

Package bc defines basic blockchain data structures: transactions, blockheaders, and blocks.

The transaction structure defined here is the _output_ of a TxVM transaction program. It's created with NewTx, which runs that program to populate the data structure.

This package also defines a 32-byte Hash type as a protocol buffer message.

Index

Constants

View Source
const (
	InputType = iota
	OutputType
)

The type of a Contract (below).

Variables

View Source
var DataType_name = map[int32]string{
	0: "BYTES",
	1: "INT",
	2: "TUPLE",
}
View Source
var DataType_value = map[string]int32{
	"BYTES": 0,
	"INT":   1,
	"TUPLE": 2,
}
View Source
var EmptyStringHash = NewHash(sha3.Sum256(nil))

EmptyStringHash is the hash of the empty string.

View Source
var ErrTooFewSignatures = errors.New("too few block signatures")

ErrTooFewSignatures is the error returned when Block.Sign cannot marshal enough signatures for a block.

Functions

func DurationMillis

func DurationMillis(d time.Duration) uint64

DurationMillis converts a time.Duration to a number of milliseconds.

func FromMillis

func FromMillis(ms uint64) time.Time

FromMillis converts a number of milliseconds since 1970 to a time.Time.

func Millis

func Millis(t time.Time) uint64

Millis converts a time.Time to a number of milliseconds since 1970.

func MillisDuration

func MillisDuration(m uint64) time.Duration

MillisDuration coverts milliseconds to a time.Duration.

func NonceCommitment

func NonceCommitment(id Hash, expms uint64) []byte

NonceCommitment returns the byte commitment for the given nonce id and expiration.

Types

type Block

type Block struct {
	*UnsignedBlock
	Arguments []interface{}
}

func SignBlock

func SignBlock(b *UnsignedBlock, prev *BlockHeader, f func(int) (interface{}, error)) (*Block, error)

SignBlock produces a SignedBlock from a Block. It invokes its callback once for each position in [0..N) where N is the number of pubkeys in the previous block's NextPredicate, until a quorum of signatures is obtained.

Any callback returning an error will cause SignBlock to return with an error. A callback may also return (nil, nil), causing it to be skipped silently. If too many callbacks do this, SignBlock will return ErrTooFewSignatures.

func (*Block) Bytes

func (b *Block) Bytes() ([]byte, error)

Bytes encodes the Block as a byte slice, by converting it to a RawBlock protobuf and marshaling that.

func (*Block) FromBytes

func (b *Block) FromBytes(bits []byte) error

FromBytes parses a Block from a byte slice, by unmarshaling and converting a RawBlock protobuf.

func (*Block) MarshalText

func (b *Block) MarshalText() ([]byte, error)

MarshalText fulfills the json.Marshaler interface. This guarantees that blocks will get deserialized correctly when being parsed from HTTP requests.

func (*Block) Scan

func (b *Block) Scan(val interface{}) error

Scan fulfills the sql.Scanner interface.

func (*Block) UnmarshalText

func (b *Block) UnmarshalText(text []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

func (*Block) Value

func (b *Block) Value() (driver.Value, error)

Value fulfills the sql.driver.Valuer interface.

type BlockHeader

type BlockHeader struct {
	Version          uint64     `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
	Height           uint64     `protobuf:"varint,2,opt,name=height" json:"height,omitempty"`
	PreviousBlockId  *Hash      `protobuf:"bytes,3,opt,name=previous_block_id,json=previousBlockId" json:"previous_block_id,omitempty"`
	TimestampMs      uint64     `protobuf:"varint,4,opt,name=timestamp_ms,json=timestampMs" json:"timestamp_ms,omitempty"`
	Runlimit         int64      `protobuf:"varint,5,opt,name=runlimit" json:"runlimit,omitempty"`
	RefsCount        int64      `protobuf:"varint,6,opt,name=refs_count,json=refsCount" json:"refs_count,omitempty"`
	TransactionsRoot *Hash      `protobuf:"bytes,7,opt,name=transactions_root,json=transactionsRoot" json:"transactions_root,omitempty"`
	ContractsRoot    *Hash      `protobuf:"bytes,8,opt,name=contracts_root,json=contractsRoot" json:"contracts_root,omitempty"`
	NoncesRoot       *Hash      `protobuf:"bytes,9,opt,name=nonces_root,json=noncesRoot" json:"nonces_root,omitempty"`
	NextPredicate    *Predicate `protobuf:"bytes,10,opt,name=next_predicate,json=nextPredicate" json:"next_predicate,omitempty"`
	// Fields added by future versions of the protocol.
	ExtraFields []*DataItem `protobuf:"bytes,11,rep,name=extra_fields,json=extraFields" json:"extra_fields,omitempty"`
}

BlockHeader is the header of a Block: everything except the block's transactions and predicate args.

func (*BlockHeader) Descriptor

func (*BlockHeader) Descriptor() ([]byte, []int)

func (*BlockHeader) GetContractsRoot

func (m *BlockHeader) GetContractsRoot() *Hash

func (*BlockHeader) GetExtraFields

func (m *BlockHeader) GetExtraFields() []*DataItem

func (*BlockHeader) GetHeight

func (m *BlockHeader) GetHeight() uint64

func (*BlockHeader) GetNextPredicate

func (m *BlockHeader) GetNextPredicate() *Predicate

func (*BlockHeader) GetNoncesRoot

func (m *BlockHeader) GetNoncesRoot() *Hash

func (*BlockHeader) GetPreviousBlockId

func (m *BlockHeader) GetPreviousBlockId() *Hash

func (*BlockHeader) GetRefsCount

func (m *BlockHeader) GetRefsCount() int64

func (*BlockHeader) GetRunlimit

func (m *BlockHeader) GetRunlimit() int64

func (*BlockHeader) GetTimestampMs

func (m *BlockHeader) GetTimestampMs() uint64

func (*BlockHeader) GetTransactionsRoot

func (m *BlockHeader) GetTransactionsRoot() *Hash

func (*BlockHeader) GetVersion

func (m *BlockHeader) GetVersion() uint64

func (*BlockHeader) Hash

func (bh *BlockHeader) Hash() (hash Hash)

Hash computes the unique Chain protocol hash of the BlockHeader.

func (*BlockHeader) ProtoMessage

func (*BlockHeader) ProtoMessage()

func (*BlockHeader) Reset

func (m *BlockHeader) Reset()

func (*BlockHeader) Scan

func (bh *BlockHeader) Scan(val interface{}) error

Scan satisfies the database.sql.Scanner interface.

func (*BlockHeader) String

func (m *BlockHeader) String() string

func (*BlockHeader) Value

func (bh *BlockHeader) Value() (driver.Value, error)

Value satisfies the Valuer interface from database/sql/driver.

type CommitmentsTx

type CommitmentsTx struct {
	Tx                *Tx
	NonceCommitments  map[Hash][]byte
	WitnessCommitment []byte
}

CommitmentsTx wraps a Tx with its nonce and witness commitments.

func NewCommitmentsTx

func NewCommitmentsTx(tx *Tx) *CommitmentsTx

NewCommitmentsTx takes a Tx object and returns a CommitmentsTx wrapped with the transaction's nonce and witness commitments.

type Contract

type Contract struct {
	Type int
	ID   Hash
}

Contract contains the ID of an input or an output from the txvm log. The Type field tells which kind of contract it is (InputType or OutputType).

type DataItem

type DataItem struct {
	Type  DataType    `protobuf:"varint,1,opt,name=type,enum=bc.DataType" json:"type,omitempty"`
	Bytes []byte      `protobuf:"bytes,2,opt,name=bytes,proto3" json:"bytes,omitempty"`
	Int   int64       `protobuf:"varint,3,opt,name=int" json:"int,omitempty"`
	Tuple []*DataItem `protobuf:"bytes,4,rep,name=tuple" json:"tuple,omitempty"`
}

DataItem is a txvm plain-data item: bytes, int, or tuple.

func (*DataItem) Descriptor

func (*DataItem) Descriptor() ([]byte, []int)

func (*DataItem) GetBytes

func (m *DataItem) GetBytes() []byte

func (*DataItem) GetInt

func (m *DataItem) GetInt() int64

func (*DataItem) GetTuple

func (m *DataItem) GetTuple() []*DataItem

func (*DataItem) GetType

func (m *DataItem) GetType() DataType

func (*DataItem) ProtoMessage

func (*DataItem) ProtoMessage()

func (*DataItem) Reset

func (m *DataItem) Reset()

func (*DataItem) String

func (m *DataItem) String() string

type DataType

type DataType int32

DataType is the type for a DataItem.

const (
	DataType_BYTES DataType = 0
	DataType_INT   DataType = 1
	DataType_TUPLE DataType = 2
)

func (DataType) EnumDescriptor

func (DataType) EnumDescriptor() ([]byte, []int)

func (DataType) String

func (x DataType) String() string

type Hash

type Hash struct {
	V0 uint64 `protobuf:"fixed64,1,opt,name=v0" json:"v0,omitempty"`
	V1 uint64 `protobuf:"fixed64,2,opt,name=v1" json:"v1,omitempty"`
	V2 uint64 `protobuf:"fixed64,3,opt,name=v2" json:"v2,omitempty"`
	V3 uint64 `protobuf:"fixed64,4,opt,name=v3" json:"v3,omitempty"`
}

Hash is a 32-byte hash.

func HashFromBytes

func HashFromBytes(b []byte) Hash

HashFromBytes creates a new Hash from a byte slice. The caller is responsible for ensuring the byte slice is of the right length. It will be 0-padded or truncated if it's not.

func NewHash

func NewHash(b32 [32]byte) (h Hash)

NewHash produces a hash from a 32-byte array.

func TxMerkleRoot

func TxMerkleRoot(txs []*Tx) Hash

TxMerkleRoot creates a merkle tree from a slice of Transactions and returns the root hash of the tree.

func (Hash) Byte32

func (h Hash) Byte32() (b32 [32]byte)

Byte32 returns the hash as a 32-byte array.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the hash as a byte slice.

func (*Hash) Descriptor

func (*Hash) Descriptor() ([]byte, []int)

func (*Hash) GetV0

func (m *Hash) GetV0() uint64

func (*Hash) GetV1

func (m *Hash) GetV1() uint64

func (*Hash) GetV2

func (m *Hash) GetV2() uint64

func (*Hash) GetV3

func (m *Hash) GetV3() uint64

func (*Hash) IsZero

func (h *Hash) IsZero() bool

IsZero tells whether a Hash pointer is nil or points to an all-zero hash.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText satisfies the TextMarshaler interface. It returns the bytes of h encoded in hex, for formats that can't hold arbitrary binary data. It never returns an error.

func (*Hash) ProtoMessage

func (*Hash) ProtoMessage()

func (*Hash) ReadFrom

func (h *Hash) ReadFrom(r io.Reader) (int64, error)

ReadFrom satisfies the io.ReaderFrom interface.

func (*Hash) Reset

func (m *Hash) Reset()

func (*Hash) Scan

func (h *Hash) Scan(v interface{}) error

Scan satisfies the driver.Scanner interface

func (*Hash) String

func (m *Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(b []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface. If b is a JSON-encoded null, it copies the zero-value into h. Othwerwise, it decodes hex data from b into h.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(v []byte) error

UnmarshalText satisfies the TextUnmarshaler interface. It decodes hex data from b into h.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface

func (Hash) WriteTo

func (h Hash) WriteTo(w io.Writer) (int64, error)

WriteTo satisfies the io.WriterTo interface.

type Input

type Input struct {
	ID      Hash
	Seed    Hash
	Stack   []txvm.Data
	Program []byte
	LogPos  int
}

Input is a parsed input-typed txvm log entry, plus information derived from stack introspection during execution.

type Issuance

type Issuance struct {
	Seed    Hash
	Stack   []txvm.Data
	Program []byte
	Amount  int64
	AssetID Hash
	Anchor  []byte
	LogPos  int
}

Issuance is a parsed issuance-typed txvm log entry.

type Nonce

type Nonce struct {
	ID      Hash
	BlockID Hash
	ExpMS   uint64
}

Nonce is a parsed nonce-typed txvm log entry.

type Output

type Output struct {
	ID      Hash
	Seed    Hash
	Stack   []txvm.Data
	Program []byte
	LogPos  int
}

Output is a parsed output-typed txvm log entry, plus information derived from stack introspection during execution.

type Predicate

type Predicate struct {
	Version int64 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
	// These fields apply only when version is 1.
	Quorum  int32    `protobuf:"varint,2,opt,name=quorum" json:"quorum,omitempty"`
	Pubkeys [][]byte `protobuf:"bytes,3,rep,name=pubkeys,proto3" json:"pubkeys,omitempty"`
	// Fields for predicate versions other than 1.
	OtherFields []*DataItem `protobuf:"bytes,4,rep,name=other_fields,json=otherFields" json:"other_fields,omitempty"`
}

Predicate contains the quorum and pubkeys needed to authenticate a block.

func (*Predicate) Descriptor

func (*Predicate) Descriptor() ([]byte, []int)

func (*Predicate) GetOtherFields

func (m *Predicate) GetOtherFields() []*DataItem

func (*Predicate) GetPubkeys

func (m *Predicate) GetPubkeys() [][]byte

func (*Predicate) GetQuorum

func (m *Predicate) GetQuorum() int32

func (*Predicate) GetVersion

func (m *Predicate) GetVersion() int64

func (*Predicate) ProtoMessage

func (*Predicate) ProtoMessage()

func (*Predicate) Reset

func (m *Predicate) Reset()

func (*Predicate) String

func (m *Predicate) String() string

type RawBlock

type RawBlock struct {
	Header       *BlockHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"`
	Transactions []*RawTx     `protobuf:"bytes,2,rep,name=transactions" json:"transactions,omitempty"`
	Arguments    []*DataItem  `protobuf:"bytes,3,rep,name=arguments" json:"arguments,omitempty"`
}

RawBlock is a raw block.

func (*RawBlock) Descriptor

func (*RawBlock) Descriptor() ([]byte, []int)

func (*RawBlock) GetArguments

func (m *RawBlock) GetArguments() []*DataItem

func (*RawBlock) GetHeader

func (m *RawBlock) GetHeader() *BlockHeader

func (*RawBlock) GetTransactions

func (m *RawBlock) GetTransactions() []*RawTx

func (*RawBlock) ProtoMessage

func (*RawBlock) ProtoMessage()

func (*RawBlock) Reset

func (m *RawBlock) Reset()

func (*RawBlock) String

func (m *RawBlock) String() string

type RawTx

type RawTx struct {
	Version  int64  `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
	Runlimit int64  `protobuf:"varint,2,opt,name=runlimit" json:"runlimit,omitempty"`
	Program  []byte `protobuf:"bytes,3,opt,name=program,proto3" json:"program,omitempty"`
}

RawTx is a raw transaction, before processing through txvm.

func (*RawTx) Descriptor

func (*RawTx) Descriptor() ([]byte, []int)

func (*RawTx) GetProgram

func (m *RawTx) GetProgram() []byte

func (*RawTx) GetRunlimit

func (m *RawTx) GetRunlimit() int64

func (*RawTx) GetVersion

func (m *RawTx) GetVersion() int64

func (*RawTx) ProtoMessage

func (*RawTx) ProtoMessage()

func (*RawTx) Reset

func (m *RawTx) Reset()

func (*RawTx) String

func (m *RawTx) String() string

type Retirement

type Retirement struct {
	Amount  int64
	AssetID Hash
	Anchor  []byte
	LogPos  int
}

Retirement is a parsed retirement-typed txvm log entry.

type Timerange

type Timerange struct {
	MinMS, MaxMS int64
}

Timerange is a parsed timerange-typed txvm log entry.

type Tx

type Tx struct {
	RawTx

	Finalized bool
	ID        Hash
	Log       []txvm.Tuple

	// Used in protocol validation and state updates
	Contracts  []Contract
	Timeranges []Timerange
	Nonces     []Nonce
	Anchor     []byte

	Inputs      []Input
	Issuances   []Issuance
	Outputs     []Output
	Retirements []Retirement
}

Tx contains the input to an instance of the txvm virtual machine, plus parsed copies of its various side effects.

func NewTx

func NewTx(prog []byte, version, runlimit int64, option ...txvm.Option) (*Tx, error)

NewTx runs the given txvm program through an instance of the txvm virtual machine, populating a new Tx object with its side effects.

func (*Tx) WriteWitnessCommitmentTo

func (tx *Tx) WriteWitnessCommitmentTo(w io.Writer) (int, error)

WriteWitnessCommitmentTo writes the "Transaction Witness Commitment" to w, consisting of the version, runlimit, and program in a tuple, encoded according to standard txvm convention, hashed together with the txid.

The only errors returned are those from w.

type UnsignedBlock

type UnsignedBlock struct {
	*BlockHeader
	Transactions []*Tx
}

UnsignedBlock describes a block with its transactions but no signatures (predicate args).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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