Repository: summa-tx/bitcoin-spv (language: rust)

Issue:
Add more example commands to golang readme
Add a few more examples for the cli in the golang readme.  Preferably find examples that aren't quite so lengthy.


Discussion / hints:

Fix patch:
diff --git a/golang/README.md b/golang/README.md
index 9f9f3448..27bb80fe 100644
--- a/golang/README.md
+++ b/golang/README.md
@@ -78,8 +78,20 @@ of calling `btcspv` functions.
 To build the CLI, run `go build -o spvcli ./cli/*`.
 
 Then you can interact with the cli (although you may need to run
-`chmod +x spvcli` first). Here's a sample command:
+`chmod +x spvcli` first). Here are some sample commands:
 
 ```
-./spvcli parseVout 2045a205000000000017a914c58d56082eeb47555f4c4fc7acb062f0e82a9bc187708203000000000017a914373733553a09172b7188d7c0d374221fdf2e46c687e1a805000000000017a9141d10131d33aaa02b19d88b04f88f3552eab2bf8587d88603000000000017a9146721b54bb3b7e9c2d9fd6fffbc411e2f0cbc0b8c874ec508000000000017a914ce549ff6a7056bcf9b651c01bae9c16cc6f6807a87ae6007000000000017a9143217f0363ec8ed14fff93de3de0733990b792b1387dc5505000000000017a914429129f4c0ffb1e31678b32a93fd9d52b6fd449587b0ad01000000000017a914dba1e2cd44c72a4b5207e96246270d839e46196987f0242c000000000017a91450d81227570591d429168103b37a107fe7dcb25f8729850a00000000001976a914a0db388af9f084082a08ba24e80fe6c9c56dc04b88ac88a302000000000017a914dd8fc156d5c7e73676fb6f008aaf05177dad36db87ca640b000000000017a914b6a81fac2db26d9865304f3e14be05388938e8d587fa9a0400000000001976a914b66df957f43c65f4d26257b18a108ce6f8386c6b88ac89b108000000000017a9148a5d64a1f792584aaffcf308eaf55a6c6c41e60287d41507000000000017a914a282ce5364195bb48686747d6ff6a4364860032f8748ee00000000000017a91469bc726bb0ecb8e1e64a4f71bb7e6f1d7437d85187d8db1400000000001976a9146bb997cef975cce8c1278dcad4b2993258703b9088ac4e0e0200000000001976a91404a8a478ea2707396554c359885f3e6b77bc035c88ac304b0700000000001976a914fc14cbb285729668d90699fb7c21eb3e2e4ddd4288ac80a70a000000000017a9141df808341dbc56c11f0823aed798bef0ed8500b687c31304000000000017a9145ade6f87813db8afb674cf6ec0a87c01af42d33687888d7400000000001976a914750a34081e7079b85e734f0d05a379137c1688da88acea7006000000000017a914c79af7945a8cb4c20add850c2f69f8e4c8ad141f87925dff00000000001976a91400e56b06a395fa5fd2bc495309d245ad4d0de3c588ac73822300000000001976a914524e377908c9aaccd4ddbd54eab719a91444610f88ac08b006000000000017a914e14a023009b395e5ed8a035172e6cdd72ae64d45870a3a0200000000001976a91465179eb63ff11f4ee0a8a386da735b13d496b18a88ac102003000000000017a9143a556b6de6fe6e28fc3eb7e44c1eea43c5a8e46a87cadd8f01000000001976a914cff8fd38572288cc475b646f886d26677ff3531788acd11b21070000000017a9143782174d94c45ed500d660a000d192249870e22c87d8e807000000000017a9145ce410d39e1e9b85ba971f0bc8ac020a86cbf6008750a506000000000017a914613be659f5015225edcb5868bb76b1cc6d709f9187
+./spvcli parseVin 0411c75317188acf700684e5bf54d21e64ce950b3d94ecb0f323cc4b8ca145dc860100000000ffffffff7761252b3ed6eb20468a29007e624976f01ebb182feb83fab07c79c6028308ac070000006a473044022047fa4bb5b1975f1fae539675653ecd7bb2698c0b110fc35658cd7b227f9b9a5402203407f59b9fa5e94dabc2c87fc65e740c281f9ed89b25db9517b92cac76d56a9a0121036d9401fba14d2e1bbe7074c6e716557f7c0c8a48e6e4bf12e5798c75afec992dffffffff33de669bb42c9e05dada07d81775b55397feeac27a05f55cd9d89a6f5e73252b010000006a473044022038f921af4da78526817aaea304b4a0f12615f29babc8da6d0e618db77e0b828f0220787efb070e00fb5a15db4d854813da78abde84317a0263b5d1cceba04aa486f10121036d9401fba14d2e1bbe7074c6e716557f7c0c8a48e6e4bf12e5798c75afec992dffffffffe72701f12466fc9f4e476d87084e05f22bb9869318d3dd9880d6624e95474ae9010000006b483045022100e15bcd9b6f968d29c2660cfb099350bec5a2f9702bf3fcf720161ca5b3ebec7f02206893cb8abe87d6994a06315a9bacbb47a4788a26e50eef922f8b942766fe2a2001210343c792123ca88b3062528b0aabaa1c428523ccaef0dc63cc67d8ddb98fd9f720ffffffff
+
+
+./spvcli parseVout 0x024db6000000000000160014455c0ea778752831d6fc25f6f8cf55dc49d335f040420f0000000000220020aedad4518f56379ef6f1f52f2e0fed64608006b3ccaff2253d847ddc90c91922
+
+
+./spvcli parseHeader 0x0000002073bd2184edd9c4fc76642ea6754ee40136970efc10c4190000000000000000000296ef123ea96da5cf695f22bf7d94be87d49db1ad7ac371ac43c4da4161c8c216349c5ba11928170d38782b
+
+
+./spvcli validateHeaderChain 0x0000002073bd2184edd9c4fc76642ea6754ee40136970efc10c4190000000000000000000296ef123ea96da5cf695f22bf7d94be87d49db1ad7ac371ac43c4da4161c8c216349c5ba11928170d38782b00000020fe70e48339d6b17fbbf1340d245338f57336e97767cc240000000000000000005af53b865c27c6e9b5e5db4c3ea8e024f8329178a79ddb39f7727ea2fe6e6825d1349c5ba1192817e2d9515900000020baaea6746f4c16ccb7cd961655b636d39b5fe1519b8f15000000000000000000c63a8848a448a43c9e4402bd893f701cd11856e14cbbe026699e8fdc445b35a8d93c9c5ba1192817b945dc6c00000020f402c0b551b944665332466753f1eebb846a64ef24c71700000000000000000033fc68e070964e908d961cd11033896fa6c9b8b76f64a2db7ea928afa7e304257d3f9c5ba11928176164145d0000ff3f63d40efa46403afd71a254b54f2b495b7b0164991c2d22000000000000000000f046dc1b71560b7d0786cfbdb25ae320bd9644c98d5c7c77bf9df05cbe96212758419c5ba1192817a2bb2caa00000020e2d4f0edd5edd80bdcb880535443747c6b22b48fb6200d0000000000000000001d3799aa3eb8d18916f46bf2cf807cb89a9b1b4c56c3f2693711bf1064d9a32435429c5ba1192817752e49ae0000002022dba41dff28b337ee3463bf1ab1acf0e57443e0f7ab1d000000000000000000c3aadcc8def003ecbd1ba514592a18baddddcd3a287ccf74f584b04c5c10044e97479c5ba1192817c341f595
+
+
+./spvcli prove 0x01000000 0x011746bd867400f3494b8f44c24b83e1aa58c4f0ff25b4a61cffeffd4bc0f9ba300000000000ffffffff 0x024897070000000000220020a4333e5612ab1a1043b25755c89b16d55184a42f81799e623e6bc39db8539c180000000000000000166a14edb1b5c2f39af0fec151732585b1049b07895211 0x00000000 0x0296ef123ea96da5cf695f22bf7d94be87d49db1ad7ac371ac43c4da4161c8c2 0xe35a0d6de94b656694589964a252957e4673a9fb1d2f8b4a92e3f0a7bb654fddb94e5a1e6d7f7f499fd1be5dd30a73bf5584bf137da5fdd77cc21aeb95b9e35788894be019284bd4fbed6dd6118ac2cb6d26bc4be4e423f55a3a48f2874d8d02a65d9c87d07de21d4dfe7b0a9f4a23cc9a58373e9e6931fefdb5afade5df54c91104048df1ee999240617984e18b6f931e2373673d0195b8c6987d7ff7650d5ce53bcec46e13ab4f2da1146a7fc621ee672f62bc22742486392d75e55e67b09960c3386a0b49e75f1723d6ab28ac9a2028a0c72866e2111d79d4817b88e17c821937847768d92837bae3832bb8e5a4ab4434b97e00a6c10182f211f592409068d6f5652400d9a3d1cc150a7fb692e874cc42d76bdafc842f2fe0f835a7c24d2d60c109b187d64571efbaa8047be85821f8e67e0e85f2f5894bc63d00c2ed9d64 281
 ```
