server

package
v0.0.0-...-4392a84 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2019 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockServer

func MockServer() (*httptest.Server, func())

Types

type APIMux

type APIMux struct {
	*chi.Mux
	// contains filtered or unexported fields
}

APIMux --

func NewAPIRouter

func NewAPIRouter(log *xlog.Log, conf *Config) APIMux

NewAPIRouter -- create new apiMux.

func (*APIMux) Close

func (a *APIMux) Close()

Close -- used to close the mux.

func (*APIMux) Init

func (a *APIMux) Init() error

Init -- used init the mux.

type Address

type Address struct {
	Pos      uint32    `json:"pos"`
	Address  string    `json:"address"`
	Balance  Balance   `json:"balance"`
	Txs      []Tx      `json:"txs"`
	Unspents []Unspent `json:"unspents"`
	// contains filtered or unexported fields
}

Address --

type AddressPos

type AddressPos struct {
	Pos     uint32 `json:"pos"`
	Address string `json:"address"`
}

AddressPos --

type Backup

type Backup struct {
	Time             int64  `json:"time"`
	Email            string `json:"email"`
	DeviceID         string `json:"deviceid"`
	CloudService     string `json:"cloud_service"`
	EncryptedPrvKey  string `json:"encrypted_prvkey"`
	EncryptionPubKey string `json:"encryption_pubkey"`
}

type Balance

type Balance struct {
	TotalBalance       uint64 `json:"total_balance"`
	UnconfirmedBalance uint64 `json:"unconfirmed_balance"`
}

Balance --

type BlockstreamChain

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

BlockstreamChain --

func (*BlockstreamChain) GetFees

func (c *BlockstreamChain) GetFees() (map[string]float32, error)

GetFees -- used to get the fees from the chain mempool.

func (*BlockstreamChain) GetTickers

func (c *BlockstreamChain) GetTickers() (map[string]Ticker, error)
func (c *BlockstreamChain) GetTxLink() string

GetTxLink -- get the tx web link.

func (*BlockstreamChain) GetTxs

func (c *BlockstreamChain) GetTxs(address string) ([]Tx, error)

GetTxs -- used to get transactions by address.

func (*BlockstreamChain) GetUTXO

func (c *BlockstreamChain) GetUTXO(address string) ([]Unspent, error)

GetUTXO -- used to get all the unspents of this address.

func (*BlockstreamChain) PushTx

func (c *BlockstreamChain) PushTx(hex string) (string, error)

PushTx -- used to push tx to the chain.

type BlockstreamTx

type BlockstreamTx struct {
	Txid     string `json:"txid"`
	Version  int64  `json:"version"`
	Locktime int64  `json:"locktime"`
	Vin      []struct {
		Txid    string `json:"txid"`
		Vout    int    `json:"vout"`
		Prevout struct {
			Scriptpubkey        string `json:"scriptpubkey"`
			ScriptpubkeyAsm     string `json:"scriptpubkey_asm"`
			ScriptpubkeyAddress string `json:"scriptpubkey_address"`
			ScriptpubkeyType    string `json:"scriptpubkey_type"`
			Value               int64  `json:"value"`
		} `json:"prevout"`
		Scriptsig    string   `json:"scriptsig"`
		ScriptsigAsm string   `json:"scriptsig_asm"`
		Witness      []string `json:"witness"`
		IsCoinbase   bool     `json:"is_coinbase"`
		Sequence     int64    `json:"sequence"`
	} `json:"vin"`
	Vout []struct {
		Scriptpubkey        string `json:"scriptpubkey"`
		ScriptpubkeyAsm     string `json:"scriptpubkey_asm"`
		ScriptpubkeyAddress string `json:"scriptpubkey_address"`
		ScriptpubkeyType    string `json:"scriptpubkey_type"`
		Value               int64  `json:"value"`
	} `json:"vout"`
	Size   int   `json:"size"`
	Weight int   `json:"weight"`
	Fee    int64 `json:"fee"`
	Status struct {
		Confirmed   bool   `json:"confirmed"`
		BlockHeight int64  `json:"block_height"`
		BlockHash   string `json:"block_hash"`
		BlockTime   int64  `json:"block_time"`
	} `json:"status"`
}

