Skip to content

Commit

Permalink
accounts,internal/ethapi: blob transaction api arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Mar 13, 2022
1 parent 4b0c1cb commit e9279d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion accounts/external/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,13 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
case types.BlobTxType:
hashes, _, blobs := tx.BlobWrapData()
if len(hashes) != len(blobs) {
return nil, fmt.Errorf("missing blobs data, expected %d blobs", len(hashes))
}
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
args.BlobVersionedHashes = tx.BlobVersionedHashes()
args.Blobs = blobs
default:
return nil, fmt.Errorf("unsupported tx type %d", tx.Type())
}
Expand Down
29 changes: 28 additions & 1 deletion internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"github.com/protolambda/ztyp/view"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -52,6 +53,8 @@ type TransactionArgs struct {
// Introduced by AccessListTxType transaction.
AccessList *types.AccessList `json:"accessList,omitempty"`
ChainID *hexutil.Big `json:"chainId,omitempty"`

Blobs []types.Blob `json:"blobs,omitempty"`
}

// from retrieves the transaction sender address.
Expand Down Expand Up @@ -247,7 +250,31 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
// This assumes that setDefaults has been called.
func (args *TransactionArgs) toTransaction() *types.Transaction {
var data types.TxData
var opts []types.TxOption
switch {
case args.Blobs != nil:
al := types.AccessList{}
if args.AccessList != nil {
al = *args.AccessList
}
msg := types.BlobTxMessage{}
msg.To.Address = (*types.AddressSSZ)(args.To)
msg.ChainID.SetFromBig((*big.Int)(args.ChainID))
msg.Nonce = view.Uint64View(*args.Nonce)
msg.Gas = view.Uint64View(*args.Gas)
msg.GasFeeCap.SetFromBig((*big.Int)(args.MaxFeePerGas))
msg.GasTipCap.SetFromBig((*big.Int)(args.MaxPriorityFeePerGas))
msg.Value.SetFromBig((*big.Int)(args.Value))
msg.Data = args.data()
msg.AccessList = types.AccessListView(al)
kzgs, ok := types.Blobs(args.Blobs).ComputeCommitments()
if ok { // if blobs are invalid we will omit the wrap-data
opts = append(opts, types.WithTxWrapData(&types.BlobTxWrapData{
BlobKzgs: kzgs,
Blobs: args.Blobs,
}))
}
data = &types.SignedBlobTx{Message: msg}
case args.MaxFeePerGas != nil:
al := types.AccessList{}
if args.AccessList != nil {
Expand Down Expand Up @@ -285,7 +312,7 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
Data: args.data(),
}
}
return types.NewTx(data)
return types.NewTx(data, opts...)
}

// ToTransaction converts the arguments to a transaction.
Expand Down

0 comments on commit e9279d9

Please sign in to comment.