1
1
#![ cfg_attr( not( feature = "std" ) , no_std) ]
2
2
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 } ;
4
4
use frame_system:: { self as system, ensure_signed} ;
5
5
use 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
+ } ;
8
10
9
11
use orml_traits:: { Auction , AuctionHandler , AuctionInfo } ;
10
12
@@ -43,22 +45,24 @@ decl_storage! {
43
45
44
46
decl_module ! {
45
47
pub struct Module <T : Trait > for enum Call where origin: T :: Origin {
48
+ type Error = Error <T >;
49
+
46
50
fn deposit_event( ) = default ;
47
51
48
- pub fn bid( origin, id: T :: AuctionId , value: T :: Balance ) -> Result {
52
+ pub fn bid( origin, id: T :: AuctionId , value: T :: Balance ) {
49
53
let from = ensure_signed( origin) ?;
50
54
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 ) ?;
52
56
53
57
let block_number = <frame_system:: Module <T >>:: block_number( ) ;
54
58
55
59
// make sure auction is started
56
- ensure!( block_number >= auction. start, Error :: AuctionNotStarted . into ( ) ) ;
60
+ ensure!( block_number >= auction. start, Error :: < T > :: AuctionNotStarted ) ;
57
61
58
62
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 ) ;
60
64
} else {
61
- ensure!( value > 0 . into ( ) , Error :: InvalidBidPrice . into ( ) ) ;
65
+ ensure!( ! value. is_zero ( ) , Error :: < T > :: InvalidBidPrice ) ;
62
66
}
63
67
let bid_result = T :: Handler :: on_new_bid(
64
68
block_number,
@@ -67,7 +71,7 @@ decl_module! {
67
71
auction. bid. clone( ) ,
68
72
) ;
69
73
70
- ensure!( bid_result. accept_bid, Error :: BidNotAccepted . into ( ) ) ;
74
+ ensure!( bid_result. accept_bid, Error :: < T > :: BidNotAccepted ) ;
71
75
if let Some ( new_end) = bid_result. auction_end {
72
76
if let Some ( old_end_block) = auction. end {
73
77
<AuctionEndTimeList <T >>:: remove( & old_end_block, id) ;
@@ -80,7 +84,6 @@ decl_module! {
80
84
auction. bid = Some ( ( from. clone( ) , value) ) ;
81
85
<Auctions <T >>:: insert( id, auction) ;
82
86
Self :: deposit_event( RawEvent :: Bid ( id, from, value) ) ;
83
- Ok ( ( ) )
84
87
}
85
88
86
89
fn on_finalize( now: T :: BlockNumber ) {
@@ -106,7 +109,7 @@ decl_module! {
106
109
107
110
decl_error ! {
108
111
/// Error for auction module.
109
- pub enum Error {
112
+ pub enum Error for Module < T : Trait > {
110
113
AuctionNotExist ,
111
114
AuctionNotStarted ,
112
115
BidNotAccepted ,
@@ -119,7 +122,6 @@ impl<T: Trait> Module<T> {}
119
122
impl < T : Trait > Auction < T :: AccountId , T :: BlockNumber > for Module < T > {
120
123
type AuctionId = T :: AuctionId ;
121
124
type Balance = T :: Balance ;
122
- type Error = Error ;
123
125
124
126
fn auction_info ( id : Self :: AuctionId ) -> Option < AuctionInfo < T :: AccountId , Self :: Balance , T :: BlockNumber > > {
125
127
Self :: auctions ( id)
@@ -128,8 +130,8 @@ impl<T: Trait> Auction<T::AccountId, T::BlockNumber> for Module<T> {
128
130
fn update_auction (
129
131
id : Self :: AuctionId ,
130
132
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 ) ?;
133
135
if let Some ( old_end) = auction. end {
134
136
<AuctionEndTimeList < T > >:: remove ( & old_end, id) ;
135
137
}
0 commit comments