Documentation
¶
Index ¶
- Constants
- func FullyQualifiedName(item Marshalled) string
- type Account
- type AddBlocksResponse
- type Block
- type BlockComparator
- type BlockConfirmationHandler
- type BlockGenerator
- type Blockchain
- type CompetingBranch
- type Competition
- type Consensus
- type Controller
- type Links
- type Marshalled
- type MessageProtocol
- func (p *MessageProtocol) BlockchainName() string
- func (p *MessageProtocol) ComponentName() string
- func (p *MessageProtocol) IsValid() bool
- func (p *MessageProtocol) ResourceType() string
- func (p *MessageProtocol) SetBlockchainName(blockchainName string)
- func (p *MessageProtocol) SetComponentName(componentName string)
- func (p *MessageProtocol) SetResourceType(resourceType string)
- func (p *MessageProtocol) SetValue(value string) (ok bool)
- func (p *MessageProtocol) SetVersion(version string)
- func (p *MessageProtocol) String() string
- func (p *MessageProtocol) Version() string
- type MessageReceiver
- type NetworkMessage
- type NetworkNode
- type Store
- type StoreBlock
- type Transaction
- type TransactionHandler
- type URI
- func (u *URI) BlockchainName() string
- func (u *URI) ComponentName() string
- func (u *URI) ID() string
- func (u *URI) IsValid() bool
- func (u *URI) ResourceType() string
- func (u *URI) SetBlockchainName(blockchainName string)
- func (u *URI) SetComponentName(componentName string)
- func (u *URI) SetID(id string)
- func (u *URI) SetResourceType(resourceType string)
- func (u *URI) SetValue(value string) (ok bool)
- func (u *URI) SetVersion(version string)
- func (u *URI) String() string
- func (u *URI) Version() string
Constants ¶
View Source
const ( ResourceTypeBlock string = "block" ResourceTypeTransaction string = "transaction" )
Variables ¶
This section is empty.
Functions ¶
func FullyQualifiedName ¶
func FullyQualifiedName(item Marshalled) string
Types ¶
type AddBlocksResponse ¶
type Block ¶
type Block interface {
Marshalled
// returns the identifier of the block's parent
ParentHash() string
// returns the sequential number of the block in the blockchain
BlockNumber() uint64
// validates the block
Valid() bool
// gets the block's transactions
Transactions() []Transaction
// gets the Unix time in milliseconds the block was generated
Timestamp() int64
}
Block interface specifies getters required for `blocktop` to function. Custom blocks must implement this interface.
type BlockComparator ¶
type BlockConfirmationHandler ¶
type BlockConfirmationHandler func(Block)
type BlockGenerator ¶
type Blockchain ¶
type CompetingBranch ¶
type CompetingBranch interface {
// Blocks returns the blocks contained in the branch, ordered from
// head to confirming root.
Blocks() []Block
// RootID is the identifier of the branch.
RootID() int
// ConsecutiveLocalHits returns the number of times the branch has
// received blocks for evaluation from only the local node. This
// is an indicator that the current node is operating in an echo
// chamber.
ConsecutiveLocalHits() int
// HitRate is a measure of popularity of the branch. If returns the
// number of blocks per second that are being evaluated from the
// network and locally for addition to the branch.
HitRate() float64
}
type Competition ¶
type Competition interface {
// Branches returns the current competing branches being tracked
// in the consensus system indexed by RootID.
Branches() map[int]CompetingBranch
}
Competition represents the latest block competition information. This entity is shared between Consensus and Blockchain.
type Consensus ¶
type Consensus interface {
OnBlockConfirmed(BlockConfirmationHandler)
OnLocalBlockConfirmed(BlockConfirmationHandler)
Evaluate() Competition
AddBlocks(block []Block, local bool) *AddBlocksResponse
ConfirmBlocks()
WasSeen(block Block) bool
SetCompeted(head Block)
SetConfirmingRoot(rootID int)
}
type Controller ¶
type Marshalled ¶
type MessageProtocol ¶
type MessageProtocol struct {
// contains filtered or unexported fields
}
MessageProtocol is a string that identifies a messaging protocol. The canonical form is:
/<blockchain type>/<resource type>/<component type>/<version>
For example:
/blocktop/block/luckyblock/v1 /blocktop/transaction/exchange/v2
func NewProtocol ¶
func NewProtocol(value string) *MessageProtocol
func NewProtocolMarshalled ¶
func NewProtocolMarshalled(blockchainName string, m Marshalled) *MessageProtocol
func NewProtocolParts ¶
func NewProtocolParts(blockchainName string, resourceType string, componentName string, version string) *MessageProtocol
func (*MessageProtocol) BlockchainName ¶
func (p *MessageProtocol) BlockchainName() string
func (*MessageProtocol) ComponentName ¶
func (p *MessageProtocol) ComponentName() string
func (*MessageProtocol) IsValid ¶
func (p *MessageProtocol) IsValid() bool
func (*MessageProtocol) ResourceType ¶
func (p *MessageProtocol) ResourceType() string
func (*MessageProtocol) SetBlockchainName ¶
func (p *MessageProtocol) SetBlockchainName(blockchainName string)
func (*MessageProtocol) SetComponentName ¶
func (p *MessageProtocol) SetComponentName(componentName string)
func (*MessageProtocol) SetResourceType ¶
func (p *MessageProtocol) SetResourceType(resourceType string)
func (*MessageProtocol) SetValue ¶
func (p *MessageProtocol) SetValue(value string) (ok bool)
func (*MessageProtocol) SetVersion ¶
func (p *MessageProtocol) SetVersion(version string)
func (*MessageProtocol) String ¶
func (p *MessageProtocol) String() string
func (*MessageProtocol) Version ¶
func (p *MessageProtocol) Version() string
type MessageReceiver ¶
type MessageReceiver func(*NetworkMessage)
type NetworkMessage ¶
type NetworkMessage struct {
Data []byte
Links Links
Hash string
Protocol *MessageProtocol
From string
}
type NetworkNode ¶
type NetworkNode interface {
Bootstrap(context.Context) error
PeerID() string
Listen(context.Context)
Sign(data []byte) ([]byte, error)
Verify(peerID string, data []byte, sig []byte, pubKey []byte) (bool, error)
// Broadcast is a NetworkBroadcaster function that can be passed
// around to any component that needs to broadcast to the P2P network.
Broadcast([]*NetworkMessage)
OnMessageReceived(MessageReceiver)
Close()
}
type Store ¶
type Store interface {
OpenBlock(blockNumber uint64) (StoreBlock, error)
StoreBlock() StoreBlock
Close()
GetRoot() string
Put(context.Context, Marshalled) error
Get(ctx context.Context, hash string, obj Marshalled) error
TreeGet(ctx context.Context, key string, obj Marshalled) error
Hash(data []byte, links Links) (string, error)
}
type StoreBlock ¶
type Transaction ¶
type Transaction interface {
Marshalled
Parties() map[string]Account // e.g. ["sender"]Account{x}
}
type TransactionHandler ¶
type TransactionHandler interface {
Type() string
ReceiveTransaction(*NetworkMessage) (Transaction, error)
Execute(Transaction) (ok bool)
}
type URI ¶
type URI struct {
// contains filtered or unexported fields
}
URI is a string that identifies a resource in a blockchain. The canonical form is:
<blockchain type>://<resource type>/<component type>/<version>/<id>
For example:
blocktop://block/luckyblock/v1/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef blocktop://transaction/exchange/v2/fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210
func NewURIFromProtocol ¶
func NewURIFromProtocol(p *MessageProtocol, id string) *URI
func NewURIParts ¶
func (*URI) BlockchainName ¶
func (*URI) ComponentName ¶
func (*URI) ResourceType ¶
func (*URI) SetBlockchainName ¶
func (*URI) SetComponentName ¶
func (*URI) SetResourceType ¶
func (*URI) SetVersion ¶
Click to show internal directories.
Click to hide internal directories.