コード例 #1
0
ファイル: TxOutputs.cs プロジェクト: dntichy/Fricoin_sharp
        public (Dictionary <string, List <int> >, int) FindSpendableOutputs(byte[] pubKeyHash, int amount)
        {
            var unspentOuts = new Dictionary <string, List <int> >();
            var accumulated = 0;

            var cursor = Chain.TransactionDB.Cursor();

            foreach (var current in cursor)
            {
                var key   = current.Key;
                var value = current.Value;

                var txId = HexadecimalEncoding.ToHexString(key);
                var outs = TxOutputs.DeSerialize(value);


                if (!unspentOuts.ContainsKey(txId))
                {
                    unspentOuts.Add(txId, new List <int>());
                }

                foreach (var(output, index) in outs.Outputs.Select((v, i) => (v, i)))
                {
                    if (output.IsLockedWithKey(pubKeyHash) && accumulated < amount)
                    {
                        accumulated += output.Value;
                        unspentOuts[txId].Add(index);
                    }
                }
            }

            return(unspentOuts, accumulated);
        }
コード例 #2
0
ファイル: TxOutputs.cs プロジェクト: dntichy/Fricoin_sharp
        public void Update(Block b)
        {
            foreach (var tx in b.Transactions)
            {
                if (!tx.IsCoinBase())
                {
                    foreach (var input in tx.Inputs)
                    {
                        var updatedOutputs = new TxOutputs();
                        var inId           = input.Id;
                        var item           = Chain.TransactionDB.Get(inId);

                        var outs = TxOutputs.DeSerialize(item);

                        foreach (var(@out, index) in outs.Outputs.Select((v, i) => (v, i)))
                        {
                            if (input.Out != index)
                            {
                                updatedOutputs.Outputs.Add(@out);
                            }
                        }

                        if (updatedOutputs.Outputs.Count == 0)
                        {
                            Chain.TransactionDB.Delete(inId);
                        }
                        else
                        {
                            Chain.TransactionDB.Put(inId, updatedOutputs.Serialize());
                        }
                    }
                }

                var newOutputs = new TxOutputs();
                foreach (var @out in tx.Outputs)
                {
                    newOutputs.Outputs.Add(@out);
                }

                var txId = tx.Id;
                Chain.TransactionDB.Put(txId, newOutputs.Serialize());
            }
        }
コード例 #3
0
        public List <TxOutput> FindUnspentTransactionsOutputs(byte[] pubKeyHash)
        {
            var UTXOs = new List <TxOutput>();

            var cursor = TransactionDB.Cursor();

            foreach (var current in cursor)
            {
                var outs = TxOutputs.DeSerialize(current.Value);
                foreach (var output in outs.Outputs)
                {
                    if (output.IsLockedWithKey(pubKeyHash))
                    {
                        UTXOs.Add(output);
                    }
                }
            }

            return(UTXOs);
        }