wallet

package
v0.0.0-...-f94ef0f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Script hexutil.Bytes `json:"script"`

	Address common.Address `json:"address"`

	// Encrypted WIF of the account also known as the key.
	EncryptedWIF string `json:"key"`

	// Label is a label the user had made for this account.
	Label string `json:"label"`

	// Indicates whether the account is locked by the user.
	// the client shouldn't spend the funds in a locked account.
	Locked bool `json:"lock"`

	// Indicates whether the account is the default change account.
	Default bool `json:"isDefault"`
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount() (*Account, error)

NewAccount creates a new Account with a random generated PrivateKey.

func NewAccountFromEncryptedWIF

func NewAccountFromEncryptedWIF(wif string, pass string, scrypt keys.ScryptParams) (*Account, error)

NewAccountFromEncryptedWIF creates a new Account from the given encrypted WIF.

func NewAccountFromPrivateKey

func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account

NewAccountFromPrivateKey creates a wallet from the given PrivateKey.

func (*Account) Decrypt

func (a *Account) Decrypt(passphrase string, scrypt keys.ScryptParams) error

Decrypt decrypts the EncryptedWIF with the given passphrase returning error if anything goes wrong.

func (*Account) Encrypt

func (a *Account) Encrypt(passphrase string, scrypt keys.ScryptParams) error

Encrypt encrypts the wallet's PrivateKey with the given passphrase under the NEP-2 standard.

func (*Account) IsMultiSig

func (a *Account) IsMultiSig() bool

func (*Account) PrivateKey

func (a *Account) PrivateKey() *keys.PrivateKey

PrivateKey returns private key corresponding to the account.

func (*Account) SignTx

func (a *Account) SignTx(chainId uint64, t *transaction.Transaction) error

SignTx signs transaction t and updates it's Witnesses.

type Extra

type Extra struct {
	// Tokens is a list of imported token contracts.
	Tokens []*Token
}

Extra stores imported token contracts.

type Token

type Token struct {
	Name     string         `json:"name"`
	Hash     common.Address `json:"script_hash"`
	Decimals int64          `json:"decimals"`
	Symbol   string         `json:"symbol"`
	Standard string         `json:"standard"`
}

Token represents imported token contract.

func NewToken

func NewToken(tokenHash common.Address, name, symbol string, decimals int64, standardName string) *Token

NewToken returns new token contract info.

type Wallet

type Wallet struct {
	// Version of the wallet, used for later upgrades.
	Version string `json:"version"`

	// A list of accounts which describes the details of each account
	// in the wallet.
	Accounts []*Account `json:"accounts"`

	Scrypt keys.ScryptParams `json:"scrypt"`

	// Extra metadata can be used for storing arbitrary data.
	// This field can be empty.
	Extra Extra `json:"extra"`
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet(location string) (*Wallet, error)

func NewWalletFromFile

func NewWalletFromFile(path string) (*Wallet, error)

NewWalletFromFile creates a Wallet from the given wallet file path.

func (*Wallet) AddAccount

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

AddAccount adds an existing Account to the wallet.

func (*Wallet) AddToken

func (w *Wallet) AddToken(tok *Token)

AddToken adds new token to a wallet.

func (*Wallet) Close

func (w *Wallet) Close()

Close closes the internal rw if its an io.ReadCloser.

func (*Wallet) CreateAccount

func (w *Wallet) CreateAccount(name, passphrase string) error

CreateAccount generates a new account for the end user and encrypts the private key with the given passphrase.

func (*Wallet) GetAccount

func (w *Wallet) GetAccount(addr common.Address) *Account

GetAccount returns account corresponding to the provided scripthash.

func (*Wallet) GetChangeAddress

func (w *Wallet) GetChangeAddress() common.Address

GetChangeAddress returns the default address to send transaction's change to.

func (*Wallet) JSON

func (w *Wallet) JSON() ([]byte, error)

JSON outputs a pretty JSON representation of the wallet.

func (*Wallet) Path

func (w *Wallet) Path() string

Path returns the location of the wallet on the filesystem.

func (*Wallet) RemoveAccount

func (w *Wallet) RemoveAccount(addr string) error

RemoveAccount removes an Account with the specified addr from the wallet.

func (*Wallet) RemoveToken

func (w *Wallet) RemoveToken(h common.Address) error

RemoveToken removes token with the specified hash from the wallet.

func (*Wallet) Save

func (w *Wallet) Save() error

Save saves the wallet data. It's the internal io.ReadWriter that is responsible for saving the data. This can be a buffer, file, etc..

Jump to

Keyboard shortcuts

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