wallet

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 9 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	// NEO  KeyPair.
	KeyPair *keys.KeyPair `json:"-"`

	// NEO public address.
	Address string `json:"address"`

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

	// Indicates whether the account is the default change account.
	Default bool `json:"isDefault"`

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

	// Encrypted Key of the account also known as the key.
	Nep2Key string `json:"key"`

	// contract is a Contract object which describes the details of the contract.
	// This field can be null (for watch-only address).
	Contract *Contract `json:"contract"`

	// This field can be empty.
	Extra interface{} `json:"extra"`
}

Account represents a NEO account. It holds the private and public key along with some metadata.

func NewAccount

func NewAccount() (*Account, error)

NewAccount creates a new Account with a random generated PrivateKey.

func NewAccountFromKeyPair

func NewAccountFromKeyPair(p *keys.KeyPair) *Account

NewAccountFromKeyPair created a wallet from the given PrivateKey.

func NewAccountFromNEP2

func NewAccountFromNEP2(nep2Key, passphrase string) (*Account, error)

NewAccountFromNep2 decrypts the nep2Key with the given passphrase and returns the decrypted Account.

func NewAccountFromWIF

func NewAccountFromWIF(wif string) (*Account, error)

NewAccountFromWIF creates a new Account from the given WIF.

func (*Account) Decrypt

func (a *Account) Decrypt(passphrase string) (err error)

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

func (*Account) Encrypt

func (a *Account) Encrypt(passphrase string) (err error)

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

type Contract

type Contract struct {
	// Script hash of the contract deployed on the block chain.
	Script string `json:"script"`

	// A list of parameters used deploying this contract.
	Parameters []interface{} `json:"parameters"`

	// Indicates whether the contract has been deployed to the block chain.
	Deployed bool `json:"deployed"`
}

Contract represents a subset of the smart contract to embed in the Account so it's NEP-6 compliant.

type ScryptParams

type ScryptParams struct {
	N int `json:"n"`
	R int `json:"r"`
	P int `json:"p"`
}

ScryptParams is a json-serializable container for scrypt KDF parameters.

type Wallet

type Wallet struct {
	// string type
	Name string `json:"name"`

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

	Scrypt *ScryptParams `json:"scrypt"`

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

	// Extra metadata can be used for storing arbitrary data.
	// This field can be empty.
	Extra interface{} `json:"extra"`
}

Wallet represents a NEO (NEP-2, NEP-6) compliant wallet.

func NewWallet

func NewWallet() *Wallet

NewWallet creates a NEO wallet.

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 if the account is not in wallet

func (*Wallet) AddNewAccount

func (w *Wallet) AddNewAccount() error

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

func (*Wallet) DecryptAll

func (w *Wallet) DecryptAll(password string) error

decrypt all the accounts in wallet, save the nep2Key

func (*Wallet) EncryptAll

func (w *Wallet) EncryptAll(password string) error

encrypt all the accounts in wallet, save the nep2Key

func (*Wallet) ImportFromNEP2Key

func (w *Wallet) ImportFromNEP2Key(nep2Key, passphare string) error

Import account from Nep2Key

func (*Wallet) ImportFromWIF

func (w *Wallet) ImportFromWIF(wif string) error

Import account from WIF

func (*Wallet) JSON

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

JSON outputs a pretty JSON representation of the wallet.

func (*Wallet) Save

func (w *Wallet) Save(path string) 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..

type WalletHelper

type WalletHelper struct {
	TxBuilder *tx.TransactionBuilder
	Account   *Account
}

func NewWalletHelper

func NewWalletHelper(txBuilder *tx.TransactionBuilder, account *Account) *WalletHelper

func (*WalletHelper) ClaimGas

func (w *WalletHelper) ClaimGas(from string) (string, error)

ClaimGas, return txid

func (*WalletHelper) DeployContract

func (w *WalletHelper) DeployContract(script []byte,
	paramTypes string, returnTypeHexString string,
	hasStorage bool, hasDynamicInvoke bool, isPayable bool,
	contractName string, contractVersion string, contractAuthor string, contractEmail string, contractDescription string) (*helper.UInt160, error)

func (*WalletHelper) GetBalance

func (w *WalletHelper) GetBalance(address string) (neoBalance int, gasBalance float64, err error)

GetBalance is used to get neo and gas balance of an address

func (*WalletHelper) InvokeContract

func (w *WalletHelper) InvokeContract(scriptHash helper.UInt160, method string, args []sc.ContractParameter) (*helper.UInt256, error)

func (*WalletHelper) Transfer

func (w *WalletHelper) Transfer(assetId helper.UInt256, from string, to string, amount float64) (string, error)

Transfer is used to transfer neo or gas or other utxo asset, single signature, return txid

func (*WalletHelper) TransferNep5

func (w *WalletHelper) TransferNep5(assetId helper.UInt160, from string, to string, amount float64) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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