Beispiel #1
0
        public void CreateAMosaicInfoViaConstructor()
        {
            var mosaicProperties = new MosaicProperties(true, true, true, 3, 10);

            var mosaicInfo = new MosaicInfo(true,
                                            1,
                                            "5A3CD9B09CD1E8000159249B",
                                            new NamespaceId(9562080086528621131),
                                            new MosaicId(15358872602548358953),
                                            100,
                                            1,
                                            new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.Types.MIJIN_TEST),
                                            mosaicProperties);

            Assert.AreEqual(true, mosaicInfo.IsActive);
            Assert.IsTrue(mosaicInfo.Index == 1);
            Assert.AreEqual("5A3CD9B09CD1E8000159249B", mosaicInfo.MetaId);
            Assert.AreEqual(9562080086528621131, mosaicInfo.NamespaceId.Id);
            Assert.AreEqual(15358872602548358953, mosaicInfo.MosaicId.Id);
            Assert.AreEqual((ulong)100, mosaicInfo.Supply);
            Assert.AreEqual((ulong)1, mosaicInfo.Height);
            Assert.AreEqual(new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.Types.MIJIN_TEST).Address.Plain, mosaicInfo.Owner.Address.Plain);
            Assert.IsTrue(mosaicInfo.IsSupplyMutable);
            Assert.IsTrue(mosaicInfo.IsTransferable);
            Assert.IsTrue(mosaicInfo.IsLevyMutable);
            Assert.AreEqual(3, mosaicInfo.Divisibility);
            Assert.AreEqual((ulong)10, mosaicInfo.Duration);
        }
        internal new MosaicDefinitionTransaction Apply(string input)
        {
            var tx               = JsonConvert.DeserializeObject <MosaicCreationTransactionInfoDTO>(input);
            var transaction      = tx.Transaction;
            var mosaicProperties = tx.Transaction.Properties;
            var flags            = "00" + Convert.ToString((long)mosaicProperties[0].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].value,
                                                  mosaicProperties.Count == 3 ? mosaicProperties[2].value : 0);

            return(new MosaicDefinitionTransaction(
                       ExtractNetworkType(tx.Transaction.Version),
                       ExtractTransactionVersion(tx.Transaction.Version),
                       new Deadline(tx.Transaction.Deadline),
                       transaction.Fee,
                       transaction.Name,
                       new NamespaceId(transaction.ParentId),
                       new MosaicId(transaction.MosaicId),
                       properties,
                       transaction.Signature,
                       new PublicAccount(transaction.Signer, ExtractNetworkType(tx.Transaction.Version)),
                       TransactionInfo.Create(tx.Meta.Height, tx.Meta.Index, tx.Meta.Id, tx.Meta.Hash, tx.Meta.MerkleComponentHash)
                       ));
        }
Beispiel #4
0
        public void ShouldCreateMosaicPropertiesViaBuilder()
        {
            var mosaicProperties = new MosaicProperties(true, true, true, 1, 1000);

            Assert.IsTrue(mosaicProperties.IsSupplyMutable);
            Assert.IsTrue(mosaicProperties.IsTransferable);
            Assert.IsTrue(mosaicProperties.IsLevyMutable);
            Assert.IsTrue(1 == mosaicProperties.Divisibility);
            Assert.AreEqual((ulong)1000, mosaicProperties.Duration);
        }
 /// <summary>
 ///     Constructor.
 /// </summary>
 public MosaicDefinitionTransaction(NetworkType networkType, int version, Deadline deadline, ulong maxFee,
                                    MosaicNonce nonce, MosaicId mosaicId, MosaicProperties properties, string signature = null,
                                    PublicAccount signer = null, TransactionInfo transactionInfo = null)
     : base(networkType, version, EntityType.MOSAIC_DEFINITION, deadline, maxFee, signature, signer,
            transactionInfo)
 {
     Properties  = properties;
     MosaicId    = mosaicId;
     MosaicNonce = nonce;
 }
