Exemple #1
0
        private static NameValueCollection GetProtectionHeaders(PrivateKeyAccount account)
        {
            long timestamp = Utils.CurrentTimestamp();
            var  stream    = new MemoryStream(40);
            var  writer    = new BinaryWriter(stream);

            writer.Write(account.PublicKey);
            writer.WriteLong(timestamp);
            var signature = account.Sign(stream);

            return(new NameValueCollection
            {
                { "Timestamp", Convert.ToString(timestamp) },
                { "Signature", signature.ToBase58() }
            });
        }
Exemple #2
0
        public static DictionaryObject MakeOrderCancelRequest(PrivateKeyAccount sender, string orderId)
        {
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write(sender.PublicKey);
            writer.Write(Base58.Decode(orderId));
            var signature = sender.Sign(stream);

            return(new DictionaryObject
            {
                { "sender", sender.PublicKey.ToBase58() },
                { "orderId", orderId },
                { "signature", signature.ToBase58() }
            });
        }
Exemple #3
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.TN.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.TN.AmountToLong(matcherFee) },
                { "signature", signature.ToBase58() }
            });
        }
Exemple #4
0
 public static T Sign <T>(this T transaction, PrivateKeyAccount account, int proofIndex = 0) where T : Transaction
 {
     transaction.Proofs[proofIndex] = account.Sign(transaction.GetBody());
     return(transaction);
 }