Skip to content

Commit

Permalink
Merge 452d90a into d6c9de9
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilthoniel committed Mar 8, 2020
2 parents d6c9de9 + 452d90a commit d257e7c
Show file tree
Hide file tree
Showing 52 changed files with 2,877 additions and 2,263 deletions.
250 changes: 0 additions & 250 deletions blockchain/messages.pb.go

This file was deleted.

27 changes: 0 additions & 27 deletions blockchain/messages.proto

This file was deleted.

64 changes: 52 additions & 12 deletions blockchain/mod.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,85 @@
package blockchain

import (
"bytes"
"context"
"io"
fmt "fmt"

"github.com/golang/protobuf/proto"
"go.dedis.ch/fabric/crypto"
"go.dedis.ch/fabric/encoding"
mino "go.dedis.ch/fabric/mino"
)

//go:generate protoc -I ./ --proto_path=../ --go_out=Mmino/messages.proto=go.dedis.ch/fabric/mino:. ./messages.proto
// BlockID is a unique identifier for each block which is composed
// of its hash.
type BlockID [32]byte

// Roster is a set of identifiable addresses.
type Roster interface {
io.WriterTo
// NewBlockID returns an instance of a block identifier.
func NewBlockID(buffer []byte) BlockID {
id := BlockID{}
copy(id[:], buffer)
return id
}

// Bytes returns the slice of bytes of the identifier.
func (id BlockID) Bytes() []byte {
return id[:]
}

// Equal returns true when both identifiers are equal.
func (id BlockID) Equal(other BlockID) bool {
return bytes.Equal(id[:], other[:])
}

func (id BlockID) String() string {
return fmt.Sprintf("%x", id[:])[:8]
}

GetConodes() []*Conode
GetAddresses() []*mino.Address
GetPublicKeys() []crypto.PublicKey
// Block is the interface of the unit of storage in the blockchain
type Block interface {
encoding.Packable

GetID() BlockID
}

// VerifiableBlock is an extension of a block so that its integrity can be
// verified from the genesis block.
type VerifiableBlock interface {
Block

Verify(crypto.Verifier) error
}

// BlockFactory provides primitives to create blocks from a untrusted source.
type BlockFactory interface {
FromVerifiable(src *VerifiableBlock, originPublicKeys []crypto.PublicKey) (interface{}, error)
FromVerifiable(src proto.Message) (Block, error)
}

// Validator is the interface to implement to validate the generic payload
// stored in the block.
type Validator interface {
Validate(data proto.Message) error
Commit(data proto.Message) error
}

// Blockchain is the interface that provides the primitives to interact with the
// blockchain.
type Blockchain interface {
GetBlockFactory() BlockFactory

Listen(validator Validator) error

// Store stores any representation of a data structure into a new block.
// The implementation is responsible for any validations required.
Store(roster Roster, data proto.Message) error
Store(data proto.Message, nodes mino.Node) error

// GetBlock returns the latest block.
GetBlock() (*Block, error)
GetBlock() (Block, error)

// GetVerifiableBlock returns the latest block alongside with a proof from
// the genesis block.
GetVerifiableBlock() (*VerifiableBlock, error)
GetVerifiableBlock() (VerifiableBlock, error)

// Watch takes an observer that will be notified for each new block
// definitely appended to the chain.
Expand Down
Loading

0 comments on commit d257e7c

Please sign in to comment.