Documentation ¶
Index ¶
- Constants
- Variables
- func CheckProofOfWork(prefix []byte, hash []byte) bool
- func ConnectToNode(dst string, timeout time.Duration, retry bool, cb NodeChannel)
- func CreateConnectionsQueue() (ConnectionsQueue, NodeChannel)
- func GetIpAddress() []string
- func HandleIncomingMessage(msg Message)
- func HandleNode(node *Node)
- func SEED_NODES() []string
- func SignatureVerify(publicKey, sig, hash []byte) bool
- func Start(address string)
- type Block
- func (b *Block) AddTransaction(t *Transaction)
- func (b *Block) GenerateMerkelRoot() []byte
- func (b *Block) GenerateNonce(prefix []byte) uint32
- func (b *Block) Hash() []byte
- func (b *Block) MarshalBinary() ([]byte, error)
- func (b *Block) Sign(keypair *Keypair) []byte
- func (b *Block) UnmarshalBinary(d []byte) error
- func (b *Block) VerifyBlock(prefix []byte) bool
- type BlockHeader
- type BlockSlice
- type Blockchain
- type BlocksQueue
- type ConnectionsQueue
- type Keypair
- type Message
- type Network
- type Node
- type NodeChannel
- type Nodes
- type Transaction
- func (t *Transaction) GenerateNonce(prefix []byte) uint32
- func (t *Transaction) Hash() []byte
- func (t *Transaction) MarshalBinary() ([]byte, error)
- func (t *Transaction) Sign(keypair *Keypair) []byte
- func (t *Transaction) UnmarshalBinary(d []byte) ([]byte, error)
- func (t *Transaction) VerifyTransaction(pow []byte) bool
- type TransactionHeader
- type TransactionSlice
- func (slice TransactionSlice) AddTransaction(t Transaction) TransactionSlice
- func (slice TransactionSlice) Exists(tr Transaction) bool
- func (slice TransactionSlice) Len() int
- func (slice *TransactionSlice) MarshalBinary() ([]byte, error)
- func (slice *TransactionSlice) UnmarshalBinary(d []byte) error
- type TransactionsQueue
Constants ¶
View Source
const ( BLOCKCHAIN_PORT = "9119" MAX_NODE_CONNECTIONS = 400 NETWORK_KEY_SIZE = 80 TRANSACTION_HEADER_SIZE = NETWORK_KEY_SIZE + NETWORK_KEY_SIZE + 4 + 32 + 4 + 4 /* int32 nonce */ BLOCK_HEADER_SIZE = NETWORK_KEY_SIZE + 4 + 32 + 32 + 4 /* int32 nonce */ KEY_POW_COMPLEXITY = 0 TEST_KEY_POW_COMPLEXITY = 0 TRANSACTION_POW_COMPLEXITY = 1 TEST_TRANSACTION_POW_COMPLEXITY = 1 BLOCK_POW_COMPLEXITY = 2 TEST_BLOCK_POW_COMPLEXITY = 2 KEY_SIZE = 28 POW_PREFIX = 0 TEST_POW_PREFIX = 0 MESSAGE_TYPE_SIZE = 1 MESSAGE_OPTIONS_SIZE = 4 )
View Source
const ( MESSAGE_GET_NODES = iota + 20 MESSAGE_SEND_NODES MESSAGE_GET_TRANSACTION MESSAGE_SEND_TRANSACTION MESSAGE_GET_BLOCK MESSAGE_SEND_BLOCK )
Variables ¶
View Source
var ( TRANSACTION_POW = helpers.ArrayOfBytes(TRANSACTION_POW_COMPLEXITY, POW_PREFIX) BLOCK_POW = helpers.ArrayOfBytes(BLOCK_POW_COMPLEXITY, POW_PREFIX) TEST_TRANSACTION_POW = helpers.ArrayOfBytes(TEST_TRANSACTION_POW_COMPLEXITY, POW_PREFIX) TEST_BLOCK_POW = helpers.ArrayOfBytes(TEST_BLOCK_POW_COMPLEXITY, POW_PREFIX) )
View Source
var Core = struct { *Keypair *Blockchain *Network }{}
Functions ¶
func CheckProofOfWork ¶
func ConnectToNode ¶
func ConnectToNode(dst string, timeout time.Duration, retry bool, cb NodeChannel)
func CreateConnectionsQueue ¶
func CreateConnectionsQueue() (ConnectionsQueue, NodeChannel)
func GetIpAddress ¶
func GetIpAddress() []string
func HandleIncomingMessage ¶
func HandleIncomingMessage(msg Message)
func HandleNode ¶
func HandleNode(node *Node)
func SEED_NODES ¶
func SEED_NODES() []string
func SignatureVerify ¶
Types ¶
type Block ¶
type Block struct { *BlockHeader Signature []byte *TransactionSlice }
func (*Block) AddTransaction ¶
func (b *Block) AddTransaction(t *Transaction)
func (*Block) GenerateMerkelRoot ¶
func (*Block) GenerateNonce ¶
func (*Block) MarshalBinary ¶
func (*Block) UnmarshalBinary ¶
func (*Block) VerifyBlock ¶
type BlockHeader ¶
type BlockHeader struct { Origin []byte PrevBlock []byte MerkelRoot []byte Timestamp uint32 Nonce uint32 }
func (*BlockHeader) MarshalBinary ¶
func (h *BlockHeader) MarshalBinary() ([]byte, error)
func (*BlockHeader) UnmarshalBinary ¶
func (h *BlockHeader) UnmarshalBinary(d []byte) error
type BlockSlice ¶
type BlockSlice []Block
func (BlockSlice) Exists ¶
func (bs BlockSlice) Exists(b Block) bool
func (BlockSlice) PreviousBlock ¶
func (bs BlockSlice) PreviousBlock() *Block
type Blockchain ¶
type Blockchain struct { CurrentBlock Block BlockSlice TransactionsQueue BlocksQueue }
func SetupBlockchan ¶
func SetupBlockchan() *Blockchain
func (*Blockchain) AddBlock ¶
func (bl *Blockchain) AddBlock(b Block)
func (*Blockchain) CreateNewBlock ¶
func (bl *Blockchain) CreateNewBlock() Block
func (*Blockchain) GenerateBlocks ¶
func (bl *Blockchain) GenerateBlocks() chan Block
func (*Blockchain) Run ¶
func (bl *Blockchain) Run()
type BlocksQueue ¶
type BlocksQueue chan Block
type ConnectionsQueue ¶
type ConnectionsQueue chan string
type Keypair ¶
type Keypair struct { Public []byte `json:"public"` // base58 (x y) Private []byte `json:"private"` // d (base58 encoded) }
Key generation with proof of work
func GenerateNewKeypair ¶
func GenerateNewKeypair() *Keypair
type Network ¶
type Network struct { Nodes ConnectionsQueue Address string ConnectionCallback NodeChannel BroadcastQueue chan Message IncomingMessages chan Message }
func SetupNetwork ¶
func (*Network) BroadcastMessage ¶
type NodeChannel ¶
type NodeChannel chan *Node
func StartListening ¶
func StartListening(address string) NodeChannel
type Transaction ¶
type Transaction struct { Header TransactionHeader Signature []byte Payload []byte }
func CreateTransaction ¶
func CreateTransaction(txt string) *Transaction
func NewTransaction ¶
func NewTransaction(from, to, payload []byte) *Transaction
Returns bytes to be sent to the network
func (*Transaction) GenerateNonce ¶
func (t *Transaction) GenerateNonce(prefix []byte) uint32
func (*Transaction) Hash ¶
func (t *Transaction) Hash() []byte
func (*Transaction) MarshalBinary ¶
func (t *Transaction) MarshalBinary() ([]byte, error)
func (*Transaction) Sign ¶
func (t *Transaction) Sign(keypair *Keypair) []byte
func (*Transaction) UnmarshalBinary ¶
func (t *Transaction) UnmarshalBinary(d []byte) ([]byte, error)
func (*Transaction) VerifyTransaction ¶
func (t *Transaction) VerifyTransaction(pow []byte) bool
type TransactionHeader ¶
type TransactionHeader struct { From []byte To []byte Timestamp uint32 PayloadHash []byte PayloadLength uint32 Nonce uint32 }
func (*TransactionHeader) MarshalBinary ¶
func (th *TransactionHeader) MarshalBinary() ([]byte, error)
func (*TransactionHeader) UnmarshalBinary ¶
func (th *TransactionHeader) UnmarshalBinary(d []byte) error
type TransactionSlice ¶
type TransactionSlice []Transaction
func DiffTransactionSlices ¶
func DiffTransactionSlices(a, b TransactionSlice) (diff TransactionSlice)
func (TransactionSlice) AddTransaction ¶
func (slice TransactionSlice) AddTransaction(t Transaction) TransactionSlice
func (TransactionSlice) Exists ¶
func (slice TransactionSlice) Exists(tr Transaction) bool
func (TransactionSlice) Len ¶
func (slice TransactionSlice) Len() int
func (*TransactionSlice) MarshalBinary ¶
func (slice *TransactionSlice) MarshalBinary() ([]byte, error)
func (*TransactionSlice) UnmarshalBinary ¶
func (slice *TransactionSlice) UnmarshalBinary(d []byte) error
type TransactionsQueue ¶
type TransactionsQueue chan *Transaction
Click to show internal directories.
Click to hide internal directories.