예제 #1
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.BCT.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);
        }
예제 #2
0
 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.ZBS.AmountToLong(MatcherFee) },
         { "assetPair", new DictionaryObject
           {
               { "amountAsset", AmountAsset.IdOrNull },
               { "priceAsset", PriceAsset.IdOrNull }
           } },
         { "orderType", Side.ToString().ToLower() },
         { "signature", Signature.ToBase58() },
         { "version", Version }
     });
 }
예제 #3
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.BCT.AmountToLong(MatcherFee));

                    return(stream.ToArray());
                }
        }