-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement custom data types decoder (#8)
* fix(data): add custom decoder logic for returned objects Signed-off-by: Luca Georges Francois <[email protected]> * refactor(data): update struct names Signed-off-by: Luca Georges Francois <[email protected]> --------- Signed-off-by: Luca Georges Francois <[email protected]>
- Loading branch information
1 parent
c271633
commit ff34019
Showing
2 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,106 @@ | ||
package v1 | ||
|
||
import ( | ||
"encoding/json" | ||
"math/big" | ||
"time" | ||
|
||
v1 "github.com/attestantio/go-builder-client/api/v1" | ||
) | ||
|
||
type BidsDelivered struct { | ||
v1.BidTrace | ||
|
||
type BidDeliveredMeta struct { | ||
BlockNumber *big.Int `json:"block_number"` | ||
NumTx uint `json:"num_tx"` | ||
} | ||
|
||
type BidsReceived struct { | ||
type bidDeliveredMetaJSON struct { | ||
BlockNumber string `json:"block_number"` | ||
NumTx uint `json:"num_tx,string"` | ||
} | ||
|
||
type BidDelivered struct { | ||
v1.BidTrace | ||
BidDeliveredMeta | ||
} | ||
|
||
func (b *BidDelivered) UnmarshalJSON(input []byte) error { | ||
bt := new(v1.BidTrace) | ||
|
||
if err := json.Unmarshal(input, bt); err != nil { | ||
return err | ||
} | ||
|
||
br := new(bidDeliveredMetaJSON) | ||
|
||
if err := json.Unmarshal(input, br); err != nil { | ||
return err | ||
} | ||
|
||
b.Slot = bt.Slot | ||
b.ParentHash = bt.ParentHash | ||
b.BlockHash = bt.BlockHash | ||
b.BuilderPubkey = bt.BuilderPubkey | ||
b.ProposerPubkey = bt.ProposerPubkey | ||
b.ProposerFeeRecipient = bt.ProposerFeeRecipient | ||
b.GasLimit = bt.GasLimit | ||
b.GasUsed = bt.GasUsed | ||
b.Value = bt.Value | ||
|
||
b.BlockNumber = big.NewInt(0).SetBytes([]byte(br.BlockNumber)) | ||
b.NumTx = br.NumTx | ||
|
||
return nil | ||
} | ||
|
||
type BidReceivedMeta struct { | ||
BlockNumber *big.Int | ||
NumTx uint | ||
Timestamp time.Time | ||
TimestampMs time.Time | ||
OptimisticSubmission bool | ||
} | ||
|
||
type bidReceivedMetaJSON struct { | ||
BlockNumber string `json:"block_number"` | ||
NumTx uint `json:"num_tx,string"` | ||
Timestamp int64 `json:"timestamp,string"` | ||
TimestampMs int64 `json:"timestamp_ms,string"` | ||
OptimisticSubmission bool `json:"optimistic_submission"` | ||
} | ||
|
||
type BidReceived struct { | ||
v1.BidTrace | ||
BidReceivedMeta | ||
} | ||
|
||
func (b *BidReceived) UnmarshalJSON(input []byte) error { | ||
bt := new(v1.BidTrace) | ||
|
||
if err := json.Unmarshal(input, bt); err != nil { | ||
return err | ||
} | ||
|
||
br := new(bidReceivedMetaJSON) | ||
|
||
if err := json.Unmarshal(input, br); err != nil { | ||
return err | ||
} | ||
|
||
b.Slot = bt.Slot | ||
b.ParentHash = bt.ParentHash | ||
b.BlockHash = bt.BlockHash | ||
b.BuilderPubkey = bt.BuilderPubkey | ||
b.ProposerPubkey = bt.ProposerPubkey | ||
b.ProposerFeeRecipient = bt.ProposerFeeRecipient | ||
b.GasLimit = bt.GasLimit | ||
b.GasUsed = bt.GasUsed | ||
b.Value = bt.Value | ||
|
||
b.BlockNumber = big.NewInt(0).SetBytes([]byte(br.BlockNumber)) | ||
b.NumTx = br.NumTx | ||
b.Timestamp = time.Unix(br.Timestamp, 0) | ||
b.TimestampMs = time.Unix(br.Timestamp, (br.Timestamp%1_000)*1_000_000) | ||
b.OptimisticSubmission = br.OptimisticSubmission | ||
|
||
BlockNumber *big.Int `json:"block_number"` | ||
NumTx uint `json:"num_tx"` | ||
Timestamp uint64 `json:"timestamp"` | ||
TimestampMs uint64 `json:"timestamp_ms"` | ||
OptimisticSubmission bool `json:"optimistic_submission"` | ||
return nil | ||
} |