Skip to content

Commit

Permalink
Remove empty keys (#825)
Browse files Browse the repository at this point in the history
* Close #824

* optimize

* remove redundancy

* simplified

* allow const empty array

* Update InteropService.cs

* Update InteropService.cs
  • Loading branch information
shargon authored Jun 15, 2019
1 parent fe3ab04 commit d411153
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions neo/SmartContract/InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,26 @@ private static bool PutEx(ApplicationEngine engine, StorageContext context, byte
if (value.Length > MaxStorageValueSize) return false;
if (context.IsReadOnly) return false;
if (!CheckStorageContext(engine, context)) return false;

StorageKey skey = new StorageKey
{
ScriptHash = context.ScriptHash,
Key = key
};
StorageItem item = engine.Snapshot.Storages.GetAndChange(skey, () => new StorageItem());
if (item.IsConstant) return false;
item.Value = value;
item.IsConstant = flags.HasFlag(StorageFlags.Constant);

if (engine.Snapshot.Storages.TryGet(skey)?.IsConstant == true) return false;

if (value.Length == 0 && !flags.HasFlag(StorageFlags.Constant))
{
// If put 'value' is empty (and non-const), we remove it (implicit `Storage.Delete`)
engine.Snapshot.Storages.Delete(skey);
}
else
{
StorageItem item = engine.Snapshot.Storages.GetAndChange(skey, () => new StorageItem());
item.Value = value;
item.IsConstant = flags.HasFlag(StorageFlags.Constant);
}
return true;
}

Expand Down

0 comments on commit d411153

Please sign in to comment.