public override (bool, int) Validate(Transaction transaction, FeatureData featureData) { var error = EnforceReceiverFriendError.None; var receivers = transaction.GetFeature <Receiver>(Receiver.FeatureId)?.Receivers; if (receivers == null) { error = EnforceReceiverFriendError.ReceiversMissing; goto end; } var friendContainer = _friendChain.GetFeatureAccount(transaction.AccountId)?.GetFeatureContainer <FriendContainer>(Friend.FeatureId); if (friendContainer == null) { error = EnforceReceiverFriendError.InvalidFriend; goto end; } foreach (var receiverId in receivers) { if (!friendContainer.HasFriend(receiverId)) { error = EnforceReceiverFriendError.InvalidFriend; goto end; } } end: return(error == EnforceReceiverFriendError.None, (int)error); }
public override void PreProcess(IFeatureChain featureChain, FeatureAccount featureAccount, Transaction transaction, FeatureData featureData) { var receiverData = featureData as Receiver; var receivers = receiverData.Receivers; foreach (var receiverId in receivers) { var receiverAccount = featureChain.GetFeatureAccount(receiverId); var info = receiverAccount.GetFeatureContainer <ReceiverContainer>(featureData.FeatureId)?.LastReceiverTransactionInfo ?? LastTransactionCountInfo.Empty; _lastTransactionIdLookup.Set(receiverId, info.TransactionId); _lastTransactionCountLookup.Set(receiverId, info.Count); } }
protected Result GetAccountData <T>(FeatureQuery query, int queryIndex, Func <T, Result> handle) where T : FeatureAccountContainer { if (query.GetLong(queryIndex, out var accountId)) { var account = CurrentChain.GetFeatureAccount(accountId); if (account != null) { var container = account.GetFeatureContainer <T>(FeatureId); return(handle?.Invoke(container)); } return(Result.AccountNotFound); } return(Result.InvalidQuery); }
public override void Update(CommitItems commitItems, IFeatureChain chain, Transaction transaction, FeatureData featureData) { var receivers = transaction.GetFeature <Receiver>(Receiver.FeatureId).Receivers; var sharedIndex = featureData as SharedAccountIndex; var index = sharedIndex.Index; var info = new LastTransactionCountInfo(transaction.TransactionId, transaction.Timestamp, sharedIndex.TransactionCount); UpdateLastTransactionInfo(index, info); commitItems.DirtyAccounts.Add(AccountId); foreach (var receiverId in receivers) { var account = chain.GetFeatureAccount(receiverId).GetOrAddFeatureContainer <SharedAccountIndexContainer>(SharedAccountIndex.FeatureId); account.UpdateLastTransactionInfo(index, info); commitItems.DirtyAccounts.Add(receiverId); } }
public override void Update(CommitItems commitItems, IFeatureChain chain, Transaction transaction, FeatureData featureData) { var receiverData = featureData as Receiver; for (var i = 0; i < receiverData.Receivers.Count; i++) { var receiverAccountId = receiverData.Receivers[i]; var receiverAccount = chain.GetFeatureAccount(receiverAccountId); var receiverContainer = receiverAccount.GetOrAddFeatureContainer <ReceiverContainer>(FeatureId); if (receiverContainer != null) { if (receiverContainer.SetLastReceiverInfo(transaction, receiverData._receiverTransactionCount[i])) { commitItems.DirtyAccounts.Add(receiverAccountId); } } } }