BlockstreamTx --

type BlockstreamUTXO

type BlockstreamUTXO struct {
	Txid   string `json:"txid"`
	Vout   uint32 `json:"vout"`
	Status struct {
		Confirmed   bool   `json:"confirmed"`
		BlockHeight uint32 `json:"block_height"`
		BlockHash   string `json:"block_hash"`
		BlockTime   uint32 `json:"block_time"`
	} `json:"status"`
	Value uint64 `json:"value"`
}

BlockstreamUTXO --

type Chain

type Chain interface {
	GetTxs(address string) ([]Tx, error)
	GetFees() (map[string]float32, error)
	GetUTXO(address string) ([]Unspent, error)
	GetTickers() (map[string]Ticker, error)
	GetTxLink() string
	PushTx(hex string) (string, error)
}

Chain --

func NewBlockstreamChain

func NewBlockstreamChain(log *xlog.Log, conf *Config) Chain

NewBlockstreamChain -- creates new BlockstreamChain.

func NewChainProxy

func NewChainProxy(log *xlog.Log, conf *Config) Chain

NewChainProxy -- creates new Chain, default provider is blockstream.info.

type Config

type Config struct {
	DataDir              string      `json:"datadir"`
	ChainNet             string      `json:"chainnet"`
	Endpoint             string      `json:"endpoint"`
	TokenSecret          string      `json:"token_secret"`
	SpvProvider          string      `json:"spv_provider"`
	EnableVCode          bool        `json:"enable_vcode"`
	ForceRecover         bool        `json:"force_recover"`
	VCodeExpired         int         `json:"vcode_expired"`
	WalletSyncIntervalMs int         `json:"wallet_sync_interval_ms"`
	Smtp                 *SmtpConfig `json:"smtp"`
}

Config --

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig -- returns default server config.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig -- used to load the config from file.

func MockConfig

func MockConfig() *Config

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(b []byte) error

UnmarshalJSON -- built-in method for set default value when Unmarshal.

type Handler

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

Handler --

func NewHandler

func NewHandler(log *xlog.Log, conf *Config) *Handler

NewHandler -- creates new Handler.

func (*Handler) Close

func (h *Handler) Close()

Close -- used to close the handler.

func (*Handler) Init

func (h *Handler) Init() error

Init -- starts the handler.

type LoginType

type LoginType int
const (
	Unknow LoginType = iota
	Mobile
	Email
)

type SendFees

type SendFees struct {
	Fees          uint64 `json:"fees"`
	TotalValue    uint64 `json:"total_value"`
	SendableValue uint64 `json:"sendable_value"`
}

SendFees --

type Smtp

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

Smtp --

func NewSmtp

func NewSmtp(log *xlog.Log, conf *Config) *Smtp

NewSmtp -- creates new Smtp.

func (*Smtp) Backup

func (smtp *Smtp) Backup(uid string, name string) error

Backup -- used to backup the user wallet json file via smtp.

func (*Smtp) VCode

func (smtp *Smtp) VCode(uid string, name string, vcode string) error

VCode -- send vcode to email.

type SmtpConfig

type SmtpConfig struct {
	Server   string `json:"server"`
	Port     int    `json:"port"`
	UserName string `json:"username"`
	Password string `json:"password"`
	BackupTo string `json:"backup_to"`
}

SmtpConfig --

type Ticker

type Ticker struct {
	One5M  float64 `json:"15m"`
	Last   float64 `json:"last"`
	Buy    float64 `json:"buy"`
	Sell   float64 `json:"sell"`
	Symbol string  `json:"symbol"`
}

Ticker --

type Tx

