private bool Storage_Find(ExecutionEngine engine) { if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface) { StorageContext context = _interface.GetInterface <StorageContext>(); if (!CheckStorageContext(context)) { return(false); } byte[] prefix = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); byte[] prefix_key; using (MemoryStream ms = new MemoryStream()) { int index = 0; int remain = prefix.Length; while (remain >= 16) { ms.Write(prefix, index, 16); ms.WriteByte(0); index += 16; remain -= 16; } if (remain > 0) { ms.Write(prefix, index, remain); } prefix_key = context.ScriptHash.ToArray().Concat(ms.ToArray()).ToArray(); } StorageIterator iterator = new StorageIterator(Snapshot.Storages.Find(prefix_key).Where(p => p.Key.Key.Take(prefix.Length).SequenceEqual(prefix)).GetEnumerator()); engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(iterator)); Disposables.Add(iterator); return(true); } return(false); }
public void TestGeneratorAndDispose() { StorageIterator storageIterator = new StorageIterator(new List <KeyValuePair <StorageKey, StorageItem> >().GetEnumerator()); Assert.IsNotNull(storageIterator); Action action = () => storageIterator.Dispose(); action.Should().NotThrow <Exception>(); }
public void TestKeyAndValueAndNext() { List <(StorageKey, StorageItem)> list = new List <(StorageKey, StorageItem)>(); StorageKey storageKey = new StorageKey(); storageKey.Key = new byte[1]; StorageItem storageItem = new StorageItem(); storageItem.Value = new byte[1]; list.Add((storageKey, storageItem)); StorageIterator storageIterator = new StorageIterator(list.GetEnumerator(), FindOptions.ValuesOnly, null); storageIterator.Next(); Assert.AreEqual(new ByteString(new byte[1]), storageIterator.Value()); }
public void TestKeyAndValueAndNext() { List <KeyValuePair <StorageKey, StorageItem> > list = new List <KeyValuePair <StorageKey, StorageItem> >(); StorageKey storageKey = new StorageKey(); storageKey.Key = new byte[1]; StorageItem storageItem = new StorageItem(); storageItem.Value = new byte[1]; list.Add(new KeyValuePair <StorageKey, StorageItem>(storageKey, storageItem)); StorageIterator storageIterator = new StorageIterator(list.GetEnumerator()); storageIterator.Next(); Assert.AreEqual(new ByteArray(new byte[1]), storageIterator.Key()); Assert.AreEqual(new ByteArray(new byte[1]), storageIterator.Value()); }