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
- Variables
- func DurationMillis(d time.Duration) uint64
- func FromMillis(ms uint64) time.Time
- func Millis(t time.Time) uint64
- func MillisDuration(m uint64) time.Duration
- func NonceCommitment(id Hash, expms uint64) []byte
- type Block
- type BlockHeader
- func (*BlockHeader) Descriptor() ([]byte, []int)
- func (m *BlockHeader) GetContractsRoot() *Hash
- func (m *BlockHeader) GetExtraFields() []*DataItem
- func (m *BlockHeader) GetHeight() uint64
- func (m *BlockHeader) GetNextPredicate() *Predicate
- func (m *BlockHeader) GetNoncesRoot() *Hash
- func (m *BlockHeader) GetPreviousBlockId() *Hash
- func (m *BlockHeader) GetRefsCount() int64
- func (m *BlockHeader) GetRunlimit() int64
- func (m *BlockHeader) GetTimestampMs() uint64
- func (m *BlockHeader) GetTransactionsRoot() *Hash
- func (m *BlockHeader) GetVersion() uint64
- func (bh *BlockHeader) Hash() (hash Hash)
- func (*BlockHeader) ProtoMessage()
- func (m *BlockHeader) Reset()
- func (bh *BlockHeader) Scan(val interface{}) error
- func (m *BlockHeader) String() string
- func (bh *BlockHeader) Value() (driver.Value, error)
- type CommitmentsTx
- type Contract
- type DataItem
- type DataType
- type Hash
- func (h Hash) Byte32() (b32 [32]byte)
- func (h Hash) Bytes() []byte
- func (*Hash) Descriptor() ([]byte, []int)
- func (m *Hash) GetV0() uint64
- func (m *Hash) GetV1() uint64
- func (m *Hash) GetV2() uint64
- func (m *Hash) GetV3() uint64
- func (h *Hash) IsZero() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (*Hash) ProtoMessage()
- func (h *Hash) ReadFrom(r io.Reader) (int64, error)
- func (m *Hash) Reset()
- func (h *Hash) Scan(v interface{}) error
- func (m *Hash) String() string
- func (h *Hash) UnmarshalJSON(b []byte) error
- func (h *Hash) UnmarshalText(v []byte) error
- func (h Hash) Value() (driver.Value, error)
- func (h Hash) WriteTo(w io.Writer) (int64, error)
- type Input
- type Issuance
- type Nonce
- type Output
- type Predicate
- func (*Predicate) Descriptor() ([]byte, []int)
- func (m *Predicate) GetOtherFields() []*DataItem
- func (m *Predicate) GetPubkeys() [][]byte
- func (m *Predicate) GetQuorum() int32
- func (m *Predicate) GetVersion() int64
- func (*Predicate) ProtoMessage()
- func (m *Predicate) Reset()
- func (m *Predicate) String() string
- type RawBlock
- type RawTx
- type Retirement
- type Timerange
- type Tx
- type UnsignedBlock
Constants ¶
const ( InputType = iota OutputType )
The type of a Contract (below).
Variables ¶
var DataType_name = map[int32]string{
0: "BYTES",
1: "INT",
2: "TUPLE",
}
var DataType_value = map[string]int32{
"BYTES": 0,
"INT": 1,
"TUPLE": 2,
}
var EmptyStringHash = NewHash(sha3.Sum256(nil))
EmptyStringHash is the hash of the empty string.
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 ¶
DurationMillis converts a time.Duration to a number of milliseconds.
func FromMillis ¶
FromMillis converts a number of milliseconds since 1970 to a time.Time.
func MillisDuration ¶
MillisDuration coverts milliseconds to a time.Duration.
func NonceCommitment ¶
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 ¶
Bytes encodes the Block as a byte slice, by converting it to a RawBlock protobuf and marshaling that.
func (*Block) FromBytes ¶
FromBytes parses a Block from a byte slice, by unmarshaling and converting a RawBlock protobuf.
func (*Block) MarshalText ¶
MarshalText fulfills the json.Marshaler interface. This guarantees that blocks will get deserialized correctly when being parsed from HTTP requests.
func (*Block) UnmarshalText ¶
UnmarshalText fulfills the encoding.TextUnmarshaler 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
type CommitmentsTx ¶
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 ¶
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) ProtoMessage ¶
func (*DataItem) ProtoMessage()
type DataType ¶
type DataType int32
DataType is the type for a DataItem.
func (DataType) EnumDescriptor ¶
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 ¶
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 TxMerkleRoot ¶
TxMerkleRoot creates a merkle tree from a slice of Transactions and returns the root hash of the tree.
func (*Hash) Descriptor ¶
func (Hash) MarshalText ¶
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) UnmarshalJSON ¶
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 ¶
UnmarshalText satisfies the TextUnmarshaler interface. It decodes hex data from b into h.
type Input ¶
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 Output ¶
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) GetOtherFields ¶
func (*Predicate) GetPubkeys ¶
func (*Predicate) GetVersion ¶
func (*Predicate) ProtoMessage ¶
func (*Predicate) ProtoMessage()
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) GetArguments ¶
func (*RawBlock) GetHeader ¶
func (m *RawBlock) GetHeader() *BlockHeader
func (*RawBlock) GetTransactions ¶
func (*RawBlock) ProtoMessage ¶
func (*RawBlock) ProtoMessage()
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) GetProgram ¶
func (*RawTx) GetRunlimit ¶
func (*RawTx) GetVersion ¶
func (*RawTx) ProtoMessage ¶
func (*RawTx) ProtoMessage()
type Retirement ¶
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 ¶
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 ¶
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).