/// <summary>
        ///     ToSecretProofTransaction
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="txInfo"></param>
        /// <returns></returns>
        private static SecretProofTransaction ToSecretProofTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }
            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var recipient = Recipient.From(Address.CreateFromHex(transaction["recipient"].ToObject <string>()));
            var hashType  = HashTypeExtension.GetRawValue(transaction["hashAlgorithm"].ToObject <int>());
            var secret    = transaction["secret"].ToObject <string>();
            var proof     = transaction["proof"].ToObject <string>();

            return(new SecretProofTransaction(
                       network, txVersion, deadline, maxFee, hashType, recipient, secret,
                       proof, signature, signer, txInfo));
        }
Beispiel #2
0
        private ExchangeOfferTransaction ToExchangeOfferTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];


            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);

            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();

            return(new ExchangeOfferTransaction(network, txVersion, deadline, maxFee, LoadOffers(transaction, network),
                                                signature));
        }
        private static MosaicSupplyChangeTransaction ToMosaicSupplyChangeTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network          = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion        = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline         = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee           = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64() ?? 0;
            var mosaicId         = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
            var mosaicSupplyType = MosaicSupplyTypeExtension.GetRawValue(transaction["direction"].ToObject <int>());
            var delta            = transaction["delta"].ToObject <UInt64DTO>().ToUInt64();
            var signature        = transaction["signature"].ToObject <string>();
            var signer           = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            return(new MosaicSupplyChangeTransaction(network, txVersion, deadline,
                                                     maxFee, mosaicId, mosaicSupplyType, delta, signature, signer, txInfo));
        }
        /// <summary>
        /// Converts to AccountLinkTransactionMapping
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="txInfo"></param>
        /// <returns></returns>
        private static AccountLinkTransaction ToAccountLinkTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];


            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);

            var deadline      = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee        = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature     = transaction["signature"].ToObject <string>();
            var signer        = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var remoteAccount = new PublicAccount(transaction["remoteAccountKey"].ToObject <string>(), network);

            var action     = transaction["action"] ?? transaction["linkAction"];
            var linkAction = AccountLinkActionExtension.GetRawValue(action.ToObject <int>());

            return(new AccountLinkTransaction(network, txVersion, deadline, maxFee, EntityType.LINK_ACCOUNT,
                                              remoteAccount, linkAction, signature, signer));
        }
        private AggregateTransaction ToAggregateTransactionTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network = TransactionMappingUtils.ExtractNetworkType(versionValue);

            var type              = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var deadline          = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee            = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var innerTransactions = MapInnerTransactions(tx);
            var cosignatures      = MapCosignatures(tx);
            var signature         = transaction["signature"].ToObject <string>();
            var signer            = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            return(new AggregateTransaction(
                       network, TransactionMappingUtils.ExtractTransactionVersion(versionValue), type, deadline, maxFee,
                       innerTransactions, cosignatures, signature, signer, txInfo));
        }
        private static AccountMetadataTransaction ToMetadataTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }
            var network           = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion         = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline          = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee            = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature         = transaction["signature"].ToObject <string>();
            var signer            = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var type              = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var scopedMetadataKey = transaction["scopedMetadataKey"].ToObject <UInt64DTO>().ToUInt64();
            var targetKey         = new PublicAccount(transaction["targetKey"].ToObject <string>(), network);
            var valueSizeDelta    = transaction["valueSizeDelta"].ToObject <short>();
            var valueSize         = transaction["valueSize"].ToObject <ushort>();
            var value             = transaction["value"].ToObject <string>();

            var accountMetadataTransaction = new AccountMetadataTransaction(network, txVersion, type, deadline, maxFee, scopedMetadataKey, targetKey, value, valueSizeDelta, valueSize, signature, signer, txInfo);

            return(accountMetadataTransaction);
        }
