Exemplo n.º 1
0
        /// <summary>
        ///     GenerateBytes
        /// </summary>
        /// <returns></returns>
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // track the size of the whole metadata modification
            var totalSize = 0;

            // load modifications
            var modificationVectors = new Offset <PropertyModificationBuffer> [Modifications.Count];

            for (var i = 0; i < modificationVectors.Length; i++)
            {
                var mod     = Modifications[i];
                var modType = mod.Type;

                var valueBytes = GetValueBytesFromModification(mod);

                var valueVector = PropertyModificationBuffer.CreateValueVector(builder, valueBytes);

                // compute number of bytes: modType + value bytes
                var modSize = 1 + valueBytes.Length;

                // increase total size
                totalSize += modSize;

                PropertyModificationBuffer.StartPropertyModificationBuffer(builder);
                PropertyModificationBuffer.AddValue(builder, valueVector);
                PropertyModificationBuffer.AddModificationType(builder, modType.GetValueInByte());
                modificationVectors[i] = PropertyModificationBuffer.EndPropertyModificationBuffer(builder);
            }

            // create version
            var version = GetTxVersionSerialization();

            var signatureVector = AccountPropertiesTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = AccountPropertiesTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = AccountPropertiesTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                AccountPropertiesTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var modificationsVector =
                AccountPropertiesTransactionBuffer.CreateModificationsVector(builder, modificationVectors);

            // add size of the header (120) + size of prop type (1) + size of mod count (1)
            var fixedSize = HEADER_SIZE + +1 + 1 + totalSize;

            AccountPropertiesTransactionBuffer.StartAccountPropertiesTransactionBuffer(builder);
            AccountPropertiesTransactionBuffer.AddSize(builder, (uint)fixedSize);
            AccountPropertiesTransactionBuffer.AddSignature(builder, signatureVector);
            AccountPropertiesTransactionBuffer.AddSigner(builder, signerVector);
            AccountPropertiesTransactionBuffer.AddVersion(builder, (uint)version);
            AccountPropertiesTransactionBuffer.AddType(builder, TransactionType.GetValue());
            AccountPropertiesTransactionBuffer.AddMaxFee(builder, feeVector);
            AccountPropertiesTransactionBuffer.AddDeadline(builder, deadlineVector);

            AccountPropertiesTransactionBuffer.AddPropertyType(builder, PropertyType.GetValueInByte());
            AccountPropertiesTransactionBuffer.AddModificationCount(builder, (byte)Modifications.Count);
            AccountPropertiesTransactionBuffer.AddModifications(builder, modificationsVector);

            // end build
            var codedTransfer = AccountPropertiesTransactionBuffer.EndAccountPropertiesTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new ModifyAccountPropertyTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != fixedSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
