Documentation
¶
Index ¶
- Variables
- func HandleJSONData(sender interface{}, data []byte) [][]byte
- func MapType(i Behavior) string
- type Behavior
- type BroadcastBlock
- type Error
- func BadRequestError(err string) *Error
- func BlockValidationError(err blockchain.BlockValidationError) *Error
- func ChainNotAcceptError(err string) *Error
- func DuplicateBroadcastError(err string) *Error
- func IncompatibleProtocolVersionError(err string) *Error
- func InvalidBehaviorError(err string) *Error
- func InvalidMessageError(err string) *Error
- func InvalidURLError(err string) *Error
- func JSONDecodeError(err string) *Error
- type Info
- type Message
- type RequestBlocks
- type RequestPeers
- type ResponseBlocks
- type ResponsePeers
- type Serializable
Constants ¶
This section is empty.
Variables ¶
View Source
var BroadcastChannel = make(chan *BroadcastBlock)
TODO: may need to find a better way to save the channel
View Source
var MessageTypeMap = map[string]reflect.Type{ "info": reflect.TypeOf(Info{}), "error": reflect.TypeOf(Error{}), "request:blocks": reflect.TypeOf(RequestBlocks{}), "request:peers": reflect.TypeOf(RequestPeers{}), "response:blocks": reflect.TypeOf(ResponseBlocks{}), "response:peers": reflect.TypeOf(ResponsePeers{}), "broadcast:block": reflect.TypeOf(BroadcastBlock{}), }
Functions ¶
func HandleJSONData ¶
Types ¶
type Behavior ¶
type Behavior interface {
// returns an Error if invalid, otherwise returns nil
Validate() *Error
// Call Validate() before this method
React() []Behavior
// Description for debuging
String() string
}
func MapBehavior ¶
type BroadcastBlock ¶
type BroadcastBlock struct {
Block json.RawMessage `json:"block"`
ID string
Sender interface{}
// contains filtered or unexported fields
}
func (*BroadcastBlock) Message ¶
func (b *BroadcastBlock) Message() *Message
func (*BroadcastBlock) React ¶
func (b *BroadcastBlock) React() []Behavior
func (BroadcastBlock) Serialize ¶
func (b BroadcastBlock) Serialize() []byte
func (*BroadcastBlock) SetBlock ¶
func (b *BroadcastBlock) SetBlock(block *blockchain.Block)
func (BroadcastBlock) String ¶
func (b BroadcastBlock) String() string
func (*BroadcastBlock) Validate ¶
func (b *BroadcastBlock) Validate() *Error
type Error ¶
func BadRequestError ¶
func BlockValidationError ¶
func BlockValidationError(err blockchain.BlockValidationError) *Error
func ChainNotAcceptError ¶
func DuplicateBroadcastError ¶
func InvalidBehaviorError ¶
func InvalidMessageError ¶
func InvalidURLError ¶
func JSONDecodeError ¶
type Info ¶
type Info struct {
Version string `json:"version"`
Peers int `json:"peers"`
Chains map[string]uint64 `json:"chains"`
Platform map[string]string `json:"platform"`
FullNode bool `json:"full_node"`
}
- Declarations
type Message ¶
type Message struct {
ID string `json:"id"`
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
func DeserializeMessage ¶
func NewMessage ¶
type RequestBlocks ¶
type RequestBlocks struct {
ChainID string `json:"chain_id"`
From uint64 `json:"from"`
To uint64 `json:"to"`
}
func (RequestBlocks) String ¶
func (b RequestBlocks) String() string
func (RequestBlocks) Validate ¶
func (b RequestBlocks) Validate() *Error
type RequestPeers ¶
type RequestPeers struct {
Count int `json:"count"`
}
func (RequestPeers) React ¶
func (b RequestPeers) React() []Behavior
func (RequestPeers) String ¶
func (b RequestPeers) String() string
func (RequestPeers) Validate ¶
func (b RequestPeers) Validate() *Error
type ResponseBlocks ¶
type ResponseBlocks struct {
Blocks []json.RawMessage `json:"blocks"`
// contains filtered or unexported fields
}
func (ResponseBlocks) React ¶
func (b ResponseBlocks) React() []Behavior
func (ResponseBlocks) String ¶
func (b ResponseBlocks) String() string
func (*ResponseBlocks) Validate ¶
func (b *ResponseBlocks) Validate() *Error
type ResponsePeers ¶
type ResponsePeers struct {
Peers []string `json:"peers"`
}
func (ResponsePeers) React ¶
func (b ResponsePeers) React() []Behavior
func (ResponsePeers) String ¶
func (b ResponsePeers) String() string
func (ResponsePeers) Validate ¶
func (b ResponsePeers) Validate() *Error
type Serializable ¶
type Serializable interface {
Serialize() []byte
}
Click to show internal directories.
Click to hide internal directories.