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
- Variables
- func ECAddressToHumanReadable(add interfaces.IAddress) string
- func FactoidAddressToHumanReadable(add interfaces.IAddress) string
- func GetHomeDir() string
- func StringAmountsToUin64Amounts(addresses []string, amounts []string) ([]uint64, error)
- type AddressBalancePair
- type AddressBalancePairs
- type BalanceCache
- type DisplayTransaction
- type DisplayTransactions
- type ReturnTransStruct
- type SendTransactionResp
- type TransactionAddressInfo
- type UpdateANP
- type WalletDB
- func (w *WalletDB) AddAddress(name string, secret string) (*address.AddressNamePair, error)
- func (w *WalletDB) AddBalancesToAddresses()
- func (w *WalletDB) AddExternalAddress(name string, public string) (*address.AddressNamePair, error)
- func (wal *WalletDB) CalculateNeededInput(toAddresses []string, toAmounts []string) (uint64, error)
- func (w *WalletDB) ChangeAddressName(address string, toName string) error
- func (wal *WalletDB) CheckTransactionAndGetName(toAddresses []string, amounts []string, feeAddress string) (string, error)
- func (w *WalletDB) Close() error
- func (wal *WalletDB) ConstructConvertEntryCreditsStrings(toAddresses []string, amounts []string) (string, *ReturnTransStruct, error)
- func (wal *WalletDB) ConstructSendFactoidsStrings(toAddresses []string, amounts []string) (string, *ReturnTransStruct, error)
- func (wal *WalletDB) ConstructTransaction(toAddresses []string, amounts []uint64) (string, *ReturnTransStruct, error)
- func (wal *WalletDB) ConstructTransactionFromValues(toAddresses []string, toAmounts []uint64, fromAddresses []string, ...) (string, *ReturnTransStruct, error)
- func (wal *WalletDB) ConstructTransactionFromValuesStrings(toAddresses []string, toAmounts []string, fromAddresses []string, ...) (string, *ReturnTransStruct, error)
- func (wal *WalletDB) DeleteTransaction(trans string) error
- func (wal *WalletDB) ECAddressToHumanReadable(add interfaces.IAddress) string
- func (w *WalletDB) ExportSeed() (string, error)
- func (wal *WalletDB) ExportTransaction(name string) (string, error)
- func (wal *WalletDB) FactoidAddressToHumanReadable(add interfaces.IAddress) string
- func (w *WalletDB) FactomdOnline() (bool, string)
- func (w *WalletDB) GenerateEntryCreditAddress(name string) (*address.AddressNamePair, error)
- func (w *WalletDB) GenerateFactoidAddress(name string) (*address.AddressNamePair, error)
- func (wal *WalletDB) GetAddressBalance(address string) (uint64, error)
- func (w *WalletDB) GetAllGUIAddresses() []address.AddressNamePair
- func (w *WalletDB) GetAllMyGUIAddresses() []address.AddressNamePair
- func (w *WalletDB) GetECBalance() int64
- func (w *WalletDB) GetFactoidBalance() int64
- func (w *WalletDB) GetGUIAddress(address string) (anp *address.AddressNamePair, list int)
- func (w *WalletDB) GetGUIWalletJSON(getBals bool) ([]byte, error)
- func (w *WalletDB) GetPrivateKey(address string) (secret string, err error)
- func (wal *WalletDB) GetRate() (uint64, error)
- func (w *WalletDB) GetRelatedTransactions() (dt []DisplayTransaction, err error)
- func (w *WalletDB) GetRelatedTransactionsNoCaching() ([]DisplayTransaction, error)
- func (w *WalletDB) GetStage() int
- func (w *WalletDB) GetTotalGUIAddresses() uint64
- func (w *WalletDB) ImportKoinify(name string, koinify string) (*address.AddressNamePair, error)
- func (w *WalletDB) ImportSeed(seed string) error
- func (wal *WalletDB) ImportTransaction(name string, hex string) error
- func (w *WalletDB) IsValidAddress(address string) bool
- func (w *WalletDB) NewDisplayTransaction(t interfaces.ITransaction) (*DisplayTransaction, error)
- func (w *WalletDB) RemoveAddress(address string, list int) (*address.AddressNamePair, error)
- func (w *WalletDB) RemoveAddressFromAnyList(address string) (*address.AddressNamePair, error)
- func (w *WalletDB) Save() error
- func (w *WalletDB) ScrubDisplayTransactionsForNameChanges(list []DisplayTransaction) []DisplayTransaction
- func (wal *WalletDB) SendTransaction(trans string) (string, error)
- func (w *WalletDB) SetStage(stage int)
- func (w *WalletDB) UpdateGUIDB() error
- type WalletStruct
- func (w *WalletStruct) AddAddress(name string, address string, list int) (*address.AddressNamePair, error)
- func (w *WalletStruct) AddBalancesToAddresses()
- func (w *WalletStruct) AddSeededAddress(name string, address string, list int) (*address.AddressNamePair, error)
- func (w *WalletStruct) ChangeAddressName(address string, toName string) error
- func (w *WalletStruct) GetAddress(address string) (anp *address.AddressNamePair, list int, index int)
- func (w *WalletStruct) GetAllAddresses() []address.AddressNamePair
- func (w *WalletStruct) GetAllAddressesFromList(list int) []address.AddressNamePair
- func (w *WalletStruct) GetAllMyGUIAddresses() []address.AddressNamePair
- func (w *WalletStruct) GetTotalAddressCount() uint64
- func (w *WalletStruct) IsSameAs(b *WalletStruct) bool
- func (w *WalletStruct) MarshalBinary() ([]byte, error)
- func (w *WalletStruct) RemoveAddress(address string, list int) (string, error)
- func (w *WalletStruct) RemoveAddressFromAnyList(address string) (*address.AddressNamePair, error)
- func (w *WalletStruct) ResetSeeded()
- func (w *WalletStruct) UnmarshalBinary(data []byte) error
- func (w *WalletStruct) UnmarshalBinaryData(data []byte) (newData []byte, err error)
Constants ¶
const ( MAP int = iota LDB BOLT ENCRYPTED )
List of int to db type
Variables ¶
var ( GUI_DB = MAP WALLET_DB = MAP TX_DB = MAP )
Default settings
var PROCESSING_RELATED_TRANSACTIONS = false
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
var RTStage int = 0
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
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 ¶
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 AddressBalancePairs ¶
type AddressBalancePairs []AddressBalancePair
func (AddressBalancePairs) Index ¶
func (slice AddressBalancePairs) Index(i int) AddressBalancePair
func (AddressBalancePairs) Len ¶
func (slice AddressBalancePairs) Len() int
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 (a *DisplayTransaction) IsSameAs(b DisplayTransaction) bool
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 SendTransactionResp ¶
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 (a *TransactionAddressInfo) IsSameAs(b TransactionAddressInfo) bool
func (*TransactionAddressInfo) IsSimilarTo ¶
func (a *TransactionAddressInfo) IsSimilarTo(b TransactionAddressInfo) bool
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 ¶
LoadWalletDB is the same as New
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 (*WalletDB) AddBalancesToAddresses ¶
func (w *WalletDB) AddBalancesToAddresses()
func (*WalletDB) AddExternalAddress ¶
func (*WalletDB) CalculateNeededInput ¶
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 (*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) ConstructConvertEntryCreditsStrings ¶
func (*WalletDB) ConstructSendFactoidsStrings ¶
func (*WalletDB) ConstructTransaction ¶
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 (*WalletDB) ECAddressToHumanReadable ¶
func (wal *WalletDB) ECAddressToHumanReadable(add interfaces.IAddress) string
func (*WalletDB) ExportSeed ¶
func (*WalletDB) ExportTransaction ¶
func (*WalletDB) FactoidAddressToHumanReadable ¶
func (wal *WalletDB) FactoidAddressToHumanReadable(add interfaces.IAddress) string
func (*WalletDB) FactomdOnline ¶
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 ¶
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 (*WalletDB) GetFactoidBalance ¶
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 (*WalletDB) GetPrivateKey ¶
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) GetTotalGUIAddresses ¶
func (*WalletDB) ImportKoinify ¶
func (*WalletDB) ImportSeed ¶
func (*WalletDB) ImportTransaction ¶
func (*WalletDB) IsValidAddress ¶
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 (*WalletDB) RemoveAddressFromAnyList ¶
func (w *WalletDB) RemoveAddressFromAnyList(address string) (*address.AddressNamePair, 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 (*WalletDB) UpdateGUIDB ¶
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)