types

package
v0.0.0-...-491e088 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2019 License: Apache-2.0 Imports: 10 Imported by: 42

Documentation

Index

Constants

View Source
const (
	Bytes32Length = 32
)

Variables

View Source
var (
	NilHash    = common.HexToHash("0x")
	NilAddress = common.HexToAddress("0x")
)
View Source
var MaxUint256 = maxUint256()

Functions

func BigintToHex

func BigintToHex(b *big.Int) string

func HexToBigint

func HexToBigint(h string) *big.Int

func InUnchangeableStatus

func InUnchangeableStatus(status OrderStatus) bool

func Int2BlockNumHex

func Int2BlockNumHex(height int) string

func IsZeroAddress

func IsZeroAddress(addr common.Address) bool

func IsZeroHash

func IsZeroHash(hash common.Hash) bool

func StatusStr

func StatusStr(status TxStatus) string

func Xor

func Xor(bytes1, bytes2 []byte) []byte

Types

type AddressAuthorizedEvent

type AddressAuthorizedEvent struct {
	TxInfo
	Protocol common.Address
	Number   int
}

type AddressDeAuthorizedEvent

type AddressDeAuthorizedEvent struct {
	TxInfo
	Protocol common.Address
	Number   int
}

type ApprovalEvent

type ApprovalEvent struct {
	TxInfo
	Owner   common.Address
	Spender common.Address
	Amount  *big.Int
}

type BalanceUpdateEvent

type BalanceUpdateEvent struct {
	DelegateAddress string
	Owner           string
}

type Big

type Big big.Int

func NewBigPtr

func NewBigPtr(v *big.Int) *Big

func NewBigWithInt

func NewBigWithInt(v int) *Big

func (*Big) BigInt

func (h *Big) BigInt() *big.Int

func (*Big) Int

func (h *Big) Int() int

func (*Big) Int64

func (h *Big) Int64() int64

func (*Big) MarshalText

func (h *Big) MarshalText() ([]byte, error)

func (*Big) SetInt

func (h *Big) SetInt(v *big.Int) Big

func (*Big) Uint

func (h *Big) Uint() uint

func (*Big) Uint64

func (h *Big) Uint64() uint64

func (*Big) UnmarshalText

func (h *Big) UnmarshalText(input []byte) error

type Block

type Block struct {
	BlockHash   common.Hash
	ParentHash  common.Hash
	BlockNumber *big.Int
	CreateTime  int64
}

type BlockEvent

type BlockEvent struct {
	BlockNumber *big.Int
	BlockHash   common.Hash
	BlockTime   int64
}

type Bytes32

type Bytes32 [Bytes32Length]byte

func BitToBytes32

func BitToBytes32(b *big.Int) Bytes32

func BytesToBytes32

func BytesToBytes32(b []byte) Bytes32

func HexToBytes32

func HexToBytes32(s string) Bytes32

func (Bytes32) Big

func (s Bytes32) Big() *big.Int

func (Bytes32) Bytes

func (s Bytes32) Bytes() []byte

func (Bytes32) Bytes32

func (s Bytes32) Bytes32() [32]byte

func (Bytes32) Hex

func (s Bytes32) Hex() string

func (*Bytes32) MarshalText

func (a *Bytes32) MarshalText() ([]byte, error)

MarshalJson

func (*Bytes32) SetBytes

func (s *Bytes32) SetBytes(b []byte)

func (Bytes32) Str

func (s Bytes32) Str() string

func (*Bytes32) UnmarshalText

func (a *Bytes32) UnmarshalText(input []byte) error

type CheckNull

type CheckNull interface {
	IsNull() bool
}

type CurrencyMarketCap

type CurrencyMarketCap struct {
	Id           string         `json:"id"`
	Name         string         `json:"name"`
	Symbol       string         `json:"symbol"`
	Address      common.Address `json:"address"`
	PriceUsd     *big.Rat       `json:"price_usd"`
	PriceBtc     *big.Rat       `json:"price_btc"`
	PriceCny     *big.Rat       `json:"price_cny"`
	Volume24HCNY *big.Rat       `json:"24h_volume_cny"`
	Volume24HUSD *big.Rat       `json:"24h_volume_usd"`
	LastUpdated  int64          `json:"last_updated"`
	Decimals     *big.Int
}

func (*CurrencyMarketCap) UnmarshalJSON

func (cap *CurrencyMarketCap) UnmarshalJSON(input []byte) error

type CutoffEvent

type CutoffEvent struct {
	TxInfo
	Owner         common.Address
	Cutoff        *big.Int
	OrderHashList []common.Hash
}

type CutoffPairEvent

type CutoffPairEvent struct {
	TxInfo
	Owner         common.Address
	Token1        common.Address
	Token2        common.Address
	Cutoff        *big.Int
	OrderHashList []common.Hash
}

type DepthUpdateEvent

type DepthUpdateEvent struct {
	DelegateAddress string
	Market          string
}

type ExtractorWarningEvent

type ExtractorWarningEvent struct{}

type FilledOrder

type FilledOrder struct {
	OrderState       OrderState `json:"orderState" gencodec:"required"`
	FeeSelection     uint8      `json:"feeSelection"`     //0 -> lrc
	RateAmountS      *big.Rat   `json:"rateAmountS"`      //提交需要
	AvailableAmountS *big.Rat   `json:"availableAmountS"` //需要,也是用于计算fee
	AvailableAmountB *big.Rat   //需要,也是用于计算fee
	FillAmountS      *big.Rat   `json:"fillAmountS"`
	FillAmountB      *big.Rat   `json:"fillAmountB"` //计算需要
	LrcReward        *big.Rat   `json:"lrcReward"`
	LrcFee           *big.Rat   `json:"lrcFee"`
	LegalLrcFee      *big.Rat   `json:"legalLrcFee"`
	FeeS             *big.Rat   `json:"feeS"`
	LegalFeeS        *big.Rat   `json:"legalFeeS"`
	LegalFee         *big.Rat   `json:"legalFee"` //法币计算的fee

	SPrice *big.Rat `json:"SPrice"`
	BPrice *big.Rat `json:"BPrice"`

	AvailableLrcBalance    *big.Rat
	AvailableTokenSBalance *big.Rat
}

RateAmountS、FeeSelection 需要提交到contract

func ConvertOrderStateToFilledOrder

func ConvertOrderStateToFilledOrder(orderState OrderState, lrcBalance, tokenSBalance *big.Rat, lrcAddress common.Address) *FilledOrder

type ForkedEvent

type ForkedEvent struct {
	DetectedBlock *big.Int
	DetectedHash  common.Hash
	ForkBlock     *big.Int
	ForkHash      common.Hash
}

type NameRegistryInfo

type NameRegistryInfo struct {
	Name          string
	Owner         common.Address
	FeeRecipient  common.Address
	Signer        common.Address
	ParticipantId *big.Int
}

type Order

type Order struct {
	Protocol              common.Address             `json:"protocol" gencodec:"required"`        // 智能合约地址
	DelegateAddress       common.Address             `json:"delegateAddress" gencodec:"required"` // 智能合约地址
	AuthAddr              common.Address             `json:"authAddr" gencodec:"required"`        //
	AuthPrivateKey        crypto.EthPrivateKeyCrypto `json:"authPrivateKey" gencodec:"required"`  //
	WalletAddress         common.Address             `json:"walletAddress" gencodec:"required"`
	TokenS                common.Address             `json:"tokenS" gencodec:"required"`     // 卖出erc20代币智能合约地址
	TokenB                common.Address             `json:"tokenB" gencodec:"required"`     // 买入erc20代币智能合约地址
	AmountS               *big.Int                   `json:"amountS" gencodec:"required"`    // 卖出erc20代币数量上限
	AmountB               *big.Int                   `json:"amountB" gencodec:"required"`    // 买入erc20代币数量上限
	ValidSince            *big.Int                   `json:"validSince" gencodec:"required"` //
	ValidUntil            *big.Int                   `json:"validUntil" gencodec:"required"` // 订单过期时间
	LrcFee                *big.Int                   `json:"lrcFee" `                        // 交易总费用,部分成交的费用按该次撮合实际卖出代币额与比例计算
	BuyNoMoreThanAmountB  bool                       `json:"buyNoMoreThanAmountB" gencodec:"required"`
	MarginSplitPercentage uint8                      `json:"marginSplitPercentage" gencodec:"required"` // 不为0时支付给交易所的分润比例,否则视为100%
	V                     uint8                      `json:"v" gencodec:"required"`
	R                     Bytes32                    `json:"r" gencodec:"required"`
	S                     Bytes32                    `json:"s" gencodec:"required"`
	Price                 *big.Rat                   `json:"price"`
	Owner                 common.Address             `json:"owner"`
	Hash                  common.Hash                `json:"hash"`
	Market                string                     `json:"market"`
	CreateTime            int64                      `json:"createTime"`
	PowNonce              uint64                     `json:"powNonce"`
	Side                  string                     `json:"side"`
	OrderType             string                     `json:"orderType"`
}

func ToOrder

func ToOrder(request *OrderJsonRequest) *Order

func (*Order) GenerateAndSetSignature

func (o *Order) GenerateAndSetSignature(singerAddr common.Address) error

func (*Order) GenerateHash

func (o *Order) GenerateHash() common.Hash

func (*Order) GeneratePrice

func (o *Order) GeneratePrice()

func (Order) MarshalJSON

func (o Order) MarshalJSON() ([]byte, error)

func (*Order) SignerAddress

func (o *Order) SignerAddress() (common.Address, error)

func (*Order) UnmarshalJSON

func (o *Order) UnmarshalJSON(input []byte) error

func (*Order) ValidateSignatureValues

func (o *Order) ValidateSignatureValues() bool

type OrderCancelledEvent

type OrderCancelledEvent struct {
	TxInfo
	OrderHash       common.Hash
	AmountCancelled *big.Int
}

type OrderDelayList

type OrderDelayList struct {
	OrderHash    []common.Hash
	DelayedCount int64
}

type OrderFilledEvent

type OrderFilledEvent struct {
	TxInfo
	Ringhash      common.Hash
	PreOrderHash  common.Hash
	OrderHash     common.Hash
	NextOrderHash common.Hash
	Owner         common.Address
	TokenS        common.Address
	TokenB        common.Address
	SellTo        common.Address
	BuyFrom       common.Address
	RingIndex     *big.Int
	AmountS       *big.Int
	AmountB       *big.Int
	LrcReward     *big.Int
	LrcFee        *big.Int
	SplitS        *big.Int
	SplitB        *big.Int
	Market        string
	FillIndex     *big.Int
}

type OrderJsonRequest

type OrderJsonRequest struct {
	Protocol        common.Address             `json:"protocol" gencodec:"required"`        // 智能合约地址
	DelegateAddress common.Address             `json:"delegateAddress" gencodec:"required"` // 智能合约地址
	TokenS          common.Address             `json:"tokenS" gencodec:"required"`          // 卖出erc20代币智能合约地址
	TokenB          common.Address             `json:"tokenB" gencodec:"required"`          // 买入erc20代币智能合约地址
	AuthAddr        common.Address             `json:"authAddr" gencodec:"required"`        //
	AuthPrivateKey  crypto.EthPrivateKeyCrypto `json:"authPrivateKey"`                      //
	WalletAddress   common.Address             `json:"walletAddress" gencodec:"required"`
	AmountS         *big.Int                   `json:"amountS" gencodec:"required"`    // 卖出erc20代币数量上限
	AmountB         *big.Int                   `json:"amountB" gencodec:"required"`    // 买入erc20代币数量上限
	ValidSince      *big.Int                   `json:"validSince" gencodec:"required"` //
	ValidUntil      *big.Int                   `json:"validUntil" gencodec:"required"` // 订单过期时间
	// Salt                  int64          `json:"salt" gencodec:"required"`
	LrcFee                *big.Int       `json:"lrcFee" ` // 交易总费用,部分成交的费用按该次撮合实际卖出代币额与比例计算
	BuyNoMoreThanAmountB  bool           `json:"buyNoMoreThanAmountB" gencodec:"required"`
	MarginSplitPercentage uint8          `json:"marginSplitPercentage" gencodec:"required"` // 不为0时支付给交易所的分润比例,否则视为100%
	V                     uint8          `json:"v" gencodec:"required"`
	R                     Bytes32        `json:"r" gencodec:"required"`
	S                     Bytes32        `json:"s" gencodec:"required"`
	Price                 *big.Rat       `json:"price"`
	Owner                 common.Address `json:"owner"`
	Hash                  common.Hash    `json:"hash"`
	CreateTime            int64          `json:"createTime"`
	PowNonce              uint64         `json:"powNonce"`
	Side                  string         `json:"side"`
	OrderType             string         `json:"orderType"`
}

func (OrderJsonRequest) MarshalJSON

func (o OrderJsonRequest) MarshalJSON() ([]byte, error)

func (*OrderJsonRequest) UnmarshalJSON

func (o *OrderJsonRequest) UnmarshalJSON(input []byte) error

type OrderState

type OrderState struct {
	RawOrder         Order       `json:"rawOrder"`
	UpdatedBlock     *big.Int    `json:"updatedBlock"`
	DealtAmountS     *big.Int    `json:"dealtAmountS"`
	DealtAmountB     *big.Int    `json:"dealtAmountB"`
	SplitAmountS     *big.Int    `json:"splitAmountS"`
	SplitAmountB     *big.Int    `json:"splitAmountB"`
	CancelledAmountS *big.Int    `json:"cancelledAmountS"`
	CancelledAmountB *big.Int    `json:"cancelledAmountB"`
	Status           OrderStatus `json:"status"`
	BroadcastTime    int         `json:"broadcastTime"`
}

从[]byte解析时使用json.Unmarshal

func (*OrderState) DealtAndSplitAmount

func (state *OrderState) DealtAndSplitAmount() (totalAmountS *big.Rat, totalAmountB *big.Rat)

func (*OrderState) IsEffective

func (ord *OrderState) IsEffective() bool

func (*OrderState) IsExpired

func (ord *OrderState) IsExpired() bool

func (*OrderState) RemainedAmount

func (orderState *OrderState) RemainedAmount() (remainedAmountS *big.Rat, remainedAmountB *big.Rat)

func (*OrderState) ResolveStatus

func (ord *OrderState) ResolveStatus(allowance, balance *big.Int)

解释订单最终状态

type OrderStatus

type OrderStatus uint8
const (
	ORDER_UNKNOWN         OrderStatus = 0
	ORDER_NEW             OrderStatus = 1
	ORDER_PARTIAL         OrderStatus = 2
	ORDER_FINISHED        OrderStatus = 3
	ORDER_CANCEL          OrderStatus = 4
	ORDER_CUTOFF          OrderStatus = 5
	ORDER_EXPIRE          OrderStatus = 6
	ORDER_PENDING         OrderStatus = 7
	ORDER_PENDING_FOR_P2P OrderStatus = 17

	ORDER_TYPE_MARKET = "market_order"
	ORDER_TYPE_P2P    = "p2p_order"
)

type Rat

type Rat big.Rat

func NewBigRat

func NewBigRat(v *big.Rat) *Rat

func (*Rat) BigRat

func (r *Rat) BigRat() *big.Rat

func (*Rat) MarshalText

func (r *Rat) MarshalText() ([]byte, error)

func (*Rat) UnmarshalText

func (r *Rat) UnmarshalText(input []byte) error

type Ring

type Ring struct {
	Orders      []*FilledOrder `json:"orderes"`
	V           uint8          `json:"v"`
	R           Bytes32        `json:"r"`
	S           Bytes32        `json:"s"`
	Hash        common.Hash    `json:"hash"`
	ReducedRate *big.Rat       `json:"reducedRate"` //成环之后,折价比例
	LegalFee    *big.Rat       `json:"legalFee"`    //法币计算的fee
	UniqueId    common.Hash    `json:"uniquedId"`

	//
	Received  *big.Rat
	LegalCost *big.Rat
	Gas       *big.Int
	GasPrice  *big.Int
}

func (*Ring) FeeSelections

func (ring *Ring) FeeSelections() *big.Int

func (*Ring) GenerateHash

func (ring *Ring) GenerateHash(feeReceipt common.Address) common.Hash

func (*Ring) GenerateUniqueId

func (ring *Ring) GenerateUniqueId() common.Hash

func (*Ring) ValidSinceTime

func (ring *Ring) ValidSinceTime() int64

