Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable in Storage classes #3670

Merged
merged 23 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/Neo/Persistence/ClonedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,60 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

#nullable enable

using Neo.SmartContract;
using System.Collections.Generic;

namespace Neo.Persistence
{
class ClonedCache : DataCache
{
private readonly DataCache innerCache;
private readonly DataCache _innerCache;

public ClonedCache(DataCache innerCache)
{
this.innerCache = innerCache;
_innerCache = innerCache;
}

protected override void AddInternal(StorageKey key, StorageItem value)
{
innerCache.Add(key, value.Clone());
_innerCache.Add(key, value.Clone());
}

protected override void DeleteInternal(StorageKey key)
{
innerCache.Delete(key);
_innerCache.Delete(key);
}

protected override bool ContainsInternal(StorageKey key)
{
return innerCache.Contains(key);
return _innerCache.Contains(key);
}

/// <inheritdoc/>
protected override StorageItem GetInternal(StorageKey key)
{
return innerCache[key].Clone();
return _innerCache[key].Clone();
}

protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPreifx, SeekDirection direction)
{
foreach (var (key, value) in innerCache.Seek(keyOrPreifx, direction))
foreach (var (key, value) in _innerCache.Seek(keyOrPreifx, direction))
yield return (key, value.Clone());
}

protected override StorageItem TryGetInternal(StorageKey key)
protected override StorageItem? TryGetInternal(StorageKey key)
{
return innerCache.TryGet(key)?.Clone();
return _innerCache.TryGet(key)?.Clone();
}

protected override void UpdateInternal(StorageKey key, StorageItem value)
{
innerCache.GetAndChange(key).FromReplica(value);
var entry = _innerCache.GetAndChange(key)
?? throw new KeyNotFoundException();

entry.FromReplica(value);
}
}
}
Loading
Loading