Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch amount event #194

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading