public override sdkxdr.Operation.OperationBody ToOperationBody()
        {
            sdkxdr.PathPaymentOp op = new sdkxdr.PathPaymentOp();

            // sendAsset
            op.SendAsset = SendAsset.ToXdr();
            // sendMax
            sdkxdr.Int64 sendMax = new sdkxdr.Int64();
            sendMax.InnerValue = ToXdrAmount(SendMax);
            op.SendMax         = sendMax;
            // destination
            sdkxdr.AccountID destination = new sdkxdr.AccountID();
            destination.InnerValue = Destination.XdrPublicKey;
            op.Destination         = destination;
            // destAsset
            op.DestAsset = DestAsset.ToXdr();
            // destAmount
            sdkxdr.Int64 destAmount = new sdkxdr.Int64();
            destAmount.InnerValue = ToXdrAmount(DestAmount);
            op.DestAmount         = destAmount;
            // path
            sdkxdr.Asset[] path = new sdkxdr.Asset[Path.Length];

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

            op.Path = path;

            sdkxdr.Operation.OperationBody body = new sdkxdr.Operation.OperationBody();
            body.Discriminant  = sdkxdr.OperationType.Create(sdkxdr.OperationType.OperationTypeEnum.PATH_PAYMENT);
            body.PathPaymentOp = op;
            return(body);
        }
Ejemplo n.º 2
0
        public override xdr.Asset ToXdr()
        {
            var thisXdr = new xdr.Asset();

            thisXdr.Discriminant = AssetType.Create(AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE);
            return(thisXdr);
        }
Ejemplo n.º 3
0
        public override xdr.Asset ToXdr()
        {
            xdr.Asset thisXdr = new xdr.Asset();
            thisXdr.Discriminant = AssetType.Create(AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12);
            xdr.Asset.AssetAlphaNum12 credit = new xdr.Asset.AssetAlphaNum12();
            credit.AssetCode = Util.PaddedByteArray(Code, 12);
            AccountID accountID = new AccountID();

            accountID.InnerValue = Issuer.XdrPublicKey;
            credit.Issuer        = accountID;
            thisXdr.AlphaNum12   = credit;
            return(thisXdr);
        }
Ejemplo n.º 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);
            }
        }