@@ -63,7 +63,9 @@ pub mod pallet {
63
63
/// The currency trait.
64
64
type Currency : Inspect < Self :: AccountId >
65
65
+ Mutate < Self :: AccountId >
66
- + MutateHold < Self :: AccountId , Reason = Self :: RuntimeHoldReason > ;
66
+ + MutateHold < Self :: AccountId , Reason = <Self as pallet:: Config >:: RuntimeHoldReason > ;
67
+
68
+ type Escrow : Escrow < Self :: AccountId , BalanceOf < Self > , Self :: AccountId > ;
67
69
68
70
/// Overarching hold reason.
69
71
type RuntimeHoldReason : From < HoldReason > ;
@@ -121,7 +123,7 @@ pub mod pallet {
121
123
T :: CollectionId ,
122
124
Blake2_128Concat ,
123
125
T :: ItemId ,
124
- Ask < T :: AccountId , BalanceOf < T > , T :: Moment > ,
126
+ Ask < T :: AccountId , BalanceOf < T > , T :: Moment , T :: AccountId > ,
125
127
> ;
126
128
127
129
#[ pallet:: storage]
@@ -382,6 +384,7 @@ pub mod pallet {
382
384
order. item ,
383
385
& order. price ,
384
386
& order. fee ,
387
+ order. escrow_agent ,
385
388
) ?;
386
389
} else {
387
390
ensure ! (
@@ -394,6 +397,7 @@ pub mod pallet {
394
397
price : order. price ,
395
398
expiration : order. expires_at ,
396
399
fee : order. fee ,
400
+ escrow_agent : order. escrow_agent ,
397
401
} ;
398
402
399
403
Asks :: < T > :: insert ( order. collection , order. item , ask) ;
@@ -429,6 +433,7 @@ pub mod pallet {
429
433
order. item ,
430
434
& order. price ,
431
435
& order. fee ,
436
+ order. escrow_agent ,
432
437
) ?;
433
438
} else {
434
439
ensure ! (
@@ -529,7 +534,7 @@ pub mod pallet {
529
534
collection : & T :: CollectionId ,
530
535
item : & T :: ItemId ,
531
536
price : & BalanceOf < T > ,
532
- ) -> Option < ExecOrder < T :: AccountId , BalanceOf < T > , T :: Moment > > {
537
+ ) -> Option < ExecOrder < T :: AccountId , BalanceOf < T > , T :: Moment , T :: AccountId > > {
533
538
let timestamp = pallet_timestamp:: Pallet :: < T > :: get ( ) ;
534
539
535
540
match order_type {
@@ -554,17 +559,19 @@ pub mod pallet {
554
559
}
555
560
556
561
pub fn execute_order (
557
- exec_order : ExecOrder < T :: AccountId , BalanceOf < T > , T :: Moment > ,
562
+ exec_order : ExecOrder < T :: AccountId , BalanceOf < T > , T :: Moment , T :: AccountId > ,
558
563
who : T :: AccountId ,
559
564
collection : T :: CollectionId ,
560
565
item : T :: ItemId ,
561
566
price : & BalanceOf < T > ,
562
567
fee : & BalanceOf < T > ,
568
+ order_escrow_agent : Option < T :: AccountId > ,
563
569
) -> Result < ( ) , DispatchError > {
564
570
let seller: T :: AccountId ;
565
571
let buyer: T :: AccountId ;
566
572
let seller_fee: BalanceOf < T > ;
567
573
let buyer_fee: BalanceOf < T > ;
574
+ let escrow_agent: Option < T :: AccountId > ;
568
575
569
576
match exec_order {
570
577
ExecOrder :: Bid ( bid) => {
@@ -574,6 +581,7 @@ pub mod pallet {
574
581
buyer = bid. buyer ;
575
582
seller_fee = * fee;
576
583
buyer_fee = bid. fee ;
584
+ escrow_agent = order_escrow_agent;
577
585
} ,
578
586
ExecOrder :: Ask ( ask) => {
579
587
ensure ! ( who. clone( ) != ask. seller. clone( ) , Error :: <T >:: BuyerIsSeller ) ;
@@ -582,13 +590,14 @@ pub mod pallet {
582
590
buyer = who;
583
591
seller_fee = ask. fee ;
584
592
buyer_fee = * fee;
593
+ escrow_agent = ask. escrow_agent ;
585
594
} ,
586
595
} ;
587
596
588
597
Asks :: < T > :: remove ( collection, item) ;
589
598
Bids :: < T > :: remove ( ( collection, item, * price) ) ;
590
599
591
- Self :: process_fees ( & seller, seller_fee, & buyer, buyer_fee, * price) ?;
600
+ Self :: process_fees ( & seller, seller_fee, & buyer, buyer_fee, * price, escrow_agent ) ?;
592
601
593
602
pallet_nfts:: Pallet :: < T > :: enable_transfer ( & collection, & item) ?;
594
603
<pallet_nfts:: Pallet < T > as Transfer < T :: AccountId > >:: transfer (
@@ -622,6 +631,7 @@ pub mod pallet {
622
631
buyer : & T :: AccountId ,
623
632
buyer_fee : BalanceOf < T > ,
624
633
price : BalanceOf < T > ,
634
+ escrow_agent : Option < T :: AccountId > ,
625
635
) -> Result < ( ) , DispatchError > {
626
636
//Amount to be payed by the buyer
627
637
let buyer_payment_amount = price. checked_add ( & buyer_fee) . ok_or ( Error :: < T > :: Overflow ) ?;
@@ -651,7 +661,19 @@ pub mod pallet {
651
661
Preserve ,
652
662
) ?;
653
663
//Pay earnings to seller
654
- <T as crate :: Config >:: Currency :: transfer ( buyer, seller, seller_pay_amount, Preserve ) ?;
664
+ match escrow_agent {
665
+ Some ( agent) => {
666
+ T :: Escrow :: make_deposit ( buyer, seller, seller_pay_amount, & agent) ?;
667
+ } ,
668
+ None => {
669
+ <T as crate :: Config >:: Currency :: transfer (
670
+ buyer,
671
+ seller,
672
+ seller_pay_amount,
673
+ Preserve ,
674
+ ) ?;
675
+ } ,
676
+ }
655
677
656
678
Ok ( ( ) )
657
679
}
0 commit comments