Exemplo n.º 2
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create version
            var version = GetTxVersionSerialization();

            var signatureVector = CatapultUpgradeTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = CatapultUpgradeTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = CatapultUpgradeTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                CatapultUpgradeTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());


            var upgradePeriodVector      = CatapultUpgradeTransactionBuffer.CreateUpgradePeriodVector(builder, UpgradePeriod.ToUInt8Array());
            var newCatapultVersionVector = CatapultUpgradeTransactionBuffer.CreateNewCatapultVersionVector(builder, NewVersion.GetVersionValue().ToUInt8Array());

            // header, 2 uint64
            var totalSize = GetPayloadSerializedSize();

            CatapultUpgradeTransactionBuffer.StartCatapultUpgradeTransactionBuffer(builder);
            CatapultUpgradeTransactionBuffer.AddSize(builder, (uint)totalSize);
            CatapultUpgradeTransactionBuffer.AddSignature(builder, signatureVector);
            CatapultUpgradeTransactionBuffer.AddSigner(builder, signerVector);
            CatapultUpgradeTransactionBuffer.AddVersion(builder, (uint)version);
            CatapultUpgradeTransactionBuffer.AddType(builder, TransactionType.GetValue());
            CatapultUpgradeTransactionBuffer.AddMaxFee(builder, feeVector);
            CatapultUpgradeTransactionBuffer.AddDeadline(builder, deadlineVector);
            CatapultUpgradeTransactionBuffer.AddNewCatapultVersion(builder, newCatapultVersionVector);
            CatapultUpgradeTransactionBuffer.AddUpgradePeriod(builder, upgradePeriodVector);

            // end build
            var codedTransfer = CatapultUpgradeTransactionBuffer.EndCatapultUpgradeTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new BlockchainUpgradeTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        /// <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);


            IList <KeyValuePair <MosaicPropertyId, ulong> > propertyList = new List <KeyValuePair <MosaicPropertyId, ulong> >();

            var duration = Properties.Duration;

            if (duration > 0)
            {
                propertyList.Add(new KeyValuePair <MosaicPropertyId, ulong>(MosaicPropertyId.DURATION, duration));
            }

            var mosaicProperties = new Offset <MosaicProperty> [propertyList.Count];

            for (var index = 0; index < propertyList.Count; index++)
            {
                KeyValuePair <MosaicPropertyId, ulong> mp = propertyList[index];
                var valueOffset = MosaicProperty.CreateValueVector(builder, mp.Value.ToUInt8Array());
                MosaicProperty.StartMosaicProperty(builder);
                MosaicProperty.AddMosaicPropertyId(builder, mp.Key.GetValueInByte());
                MosaicProperty.AddValue(builder, valueOffset);
                mosaicProperties[index] = MosaicProperty.EndMosaicProperty(builder);
            }



            // create vectors
            var signatureVector = MosaicDefinitionTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = MosaicDefinitionTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = MosaicDefinitionTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                MosaicDefinitionTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var mosaicIdVector =
                MosaicDefinitionTransactionBuffer.CreateMosaicIdVector(builder, MosaicId.Id.ToUInt8Array());
            var optionalPropertiesVector =
                MosaicDefinitionTransactionBuffer.CreateOptionalPropertiesVector(builder, mosaicProperties);

            // create version
            var version = (uint)GetTxVersionSerialization();

            // header + nonce + id + numOptProp + flags + divisibility + (id + value)*numOptProp
            var totalSize = GetSerializedSize(); //HEADER_SIZE + 4 + 8 + 1 + 1 + 1 + (1 + 8) * mosaicProperties.Length;

            // add vectors to buffer
            MosaicDefinitionTransactionBuffer.StartMosaicDefinitionTransactionBuffer(builder);
            MosaicDefinitionTransactionBuffer.AddSize(builder, (uint)totalSize);
            MosaicDefinitionTransactionBuffer.AddSignature(builder, signatureVector);
            MosaicDefinitionTransactionBuffer.AddSigner(builder, signerVector);
            MosaicDefinitionTransactionBuffer.AddVersion(builder, (uint)version);
            MosaicDefinitionTransactionBuffer.AddType(builder, TransactionType.GetValue());
            MosaicDefinitionTransactionBuffer.AddMaxFee(builder, feeVector);
            MosaicDefinitionTransactionBuffer.AddDeadline(builder, deadlineVector);

            MosaicDefinitionTransactionBuffer.AddMosaicNonce(builder, BitConverter.ToUInt32(MosaicNonce.Nonce, 0));
            MosaicDefinitionTransactionBuffer.AddMosaicId(builder, mosaicIdVector);
            MosaicDefinitionTransactionBuffer.AddNumOptionalProperties(builder, (byte)mosaicProperties.Length);
            MosaicDefinitionTransactionBuffer.AddFlags(builder, flags);
            MosaicDefinitionTransactionBuffer.AddDivisibility(builder, (byte)Properties.Divisibility);
            MosaicDefinitionTransactionBuffer.AddOptionalProperties(builder, optionalPropertiesVector);


            // Calculate size
            var codedMosaicDefinition = MosaicDefinitionTransactionBuffer.EndMosaicDefinitionTransactionBuffer(builder);

            builder.Finish(codedMosaicDefinition.Value);

            // validate size
            var output = new MosaicDefinitionTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create version
            var version                 = GetTxVersionSerialization();
            var signatureVector         = MetadataTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector            = MetadataTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector               = MetadataTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector          = MetadataTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var TargetIdVector          = MetadataTransactionBuffer.CreateTargetIdVector(builder, TargetId.Id.ToUInt8Array());
            var targetKeyVector         = MetadataTransactionBuffer.CreateTargetKeyVector(builder, TargetPublicKey.PublicKey.DecodeHexString());
            var scopedMetadataKeyVector = MetadataTransactionBuffer.CreateScopedMetadataKeyVector(builder, ScopedKey.ToUInt8Array());

            var valueVector = MetadataTransactionBuffer.CreateValueVector(builder, valueDifference_Bytes);
            // add size of stuff with constant size and size of metadata id
            var totalSize = GetSerializedSize();

            MetadataTransactionBuffer.StartMetadataTransactionBuffer(builder);
            MetadataTransactionBuffer.AddSize(builder, (uint)totalSize);
            MetadataTransactionBuffer.AddSignature(builder, signatureVector);
            MetadataTransactionBuffer.AddSigner(builder, signerVector);
            MetadataTransactionBuffer.AddVersion(builder, (uint)version);
            MetadataTransactionBuffer.AddType(builder, TransactionType.GetValue());
            MetadataTransactionBuffer.AddMaxFee(builder, feeVector);
            MetadataTransactionBuffer.AddDeadline(builder, deadlineVector);

            MetadataTransactionBuffer.AddTargetKey(builder, targetKeyVector);
            MetadataTransactionBuffer.AddScopedMetadataKey(builder, scopedMetadataKeyVector);
            MetadataTransactionBuffer.AddTargetId(builder, TargetIdVector);
            MetadataTransactionBuffer.AddValueSizeDelta(builder, ValueSizeDelta);
            MetadataTransactionBuffer.AddValueSize(builder, ValueSize);
            MetadataTransactionBuffer.AddValue(builder, valueVector);

            // end build
            var codedTransfer = MetadataTransactionBuffer.EndMetadataTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new MetadataTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);


            // create vectors
            var signatureVector = SecretProofTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = SecretProofTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = SecretProofTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                SecretProofTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var secretVector = SecretLockTransactionBuffer.CreateSecretVector(builder, Secret.DecodeHexString());
            var proofVector  = SecretProofTransactionBuffer.CreateProofVector(builder, Proof.DecodeHexString());
            var version      = int.Parse(NetworkType.GetValueInByte().ToString("X") + "0" + Version.ToString("X"),
                                         NumberStyles.HexNumber);
            var recipientVector = SecretProofTransactionBuffer.CreateRecipientVector(builder, Recipient.GetBytes());

            int totalSize = GetSerializedSize();


            SecretProofTransactionBuffer.StartSecretProofTransactionBuffer(builder);
            SecretProofTransactionBuffer.AddSize(builder, (uint)totalSize);
            SecretProofTransactionBuffer.AddSignature(builder, signatureVector);
            SecretProofTransactionBuffer.AddSigner(builder, signerVector);
            SecretProofTransactionBuffer.AddVersion(builder, (uint)version);
            SecretProofTransactionBuffer.AddType(builder, TransactionType.GetValue());
            SecretProofTransactionBuffer.AddMaxFee(builder, feeVector);
            SecretProofTransactionBuffer.AddDeadline(builder, deadlineVector);
            SecretProofTransactionBuffer.AddHashAlgorithm(builder, HashType.GetValueInByte());
            SecretProofTransactionBuffer.AddRecipient(builder, recipientVector);
            SecretProofTransactionBuffer.AddSecret(builder, secretVector);
            SecretProofTransactionBuffer.AddProofSize(builder, Convert.ToUInt16(Proof.DecodeHexString().Length));
            SecretProofTransactionBuffer.AddProof(builder, proofVector);

            var codedSecretProof = SecretProofTransactionBuffer.EndSecretProofTransactionBuffer(builder);

            builder.Finish(codedSecretProof.Value);

            var output = new SecretProofTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
