aboutsummaryrefslogtreecommitdiff
path: root/message/message.go
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2021-12-11 01:09:24 +0000
committerGitHub <noreply@github.com>2021-12-11 01:09:24 +0000
commit324bf3196ef7bf24b098f8444718cdc52c87f230 (patch)
treef8a443affd31c3dd1ef1bf4bf68b1dcb02cd1b62 /message/message.go
parent06855381f1a6e6fcd6a92b8e78ced65c45936673 (diff)
Add rudimentary read option
Diffstat (limited to 'message/message.go')
-rw-r--r--message/message.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/message/message.go b/message/message.go
index 19f04a5..aa2a3e5 100644
--- a/message/message.go
+++ b/message/message.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"math/bits"
+ "time"
ipfs "github.com/ipfs/go-ipfs-api"
)
@@ -25,6 +26,11 @@ type Message struct {
Nonce int
}
+// String method for Message: "Message *hash* sent at *human readable timestamp* with nonce *nonce*:\n*message*"
+func (m *Message) String() string {
+ return fmt.Sprintf("Message %x sent at %s with nonce %d:\n%s", m.Hash(), time.Unix(m.Timestamp, 0).Format(time.RFC3339), m.Nonce, m.Message)
+}
+
// Proof of Work: Find the nonce for a message by hashing the message and checking for at least n initial zeroes in the binary representation of the resulting hash
func (msg *Message) ProofOfWork(n int) {
// Create a local copy of the message and start counting