예제 #1
0
 private static bool Storage_Find(ApplicationEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         StorageContext context = _interface.GetInterface <StorageContext>();
         if (!CheckStorageContext(engine, 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 = engine.AddDisposable(new StorageIterator(engine.Snapshot.Storages.Find(prefix_key).Where(p => p.Key.Key.Take(prefix.Length).SequenceEqual(prefix)).GetEnumerator()));
         engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(iterator));
         return(true);
     }
     return(false);
 }
예제 #2
0
        protected internal IIterator Find(StorageContext context, byte[] prefix)
        {
            byte[]          prefix_key = StorageKey.CreateSearchPrefix(context.Id, prefix);
            StorageIterator iterator   = new StorageIterator(Snapshot.Storages.Find(prefix_key).Where(p => p.Key.Key.AsSpan().StartsWith(prefix)).GetEnumerator());

            Disposables.Add(iterator);
            return(iterator);
        }
예제 #3
0
 protected virtual bool Storage_Find(ExecutionEngine engine)
 {
     if (engine.EvaluationStack.Pop() is InteropInterface _interface)
     {
         StorageContext context = _interface.GetInterface <StorageContext>();
         if (!CheckStorageContext(context))
         {
             return(false);
         }
         byte[] prefix = engine.EvaluationStack.Pop().GetByteArray();
         prefix = context.ScriptHash.ToArray().Concat(prefix).ToArray();
         StorageIterator iterator = new StorageIterator(Storages.Find(prefix).GetEnumerator());
         engine.EvaluationStack.Push(StackItem.FromInterface(iterator));
         disposables.Add(iterator);
         return(true);
     }
     return(false);
 }