Exemplo n.º 6
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // Create modifications vector
            var modificationsArray = new Offset <CosignatoryModificationBuffer> [Modifications.Count];

            for (var index = 0; index < Modifications.Count; ++index)
            {
                var modification = Modifications[index];

                var cosignatoryPublicKeyVector =
                    CosignatoryModificationBuffer.CreateCosignatoryPublicKeyVector(builder,
                                                                                   modification.CosignatoryPublicAccount.PublicKey.FromHex());
                CosignatoryModificationBuffer.StartCosignatoryModificationBuffer(builder);
                CosignatoryModificationBuffer.AddType(builder, modification.Type.GetValueInByte());
                CosignatoryModificationBuffer.AddCosignatoryPublicKey(builder, cosignatoryPublicKeyVector);
                modificationsArray[index] = CosignatoryModificationBuffer.EndCosignatoryModificationBuffer(builder);
            }

            // create vectors
            var signatureVector = ModifyMultisigAccountTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = ModifyMultisigAccountTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = ModifyMultisigAccountTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                ModifyMultisigAccountTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var modificationVector =
                ModifyMultisigAccountTransactionBuffer.CreateModificationsVector(builder, modificationsArray);

            // create version
            var version = GetTxVersionSerialization();

            var totalSize = GetSerializedSize();

            ModifyMultisigAccountTransactionBuffer.StartModifyMultisigAccountTransactionBuffer(builder);
            ModifyMultisigAccountTransactionBuffer.AddSize(builder, (uint)totalSize);
            ModifyMultisigAccountTransactionBuffer.AddSignature(builder, signatureVector);
            ModifyMultisigAccountTransactionBuffer.AddSigner(builder, signerVector);
            ModifyMultisigAccountTransactionBuffer.AddVersion(builder, (uint)version);
            ModifyMultisigAccountTransactionBuffer.AddType(builder, TransactionType.GetValue());
            ModifyMultisigAccountTransactionBuffer.AddMaxFee(builder, feeVector);
            ModifyMultisigAccountTransactionBuffer.AddDeadline(builder, deadlineVector);
            ModifyMultisigAccountTransactionBuffer.AddMinRemovalDelta(builder, Convert.ToSByte(MinRemovalDelta));
            ModifyMultisigAccountTransactionBuffer.AddMinApprovalDelta(builder, Convert.ToSByte(MinApprovalDelta));
            ModifyMultisigAccountTransactionBuffer.AddNumModifications(builder, Convert.ToByte(Modifications.Count));
            ModifyMultisigAccountTransactionBuffer.AddModifications(builder, modificationVector);

            // end build
            var codedTransfer =
                ModifyMultisigAccountTransactionBuffer.EndModifyMultisigAccountTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new ModifyMultisigAccountTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create vectors
            var mosaicidVector     = Buffers.MosaicLevy.CreateMosaicIdVector(builder, LevyInfo.Mosaic.Id.ToUInt8Array());
            var levyFeeVector      = Buffers.MosaicLevy.CreateFeeVector(builder, LevyInfo.Amount.ToUInt8Array());
            var levyRecipentVector = Buffers.MosaicLevy.CreateRecipientVector(builder, LevyInfo.Recipent.GetBytes());

            Buffers.MosaicLevy.StartMosaicLevy(builder);
            Buffers.MosaicLevy.AddFee(builder, levyFeeVector);
            Buffers.MosaicLevy.AddMosaicId(builder, mosaicidVector);
            Buffers.MosaicLevy.AddRecipient(builder, levyRecipentVector);
            Buffers.MosaicLevy.AddType(builder, LevyInfo.Levytype.GetValueInByte());

            var Mosaic = Buffers.MosaicLevy.EndMosaicLevy(builder);

            // create vectors
            var signatureVector = ModifyMosaicLevyTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = ModifyMosaicLevyTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = ModifyMosaicLevyTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                ModifyMosaicLevyTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var mosaicIdVector =
                ModifyMosaicLevyTransactionBuffer.CreateMosaicIdVector(builder, MosaicId.Id.ToUInt8Array());

            // add size of the transaction
            int totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();

            //  add vectors to buffer
            ModifyMosaicLevyTransactionBuffer.StartModifyMosaicLevyTransactionBuffer(builder);
            ModifyMosaicLevyTransactionBuffer.AddSize(builder, (uint)totalSize);
            ModifyMosaicLevyTransactionBuffer.AddSignature(builder, signatureVector);
            ModifyMosaicLevyTransactionBuffer.AddSigner(builder, signerVector);
            ModifyMosaicLevyTransactionBuffer.AddVersion(builder, (uint)version);
            ModifyMosaicLevyTransactionBuffer.AddType(builder, TransactionType.GetValue());
            ModifyMosaicLevyTransactionBuffer.AddMaxFee(builder, feeVector);
            ModifyMosaicLevyTransactionBuffer.AddDeadline(builder, deadlineVector);

            ModifyMosaicLevyTransactionBuffer.AddLevy(builder, Mosaic);
            ModifyMosaicLevyTransactionBuffer.AddMosaicId(builder, mosaicIdVector);

            // Calculate size
            var codedTransaction = ModifyMosaicLevyTransactionBuffer.EndModifyMosaicLevyTransactionBuffer(builder);

            builder.Finish(codedTransaction.Value);

            var output = new ModifyMosaicLevyTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        /// <summary>
        ///     Generate Bytes
        /// </summary>
        /// <returns>byte[]</returns>
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create vectors
            var signatureVector = RegisterNamespaceTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = RegisterNamespaceTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = TransferTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                RegisterNamespaceTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var namespaceIdVector =
                RegisterNamespaceTransactionBuffer.CreateNamespaceIdVector(builder, NamespaceId.Id.ToUInt8Array());
            var durationParentId = NamespaceType == NamespaceType.ROOT_NAMESPACE
                ? Duration?.ToUInt8Array()
                : ParentId.Id.ToUInt8Array();
            var durationParentIdVector =
                RegisterNamespaceTransactionBuffer.CreateDurationParentIdVector(builder, durationParentId);



            // header, ns type, duration, ns id, name size, name
            int totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();

            var name = builder.CreateString(NamespaceName);

            // ADD to buffer
            RegisterNamespaceTransactionBuffer.StartRegisterNamespaceTransactionBuffer(builder);
            RegisterNamespaceTransactionBuffer.AddSize(builder, (uint)totalSize);
            RegisterNamespaceTransactionBuffer.AddSignature(builder, signatureVector);
            RegisterNamespaceTransactionBuffer.AddSigner(builder, signerVector);
            RegisterNamespaceTransactionBuffer.AddVersion(builder, (uint)version);
            RegisterNamespaceTransactionBuffer.AddType(builder, TransactionType.GetValue());
            RegisterNamespaceTransactionBuffer.AddMaxFee(builder, feeVector);
            RegisterNamespaceTransactionBuffer.AddDeadline(builder, deadlineVector);
            RegisterNamespaceTransactionBuffer.AddNamespaceType(builder, NamespaceType.GetValueInByte());
            RegisterNamespaceTransactionBuffer.AddDurationParentId(builder, durationParentIdVector);
            RegisterNamespaceTransactionBuffer.AddNamespaceId(builder, namespaceIdVector);
            RegisterNamespaceTransactionBuffer.AddNamespaceNameSize(builder, (byte)NamespaceName.Length);
            RegisterNamespaceTransactionBuffer.AddNamespaceName(builder, name);

            // Calculate size
            var codedNamespace = RegisterNamespaceTransactionBuffer.EndRegisterNamespaceTransactionBuffer(builder);

            builder.Finish(codedNamespace.Value);

            var output = new RegisterNamespaceTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);


            // create offers
            var offerOffsets = new Offset <RemoveExchangeOfferBuffer> [Offers.Count];

            for (var i = 0; i < offerOffsets.Length; i++)
            {
                var offer = Offers[i];

                var mosaicIdVector = RemoveExchangeOfferBuffer.CreateMosaicIdVector(builder, offer.MosaicId.Id.ToUInt8Array());


                RemoveExchangeOfferBuffer.StartRemoveExchangeOfferBuffer(builder);
                RemoveExchangeOfferBuffer.AddMosaicId(builder, mosaicIdVector);
                RemoveExchangeOfferBuffer.AddType(builder, offer.Type.GetValueInByte());

                offerOffsets[i] = RemoveExchangeOfferBuffer.EndRemoveExchangeOfferBuffer(builder);
            }

            // create vectors
            var signatureVector = RemoveExchangeOfferTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = RemoveExchangeOfferTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = RemoveExchangeOfferTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                RemoveExchangeOfferTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var offersVector = RemoveExchangeOfferTransactionBuffer.CreateOffersVector(builder, offerOffsets);


            // add size of the transaction
            int totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();


            // ADD to buffer
            RemoveExchangeOfferTransactionBuffer.StartRemoveExchangeOfferTransactionBuffer(builder);
            RemoveExchangeOfferTransactionBuffer.AddSize(builder, (uint)totalSize);
            RemoveExchangeOfferTransactionBuffer.AddSignature(builder, signatureVector);
            RemoveExchangeOfferTransactionBuffer.AddSigner(builder, signerVector);
            RemoveExchangeOfferTransactionBuffer.AddVersion(builder, (uint)version);
            RemoveExchangeOfferTransactionBuffer.AddType(builder, TransactionType.GetValue());
            RemoveExchangeOfferTransactionBuffer.AddMaxFee(builder, feeVector);
            RemoveExchangeOfferTransactionBuffer.AddDeadline(builder, deadlineVector);
            RemoveExchangeOfferTransactionBuffer.AddOffersCount(builder, (byte)offerOffsets.Length);
            RemoveExchangeOfferTransactionBuffer.AddOffers(builder, offersVector);

            // Calculate size
            var codedTransaction = RemoveExchangeOfferTransactionBuffer.EndRemoveExchangeOfferTransactionBuffer(builder);

            builder.Finish(codedTransaction.Value);

            var output = new ExchangeOfferRemoveTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);


            // create vectors
            var signatureVector     = AccountLinkTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector        = AccountLinkTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector           = AccountLinkTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector      = AccountLinkTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var remoteAccountVector = AccountLinkTransactionBuffer.CreateRemoteAccountKeyVector(builder, RemoteAccount.PublicKey.DecodeHexString());

            /*var totalSize =
             * // header
             * HEADER_SIZE +
             * // remote account public key
             * 32 +
             * // link action
             * 1;*/
            var totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();


            AccountLinkTransactionBuffer.StartAccountLinkTransactionBuffer(builder);
            AccountLinkTransactionBuffer.AddSize(builder, (uint)totalSize);
            AccountLinkTransactionBuffer.AddSignature(builder, signatureVector);
            AccountLinkTransactionBuffer.AddSigner(builder, signerVector);
            AccountLinkTransactionBuffer.AddVersion(builder, (uint)version);
            AccountLinkTransactionBuffer.AddType(builder, TransactionType.GetValue());
            AccountLinkTransactionBuffer.AddMaxFee(builder, feeVector);
            AccountLinkTransactionBuffer.AddDeadline(builder, deadlineVector);
            AccountLinkTransactionBuffer.AddRemoteAccountKey(builder, remoteAccountVector);
            AccountLinkTransactionBuffer.AddLinkAction(builder, Action.GetValueInByte());

            // end build
            var codedTransaction = AccountLinkTransactionBuffer.EndAccountLinkTransactionBuffer(builder).Value;

            builder.Finish(codedTransaction);

            var output = new AccountLinkTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
