|
|
|
@@ -0,0 +1,25 @@ |
|
|
|
package model |
|
|
|
|
|
|
|
import ( |
|
|
|
"crypto/sha256" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
) |
|
|
|
|
|
|
|
func (b *BeaconEvent) Hash() []byte { |
|
|
|
rBatt := (b.Battery / 10) * 10 |
|
|
|
c := fmt.Sprintf("%d%d%s%s%s", rBatt, b.Event, b.ID, b.Name, b.Type) |
|
|
|
h := sha256.New() |
|
|
|
h.Write([]byte(c)) |
|
|
|
bs := h.Sum(nil) |
|
|
|
|
|
|
|
return bs |
|
|
|
} |
|
|
|
|
|
|
|
func (b BeaconEvent) ToJSON() ([]byte, error) { |
|
|
|
eData, err := json.Marshal(b) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return eData, nil |
|
|
|
} |