node

package
v0.0.0-...-3b62c27 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DiscoveryTag is the mDNS discovery service tag
	DiscoveryTag = "vine._tcp"
	// DiscoveryTime is the time that the discovery service waits
	// between restarts
	DiscoveryTime = time.Second * 30

	// GRPCProto is the default gRPC protocol
	GRPCProto = "/vine/grpc/0.1"
)

Variables

View Source
var (
	Status_StatusCode_name = map[int32]string{
		0: "Ok",
		1: "Err",
	}
	Status_StatusCode_value = map[string]int32{
		"Ok":  0,
		"Err": 1,
	}
)

Enum value maps for Status_StatusCode.

Functions

func GRPCDialer

func GRPCDialer(h host.Host, proto ...protocol.ID) func(context.Context, string) (net.Conn, error)

GRPCDialer creates a dialer function for use as a grpc.DialOption. A stream creator can be a host.Host from libp2p

Use with the grpc.WithContextDialer dialer option

func RegisterBlockStoreServer

func RegisterBlockStoreServer(s *grpc.Server, srv BlockStoreServer)

Types

type BlockMsg

type BlockMsg struct {
	Sender string       `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"`
	Block  *block.Block `protobuf:"bytes,2,opt,name=block,proto3" json:"block,omitempty"`
	Error  string       `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"`
	// contains filtered or unexported fields
}

func (*BlockMsg) Descriptor deprecated

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

Deprecated: Use BlockMsg.ProtoReflect.Descriptor instead.

func (*BlockMsg) GetBlock

func (x *BlockMsg) GetBlock() *block.Block

func (*BlockMsg) GetError

func (x *BlockMsg) GetError() string

func (*BlockMsg) GetSender

func (x *BlockMsg) GetSender() string

func (*BlockMsg) ProtoMessage

func (*BlockMsg) ProtoMessage()

func (*BlockMsg) ProtoReflect

func (x *BlockMsg) ProtoReflect() protoreflect.Message

func (*BlockMsg) Reset

func (x *BlockMsg) Reset()

func (*BlockMsg) String

func (x *BlockMsg) String() string

type BlockReq

type BlockReq struct {
	Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
	// contains filtered or unexported fields
}

func (*BlockReq) Descriptor deprecated

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

Deprecated: Use BlockReq.ProtoReflect.Descriptor instead.

func (*BlockReq) GetHash

func (x *BlockReq) GetHash() []byte

func (*BlockReq) ProtoMessage

func (*BlockReq) ProtoMessage()

func (*BlockReq) ProtoReflect

func (x *BlockReq) ProtoReflect() protoreflect.Message

func (*BlockReq) Reset

func (x *BlockReq) Reset()

func (*BlockReq) String

func (x *BlockReq) String() string

type BlockStoreClient

type BlockStoreClient interface {
	// Get a block by hash
	GetBlock(ctx context.Context, in *BlockReq, opts ...grpc.CallOption) (*BlockMsg, error)
	// Get a transaction by id
	GetTx(ctx context.Context, in *TxReq, opts ...grpc.CallOption) (*TxMsg, error)
	// Ask for the head of the chain
	Head(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*BlockMsg, error)
	// Ask for the base of the chain
	Base(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*BlockMsg, error)
	// Send and receive new transactions
	Tx(ctx context.Context, in *TxMsg, opts ...grpc.CallOption) (*Status, error)
	// Send and receive new mined blocks
	Mined(ctx context.Context, in *BlockMsg, opts ...grpc.CallOption) (*Status, error)
}

BlockStoreClient is the client API for BlockStore service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewBlockStoreClient

func NewBlockStoreClient(cc grpc.ClientConnInterface) BlockStoreClient

type BlockStoreServer

type BlockStoreServer interface {
	// Get a block by hash
	GetBlock(context.Context, *BlockReq) (*BlockMsg, error)
	// Get a transaction by id
	GetTx(context.Context, *TxReq) (*TxMsg, error)
	// Ask for the head of the chain
	Head(context.Context, *Empty) (*BlockMsg, error)
	// Ask for the base of the chain
	Base(context.Context, *Empty) (*BlockMsg, error)
	// Send and receive new transactions
	Tx(context.Context, *TxMsg) (*Status, error)
	// Send and receive new mined blocks
	Mined(context.Context, *BlockMsg) (*Status, error)
	// contains filtered or unexported methods
}

BlockStoreServer is the server API for BlockStore service. All implementations must embed UnimplementedBlockStoreServer for forward compatibility

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

func (*Empty) Descriptor deprecated

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

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type Node

type Node struct {
	UnimplementedBlockStoreServer
	// contains filtered or unexported fields
}

Node is a node

func FullNode

func FullNode(ctx context.Context, host host.Host, store blockStoreTxdb) (*Node, error)

FullNode will run a full node

func New

func New(ctx context.Context, host host.Host) (*Node, error)

New will create a partial node

func (*Node) Base

func (n *Node) Base(ctx context.Context, e *Empty) (*BlockMsg, error)

Base is receive requests for the base of the blockchain.

func (*Node) BroadcastTx

func (n *Node) BroadcastTx(tx *block.Transaction) error

BroadcastTx will broadcast a transaction to all the node's peers

func (*Node) Close