type Tx struct {
	Txid        string `json:"txid"`
	Fee         int64  `json:"fee"`
	Data        string `json:"data"`
	Link        string `json:"link"`
	Value       int64  `json:"value"`
	Confirmed   bool   `json:"confirmed"`
	BlockTime   int64  `json:"block_time"`
	BlockHeight int64  `json:"block_height"`
}

Tx --

type UTXO

type UTXO struct {
	Pos          uint32 `json:"pos"`
	Txid         string `json:"txid"`
	Vout         uint32 `json:"vout"`
	Value        uint64 `json:"value"`
	Address      string `json:"address"`
	Confirmed    bool   `json:"confirmed"`
	SvrPubKey    string `json:"svrpubkey"`
	Scriptpubkey string `json:"Scriptpubkey"`
}

UTXO --

type Unspent

type Unspent struct {
	Txid         string `json:"txid"`
	Vout         uint32 `json:"vout"`
	Value        uint64 `json:"value"`
	Confirmed    bool   `json:"confirmed"`
	BlockTime    uint32 `json:"block_time"`
	BlockHeight  uint32 `json:"block_height"`
	Scriptpubkey string `json:"Scriptpubkey"`
}

Unspent --

type Vcode

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

Vcode --

func NewVcode

func NewVcode(log *xlog.Log, conf *Config) *Vcode

NewVcode -- creates new Vcode.

func (*Vcode) Add

func (vc *Vcode) Add(uid string, code string)

Add -- used to add a new <uid, code> pair to vcode pool.

func (*Vcode) Check

func (vc *Vcode) Check(uid string, code string) error

Check -- used to check the code valid or not with the vcode in the pool.

func (*Vcode) Remove

func (vc *Vcode) Remove(uid string)

Remove -- used to remove the code of the uid from the vcode pool.

type Wallet

type Wallet struct {
	UID             string              `json:"uid"`
	DID             string              `json:"did"`
	Backup          Backup              `json:"backup"`
	LastPos         uint32              `json:"lastpos"`
	Address         map[string]*Address `json:"address"`
	SvrMasterPrvKey string              `json:"svrmasterprvkey"`
	CliMasterPubKey string              `json:"climasterpubkey"`
	// contains filtered or unexported fields
}

Wallet --

func NewWallet

func NewWallet() *Wallet

NewWallet -- creates new Wallet.

func (*Wallet) AddressPoss

func (w *Wallet) AddressPoss(offset int, limit int) []AddressPos

AddressPoss -- used to return the AddressPoss from offset to offset+limit.

func (*Wallet) Addresses

func (w *Wallet) Addresses() []AddressPos

Addresses -- used to returns all the address of the wallet.

func (*Wallet) Balance

func (w *Wallet) Balance() *Balance

Balance --used to return balance of the wallet.

func (*Wallet) Lock

func (w *Wallet) Lock()

Lock -- used to lock the wallet entry for thread-safe purposes.

func (*Wallet) NewAddress

func (w *Wallet) NewAddress(typ string) (*Address, error)

NewAddress -- used to generate new address.

func (*Wallet) SendFees

func (w *Wallet) SendFees(sendValue uint64, feesPerKB int) (*SendFees, error)

SendFees -- used to get the send fees by send amount.

func (*Wallet) Txs

func (w *Wallet) Txs(offset int, limit int) []Tx

Txs -- used to return the txs starts from offset to offset+limit.

func (*Wallet) Unlock

func (w *Wallet) Unlock()

Unlock -- used to unlock the wallet entry for thread-safe purposes.

func (*Wallet) Unspents

func (w *Wallet) Unspents(sendAmount uint64) ([]UTXO, error)

Unspents -- used to return unspent which all the value upper than the amount.

func (*Wallet) UpdateTxs

func (w *Wallet) UpdateTxs(addr string, txs []Tx)

UpdateTxs -- update the tx fetchs from the chain.

func (*Wallet) UpdateUnspents

func (w *Wallet) UpdateUnspents(addr string, unspents []Unspent)