Beispiel #7
0
        /// <summary>
        ///     ToModifyAccountPropertyTransaction
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="txInfo"></param>
        /// <returns></returns>
        private static ModifyAccountPropertyTransaction <IUInt64Id> ToModifyAccountPropertyTransaction(JObject tx,
                                                                                                       TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network      = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion    = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline     = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee       = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature    = transaction["signature"].ToObject <string>();
            var signer       = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var type         = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var propertyType = PropertyTypeExtension.GetRawValue(transaction["propertyType"].ToObject <int>());

            var modifications    = transaction["modifications"];
            var modificationList = modifications == null
                ? new List <AccountPropertyModification <IUInt64Id> >()
                : modifications.Select(e =>
            {
                var mt = e["modificationType"] ?? e["type"];
                var modificationType =
                    PropertyModificationTypeExtension.GetRawValue(mt.ToObject <int>());
                var mosaicId     = new MosaicId(e["value"].ToObject <UInt64DTO>().ToUInt64());
                var modification = new AccountPropertyModification <IUInt64Id>(modificationType,
                                                                               mosaicId);
                return(modification);
            }).ToList();

            if (type == EntityType.MODIFY_ACCOUNT_PROPERTY_MOSAIC)
            {
                return(new MosaicModification(
                           network,
                           txVersion,
                           deadline,
                           propertyType,
                           modificationList,
                           maxFee,
                           signature,
                           signer,
                           txInfo
                           ));
            }

            throw new Exception("Unsupported transaction type");
        }
        public void Should_Extract_NetworkType_From_Version()
        {
            var transactionVersion = -1000;

            var networkType = TransactionMappingUtils.ExtractNetworkType(transactionVersion);

            networkType.Should().NotBeNull();
        }
Beispiel #9
0
        public void Should_Extract_TransactionVersion_From_Version()
        {
            var transactionVersion = -1879048189;

            var version = TransactionMappingUtils.ExtractTransactionVersion(transactionVersion);

            version.Should().Be(3);
        }
Beispiel #10
0
        public void Should_Extract_NetworkType_From_Version()
        {
            var transactionVersion = -1879048189;

            var networkType = TransactionMappingUtils.ExtractNetworkType(transactionVersion);

            networkType.Should().Be(NetworkType.MIJIN_TEST);
        }
Beispiel #11
0
        private static AliasTransaction ToAliasTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];


            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);

            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            var namespaceId = new NamespaceId(transaction["namespaceId"].ToObject <UInt64DTO>().ToUInt64());
            var type        = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var actionType  = TransactionMappingHelper.ExtractActionType(tx);

            AliasTransaction aliasTransaction = null;

            switch (type)
            {
            case EntityType.ADDRESS_ALIAS:
                var addressHex = transaction["address"].ToObject <string>();
                var address    = Address.CreateFromHex(addressHex);
                aliasTransaction = new AliasTransaction(network, txVersion, deadline, maxFee, type,
                                                        namespaceId, actionType, null, address, signature, signer, txInfo);
                break;

            case EntityType.MOSAIC_ALIAS:
                var mosaic = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
                aliasTransaction = new AliasTransaction(network, txVersion, deadline, maxFee, type,
                                                        namespaceId, actionType, mosaic, null, signature, signer, txInfo);
                break;
            }

            return(aliasTransaction);
        }