Exemplo n.º 11
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            byte[] aliasIdBytes;

            if (MosaicId != null)
            {
                aliasIdBytes = BitConverter.GetBytes(MosaicId.Id);
            }
            else if (Address != null)
            {
                aliasIdBytes = Address.Plain.FromBase32String();
            }
            else
            {
                throw new Exception("Unsupported Alias");
            }

            // create vectors
            var signatureVector   = AliasTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector      = AliasTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector         = AliasTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector    = AliasTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var namespaceIdVector =
                AliasTransactionBuffer.CreateNamespaceIdVector(builder, NamespaceId.Id.ToUInt8Array());
            var aliasIdVector = AliasTransactionBuffer.CreateAliasIdVector(builder, aliasIdBytes);

            //var fixedSize = HEADER_SIZE + aliasIdBytes.Length + 8 + 1;

            // header, 2 uint64 and int
            int totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();


            AliasTransactionBuffer.StartAliasTransactionBuffer(builder);
            AliasTransactionBuffer.AddSize(builder, (uint)totalSize);
            AliasTransactionBuffer.AddSignature(builder, signatureVector);
            AliasTransactionBuffer.AddSigner(builder, signerVector);
            AliasTransactionBuffer.AddVersion(builder, (uint)version);
            AliasTransactionBuffer.AddType(builder, TransactionType.GetValue());
            AliasTransactionBuffer.AddMaxFee(builder, feeVector);
            AliasTransactionBuffer.AddDeadline(builder, deadlineVector);
            AliasTransactionBuffer.AddAliasId(builder, aliasIdVector);
            AliasTransactionBuffer.AddNamespaceId(builder, namespaceIdVector);
            AliasTransactionBuffer.AddActionType(builder, AliasActionType.GetValueInByte());

            // end build
            var codedTransaction = AliasTransactionBuffer.EndAliasTransactionBuffer(builder).Value;

            builder.Finish(codedTransaction);

            return(new AliasTransactionSchema().Serialize(builder.SizedByteArray()));
        }
