Example #1
0
        private Transaction(KeyPair sourceAccount, int fee, long sequenceNumber, Operation[] operations, Memo memo, TimeBounds timeBounds)
        {
            SourceAccount = sourceAccount ?? throw new ArgumentNullException(nameof(sourceAccount), "sourceAccount cannot be null");
            SequenceNumber = sequenceNumber;
            Operations = operations ?? throw new ArgumentNullException(nameof(operations), "operations cannot be null");

            if (operations.Length == 0)
                throw new ArgumentNullException(nameof(operations), "At least one operation required");

            Fee = fee;
            Signatures = new List<DecoratedSignature>();
            Memo = memo ?? Memo.None();
            TimeBounds = timeBounds;
        }
        /// <summary>
        ///     Generates Transaction XDR object.
        /// </summary>
        /// <returns></returns>
        public xdr.Transaction ToXdr()
        {
            // fee
            Uint32 fee = new Uint32 {
                InnerValue = Fee
            };

            // sequenceNumber
            Int64          sequenceNumberUint = new Int64(SequenceNumber);
            SequenceNumber sequenceNumber     = new SequenceNumber {
                InnerValue = sequenceNumberUint
            };

            // sourceAccount
            AccountID sourceAccount = new AccountID {
                InnerValue = SourceAccount.XdrPublicKey
            };

            // operations
            xdr.Operation[] operations = new xdr.Operation[Operations.Length];

            for (int i = 0; i < Operations.Length; i++)
            {
                operations[i] = Operations[i].ToXdr();
            }

            // ext
            xdr.Transaction.TransactionExt ext = new xdr.Transaction.TransactionExt {
                Discriminant = 0
            };

            xdr.Transaction transaction = new xdr.Transaction
            {
                Fee           = fee,
                SeqNum        = sequenceNumber,
                SourceAccount = sourceAccount,
                Operations    = operations,
                Memo          = Memo.ToXdr(),
                TimeBounds    = TimeBounds?.ToXdr(),
                Ext           = ext
            };
            return(transaction);
        }
Example #3
0
        public static Transaction FromEnvelopeXdr(TransactionEnvelope envelope)
        {
            xdr.Transaction transactionXdr = envelope.Tx;
            int fee = transactionXdr.Fee.InnerValue;
            KeyPair sourceAccount = KeyPair.FromXdrPublicKey(transactionXdr.SourceAccount.InnerValue);
            long sequenceNumber = transactionXdr.SeqNum.InnerValue.InnerValue;
            Memo memo = Memo.FromXdr(transactionXdr.Memo);
            TimeBounds timeBounds = TimeBounds.FromXdr(transactionXdr.TimeBounds);

            Operation[] operations = new Operation[transactionXdr.Operations.Length];
            for (int i = 0; i < transactionXdr.Operations.Length; i++)
            {
                operations[i] = Operation.FromXdr(transactionXdr.Operations[i]);
            }

            Transaction transaction = new Transaction(sourceAccount, fee, sequenceNumber, operations, memo, timeBounds);

            foreach (var signature in envelope.Signatures)
            {
                transaction.Signatures.Add(signature);
            }

            return transaction;
        }