Skip to content

Commit

Permalink
Refactor accounting functions to use more
Browse files Browse the repository at this point in the history
descriptive names
  • Loading branch information
d0rich committed Nov 12, 2023
1 parent f93e0ef commit ef0cd44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions contracts/contracts/lib/trait_accounting.tact
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ trait Accounting {
return ctx.value;
}

fun getMinOperationFee(): Int {
fun calculateMinOperationFee(): Int {
let tonBalanceBeforeMsg: Int = myBalance() - self.getTonRecieved();
// calculate TON to keep in contract, handle case when balance is less than MIN_TON_FOR_STORAGE
let storageFee: Int = self.MIN_TON_FOR_STORAGE - min(tonBalanceBeforeMsg, self.MIN_TON_FOR_STORAGE);
return storageFee + self.getGasConsumption();
}

fun getFullAmountForSending(): Int {
return self.getTonRecieved() - self.getMinOperationFee();
fun calculateFullAmountForSending(): Int {
return self.getTonRecieved() - self.calculateMinOperationFee();
}

fun getFullAmountForSendingWithPersonalFee(personalFee: Int): Int {
return self.getFullAmountForSending() - personalFee;
fun calculateFullAmountForSendingWithPersonalFee(personalFee: Int): Int {
return self.calculateFullAmountForSending() - personalFee;
}
}
2 changes: 1 addition & 1 deletion contracts/contracts/lib/trait_nft_collection.tact
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait NftCollection with Deployable, Accounting {
let nft_init: StateInit = self.getNftItemInit(self.next_item_index);
send(SendParameters{
to: contractAddress(nft_init),
value: self.getFullAmountForSending(),
value: self.calculateFullAmountForSending(),
bounce: false,
mode: SendIgnoreErrors,
body: Transfer {
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/lib/trait_nft_item.tact
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ trait NftItem with Deployable, Ownable, Accounting {

fun transferNftItem(msg: Transfer) {
self.requireOwner();
let msgValue: Int = self.getFullAmountForSending();
let msgValue: Int = self.calculateFullAmountForSending();
let ctx: Context = context();
self.owner = msg.new_owner; // change current owner to the new_owner
if (msg.forward_amount > 0) {
Expand Down

0 comments on commit ef0cd44

Please sign in to comment.