diff --git a/cmd/beacondeposit.go b/cmd/beacondeposit.go index 1884133..b948712 100644 --- a/cmd/beacondeposit.go +++ b/cmd/beacondeposit.go @@ -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 @@ -57,6 +57,7 @@ var ( beaconDepositContractAddress string beaconDepositEth2Network string beaconDepositOverrideGas uint64 + beaconDepositJson bool ) type beaconDepositContract struct { @@ -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 + 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") @@ -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", @@ -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") } diff --git a/cmd/version.go b/cmd/version.go index 538a622..b0809cd 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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 { diff --git a/conn/conn.go b/conn/conn.go index 8ab62d9..61d0b49 100644 --- a/conn/conn.go +++ b/conn/conn.go @@ -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") diff --git a/go.mod b/go.mod index 22c72b2..4f0ba51 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index bd8d157..849b921 100644 --- a/go.sum +++ b/go.sum @@ -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=