Exemplo n.º 12
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create transaction bytes
            var transactionsBytes = new byte[0];

            transactionsBytes = InnerTransactions.Aggregate(transactionsBytes,
                                                            (current, innerTransaction) => current.Concat(innerTransaction.ToAggregate()).ToArray());

            // Create Vectors
            var signatureVector = AggregateTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = AggregateTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var deadlineVector  =
                AggregateTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var feeVector          = AggregateTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var transactionsVector = AggregateTransactionBuffer.CreateTransactionsVector(builder, transactionsBytes);

            // total size of transaction

            /*var totalSize = HEADER_SIZE
            + 4
            + transactionsBytes.Length;*/

            var totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();


            // add vectors
            AggregateTransactionBuffer.StartAggregateTransactionBuffer(builder);
            AggregateTransactionBuffer.AddSize(builder, (uint)totalSize);
            AggregateTransactionBuffer.AddSignature(builder, signatureVector);
            AggregateTransactionBuffer.AddSigner(builder, signerVector);
            AggregateTransactionBuffer.AddVersion(builder, (uint)version);
            AggregateTransactionBuffer.AddType(builder, TransactionType.GetValue());
            AggregateTransactionBuffer.AddMaxFee(builder, feeVector);
            AggregateTransactionBuffer.AddDeadline(builder, deadlineVector);

            AggregateTransactionBuffer.AddTransactionsSize(builder, (uint)transactionsBytes.Length);
            AggregateTransactionBuffer.AddTransactions(builder, transactionsVector);

            // end build
            var codedTransaction = AggregateTransactionBuffer.EndAggregateTransactionBuffer(builder).Value;

            builder.Finish(codedTransaction);

            var output = new AggregateTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder         = new FlatBufferBuilder(1);
            var signatureVector = MosaicSupplyChangeTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = MosaicSupplyChangeTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = MosaicSupplyChangeTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                MosaicSupplyChangeTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var mosaicIdVector =
                MosaicSupplyChangeTransactionBuffer.CreateMosaicIdVector(builder, MosaicId.Id.ToUInt8Array());
            var deltaVector = MosaicSupplyChangeTransactionBuffer.CreateDeltaVector(builder, Delta.ToUInt8Array());

            // create version
            var version = GetTxVersionSerialization();

            int totalSize = GetSerializedSize();

            MosaicSupplyChangeTransactionBuffer.StartMosaicSupplyChangeTransactionBuffer(builder);
            MosaicSupplyChangeTransactionBuffer.AddSize(builder, (uint)totalSize);
            MosaicSupplyChangeTransactionBuffer.AddSignature(builder, signatureVector);
            MosaicSupplyChangeTransactionBuffer.AddSigner(builder, signerVector);
            MosaicSupplyChangeTransactionBuffer.AddVersion(builder, (uint)version);
            MosaicSupplyChangeTransactionBuffer.AddType(builder, TransactionType.GetValue());
            MosaicSupplyChangeTransactionBuffer.AddMaxFee(builder, feeVector);
            MosaicSupplyChangeTransactionBuffer.AddDeadline(builder, deadlineVector);
            MosaicSupplyChangeTransactionBuffer.AddMosaicId(builder, mosaicIdVector);
            MosaicSupplyChangeTransactionBuffer.AddDirection(builder, MosaicSupplyType.GetValueInByte());
            MosaicSupplyChangeTransactionBuffer.AddDelta(builder, deltaVector);

            var codedTransaction = MosaicSupplyChangeTransactionBuffer.EndMosaicSupplyChangeTransactionBuffer(builder);

            builder.Finish(codedTransaction.Value);

            var output = new MosaicSupplyChangeTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
