//TODO pass amt in from url. (make estimate of length)
func UpdateNameReg(fileName, hash, amt string) (string, error) {
	nodeAddr := os.Getenv("MINTX_NODE_ADDR")
	signAddr := os.Getenv("MINTX_SIGN_ADDR")
	chainID := os.Getenv("MINTX_CHAINID")
	pubkey := os.Getenv("MINTX_PUBKEY")
	addr := ""
	amtS := "1000000"
	nonceS := ""
	feeS := "0"
	name := fileName
	data := hash

	//build and sign a nameTx, send it away for broadcasting
	nTx, err := core.Name(nodeAddr, pubkey, addr, amtS, nonceS, feeS, name, data)
	if err != nil {
		fmt.Printf("corename error: %v\n", err)
	}

	//sign but don't broadcast
	_, err = core.SignAndBroadcast(chainID, "", signAddr, nTx, true, false, false)
	if err != nil {
		fmt.Printf("sign error: %v\n", err)
	}

	n := new(int64)
	w := new(bytes.Buffer)
	wire.WriteBinary(nTx, w, n, &err)

	err = postTxData(nodeAddr, hash, w.Bytes())
	if err != nil {
		fmt.Printf("post error: %v\n", err)
	}
	return "", nil
}
// General Convenience
func SimpleHashFromBinary(item interface{}) []byte {
	hasher, n, err := ripemd160.New(), new(int64), new(error)
	wire.WriteBinary(item, hasher, n, err)
	if *err != nil {
		PanicCrisis(err)
	}
	return hasher.Sum(nil)
}
// TODO: Slicing the array gives us length prefixing but loses the type byte.
// Revisit if we add more pubkey types.
// For now, we artificially append the type byte in front to give us backwards
// compatibility for when the pubkey wasn't fixed length array
func (pubKey PubKeyEd25519) Address() []byte {
	w, n, err := new(bytes.Buffer), new(int64), new(error)
	wire.WriteBinary(pubKey[:], w, n, err)
	if *err != nil {
		PanicCrisis(*err)
	}
	// append type byte
	encodedPubkey := append([]byte{1}, w.Bytes()...)
	hasher := ripemd160.New()
	hasher.Write(encodedPubkey) // does not error
	return hasher.Sum(nil)
}
func (kv KVPair) Hash() []byte {
	hasher, n, err := ripemd160.New(), new(int64), new(error)
	wire.WriteString(kv.Key, hasher, n, err)
	if kvH, ok := kv.Value.(Hashable); ok {
		wire.WriteByteSlice(kvH.Hash(), hasher, n, err)
	} else {
		wire.WriteBinary(kv.Value, hasher, n, err)
	}
	if *err != nil {
		PanicSanity(*err)
	}
	return hasher.Sum(nil)
}
func AccountEncoder(o interface{}, w io.Writer, n *int64, err *error) {
	wire.WriteBinary(o.(*Account), w, n, err)
}
func ValidatorInfoEncoder(o interface{}, w io.Writer, n *int64, err *error) {
	wire.WriteBinary(o.(*ValidatorInfo), w, n, err)
}
func (vc validatorCodec) Encode(o interface{}, w io.Writer, n *int64, err *error) {
	wire.WriteBinary(o.(*Validator), w, n, err)
}