use atomic.Value

This commit is contained in:
maskpp 2025-07-01 06:31:00 +08:00
parent 2fcbfa4045
commit 8aa2362b76

View file

@ -79,8 +79,8 @@ type SetCodeAuthorization struct {
S uint256.Int `json:"s" gencodec:"required"` S uint256.Int `json:"s" gencodec:"required"`
// caches // caches
hash atomic.Pointer[common.Hash] hash atomic.Value // common.Hash
authority atomic.Pointer[common.Address] addr atomic.Value // common.Address
} }
// field type overrides for gencodec // field type overrides for gencodec
@ -112,21 +112,21 @@ func SignSetCode(prv *ecdsa.PrivateKey, auth SetCodeAuthorization) (SetCodeAutho
func (a *SetCodeAuthorization) sigHash() common.Hash { func (a *SetCodeAuthorization) sigHash() common.Hash {
if hash := a.hash.Load(); hash != nil { if hash := a.hash.Load(); hash != nil {
return *hash return hash.(common.Hash)
} }
hash := prefixedRlpHash(0x05, []any{ hash := prefixedRlpHash(0x05, []any{
a.ChainID, a.ChainID,
a.Address, a.Address,
a.Nonce, a.Nonce,
}) })
a.hash.Store(&hash) a.hash.Store(hash)
return hash return hash
} }
// Authority recovers the authorizing account of an authorization. // Authority recovers the authorizing account of an authorization.
func (a *SetCodeAuthorization) Authority() (common.Address, error) { func (a *SetCodeAuthorization) Authority() (common.Address, error) {
if addr := a.authority.Load(); addr != nil { if addr := a.addr.Load(); addr != nil {
return *addr, nil return addr.(common.Address), nil
} }
sighash := a.sigHash() sighash := a.sigHash()
if !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) { if !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) {
@ -147,7 +147,7 @@ func (a *SetCodeAuthorization) Authority() (common.Address, error) {
} }
var addr common.Address var addr common.Address
copy(addr[:], crypto.Keccak256(pub[1:])[12:]) copy(addr[:], crypto.Keccak256(pub[1:])[12:])
a.authority.Store(&addr) a.addr.Store(addr)
return addr, nil return addr, nil
} }