Skip to content

Commit

Permalink
Merge pull request #196 from eforest-finance/release/2.15.0
Browse files Browse the repository at this point in the history
Add batch amount event
  • Loading branch information
fyannch authored Aug 30, 2024
2 parents 19be228 + d4378ec commit 88af9ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
21 changes: 14 additions & 7 deletions contract/Forest/ForestContract_Buyers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public override Empty BatchBuyNow(BatchBuyNowInput input)
var userBalanceDic = new Dictionary<string,long>();
var failPriceDic = new Dictionary<long, FailPrice>();
var listOwnerAllowanceDic = new Dictionary<string, long>();

var batchDealAmount = 0l;
foreach (var fixPrice in input.FixPriceList)
{
Assert(fixPrice.Quantity > 0, "Invalid param Quantity.");
Expand All @@ -247,7 +247,8 @@ public override Empty BatchBuyNow(BatchBuyNowInput input)
Quantity = fixPrice.Quantity,
Price = fixPrice.Price,
StartTime = fixPrice.StartTime
}, userBalanceDic, failPriceDic, listOwnerAllowanceDic);
}, userBalanceDic, failPriceDic, listOwnerAllowanceDic, out var dealTotalAmount);
batchDealAmount += dealTotalAmount;
}

Context.Fire(new BatchBuyNowResult
Expand All @@ -257,7 +258,8 @@ public override Empty BatchBuyNow(BatchBuyNowInput input)
FailPriceList = new FailPriceList()
{
Value = { failPriceDic?.Values?.ToList() }
}
},
TotalDealAmountPrice = batchDealAmount
});

return new Empty();
Expand All @@ -266,8 +268,10 @@ public override Empty BatchBuyNow(BatchBuyNowInput input)
private void SingleMakeOfferForBatchBuyNow(string symbol, FixPrice inputFixPrice
, Dictionary<string,long> userBalanceDic
, Dictionary<long, FailPrice> failPriceDic
, Dictionary<string, long> listOwnerAllowanceDic)
, Dictionary<string, long> listOwnerAllowanceDic,
out long dealTotalAmount)
{
dealTotalAmount = 0;
var nftInfo = State.TokenContract.GetTokenInfo.Call(new GetTokenInfoInput
{
Symbol = symbol,
Expand Down Expand Up @@ -308,8 +312,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)
{
Expand Down Expand Up @@ -689,7 +693,7 @@ private bool TryDealWithFixedPrice(Address sender, MakeOfferInput input, DealRes
/// Sender is buyer.
/// </summary>
private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPrice input, DealResult dealResult,
ListedNFTInfo listedNftInfo, Dictionary<string,long> userBalanceDic ,out long actualQuantity,int decimals)
ListedNFTInfo listedNftInfo, Dictionary<string,long> userBalanceDic ,out long actualQuantity,int decimals, out long dealAmount)
{
var userBalanceKey = symbol + input.OfferTo;
long senderBalanceCount;
Expand All @@ -711,6 +715,7 @@ private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPri
if (senderBalanceCount== 0)
{
actualQuantity = 0;
dealAmount = 0;
return false;
}
var usePrice = input.Price.Clone();
Expand All @@ -720,13 +725,15 @@ private bool TryDealWithFixedPriceForBatch(Address sender, string symbol, FixPri

if (actualQuantity == 0)
{
dealAmount = 0;
return false;
}

senderBalanceCount -= actualQuantity;
userBalanceDic[userBalanceKey]=senderBalanceCount;

var totalAmount = usePrice.Amount.Mul(NumberHelper.DivideByPowerOfTen(actualQuantity, decimals));
dealAmount = totalAmount;
PerformDeal(new PerformDealInput
{
NFTFrom = input.OfferTo,
Expand Down
1 change: 1 addition & 0 deletions protobuf/forest_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ message BatchBuyNowResult{
string symbol = 1;
bool all_success_flag = 2;
FailPriceList fail_price_list = 3;
int64 total_deal_amount_price = 4;
}

message FailPriceList {
Expand Down

0 comments on commit 88af9ad

Please sign in to comment.