gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: implement manual withdrawal


From: gnunet
Subject: [taler-wallet-core] branch master updated: implement manual withdrawal
Date: Sun, 21 Jun 2020 14:49:35 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 39035139 implement manual withdrawal
39035139 is described below

commit 39035139130925bf596175ad8a3419a4cea401a8
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Sun Jun 21 18:19:27 2020 +0530

    implement manual withdrawal
---
 src/headless/taler-wallet-cli.ts | 37 +++++++++++++++++++++++++++++++++++++
 src/util/payto.ts                | 19 ++++++++++++++++---
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index b45b0eae..839ee999 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -34,6 +34,7 @@ import { setDangerousTimetravel } from "../util/time";
 import { makeCodecForList, codecForString } from "../util/codec";
 import { NodeHttpLib } from "./NodeHttpLib";
 import * as nacl from "../crypto/primitives/nacl-fast";
+import { addPaytoQueryParams } from "../util/payto";
 
 const logger = new Logger("taler-wallet-cli.ts");
 
@@ -367,6 +368,42 @@ advancedCli
     fs.writeFileSync(1, decodeCrock(enc.trim()));
   });
 
+
+advancedCli
+.subcommand("withdrawManually", "withdraw-manually", {
+  help: "Withdraw manually from an exchange.",
+})
+.requiredOption("exchange", ["--exchange"], clk.STRING, {
+  help: "Base URL of the exchange.",
+})
+.requiredOption("amount", ["--amount"], clk.STRING, {
+  help: "Amount to withdraw",
+})
+.action(async (args) => {
+  await withWallet(args, async (wallet) => {
+    const exchange = await 
wallet.updateExchangeFromUrl(args.withdrawManually.exchange);
+    const acct = exchange.wireInfo?.accounts[0];
+    if (!acct) {
+      console.log("exchange has no accounts");
+      return;
+    }
+    const reserve = await wallet.createReserve({
+      amount: Amounts.parseOrThrow(args.withdrawManually.amount),
+      exchangeWire: acct.payto_uri,
+      exchange: exchange.baseUrl,
+    });
+    await wallet.confirmReserve({
+      reservePub: reserve.reservePub,
+    });
+    const completePaytoUri = addPaytoQueryParams(acct.payto_uri, {
+      amount: args.withdrawManually.amount,
+      message: `Taler top-up ${reserve.reservePub}`,
+    });
+    console.log("Created reserve", reserve.reservePub);
+    console.log("Payto URI", completePaytoUri);
+  });
+});
+
 const reservesCli = advancedCli.subcommand("reserves", "reserves", {
   help: "Manage reserves.",
 });
diff --git a/src/util/payto.ts b/src/util/payto.ts
index ac5bc0c7..0f624de6 100644
--- a/src/util/payto.ts
+++ b/src/util/payto.ts
@@ -20,13 +20,26 @@ interface PaytoUri {
   params: { [name: string]: string };
 }
 
+const paytoPfx = "payto://";
+
+/**
+ * Add query parameters to a payto URI
+ */
+export function addPaytoQueryParams(s: string, params: { [name: string]: 
string }): string {
+  const [acct, search] = s.slice(paytoPfx.length).split("?");
+  const searchParams = new URLSearchParams(search || "");
+  for (let k of Object.keys(params)) {
+    searchParams.set(k, params[k]);
+  }
+  return paytoPfx + acct + "?" + searchParams.toString();
+}
+
 export function parsePaytoUri(s: string): PaytoUri | undefined {
-  const pfx = "payto://";
-  if (!s.startsWith(pfx)) {
+  if (!s.startsWith(paytoPfx)) {
     return undefined;
   }
 
-  const [acct, search] = s.slice(pfx.length).split("?");
+  const [acct, search] = s.slice(paytoPfx.length).split("?");
 
   const firstSlashPos = acct.indexOf("/");
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]