Beispiel #1
0
        ////III.处理交易
        //1.(修改后重用)执行铸币交易
        public void execute_CoinbaseTransaction(Transaction transaction)
        {
            uint indexOfOutput = 0;

            foreach (TransactionOutput transactionOutput in transaction.Outputs)
            {
                string txhashAndIndex = transaction.TransactionHash + "#" + indexOfOutput;
                string txhash         = transaction.TransactionHash.ToString();
                ulong  value          = transactionOutput.OutputValueSatoshi;
                string script         = transactionOutput.OutputScript.ToString();
                if (value == 0)
                {
                    if (transactionOutput.OutputScript.ToArray()[0] == 0x6a || transactionOutput.OutputScript.ToArray()[1] == 0x6a)
                    {
                        opreturnOutputItem_Class opreturnOutputItem = new opreturnOutputItem_Class(txhash, indexOfOutput, value, script);
                        opreturnOutputLinkedList.AddLast(opreturnOutputItem);
                    }
                    else
                    {
                        UTXOItem_Class unSpentTxOutItem = new UTXOItem_Class(txhash, indexOfOutput, value, script);
                        if (!utxoDictionary.ContainsKey(txhashAndIndex))
                        {
                            utxoDictionary.Add(txhashAndIndex, unSpentTxOutItem);
                        }
                        else
                        {
                            utxoDictionary[txhashAndIndex].utxoItemAmount++;
                            sameTransactionCount++;
                        }
                    }
                }
                else
                {
                    UTXOItem_Class unSpentTxOutItem = new UTXOItem_Class(txhash, indexOfOutput, value, script);
                    if (!utxoDictionary.ContainsKey(txhashAndIndex))
                    {
                        utxoDictionary.Add(txhashAndIndex, unSpentTxOutItem);
                    }
                    else
                    {
                        utxoDictionary[txhashAndIndex].utxoItemAmount++;
                        sameTransactionCount++;
                    }
                }
                indexOfOutput++;
            }
        }
Beispiel #2
0
        //2.(修改后重用)执行常规交易
        public void execute_RegularTransaction(Transaction transaction)
        {
            foreach (TransactionInput transactionInput in transaction.Inputs)
            {
                string sourceTxhashAndIndex = transactionInput.SourceTransactionHash + "#" + transactionInput.SourceTransactionOutputIndex;
                if (utxoDictionary.ContainsKey(sourceTxhashAndIndex))
                {
                    if (utxoDictionary[sourceTxhashAndIndex].utxoItemAmount > 1)
                    {
                        utxoDictionary[sourceTxhashAndIndex].utxoItemAmount--;
                    }
                    else
                    {
                        utxoDictionary.Remove(sourceTxhashAndIndex);
                    }
                }
                else
                {
                    Console.WriteLine("当前交易中的输入不存在:" + sourceTxhashAndIndex);
                    return;
                }
            }
            uint indexOfOutput = 0;

            foreach (TransactionOutput transactionOutput in transaction.Outputs)
            {
                string txhashAndIndex = transaction.TransactionHash + "#" + indexOfOutput;
                string txhash         = transaction.TransactionHash.ToString();
                ulong  value          = transactionOutput.OutputValueSatoshi;
                string script         = transactionOutput.OutputScript.ToString();
                if (value == 0)
                {
                    if (transactionOutput.OutputScript.ToArray()[0] == 0x6a || transactionOutput.OutputScript.ToArray()[1] == 0x6a)
                    {
                        opreturnOutputItem_Class opreturnOutputItem = new opreturnOutputItem_Class(txhash, indexOfOutput, value, script);
                        opreturnOutputLinkedList.AddLast(opreturnOutputItem);
                    }
                    else
                    {
                        UTXOItem_Class unSpentTxOutItem = new UTXOItem_Class(txhash, indexOfOutput, value, script);
                        if (!utxoDictionary.ContainsKey(txhashAndIndex))
                        {
                            utxoDictionary.Add(txhashAndIndex, unSpentTxOutItem);
                        }
                        else
                        {
                            utxoDictionary[txhashAndIndex].utxoItemAmount++;
                            sameTransactionCount++;
                        }
                    }
                }
                else
                {
                    UTXOItem_Class unSpentTxOutItem = new UTXOItem_Class(txhash, indexOfOutput, value, script);
                    if (!utxoDictionary.ContainsKey(txhashAndIndex))
                    {
                        utxoDictionary.Add(txhashAndIndex, unSpentTxOutItem);
                    }
                    else
                    {
                        utxoDictionary[txhashAndIndex].utxoItemAmount++;
                        sameTransactionCount++;
                    }
                }
                indexOfOutput++;
            }
        }