public static MusicAssetTransferQueryData ToMusicAssetTransferQueryData(this MusicAssetTransfer transfer)
        {
            if (transfer == null)
            {
                return(null);
            }
            var result = new MusicAssetTransferQueryData()
            {
                From              = transfer.From,
                To                = transfer.To,
                Id                = transfer.Id,
                MusicInfo         = transfer.MusicInfo,
                IsConfirmed       = transfer.IsConfirmed,
                ContractAddress   = transfer.ContractAddress,
                DateCreated       = transfer.DateCreated,
                TransactionHash   = transfer.TransactionHash,
                TransactionStatus = transfer.TransactionStatus.ToString()
            };

            return(result);
        }
示例#2
0
        void IMusicAssetTransferUndergroundJob.WaitForTransactionToSuccessThenFinishCreating(MusicAssetTransfer transfer)
        {
            bool isTransactionSuccess = false;

            do
            {
                var receipt = ethereumService.GetTransactionReceipt(transfer.TransactionHash).Result;
                if (receipt == null)
                {
                    continue;
                }
                if (receipt.Status.Value == (new HexBigInteger(1)).Value)
                {
                    isTransactionSuccess = true;
                    var contractAddress = ethereumService.GetObjectContractAddress(transfer.Id).Result;
                    transfer.ContractAddress   = contractAddress;
                    transfer.TransactionStatus = TransactionStatuses.Success;
                    musicAssetTransferRepository.Update(transfer);
                }
            }while (isTransactionSuccess != true);
        }
示例#3
0
 Guid IMusicAssetTransferRepository.CreateAndReturnId(MusicAssetTransfer musicAssetTransfer)
 {
     (this as IMusicAssetTransferRepository).Create(musicAssetTransfer);
     return(musicAssetTransfer.Id);
 }
示例#4
0
 void IMusicAssetTransferRepository.Create(MusicAssetTransfer musicAssetTransfer)
 {
     dbContext.MusicAssetTransfers.Add(musicAssetTransfer);
     dbContext.SaveChanges();
 }
示例#5
0
        async Task <Guid> IMusicAssetTransferService.Create(Guid musicId, string fromUserId, string toUserId, int buyerId, TranTypes tranType, FanTypes fanType, int duration, decimal amountValue, string key2)
        {
            var      music            = musicRepository.Get(musicId);
            DateTime startDate        = DateTime.UtcNow;
            uint     currentTime      = (uint)startDate.ToUnixTimestamp();
            DateTime endDate          = startDate.AddDays(duration);
            uint     endDateTimeStamp = (uint)endDate.ToUnixTimestamp();

            var transfer = new MusicAssetTransfer()
            {
                MusicId         = music.Id,
                FromId          = fromUserId,
                ToId            = toUserId,
                BuyerId         = buyerId,
                Key2            = key2,
                DateTransferred = currentTime,
                TranType        = tranType,
                FanType         = fanType,
                DateStart       = currentTime,
                DateEnd         = endDateTimeStamp,
                IsPermanent     = false,
                IsConfirmed     = true,
                DateCreated     = DateTime.UtcNow,
                AmountValue     = amountValue
            };

            var newTransferId = musicAssetTransferRepository.CreateAndReturnId(transfer);


            var  deployContract    = ethereumService.DeployContract();
            bool isCreatedContract = false;

            do
            {
                var receipt = deployContract.Result;
                if (receipt == null)
                {
                    continue;
                }
                if (receipt.Status.Value == (new HexBigInteger(1)).Value)
                {
                    isCreatedContract = true;

                    var function = ethereumService.GetFunction(EthereumFunctions.AddTransactionMusic);

                    var transactionHash = await function.SendTransactionAsync(
                        ethereumService.GetEthereumAccount(),
                        new HexBigInteger(6000000),
                        new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(10, UnitConversion.EthUnit.Gwei)),
                        new HexBigInteger(0),
                        functionInput : new object[] {
                        newTransferId.ToString(),
                        transfer.MusicId.ToString(),
                        transfer.FromId.ToString(),
                        transfer.ToId.ToString(),
                        transfer.Key2,
                        transfer.TranType,
                        transfer.FanType,
                        transfer.DateStart,
                        transfer.DateEnd,
                        transfer.IsPermanent,
                        transfer.IsConfirmed
                    });

                    var privateKey = musicAssetTransferRepository.GetUserInfo(buyerId).OwnerPrivateKey;
                    //var privateKey = "0xC40B82DCA66F1B0F117851AEF8E40D197F55499B09858B89AF2F8FF3B4FE83F3";
                    var  account     = new Account(privateKey);
                    Web3 web3        = new Web3(account, "https://ropsten.infura.io/v3/aaceb4b7c236404e9eb5416bef5292e0");
                    var  transaction = web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(transfer.ToId.ToString(), amountValue);

                    transfer.TransactionHash = transactionHash;
                    transfer.ContractAddress = ethereumService.GetMasterContractAddress();
                    musicAssetTransferRepository.Update(transfer);
                }
            }while (isCreatedContract != true);


            BackgroundJob.Schedule <IMusicAssetTransferUndergroundJob>(
                job => job.WaitForTransactionToSuccessThenFinishCreating(transfer),
                TimeSpan.FromSeconds(3)
                );

            return(newTransferId);
        }
