예제 #1
0
 private static void PutAsset(MemoryStream stream, String assetId)
 {
     if (assetId == null || assetId == string.Empty)
     {
         stream.WriteByte((byte)0);
     }
     else
     {
         stream.WriteByte((byte)1);
         var decoded = Base58.Decode(assetId);
         stream.Write(decoded, 0, decoded.Length);
     }
 }
예제 #2
0
 public static void WriteAsset(this BinaryWriter stream, string assetId)
 {
     if (string.IsNullOrEmpty(assetId) || assetId == "WAVES")
     {
         stream.WriteByte(0);
     }
     else
     {
         stream.WriteByte(1);
         var decoded = Base58.Decode(assetId);
         stream.Write(decoded, 0, decoded.Length);
     }
 }
예제 #3
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() }
            });
        }
예제 #4
0
        //private static Dictionary<String, String> AssetPair(String amountAssetId, String priceAssetId)
        //{
        //    Dictionary<String, String> assetPair = new Dictionary<String, String>
        //    {
        //        ["amountAsset"] = amountAssetId,
        //        ["priceAsset"] = priceAssetId
        //    };
        //    return assetPair;
        //}

        public static Transaction MakeOrderCancelTransaction(PrivateKeyAccount sender,
                                                             String amountAssetId, String priceAssetId, String orderId, long fee)
        {
            MemoryStream stream = new MemoryStream(MinBufferSize);
            BinaryWriter writer = new BinaryWriter(stream);

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

            amountAssetId = NormalizeAsset(amountAssetId);
            priceAssetId  = NormalizeAsset(priceAssetId);
            return(new Transaction(String.Format("matcher/orderbook/{0}/{1}/cancel", amountAssetId, priceAssetId),
                                   "sender", Base58.Encode(sender.PublicKey), "orderId", orderId,
                                   "signature", signature));
        }
예제 #5
0
        public static Transaction MakeLeaseCancelTransaction(PrivateKeyAccount account, String TransactionId, long fee)
        {
            long         timestamp = Utils.CurrentTimestamp();
            MemoryStream stream    = new MemoryStream(MinBufferSize);
            BinaryWriter writer    = new BinaryWriter(stream);

            writer.Write(LeaseCancel);
            writer.Write(account.PublicKey);
            Utils.WriteToNetwork(writer, fee);
            Utils.WriteToNetwork(writer, timestamp);
            writer.Write(Base58.Decode(TransactionId));
            String signature = Sign(account, stream);

            return(new Transaction("leasing/broadcast/cancel",
                                   "type", LeaseCancel,
                                   "senderPublicKey", Base58.Encode(account.PublicKey),
                                   "signature", signature,
                                   "TransactionId", TransactionId,
                                   "fee", fee,
                                   "timestamp", timestamp));
        }
예제 #6
0
        public static Transaction MakeOrderTransaction(PrivateKeyAccount sender, String matcherKey, Order.Type orderType,
                                                       String amountAssetId, String priceAssetId, long price, long amount, long expiration, long matcherFee)
        {
            long timestamp = Utils.CurrentTimestamp();
            int  datalen   = MinBufferSize +
                             (amountAssetId == null ? 0 : 32) +
                             (priceAssetId == null ? 0 : 32);

            if (datalen == MinBufferSize)
            {
                throw new ArgumentException("Both spendAsset and receiveAsset are WAVES");
            }
            MemoryStream stream = new MemoryStream(datalen);
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(sender.PublicKey);
            writer.Write(Base58.Decode(matcherKey));
            PutAsset(stream, amountAssetId);
            PutAsset(stream, priceAssetId);
            writer.Write((byte)orderType.Ordinal);
            Utils.WriteToNetwork(writer, price);
            Utils.WriteToNetwork(writer, amount);
            Utils.WriteToNetwork(writer, timestamp);
            Utils.WriteToNetwork(writer, expiration);
            Utils.WriteToNetwork(writer, matcherFee);
            String signature = Sign(sender, stream);

            return(new Transaction("matcher/orderbook",
                                   "senderPublicKey", Base58.Encode(sender.PublicKey),
                                   "matcherPublicKey", matcherKey,
                                   "assetPair", new AssetPair(amountAssetId, priceAssetId).GetDictionary(),
                                   "orderType", orderType.json,
                                   "price", price,
                                   "amount", amount,
                                   "timestamp", timestamp,
                                   "expiration", expiration,
                                   "matcherFee", matcherFee,
                                   "signature", signature));
        }
예제 #7
0
        public static Transaction MakeLeaseTransaction(PrivateKeyAccount account, String toAddress, long amount, long fee)
        {
            long         timestamp = Utils.CurrentTimestamp();
            MemoryStream stream    = new MemoryStream(MinBufferSize);
            BinaryWriter writer    = new BinaryWriter(stream);

            writer.Write(Lease);
            writer.Write(account.PublicKey);
            writer.Write(Base58.Decode(toAddress));
            Utils.WriteToNetwork(writer, amount);
            Utils.WriteToNetwork(writer, fee);
            Utils.WriteToNetwork(writer, timestamp);
            String signature = Sign(account, stream);

            return(new Transaction(TransactionsBroadcastPath,
                                   "type", Lease,
                                   "senderPublicKey", Base58.Encode(account.PublicKey),
                                   "signature", signature,
                                   "recipient", toAddress,
                                   "amount", amount,
                                   "fee", fee,
                                   "timestamp", timestamp));
        }
예제 #8
0
        public static Transaction MakeTransferTransaction(PrivateKeyAccount account, String toAddress,
                                                          long amount, String assetId, long fee, String feeAssetId, String attachment)
        {
            byte[] attachmentBytes = Encoding.UTF8.GetBytes(attachment == null ? "" : attachment);
            int    datalen         = (assetId == null ? 0 : 32) +
                                     (feeAssetId == null ? 0 : 32) +
                                     attachmentBytes.Length + MinBufferSize;
            long timestamp = Utils.CurrentTimestamp();

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

            writer.Write(Transfer);
            writer.Write(account.PublicKey);
            PutAsset(stream, assetId);
            PutAsset(stream, feeAssetId);
            Utils.WriteToNetwork(writer, timestamp);
            Utils.WriteToNetwork(writer, amount);
            Utils.WriteToNetwork(writer, fee);
            writer.Write(Base58.Decode(toAddress));
            //writer.Write((short)attachmentBytes.Length);
            Utils.WriteBigEndian(writer, (short)attachmentBytes.Length);
            writer.Write(attachmentBytes);
            String signature = Sign(account, stream);

            return(new Transaction(TransactionsBroadcastPath,
                                   "type", Transfer,
                                   "senderPublicKey", Base58.Encode(account.PublicKey),
                                   "signature", signature,
                                   "recipient", toAddress,
                                   "amount", amount,
                                   "assetId", assetId,
                                   "fee", fee,
                                   "feeAssetId", feeAssetId,
                                   "timestamp", timestamp,
                                   "attachment", Base58.Encode(attachmentBytes)));
        }
예제 #9
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() }
            });
        }
예제 #10
0
 private PrivateKeyAccount(string privateKey, char scheme) : this(Base58.Decode(privateKey), scheme)
 {
 }
예제 #11
0
 private PrivateKeyAccount(string privateKey, char chainId) : this(Base58.Decode(privateKey), chainId)
 {
 }