/// <summary>
        /// Generates the bytes.
        /// </summary>
        /// <returns>System.Byte[].</returns>
        internal override byte[] GenerateBytes()
        {
            byte flags = 0;

            if (Properties.IsSupplyMutable)
            {
                flags += 1;
            }

            if (Properties.IsTransferable)
            {
                flags += 2;
            }

            if (Properties.IsLevyMutable)
            {
                flags += 4;
            }

            var builder = new FlatBufferBuilder(1);

            // create vectors
            var signatureVector  = MosaicCreationTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector     = MosaicCreationTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector        = MosaicCreationTransactionBuffer.CreateFeeVector(builder, Fee.ToUInt8Array());
            var deadlineVector   = MosaicCreationTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var parentIdVector   = MosaicCreationTransactionBuffer.CreateParentIdVector(builder, NamespaceId.Id.ToUInt8Array());
            var mosaicIdVector   = MosaicCreationTransactionBuffer.CreateMosaicIdVector(builder, MosaicId.Id.ToUInt8Array());
            var mosaicNameVector = MosaicCreationTransactionBuffer.CreateMosaicNameVector(builder, Encoding.UTF8.GetBytes(MosaicId.MosaicName));
            var durationVector   = MosaicCreationTransactionBuffer.CreateDurationVector(builder, Properties.Duration.ToUInt8Array());

            ushort version = ushort.Parse(NetworkType.GetNetworkByte().ToString("X") + "0" + Version.ToString("X"), System.Globalization.NumberStyles.HexNumber);


            // add vectors to buffer
            MosaicCreationTransactionBuffer.StartMosaicCreationTransactionBuffer(builder);
            MosaicCreationTransactionBuffer.AddSize(builder, (uint)(149 + Encoding.UTF8.GetBytes(MosaicId.MosaicName).ToHexLower().Length / 2));
            MosaicCreationTransactionBuffer.AddSignature(builder, signatureVector);
            MosaicCreationTransactionBuffer.AddSigner(builder, signerVector);
            MosaicCreationTransactionBuffer.AddVersion(builder, version);
            MosaicCreationTransactionBuffer.AddType(builder, TransactionTypes.Types.MosaicDefinition.GetValue());
            MosaicCreationTransactionBuffer.AddFee(builder, feeVector);
            MosaicCreationTransactionBuffer.AddDeadline(builder, deadlineVector);
            MosaicCreationTransactionBuffer.AddMosaicId(builder, mosaicIdVector);
            MosaicCreationTransactionBuffer.AddParentId(builder, parentIdVector);
            MosaicCreationTransactionBuffer.AddNameLength(builder, (byte)(Encoding.UTF8.GetBytes(MosaicId.MosaicName).ToHexLower().Length / 2));
            MosaicCreationTransactionBuffer.AddNumOptionalProperties(builder, 1);
            MosaicCreationTransactionBuffer.AddFlags(builder, flags);
            MosaicCreationTransactionBuffer.AddDivisibility(builder, (byte)Properties.Divisibility);
            MosaicCreationTransactionBuffer.AddMosaicName(builder, mosaicNameVector);
            MosaicCreationTransactionBuffer.AddIndicateDuration(builder, 2);
            MosaicCreationTransactionBuffer.AddDuration(builder, durationVector);

            // Calculate size
            var codedNamespace = NamespaceCreationTransactionBuffer.EndNamespaceCreationTransactionBuffer(builder);

            builder.Finish(codedNamespace.Value);

            return(new MosaicCreationTransactionSchema().Serialize(builder.SizedByteArray()));
        }
Пример #2
0
        /// <summary>
        /// Generates the bytes.
        /// </summary>
        /// <returns>System.Byte[].</returns>
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            var namespaceNameLength = (uint)Encoding.UTF8.GetBytes(NamespaceId.Name).Length;

            // create vectors
            var signatureVector  = NamespaceCreationTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector     = NamespaceCreationTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector        = NamespaceCreationTransactionBuffer.CreateFeeVector(builder, Fee.ToUInt8Array());
            var deadlineVector   = NamespaceCreationTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var durationParentId = ParentId == null?Duration.ToUInt8Array() : ParentId.Id.ToUInt8Array();

            var durationParentIdVector = NamespaceCreationTransactionBuffer.CreateDurationParentIdVector(builder, durationParentId);
            var namespaceIdVector      = NamespaceCreationTransactionBuffer.CreateNamespaceIdVector(builder, IdGenerator.GenerateId(NamespaceType == 0x00 ? 0 : IdGenerator.GenerateId(0, ParentId.Name), NamespaceId.Name).ToUInt8Array());

            var    name    = NamespaceCreationTransactionBuffer.CreateNamespaceNameVector(builder, Encoding.UTF8.GetBytes(NamespaceId.Name));
            ushort version = ushort.Parse(NetworkType.GetNetworkByte().ToString("X") + "0" + Version.ToString("X"), System.Globalization.NumberStyles.HexNumber);

            // Add to buffer
            NamespaceCreationTransactionBuffer.StartNamespaceCreationTransactionBuffer(builder);
            NamespaceCreationTransactionBuffer.AddSize(builder, 138 + namespaceNameLength);
            NamespaceCreationTransactionBuffer.AddSignature(builder, signatureVector);
            NamespaceCreationTransactionBuffer.AddSigner(builder, signerVector);
            NamespaceCreationTransactionBuffer.AddVersion(builder, version);
            NamespaceCreationTransactionBuffer.AddType(builder, TransactionTypes.Types.RegisterNamespace.GetValue());
            NamespaceCreationTransactionBuffer.AddFee(builder, feeVector);
            NamespaceCreationTransactionBuffer.AddDeadline(builder, deadlineVector);
            NamespaceCreationTransactionBuffer.AddNamespaceType(builder, NamespaceType.GetValue());
            NamespaceCreationTransactionBuffer.AddDurationParentId(builder, durationParentIdVector);
            NamespaceCreationTransactionBuffer.AddNamespaceId(builder, namespaceIdVector);
            NamespaceCreationTransactionBuffer.AddNamespaceNameSize(builder, (byte)namespaceNameLength);
            NamespaceCreationTransactionBuffer.AddNamespaceName(builder, name);

            // Calculate size
            var codedNamespace = NamespaceCreationTransactionBuffer.EndNamespaceCreationTransactionBuffer(builder);

            builder.Finish(codedNamespace.Value);

            return(new NamespaceCreateionTransactionSchema().Serialize(builder.SizedByteArray()));
        }