public void CreateSessionRequest( string beneficiaryName, string originatorName, PostalAddress originatorPostalAddress, PlaceOfBirth placeOfBirth, VirtualAssetType assetType, decimal transferAmount) { (VaspInformation vaspInfoPerson, VaspContractInfo vaspContractInfoPerson) = VaspInformationBuilder.CreateForNaturalPersonAsync( _ethereumRpc, _vaspSmartContractAddressPerson, _naturalPersonIds, placeOfBirth) .GetAwaiter() .GetResult(); VaspClient originator = VaspClient.Create( vaspInfoPerson, vaspContractInfoPerson, _personHandshakePrivateKeyHex, _personSignaturePrivateKeyHex, _ethereumRpc, _whisperRpc, _fakeEnsProvider, _signService, _transportClient); (VaspInformation vaspInfoJuridical, VaspContractInfo vaspContractInfoJuridical) = VaspInformationBuilder.CreateForJuridicalPersonAsync( _ethereumRpc, _vaspSmartContractAddressJuridical, _juridicalPersonIds) .GetAwaiter() .GetResult(); VaspClient beneficiary = VaspClient.Create( vaspInfoJuridical, vaspContractInfoJuridical, _juridicalHandshakePrivateKeyHex, _juridicalSignaturePrivateKeyHex, _ethereumRpc, _whisperRpc, _fakeEnsProvider, _signService, _transportClient); var originatorVaan = VirtualAssetssAccountNumber.Create(vaspInfoPerson.GetVaspCode(), "524ee3fb082809"); var beneficiaryVaan = VirtualAssetssAccountNumber.Create(vaspInfoJuridical.GetVaspCode(), "524ee3fb082809"); var vaspSession = new VaspSessionWrapper( beneficiaryName, originator, beneficiary); VaspSessions[vaspSession.Id] = vaspSession; var originatorDoc = Originator.CreateOriginatorForNaturalPerson( originatorName, originatorVaan, originatorPostalAddress, placeOfBirth, new NaturalPersonId[] { new NaturalPersonId("Id", NaturalIdentificationType.NationalIdentityNumber, Country.List["DE"]), }); vaspSession.StartSession(originatorDoc, beneficiaryVaan, assetType, transferAmount); }
public async Task CreateSessionBetweenVASPs() { int sessionTerminationCounter = 0; SessionTermination sessionTerminationDelegate = @event => { sessionTerminationCounter++; }; (VaspInformation vaspInfoPerson, VaspContractInfo vaspContractInfoPerson) = await VaspInformationBuilder.CreateForNaturalPersonAsync( NodeClient.EthereumRpc, Settings.VaspSmartContractAddressPerson, Settings.NaturalPersonIds, Settings.PlaceOfBirth); VaspClient originator = VaspClient.Create( vaspInfoPerson, vaspContractInfoPerson, Settings.PersonHandshakePrivateKeyHex, Settings.PersonSignaturePrivateKeyHex, NodeClient.EthereumRpc, NodeClient.WhisperRpc, _fakeEnsProvider, _signService, NodeClient.TransportClient); (VaspInformation vaspInfoJuridical, VaspContractInfo vaspContractInfoJuridical) = await VaspInformationBuilder.CreateForJuridicalPersonAsync( NodeClient.EthereumRpc, Settings.VaspSmartContractAddressJuridical, Settings.JuridicalIds); VaspClient beneficiary = VaspClient.Create( vaspInfoJuridical, vaspContractInfoJuridical, Settings.JuridicalHandshakePrivateKeyHex, Settings.JuridicalSignaturePrivateKeyHex, NodeClient.EthereumRpc, NodeClient.WhisperRpc, _fakeEnsProvider, _signService, NodeClient.TransportClient); var originatorVaan = VirtualAssetssAccountNumber.Create(vaspInfoPerson.GetVaspCode(), "524ee3fb082809"); var beneficiaryVaan = VirtualAssetssAccountNumber.Create(vaspInfoJuridical.GetVaspCode(), "524ee3fb082809"); IVaspMessageHandler messageHandler = new VaspMessageHandlerCallbacks( (vaspInfo) => { return(Task.FromResult(true)); }, (request, currentSession) => { var message = new TransferReplyMessage(currentSession.SessionId, TransferReplyMessage.TransferReplyMessageCode.TransferAccepted, request.Originator, new Beneficiary("Mr. Test", request.Beneficiary.VAAN), new TransferReply( request.Transfer.VirtualAssetType, request.Transfer.TransferType, request.Transfer.Amount, "0x0"), request.VASP); return(Task.FromResult(message)); }, (dispatch, currentSession) => { var message = new TransferConfirmationMessage(currentSession.SessionId, TransferConfirmationMessage.TransferConfirmationMessageCode.TransferConfirmed, dispatch.Originator, dispatch.Beneficiary, dispatch.Transfer, dispatch.Transaction, dispatch.VASP); return(Task.FromResult(message)); }); beneficiary.RunListener(messageHandler); originator.SessionTerminated += sessionTerminationDelegate; beneficiary.SessionTerminated += sessionTerminationDelegate; // change enum to string and add constants //beneficiary.TransferRequest += request => new TransferReply(VirtualAssetType.ETH, TransferType.BlockchainTransfer, "10", "1223"); //beneficiary.TransferDispatch += message => new TransferConfirmationMessage(); var originatorDoc = Originator.CreateOriginatorForNaturalPerson( "Test van der Test", originatorVaan, new PostalAddress( "StreetX", 44, "AddressLineX", "510051", "TownX", Country.List["DE"]), new PlaceOfBirth(DateTime.Today.AddYears(-30), "TownX", Country.List["DE"]), new NaturalPersonId[] { new NaturalPersonId("Id", NaturalIdentificationType.NationalIdentityNumber, Country.List["DE"]), }); var session = await originator.CreateSessionAsync(originatorDoc, beneficiaryVaan); var transferReply = await session.TransferRequestAsync(new TransferInstruction() { VirtualAssetTransfer = new VirtualAssetTransfer() { TransferType = TransferType.BlockchainTransfer, VirtualAssetType = VirtualAssetType.ETH, TransferAmount = "1000000000000000000" } }); var transferConformation = await session.TransferDispatchAsync(transferReply.Transfer, new Transaction("0xtxhash", DateTime.UtcNow, "0x0...a")); Assert.Equal(1, originator.GetActiveSessions().Count); Assert.True(originator.GetActiveSessions().First() is OriginatorSession); Assert.Equal(1, beneficiary.GetActiveSessions().Count); Assert.True(beneficiary.GetActiveSessions().First() is BeneficiarySession); await session.TerminateAsync(TerminationMessage.TerminationMessageCode.SessionClosedTransferOccured); session.Wait(); originator.Dispose(); beneficiary.Dispose(); Assert.Equal(2, sessionTerminationCounter); _testOutputHelper.WriteLine("End of test"); }