11#![ cfg_attr( not( feature = "std" ) , no_std) ]
22
3- use frame_support:: { decl_error, decl_event, decl_module, decl_storage, dispatch :: Result , ensure, Parameter } ;
3+ use frame_support:: { decl_error, decl_event, decl_module, decl_storage, ensure, Parameter } ;
44use frame_system:: { self as system, ensure_signed} ;
55use orml_utilities:: { LinkedItem , LinkedList } ;
6- use rstd:: result;
7- use sp_runtime:: traits:: { MaybeSerializeDeserialize , Member , SimpleArithmetic } ;
6+ use sp_runtime:: {
7+ traits:: { MaybeSerializeDeserialize , Member , SimpleArithmetic , Zero } ,
8+ DispatchResult ,
9+ } ;
810
911use orml_traits:: { Auction , AuctionHandler , AuctionInfo } ;
1012
@@ -43,22 +45,24 @@ decl_storage! {
4345
4446decl_module ! {
4547 pub struct Module <T : Trait > for enum Call where origin: T :: Origin {
48+ type Error = Error <T >;
49+
4650 fn deposit_event( ) = default ;
4751
48- pub fn bid( origin, id: T :: AuctionId , value: T :: Balance ) -> Result {
52+ pub fn bid( origin, id: T :: AuctionId , value: T :: Balance ) {
4953 let from = ensure_signed( origin) ?;
5054
51- let mut auction = <Auctions <T >>:: get( id) . ok_or( Error :: AuctionNotExist ) ?;
55+ let mut auction = <Auctions <T >>:: get( id) . ok_or( Error :: < T > :: AuctionNotExist ) ?;
5256
5357 let block_number = <frame_system:: Module <T >>:: block_number( ) ;
5458
5559 // make sure auction is started
56- ensure!( block_number >= auction. start, Error :: AuctionNotStarted . into ( ) ) ;
60+ ensure!( block_number >= auction. start, Error :: < T > :: AuctionNotStarted ) ;
5761
5862 if let Some ( ref current_bid) = auction. bid {
59- ensure!( value > current_bid. 1 , Error :: InvalidBidPrice . into ( ) ) ;
63+ ensure!( value > current_bid. 1 , Error :: < T > :: InvalidBidPrice ) ;
6064 } else {
61- ensure!( value > 0 . into ( ) , Error :: InvalidBidPrice . into ( ) ) ;
65+ ensure!( ! value. is_zero ( ) , Error :: < T > :: InvalidBidPrice ) ;
6266 }
6367 let bid_result = T :: Handler :: on_new_bid(
6468 block_number,
@@ -67,7 +71,7 @@ decl_module! {
6771 auction. bid. clone( ) ,
6872 ) ;
6973
70- ensure!( bid_result. accept_bid, Error :: BidNotAccepted . into ( ) ) ;
74+ ensure!( bid_result. accept_bid, Error :: < T > :: BidNotAccepted ) ;
7175 if let Some ( new_end) = bid_result. auction_end {
7276 if let Some ( old_end_block) = auction. end {
7377 <AuctionEndTimeList <T >>:: remove( & old_end_block, id) ;
@@ -80,7 +84,6 @@ decl_module! {
8084 auction. bid = Some ( ( from. clone( ) , value) ) ;
8185 <Auctions <T >>:: insert( id, auction) ;
8286 Self :: deposit_event( RawEvent :: Bid ( id, from, value) ) ;
83- Ok ( ( ) )
8487 }
8588
8689 fn on_finalize( now: T :: BlockNumber ) {
@@ -106,7 +109,7 @@ decl_module! {
106109
107110decl_error ! {
108111 /// Error for auction module.
109- pub enum Error {
112+ pub enum Error for Module < T : Trait > {
110113 AuctionNotExist ,
111114 AuctionNotStarted ,
112115 BidNotAccepted ,
@@ -119,7 +122,6 @@ impl<T: Trait> Module<T> {}
119122impl < T : Trait > Auction < T :: AccountId , T :: BlockNumber > for Module < T > {
120123 type AuctionId = T :: AuctionId ;
121124 type Balance = T :: Balance ;
122- type Error = Error ;
123125
124126 fn auction_info ( id : Self :: AuctionId ) -> Option < AuctionInfo < T :: AccountId , Self :: Balance , T :: BlockNumber > > {
125127 Self :: auctions ( id)
@@ -128,8 +130,8 @@ impl<T: Trait> Auction<T::AccountId, T::BlockNumber> for Module<T> {
128130 fn update_auction (
129131 id : Self :: AuctionId ,
130132 info : AuctionInfo < T :: AccountId , Self :: Balance , T :: BlockNumber > ,
131- ) -> result :: Result < ( ) , Self :: Error > {
132- let auction = <Auctions < T > >:: get ( id) . ok_or ( Error :: AuctionNotExist ) ?;
133+ ) -> DispatchResult {
134+ let auction = <Auctions < T > >:: get ( id) . ok_or ( Error :: < T > :: AuctionNotExist ) ?;
133135 if let Some ( old_end) = auction. end {
134136 <AuctionEndTimeList < T > >:: remove ( & old_end, id) ;
135137 }
0 commit comments