Esempio n. 1
0
        public override byte[] GetBody()
        {
            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write(TransactionType.Exchange);

                    var buyOrderBytes  = BuyOrder.GetBytes();
                    var sellOrderBytes = SellOrder.GetBytes();

                    writer.WriteShort(0);
                    writer.WriteShort((short)buyOrderBytes.Length + BuyOrder.Signature.Length);
                    writer.WriteShort(0);
                    writer.WriteShort((short)sellOrderBytes.Length + BuyOrder.Signature.Length);
                    writer.Write(buyOrderBytes);
                    writer.Write(BuyOrder.Signature);
                    writer.Write(sellOrderBytes);
                    writer.Write(SellOrder.Signature);
                    writer.WriteLong(Asset.PriceToLong(AmountAsset, PriceAsset, Price));
                    writer.WriteLong(AmountAsset.AmountToLong(Amount));
                    writer.WriteLong(Assets.WAVES.AmountToLong(BuyMatcherFee));
                    writer.WriteLong(Assets.WAVES.AmountToLong(SellMatcherFee));
                    writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
                    writer.WriteLong(Timestamp.ToLong());
                    return(stream.ToArray());
                }
        }
Esempio n. 2
0
        public DictionaryObject GetJson()
        {
            var json = new DictionaryObject
            {
                { "amount", AmountAsset.AmountToLong(Amount) },
                { "price", Asset.PriceToLong(AmountAsset, PriceAsset, Price) },
                { "timestamp", Timestamp.ToLong() },
                { "expiration", Expiration.ToLong() },
                { "senderPublicKey", SenderPublicKey.ToBase58() },
                { "matcherPublicKey", MatcherPublicKey.ToBase58() },
                { "matcherFee", Assets.WAVES.AmountToLong(MatcherFee) },
                { "assetPair", new DictionaryObject
                  {
                      { "amountAsset", AmountAsset.IdOrNull },
                      { "priceAsset", PriceAsset.IdOrNull }
                  } },
                { "orderType", Side.ToString().ToLower() },
                { "version", Version }
            };

            var proofs = Proofs
                         .Take(Array.FindLastIndex(Proofs, p => p != null && p.Length > 0) + 1)
                         .Select(p => p == null ? "" : p.ToBase58())
                         .ToArray();

            if (SupportsProofs())
            {
                json.Add("proofs", proofs);
            }
            else
            {
                if (proofs.Length == 0)
                {
                    throw new InvalidOperationException("Order is not signed");
                }
                if (proofs.Length > 1)
                {
                    throw new InvalidOperationException("Order version doesn't support multiple proofs");
                }
                json.Add("signature", proofs.Single());
            }

            return(json);
        }
 public DictionaryObject GetJson()
 {
     return(new DictionaryObject
     {
         { "amount", AmountAsset.AmountToLong(Amount) },
         { "price", Asset.PriceToLong(AmountAsset, PriceAsset, Price) },
         { "timestamp", Timestamp.ToLong() },
         { "expiration", Expiration.ToLong() },
         { "senderPublicKey", SenderPublicKey.ToBase58() },
         { "matcherPublicKey", MatcherPublicKey.ToBase58() },
         { "matcherFee", Assets.WAVES.AmountToLong(MatcherFee) },
         { "assetPair", new DictionaryObject
           {
               { "amountAsset", AmountAsset.IdOrNull },
               { "priceAsset", PriceAsset.IdOrNull }
           } },
         { "orderType", Side.ToString().ToLower() },
         { "signature", Signature.ToBase58() },
         { "version", Version }
     });
 }
Esempio n. 4
0
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                {"version", Version },
                {"type", (byte) TransactionType.Exchange},
                {"senderPublicKey", SenderPublicKey.ToBase58() },
                {"fee", Assets.WAVES.AmountToLong(Fee)},
                {"timestamp", Timestamp.ToLong()},
                {"order1", BuyOrder.GetJson()},
                {"order2", SellOrder.GetJson()},
                {"price", Asset.PriceToLong(AmountAsset, PriceAsset, Price) },
                {"amount", AmountAsset.AmountToLong(Amount) },
                {"buyMatcherFee", Assets.WAVES.AmountToLong(BuyMatcherFee)},
                {"sellMatcherFee", Assets.WAVES.AmountToLong(SellMatcherFee)}
            };

            if (Sender != null)
                result.Add("sender", Sender);

            return result;
        }
Esempio n. 5
0
        public byte[] GetBody()
        {
            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    if (Version > 1)
                    {
                        writer.Write(Version);
                    }
                    writer.Write(SenderPublicKey);
                    writer.Write(MatcherPublicKey);
                    writer.WriteAsset(AmountAsset.Id);
                    writer.WriteAsset(PriceAsset.Id);
                    writer.Write(Side == OrderSide.Buy ? (byte)0x0 : (byte)0x1);
                    writer.WriteLong(Asset.PriceToLong(AmountAsset, PriceAsset, Price));
                    writer.WriteLong(AmountAsset.AmountToLong(Amount));
                    writer.WriteLong(Timestamp.ToLong());
                    writer.WriteLong(Expiration.ToLong());
                    writer.WriteLong(Assets.WAVES.AmountToLong(MatcherFee));

                    return(stream.ToArray());
                }
        }
Esempio n. 6
0
        public static DictionaryObject MakeOrder(PrivateKeyAccount sender, string matcherKey, OrderSide side,
                                                 Asset amountAsset, Asset priceAsset, decimal price, decimal amount, DateTime expiration, decimal matcherFee)
        {
            long timestamp = Utils.CurrentTimestamp();

            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write(sender.PublicKey);
            writer.Write(Base58.Decode(matcherKey));
            writer.WriteAsset(amountAsset.Id);
            writer.WriteAsset(priceAsset.Id);
            writer.Write((byte)(side == OrderSide.Buy ? 0x0 : 0x1));
            writer.WriteLong(Asset.PriceToLong(amountAsset, priceAsset, price));
            writer.WriteLong(amountAsset.AmountToLong(amount));
            writer.WriteLong(timestamp);
            writer.WriteLong(expiration.ToLong());
            writer.WriteLong(Assets.WAVES.AmountToLong(matcherFee));
            var signature = sender.Sign(stream);

            return(new DictionaryObject {
                { "senderPublicKey", Base58.Encode(sender.PublicKey) },
                { "matcherPublicKey", matcherKey },
                { "assetPair", new DictionaryObject {
                      { "amountAsset", amountAsset.IdOrNull },
                      { "priceAsset", priceAsset.IdOrNull }
                  } },
                { "orderType", side.ToString().ToLower() },
                { "price", Asset.PriceToLong(amountAsset, priceAsset, price) },
                { "amount", amountAsset.AmountToLong(amount) },
                { "timestamp", timestamp },
                { "expiration", expiration.ToLong() },
                { "matcherFee", Assets.WAVES.AmountToLong(matcherFee) },
                { "signature", signature.ToBase58() }
            });
        }