wallet

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: BSD-2-Clause, BSD-3-Clause, ISC, + 2 more Imports: 21 Imported by: 2

Documentation

Overview

.

WalletDB

The wallet consists of three 3 main structures that are interacted with: Wallet : From 'factom' library, this contains all the funcationality related with transactions. GuiWallet : Contains all the addresses associated with the addresses in the Wallet. TransactionDB : Contains all transactions from factom. Has helpful functions to find transactions.

Index

Constants

View Source
const (
	MAP int = iota
	LDB
	BOLT
	ENCRYPTED
)

List of int to db type

Variables

View Source
var (
	GUI_DB    = MAP
	WALLET_DB = MAP
	TX_DB     = MAP
)

Default settings

View Source
var PROCESSING_RELATED_TRANSACTIONS = false
View Source
var RTLock sync.RWMutex

The user's need feedback on the sync. The function prints out the best information, but to display to front end, we need a simple 1 percent number

Stage 0: Setup
Stage 1: Gathering Transactions
Stage 2: Checking New Addresses
Stage 3: Sorting
View Source
var RTStage int = 0
View Source
var (
	STEPS_TO_PRINT int = 10000 // How many steps needed to alert user of progress
)

This has to do with launching via CLI. How often to show progress in syncing

View Source
var (
	WalletBoltV1Path = "/.factom/factoid_wallet_bolt.db"
)

Functions

func ECAddressToHumanReadable

func ECAddressToHumanReadable(add interfaces.IAddress) string

func FactoidAddressToHumanReadable

func FactoidAddressToHumanReadable(add interfaces.IAddress) string

func GetHomeDir

func GetHomeDir() string

func StringAmountsToUin64Amounts

func StringAmountsToUin64Amounts(addresses []string, amounts []string) ([]uint64, error)

StringAmountsToUin64Amounts assumes amounts to be a float for a factoid and a uint64 for an entry credit Will multiply by 1e8 for factoids so "1" is 1 factoid. Not 1 factoshi. This is because this call usally comes from input from the user

Types

type AddressBalancePair

type AddressBalancePair struct {
	Address string
	Balance uint64
}

type AddressBalancePairs

type AddressBalancePairs []AddressBalancePair

func (AddressBalancePairs) Index

func (AddressBalancePairs) Len

func (slice AddressBalancePairs) Len() int

func (AddressBalancePairs) Less

func (slice AddressBalancePairs) Less(i int, j int) bool

func (AddressBalancePairs) Swap

func (slice AddressBalancePairs) Swap(i int, j int)

type BalanceCache added in v0.3.1

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

BalanceCache holds temporary data as a buffer

ttl - the duration a value should be cached

func NewBalanceCache added in v0.3.1

func NewBalanceCache() *BalanceCache

NewBalanceCache create a new default cache with a ttl of 60 seconds

func (*BalanceCache) Clear added in v0.3.1

func (c *BalanceCache) Clear()

Clear removes all data from the cache

func (*BalanceCache) Get added in v0.3.1

func (c *BalanceCache) Get(key string) (uint64, bool)

Get retrieve a value for the given key, returns false in second param if key not found or expired

func (*BalanceCache) Set added in v0.3.1

func (c *BalanceCache) Set(key string, val uint64)

Set store a value for the given key

type DisplayTransaction

type DisplayTransaction struct {
	Inputs     []TransactionAddressInfo
	TotalInput uint64

	Outputs        []TransactionAddressInfo
	TotalFCTOutput uint64
	TotalECOutput  uint64

	TxID      string
	Height    uint32
	Action    [3]bool // Sent, received, converted
	Date      string
	Time      string
	ExactTime time.Time
}

DisplayTransaction is a struct to send transactions to the front end Names are "" if not in wallet in TransactionAddressInfo

func (*DisplayTransaction) IsSameAs

func (*DisplayTransaction) IsSimilarTo

func (a *DisplayTransaction) IsSimilarTo(b DisplayTransaction) bool

IsSimilarTo does not count actions when checking

type DisplayTransactions

type DisplayTransactions []DisplayTransaction

DisplayTransactions is used for sorting

func (DisplayTransactions) IsSameAs

func (slice DisplayTransactions) IsSameAs(comp DisplayTransactions) bool

