Skip to content

Commit

Permalink
Merge branch '8lecramm-wallet-token-support' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDero committed Jun 11, 2023
2 parents d94bf77 + d9c1a22 commit 0951e98
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
56 changes: 38 additions & 18 deletions cmd/dero-wallet-cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@

package main

import "os"
import "io"
import "fmt"
import "bytes"
import "time"
import (
"bytes"
"encoding/hex"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"
"unicode"

"github.com/chzyer/readline"
"github.com/deroproject/derohe/config"
"github.com/deroproject/derohe/cryptography/crypto"
"github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/rpc"
"github.com/deroproject/derohe/walletapi"
)

//import "io/ioutil"
//import "path/filepath"
import "strings"
import "unicode"
import "strconv"
import "encoding/hex"

import "github.com/chzyer/readline"

import "github.com/deroproject/derohe/rpc"
import "github.com/deroproject/derohe/config"
import "github.com/deroproject/derohe/globals"
import "github.com/deroproject/derohe/walletapi"

import "github.com/deroproject/derohe/cryptography/crypto"

var account walletapi.Account

Expand Down Expand Up @@ -118,6 +118,24 @@ func handle_prompt_command(l *readline.Instance, line string) {
break
}

case "token_add":
line_parts := line_parts[1:] // remove first part

switch len(line_parts) {
case 0:
break
case 1:
scid := crypto.HashHexToHash(line_parts[0])
if err := wallet.TokenAdd(scid); err != nil {
logger.Error(err, "Token")
} else {
wallet.Save_Wallet()
fmt.Fprintf(l.Stderr(), "SCID "+color_green+"%s"+color_white+" added\n\n", scid.String())
}
default:
logger.Error(err, "not implemented")
}

case "rescan_bc", "rescan_spent": // rescan from 0
if offline_mode {
logger.Error(err, "Offline wallet rescanning NOT implemented")
Expand Down Expand Up @@ -902,6 +920,7 @@ var completer = readline.NewPrefixCompleter(
readline.PcItem("help"),
readline.PcItem("address"),
readline.PcItem("balance"),
readline.PcItem("token_add"),
readline.PcItem("integrated_address"),
readline.PcItem("get_tx_key"),
readline.PcItem("filesign"),
Expand Down Expand Up @@ -936,6 +955,7 @@ func usage(w io.Writer) {
io.WriteString(w, "\t\033[1mhelp\033[0m\t\tthis help\n")
io.WriteString(w, "\t\033[1maddress\033[0m\t\tDisplay user address\n")
io.WriteString(w, "\t\033[1mbalance\033[0m\t\tDisplay user balance\n")
io.WriteString(w, "\t\033[1mtoken_add\033[0m\t\tAdd token\n")
io.WriteString(w, "\t\033[1mintegrated_address\033[0m\tDisplay random integrated address (with encrypted payment ID)\n")
io.WriteString(w, "\t\033[1mmenu\033[0m\t\tEnable menu mode\n")
io.WriteString(w, "\t\033[1mrescan_bc\033[0m\tRescan blockchain to re-obtain transaction history \n")
Expand Down
13 changes: 13 additions & 0 deletions walletapi/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ func (w *Wallet_Memory) InsertReplace(scid crypto.Hash, e rpc.Entry) {
w.account.EntriesNative[scid] = entries
}

func (w *Wallet_Memory) TokenAdd(scid crypto.Hash) (err error) {
w.Lock()
defer w.Unlock()

if _, ok := w.account.EntriesNative[scid]; !ok {
w.account.EntriesNative[scid] = []rpc.Entry{}
} else {
return fmt.Errorf("token already added")
}

return nil
}

// generate keys from using random numbers
func Generate_Keys_From_Random() (user *Account, err error) {
user = &Account{Ringsize: 16, FeesMultiplier: 2.0}
Expand Down

0 comments on commit 0951e98

Please sign in to comment.