dex

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

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

Go to latest
Published: Dec 16, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sending = iota
	Trading
	Finish
)

Variables

This section is empty.

Functions

func Args1

func Args1(a1 interface{}) ([]byte, error)

func Args2

func Args2(a1 interface{}, a2 interface{}) ([]byte, error)

func Args3

func Args3(a1 interface{}, a2 interface{}, a3 interface{}) ([]byte, error)

func ArgsNull

func ArgsNull() []byte

func CheckOrder

func CheckOrder(order *types.Order) error

func EthCall

func EthCall(args *rtypes.SendTxArgs) (hexutil.Bytes, error)

GenesisBlockNumber return genesisBlock init height

func GenesisBlockNumber

func GenesisBlockNumber() (*hexutil.Uint64, error)

GenesisBlockNumber return genesisBlock init height

func MarshalTx

func MarshalTx(args *rtypes.SendTxArgs) map[string]interface{}

func Ret

func Ret(ret []byte) (string, error)

func SendRawTx

func SendRawTx(b hexutil.Bytes, txType string) (common.Hash, error)

func WalletEstimateGas

func WalletEstimateGas(args *rtypes.SendTxArgs) (hexutil.Uint64, error)

func WalletGetTransactionCount

func WalletGetTransactionCount(addr common.Address) (uint64, error)

func WalletSendRawTransaction

func WalletSendRawTransaction(b hexutil.Bytes) (common.Hash, error)

func WalletSignHash

func WalletSignHash(addr common.Address, hash common.Hash) (hexutil.Bytes, error)

func WalletSignTx

func WalletSignTx(args *rtypes.SendTxArgs) (*rtypes.SignTransactionResult, error)

Types

type AccountModel

type AccountModel struct {
	UserID string `gorm:"primary_key;type:char(42)"`
	Token  string `gorm:"type:char(42)"`
	Amount string
}

Account Balance DateBase: not used

type BlockSyncModel

type BlockSyncModel struct {
	gorm.Model
	BeginBlock sql.NullInt64 `gorm:"not null"`
	EndBlock   sql.NullInt64 `gorm:"not null"`
}

type Dex

type Dex struct {
	Logger log.Logger
	// contains filtered or unexported fields
}

Dex dex

func NewDex

func NewDex(config *config.Config, logger log.Logger, db *SQLDBBackend) (*Dex, error)

func (*Dex) DexAvailableVolume

func (dex *Dex) DexAvailableVolume(order *types.Order) (*big.Int, error)

func (*Dex) DexCallRequest

func (dex *Dex) DexCallRequest(from common.Address, txData []byte) (hexutil.Bytes, error)

func (*Dex) DexCancelOrder

func (dex *Dex) DexCancelOrder(order *types.SignOrder) (common.Hash, error)

func (*Dex) DexDeposit

func (dex *Dex) DexDeposit(a common.Address, token common.Address, amount *hexutil.Big) (common.Hash, error)

func (*Dex) DexGetDepositAmount

func (dex *Dex) DexGetDepositAmount(user *common.Address, token *common.Address) (*big.Int, error)

func (*Dex) DexPostOrder

func (dex *Dex) DexPostOrder(order *types.SignOrder) (common.Hash, error)

func (*Dex) DexPostRequest

func (dex *Dex) DexPostRequest(from common.Address, txData []byte) (common.Hash, error)

user call contract

func (*Dex) DexTestTakerTrade

func (dex *Dex) DexTestTakerTrade(order *types.Order, taker common.Address, amount *big.Int) (string, error)

func (*Dex) DexTrade

func (dex *Dex) DexTrade(a common.Address, order *types.SignOrder, amount *hexutil.Big) (common.Hash, error)

func (*Dex) DexUsedVolumeByHash

func (dex *Dex) DexUsedVolumeByHash(hash *common.Hash) (*big.Int, error)

func (*Dex) DexWithDraw

func (dex *Dex) DexWithDraw(a common.Address, token common.Address, amount *hexutil.Big) (common.Hash, error)

func (*Dex) PostChainTx

func (dex *Dex) PostChainTx(tx *rtypes.SendTxArgs) (common.Hash, error)

func (*Dex) SignDexOrder

func (dex *Dex) SignDexOrder(order *types.Order) ([]byte, error)

type DexSubscription

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

func NewDexSubscription

func NewDexSubscription(peer string, contractAddr string, logger log.Logger, db *SQLDBBackend) (*DexSubscription, error)

func (*DexSubscription) FilterrLog

func (c *DexSubscription) FilterrLog(vlog *lktypes.Log) error

func (*DexSubscription) OnStart

func (c *DexSubscription) OnStart() error

func (*DexSubscription) SubLoop

func (c *DexSubscription) SubLoop(chanLog chan lktypes.Log, cli *rpc.ClientSubscription)

type OrderModel

