/// <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);
        }
示例#2
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}");
        }