add solana types package
This commit is contained in:
parent
85ff933995
commit
cee922dd4f
|
@ -10,8 +10,11 @@ package base58
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var ErrEncode = errors.New("base58 encoding error")
|
||||
|
||||
// alphabet maps [0, 58) to the base58 character.
|
||||
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
|
||||
|
@ -270,3 +273,14 @@ func Decode32(out *[32]byte, encoded []byte) (ok bool) {
|
|||
|
||||
return true
|
||||
}
|
||||
|
||||
func Encode(buf []byte) string {
|
||||
switch len(buf) {
|
||||
case 32:
|
||||
var out [44]byte
|
||||
outLen := Encode32(&out, *(*[32]byte)(buf))
|
||||
return string(out[:outLen])
|
||||
default:
|
||||
panic("unsupported base58 length")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package solana
|
||||
|
||||
import "go.firedancer.io/radiance/pkg/base58"
|
||||
|
||||
type Hash [32]byte
|
||||
type Address [32]byte
|
||||
type Signature [64]byte
|
||||
|
||||
func (p *Hash) String() string {
|
||||
return base58.Encode(p[:])
|
||||
}
|
||||
|
||||
func (p *Hash) UnmarshalText(b []byte) error {
|
||||
if !base58.Decode32((*[32]byte)(p), b) {
|
||||
return base58.ErrEncode
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Address) String() string {
|
||||
return (*Hash)(p).String()
|
||||
}
|
||||
|
||||
func (p *Address) UnmarshalText(b []byte) error {
|
||||
return (*Hash)(p).UnmarshalText(b)
|
||||
}
|
Loading…
Reference in New Issue