Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchon committed Oct 17, 2020
2 parents cce557c + 693f945 commit adc7d9d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var eip712OrderTypes = gethsigner.Types{
Type: "address",
},
},
"Order": {
"ZOrder": {
{
Name: "makerAddress",
Type: "address",
Expand Down
16 changes: 8 additions & 8 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
Orders: make([]*Order, 1),
Orders: make([]*ZOrder, 1),
TakerAssetFillAmounts: make([]*big.Int, 1),
Signatures: make([][]byte, 1),
}
Expand All @@ -124,7 +124,7 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
Orders: make([]*Order, len(inputs.Orders)),
Orders: make([]*ZOrder, len(inputs.Orders)),
TakerAssetFillAmounts: make([]*big.Int, len(inputs.TakerAssetFillAmounts)),
Signatures: make([][]byte, len(inputs.Signatures)),
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
Orders: make([]*Order, len(inputs.Orders)),
Orders: make([]*ZOrder, len(inputs.Orders)),
Signatures: make([][]byte, len(inputs.Signatures)),
}
for idx, order := range inputs.Orders {
Expand All @@ -179,7 +179,7 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
Orders: make([]*Order, len(inputs.Orders)),
Orders: make([]*ZOrder, len(inputs.Orders)),
Signatures: make([][]byte, len(inputs.Signatures)),
}
for idx, order := range inputs.Orders {
Expand All @@ -204,7 +204,7 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
Orders: make([]*Order, 1),
Orders: make([]*ZOrder, 1),
}
txData.Orders[0] = FromTrimmedOrder(inputs.Order)

Expand All @@ -220,7 +220,7 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
Orders: make([]*Order, len(inputs.Orders)),
Orders: make([]*ZOrder, len(inputs.Orders)),
}
for idx, order := range inputs.Orders {
txData.Orders[idx] = FromTrimmedOrder(order)
Expand All @@ -239,8 +239,8 @@ func DecodeFromTransactionData(data []byte) (txData *ZeroExTransactionData, err

txData = &ZeroExTransactionData{
FunctionName: ExchangeFunctionName(method.Name),
LeftOrders: make([]*Order, len(inputs.LeftOrders)),
RightOrders: make([]*Order, len(inputs.RightOrders)),
LeftOrders: make([]*ZOrder, len(inputs.LeftOrders)),
RightOrders: make([]*ZOrder, len(inputs.RightOrders)),
LeftSignatures: make([][]byte, len(inputs.LeftSignatures)),
RightSignatures: make([][]byte, len(inputs.RightSignatures)),
}
Expand Down
34 changes: 17 additions & 17 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/InjectiveLabs/zeroex-go/wrappers"
)

// Order represents an unsigned 0x order
type Order struct {
// ZOrder represents an unsigned 0x order
type ZOrder struct {
ChainID *big.Int `json:"chainId"`
ExchangeAddress common.Address `json:"exchangeAddress"`
MakerAddress common.Address `json:"makerAddress"`
Expand All @@ -41,17 +41,17 @@ type Order struct {

// SignedOrder represents a signed 0x order
type SignedOrder struct {
Order
ZOrder
Signature []byte `json:"signature"`
}

// ResetHash resets the cached order hash. Usually only required for testing.
func (o *Order) ResetHash() {
func (o *ZOrder) ResetHash() {
o.hash = nil
}

// ComputeOrderHash computes a 0x order hash
func (o *Order) ComputeOrderHash() (common.Hash, error) {
func (o *ZOrder) ComputeOrderHash() (common.Hash, error) {
if o.hash != nil {
return *o.hash, nil
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func (o *Order) ComputeOrderHash() (common.Hash, error) {

var typedData = gethsigner.TypedData{
Types: eip712OrderTypes,
PrimaryType: "Order",
PrimaryType: "ZOrder",
Domain: domain,
Message: message,
}
Expand All @@ -109,7 +109,7 @@ func (o *Order) ComputeOrderHash() (common.Hash, error) {
}

// SignOrder signs the 0x order with the supplied Signer.
func SignOrder(signer Signer, order *Order) (*SignedOrder, error) {
func SignOrder(signer Signer, order *ZOrder) (*SignedOrder, error) {
if order == nil {
return nil, errors.New("cannot sign nil order")
}
Expand All @@ -131,7 +131,7 @@ func SignOrder(signer Signer, order *Order) (*SignedOrder, error) {
copy(signature[33:65], ecSignature.S[:])
signature[65] = byte(EthSignSignature)
signedOrder := &SignedOrder{
Order: *order,
ZOrder: *order,
Signature: signature,
}

Expand Down Expand Up @@ -159,8 +159,8 @@ func (s *SignedOrder) Trim() wrappers.Order {
}
}

func FromTrimmedOrder(order wrappers.Order) *Order {
return &Order{
func FromTrimmedOrder(order wrappers.Order) *ZOrder {
return &ZOrder{
MakerAddress: order.MakerAddress,
MakerAssetData: order.MakerAssetData,
MakerFeeAssetData: order.MakerFeeAssetData,
Expand All @@ -178,7 +178,7 @@ func FromTrimmedOrder(order wrappers.Order) *Order {
}
}

// TrimmedOrderJSON is an unmodified JSON representation of a Trimmed Order
// TrimmedOrderJSON is an unmodified JSON representation of a Trimmed ZOrder
type TrimmedOrderJSON struct {
MakerAddress string `json:"makerAddress"`
MakerAssetData string `json:"makerAssetData"`
Expand All @@ -196,8 +196,8 @@ type TrimmedOrderJSON struct {
Salt string `json:"salt"`
}

// MarshalJSON implements a custom JSON marshaller for the Order type into Trimmed Order
func (o *Order) MarshalIntoTrimmedOrderJSON() ([]byte, error) {
// MarshalJSON implements a custom JSON marshaller for the ZOrder type into Trimmed ZOrder
func (o *ZOrder) MarshalIntoTrimmedOrderJSON() ([]byte, error) {
makerAssetData := "0x"
if len(o.MakerAssetData) != 0 {
makerAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(o.MakerAssetData))
Expand Down Expand Up @@ -366,13 +366,13 @@ func (s *SignedOrder) UnmarshalJSON(data []byte) error {
return nil
}

// OrderStatus represents the status of an order as returned from the 0x smart contracts
// ZOrderStatus represents the status of an order as returned from the 0x smart contracts
// as part of OrderInfo
type OrderStatus uint8
type ZOrderStatus uint8

// OrderStatus values
// ZOrderStatus values
const (
OSInvalid OrderStatus = iota
OSInvalid ZOrderStatus = iota
OSInvalidMakerAssetAmount
OSInvalidTakerAssetAmount
OSFillable
Expand Down
6 changes: 3 additions & 3 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (tx *Transaction) ComputeTransactionHash() (common.Hash, error) {

type ZeroExTransactionData struct {
FunctionName ExchangeFunctionName
Orders []*Order
LeftOrders []*Order
RightOrders []*Order
Orders []*ZOrder
LeftOrders []*ZOrder
RightOrders []*ZOrder
TakerAssetFillAmounts []*big.Int
MakerAssetFillAmount *big.Int
TakerAssetFillAmount *big.Int
Expand Down
Loading

0 comments on commit adc7d9d

Please sign in to comment.