Beispiel #6
0
        private static MosaicProperties ExtractMosaicProperties(List <MosaicPropertyDTO> properties)
        {
            var flags       = "00" + Convert.ToString((long)properties[0].Value.FromUInt8Array(), 2);
            var bitMapFlags = flags.Substring(flags.Length - 3, 3);

            return(MosaicProperties.Create(bitMapFlags.ToCharArray()[2] == '1',
                                           bitMapFlags.ToCharArray()[1] == '1',
                                           bitMapFlags.ToCharArray()[0] == '1',
                                           (int)properties[1].Value.FromUInt8Array(),
                                           properties.Count == 3 ? properties[2].Value.FromUInt8Array() : 0));
        }
        public static MosaicDefinitionTransaction Create(MosaicNonce nonce, MosaicId mosaicId, Deadline deadline,
                                                         MosaicProperties properties, NetworkType networkType)
        {
            if (mosaicId == null)
            {
                throw new ArgumentNullException(nameof(mosaicId));
            }

            return(new MosaicDefinitionTransaction(networkType, EntityVersion.MOSAIC_DEFINITION.GetValue(),
                                                   deadline, 0, nonce, mosaicId, properties));
        }
        public async Task <MosaicId> CreateMosaic(Account account)
        {
            var nonce    = MosaicNonce.CreateRandom();
            var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey);

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

            var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicSupplyType.INCREASE,
                1000000,
                NetworkType);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                mosaicDefinitionTransaction.ToAggregate(account.PublicAccount),
                mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount)
            },
                NetworkType);

            var signedTransaction = account.Sign(aggregateTransaction, GenerationHash);

            WatchForFailure(signedTransaction);



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

            await SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;


            return(mosaicId);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public MosaicDefinitionTransaction(NetworkType.Types networkType, int version, Deadline deadline, ulong fee, string mosaicName, NamespaceId namespaceId, MosaicId mosaicId, MosaicProperties properties, string signature, PublicAccount signer, TransactionInfo transactionInfo)
 {
     Deadline        = deadline;
     NetworkType     = networkType;
     Version         = version;
     Properties      = properties;
     MosaicId        = mosaicId;
     NamespaceId     = namespaceId;
     MosaicName      = mosaicName;
     Fee             = fee;
     TransactionType = TransactionTypes.Types.MosaicDefinition;
     Signature       = signature;
     Signer          = signer;
     TransactionInfo = transactionInfo;
 }
Beispiel #10
0
        public void ShouldReturnIsTransferableWhenItsTransferable()
        {
            var mosaicProperties = new MosaicProperties(true, true, true, 3, 10);

            var mosaicInfo = new MosaicInfo(true,
                                            1,
                                            "5A3CD9B09CD1E8000159249B",
                                            new NamespaceId(9562080086528621131),
                                            new MosaicId(15358872602548358953),
                                            100,
                                            1,
                                            new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.Types.MIJIN_TEST),
                                            mosaicProperties);

            Assert.IsTrue(mosaicInfo.IsTransferable);
        }
        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 #12
0
        public async Task Should_Increase_Mosaic_Supply()
        {
            var account = Fixture.SeedAccount;

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

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

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

            var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicSupplyType.INCREASE,
                1000000,
                Fixture.NetworkType);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                mosaicDefinitionTransaction.ToAggregate(account.PublicAccount),
                mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount)
            },
                Fixture.NetworkType);

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

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

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

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

            var result = await tx;

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



            var mosaicDecreaseSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicSupplyType.INCREASE,
                500000,
                Fixture.NetworkType);

            const ulong expectedAmount = 1000000 + 500000;

            var signedDecreaseTransaction = account.Sign(mosaicDecreaseSupplyChangeTransaction, Fixture.GenerationHash);
            await Fixture.SiriusClient.TransactionHttp.Announce(signedDecreaseTransaction);

            var result2 = await tx;

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

            var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId);

            mosaicInfo.Should().NotBeNull();
            mosaicInfo.Divisibility.Should().Be(3);
            mosaicInfo.Duration.Should().Be(1000);
            mosaicInfo.IsLevyMutable.Should().BeFalse();
            mosaicInfo.IsSupplyMutable.Should().BeTrue();
            mosaicInfo.IsTransferable.Should().BeTrue();
            mosaicInfo.Supply.Should().Be(expectedAmount);
        }
