Beispiel #1
0
        private TransitionResult SwitchState(IList <CashinState> expectedStates, CashinState nextState)
        {
            if (expectedStates.Contains(State))
            {
                State = nextState;

                return(TransitionResult.Switched);
            }

            if (State < expectedStates.Max())
            {
                // Throws to retry and wait until aggregate will be in the required state
                throw new InvalidAggregateStateException(State, expectedStates, nextState);
            }

            if (State > expectedStates.Min())
            {
                // Aggregate already in the next state, so this event can be just ignored
                return(State == nextState
                    ? TransitionResult.AlreadyInTargetState
                    : TransitionResult.AlreadyInFutureState);
            }

            throw new InvalidOperationException("This shouldn't be happened");
        }
Beispiel #2
0
 private CashinAggregate(
     Guid operationId,
     string assetId,
     int assetAccuracy,
     int blockchainAssetAccuracy,
     string blockchainAssetId,
     string blockchainType,
     decimal cashinMinimalAmount,
     string depositWalletAddress,
     string hotWalletAddress,
     DateTime creationMoment,
     CashinResult result,
     CashinState state,
     string version)
 {
     OperationId             = operationId;
     AssetId                 = assetId;
     BlockchainAssetAccuracy = blockchainAssetAccuracy;
     BlockchainAssetId       = blockchainAssetId;
     BlockchainType          = blockchainType;
     CashinMinimalAmount     = cashinMinimalAmount;
     DepositWalletAddress    = depositWalletAddress;
     HotWalletAddress        = hotWalletAddress;
     CreationMoment          = creationMoment;
     Result        = result;
     State         = state;
     Version       = version;
     AssetAccuracy = assetAccuracy;
 }
        private static string BuildMessage(CashinState currentState, IList <CashinState> expectedStates, CashinState targetState)
        {
            var expectedStateMessage = expectedStates.Count == 1
                ? $"{expectedStates.First()} state"
                : $"one of [{string.Join(", ", expectedStates.Select(s => s.ToString()))}] states";

            return($"Cashin state can't be switched: {currentState} -> {targetState}. Waiting for the {expectedStateMessage}.");
        }
Beispiel #4
0
 private TransitionResult SwitchState(CashinState expectedState, CashinState nextState)
 {
     return(SwitchState(new[] { expectedState }, nextState));
 }
Beispiel #5
0
        public static CashinAggregate Restore(
            Guid?clientId,
            string assetId,
            int assetAccuracy,
            int blockchainAssetAccuracy,
            decimal?balanceAmount,
            long?balanceBlock,
            string blockchainAssetId,
            string blockchainType,
            decimal cashinMinimalAmount,
            DateTime creationMoment,
            string depositWalletAddress,
            decimal?enrolledBalanceAmount,
            long?enrolledBalanceBlock,
            DateTime?enrolledBalanceResetMoment,
            DateTime?enrolledBalanceSetMoment,
            string error,
            decimal?fee,
            string hotWalletAddress,
            DateTime?matchingEngineEnrollementMoment,
            decimal?operationAmount,
            double?meAmount,
            DateTime?operationFinishMoment,
            DateTime?depositWalletLockReleasedMoment,
            Guid operationId,
            CashinResult result,
            DateTime?startMoment,
            DateTime?balanceOutdatingMoment,
            decimal?transactionAmount,
            long?transactionBlock,
            string transactionHash,
            CashinState state,
            bool?isDustCashin,
            string version,
            CashinErrorCode?cashinErrorCode,
            DateTime?operationAcceptanceMoment)
        {
            return(new CashinAggregate
                   (
                       assetId: assetId,
                       assetAccuracy: assetAccuracy,
                       blockchainAssetAccuracy: blockchainAssetAccuracy,
                       blockchainAssetId: blockchainAssetId,
                       blockchainType: blockchainType,
                       cashinMinimalAmount: cashinMinimalAmount,
                       depositWalletAddress: depositWalletAddress,
                       hotWalletAddress: hotWalletAddress,
                       creationMoment: creationMoment,
                       operationId: operationId,
                       result: result,
                       state: state,
                       version: version
                   )
            {
                StartMoment = startMoment,
                BalanceOutdatingMoment = balanceOutdatingMoment,
                MatchingEngineEnrollementMoment = matchingEngineEnrollementMoment,
                EnrolledBalanceSetMoment = enrolledBalanceSetMoment,
                EnrolledBalanceResetMoment = enrolledBalanceResetMoment,
                OperationFinishMoment = operationFinishMoment,
                DepositWalletLockReleasedMoment = depositWalletLockReleasedMoment,
                OperationAcceptanceMoment = operationAcceptanceMoment,

                ClientId = clientId,
                TransactionHash = transactionHash,
                TransactionBlock = transactionBlock,
                Fee = fee,
                Error = error,
                BalanceAmount = balanceAmount,
                BalanceBlock = balanceBlock,
                EnrolledBalanceAmount = enrolledBalanceAmount,
                EnrolledBalanceBlock = enrolledBalanceBlock,
                OperationAmount = operationAmount,
                MeAmount = meAmount,
                TransactionAmount = transactionAmount,
                IsDustCashin = isDustCashin,
                ErrorCode = cashinErrorCode
            });
        }
 public InvalidAggregateStateException(CashinState currentState, IList <CashinState> expectedStates, CashinState targetState) :
     base(BuildMessage(currentState, expectedStates, targetState))
 {
 }