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

Issue:
Add address associated with output payload
Add a line to `prettifyOutput` that prints the address associated with the output payload.


Discussion / hints:
@prestwich Any suggestions on how to do this?
switch based on output type. if the type is `P2PKH`, pass the `payload` to `EncodeP2PKH`, etc.

Fix patch:
diff --git a/golang/cli/vout.go b/golang/cli/vout.go
index 4e3fef0b..e2cfaf53 100644
--- a/golang/cli/vout.go
+++ b/golang/cli/vout.go
@@ -18,12 +18,33 @@ func prettifyOutput(
 	// Get the output type in readable format
 	outputTypeString := btcspv.GetOutputType(outputType)
 
+	// Get the address associated with the output
+	address := getAddress(outputType, outpoint)
+
 	dataStr := fmt.Sprintf(
-		"\nOutput #%d:\n  Payload: %s,\n  Value: %d,\n  Type: %s\n",
-		numOutput, outpointStr, value, outputTypeString)
+		"\nOutput #%d:\n  Address: %s\n  Payload: %s,\n  Value: %d,\n  Type: %s\n",
+		numOutput, address, outpointStr, value, outputTypeString)
 	return dataStr
 }
 
+// getAddress return the address associated with the output
+func getAddress(outputType btcspv.OutputType, outpoint []byte) string {
+	var address string
+	switch outputType {
+	case btcspv.WPKH:
+		address = btcspv.EncodeP2WPKH(outpoint)
+	case btcspv.WSH:
+		address = btcspv.EncodeP2WSH(outpoint)
+	case btcspv.PKH:
+		address = btcspv.EncodeP2PKH(outpoint)
+	case btcspv.SH:
+		address = btcspv.EncodeP2SH(outpoint)
+	default:
+		address = ""
+	}
+	return address
+}
+
 // ParseVout parses an output vector from hex
 func ParseVout(vout []byte) string {
 	// Validate the vout


Test patch: