mirror of https://github.com/ethereum/go-ethereum
parent
d71831255d
commit
dbdecb55dc
@ -0,0 +1,53 @@ |
||||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package types |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"errors" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
) |
||||
|
||||
var _ = (*withdrawalRequestMarshaling)(nil) |
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (w WithdrawalRequest) MarshalJSON() ([]byte, error) { |
||||
type WithdrawalRequest struct { |
||||
Source common.Address `json:"sourceAddress"` |
||||
PublicKey hexutil.Bytes `json:"validatorPubkey"` |
||||
Amount hexutil.Uint64 `json:"amount"` |
||||
} |
||||
var enc WithdrawalRequest |
||||
enc.Source = w.Source |
||||
enc.PublicKey = w.PublicKey[:] |
||||
enc.Amount = hexutil.Uint64(w.Amount) |
||||
return json.Marshal(&enc) |
||||
} |
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (w *WithdrawalRequest) UnmarshalJSON(input []byte) error { |
||||
type WithdrawalRequest struct { |
||||
Source *common.Address `json:"sourceAddress"` |
||||
PublicKey *hexutil.Bytes `json:"validatorPubkey"` |
||||
Amount *hexutil.Uint64 `json:"amount"` |
||||
} |
||||
var dec WithdrawalRequest |
||||
if err := json.Unmarshal(input, &dec); err != nil { |
||||
return err |
||||
} |
||||
if dec.Source != nil { |
||||
w.Source = *dec.Source |
||||
} |
||||
if dec.PublicKey != nil { |
||||
if len(*dec.PublicKey) != len(w.PublicKey) { |
||||
return errors.New("field 'validatorPubkey' has wrong length, need 48 items") |
||||
} |
||||
copy(w.PublicKey[:], *dec.PublicKey) |
||||
} |
||||
if dec.Amount != nil { |
||||
w.Amount = uint64(*dec.Amount) |
||||
} |
||||
return nil |
||||
} |
@ -0,0 +1,80 @@ |
||||
// Copyright 2024 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
package types |
||||
|
||||
import ( |
||||
"bytes" |
||||
"encoding/binary" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
"github.com/ethereum/go-ethereum/rlp" |
||||
) |
||||
|
||||
//go:generate go run github.com/fjl/gencodec -type WithdrawalRequest -field-override withdrawalRequestMarshaling -out gen_withdrawal_request_json.go
|
||||
|
||||
// WithdrawalRequest represents an EIP-7002 withdrawal request from source for
|
||||
// the validator associated with the public key for amount.
|
||||
type WithdrawalRequest struct { |
||||
Source common.Address `json:"sourceAddress"` |
||||
PublicKey [48]byte `json:"validatorPubkey"` |
||||
Amount uint64 `json:"amount"` |
||||
} |
||||
|
||||
// field type overrides for gencodec
|
||||
type withdrawalRequestMarshaling struct { |
||||
PublicKey hexutil.Bytes |
||||
Amount hexutil.Uint64 |
||||
} |
||||
|
||||
func (w *WithdrawalRequest) Bytes() []byte { |
||||
out := make([]byte, 76) |
||||
copy(out, w.Source.Bytes()) |
||||
copy(out[20:], w.PublicKey[:]) |
||||
binary.LittleEndian.PutUint64(out, w.Amount) |
||||
return out |
||||
} |
||||
|
||||
// WithdrawalRequests implements DerivableList for withdrawal requests.
|
||||
type WithdrawalRequests []*WithdrawalRequest |
||||
|
||||
// Len returns the length of s.
|
||||
func (s WithdrawalRequests) Len() int { return len(s) } |
||||
|
||||
// EncodeIndex encodes the i'th withdrawal request to w.
|
||||
func (s WithdrawalRequests) EncodeIndex(i int, w *bytes.Buffer) { |
||||
rlp.Encode(w, s[i]) |
||||
} |
||||
|
||||
// Requests creates a deep copy of each deposit and returns a slice of the
|
||||
// withdrwawal requests as Request objects.
|
||||
func (s WithdrawalRequests) Requests() (reqs Requests) { |
||||
for _, d := range s { |
||||
reqs = append(reqs, NewRequest(d)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
func (w *WithdrawalRequest) requestType() byte { return WithdrawalRequestType } |
||||
func (w *WithdrawalRequest) encode(b *bytes.Buffer) error { return rlp.Encode(b, w) } |
||||
func (w *WithdrawalRequest) decode(input []byte) error { return rlp.DecodeBytes(input, w) } |
||||
func (w *WithdrawalRequest) copy() RequestData { |
||||
return &WithdrawalRequest{ |
||||
Source: w.Source, |
||||
PublicKey: w.PublicKey, |
||||
Amount: w.Amount, |
||||
} |
||||
} |
Loading…
Reference in new issue