Пример #1
0
        public TransferTransaction(DictionaryObject tx) : base(tx)
        {
            var node = new Node(tx.GetChar("chainId"));

            Asset = Assets.ZBS;
            if (tx.ContainsKey("assetId") && tx.GetString("assetId") != null)
            {
                Asset = node.GetAsset(tx.GetString("assetId"));
            }

            FeeAsset = Assets.ZBS;
            if (tx.ContainsKey("feeAssetId") &&
                tx.GetString("feeAssetId") != null &&
                tx.GetString("feeAssetId") != "")
            {
                FeeAsset = node.GetAsset(tx.GetString("feeAssetId"));
            }

            Amount = Asset.LongToAmount(tx.GetLong("amount"));
            Fee    = FeeAsset.LongToAmount(tx.GetLong("fee"));

            Recipient = tx.GetString("recipient");

            Attachment = tx.ContainsKey("attachment")
                           ? tx.GetString("attachment").FromBase58()
                           : new byte[0];
        }
Пример #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);
        }
Пример #3
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);
        }
        public void CreateWithoutAsset(Dictionary <string, object> tx)
        {
            DappAddress    = tx.GetString("dApp");
            FunctionHeader = tx.ContainsKey("call") ? tx.GetString("call.function") : null;

            FunctionCallArguments = tx.GetObjects("call.args")
                                    .Select(Node.DataValue)
                                    .ToList();

            Payment = tx.GetObjects("payment")
                      .ToDictionary(o => new Asset(o.GetString("assetId"), "", 0), o => Convert.ToDecimal(o.GetLong("amount")));

            FeeAsset = tx.ContainsKey("feeAssetId") && tx.GetString("feeAssetId") != null ? new Asset(tx.GetString("feeAssetId"), "", 0) : Assets.WAVES;
            Fee      = FeeAsset.LongToAmount(tx.GetLong("fee"));
        }
Пример #5
0
        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);
        }
Пример #6
0
 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());
         }
 }
Пример #7
0
        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());
        }