This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from sunshine-protocol/clight-light-work
slight client light work
- Loading branch information
Showing
21 changed files
with
1,264 additions
and
1,069 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ cache/ | |
Cargo.lock | ||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
client/tmp/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
Oops, something went wrong.