public async Task Should_Add_Metadata_To_Namespace()
        {
            var namespaceName = "nsp" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
            var namespaceId   = new NamespaceId(namespaceName);
            var account       = Fixture.SeedAccount;

            await Fixture.SiriusWebSocketClient.Listener.Open();

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(1000));


            Log.WriteLine($"Going to generate namespace {namespaceId}");

            var registerRootTransaction = RegisterNamespaceTransaction.CreateRootNamespace(
                Deadline.Create(),
                namespaceName,
                100,
                Fixture.NetworkType
                );

            var signedTransaction = account.Sign(registerRootTransaction, Fixture.GenerationHash);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);


            var result = await tx;

            Log.WriteLine($"Request register namespace confirmed with transaction {result.TransactionInfo.Hash}");


            var modifications = new List <MetadataModification>
            {
                MetadataModification.Add("company", "ProximaX"),
                MetadataModification.Add("department", "IT")
            };

            var modifyMetadataTransaction = ModifyMetadataTransaction.CreateForNamespace(
                Deadline.Create(),
                namespaceId,
                modifications,
                Fixture.NetworkType);

            signedTransaction = account.Sign(modifyMetadataTransaction, Fixture.GenerationHash);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            result = await tx;
            Log.WriteLine($"Request add metadata to namespace confirmed with transaction {result.TransactionInfo.Hash}");


            var metaInfo = await Fixture.SiriusClient.MetadataHttp.GetMetadataFromNamespace(namespaceId);

            metaInfo.Fields.Should().HaveCount(2);
            metaInfo.Type.Should().BeEquivalentTo(MetadataType.NAMESPACE);
        }
        public async Task Should_Add_Metadata_To_Address()
        {
            var account = Account.GenerateNewAccount(Fixture.NetworkType);

            await Fixture.SiriusWebSocketClient.Listener.Open();

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1)
                     .Timeout(TimeSpan.FromSeconds(1000));

            Log.WriteLine($"Generated account {account}");

            var modifications = new List <MetadataModification>
            {
                MetadataModification.Add("productId", "123"),
                MetadataModification.Add("productName", "TestProduct")
            };

            var modifyMetadataTransaction = ModifyMetadataTransaction.CreateForAddress(
                Deadline.Create(),
                account.Address,
                modifications,
                Fixture.NetworkType);

            var signedTransaction = account.Sign(modifyMetadataTransaction, Fixture.GenerationHash);

            Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}");



            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;

            Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}");


            var metaInfo = await Fixture.SiriusClient.MetadataHttp.GetMetadataFromAddress(account.Address);

            metaInfo.Fields.Should().HaveCount(2);
            metaInfo.Type.Should().BeEquivalentTo(MetadataType.ADDRESS);
        }
        public async Task Should_Remove_Metadata_From_Mosaic()
        {
            var account = Fixture.SeedAccount;

            await Fixture.SiriusWebSocketClient.Listener.Open();

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(500));

            var nonce    = MosaicNonce.CreateRandom();
            var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey);

            Log.WriteLine($"Going to generate mosaicId {mosaicId}");

            var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create(
                nonce,
                mosaicId,
                Deadline.Create(),
                MosaicProperties.Create(
                    supplyMutable: true,
                    transferable: true,
                    levyMutable: false,
                    divisibility: 0,
                    duration: 1000
                    ),
                Fixture.NetworkType);


            var signedTransaction = account.Sign(mosaicDefinitionTransaction, Fixture.GenerationHash);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);


            var result = await tx;

            Log.WriteLine($"Request create mosaic confirmed with transaction {result.TransactionInfo.Hash}");

            var modifications = new List <MetadataModification>
            {
                MetadataModification.Add("company", "ProximaX"),
                MetadataModification.Add("department", "IT")
            };

            var modifyMetadataTransaction = ModifyMetadataTransaction.CreateForMosaic(
                Deadline.Create(),
                mosaicId,
                modifications,
                Fixture.NetworkType);

            signedTransaction = account.Sign(modifyMetadataTransaction, Fixture.GenerationHash);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            result = await tx;
            Log.WriteLine($"Request add metadata to mosaic confirmed with transaction {result.TransactionInfo.Hash}");

            modifications = new List <MetadataModification>
            {
                MetadataModification.Remove("department")
            };

            modifyMetadataTransaction = ModifyMetadataTransaction.CreateForMosaic(
                Deadline.Create(),
                mosaicId,
                modifications,
                Fixture.NetworkType);

            signedTransaction = account.Sign(modifyMetadataTransaction, Fixture.GenerationHash);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            result = await tx;
            Log.WriteLine($"Request remove metadata from mosaic confirmed with transaction {result.TransactionInfo.Hash}");


            var metaInfo = await Fixture.SiriusClient.MetadataHttp.GetMetadataFromMosaic(mosaicId);

            metaInfo.Fields.Should().HaveCount(1);
            metaInfo.Type.Should().BeEquivalentTo(MetadataType.MOSAIC);
        }
Exemple #4
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);
        }