func (DisplayTransactions) IsSimilarTo

func (slice DisplayTransactions) IsSimilarTo(comp DisplayTransactions) bool

func (DisplayTransactions) Len

func (slice DisplayTransactions) Len() int

func (DisplayTransactions) Less

func (slice DisplayTransactions) Less(i, j int) bool

func (DisplayTransactions) Swap

func (slice DisplayTransactions) Swap(i, j int)

type ReturnTransStruct

type ReturnTransStruct struct {
	Total uint64 `json:"Total"`
	Fee   uint64 `json:"Fee"`
}

type SendTransactionResp

type SendTransactionResp struct {
	Message string `json:"message"`
	Txid    string `json:"txid"`
}

type TransactionAddressInfo

type TransactionAddressInfo struct {
	Name    string
	Address string
	Amount  uint64
	Type    string // FCT or EC
}

TransactionAddressInfo

func NewTransactionAddressInfo

func NewTransactionAddressInfo(name string, address string, amount uint64, tokenType string) *TransactionAddressInfo

func (*TransactionAddressInfo) IsSameAs

func (*TransactionAddressInfo) IsSimilarTo

type UpdateANP added in v0.3.1

type UpdateANP struct {
	Address string
	Name    string
}

type WalletDB

type WalletDB struct {
	GUIlDB interfaces.IDatabase //database.IDatabase        // GUI DB

	Wallet        *wallet.Wallet            // Wallet from factom/wallet
	TransactionDB *wallet.TXDatabaseOverlay // Used to display transactions

	ActiveCachedTransactions []DisplayTransaction // Active cache being used.

	BalanceCache *BalanceCache
	// contains filtered or unexported fields
}

WalletDB interacting with LDB and factom/wallet

The LDB doesn't need to be updated often, so we save after every add and only
deal with cached version

func LoadWalletDB

func LoadWalletDB(v1Import bool, password string) (*WalletDB, error)

LoadWalletDB is the same as New

func NewWalletDB

func NewWalletDB(v1Import bool, password string) (*WalletDB, error)

func StartWallet

func StartWallet(factomdLocation string, walletDBType int, guiDBType int, txDBType int, v1Import bool, password string) (*WalletDB, error)

StartWallet : Must give the port for the factomd instance

func (*WalletDB) AddAddress

func (w *WalletDB) AddAddress(name string, secret string) (*address.AddressNamePair, error)

func (*WalletDB) AddBalancesToAddresses

func (w *WalletDB) AddBalancesToAddresses()

func (*WalletDB) AddExternalAddress

func (w *WalletDB) AddExternalAddress(name string, public string) (*address.AddressNamePair, error)

func (*WalletDB) CalculateNeededInput

func (wal *WalletDB) CalculateNeededInput(toAddresses []string, toAmounts []string) (uint64, error)

CalculateNeededInput calculates how many factoids are needed to cover the outputs. Takes into consideration the EC rate if EC is output

func (*WalletDB) ChangeAddressName

func (w *WalletDB) ChangeAddressName(address string, toName string) error

func (*WalletDB) CheckTransactionAndGetName

func (wal *WalletDB) CheckTransactionAndGetName(toAddresses []string, amounts []string, feeAddress string) (string, error)

CheckTransactionAndGetName doublechecks the transaction is the same (with amounts and addresses) This is to confirm an already constructed transaction

func (*WalletDB) Close

func (w *WalletDB) Close() error

func (*WalletDB) ConstructConvertEntryCreditsStrings

func (wal *WalletDB) ConstructConvertEntryCreditsStrings(toAddresses []string, amounts []string) (string, *ReturnTransStruct, error)

func (*WalletDB) ConstructSendFactoidsStrings

func (wal *WalletDB) ConstructSendFactoidsStrings(toAddresses []string, amounts []string) (string, *ReturnTransStruct, error)

func (*WalletDB) ConstructTransaction

func (wal *WalletDB) ConstructTransaction(toAddresses []string, amounts []uint64) (string, *ReturnTransStruct, error)

func (*WalletDB) ConstructTransactionFromValues

func (wal *WalletDB) ConstructTransactionFromValues(toAddresses []string, toAmounts []uint64, fromAddresses []string, fromAmounts []uint64, feeAddress string, sign bool) (string, *ReturnTransStruct, error)

