Esempio n. 1
0
        Transaction ToEntity(NBitcoin.Transaction tx)
        {
            var entity = new Transaction(
                tx.GetHash(),
                tx.GetTransactionType(),
                (short)Convert.ToUInt16(tx.Version),
                tx.LockTime);

            // Outputs.
            for (int i = 0; i < tx.Outputs.Count; i++)
            {
                var output = new Output(entity.Hash, i, tx.Outputs[i].ScriptPubKey, tx.Outputs[i].Value);
                entity.Outputs.Add(output);
            }

            // Inputs.
            for (int i = 0; i < tx.Inputs.Count; i++)
            {
                var input = new Input(
                    entity.Hash,
                    i,
                    tx.Inputs[i].PrevOut.Hash,
                    (int)tx.Inputs[i].PrevOut.N,
                    tx.Inputs[i].ScriptSig,
                    (int)tx.Inputs[i].Sequence.Value);

                entity.Inputs.Add(input);
            }

            // Extra payload.
            var extra = tx.GetExtraPayload();

            if (extra.Length != 0)
            {
                entity.ExtraPayload = extra;
            }

            // Elysium.
            var elysium = tx.GetElysiumTransaction();

            if (elysium != null)
            {
                var serialized = new ArrayBufferWriter <byte>();

                this.elysiumSerializer.Serialize(serialized, elysium);

                entity.Elysium = new ElysiumTransaction(
                    entity.Hash,
                    elysium.Sender?.ToString(),
                    elysium.Receiver?.ToString(),
                    serialized.WrittenSpan.ToArray());
            }

            return(entity);
        }