Exemple #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());
                }
        }
Exemple #2
0
        public void WriteBytes(BinaryWriter writer)
        {
            writer.Write(SenderPublicKey);
            writer.WriteAsset(Asset.Id);
            writer.WriteAsset(FeeAsset.Id);
            writer.WriteLong(Timestamp.ToLong());
            writer.WriteLong(Asset.AmountToLong(Amount));
            writer.WriteLong(FeeAsset.AmountToLong(Fee));

            if (Recipient.StartsWith("alias", StringComparison.Ordinal))
            {
                var chainId = Recipient[6];
                var name    = Recipient.Substring(8);

                writer.Write((byte)2);
                writer.Write(chainId);

                writer.WriteShort(name.Length);
                writer.Write(Encoding.UTF8.GetBytes(name));
            }
            else
            {
                writer.Write(Recipient.FromBase58());
            }
            writer.WriteShort(Attachment.Length);
            writer.Write(Attachment);
        }
Exemple #3
0
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                { "type", (byte)TransactionType.MassTransfer },
                { "version", Version },
                { "senderPublicKey", Base58.Encode(SenderPublicKey) },
                { "transfers", Transfers.Select(t => new DictionaryObject()
                    {
                        { "recipient", t.Recipient },
                        { "amount", Asset.AmountToLong(t.Amount) }
                    }).ToArray() },
                { "assetId", Asset.IdOrNull },
                { "fee", Assets.WAVES.AmountToLong(Fee) },
                { "timestamp", Timestamp.ToLong() },
                { "attachment", Attachment.ToBase58() }
            };

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

            return(result);
        }
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                { "type", (byte)TransactionType.Issue },
                { "senderPublicKey", Base58.Encode(SenderPublicKey) },
                { "name", Name },
                { "description", Description },
                { "quantity", Asset.AmountToLong(Quantity) },
                { "decimals", Decimals },
                { "reissuable", Reissuable },
                { "fee", Assets.WAVES.AmountToLong(Fee) },
                { "timestamp", Timestamp.ToLong() },
                { "script", Script?.ToBase64() }
            };

            if (Version > 1)
            {
                result.Add("version", Version);
            }

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

            return(result);
        }
Exemple #5
0
        public override byte[] GetBody()
        {
            using(var stream = new MemoryStream())
            using(var writer = new BinaryWriter(stream))
            {
                writer.Write(TransactionType.MassTransfer);
                writer.Write(Version);
                writer.Write(SenderPublicKey);
                writer.WriteAsset(Asset.Id);
                writer.WriteShort(Transfers.Length);
                foreach (var transfer in Transfers)
                {
                    if (transfer.Recipient.StartsWith("alias", StringComparison.Ordinal))
                    {
                        var chainId = transfer.Recipient[6];
                        var name = transfer.Recipient.Substring(8);

                        writer.Write((byte)2);
                        writer.Write(chainId);
                        writer.WriteShort((short)name.Length);
                        writer.Write(Encoding.UTF8.GetBytes(name));
                    }
                    else
                        writer.Write(transfer.Recipient.FromBase58());

                    writer.WriteLong(Asset.AmountToLong(transfer.Amount));
                }
                writer.WriteLong(Timestamp.ToLong());
                writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
                writer.WriteShort((short) Attachment.Length);
                writer.Write(Attachment);
                return stream.ToArray();
            }
        }
Exemple #6
0
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                { "type", (byte)TransactionType.Transfer },
                { "senderPublicKey", SenderPublicKey.ToBase58() },
                { "recipient", Recipient },
                { "amount", Asset.AmountToLong(Amount) },
                { "assetId", Asset.IdOrNull },
                { "fee", FeeAsset.AmountToLong(Fee) },
                { "feeAsset", FeeAsset.IdOrNull },  // legacy v0.11.1 compat
                { "feeAssetId", FeeAsset.IdOrNull },
                { "timestamp", Timestamp.ToLong() },
                { "attachment", Attachment.ToBase58() }
            };

            if (Version > 1)
            {
                result.Add("version", Version);
            }

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

            return(result);
        }
Exemple #7
0
 public override Dictionary <string, object> GetJson()
 {
     return(new Dictionary <string, object>
     {
         { "type", TransactionType.Burn },
         { "senderPublicKey", SenderPublicKey.ToBase58() },
         { "assetId", Asset.Id },
         { "quantity", Asset.AmountToLong(Quantity) },
         { "fee", Assets.WAVES.AmountToLong(Fee) },
         { "timestamp", Timestamp.ToLong() }
     });
 }