UpdateUnspents -- update the address balance/unspent which fetchs from the chain.

type WalletDB

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

WalletDB --

func NewWalletDB

func NewWalletDB(log *xlog.Log, conf *Config) *WalletDB

NewWalletDB -- creates new WalletDB.

func (*WalletDB) Addresses

func (wdb *WalletDB) Addresses(uid string, offset int, limit int) ([]AddressPos, error)

Addresses -- used to get address list.

func (*WalletDB) Balance

func (wdb *WalletDB) Balance(uid string) (*Balance, error)

Balance --used to return balance of the wallet.

func (*WalletDB) Close

func (wdb *WalletDB) Close()

Close -- used to close the db.

func (*WalletDB) CreateWallet

func (wdb *WalletDB) CreateWallet(uid string, cliMasterPubKey string) error

CreateWallet -- used to create a wallet file.

func (*WalletDB) GetBackup

func (wdb *WalletDB) GetBackup(uid string) (Backup, error)

func (*WalletDB) MasterPrvKey

func (wdb *WalletDB) MasterPrvKey(uid string) (string, error)

func (*WalletDB) NewAddress

func (wdb *WalletDB) NewAddress(uid string, typ string) (*Address, error)

NewAddress -- used to generate new address of this uid.

func (*WalletDB) Open

func (wdb *WalletDB) Open(dir string) error

Open -- used to load all the wallets who in the disk to the cache.

func (*WalletDB) SendFees

func (wdb *WalletDB) SendFees(uid string, priority string, sendAmount uint64) (*SendFees, error)

SendFees -- returns the fee info for this send.

func (*WalletDB) StoreBackup

func (wdb *WalletDB) StoreBackup(uid string, email string, did string, cloudService string, encryptedPrvKey string, encryptionPubKey string) error

func (*WalletDB) Txs

func (wdb *WalletDB) Txs(uid string, offset int, limit int) ([]Tx, error)

Txs -- used to returns tx list.

func (*WalletDB) Unspents

func (wdb *WalletDB) Unspents(uid string, amount uint64) ([]UTXO, error)

Unspents -- used to return unspent which all the value upper than the amount.

func (*WalletDB) Wallet

func (wdb *WalletDB) Wallet(uid string) *Wallet

Wallet -- used to get the wallet.

type WalletStore

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

WalletStore --

func NewWalletStore

func NewWalletStore(log *xlog.Log, conf *Config) *WalletStore

NewWalletStore -- creates new WalletStore.

func (*WalletStore) AllUID

func (s *WalletStore) AllUID() []string

AllUID -- used to clone all the wallet uids.

func (*WalletStore) FeesPerKB

func (s *WalletStore) FeesPerKB(priority string) int

FeesPerKB -- used to return the fees.

func (*WalletStore) Get

func (s *WalletStore) Get(uid string) *Wallet

Get -- used to get a wallet from the wallets list. Returns nil if not exists.

func (*WalletStore) Open

func (s *WalletStore) Open(dir string) error

Open -- used to open the dir database.

func (*WalletStore) Read

func (s *WalletStore) Read(path string) (*Wallet, error)

Read -- reads a wallet from the file.

func (*WalletStore) Write

func (s *WalletStore) Write(wallet *Wallet) error

Write -- write wallet to the file. Thread-Safe.

type WalletSyncer

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

WalletSyncer --

func NewWalletSyncer

func NewWalletSyncer(log *xlog.Log, conf *Config, chain Chain, store *WalletStore) *WalletSyncer

NewWalletSyncer -- creates new WalletSyncer.

func (*WalletSyncer) Start

func (ws *WalletSyncer) Start()

Start -- used to start the sync worker talk with chain.

func (*WalletSyncer) Stop

func (ws *WalletSyncer) Stop()

Stop -- used to stop the sync worker.

func (*WalletSyncer) Sync

func (ws *WalletSyncer) Sync()

Sync -- the sync worker.

Jump to

Keyboard shortcuts

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