bcpb

package
v0.0.0-...-811092d Latest Latest
Warning

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

Go to latest
Published: May 23, 2018 License: MPL-2.0 Imports: 16 Imported by: 2

Documentation

Overview

Package bcpb is a generated protocol buffer package.

It is generated from these files:

types.proto

It has these top-level messages:

BlockHeader
Block
TxHeader
TxInput
TxOutput
Tx

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSignatureVerificationFailed is returned when a signature cannot be
	// verified
	ErrSignatureVerificationFailed = errors.New("signature verification failed")
	// ErrNotAuthorized is returned when the given public is not allowed to
	// access the output
	ErrNotAuthorized = errors.New("not authorized")
	// ErrSignerNotInBlock is returned when a signer signs a block but is not
	// a participant block signer
	ErrSignerNotInBlock = errors.New("signer not in block")
	// ErrSignerAlreadySigned is returned when a signer tries to sign when they
	// already have
	ErrSignerAlreadySigned = errors.New("signer already signed")
)
View Source
var (
	ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTypes   = fmt.Errorf("proto: integer overflow")
)

Functions

func ValidatePublicKeyAddress

func ValidatePublicKeyAddress(address []byte, h hash.Hash) bool

ValidatePublicKeyAddress validates the public key address returning true if it is valid

Types

type Block

type Block struct {
	// Block header.  All signature data should be part of the ledger
	Header *BlockHeader `protobuf:"bytes,1,opt,name=Header" json:"Header,omitempty"`
	// List of tx ids part of this block
	Txs []Digest `protobuf:"bytes,2,rep,name=Txs,casttype=Digest" json:"Txs,omitempty"`
	// Signatures associated to each pubkey
	Signatures [][]byte `protobuf:"bytes,3,rep,name=Signatures" json:"Signatures,omitempty"`
	// Digest of the block
	Digest Digest `protobuf:"bytes,4,opt,name=Digest,proto3,casttype=Digest" json:"Digest,omitempty"`
}

Block is a ledger block

func NewBlock

func NewBlock() *Block

NewBlock returns a new empty block

func (*Block) AddSigner

func (blk *Block) AddSigner(pubkey PublicKey)

AddSigner adds a signer i.e public key to the block header

func (*Block) Clone

func (blk *Block) Clone() *Block

Clone clones the block

func (*Block) Descriptor

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

func (*Block) GetDigest

func (m *Block) GetDigest() Digest

func (*Block) GetHeader

func (m *Block) GetHeader() *BlockHeader

func (*Block) GetSignatures

func (m *Block) GetSignatures() [][]byte

func (*Block) GetTxs

func (m *Block) GetTxs() []Digest

func (*Block) HasSignatures

func (blk *Block) HasSignatures() bool

HasSignatures returns true if the block has the required number of signatures as specified by the S value in the header

func (*Block) Height

func (blk *Block) Height() uint32

Height returns the block height

func (*Block) Marshal

func (m *Block) Marshal() (dAtA []byte, err error)

func (*Block) MarshalTo

func (m *Block) MarshalTo(dAtA []byte) (int, error)

func (*Block) ProposerSigned

func (blk *Block) ProposerSigned() bool

ProposerSigned returns true if the proposer has signed the block

func (*Block) ProtoMessage

func (*Block) ProtoMessage()

func (*Block) Reset

func (m *Block) Reset()

func (*Block) SetHash

func (blk *Block) SetHash(h hasher.Hasher)

SetHash sets the block hash using the given hash function

func (*Block) SetProposer

func (blk *Block) SetProposer(pubkey PublicKey)

SetProposer sets the proposer index given the public key. If the public is not in the signers it is added and then the index is set

func (*Block) SetSigners

func (blk *Block) SetSigners(signers ...PublicKey)

SetSigners sets the signers resetting all signatures

func (*Block) SetTxs

func (blk *Block) SetTxs(txns []*Tx, hf hasher.Hasher)

SetTxs sets the transaction id's to the block

func (*Block) Sign

func (blk *Block) Sign(pubkey PublicKey, signature []byte) error

Sign adds the public key and signature to the block. They are added at the same index. If the public key is already in Signers then the signature is set to the corresponding index in the Signatures field

func (*Block) SignatureCount

func (blk *Block) SignatureCount() int32

SignatureCount returns the number of signatures in the block. This is different from the S value which represents the 'required' signatures

func (*Block) Size

