2019-02-25 22:44:14 +00:00
|
|
|
package address
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/base58"
|
2019-03-25 01:04:54 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/wire/util"
|
2019-02-25 22:44:14 +00:00
|
|
|
)
|
|
|
|
|
2019-03-17 18:26:35 +00:00
|
|
|
// ToScriptHash converts an address to a script hash
|
2019-02-25 22:44:14 +00:00
|
|
|
func ToScriptHash(address string) string {
|
2019-08-05 07:34:31 +00:00
|
|
|
a, err := Uint160Decode(address)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return a.String()
|
|
|
|
|
|
|
|
}
|
2019-02-25 22:44:14 +00:00
|
|
|
|
2019-08-05 07:34:31 +00:00
|
|
|
// ToReverseScriptHash converts an address to a reverse script hash
|
|
|
|
func ToReverseScriptHash(address string) string {
|
|
|
|
a, err := Uint160Decode(address)
|
2019-02-25 22:44:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
2019-08-05 07:34:31 +00:00
|
|
|
return a.ReverseString()
|
2019-02-25 22:44:14 +00:00
|
|
|
}
|
2019-03-25 01:04:54 +00:00
|
|
|
|
|
|
|
// FromUint160 returns the "NEO address" from the given
|
|
|
|
// Uint160.
|
|
|
|
func FromUint160(u util.Uint160) (string, error) {
|
|
|
|
// Dont forget to prepend the Address version 0x17 (23) A
|
|
|
|
b := append([]byte{0x17}, u.Bytes()...)
|
|
|
|
return base58.CheckEncode(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uint160Decode attempts to decode the given NEO address string
|
|
|
|
// into an Uint160.
|
|
|
|
func Uint160Decode(s string) (u util.Uint160, err error) {
|
|
|
|
b, err := base58.CheckDecode(s)
|
|
|
|
if err != nil {
|
|
|
|
return u, err
|
|
|
|
}
|
|
|
|
return util.Uint160DecodeBytes(b[1:21])
|
|
|
|
}
|