Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to v2.0.0 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,289 changes: 940 additions & 349 deletions Cargo.lock

Large diffs are not rendered by default.

62 changes: 12 additions & 50 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,27 @@ version = "0.1.0"
authors = ["Logan Saether <x@logansaether.com>"]
edition = "2018"

[dependencies.pallet-balances]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'pallet-balances'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'
[dependencies]
codec = { version = '1.3.4', default-features = false, features = ['derive'], package = 'parity-scale-codec' }
safe-mix = { version = '1.0.0', default-features = false }

[dependencies.pallet-fungible]
default-features = false
path = './fungible'
pallet-balances = { version = '2.0.0', default-features = false }
pallet-fungible = { default-features = false, path = './fungible' }
frame-support = { version = '2.0.0', default-features = false }
sp-runtime = { version = '2.0.0', default-features = false }
frame-system = { version = '2.0.0', default-features = false }

[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '1.0.0'

[dependencies.frame-support]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dependencies.safe-mix]
default-features = false
version = '1.0.0'

[dependencies.system]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'frame-system'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dev-dependencies.sp-core]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dev-dependencies.sp-io]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'
[dev-dependencies]
sp-core = { version = '2.0.0', default-features = false }
sp-io = { version = '2.0.0', default-features = false }

[features]
default = ['std']
std = [
'codec/std',
'frame-support/std',
'safe-mix/std',
'system/std',
'frame-system/std',
'sp-runtime/std',
'pallet-balances/std'
]
57 changes: 11 additions & 46 deletions fungible/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,26 @@ version = "0.1.0"
authors = ["Logan Saether <x@logansaether.com>"]
edition = "2018"

[dependencies.pallet-balances]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'pallet-balances'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'
[dependencies]
codec = { version = '1.3.4', default-features = false, features = ['derive'], package = 'parity-scale-codec' }
safe-mix = { version = '1.0.0', default-features = false }

[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '1.0.0'
frame-support = { version = '2.0.0', default-features = false }
pallet-balances = { version = '2.0.0', default-features = false }
sp-runtime = { version = '2.0.0', default-features = false }
frame-system = { version = '2.0.0', default-features = false }

[dependencies.frame-support]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dependencies.safe-mix]
default-features = false
version = '1.0.0'

[dependencies.system]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'frame-system'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dev-dependencies.sp-core]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dev-dependencies.sp-io]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'

