Problem to solve
To SUDT deposit to the exchange, the user has to prepare a 142 CKBytes cell to contain the token, or the exchange has to prepare numerous cells for every user and every kind of token. Which is a heavy burden for both sides.
There are some discussions on this, and the community finally figure out a solution, which follows these steps.
- The exchange generates
secp256k1_sighash_all
short addresses for every user sperately. - The user deposit their SUDT to a temporary
Cheque Cell
. - The exchange scans all the live
Cheque Cells
, and claims them. - Simultaneously, the claim transaction will return the temporary
Cheque Cell
capacity back to the user.
Implementation
The lockscript of a Cheque cell is:
Lock:
code_hash: <cheque_cell_lock_script>
hash_type: type
args: <receiver_lock_hash[:20]> | <sender_lock_hash[:20]>
There are two methods to unlock the Cheque cell for both sender and receiver:
Input cell match method
- The witness field of the Cheque cell is empty
- There is at least one input cell’s lock script matchs the lock_hash declared in the Cheque cell’s lock args
- The conresponding input cell’s witness is not empty
Signature match method
- The witness field of the Cheque cell is an valid secp256k1 signature
- Generate a lockscript by the following rules:
- Recover the public key from the signature, get the first 20 bytes of its blake2b hash as
lock args
- Use the default secp256k1_signhash_all script as
code_hash
- Set
hash_type
astype
- Recover the public key from the signature, get the first 20 bytes of its blake2b hash as
- Ensure the hash of the generated lockscript matchs the lock_hash declared in the Cheque cell’s lock args
And additionally, the transaction must follow other business logics defined by the spec, including the withdrawal time limit and so on.
Creation example
create cheque cell #1
create cheque cell #2
create cheque cell #3
Claim example
claim cheque cell