mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
_pkg.dev: drop address pkg, move test into crypto
address wrappers don't seem to fit well into master's code, so just drop 'em, but pick the testing function with good known input/output pair.
This commit is contained in:
parent
d7701fe7db
commit
2275b9e4ad
3 changed files with 13 additions and 61 deletions
|
@ -1,43 +0,0 @@
|
|||
package address
|
||||
|
||||
import (
|
||||
"github.com/CityOfZion/neo-go/pkg/crypto/base58"
|
||||
"github.com/CityOfZion/neo-go/pkg/wire/util"
|
||||
)
|
||||
|
||||
// ToScriptHash converts an address to a script hash
|
||||
func ToScriptHash(address string) string {
|
||||
a, err := Uint160Decode(address)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return a.String()
|
||||
|
||||
}
|
||||
|
||||
// ToReverseScriptHash converts an address to a reverse script hash
|
||||
func ToReverseScriptHash(address string) string {
|
||||
a, err := Uint160Decode(address)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return a.ReverseString()
|
||||
}
|
||||
|
||||
// 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])
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package address
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestScriptHash(t *testing.T) {
|
||||
address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP"
|
||||
|
||||
hash := ToScriptHash(address)
|
||||
reverseHash := ToReverseScriptHash(address)
|
||||
|
||||
assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", reverseHash)
|
||||
assert.Equal(t, "1f72e68b4e39602912106d53b229378a082784b2", hash)
|
||||
}
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUint160DecodeAddress(t *testing.T) {
|
||||
func TestUint160DecodeEncodeAddress(t *testing.T) {
|
||||
addrs := []string{
|
||||
"AMLr1CpPQtbEdiJdriX1HpRNMZUwbU2Huj",
|
||||
"AKtwd3DRXj3nL5kHMUoNsdnsCEVjnuuTFF",
|
||||
|
@ -20,3 +20,15 @@ func TestUint160DecodeAddress(t *testing.T) {
|
|||
assert.Equal(t, addr, AddressFromUint160(val))
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint160DecodeKnownAddress(t *testing.T) {
|
||||
address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP"
|
||||
|
||||
val, err := Uint160DecodeAddress(address)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", val.ReverseString())
|
||||
assert.Equal(t, "1f72e68b4e39602912106d53b229378a082784b2", val.String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue