11module Escrow ::escrow {
2- use std::signer;
3-
42 /// Error codes
53 const E_ALREADY_FUNDED : u64 = 1 ;
64 const E_NOT_FUNDED : u64 = 2 ;
@@ -9,10 +7,10 @@ module Escrow::escrow {
97 const E_NOT_BUYER : u64 = 5 ;
108 const E_NOT_SELLER : u64 = 6 ;
119
12- /// Simple wallet resource for demo/tests (no global storage)
10+ /// Simple wallet (no global storage)
1311 struct Wallet has store { balance: u64 }
1412
15- /// Deal state kept in-memory for demo
13+ /// Deal state ( in-memory demo)
1614 struct Deal has store {
1715 buyer: address ,
1816 seller: address ,
@@ -21,45 +19,37 @@ module Escrow::escrow {
2119 completed: bool ,
2220 }
2321
24- public fun new_wallet (_owner: & signer ): Wallet { Wallet { balance: 0 } }
22+ public fun new_wallet (): Wallet { Wallet { balance: 0 } }
2523
26- public fun deposit (_owner: &signer , w: &mut Wallet , amount: u64 ) {
27- w.balance = w.balance + amount;
28- }
24+ public fun deposit (w: &mut Wallet , amount: u64 ) { w.balance = w.balance + amount; }
2925
3026 public fun balance (w: &Wallet ): u64 { w.balance }
3127
32- public fun create (buyer: &signer , seller: address , amount: u64 ): Deal {
33- Deal {
34- buyer: signer ::address_of (buyer),
35- seller,
36- amount,
37- funded: false ,
38- completed: false ,
39- }
28+ public fun create (buyer: address , seller: address , amount: u64 ): Deal {
29+ Deal { buyer, seller, amount, funded: false , completed: false }
4030 }
4131
42- public fun fund (buyer: & signer , buyer_wallet : &mut Wallet , d: &mut Deal ) {
43- assert ! (signer :: address_of ( buyer) == d.buyer, E_NOT_BUYER );
32+ public fun fund (buyer: address , bw : &mut Wallet , d: &mut Deal ) {
33+ assert ! (buyer == d.buyer, E_NOT_BUYER );
4434 assert ! (!d.funded, E_ALREADY_FUNDED );
45- assert ! (buyer_wallet .balance >= d.amount, E_INSUFFICIENT );
46- buyer_wallet .balance = buyer_wallet .balance - d.amount;
35+ assert ! (bw .balance >= d.amount, E_INSUFFICIENT );
36+ bw .balance = bw .balance - d.amount;
4737 d.funded = true ;
4838 }
4939
50- public fun release (seller: & signer , seller_wallet : &mut Wallet , d: &mut Deal ) {
51- assert ! (signer :: address_of ( seller) == d.seller, E_NOT_SELLER );
40+ public fun release (seller: address , sw : &mut Wallet , d: &mut Deal ) {
41+ assert ! (seller == d.seller, E_NOT_SELLER );
5242 assert ! (d.funded, E_NOT_FUNDED );
5343 assert ! (!d.completed, E_COMPLETED );
54- seller_wallet .balance = seller_wallet .balance + d.amount;
44+ sw .balance = sw .balance + d.amount;
5545 d.completed = true ;
5646 }
5747
58- public fun refund (buyer: & signer , buyer_wallet : &mut Wallet , d: &mut Deal ) {
59- assert ! (signer :: address_of ( buyer) == d.buyer, E_NOT_BUYER );
48+ public fun refund (buyer: address , bw : &mut Wallet , d: &mut Deal ) {
49+ assert ! (buyer == d.buyer, E_NOT_BUYER );
6050 assert ! (d.funded, E_NOT_FUNDED );
6151 assert ! (!d.completed, E_COMPLETED );
62- buyer_wallet .balance = buyer_wallet .balance + d.amount;
52+ bw .balance = bw .balance + d.amount;
6353 d.completed = true ;
6454 }
6555}
0 commit comments