Esempio n. 1
0
        public HttpResponseMessage Approve(NotificationDTO postData)
        {
            try
            {
                var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                if (notification != null)
                {
                    if (string.IsNullOrEmpty(notification.Context))
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                    }

                    string[] parameters = notification.Context.Split(':');

                    var stateTransiction = new StateTransaction
                    {
                        ContentItemId  = int.Parse(parameters[0]),
                        CurrentStateId = int.Parse(parameters[2]),
                        Message        = new StateTransactionMessage(),
                        UserId         = UserInfo.UserID
                    };
                    _workflowEngine.CompleteState(stateTransiction);

                    return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                }
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
Esempio n. 2
0
        public async Task Persist_AccountStateDescriptor_UpdateVotes()
        {
            var scriptHash = new UInt160(RandomByteArray(20));
            var value      = new byte[1];
            var input      = new StateTransaction
            {
                Descriptors = new[]
                {
                    new StateDescriptor
                    {
                        Type  = StateType.Account,
                        Field = "Votes",
                        Key   = scriptHash.ToArray(),
                        Value = value
                    }
                }
            };
            var ecpoints         = new ECPoint[0];
            var deserializerMock = AutoMockContainer.GetMock <IBinarySerializer>();

            deserializerMock.Setup(m => m.Deserialize <ECPoint[]>(value, null)).Returns(ecpoints);
            var accountManagerMock = AutoMockContainer.GetMock <IAccountManager>();
            var testee             = AutoMockContainer.Create <StateTransactionPersister>();

            await testee.Persist(input);

            accountManagerMock.Verify(m => m.UpdateVotes(It.Is <UInt160>(u => u.Equals(scriptHash)), ecpoints));
        }
Esempio n. 3
0
        public async Task Persist_ValidatorStateDescriptor_NewValidator()
        {
            var pubKey = new byte[33];

            pubKey[0] = 0x02;
            var input = new StateTransaction
            {
                Descriptors = new[]
                {
                    new StateDescriptor
                    {
                        Type  = StateType.Validator,
                        Key   = pubKey,
                        Field = "Registered",
                        Value = new byte[] { 0x01 }
                    }
                }
            };
            var repositoryMock = AutoMockContainer.GetMock <IRepository>();

            repositoryMock.Setup(m => m.GetValidator(It.Is <ECPoint>(p => p.CompareTo(new ECPoint(pubKey)) == 0)))
            .ReturnsAsync((Validator)null);
            var testee = AutoMockContainer.Create <StateTransactionPersister>();

            await testee.Persist(input);

            repositoryMock.Verify(m => m.AddValidator(It.Is <Validator>(v =>
                                                                        v.PublicKey.CompareTo(new ECPoint(pubKey)) == 0 &&
                                                                        v.Registered &&
                                                                        v.Votes.Equals(Fixed8.Zero))));
        }
        private void SendNotificationToWorkflowStarter(StateTransaction stateTransaction, Entities.Workflow workflow, ContentItem contentItem, int starterUserId, WorkflowActionTypes workflowActionType)
        {
            try
            {
                var workflowAction = GetWorkflowActionInstance(contentItem, workflowActionType);
                if (workflowAction == null)
                {
                    return;
                }

                var user = _userController.GetUser(workflow.PortalID, starterUserId);

                var message = workflowAction.GetActionMessage(stateTransaction, workflow.FirstState);

                var notification = new Notification
                {
                    NotificationTypeID = _notificationsController.GetNotificationType(ContentWorkflowNotificatioStartWorkflowType).NotificationTypeId,
                    Subject            = message.Subject,
                    Body = message.Body,
                    IncludeDismissAction = true,
                    SenderUserID         = stateTransaction.UserId,

                    Context = GetWorkflowNotificationContext(contentItem, workflow.FirstState)
                };

                _notificationsController.SendNotification(notification, workflow.PortalID, null, new[] { user });
            }
            catch (Exception ex)
            {
                Services.Exceptions.Exceptions.LogException(ex);
            }
        }
Esempio n. 5
0
        public void SerializeDeserialize_StateTransaction()
        {
            var original = new StateTransaction()
            {
                Version     = 0x01,
                Descriptors = RandomStateDescriptors(_random.Next(1, 16)).ToArray()
            };

            FillRandomTx(original);

            var ret   = _serializer.Serialize(original);
            var copy  = _deserializer.Deserialize <Transaction>(ret);
            var copy2 = _deserializer.Deserialize <StateTransaction>(ret);

            // Check exclusive data

            foreach (var check in new StateTransaction[] { (StateTransaction)copy, copy2 })
            {
                Assert.AreEqual(original.Descriptors.Length, check.Descriptors.Length);

                for (int x = 0; x < original.Descriptors.Length; x++)
                {
                    Assert.AreEqual(original.Descriptors[0].Field, check.Descriptors[0].Field);
                    Assert.AreEqual(original.Descriptors[0].SystemFee, check.Descriptors[0].SystemFee);
                    Assert.AreEqual(original.Descriptors[0].Type, check.Descriptors[0].Type);
                    CollectionAssert.AreEqual(original.Descriptors[0].Key, check.Descriptors[0].Key);
                    CollectionAssert.AreEqual(original.Descriptors[0].Value, check.Descriptors[0].Value);
                }
            }

            // Check base data

            EqualTx(original, copy, copy2);
        }
        private byte[] GetStateTransactionBytes(StateTransaction transaction)
        {
            // Accumulate all bytes (using BigEndian to support multiple platform architectures)
            List <byte[]> propertyByteList = new List <byte[]>()
            {
                Encoding.BigEndianUnicode.GetBytes(transaction.FromPubKey ?? ""),
                Encoding.BigEndianUnicode.GetBytes(transaction.ToPubKey ?? ""),
                Encoding.BigEndianUnicode.GetBytes(transaction.SkuBlockHash ?? ""),
                Encoding.BigEndianUnicode.GetBytes(transaction.SkuTxIndex.ToString()),
                Encoding.BigEndianUnicode.GetBytes(transaction.Amount.ToString()),
                Encoding.BigEndianUnicode.GetBytes(transaction.Version.ToString()),
                Encoding.BigEndianUnicode.GetBytes(transaction.Action),
                Encoding.BigEndianUnicode.GetBytes(transaction.Data ?? ""),
                Encoding.BigEndianUnicode.GetBytes(transaction.Fee.ToString())
            };

            int transactionsByteArraySize = 0;

            propertyByteList.ForEach(fieldByteArr => transactionsByteArraySize += fieldByteArr.Length);
            byte[] transactionsByteArray = new byte[transactionsByteArraySize];

            // Copy the bytes to array
            int loopedSize = 0;

            for (int i = 0; i < propertyByteList.Count; i++)
            {
                if (propertyByteList[i].Length > 0)
                {
                    Buffer.BlockCopy(propertyByteList[i], 0, transactionsByteArray, loopedSize, propertyByteList[i].Length);
                    loopedSize += propertyByteList[i].Length;
                }
            }

            return(transactionsByteArray);
        }
Esempio n. 7
0
 public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
 {
     return(new ActionMessage
     {
         Subject = "The Item state has been discarded.",
         Body = "The Item state has been discarded."
     });
 }
Esempio n. 8
0
 public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
 {
     return(new ActionMessage
     {
         Subject = "The Item has been published.",
         Body = "Your item has been published."
     });
 }
Esempio n. 9
0
        public async Task Persist_StateTx_CallsStateTxPersister()
        {
            var input = new StateTransaction();
            var stateTxPersisterMock = AutoMockContainer.GetMock <ITransactionPersister <StateTransaction> >();
            var testee = AutoMockContainer.Create <TransactionPersister>();

            await testee.Persist(input);

            stateTxPersisterMock.Verify(m => m.Persist(input));
        }
Esempio n. 10
0
        public async Task Process_StateTx_CallsStateTxProcessor()
        {
            var input = new StateTransaction();
            var stateTxProcessorMock = AutoMockContainer.GetMock <IProcessor <StateTransaction> >();
            var testee = AutoMockContainer.Create <TransactionProcessor>();

            await testee.Process(input);

            stateTxProcessorMock.Verify(m => m.Process(input));
        }
Esempio n. 11
0
        /// <summary>
        /// System Fee
        /// </summary>
        public Fixed8 GetSystemFee(Transaction tx)
        {
            if (_systemFee == -Fixed8.Satoshi)
            {
                _systemFee = DefaultSystemFee;

                switch (tx.Type)
                {
                case TransactionType.InvocationTransaction:
                {
                    InvocationTransaction itx = (InvocationTransaction)tx;
                    _systemFee = itx.Gas;

                    break;
                }

                case TransactionType.IssueTransaction:
                {
                    if (tx.Version >= 1)
                    {
                        _systemFee = Fixed8.Zero;
                        return(_systemFee);
                    }

                    if (tx.Outputs.All(p => p.AssetId == GoverningTokenHash || p.AssetId == UtilityTokenHash))
                    {
                        _systemFee = Fixed8.Zero;
                    }

                    break;
                }

                case TransactionType.RegisterTransaction:
                {
                    var rtx = (RegisterTransaction)tx;

                    if (rtx.AssetType == AssetType.GoverningToken || rtx.AssetType == AssetType.UtilityToken)
                    {
                        _systemFee = Fixed8.Zero;
                    }

                    break;
                }

                case TransactionType.StateTransaction:
                {
                    StateTransaction stx = (StateTransaction)tx;
                    _systemFee = new Fixed8(stx.Descriptors.Sum(p => p.SystemFee.Value));

                    break;
                }
                }
            }
            return(_systemFee);
        }