0x-mesh: github.com/0xProject/0x-mesh/zeroex/ordervalidator Index | Files

package ordervalidator

import "github.com/0xProject/0x-mesh/zeroex/ordervalidator"


Package Files



const (
    ZeroExValidation = RejectedOrderKind("ZEROEX_VALIDATION")
    MeshError        = RejectedOrderKind("MESH_ERROR")
    MeshValidation   = RejectedOrderKind("MESH_VALIDATION")

RejectedOrderKind values

const ROInvalidSchemaCode = "InvalidSchema"

ROInvalidSchemaCode is the RejectedOrderStatus emitted if an order doesn't conform to the order schema


var (
    ROEthRPCRequestFailed = RejectedOrderStatus{
        Code:    "EthRPCRequestFailed",
        Message: "network request to Ethereum RPC endpoint failed",
    ROInvalidMakerAssetAmount = RejectedOrderStatus{
        Code:    "OrderHasInvalidMakerAssetAmount",
        Message: "order makerAssetAmount cannot be 0",
    ROInvalidTakerAssetAmount = RejectedOrderStatus{
        Code:    "OrderHasInvalidTakerAssetAmount",
        Message: "order takerAssetAmount cannot be 0",
    ROExpired = RejectedOrderStatus{
        Code:    "OrderExpired",
        Message: "order expired according to latest block timestamp",
    ROFullyFilled = RejectedOrderStatus{
        Code:    "OrderFullyFilled",
        Message: "order already fully filled",
    ROCancelled = RejectedOrderStatus{
        Code:    "OrderCancelled",
        Message: "order cancelled",
    ROUnfunded = RejectedOrderStatus{
        Code:    "OrderUnfunded",
        Message: "maker has insufficient balance or allowance for this order to be filled",
    ROInvalidMakerAssetData = RejectedOrderStatus{
        Code:    "OrderHasInvalidMakerAssetData",
        Message: "order makerAssetData must encode a supported assetData type",
    ROInvalidMakerFeeAssetData = RejectedOrderStatus{
        Code:    "OrderHasInvalidMakerFeeAssetData",
        Message: "order makerFeeAssetData must encode a supported assetData type",
    ROInvalidTakerAssetData = RejectedOrderStatus{
        Code:    "OrderHasInvalidTakerAssetData",
        Message: "order takerAssetData must encode a supported assetData type",
    ROInvalidTakerFeeAssetData = RejectedOrderStatus{
        Code:    "OrderHasInvalidTakerFeeAssetData",
        Message: "order takerFeeAssetData must encode a supported assetData type",
    ROInvalidSignature = RejectedOrderStatus{
        Code:    "OrderHasInvalidSignature",
        Message: "order signature must be valid",
    ROMaxExpirationExceeded = RejectedOrderStatus{
        Code:    "OrderMaxExpirationExceeded",
        Message: "order expiration too far in the future",
    ROInternalError = RejectedOrderStatus{
        Code:    "InternalError",
        Message: "an unexpected internal error has occurred",
    ROMaxOrderSizeExceeded = RejectedOrderStatus{
        Code:    "MaxOrderSizeExceeded",
        Message: fmt.Sprintf("order exceeds the maximum encoded size of %d bytes", constants.MaxOrderSizeInBytes),
    ROOrderAlreadyStoredAndUnfillable = RejectedOrderStatus{
        Code:    "OrderAlreadyStoredAndUnfillable",
        Message: "" /* 151 byte string literal not displayed */,
    ROIncorrectChain = RejectedOrderStatus{
        Code:    "OrderForIncorrectChain",
        Message: "order was created for a different chain than the one this Mesh node is configured to support",
    ROIncorrectExchangeAddress = RejectedOrderStatus{
        Code:    "IncorrectExchangeAddress",
        Message: "the exchange address for the order does not match the chain ID/network ID",
    ROSenderAddressNotAllowed = RejectedOrderStatus{
        Code:    "SenderAddressNotAllowed",
        Message: "orders with a senderAddress are not currently supported",
    RODatabaseFullOfOrders = RejectedOrderStatus{
        Code:    "DatabaseFullOfOrders",
        Message: "database is full of pinned orders and no orders can be deleted to make space (consider increasing MAX_ORDERS_IN_STORAGE)",
    ROTakerAddressNotAllowed = RejectedOrderStatus{
        Code:    "TakerAddressNotAllowed",
        Message: "the taker address is not a whitelisted address",

RejectedOrderStatus values

func ConvertRejectOrderCodeToOrderEventEndState Uses

func ConvertRejectOrderCodeToOrderEventEndState(rejectedOrderStatus RejectedOrderStatus) (zeroex.OrderEventEndState, bool)

ConvertRejectOrderCodeToOrderEventEndState converts an RejectOrderCode to an OrderEventEndState type

type AcceptedOrderInfo Uses

type AcceptedOrderInfo struct {
    OrderHash                common.Hash         `json:"orderHash"`
    SignedOrder              *zeroex.SignedOrder `json:"signedOrder"`
    FillableTakerAssetAmount *big.Int            `json:"fillableTakerAssetAmount"`
    IsNew                    bool                `json:"isNew"`

AcceptedOrderInfo represents an fillable order and how much it could be filled for

func (AcceptedOrderInfo) MarshalJSON Uses

func (a AcceptedOrderInfo) MarshalJSON() ([]byte, error)

MarshalJSON is a custom Marshaler for AcceptedOrderInfo

func (*AcceptedOrderInfo) UnmarshalJSON Uses

func (a *AcceptedOrderInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON implements a custom JSON unmarshaller for the OrderEvent type

type OrderValidator Uses

type OrderValidator struct {
    // contains filtered or unexported fields

OrderValidator validates 0x orders

func New Uses

func New(contractCaller bind.ContractCaller, chainID int, maxRequestContentLength int, contractAddresses ethereum.ContractAddresses) (*OrderValidator, error)

New instantiates a new order validator

func (*OrderValidator) BatchOffchainValidation Uses

func (o *OrderValidator) BatchOffchainValidation(signedOrders []*zeroex.SignedOrder) ([]*zeroex.SignedOrder, []*RejectedOrderInfo)

BatchOffchainValidation performs all off-chain validation checks on a batch of 0x orders. These checks include: - `MakerAssetAmount` and `TakerAssetAmount` cannot be 0 - `AssetData` fields contain properly encoded, and currently supported assetData (ERC20 & ERC721 for now) - `Signature` contains a properly encoded 0x signature - Validate that order isn't expired Returns the signedOrders that are off-chain valid along with an array of orderInfo for the rejected orders

func (*OrderValidator) BatchValidate Uses

func (o *OrderValidator) BatchValidate(ctx context.Context, signedOrders []*zeroex.SignedOrder, areNewOrders bool, validationBlock *types.MiniHeader) *ValidationResults

BatchValidate retrieves all the information needed to validate the supplied orders. It splits the orders into chunks of `chunkSize`, and makes no more then `concurrencyLimit` requests concurrently. If a request fails, re-attempt it up to four times before giving up. If some requests fail, this method still returns whatever order information it was able to retrieve up until the failure. The `validationBlock` parameter lets the caller specify a specific block at which to validate the orders. This can be set to the `latest` block or any other historical block.

type RejectedOrderInfo Uses

type RejectedOrderInfo struct {
    OrderHash   common.Hash         `json:"orderHash"`
    SignedOrder *zeroex.SignedOrder `json:"signedOrder"`
    Kind        RejectedOrderKind   `json:"kind"`
    Status      RejectedOrderStatus `json:"status"`

RejectedOrderInfo encapsulates all the needed information to understand _why_ a 0x order was rejected (i.e. did not pass) order validation. Since there are many potential reasons, some Mesh-specific, others 0x-specific and others due to external factors (i.e., network disruptions, etc...), we categorize them into `Kind`s and uniquely identify the reasons for machines with a `Code`

type RejectedOrderKind Uses

type RejectedOrderKind string

RejectedOrderKind enumerates all kinds of reasons an order could be rejected by Mesh

type RejectedOrderStatus Uses

type RejectedOrderStatus struct {
    Code    string `json:"code"`
    Message string `json:"message"`

RejectedOrderStatus enumerates all the unique reasons for an orders rejection

type ValidationResults Uses

type ValidationResults struct {
    Accepted []*AcceptedOrderInfo `json:"accepted"`
    Rejected []*RejectedOrderInfo `json:"rejected"`

ValidationResults defines the validation results returned from BatchValidate Within this context, an order is `Accepted` if it passes all the 0x schema tests and is fillable for a non-zero amount. An order is `Rejected` if it does not satisfy these conditions OR if we were unable to complete the validation process for whatever reason

Package ordervalidator imports 18 packages (graph) and is imported by 5 packages. Updated 2020-09-27. Refresh now. Tools for package owners.