Exemplo n.º 1
0
            public static OperationBody Decode(XdrDataInputStream stream)
            {
                OperationBody decodedOperationBody = new OperationBody();
                OperationType discriminant         = OperationType.Decode(stream);

                decodedOperationBody.Discriminant = discriminant;
                switch (decodedOperationBody.Discriminant.InnerValue)
                {
                case OperationType.OperationTypeEnum.CREATE_ACCOUNT:
                    decodedOperationBody.CreateAccountOp = CreateAccountOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.PAYMENT:
                    decodedOperationBody.PaymentOp = PaymentOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.PATH_PAYMENT:
                    decodedOperationBody.PathPaymentOp = PathPaymentOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.MANAGE_OFFER:
                    decodedOperationBody.ManageOfferOp = ManageOfferOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.CREATE_PASSIVE_OFFER:
                    decodedOperationBody.CreatePassiveOfferOp = CreatePassiveOfferOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.SET_OPTIONS:
                    decodedOperationBody.SetOptionsOp = SetOptionsOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.CHANGE_TRUST:
                    decodedOperationBody.ChangeTrustOp = ChangeTrustOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.ALLOW_TRUST:
                    decodedOperationBody.AllowTrustOp = AllowTrustOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.ACCOUNT_MERGE:
                    decodedOperationBody.Destination = AccountID.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.INFLATION:
                    break;

                case OperationType.OperationTypeEnum.MANAGE_DATA:
                    decodedOperationBody.ManageDataOp = ManageDataOp.Decode(stream);
                    break;

                case OperationType.OperationTypeEnum.BUMP_SEQUENCE:
                    decodedOperationBody.BumpSequenceOp = BumpSequenceOp.Decode(stream);
                    break;
                }
                return(decodedOperationBody);
            }
Exemplo n.º 2
0
            public static void Encode(XdrDataOutputStream stream, OperationBody encodedOperationBody)
            {
                stream.WriteInt((int)encodedOperationBody.Discriminant.InnerValue);
                switch (encodedOperationBody.Discriminant.InnerValue)
                {
                case OperationType.OperationTypeEnum.CREATE_ACCOUNT:
                    CreateAccountOp.Encode(stream, encodedOperationBody.CreateAccountOp);
                    break;

                case OperationType.OperationTypeEnum.PAYMENT:
                    PaymentOp.Encode(stream, encodedOperationBody.PaymentOp);
                    break;

                case OperationType.OperationTypeEnum.PATH_PAYMENT:
                    PathPaymentOp.Encode(stream, encodedOperationBody.PathPaymentOp);
                    break;

                case OperationType.OperationTypeEnum.MANAGE_SELL_OFFER:
                    ManageSellOfferOp.Encode(stream, encodedOperationBody.ManageSellOfferOp);
                    break;

                case OperationType.OperationTypeEnum.CREATE_PASSIVE_SELL_OFFER:
                    CreatePassiveSellOfferOp.Encode(stream, encodedOperationBody.CreatePassiveSellOfferOp);
                    break;

                case OperationType.OperationTypeEnum.SET_OPTIONS:
                    SetOptionsOp.Encode(stream, encodedOperationBody.SetOptionsOp);
                    break;

                case OperationType.OperationTypeEnum.CHANGE_TRUST:
                    ChangeTrustOp.Encode(stream, encodedOperationBody.ChangeTrustOp);
                    break;

                case OperationType.OperationTypeEnum.ALLOW_TRUST:
                    AllowTrustOp.Encode(stream, encodedOperationBody.AllowTrustOp);
                    break;

                case OperationType.OperationTypeEnum.ACCOUNT_MERGE:
                    AccountID.Encode(stream, encodedOperationBody.Destination);
                    break;

                case OperationType.OperationTypeEnum.INFLATION:
                    break;

                case OperationType.OperationTypeEnum.MANAGE_DATA:
                    ManageDataOp.Encode(stream, encodedOperationBody.ManageDataOp);
                    break;

                case OperationType.OperationTypeEnum.BUMP_SEQUENCE:
                    BumpSequenceOp.Encode(stream, encodedOperationBody.BumpSequenceOp);
                    break;

                case OperationType.OperationTypeEnum.MANAGE_BUY_OFFER:
                    ManageBuyOfferOp.Encode(stream, encodedOperationBody.ManageBuyOfferOp);
                    break;
                }
            }
 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]);
     }
 }
        public static void Encode(XdrDataOutputStream stream, PathPaymentOp encodedPathPaymentOp)
        {
            Asset.Encode(stream, encodedPathPaymentOp.SendAsset);
            Int64.Encode(stream, encodedPathPaymentOp.SendMax);
            AccountID.Encode(stream, encodedPathPaymentOp.Destination);
            Asset.Encode(stream, encodedPathPaymentOp.DestAsset);
            Int64.Encode(stream, encodedPathPaymentOp.DestAmount);
            int pathsize = encodedPathPaymentOp.Path.Length;

            stream.WriteInt(pathsize);
            for (int i = 0; i < pathsize; i++)
            {
                Asset.Encode(stream, encodedPathPaymentOp.Path[i]);
            }
        }
        public static PathPaymentOp Decode(XdrDataInputStream stream)
        {
            PathPaymentOp decodedPathPaymentOp = new PathPaymentOp();

            decodedPathPaymentOp.SendAsset   = Asset.Decode(stream);
            decodedPathPaymentOp.SendMax     = Int64.Decode(stream);
            decodedPathPaymentOp.Destination = AccountID.Decode(stream);
            decodedPathPaymentOp.DestAsset   = Asset.Decode(stream);
            decodedPathPaymentOp.DestAmount  = Int64.Decode(stream);
            int pathsize = stream.ReadInt();

            decodedPathPaymentOp.Path = new Asset[pathsize];
            for (int i = 0; i < pathsize; i++)
            {
                decodedPathPaymentOp.Path[i] = Asset.Decode(stream);
            }
            return(decodedPathPaymentOp);
        }
        public override sdkxdr.Operation.OperationBody ToOperationBody()
        {
            var op = new sdkxdr.PathPaymentOp();

            // sendAsset
            op.SendAsset = SendAsset.ToXdr();
            // sendMax
            var sendMax = new sdkxdr.Int64();

            sendMax.InnerValue = ToXdrAmount(SendMax);
            op.SendMax         = sendMax;
            // destination
            var destination = new sdkxdr.AccountID();

            destination.InnerValue = Destination.XdrPublicKey;
            op.Destination         = destination;
            // destAsset
            op.DestAsset = DestAsset.ToXdr();
            // destAmount
            var destAmount = new sdkxdr.Int64();

            destAmount.InnerValue = ToXdrAmount(DestAmount);
            op.DestAmount         = destAmount;
            // path
            var path = new sdkxdr.Asset[Path.Length];

            for (var i = 0; i < Path.Length; i++)
            {
                path[i] = Path[i].ToXdr();
            }
            op.Path = path;

            var body = new sdkxdr.Operation.OperationBody();

            body.Discriminant  = sdkxdr.OperationType.Create(sdkxdr.OperationType.OperationTypeEnum.PATH_PAYMENT);
            body.PathPaymentOp = op;
            return(body);
        }