Documentation ¶
Overview ¶
Package wallet contains the simulated wallet backend.
Index ¶
- type Account
- type Address
- type Backend
- type Randomizer
- type Wallet
- func (w *Wallet) AddAccount(acc *Account) error
- func (w *Wallet) DecrementUsage(a wallet.Address)
- func (w *Wallet) HasAccount(acc *Account) bool
- func (w *Wallet) IncrementUsage(a wallet.Address)
- func (w *Wallet) LockAll()
- func (w *Wallet) NewRandomAccount(rng *rand.Rand) wallet.Account
- func (w *Wallet) Unlock(a wallet.Address) (wallet.Account, error)
- func (w *Wallet) UsageCount(a wallet.Address) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
Account represents a mocked account.
func NewRandomAccount ¶
NewRandomAccount generates a new account, reading randomness form the given rng. It is not saved to any wallet.
type Address ¶
Address represents a simulated address.
func NewRandomAddress ¶
NewRandomAddress creates a new address using the randomness provided by rng.
func (*Address) Cmp ¶ added in v0.4.0
Cmp checks the ordering of two addresses according to following definition:
-1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y)) 0 if (a.X == addr.X) && (a.Y == addr.Y) +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y))
So the X coordinate is weighted higher. Pancis if the passed address is of the wrong type.
func (*Address) Equal ¶ added in v0.9.0
Equal checks the equality of two addresses. The implementation must be equivalent to checking `Address.Cmp(Address) == 0`. Pancis if the passed address is of the wrong type.
func (*Address) MarshalBinary ¶ added in v0.9.0
MarshalBinary marshals the address into its binary representation. Error will always be nil, it is for implementing BinaryMarshaler.
func (*Address) UnmarshalBinary ¶ added in v0.9.0
UnmarshalBinary unmarshals the address from its binary representation.
type Backend ¶
type Backend struct{}
Backend implements the utility interface defined in the wallet package.
func (*Backend) NewAddress ¶ added in v0.9.0
NewAddress returns a variable of type Address, which can be used for unmarshalling an address from its binary representation.
type Randomizer ¶
type Randomizer struct{ Wallet }
Randomizer provides random addresses and accounts.
func (*Randomizer) NewRandomAddress ¶
func (*Randomizer) NewRandomAddress(rng *rand.Rand) wallet.Address
NewRandomAddress creates a new random simulated address.
func (*Randomizer) NewWallet ¶ added in v0.2.1
func (r *Randomizer) NewWallet() test.Wallet
NewWallet returns a new, empty Wallet.
func (*Randomizer) RandomWallet ¶ added in v0.2.1
func (r *Randomizer) RandomWallet() test.Wallet
RandomWallet returns a fixed wallet that can be used to generate random accounts.
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
Wallet is a collection of accounts. Query accounts using Unlock, track their usage using IncrementUsage and DecrementUsage, and lock them using LockAll. Create new accounts using NewRandomAccount, and add existing accounts using AddAccount. Check whether the wallet owns a particular account via HasAccount.
func NewRestoredWallet ¶ added in v0.2.1
NewRestoredWallet creates a wallet with a list of preexisting accounts which are initially locked. This simulates a wallet that has just been restored from persistent storage, and Unlock() has to be called to make accounts usable.
func (*Wallet) AddAccount ¶ added in v0.2.1
AddAccount registers an externally generated account to the wallet. If the account was already registered beforehand, an error is returned. Does not lock or unlock the account.
func (*Wallet) DecrementUsage ¶ added in v0.2.1
DecrementUsage decreases an account's usage count, and if it reaches 0, locks and deletes the account from the wallet. Panics if the call is not matched to another preceding IncrementUsage call or if the supplied address does not correspond to any of the wallet's accounts.
func (*Wallet) HasAccount ¶ added in v0.2.1
HasAccount checks whether a Wallet has an account. This is only useful for easier testing.
func (*Wallet) IncrementUsage ¶ added in v0.2.1
IncrementUsage increases an account's usage count, which is used for resource management. Panics if the wallet does not have an account that corresponds to the supplied address.
func (*Wallet) LockAll ¶ added in v0.2.1
func (w *Wallet) LockAll()
LockAll locks all of a wallet's accounts.
func (*Wallet) NewRandomAccount ¶ added in v0.2.1
NewRandomAccount creates and a new random account from the provided randomness stream. The account is automatically added to the wallet. Returns the generated account. The returned account is already unlocked.