ConstructTransactionFromValues constructs a transaction from given input and output values. An error might contain the amount of input needed aswell if it is incorrect

func (*WalletDB) ConstructTransactionFromValuesStrings

func (wal *WalletDB) ConstructTransactionFromValuesStrings(toAddresses []string, toAmounts []string, fromAddresses []string, fromAmounts []string, feeAddress string, sign bool) (string, *ReturnTransStruct, error)

ConstructTransactionFromValuesStrings constructs a transaction if all inputs are already given Amounts are parsed into a float or uint64 depending on factoid/ec

func (*WalletDB) DeleteTransaction

func (wal *WalletDB) DeleteTransaction(trans string) error

func (*WalletDB) ECAddressToHumanReadable

func (wal *WalletDB) ECAddressToHumanReadable(add interfaces.IAddress) string

func (*WalletDB) ExportSeed

func (w *WalletDB) ExportSeed() (string, error)

func (*WalletDB) ExportTransaction

func (wal *WalletDB) ExportTransaction(name string) (string, error)

func (*WalletDB) FactoidAddressToHumanReadable

func (wal *WalletDB) FactoidAddressToHumanReadable(add interfaces.IAddress) string

func (*WalletDB) FactomdOnline

func (w *WalletDB) FactomdOnline() (bool, string)

func (*WalletDB) GenerateEntryCreditAddress

func (w *WalletDB) GenerateEntryCreditAddress(name string) (*address.AddressNamePair, error)

func (*WalletDB) GenerateFactoidAddress

func (w *WalletDB) GenerateFactoidAddress(name string) (*address.AddressNamePair, error)

func (*WalletDB) GetAddressBalance

func (wal *WalletDB) GetAddressBalance(address string) (uint64, error)

GetAddressBalance Return balance for an address Checks the balance cache first, if nothing is found it sends a request to factomd

func (*WalletDB) GetAllGUIAddresses

func (w *WalletDB) GetAllGUIAddresses() []address.AddressNamePair

func (*WalletDB) GetAllMyGUIAddresses

func (w *WalletDB) GetAllMyGUIAddresses() []address.AddressNamePair

func (*WalletDB) GetECBalance

func (w *WalletDB) GetECBalance() int64

func (*WalletDB) GetFactoidBalance

func (w *WalletDB) GetFactoidBalance() int64

func (*WalletDB) GetGUIAddress

func (w *WalletDB) GetGUIAddress(address string) (anp *address.AddressNamePair, list int)

GetGUIAddress returns address with associated name List is 0 for not found, 1 for Factoid address, 2 for EC Address, 3 for External

func (*WalletDB) GetGUIWalletJSON

func (w *WalletDB) GetGUIWalletJSON(getBals bool) ([]byte, error)

func (*WalletDB) GetPrivateKey

func (w *WalletDB) GetPrivateKey(address string) (secret string, err error)

func (*WalletDB) GetRate added in v0.3.1

func (wal *WalletDB) GetRate() (uint64, error)

GetRate Return current EC rate, Cached for 60 seconds

func (*WalletDB) GetRelatedTransactions

func (w *WalletDB) GetRelatedTransactions() (dt []DisplayTransaction, err error)

GetRelatedTransactions This function grabs all transactions related to any address in the address book and sorts them by time.Time. If a new address is added, this will grab all transactions from that new address and insert them.

func (*WalletDB) GetRelatedTransactionsNoCaching

func (w *WalletDB) GetRelatedTransactionsNoCaching() ([]DisplayTransaction, error)

GetRelatedTransactionsNoCaching is the no cache solution, not going to use it. It is too slow, but was used in early phases and kept for testing comparisons as this should be all inclusive and correct

func (*WalletDB) GetStage

func (w *WalletDB) GetStage() int

func (*WalletDB) GetTotalGUIAddresses

func (w *WalletDB) GetTotalGUIAddresses() uint64

func (*WalletDB) ImportKoinify

func (w *WalletDB) ImportKoinify(name string, koinify string) (*address.AddressNamePair, error)

func (*WalletDB) ImportSeed

func (w *WalletDB) ImportSeed(seed string) error

func (*WalletDB) ImportTransaction

func (wal *WalletDB) ImportTransaction(name string, hex string) error

