-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create idea.md #742
base: main
Are you sure you want to change the base?
Create idea.md #742
Conversation
|
||
/* | ||
*/ | ||
const released = released_tokens_of_user.get(token).get(user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is this variable released
that is important to prevent double payments. The contract needs to copy/increase released
from sender to recipient.
total_released_tokens.get(token) + payment | ||
); | ||
|
||
+ last_balance_of_user_for_tokens[token][user] = user_balance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of withdraw
transaction, the user's token balance is recorded here. This value will always be referenced inwithdraw
transaction to detect any change in the balance.
const Withdraw = Withdraw(Registry(registry).registries('Withdraw')); | ||
|
||
function updateReleasedTokens(token, user, current_balance) { | ||
if (last_balance_of_user_for_tokens[token][user] === current_balance) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the recorded balance and the latest balance match, nothing is done.
updateReleasedTokens(token, history.from, Property.balanceOf(history.from)); | ||
|
||
const released_tokens = released_tokens_of_user.get(token).get(history.from); | ||
const part_of_released = released_tokens * history.preBalanceOfSender / history.amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To copy the sender's released
to the recipient, calculate part_of_released
.
const part_of_released = released_tokens * history.preBalanceOfSender / history.amount; | ||
released_tokens_of_user.get(token).set( | ||
user, | ||
part_of_released + released_tokens_of_user.get(token).get(user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add part_of_released
to the recipient's released
.
|
||
i = i - 1; | ||
calculated = calculated + history.amount; | ||
done = last_balance_of_user_for_tokens[token][user] + calculated === current_balance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the calculated transfers + recorded balance matches the user's latest balance, the loop ends.
history.amount = current_balance - history.preBalanceOfRecipient; | ||
} | ||
|
||
updateReleasedTokens(token, history.from, Property.balanceOf(history.from)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are making recursive call here which will re-trigger the loop from the beginning without updating the released_tokens_of_user
state. So, base case might get skipped and it can get stuck in infinite loop?
<<DON'T MARGE THIS PR. IT'S JUST FOR DISCUSSION>>