solana-go/account.go

53 lines
932 B
Go
Raw Normal View History

2020-11-25 11:25:32 -08:00
package solana
import (
"fmt"
)
type Account struct {
PrivateKey PrivateKey
}
func NewAccount() *Account {
_, privateKey, err := NewRandomPrivateKey()
if err != nil {
panic(fmt.Sprintf("failed to generate private key: %s", err))
}
return &Account{
PrivateKey: privateKey,
}
}
func AccountFromPrivateKeyBase58(privateKey string) (*Account, error) {
k, err := PrivateKeyFromBase58(privateKey)
if err != nil {
return nil, fmt.Errorf("account from private key: private key from b58: %w", err)
}
return &Account{
PrivateKey: k,
}, nil
}
func (a *Account) PublicKey() PublicKey {
return a.PrivateKey.PublicKey()
}
2020-11-26 14:05:05 -08:00
type AccountMeta struct {
PublicKey PublicKey
IsSigner bool
IsWritable bool
}
func (a *AccountMeta) less(act *AccountMeta) bool {
if a.IsSigner && !act.IsSigner {
return true
} else if !a.IsSigner && act.IsSigner {
return false
}
if a.IsWritable {
return true
}
return false
}