示例#1
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}");
        }
示例#2
0
        public async Task Should_Create_Mosaic()
        {
            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: 1000
                    ),
                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}");

            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 mosaic_Id = new MosaicId(mosaicId.HexId);

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

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

            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);
        }
示例#3
0
        public async Task Should_Link_Namespace_To_Mosaic()
        {
            #region Create mosaic

            var account = await Fixture.GenerateAccountWithCurrency(150000);

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

            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 Create mosaic

            #region register new namespace

            var namespaceName = "haieng";
            //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 register new namespace

            #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 Link namespace to the mosaic

            #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 Send mosaic using namespace alias to recipient
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SupplyChangeTransaction"/> 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="delta">The delta.</param>
 /// <param name="mosaicId">The mosaic identifier.</param>
 /// <param name="supplyType">Type of the supply.</param>
 public SupplyChangeTransaction(NetworkType.Types networkType, int version, Deadline deadline, ulong fee, ulong delta, MosaicId mosaicId, int supplyType)
 {
     TransactionType = TransactionTypes.Types.SupplyChange;
     Version         = version;
     Deadline        = deadline;
     NetworkType     = networkType;
     Fee             = fee == 0 ? 150000 : fee;
     Delta           = delta;
     MosaicId        = mosaicId;
     SupplyType      = supplyType;
 }
 /// <summary>
 /// Initializes a new signed instance of the <see cref="SupplyChangeTransaction"/> class.
 /// </summary>
 /// <param name="networkType">Type of the network.</param>
 /// <param name="version">The version.</param>
 /// <param name="networkTime">The networkTime.</param>
 /// <param name="deadline">The deadline.</param>
 /// <param name="fee">The fee.</param>
 /// <param name="delta">The delta.</param>
 /// <param name="mosaicId">The mosaic identifier.</param>
 /// <param name="supplyType">Type of the supply.</param>
 /// <param name="signature">The signature.</param>
 /// <param name="signer">The signer.</param>
 /// <param name="transactionInfo">The transaction information.</param>
 public SupplyChangeTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, ulong delta, MosaicId mosaicId, int supplyType, string signature, PublicAccount signer, TransactionInfo transactionInfo)
 {
     TransactionType = TransactionTypes.Types.SupplyChange;
     Version         = version;
     NetworkTime     = networkTime;
     Deadline        = deadline;
     NetworkType     = networkType;
     Signature       = signature;
     Signer          = signer;
     TransactionInfo = transactionInfo;
     Fee             = fee == 0 ? 150000 : fee;
     Delta           = delta;
     MosaicId        = mosaicId;
     SupplyType      = supplyType;
 }
 /// <summary>
 ///  Creates a supply decrease instance of SupplyChangeTransaction.
 /// </summary>
 /// <param name="network">The network.</param>
 /// <param name="deadline">The deadline.</param>
 /// <param name="delta">The delta.</param>
 /// <param name="mosaicId">The mosaic identifier.</param>
 /// <returns>SupplyChangeTransaction.</returns>
 public static SupplyChangeTransaction CreateDecrease(NetworkType.Types network, Deadline deadline, ulong delta, MosaicId mosaicId)
 {
     return(new SupplyChangeTransaction(network, 1, deadline, 150000, delta, mosaicId, 2));
 }
 public static RemoveMosaicLevyTransaction Create(Deadline deadline, MosaicId mosaicid, NetworkType networkType)
 {
     return(new RemoveMosaicLevyTransaction(networkType, EntityVersion.REMOVE_MOSAIC_LEVY_VERSION.GetValue(), deadline, mosaicid, 0));
 }
 public RemoveMosaicLevyTransaction(NetworkType networkType, int version, Deadline deadline, MosaicId mosaidId, ulong?maxFee, string signature = null, PublicAccount signer = null, TransactionInfo transactionInfo = null) : base(networkType, version, EntityType.REMOVE_MOSAIC_LEVY, deadline, maxFee, signature, signer, transactionInfo)
 {
     MosaicId = mosaidId;
 }
示例#9
0
 public ModifyMosaicLevyTransactionBuilder SetMosaicId(MosaicId mosaicId)
 {
     MosaicId = mosaicId;
     return(Self());
 }
        public async Task Should_Add_Account_Filter_With_Allow_Mosaic()
        {
            var company = await Fixture.GenerateAccountWithCurrency(1000);


            var allowedMosaic = await Fixture.CreateMosaic(company);

            var accountFilter = ModifyAccountPropertyTransaction <IUInt64Id> .CreateForMosaic(
                Deadline.Create(),
                (ulong)0,
                PropertyType.ALLOW_MOSAIC,
                new List <AccountPropertyModification <IUInt64Id> >()
            {
                new AccountPropertyModification <IUInt64Id>(PropertyModificationType.ADD, allowedMosaic)
            },
                Fixture.NetworkType);

            Log.WriteLine($"Going to filter the address {company.Address} ");

            await Fixture.SiriusWebSocketClient.Listener.Open();

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


            var signedTransaction = accountFilter.SignWith(company, 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 accountProperties = await Fixture.SiriusClient.AccountHttp.GetAccountProperty(company.PublicAccount);

            accountProperties.Should().NotBeNull();
            var allowMosaicProperty =
                accountProperties.AccountProperties.Properties.Single(ap =>
                                                                      ap.PropertyType == PropertyType.ALLOW_MOSAIC);

            allowMosaicProperty.Should().NotBeNull();

            bool hasAllowMosaic = false;

            foreach (var am in allowMosaicProperty.Values)
            {
                var m   = JsonConvert.DeserializeObject <UInt64DTO>(am.ToString());
                var mId = new MosaicId(m.FromUInt8Array());

                if (mId.Id.ToHex().Equals(allowedMosaic.HexId))
                {
                    hasAllowMosaic = true;
                }
            }
            hasAllowMosaic.Should().Be(true);

            /* var allowMosaic = allowMosaicProperty.Values
             *   .Single(a =>
             *   {
             *       var m = JsonConvert.DeserializeObject<UInt64DTO>(a.ToString());
             *       return (new MosaicId(m.ToUInt64())).HexId == allowedMosaic.HexId;
             *   });
             * allowMosaic.Should().NotBeNull();*/
        }