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

Issue:
golang cli is out of date
with the new type refactor, the CLI needs to be refactored

@ErinHales  want to take this one?


Discussion / hints:
Sure

Fix patch:
diff --git a/golang/cli/header.go b/golang/cli/header.go
index f01b2088..e31c813b 100644
--- a/golang/cli/header.go
+++ b/golang/cli/header.go
@@ -12,18 +12,18 @@ import (
 
 func prettifyHeaderData(
 	num uint,
-	digest []byte,
+	digest btcspv.Hash256Digest,
 	version uint,
-	prevHash []byte,
-	merkleRoot []byte,
+	prevHash btcspv.Hash256Digest,
+	merkleRoot btcspv.Hash256Digest,
 	timestamp uint,
 	target sdk.Uint,
 	nonce uint) string {
 
 	// Convert byte arrays to readable hex strings
-	digestStr := hex.EncodeToString(digest)
-	prevHashStr := hex.EncodeToString(prevHash)
-	merkleRootStr := hex.EncodeToString(merkleRoot)
+	digestStr := hex.EncodeToString(digest[:])
+	prevHashStr := hex.EncodeToString(prevHash[:])
+	merkleRootStr := hex.EncodeToString(merkleRoot[:])
 
 	// Convert timestamp to readable time
 	timestampStr := strconv.Itoa(int(timestamp))
@@ -42,7 +42,7 @@ func prettifyHeaderData(
 }
 
 // ParseHeader takes in a header and returns information about that header: digest, version, previous header hash, merkle root, timestamp, target and nonce
-func ParseHeader(header []byte) string {
+func ParseHeader(header btcspv.RawHeader) string {
 	// Get information about the header using ParseHeader
 	digest, version, prevHash, merkleRoot, timestamp, target, nonce, err := btcspv.ParseHeader(header)
 	// Check for errors
diff --git a/golang/cli/prove.go b/golang/cli/prove.go
index 696f6931..75b87c5f 100644
--- a/golang/cli/prove.go
+++ b/golang/cli/prove.go
@@ -12,7 +12,7 @@ func Prove(
 	vin []byte,
 	vout []byte,
 	locktime []byte,
-	merkleRoot []byte,
+	merkleRoot btcspv.Hash256Digest,
 	intermediateNodes []byte,
 	index uint) string {
 	// Calculate the tx id
diff --git a/golang/cli/spvcli.go b/golang/cli/spvcli.go
index a9636ed6..5990b4bd 100644
--- a/golang/cli/spvcli.go
+++ b/golang/cli/spvcli.go
@@ -17,7 +17,8 @@ func route(command string, arguments [][]byte) string {
 	case "parseVout":
 		result = ParseVout(arguments[0])
 	case "parseHeader":
-		result = ParseHeader(arguments[0])
+		rawHeader, _ := btcspv.NewRawHeader(arguments[0])
+		result = ParseHeader(rawHeader)
 	case "validateHeaderChain":
 		result = ValidateHeaderChain(arguments[0])
 	case "prove":
@@ -28,7 +29,8 @@ func route(command string, arguments [][]byte) string {
 			return fmt.Sprintf("%s\n", err)
 		}
 		uintArg := uint(uint64Arg)
-		result = Prove(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], uintArg)
+		merkleRoot, _ := btcspv.NewHash256Digest(arguments[4])
+		result = Prove(arguments[0], arguments[1], arguments[2], arguments[3], merkleRoot, arguments[5], uintArg)
 	default:
 		result = fmt.Sprintf("Unknown command: %s\n", command)
 	}
diff --git a/golang/cli/vin.go b/golang/cli/vin.go
index c8402fde..e2394680 100644
--- a/golang/cli/vin.go
+++ b/golang/cli/vin.go
@@ -7,8 +7,8 @@ import (
 	btcspv "github.com/summa-tx/bitcoin-spv/golang/btcspv"
 )
 
-func prettifyInput(numInput int, outpoint []byte, index uint, inputType btcspv.InputType, sequence uint) string {
-	outpointStr := hex.EncodeToString(outpoint)
+func prettifyInput(numInput int, outpoint btcspv.Hash256Digest, index uint, inputType btcspv.InputType, sequence uint) string {
+	outpointStr := hex.EncodeToString(outpoint[:])
 
 	// Get the input type in readable format
 	inputTypeString := btcspv.GetInputType(inputType)
diff --git a/golang/cli/vout.go b/golang/cli/vout.go
index 6068339f..7ba16806 100644
--- a/golang/cli/vout.go
+++ b/golang/cli/vout.go
@@ -36,7 +36,8 @@ func getAddress(outputType btcspv.OutputType, outpoint []byte) string {
 	case btcspv.WPKH:
 		address, err = btcspv.EncodeP2WPKH(outpoint)
 	case btcspv.WSH:
-		address, err = btcspv.EncodeP2WSH(outpoint)
+		digest, _ := btcspv.NewHash256Digest(outpoint)
+		address, err = btcspv.EncodeP2WSH(digest)
 	case btcspv.PKH:
 		address, err = btcspv.EncodeP2PKH(outpoint)
 	case btcspv.SH:


Test patch: