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 (DecoratedSignature signature in envelope.Signatures)
            {
                transaction.Signatures.Add(signature);
            }

            return(transaction);
        }
 public Builder(sdkxdr.PathPaymentOp op)
 {
     _SendAsset   = Asset.FromXdr(op.SendAsset);
     _SendMax     = FromXdrAmount(op.SendMax.InnerValue);
     _Destination = KeyPair.FromXdrPublicKey(op.Destination.InnerValue);
     _DestAsset   = Asset.FromXdr(op.DestAsset);
     _DestAmount  = FromXdrAmount(op.DestAmount.InnerValue);
     _Path        = new Asset[op.Path.Length];
     for (var i = 0; i < op.Path.Length; i++)
     {
         _Path[i] = Asset.FromXdr(op.Path[i]);
     }
 }
Example #3
0
            public Builder(sdkxdr.SetOptionsOp op)
            {
                if (op.InflationDest != null)
                {
                    inflationDestination = KeyPair.FromXdrPublicKey(
                        op.InflationDest.InnerValue);
                }

                if (op.ClearFlags != null)
                {
                    clearFlags = op.ClearFlags.InnerValue;
                }

                if (op.SetFlags != null)
                {
                    setFlags = op.SetFlags.InnerValue;
                }

                if (op.MasterWeight != null)
                {
                    masterKeyWeight = op.MasterWeight.InnerValue;
                }

                if (op.LowThreshold != null)
                {
                    lowThreshold = op.LowThreshold.InnerValue;
                }

                if (op.MedThreshold != null)
                {
                    mediumThreshold = op.MedThreshold.InnerValue;
                }

                if (op.HighThreshold != null)
                {
                    highThreshold = op.HighThreshold.InnerValue;
                }

                if (op.HomeDomain != null)
                {
                    homeDomain = op.HomeDomain.InnerValue;
                }

                if (op.Signer != null)
                {
                    signer       = op.Signer.Key;
                    signerWeight = op.Signer.Weight.InnerValue & 0xFF;
                }
            }
Example #4
0
        /// <summary>
        ///     Generates Asset object from a given XDR object
        /// </summary>
        /// <param name="thisXdr"></param>
        public static Asset FromXdr(xdr.Asset thisXdr)
        {
            switch (thisXdr.Discriminant.InnerValue)
            {
            case AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE:
                return(new AssetTypeNative());

            case AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM4:
                string  assetCode4 = Util.PaddedByteArrayToString(thisXdr.AlphaNum4.AssetCode);
                KeyPair issuer4    = KeyPair.FromXdrPublicKey(thisXdr.AlphaNum4.Issuer.InnerValue);
                return(new AssetTypeCreditAlphaNum4(assetCode4, issuer4));

            case AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12:
                string  assetCode12 = Util.PaddedByteArrayToString(thisXdr.AlphaNum12.AssetCode);
                KeyPair issuer12    = KeyPair.FromXdrPublicKey(thisXdr.AlphaNum12.Issuer.InnerValue);
                return(new AssetTypeCreditAlphaNum12(assetCode12, issuer12));

            default:
                throw new ArgumentException("Unknown asset type " + thisXdr.Discriminant.InnerValue);
            }
        }
Example #5
0
            /// <summary>
            /// Builder to build the AllowTrust Operation given an XDR AllowTrustOp
            /// </summary>
            /// <param name="op"></param>
            /// <exception cref="Exception"></exception>
            public Builder(sdkxdr.AllowTrustOp op)
            {
                _trustor = KeyPair.FromXdrPublicKey(op.Trustor.InnerValue);
                switch (op.Asset.Discriminant.InnerValue)
                {
                case sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM4:
                    _assetCode = Encoding.UTF8.GetString(op.Asset.AssetCode4);
                    break;

                case sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12:
                    _assetCode = Encoding.UTF8.GetString(op.Asset.AssetCode12);
                    break;

                case sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE:
                    break;

                default:
                    throw new Exception("Unknown asset code");
                }
                _authorize = op.Authorize;
            }
 /// <summary>
 /// Builder to build the AccountMerge Operation given an XDR OperationBody
 /// </summary>
 /// <param name="op"></param>
 public Builder(xdr.Operation.OperationBody op)
 {
     _destination = KeyPair.FromXdrPublicKey(op.Destination.InnerValue);
 }
 /// <summary>
 ///     Construct a new PaymentOperation builder from a PaymentOp XDR.
 /// </summary>
 /// <param name="op">
 ///     <see cref="PaymentOp" />
 /// </param>
 public Builder(PaymentOp op)
 {
     destination = KeyPair.FromXdrPublicKey(op.Destination.InnerValue);
     asset       = Asset.FromXdr(op.Asset);
     amount      = FromXdrAmount(op.Amount.InnerValue);
 }
 public Builder(CreateAccountOp createAccountOp)
 {
     destination     = KeyPair.FromXdrPublicKey(createAccountOp.Destination.InnerValue);
     startingBalance = FromXdrAmount(createAccountOp.StartingBalance.InnerValue);
 }