@@ -192,13 +192,17 @@ pub struct OpenTip<
192
192
reason : Hash ,
193
193
/// The account to be tipped.
194
194
who : AccountId ,
195
- /// The account who began this tip and the amount held on deposit.
196
- finder : Option < ( AccountId , Balance ) > ,
195
+ /// The account who began this tip.
196
+ finder : AccountId ,
197
+ /// The amount held on deposit for this tip.
198
+ deposit : Balance ,
197
199
/// The block number at which this tip will close if `Some`. If `None`, then no closing is
198
200
/// scheduled.
199
201
closes : Option < BlockNumber > ,
200
202
/// The members who have voted for this tip. Sorted by AccountId.
201
203
tips : Vec < ( AccountId , Balance ) > ,
204
+ /// Whether this tip should result in the finder taking a fee.
205
+ finders_fee : bool ,
202
206
}
203
207
204
208
decl_storage ! {
@@ -428,8 +432,15 @@ decl_module! {
428
432
T :: Currency :: reserve( & finder, deposit) ?;
429
433
430
434
Reasons :: <T >:: insert( & reason_hash, & reason) ;
431
- let finder = Some ( ( finder, deposit) ) ;
432
- let tip = OpenTip { reason: reason_hash, who, finder, closes: None , tips: vec![ ] } ;
435
+ let tip = OpenTip {
436
+ reason: reason_hash,
437
+ who,
438
+ finder,
439
+ deposit,
440
+ closes: None ,
441
+ tips: vec![ ] ,
442
+ finders_fee: true
443
+ } ;
433
444
Tips :: <T >:: insert( & hash, tip) ;
434
445
Self :: deposit_event( RawEvent :: NewTip ( hash) ) ;
435
446
}
@@ -457,12 +468,13 @@ decl_module! {
457
468
fn retract_tip( origin, hash: T :: Hash ) {
458
469
let who = ensure_signed( origin) ?;
459
470
let tip = Tips :: <T >:: get( & hash) . ok_or( Error :: <T >:: UnknownTip ) ?;
460
- let ( finder, deposit) = tip. finder. ok_or( Error :: <T >:: NotFinder ) ?;
461
- ensure!( finder == who, Error :: <T >:: NotFinder ) ;
471
+ ensure!( tip. finder == who, Error :: <T >:: NotFinder ) ;
462
472
463
473
Reasons :: <T >:: remove( & tip. reason) ;
464
474
Tips :: <T >:: remove( & hash) ;
465
- let _ = T :: Currency :: unreserve( & who, deposit) ;
475
+ if !tip. deposit. is_zero( ) {
476
+ let _ = T :: Currency :: unreserve( & who, tip. deposit) ;
477
+ }
466
478
Self :: deposit_event( RawEvent :: TipRetracted ( hash) ) ;
467
479
}
468
480
@@ -501,8 +513,16 @@ decl_module! {
501
513
502
514
Reasons :: <T >:: insert( & reason_hash, & reason) ;
503
515
Self :: deposit_event( RawEvent :: NewTip ( hash. clone( ) ) ) ;
504
- let tips = vec![ ( tipper, tip_value) ] ;
505
- let tip = OpenTip { reason: reason_hash, who, finder: None , closes: None , tips } ;
516
+ let tips = vec![ ( tipper. clone( ) , tip_value) ] ;
517
+ let tip = OpenTip {
518
+ reason: reason_hash,
519
+ who,
520
+ finder: tipper,
521
+ deposit: Zero :: zero( ) ,
522
+ closes: None ,
523
+ tips,
524
+ finders_fee: false ,
525
+ } ;
506
526
Tips :: <T >:: insert( & hash, tip) ;
507
527
}
508
528
@@ -667,15 +687,17 @@ impl<T: Trait> Module<T> {
667
687
let treasury = Self :: account_id ( ) ;
668
688
let max_payout = Self :: pot ( ) ;
669
689
let mut payout = tips[ tips. len ( ) / 2 ] . 1 . min ( max_payout) ;
670
- if let Some ( ( finder, deposit) ) = tip. finder {
671
- let _ = T :: Currency :: unreserve ( & finder, deposit) ;
672
- if finder != tip. who {
690
+ if !tip. deposit . is_zero ( ) {
691
+ let _ = T :: Currency :: unreserve ( & tip. finder , tip. deposit ) ;
692
+ }
693
+ if tip. finders_fee {
694
+ if tip. finder != tip. who {
673
695
// pay out the finder's fee.
674
696
let finders_fee = T :: TipFindersFee :: get ( ) * payout;
675
697
payout -= finders_fee;
676
698
// this should go through given we checked it's at most the free balance, but still
677
699
// we only make a best-effort.
678
- let _ = T :: Currency :: transfer ( & treasury, & finder, finders_fee, KeepAlive ) ;
700
+ let _ = T :: Currency :: transfer ( & treasury, & tip . finder , finders_fee, KeepAlive ) ;
679
701
}
680
702
}
681
703
// same as above: best-effort only.
@@ -753,6 +775,55 @@ impl<T: Trait> Module<T> {
753
775
// Must never be less than 0 but better be safe.
754
776
. saturating_sub ( T :: Currency :: minimum_balance ( ) )
755
777
}
778
+
779
+ pub fn migrate_retract_tip_for_tip_new ( ) {
780
+ /// An open tipping "motion". Retains all details of a tip including information on the finder
781
+ /// and the members who have voted.
782
+ #[ derive( Clone , Eq , PartialEq , Encode , Decode , RuntimeDebug ) ]
783
+ pub struct OldOpenTip <
784
+ AccountId : Parameter ,
785
+ Balance : Parameter ,
786
+ BlockNumber : Parameter ,
787
+ Hash : Parameter ,
788
+ > {
789
+ /// The hash of the reason for the tip. The reason should be a human-readable UTF-8 encoded string. A URL would be
790
+ /// sensible.
791
+ reason : Hash ,
792
+ /// The account to be tipped.
793
+ who : AccountId ,
794
+ /// The account who began this tip and the amount held on deposit.
795
+ finder : Option < ( AccountId , Balance ) > ,
796
+ /// The block number at which this tip will close if `Some`. If `None`, then no closing is
797
+ /// scheduled.
798
+ closes : Option < BlockNumber > ,
799
+ /// The members who have voted for this tip. Sorted by AccountId.
800
+ tips : Vec < ( AccountId , Balance ) > ,
801
+ }
802
+
803
+ use frame_support:: { Twox64Concat , migration:: StorageKeyIterator } ;
804
+
805
+ for ( hash, old_tip) in StorageKeyIterator :: <
806
+ T :: Hash ,
807
+ OldOpenTip < T :: AccountId , BalanceOf < T > , T :: BlockNumber , T :: Hash > ,
808
+ Twox64Concat ,
809
+ > :: new ( b"Treasury" , b"Tips" ) . drain ( )
810
+ {
811
+ let ( finder, deposit, finders_fee) = match old_tip. finder {
812
+ Some ( ( finder, deposit) ) => ( finder, deposit, true ) ,
813
+ None => ( T :: AccountId :: default ( ) , Zero :: zero ( ) , false ) ,
814
+ } ;
815
+ let new_tip = OpenTip {
816
+ reason : old_tip. reason ,
817
+ who : old_tip. who ,
818
+ finder,
819
+ deposit,
820
+ closes : old_tip. closes ,
821
+ tips : old_tip. tips ,
822
+ finders_fee
823
+ } ;
824
+ Tips :: < T > :: insert ( hash, new_tip)
825
+ }
826
+ }
756
827
}
757
828
758
829
impl < T : Trait > OnUnbalanced < NegativeImbalanceOf < T > > for Module < T > {
0 commit comments