store

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: LGPL-3.0 Imports: 8 Imported by: 19

Documentation

Overview

Package store provides local keystore management for TRON accounts.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoUnlockBadPassphrase is returned when an account cannot be unlocked with the given passphrase.
	ErrNoUnlockBadPassphrase = fmt.Errorf("could not unlock account with passphrase, perhaps need different phrase")
)

Functions

func AddressFromAccountName

func AddressFromAccountName(name string) (string, error)

AddressFromAccountName returns the Base58 address for the named account, or an error if not found.

func CloseAll added in v0.24.3

func CloseAll()

CloseAll closes all tracked keystores and resets the factory to production defaults. This is a safety net for test cleanup.

func DefaultLocation

func DefaultLocation() string

DefaultLocation returns the current default keystore directory path.

func DescribeLocalAccounts

func DescribeLocalAccounts()

DescribeLocalAccounts prints all account alias names and their addresses to stdout.

func DoesNamedAccountExist

func DoesNamedAccountExist(name string) bool

DoesNamedAccountExist reports whether an account alias with the given name exists locally.

func FromAccountName

func FromAccountName(name string) *keystore.KeyStore

FromAccountName returns a KeyStore loaded from the named account's directory.

func FromAddress

func FromAddress(addr string) *keystore.KeyStore

FromAddress will return nil if the Base58 string is not found in the imported accounts. Non-matching keystores are closed to prevent goroutine leaks.

func InitConfigDir

func InitConfigDir()

InitConfigDir creates the account keystore directory if it does not exist.

func LocalAccounts

func LocalAccounts() []string

LocalAccounts returns the alias names of all locally stored accounts.

func SetDefaultLocation

func SetDefaultLocation(directory string)

SetDefaultLocation updates the default keystore directory and creates it if needed.

func SetKeystoreFactory added in v0.24.3

func SetKeystoreFactory(fn func(string) *keystore.KeyStore)

SetKeystoreFactory replaces the function used to create keystores. Pass keystore.ForPathLight in tests for faster key derivation.

func UnlockedKeystore

func UnlockedKeystore(from, passphrase string) (*keystore.KeyStore, *keystore.Account, error)

UnlockedKeystore finds, unlocks, and returns the keystore and account for the given Base58 address.

Types

type Store added in v0.26.0

type Store struct {
	// contains filtered or unexported fields
}

Store manages keystores for TRON accounts.

func DefaultStoreInstance added in v0.26.0

func DefaultStoreInstance() *Store

DefaultStoreInstance creates a Store using the default ~/.tronctl directory.

func NewStore added in v0.26.0

func NewStore(configDir string) *Store

NewStore creates a Store rooted at the given directory.

func (*Store) AddressFromAccountName added in v0.26.0

func (s *Store) AddressFromAccountName(name string) (string, error)

AddressFromAccountName returns the Base58 address for the named account, or an error if not found.

func (*Store) CloseAll added in v0.26.0

func (s *Store) CloseAll()

CloseAll closes all tracked keystores and resets the factory to production defaults. This is a safety net for test cleanup.

func (*Store) DefaultLocation added in v0.26.0

func (s *Store) DefaultLocation() string

DefaultLocation returns the current default keystore directory path.

func (*Store) DescribeLocalAccounts added in v0.26.0

func (s *Store) DescribeLocalAccounts()

DescribeLocalAccounts prints all account alias names and their addresses to stdout.

func (*Store) DoesNamedAccountExist added in v0.26.0

func (s *Store) DoesNamedAccountExist(name string) bool

DoesNamedAccountExist reports whether an account alias with the given name exists locally.

func (*Store) Forget added in v0.26.0

func (s *Store) Forget(ks *keystore.KeyStore)

Forget removes a keystore from the tracked set. Call this after closing a keystore obtained via FromAccountName to allow garbage collection.

func (*Store) FromAccountName added in v0.26.0

func (s *Store) FromAccountName(name string) *keystore.KeyStore

FromAccountName returns a KeyStore loaded from the named account's directory.

func (*Store) FromAddress added in v0.26.0

func (s *Store) FromAddress(addr string) *keystore.KeyStore

FromAddress will return nil if the Base58 string is not found in the imported accounts. Non-matching keystores are closed to prevent goroutine leaks.

func (*Store) InitConfigDir added in v0.26.0

func (s *Store) InitConfigDir()

InitConfigDir creates the account keystore directory if it does not exist.

func (*Store) LocalAccounts added in v0.26.0

func (s *Store) LocalAccounts() []string

LocalAccounts returns the alias names of all locally stored accounts.

func (*Store) SetDefaultLocation added in v0.26.0

func (s *Store) SetDefaultLocation(directory string)

SetDefaultLocation updates the config directory and creates the account-keys subdirectory if needed.

func (*Store) SetKeystoreFactory added in v0.26.0

func (s *Store) SetKeystoreFactory(fn func(string) *keystore.KeyStore)

SetKeystoreFactory replaces the function used to create keystores. Pass keystore.ForPathLight in tests for faster key derivation.

func (*Store) UnlockedKeystore added in v0.26.0

func (s *Store) UnlockedKeystore(from, passphrase string) (*keystore.KeyStore, *keystore.Account, error)

UnlockedKeystore finds, unlocks, and returns the keystore and account for the given Base58 address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL