cxserver

package
v0.0.0-...-7ad0b1f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpencxServer

type OpencxServer struct {
	SettlementEngines map[*coinparam.Params]match.SettlementEngine
	MatchingEngines   map[match.Pair]match.LimitEngine
	Orderbooks        map[match.Pair]match.LimitOrderbook
	DepositStores     map[*coinparam.Params]cxdb.DepositStore
	SettlementStores  map[*coinparam.Params]cxdb.SettlementStore

	ExchangeNode *qln.LitNode

	BlockChanMap       map[int]chan *wire.MsgBlock
	HeightEventChanMap map[int]chan lnutil.HeightEvent

	OpencxRoot string

	// All you should need to add a new coin to the exchange is the correct coin params to connect
	// to nodes and (if it works), do proof of work and such.
	HookMap map[*coinparam.Params]*uspv.ChainHook

	WalletMap map[*coinparam.Params]*wallit.Wallit

	PrivKeyMap map[*coinparam.Params]*hdkeychain.ExtendedKey
	// contains filtered or unexported fields
}

OpencxServer is what orchestrates the exchange. It's where you plug everything into basically. The Server looks spookily like a node.

func InitServer

func InitServer(setEngines map[*coinparam.Params]match.SettlementEngine, matchEngines map[match.Pair]match.LimitEngine, books map[match.Pair]match.LimitOrderbook, depositStores map[*coinparam.Params]cxdb.DepositStore, settleStores map[*coinparam.Params]cxdb.SettlementStore, rootDir string) (server *OpencxServer, err error)

InitServer creates a new server

func (*OpencxServer) CallIngest

func (server *OpencxServer) CallIngest(blockHeight int32, block *wire.MsgBlock, coinType *coinparam.Params)

CallIngest calls the ingest function. This is so we can make a bunch of different handlers that call this depending on which way they use channels.

func (*OpencxServer) CancelOrder

func (server *OpencxServer) CancelOrder(order *match.LimitOrderIDPair) (err error)

CancelOrder places an order by first checking if we can credit the user, then calling the appropriate database calls

func (*OpencxServer) ChainHookHeightHandler

func (server *OpencxServer) ChainHookHeightHandler(incomingBlockHeight chan int32, blockChan chan *wire.MsgBlock, coinType *coinparam.Params)

ChainHookHeightHandler is a handler for when there is a height and block event. We need both channels to work and be synchronized, which I'm assuming is the case in the lit repos. Will need to double check.

func (*OpencxServer) CreateChannel

func (server *OpencxServer) CreateChannel(pubkey *koblitz.PublicKey, initSend int64, ccap int64, params *coinparam.Params) (txid string, err error)

CreateChannel creates a channel with pubkey and will send a certain amount on creation. if the send amount is not 0 then it will withdraw from the

func (*OpencxServer) CreateSwap

func (server *OpencxServer) CreateSwap(pubkey *koblitz.PublicKey, order *match.LimitOrder) (err error)

CreateSwap creates a swap with the user depending on an order specified. This is the main functionality for non custodial exchange. TODO: check over this code, it's a large function

func (*OpencxServer) CreditUser

func (server *OpencxServer) CreditUser(pubkey *koblitz.PublicKey, amount uint64, param *coinparam.Params) (err error)

CreditUser subtracts the balance of the pubkey by issuing a settlement exec and bringing it through all of the required data stores. CreditUser acquires dbLock so it can just be called.

func (*OpencxServer) DebitUser

func (server *OpencxServer) DebitUser(pubkey *koblitz.PublicKey, amount uint64, param *coinparam.Params) (err error)

DebitUser adds to the balance of the pubkey by issuing a settlement exec and bringing it through all of the required data stores. DebitUser acquires dbLock so it can just be called.

func (*OpencxServer) GetAddrForCoin

func (server *OpencxServer) GetAddrForCoin(coinType *coinparam.Params, pubkey *koblitz.PublicKey) (addr string, err error)

GetAddrForCoin gets an address based on a wallet and pubkey

func (*OpencxServer) GetAddressMap

func (server *OpencxServer) GetAddressMap(pubkey *koblitz.PublicKey) (addrMap map[*coinparam.Params]string, err error)

GetAddressMap gets an address map for a pubkey. This is so we can register multiple ways.

func (*OpencxServer) GetBalance

func (server *OpencxServer) GetBalance(pubkey *koblitz.PublicKey, coin *coinparam.Params) (amount uint64, err error)

GetBalance gets the balance for a specific public key and coin.

func (*OpencxServer) GetDepositAddress

func (server *OpencxServer) GetDepositAddress(pubkey *koblitz.PublicKey, coin *coinparam.Params) (address string, err error)

GetDepositAddress gets the deposit address for the pubkey and the param based on the storage in the server

func (*OpencxServer) GetOPConfirmHandler

func (server *OpencxServer) GetOPConfirmHandler() (hFunc func(event eventbus.Event) eventbus.EventHandleResult)

GetOPConfirmHandler gets the handler func to pass in an amount to the updatebalance function

func (*OpencxServer) GetOrder

func (server *OpencxServer) GetOrder(orderID *match.OrderID) (order *match.LimitOrderIDPair, err error)

GetOrder gets the order for the given id from the limit orderbook

func (*OpencxServer) GetOrdersForPubkey

func (server *OpencxServer) GetOrdersForPubkey(pubkey *koblitz.PublicKey) (orders []*match.LimitOrderIDPair, err error)

GetOrdersForPubkey returns orders for a specific pubkey and pair

func (*OpencxServer) GetOrdersString

func (server *OpencxServer) GetOrdersString() (getOrderStr string)

GetOrdersString gets a string that should be signed in order for a client to be registered

func (*OpencxServer) GetOrdersStringVerify

func (server *OpencxServer) GetOrdersStringVerify(sig []byte) (pubkey *koblitz.PublicKey, err error)

GetOrdersStringVerify verifies a signature for the getOrdersString

func (*OpencxServer) GetPairs

func (server *OpencxServer) GetPairs() (pairs []*match.Pair)

GetPairs just iterates throug the matching engine map, getting their pair keys and appending to a list

func (*OpencxServer) GetPeerFromPubkey

func (server *OpencxServer) GetPeerFromPubkey(pubkey *koblitz.PublicKey) (peerIdx uint32, err error)

GetPeerFromPubkey gets a peer index from a pubkey.

func (*OpencxServer) GetPrice

func (server *OpencxServer) GetPrice(pair *match.Pair) (price float64, err error)

func (*OpencxServer) GetPushHandler

func (server *OpencxServer) GetPushHandler() (hFunc func(event eventbus.Event) eventbus.EventHandleResult)

GetPushHandler gets the handler func to add to the user's balance since they've pushed over a lightning channel

func (*OpencxServer) GetQchansByPeerParam

func (server *OpencxServer) GetQchansByPeerParam(pubkey *koblitz.PublicKey, param *coinparam.Params) (qchans []*qln.Qchan, err error)

GetQchansByPeerParam gets channel indexes for a param and pubkey / peer

func (*OpencxServer) GetRegistrationString

func (server *OpencxServer) GetRegistrationString() (regStr string)

GetRegistrationString gets a string that should be signed in order for a client to be registered

func (*OpencxServer) GetSigProofHandler

func (server *OpencxServer) GetSigProofHandler() (hFunc func(event eventbus.Event) eventbus.EventHandleResult)

GetSigProofHandler gets the handler func to pass in things to the register function. We get their pub key from the QChan through the event bus and then use that to register a new user.

func (*OpencxServer) HeightHandler

func (server *OpencxServer) HeightHandler(incomingBlockHeight chan lnutil.HeightEvent, blockChan chan *wire.MsgBlock, coinType *coinparam.Params)

HeightHandler is a handler for when there is a height and block event for the wallet. We need both channels to work and be synchronized, which I'm assuming is the case in the lit repos. Will need to double check.

func (*OpencxServer) LinkAllWallets

func (server *OpencxServer) LinkAllWallets() (err error)

LinkAllWallets will link the exchanges' wallets with the lit node running. Defaults to false for running tower.

