Skip to content

Commit 0a68558

Browse files
karalabefjl
andauthored
accounts/external: handle 0 chainid as not-set for the Clef API (#23394)
* accounts/external: handle 0 chainid as not-set for the Clef API * accounts/external: document SignTx Co-authored-by: Felix Lange <[email protected]>
1 parent fd604be commit 0a68558

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

accounts/external/backend.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ type signTransactionResult struct {
196196
Tx *types.Transaction `json:"tx"`
197197
}
198198

199+
// SignTx sends the transaction to the external signer.
200+
// If chainID is nil, or tx.ChainID is zero, the chain ID will be assigned
201+
// by the external signer. For non-legacy transactions, the chain ID of the
202+
// transaction overrides the chainID parameter.
199203
func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
200204
data := hexutil.Bytes(tx.Data())
201205
var to *common.MixedcaseAddress
@@ -218,17 +222,17 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
218222
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
219223
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
220224
default:
221-
return nil, fmt.Errorf("Unsupported tx type %d", tx.Type())
225+
return nil, fmt.Errorf("unsupported tx type %d", tx.Type())
222226
}
223227
// We should request the default chain id that we're operating with
224228
// (the chain we're executing on)
225-
if chainID != nil {
229+
if chainID != nil && chainID.Sign() != 0 {
226230
args.ChainID = (*hexutil.Big)(chainID)
227231
}
228232
if tx.Type() != types.LegacyTxType {
229233
// However, if the user asked for a particular chain id, then we should
230234
// use that instead.
231-
if tx.ChainId() != nil {
235+
if tx.ChainId().Sign() != 0 {
232236
args.ChainID = (*hexutil.Big)(tx.ChainId())
233237
}
234238
accessList := tx.AccessList()

0 commit comments

Comments
 (0)