From 2fcac993d0e7b9196ff98b6d5a17acf23f1740c7 Mon Sep 17 00:00:00 2001 From: avalonche Date: Mon, 10 Jul 2023 16:04:35 +1000 Subject: [PATCH] linting --- spec/versionedsubmitblockrequest.go | 37 ++++++++++++------------ spec/versionedsubmitblockrequest_test.go | 19 ++++++------ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/spec/versionedsubmitblockrequest.go b/spec/versionedsubmitblockrequest.go index c50be99..9c60e4b 100644 --- a/spec/versionedsubmitblockrequest.go +++ b/spec/versionedsubmitblockrequest.go @@ -20,6 +20,7 @@ import ( "github.com/attestantio/go-builder-client/api/bellatrix" "github.com/attestantio/go-builder-client/api/capella" + v1 "github.com/attestantio/go-builder-client/api/v1" consensusspec "github.com/attestantio/go-eth2-client/spec" consensusbellatrix "github.com/attestantio/go-eth2-client/spec/bellatrix" consensuscapella "github.com/attestantio/go-eth2-client/spec/capella" @@ -46,7 +47,7 @@ func (v *VersionedSubmitBlockRequest) IsEmpty() bool { } } -// Slot returns the slot of the request +// Slot returns the slot of the request. func (v *VersionedSubmitBlockRequest) Slot() (uint64, error) { if v == nil { return 0, errors.New("nil struct") @@ -235,30 +236,30 @@ func (v *VersionedSubmitBlockRequest) Value() (*uint256.Int, error) { } } -// MessageHashTreeRoot returns the hash tree root of the message of the bid. -func (v *VersionedSubmitBlockRequest) MessageHashTreeRoot() (phase0.Root, error) { +// BidTrace returns the bid trace of the request. +func (v *VersionedSubmitBlockRequest) BidTrace() (*v1.BidTrace, error) { if v == nil { - return phase0.Root{}, errors.New("nil struct") + return nil, errors.New("nil struct") } switch v.Version { case consensusspec.DataVersionBellatrix: if v.Bellatrix == nil { - return phase0.Root{}, errors.New("no data") + return nil, errors.New("no data") } if v.Bellatrix.Message == nil { - return phase0.Root{}, errors.New("no data message") + return nil, errors.New("no data message") } - return v.Bellatrix.Message.HashTreeRoot() + return v.Bellatrix.Message, nil case consensusspec.DataVersionCapella: if v.Capella == nil { - return phase0.Root{}, errors.New("no data") + return nil, errors.New("no data") } if v.Capella.Message == nil { - return phase0.Root{}, errors.New("no data message") + return nil, errors.New("no data message") } - return v.Capella.Message.HashTreeRoot() + return v.Capella.Message, nil default: - return phase0.Root{}, errors.New("unsupported version") + return nil, errors.New("unsupported version") } } @@ -283,7 +284,7 @@ func (v *VersionedSubmitBlockRequest) Signature() (phase0.BLSSignature, error) { } } -// ExecutionPayloadBlockHash returns the block hash of the payload +// ExecutionPayloadBlockHash returns the block hash of the payload. func (v *VersionedSubmitBlockRequest) ExecutionPayloadBlockHash() (phase0.Hash32, error) { if v == nil { return phase0.Hash32{}, errors.New("nil struct") @@ -310,7 +311,7 @@ func (v *VersionedSubmitBlockRequest) ExecutionPayloadBlockHash() (phase0.Hash32 } } -// ExecutionPayloadParentHash returns the block hash of the payload +// ExecutionPayloadParentHash returns the block hash of the payload. func (v *VersionedSubmitBlockRequest) ExecutionPayloadParentHash() (phase0.Hash32, error) { if v == nil { return phase0.Hash32{}, errors.New("nil struct") @@ -337,7 +338,7 @@ func (v *VersionedSubmitBlockRequest) ExecutionPayloadParentHash() (phase0.Hash3 } } -// PrevRandao returns the prev randao of the payload +// PrevRandao returns the prev randao of the payload. func (v *VersionedSubmitBlockRequest) PrevRandao() (phase0.Hash32, error) { if v == nil { return phase0.Hash32{}, errors.New("nil struct") @@ -364,7 +365,7 @@ func (v *VersionedSubmitBlockRequest) PrevRandao() (phase0.Hash32, error) { } } -// GasLimit returns the prev randao of the payload +// GasLimit returns the prev randao of the payload. func (v *VersionedSubmitBlockRequest) GasLimit() (uint64, error) { if v == nil { return 0, errors.New("nil struct") @@ -391,7 +392,7 @@ func (v *VersionedSubmitBlockRequest) GasLimit() (uint64, error) { } } -// GasUsed returns the prev randao of the payload +// GasUsed returns the prev randao of the payload. func (v *VersionedSubmitBlockRequest) GasUsed() (uint64, error) { if v == nil { return 0, errors.New("nil struct") @@ -472,7 +473,7 @@ func (v *VersionedSubmitBlockRequest) Timestamp() (uint64, error) { } } -// Transactions returns the transactions of the payload +// Transactions returns the transactions of the payload. func (v *VersionedSubmitBlockRequest) Transactions() ([]consensusbellatrix.Transaction, error) { if v == nil { return nil, errors.New("nil struct") @@ -499,7 +500,7 @@ func (v *VersionedSubmitBlockRequest) Transactions() ([]consensusbellatrix.Trans } } -// Withdrawals returns the withdrawals of the payload +// Withdrawals returns the withdrawals of the payload. func (v *VersionedSubmitBlockRequest) Withdrawals() ([]*consensuscapella.Withdrawal, error) { if v == nil { return nil, errors.New("nil struct") diff --git a/spec/versionedsubmitblockrequest_test.go b/spec/versionedsubmitblockrequest_test.go index b663207..3c0a085 100644 --- a/spec/versionedsubmitblockrequest_test.go +++ b/spec/versionedsubmitblockrequest_test.go @@ -19,6 +19,7 @@ import ( "github.com/attestantio/go-builder-client/api/bellatrix" "github.com/attestantio/go-builder-client/api/capella" apiv1 "github.com/attestantio/go-builder-client/api/v1" + v1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-builder-client/spec" consensusspec "github.com/attestantio/go-eth2-client/spec" consensusbellatrix "github.com/attestantio/go-eth2-client/spec/bellatrix" @@ -737,11 +738,11 @@ func TestVersionedSubmitBlockRequestValue(t *testing.T) { } } -func TestVersionedSubmitBlockRequestMessageHashTreeRoot(t *testing.T) { +func TestVersionedSubmitBlockRequestBidTrace(t *testing.T) { tests := []struct { name string request *spec.VersionedSubmitBlockRequest - res phase0.Root + res *v1.BidTrace err string }{ { @@ -780,9 +781,9 @@ func TestVersionedSubmitBlockRequestMessageHashTreeRoot(t *testing.T) { }, }, }, - res: phase0.Root{ - 0x6e, 0x21, 0x57, 0xbe, 0x11, 0xe5, 0xda, 0xc3, 0x30, 0x6b, 0xd6, 0x41, 0x61, 0x17, 0x93, 0x30, - 0x53, 0xe8, 0x7d, 0x66, 0xb2, 0xfc, 0xcd, 0x7b, 0xd1, 0x7f, 0x27, 0xee, 0x90, 0xb4, 0x6c, 0x7c, + res: &v1.BidTrace{ + Slot: 123, + Value: uint256.NewInt(12345), }, }, { @@ -810,16 +811,16 @@ func TestVersionedSubmitBlockRequestMessageHashTreeRoot(t *testing.T) { }, }, }, - res: phase0.Root{ - 0x6e, 0x21, 0x57, 0xbe, 0x11, 0xe5, 0xda, 0xc3, 0x30, 0x6b, 0xd6, 0x41, 0x61, 0x17, 0x93, 0x30, - 0x53, 0xe8, 0x7d, 0x66, 0xb2, 0xfc, 0xcd, 0x7b, 0xd1, 0x7f, 0x27, 0xee, 0x90, 0xb4, 0x6c, 0x7c, + res: &v1.BidTrace{ + Slot: 123, + Value: uint256.NewInt(12345), }, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - res, err := test.request.MessageHashTreeRoot() + res, err := test.request.BidTrace() if test.err != "" { require.EqualError(t, err, test.err) } else {