From 7aa71680132984ba729c12af727fddd6d23670d2 Mon Sep 17 00:00:00 2001 From: Joop Kiefte Date: Fri, 10 Dec 2021 13:01:14 +0000 Subject: Implement Proof of Work --- main.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 main.go (limited to 'main.go') 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()) +} -- cgit v1.2.3-70-g09d2