Skip to content

Commit

Permalink
Add --json option for beacon deposits.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Mar 19, 2024
1 parent ba04e67 commit a0a3a42
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
19 changes: 17 additions & 2 deletions cmd/beacondeposit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017-2022 Weald Technology Trading
// Copyright © 2017-2024 Weald Technology Trading
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -57,6 +57,7 @@ var (
beaconDepositContractAddress string
beaconDepositEth2Network string
beaconDepositOverrideGas uint64
beaconDepositJson bool

Check warning on line 60 in cmd/beacondeposit.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var beaconDepositJson should be beaconDepositJSON (revive)
)

type beaconDepositContract struct {
Expand Down Expand Up @@ -309,7 +310,11 @@ func sendOnline(ctx context.Context, deposits []*util.DepositInfo, contractDetai
cli.ErrCheck(graphCheck(ctx, contractDetails.subgraph, deposit.PublicKey, opts.Value.Uint64(), deposit.WithdrawalCredentials), quiet, "Existing deposit check")
}

outputIf(verbose, fmt.Sprintf("Creating %s deposit for %s", string2eth.WeiToString(big.NewInt(int64(deposit.Amount)), true), deposit.Account))
accountId := deposit.Account

Check warning on line 313 in cmd/beacondeposit.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var accountId should be accountID (revive)
if accountId == "" {
accountId = fmt.Sprintf("%#x", deposit.PublicKey)
}
outputIf(verbose, fmt.Sprintf("Creating %s deposit for %s", string2eth.WeiToString(big.NewInt(int64(deposit.Amount)), true), accountId))

_, err = c.NextNonce(context.Background(), fromAddress)
cli.ErrCheck(err, quiet, "Failed to obtain next nonce")
Expand All @@ -319,9 +324,18 @@ func sendOnline(ctx context.Context, deposits []*util.DepositInfo, contractDetai
opts.GasFeeCap, opts.GasTipCap, err = c.CalculateFees()
cli.ErrCheck(err, quiet, "Failed to obtain fees")

opts.NoSend = beaconDepositJson
signedTx, err := contract.Deposit(opts, deposit.PublicKey, deposit.WithdrawalCredentials, deposit.Signature, depositDataRoot)
cli.ErrCheck(err, quiet, "Failed to send deposit")

if beaconDepositJson {
data, err := json.Marshal(signedTx)
cli.ErrCheck(err, quiet, "Failed to marshal transaction")
fmt.Fprintf(os.Stdout, "%s\n", string(data))

return
}

handleSubmittedTransaction(signedTx, log.Fields{
"group": "beacon",
"command": "deposit",
Expand Down Expand Up @@ -464,5 +478,6 @@ func init() {
beaconDepositCmd.Flags().StringVar(&beaconDepositContractAddress, "address", "", "The contract address to which to send the deposit (overrides the value obtained from eth2network)")
beaconDepositCmd.Flags().StringVar(&beaconDepositEth2Network, "eth2network", "mainnet", "The name of the Ethereum 2 network for which to send the deposit (mainnet/prater/holesky/sepolia)")
beaconDepositCmd.Flags().Uint64Var(&beaconDepositOverrideGas, "override-gas", 0, "Override the gas limit for the deposit transaction")
beaconDepositCmd.Flags().BoolVar(&beaconDepositJson, "json", false, "Print the deposit transaction(s) as JSON rather than broadcast them")
addTransactionFlags(beaconDepositCmd, "the account from which to send the deposit")
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{
ethereal version.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("2.9.0")
fmt.Println("2.9.1")
if viper.GetBool("verbose") {
buildInfo, ok := dbg.ReadBuildInfo()
if ok {
Expand Down
2 changes: 1 addition & 1 deletion conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func New(ctx context.Context, url string) (*Conn, error) {
// Fetch chain ID to confirm connection.
chainID, err := client.ChainID(ctx)
if err != nil {
return nil, errors.New("unable to contact client")
return nil, errors.Wrap(err, "unable to contact client")
}

timeout := viper.GetDuration("timeout")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/antlr4-go/antlr/v4 v4.13.0
github.com/attestantio/go-execution-client v0.8.10
github.com/attestantio/go-execution-client v0.9.0
github.com/ethereum/go-ethereum v1.13.10
github.com/miekg/dns v1.1.57
github.com/mitchellh/go-homedir v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/attestantio/go-execution-client v0.8.10 h1:PA8JsfOvz2UPOQYcQbYeeSfyrkOHp0Ca+L5Z9+nJbUU=
github.com/attestantio/go-execution-client v0.8.10/go.mod h1:IKw0ev7ESktmlGrvyciLzCxJO0d3omUiLD7XmT9URag=
github.com/attestantio/go-execution-client v0.9.0 h1:e5odnYRbMLfcJTvSpztjXRN9EvCpNUcQpif8wT/VqR8=
github.com/attestantio/go-execution-client v0.9.0/go.mod h1:/mY2pS2/ZIOhMiaHkBm5JW67MFTm2Tqp5oLD/v20m4E=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
Expand Down

0 comments on commit a0a3a42

Please sign in to comment.