Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

slight client light work #89

Merged
merged 28 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d8ab1ae
first commit closes issue 87
4meta5 Jun 11, 2020
cce0890
remove unused error variants in org
4meta5 Jun 11, 2020
c7121a7
async reserve shares
4meta5 Jun 11, 2020
3fd24b0
client achieves org functionality with hard coded alice keyring so ne…
4meta5 Jun 12, 2020
2cdc21a
push some changes with client compilation errors related to lack of i…
4meta5 Jun 13, 2020
b763ea5
sunclient works without any generics, cool, cool
4meta5 Jun 13, 2020
764460a
got rid of sp-keyring as dep because we no longer will use hard coded…
4meta5 Jun 13, 2020
8baf9a5
add back light client feature and remove subxt_test stuff because it …
4meta5 Jun 13, 2020
55a508d
getting an error with keystore not found, must not be initialized cor…
4meta5 Jun 13, 2020
5212785
push some changes that simplify initialization of client but it still…
4meta5 Jun 13, 2020
c789fdc
remove tmp db and add gitignore to the typical path for our examples …
4meta5 Jun 13, 2020
7cb1c03
EventNotFound error returned by client for all calls ew
4meta5 Jun 14, 2020
3abb78b
push changes such that examples org is one issue shares call but we d…
4meta5 Jun 14, 2020
ccf0c60
removed WithdrawalPermissions to simplify bank and bounty and close i…
4meta5 Jun 14, 2020
6d1ccbd
vote boilerplate for client macros
4meta5 Jun 14, 2020
dbde267
Voted shouldve been named VotedEvent
4meta5 Jun 14, 2020
fe4125b
push client which does not compile due to extenuating errors in srml …
4meta5 Jun 15, 2020
793e6d6
adding bounds to bank fixed the errors previously emitted during clie…
4meta5 Jun 15, 2020
a7d7909
push client that doesnt compile because of issue #93
4meta5 Jun 15, 2020
11dccca
added all bank module constants maps calls and events and added tempo…
4meta5 Jun 15, 2020
7eb518b
this commit demonstrates issue #95 with an updated attempt to follow …
4meta5 Jun 15, 2020
b32dfaf
change examples org back to match substrate identity ex norms aka no …
4meta5 Jun 15, 2020
8d9225c
direct inheritance of bank for bounty in the client as per issue #96
4meta5 Jun 15, 2020
9204b36
added storage item boilerplate to client srml bounty
4meta5 Jun 15, 2020
f1b70ed
changed bounty to directly inherit bank instead of as an associated t…
4meta5 Jun 15, 2020
2717a74
finish client boilerplate for bounty module
4meta5 Jun 16, 2020
0841c31
separate permissions in bounty into separate trait just like in bank …
4meta5 Jun 16, 2020
69763b2
clippy makes code better
4meta5 Jun 16, 2020
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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cache/
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
client/tmp/

.DS_Store
12 changes: 8 additions & 4 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@ readme = "README.md"
description = "Submit extrinsics (transactions) to the sunshine node via RPC"
keywords = ["sunshine", "substrate", "blockchain"]

[features]
light-client = ["substrate-subxt-light-client", "sunshine-node"]

[dependencies]
async-std = "=1.5.0"
ipld-block-builder = "0.3.0"
libipld = { version = "0.3.0", features = ["dag-json"] }
serde = { version = "1.0.111", features = ["derive"] }
# TODO export error in libipld
sled = "0.32.0-rc1"
serde_json = "1.0.53"
ipfs-embed = "0.1.0"
# point at git master, could be done with patch.crates.io = giturl
substrate-subxt = "0.8.0"
surf = "1.0.3"
thiserror = "1.0.19"
utils-identity = { version = "0.1.0", path = "../utils" }
# substrate
sp-runtime = { version = "2.0.0-rc3", default-features = false }
sp-core = { version = "2.0.0-rc3", default-features = false }
codec = { version = "1.3.0", package = "parity-scale-codec" }
frame-support = "2.0.0-rc3"
pallet-indices = "2.0.0-rc3"
derive-new = {version = "0.5", default-features=false}
substrate-subxt-light-client = { package = "substrate-subxt", git = "https://github.com/dvc94ch/substrate-subxt", branch = "lightclient", optional = true }
sunshine-node = { path = "../node", default-features = false, optional = true }
keystore = {package = "keybase-keystore", git = "https://github.com/sunshine-protocol/substrate-identity"}
# local deps
utils-identity = { version = "0.1.0", path = "../utils" }
util = { package = "sunshine-util", path = "../modules/util", default-features = false }
org = {package = "sunshine-org", path = "../modules/org", default-features=false }
vote = { package = "sunshine-vote", path = "../modules/vote", default-features=false}
Expand Down
42 changes: 42 additions & 0 deletions client/examples/org.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use sp_keyring::AccountKeyring;
//#[cfg(feature = "light-client")]
//use sunshine_client::ChainType;
use ipfs_embed::{Config, Store};
use ipld_block_builder::{BlockBuilder, Codec};
use keystore::{DeviceKey, KeyStore, Password};
use sp_core::crypto::Pair;
use sunshine_client::{ClientBuilder, Error, Runtime, SunClient};
// use libipld::cid::{Cid, Codec};
// use libipld::multihash::Sha2_256;
// use utils_identity::cid::CidBytes;

