Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Jun 26, 2023
1 parent cf760cd commit 4b82b69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 7 additions & 6 deletions state/domain_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"container/heap"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"math"
"sync"
Expand Down Expand Up @@ -152,10 +151,11 @@ func (sd *SharedDomains) clear() {
func (sd *SharedDomains) put(table kv.Domain, key, val []byte) {
sd.muMaps.Lock()
defer sd.muMaps.Unlock()
sd.puts(table, hex.EncodeToString(key), val)
sd.puts(table, key, val)
}

func (sd *SharedDomains) puts(table kv.Domain, key string, val []byte) {
func (sd *SharedDomains) puts(table kv.Domain, keyB, val []byte) {
key := string(keyB)
switch table {
case kv.AccountsDomain:
if old, ok := sd.account[key]; ok {
Expand Down Expand Up @@ -197,7 +197,8 @@ func (sd *SharedDomains) Get(table kv.Domain, key []byte) (v []byte, ok bool) {

func (sd *SharedDomains) get(table kv.Domain, key []byte) (v []byte, ok bool) {
//keyS := *(*string)(unsafe.Pointer(&key))
keyS := hex.EncodeToString(key)
keyS := string(key)
//keyS := hex.EncodeToString(key)
switch table {
case kv.AccountsDomain:
v, ok = sd.account[keyS]
Expand Down Expand Up @@ -529,7 +530,7 @@ func (sd *SharedDomains) IterateStoragePrefix(roTx kv.Tx, prefix []byte, it func
if iter.Seek(string(prefix)) {
kx := iter.Key()
v = iter.Value()
k, _ = hex.DecodeString(kx)
k = []byte(kx)

if len(kx) > 0 && bytes.HasPrefix(k, prefix) {
heap.Push(&cp, &CursorItem{t: RAM_CURSOR, key: common.Copy(k), val: common.Copy(v), iter: iter, endTxNum: sd.txNum.Load(), reverse: true})
Expand Down Expand Up @@ -585,7 +586,7 @@ func (sd *SharedDomains) IterateStoragePrefix(roTx kv.Tx, prefix []byte, it func
switch ci1.t {
case RAM_CURSOR:
if ci1.iter.Next() {
k, _ = hex.DecodeString(ci1.iter.Key())
k = []byte(ci1.iter.Key())
if k != nil && bytes.HasPrefix(k, prefix) {
ci1.key = common.Copy(k)
ci1.val = common.Copy(ci1.iter.Value())
Expand Down
7 changes: 3 additions & 4 deletions state/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"math"
"math/rand"
Expand Down Expand Up @@ -952,7 +951,7 @@ func TestDomainContext_IteratePrefix(t *testing.T) {
rnd.Read(key[2:])
rnd.Read(value)

values[hex.EncodeToString(key)] = common.Copy(value)
values[string(key)] = common.Copy(value)

err := d.PutWithPrev(key, nil, value, nil)
require.NoError(t, err)
Expand All @@ -965,7 +964,7 @@ func TestDomainContext_IteratePrefix(t *testing.T) {
return
}
counter++
v, ok := values[hex.EncodeToString(kx)]
v, ok := values[string(kx)]
require.True(t, ok)
require.Equal(t, v, vx)
})
Expand All @@ -983,7 +982,7 @@ func TestDomainContext_IteratePrefix(t *testing.T) {
return
}
counter++
v, ok := values[hex.EncodeToString(kx)]
v, ok := values[string(kx)]
require.True(t, ok)
require.Equal(t, v, vx)
}
Expand Down

0 comments on commit 4b82b69

Please sign in to comment.