Skip to content

Commit

Permalink
Merge pull request #81 from XDagger/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
swordlet authored Sep 7, 2024
2 parents 85925e1 + ab31258 commit 85edc47
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 35 deletions.
3 changes: 2 additions & 1 deletion wallet/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"goXdagWallet/xlog"
"os"
"path"
"path/filepath"

"github.com/manifoldco/promptui"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func selectWallet() {
}
func registerWallet() {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
fmt.Println("Registering wallet....")
prompt := promptui.Select{
Label: "Select Wallet Type",
Expand Down
2 changes: 1 addition & 1 deletion wallet/components/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func getUrl(apiUrl, address, query string, page int, body *[]byte) error {
req.Header.Set("User-Agent", "Apache-HttpClient/4.3.1")

client := &http.Client{
Timeout: 8 * time.Minute,
Timeout: 18 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions wallet/components/logon_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"io"
"os"
"path"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -147,7 +148,7 @@ func (l *LogonWin) connectClick() {
return
}
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
accountStatus := l.WalletType
if l.HasAccount {
if accountStatus == HAS_BOTH {
Expand Down Expand Up @@ -321,7 +322,7 @@ func CheckOldWallet(walletDir string) bool {

func CopyOldWallet(walletDir string) error {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
pathDest := path.Join(pwd, "xdagj_dat")
if err := os.RemoveAll(pathDest); err != nil {
return err
Expand All @@ -346,7 +347,7 @@ func CopyOldWallet(walletDir string) error {

func (l *LogonWin) ImportMnemonic(data []byte) error {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
pathDest := path.Join(pwd, common.BIP32_WALLET_FOLDER)
if err := os.RemoveAll(pathDest); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion wallet/components/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TransferRpc(from, to, amount, remark string, key *secp256k1.PrivateKey) (st

value, _ := strconv.ParseFloat(amount, 64)
blockHexStr := transactionBlock(from, to, remark, value, key)
//xlog.Info(blockHexStr)
xlog.Debug(blockHexStr)
if blockHexStr == "" {
return "", errors.New("create transaction block error")
}
Expand Down Expand Up @@ -106,6 +106,7 @@ func transactionBlock(from, to, remark string, value float64, key *secp256k1.Pri

inAddress, err = checkBase58Address(from)
isFromOld := err != nil
xlog.Debug("is old address", isFromOld)

if isFromOld { // old xdag address
hash, err := xdagoUtils.Address2Hash(from)
Expand Down
9 changes: 5 additions & 4 deletions wallet/components/wallet_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"goXdagWallet/xlog"
"os"
"path"
"path/filepath"
"time"

"fyne.io/fyne/v2"
Expand All @@ -28,7 +29,7 @@ func Xdag_Wallet_fount() int {
hasXdagWallet := 0
hasBip32Wallet := 0
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
pathName := path.Join(pwd, "xdagj_dat", "dnet_key.dat")
// change current working directory
os.Chdir(pwd)
Expand Down Expand Up @@ -64,7 +65,7 @@ func ConnectBipWallet(password string) bool {
xlog.Info("Initializing cryptography...")
xlog.Info("Reading wallet...")
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
wallet := bip.NewWallet(path.Join(pwd, common.BIP32_WALLET_FOLDER, common.BIP32_WALLET_FILE_NAME))
res := wallet.UnlockWallet(password)
if wallet.IsHdWalletInitialized() {
Expand All @@ -79,7 +80,7 @@ func ConnectBipWallet(password string) bool {
}
func NewBipWallet(password string, bitSize int) (*bip.Wallet, bool) {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
if len(LogonWindow.MnemonicBytes) > 0 {
xlog.Info("import Mnemonic...")
fmt.Println("Importing Mnemonic...")
Expand Down Expand Up @@ -113,7 +114,7 @@ func ValidateBipAddress(address string) bool {
}

func ValidateRemark(remark string) bool {
return utf8string.NewString(remark).IsASCII() && len(remark) < 32
return utf8string.NewString(remark).IsASCII() && len(remark) <= 32
}

func NewWalletWindow(walletExists int) {
Expand Down
3 changes: 2 additions & 1 deletion wallet/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path"
"path/filepath"
)

const configFile = "wallet-config.json"
Expand Down Expand Up @@ -45,7 +46,7 @@ func InitConfig() {
conf.Option.PoolAddress = "xdag.org:13656"

pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)
data, err := os.ReadFile(path.Join(pwd, configFile))
if err == nil {
err = json.Unmarshal(data, &conf)
Expand Down
3 changes: 2 additions & 1 deletion wallet/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"goXdagWallet/config"
"os"
"path"
"path/filepath"
)

var i18n = make(map[string]string)

func stringRead(res string) []byte {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)

bytes, err := os.ReadFile(path.Join(pwd, "data", res))
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net"
"os"
"path"
"path/filepath"
"strconv"

"fyne.io/fyne/v2"
Expand All @@ -23,7 +24,7 @@ var splashDone = make(chan struct{})

func init() {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)

os.Setenv("FYNE_FONT", path.Join(pwd, "data", "myFont.ttf"))

Expand Down
3 changes: 2 additions & 1 deletion wallet/server/import_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
bip "goXdagWallet/xdago/wallet"
"os"
"path"
"path/filepath"
)

func ImportServWallet() error {
pwd, _ := os.Executable()
pwd, _ = path.Split(pwd)
pwd = filepath.Dir(pwd)

filePath := cli.InputFilePath()
cli.WalletAccount.Password = cli.ShowPassword()
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pool_address": "https://mainnet-rpc.xdagj.org",
"testnet_api_url": ""
},
"version": "0.6.6",
"version": "0.6.7",
"culture_info": "en-US",
"addresses": [],
"query": {
Expand Down
34 changes: 17 additions & 17 deletions wallet/xdago/cryptography/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import (

func EcdsaSign(key *secp256k1.PrivateKey, hash []byte) (r, s common.Field) {
signature := ecdsa.Sign(key, hash)
serial := signature.Serialize()
rLen := int(serial[3])
serial = serial[4:]
if rLen >= common.XDAG_FIELD_SIZE {
copy(r[:], serial[rLen-common.XDAG_FIELD_SIZE:rLen])
} else {
copy(r[:rLen], serial[:rLen])
}
// serial := signature.Serialize()
// rLen := int(serial[3])
// serial = serial[4:]
// if rLen >= common.XDAG_FIELD_SIZE {
// copy(r[:], serial[rLen-common.XDAG_FIELD_SIZE:rLen])
// } else {
// copy(r[:rLen], serial[:rLen])
// }

sLen := int(serial[rLen+1])
serial = serial[rLen+2:]
if sLen >= common.XDAG_FIELD_SIZE {
copy(s[:], serial[sLen-common.XDAG_FIELD_SIZE:sLen])
} else {
copy(s[:sLen], serial[:sLen])
}
xlog.Debug("Sign")
return
// sLen := int(serial[rLen+1])
// serial = serial[rLen+2:]
// if sLen >= common.XDAG_FIELD_SIZE {
// copy(s[:], serial[sLen-common.XDAG_FIELD_SIZE:sLen])
// } else {
// copy(s[:sLen], serial[:sLen])
// }
// xlog.Debug("Sign")
return signature.Bytes()
}

func EcdsaVerify(key *secp256k1.PublicKey, hash, r, s []byte) bool {
Expand Down
4 changes: 4 additions & 0 deletions wallet/xdago/secp256k1/ecdsa/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,3 +923,7 @@ func RecoverCompact(signature, hash []byte) (*secp256k1.PublicKey, bool, error)
pubKey := secp256k1.NewPublicKey(&Q.X, &Q.Y)
return pubKey, wasCompressed, nil
}

func (sig *Signature) Bytes() ([32]byte, [32]byte) {
return sig.r.Bytes(), sig.s.Bytes()
}
6 changes: 3 additions & 3 deletions wallet/xdago/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (w *Wallet) readHdSeed(key []byte, r *utils.SimpleReader) bool {
xlog.Error("parse wallet mnemonic failed, bytes length error")
return false
}
w.mnemonicPhrase = string(r2.ReadCString(int(size)))
w.mnemonicPhrase = strings.TrimSpace(string(r2.ReadCString(int(size))))
r2.ReadInt(binary.BigEndian, &w.nextAccountIndex)
if r2.Error() != nil {
xlog.Error("parse wallet mnemonic failed," + r2.Error().Error())
Expand Down Expand Up @@ -426,7 +426,7 @@ func (w *Wallet) IsHdWalletInitialized() bool {
func (w *Wallet) InitializeHdWallet(mnemonic string) {
w.Lock()
defer w.Unlock()
w.mnemonicPhrase = mnemonic
w.mnemonicPhrase = strings.TrimSpace(mnemonic)
w.nextAccountIndex = 0
}

Expand Down Expand Up @@ -499,7 +499,7 @@ func (w *Wallet) ExportMnemonic(path string) error {
if w.mnemonicPhrase == "" {
return errors.New("no mnemonic to export")
}
return fileutils.WriteFile(path, []byte(w.mnemonicPhrase))
return fileutils.WriteFile(path, []byte(strings.TrimSpace(w.mnemonicPhrase)))
}

func ImportWalletFromDefKey(pathSrc, dirDest, pwd string) (*Wallet, error) {
Expand Down

0 comments on commit 85edc47

Please sign in to comment.