#[async_std::main]
async fn main() -> Result<(), Error> {
env_logger::init();
let subxt = ClientBuilder::new().build().await.unwrap();
let db = sled::open("tmp/db")?;
let ipld_tree = db.open_tree("ipld_tree")?;
let config = Config::from_tree(ipld_tree);
let store = Store::new(config)?;
let codec = Codec::new();
let ipld = BlockBuilder::new(store, codec);
let keystore = KeyStore::new("/tmp/keystore");
let alice_seed: [u8; 32] = AccountKeyring::Alice.into();
let _ = keystore.initialize(
&DeviceKey::from_seed(alice_seed),
&Password::from("password".to_string()),
)?;
// //#[cfg(not(feature = "light-client"))]
let client = SunClient::new(subxt, keystore, ipld);
// #[cfg(feature = "light-client")]
// let client = Sunshine::new("/tmp/db", signer, ChainType::Development).await?;
let account_id = sp_keyring::AccountKeyring::Alice.to_account_id();
client.issue_shares(1u64, account_id, 10u64).await?;

// println!(
// "Account {:?} was issued {:?} shares for organization {:?}",
// event.who, event.shares, event.organization,
// );

Ok(())
}
23 changes: 0 additions & 23 deletions client/examples/reserve_shares_and_watch.rs

This file was deleted.

6 changes: 6 additions & 0 deletions client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub enum Error {
Sled(#[from] sled::Error),
#[error("{0}")]
Ipfs(#[from] ipfs_embed::Error),
#[error(transparent)]
Keystore(#[from] keystore::Error),
#[error("keystore already initialized")]
KeystoreInitialized,
#[error("event not found")]
EventNotFound,
}

pub type Result<T> = core::result::Result<T, Error>;
6 changes: 5 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#[macro_use]
extern crate substrate_subxt;

#[macro_use]
extern crate derive_new;

mod error;
#[cfg(feature = "light-client")]
mod light_client;
Expand All @@ -13,4 +16,5 @@ mod sunshine;
pub use error::Error;
#[cfg(feature = "light-client")]
pub use light_client::ChainType;
pub use sunshine::Sunshine;
pub use runtime::{ClientBuilder, Runtime};
pub use sunshine::SunClient;
14 changes: 10 additions & 4 deletions client/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ use sp_runtime::{
use std::marker::PhantomData;
use substrate_subxt::{
balances::{AccountData, Balances},
system::System,
CheckEra, CheckGenesis, CheckNonce, CheckSpecVersion, CheckTxVersion, CheckWeight, SignedExtra,
system::System, //sp_core::crypto::Pair,
CheckEra,
CheckGenesis,
CheckNonce,
CheckSpecVersion,
CheckTxVersion,
CheckWeight,
SignedExtra,
};
use utils_identity::cid::CidBytes;

pub type Pair = sp_core::sr25519::Pair;
pub type ClientBuilder = substrate_subxt::ClientBuilder<Runtime, MultiSignature, RuntimeExtra>;
pub type Client = substrate_subxt::Client<Runtime, MultiSignature, RuntimeExtra>;
//pub type XtBuilder = substrate_subxt::XtBuilder<Runtime, Pair, MultiSignature, RuntimeExtra>;
pub type PairSigner = substrate_subxt::PairSigner<Runtime, MultiSignature, RuntimeExtra, Pair>;

/// Concrete type definitions compatible w/ sunshine's runtime aka `suntime`
#[derive(Debug, Clone, Eq, PartialEq)]
Expand All @@ -30,7 +36,7 @@ impl System for Runtime {
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
type Address = pallet_indices::address::Address<Self::AccountId, u32>;
type Address = pallet_indices::address::Address<Self::AccountId, u64>;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Extrinsic = OpaqueExtrinsic;
type AccountData = AccountData<<Self as Balances>::Balance>;
Expand Down
224 changes: 224 additions & 0 deletions client/src/srml/bank.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
use crate::srml::{
org::{Org, OrgEventsDecoder},
vote::{Vote, VoteEventsDecoder},
};
use codec::{Codec, Decode, Encode};
use frame_support::Parameter;
use sp_runtime::traits::{AtLeast32Bit, MaybeSerializeDeserialize, Member, Zero};
use std::fmt::Debug;
use substrate_subxt::system::{System, SystemEventsDecoder};
use util::bank::{
BankState, DepositInfo, InternalTransferInfo, OnChainTreasuryID, ReservationInfo,
};

pub type BalanceOf<T> = <T as Bank>::Currency; // as Currency<<T as System>::AccountId>>::Balance;

/// The subset of the bank trait and its inherited traits that the client must inherit
#[module]
pub trait Bank: System + Org + Vote {
/// Identifier for bank-related maps
type BankAssociatedId: Parameter
+ Member
+ AtLeast32Bit
+ Codec
+ Default
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ PartialOrd
+ PartialEq
+ Zero;

/// The currency type for on-chain transactions
type Currency: Parameter
+ Member
+ AtLeast32Bit
+ Codec
+ Default
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ PartialOrd
+ PartialEq
+ Zero; // + Currency<<Self as System>::AccountId> // commented out until #93 is resolved
}

// ~~ Values (Constants) ~~

#[derive(Clone, Debug, Eq, PartialEq, Encode)]
pub struct MinimumInitialDepositStore<T: Bank> {
pub amount: BalanceOf<T>,
}

// ~~ Maps ~~

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct BankStoresStore<T: Bank> {
#[store(returns = BankState<<T as Org>::OrgId, BalanceOf<T>>)]
pub id: OnChainTreasuryID,
phantom: std::marker::PhantomData<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct DepositsStore<T: Bank> {
#[store(returns = DepositInfo<<T as System>::AccountId, <T as Org>::IpfsReference, BalanceOf<T>>)]
pub bank_id: OnChainTreasuryID,
pub deposit_id: T::BankAssociatedId,
}

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct SpendReservationsStore<T: Bank> {
#[store(returns = ReservationInfo<<T as Org>::IpfsReference, BalanceOf<T>, <T as Org>::OrgId>)]
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
}

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct InternalTransfersStore<T: Bank> {
#[store(returns = InternalTransferInfo<T::BankAssociatedId, <T as Org>::IpfsReference, BalanceOf<T>, <T as Org>::OrgId>)]
pub bank_id: OnChainTreasuryID,
pub transfer_id: T::BankAssociatedId,
}

// ~~ (Calls, Events) ~~

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct DepositFromSignerForBankAccountCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub amount: BalanceOf<T>,
pub reason: <T as Org>::IpfsReference,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct CapitalDepositedIntoOnChainBankAccountEvent<T: Bank> {
pub depositer: <T as System>::AccountId,
pub bank_id: OnChainTreasuryID,
pub amount: BalanceOf<T>,
pub reason: <T as Org>::IpfsReference,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct RegisterAndSeedForBankAccountCall<T: Bank> {
pub seed: BalanceOf<T>,
pub hosting_org: <T as Org>::OrgId,
pub bank_operator: Option<<T as Org>::OrgId>,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct RegisteredNewOnChainBankEvent<T: Bank> {
pub seeder: <T as System>::AccountId,
pub new_bank_id: OnChainTreasuryID,
pub seed: BalanceOf<T>,
pub hosting_org: <T as Org>::OrgId,
pub bank_operator: Option<<T as Org>::OrgId>,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct ReserveSpendForBankAccountCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub reason: <T as Org>::IpfsReference,
pub amount: BalanceOf<T>,
pub controller: <T as Org>::OrgId,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct SpendReservedForBankAccountEvent<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub new_reservation_id: T::BankAssociatedId,
pub reason: <T as Org>::IpfsReference,
pub amount: BalanceOf<T>,
pub controller: <T as Org>::OrgId,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct CommitReserveSpendForTransferInsideBankAccountCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
pub reason: <T as Org>::IpfsReference,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct CommitSpendBeforeInternalTransferEvent<T: Bank> {
pub committer: <T as System>::AccountId,
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct UnreserveUncommittedReservationToMakeFreeCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct UnreserveUncommittedReservationToMakeFreeEvent<T: Bank> {
pub qualified_bank_controller: <T as System>::AccountId,
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct UnreserveCommittedReservationToMakeFreeCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct UnreserveCommittedReservationToMakeFreeEvent<T: Bank> {
pub qualified_spend_reservation_controller: <T as System>::AccountId,
pub bank_id: OnChainTreasuryID,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct TransferSpendingPowerForSpendCommitmentCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub reason: <T as Org>::IpfsReference,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
pub committed_controller: <T as Org>::OrgId,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct InternalTransferExecutedAndSpendingPowerDoledOutToControllerEvent<T: Bank> {
pub qualified_spend_reservation_controller: <T as System>::AccountId,
pub bank_id: OnChainTreasuryID,
pub reason: <T as Org>::IpfsReference,
pub reservation_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
pub committed_controller: <T as Org>::OrgId,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct WithdrawByReferencingInternalTransferCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub transfer_id: T::BankAssociatedId,
pub amount: BalanceOf<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct SpendRequestForInternalTransferApprovedAndExecutedEvent<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub requester: <T as System>::AccountId,
pub amount: BalanceOf<T>,
pub transfer_id: T::BankAssociatedId,
}

#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct BurnAllSharesToLeaveWeightedMembershipBankAndWithdrawRelatedFreeCapitalCall<T: Bank> {
pub bank_id: OnChainTreasuryID,
phantom: std::marker::PhantomData<T>,
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct AccountLeftMembershipAndWithdrewProportionOfFreeCapitalInBankEvent<T: Bank> {
pub bank_id: OnChainTreasuryID,
pub leaving_member: <T as System>::AccountId,
pub amount_withdrawn_by_burning_shares: BalanceOf<T>,
}
Loading