From ad95f013087c7a4077236309063229fb59a2d809 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 29 Aug 2024 00:40:23 +0800 Subject: [PATCH] return batch deal amount --- contract/Forest/ForestContract_Buyers.cs | 22 +++++++++++++++------- protobuf/forest_contract.proto | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/contract/Forest/ForestContract_Buyers.cs b/contract/Forest/ForestContract_Buyers.cs index 9a3ab4a..c0b44a0 100644 --- a/contract/Forest/ForestContract_Buyers.cs +++ b/contract/Forest/ForestContract_Buyers.cs @@ -229,6 +229,7 @@ public override Empty BatchBuyNow(BatchBuyNowInput input) Assert(nftInfo != null && !string.IsNullOrWhiteSpace(nftInfo.Symbol), "Invalid symbol data"); var userBalanceDic = new Dictionary(); var failPriceDic = new Dictionary(); + var batchDealAmount = 0l; foreach (var fixPrice in input.FixPriceList) { SingleMakeOfferForBatchBuyNow(input.Symbol, new FixPrice() @@ -237,7 +238,8 @@ public override Empty BatchBuyNow(BatchBuyNowInput input) Quantity = fixPrice.Quantity, Price = fixPrice.Price, StartTime = fixPrice.StartTime - }, userBalanceDic, failPriceDic); + }, userBalanceDic, failPriceDic,out var dealTotalAmount); + batchDealAmount += dealTotalAmount; } Context.Fire(new BatchBuyNowResult @@ -247,7 +249,8 @@ public override Empty BatchBuyNow(BatchBuyNowInput input) FailPriceList = new FailPriceList() { Value = { failPriceDic?.Values?.ToList() } - } + }, + TotalDealAmountPrice = batchDealAmount }); return new Empty(); @@ -255,8 +258,10 @@ public override Empty BatchBuyNow(BatchBuyNowInput input) private void SingleMakeOfferForBatchBuyNow(string symbol, FixPrice inputFixPrice , Dictionary userBalanceDic - , Dictionary failPriceDic) + , Dictionary failPriceDic, + out long dealTotalAmount) { + dealTotalAmount = 0; Assert(inputFixPrice.Quantity > 0, "Invalid param Quantity."); Assert(inputFixPrice.Price.Amount > 0, "Invalid price amount."); Assert(inputFixPrice.OfferTo != null, "Invalid param OfferTo."); @@ -266,7 +271,7 @@ private void SingleMakeOfferForBatchBuyNow(string symbol, FixPrice inputFixPrice }); Assert(nftInfo != null && !string.IsNullOrWhiteSpace(nftInfo.Symbol), "Invalid symbol data"); Assert(inputFixPrice.Quantity <= nftInfo?.TotalSupply, "Offer quantity beyond totalSupply"); - + var balance = State.TokenContract.GetBalance.Call(new GetBalanceInput { Symbol = inputFixPrice.Price.Symbol, @@ -300,8 +305,8 @@ private void SingleMakeOfferForBatchBuyNow(string symbol, FixPrice inputFixPrice var listedNftInfo = affordableNftInfoList[dealResult.Index]; TryDealWithFixedPriceForBatch(sender, symbol, inputFixPrice, dealResult - , listedNftInfo, userBalanceDic, out var dealQuantity,nftInfo.Decimals); - + , listedNftInfo, userBalanceDic, out var dealQuantity,nftInfo.Decimals, out var dealAmount); + dealTotalAmount += dealAmount; long realFail = dealResult.Quantity - dealQuantity; if (realFail > 0) { @@ -681,7 +686,7 @@ private bool TryDealWithFixedPrice(Address sender, MakeOfferInput input, DealRes /// Sender is buyer. /// private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPrice input, DealResult dealResult, - ListedNFTInfo listedNftInfo, Dictionary userBalanceDic ,out long actualQuantity,int decimals) + ListedNFTInfo listedNftInfo, Dictionary userBalanceDic ,out long actualQuantity,int decimals, out long dealAmount) { var userBalanceKey = symbol + input.OfferTo; long senderBalanceCount; @@ -703,6 +708,7 @@ private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPri if (senderBalanceCount== 0) { actualQuantity = 0; + dealAmount = 0; return false; } var usePrice = input.Price.Clone(); @@ -712,6 +718,7 @@ private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPri if (actualQuantity == 0) { + dealAmount = 0; return false; } @@ -719,6 +726,7 @@ private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPri userBalanceDic[userBalanceKey]=senderBalanceCount; var totalAmount = usePrice.Amount.Mul(NumberHelper.DivideByPowerOfTen(actualQuantity, decimals)); + dealAmount = totalAmount; PerformDeal(new PerformDealInput { NFTFrom = input.OfferTo, diff --git a/protobuf/forest_contract.proto b/protobuf/forest_contract.proto index 9aa64e8..7425a43 100755 --- a/protobuf/forest_contract.proto +++ b/protobuf/forest_contract.proto @@ -327,6 +327,7 @@ message BatchBuyNowResult{ string symbol = 1; bool all_success_flag = 2; FailPriceList fail_price_list = 3; + int64 total_deal_amount_price = 4; } message FailPriceList {