You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
629 B

6 years ago
  1. package main
  2. import (
  3. "fmt"
  4. p2plib "./p2plib"
  5. blockchainlib "./blockchainlib"
  6. )
  7. func createMsgHandlerCases() map[string]func(p2plib.Peer, p2plib.Msg) {
  8. configuredMsgCases := make(map[string]func(p2plib.Peer, p2plib.Msg))
  9. configuredMsgCases["Block"] = func(peer p2plib.Peer, msg p2plib.Msg) {
  10. //TODO check if the block is signed by an autorized emitter
  11. //block = msg.Data converted to Block
  12. var block blockchainlib.Block
  13. if !blockchain.BlockExists(block) {
  14. blockchain.AddBlock(block)
  15. p2plib.PropagateData(peer, "block in string format")
  16. }
  17. }
  18. fmt.Println(configuredMsgCases)
  19. return configuredMsgCases
  20. }