Beispiel #1
0
        public async Task <IActionResult> PostDeadline([FromBody] Deadline deadline)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var isAdmin = _usercontext.IsAdmin(this.User);

            if (!isAdmin)
            {
                return(null);
            }

            _context.Deadline.Add(deadline);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDeadline", new { id = deadline.Id }, deadline));
        }
Beispiel #2
0
 private Receive ReceiveWhenSuspended(TimeSpan suspendDuration, Deadline suspendDeadline)
 {
     return(message =>
     {
         if (message is DeadLetter deadLetter)
         {
             IncrementCount();
             if (suspendDeadline.IsOverdue)
             {
                 var doneMsg = $", of which {(_count - _maxCount - 1).ToString()} were not logged. The counter will be reset now";
                 LogDeadLetter(deadLetter.Message, deadLetter.Sender, deadLetter.Recipient, doneMsg);
                 _count = 0;
                 Context.Become(ReceiveWithSuspendLogging(suspendDuration));
             }
             return true;
         }
         return false;
     });
 }
Beispiel #3
0
        public void ShouldUploadWithTransactionDeadlinesProvided()
        {
            var param = UploadParameter
                        .CreateForStringUpload(TestString, AccountPrivateKey1)
                        .WithTransactionDeadline(2)
                        .Build();

            var result = UnitUnderTest.Upload(param);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.TransactionHash);
            var transaction = WaitForTransactionConfirmation(AccountPrivateKey1, result.TransactionHash);

            Assert.IsTrue(transaction is TransferTransaction);
            Assert.IsTrue((transaction as TransferTransaction).Deadline.GetInstant() <=
                          Deadline.CreateHours(2).GetInstant());

            LogAndSaveResult(result, GetType().Name + ".ShouldUploadWithTransactionDeadlinesProvided");
        }
Beispiel #4
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = Id;
         result = (result * 397) ^ (State != null ? State.GetHashCode() : 0);
         result = (result * 397) ^ StateEnum.GetHashCode();
         result = (result * 397) ^ Project;
         result = (result * 397) ^ Run;
         result = (result * 397) ^ Clone;
         result = (result * 397) ^ Gen;
         result = (result * 397) ^ (Core != null ? Core.GetHashCode() : 0);
         result = (result * 397) ^ (UnitId != null ? UnitId.GetHashCode() : 0);
         result = (result * 397) ^ (PercentDone != null ? PercentDone.GetHashCode() : 0);
         result = (result * 397) ^ TotalFrames;
         result = (result * 397) ^ FramesDone;
         result = (result * 397) ^ (Assigned != null ? Assigned.GetHashCode() : 0);
         result = (result * 397) ^ (AssignedDateTime.HasValue ? AssignedDateTime.Value.GetHashCode() : 0);
         result = (result * 397) ^ (Timeout != null ? Timeout.GetHashCode() : 0);
         result = (result * 397) ^ (TimeoutDateTime.HasValue ? TimeoutDateTime.Value.GetHashCode() : 0);
         result = (result * 397) ^ (Deadline != null ? Deadline.GetHashCode() : 0);
         result = (result * 397) ^ (DeadlineDateTime.HasValue ? DeadlineDateTime.Value.GetHashCode() : 0);
         result = (result * 397) ^ (WorkServer != null ? WorkServer.GetHashCode() : 0);
         result = (result * 397) ^ (WorkServerIPAddress != null ? WorkServerIPAddress.GetHashCode() : 0);
         result = (result * 397) ^ (CollectionServer != null ? CollectionServer.GetHashCode() : 0);
         result = (result * 397) ^ (CollectionServerIPAddress != null ? CollectionServerIPAddress.GetHashCode() : 0);
         result = (result * 397) ^ (WaitingOn != null ? WaitingOn.GetHashCode() : 0);
         result = (result * 397) ^ Attempts;
         result = (result * 397) ^ (NextAttempt != null ? NextAttempt.GetHashCode() : 0);
         result = (result * 397) ^ (NextAttemptTimeSpan.HasValue ? NextAttemptTimeSpan.Value.GetHashCode() : 0);
         result = (result * 397) ^ Slot;
         result = (result * 397) ^ (Eta != null ? Eta.GetHashCode() : 0);
         result = (result * 397) ^ (EtaTimeSpan.HasValue ? EtaTimeSpan.Value.GetHashCode() : 0);
         result = (result * 397) ^ Ppd.GetHashCode();
         result = (result * 397) ^ (Tpf != null ? Tpf.GetHashCode() : 0);
         result = (result * 397) ^ (TpfTimeSpan.HasValue ? TpfTimeSpan.Value.GetHashCode() : 0);
         result = (result * 397) ^ BaseCredit.GetHashCode();
         result = (result * 397) ^ CreditEstimate.GetHashCode();
         result = (result * 397) ^ (Description != null ? Description.GetHashCode() : 0);
         return(result);
     }
 }