示例#6
0
        async Task <Guid> IMusicAssetTransferService.CreateLicenceTransaction(Guid musicId, string fromUserId, string toUserId, int buyerId, TranTypes tranType, FanTypes fanType, decimal amountValue)
        {
            var  music       = musicRepository.Get(musicId);
            uint currentTime = (uint)DateTime.UtcNow.ToUnixTimestamp();

            var transfer = new MusicAssetTransfer()
            {
                MusicId         = music.Id,
                FromId          = fromUserId,
                ToId            = toUserId,
                Key2            = "0",
                DateTransferred = currentTime,
                BuyerId         = buyerId,
                TranType        = tranType,
                FanType         = fanType,
                DateStart       = currentTime,
                DateEnd         = currentTime,
                IsPermanent     = true,
                IsConfirmed     = false,
                DateCreated     = DateTime.UtcNow,
                AmountValue     = amountValue
            };

            var newTransferId = musicAssetTransferRepository.CreateAndReturnId(transfer);

            var  deployContract    = ethereumService.DeployContract();
            bool isCreatedContract = false;

            do
            {
                var receipt = deployContract.Result;
                if (receipt == null)
                {
                    continue;
                }
                if (receipt.Status.Value == (new HexBigInteger(1)).Value)
                {
                    isCreatedContract = true;

                    var function        = ethereumService.GetFunction(EthereumFunctions.AddTransactionMusic);
                    var transactionHash = await function.SendTransactionAsync(
                        ethereumService.GetEthereumAccount(),
                        new HexBigInteger(6000000),
                        new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(10, UnitConversion.EthUnit.Gwei)),
                        new HexBigInteger(0),
                        functionInput : new object[] {
                        newTransferId.ToString(),
                        transfer.MusicId.ToString(),
                        transfer.FromId.ToString(),
                        transfer.ToId.ToString(),
                        transfer.Key2,
                        transfer.TranType,
                        transfer.FanType,
                        transfer.DateStart,
                        transfer.DateEnd,
                        transfer.IsPermanent,
                        transfer.IsConfirmed
                    });

                    transfer.ContractAddress = ethereumService.GetMasterContractAddress();
                    transfer.TransactionHash = transactionHash;
                    musicAssetTransferRepository.Update(transfer);
                }
            }while (isCreatedContract != true);

            BackgroundJob.Schedule <IMusicAssetTransferUndergroundJob>(
                job => job.WaitForTransactionToSuccessThenFinishCreating(transfer),
                TimeSpan.FromSeconds(3)
                );

            return(newTransferId);
        }