Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Handle null fee asset data in browser bindings #579

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions zeroex/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ func (s SignedOrder) MarshalJSON() ([]byte, error) {
if len(s.MakerAssetData) != 0 {
makerAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(s.MakerAssetData))
}
// Note(albrow): Because of how our smart contracts work, most fields of an
// order cannot be null. However, makerAssetFeeData and takerAssetFeeData are
// the exception. For these fields, "0x" is used to indicate a null value.
makerFeeAssetData := "0x"
if len(s.MakerFeeAssetData) != 0 {
makerFeeAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(s.MakerFeeAssetData))
Expand Down
22 changes: 13 additions & 9 deletions zeroex/order_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"syscall/js"

"github.com/ethereum/go-ethereum/common"
)

Expand All @@ -17,7 +18,7 @@ func (o OrderEvent) JSValue() js.Value {
return js.ValueOf(map[string]interface{}{
"orderHash": o.OrderHash.Hex(),
"signedOrder": o.SignedOrder.JSValue(),
"endState": string(o.EndState),
"endState": string(o.EndState),
"fillableTakerAssetAmount": o.FillableTakerAssetAmount.String(),
"contractEvents": contractEventsJS,
})
Expand All @@ -28,15 +29,18 @@ func (s SignedOrder) JSValue() js.Value {
if len(s.MakerAssetData) != 0 {
makerAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(s.MakerAssetData))
}
makerFeeAssetData := ""
// Note(albrow): Because of how our smart contracts work, most fields of an
// order cannot be null. However, makerAssetFeeData and takerAssetFeeData are
// the exception. For these fields, "0x" is used to indicate a null value.
makerFeeAssetData := "0x"
if len(s.MakerFeeAssetData) != 0 {
makerFeeAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(s.MakerFeeAssetData))
}
takerAssetData := ""
if len(s.TakerAssetData) != 0 {
takerAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(s.TakerAssetData))
}
takerFeeAssetData := ""
takerFeeAssetData := "0x"
if len(s.TakerFeeAssetData) != 0 {
takerFeeAssetData = fmt.Sprintf("0x%s", common.Bytes2Hex(s.TakerFeeAssetData))
}
Expand Down Expand Up @@ -68,12 +72,12 @@ func (s SignedOrder) JSValue() js.Value {

func (c ContractEvent) JSValue() js.Value {
m := map[string]interface{}{
"blockHash": c.BlockHash.Hex(),
"txHash": c.TxHash.Hex(),
"txIndex": c.TxIndex,
"logIndex": c.LogIndex,
"isRemoved": c.IsRemoved,
"kind": c.Kind,
"blockHash": c.BlockHash.Hex(),
"txHash": c.TxHash.Hex(),
"txIndex": c.TxIndex,
"logIndex": c.LogIndex,
"isRemoved": c.IsRemoved,
"kind": c.Kind,
"parameters": c.Parameters.(js.Wrapper).JSValue(),
}
return js.ValueOf(m)
Expand Down