[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd1b9ccad107e4899978858de5ddd2868b9777aab'
version = '2.0.0-alpha.5'
[dev-dependencies]
sp-core = { version = '2.0.0', default-features = false }
sp-io = { version = '2.0.0', default-features = false }

[features]
default = ['std']
std = [
'codec/std',
'frame-support/std',
'safe-mix/std',
'system/std',
'frame-system/std',
'sp-runtime/std',
'pallet-balances/std'
]
36 changes: 21 additions & 15 deletions fungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ use frame_support::{
decl_module, decl_storage, decl_event, decl_error, dispatch, ensure,
Parameter,
};
use system::ensure_signed;
use frame_system::ensure_signed;

#[cfg(test)]
mod mock;

#[cfg(test)]
mod tests;

pub trait Trait: system::Trait {
pub trait Trait: frame_system::Trait {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;

type TokenBalance: Parameter + Member + AtLeast32Bit + Default + Copy
+ MaybeSerializeDeserialize;

type TokenId: Parameter + Member + AtLeast32Bit + Default + Copy
+ MaybeSerializeDeserialize;
}

decl_event!(
pub enum Event<T>
where
AccountId = <T as system::Trait>::AccountId,
TokenBalance = <T as Trait>::TokenBalance,
TokenId = <T as Trait>::TokenId,
<T as frame_system::Trait>::AccountId,
<T as Trait>::TokenBalance,
<T as Trait>::TokenId,
{
NewToken(TokenId, AccountId, TokenBalance),
/// <from, to, amount>
Expand All @@ -59,13 +59,13 @@ decl_error! {

decl_storage!(
trait Store for Module<T: Trait> as Fungible {
TokenCount get(token_count): T::TokenId;
TokenCount get(fn token_count): T::TokenId;

/// ERC20 compatible.
/// Maps (id, owner, spender) => amount.
Allowance get(allowance): map hasher(opaque_blake2_256) (T::TokenId, T::AccountId, T::AccountId) => T::TokenBalance;
Balances get(balance_of): map hasher(opaque_blake2_256) (T::TokenId, T::AccountId) => T::TokenBalance;
TotalSupply get(total_supply): map hasher(opaque_blake2_256) T::TokenId => T::TokenBalance;
Allowance get(fn allowance): map hasher(opaque_blake2_256) (T::TokenId, T::AccountId, T::AccountId) => T::TokenBalance;
Balances get(fn balance_of): map hasher(opaque_blake2_256) (T::TokenId, T::AccountId) => T::TokenBalance;
TotalSupply get(fn total_supply): map hasher(opaque_blake2_256) T::TokenId => T::TokenBalance;
}
);

Expand All @@ -76,10 +76,11 @@ decl_module!(

fn deposit_event() = default;

#[weight = 0]
pub fn debug_create_token(
origin,
#[compact] total_supply: T::TokenBalance,
) -> dispatch::DispatchResult
) -> dispatch::DispatchResult
{
let sender = ensure_signed(origin)?;

Expand All @@ -88,6 +89,7 @@ decl_module!(
Ok(())
}

#[weight = 0]
pub fn transfer(
origin,
id: T::TokenId,
Expand All @@ -103,6 +105,7 @@ decl_module!(
Self::do_transfer(id, sender.clone(), recipient.clone(), amount)
}

#[weight = 0]
pub fn transfer_from(
origin,
id: T::TokenId,
Expand All @@ -128,6 +131,7 @@ decl_module!(
Ok(())
}

#[weight = 0]
pub fn approve(
origin,
id: T::TokenId,
Expand All @@ -149,6 +153,7 @@ decl_module!(
Ok(())
}

#[weight = 0]
pub fn debug_mint(
origin,
id: T::TokenId,
Expand All @@ -160,7 +165,8 @@ decl_module!(
Self::mint(id, to, amount)
}

pub fn debug_burn(origin, id: T::TokenId, from: T::AccountId, amount: T::TokenBalance)
#[weight = 0]
pub fn debug_burn(origin, id: T::TokenId, from: T::AccountId, amount: T::TokenBalance)
-> dispatch::DispatchResult
{
ensure_signed(origin)?;
Expand Down Expand Up @@ -205,13 +211,13 @@ impl<T: Trait> Module<T> {
// TODO: Watch for overflow here. PUZZLE: Find a good solution that doesn't
// need to make this function return a result, which may be an anti-pattern.
let next_id = id.checked_add(&One::one()).unwrap();

<Balances<T>>::insert((id, who.clone()), total_supply);
<TotalSupply<T>>::insert(id, total_supply);
<TokenCount<T>>::put(next_id);

Self::deposit_event(RawEvent::NewToken(id, who, total_supply));

id
}

Expand Down
14 changes: 10 additions & 4 deletions fungible/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}

impl system::Trait for Test {
impl frame_system::Trait for Test {
type Origin = Origin;
type Call = ();
type Index = u64;
Expand All @@ -40,10 +40,16 @@ impl system::Trait for Test {
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type PalletInfo = ();
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type BaseCallFilter = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type SystemWeightInfo = ();
}

impl Trait for Test {
Expand All @@ -61,10 +67,10 @@ impl Trait for Test {
// type AccountStore = System;
// }

// type System = system::Module<Test>;
// type System = frame_system::Module<Test>;
// type Balances = pallet_balances::Module<Test>;
pub type FungiblePallet = Module<Test>;

pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
}
8 changes: 4 additions & 4 deletions fungible/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn it_works() {
fn it_creates_a_token() {
new_test_ext().execute_with(|| {
assert_eq!(FungiblePallet::token_count(), 0);
assert_eq!(FungiblePallet::create_token(1, 42), 0u64.into());
assert_eq!(FungiblePallet::create_token(1, 42), 0);
assert_eq!(FungiblePallet::token_count(), 1);
assert_eq!(
FungiblePallet::balance_of((0, 1)),
Expand All @@ -28,7 +28,7 @@ fn it_creates_a_token() {
#[test]
fn it_transfers_a_token() {
new_test_ext().execute_with(|| {
assert_eq!(FungiblePallet::create_token(1, 42), 0u64.into());
assert_eq!(FungiblePallet::create_token(1, 42), 0);
assert_ok!(
FungiblePallet::transfer(Origin::signed(1), 0, 2, 22)
);
Expand All @@ -44,7 +44,7 @@ fn it_transfers_a_token() {
#[test]
fn it_creates_allowance_and_transfers() {
new_test_ext().execute_with(|| {
assert_eq!(FungiblePallet::create_token(1, 42), 0u64.into());
assert_eq!(FungiblePallet::create_token(1, 42), 0);
assert_ok!(
FungiblePallet::approve(Origin::signed(1), 0, 2, 20)
);
Expand All @@ -56,4 +56,4 @@ fn it_creates_allowance_and_transfers() {
assert_eq!(FungiblePallet::balance_of((0, 1)), 32);
assert_eq!(FungiblePallet::balance_of((0, 3)), 10);
});
}
}
Loading