func (*WalletDB) IsValidAddress

func (w *WalletDB) IsValidAddress(address string) bool

func (*WalletDB) NewDisplayTransaction

func (w *WalletDB) NewDisplayTransaction(t interfaces.ITransaction) (*DisplayTransaction, error)

NewDisplayTransaction is used because we don't keep the original interface of a transaction, but build our own

func (*WalletDB) RemoveAddress

func (w *WalletDB) RemoveAddress(address string, list int) (*address.AddressNamePair, error)

func (*WalletDB) RemoveAddressFromAnyList

func (w *WalletDB) RemoveAddressFromAnyList(address string) (*address.AddressNamePair, error)

func (*WalletDB) Save

func (w *WalletDB) Save() error

func (*WalletDB) ScrubDisplayTransactionsForNameChanges

func (w *WalletDB) ScrubDisplayTransactionsForNameChanges(list []DisplayTransaction) []DisplayTransaction

ScrubDisplayTransactionsForNameChanges scrubs all transactions before serving to front end. Changes the names to the current names of the addresses, as user can change the name of their addresses.

func (*WalletDB) SendTransaction

func (wal *WalletDB) SendTransaction(trans string) (string, error)

func (*WalletDB) SetStage

func (w *WalletDB) SetStage(stage int)

func (*WalletDB) UpdateGUIDB

func (w *WalletDB) UpdateGUIDB() error

UpdateGUIDB grabs the list of addresses from the walletDB and updates our GUI with any that are missing. All will be external

type WalletStruct

type WalletStruct struct {
	FactoidAddresses     *address.AddressList
	EntryCreditAddresses *address.AddressList
	ExternalAddresses    *address.AddressList

	// Not marshaled into database
	FactoidTotal int64
	ECTotal      int64

	sync.RWMutex
}

WalletStruct used outside DB

func NewWallet

func NewWallet() *WalletStruct

func (*WalletStruct) AddAddress

func (w *WalletStruct) AddAddress(name string, address string, list int) (*address.AddressNamePair, error)

func (*WalletStruct) AddBalancesToAddresses

func (w *WalletStruct) AddBalancesToAddresses()

AddBalancesToAddresses adds balances to addresses so the GUI can display

func (*WalletStruct) AddSeededAddress

func (w *WalletStruct) AddSeededAddress(name string, address string, list int) (*address.AddressNamePair, error)

func (*WalletStruct) ChangeAddressName

func (w *WalletStruct) ChangeAddressName(address string, toName string) error

func (*WalletStruct) GetAddress

func (w *WalletStruct) GetAddress(address string) (anp *address.AddressNamePair, list int, index int)

GetAddress :

Returns:
	list:	-1 for not found,
		 	1 for FactoidAddressList,
			2 for EntryCreditList,
			3 for External

func (*WalletStruct) GetAllAddresses

func (w *WalletStruct) GetAllAddresses() []address.AddressNamePair

func (*WalletStruct) GetAllAddressesFromList

func (w *WalletStruct) GetAllAddressesFromList(list int) []address.AddressNamePair

func (*WalletStruct) GetAllMyGUIAddresses

func (w *WalletStruct) GetAllMyGUIAddresses() []address.AddressNamePair

func (*WalletStruct) GetTotalAddressCount

func (w *WalletStruct) GetTotalAddressCount() uint64

func (*WalletStruct) IsSameAs

func (w *WalletStruct) IsSameAs(b *WalletStruct) bool

func (*WalletStruct) MarshalBinary

func (w *WalletStruct) MarshalBinary() ([]byte, error)

func (*WalletStruct) RemoveAddress

func (w *WalletStruct) RemoveAddress(address string, list int) (string, error)

func (*WalletStruct) RemoveAddressFromAnyList

func (w *WalletStruct) RemoveAddressFromAnyList(address string) (*address.AddressNamePair, error)

func (*WalletStruct) ResetSeeded

func (w *WalletStruct) ResetSeeded()

Simply remove all seeded flags

func (*WalletStruct) UnmarshalBinary

func (w *WalletStruct) UnmarshalBinary(data []byte) error

func (*WalletStruct) UnmarshalBinaryData

func (w *WalletStruct) UnmarshalBinaryData(data []byte) (newData []byte, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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