private async Task DeployAndConfigureEShopAsync()
        {
            try
            {
                Log($"Deploying eShop: {ContractNewDeploymentConfig.Eshop.EShopId} {ContractNewDeploymentConfig.Eshop.EShopDescription}...");

                //-----------------------------------------------------------------------------------
                // Contract deployments
                //-----------------------------------------------------------------------------------
                #region contract deployments
                // Deploy Address Registry
                Log();
                var contractName = CONTRACT_NAME_ADDRESS_REGISTRY;
                Log($"Deploying {contractName}...");
                var addressRegDeployment = new AddressRegistryDeployment();
                AddressRegistryService = await AddressRegistryService.DeployContractAndGetServiceAsync(
                    _web3, addressRegDeployment).ConfigureAwait(false);

                var addressRegOwner = await AddressRegistryService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {AddressRegistryService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {addressRegOwner}");

                // Deploy Eternal Storage
                Log();
                contractName = CONTRACT_NAME_ETERNAL_STORAGE;
                Log($"Deploying {contractName}...");
                var eternalStorageDeployment = new EternalStorageDeployment();
                EternalStorageService = await EternalStorageService.DeployContractAndGetServiceAsync(
                    _web3, eternalStorageDeployment).ConfigureAwait(false);

                var eternalStorageOwner = await EternalStorageService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {EternalStorageService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {eternalStorageOwner}");

                // Deploy Business Partner Storage
                Log();
                contractName = CONTRACT_NAME_BUSINESS_PARTNER_STORAGE;
                Log($"Deploying {contractName}...");
                var bpStorageDeployment = new BusinessPartnerStorageDeployment()
                {
                    ContractAddressOfRegistry = AddressRegistryService.ContractHandler.ContractAddress
                };
                BusinessPartnerStorageService = await BusinessPartnerStorageService.DeployContractAndGetServiceAsync(
                    _web3, bpStorageDeployment).ConfigureAwait(false);

                var bpStorageOwner = await BusinessPartnerStorageService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {BusinessPartnerStorageService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {bpStorageOwner}");

                // Deploy PO Storage
                Log();
                contractName = CONTRACT_NAME_PO_STORAGE;
                Log($"Deploying {contractName}...");
                var poStorageDeployment = new PoStorageDeployment()
                {
                    ContractAddressOfRegistry = AddressRegistryService.ContractHandler.ContractAddress
                };
                PoStorageService = await PoStorageService.DeployContractAndGetServiceAsync(
                    _web3, poStorageDeployment).ConfigureAwait(false);

                var poStorageOwner = await PoStorageService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {PoStorageService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {poStorageOwner}");

                // Deploy Wallet Buyer
                Log();
                contractName = CONTRACT_NAME_BUYER_WALLET;
                Log($"Deploying {contractName}...");
                var buyerWalletDeployment = new BuyerWalletDeployment()
                {
                    ContractAddressOfRegistry = AddressRegistryService.ContractHandler.ContractAddress
                };
                BuyerWalletService = await BuyerWalletService.DeployContractAndGetServiceAsync(
                    _web3, buyerWalletDeployment).ConfigureAwait(false);

                var buyerWalletOwner = await BuyerWalletService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {BuyerWalletService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {buyerWalletOwner}");

                // Deploy Wallet Seller
                Log();
                contractName = CONTRACT_NAME_SELLER_ADMIN;
                Log($"Deploying {contractName}...");
                var sellerAdminDeployment = new SellerAdminDeployment()
                {
                    ContractAddressOfRegistry = AddressRegistryService.ContractHandler.ContractAddress,
                    SellerIdString            = ContractNewDeploymentConfig.Seller.SellerId,
                };
                SellerAdminService = await SellerAdminService.DeployContractAndGetServiceAsync(
                    _web3, sellerAdminDeployment).ConfigureAwait(false);

                var sellerAdminOwner = await SellerAdminService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {SellerAdminService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {sellerAdminOwner}");

                // Deploy Purchasing
                Log();
                contractName = CONTRACT_NAME_PURCHASING;
                Log($"Deploying {contractName}...");
                var purchasingDeployment = new PurchasingDeployment()
                {
                    ContractAddressOfRegistry = AddressRegistryService.ContractHandler.ContractAddress,
                    EShopIdString             = ContractNewDeploymentConfig.Eshop.EShopId
                };
                PurchasingService = await PurchasingService.DeployContractAndGetServiceAsync(
                    _web3, purchasingDeployment).ConfigureAwait(false);

                var purchasingOwner = await PurchasingService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {PurchasingService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {purchasingOwner}");

                // Deploy Funding
                Log();
                contractName = CONTRACT_NAME_FUNDING;
                Log($"Deploying {contractName}...");
                var fundingDeployment = new FundingDeployment()
                {
                    ContractAddressOfRegistry = AddressRegistryService.ContractHandler.ContractAddress
                };
                FundingService = await FundingService.DeployContractAndGetServiceAsync(
                    _web3, fundingDeployment).ConfigureAwait(false);

                var fundingOwner = await FundingService.OwnerQueryAsync().ConfigureAwait(false);

                Log($"{contractName} address is: {FundingService.ContractHandler.ContractAddress}");
                Log($"{contractName} owner is  : {fundingOwner}");

                #endregion

                //-----------------------------------------------------------------------------------
                // Configure Address Registry
                //-----------------------------------------------------------------------------------
                #region configure address registry
                Log();
                Log($"Configuring Address Registry...");

                // Add address entry for eternal storage
                contractName = CONTRACT_NAME_ETERNAL_STORAGE;
                Log($"Configuring Address Registry, adding {contractName}...");
                var txReceipt = await AddressRegistryService.RegisterAddressStringRequestAndWaitForReceiptAsync(
                    contractName, EternalStorageService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Add address entry for BP storage
                contractName = CONTRACT_NAME_BUSINESS_PARTNER_STORAGE;
                Log($"Configuring Address Registry, adding {contractName}...");
                txReceipt = await AddressRegistryService.RegisterAddressStringRequestAndWaitForReceiptAsync(
                    contractName, BusinessPartnerStorageService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Add address entry for PO storage
                contractName = CONTRACT_NAME_PO_STORAGE;
                Log($"Configuring Address Registry, adding {contractName}...");
                txReceipt = await AddressRegistryService.RegisterAddressStringRequestAndWaitForReceiptAsync(
                    contractName, PoStorageService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Add address entry for Purchasing
                contractName = CONTRACT_NAME_PURCHASING;
                Log($"Configuring Address Registry, adding {contractName}...");
                txReceipt = await AddressRegistryService.RegisterAddressStringRequestAndWaitForReceiptAsync(
                    contractName, PurchasingService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Add address entry for Funding
                contractName = CONTRACT_NAME_FUNDING;
                Log($"Configuring Address Registry, adding {contractName}...");
                txReceipt = await AddressRegistryService.RegisterAddressStringRequestAndWaitForReceiptAsync(
                    contractName, FundingService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Authorisations. Nothing needed.
                #endregion

                //-----------------------------------------------------------------------------------
                // Configure Eternal Storage
                //-----------------------------------------------------------------------------------
                #region configure eternal storage
                // Authorisations. Bind all contracts that will use eternal storage
                Log();
                Log($"Authorisations for Eternal Storage...");
                contractName = CONTRACT_NAME_BUSINESS_PARTNER_STORAGE;
                Log($"Configuring Eternal Storage, binding {contractName}...");
                txReceipt = await EternalStorageService.BindAddressRequestAndWaitForReceiptAsync(
                    BusinessPartnerStorageService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                contractName = CONTRACT_NAME_PO_STORAGE;
                Log($"Configuring Eternal Storage, binding {contractName}...");
                txReceipt = await EternalStorageService.BindAddressRequestAndWaitForReceiptAsync(
                    PoStorageService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");
                #endregion

                //-----------------------------------------------------------------------------------
                // Configure Business Partner Storage
                //-----------------------------------------------------------------------------------
                #region configure business partner storage and store master data
                Log();
                Log($"Configuring BP Storage...");
                txReceipt = await BusinessPartnerStorageService.ConfigureRequestAndWaitForReceiptAsync(
                    CONTRACT_NAME_ETERNAL_STORAGE).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                //-----------------------------------------------------------------------------------
                // Add some Business Partner master data
                //-----------------------------------------------------------------------------------
                // Need at least one eShop and one Seller to be a useful deployment
                Log($"Adding eShop master data...");
                txReceipt = await BusinessPartnerStorageService.SetEshopRequestAndWaitForReceiptAsync(
                    new Eshop()
                {
                    EShopId                   = ContractNewDeploymentConfig.Eshop.EShopId,
                    EShopDescription          = ContractNewDeploymentConfig.Eshop.EShopDescription,
                    PurchasingContractAddress = PurchasingService.ContractHandler.ContractAddress,
                    IsActive                  = true,
                    CreatedByAddress          = string.Empty, // filled by contract
                    QuoteSignerCount          = Convert.ToUInt32(ContractNewDeploymentConfig.Eshop.QuoteSigners.Count),
                    QuoteSigners              = ContractNewDeploymentConfig.Eshop.QuoteSigners
                }).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                Log($"Adding Seller master data...");
                txReceipt = await BusinessPartnerStorageService.SetSellerRequestAndWaitForReceiptAsync(
                    new Seller()
                {
                    SellerId             = ContractNewDeploymentConfig.Seller.SellerId,
                    SellerDescription    = ContractNewDeploymentConfig.Seller.SellerDescription,
                    AdminContractAddress = SellerAdminService.ContractHandler.ContractAddress,
                    IsActive             = true,
                    CreatedByAddress     = string.Empty  // filled by contract
                }).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");
                #endregion

                // Authorisations.
                // Bind all contracts that will use BP storage here - currently none other than owner

                //-----------------------------------------------------------------------------------
                // Configure PO Storage
                //-----------------------------------------------------------------------------------
                Log();
                Log($"Configuring PO Storage...");
                txReceipt = await PoStorageService.ConfigureRequestAndWaitForReceiptAsync(
                    CONTRACT_NAME_ETERNAL_STORAGE).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Authorisations. Bind all contracts that will use PO storage
                // Bind Purchasing to PO Storage
                Log($"Authorisations for PO Storage...");
                contractName = CONTRACT_NAME_PURCHASING;
                Log($"Configuring PO Storage, binding {contractName}...");
                txReceipt = await PoStorageService.BindAddressRequestAndWaitForReceiptAsync(
                    PurchasingService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                //-----------------------------------------------------------------------------------
                // Configure Seller Admin
                //-----------------------------------------------------------------------------------
                Log();
                Log($"Configuring Seller Admin...");
                txReceipt = await SellerAdminService.ConfigureRequestAndWaitForReceiptAsync(
                    CONTRACT_NAME_BUSINESS_PARTNER_STORAGE).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                //-----------------------------------------------------------------------------------
                // Configure Buyer Wallet
                //-----------------------------------------------------------------------------------
                Log();
                Log($"Configuring Buyer Wallet...");
                txReceipt = await BuyerWalletService.ConfigureRequestAndWaitForReceiptAsync(
                    CONTRACT_NAME_BUSINESS_PARTNER_STORAGE).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                //-----------------------------------------------------------------------------------
                // Configure Purchasing
                //-----------------------------------------------------------------------------------
                Log();
                Log($"Configuring Purchasing...");
                txReceipt = await PurchasingService.ConfigureRequestAndWaitForReceiptAsync(
                    CONTRACT_NAME_PO_STORAGE, CONTRACT_NAME_BUSINESS_PARTNER_STORAGE, CONTRACT_NAME_FUNDING)
                            .ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Authorisations. Bind all contracts that will use Purchasing
                Log($"Authorisations for Purchasing...");
                // Bind BuyerWallet to Purchasing
                contractName = CONTRACT_NAME_BUYER_WALLET;
                Log($"Configuring Purchasing, binding {contractName}...");
                txReceipt = await PurchasingService.BindAddressRequestAndWaitForReceiptAsync(
                    BuyerWalletService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");
                // Bind SellerAdmin to Purchasing
                contractName = CONTRACT_NAME_SELLER_ADMIN;
                Log($"Configuring Purchasing, binding {contractName}...");
                txReceipt = await PurchasingService.BindAddressRequestAndWaitForReceiptAsync(
                    SellerAdminService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");
                // Bind Funding to Purchasing
                contractName = CONTRACT_NAME_FUNDING;
                Log($"Configuring Purchasing, binding {contractName}...");
                txReceipt = await PurchasingService.BindAddressRequestAndWaitForReceiptAsync(
                    FundingService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                //-----------------------------------------------------------------------------------
                // Configure Funding
                //-----------------------------------------------------------------------------------
                Log();
                Log($"Configuring Funding...");
                txReceipt = await FundingService.ConfigureRequestAndWaitForReceiptAsync(
                    CONTRACT_NAME_PO_STORAGE, CONTRACT_NAME_BUSINESS_PARTNER_STORAGE)
                            .ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");

                // Authorisations. Bind all contracts that will use Funding
                Log($"Authorisations for Funding...");
                // Bind BuyerWallet to Funding
                contractName = CONTRACT_NAME_BUYER_WALLET;
                Log($"Configuring Funding, binding {contractName}...");
                txReceipt = await FundingService.BindAddressRequestAndWaitForReceiptAsync(
                    BuyerWalletService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");
                // Bind Purchasing to Funding
                contractName = CONTRACT_NAME_PURCHASING;
                Log($"Configuring Funding, binding {contractName}...");
                txReceipt = await FundingService.BindAddressRequestAndWaitForReceiptAsync(
                    PurchasingService.ContractHandler.ContractAddress).ConfigureAwait(false);

                Log($"Tx status: {txReceipt.Status.Value}");
            }
            catch (Exception ex)
            {
                Log($"Exception thrown: {ex.Message}");
            }
            finally
            {
                Log($"Deploy and configure complete.");
            }
        }
Example #2
0
 public static Task <string> DeployContractAsync(Nethereum.Web3.Web3 web3, SellerAdminDeployment sellerAdminDeployment)
 {
     return(web3.Eth.GetContractDeploymentHandler <SellerAdminDeployment>().SendRequestAsync(sellerAdminDeployment));
 }
Example #3
0
        public static async Task <SellerAdminService> DeployContractAndGetServiceAsync(Nethereum.Web3.Web3 web3, SellerAdminDeployment sellerAdminDeployment, CancellationTokenSource cancellationTokenSource = null)
        {
            var receipt = await DeployContractAndWaitForReceiptAsync(web3, sellerAdminDeployment, cancellationTokenSource);

            return(new SellerAdminService(web3, receipt.ContractAddress));
        }
Example #4
0
 public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Nethereum.Web3.Web3 web3, SellerAdminDeployment sellerAdminDeployment, CancellationTokenSource cancellationTokenSource = null)
 {
     return(web3.Eth.GetContractDeploymentHandler <SellerAdminDeployment>().SendRequestAndWaitForReceiptAsync(sellerAdminDeployment, cancellationTokenSource));
 }