Beispiel #12
0
        private static TransferTransaction ToTransferTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue = -1879048189;
            var version      = transaction["version"];

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var deadline  = transaction["deadline"].ToObject <UInt64DTO>().ToUInt64();
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var recipient = transaction["recipient"]?.ToObject <string>();
            var mosaics   = transaction["mosaics"]?.ToObject <IList <MosaicDTO> >();
            var message   = new JObject();

            if (transaction["message"] != null)
            {
                message = transaction["message"].ToObject <JObject>();
            }

            var signature = transaction["signature"].ToObject <string>();
            var signer    = transaction["signer"].ToObject <string>();

            return(new TransferTransaction(network,
                                           TransactionMappingUtils.ExtractTransactionVersion(versionValue),
                                           new Deadline(deadline),
                                           maxFee,
                                           Recipient.From(Address.CreateFromHex(recipient)),
                                           mosaics != null ? mosaics.Select(m => new Mosaic(new MosaicId(m.Id.ToUInt64()), m.Amount.ToUInt64())).ToList() : new List <Mosaic> {
            },
                                           GetMessage(message),
                                           signature,
                                           new PublicAccount(signer, network),
                                           txInfo
                                           ));
        }
        private static MosaicDefinitionTransaction ToMosaicDefinitionTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();

            var mosaicProperties = transaction["properties"];
            var flags            = "00" + Convert.ToString((int)mosaicProperties[0].ExtractBigInteger("value"), 2);
            var bitMapFlags      = flags.Substring(flags.Length - 3, 3);

            var properties = new MosaicProperties(
                bitMapFlags.ToCharArray()[2] == '1',
                bitMapFlags.ToCharArray()[1] == '1',
                bitMapFlags.ToCharArray()[0] == '1',
                (int)mosaicProperties[1].ExtractBigInteger("value"),
                mosaicProperties.ToList().Count == 3 ? mosaicProperties[2].ExtractBigInteger("value") : 0);

            var version = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);

            var deadline    = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee      = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64() ?? 0;
            var mosaicNonce = TransactionMappingHelper.ExtractMosaicNonce(tx);
            var mosaicId    = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
            var signature   = transaction["signature"].ToObject <string>();
            var signer      = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            return(new MosaicDefinitionTransaction(
                       network, txVersion, deadline, maxFee, mosaicNonce, mosaicId, properties, signature, signer, txInfo));
        }
Beispiel #14
0
        private static ModifyMultisigAccountTransaction ToModifyMultisigAccountTransaction(JObject tx,
                                                                                           TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);


            var minApproved = transaction["minApprovalDelta"].ToObject <int>();
            var minRemoved  = transaction["minRemovalDelta"].ToObject <int>();

            var modifications    = transaction["modifications"];
            var modificationList = modifications == null
                ? new List <MultisigCosignatoryModification>()
                : modifications.Select(e =>
                                       new MultisigCosignatoryModification(
                                           MultisigCosignatoryModificationTypeExtension.GetRawValue(e["type"].ToObject <int>()),
                                           new PublicAccount(e["cosignatoryPublicKey"].ToObject <string>(), network))).ToList();

            return(new ModifyMultisigAccountTransaction(
                       network, txVersion, deadline, maxFee, minApproved,
                       minRemoved, modificationList,
                       signature, signer, txInfo));
        }
        private static RegisterNamespaceTransaction ToRegisterNamespaceTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network       = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion     = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline      = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee        = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var namespaceName = transaction["name"].ToObject <string>();
            var namespaceType = NamespaceTypeExtension.GetRawValue(transaction["namespaceType"].ToObject <int>());
            var namespaceId   = new NamespaceId(transaction["namespaceId"].ToObject <UInt64DTO>().ToUInt64());
            var duration      = namespaceType == NamespaceType.ROOT_NAMESPACE
                ? transaction["duration"].ToObject <UInt64DTO>().ToUInt64()
                : 0;
            var parentId = namespaceType == NamespaceType.SUB_NAMESPACE
                ? new NamespaceId(transaction["parentId"].ToObject <UInt64DTO>()
                                  .ToUInt64())
                : null;
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            return(new RegisterNamespaceTransaction(network, txVersion, deadline, maxFee,
                                                    namespaceName, namespaceId, namespaceType, duration, parentId,
                                                    signature, signer, txInfo));
        }
        /// <summary>
        /// Converts to AccountLinkTransactionMapping
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="txInfo"></param>
        /// <returns></returns>
        private static ModifyMosaicLevyTransaction ToMosaicModifyLevyTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);

            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            var mosaicId      = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
            var levy          = transaction["levy"].ToObject <JObject>();
            var fee           = levy["fee"].ToObject <UInt64DTO>().ToUInt64();
            var type          = MosaicLevyTypeExtension.GetRawValue(levy["type"].ToObject <int>());
            var levy_mosaicId = new MosaicId(levy["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
            var recipient     = levy["recipient"].ToObject <string>();

            var modifyMosaicLevyTransaction = new ModifyMosaicLevyTransaction(network, txVersion, deadline,
                                                                              mosaicId, new MosaicLevy(type, Recipient.From(Address.CreateFromHex(recipient)), levy_mosaicId, fee), maxFee, signature, signer, txInfo);

            return(modifyMosaicLevyTransaction);
        }
        private static LockFundsTransaction ToLockFundsTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];


            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);


            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var mosaic    = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
            var amount    = transaction["amount"].ToObject <UInt64DTO>().ToUInt64();
            var duration  = transaction["duration"].ToObject <UInt64DTO>().ToUInt64();
            var hash      = transaction["hash"].ToObject <string>();

            return(new LockFundsTransaction(network, txVersion, deadline, maxFee,
                                            new Mosaic(mosaic, amount), duration,
                                            new SignedTransaction(string.Empty, hash, string.Empty,
                                                                  EntityType.AGGREGATE_BONDED, network),
                                            signature, signer, txInfo));
        }
 /// <summary>
 /// Get value of the version field for serialization
 /// </summary>
 /// <returns>4 bytes</returns>
 protected int GetTxVersionSerialization()
 {
     return(TransactionMappingUtils.SerializeVersion(Version, NetworkType.GetValue()));
 }