func (m *Block) Size() (n int)

func (*Block) String

func (m *Block) String() string

func (*Block) Unmarshal

func (m *Block) Unmarshal(dAtA []byte) error

type BlockHeader

type BlockHeader struct {
	// Block height in the chain. Genesis will always be 0
	Height uint32 `protobuf:"varint,1,opt,name=Height,proto3" json:"Height,omitempty"`
	// Previous block digest.  This is zero for the genesis block
	PrevBlock Digest `protobuf:"bytes,2,opt,name=PrevBlock,proto3,casttype=Digest" json:"PrevBlock,omitempty"`
	// Timestamp when block creation was started
	Timestamp int64 `protobuf:"varint,3,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"`
	// Incrementing nonce
	Nonce uint64 `protobuf:"varint,4,opt,name=Nonce,proto3" json:"Nonce,omitempty"`
	// Root hash of all tx's
	Root Digest `protobuf:"bytes,5,opt,name=Root,proto3,casttype=Digest" json:"Root,omitempty"`
	// All block signers
	Signers []PublicKey `protobuf:"bytes,6,rep,name=Signers,casttype=PublicKey" json:"Signers,omitempty"`
	// Node that proposed the block
	ProposerIndex int32 `protobuf:"varint,7,opt,name=ProposerIndex,proto3" json:"ProposerIndex,omitempty"`
	// Total number of signers for this block
	N int32 `protobuf:"varint,8,opt,name=N,proto3" json:"N,omitempty"`
	// Number of signatures.  This must be a atleast quorum value of N
	S int32 `protobuf:"varint,9,opt,name=S,proto3" json:"S,omitempty"`
	// Number of commits.  This must be a atleast quorum value of N
	Q int32 `protobuf:"varint,10,opt,name=Q,proto3" json:"Q,omitempty"`
}

func (*BlockHeader) Descriptor

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

func (*BlockHeader) GetHeight

func (m *BlockHeader) GetHeight() uint32

func (*BlockHeader) GetN

func (m *BlockHeader) GetN() int32

func (*BlockHeader) GetNonce

func (m *BlockHeader) GetNonce() uint64

func (*BlockHeader) GetPrevBlock

func (m *BlockHeader) GetPrevBlock() Digest

func (*BlockHeader) GetProposerIndex

func (m *BlockHeader) GetProposerIndex() int32

func (*BlockHeader) GetQ

func (m *BlockHeader) GetQ() int32

func (*BlockHeader) GetRoot

func (m *BlockHeader) GetRoot() Digest

func (*BlockHeader) GetS

func (m *BlockHeader) GetS() int32

func (*BlockHeader) GetSigners

func (m *BlockHeader) GetSigners() []PublicKey

func (*BlockHeader) GetTimestamp

func (m *BlockHeader) GetTimestamp() int64

func (*BlockHeader) HasSigners

func (header *BlockHeader) HasSigners() bool

HasSigners returns true if the block has the number of signers as specified by N

func (*BlockHeader) Hash

func (header *BlockHeader) Hash(h hasher.Hasher) Digest

Hash returns the hash of the header

func (*BlockHeader) Marshal

func (m *BlockHeader) Marshal() (dAtA []byte, err error)

func (*BlockHeader) MarshalTo

func (m *BlockHeader) MarshalTo(dAtA []byte) (int, error)

func (*BlockHeader) Proposer

func (header *BlockHeader) Proposer() PublicKey

Proposer returns the public key of the block proposer

func (*BlockHeader) ProtoMessage

func (*BlockHeader) ProtoMessage()

func (*BlockHeader) Reset

func (m *BlockHeader) Reset()

func (*BlockHeader) SignerIndex

func (header *BlockHeader) SignerIndex(pubkey PublicKey) int

SignerIndex returns the index in the signers list given the public key

func (*BlockHeader) Size

func (m *BlockHeader) Size() (n int)

func (*BlockHeader) String

func (m *BlockHeader) String() string

func (*BlockHeader) Unmarshal

func (m *BlockHeader) Unmarshal(dAtA []byte) error

type DataKey

type DataKey []byte

DataKey represents a data key. This is a token key as opposed to a crypto key It is in the format <type>:<some uinque key in type>, where type is the datatype with the remainder to be used as an identifier

func NewDataKey

func NewDataKey(typ, key []byte) DataKey

NewDataKey returns a new data key with the given type and id delimited by ':'

