private async Task SessionReplyMessageReceivedAsync(SessionMessageEvent <SessionReplyMessage> evt) { var transaction = await _transactionsRepository.GetBySessionIdAsync(evt.SessionId); if (!_originatorSessionsDict.TryGetValue(transaction.SessionId, out var originatorSession)) { return; //todo: handle this case. } transaction.CounterPartyVasp = evt.Message.Vasp; if (evt.Message.Message.MessageCode == SessionReplyMessage.GetMessageCode(SessionReplyMessage.SessionReplyMessageCode.SessionAccepted)) { transaction.Status = TransactionStatus.SessionConfirmed; await originatorSession.TransferRequestAsync( _transactionDataService.GetOriginatorFromTx(transaction), _transactionDataService.GetBeneficiaryFromTx(transaction), transaction.Asset, transaction.Amount); transaction.Status = TransactionStatus.TransferRequested; } else { transaction.Status = TransactionStatus.SessionDeclined; transaction.SessionDeclineCode = evt.Message.Message.MessageCode; } await _transactionsRepository.UpdateAsync(transaction); }
public async Task SendSessionReplyAsync(string txId, SessionReplyMessage.SessionReplyMessageCode code) { var transaction = await _transactionsRepository.GetAsync(txId); if (transaction == null) { throw new NullReferenceException(); } if (transaction.Status != TransactionStatus.SessionRequested) { return; //todo: handle properly } if (!_benefeciarySessionsDict.TryGetValue(transaction.SessionId, out var beneficiarySession)) { return; //todo: handle this case. } await beneficiarySession.SessionReplyAsync(_vaspInformation, code); if (code == SessionReplyMessage.SessionReplyMessageCode.SessionAccepted) { transaction.Status = TransactionStatus.SessionConfirmed; } else { transaction.Status = TransactionStatus.SessionDeclined; transaction.SessionDeclineCode = SessionReplyMessage.GetMessageCode(code); } await _transactionsRepository.UpdateAsync(transaction); }
public static ProtoSessionReplyMessage MapToProto(SessionReplyMessage message) { var proto = new ProtoSessionReplyMessage() { Comment = message.Comment, TopicB = message.HandShake.TopicB, Message = Mapper.MapMessageToProto(message.MessageType, message.Message), VaspInfo = Mapper.MapVaspInformationToProto(message.VASP), }; return(proto); }
public static SessionReplyMessage MapFromProto(ProtoSessionReplyMessage message) { var messageIn = new Message( message.Message.MessageId, message.Message.SessionId, message.Message.MessageCode); var handshake = new HandShakeResponse(message.TopicB); var vasp = Mapper.MapVaspInformationFromProto(message.VaspInfo); var proto = new SessionReplyMessage(messageIn, handshake, vasp) { Comment = message.Comment, }; return(proto); }
private static SessionReplyMessage GetSessionReplyMessage() { //Should be a contract var vaspKey = EthECKey.GenerateKey(); //4Bytes var topic = "0x12345678"; //"0x" + "My Topic".GetHashCode().ToString("x"); var message = new Message( Guid.NewGuid().ToByteArray().ToHex(prefix: false), Guid.NewGuid().ToByteArray().ToHex(prefix: false), "1"); var handshake = new HandShakeResponse(topic); var postalAddress = new PostalAddress( "TestingStreet", 61, "Test Address Line", "410000", "TownN", Country.List["DE"] ); var placeOfBirth = new PlaceOfBirth(DateTime.UtcNow, "TownN", Country.List["DE"]); var vaspInformation = new VaspInformation( "Test test", vaspKey.GetPublicAddress(), vaspKey.GetPubKey().ToHex(prefix: false), postalAddress, placeOfBirth, new NaturalPersonId[] { new NaturalPersonId("SomeId2", NaturalIdentificationType.AlienRegistrationNumber, Country.List["DE"]), }, new JuridicalPersonId[] { new JuridicalPersonId("SomeId1", JuridicalIdentificationType.BankPartyIdentification, Country.List["DE"]), }, "DEUTDEFF"); var request = new SessionReplyMessage(message, handshake, vaspInformation) { Comment = "This is test message", }; return(request); }
public override int GetHashCode() { int hash = 1; if (msgCase_ == MsgOneofCase.SessionRequestMessage) { hash ^= SessionRequestMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.SessionReplyMessage) { hash ^= SessionReplyMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.TransferRequestMessage) { hash ^= TransferRequestMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.TransferReplyMessage) { hash ^= TransferReplyMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.TransferDispatchMessage) { hash ^= TransferDispatchMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.TransaferConfirmationMessage) { hash ^= TransaferConfirmationMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.TerminationMessage) { hash ^= TerminationMessage.GetHashCode(); } if (msgCase_ == MsgOneofCase.ReservedField) { hash ^= ReservedField.GetHashCode(); } if (Signature.Length != 0) { hash ^= Signature.GetHashCode(); } hash ^= (int)msgCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override async Task StartAsync() { var reply = new SessionReplyMessage(this.SessionId, new HandShakeResponse(this.SessionTopic), this._vaspInfo); this.CounterParty.VaspInfo = reply.VASP; _sharedSymKeyId = await _whisperRpc.RegisterSymKeyAsync(_sharedKey); await _transportClient.SendAsync(new MessageEnvelope() { EncryptionKey = _sharedSymKeyId, EncryptionType = EncryptionType.Symmetric, Topic = this.CounterPartyTopic, SigningKey = this._privateSigningKey }, reply); await base.StartAsync(); }
public async Task SessionReplyMessageReceivedAsync(string sessionId, SessionReplyMessage message) { var transaction = _outgoingTransactions.SingleOrDefault(x => x.SessionId == sessionId); if (transaction == null) { return; //todo: handle this case. } transaction.Status = TransactionStatus.SessionConfirmed; await _vaspSessionsManager.TransferRequestAsync( transaction.SessionId, transaction.BeneficiaryFullName, transaction.Asset, transaction.Amount); transaction.Status = TransactionStatus.TransferRequested; }
private static void AssertSessionReply(SessionReplyMessage response, SessionReplyMessage request) { Assert.NotNull(response); Assert.Equal(request.HandShake.TopicB, response.HandShake.TopicB); Assert.Equal(request.Comment, response.Comment); Assert.Equal(request.Message.SessionId, response.Message.SessionId); Assert.Equal(request.MessageType, response.MessageType); Assert.Equal(request.Message.MessageCode, response.Message.MessageCode); Assert.Equal(request.Message.MessageId, response.Message.MessageId); Assert.Equal(request.VASP.PlaceOfBirth.DateOfBirth.Date, response.VASP.PlaceOfBirth.DateOfBirth.Date); Assert.Equal(request.VASP.PlaceOfBirth.CountryOfBirth, response.VASP.PlaceOfBirth.CountryOfBirth); Assert.Equal(request.VASP.PlaceOfBirth.CityOfBirth, response.VASP.PlaceOfBirth.CityOfBirth); Assert.Equal(request.VASP.BIC, response.VASP.BIC); Assert.Equal(request.VASP.Name, response.VASP.Name); Assert.Equal(request.VASP.VaspPublickKey, response.VASP.VaspPublickKey); Assert.Equal(request.VASP.VaspIdentity, response.VASP.VaspIdentity); Assert.Equal(request.VASP.PostalAddress.StreetName, response.VASP.PostalAddress.StreetName); Assert.Equal(request.VASP.PostalAddress.AddressLine, response.VASP.PostalAddress.AddressLine); Assert.Equal(request.VASP.PostalAddress.BuildingNumber, response.VASP.PostalAddress.BuildingNumber); Assert.Equal(request.VASP.PostalAddress.Country, response.VASP.PostalAddress.Country); Assert.Equal(request.VASP.PostalAddress.PostCode, response.VASP.PostalAddress.PostCode); Assert.Equal(request.VASP.JuridicalPersonIds.Count(), response.VASP.JuridicalPersonIds.Count()); AssertJuridicalPersonIds(request.VASP.JuridicalPersonIds, response.VASP.JuridicalPersonIds); Assert.Equal(request.VASP.NaturalPersonIds.Count(), response.VASP.NaturalPersonIds.Count()); AssertNaturalPersonIds(request.VASP.NaturalPersonIds, response.VASP.NaturalPersonIds); }
public Task SessionReplyMessageHandlerAsync(SessionReplyMessage message, OriginatorSession session) { return(_sessionReply.Invoke(message, session)); }
public void MergeFrom(ProtoMessageWrapper other) { if (other == null) { return; } if (other.Signature.Length != 0) { Signature = other.Signature; } switch (other.MsgCase) { case MsgOneofCase.SessionRequestMessage: if (SessionRequestMessage == null) { SessionRequestMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoSessionRequestMessage(); } SessionRequestMessage.MergeFrom(other.SessionRequestMessage); break; case MsgOneofCase.SessionReplyMessage: if (SessionReplyMessage == null) { SessionReplyMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoSessionReplyMessage(); } SessionReplyMessage.MergeFrom(other.SessionReplyMessage); break; case MsgOneofCase.TransferRequestMessage: if (TransferRequestMessage == null) { TransferRequestMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoTransferRequestMessage(); } TransferRequestMessage.MergeFrom(other.TransferRequestMessage); break; case MsgOneofCase.TransferReplyMessage: if (TransferReplyMessage == null) { TransferReplyMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoTransferReplyMessage(); } TransferReplyMessage.MergeFrom(other.TransferReplyMessage); break; case MsgOneofCase.TransferDispatchMessage: if (TransferDispatchMessage == null) { TransferDispatchMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoTransferDispatchMessage(); } TransferDispatchMessage.MergeFrom(other.TransferDispatchMessage); break; case MsgOneofCase.TransaferConfirmationMessage: if (TransaferConfirmationMessage == null) { TransaferConfirmationMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoTransferConfirmationMessage(); } TransaferConfirmationMessage.MergeFrom(other.TransaferConfirmationMessage); break; case MsgOneofCase.TerminationMessage: if (TerminationMessage == null) { TerminationMessage = new global::OpenVASP.ProtocolMessages.Messages.ProtoTerminationMessage(); } TerminationMessage.MergeFrom(other.TerminationMessage); break; case MsgOneofCase.ReservedField: ReservedField = other.ReservedField; break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }