コード例 #1
0
 public string GetPaymentId()
 {
     return(Outpoint.ToString());
 }
コード例 #2
0
        public void AddToStorageBatch(StorageBatch storageBatch, SyncBlockTransactionsOperation item)
        {
            storageBatch.TotalSize += item.BlockInfo.Size;
            storageBatch.BlockTable.Add(item.BlockInfo.Height, mongoBlockToStorageBlock.Map(item.BlockInfo));

            int transactionIndex = 0;

            foreach (Transaction trx in item.Transactions)
            {
                string trxHash = trx.GetHash().ToString();

                storageBatch.TransactionBlockTable.Add(
                    new TransactionBlockTable
                {
                    BlockIndex       = item.BlockInfo.HeightAsUint32,
                    TransactionId    = trxHash,
                    TransactionIndex = transactionIndex++,
                });

                if (configuration.StoreRawTransactions)
                {
                    storageBatch.TransactionTable.Add(new TransactionTable
                    {
                        TransactionId  = trxHash,
                        RawTransaction = trx.ToBytes(syncConnection.Network.Consensus.ConsensusFactory)
                    });
                }

                int outputIndex = 0;
                foreach (TxOut output in trx.Outputs)
                {
                    ScriptOutputInfo res  = scriptInterpeter.InterpretScript(syncConnection.Network, output.ScriptPubKey);
                    string           addr = res != null
                  ? (res?.Addresses != null && res.Addresses.Any()) ? res.Addresses.First() : res.ScriptType
                  : "none";

                    var outpoint = new Outpoint {
                        TransactionId = trxHash, OutputIndex = outputIndex++
                    };

                    storageBatch.OutputTable.Add(outpoint.ToString(), new OutputTable
                    {
                        Address    = addr,
                        Outpoint   = outpoint,
                        BlockIndex = item.BlockInfo.HeightAsUint32,
                        Value      = output.Value,
                        ScriptHex  = output.ScriptPubKey.ToHex(),
                        CoinBase   = trx.IsCoinBase,
                        CoinStake  = syncConnection.Network.Consensus.IsProofOfStake && trx.IsCoinStake,
                    });
                }

                if (trx.IsCoinBase)
                {
                    continue; //no need to check the inputs for that transaction
                }
                foreach (TxIn input in trx.Inputs)
                {
                    var outpoint = new Outpoint
                    {
                        TransactionId = input.PrevOut.Hash.ToString(), OutputIndex = (int)input.PrevOut.N
                    };

                    storageBatch.OutputTable.TryGetValue(outpoint.ToString(), out OutputTable output);

                    storageBatch.InputTable.Add(new InputTable()
                    {
                        Outpoint   = outpoint,
                        TrxHash    = trxHash,
                        BlockIndex = item.BlockInfo.HeightAsUint32,
                        Address    = output?.Address,
                        Value      = output?.Value ?? 0,
                    });
                }
            }

            // allow any extensions to add ot the batch.
            OnAddToStorageBatch(storageBatch, item);
        }