Skip to content

Commit

Permalink
wip: generate wallet from keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Jun 28, 2024
1 parent 39323cf commit 0d6658e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 53 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

- uses: actions/upload-artifact@v4
with:
name: goldboot-${{ matrix.target }}
name: turbine-${{ matrix.target }}
path: target/${{ matrix.target }}/release/turbine

- name: Upload artifacts to release
Expand All @@ -58,8 +58,8 @@ jobs:
GH_REPO: ${{ github.repository }}
run: |
for tag in $(git tag --points-at HEAD); do
if cp target/${{ matrix.target }}/release/${tag%-*} ${tag%-*}_${{ matrix.target }}; then
gh release upload "${tag}" "${tag%-*}_${{ matrix.target }}"
if cp target/${{ matrix.target }}/release/turbine turbine_${{ matrix.target }}; then
gh release upload "${tag##*-}" "turbine_${{ matrix.target }}"
fi
done
Expand Down Expand Up @@ -94,14 +94,14 @@ jobs:
id: get_tags
run: |
for tag in $(git tag --points-at HEAD); do
echo "${tag%-*}=${tag##*-}" >>"$GITHUB_OUTPUT"
echo "turbine=${tag##*-}" >>"$GITHUB_OUTPUT"
done
- uses: docker/build-push-action@v5
if: ${{ steps.get_tags.outputs.goldboot != '' }}
if: ${{ steps.get_tags.outputs.turbine != '' }}
with:
context: .
platforms: linux/amd64,linux/arm64 #,linux/arm/v7
platforms: linux/amd64 #,linux/arm64,linux/arm/v7
push: true
tags: fossable/turbine:latest,fossable/turbine:${{ steps.get_tags.outputs.turbine }}

Expand Down
29 changes: 23 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ git2 = "0.18.1"
hex = "0.4.3"
mime_guess = "2.0.4"
monero = "0.21.0"
monero-rpc = { git = "https://github.com/cilki/monero-rpc-rs", branch = "add_restore_deterministic_wallet", features = ["rpc_authentication"], optional = true }
monero-rpc = { version = "0.4.0", features = ["rpc_authentication"], optional = true }
reqwest = { version = "0.12.4", features = ["json"] }
rust-embed = { version = "8.4.0", features = ["axum", "debug-embed"] }
serde = { version = "1.0.203", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub async fn refresh(State(state): State<AppState>) {
.monero
.transfer(
&address,
monero::Amount::from_pico(
monero_rpc::monero::Amount::from_pico(
contributor.compute_payout(commit_id.clone()),
),
commit_id,
Expand Down
17 changes: 10 additions & 7 deletions src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub fn generate(title: &str, value: &str) -> String {
r###"
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="balance: 20.0 XMR">
<title>balance: 20.0 XMR</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="{0}: {1}">
<title>{0}: {1}</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
Expand All @@ -19,13 +19,16 @@ pub fn generate(title: &str, value: &str) -> String {
<rect width="116" height="20" fill="url(#s)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="275" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">balance</text>
<text x="275" y="140" transform="scale(.1)" fill="#fff" textLength="430">{}</text>
<text aria-hidden="true" x="835" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">20.0 XMR</text>
<text x="835" y="140" transform="scale(.1)" fill="#fff" textLength="530">{}</text>
<text aria-hidden="true" x="275" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">{0}</text>
<text x="275" y="140" transform="scale(.1)" fill="#fff" textLength="430">{0}</text>
<text aria-hidden="true" x="835" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">{1}</text>
<text x="835" y="140" transform="scale(.1)" fill="#fff" textLength="530">{1}</text>
</g>
</svg>
"###,
title, value,
title,
value,
// title.len() * 10,
// value.len() * 10,
)
}
23 changes: 6 additions & 17 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,9 @@ pub struct ServeArgs {
pub monero_wallet_password: String,

#[cfg(feature = "monero")]
#[clap(long, conflicts_with = "monero_wallet_seed")]
#[clap(long)]
pub monero_wallet_path: Option<String>,

/// Restore wallet from a mnemonic seed phrase given by the environment variable:
/// MONERO_WALLET_SEED.
#[cfg(feature = "monero")]
#[clap(
long,
num_args = 0,
conflicts_with = "monero_wallet_path",
default_value_t = false
)]
pub monero_wallet_seed: bool,

#[cfg(feature = "monero")]
#[clap(long, default_value = "stagenet.xmr-tw.org:38081")]
pub monero_daemon_address: String,
Expand Down Expand Up @@ -95,23 +84,23 @@ pub async fn serve(args: &ServeArgs) -> Result<ExitCode> {
#[cfg(feature = "monero")]
let app = app.route("/xmr/payouts", get(crate::currency::monero::payouts));

let address = args.bind.clone().unwrap_or("0.0.0.0:80".to_string());

// Refresh every hour
let every_hour = every(1)
.hour()
.at(10, 30)
.in_timezone(&Utc)
.perform(|| async {
.perform(|| async move {
reqwest::Client::new()
.post("http://127.0.0.1:3000/refresh")
.post(format!("http://127.0.0.1:{}/refresh", 80)) // TODO
.send()
.await
.unwrap();
});
tokio::spawn(every_hour);

let address = args.bind.clone().unwrap_or("0.0.0.0:3000".to_string());

info!(address =?address,"Starting API");
info!(address = ?address,"Starting API");
let listener = TcpListener::bind(address).await?;
axum::serve(listener, app.with_state(state)).await?;
Ok(ExitCode::SUCCESS)
Expand Down
44 changes: 29 additions & 15 deletions src/currency/monero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use axum::response::IntoResponse;
use float_pretty_print::PrettyPrintFloat;
use git2::Oid;
use monero_rpc::{
monero::{Address, Amount},
BlockHeightFilter, GetTransfersCategory, GetTransfersSelector, GotTransfer,
RestoreDeterministicWalletArgs, RpcClientBuilder, TransferOptions, TransferPriority,
WalletClient,
monero::{Address, Amount, PrivateKey},
BlockHeightFilter, GenerateFromKeysArgs, GetTransfersCategory, GetTransfersSelector,
GotTransfer, RpcClientBuilder, TransferOptions, TransferPriority, WalletClient,
};
use reqwest::header;
use std::{
Expand Down Expand Up @@ -82,22 +81,37 @@ impl MoneroState {
.build(format!("http://127.0.0.1:{}", args.monero_rpc_port))?
.wallet();

if args.monero_wallet_seed {
if let Some(path) = args.monero_wallet_path.as_ref() {
wallet
.open_wallet(path.to_owned(), Some(args.monero_wallet_password.clone()))
.await?;
} else if let Ok(_seed) = std::env::var("MONERO_WALLET_SEED") {
debug!("Restoring wallet from mnemonic seed phrase");
todo!();
// wallet
// .restore_deterministic_wallet(RestoreDeterministicWalletArgs {
// autosave_current: None,
// filename: "turbine".into(),
// password: args.monero_wallet_password.clone(),
// restore_height: Some(args.monero_block_height),
// seed,
// seed_offset: None,
// })
// .await?;
} else {
wallet
.restore_deterministic_wallet(RestoreDeterministicWalletArgs {
autosave_current: None,
.generate_from_keys(GenerateFromKeysArgs {
restore_height: Some(args.monero_block_height),
filename: "turbine".into(),
address: Address::from_str(&std::env::var("MONERO_WALLET_ADDRESS")?)?,
spendkey: Some(PrivateKey::from_str(&std::env::var(
"MONERO_WALLET_SPENDKEY",
)?)?),
viewkey: PrivateKey::from_str(&std::env::var("MONERO_WALLET_VIEWKEY")?)?,
password: args.monero_wallet_password.clone(),
restore_height: Some(args.monero_block_height),
seed: std::env::var("MONERO_WALLET_SEED")?,
seed_offset: None,
autosave_current: None,
})
.await?;
} else if let Some(path) = args.monero_wallet_path.as_ref() {
wallet
.open_wallet(path.to_owned(), Some(args.monero_wallet_password.clone()))
.await?;
}

info!(
Expand Down Expand Up @@ -208,7 +222,7 @@ pub async fn payouts(State(state): State<AppState>) -> impl IntoResponse {
[(header::CONTENT_TYPE, "image/svg+xml")],
crate::badge::generate(
"payouts",
&format!("{}", state.monero.get_transfers().await.unwrap().len()),
&format!("{:.1}", state.monero.get_transfers().await.unwrap().len()),
),
)
}

0 comments on commit 0d6658e

Please sign in to comment.