Exemple #8
0
 public override byte[] GetBody()
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream))
         {
             writer.Write(TransactionType.Burn);
             writer.Write(SenderPublicKey);
             writer.Write(Asset.Id.FromBase58());
             writer.WriteLong(Asset.AmountToLong(Quantity));
             writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
             writer.WriteLong(Timestamp.ToLong());
             return(stream.ToArray());
         }
 }
        public void WriteBytes(BinaryWriter writer)
        {
            var asset = new Asset("", "", Decimals);

            writer.Write(SenderPublicKey);
            writer.WriteShort(Name.Length);
            writer.Write(Encoding.ASCII.GetBytes(Name));
            writer.WriteShort(Description.Length);
            writer.Write(Encoding.ASCII.GetBytes(Description));
            writer.WriteLong(asset.AmountToLong(Quantity));
            writer.Write(Decimals);
            writer.Write((byte)(Reissuable ? 1 : 0));
            writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
            writer.WriteLong(Timestamp.ToLong());
        }
Exemple #10
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() }
            });
        }
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                {"type", (byte) TransactionType.Burn},
                {"senderPublicKey", SenderPublicKey.ToBase58()},
                {"assetId", Asset.Id},
                {"amount", Asset.AmountToLong(Quantity)},
                {"fee", Assets.WAVES.AmountToLong(Fee)},
                {"timestamp", Timestamp.ToLong()}
            };

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

            return result;
        }
Exemple #12
0
 public override Dictionary <string, object> GetJson()
 {
     return(new Dictionary <string, object>
     {
         { "type", TransactionType.MassTransfer },
         { "version", Version },
         { "senderPublicKey", Base58.Encode(SenderPublicKey) },
         { "transfers", Transfers.Select(t => new Dictionary <string, object>()
             {
                 { "recipient", t.Recipient },
                 { "amount", Asset.AmountToLong(t.Amount) }
             }).ToArray() },
         { "assetId", Asset.IdOrNull },
         { "fee", Assets.WAVES.AmountToLong(Fee) },
         { "timestamp", Timestamp.ToLong() },
         { "attachment", Attachment.ToBase58() }
     });
 }
Exemple #13
0
        public override byte[] GetBody()
        {
            var asset  = new Asset("", "", Decimals);
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write(TransactionType.Issue);
            writer.Write(SenderPublicKey);
            writer.WriteShort(Name.Length);
            writer.Write(Encoding.ASCII.GetBytes(Name));
            writer.WriteShort(Description.Length);
            writer.Write(Encoding.ASCII.GetBytes(Description));
            writer.WriteLong(asset.AmountToLong(Quantity));
            writer.Write(Decimals);
            writer.Write((byte)(Reissuable ? 1 : 0));
            writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
            writer.WriteLong(Timestamp.ToLong());
            return(stream.ToArray());
        }
 public override byte[] GetBody()
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream))
         {
             writer.Write(TransactionType.Reissue);
             if (Version > 1)
             {
                 writer.WriteByte(Version);
                 writer.WriteByte((byte)ChainId);
             }
             writer.Write(SenderPublicKey);
             writer.Write(Asset.Id.FromBase58());
             writer.WriteLong(Asset.AmountToLong(Quantity));
             writer.Write((byte)(Reissuable ? 1 : 0));
             writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
             writer.WriteLong(Timestamp.ToLong());
             return(stream.ToArray());
         }
 }
