public async Task CreateInboxAsync(IAgentContext agentContext, Dictionary <string, string> metadata = null) { var provisioning = await provisioningService.GetProvisioningAsync(agentContext.Wallet); if (provisioning.GetTag(MediatorInboxIdTagName) != null) { return; } var connection = await GetMediatorConnectionAsync(agentContext); var createInboxMessage = new CreateInboxMessage { Metadata = metadata }; var response = await messageService.SendReceiveAsync <CreateInboxResponseMessage>(agentContext.Wallet, createInboxMessage, connection); provisioning.SetTag(MediatorInboxIdTagName, response.InboxId); provisioning.SetTag(MediatorInboxKeyTagName, response.InboxKey); await recordService.UpdateAsync(agentContext.Wallet, provisioning); }
private async Task <CreateInboxResponseMessage> CreateInboxAsync(IAgentContext agentContext, ConnectionRecord connection, CreateInboxMessage createInboxMessage) { if (connection.State != ConnectionState.Connected) { throw new InvalidOperationException("Can't create inbox if connection is not in final state"); } var inboxId = $"Edge{Guid.NewGuid().ToString("N")}"; var inboxKey = Guid.NewGuid().ToString(); var inboxRecord = new InboxRecord { Id = inboxId, WalletConfiguration = new WalletConfiguration { Id = inboxId }, WalletCredentials = new WalletCredentials { Key = inboxKey } }; connection.SetTag("InboxId", inboxId); await walletService.CreateWalletAsync( configuration : inboxRecord.WalletConfiguration, credentials : inboxRecord.WalletCredentials); await recordService.AddAsync(agentContext.Wallet, inboxRecord); await recordService.UpdateAsync(agentContext.Wallet, connection); return(new CreateInboxResponseMessage { InboxId = inboxId, InboxKey = inboxKey }); }
private async Task <CreateInboxResponseMessage> CreateInboxAsync(IAgentContext agentContext, ConnectionRecord connection, CreateInboxMessage createInboxMessage) { if (connection.State != ConnectionState.Connected) { throw new InvalidOperationException("Can't create inbox if connection is not in final state"); } var inboxId = $"Edge{Guid.NewGuid().ToString("N")}"; var inboxKey = Guid.NewGuid().ToString(); var inboxRecord = new InboxRecord { Id = inboxId, WalletConfiguration = new WalletConfiguration { Id = inboxId, StorageType = options.WalletConfiguration?.StorageType ?? "default", StorageConfiguration = options.WalletConfiguration?.StorageConfiguration }, WalletCredentials = new WalletCredentials { Key = inboxKey, StorageCredentials = options.WalletCredentials?.StorageCredentials } }; connection.SetTag("InboxId", inboxId); await walletService.CreateWalletAsync( configuration : inboxRecord.WalletConfiguration, credentials : inboxRecord.WalletCredentials); if (createInboxMessage.Metadata != null) { foreach (var metadata in createInboxMessage.Metadata) { inboxRecord.SetTag(metadata.Key, metadata.Value); } } await recordService.AddAsync(agentContext.Wallet, inboxRecord); await recordService.UpdateAsync(agentContext.Wallet, connection); return(new CreateInboxResponseMessage { InboxId = inboxId, InboxKey = inboxKey }); }