Bladeren bron

drk/swap: support aliases, doc/testnet: update payment and atomic swap with aliases

aggstam 3 jaren geleden
bovenliggende
commit
99bbe777b9
4 gewijzigde bestanden met toevoegingen van 16 en 12 verwijderingen
  1. 9 3
      bin/drk/src/cli_util.rs
  2. 1 1
      bin/drk/src/main.rs
  3. 4 6
      doc/src/testnet/atomic-swap.md
  4. 2 2
      doc/src/testnet/payment.md

+ 9 - 3
bin/drk/src/cli_util.rs

@@ -21,6 +21,8 @@ use async_std::{fs::File, io::WriteExt};
 use darkfi::{util::parse::decode_base10, Result};
 use darkfi_sdk::crypto::TokenId;
 
+use crate::Drk;
+
 pub fn parse_value_pair(s: &str) -> Result<(u64, u64)> {
     let v: Vec<&str> = s.split(':').collect();
     if v.len() != 2 {
@@ -40,19 +42,23 @@ pub fn parse_value_pair(s: &str) -> Result<(u64, u64)> {
     Ok((val0.unwrap(), val1.unwrap()))
 }
 
-pub fn parse_token_pair(s: &str) -> Result<(TokenId, TokenId)> {
+pub async fn parse_token_pair(drk: &Drk, s: &str) -> Result<(TokenId, TokenId)> {
     let v: Vec<&str> = s.split(':').collect();
     if v.len() != 2 {
         eprintln!("Invalid token pair. Use a pair such as:");
+        eprintln!("WCKD:MLDY");
+        eprintln!("or");
         eprintln!("A7f1RKsCUUHrSXA7a9ogmwg8p3bs6F47ggsW826HD4yd:FCuoMii64H5Ee4eVWBjP18WTFS8iLUJmGi16Qti1xFQ2");
         exit(1);
     }
 
-    let tok0 = TokenId::try_from(v[0]);
-    let tok1 = TokenId::try_from(v[1]);
+    let tok0 = drk.get_token(v[0].to_string()).await;
+    let tok1 = drk.get_token(v[1].to_string()).await;
 
     if tok0.is_err() || tok1.is_err() {
         eprintln!("Invalid token pair. Use a pair such as:");
+        eprintln!("WCKD:MLDY");
+        eprintln!("or");
         eprintln!("A7f1RKsCUUHrSXA7a9ogmwg8p3bs6F47ggsW826HD4yd:FCuoMii64H5Ee4eVWBjP18WTFS8iLUJmGi16Qti1xFQ2");
         exit(1);
     }

+ 1 - 1
bin/drk/src/main.rs

@@ -728,7 +728,7 @@ async fn main() -> Result<()> {
             match cmd {
                 OtcSubcmd::Init { value_pair, token_pair } => {
                     let (vp_send, vp_recv) = parse_value_pair(&value_pair)?;
-                    let (tp_send, tp_recv) = parse_token_pair(&token_pair)?;
+                    let (tp_send, tp_recv) = parse_token_pair(&drk, &token_pair).await?;
 
                     let half = drk
                         .init_swap(vp_send, tp_send, vp_recv, tp_recv)

+ 4 - 6
doc/src/testnet/atomic-swap.md

@@ -3,9 +3,9 @@
 In order to do an atomic swap with someone, you will
 first have to come to consensus on what tokens you wish to
 swap. For example purposes, let's say you want to swap `40`
-`DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq` (which is the balance
-you should have left over after doing the above payment) for your
-counterparty's `20` `AcABG4fnmBuT5vuXV8TLdEV8panhk5SdtBZxCCLqQxyL`.
+`WCKD` (which is the balance you should have left over after
+doing the above payment) for your counterparty's `20` `MLDY`.
+For this tautorial the counterparty is yourself.
 
 To protect your anonymity from the counterparty, the swap can only
 send entire coins. To create a smaller coin denomination, send
@@ -19,9 +19,7 @@ $ ./drk wallet --coins
 You'll have to initiate the swap and build your half of the swap tx:
 
 ```
-$ ./drk otc init -v 40.0:20.0 \
-    -t DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq:AcABG4fnmBuT5vuXV8TLdEV8panhk5SdtBZxCCLqQxyL \
-    > half_swap
+$ ./drk otc init -v 40.0:20.0 -t WCKD:MLDY > half_swap
 ```
 
 Then you can send this `half_swap` file to your counterparty and they

+ 2 - 2
doc/src/testnet/payment.md

@@ -1,11 +1,11 @@
 # Payments
 
 Using the tokens we minted, we can make payments to other addresses.
-Let's try to send some `DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq`
+Let's try to send some `WCKD`
 tokens to `8sRwB7AwBTKEkyTW6oMyRoJWZhJwtqGTf7nyHwuJ74pj`:
 
 ```
-$ ./drk transfer 2.69 DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq \
+$ ./drk transfer 2.69 WCKD \
     8sRwB7AwBTKEkyTW6oMyRoJWZhJwtqGTf7nyHwuJ74pj > payment_tx
 ```