Exemple #15
0
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                { "version", Version },
                { "type", (byte)TransactionType.Reissue },
                { "senderPublicKey", SenderPublicKey.ToBase58() },
                { "assetId", Asset.Id },
                { "quantity", Asset.AmountToLong(Quantity) },
                { "reissuable", Reissuable },
                { "fee", Assets.WAVES.AmountToLong(Fee) },
                { "timestamp", Timestamp.ToLong() }
            };

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

            return(result);
        }
        public override DictionaryObject GetJson()
        {
            var result = new DictionaryObject
            {
                { "type", (byte)TransactionType.SponsoredFee },
                { "version", Version },
                { "senderPublicKey", Base58.Encode(SenderPublicKey) },

                { "assetId", Asset.IdOrNull },
                { "fee", Assets.WAVES.AmountToLong(Fee) },
                { "timestamp", Timestamp.ToLong() },
                { "minSponsoredAssetFee", Asset.AmountToLong(MinimalFeeInAssets) }
            };

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

            return(result);
        }
        public override Dictionary <string, object> GetJson()
        {
            var result = new Dictionary <string, object>
            {
                { "type", TransactionType.Transfer },
                { "senderPublicKey", SenderPublicKey.ToBase58() },
                { "recipient", Recipient },
                { "amount", Asset.AmountToLong(Amount) },
                { "assetId", Asset.IdOrNull },
                { "fee", FeeAsset.AmountToLong(Fee) },
                { "feeAssetId", FeeAsset.IdOrNull },
                { "timestamp", Timestamp.ToLong() },
                { "attachment", Attachment.ToBase58() }
            };

            if (Version > 1)
            {
                result.Add("version", Version);
            }
            return(result);
        }
        public override byte[] GetBody()
        {
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write(TransactionType.Transfer);

            if (Version > 1)
            {
                writer.WriteByte(Version);
            }

            writer.Write(SenderPublicKey);
            writer.WriteAsset(Asset.Id);
            writer.WriteAsset(FeeAsset.Id);
            writer.WriteLong(Timestamp.ToLong());
            writer.WriteLong(Asset.AmountToLong(Amount));
            writer.WriteLong(FeeAsset.AmountToLong(Fee));

            if (Recipient.StartsWith("alias", StringComparison.Ordinal))
            {
                var chainId = Recipient[6];
                var name    = Recipient.Substring(8);

                writer.Write((byte)2);
                writer.Write(chainId);

                writer.WriteShort(name.Length);
                writer.Write(Encoding.UTF8.GetBytes(name));
            }
            else
            {
                writer.Write(Recipient.FromBase58());
            }
            writer.WriteShort(Attachment.Length);
            writer.Write(Attachment);

            return(stream.ToArray());
        }
 public override byte[] GetBody()
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream))
         {
             writer.Write(TransactionType.Transfer);
             if (Version == 2)
             {
                 writer.Write(Version);
             }
             writer.Write(SenderPublicKey);
             writer.WriteAsset(Asset.Id);
             writer.WriteAsset(FeeAsset.Id);
             writer.WriteLong(Timestamp.ToLong());
             writer.WriteLong(Asset.AmountToLong(Amount));
             writer.WriteLong(FeeAsset.AmountToLong(Fee));
             writer.Write(Recipient.FromBase58());
             writer.WriteShort(Attachment.Length);
             writer.Write(Attachment);
             return(stream.ToArray());
         }
 }
Exemple #20
0
 public override byte[] GetBody()
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream))
         {
             writer.Write(TransactionType.MassTransfer);
             writer.Write(Version);
             writer.Write(SenderPublicKey);
             writer.WriteAsset(Asset.Id);
             writer.WriteShort(Transfers.Length);
             foreach (var transfer in Transfers)
             {
                 writer.Write(transfer.Recipient.FromBase58());
                 writer.WriteLong(Asset.AmountToLong(transfer.Amount));
             }
             writer.WriteLong(Timestamp.ToLong());
             writer.WriteLong(Assets.WAVES.AmountToLong(Fee));
             writer.WriteShort((short)Attachment.Length);
             writer.Write(Attachment);
             return(stream.ToArray());
         }
 }
Exemple #21
0
        public override byte[] GetBody()
        {
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write(TransactionType.InvokeScript);
            writer.Write(Version);
            writer.Write((byte)ChainId);

            writer.Write(SenderPublicKey);
            writer.Write(DappAddress.FromBase58());

            if (FunctionHeader != null)
            {
                writer.WriteByte((byte)1);
                writer.WriteByte((byte)9);
                writer.WriteByte((byte)1);

                writer.WriteInt(FunctionHeader.Length);
                writer.Write(Encoding.UTF8.GetBytes(FunctionHeader));
                writer.WriteInt(FunctionCallArguments.Count);
                foreach (var argument in FunctionCallArguments)
                {
                    writer.WriteEvaluatedExpression(argument);
                }
            }
            else
            {
                writer.WriteByte(0);
            }

            writer.WriteShort(Payment.Count);

            foreach (var p in Payment)
            {
                var tmpStream = new MemoryStream();
                var tmpWriter = new BinaryWriter(tmpStream);

                tmpWriter.WriteLong(p.Key.AmountToLong(p.Value));

                var id = p.Key.IdOrNull?.FromBase58();

                if (id == null)
                {
                    tmpWriter.WriteByte(0);
                }
                else
                {
                    tmpWriter.WriteByte(1);
                    // tmpWriter.WriteShort(id.Length);
                    tmpWriter.Write(id);
                }

                var array = tmpStream.ToArray();
                writer.WriteShort(array.Count());
                writer.Write(array);
            }

            writer.WriteLong(FeeAsset.AmountToLong(Fee));
            writer.WriteAsset(FeeAsset.Id);
            writer.WriteLong(Timestamp.ToLong());

            return(stream.ToArray());
        }