address: rename functions as per #579 comments

Make them more clear to understand.
This commit is contained in:
Roman Khimov 2019-12-25 17:34:18 +03:00
parent 53e6fbbbf9
commit b246653f62
16 changed files with 28 additions and 28 deletions

View file

@ -72,7 +72,7 @@ func getWif(t *testing.B) *keys.WIF {
// getTX returns Invocation transaction with some random attributes in order to have different hashes.
func getTX(t *testing.B, wif *keys.WIF) *transaction.Transaction {
fromAddress := wif.PrivateKey.Address()
fromAddressHash, err := address.DecodeUint160(fromAddress)
fromAddressHash, err := address.StringToUint160(fromAddress)
require.NoError(t, err)
tx := &transaction.Transaction{

View file

@ -673,7 +673,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
// contain double quotes that need to be stripped.
addressStr := expr.Args[0].(*ast.BasicLit).Value
addressStr = strings.Replace(addressStr, "\"", "", 2)
uint160, err := address.DecodeUint160(addressStr)
uint160, err := address.StringToUint160(addressStr)
if err != nil {
c.prog.Err = err
return

View file

@ -34,7 +34,7 @@ func TestDecodeBlock1(t *testing.T) {
assert.Equal(t, data["hash"].(string), block.Hash().StringLE())
assert.Equal(t, data["previousblockhash"].(string), block.PrevHash.StringLE())
assert.Equal(t, data["merkleroot"].(string), block.MerkleRoot.StringLE())
assert.Equal(t, data["nextconsensus"].(string), address.EncodeUint160(block.NextConsensus))
assert.Equal(t, data["nextconsensus"].(string), address.Uint160ToString(block.NextConsensus))
script := data["script"].(map[string]interface{})
assert.Equal(t, script["invocation"].(string), hex.EncodeToString(block.Script.InvocationScript))
@ -273,7 +273,7 @@ func TestBlockSizeCalculation(t *testing.T) {
assert.Equal(t, 1527894405, int(b.Timestamp))
assert.Equal(t, 2340363, int(b.Index))
nextConsensus := address.EncodeUint160(b.NextConsensus)
nextConsensus := address.Uint160ToString(b.NextConsensus)
assert.Equal(t, "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR", nextConsensus)
assert.Equal(t, "4012afae6df64195041e4764b57caa9e27fc2cfc596833163904136ec95816d104b44b3737d0e9f6b1b4445cd3b6a5cc80f6b0935675bc44dba44415eb309832b3404dc95bcf85e4635556a1d618e4ce947b26972992ed74788df5f9501b850ac0b40b7112d1ff30e4ade00369e16f0d13932d1ba76725e7682db072f8e2cd7752b840d12bb7dd45dd3b0e2098db5c67b6de55b7c40164937491fcaca1239b25860251224ead23ab232add78ccccd347239eae50ffc98f50b2a84c60ec5c3d284647a7406fabf6ca241b759af6b71080c0dfad7395632e989226a7e52f8cd2c133aeb2226e6e1aea47666fd81f578405a9f9bbd9d0bc523c3a44d7a5099ddc649feabe5f406188b8ee478731a89beeb76fdbd108eb0071b8f2b8678f40c5a1f387a491314336783255dee8cc5af4bf914dfeaacecc318fc13e02262658e39e8ce0631941b1", hex.EncodeToString(b.Script.InvocationScript))

View file

@ -52,7 +52,7 @@ func (out *Output) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"asset": out.AssetID,
"value": out.Amount,
"address": address.EncodeUint160(out.ScriptHash),
"address": address.Uint160ToString(out.ScriptHash),
"n": out.Position,
})
}

View file

@ -58,7 +58,7 @@ func TestDecodeRegisterTXFromRawString(t *testing.T) {
assert.Equal(t, util.Fixed8FromInt64(100000000), txData.Amount)
assert.Equal(t, uint8(0), txData.Precision)
assert.Equal(t, keys.PublicKey{}, txData.Owner)
assert.Equal(t, "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", address.EncodeUint160(txData.Admin))
assert.Equal(t, "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", address.Uint160ToString(txData.Admin))
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Hash().StringLE())
buf := io.NewBufBinWriter()

View file

@ -51,7 +51,7 @@ func TestDecodeEncodeClaimTX(t *testing.T) {
assert.Equal(t, 0, len(tx.Attributes))
assert.Equal(t, 0, len(tx.Inputs))
assert.Equal(t, 1, len(tx.Outputs))
assert.Equal(t, "AQJseD8iBmCD4sgfHRhMahmoi9zvopG6yz", address.EncodeUint160(tx.Outputs[0].ScriptHash))
assert.Equal(t, "AQJseD8iBmCD4sgfHRhMahmoi9zvopG6yz", address.Uint160ToString(tx.Outputs[0].ScriptHash))
assert.Equal(t, "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7", tx.Outputs[0].AssetID.StringLE())
assert.Equal(t, tx.Outputs[0].Amount.String(), "0.06247739")
invoc := "40456349cec43053009accdb7781b0799c6b591c812768804ab0a0b56b5eae7a97694227fcd33e70899c075848b2cee8fae733faac6865b484d3f7df8949e2aadb"

View file

@ -45,7 +45,7 @@ func TestGetConsensusAddressMainNet(t *testing.T) {
}
assert.Equal(t, consensusScript, script.String())
assert.Equal(t, consensusAddr, address.EncodeUint160(script))
assert.Equal(t, consensusAddr, address.Uint160ToString(script))
}
func TestUtilityTokenTX(t *testing.T) {

View file

@ -244,7 +244,7 @@ func (p *PublicKey) Signature() []byte {
func (p *PublicKey) Address() string {
sig := hash.Hash160(p.GetVerificationScript())
return address.EncodeUint160(sig)
return address.Uint160ToString(sig)
}
// Verify returns true if the signature is valid and corresponds

View file

@ -11,16 +11,16 @@ import (
// be changed and defaults to 23 (0x17), the standard NEO prefix.
var Prefix = byte(0x17)
// EncodeUint160 returns the "NEO address" from the given Uint160.
func EncodeUint160(u util.Uint160) string {
// Uint160ToString returns the "NEO address" from the given Uint160.
func Uint160ToString(u util.Uint160) string {
// Dont forget to prepend the Address version 0x17 (23) A
b := append([]byte{Prefix}, u.BytesBE()...)
return base58.CheckEncode(b)
}
// DecodeUint160 attempts to decode the given NEO address string
// StringToUint160 attempts to decode the given NEO address string
// into an Uint160.
func DecodeUint160(s string) (u util.Uint160, err error) {
func StringToUint160(s string) (u util.Uint160, err error) {
b, err := base58.CheckDecode(s)
if err != nil {
return u, err

View file

@ -14,18 +14,18 @@ func TestUint160DecodeEncodeAddress(t *testing.T) {
"AMxkaxFVG8Q1BhnB4fjTA5ZmUTEnnTMJMa",
}
for _, addr := range addrs {
val, err := DecodeUint160(addr)
val, err := StringToUint160(addr)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, addr, EncodeUint160(val))
assert.Equal(t, addr, Uint160ToString(val))
}
}
func TestUint160DecodeKnownAddress(t *testing.T) {
address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP"
val, err := DecodeUint160(address)
val, err := StringToUint160(address)
if err != nil {
t.Fatal(err)
}
@ -37,7 +37,7 @@ func TestUint160DecodeKnownAddress(t *testing.T) {
func TestUint160DecodeBadBase58(t *testing.T) {
address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJv@"
_, err := DecodeUint160(address)
_, err := StringToUint160(address)
require.Error(t, err)
}
@ -45,6 +45,6 @@ func TestUint160DecodeBadPrefix(t *testing.T) {
// The same AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP key encoded with 0x18 prefix.
address := "AhymDz4vvHLtvaN36CMbzkki7H2U8ENb8F"
_, err := DecodeUint160(address)
_, err := StringToUint160(address)
require.Error(t, err)
}

View file

@ -96,7 +96,7 @@ func (p Param) GetUint160FromAddress() (util.Uint160, error) {
return util.Uint160{}, err
}
return address.DecodeUint160(s)
return address.StringToUint160(s)
}
// GetFuncParam returns current parameter as a function call parameter.

View file

@ -129,7 +129,7 @@ func TestParamGetUint160FromHex(t *testing.T) {
func TestParamGetUint160FromAddress(t *testing.T) {
in := "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"
u160, _ := address.DecodeUint160(in)
u160, _ := address.StringToUint160(in)
p := Param{stringT, in}
u, err := p.GetUint160FromAddress()
assert.Equal(t, u160, u)

View file

@ -31,11 +31,11 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac
fromAddress = wif.PrivateKey.Address()
if fromAddressHash, err = address.DecodeUint160(fromAddress); err != nil {
if fromAddressHash, err = address.StringToUint160(fromAddress); err != nil {
return nil, errs.Wrapf(err, "Failed to take script hash from address: %v", fromAddress)
}
if toAddressHash, err = address.DecodeUint160(toAddress); err != nil {
if toAddressHash, err = address.StringToUint160(toAddress); err != nil {
return nil, errs.Wrapf(err, "Failed to take script hash from address: %v", toAddress)
}
tx.Attributes = append(tx.Attributes,
@ -59,7 +59,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac
// AddInputsAndUnspentsToTx adds inputs needed to transaction and one output
// with change.
func AddInputsAndUnspentsToTx(tx *transaction.Transaction, addr string, assetID util.Uint256, amount util.Fixed8, balancer BalanceGetter) error {
scriptHash, err := address.DecodeUint160(addr)
scriptHash, err := address.StringToUint160(addr)
if err != nil {
return errs.Wrapf(err, "failed to take script hash from address: %v", addr)
}

View file

@ -37,8 +37,8 @@ func NewAssetState(a *state.Asset) AssetState {
FeeMode: a.FeeMode,
FeeAddress: a.FeeAddress,
Owner: a.Owner.String(),
Admin: address.EncodeUint160(a.Admin),
Issuer: address.EncodeUint160(a.Issuer),
Admin: address.Uint160ToString(a.Admin),
Issuer: address.Uint160ToString(a.Issuer),
Expiration: a.Expiration,
IsFrozen: a.IsFrozen,
}

View file

@ -15,7 +15,7 @@ type ValidateAddressResponse struct {
func ValidateAddress(addr interface{}) ValidateAddressResponse {
resp := ValidateAddressResponse{Address: addr}
if addr, ok := addr.(string); ok {
_, err := address.DecodeUint160(addr)
_, err := address.StringToUint160(addr)
resp.IsValid = err == nil
}
return resp

View file

@ -156,7 +156,7 @@ func adjustValToType(typ ParamType, val string) (interface{}, error) {
case IntegerType:
return strconv.Atoi(val)
case Hash160Type:
u, err := address.DecodeUint160(val)
u, err := address.StringToUint160(val)
if err == nil {
return hex.EncodeToString(u.BytesBE()), nil
}
@ -215,7 +215,7 @@ func inferParamType(val string) ParamType {
return BoolType
}
_, err = address.DecodeUint160(val)
_, err = address.StringToUint160(val)
if err == nil {
return Hash160Type
}