type RingMinedEvent

type RingMinedEvent struct {
	TxInfo
	RingIndex    *big.Int
	TotalLrcFee  *big.Int
	TradeAmount  int
	Ringhash     common.Hash
	Miner        common.Address
	FeeRecipient common.Address
	Err          error
}

type RingSubmitInfo

type RingSubmitInfo struct {
	RawRing *Ring

	//todo:remove it
	Miner            common.Address
	ProtocolAddress  common.Address
	Ringhash         common.Hash
	OrdersCount      *big.Int
	ProtocolData     []byte
	ProtocolGas      *big.Int
	ProtocolUsedGas  *big.Int
	ProtocolGasPrice *big.Int

	SubmitTxHash common.Hash
}

type RingSubmitResultEvent

type RingSubmitResultEvent struct {
	RingHash     common.Hash
	RingUniqueId common.Hash
	TxHash       common.Hash
	Status       TxStatus
	RingIndex    *big.Int
	BlockNumber  *big.Int
	UsedGas      *big.Int
	Err          error
}

type SubmitRingMethodEvent

type SubmitRingMethodEvent struct {
	TxInfo
	OrderList    []Order
	FeeReceipt   common.Address
	FeeSelection uint16
	Err          error
}

type Token

type Token struct {
	Protocol common.Address `json:"protocol"`
	Symbol   string         `json:"symbol"`
	Source   string         `json:"source"`
	Time     int64          `json:"time"`
	Deny     bool           `json:"deny"`
	Decimals *big.Int       `json:"decimals"`
	IsMarket bool           `json:"isMarket"`
	IcoPrice *big.Rat       `json:"icoPrice"`
}

type TokenRegisterEvent

type TokenRegisterEvent struct {
	TxInfo
	Token  common.Address
	Symbol string
}

type TokenUnRegisterEvent

type TokenUnRegisterEvent struct {
	TxInfo
	Token  common.Address
	Symbol string
}

type TransactionEvent

type TransactionEvent struct {
	Tx TxInfo
}

type TransferEvent

type TransferEvent struct {
	TxInfo
	Sender   common.Address
	Receiver common.Address
	Amount   *big.Int
}

type TxInfo

type TxInfo struct {
	Protocol        common.Address `json:"from"`
	DelegateAddress common.Address `json:"to"`
	From            common.Address `json:"from"`
	To              common.Address `json:"to"`
	BlockHash       common.Hash    `json:"block_hash"`
	BlockNumber     *big.Int       `json:"block_number"`
	BlockTime       int64          `json:"block_time"`
	TxHash          common.Hash    `json:"tx_hash"`
	TxIndex         int64          `json:"tx_index"`
	TxLogIndex      int64          `json:"tx_log_index"`
	Value           *big.Int       `json:"value"`
	Status          TxStatus       `json:"status"`
	GasLimit        *big.Int       `json:"gas_limit"`
	GasUsed         *big.Int       `json:"gas_used"`
	GasPrice        *big.Int       `json:"gas_price"`
	Nonce           *big.Int       `json:"nonce"`
	Identify        string         `json:"identify"`
}

type TxStatus

type TxStatus uint8
const (
	TX_STATUS_UNKNOWN TxStatus = 0
	TX_STATUS_PENDING TxStatus = 1
	TX_STATUS_SUCCESS TxStatus = 2
	TX_STATUS_FAILED  TxStatus = 3
)

func StrToTxStatus

func StrToTxStatus(txType string) TxStatus

type WethDepositEvent

type WethDepositEvent struct {
	TxInfo
	Dst    common.Address
	Amount *big.Int
}

type WethWithdrawalEvent

type WethWithdrawalEvent struct {
	TxInfo
	Src    common.Address
	Amount *big.Int
}

type WhiteListUser

type WhiteListUser struct {
	Owner      common.Address `json:"owner"`
	CreateTime int64          `json:"create_time"`
}

func (WhiteListUser) MarshalJSON

func (w WhiteListUser) MarshalJSON() ([]byte, error)

func (*WhiteListUser) UnmarshalJSON

func (w *WhiteListUser) UnmarshalJSON(input []byte) error

Jump to

Keyboard shortcuts

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