diff --git a/golang/btcspv/utils.go b/golang/btcspv/utils.go
index 871be0d0..ac828c6b 100644
--- a/golang/btcspv/utils.go
+++ b/golang/btcspv/utils.go
@@ -26,7 +26,7 @@ func DecodeIfHex(s string) []byte {
 	return res
 }
 
-// GetOuputType returns the name of the output type associated with the number
+// GetOutputType returns the name of the output type associated with the number
 func GetOutputType(outputType OutputType) string {
 	var typeString string
 	switch outputType {
diff --git a/golang/cli/header.go b/golang/cli/header.go
index 64463fc8..f01b2088 100644
--- a/golang/cli/header.go
+++ b/golang/cli/header.go
@@ -26,9 +26,10 @@ func prettifyHeaderData(
 	merkleRootStr := hex.EncodeToString(merkleRoot)
 
 	// Convert timestamp to readable time
-	unixIntValue, err := strconv.ParseInt(string(timestamp), 10, 64)
+	timestampStr := strconv.Itoa(int(timestamp))
+	unixIntValue, err := strconv.ParseInt(timestampStr, 10, 64)
 	if err != nil {
-		return fmt.Sprintf("%s", err)
+		return fmt.Sprintf("%s\n", err)
 	}
 	timeStr := time.Unix(unixIntValue, 0)
 
@@ -46,7 +47,7 @@ func ParseHeader(header []byte) string {
 	digest, version, prevHash, merkleRoot, timestamp, target, nonce, err := btcspv.ParseHeader(header)
 	// Check for errors
 	if err != nil {
-		return fmt.Sprintf("%s", err)
+		return fmt.Sprintf("%s\n", err)
 	}
 
 	// Format data using prettifyHeaderData
@@ -61,7 +62,7 @@ func ValidateHeaderChain(headers []byte) string {
 	totalDifficulty, err := btcspv.ValidateHeaderChain(headers)
 	// Check for errors
 	if err != nil {
-		return fmt.Sprintf("%s", err)
+		return fmt.Sprintf("%s\n", err)
 	}
 
 	// Return the total difficulty
diff --git a/golang/cli/spvcli.go b/golang/cli/spvcli.go
index 70289da3..a9636ed6 100644
--- a/golang/cli/spvcli.go
+++ b/golang/cli/spvcli.go
@@ -25,12 +25,12 @@ func route(command string, arguments [][]byte) string {
 		str := string(arguments[6])
 		uint64Arg, err := strconv.ParseUint(str, 10, 32)
 		if err != nil {
-			return "Error converting arg to uint"
+			return fmt.Sprintf("%s\n", err)
 		}
 		uintArg := uint(uint64Arg)
 		result = Prove(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], uintArg)
 	default:
-		result = fmt.Sprintf("Unknown command: %s", command)
+		result = fmt.Sprintf("Unknown command: %s\n", command)
 	}
 
 	return result
@@ -49,7 +49,7 @@ func main() {
 	var result string
 
 	if len(os.Args) < 2 {
-		fmt.Print("Not enough arguments")
+		fmt.Print("Not enough arguments\n")
 		return
 	}
 
diff --git a/golang/cli/vin.go b/golang/cli/vin.go
index d55b8bc6..c8402fde 100644
--- a/golang/cli/vin.go
+++ b/golang/cli/vin.go
@@ -23,7 +23,7 @@ func ParseVin(vin []byte) string {
 	// Validate the vin
 	isVin := btcspv.ValidateVin(vin)
 	if !isVin {
-		return "Invalid Vin"
+		return "Invalid Vin\n"
 	}
 
 	numInputs := int(vin[0])
diff --git a/golang/cli/vout.go b/golang/cli/vout.go
index dd57a962..4e3fef0b 100644
--- a/golang/cli/vout.go
+++ b/golang/cli/vout.go
@@ -29,7 +29,7 @@ func ParseVout(vout []byte) string {
 	// Validate the vout
 	isVout := btcspv.ValidateVout(vout)
 	if !isVout {
-		return "Invalid Vout"
+		return "Invalid Vout\n"
 	}
 
 	numOutputs := int(vout[0])
@@ -38,7 +38,7 @@ func ParseVout(vout []byte) string {
 		// Extract each vout at the specified index
 		vout, err := btcspv.ExtractOutputAtIndex(vout, uint8(i))
 		if err != nil {
-			return fmt.Sprintf("%s", err)
+			return fmt.Sprintf("%s\n", err)
 		}
 
 		// Use ParseOutput to get more information about the vout


Test patch: