From e3665f03703fdfd71b4d5a42dc97a3f000b236d3 Mon Sep 17 00:00:00 2001 From: 8lecramm <89603217+8lecramm@users.noreply.github.com> Date: Thu, 25 May 2023 23:09:36 +0200 Subject: [PATCH 1/2] Wallet token support --- walletapi/wallet.go | 52 ++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/walletapi/wallet.go b/walletapi/wallet.go index d0a52cf5..26362385 100644 --- a/walletapi/wallet.go +++ b/walletapi/wallet.go @@ -16,26 +16,25 @@ package walletapi -import "os" -import "fmt" -import "sort" -import "sync" -import "time" -import "strings" -import "math/big" -import "crypto/rand" - -import "encoding/pem" -import "encoding/binary" - -import "github.com/go-logr/logr" - -import "github.com/deroproject/derohe/rpc" -import "github.com/deroproject/derohe/cryptography/crypto" -import "github.com/deroproject/derohe/cryptography/bn256" - -import "github.com/deroproject/derohe/walletapi/mnemonics" -import "github.com/deroproject/derohe/transaction" +import ( + "crypto/rand" + "encoding/binary" + "encoding/pem" + "fmt" + "math/big" + "os" + "sort" + "strings" + "sync" + "time" + + "github.com/deroproject/derohe/cryptography/bn256" + "github.com/deroproject/derohe/cryptography/crypto" + "github.com/deroproject/derohe/rpc" + "github.com/deroproject/derohe/transaction" + "github.com/deroproject/derohe/walletapi/mnemonics" + "github.com/go-logr/logr" +) //import "github.com/deroproject/derohe/blockchain/inputmaturity" @@ -129,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} From f4cde2e38c56a9c49c251e503770c69b71301e62 Mon Sep 17 00:00:00 2001 From: 8lecramm <89603217+8lecramm@users.noreply.github.com> Date: Thu, 25 May 2023 23:10:19 +0200 Subject: [PATCH 2/2] Wallet token support --- cmd/dero-wallet-cli/prompt.go | 56 ++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/cmd/dero-wallet-cli/prompt.go b/cmd/dero-wallet-cli/prompt.go index 98cf3476..b49b0c85 100644 --- a/cmd/dero-wallet-cli/prompt.go +++ b/cmd/dero-wallet-cli/prompt.go @@ -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 @@ -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") @@ -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"), @@ -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")