Exemple #1
0
        public override IEnumerable <RegisterTransaction> GetAssets()
        {
            yield return(AntCoin);

            ReadOptions options = new ReadOptions();

            using (options.Snapshot = db.GetSnapshot())
            {
                int height;
                foreach (Slice key in db.Find(options, SliceBuilder.Begin(DataEntryPrefix.IX_Asset), (k, v) => k))
                {
                    UInt256 hash = new UInt256(key.ToArray().Skip(1).ToArray());
                    yield return((RegisterTransaction)GetTransaction(options, hash, out height));
                }
            }
        }
Exemple #2
0
        public override IEnumerable <EnrollmentTransaction> GetEnrollments(IEnumerable <Transaction> others)
        {
            ReadOptions options = new ReadOptions();

            using (options.Snapshot = db.GetSnapshot())
            {
                int height;
                foreach (Slice key in db.Find(options, SliceBuilder.Begin(DataEntryPrefix.IX_Enrollment), (k, v) => k))
                {
                    UInt256 hash = new UInt256(key.ToArray().Skip(1).Take(32).ToArray());
                    if (others.SelectMany(p => p.Inputs).Any(p => p.PrevHash == hash && p.PrevIndex == 0))
                    {
                        continue;
                    }
                    yield return((EnrollmentTransaction)GetTransaction(options, hash, out height));
                }
            }
            foreach (EnrollmentTransaction tx in others.OfType <EnrollmentTransaction>())
            {
                yield return(tx);
            }
        }
        public override TransactionOutput GetUnspent(UInt256 hash, ushort index)
        {
            ReadOptions options = new ReadOptions();

            using (options.Snapshot = db.GetSnapshot())
            {
                UnspentCoinState state = db.TryGet <UnspentCoinState>(options, DataEntryPrefix.ST_Coin, hash);
                if (state == null)
                {
                    return(null);
                }
                if (index >= state.Items.Length)
                {
                    return(null);
                }
                if (state.Items[index].HasFlag(CoinState.Spent))
                {
                    return(null);
                }
                int height;
                return(GetTransaction(options, hash, out height).Outputs[index]);
            }
        }
Exemple #4
0
        public override IEnumerable <ValidatorState> GetEnrollments(IEnumerable <Transaction> others)
        {
            Dictionary <ECPoint, ValidatorState> dictionary = new Dictionary <ECPoint, ValidatorState>();
            ReadOptions options = new ReadOptions();

            using (options.Snapshot = db.GetSnapshot())
            {
                foreach (ValidatorState validator in db.Find <ValidatorState>(options, DataEntryPrefix.ST_Validator))
                {
                    dictionary.Add(validator.PublicKey, validator);
                }
            }
            foreach (EnrollmentTransaction tx in others.OfType <EnrollmentTransaction>())
            {
                if (!dictionary.ContainsKey(tx.PublicKey))
                {
                    dictionary.Add(tx.PublicKey, new ValidatorState
                    {
                        PublicKey = tx.PublicKey
                    });
                }
            }
            return(dictionary.Values);
        }