func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash []byte) {
	// Proof must verify.
	if !proof.Verify(keyBytes, valueBytes, rootHash) {
		t.Errorf("Invalid proof. Verification failed.")
		return
	}
	// Write/Read then verify.
	proofBytes := wire.BinaryBytes(proof)
	n, err := int64(0), error(nil)
	proof2 := wire.ReadBinary(&IAVLProof{}, bytes.NewBuffer(proofBytes), &n, &err).(*IAVLProof)
	if err != nil {
		t.Errorf("Failed to read IAVLProof from bytes: %v", err)
		return
	}
	if !proof2.Verify(keyBytes, valueBytes, rootHash) {
		// t.Log(Fmt("%X\n%X\n", proofBytes, wire.BinaryBytes(proof2)))
		t.Errorf("Invalid proof after write/read. Verification failed.")
		return
	}
	// Random mutations must not verify
	for i := 0; i < 5; i++ {
		badProofBytes := MutateByteSlice(proofBytes)
		n, err := int64(0), error(nil)
		badProof := wire.ReadBinary(&IAVLProof{}, bytes.NewBuffer(badProofBytes), &n, &err).(*IAVLProof)
		if err != nil {
			continue // This is fine.
		}
		if badProof.Verify(keyBytes, valueBytes, rootHash) {
			t.Errorf("Proof was still valid after a random mutation:\n%X\n%X", proofBytes, badProofBytes)
		}
	}
}
func receiveNameTx(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		str := r.URL.Path[1:]
		hash := strings.Split(str, "/")[1]

		fmt.Printf("hash in rnt %v\n", hash)

		txData, err := ioutil.ReadAll(r.Body)
		if err != nil {
			fmt.Printf("error reading body: %v\n", err)
		}

		tx := new(types.NameTx)
		n := new(int64)
		txD := bytes.NewReader(txData)

		wire.ReadBinary(tx, txD, n, &err)
		if err != nil {
			fmt.Printf("error reading binary: %v\n", err)
		}

		rpcAddr := "http://0.0.0.0:46657"
		_, err1 := core.Broadcast(tx, rpcAddr)
		if err1 != nil {
			fmt.Printf("error broadcasting: %v\n", err1)
		}

		//TODO check Name reg

		endpoint := "http://0.0.0.0:11113/" + "cacheHash/" + hash
		_, err2 := http.Post(endpoint, "", nil)
		if err2 != nil {
			fmt.Printf("cache post error: %v\n", err2)
		}
		w.Write([]byte("success!"))
	}
}
func AccountDecoder(r io.Reader, n *int64, err *error) interface{} {
	return wire.ReadBinary(&Account{}, r, n, err)
}
func ValidatorInfoDecoder(r io.Reader, n *int64, err *error) interface{} {
	return wire.ReadBinary(&ValidatorInfo{}, r, n, err)
}
func (vc validatorCodec) Decode(r io.Reader, n *int64, err *error) interface{} {
	return wire.ReadBinary(&Validator{}, r, n, err)
}