added website resize symbol and fix meta data size
This commit is contained in:
parent
5069128e64
commit
c6668030bf
|
@ -111,6 +111,7 @@ type RegisterTokenAccounts struct {
|
|||
type RegisterToken struct {
|
||||
Logo Logo
|
||||
Name Name
|
||||
Website Website
|
||||
Symbol Symbol
|
||||
Accounts *RegisterTokenAccounts `bin:"-"`
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue