@ -1,3 +1,5 @@ |
|||||
# bc |
# bc |
||||
|
|
||||
Own p2p network and own blockchain libraries written in Go, to develop own decentralized apps. |
Own p2p network and own blockchain libraries written in Go, to develop own decentralized apps. |
||||
|
|
||||
|
The purpose of this code is to learn to develop a p2p network and a blockchain system. |
@ -0,0 +1,25 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
|
||||
|
p2plib "./p2plib" |
||||
|
|
||||
|
blockchainlib "./blockchainlib" |
||||
|
) |
||||
|
|
||||
|
func createMsgHandlerCases() map[string]func(p2plib.Peer, p2plib.Msg) { |
||||
|
configuredMsgCases := make(map[string]func(p2plib.Peer, p2plib.Msg)) |
||||
|
configuredMsgCases["Block"] = func(peer p2plib.Peer, msg p2plib.Msg) { |
||||
|
//TODO check if the block is signed by an autorized emitter
|
||||
|
//block = msg.Data converted to Block
|
||||
|
var block blockchainlib.Block |
||||
|
if !blockchain.BlockExists(block) { |
||||
|
blockchain.AddBlock(block) |
||||
|
p2plib.PropagateData(peer, "block in string format") |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
fmt.Println(configuredMsgCases) |
||||
|
return configuredMsgCases |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
package p2plib |
||||
|
|
||||
|
func SendPetition(peer Peer, petition string) { |
||||
|
_, err := peer.Conn.Write([]byte(petition)) |
||||
|
check(err) |
||||
|
} |