func ParseDataKey

func ParseDataKey(dk string) DataKey

ParseDataKey parses a string DataKey

func (DataKey) Equal

func (k DataKey) Equal(b []byte) bool

Equal trues true if both keys are equal

func (DataKey) ID

func (k DataKey) ID() []byte

ID returns the id part of the key and nil if the key does not contain an id

func (DataKey) String

func (k DataKey) String() string

func (DataKey) Type

func (k DataKey) Type() []byte

Type returns the key type par of the key. This is all bytes before the first '/'

type Digest

type Digest []byte

Digest is a hash with the hash function used. The format is as follows algo ':' hash

func NewDigest

func NewDigest(algo string, hash []byte) Digest

NewDigest creates a new digest with the given algorithm identifier and hash

func NewZeroDigest

func NewZeroDigest(h hasher.Hasher) Digest

NewZeroDigest returns a zero digest for the given hash function

func ParseDigest

func ParseDigest(str string) (Digest, error)

ParseDigest parses a digest string into a digest

func (Digest) Algorithm

func (digest Digest) Algorithm() string

Algorithm returns the hasing algorithm used

func (Digest) Copy

func (digest Digest) Copy() Digest

Copy does a byte copy of the digest returning a new copy

func (Digest) Equal

func (digest Digest) Equal(d Digest) bool

Equal returns true if both digests are the same

func (Digest) Hash

func (digest Digest) Hash() []byte

Hash returns the hash bytes of the digest

func (Digest) String

func (digest Digest) String() string

type Digests

type Digests []Digest

Digests is a list of digests of the same hash function

func (Digests) Root

func (digests Digests) Root() (Digest, error)

Root calculates the root hash of the transactions TODO: merkle tree

type PublicKey

type PublicKey []byte

PublicKey contains public key bytes

func (PublicKey) Address

func (w PublicKey) Address(h hasher.Hasher) []byte

Address returns the hashed key address

func (PublicKey) Equal

func (w PublicKey) Equal(pk PublicKey) bool

Equal returns true if both keys are the same

func (PublicKey) Hash

func (w PublicKey) Hash(hf hasher.Hasher) Digest

Hash generates the hash of the public key

type Tx

type Tx struct {
	// Tx header including the transaction type
	Header  *TxHeader   `protobuf:"bytes,1,opt,name=Header" json:"Header,omitempty"`
	Inputs  []*TxInput  `protobuf:"bytes,2,rep,name=Inputs" json:"Inputs,omitempty"`
	Outputs []*TxOutput `protobuf:"bytes,3,rep,name=Outputs" json:"Outputs,omitempty"`
	// Transaction digest
	Digest Digest `protobuf:"bytes,4,opt,name=Digest,proto3,casttype=Digest" json:"Digest,omitempty"`
}

func NewBaseTx

func NewBaseTx(pubkeys ...PublicKey) *Tx

NewBaseTx returns a new base transaction. This is used when new entities are being created

func NewTx

func NewTx() *Tx

NewTx returns a new transaction

func (*Tx) AddInput

func (tx *Tx) AddInput(in *TxInput)

AddInput appends the given input to the transaction inputs

func (*Tx) AddOutput

func (tx *Tx) AddOutput(out *TxOutput)

AddOutput appends the given output to the transaction outputs

func (*Tx) DataHash

func (tx *Tx) DataHash(h hasher.Hasher) Digest

DataHash hashes all inputs and outputs updating the DataSize in the header and returning the data digest

func (*Tx) Descriptor

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

func (*Tx) GetDigest

func (m *Tx) GetDigest() Digest

func (*Tx) GetHeader

func (m *Tx) GetHeader() *TxHeader

func (*Tx) GetInputs

func (m *Tx) GetInputs() []*TxInput

func (*Tx) GetOutputs

func (m *Tx) GetOutputs() []*TxOutput

func (*Tx) IsBase

func (tx *Tx) IsBase() bool

IsBase returns true if this is a base tx i.e. inputs do not reference any outputs

func (*Tx) Marshal

func (m *Tx) Marshal() (dAtA []byte, err error)

func (*Tx) MarshalTo

func (m *Tx) MarshalTo(dAtA []byte) (int, error)

func (*Tx) ProtoMessage

func (*Tx) ProtoMessage()

func (*Tx) Reset

func (m *Tx) Reset()

func (*Tx) SetDigest