Exemplo n.º 14
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);


            // create vectors
            var signatureVector = LockFundsTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = LockFundsTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = LockFundsTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                LockFundsTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var mosaicIdVector     = LockFundsTransactionBuffer.CreateMosaicIdVector(builder, Mosaic.Id.Id.ToUInt8Array());
            var mosaicAmountVector =
                LockFundsTransactionBuffer.CreateMosaicAmountVector(builder, Mosaic.Amount.ToUInt8Array());
            var durationVector = LockFundsTransactionBuffer.CreateDurationVector(builder, Duration.ToUInt8Array());
            var hashVector     = LockFundsTransactionBuffer.CreateHashVector(builder, Transaction.Hash.FromHex());

            // create version
            var version = GetTxVersionSerialization();

            int totalSize = GetSerializedSize();


            LockFundsTransactionBuffer.StartLockFundsTransactionBuffer(builder);
            LockFundsTransactionBuffer.AddSize(builder, (uint)totalSize);
            LockFundsTransactionBuffer.AddSignature(builder, signatureVector);
            LockFundsTransactionBuffer.AddSigner(builder, signerVector);
            LockFundsTransactionBuffer.AddVersion(builder, (uint)version);
            LockFundsTransactionBuffer.AddType(builder, TransactionType.GetValue());
            LockFundsTransactionBuffer.AddMaxFee(builder, feeVector);
            LockFundsTransactionBuffer.AddDeadline(builder, deadlineVector);
            LockFundsTransactionBuffer.AddMosaicId(builder, mosaicIdVector);
            LockFundsTransactionBuffer.AddMosaicAmount(builder, mosaicAmountVector);
            LockFundsTransactionBuffer.AddDuration(builder, durationVector);
            LockFundsTransactionBuffer.AddHash(builder, hashVector);

            // end build
            var codedTransfer = LockFundsTransactionBuffer.EndLockFundsTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new LockFundsTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create message
            var bytePayload = Message.GetPayload();
            var payload     = MessageBuffer.CreatePayloadVector(builder, bytePayload);

            MessageBuffer.StartMessageBuffer(builder);
            MessageBuffer.AddType(builder, Message.GetMessageType());
            MessageBuffer.AddPayload(builder, payload);
            var messageVector = MessageBuffer.EndMessageBuffer(builder);

            // create mosaics
            var mosaicBuffers = new Offset <MosaicBuffer> [Mosaics.Count];

            for (var index = 0; index < Mosaics.Count; ++index)
            {
                var mosaic = Mosaics[index];
                var id     = MosaicBuffer.CreateIdVector(builder, mosaic.Id.Id.ToUInt8Array());
                var amount = MosaicBuffer.CreateAmountVector(builder, mosaic.Amount.ToUInt8Array());
                MosaicBuffer.StartMosaicBuffer(builder);
                MosaicBuffer.AddId(builder, id);
                MosaicBuffer.AddAmount(builder, amount);
                mosaicBuffers[index] = MosaicBuffer.EndMosaicBuffer(builder);
            }

            // create recipient
            byte[] recipientBytes = Recipient.GetBytes();

            // create vectors
            var signatureVector = TransferTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = TransferTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var deadlineVector  = TransferTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var feeVector       = TransferTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var recipientVector =
                TransferTransactionBuffer.CreateRecipientVector(builder, recipientBytes);
            var mosaicsVector = TransferTransactionBuffer.CreateMosaicsVector(builder, mosaicBuffers);

            // total size of transaction

            /*var totalSize = HEADER_SIZE
             + 25 // recipient
             + 2 // message size is short
             + 1 // message type byte
             + 1 // no of mosaics
             + ((8 + 8) * Mosaics.Count) //each mosaic has id(8bytes) and amount(8bytes)
             + bytePayload.Length; // number of message bytes*/

            var totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();


            // add vectors
            TransferTransactionBuffer.StartTransferTransactionBuffer(builder);
            TransferTransactionBuffer.AddSize(builder, (uint)totalSize);
            TransferTransactionBuffer.AddSignature(builder, signatureVector);
            TransferTransactionBuffer.AddSigner(builder, signerVector);
            TransferTransactionBuffer.AddVersion(builder, (uint)version);
            TransferTransactionBuffer.AddType(builder, EntityType.TRANSFER.GetValue());
            TransferTransactionBuffer.AddMaxFee(builder, feeVector);
            TransferTransactionBuffer.AddDeadline(builder, deadlineVector);

            TransferTransactionBuffer.AddRecipient(builder, recipientVector);
            TransferTransactionBuffer.AddNumMosaics(builder, (byte)Mosaics.Count);
            TransferTransactionBuffer.AddMessageSize(builder, (ushort)(bytePayload.Length + 1));
            TransferTransactionBuffer.AddMessage(builder, messageVector);
            TransferTransactionBuffer.AddMosaics(builder, mosaicsVector);

            // end build
            var codedTransfer = TransferTransactionBuffer.EndTransferTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            // validate size
            var output = new TransferTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // track the size of the whole metadata modification
            //var totalSize = 0;

            // load modifications
            var modificationVectors = new Offset<MetadataModificationBuffer>[Modifications.Count];

            for (var i = 0; i < modificationVectors.Length; i++)
            {
                var mod = Modifications[i];
                var modField = mod.Field;
                var modType = mod.Type;

                // prepare intermediate data
                var keyBytes = Encoding.UTF8.GetBytes(modField.Key);
                var valueBytes = modType == MetadataModificationType.REMOVE
                    ? new byte[0]
                    : Encoding.UTF8.GetBytes(modField.Value);

                // 2 bytes
                var valueSizeBytes = BitConverter.GetBytes((short) valueBytes.Length);

                // prepare vectors for collections
                var keyVector = MetadataModificationBuffer.CreateKeyVector(builder, keyBytes);
                var valueVector = MetadataModificationBuffer.CreateValueVector(builder, valueBytes);
                var valueSizeVector = MetadataModificationBuffer.CreateValueSizeVector(builder, valueSizeBytes);

                // compute number of bytes: size + modType + keySize + valueSize + key + value
                var modSize = 4 + 1 + 1 + 2 + keyBytes.Length + valueBytes.Length;

                // increase total size
                //totalSize += modSize;

                // populate flat-buffer
                MetadataModificationBuffer.StartMetadataModificationBuffer(builder);
                MetadataModificationBuffer.AddSize(builder, (uint) modSize);
                MetadataModificationBuffer.AddKeySize(builder, (byte) keyBytes.Length);
                MetadataModificationBuffer.AddKey(builder, keyVector);
                MetadataModificationBuffer.AddValueSize(builder, valueSizeVector);
                MetadataModificationBuffer.AddValue(builder, valueVector);
                MetadataModificationBuffer.AddModificationType(builder, modType.GetValueInByte());
                modificationVectors[i] = MetadataModificationBuffer.EndMetadataModificationBuffer(builder);
            }

            // create version
            var version = GetTxVersionSerialization();

            var signatureVector = ModifyMetadataTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector = ModifyMetadataTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector = ModifyMetadataTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector =
                ModifyMetadataTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());

            var metadataIdBytes = new byte[0];
            switch (MetadataType)
            {
                case MetadataType.ADDRESS:
                    metadataIdBytes = Address.Plain.FromBase32String();
                    break;
                case MetadataType.MOSAIC:
                case MetadataType.NAMESPACE:
                    metadataIdBytes = MetadataId.HasValue ? BitConverter.GetBytes(MetadataId.Value) : new byte[0];
                    break;
            }


            var metadataIdVector = ModifyMetadataTransactionBuffer.CreateMetadataIdVector(builder, metadataIdBytes);
            var modificationsVector =
                ModifyMetadataTransactionBuffer.CreateModificationsVector(builder, modificationVectors);

            // add size of stuff with constant size and size of metadata id
            // var fixedSize = HEADER_SIZE + 1 + metadataIdBytes.Length + totalSize;
            var totalSize = GetSerializedSize();

            ModifyMetadataTransactionBuffer.StartModifyMetadataTransactionBuffer(builder);
            ModifyMetadataTransactionBuffer.AddSize(builder, (uint)totalSize);
            ModifyMetadataTransactionBuffer.AddSignature(builder, signatureVector);
            ModifyMetadataTransactionBuffer.AddSigner(builder, signerVector);
            ModifyMetadataTransactionBuffer.AddVersion(builder, (uint)version);
            ModifyMetadataTransactionBuffer.AddType(builder, TransactionType.GetValue());
            ModifyMetadataTransactionBuffer.AddMaxFee(builder, feeVector);
            ModifyMetadataTransactionBuffer.AddDeadline(builder, deadlineVector);
            ModifyMetadataTransactionBuffer.AddMetadataId(builder, metadataIdVector);
            ModifyMetadataTransactionBuffer.AddMetadataType(builder, MetadataType.GetValueInByte());
            ModifyMetadataTransactionBuffer.AddModifications(builder, modificationsVector);

            // end build
            var codedTransfer = ModifyMetadataTransactionBuffer.EndModifyMetadataTransactionBuffer(builder);
            builder.Finish(codedTransfer.Value);

            var output = new ModifyMetadataTransactionSchema().Serialize(builder.SizedByteArray());
            if (output.Length != totalSize) throw new SerializationException("Serialized form has incorrect length");

            return output;
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create version
            var version = GetTxVersionSerialization();

            var signatureVector = CatapultConfigTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = CatapultConfigTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = CatapultConfigTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                CatapultConfigTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());

            var configBytes       = Encoding.UTF8.GetBytes(BlockchainConfig);
            var entityBytes       = Encoding.UTF8.GetBytes(SupportedEntityVersions);
            var applyHeightVector = CatapultConfigTransactionBuffer.CreateApplyHeightDeltaVector(builder, ApplyHeightDelta.ToUInt8Array());
            var configVector      = CatapultConfigTransactionBuffer.CreateBlockChainConfigVector(builder, configBytes);
            var entityVector      = CatapultConfigTransactionBuffer.CreateBlockChainConfigVector(builder, entityBytes);

            // header, 2 uint64 and int
            //var fixedSize = HEADER_SIZE + 8 + 2 + 2 + entityBytes.Length + configBytes.Length;
            var totalSize = GetPayloadSerializedSize();

            CatapultConfigTransactionBuffer.StartCatapultConfigTransactionBuffer(builder);
            CatapultConfigTransactionBuffer.AddSize(builder, (uint)totalSize);
            CatapultConfigTransactionBuffer.AddSignature(builder, signatureVector);
            CatapultConfigTransactionBuffer.AddSigner(builder, signerVector);
            CatapultConfigTransactionBuffer.AddVersion(builder, (uint)version);
            CatapultConfigTransactionBuffer.AddType(builder, TransactionType.GetValue());
            CatapultConfigTransactionBuffer.AddMaxFee(builder, feeVector);
            CatapultConfigTransactionBuffer.AddDeadline(builder, deadlineVector);
            CatapultConfigTransactionBuffer.AddApplyHeightDelta(builder, applyHeightVector);
            CatapultConfigTransactionBuffer.AddBlockChainConfig(builder, configVector);
            CatapultConfigTransactionBuffer.AddBlockChainConfigSize(builder, (ushort)configBytes.Length);
            CatapultConfigTransactionBuffer.AddSupportedEntityVersionsSize(builder, (ushort)entityBytes.Length);
            CatapultConfigTransactionBuffer.AddSupportedEntityVersions(builder, entityVector);

            // end build
            var codedTransfer = CatapultConfigTransactionBuffer.EndCatapultConfigTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new BlockchainConfigTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