Beispiel #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Key.GetHashCode();
         hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ProcessInstanceKey.GetHashCode();
         hashCode = (hashCode * 397) ^ (BpmnProcessId != null ? BpmnProcessId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ProcessDefinitionVersion;
         hashCode = (hashCode * 397) ^ ProcessDefinitionKey.GetHashCode();
         hashCode = (hashCode * 397) ^ (ElementId != null ? ElementId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ElementInstanceKey.GetHashCode();
         hashCode = (hashCode * 397) ^ (Worker != null ? Worker.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Retries;
         hashCode = (hashCode * 397) ^ Deadline.GetHashCode();
         hashCode = (hashCode * 397) ^ (Variables != null ? Variables.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (CustomHeaders != null ? CustomHeaders.GetHashCode() : 0);
         return(hashCode);
     }
 }
        public IActionResult EditDeadline(int id, [FromForm] Deadline _deadline)
        {
            var deadline = FindDeadline(id);

            if (deadline == null)
            {
                ModelState.AddModelError("", "Не выбран дедлайн для редактирования");
                return(NotFound(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            deadline.Finish = _deadline.Finish;
            deadline.Name   = _deadline.Name;
            db.SaveChanges();
            return(Ok(deadline));
        }
        public async Task AggregateTransactionWithOnlyInitiator()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction("nem:xem")
                .ToAggregate(PublicAccount.CreateFromPublicKey("B974668ABED344BE9C35EE257ACC246117EFFED939EAF42391AE995912F985FE", NetworkType.Types.MIJIN_TEST)),
            }
                ).SignWith(keyPair);

            await new TransactionHttp(host).Announce(aggregateTransaction);

            var status2 = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(aggregateTransaction.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == aggregateTransaction.Hash).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status2.Signer.PublicKey);
        }
        public async Task AnnounceTransferTransactionWithMultipleMosaicsWithoutMessage()
        {
            var keyPair =
                KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"),
                new List <Mosaic>()
            {
                Mosaic.CreateFromIdentifier("nem:xem", 10)
            },
                EmptyMessage.Create()
                ).SignWith(keyPair);

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
        public async Task AnnounceTransferTransactionWithMultipleMosaicsWithoutMessage()
        {
            var keyPair =
                new KeyPair(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                new Address("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"),
                new List <MosaicAmount>()
            {
                new MosaicAmount("nem:xem", 10)
            },
                EmptyMessage.Create()
                ).SignWith(keyPair);

            var response = await new TransactionHttp(host).Announce(transaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
Beispiel #10
0
        public override void Execute(ProjectRepository repository, IConsole console)
        {
            var      orderedTasks = repository.GetTasksByDate();
            Deadline previousDate = null;

            foreach (var task in orderedTasks)
            {
                if (task.Deadline != previousDate)
                {
                    if (previousDate != null)
                    {
                        console.WriteLine();
                    }
                    previousDate = task.Deadline;
                    console.WriteLine(task.Deadline.Format(noDate: "No date"));
                }
                console.WriteLine(task.Format(showDeadline: false));
            }
            console.WriteLine();
        }
        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);
        }
Beispiel #12
0
        protected bool DefaultReceive(object message)
        {
            if (message is Subscribe)
            {
                var subscribe = (Subscribe)message;

                Context.Watch(subscribe.Ref);
                Subscribers.Add(subscribe.Ref);
                PruneDeadline = null;
                Context.Parent.Tell(new Subscribed(new SubscribeAck(subscribe), Sender));
            }
            else if (message is Unsubscribe)
            {
                var unsubscribe = (Unsubscribe)message;

                Context.Unwatch(unsubscribe.Ref);
                Remove(unsubscribe.Ref);
                Context.Parent.Tell(new Unsubscribed(new UnsubscribeAck(unsubscribe), Sender));
            }
            else if (message is Terminated)
            {
                var terminated = (Terminated)message;
                Remove(terminated.ActorRef);
            }
            else if (message is Prune)
            {
                if (PruneDeadline != null && PruneDeadline.IsOverdue)
                {
                    Context.Stop(Self);
                }
            }
            else
            {
                foreach (var subscriber in Subscribers)
                {
                    subscriber.Forward(message);
                }
            }

            return(true);
        }
Beispiel #13
0
 public RoomContract(BoardBasisTypes boardBasis, string mealPlan, int contractTypeCode, bool isAvailableImmediately,
                     bool isDynamic, string contractDescription, List <KeyValuePair <string, string> > remarks, List <DailyRate> dailyRoomRates,
                     Rate rate, int adultsNumber, List <int> childrenAges, RoomTypes type, bool isExtraBedNeeded, Deadline deadline,
                     bool isAdvancePurchaseRate)
 {
     BoardBasis             = boardBasis;
     MealPlan               = mealPlan;
     ContractTypeCode       = contractTypeCode;
     IsAvailableImmediately = isAvailableImmediately;
     IsDynamic              = isDynamic;
     ContractDescription    = contractDescription;
     Rate                  = rate;
     Remarks               = remarks;
     AdultsNumber          = adultsNumber;
     ChildrenAges          = childrenAges;
     IsExtraBedNeeded      = isExtraBedNeeded;
     Deadline              = deadline;
     IsAdvancePurchaseRate = isAdvancePurchaseRate;
     DailyRoomRates        = dailyRoomRates;
     Type                  = type;
 }
        public async Task AnnounceTransferTransactionWithMultipleMosaicsWithSecureMessage()
        {
            var keyPair =
                new KeyPair(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                new Address("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"),
                new List <MosaicAmount>()
            {
                new MosaicAmount("nem:xem", 1000),
                //Mosaic.CreateFromIdentifier("nis1porttest:test", 10), TODO: fix multiple mosaic transfer
            },
                SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068")
                ).SignWith(keyPair);

            var response = await new TransactionHttp(host).Announce(transaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
Beispiel #15
0
        /// <summary>
        /// Handles message if it contains heartbeat.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        private void HandleIfHeartbeat(Message msg)
        {
            var heartbeat = msg.Content as Heartbeat;

            if (heartbeat != null)
            {
                _peerHeartbeatDeadlines.AddOrUpdate(heartbeat.Identity,
                                                    identity =>
                {
                    var deadline = new Deadline(TimeSpan.FromMilliseconds(HeatbeatDeadline));

                    foreach (var handler in PeerConnected?.GetInvocationList().ToArray() ?? new Delegate[0])
                    {
                        ((Action <PeerIdentity>)handler)?.Invoke(heartbeat.Identity);
                    }

                    return(deadline);
                },
                                                    (identity, deadline) => new Deadline(TimeSpan.FromMilliseconds(HeatbeatDeadline)));
            }
        }
        public IActionResult AddDeadline([FromForm] Deadline deadline)
        {
            if (deadline == null)
            {
                ModelState.AddModelError("", "Не указаны параметры дедлайна");
                return(BadRequest(ModelState));
            }


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = CurrentUser;

            deadline.UserId = user.Id;
            db.Deadlines.Add(deadline);
            db.SaveChanges();
            return(Ok(new { message = "Deadline added" }));
        }
Beispiel #17
0
        public async Task MosaicSupplyDecreaseTransction()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = MosaicSupplyChangeTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new MosaicId("happy:test2"),
                MosaicSupplyType.Type.DECREASE,
                10000)
                              .SignWith(signer);

            await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction);

            listener.TransactionStatus(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST))
            .Subscribe(e => Console.WriteLine(e.Status));

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1);

            Assert.AreEqual("B974668ABED344BE9C35EE257ACC246117EFFED939EAF42391AE995912F985FE", status.Signer.PublicKey);
        }
        public async Task CanModifyMultisigAccount()
        {
            var keyPair = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256");

            var transaction = MultisigAggregateModificationTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(1),
                1,
                new List <MultisigModification>()
            {
                new MultisigModification(PublicAccount.CreateFromPublicKey("eb100d6b2da10fc5359ab35a5801b0e6f0b6cc18d849c0aa78ba1aab2b945dea", NetworkType.Types.TEST_NET),
                                         CosignatoryModificationType.Types.Add)
            });

            var multisigTransaction = MultisigTransaction.Create(NetworkType.Types.TEST_NET, Deadline.CreateHours(1), transaction)
                                      .SignWith(keyPair, PublicAccount.CreateFromPublicKey("29c4a4aa674953749053c8a35399b37b713dedd5d002cb29b3331e56ff1ea65a", NetworkType.Types.TEST_NET));

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(multisigTransaction);

            Assert.AreEqual("FAILURE_MULTISIG_ALREADY_A_COSIGNER", response.Message);
        }
Beispiel #19
0
 private void Reconnect()
 {
     _log.Debug("Connecting...");
     _nextAttempt = Deadline.Now + _backoff;
     RemoteConnection.CreateConnection(Role.Client, _server, _poolSize, this).ContinueWith(tr =>
     {
         _log.Debug("Failed to connect.... Retrying again in {0}s. {1} attemps left.", _nextAttempt.TimeLeft, _reconnects);
         if (_reconnects > 0)
         {
             _reconnects -= 1;
             if (_nextAttempt.IsOverdue)
             {
                 Reconnect();
             }
             else
             {
                 _scheduler.Advanced.ScheduleOnce(_nextAttempt.TimeLeft, Reconnect);
             }
         }
     }, TaskContinuationOptions.NotOnRanToCompletion);
 }
        public async Task LockFundsTransactionTest()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var aggregateTransaction = AggregateTransaction.CreateBonded(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction(
                    "nem:xem").ToAggregate(PublicAccount.CreateFromPublicKey("10CC07742437C205D9A0BC0434DC5B4879E002114753DE70CDC4C4BD0D93A64A", NetworkType.Types.MIJIN_TEST)),
                TransferTransactionTests.CreateInnerTransferTransaction(
                    "nem:xem").ToAggregate(PublicAccount.CreateFromPublicKey("A8FCF4371B9C4B26CE19A407BA803D3813647608D57ABC1550925A54AEE2C9EA", NetworkType.Types.MIJIN_TEST))
            },
                null)
                                       .SignWith(signer);

            var hashLock = LockFundsTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                0,
                new Mosaic(new MosaicId("nem:xem"), 10000000),
                10000,
                aggregateTransaction)
                           .SignWith(KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain));

            WatchForFailure(hashLock);

            await new TransactionHttp(host).Announce(hashLock);

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(hashLock.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == hashLock.Hash).Take(1);

            Assert.AreEqual(signer.PublicKeyString, status.Signer.PublicKey);

            await new TransactionHttp(host).AnnounceAggregateBonded(aggregateTransaction);

            var status2 = await listener.AggregateBondedAdded(Address.CreateFromPublicKey(aggregateTransaction.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == aggregateTransaction.Hash).Take(1);

            Assert.AreEqual(signer.PublicKeyString, status2.Signer.PublicKey);
        }
        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));
        }
        public async Task AnnounceTransferTransactionWithMosaicWithMessage()
        {
            KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            TransferTransaction transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TACOPE-XRLZTU-WBQA3U-XV66R4-55L76E-NWK6OY-ITBJ"),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 1)
            },
                EmptyMessage.Create()
                );

            SignedTransaction signedTransaction = transaction.SignWith(keyPair);

            Console.WriteLine(signedTransaction.Hash);
            Console.WriteLine(transaction.Fee);
            TransactionResponse response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signedTransaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
        private static MosaicMetadataTransaction ToMetadataTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];
            //var transactions = transaction["transactions"];
            //var metatransaction = transactions["transaction"];
            //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 targetId          = new MosaicId(transaction["targetMosaicId"].ToObject <UInt64DTO>().ToUInt64());

            var valueSizeDelta = transaction["valueSizeDelta"].ToObject <short>();
            var valueSize      = transaction["valueSize"].ToObject <ushort>();
            var value          = transaction["value"].ToObject <string>();

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

            return(mosaicMetadataTransaction);
        }
        /// <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);
        }
        internal new TransferTransaction Apply(string input)
        {
            var tx = JsonConvert.DeserializeObject <TransferTransactionInfoDTO>(input);

            var txInfo   = TransactionInfo.Create(tx.Meta.Height, tx.Meta.Index, tx.Meta.Id, tx.Meta.Hash, tx.Meta.MerkleComponentHash);
            var deadline = new Deadline(tx.Transaction.Deadline);
            var mosaics  = tx.Transaction.Mosaics.Select(m => new Mosaic(new MosaicId(BitConverter.ToUInt64(m.MosaicId.FromHex(), 0)), m.Amount)).ToList();

            IMessage message;

            try
            {
                message = PlainMessage.Create(Encoding.UTF8.GetString(tx.Transaction.Message.Payload.FromHex()));
            }
            catch (Exception)
            {
                try
                {
                    message = PlainMessage.Create(tx.Transaction.Message.Payload);
                }
                catch (Exception)
                {
                    message = EmptyMessage.Create();
                }
            }

            return(new TransferTransaction(
                       ExtractNetworkType(tx.Transaction.Version),
                       ExtractTransactionVersion(tx.Transaction.Version),
                       deadline,
                       tx.Transaction.Fee,
                       Address.CreateFromEncoded(tx.Transaction.Recipient),
                       mosaics,
                       message,
                       tx.Transaction.Signature,
                       new PublicAccount(tx.Transaction.Signer, ExtractNetworkType(tx.Transaction.Version)),
                       txInfo
                       ));
        }