func (tx *Tx) SetDigest(h hasher.Hasher)

SetDigest computes the hash of the tx and set the digest field

func (*Tx) Size

func (m *Tx) Size() (n int)

func (*Tx) String

func (m *Tx) String() string

func (*Tx) Unmarshal

func (m *Tx) Unmarshal(dAtA []byte) error

type TxHeader

type TxHeader struct {
	// Tx timestamp
	Timestamp int64 `protobuf:"varint,1,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"`
	// Payload hash
	Data Digest `protobuf:"bytes,2,opt,name=Data,proto3,casttype=Digest" json:"Data,omitempty"`
	// Payload size
	DataSize int64 `protobuf:"varint,3,opt,name=DataSize,proto3" json:"DataSize,omitempty"`
}

func (*TxHeader) Descriptor

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

func (*TxHeader) GetData

func (m *TxHeader) GetData() Digest

func (*TxHeader) GetDataSize

func (m *TxHeader) GetDataSize() int64

func (*TxHeader) GetTimestamp

func (m *TxHeader) GetTimestamp() int64

func (*TxHeader) Hash

func (header *TxHeader) Hash(h hasher.Hasher) Digest

Hash returns the hash digest of the header

func (*TxHeader) Marshal

func (m *TxHeader) Marshal() (dAtA []byte, err error)

func (*TxHeader) MarshalTo

func (m *TxHeader) MarshalTo(dAtA []byte) (int, error)

func (*TxHeader) ProtoMessage

func (*TxHeader) ProtoMessage()

func (*TxHeader) Reset

func (m *TxHeader) Reset()

func (*TxHeader) Size

func (m *TxHeader) Size() (n int)

func (*TxHeader) String

func (m *TxHeader) String() string

func (*TxHeader) Unmarshal

func (m *TxHeader) Unmarshal(dAtA []byte) error

type TxInput

type TxInput struct {
	// Previous tx. Empty if no ref is specificed along with the index
	// then it is considered a base tx
	Ref Digest `protobuf:"bytes,1,opt,name=Ref,proto3,casttype=Digest" json:"Ref,omitempty"`
	// Output index in txn. -1 if no previous output needed as input
	Index int32 `protobuf:"varint,2,opt,name=Index,proto3" json:"Index,omitempty"`
	// Public key as set in the output tx being referenced and used to verify
	// the signature below.  These are strictly used to assist in the
	// verification of signatures and are not necessarily required to be
	// specified as in the input
	PubKeys []PublicKey `protobuf:"bytes,3,rep,name=PubKeys,casttype=PublicKey" json:"PubKeys,omitempty"`
	// Data needed to unlock TxnOutput OR i.e.
	// signature along with any other data.  This is used in conjunction with
	// the TxnOutput referenced by the above fields to unlock the referenced
	// TxnOutput. All data after the pub keys length is consider part of the
	// state transition and unlock logic
	Signatures [][]byte `protobuf:"bytes,4,rep,name=Signatures" json:"Signatures,omitempty"`
}

TxnInput contains all data needed to use the referenced output

func NewBaseTxInput

func NewBaseTxInput(sigData ...[]byte) *TxInput

NewBaseTxInput creates a new base TxnInput with arbitrary data as the signature. This is used in for example the genesis block

func NewTxInput

func NewTxInput(ref Digest, i int32, pubkeys []PublicKey) *TxInput

NewTxInput creates a new transaction input. It inits the signatures to the the number of given public keys

func (*TxInput) AddArgs

func (txi *TxInput) AddArgs(args ...[]byte)

AddArgs adds inputs args to the txinput. Args are always after all signatures

func (*TxInput) AddPubKey

func (txi *TxInput) AddPubKey(pk PublicKey) bool

AddPubKey adds a public key to the input if it does not exist. It also adjusts the signatures slices accordingly if the addition is successful

func (*TxInput) Args

func (txi *TxInput) Args() [][]byte

Args returns all arguments minus the signatures needed as input. Inputs are located after the given number of public keys in the signatures files

func (*TxInput) Descriptor

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

func (*TxInput) GetIndex

func (m *TxInput) GetIndex() int32

func (*TxInput) GetPubKeys

func (m *TxInput) GetPubKeys() []PublicKey

func (*TxInput) GetRef

func (m *TxInput) GetRef() Digest

func (*TxInput) GetSignatures

func (m *TxInput) GetSignatures() [][]byte

