Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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.amount, event.org,
// );

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
27 changes: 27 additions & 0 deletions client/src/srml/bank.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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::{organization::Organization, share::ShareProfile};
use crate::srml::org::Org;

/// The subset of the bank trait and its inherited traits that the client must inherit
#[module]
pub trait Bank: System + Org {
/// Cid type
type IpfsReference: Parameter + Member + Default;

/// Identifier for bank-related maps
type BankAssociatedId: Parameter
+ Member
+ AtLeast32Bit
+ Codec
+ Default
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ PartialOrd
+ PartialEq
+ Zero;
}
2 changes: 1 addition & 1 deletion client/src/srml/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod org;
//pub mod vote;
pub mod vote;
Loading