marigold-dev / chusai

MIT License
5 stars 0 forks source link

Implement Withdraws #15

Open xvw opened 2 years ago

xvw commented 2 years ago

Withdraw in two parts:

When the operation Freeze is process, a lookup on the balance is done, if there is enough, then it is deduced and put into a Frozen account. If not, it is a noop. When a block is sent, if it's level includes some Freeze operations, then their result is mentioned in the block. The fridge is part of the state, and as such, the bissection game does not need to be modified (agreeing on the hash of the state means agreeing on the state of the fridge). When a block is finalized, the result of the included Freeze operations are processed, and the asset is prepared for the user. When a user calls the Withdraw endpoint, then the assets in the fridge, prepared for him, are sent back.

The fridge: Each block starts with an empty fridge. The initial state of the block is the root hash of the ledger + hash of the empty fridge. During the executions of the operations, the fridge is filled by each Freeze request. When preparing a block, a representation of the fridge is included. It can be checked by comparing with hash of the fridge in the block.