func (*TxInput) HasPubKey

func (txi *TxInput) HasPubKey(pubkey []byte) (int, bool)

HasPubKey returns true if the given public key is in the input

func (*TxInput) Hash

func (txi *TxInput) Hash(hf hasher.Hasher) Digest

Hash returns a hash of the ref, output index, and public keys

func (*TxInput) IsBase

func (txi *TxInput) IsBase() bool

IsBase returns true if the reference is not present and the index is set to -1. This is true for creation of entities

func (*TxInput) Marshal

func (m *TxInput) Marshal() (dAtA []byte, err error)

func (*TxInput) MarshalTo

func (m *TxInput) MarshalTo(dAtA []byte) (int, error)

func (*TxInput) ProtoMessage

func (*TxInput) ProtoMessage()

func (*TxInput) Reset

func (m *TxInput) Reset()

func (*TxInput) Sign

func (txi *TxInput) Sign(pk PublicKey, sig []byte) error

Sign adds the public key and associated signature to the transaction input . If returns a ErrNotAuthorized error is the public key is not specified in the input

func (*TxInput) Size

func (m *TxInput) Size() (n int)

func (*TxInput) String

func (m *TxInput) String() string

func (*TxInput) Unmarshal

func (m *TxInput) Unmarshal(dAtA []byte) error

type TxOutput

type TxOutput struct {
	// Key used to identify the data
	DataKey DataKey `protobuf:"bytes,1,opt,name=DataKey,proto3,casttype=DataKey" json:"DataKey,omitempty"`
	// Actual data associated to the key
	Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"`
	// Counter incremented on each write
	// int64 Counter = 3;
	Metrics map[string]float64 `` /* 150-byte string literal not displayed */
	Tags    map[string]string  `` /* 142-byte string literal not displayed */
	Labels  []string           `protobuf:"bytes,6,rep,name=Labels" json:"Labels,omitempty"`
	// Recipients (plural) public key. These are check along with the logic
	PubKeys []PublicKey `protobuf:"bytes,7,rep,name=PubKeys,casttype=PublicKey" json:"PubKeys,omitempty"`
	// Defines the 'verification' logic using TxnInput.Signature as data.  This
	// is run as a check along with the public key match
	Logic []byte `protobuf:"bytes,8,opt,name=Logic,proto3" json:"Logic,omitempty"`
}

func (*TxOutput) Copy

func (txo *TxOutput) Copy() *TxOutput

Copy returns a copy of the transaction output

func (*TxOutput) Descriptor

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

func (*TxOutput) GetData

func (m *TxOutput) GetData() []byte

func (*TxOutput) GetDataKey

func (m *TxOutput) GetDataKey() DataKey

func (*TxOutput) GetLabels

func (m *TxOutput) GetLabels() []string

func (*TxOutput) GetLogic

func (m *TxOutput) GetLogic() []byte

func (*TxOutput) GetMetrics

func (m *TxOutput) GetMetrics() map[string]float64

func (*TxOutput) GetPubKeys

func (m *TxOutput) GetPubKeys() []PublicKey

func (*TxOutput) GetTags

func (m *TxOutput) GetTags() map[string]string

func (*TxOutput) HasPublicKey

func (txo *TxOutput) HasPublicKey(pk PublicKey) bool

HasPublicKey return true if the public key is one of the public keys listed in the output

func (*TxOutput) Marshal

func (m *TxOutput) Marshal() (dAtA []byte, err error)

func (*TxOutput) MarshalTo

func (m *TxOutput) MarshalTo(dAtA []byte) (int, error)

func (*TxOutput) ProtoMessage

func (*TxOutput) ProtoMessage()

func (*TxOutput) RemovePublicKey

func (txo *TxOutput) RemovePublicKey(pk PublicKey) bool

RemovePublicKey removes the public key returning true if it was removed

func (*TxOutput) Reset

func (m *TxOutput) Reset()

func (*TxOutput) SetRequiredSignatures

func (txo *TxOutput) SetRequiredSignatures(c uint8)

SetRequiredSignatures sets the required signatures to mutate the output

func (*TxOutput) Size

func (m *TxOutput) Size() (n int)

func (*TxOutput) String

func (m *TxOutput) String() string

func (*TxOutput) Unmarshal

func (m *TxOutput) Unmarshal(dAtA []byte) error

Jump to

Keyboard shortcuts

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