Skip to content

Commit 47d36eb

Browse files
authored
update to latest substrate (#65)
1 parent cf54a91 commit 47d36eb

File tree

14 files changed

+116
-170
lines changed

14 files changed

+116
-170
lines changed

auction/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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};
44
use frame_system::{self as system, ensure_signed};
55
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+
};
810

911
use orml_traits::{Auction, AuctionHandler, AuctionInfo};
1012

@@ -43,22 +45,24 @@ decl_storage! {
4345

4446
decl_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

107110
decl_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> {}
119122
impl<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
}

auction/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl frame_system::Trait for Runtime {
5454
type MaximumBlockLength = MaximumBlockLength;
5555
type AvailableBlockRatio = AvailableBlockRatio;
5656
type Version = ();
57+
type ModuleToIndex = ();
5758
}
5859

5960
pub struct Handler;

auction/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use super::*;
66
use frame_support::assert_ok;
7-
use mock::{AuctionModule, ExtBuilder, ALICE};
7+
use mock::{AuctionModule, ExtBuilder, Runtime, ALICE};
88

99
#[test]
1010
fn new_auction_should_work() {
@@ -65,7 +65,7 @@ fn bid_should_fail() {
6565
assert_eq!(AuctionModule::new_auction(10, Some(100)), 0);
6666
assert_eq!(
6767
AuctionModule::bid(Some(ALICE).into(), 0, 20),
68-
Err(Error::AuctionNotStarted.into())
68+
Err(Error::<Runtime>::AuctionNotStarted.into())
6969
);
7070
});
7171
}

0 commit comments

Comments
 (0)