wallet

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package wallet contains the simulated wallet backend.

Index

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

func NewRandomAccount(rng io.Reader) *Account

NewRandomAccount generates a new account, reading randomness form the given rng. It is not saved to any wallet.

func (*Account) Address

func (a *Account) Address() wallet.Address

Address returns the address of this account.

func (*Account) SignData

func (a *Account) SignData(data []byte) ([]byte, error)

SignData is used to sign data with this account. If the account is locked, returns an error instead of a signature.

type Address

type Address ecdsa.PublicKey

Address represents a simulated address.

func NewRandomAddress

func NewRandomAddress(rng io.Reader) *Address

NewRandomAddress creates a new address using the randomness provided by rng.

func (*Address) Bytes

func (a *Address) Bytes() []byte

Bytes converts this address to bytes.

func (*Address) Cmp added in v0.4.0

func (a *Address) Cmp(addr wallet.Address) int

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

func (a *Address) Equal(addr wallet.Address) bool

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

func (a *Address) MarshalBinary() ([]byte, error)

MarshalBinary marshals the address into its binary representation. Error will always be nil, it is for implementing BinaryMarshaler.

func (*Address) String

func (a *Address) String() string

String converts this address to a human-readable string.

func (*Address) UnmarshalBinary added in v0.9.0

func (a *Address) UnmarshalBinary(data []byte) error

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) DecodeSig

func (b *Backend) DecodeSig(r io.Reader) (wallet.Sig, error)

DecodeSig reads a []byte with length of a signature.

func (*Backend) NewAddress added in v0.9.0

func (b *Backend) NewAddress() wallet.Address

NewAddress returns a variable of type Address, which can be used for unmarshalling an address from its binary representation.

func (*Backend) VerifySignature

func (b *Backend) VerifySignature(msg []byte, sig wallet.Sig, a wallet.Address) (bool, error)

VerifySignature verifies if a signature was made by this account.

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

func NewRestoredWallet(accounts ...*Account) *Wallet

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 NewWallet added in v0.2.1

func NewWallet() *Wallet

NewWallet creates a new empty wallet.

func (*Wallet) AddAccount added in v0.2.1

func (w *Wallet) AddAccount(acc *Account) error

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

func (w *Wallet) DecrementUsage(a wallet.Address)

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

func (w *Wallet) HasAccount(acc *Account) bool

HasAccount checks whether a Wallet has an account. This is only useful for easier testing.

func (*Wallet) IncrementUsage added in v0.2.1

func (w *Wallet) IncrementUsage(a wallet.Address)

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

func (w *Wallet) NewRandomAccount(rng *rand.Rand) wallet.Account

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.

func (*Wallet) Unlock added in v0.2.1

func (w *Wallet) Unlock(a wallet.Address) (wallet.Account, error)

Unlock retrieves the account belonging to the supplied address, and unlocks it. If the address does not have a corresponding account in the wallet, returns an error.

func (*Wallet) UsageCount added in v0.2.1

func (w *Wallet) UsageCount(a wallet.Address) int

UsageCount retrieves an account's usage count (controlled via IncrementUsage and DecrementUsage). Panics if the supplied address does not correspond to any of the wallet's accounts.

Jump to

Keyboard shortcuts

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