Exemplo n.º 18
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);


            // create vectors
            var signatureVector = SecretLockTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = SecretLockTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = SecretLockTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                SecretLockTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var mosaicIdVector     = SecretLockTransactionBuffer.CreateMosaicIdVector(builder, Mosaic.Id.Id.ToUInt8Array());
            var mosaicAmountVector =
                SecretLockTransactionBuffer.CreateMosaicAmountVector(builder, Mosaic.Amount.ToUInt8Array());
            var durationVector  = SecretLockTransactionBuffer.CreateDurationVector(builder, Duration.ToUInt8Array());
            var secretVector    = SecretLockTransactionBuffer.CreateSecretVector(builder, Secret.DecodeHexString());
            var recipientVector =
                SecretLockTransactionBuffer.CreateRecipientVector(builder, Recipient.Plain.FromBase32String());

            var version = int.Parse(NetworkType.GetValueInByte().ToString("X") + "0" + Version.ToString("X"),
                                    NumberStyles.HexNumber);

            // mosaicID, amount, duration, hash algo, secret, recipient
            var totalSize = GetSerializedSize();

            SecretLockTransactionBuffer.StartSecretLockTransactionBuffer(builder);
            SecretLockTransactionBuffer.AddSize(builder, (uint)totalSize);
            SecretLockTransactionBuffer.AddSignature(builder, signatureVector);
            SecretLockTransactionBuffer.AddSigner(builder, signerVector);
            SecretLockTransactionBuffer.AddVersion(builder, (uint)version);
            SecretLockTransactionBuffer.AddType(builder, TransactionType.GetValue());
            SecretLockTransactionBuffer.AddMaxFee(builder, feeVector);
            SecretLockTransactionBuffer.AddDeadline(builder, deadlineVector);
            SecretLockTransactionBuffer.AddMosaicId(builder, mosaicIdVector);
            SecretLockTransactionBuffer.AddMosaicAmount(builder, mosaicAmountVector);
            SecretLockTransactionBuffer.AddDuration(builder, durationVector);
            SecretLockTransactionBuffer.AddHashAlgorithm(builder, HashType.GetValueInByte());
            SecretLockTransactionBuffer.AddSecret(builder, secretVector);
            SecretLockTransactionBuffer.AddRecipient(builder, recipientVector);

            // end build
            var codedTransfer = SecretLockTransactionBuffer.EndSecretLockTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            var output = new SecretLockTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }