Esempio n. 1
0
 public byte[] ToArray()
 {
     using (stream)
     {
         return(StorageKey.CreateSearchPrefix(id, stream.ToArray()));
     }
 }
 protected override IEnumerable <(ReadOnlyMemory <byte>, StorageItem)> GetStorages()
 {
     return(contractId.HasValue
         ? snapshot.Find(StorageKey.CreateSearchPrefix(contractId.Value, default))
            .Select(t => ((ReadOnlyMemory <byte>)t.Key.Key, t.Value))
         : Enumerable.Empty <(ReadOnlyMemory <byte>, StorageItem)>());
 }
Esempio n. 3
0
        public Task <IReadOnlyList <ExpressStorage> > ListStoragesAsync(UInt160 scriptHash)
        {
            try
            {
                if (disposedValue)
                {
                    return(Task.FromException <IReadOnlyList <ExpressStorage> >(new ObjectDisposedException(nameof(OfflineNode))));
                }

                using var snapshot = neoSystem.GetSnapshot();
                var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash);

                if (contract == null)
                {
                    return(Task.FromResult <IReadOnlyList <ExpressStorage> >(Array.Empty <ExpressStorage>()));
                }

                byte[] prefix  = StorageKey.CreateSearchPrefix(contract.Id, default);
                var    results = snapshot.Find(prefix)
                                 .Select(t => new ExpressStorage()
                {
                    Key   = t.Key.Key.ToHexString(),
                    Value = t.Value.Value.ToHexString(),
                });

                return(Task.FromResult <IReadOnlyList <ExpressStorage> >(results.ToArray()));
            }
            catch (Exception ex)
            {
                return(Task.FromException <IReadOnlyList <ExpressStorage> >(ex));
            }
        }
Esempio n. 4
0
 public IEnumerable <(ECPoint PublicKey, BigInteger Votes)> GetRegisteredValidators(Snapshot snapshot)
 {
     byte[] prefix_key = StorageKey.CreateSearchPrefix(Hash, new[] { Prefix_Validator });
     return(snapshot.Storages.Find(prefix_key).Select(p =>
                                                      (
                                                          p.Key.Key.Skip(1).ToArray().AsSerializable <ECPoint>(),
                                                          ValidatorState.FromByteArray(p.Value.Value).Votes
                                                      )));
 }
Esempio n. 5
0
 public IEnumerable <(ECPoint PublicKey, BigInteger Votes)> GetCandidates(StoreView snapshot)
 {
     byte[] prefix_key = StorageKey.CreateSearchPrefix(Id, new[] { Prefix_Candidate });
     return(snapshot.Storages.Find(prefix_key).Select(p =>
                                                      (
                                                          p.Key.Key.AsSerializable <ECPoint>(1),
                                                          p.Value.GetInteroperable <CandidateState>()
                                                      )).Where(p => p.Item2.Registered).Select(p => (p.Item1, p.Item2.Votes)));
 }
 private void Destroy(ApplicationEngine engine)
 {
     UInt160 hash = engine.CallingScriptHash;
     StorageKey ckey = CreateStorageKey(Prefix_Contract).Add(hash);
     ContractState contract = engine.Snapshot.TryGet(ckey)?.GetInteroperable<ContractState>();
     if (contract is null) return;
     engine.Snapshot.Delete(ckey);
     foreach (var (key, _) in engine.Snapshot.Find(StorageKey.CreateSearchPrefix(contract.Id, ReadOnlySpan<byte>.Empty)))
         engine.Snapshot.Delete(key);
     engine.SendNotification(Hash, "Destroy", new VM.Types.Array { hash.ToArray() });
 }
 private void WriteStorages(UInt160 scriptHash)
 {
     if (scriptHash != null)
     {
         var contractState = NativeContract.ContractManagement.GetContract(Snapshot, scriptHash);
         if (contractState != null)
         {
             var storages = Snapshot.Find(StorageKey.CreateSearchPrefix(contractState.Id, default));
             traceDebugSink.Storages(scriptHash, storages);
         }
     }
 }
Esempio n. 8
0
        public JObject?ExpressGetContractStorage(JArray @params)
        {
            var scriptHash = UInt160.Parse(@params[0].AsString());
            var contract   = NativeContract.ContractManagement.GetContract(neoSystem.StoreView, scriptHash);

            if (contract == null)
            {
                return(null);
            }

            var storages = new JArray();

            byte[] prefix = StorageKey.CreateSearchPrefix(contract.Id, default);
            using var snapshot = neoSystem.GetSnapshot();
            foreach (var(key, value) in snapshot.Find(prefix))
            {
                var storage = new JObject();
                storage["key"]   = key.Key.ToHexString();
                storage["value"] = value.Value.ToHexString();
                storages.Add(storage);
            }
            return(storages);
        }