Skip to content

实现coin的deposit功能想到的所有权问题 #208

Answered by hotboice
pingp76 asked this question in Q&A
Discussion options

You must be logged in to vote

Aptos上的coin::transfer都必须在接收者地址调用了coin::register之后,才能被转入。
所以不是“不需要对方的签名就能够操作对方的balance”,而是接收方事先注册过了当前转账的Coin,所以可以接收他人的转入,
但转出是必须需要签名的。
既遵守了"资源"的概念,也避免了被空投一些山寨币或广告币。
代码如下

public fun register<CoinType>(account: &signer) {
        let account_addr = signer::address_of(account);
        // Short-circuit and do nothing if account is already registered for CoinType.
        if (is_account_registered<CoinType>(account_addr)) {
            return
        };

        account::register_coin<CoinType>(account_addr);
        let coin_store = CoinStore<CoinType> {
            coin: Coin { value: 0 },
            frozen: false,
            deposit_events: account::new_event_handle<DepositEvent>(account),

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Demian101
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by leeduckgo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants