From c6668030bf4065d01b65607b59c3c7e5a30ad554 Mon Sep 17 00:00:00 2001 From: billettc Date: Fri, 27 Nov 2020 10:23:45 -0500 Subject: [PATCH] added website resize symbol and fix meta data size --- programs/tokenregistry/instruction.go | 1 + programs/tokenregistry/types.go | 21 +++++++++++++++++++-- programs/tokenregistry/types_test.go | 10 +++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/programs/tokenregistry/instruction.go b/programs/tokenregistry/instruction.go index 4066049..439882c 100644 --- a/programs/tokenregistry/instruction.go +++ b/programs/tokenregistry/instruction.go @@ -111,6 +111,7 @@ type RegisterTokenAccounts struct { type RegisterToken struct { Logo Logo Name Name + Website Website Symbol Symbol Accounts *RegisterTokenAccounts `bin:"-"` } diff --git a/programs/tokenregistry/types.go b/programs/tokenregistry/types.go index ec66032..5784ed3 100644 --- a/programs/tokenregistry/types.go +++ b/programs/tokenregistry/types.go @@ -21,7 +21,7 @@ import ( "github.com/dfuse-io/solana-go" ) -const TOKEN_META_SIZE = 145 +const TOKEN_META_SIZE = 197 type TokenMeta struct { IsInitialized bool @@ -31,6 +31,7 @@ type TokenMeta struct { RegistrationAuthority *solana.PublicKey Logo Logo Name Name + Website Website Symbol Symbol } @@ -75,7 +76,7 @@ func (n Name) String() string { return AsciiString(n[:]) } -type Symbol [12]byte +type Symbol [32]byte func SymbolFromString(symbol string) (Symbol, error) { data := []byte(symbol) @@ -91,6 +92,22 @@ func (s Symbol) String() string { return AsciiString(s[:]) } +type Website [32]byte + +func WebsiteFromString(symbol string) (Website, error) { + data := []byte(symbol) + if len(data) > 32 { + return Website{}, fmt.Errorf("website data to long expected 32 got %d", len(data)) + } + s := Website{} + copy(s[:], data) + return s, nil +} + +func (s Website) String() string { + return AsciiString(s[:]) +} + func AsciiString(data []byte) string { var trimmed []byte for _, b := range data { diff --git a/programs/tokenregistry/types_test.go b/programs/tokenregistry/types_test.go index 46a59ea..8657bc0 100644 --- a/programs/tokenregistry/types_test.go +++ b/programs/tokenregistry/types_test.go @@ -31,5 +31,13 @@ func TestSymbolFromString(t *testing.T) { require.NoError(t, err) require.Equal(t, "symb", l.String()) - require.Equal(t, Symbol([12]byte{115, 121, 109, 98, 0, 0, 0, 0, 0, 0, 0, 0}), l) + require.Equal(t, Symbol([32]byte{115, 121, 109, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), l) +} + +func TestWebsiteFromString(t *testing.T) { + l, err := WebsiteFromString("webs") + require.NoError(t, err) + + require.Equal(t, "webs", l.String()) + require.Equal(t, Website([32]byte{119, 101, 98, 115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), l) }