mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Create nevm_address_mapping.go
This commit is contained in:
parent
4e4e1e178a
commit
e2470b9d98
1 changed files with 47 additions and 0 deletions
47
core/rawdb/nevm_address_mapping.go
Normal file
47
core/rawdb/nevm_address_mapping.go
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
package rawdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"encoding/binary"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NEVMAddressMapping struct {
|
||||||
|
AddressMappings map[common.Address]uint32 // Map from address to collateral height
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewNEVMAddressMapping creates a new NEVMAddressMapping instance
|
||||||
|
func NewNEVMAddressMapping() *NEVMAddressMapping {
|
||||||
|
return &NEVMAddressMapping{
|
||||||
|
AddressMappings: make(map[common.Address]uint32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddNEVMAddress adds a new NEVM address to the mapping
|
||||||
|
func (m *NEVMAddressMapping) AddNEVMAddress(address common.Address, collateralHeight uint32) {
|
||||||
|
m.AddressMappings[address] = collateralHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNEVMAddress updates an existing NEVM address with a new address
|
||||||
|
func (m *NEVMAddressMapping) UpdateNEVMAddress(oldAddress common.Address, newAddress common.Address) {
|
||||||
|
if height, exists := m.AddressMappings[oldAddress]; exists {
|
||||||
|
m.AddressMappings[newAddress] = height
|
||||||
|
delete(m.AddressMappings, oldAddress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveNEVMAddress removes an NEVM address from the mapping
|
||||||
|
func (m *NEVMAddressMapping) RemoveNEVMAddress(address common.Address) {
|
||||||
|
delete(m.AddressMappings, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNEVMAddress returns the collateral height for a given NEVM address
|
||||||
|
func (m *NEVMAddressMapping) GetNEVMAddress(address common.Address) []byte {
|
||||||
|
collateralHeight, exists := m.AddressMappings[address]
|
||||||
|
if exists {
|
||||||
|
buf := make([]byte, 4)
|
||||||
|
binary.BigEndian.PutUint32(buf, collateralHeight)
|
||||||
|
return buf
|
||||||
|
} else {
|
||||||
|
return []byte{}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue