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 list limit #188

Merged
merged 1 commit into from
Aug 22, 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
29 changes: 28 additions & 1 deletion contract/Forest/ForestContract_Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,31 @@ private RoyaltyInfo GetRoyaltyInfo(string nftSymbol)

return State.RoyaltyInfoMap[symbol];
}
}

private long GetEffectiveNFTListedTotalAmount(Address address, string symbol)
{
Assert(address != null, $"Invalid param Address");
Assert(symbol != null, $"Invalid param Symbol");

var listedNftInfoList = State.ListedNFTInfoListMap[symbol][address];
var totalAmount = 0L;
if (listedNftInfoList != null)
{
foreach (var listedNftInfo in listedNftInfoList.Value)
{
var expireTime = listedNftInfo.Duration.StartTime.AddHours(listedNftInfo.Duration.DurationHours).AddMinutes(listedNftInfo.Duration.DurationMinutes);
if(expireTime >= Context.CurrentBlockTime)
{
totalAmount = totalAmount.Add(listedNftInfo.Quantity);
}
}
}
return totalAmount;
}

private void AssertBalanceEnoughForList(string symbol, Address address, long currentBalance, long amount)
{
var listedAmount = GetEffectiveNFTListedTotalAmount(address, symbol);
Assert(currentBalance >= (listedAmount + amount), $"The balance is not enough. Please reset it.");
}
}
3 changes: 2 additions & 1 deletion contract/Forest/ForestContract_Sellers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public override Empty ListWithFixedPrice(ListWithFixedPriceInput input)
Owner = Context.Sender
});
Assert(balance.Balance >= input.Quantity, "Check sender NFT balance failed.");

AssertBalanceEnoughForList(input.Symbol, Context.Sender, balance.Balance, input.Quantity);

AssertAllowanceInsufficient(input.Symbol, Context.Sender, input.Quantity);

var duration = AdjustListDuration(input.Duration);
Expand Down
Loading