Beispiel #13
0
 /// <summary>
 /// Creates a mosaic with a levy.
 /// </summary>
 /// <param name="networkType">Type of the network.</param>
 /// <param name="deadline">The deadline.</param>
 /// <param name="properties">The properties.</param>
 /// <param name="mosaic">The mosaic.</param>
 /// <param name="levy">The levy.</param>
 /// <param name="creator">The creator.</param>
 /// <param name="description">The description.</param>
 /// <returns>MosaicDefinitionTransaction.</returns>
 public static MosaicDefinitionTransaction CreateWithLevy(NetworkType.Types networkType, Deadline deadline, MosaicProperties properties, MosaicId mosaic, MosaicLevy levy, PublicAccount creator, string description)
 {
     return(new MosaicDefinitionTransaction(networkType, 1, deadline, 150000, properties, mosaic, levy, creator, description));
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MosaicDefinitionTransaction"/> class.
 /// </summary>
 /// <param name="networkType">Type of the network.</param>
 /// <param name="version">The version.</param>
 /// <param name="deadline">The deadline.</param>
 /// <param name="fee">The fee.</param>
 /// <param name="properties">The properties.</param>
 /// <param name="mosaic">The mosaic.</param>
 /// <param name="mosaicLevy">The mosaic levy.</param>
 /// <param name="creator">The creator.</param>
 /// <param name="description">The description.</param>
 /// <exception cref="System.ArgumentNullException">
 /// properties
 /// or
 /// mosaic
 /// or
 /// creator
 /// </exception>
 public MosaicDefinitionTransaction(NetworkType.Types networkType, int version, Deadline deadline, ulong fee, MosaicProperties properties, MosaicId mosaic, MosaicLevy mosaicLevy, PublicAccount creator, string description)
 {
     TransactionType = TransactionTypes.Types.MosaicDefinition;
     Version         = version;
     Deadline        = deadline;
     NetworkType     = networkType;
     Fee             = fee == 0 ? 150000 : fee;
     Properties      = properties ?? throw new ArgumentNullException(nameof(properties));
     Mosaic          = mosaic ?? throw new ArgumentNullException(nameof(mosaic));
     Creator         = creator ?? throw new ArgumentNullException(nameof(creator));
     Description     = description;
     MosaicLevy      = mosaicLevy;
 }
 public static MosaicDefinitionTransaction Create(NetworkType.Types networkType, Deadline deadline, string namespaceId, string mosaicName, MosaicProperties properties)
 {
     return(new MosaicDefinitionTransaction(
                networkType,
                3,
                deadline,
                0,
                mosaicName,
                NamespaceId.Create(namespaceId),
                MosaicId.CreateFromMosaicIdentifier(namespaceId + ":" + mosaicName),
                properties
                ));
 }
Beispiel #16
0
 /// <summary>
 /// Creates the mosaic without a levy.
 /// </summary>
 /// <param name="networkType">Type of the network.</param>
 /// <param name="deadline">The deadline.</param>
 /// <param name="fee">The fee.</param>
 /// <param name="properties">The properties.</param>
 /// <param name="mosaic">The mosaic.</param>
 /// <param name="creator">The creator.</param>
 /// <param name="description">The description.</param>
 /// <returns>MosaicDefinitionTransaction.</returns>
 public static MosaicDefinitionTransaction CreateWithoutLevy(NetworkType.Types networkType, Deadline deadline, ulong fee, MosaicProperties properties, MosaicId mosaic, PublicAccount creator, string description)
 {
     return(new MosaicDefinitionTransaction(networkType, 1, deadline, fee, properties, mosaic, null, creator, description));
 }
        public async Task Should_Add_Metadata_To_Mosaic()
        {
            var account = await Fixture.GenerateAccountWithCurrency(10000);

            Log.WriteLine($"Company Account {account.Address.Plain} \r\n Private Key: {account.PrivateKey} \r\n Public Key {account.PublicKey}");
            var nonce    = MosaicNonce.CreateRandom();
            var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey);

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

            Log.WriteLine($"Going to create mosaic {mosaicDefinitionTransaction.MosaicId.HexId}");

            var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicSupplyType.INCREASE,
                1000,
                Fixture.NetworkType);
            var aggregateTransactiontx = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                mosaicDefinitionTransaction.ToAggregate(account.PublicAccount),
                mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount)
            },
                Fixture.NetworkType);
            var aggregateTransactionsigned = account.Sign(aggregateTransactiontx, Fixture.GenerationHash);
            await Fixture.SiriusWebSocketClient.Listener.Open();

            Log.WriteLine($"Going to announce aggregate transaction: {aggregateTransactionsigned.Hash}");
            await Fixture.SiriusClient.TransactionHttp.Announce(aggregateTransactionsigned);

            var metadatatrx = MosaicMetadataTransaction.Create(
                Deadline.Create(),
                account.PublicAccount,
                mosaicDefinitionTransaction.MosaicId,
                "test_mosaic",
                "1",
                "",
                Fixture.NetworkType);
            var aggregateTransaction = AggregateTransaction.CreateBonded(
                Deadline.Create(),
                new List <Transaction>
            {
                metadatatrx.ToAggregate(account.PublicAccount),
            },
                Fixture.NetworkType);

            var aggregateTrxsigned = account.Sign(aggregateTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(aggregateTransactionsigned);

            var hashLockTransaction = HashLockTransaction.Create(
                Deadline.Create(),
                //new Mosaic(new MosaicId("0BB1469B94E6FEF8"), 10),
                NetworkCurrencyMosaic.CreateRelative(10),
                (ulong)3650,
                aggregateTrxsigned,
                Fixture.NetworkType);

            var hashLockTransactionSigned = account.Sign(hashLockTransaction, Fixture.GenerationHash);

            Log.WriteLine($"Going to announce hashlock transaction: {hashLockTransactionSigned.Hash}");
            await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned);

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

            Fixture.WatchForFailure(hashLockTransactionSigned);
            var hashLockConfirmed = await hashLocktx;

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

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

            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(aggregateTransactionsigned);

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

            var MosaicMetadataDetail = await Fixture.SiriusClient.MetadataHttp.SearchMetadata(new MetadataQueryParams(1, Order.ASC, 1, Address.CreateFromRawAddress(account.Address.ToString()), null, null, null));

            Log.WriteLine($"Metadata mosaic {MosaicMetadataDetail}");
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public MosaicDefinitionTransaction(NetworkType.Types networkType, int version, Deadline deadline, ulong fee, string mosaicName, NamespaceId namespaceId, MosaicId mosaicId, MosaicProperties properties)
     : this(networkType, version, deadline, fee, mosaicName, namespaceId, mosaicId, properties, null, null, null)
 {
 }
        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);
        }
Beispiel #20
0
        public async Task Should_Create_Mosaic_With_Builder()
        {
            var account  = Fixture.SeedAccount;
            var nonce    = MosaicNonce.CreateRandom();
            var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey);
            var builder  = new MosaicDefinitionTransactionBuilder();

            builder.SetNonce(nonce)
            .SetMosaicId(mosaicId)
            .SetMosaicProperties(MosaicProperties.Create(
                                     supplyMutable: true,
                                     transferable: true,
                                     levyMutable: false,
                                     divisibility: 0,
                                     duration: 1000
                                     ))
            .SetDeadline(Deadline.Create())
            .SetNetworkType(Fixture.NetworkType);

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


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

            var supplyBuilder = new MosaicSupplyChangeTransactionBuilder();

            supplyBuilder
            .SetDeadline(Deadline.Create())
            .SetNetworkType(Fixture.NetworkType)
            .IncreaseSupplyFor(mosaicDefinitionTransaction.MosaicId)
            .SetDelta(1000000);

            var mosaicSupplyChangeTransaction = supplyBuilder.Build();

            /*
             * var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
             * Deadline.Create(),
             * mosaicDefinitionTransaction.MosaicId,
             * MosaicSupplyType.INCREASE,
             * 1000000,
             * Fixture.NetworkType);
             */

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                mosaicDefinitionTransaction.ToAggregate(account.PublicAccount),
                mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount)
            },
                Fixture.NetworkType);

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

            Fixture.WatchForFailure(signedTransaction);

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

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

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

            var result = await tx;

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


            var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId);

            Log.WriteLine($"Mosaic created {mosaicInfo}");

            mosaicInfo.Should().NotBeNull();
            mosaicInfo.Divisibility.Should().Be(0);
            mosaicInfo.Duration.Should().Be(1000);
            mosaicInfo.IsLevyMutable.Should().BeFalse();
            mosaicInfo.IsSupplyMutable.Should().BeTrue();
            mosaicInfo.IsTransferable.Should().BeTrue();
            mosaicInfo.Supply.Should().Be(1000000);
        }
