Skip to content

Commit

Permalink
add sale history
Browse files Browse the repository at this point in the history
  • Loading branch information
tuminfei committed Dec 18, 2020
1 parent 55e9020 commit 8d26a70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions pallets/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ pub struct SaleOrder<AccountId> {
pub price: u64, // maker order's price\
}

#[derive(Encode, Decode, Default, Clone, PartialEq)]
pub struct SaleOrderHistory<AccountId, BlockNumber> {
pub collection_id: u64,
pub item_id: u64,
pub value: u64,
pub seller: AccountId,
pub buyer: AccountId,
pub price: u64,
pub buy_time: BlockNumber,
}

#[derive(Debug, Eq, PartialEq)]
pub enum TransferFromAccountError {
InsufficientBalance,
Expand Down Expand Up @@ -245,6 +256,9 @@ decl_storage! {

/// Consignment
pub SaleOrderList get(fn nft_trade_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => SaleOrder<T::AccountId>;

/// Sales history
pub SaleOrderHistoryList get(fn nft_trade_history_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => SaleOrderHistory<T::AccountId, T::BlockNumber>;
}
}

Expand Down Expand Up @@ -836,6 +850,7 @@ decl_module! {
let target_sale_order = <SaleOrderList<T>>::get(collection_id, item_id);
let nft_owner = target_sale_order.owner;
let price = target_sale_order.price;
let buy_time = <system::Module<T>>::block_number();


let target_collection = <Collection<T>>::get(collection_id);
Expand All @@ -862,6 +877,18 @@ decl_module! {
_ => ()
};

// Create order history
let order_history = SaleOrderHistory {
collection_id: collection_id,
item_id: item_id,
value: price,
seller: nft_owner.clone(),
buyer: sender.clone(),
price: price,
buy_time: buy_time,
};
<SaleOrderHistoryList<T>>::insert(collection_id, item_id, order_history);

<SaleOrderList<T>>::remove(collection_id, item_id);

// call event
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("uart"),
impl_name: create_runtime_str!("uart"),
authoring_version: 1,
spec_version: 8,
spec_version: 9,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 8d26a70

Please sign in to comment.