-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
510 additions
and
118 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
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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
|
||
|
||
|
||
use sube::{ builder::SubeBuilder as Sube }; | ||
use async_trait::async_trait; | ||
use core::future::{Future, IntoFuture}; | ||
use sube::{ Response, sube, Result }; | ||
|
||
#[async_std::main] | ||
async fn main () { | ||
let a = Sube("wss://rpc.polkadot.io").await?; | ||
async fn main() -> Result<()> { | ||
|
||
let result = sube!("https://kusama.olanod.com/system/_constants/version").await?; | ||
|
||
println!("{:?}", result); | ||
Ok(()) | ||
} |
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,13 @@ | ||
use async_trait::async_trait; | ||
|
||
use sube::{ Response, sube, Result, builder::QueryBuilder, SignerFn, ExtrinicBody }; | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<()> { | ||
let builder = QueryBuilder::default() | ||
.with_url("https://kusama.olanod.com/system/_constants/version") | ||
.await?; | ||
|
||
println!("{:?}", builder); | ||
Ok(()) | ||
} |
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,47 @@ | ||
use futures_util::TryFutureExt; | ||
use serde_json::json; | ||
use libwallet::{self, vault}; | ||
use sube::sube; | ||
use std::env; | ||
use rand_core::OsRng; | ||
|
||
type Wallet = libwallet::Wallet<vault::Simple>; | ||
|
||
use anyhow::{ Result, anyhow }; | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let phrase = env::args().skip(1).collect::<Vec<_>>().join(" "); | ||
|
||
let (vault, phrase) = if phrase.is_empty() { | ||
vault::Simple::generate_with_phrase(&mut rand_core::OsRng) | ||
} else { | ||
let phrase: libwallet::Mnemonic = phrase.parse().expect("Invalid phrase"); | ||
(vault::Simple::from_phrase(&phrase), phrase) | ||
}; | ||
|
||
let mut wallet = Wallet::new(vault); | ||
wallet.unlock(None).await?; | ||
|
||
let account = wallet.default_account(); | ||
let public = account.public(); | ||
|
||
let response = sube!("https://kusama.olanod.com/balances/transfer" => { | ||
signer: |message: &[u8]| Ok(wallet.sign(message).into()), | ||
sender: public.as_ref(), | ||
body: json!({ | ||
"dest": { | ||
"Id": public.as_ref() | ||
}, | ||
"value": 100000 | ||
}), | ||
}) | ||
.map_err(|err| anyhow!(format!("SubeError {:?}", err))) | ||
.await?; | ||
|
||
|
||
println!("Secret phrase: \"{phrase}\""); | ||
println!("Default Account: 0x{account}"); | ||
|
||
Ok(()) | ||
} |
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,49 @@ | ||
use jsonrpc::error; | ||
use serde_json::json; | ||
use libwallet::{self, vault}; | ||
use sube::builder::TxBuilder; | ||
use std::env; | ||
use rand_core::OsRng; | ||
|
||
type Wallet = libwallet::Wallet<vault::Simple>; | ||
use anyhow::{ Result, anyhow }; | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<()> { | ||
let phrase = env::args().skip(1).collect::<Vec<_>>().join(" "); | ||
|
||
let (vault, phrase) = if phrase.is_empty() { | ||
vault::Simple::generate_with_phrase(&mut rand_core::OsRng) | ||
} else { | ||
let phrase: libwallet::Mnemonic = phrase.parse().expect("Invalid phrase"); | ||
(vault::Simple::from_phrase(&phrase), phrase) | ||
}; | ||
|
||
let mut wallet = Wallet::new(vault); | ||
|
||
wallet.unlock(None).await?; | ||
|
||
let account = wallet.default_account(); | ||
|
||
let response = TxBuilder::default() | ||
.with_url("https://kusama.olanod.com/balances/transfer") | ||
.with_signer(|message: &[u8]| { | ||
let signature = wallet.sign(message); | ||
let signature: [u8; 64] = signature.as_ref()[..].try_into().expect("isn't a 64 size slice"); | ||
Ok(signature) | ||
} | ||
) | ||
.with_sender(wallet.default_account().public().as_ref()) | ||
.with_body(json!({ | ||
"dest": { | ||
"Id": wallet.default_account().public().as_ref() | ||
}, | ||
"value": 100000 | ||
})) | ||
.await | ||
.map_err(|err| { | ||
anyhow!(format!("Error {:?}", err)) | ||
})?; | ||
|
||
Ok(()) | ||
} |
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,47 @@ | ||
use futures_util::TryFutureExt; | ||
use serde_json::json; | ||
use libwallet::{self, vault}; | ||
use sube::{ sube }; | ||
use std::env; | ||
use rand_core::OsRng; | ||
|
||
type Wallet = libwallet::Wallet<vault::Simple>; | ||
|
||
use anyhow::{ Result, anyhow }; | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let phrase = env::args().skip(1).collect::<Vec<_>>().join(" "); | ||
|
||
let (vault, phrase) = if phrase.is_empty() { | ||
vault::Simple::generate_with_phrase(&mut rand_core::OsRng) | ||
} else { | ||
let phrase: libwallet::Mnemonic = phrase.parse().expect("Invalid phrase"); | ||
(vault::Simple::from_phrase(&phrase), phrase) | ||
}; | ||
|
||
let mut wallet = Wallet::new(vault); | ||
wallet.unlock(None).await?; | ||
|
||
let account = wallet.default_account(); | ||
let public = account.public(); | ||
|
||
|
||
let response = sube!( | ||
"https://kusama.olanod.com/balances/transfer" => | ||
(wallet, json!({ | ||
"dest": { | ||
"Id": public.as_ref(), | ||
}, | ||
"value": 100000 | ||
})) | ||
) | ||
.map_err(|err| anyhow!(format!("SubeError {:?}", err))) | ||
.await?; | ||
|
||
|
||
println!("Secret phrase: \"{phrase}\""); | ||
// println!("Default Account: 0x{account}"); | ||
|
||
Ok(()) | ||
} |
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,72 @@ | ||
#![feature(prelude_import)] | ||
#[prelude_import] | ||
use std::prelude::rust_2021::*; | ||
#[macro_use] | ||
extern crate std; | ||
use futures_util::TryFutureExt; | ||
use serde_json::json; | ||
use libwallet::{self, vault}; | ||
use sube::sube; | ||
use std::env; | ||
use rand_core::OsRng; | ||
type Wallet = libwallet::Wallet<vault::Simple>; | ||
use anyhow::{Result, anyhow}; | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
{ | ||
let phrase = env::args().skip(1).collect::<Vec<_>>().join(" "); | ||
let (vault, phrase) = if phrase.is_empty() { | ||
vault::Simple::generate_with_phrase(&mut rand_core::OsRng) | ||
} else { | ||
let phrase: libwallet::Mnemonic = phrase | ||
.parse() | ||
.expect("Invalid phrase"); | ||
(vault::Simple::from_phrase(&phrase), phrase) | ||
}; | ||
let mut wallet = Wallet::new(vault); | ||
wallet.unlock(None).await?; | ||
let account = wallet.default_account().public(); | ||
let public = account.as_ref(); | ||
|
||
let response = async { | ||
let mut builder = ::sube::builder::TxBuilder::default(); | ||
// let account = &wallet.default_account(); | ||
// let public = account.public(); | ||
|
||
builder | ||
.with_signer(|message: &[u8]| Ok(wallet.sign(message).into())) | ||
.with_sender(public.into()) | ||
.with_body( | ||
::serde_json::Value::Object({ | ||
let mut object = ::serde_json::Map::new(); | ||
let _ = object | ||
.insert( | ||
("dest").into(), | ||
::serde_json::Value::Object({ | ||
let mut object = ::serde_json::Map::new(); | ||
let _ = object | ||
.insert( | ||
("Id").into(), | ||
::serde_json::to_value(&public.as_ref()).unwrap(), | ||
); | ||
object | ||
}), | ||
); | ||
let _ = object | ||
.insert( | ||
("value").into(), | ||
::serde_json::to_value(&100000).unwrap(), | ||
); | ||
object | ||
}), | ||
) | ||
.await | ||
} | ||
.map_err(|err| anyhow!(format!("SubeError {:?}", err))) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
async_std::task::block_on(async { main().await }) | ||
} |
Oops, something went wrong.