Commit eba8bc05 authored by geo-gs's avatar geo-gs Committed by Luke Champine

Update according to pull request feedback

parent 1b561951
......@@ -251,7 +251,7 @@ func (api *API) explorerHashHandler(w http.ResponseWriter, req *http.Request, ps
// address.
hash, err := scanHash(ps.ByName("hash"))
if err != nil {
addr, err := types.ScanAddress(ps.ByName("hash"))
addr, err := scanAddress(ps.ByName("hash"))
if err != nil {
WriteError(w, Error{err.Error()}, http.StatusBadRequest)
return
......
......@@ -19,6 +19,15 @@ func scanAmount(amount string) (types.Currency, bool) {
return types.NewCurrency(i), true
}
// scanAddress scans a types.UnlockHash from a string.
func scanAddress(addrStr string) (addr types.UnlockHash, err error) {
err = addr.LoadString(addrStr)
if err != nil {
return types.UnlockHash{}, err
}
return addr, nil
}
// scanHash scans a crypto.Hash from a string.
func scanHash(s string) (h crypto.Hash, err error) {
err = h.LoadString(s)
......
......@@ -483,7 +483,7 @@ func (api *API) walletSiacoinsHandler(w http.ResponseWriter, req *http.Request,
WriteError(w, Error{"could not read amount from POST call to /wallet/siacoins"}, http.StatusBadRequest)
return
}
dest, err := types.ScanAddress(req.FormValue("destination"))
dest, err := scanAddress(req.FormValue("destination"))
if err != nil {
WriteError(w, Error{"could not read address from POST call to /wallet/siacoins"}, http.StatusBadRequest)
return
......@@ -513,7 +513,7 @@ func (api *API) walletSiafundsHandler(w http.ResponseWriter, req *http.Request,
WriteError(w, Error{"could not read 'amount' from POST call to /wallet/siafunds"}, http.StatusBadRequest)
return
}
dest, err := types.ScanAddress(req.FormValue("destination"))
dest, err := scanAddress(req.FormValue("destination"))
if err != nil {
WriteError(w, Error{"error when calling /wallet/siafunds: " + err.Error()}, http.StatusBadRequest)
return
......
......@@ -210,11 +210,11 @@ func init() {
GenesisSiafundAllocation = []SiafundOutput{
{
Value: NewCurrency64(2000),
UnlockHash: UnlockHashFromAddrStr("d6a6c5a41dc935ec6aef0a9e7f83148a3fdde61062f7204dd244740cf1591bdfc10dca990dd5"),
UnlockHash: UnlockHashFromString("d6a6c5a41dc935ec6aef0a9e7f83148a3fdde61062f7204dd244740cf1591bdfc10dca990dd5"),
},
{
Value: NewCurrency64(7000),
UnlockHash: UnlockHashFromAddrStr("d1f6e43cf84ef26e0908e3f8e1d8a3348e5d2fb067298950d408843af1bd021154874ee3dca0"),
UnlockHash: UnlockHashFromString("d1f6e43cf84ef26e0908e3f8e1d8a3348e5d2fb067298950d408843af1bd021154874ee3dca0"),
},
{
Value: NewCurrency64(1000),
......@@ -258,11 +258,11 @@ func init() {
GenesisSiafundAllocation = []SiafundOutput{
{
Value: NewCurrency64(2000),
UnlockHash: UnlockHashFromAddrStr("d6a6c5a41dc935ec6aef0a9e7f83148a3fdde61062f7204dd244740cf1591bdfc10dca990dd5"),
UnlockHash: UnlockHashFromString("d6a6c5a41dc935ec6aef0a9e7f83148a3fdde61062f7204dd244740cf1591bdfc10dca990dd5"),
},
{
Value: NewCurrency64(7000),
UnlockHash: UnlockHashFromAddrStr("d1f6e43cf84ef26e0908e3f8e1d8a3348e5d2fb067298950d408843af1bd021154874ee3dca0"),
UnlockHash: UnlockHashFromString("d1f6e43cf84ef26e0908e3f8e1d8a3348e5d2fb067298950d408843af1bd021154874ee3dca0"),
},
{
Value: NewCurrency64(1000),
......
......@@ -1026,11 +1026,13 @@ func ScanAddress(addrStr string) (addr UnlockHash, err error) {
return addr, nil
}
// UnlockHashFromAddrStr convert string address to UnlockHash
func UnlockHashFromAddrStr(addrStr string) (addr UnlockHash) {
dest, err := ScanAddress(addrStr)
// UnlockHashFromString convert string address to UnlockHash
// WARNING: You should never call that function on untrusted input
func UnlockHashFromString(addrStr string) (addr UnlockHash) {
var err error
err = addr.LoadString(addrStr)
if err != nil {
return UnlockHash{}
}
return dest
return addr
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment