Пример #1
0
        public override xdr.Asset ToXdr()
        {
            var thisXdr = new xdr.Asset();

            thisXdr.Discriminant = AssetType.Create(AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE);
            return(thisXdr);
        }
        public override xdr.Asset ToXdr()
        {
            var thisXdr = new xdr.Asset();

            thisXdr.Discriminant = AssetType.Create(AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12);
            var credit = new xdr.Asset.AssetAlphaNum12();

            credit.AssetCode = Util.PaddedByteArray(Code, 12);
            var accountID = new AccountID();

            accountID.InnerValue = Issuer.XdrPublicKey;
            credit.Issuer        = accountID;
            thisXdr.AlphaNum12   = credit;
            return(thisXdr);
        }
Пример #3
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:
                var assetCode4 = Util.PaddedByteArrayToString(thisXdr.AlphaNum4.AssetCode);
                var issuer4    = KeyPair.FromXdrPublicKey(thisXdr.AlphaNum4.Issuer.InnerValue);
                return(new AssetTypeCreditAlphaNum4(assetCode4, issuer4));

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

            default:
                throw new ArgumentException("Unknown asset type " + thisXdr.Discriminant.InnerValue);
            }
        }
        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);
        }