aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2021-12-10 13:01:14 +0000
committerGitHub <noreply@github.com>2021-12-10 13:01:14 +0000
commit7aa71680132984ba729c12af727fddd6d23670d2 (patch)
tree8cc5be934b5f6a0720245f0f2e1b8f365e26eec7 /main.go
parentf0b034381cb18671b9ffe718b01ed429c33fbd12 (diff)
Implement Proof of Work
Diffstat (limited to 'main.go')
-rw-r--r--main.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..b4a0f20
--- /dev/null
+++ b/main.go
@@ -0,0 +1,37 @@
+// Infodump is a commandline social network that works over IPFS and communicates through PubSub
+package main
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+ "strings"
+
+ "git.kiefte.eu/lapingvino/infodump/message"
+)
+
+// pubsub "github.com/libp2p/go-libp2p-pubsub"
+// ipfs "github.com/ipfs/go-ipfs-api"
+
+// Main function: get the minimal Proof of Work for a message as the first argument, the message as the rest of the argument and return the stamp
+func main() {
+ // Check if the user provided a number and a message
+ if len(os.Args) < 3 {
+ fmt.Println("Please provide a number and a message")
+ os.Exit(1)
+ }
+ // Get the number of initial zeroes from the user
+ n, err := strconv.Atoi(os.Args[1])
+ if err != nil {
+ fmt.Println("Please provide a number")
+ os.Exit(1)
+ }
+ // Get the message from the user
+ msg := strings.Join(os.Args[2:], " ")
+ // Create a new message
+ m := message.New(msg, n)
+ // Print the stamp
+ fmt.Println(m.Stamp())
+ // Print the message, nonce and number of leading zeroes
+ fmt.Println(m.Message, m.Nonce, m.Lead())
+}