11module Escrow ::escrow {
22 use 0x1 ::signer;
33
4+ /// Error codes
45 const E_ALREADY_FUNDED : u64 = 1 ;
56 const E_NOT_FUNDED : u64 = 2 ;
67 const E_COMPLETED : u64 = 3 ;
78 const E_INSUFFICIENT : u64 = 4 ;
89 const E_NOT_BUYER : u64 = 5 ;
910 const E_NOT_SELLER : u64 = 6 ;
1011
12+ /// Simple "wallet" resource for demo/tests (no global storage)
1113 struct Wallet has store {
1214 balance: u64 ,
1315 }
1416
17+ /// Deal state kept in-memory for demo
1518 struct Deal has store {
1619 buyer: address ,
1720 seller: address ,
@@ -20,22 +23,22 @@ module Escrow::escrow {
2023 completed: bool ,
2124 }
2225
23- /// Создать кошелёк (баланс = 0)
26+ /// Create empty wallet
2427 public fun new_wallet (_owner: &signer ): Wallet {
2528 Wallet { balance: 0 }
2629 }
2730
28- /// Пополнить кошелёк (утилита для тестов/демо )
31+ /// Deposit to wallet (demo helper )
2932 public fun deposit (_owner: &signer , w: &mut Wallet , amount: u64 ) {
3033 w.balance = w.balance + amount;
3134 }
3235
33- /// Баланс кошелька
36+ /// Wallet balance
3437 public fun balance (w: &Wallet ): u64 {
3538 w.balance
3639 }
3740
38- /// Создать сделку (задаём продавца и сумму )
41+ /// Create deal (buyer defines seller and amount )
3942 public fun create (buyer: &signer , seller: address , amount: u64 ): Deal {
4043 Deal {
4144 buyer: signer ::address_of (buyer),
@@ -46,7 +49,7 @@ module Escrow::escrow {
4649 }
4750 }
4851
49- /// Фандинг сделки (покупатель вносит сумму в эскроу )
52+ /// Buyer funds the deal (escrow )
5053 public fun fund (buyer: &signer , buyer_wallet: &mut Wallet , d: &mut Deal ) {
5154 assert ! (signer ::address_of (buyer) == d.buyer, E_NOT_BUYER );
5255 assert ! (!d.funded, E_ALREADY_FUNDED );
@@ -55,16 +58,16 @@ module Escrow::escrow {
5558 d.funded = true ;
5659 }
5760
58- /// Выплата продавцу (выпуск средств из эскроу)
61+ /// Release funds to seller
5962 public fun release (seller: &signer , seller_wallet: &mut Wallet , d: &mut Deal ) {
60- assert ! (signer ::address_of (seller) == d.seller, E_NOT_SELLER );
61- assert ! (d.funded, E_NOT_FUNDED ); // ДОЛЖНО быть funded = true
62- assert ! (!d.completed, E_COMPLETED );
63- seller_wallet.balance = seller_wallet.balance + d.amount;
64- d.completed = true ;
65- }
63+ assert ! (signer ::address_of (seller) == d.seller, E_NOT_SELLER );
64+ assert ! (d.funded, E_NOT_FUNDED );
65+ assert ! (!d.completed, E_COMPLETED );
66+ seller_wallet.balance = seller_wallet.balance + d.amount;
67+ d.completed = true ;
68+ }
6669
67- /// Возврат покупателю (рефанд)
70+ /// Refund to buyer
6871 public fun refund (buyer: &signer , buyer_wallet: &mut Wallet , d: &mut Deal ) {
6972 assert ! (signer ::address_of (buyer) == d.buyer, E_NOT_BUYER );
7073 assert ! (d.funded, E_NOT_FUNDED );
0 commit comments