func (n *Node) Close() error

Close the node

func (*Node) GetBlock

func (n *Node) GetBlock(ctx context.Context, req *BlockReq) (*BlockMsg, error)

GetBlock implement the GetBlock service for the BlockStoreServer grpc service.

func (*Node) GetHeadBlock

func (n *Node) GetHeadBlock() (*block.Block, error)

GetHeadBlock will get the head block from the network

func (*Node) GetTx

func (n *Node) GetTx(ctx context.Context, req *TxReq) (*TxMsg, error)

GetTx implement the GetTx service for the BlockStoreServer grpc service.

func (*Node) Head

func (n *Node) Head(ctx context.Context, e *Empty) (*BlockMsg, error)

Head implement the Head service for the BlockStoreServer grpc service.

func (*Node) Mined

func (n *Node) Mined(ctx context.Context, msg *BlockMsg) (*Status, error)

Mined implement the Mined service for the BlockStoreServer grpc service.

func (*Node) PeerAddrs

func (n *Node) PeerAddrs() []multiaddr.Multiaddr

PeerAddrs will iterate through the node's peers and collect their addresses.

func (*Node) Peers

func (n *Node) Peers() peer.IDSlice

Peers returns a slice of peer ids that are addressable

func (*Node) Start

func (n *Node) Start() error

Start the node

func (*Node) StartWithGRPC

func (n *Node) StartWithGRPC(srv *grpc.Server, proto protocol.ID) error

StartWithGRPC will start the node and listen for requests from the network with a grpc server.

func (*Node) Sync

func (n *Node) Sync() error

Sync with the rest of the network.

func (*Node) Tx

func (n *Node) Tx(ctx context.Context, msg *TxMsg) (*Status, error)

Tx implement the Tx service for the BlockStoreServer grpc service.

type Status

type Status struct {
	Code   Status_StatusCode `protobuf:"varint,1,opt,name=code,proto3,enum=node.Status_StatusCode" json:"code,omitempty"`
	Status string            `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"`
	// contains filtered or unexported fields
}

func (*Status) Descriptor deprecated

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

Deprecated: Use Status.ProtoReflect.Descriptor instead.

func (*Status) GetCode

func (x *Status) GetCode() Status_StatusCode

func (*Status) GetStatus

func (x *Status) GetStatus() string

func (*Status) ProtoMessage

func (*Status) ProtoMessage()

func (*Status) ProtoReflect

func (x *Status) ProtoReflect() protoreflect.Message

func (*Status) Reset

func (x *Status) Reset()

func (*Status) String

func (x *Status) String() string

type Status_StatusCode

type Status_StatusCode int32
const (
	Status_Ok  Status_StatusCode = 0
	Status_Err Status_StatusCode = 1
)

func (Status_StatusCode) Descriptor

func (Status_StatusCode) Enum

func (Status_StatusCode) EnumDescriptor deprecated

func (Status_StatusCode) EnumDescriptor() ([]byte, []int)

Deprecated: Use Status_StatusCode.Descriptor instead.

func (Status_StatusCode) Number

func (Status_StatusCode) String

func (x Status_StatusCode) String() string

func (Status_StatusCode) Type

type TxMsg

type TxMsg struct {
	Sender string             `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"`
	Tx     *block.Transaction `protobuf:"bytes,2,opt,name=tx,proto3" json:"tx,omitempty"`
	Error  string             `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"`
	// contains filtered or unexported fields
}

func (*TxMsg) Descriptor deprecated

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

Deprecated: Use TxMsg.ProtoReflect.Descriptor instead.

func (*TxMsg) GetError

func (x *TxMsg) GetError() string

func (*TxMsg) GetSender

func (x *TxMsg) GetSender() string

func (*TxMsg) GetTx

func (x *TxMsg) GetTx() *block.Transaction

func (*TxMsg) ProtoMessage

func (*TxMsg) ProtoMessage()

func (*TxMsg) ProtoReflect

func (x *TxMsg) ProtoReflect() protoreflect.Message

func (*TxMsg) Reset

func (x *TxMsg) Reset()

func (*TxMsg) String

func (x *TxMsg) String() string

type TxReq

type TxReq struct {
	Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
	// contains filtered or unexported fields
}

func (*TxReq) Descriptor deprecated

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

Deprecated: Use TxReq.ProtoReflect.Descriptor instead.

func (*TxReq) GetHash

func (x *TxReq) GetHash() []byte

func (*TxReq) ProtoMessage

func (*TxReq) ProtoMessage()

func (*TxReq) ProtoReflect

func (x *TxReq) ProtoReflect() protoreflect.Message

func (*TxReq) Reset

func (x *TxReq) Reset()

func (*TxReq) String

func (x *TxReq) String() string

type UnimplementedBlockStoreServer

type UnimplementedBlockStoreServer struct {
}

UnimplementedBlockStoreServer must be embedded to have forward compatible implementations.

func (*UnimplementedBlockStoreServer) Base

func (*UnimplementedBlockStoreServer) GetBlock

func (*UnimplementedBlockStoreServer) GetTx

func (*UnimplementedBlockStoreServer) Head

func (*UnimplementedBlockStoreServer) Mined

func (*UnimplementedBlockStoreServer) Tx

Jump to

Keyboard shortcuts

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