func (*OpencxServer) LinkManyWallets

func (server *OpencxServer) LinkManyWallets(wallets []*wallit.Wallit, tower bool) (err error)

LinkManyWallets takes in a bunch of wallets and links them. We set the tower for all wallets consistently coinType as specified in the parameters.

func (*OpencxServer) LinkOneWallet

func (server *OpencxServer) LinkOneWallet(wallet *wallit.Wallit, tower bool) (err error)

LinkOneWallet is a modified version of linkwallet in lit that doesn't make the wallet but links it with an already running one. Your responsibility to pass the correct cointype and tower.

func (*OpencxServer) PlaceOrder

func (server *OpencxServer) PlaceOrder(order *match.LimitOrder) (orderID *match.OrderID, err error)

PlaceOrder places an order by first checking if we can credit the user, then calling the appropriate database calls

func (*OpencxServer) RegisterUser

func (server *OpencxServer) RegisterUser(pubkey *koblitz.PublicKey) (err error)

RegisterUser gives the user a balance of 0, and gives them deposit addresses. This acquires locks so do not try to do it on your own

func (*OpencxServer) RegistrationStringVerify

func (server *OpencxServer) RegistrationStringVerify(sig []byte) (pubkey *koblitz.PublicKey, err error)

RegistrationStringVerify verifies a signature for a registration string and returns a pubkey

func (*OpencxServer) SetupAllWallets

func (server *OpencxServer) SetupAllWallets(hostParamList util.HostParamList, subDirName string, resync bool) (err error)

SetupAllWallets sets up all wallets with parameters as specified in the hostParamList

func (*OpencxServer) SetupFundBack

func (server *OpencxServer) SetupFundBack(pubkey *koblitz.PublicKey, currCoinType uint32, channelCapacity int64) (err error)

SetupFundBack funds a node back after a sigproof

func (*OpencxServer) SetupLitNode

func (server *OpencxServer) SetupLitNode(privkey *[32]byte, subDirName string, trackerURL string, proxyURL string, nat string) (err error)

SetupLitNode sets up the lit node for use later, I wanna do this because this really shouldn't be in initialization code? should it be? basically just run this after you unlock the key

func (*OpencxServer) SetupLitRPCConnect

func (server *OpencxServer) SetupLitRPCConnect(rpchost string, rpcport uint16)

SetupLitRPCConnect sets up an rpc connection with a running lit node?

func (*OpencxServer) SetupServerKeys

func (server *OpencxServer) SetupServerKeys(privkey *[32]byte) (err error)

SetupServerKeys just loads a private key from a file wallet

func (*OpencxServer) SetupSingleKey

func (server *OpencxServer) SetupSingleKey(privkey *[32]byte, param *coinparam.Params) (err error)

SetupSingleKey sets up a single key based on a single param for the server.

func (*OpencxServer) SetupWallet

func (server *OpencxServer) SetupWallet(errChan chan error, subDirName string, param *coinparam.Params, resync bool, hostString string)

SetupWallet sets up a wallet for a specific coin, based on params.

func (*OpencxServer) StartChainhookHandlers

func (server *OpencxServer) StartChainhookHandlers(wallet *wallit.Wallit)

StartChainhookHandlers gets the channels from the wallet's chainhook and starts a handler.

func (*OpencxServer) ViewOrderbook

func (server *OpencxServer) ViewOrderbook(pair *match.Pair) (book map[float64][]*match.LimitOrderIDPair, err error)

ViewOrderbook returns a view of the orderbook for the user

func (*OpencxServer) WithdrawCoins

func (server *OpencxServer) WithdrawCoins(address string, pubkey *koblitz.PublicKey, amount uint64, params *coinparam.Params) (txid string, err error)

WithdrawCoins inputs the correct parameters to return a withdraw txid

func (*OpencxServer) WithdrawLightning

func (server *OpencxServer) WithdrawLightning(pubkey *koblitz.PublicKey, amount uint64, params *coinparam.Params) (txid string, err error)

WithdrawLightning inputs the correct parameters to return a correct txid associated with a channel outpoint

Jump to

Keyboard shortcuts

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