• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lmittmann / w3 / 12712430872

10 Jan 2025 03:13PM UTC coverage: 64.258% (-0.04%) from 64.3%
12712430872

Pull #207

github

lmittmann
fix
Pull Request #207: w3vm: fix tx coinbase tip

1 of 1 new or added line in 1 file covered. (100.0%)

16 existing lines in 1 file now uncovered.

1992 of 3100 relevant lines covered (64.26%)

810.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/w3types/message.go
1
package w3types
2

3
import (
4
        "encoding/json"
5
        "math/big"
6

7
        "github.com/ethereum/go-ethereum"
8
        "github.com/ethereum/go-ethereum/common"
9
        "github.com/ethereum/go-ethereum/common/hexutil"
10
        "github.com/ethereum/go-ethereum/core/types"
11
)
12

13
// Message represents a transaction without the signature.
14
//
15
// If no input data is given, but Func is not null, the input data is
16
// automatically encoded from the given Func and Args arguments by many
17
// functions that accept a Message struct as an argument.
18
type Message struct {
19
        From          common.Address  // Sender
20
        To            *common.Address // Recipient
21
        Nonce         uint64
22
        GasPrice      *big.Int
23
        GasFeeCap     *big.Int
24
        GasTipCap     *big.Int
25
        Gas           uint64
26
        Value         *big.Int
27
        Input         []byte // Input data
28
        AccessList    types.AccessList
29
        BlobGasFeeCap *big.Int
30
        BlobHashes    []common.Hash
31

32
        Func Func  // Func to encode
33
        Args []any // Arguments for Func
34
}
35

36
// Set sets msg to the given Message and returns it.
37
func (msg *Message) Set(msg2 *Message) *Message {
×
38
        msg.From = msg2.From
×
39
        msg.To = msg2.To
×
40
        msg.Nonce = msg2.Nonce
×
41
        msg.GasPrice = msg2.GasPrice
×
42
        msg.GasFeeCap = msg2.GasFeeCap
×
43
        msg.GasTipCap = msg2.GasTipCap
×
44
        msg.Gas = msg2.Gas
×
45
        msg.Value = msg2.Value
×
46
        msg.Input = msg2.Input
×
47
        msg.AccessList = msg2.AccessList
×
48
        msg.BlobGasFeeCap = msg2.BlobGasFeeCap
×
49
        msg.BlobHashes = msg2.BlobHashes
×
50
        msg.Func = msg2.Func
×
51
        msg.Args = msg2.Args
×
52
        return msg
×
53
}
×
54

55
// SetTx sets msg to the [types.Transaction] tx and returns msg.
56
func (msg *Message) SetTx(tx *types.Transaction, signer types.Signer) (*Message, error) {
×
57
        from, err := types.Sender(signer, tx)
×
58
        if err != nil {
×
59
                return nil, err
×
60
        }
×
61

62
        msg.From = from
×
63
        msg.To = tx.To()
×
64
        msg.Nonce = tx.Nonce()
×
65
        msg.GasPrice = tx.GasPrice()
×
66
        msg.GasFeeCap = tx.GasFeeCap()
×
67
        msg.GasTipCap = tx.GasTipCap()
×
68
        msg.Gas = tx.Gas()
×
69
        msg.Value = tx.Value()
×
70
        msg.Input = tx.Data()
×
71
        msg.AccessList = tx.AccessList()
×
72
        msg.BlobGasFeeCap = tx.BlobGasFeeCap()
×
73
        msg.BlobHashes = tx.BlobHashes()
×
74
        return msg, nil
×
75
}
76

77
// MustSetTx is like [SetTx] but panics if the sender retrieval fails.
78
func (msg *Message) MustSetTx(tx *types.Transaction, signer types.Signer) *Message {
×
79
        msg, err := msg.SetTx(tx, signer)
×
80
        if err != nil {
×
81
                panic(err)
×
82
        }
83
        return msg
×
84
}
85

86
// SetCallMsg sets msg to the [ethereum.CallMsg] callMsg and returns msg.
87
func (msg *Message) SetCallMsg(callMsg ethereum.CallMsg) *Message {
×
88
        msg.From = callMsg.From
×
89
        msg.To = callMsg.To
×
90
        msg.Gas = callMsg.Gas
×
91
        msg.GasPrice = callMsg.GasPrice
×
92
        msg.GasFeeCap = callMsg.GasFeeCap
×
93
        msg.GasTipCap = callMsg.GasTipCap
×
94
        msg.Value = callMsg.Value
×
95
        msg.Input = callMsg.Data
×
96
        msg.AccessList = callMsg.AccessList
×
97
        msg.BlobGasFeeCap = callMsg.BlobGasFeeCap
×
98
        msg.BlobHashes = callMsg.BlobHashes
×
99
        return msg
×
100
}
×
101