Beispiel #19
0
        private static ModifyMetadataTransaction ToModifyMetadataTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network   = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline  = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee    = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var type      = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var metaType  = MetadataTypeExtension.GetRawValue(transaction["metadataType"].ToObject <int>());


            var modifications    = transaction["modifications"];
            var modificationList = modifications == null
                ? new List <MetadataModification>()
                : modifications.Select(e =>
            {
                var modificationType =
                    MetadataModificationTypeExtension.GetRawValue(e["modificationType"].ToObject <int>());
                var key   = e["key"].ToObject <string>();
                var value = e["value"]?.ToObject <string>();
                MetadataModification metadataModification = null;
                switch (modificationType)
                {
                case MetadataModificationType.ADD:
                    metadataModification = MetadataModification.Add(key, value);
                    break;

                case MetadataModificationType.REMOVE:
                    metadataModification = MetadataModification.Remove(key);
                    break;
                }

                return(metadataModification);
            }).ToList();

            ModifyMetadataTransaction modifyMetadataTransaction = null;

            switch (type)
            {
            case EntityType.MODIFY_ADDRESS_METADATA:
                var address = Address.CreateFromHex(transaction["metadataId"].ToObject <string>());
                modifyMetadataTransaction = new ModifyMetadataTransaction(
                    network, txVersion, type, deadline, maxFee, metaType, null, address,
                    modificationList, signature, signer, txInfo);
                break;

            case EntityType.MODIFY_MOSAIC_METADATA:
                var mosaicId = transaction["metadataId"].ToObject <UInt64DTO>().ToUInt64();
                modifyMetadataTransaction = new ModifyMetadataTransaction(
                    network, txVersion, type, deadline, maxFee, metaType, mosaicId, null,
                    modificationList, signature, signer, txInfo);
                break;

            case EntityType.MODIFY_NAMESPACE_METADATA:
                var namespaceId = transaction["metadataId"].ToObject <UInt64DTO>().ToUInt64();
                modifyMetadataTransaction = new ModifyMetadataTransaction(
                    network, txVersion, type, deadline, maxFee, metaType, namespaceId, null,
                    modificationList, signature, signer, txInfo);
                break;
            }

            return(modifyMetadataTransaction);
        }