type OrderModel struct {
	HashID       string          `gorm:"primary_key;type:char(66)"`     //Order HashID
	TokenGet     string          `gorm:"type:char(42);not null"`        //Get Token Address
	AmountGet    string          `gorm:"not null"`                      //Get Token Amount
	TokenGive    string          `gorm:"type:char(42);not null"`        //Give Token Address
	AmountGive   string          `gorm:"not null"`                      //Give Token Amount
	Nonce        sql.NullInt64   `gorm:"not null"`                      //Nonce
	Expires      sql.NullInt64   `gorm:"not null"`                      //Expire time (Unix Timestamp)
	Maker        string          `gorm:"type:char(42);not null"`        //Maker Address
	R            string          `gorm:"type:char(34);not null"`        //Sign R
	S            string          `gorm:"type:char(34);not null"`        //Sign S
	V            string          `gorm:"type:char(4);not null"`         //Sign V
	State        sql.NullInt64   `gorm:"not null"`                      //0:Sending(not save in block)  1:Trading  2:Finish(Cancel)
	Price        sql.NullFloat64 `gorm:"type:numeric(225,20);not null"` //Order Price Calculated from AmountGive and AmountGet
	FilledAmount string          `gorm:"not null"`                      //Order FilledAmount default:0
}

OrderModel Order DateBase

func (*OrderModel) ToSignOrder

func (o *OrderModel) ToSignOrder() (*types.SignOrder, error)

type OrderRet

type OrderRet struct {
	TokenGet   common.Address `json:"tokenGet"`
	AmountGet  string         `json:"amountGet"`
	TokenGive  common.Address `json:"tokenGive"`
	AmountGive string         `json:"amountGive"`
	Expires    uint64         `json:"expires"`
	Nonce      uint64         `json:"nonce"`
	Maker      common.Address `json:"maker"`
}

func (*OrderRet) ToOrder

func (o *OrderRet) ToOrder() (*types.Order, error)

type SQLDBBackend

type SQLDBBackend struct {
	gorm.DB
	// contains filtered or unexported fields
}

func (*SQLDBBackend) CreateAccountBalance

func (db *SQLDBBackend) CreateAccountBalance(account common.Address) error

Account: CURD

func (*SQLDBBackend) CreateOrder

func (db *SQLDBBackend) CreateOrder(order *types.SignOrder, state uint64) error

Order: CURD

func (*SQLDBBackend) CreateSync

func (db *SQLDBBackend) CreateSync() error

Block: CURD

func (*SQLDBBackend) CreateTrade

func (db *SQLDBBackend) CreateTrade(orderHash common.Hash, FilledAmount *big.Int, DealAmount *big.Int, BlockNum uint64, txHash common.Hash, taker common.Address) error

Trade: CURD

func (*SQLDBBackend) DeleteAccountBalance

func (db *SQLDBBackend) DeleteAccountBalance(account common.Address) error

func (*SQLDBBackend) DeleteOrder

func (db *SQLDBBackend) DeleteOrder(hash common.Hash) error

func (*SQLDBBackend) QueryOrderByTxPair

func (db *SQLDBBackend) QueryOrderByTxPair(tokenGet common.Address, tokenGive common.Address, index uint64, count uint64) ([]*types.SignOrder, error)

TODO:Query transactions on special demand QueryOrderByTxPair: order by price

func (*SQLDBBackend) ReadAccountBalance

func (db *SQLDBBackend) ReadAccountBalance(account common.Address) (*AccountModel, error)

func (*SQLDBBackend) ReadOrder

func (db *SQLDBBackend) ReadOrder(hash common.Hash) (*types.SignOrder, error)

func (*SQLDBBackend) ReadSync

func (db *SQLDBBackend) ReadSync() (uint64, uint64, error)

func (*SQLDBBackend) SetLogger

func (db *SQLDBBackend) SetLogger(logger log.Logger)

func (*SQLDBBackend) UpdateAccountBalance

func (db *SQLDBBackend) UpdateAccountBalance(account common.Address, token common.Address, amount *big.Int) error

func (*SQLDBBackend) UpdateFillAmount

func (db *SQLDBBackend) UpdateFillAmount(hash common.Hash, amount string) error

func (*SQLDBBackend) UpdateOrderState

func (db *SQLDBBackend) UpdateOrderState(hash common.Hash, state uint64) error

func (*SQLDBBackend) UpdateSync

func (db *SQLDBBackend) UpdateSync(begin, end uint64) error

type SignOrderRet

type SignOrderRet struct {
	OrderRet `json:"order"`
	R        string `json:"R"`
	S        string `json:"S"`
	V        string `json:"V"`
}

func (*SignOrderRet) ToSignOrder

func (o *SignOrderRet) ToSignOrder() (*types.SignOrder, error)

type TradeModel

type TradeModel struct {
	gorm.Model
	HashID       string        `gorm:"type:char(66);FOREIGNKEY"` //Order Hash
	DealAmount   string        `gorm:"not null"`                 //Deal amount
	FilledAmount string        `gorm:"not null"`                 //Trade Amount
	BlockNum     sql.NullInt64 `gorm:"not null"`                 //Deal BlockNum
	TxHash       string        `gorm:"type:char(66);not null"`   //Deal Tx hash
	Taker        string        `gorm:"type:char(42);not null"`   //Taker Address
}

TradeModel Trade history DateBase

type TradeRet

type TradeRet struct {
	FilledAmount string         `json:"filled"`
	DealAmount   string         `json:"deal"`
	Taker        common.Address `json:"taker"`
	Hash         common.Hash    `json:"hash"`
}

Jump to

Keyboard shortcuts

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