102
type message struct {
103
        From          *common.Address  `json:"from,omitempty"`
104
        To            *common.Address  `json:"to,omitempty"`
105
        Nonce         hexutil.Uint64   `json:"nonce,omitempty"`
106
        GasPrice      *hexutil.Big     `json:"gasPrice,omitempty"`
107
        GasFeeCap     *hexutil.Big     `json:"maxFeePerGas,omitempty"`
108
        GasTipCap     *hexutil.Big     `json:"maxPriorityFeePerGas,omitempty"`
109
        Gas           hexutil.Uint64   `json:"gas,omitempty"`
110
        Value         *hexutil.Big     `json:"value,omitempty"`
111
        Input         hexutil.Bytes    `json:"data,omitempty"`
112
        AccessList    types.AccessList `json:"accessList,omitempty"`
113
        BlobGasFeeCap *hexutil.Big     `json:"maxFeePerBlobGas,omitempty"`
114
        BlobHashes    []common.Hash    `json:"blobVersionedHashes,omitempty"`
115
}
116

117
// MarshalJSON implements the [json.Marshaler].
118
func (msg *Message) MarshalJSON() ([]byte, error) {
×
119
        var enc message
×
120
        if msg.From != (common.Address{}) {
×
121
                enc.From = &msg.From
×
122
        }
×
123
        enc.To = msg.To
×
124
        enc.Nonce = hexutil.Uint64(msg.Nonce)
×
125
        if msg.GasPrice != nil {
×
126
                enc.GasPrice = (*hexutil.Big)(msg.GasPrice)
×
127
        }
×
128
        if msg.GasFeeCap != nil {
×
129
                enc.GasFeeCap = (*hexutil.Big)(msg.GasFeeCap)
×
130
        }
×
131
        if msg.GasTipCap != nil {
×
132
                enc.GasTipCap = (*hexutil.Big)(msg.GasTipCap)
×
133
        }
×
134
        if msg.Gas > 0 {
×
135
                enc.Gas = hexutil.Uint64(msg.Gas)
×
136
        }
×
137
        if msg.Value != nil {
×
138
                enc.Value = (*hexutil.Big)(msg.Value)
×
139
        }
×
140
        if len(msg.Input) > 0 {
×
141
                enc.Input = msg.Input
×
142
        }
×
143
        if len(msg.AccessList) > 0 {
×
144
                enc.AccessList = msg.AccessList
×
145
        }
×
146
        if msg.BlobGasFeeCap != nil {
×
147
                enc.BlobGasFeeCap = (*hexutil.Big)(msg.BlobGasFeeCap)
×
148
        }
×
149
        if len(msg.BlobHashes) > 0 {
×
150
                enc.BlobHashes = msg.BlobHashes
×
151
        }
×
152
        return json.Marshal(&enc)
×
153
}
154

155
// UnmarshalJSON implements the [json.Unmarshaler].
156
func (msg *Message) UnmarshalJSON(data []byte) error {
×
157
        var dec message
×
158
        if err := json.Unmarshal(data, &dec); err != nil {
×
159
                return err
×
160
        }
×
161

162
        if dec.From != nil {
×
163
                msg.From = *dec.From
×
164
        }
×
165
        msg.To = dec.To
×
166
        msg.Nonce = uint64(dec.Nonce)
×
167
        if dec.GasPrice != nil {
×
168
                msg.GasPrice = (*big.Int)(dec.GasPrice)
×
169
        }
×
170
        if dec.GasFeeCap != nil {
×
171
                msg.GasFeeCap = (*big.Int)(dec.GasFeeCap)
×
172
        }
×
173
        if dec.GasTipCap != nil {
×
174
                msg.GasTipCap = (*big.Int)(dec.GasTipCap)
×
175
        }
×
176
        msg.Gas = uint64(dec.Gas)
×
177
        if dec.Value != nil {
×
178
                msg.Value = (*big.Int)(dec.Value)
×
179
        }
×
180
        if len(dec.Input) > 0 {
×
181
                msg.Input = dec.Input
×
182
        }
×
183
        if len(dec.AccessList) > 0 {
×
184
                msg.AccessList = dec.AccessList
×
185
        }
×
186
        if dec.BlobGasFeeCap != nil {
×
187
                msg.BlobGasFeeCap = (*big.Int)(dec.BlobGasFeeCap)
×
188
        }
×
189
        if len(dec.BlobHashes) > 0 {
×
190
                msg.BlobHashes = dec.BlobHashes
×
191
        }
×
192
        return nil
×
193
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc