教程视频 4-4 疑问 #1
Answered
by
chrisyy2003
briannnyee
asked this question in
Q&A
-
为啥教程中的市场合约不让代币直接转到卖家帐户里呢? /// A shared `Marketplace`. Can be created by anyone using the
/// `create` function. One instance of `Marketplace` accepts
/// only one type of Coin - `COIN` for all its listings.
struct Marketplace<phantom COIN> has key {
id: UID,
items: Bag,
payments: Table<address, Coin<COIN>>
}
...略
/// Internal function to purchase an item using a known Listing. Payment is done in Coin<C>.
/// Amount paid must match the requested amount. If conditions are met,
/// owner of the item gets the payment and buyer receives their item.
fun buy<T: key + store, COIN>(
marketplace: &mut Marketplace<COIN>,
item_id: ID,
paid: Coin<COIN>,
): T {
let Listing {
id,
ask,
owner
} = bag::remove(&mut marketplace.items, item_id);
assert!(ask == coin::value(&paid), EAmountIncorrect);
// Check if there's already a Coin hanging and merge `paid` with it.
// Otherwise attach `paid` to the `Marketplace` under owner's `address`.
// 这里为何不直接转给卖家呢?
if (table::contains<address, Coin<COIN>>(&marketplace.payments, owner)) {
coin::join(
table::borrow_mut<address, Coin<COIN>>(&mut marketplace.payments, owner),
paid
)
} else {
table::add(&mut marketplace.payments, owner, paid)
};
let item = ofield::remove(&mut id, true);
object::delete(id);
item
} 当时在看官方 Capy 合约就没看懂这段的意义,让卖家需要手动 Claim profit 体验不是极差吗? |
Beta Was this translation helpful? Give feedback.
Answered by
chrisyy2003
Jul 17, 2023
Replies: 2 comments 5 replies
-
可以直接引用一下教程文档或代码吗?这样也能帮助不是该章节讲课的老师来解答问题 |
Beta Was this translation helpful? Give feedback.
1 reply
-
这只是一个案例而已,这节的重点是学会使用dynamic field的使用,对于市场合约应该怎么实现,直接转钱到卖家手里也是可以的,其实sui framework里面存在Kiosk的类似的模块实现了市场的功能 |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
RandyPen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这只是一个案例而已,这节的重点是学会使用dynamic field的使用,对于市场合约应该怎么实现,直接转钱到卖家手里也是可以的,其实sui framework里面存在Kiosk的类似的模块实现了市场的功能