|
5 | 5 | "context" |
6 | 6 | "crypto/ecdsa" |
7 | 7 | "encoding/json" |
| 8 | + "errors" |
8 | 9 | "fmt" |
9 | 10 | "net/http" |
10 | 11 |
|
@@ -202,6 +203,7 @@ func (s *Client) sendBundle( |
202 | 203 | if uuid != nil { |
203 | 204 | p.SetUUID(*uuid, s.senderType) |
204 | 205 | } |
| 206 | + |
205 | 207 | req.Params = append(req.Params, p) |
206 | 208 |
|
207 | 209 | reqBody, err := json.Marshal(req) |
@@ -258,11 +260,16 @@ func (s *Client) SendPrivateRawTransaction( |
258 | 260 | return SendPrivateRawTransactionResponse{}, nil |
259 | 261 | } |
260 | 262 |
|
| 263 | + txBin, err := tx.MarshalBinary() |
| 264 | + if err != nil { |
| 265 | + return SendPrivateRawTransactionResponse{}, fmt.Errorf("marshal tx binary: %w", err) |
| 266 | + } |
| 267 | + |
261 | 268 | req := SendRequest{ |
262 | 269 | ID: SendBundleID, |
263 | 270 | JSONRPC: JSONRPC2, |
264 | 271 | Method: ETHSendPrivateRawTransaction, |
265 | | - Params: []any{"0x" + txToRlp(tx)}, |
| 272 | + Params: []any{hexutil.Encode(txBin)}, |
266 | 273 | } |
267 | 274 |
|
268 | 275 | reqBody, err := json.Marshal(req) |
@@ -352,6 +359,8 @@ type SendBundleParams struct { |
352 | 359 | // (Optional) String, UUID that can be used to cancel/replace this bundle (For beaverbuild) |
353 | 360 | UUID string `json:"uuid,omitempty"` |
354 | 361 | StateBlockNumber string `json:"stateBlockNumber,omitempty"` |
| 362 | + |
| 363 | + Errors []error `json:"-"` // check when building bundle |
355 | 364 | } |
356 | 365 |
|
357 | 366 | func (p *SendBundleParams) SetStateBlockNumber(stateBlockNumber string) *SendBundleParams { |
@@ -383,14 +392,20 @@ func (p *SendBundleParams) SetPendingTxHashes(txHashes ...common.Hash) *SendBund |
383 | 392 | return p |
384 | 393 | } |
385 | 394 |
|
| 395 | +// tested at: https://team-kyber.slack.com/archives/C03P04E6UAW/p1754280128232029?thread_ts=1754063210.955249&cid=C03P04E6UAW |
386 | 396 | func (p *SendBundleParams) SetTransactions(txs ...*types.Transaction) *SendBundleParams { |
387 | 397 | if len(txs) == 0 { |
388 | 398 | return p |
389 | 399 | } |
390 | 400 |
|
391 | 401 | transactions := make([]string, 0, len(txs)) |
392 | 402 | for _, tx := range txs { |
393 | | - transactions = append(transactions, "0x"+txToRlp(tx)) |
| 403 | + txBin, err := tx.MarshalBinary() |
| 404 | + if err != nil { |
| 405 | + p.Errors = append(p.Errors, fmt.Errorf("marshal tx: %w", err)) |
| 406 | + } else { |
| 407 | + transactions = append(transactions, hexutil.Encode(txBin)) |
| 408 | + } |
394 | 409 | } |
395 | 410 |
|
396 | 411 | p.Txs = transactions |
@@ -420,6 +435,14 @@ func (p *SendBundleParams) SetUUID(uuid string, senderType BundleSenderType) *Se |
420 | 435 | return p |
421 | 436 | } |
422 | 437 |
|
| 438 | +func (p *SendBundleParams) Err() error { |
| 439 | + if len(p.Errors) == 0 { |
| 440 | + return nil |
| 441 | + } |
| 442 | + |
| 443 | + return errors.Join(p.Errors...) |
| 444 | +} |
| 445 | + |
423 | 446 | type CancelBundleParams struct { |
424 | 447 | ReplacementUUID string `json:"replacementUuid"` |
425 | 448 | } |
0 commit comments