Beispiel #21
0
        public async Task Should_Link_Namespace_To_Mosaic()
        {
            #region Create mosaic

            var account = await Fixture.GenerateAccountWithCurrency(1500);

            var nonce = MosaicNonce.CreateRandom();

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

            var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicSupplyType.INCREASE,
                1000000,
                Fixture.NetworkType);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                mosaicDefinitionTransaction.ToAggregate(account.PublicAccount),
                mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount)
            },
                Fixture.NetworkType);

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

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

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

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

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

            var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId);

            mosaicInfo.Should().NotBeNull();
            mosaicInfo.Divisibility.Should().Be(0);
            mosaicInfo.Duration.Should().Be(1000);
            mosaicInfo.IsLevyMutable.Should().BeFalse();
            mosaicInfo.IsSupplyMutable.Should().BeTrue();
            mosaicInfo.IsTransferable.Should().BeTrue();
            mosaicInfo.Supply.Should().Be(1000000);
            #endregion

            #region register new namespace
            var namespaceName = "nsp" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
            var registerNamespaceTransaction = RegisterNamespaceTransaction.CreateRootNamespace(
                Deadline.Create(),
                namespaceName,
                100,
                Fixture.NetworkType
                );

            var registeredNsSignedTransaction = account.Sign(registerNamespaceTransaction, Fixture.GenerationHash);

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

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

            Log.WriteLine(
                $"Registered namespace {namespaceName} for account {account.Address.Plain} with transaction {registeredNsSignedTransaction.Hash}");

            result = await tx;

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

            var expectedId = new NamespaceId(namespaceName);

            var nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId);

            Log.WriteLine(
                $"Retrieved namespace {namespaceName} successfully. The namespace HexId {nsInfo.Id.HexId}");
            nsInfo.Should().NotBeNull();
            #endregion

            #region Link namespace to the mosaic
            var mosaicAliasTransaction = AliasTransaction.CreateForMosaic(
                mosaicInfo.MosaicId,
                nsInfo.Id,
                AliasActionType.LINK,
                Deadline.Create(),
                Fixture.NetworkType
                );

            tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1);

            var aliasSignedTransaction = account.Sign(mosaicAliasTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(aliasSignedTransaction);

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

            result = await tx;

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


            nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId);

            nsInfo.Should().NotBeNull();
            nsInfo.HasAlias.Should().BeTrue();
            nsInfo.Alias.Type.Should().BeEquivalentTo(AliasType.MOSAIC_ID);
            nsInfo.Alias.MosaicId.HexId.Should().BeEquivalentTo(mosaicInfo.MosaicId.HexId);

            #endregion

            #region Send mosaic using namespace alias to recipient

            var newAccount = Account.GenerateNewAccount(Fixture.NetworkType);

            var transferTransaction = TransferTransaction.Create(
                Deadline.Create(),
                Recipient.From(newAccount.Address),
                new List <Mosaic>()
            {
                new Mosaic(nsInfo.Id, 10)
            },
                PlainMessage.Create("Send some mosaic to new address"),
                Fixture.NetworkType);

            var tx2 = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(newAccount.Address).Take(1)
                      .Timeout(TimeSpan.FromSeconds(3000));

            var nsSignedTransferTransaction = account.Sign(transferTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(nsSignedTransferTransaction);

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

            var result2 = await tx2;

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

            var newAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(newAccount.Address);

            Log.WriteLine($"Account {newAccountInfo.Address.Plain} with mosaic {newAccountInfo.Mosaics[0]} after transfer to the namespace alias");

            var expectedMosaicAmount = Convert.ToUInt64(10);
            newAccountInfo.Mosaics[0].Id.Id.Should().Be(mosaicInfo.MosaicId.Id);
            newAccountInfo.Mosaics[0]?.Amount.Should().Be(expectedMosaicAmount);
            #endregion
        }
Beispiel #22
0
        public async Task Should_Create_Levy_WithPercentageFee()
        {
            var account  = Fixture.SeedAccount;
            var nonce    = MosaicNonce.CreateRandom();
            var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey);
            var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create(
                nonce,
                mosaicId,
                Deadline.Create(),
                MosaicProperties.Create(
                    supplyMutable: true,
                    transferable: true,
                    levyMutable: false,
                    divisibility: 0,
                    duration: 0
                    ),
                Fixture.NetworkType);

            Log.WriteLine($"Going to create mosaic {mosaicDefinitionTransaction.MosaicId.HexId}");
            Log.WriteLine($"{account.PublicAccount.PublicKey}");
            Log.WriteLine($"{account.PublicAccount.Address}");

            var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicSupplyType.INCREASE,
                1000000,
                Fixture.NetworkType);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                mosaicDefinitionTransaction.ToAggregate(account.PublicAccount),
                mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount)
            },
                Fixture.NetworkType);

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

            Fixture.WatchForFailure(signedTransaction);

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

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

            var recipient = Account.GenerateNewAccount(Fixture.NetworkType);

            var mosaic_Id = new MosaicId(mosaicId.HexId);

            Log.WriteLine($"Mosaic Id: {mosaic_Id.HexId}");
            var mosaicLevy = ModifyMosaicLevyTransaction.Create(
                Deadline.Create(),
                mosaicDefinitionTransaction.MosaicId,
                MosaicLevy.CreateWithPercentageFee(
                    Recipient.From(recipient.Address),
                    mosaicDefinitionTransaction.MosaicId, 200),
                Fixture.NetworkType);
            var signedTransaction_mosaicLevy = account.Sign(mosaicLevy, Fixture.GenerationHash);

            Fixture.WatchForFailure(signedTransaction_mosaicLevy);
            var tx_Levy = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(3000));
            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction_mosaicLevy);

            var result_levy = await tx_Levy;

            Log.WriteLine($"Request confirmed with transaction {result_levy.TransactionInfo.Hash}");
        }
Beispiel #23
0
 public MosaicDefinitionTransactionBuilder SetMosaicProperties(MosaicProperties mosaicProperties)
 {
     MosaicProperties = mosaicProperties;
     return(Self());
 }