github.com/klaytn/klaytn@v1.12.1/blockchain/state/transient_storage.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2022 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from core/state/transient_storage.go (2023/10/06). 19 // Modified and improved for the klaytn development. 20 21 package state 22 23 import ( 24 "github.com/klaytn/klaytn/common" 25 ) 26 27 // transientStorage is a representation of EIP-1153 "Transient Storage". 28 type transientStorage map[common.Address]Storage 29 30 // newTransientStorage creates a new instance of a transientStorage. 31 func newTransientStorage() transientStorage { 32 return make(transientStorage) 33 } 34 35 // Set sets the transient-storage `value` for `key` at the given `addr`. 36 func (t transientStorage) Set(addr common.Address, key, value common.Hash) { 37 if _, ok := t[addr]; !ok { 38 t[addr] = make(Storage) 39 } 40 t[addr][key] = value 41 } 42 43 // Get gets the transient storage for `key` at the given `addr`. 44 func (t transientStorage) Get(addr common.Address, key common.Hash) common.Hash { 45 val, ok := t[addr] 46 if !ok { 47 return common.Hash{} 48 } 49 return val[key] 50 } 51 52 // Copy does a deep copy of the transientStorage 53 func (t transientStorage) Copy() transientStorage { 54 storage := make(transientStorage) 55 for key, value := range t { 56 storage[key] = value.Copy() 57 } 58 return storage 59 }