Beispiel #26
0
        public void Should_Serialize_And_Sign_Transaction()
        {
            var mosaics = new List <Mosaic>()
            {
                new Mosaic((new MosaicId(992621222383397347)), 20)
            };

            var transferTransaction = TransferTransaction.Create(Deadline.Create(1),
                                                                 Recipient.From(new Address("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", NetworkType.MIJIN_TEST)),
                                                                 mosaics,
                                                                 PlainMessage.Create("test-message"),
                                                                 NetworkType.MIJIN_TEST,
                                                                 0
                                                                 );
            var account           = Account.CreateFromPrivateKey("26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930", NetworkType.MIJIN_TEST);
            var generationHash    = "B750FC8ADD9FAB8C71F0BB90B6409C66946844F07C5CADB51F27A9FAF219BFC7";
            var signedTransaction = transferTransaction.SignWith(account, generationHash);

            // var payload = signedTransaction.Payload;
            signedTransaction.Payload.Should().NotBeNullOrEmpty();
            signedTransaction.Hash.Should().NotBeNullOrEmpty();
        }
        public async Task AnnounceTransferTransactionWithMosaicWithMessage()
        {
            KeyPair keyPair = new KeyPair(Config.PrivateKeyMain);

            TransferTransaction transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                new Address("TACOPE-XRLZTU-WBQA3U-XV66R4-55L76E-NWK6OY-ITBJ"),
                new List <MosaicAmount> {
                new MosaicAmount("nem:xem", 1)
            },
                EmptyMessage.Create()
                );

            SignedTransaction signedTransaction = transaction.SignWith(keyPair);

            Console.WriteLine(signedTransaction.Hash);
            Console.WriteLine(transaction.Fee);
            TransactionResponse response = await new TransactionHttp(host).Announce(signedTransaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
Beispiel #28
0
 private Receive ReceiveWhenSuspended(TimeSpan suspendDuration, Deadline suspendDeadline)
 {
     return(message =>
     {
         if (message is AllDeadLetters d)
         {
             if (!IsWrappedSuppressed(d))
             {
                 IncrementCount();
                 if (suspendDeadline.IsOverdue)
                 {
                     var doneMsg = $", of which {(_count - _maxCount - 1)} were not logged. The counter will be reset now";
                     LogDeadLetter(d, doneMsg);
                     _count = 0;
                     Context.Become(ReceiveWithSuspendLogging(suspendDuration));
                 }
             }
             return true;
         }
         return false;
     });
 }
Beispiel #29
0
        public async Task ImmutableMosaicCreationTransaction()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = MosaicDefinitionTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(1),
                "happy",
                "test4",
                new MosaicProperties(false, true, false, 0x04, 11000))
                              .SignWith(signer);

            await new TransactionHttp(host).Announce(transaction);

            listener.TransactionStatus(
                Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST))
            .Subscribe(e => Console.WriteLine(e.Status));

            var status = await listener.TransactionStatus(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Where(e => e.Hash == transaction.Hash).Take(1);

            Assert.AreEqual("Failure_Mosaic_Modification_No_Changes", status.Status);
        }
        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));
        }