From b6958aa091f282f61ce4e9b210aa316976f0985f Mon Sep 17 00:00:00 2001 From: chance Date: Mon, 29 Mar 2021 19:04:30 +0800 Subject: [PATCH 01/26] update workflows --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 26c52a8..33cf033 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: echo "OPENWCLIBINARY=openw-cli-$(git describe --tags `git rev-list --tags --max-count=1`)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "OPENWCLILDFLAGS=-X github.com/blocktree/go-openw-cli/v2/openwcli.Version=$(git describe --tags `git rev-list --tags --max-count=1`) -X github.com/blocktree/go-openw-cli/v2/openwcli.GitRev=$(git rev-parse --short HEAD) -X github.com/blocktree/go-openw-cli/v2/openwcli.BuildTime=$(date +'%Y-%m-%d_%T')" >> $GITHUB_ENV - name: Build with xgo - uses: crazy-max/ghaction-xgo@v1.0.0 + uses: crazy-max/ghaction-xgo@v0.5.0 with: go_version: 1.13.3 dest: build/ From 27a460b64593b2ebafde855fa63eb6ba2dc8a7e2 Mon Sep 17 00:00:00 2001 From: Chance Date: Mon, 29 Mar 2021 19:24:02 +0800 Subject: [PATCH 02/26] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 33cf033..dd0ac2a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: echo "OPENWCLIBINARY=openw-cli-$(git describe --tags `git rev-list --tags --max-count=1`)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "OPENWCLILDFLAGS=-X github.com/blocktree/go-openw-cli/v2/openwcli.Version=$(git describe --tags `git rev-list --tags --max-count=1`) -X github.com/blocktree/go-openw-cli/v2/openwcli.GitRev=$(git rev-parse --short HEAD) -X github.com/blocktree/go-openw-cli/v2/openwcli.BuildTime=$(date +'%Y-%m-%d_%T')" >> $GITHUB_ENV - name: Build with xgo - uses: crazy-max/ghaction-xgo@v0.5.0 + uses: crazy-max/ghaction-xgo@v1.6.1 with: go_version: 1.13.3 dest: build/ From de7de62bc0447d949beb93007c6d7df09ac2a7bd Mon Sep 17 00:00:00 2001 From: YINGHAO FAN Date: Mon, 29 Mar 2021 19:50:36 +0800 Subject: [PATCH 03/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a8cce23..a28ff1d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # openw-cli -[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) +[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![CI](https://github.com/blocktree/go-openw-cli/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/blocktree/go-openw-cli/actions/workflows/main.yml) ## 概述 @@ -368,4 +368,4 @@ $ ./openw-cli -c=./node.ini trustserver -``` \ No newline at end of file +``` From 6b63233e61bd5dc8ab4ef0f0d48d287cc80a042e Mon Sep 17 00:00:00 2001 From: ldx Date: Fri, 7 May 2021 17:59:16 +0800 Subject: [PATCH 04/26] add bls --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 2fcc018..b2aa10e 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.1.5 - github.com/blocktree/go-owcrypt v1.1.4 + github.com/blocktree/go-openw-sdk/v2 v2.1.6 + github.com/blocktree/go-owcrypt v1.1.7 github.com/blocktree/openwallet/v2 v2.1.0 github.com/bndr/gotabulate v1.1.2 github.com/google/uuid v1.1.1 From 7437ff855fa8cc781508292410adaf02df924396 Mon Sep 17 00:00:00 2001 From: ldx Date: Fri, 7 May 2021 22:53:53 +0800 Subject: [PATCH 05/26] update drivers --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index b2aa10e..f164f74 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 github.com/blocktree/go-openw-sdk/v2 v2.1.6 + github.com/blocktree/go-owcdrivers v1.2.22 // indirect github.com/blocktree/go-owcrypt v1.1.7 github.com/blocktree/openwallet/v2 v2.1.0 github.com/bndr/gotabulate v1.1.2 From 01ffc105cb582b209ea5ed84636a65cf81241699 Mon Sep 17 00:00:00 2001 From: ldx Date: Fri, 7 May 2021 22:58:36 +0800 Subject: [PATCH 06/26] update new version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f164f74..a3e2db1 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/blocktree/go-openw-sdk/v2 v2.1.6 github.com/blocktree/go-owcdrivers v1.2.22 // indirect github.com/blocktree/go-owcrypt v1.1.7 - github.com/blocktree/openwallet/v2 v2.1.0 + github.com/blocktree/openwallet/v2 v2.3.0 github.com/bndr/gotabulate v1.1.2 github.com/google/uuid v1.1.1 github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114 From 29a45ad1c430a939933517a04f2e52ac38103298 Mon Sep 17 00:00:00 2001 From: ldx Date: Mon, 10 May 2021 12:55:19 +0800 Subject: [PATCH 07/26] support the bls type --- go.mod | 3 +-- openwcli/summary_manager.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index a3e2db1..135c9a4 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.1.6 - github.com/blocktree/go-owcdrivers v1.2.22 // indirect + github.com/blocktree/go-openw-sdk/v2 v2.1.10 github.com/blocktree/go-owcrypt v1.1.7 github.com/blocktree/openwallet/v2 v2.3.0 github.com/bndr/gotabulate v1.1.2 diff --git a/openwcli/summary_manager.go b/openwcli/summary_manager.go index 0c0830b..4c508a3 100644 --- a/openwcli/summary_manager.go +++ b/openwcli/summary_manager.go @@ -429,6 +429,22 @@ func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.Summary //签名交易 signatures, sigErr := cli.txSigner(rawTx.Signatures, key) if sigErr != nil { + for accountID, signatures := range rawTx.Signatures { + log.Error("[Sign Failed] sign accountID: %s", accountID) + for _, keySignature := range signatures { + signaturesJSON, jsonErr := json.Marshal(keySignature) + if jsonErr == nil { + log.Warningf("[Failed] keySignature: %s", string(signaturesJSON)) + } + //childKey, _ := key.DerivedKeyWithPath(keySignature.DerivedPath, keySignature.EccType) + //keyBytes, _ := childKey.GetPrivateKeyBytes() + //hexKey := hex.EncodeToString(keyBytes) + //public_key, _ := owcrypt.GenPubkey(keyBytes, keySignature.EccType) + //public := hex.EncodeToString(public_key) + //log.Warningf("[Failed] Pub: %s", string(public)) + //log.Warningf("[Failed] Key: %s", string(hexKey)) + } + } log.Warn("SignRawTransaction unexpected error: %v", sigErr) continue } @@ -508,6 +524,13 @@ func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.Summary if jsonErr == nil { log.Warningf("[Failed] keySignature: %s", string(signaturesJSON)) } + //childKey, _ := key.DerivedKeyWithPath(keySignature.DerivedPath, keySignature.EccType) + //keyBytes, _ := childKey.GetPrivateKeyBytes() + //hexKey := hex.EncodeToString(keyBytes) + //public_key, _ := owcrypt.GenPubkey(keyBytes, keySignature.EccType) + //public := hex.EncodeToString(public_key) + //log.Warningf("[Failed] Pub: %s", string(public)) + //log.Warningf("[Failed] Key: %s", string(hexKey)) } } } From 6a3d5a24982e074636c55507763178595d3ef147 Mon Sep 17 00:00:00 2001 From: chance Date: Mon, 28 Jun 2021 18:04:25 +0800 Subject: [PATCH 08/26] add command: signhash --- README.md | 5 +-- commands/commands.go | 23 ++++++++++++++ go.mod | 2 +- openwcli/cli.go | 47 +++++++++++++++++++++++++++- openwcli/trustserver_manager.go | 3 +- openwcli/trustserver_manager_test.go | 34 ++++++++++++++++++-- openwcli/wallet_manager.go | 6 ++-- openwcli/wallet_manager_test.go | 2 +- 8 files changed, 112 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a8cce23..075a0c0 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,7 @@ $ ./openw-cli -c=./node.ini listtokenbalance # 启动后台托管钱包服务,执行时会要求是否解锁钱包 $ ./openw-cli -c=./node.ini trustserver +# 输入消息哈希和地址,并解锁改地址所属钱包,利用该地址的私钥对消息哈希进行签名 +$ ./openw-cli -c=node.ini signhash - -``` \ No newline at end of file +``` diff --git a/commands/commands.go b/commands/commands.go index 3933fea..58a073c 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -242,6 +242,15 @@ var ( Category: "WALLET COMMANDS", Flags: []cli.Flag{}, }, + { + + Name: "signhash", + Usage: "Select the private key of a specific address to sign the hash.", + ArgsUsage: "", + Action: signhash, + Category: "WALLET COMMANDS", + Flags: []cli.Flag{}, + }, } ) @@ -627,3 +636,17 @@ func triggerabi(c *cli.Context) error { return nil } + +//signhash 消息签名 +func signhash(c *cli.Context) error { + + if cli := getCLI(c); cli != nil { + err := cli.SignHashFlow() + if err != nil { + log.Error("unexpected error: ", err) + return err + } + } + + return nil +} diff --git a/go.mod b/go.mod index 2fcc018..e9c89f7 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 github.com/blocktree/go-openw-sdk/v2 v2.1.5 - github.com/blocktree/go-owcrypt v1.1.4 + github.com/blocktree/go-owcrypt v1.1.8 github.com/blocktree/openwallet/v2 v2.1.0 github.com/bndr/gotabulate v1.1.2 github.com/google/uuid v1.1.1 diff --git a/openwcli/cli.go b/openwcli/cli.go index 94ce62a..6cc599e 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -1207,4 +1207,49 @@ func (cli *CLI) CallABIFlow() error { } return nil -} \ No newline at end of file +} + + + +// SignHashFlow 消息签名 +func (cli *CLI) SignHashFlow() error { + + + // 等待用户输入代签消息 + message, err := console.InputText("Enter message: ", false) + if err != nil { + return err + } + + // 等待用户输入地址 + addr, err := console.InputText("Enter address: ", true) + if err != nil { + return err + } + + address, err := cli.SearchAddressOnServer(addr) + if err != nil { + return err + } + + fmt.Printf("[The found address belongs to WalletID: %s] \n", address.WalletID) + + // 等待用户输入密码 + password, err := console.InputPassword(false, 3) + if err != nil { + return err + } + + signature, exErr := cli.SignHash(address, message, password, false) + if exErr != nil { + return exErr + } + + //打印公钥和消息 + fmt.Printf("--------------- PUBLIC KEY --------------- \n") + fmt.Printf("%s\n", address.PublicKey) + fmt.Printf("--------------- SIGNATURE --------------- \n") + fmt.Printf("%s\n", signature) + + return nil +} diff --git a/openwcli/trustserver_manager.go b/openwcli/trustserver_manager.go index c6467ad..52d1b75 100644 --- a/openwcli/trustserver_manager.go +++ b/openwcli/trustserver_manager.go @@ -835,6 +835,7 @@ func (cli *CLI) signHashViaTrustNode(ctx *owtp.Context) { address := ctx.Params().Get("address").String() symbol := ctx.Params().Get("symbol").String() hdPath := ctx.Params().Get("hdPath").String() + rsv := ctx.Params().Get("rsv").Bool() if len(password) == 0 { //钱包是否已经解锁 @@ -852,7 +853,7 @@ func (cli *CLI) signHashViaTrustNode(ctx *owtp.Context) { HdPath: hdPath, } - signature, err := cli.SignHash(addr, message, password) + signature, err := cli.SignHash(addr, message, password, rsv) if err != nil { ctx.Response(nil, openwallet.ErrSystemException, err.Error()) return diff --git a/openwcli/trustserver_manager_test.go b/openwcli/trustserver_manager_test.go index 8f981e2..f9e6f05 100644 --- a/openwcli/trustserver_manager_test.go +++ b/openwcli/trustserver_manager_test.go @@ -2,12 +2,12 @@ package openwcli import ( "bytes" + "github.com/blocktree/openwallet/v2/log" "io/ioutil" "net" "net/http" "testing" - - "github.com/blocktree/openwallet/v2/log" + "time" ) func TestCLI_ConnectTransmitNode(t *testing.T) { @@ -57,3 +57,33 @@ func TestExternalIPAddress(t *testing.T) { buf.ReadFrom(resp.Body) log.Infof("addr: %s", string(content)) } + +func TestCLI_TestRunTimeTask(t *testing.T) { + + testRunTimeTask := func (cli *CLI) { + for { + walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" + accounts, cErr := cli.GetAccountsOnServer(walletID) + if cErr != nil { + log.Errorf("GetAccountsOnServer failed, err: %v", cErr) + } + log.Infof("accounts length: %d", len(accounts)) + time.Sleep(1 * time.Second) + } + } + + cli := getTestOpenwCLI() + if cli == nil { + return + } + + err := cli.ServeTransmitNode(true) + if err != nil { + t.Logf("ConnectTransmitNode error: %v\n", err) + return + } + + testRunTimeTask(cli) + +} + diff --git a/openwcli/wallet_manager.go b/openwcli/wallet_manager.go index 7ec767f..2a6c2fd 100644 --- a/openwcli/wallet_manager.go +++ b/openwcli/wallet_manager.go @@ -1202,7 +1202,7 @@ func (cli *CLI) IsTrustAddress(address, symbol string) bool { } // SignHash 哈希消息签名 -func (cli *CLI) SignHash(address *openwsdk.Address, message, password string) (string, error) { +func (cli *CLI) SignHash(address *openwsdk.Address, message, password string, appendV bool) (string, error) { wallet, err := cli.GetWalletByWalletID(address.WalletID) if err != nil { @@ -1240,7 +1240,9 @@ func (cli *CLI) SignHash(address *openwsdk.Address, message, password string) (s return "", fmt.Errorf("sign hash message failed") } - signature = append(signature, v) + if appendV { + signature = append(signature, v) + } return hex.EncodeToString(signature), nil } diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index 28dfb48..6a62a50 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -180,7 +180,7 @@ func TestCLI_GetTokenContractList(t *testing.T) { if cli == nil { return } - tokens, err := cli.GetTokenContractList() + tokens, err := cli.GetTokenContractList("Symbol", "ETP", "Address", "dna") if err != nil { log.Error("GetTokenContractList error:", err) return From 57561ffc78dfc51020c56c3b1608f6bf2a739b39 Mon Sep 17 00:00:00 2001 From: chance Date: Fri, 2 Jul 2021 10:00:57 +0800 Subject: [PATCH 09/26] update mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1f9d75d..86a43aa 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 github.com/blocktree/go-openw-sdk/v2 v2.1.10 - github.com/blocktree/go-owcrypt v1.1.8 + github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.3.0 github.com/bndr/gotabulate v1.1.2 github.com/google/uuid v1.1.1 From 38e598a75d78019a97002b7ee026b9d8b1f47ca5 Mon Sep 17 00:00:00 2001 From: chance Date: Fri, 3 Sep 2021 16:29:06 +0800 Subject: [PATCH 10/26] change private func to public func --- openwcli/cli.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/openwcli/cli.go b/openwcli/cli.go index 6cc599e..5e62128 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -339,7 +339,7 @@ func (cli *CLI) NewAddressFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -413,7 +413,7 @@ func (cli *CLI) TransferFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -478,7 +478,7 @@ func (cli *CLI) TransferAllFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -556,7 +556,7 @@ func (cli *CLI) SetSumFlow() error { //} //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -668,7 +668,7 @@ func (cli *CLI) StartSumFlow(file string) error { } //:选择账户 - account, selectErr := cli.selectAccountStep(wallet.WalletID) + account, selectErr := cli.SelectAccountStep(wallet.WalletID) if selectErr != nil { return selectErr } @@ -795,7 +795,7 @@ func (cli *CLI) ListAddressFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -893,8 +893,8 @@ func (cli *CLI) SelectWalletStep() (*openwsdk.Wallet, error) { return wallet, nil } -//selectAccountStep 选择资产账户操作 -func (cli *CLI) selectAccountStep(walletID string) (*openwsdk.Account, error) { +//SelectAccountStep 选择资产账户操作 +func (cli *CLI) SelectAccountStep(walletID string) (*openwsdk.Account, error) { accounts, _ := cli.GetAccountsOnServer(walletID) cli.printAccountList(accounts) @@ -929,7 +929,7 @@ func (cli *CLI) ListTokenBalanceFlow() error { } //:选择账户 - account, selectErr := cli.selectAccountStep(wallet.WalletID) + account, selectErr := cli.SelectAccountStep(wallet.WalletID) if selectErr != nil { return selectErr } @@ -1125,7 +1125,7 @@ func (cli *CLI) TriggerABIFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -1182,7 +1182,7 @@ func (cli *CLI) CallABIFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } From c27f3385ad98d0bde28d717b4a7c909943adc92a Mon Sep 17 00:00:00 2001 From: nixnij Date: Sat, 29 Jan 2022 10:48:22 +0800 Subject: [PATCH 11/26] Update summary_manager.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createErr 全局,当CreateSummaryTx失败createErr != nil continue后还是会在createErr这里continue --- openwcli/summary_manager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/openwcli/summary_manager.go b/openwcli/summary_manager.go index 4c508a3..207ddf7 100644 --- a/openwcli/summary_manager.go +++ b/openwcli/summary_manager.go @@ -365,6 +365,7 @@ func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.Summary //分页汇总交易 for i := 0; i < int(account.AddressIndex)+1; i = i + addressLimit { + createErr = nil err = nil retRawTxs = make([]*openwsdk.RawTransaction, 0) retRawFeesSupportTxs = make([]*openwsdk.RawTransaction, 0) From 72cc1c7d5c79649fa8023d8e4ca95bdf49e1d7a5 Mon Sep 17 00:00:00 2001 From: ZQM Date: Fri, 14 Oct 2022 17:00:46 +0800 Subject: [PATCH 12/26] update mod, update api --- Makefile | 3 +- go.mod | 6 +- openwcli/cli.go | 84 +++++++++++--------- openwcli/contract_manager_test.go | 4 +- openwcli/summary_manager.go | 61 +++++++++----- openwcli/transaction_manager.go | 27 ++++--- openwcli/transaction_manager_test.go | 14 ++-- openwcli/trustserver_manager.go | 22 +++--- openwcli/wallet_manager.go | 114 ++++++++++++++++----------- openwcli/wallet_manager_test.go | 6 +- 10 files changed, 199 insertions(+), 142 deletions(-) diff --git a/Makefile b/Makefile index 34c4cb7..2d7c1cb 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,8 @@ OPENWCLILDFLAGS="-X github.com/blocktree/go-openw-cli/v2/openwcli.Version=${OPEN TARGETS="darwin-10.10/amd64,linux/amd64,windows-6.0/*" deps: - go get -u github.com/gythialy/xgo + #go get -u github.com/gythialy/xgo + go get -u src.techknowlogick.com/xgo build: GO111MODULE=on go build -ldflags $(OPENWCLILDFLAGS) -i -o $(shell pwd)/$(BUILDDIR)/$(OPENWCLIBINARY) $(shell pwd)/$(OPENWCLIMAIN) diff --git a/go.mod b/go.mod index 86a43aa..774c180 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,11 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.1.10 + github.com/blocktree/go-openw-sdk/v2 v2.2.0 github.com/blocktree/go-owcrypt v1.1.9 - github.com/blocktree/openwallet/v2 v2.3.0 + github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 - github.com/google/uuid v1.1.1 + github.com/google/uuid v1.2.0 github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114 go.etcd.io/bbolt v1.3.3 gopkg.in/urfave/cli.v1 v1.20.0 diff --git a/openwcli/cli.go b/openwcli/cli.go index 5e62128..d883289 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -29,7 +29,7 @@ const ( maxAddresNum = 2000 ) -//type SignRawTransactionFunc func(rawTx *openwsdk.RawTransaction, key *hdkeystore.HDKey) error +// type SignRawTransactionFunc func(rawTx *openwsdk.RawTransaction, key *hdkeystore.HDKey) error type SignTxHashFunc func(signatures map[string][]*openwsdk.KeySignature, key *hdkeystore.HDKey) (map[string][]*openwsdk.KeySignature, error) type CLI struct { @@ -77,7 +77,7 @@ func NewCLI(c *Config) (*CLI, error) { return cli, nil } -//setupAPI 配置APISDK +// setupAPI 配置APISDK func (cli *CLI) setupAPISDK(keychain *Keychain) error { if keychain != nil { @@ -101,7 +101,7 @@ func (cli *CLI) setupAPISDK(keychain *Keychain) error { return nil } -//checkConfig 检查配置加载完 +// checkConfig 检查配置加载完 func (cli *CLI) checkConfig() error { if cli.config == nil { @@ -148,7 +148,7 @@ func (cli *CLI) closeDB() { } } -//GenKeychainFlow 生成新的keychain流程 +// GenKeychainFlow 生成新的keychain流程 func GenKeychainFlow() error { //生成keychain @@ -163,7 +163,7 @@ func GenKeychainFlow() error { return nil } -//RegisterFlow 注册节点流程 +// RegisterFlow 注册节点流程 func (cli *CLI) RegisterFlow() error { var ( @@ -218,7 +218,7 @@ func (cli *CLI) RegisterFlow() error { return nil } -//GetNodeInfo 获取节点信息 +// GetNodeInfo 获取节点信息 func (cli *CLI) GetNodeInfoFlow() error { keychain, err := cli.GetKeychain() @@ -231,7 +231,7 @@ func (cli *CLI) GetNodeInfoFlow() error { return nil } -//printKeychain 打印证书钥匙串 +// printKeychain 打印证书钥匙串 func printKeychain(keychain *Keychain) { //打印证书信息 log.Notice("--------------- PRIVATE KEY ---------------") @@ -242,7 +242,7 @@ func printKeychain(keychain *Keychain) { log.Notice(keychain.NodeID) } -//NewWalletFlow 创建钱包流程 +// NewWalletFlow 创建钱包流程 func (cli *CLI) NewWalletFlow() error { var ( @@ -269,14 +269,14 @@ func (cli *CLI) NewWalletFlow() error { return nil } -//ListWalletFlow +// ListWalletFlow func (cli *CLI) ListWalletFlow() error { wallets, _ := cli.GetWalletsOnServer() cli.printWalletList(wallets) return nil } -//NewAccountFlow +// NewAccountFlow func (cli *CLI) NewAccountFlow() error { //:选择钱包 @@ -315,7 +315,7 @@ func (cli *CLI) NewAccountFlow() error { return nil } -//ListAccountFlow +// ListAccountFlow func (cli *CLI) ListAccountFlow() error { //:选择钱包 @@ -329,7 +329,7 @@ func (cli *CLI) ListAccountFlow() error { return nil } -//NewAddressFlow +// NewAddressFlow func (cli *CLI) NewAddressFlow() error { //:选择钱包 @@ -361,13 +361,19 @@ func (cli *CLI) NewAddressFlow() error { return nil } -//SearchAddressFlow +// SearchAddressFlow func (cli *CLI) SearchAddressFlow() error { var ( password string ) + // 等待用户输入symbol + symbol, err := console.InputText("Enter symbol: ", true) + if err != nil { + return err + } + // 等待用户输入地址 addr, err := console.InputText("Enter address: ", true) if err != nil { @@ -384,7 +390,7 @@ func (cli *CLI) SearchAddressFlow() error { } } - address, err := cli.SearchAddressOnServer(addr) + address, err := cli.SearchAddressOnServer(symbol, addr) if err != nil { return err } @@ -404,7 +410,7 @@ func (cli *CLI) SearchAddressFlow() error { return nil } -//TransferFlow +// TransferFlow func (cli *CLI) TransferFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -469,7 +475,7 @@ func (cli *CLI) TransferFlow() error { return nil } -//TransferAllFlow +// TransferAllFlow func (cli *CLI) TransferAllFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -528,13 +534,13 @@ func (cli *CLI) TransferAllFlow() error { return nil } -//ListSumInfoFlow +// ListSumInfoFlow func (cli *CLI) ListSumInfoFlow() error { cli.printAccountSummaryInfo() return nil } -//SetSumFlow +// SetSumFlow func (cli *CLI) SetSumFlow() error { //:选择钱包 @@ -589,6 +595,7 @@ func (cli *CLI) SetSumFlow() error { obj := &openwsdk.SummarySetting{ WalletID: account.WalletID, AccountID: account.AccountID, + Symbol: account.Symbol, SumAddress: sumAddress, Threshold: threshold, MinTransfer: minTransfer, @@ -605,7 +612,7 @@ func (cli *CLI) SetSumFlow() error { return nil } -//StartSumFlow +// StartSumFlow func (cli *CLI) StartSumFlow(file string) error { var ( @@ -746,7 +753,7 @@ func (cli *CLI) StartSumFlow(file string) error { return nil } -//UpdateInfoFlow +// UpdateInfoFlow func (cli *CLI) UpdateInfoFlow() error { err := cli.UpdateSymbols() @@ -759,7 +766,7 @@ func (cli *CLI) UpdateInfoFlow() error { return nil } -//ListSymbolFlow +// ListSymbolFlow func (cli *CLI) ListSymbolFlow() error { list, err := cli.GetSymbolList() if err != nil { @@ -769,7 +776,7 @@ func (cli *CLI) ListSymbolFlow() error { return nil } -//ListTokenContractFlow +// ListTokenContractFlow func (cli *CLI) ListTokenContractFlow() error { symbol, err := console.InputText("Enter symbol: ", true) @@ -785,7 +792,7 @@ func (cli *CLI) ListTokenContractFlow() error { return nil } -//ListAddressFlow +// ListAddressFlow func (cli *CLI) ListAddressFlow() error { //:选择钱包 @@ -800,7 +807,7 @@ func (cli *CLI) ListAddressFlow() error { return err } - offset, err := console.InputNumber("Enter offset: ", true) + lastId, err := console.InputNumber("Enter last ID: ", true) if err != nil { return err } @@ -810,7 +817,7 @@ func (cli *CLI) ListAddressFlow() error { return err } - addresses, err := cli.GetAddressesOnServer(account.WalletID, account.AccountID, int(offset), int(limit)) + addresses, err := cli.GetAddressesOnServer(account.WalletID, account.AccountID, account.Symbol, int64(lastId), int64(limit)) if err != nil { return err } @@ -823,7 +830,7 @@ func (cli *CLI) ListAddressFlow() error { return nil } -//StartTrustServerFlow +// StartTrustServerFlow func (cli *CLI) StartTrustServerFlow() error { var ( @@ -868,7 +875,7 @@ func (cli *CLI) StartTrustServerFlow() error { return nil } -//SelectWalletStep 选择钱包操作 +// SelectWalletStep 选择钱包操作 func (cli *CLI) SelectWalletStep() (*openwsdk.Wallet, error) { wallets, _ := cli.GetWalletsOnServer() @@ -893,7 +900,7 @@ func (cli *CLI) SelectWalletStep() (*openwsdk.Wallet, error) { return wallet, nil } -//SelectAccountStep 选择资产账户操作 +// SelectAccountStep 选择资产账户操作 func (cli *CLI) SelectAccountStep(walletID string) (*openwsdk.Account, error) { accounts, _ := cli.GetAccountsOnServer(walletID) @@ -919,7 +926,7 @@ func (cli *CLI) SelectAccountStep(walletID string) (*openwsdk.Account, error) { return account, nil } -//ListTokenBalanceFlow +// ListTokenBalanceFlow func (cli *CLI) ListTokenBalanceFlow() error { //:选择钱包 @@ -942,7 +949,7 @@ func (cli *CLI) ListTokenBalanceFlow() error { return nil } -//unlockLocalWalletsByInputPassword 输入密码解锁钱包 +// unlockLocalWalletsByInputPassword 输入密码解锁钱包 func (cli *CLI) unlockLocalWalletsByInputPassword() error { localWallets, err := cli.GetWalletsOnServer() @@ -1115,8 +1122,7 @@ func ProcExsit(filePath string, processName string) error { return nil } - -//TriggerABIFlow +// TriggerABIFlow func (cli *CLI) TriggerABIFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -1172,8 +1178,7 @@ func (cli *CLI) TriggerABIFlow() error { return nil } - -//CallABIFlow +// CallABIFlow func (cli *CLI) CallABIFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -1209,25 +1214,28 @@ func (cli *CLI) CallABIFlow() error { return nil } - - // SignHashFlow 消息签名 func (cli *CLI) SignHashFlow() error { - // 等待用户输入代签消息 message, err := console.InputText("Enter message: ", false) if err != nil { return err } + // 等待用户输入symbol + symbol, err := console.InputText("Enter symbol: ", true) + if err != nil { + return err + } + // 等待用户输入地址 addr, err := console.InputText("Enter address: ", true) if err != nil { return err } - address, err := cli.SearchAddressOnServer(addr) + address, err := cli.SearchAddressOnServer(symbol, addr) if err != nil { return err } diff --git a/openwcli/contract_manager_test.go b/openwcli/contract_manager_test.go index 5919429..eada196 100644 --- a/openwcli/contract_manager_test.go +++ b/openwcli/contract_manager_test.go @@ -32,7 +32,7 @@ func TestCLI_CallABI(t *testing.T) { return } - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID("ETH", accountID) if err != nil { t.Errorf("GetAccountByAccountID failed, err: %v", err) return @@ -70,7 +70,7 @@ func TestCLI_TriggerABI(t *testing.T) { return } - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID("ETH", accountID) if err != nil { t.Errorf("GetAccountByAccountID failed, err: %v", err) return diff --git a/openwcli/summary_manager.go b/openwcli/summary_manager.go index 4c508a3..713ff2e 100644 --- a/openwcli/summary_manager.go +++ b/openwcli/summary_manager.go @@ -53,10 +53,17 @@ func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, return findErr } contractID = tokenBalance.ContractID - tokenSymbol = tokenBalance.Token - balance = tokenBalance.Balance.Balance + tokenSymbol = tokenBalance.ContractToken + balance = tokenBalance.Balance } else { - balance = account.Balance + balance = "0" + cli.api.GetBalanceByAccount(account.Symbol, account.AccountID, "", + true, func(status uint64, msg string, accBalance *openwsdk.BalanceResult) { + if status == owtp.StatusSuccess { + balance = accBalance.Balance + } + }) + } coin := openwsdk.Coin{ Symbol: account.Symbol, @@ -75,7 +82,7 @@ func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, return nil } -//SummaryWallets 执行汇总流程 +// SummaryWallets 执行汇总流程 func (cli *CLI) SummaryTask() { log.Infof("[Summary Task Start]------%s", common.TimeFormat("2006-01-02 15:04:05")) @@ -105,7 +112,7 @@ func (cli *CLI) SummaryTask() { for _, accountTask := range task.Accounts { - account, err := cli.GetAccountByAccountID(accountTask.AccountID) + account, err := cli.GetAccountByAccountID(accountTask.Symbol, accountTask.AccountID) if err != nil { continue } @@ -131,15 +138,23 @@ func (cli *CLI) SummaryTask() { log.Infof("[Summary Task End]------%s", common.TimeFormat("2006-01-02 15:04:05")) } -//SummaryAccountMainCoin 汇总账户主币 +// SummaryAccountMainCoin 汇总账户主币 func (cli *CLI) SummaryAccountMainCoin(accountTask *openwsdk.SummaryAccountTask, account *openwsdk.Account, key *hdkeystore.HDKey) error { var ( err error sumSets *openwsdk.SummarySetting symbol string + balance = "0" ) + cli.api.GetBalanceByAccount(account.Symbol, account.AccountID, "", + true, func(status uint64, msg string, accBalance *openwsdk.BalanceResult) { + if status == owtp.StatusSuccess { + balance = accBalance.Balance + } + }) + //读取汇总信息 sumSets, err = cli.getSummarySettingByAccount(account.AccountID) //err = cli.db.One("AccountID", account.AccountID, &sumSets) @@ -169,7 +184,7 @@ func (cli *CLI) SummaryAccountMainCoin(accountTask *openwsdk.SummaryAccountTask, log.Infof("Summary account[%s] Symbol: %s start", account.AccountID, symbol) - err = cli.summaryAccountProcess(account, accountTask, key, account.Balance, *accountTask.SummarySetting, coin) + err = cli.summaryAccountProcess(account, accountTask, key, balance, *accountTask.SummarySetting, coin) log.Infof("Summary account[%s] Symbol: %s end", account.AccountID, symbol) log.Infof("----------------------------------------------------------------------------------------") @@ -181,7 +196,7 @@ func (cli *CLI) SummaryAccountMainCoin(accountTask *openwsdk.SummaryAccountTask, return nil } -//SummaryAccountTokenContracts 汇总账户代币合约 +// SummaryAccountTokenContracts 汇总账户代币合约 func (cli *CLI) SummaryAccountTokenContracts(accountTask *openwsdk.SummaryAccountTask, account *openwsdk.Account, key *hdkeystore.HDKey) error { var ( @@ -271,7 +286,7 @@ func (cli *CLI) SummaryAccountTokenContracts(accountTask *openwsdk.SummaryAccoun return nil } -//summaryAccountProcess 汇总账户过程 +// summaryAccountProcess 汇总账户过程 func (cli *CLI) summaryAccountProcess(account *openwsdk.Account, task *openwsdk.SummaryAccountTask, key *hdkeystore.HDKey, balance string, sumSets openwsdk.SummarySetting, coin openwsdk.Coin) error { var ( @@ -288,7 +303,8 @@ func (cli *CLI) summaryAccountProcess(account *openwsdk.Account, task *openwsdk. if task.FeesSupportAccount != nil && coin.IsContract { //代币汇总才需要手续费账户 feesSupportAccountID = task.FeesSupportAccount.AccountID - feesSupportAccounInfo, err := cli.GetAccountByAccountID(feesSupportAccountID) + feesSupportSymbol := task.FeesSupportAccount.Symbol + feesSupportAccounInfo, err := cli.GetAccountByAccountID(feesSupportSymbol, feesSupportAccountID) if err != nil { return fmt.Errorf("fees support account: %s can not find", feesSupportAccountID) } @@ -302,12 +318,19 @@ func (cli *CLI) summaryAccountProcess(account *openwsdk.Account, task *openwsdk. } tokenBalance, err := cli.GetTokenBalanceByContractAddress(feesSupportAccounInfo, task.FeesSupportAccount.ContractAddress) if err == nil { - feesSupportBalance, _ = decimal.NewFromString(tokenBalance.Balance.Balance) + feesSupportBalance, _ = decimal.NewFromString(tokenBalance.Balance) } } else { //主币作为手续费 - feesSupportBalance, _ = decimal.NewFromString(feesSupportAccounInfo.Balance) + feesSupportBalance = decimal.Zero + cli.api.GetBalanceByAccount(feesSupportAccounInfo.Symbol, feesSupportAccounInfo.AccountID, "", + true, func(status uint64, msg string, balance *openwsdk.BalanceResult) { + if status == owtp.StatusSuccess { + feesSupportBalance, _ = decimal.NewFromString(balance.Balance) + } + }) + } lowBalanceWarning, _ := decimal.NewFromString(task.FeesSupportAccount.LowBalanceWarning) @@ -328,7 +351,7 @@ func (cli *CLI) summaryAccountProcess(account *openwsdk.Account, task *openwsdk. return nil } -//summaryAccount 汇总单个账户 +// summaryAccount 汇总单个账户 func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.SummaryAccountTask, key *hdkeystore.HDKey, balance string, sumSets openwsdk.SummarySetting, coin openwsdk.Coin, feesSupportAccountID string, feesSupportBalance decimal.Decimal) error { @@ -497,12 +520,12 @@ func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.Summary for _, tx := range retTx { //只计算汇总账户的 总的汇总数量,手续费 - log.Infof("[Success] txid: %s", tx.Txid) + log.Infof("[Success] txid: %s", tx.TxID) fees, _ := decimal.NewFromString(tx.Fees) totalCostFees = totalCostFees.Add(fees) - txIDs = append(txIDs, tx.Txid) + txIDs = append(txIDs, tx.TxID) sids = append(sids, tx.Sid) //统计汇总总数 for i, a := range tx.ToAddress { @@ -610,7 +633,7 @@ func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.Summary amount, _ := decimal.NewFromString(tx.Amount) totalSupportCostFees = totalSupportCostFees.Add(amount) //:手续费账户消息处理 - log.Std.Notice(" [fees support account transfer Success] txid: %s", tx.Txid) + log.Std.Notice(" [fees support account transfer Success] txid: %s", tx.TxID) } for _, tx := range retFailed { @@ -662,7 +685,7 @@ func FindExistedSummaryAccountTask(accountID string, tasks []*openwsdk.SummaryAc return -1, nil } -//checkSummaryTaskIsHaveSettings 检查汇总任务中的账户是否已配置 +// checkSummaryTaskIsHaveSettings 检查汇总任务中的账户是否已配置 func (cli *CLI) checkSummaryTaskIsHaveSettings(task *openwsdk.SummaryTask) error { for _, w := range task.Wallets { @@ -680,7 +703,7 @@ func (cli *CLI) checkSummaryTaskIsHaveSettings(task *openwsdk.SummaryTask) error for _, account := range w.Accounts { - accounInfo, err := cli.GetAccountByAccountID(account.AccountID) + accounInfo, err := cli.GetAccountByAccountID(account.Symbol, account.AccountID) if err != nil { return fmt.Errorf("summary task account: %s can not find", account.AccountID) } @@ -707,7 +730,7 @@ func (cli *CLI) checkSummaryTaskIsHaveSettings(task *openwsdk.SummaryTask) error //:查询手续费账户是否存在,是否在当前钱包下,相同的symbol,并且检查手续费账户余额是否报警 if account.FeesSupportAccount != nil && account.FeesSupportAccount.AccountID != "" { - feesSupportAccountInfo, err := cli.GetAccountByAccountID(account.FeesSupportAccount.AccountID) + feesSupportAccountInfo, err := cli.GetAccountByAccountID(account.FeesSupportAccount.Symbol, account.FeesSupportAccount.AccountID) if err != nil { return fmt.Errorf("fees support account: %s can not find", account.FeesSupportAccount.AccountID) } diff --git a/openwcli/transaction_manager.go b/openwcli/transaction_manager.go index 4b74a44..d278c7b 100644 --- a/openwcli/transaction_manager.go +++ b/openwcli/transaction_manager.go @@ -8,22 +8,22 @@ import ( "github.com/blocktree/openwallet/v2/owtp" ) -//GetTokenBalance 获取代币余额 +// GetTokenBalance 获取代币余额 func (cli *CLI) GetTokenBalance(account *openwsdk.Account, contractID string) string { getBalance := "0" - cli.api.GetTokenBalanceByAccount(account.AccountID, contractID, true, - func(status uint64, msg string, balance *openwsdk.TokenBalance) { + cli.api.GetBalanceByAccount(account.Symbol, account.AccountID, contractID, true, + func(status uint64, msg string, balance *openwsdk.BalanceResult) { if status == owtp.StatusSuccess { - getBalance = balance.Balance.Balance + getBalance = balance.Balance } }) return getBalance } -//GetTokenBalanceByContractAddress 通过代币合约的地址获取代币余额 -func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, address string) (*openwsdk.TokenBalance, error) { +// GetTokenBalanceByContractAddress 通过代币合约的地址获取代币余额 +func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, address string) (*openwsdk.BalanceResult, error) { var ( - getBalance *openwsdk.TokenBalance + getBalance *openwsdk.BalanceResult callErr error ) @@ -32,10 +32,11 @@ func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, addr return nil, findErr } contractID := token[0].ContractID - err := cli.api.GetTokenBalanceByAccount(account.AccountID, contractID, true, - func(status uint64, msg string, balance *openwsdk.TokenBalance) { + err := cli.api.GetBalanceByAccount(account.Symbol, account.AccountID, contractID, true, + func(status uint64, msg string, balance *openwsdk.BalanceResult) { if status == owtp.StatusSuccess { getBalance = balance + getBalance.ContractToken = token[0].Token } else { callErr = openwallet.Errorf(status, msg) } @@ -49,12 +50,12 @@ func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, addr return getBalance, nil } -//Transfer 转账交易 +// Transfer 转账交易 func (cli *CLI) Transfer(wallet *openwsdk.Wallet, account *openwsdk.Account, contractAddress, to, amount, sid, feeRate, memo, password string) ([]*openwsdk.Transaction, []*openwsdk.FailedRawTransaction, *openwallet.Error) { return cli.TransferExt(wallet, account, contractAddress, to, amount, sid, feeRate, memo, "", password) } -//TransferExt 转账交易 + 扩展参数 +// TransferExt 转账交易 + 扩展参数 func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, contractAddress, to, amount, sid, feeRate, memo, extParam, password string) ([]*openwsdk.Transaction, []*openwsdk.FailedRawTransaction, *openwallet.Error) { var ( @@ -99,7 +100,7 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, } api := cli.api - err = api.CreateTrade(account.AccountID, sid, coin, amount, to, feeRate, memo, extParam, true, + err = api.CreateTrade(account.AccountID, sid, coin, map[string]string{"to": amount}, feeRate, memo, extParam, true, func(status uint64, msg string, rawTx *openwsdk.RawTransaction) { if status != owtp.StatusSuccess { createErr = openwallet.Errorf(status, msg) @@ -154,7 +155,7 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, if len(retTx) > 0 { //打印交易单 log.Info("send transaction successfully.") - log.Info("transaction id:", retTx[0].Txid) + log.Info("transaction id:", retTx[0].TxID) } else if len(retFailed) > 0 { //打印交易单 log.Errorf("send transaction failed.") diff --git a/openwcli/transaction_manager_test.go b/openwcli/transaction_manager_test.go index 3b23b6a..ad0fb11 100644 --- a/openwcli/transaction_manager_test.go +++ b/openwcli/transaction_manager_test.go @@ -19,7 +19,7 @@ func testFindAccountByID(accountID string, list []*openwsdk.Account) *openwsdk.A return nil } -func testCLITransfer(walletID, accountID, contractAddress, amount, to, memo, password string) *openwallet.Error { +func testCLITransfer(walletID, accountID, symbol, contractAddress, amount, to, memo, password string) *openwallet.Error { cli := getTestOpenwCLI() if cli == nil { return openwallet.Errorf(openwallet.ErrUnknownException, "init cli error") @@ -31,7 +31,7 @@ func testCLITransfer(walletID, accountID, contractAddress, amount, to, memo, pas return openwallet.ConvertError(err) } - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID(accountID, symbol) if err != nil { //log.Error("GetAccountByAccountID error:", err) return openwallet.ConvertError(err) @@ -49,7 +49,7 @@ func testCLITransfer(walletID, accountID, contractAddress, amount, to, memo, pas return nil } -func testCLITransferAll(walletID, accountID, to, password string) *openwallet.Error { +func testCLITransferAll(walletID, accountID, symbol, to, password string) *openwallet.Error { cli := getTestOpenwCLI() if cli == nil { return openwallet.Errorf(openwallet.ErrUnknownException, "init cli error") @@ -61,7 +61,7 @@ func testCLITransferAll(walletID, accountID, to, password string) *openwallet.Er return openwallet.ConvertError(err) } - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID(accountID, symbol) if err != nil { //log.Error("GetAccountByAccountID error:", err) return openwallet.ConvertError(err) @@ -85,7 +85,7 @@ func TestCLI_Transfer_LTC(t *testing.T) { amount := "0.001" to := "LcaFc1pmJBsS7MQyMvZaboppuuvGFubD49" password := "12345678" - err := testCLITransfer(walletID, accountID, "", amount, to, "", password) + err := testCLITransfer(walletID, accountID, "ETH", "", amount, to, "", password) if err != nil { t.Errorf("Transfer error code: %d, msg: %s", err.Code(), err.Error()) return @@ -97,7 +97,7 @@ func TestCLI_TransferAll_LTC(t *testing.T) { accountID := "PgHCcfMbcw1zXRNZo23NFjRdBmcN5tzrb1j5McRLJbG" to := "LcaFc1pmJBsS7MQyMvZaboppuuvGFubD49" password := "12345678" - err := testCLITransferAll(walletID, accountID, to, password) + err := testCLITransferAll(walletID, accountID, "ETH", to, password) if err != nil { t.Errorf("Transfer All error code: %d, msg: %s", err.Code(), err.Error()) return @@ -251,7 +251,7 @@ func TestCLI_Transfer_Token(t *testing.T) { to := "tgcopenwtest" password := "12345678" memo := "N3CCXUQL" - err := testCLITransfer(walletID, accountID, contractAddress, amount, to, memo, password) + err := testCLITransfer(walletID, accountID, "ETH", contractAddress, amount, to, memo, password) if err != nil { t.Errorf("Transfer error code: %d, msg: %s \n", err.Code(), err.Error()) return diff --git a/openwcli/trustserver_manager.go b/openwcli/trustserver_manager.go index 52d1b75..77b6ecd 100644 --- a/openwcli/trustserver_manager.go +++ b/openwcli/trustserver_manager.go @@ -64,7 +64,7 @@ func (cli *CLI) ServeTransmitNode(autoReconnect bool) error { return nil } -//connectTransmitNode +// connectTransmitNode func (cli *CLI) connectTransmitNode() error { connectCfg := owtp.ConnectConfig{} @@ -96,7 +96,7 @@ func (cli *CLI) connectTransmitNode() error { return nil } -//Run 运行商户节点管理 +// Run 运行商户节点管理 func (cli *CLI) autoReconnectTransmitNode() error { var ( @@ -273,8 +273,9 @@ func (cli *CLI) sendTransactionViaTrustNode(ctx *owtp.Context) { feeRate := ctx.Params().Get("feeRate").String() memo := ctx.Params().Get("memo").String() extParam := ctx.Params().Get("extParam").String() + symbol := ctx.Params().Get("symbol").String() - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID(symbol, accountID) if err != nil { ctx.Response(nil, openwallet.ErrAccountNotFound, err.Error()) return @@ -779,13 +780,14 @@ func (cli *CLI) triggerABIViaTrustNode(ctx *owtp.Context) { raw := ctx.Params().Get("raw").String() rawType := ctx.Params().Get("rawType").Uint() awaitResult := ctx.Params().Get("awaitResult").Bool() + symbol := ctx.Params().Get("symbol").String() abiParam := make([]string, 0) for _, s := range abiArr.Array() { abiParam = append(abiParam, s.String()) } - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID(symbol, accountID) if err != nil { ctx.Response(nil, openwallet.ErrAccountNotFound, err.Error()) return @@ -845,12 +847,12 @@ func (cli *CLI) signHashViaTrustNode(ctx *owtp.Context) { } addr := &openwsdk.Address{ - AppID: appID, - WalletID: walletID, - AccountID: accountID, - Symbol: symbol, - Address: address, - HdPath: hdPath, + AppID: appID, + WalletID: walletID, + AccountID: accountID, + Symbol: symbol, + Address: address, + HdPath: hdPath, } signature, err := cli.SignHash(addr, message, password, rsv) diff --git a/openwcli/wallet_manager.go b/openwcli/wallet_manager.go index 2a6c2fd..f3f5765 100644 --- a/openwcli/wallet_manager.go +++ b/openwcli/wallet_manager.go @@ -19,7 +19,7 @@ import ( "github.com/bndr/gotabulate" ) -//CreateWalletOnServer +// CreateWalletOnServer func (cli *CLI) CreateWalletOnServer(name, password string) (*openwsdk.Wallet, error) { var ( @@ -74,7 +74,7 @@ func (cli *CLI) CreateWalletOnServer(name, password string) (*openwsdk.Wallet, e return retWallet, retErr } -//GetWalletsByKeyDir 通过给定的文件路径加载keystore文件得到钱包列表 +// GetWalletsByKeyDir 通过给定的文件路径加载keystore文件得到钱包列表 func (cli *CLI) GetWalletsOnServer() ([]*openwsdk.Wallet, error) { localWallets, err := openwallet.GetWalletsByKeyDir(cli.config.keydir) if err != nil { @@ -97,7 +97,7 @@ func (cli *CLI) GetWalletsOnServer() ([]*openwsdk.Wallet, error) { return serverWallets, nil } -//GetWalletByWalletID 查找本地且线上有的钱包对象 +// GetWalletByWalletID 查找本地且线上有的钱包对象 func (cli *CLI) GetWalletByWalletID(walletID string) (*openwsdk.Wallet, error) { var ( @@ -128,7 +128,7 @@ func (cli *CLI) GetWalletByWalletID(walletID string) (*openwsdk.Wallet, error) { return localWallet, nil } -//GetWalletByWalletIDOnLocal 查找本地种子目录的钱包对象 +// GetWalletByWalletIDOnLocal 查找本地种子目录的钱包对象 func (cli *CLI) GetWalletByWalletIDOnLocal(walletID string) (*openwsdk.Wallet, error) { localWallets, err := openwallet.GetWalletsByKeyDir(cli.config.keydir) if err != nil { @@ -148,7 +148,7 @@ func (cli *CLI) GetWalletByWalletIDOnLocal(walletID string) (*openwsdk.Wallet, e return nil, fmt.Errorf("can not find local wallet by walletID: %s", walletID) } -//printWalletList 打印钱包列表 +// printWalletList 打印钱包列表 func (cli *CLI) printWalletList(list []*openwsdk.Wallet) { if list != nil && len(list) > 0 { @@ -171,7 +171,7 @@ func (cli *CLI) printWalletList(list []*openwsdk.Wallet) { } } -//CreateAccountOnServer +// CreateAccountOnServer func (cli *CLI) CreateAccountOnServer(name, password, symbol string, wallet *openwsdk.Wallet) (*openwsdk.Account, []*openwsdk.Address, error) { var ( @@ -222,7 +222,7 @@ func (cli *CLI) CreateAccountOnServer(name, password, symbol string, wallet *ope err = cli.api.CreateNormalAccount(newaccount, true, func(status uint64, msg string, account *openwsdk.Account, addresses []*openwsdk.Address) { if status == owtp.StatusSuccess { - log.Infof("create [%s] account successfully", selectedSymbol.Coin) + log.Infof("create [%s] account successfully", selectedSymbol.Symbol) log.Infof("new accountID: %s", account.AccountID) if len(addresses) > 0 { log.Infof("new address: %s", addresses[0].Address) @@ -246,8 +246,8 @@ func (cli *CLI) CreateAccountOnServer(name, password, symbol string, wallet *ope return retAccount, retAddresses, nil } -//GetAccountOnServerByAccountID 从服务器获取账户 -func (cli *CLI) GetAccountByAccountID(accountID string) (*openwsdk.Account, error) { +// GetAccountOnServerByAccountID 从服务器获取账户 +func (cli *CLI) GetAccountByAccountID(symbol, accountID string) (*openwsdk.Account, error) { var ( getAccount *openwsdk.Account @@ -255,7 +255,7 @@ func (cli *CLI) GetAccountByAccountID(accountID string) (*openwsdk.Account, erro retErr error ) - err = cli.api.FindAccountByAccountID(accountID, 0, true, + err = cli.api.FindAccountByAccountID(symbol, accountID, 0, true, func(status uint64, msg string, account *openwsdk.Account) { if status == owtp.StatusSuccess { getAccount = account @@ -273,16 +273,18 @@ func (cli *CLI) GetAccountByAccountID(accountID string) (*openwsdk.Account, erro return getAccount, nil } -//GetAccountsOnServer 从服务器获取账户列表 +// GetAccountsOnServer 从服务器获取账户列表 func (cli *CLI) GetAccountsOnServer(walletID string) ([]*openwsdk.Account, error) { var ( list = make([]*openwsdk.Account, 0) err error retErr error + lastID = int64(0) + limit = int64(200) ) - err = cli.api.FindAccountByWalletID(walletID, true, + err = cli.api.FindAccountByWalletID("", walletID, lastID, limit, true, func(status uint64, msg string, accounts []*openwsdk.Account) { if status == owtp.StatusSuccess && len(accounts) > 0 { list = append(list, accounts...) @@ -301,7 +303,7 @@ func (cli *CLI) GetAccountsOnServer(walletID string) ([]*openwsdk.Account, error return list, nil } -//printAccountList 打印账户列表 +// printAccountList 打印账户列表 func (cli *CLI) printAccountList(list []*openwsdk.Account) { _, err := cli.getDB() @@ -324,9 +326,19 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { } else { sumTips = "√" } + balanceStr := "0" + //查询账户余额 + cli.api.GetBalanceByAccount(w.Symbol, w.AccountID, "", + true, func(status uint64, msg string, balance *openwsdk.BalanceResult) { + if status == owtp.StatusSuccess { + balanceStr = balance.Balance + } else { + balanceStr = "N/A" + } + }) tableInfo = append(tableInfo, []interface{}{ - i, w.Alias, w.AccountID, w.Symbol, w.Balance, w.AddressIndex + 1, sumTips, + i, w.Alias, w.AccountID, w.Symbol, balanceStr, w.AddressIndex + 1, sumTips, }) } @@ -342,7 +354,7 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { } } -//printAccountList 打印账户列表 +// printAccountList 打印账户列表 func (cli *CLI) printAccountSummaryInfo() { _, err := cli.getDB() @@ -375,7 +387,7 @@ func (cli *CLI) printAccountSummaryInfo() { fmt.Println(t.Render("simple")) } -//CreateAddressOnServer +// CreateAddressOnServer func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) error { var ( @@ -420,7 +432,7 @@ func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) return retErr } -//exportAddressToFile 导出地址到文件中 +// exportAddressToFile 导出地址到文件中 func (cli *CLI) exportAddressToFile(addresses []string, filePath string) bool { var ( @@ -434,8 +446,8 @@ func (cli *CLI) exportAddressToFile(addresses []string, filePath string) bool { return file.WriteFile(filePath, []byte(content), true) } -//SearchAddressOnServer -func (cli *CLI) SearchAddressOnServer(address string) (*openwsdk.Address, error) { +// SearchAddressOnServer +func (cli *CLI) SearchAddressOnServer(symbol, address string) (*openwsdk.Address, error) { var ( retErr error @@ -447,7 +459,7 @@ func (cli *CLI) SearchAddressOnServer(address string) (*openwsdk.Address, error) var addr *openwsdk.Address - err := cli.api.FindAddressByAddress(address, true, + err := cli.api.FindAddressByAddress(symbol, address, true, func(status uint64, msg string, address *openwsdk.Address) { if status == owtp.StatusSuccess { addr = address @@ -463,8 +475,8 @@ func (cli *CLI) SearchAddressOnServer(address string) (*openwsdk.Address, error) return addr, retErr } -//GetAddressesOnServer -func (cli *CLI) GetAddressesOnServer(walletID, accountID string, offset, limit int) ([]*openwsdk.Address, error) { +// GetAddressesOnServer +func (cli *CLI) GetAddressesOnServer(walletID, accountID, symbol string, lastId, limit int64) ([]*openwsdk.Address, error) { var ( retErr error @@ -480,7 +492,7 @@ func (cli *CLI) GetAddressesOnServer(walletID, accountID string, offset, limit i return nil, fmt.Errorf("walleID is empty. ") } - err := cli.api.FindAddressByAccountID(accountID, offset, limit, true, + err := cli.api.FindAddressByAccountID(symbol, accountID, lastId, limit, true, func(status uint64, msg string, addresses []*openwsdk.Address) { if status == owtp.StatusSuccess { list = addresses @@ -496,7 +508,7 @@ func (cli *CLI) GetAddressesOnServer(walletID, accountID string, offset, limit i return list, retErr } -//printAddressList 打印地址列表 +// printAddressList 打印地址列表 func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, password string) error { var ( @@ -537,7 +549,17 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass if list != nil && len(list) > 0 { tableInfo := make([][]interface{}, 0) - for i, a := range list { + for _, a := range list { + + balanceStr := "0" + cli.api.GetBalanceByAddress(a.Symbol, a.Address, "", + true, func(status uint64, msg string, balance *openwsdk.BalanceResult) { + if status == owtp.StatusSuccess { + balanceStr = balance.Balance + } else { + balanceStr = "N/A" + } + }) if isShowPrivateKey && key != nil { @@ -560,7 +582,7 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass } tableInfo = append(tableInfo, []interface{}{ - i, a.Address, a.WalletID, a.AccountID, a.Symbol, a.Balance, a.PublicKey, privatekey, + a.Id, a.Address, a.WalletID, a.AccountID, a.Symbol, balanceStr, a.PublicKey, privatekey, }) } @@ -577,7 +599,7 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass return nil } -//UpdateSymbols 更新主链 +// UpdateSymbols 更新主链 func (cli *CLI) UpdateSymbols() error { const ( @@ -611,7 +633,7 @@ func (cli *CLI) UpdateSymbols() error { for { var getTokenContract []*openwsdk.TokenContract - err = cli.api.GetContracts(s.Coin, "", i, limit, true, + err = cli.api.GetContracts(s.Symbol, "", i, limit, true, func(status uint64, msg string, tokenContract []*openwsdk.TokenContract) { getTokenContract = tokenContract }) @@ -643,7 +665,7 @@ func (cli *CLI) UpdateSymbols() error { return tx.Commit() } -//UpdateSymbols 更新主链 +// UpdateSymbols 更新主链 func (cli *CLI) UpdateTokenContracts(symbol string) error { var getTokenContract []*openwsdk.TokenContract err := cli.api.GetContracts(symbol, "", 0, 5000, true, @@ -679,7 +701,7 @@ func (cli *CLI) UpdateTokenContracts(symbol string) error { return tx.Commit() } -//GetLocalSymbolList 查询本地保存主链 +// GetLocalSymbolList 查询本地保存主链 func (cli *CLI) GetSymbolList() ([]*openwsdk.Symbol, error) { _, err := cli.getDB() @@ -711,7 +733,7 @@ func (cli *CLI) GetSymbolList() ([]*openwsdk.Symbol, error) { return getSymbols, nil } -//printSymbolList 打印主链列表 +// printSymbolList 打印主链列表 func (cli *CLI) printSymbolList(list []*openwsdk.Symbol) { if list != nil && len(list) > 0 { @@ -719,7 +741,7 @@ func (cli *CLI) printSymbolList(list []*openwsdk.Symbol) { for _, w := range list { tableInfo = append(tableInfo, []interface{}{ - w.Name, w.Coin, w.Curve, w.Decimals, + w.Name, w.Symbol, w.Curve, w.Decimals, }) } @@ -734,7 +756,7 @@ func (cli *CLI) printSymbolList(list []*openwsdk.Symbol) { } } -//GetLocalSymbolInfo 查询本地主链信息 +// GetLocalSymbolInfo 查询本地主链信息 func (cli *CLI) GetSymbolInfo(symbol string) (*openwsdk.Symbol, error) { getSymbols, err := cli.GetSymbolList() @@ -743,7 +765,7 @@ func (cli *CLI) GetSymbolInfo(symbol string) (*openwsdk.Symbol, error) { } for _, s := range getSymbols { - if s.Coin == strings.ToUpper(symbol) { + if s.Symbol == strings.ToUpper(symbol) { return s, nil } } @@ -751,7 +773,7 @@ func (cli *CLI) GetSymbolInfo(symbol string) (*openwsdk.Symbol, error) { return nil, fmt.Errorf("can not find symbol info") } -//GetContractList 查询本地保存代币合约信息 +// GetContractList 查询本地保存代币合约信息 func (cli *CLI) GetTokenContractList(cols ...interface{}) ([]*openwsdk.TokenContract, error) { var ( @@ -797,7 +819,7 @@ func (cli *CLI) GetTokenContractList(cols ...interface{}) ([]*openwsdk.TokenCont return getTokenContracts, nil } -//printTokenContractList 打印代币合约列表 +// printTokenContractList 打印代币合约列表 func (cli *CLI) printTokenContractList(list []*openwsdk.TokenContract) { if list != nil && len(list) > 0 { @@ -820,7 +842,7 @@ func (cli *CLI) printTokenContractList(list []*openwsdk.TokenContract) { } } -//GetTokenContractInfo 查询单个合约信息 +// GetTokenContractInfo 查询单个合约信息 func (cli *CLI) GetTokenContractInfo(contractID string) (*openwsdk.TokenContract, error) { getTokenContracts, err := cli.GetTokenContractList() @@ -837,11 +859,11 @@ func (cli *CLI) GetTokenContractInfo(contractID string) (*openwsdk.TokenContract return nil, fmt.Errorf("can not find symbol info") } -//SetSummaryInfo 设置账户的汇总设置 +// SetSummaryInfo 设置账户的汇总设置 func (cli *CLI) SetSummaryInfo(obj *openwsdk.SummarySetting) error { //检查账户是否存在 - account, err := cli.GetAccountByAccountID(obj.AccountID) + account, err := cli.GetAccountByAccountID(obj.Symbol, obj.AccountID) if err != nil { return err } @@ -865,7 +887,7 @@ func (cli *CLI) SetSummaryInfo(obj *openwsdk.SummarySetting) error { return cli.db.Save(obj) } -//getLocalKeyByWallet +// getLocalKeyByWallet func (cli *CLI) getLocalKeyByWallet(wallet *openwsdk.Wallet, password string) (*hdkeystore.HDKey, error) { keystore := hdkeystore.NewHDKeystore( cli.config.keydir, @@ -886,7 +908,7 @@ func (cli *CLI) getLocalKeyByWallet(wallet *openwsdk.Wallet, password string) (* return key, nil } -//GetAllTokenContractBalance 查询账户合约余额 +// GetAllTokenContractBalance 查询账户合约余额 func (cli *CLI) GetAllTokenContractBalance(accountID string, symbol string) ([]*openwsdk.TokenBalance, error) { var ( @@ -912,7 +934,7 @@ func (cli *CLI) GetAllTokenContractBalance(accountID string, symbol string) ([]* return getBalances, nil } -//GetAllTokenContractBalanceByAddress 查询地址合约余额 +// GetAllTokenContractBalanceByAddress 查询地址合约余额 func (cli *CLI) GetAllTokenContractBalanceByAddress(accountID, address, symbol string) ([]*openwsdk.TokenBalance, error) { var ( @@ -947,7 +969,7 @@ func findTokenContractByID(tokenList []*openwsdk.TokenContract, contractID strin return nil } -//printTokenContractBalanceList 打印账户代币合约余额列表 +// printTokenContractBalanceList 打印账户代币合约余额列表 func (cli *CLI) printTokenContractBalanceList(list []*openwsdk.TokenBalance, symbol string) { if list != nil && len(list) > 0 { @@ -996,7 +1018,7 @@ func (cli *CLI) AddTrustAddress(trustAddress *openwsdk.TrustAddress) error { return err } - trustAddress.Symbol = s.Coin + trustAddress.Symbol = s.Symbol _, err = cli.getDB() if err != nil { @@ -1037,7 +1059,7 @@ func (cli *CLI) ListTrustAddress(symbol string) ([]*openwsdk.TrustAddress, error return list, nil } -//printListTrustAddress 白名单地址列表 +// printListTrustAddress 白名单地址列表 func (cli *CLI) printListTrustAddress(addrs []*openwsdk.TrustAddress) { if len(addrs) == 0 { @@ -1079,7 +1101,7 @@ func (cli *CLI) importSummaryAddressToTrustAddress() error { for _, s := range sum { //检查账户是否存在 - account, err := cli.GetAccountByAccountID(s.AccountID) + account, err := cli.GetAccountByAccountID(s.Symbol, s.AccountID) if err != nil { return err } diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index 6a62a50..57e6dec 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -81,7 +81,7 @@ func TestCLI_GetAccountOnServer(t *testing.T) { } accountID := "65Y9FgipAS2M7ankrt4o3MR2Z1EEPNZKBqyQNsKt9wnj" - account, err := cli.GetAccountByAccountID(accountID) + account, err := cli.GetAccountByAccountID("ETH", accountID) if err != nil { log.Error("GetAccountByAccountID error:", err) return @@ -115,7 +115,7 @@ func TestCLI_GetAddressesOnServer(t *testing.T) { walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" accountID := "7KgNQFx35ijMA43NgY89uaiwi9Tm4MH1PH68Kpnaqstu" - addresses, err := cli.GetAddressesOnServer(walletID, accountID, 0, 50) + addresses, err := cli.GetAddressesOnServer(walletID, accountID, "ETH", 0, 50) if err != nil { log.Error("GetAddressesOnServer error:", err) return @@ -136,7 +136,7 @@ func TestCLI_SearchAddressOnServer(t *testing.T) { addr := "n4LX1HnPnM4Xwy61abUFFpzqoXctHsmmeJ" - address, err := cli.SearchAddressOnServer(addr) + address, err := cli.SearchAddressOnServer("ETH", addr) if err != nil { log.Error("SearchAddressOnServer error:", err) return From 14e6165cc58d36d31a85d2b14d3b0f5dee2c6bf8 Mon Sep 17 00:00:00 2001 From: ZQM Date: Fri, 14 Oct 2022 21:56:52 +0800 Subject: [PATCH 13/26] update mod fix bug --- .github/workflows/main.yml | 2 +- go.mod | 2 +- openwcli/cli.go | 8 +++++++- openwcli/wallet_manager.go | 10 +++++----- openwcli/wallet_manager_test.go | 20 ++++++++++---------- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd0ac2a..cc6f359 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - name: Build with xgo uses: crazy-max/ghaction-xgo@v1.6.1 with: - go_version: 1.13.3 + go_version: 1.19.2 dest: build/ prefix: ${{ env.OPENWCLIBINARY }} targets: darwin-10.10/amd64,linux/amd64,windows-6.0/* diff --git a/go.mod b/go.mod index 774c180..852cd50 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.2.0 + github.com/blocktree/go-openw-sdk/v2 v2.2.1 github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 diff --git a/openwcli/cli.go b/openwcli/cli.go index d883289..3b2373d 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -344,6 +344,12 @@ func (cli *CLI) NewAddressFlow() error { return err } + // 输入symbol + symbol, err := console.InputText("Enter symbol: ", false) + if err != nil { + return err + } + // 输入地址数量 count, err := console.InputNumber("Enter the number of addresses you want: ", false) if err != nil { @@ -354,7 +360,7 @@ func (cli *CLI) NewAddressFlow() error { return fmt.Errorf("The number of addresses can not exceed %d ", maxAddresNum) } - err = cli.CreateAddressOnServer(account.WalletID, account.AccountID, count) + err = cli.CreateAddressOnServer(account.WalletID, account.AccountID, symbol, count) if err != nil { return err } diff --git a/openwcli/wallet_manager.go b/openwcli/wallet_manager.go index f3f5765..f302155 100644 --- a/openwcli/wallet_manager.go +++ b/openwcli/wallet_manager.go @@ -388,7 +388,7 @@ func (cli *CLI) printAccountSummaryInfo() { } // CreateAddressOnServer -func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) error { +func (cli *CLI) CreateAddressOnServer(walletID, accountID, symbol string, count uint64) error { var ( retErr error @@ -406,8 +406,8 @@ func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) return fmt.Errorf("create address count can not 0. ") } - err := cli.api.CreateBatchAddress(walletID, accountID, count, true, - func(status uint64, msg string, addresses []string) { + err := cli.api.CreateAddress(symbol, walletID, accountID, count, true, + func(status uint64, msg string, addresses []*openwsdk.Address) { if status == owtp.StatusSuccess { log.Infof("create [%d] addresses successfully", len(addresses)) //:保存到本地数据库,导出到文件夹 @@ -433,14 +433,14 @@ func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) } // exportAddressToFile 导出地址到文件中 -func (cli *CLI) exportAddressToFile(addresses []string, filePath string) bool { +func (cli *CLI) exportAddressToFile(addresses []*openwsdk.Address, filePath string) bool { var ( content string ) for _, a := range addresses { - content = content + a + "\n" + content = content + a.Address + "\n" } return file.WriteFile(filePath, []byte(content), true) diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index 57e6dec..cce5687 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -14,7 +14,7 @@ func TestCLI_CreateWalletOnServer(t *testing.T) { if cli == nil { return } - _, err := cli.CreateWalletOnServer("testwallet", "12345678") + _, err := cli.CreateWalletOnServer("newwallet", "12345678") if err != nil { log.Error("CreateWalletOnServer error:", err) return @@ -41,7 +41,7 @@ func TestCLI_CreateAccountOnServer(t *testing.T) { if cli == nil { return } - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" + walletID := "WJ728uvSxc73m6BvfRsjM1v3jGfdimVEAr" wallet, err := cli.GetWalletByWalletID(walletID) if err != nil { log.Error("GetWalletByWalletID error:", err) @@ -49,7 +49,7 @@ func TestCLI_CreateAccountOnServer(t *testing.T) { } if wallet != nil { - _, _, err = cli.CreateAccountOnServer("mainnetQUORUM2", "12345678", "QUORUM", wallet) + _, _, err = cli.CreateAccountOnServer("testETH", "12345678", "ETH", wallet) if err != nil { log.Error("CreateAccountOnServer error:", err) return @@ -80,7 +80,7 @@ func TestCLI_GetAccountOnServer(t *testing.T) { return } - accountID := "65Y9FgipAS2M7ankrt4o3MR2Z1EEPNZKBqyQNsKt9wnj" + accountID := "A9PfM5Dr62WAtDEC3Pio6G1g27288gSUAJaLom68rSCZ" account, err := cli.GetAccountByAccountID("ETH", accountID) if err != nil { log.Error("GetAccountByAccountID error:", err) @@ -95,9 +95,9 @@ func TestCLI_CreateAddressOnServer(t *testing.T) { return } - walletID := "WN84dVZXpgVixsvXnU8jkFWD1qWHp15LpA" - accountID := "7ww2Gpfy8pN6HTngbMFBTEMAaVRGEpkmsiNkgAgqGQGf" - err := cli.CreateAddressOnServer(walletID, accountID, 1000) + walletID := "WJ728uvSxc73m6BvfRsjM1v3jGfdimVEAr" + accountID := "A9PfM5Dr62WAtDEC3Pio6G1g27288gSUAJaLom68rSCZ" + err := cli.CreateAddressOnServer(walletID, accountID, "ETH", 10) if err != nil { log.Error("CreateAddressOnServer error:", err) return @@ -112,8 +112,8 @@ func TestCLI_GetAddressesOnServer(t *testing.T) { return } - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" - accountID := "7KgNQFx35ijMA43NgY89uaiwi9Tm4MH1PH68Kpnaqstu" + walletID := "WJ728uvSxc73m6BvfRsjM1v3jGfdimVEAr" + accountID := "A9PfM5Dr62WAtDEC3Pio6G1g27288gSUAJaLom68rSCZ" addresses, err := cli.GetAddressesOnServer(walletID, accountID, "ETH", 0, 50) if err != nil { @@ -134,7 +134,7 @@ func TestCLI_SearchAddressOnServer(t *testing.T) { return } - addr := "n4LX1HnPnM4Xwy61abUFFpzqoXctHsmmeJ" + addr := "0x03463372a699f99775000edf9e89104af31c297f" address, err := cli.SearchAddressOnServer("ETH", addr) if err != nil { From bf220ed84200bdd7c11e121142c5a4f49730dcf8 Mon Sep 17 00:00:00 2001 From: ZQM Date: Thu, 20 Oct 2022 17:15:40 +0800 Subject: [PATCH 14/26] fix bug --- go.mod | 2 +- openwcli/cli.go | 8 ++++---- openwcli/config.go | 7 +++++-- openwcli/contract_manager.go | 8 ++++---- openwcli/contract_manager_test.go | 2 +- openwcli/trustserver_manager.go | 4 ++-- openwcli/wallet_manager.go | 20 ++++++++++---------- openwcli/wallet_manager_test.go | 16 ++++++++-------- 8 files changed, 35 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 852cd50..cf86d1a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.2.1 + github.com/blocktree/go-openw-sdk/v2 v2.2.2 github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 diff --git a/openwcli/cli.go b/openwcli/cli.go index 3b2373d..a95398d 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -401,7 +401,7 @@ func (cli *CLI) SearchAddressFlow() error { return err } - cli.printAddressList(address.WalletID, []*openwsdk.Address{address}, password) + cli.printAddressList(address.WalletID, symbol, []*openwsdk.Address{address}, password) //是否需要显示地址私钥,需要必须填入密码 show, _ := console.Stdin.PromptConfirm("Do want to show address token balance?") @@ -828,7 +828,7 @@ func (cli *CLI) ListAddressFlow() error { return err } - err = cli.printAddressList(account.WalletID, addresses, "") + err = cli.printAddressList(account.WalletID, account.Symbol, addresses, "") if err != nil { return err } @@ -1176,7 +1176,7 @@ func (cli *CLI) TriggerABIFlow() error { //创建新交易单 sid := uuid.New().String() - _, exErr := cli.TriggerABI(wallet, account, contractAddress, "", "0", sid, feeRate, password, abiParam, "", 0, true) + _, exErr := cli.TriggerABI(wallet, account, account.Symbol, contractAddress, "", "0", sid, feeRate, password, abiParam, "", 0, true) if exErr != nil { return exErr } @@ -1254,7 +1254,7 @@ func (cli *CLI) SignHashFlow() error { return err } - signature, exErr := cli.SignHash(address, message, password, false) + signature, exErr := cli.SignHash(address, symbol, message, password, false) if exErr != nil { return exErr } diff --git a/openwcli/config.go b/openwcli/config.go index e7ebe67..d9122ff 100644 --- a/openwcli/config.go +++ b/openwcli/config.go @@ -3,6 +3,7 @@ package openwcli import ( "github.com/astaxie/beego/config" "github.com/blocktree/openwallet/v2/common/file" + "github.com/blocktree/openwallet/v2/owtp" "path/filepath" ) @@ -78,7 +79,7 @@ var ( BuildTime = "" ) -//配置 +// 配置 type Config struct { // 远程服务 @@ -127,7 +128,7 @@ type Config struct { //dbReadOnlyMode bool } -//初始化一个配置对象 +// 初始化一个配置对象 func NewConfig(c config.Configer) *Config { conf := &Config{} conf.remoteserver = c.String("remoteserver") @@ -174,6 +175,8 @@ func NewConfig(c config.Configer) *Config { file.MkdirAll(conf.dbdir) file.MkdirAll(conf.exportaddressdir) + owtp.Debug = conf.logdebug + return conf } diff --git a/openwcli/contract_manager.go b/openwcli/contract_manager.go index 32fca59..0c2253a 100644 --- a/openwcli/contract_manager.go +++ b/openwcli/contract_manager.go @@ -24,7 +24,7 @@ import ( "strings" ) -//CallABI 直接调用ABI方法 +// CallABI 直接调用ABI方法 func (cli *CLI) CallABI(account *openwsdk.Account, contractAddress string, abiParam []string) (*openwsdk.SmartContractCallResult, *openwallet.Error) { var ( @@ -85,8 +85,8 @@ func (cli *CLI) CallABI(account *openwsdk.Account, contractAddress string, abiPa return retCallResult, nil } -//TriggerABI 触发合约ABI接口 -func (cli *CLI) TriggerABI(wallet *openwsdk.Wallet, account *openwsdk.Account, contractAddress, contractABI, amount, sid, feeRate, password string, abiParam []string, raw string, rawType uint64, awaitResult bool) (*openwsdk.SmartContractReceipt, *openwallet.Error) { +// TriggerABI 触发合约ABI接口 +func (cli *CLI) TriggerABI(wallet *openwsdk.Wallet, account *openwsdk.Account, symbol, contractAddress, contractABI, amount, sid, feeRate, password string, abiParam []string, raw string, rawType uint64, awaitResult bool) (*openwsdk.SmartContractReceipt, *openwallet.Error) { var ( isContract bool @@ -119,7 +119,7 @@ func (cli *CLI) TriggerABI(wallet *openwsdk.Wallet, account *openwsdk.Account, c } } coin := openwsdk.Coin{ - Symbol: account.Symbol, + Symbol: symbol, IsContract: isContract, ContractID: contractID, ContractAddress: contractAddress, diff --git a/openwcli/contract_manager_test.go b/openwcli/contract_manager_test.go index eada196..fdbda5b 100644 --- a/openwcli/contract_manager_test.go +++ b/openwcli/contract_manager_test.go @@ -77,7 +77,7 @@ func TestCLI_TriggerABI(t *testing.T) { } sid := uuid.New().String() - _, exErr := cli.TriggerABI(wallet, account, contractAddress, "", "0", sid, "", "12345678", abiParam, "", 0, true) + _, exErr := cli.TriggerABI(wallet, account, account.Symbol, contractAddress, "", "0", sid, "", "12345678", abiParam, "", 0, true) if exErr != nil { t.Errorf("TriggerABI failed, err: %v", exErr) return diff --git a/openwcli/trustserver_manager.go b/openwcli/trustserver_manager.go index 77b6ecd..d60a612 100644 --- a/openwcli/trustserver_manager.go +++ b/openwcli/trustserver_manager.go @@ -806,7 +806,7 @@ func (cli *CLI) triggerABIViaTrustNode(ctx *owtp.Context) { } } - retTx, exErr := cli.TriggerABI(wallet, account, contractAddress, contractABI, amount, sid, feeRate, password, abiParam, raw, rawType, awaitResult) + retTx, exErr := cli.TriggerABI(wallet, account, symbol, contractAddress, contractABI, amount, sid, feeRate, password, abiParam, raw, rawType, awaitResult) if exErr != nil { ctx.Response(nil, exErr.Code(), exErr.Error()) return @@ -855,7 +855,7 @@ func (cli *CLI) signHashViaTrustNode(ctx *owtp.Context) { HdPath: hdPath, } - signature, err := cli.SignHash(addr, message, password, rsv) + signature, err := cli.SignHash(addr, symbol, message, password, rsv) if err != nil { ctx.Response(nil, openwallet.ErrSystemException, err.Error()) return diff --git a/openwcli/wallet_manager.go b/openwcli/wallet_manager.go index f302155..a0c5571 100644 --- a/openwcli/wallet_manager.go +++ b/openwcli/wallet_manager.go @@ -315,7 +315,7 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { if list != nil && len(list) > 0 { tableInfo := make([][]interface{}, 0) - for i, w := range list { + for _, w := range list { //读取汇总信息 sumTips := "" @@ -338,13 +338,13 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { }) tableInfo = append(tableInfo, []interface{}{ - i, w.Alias, w.AccountID, w.Symbol, balanceStr, w.AddressIndex + 1, sumTips, + w.Id, w.Alias, w.AccountID, w.Symbol, balanceStr, w.AddressIndex + 1, sumTips, }) } t := gotabulate.Create(tableInfo) // Set Headers - t.SetHeaders([]string{"No.", "Name", "AccountID", "Symbol", "Balance", "Addresses", + t.SetHeaders([]string{"ID", "Name", "AccountID", "Symbol", "Balance", "Addresses", "Setup summary info"}) //打印信息 @@ -509,7 +509,7 @@ func (cli *CLI) GetAddressesOnServer(walletID, accountID, symbol string, lastId, } // printAddressList 打印地址列表 -func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, password string) error { +func (cli *CLI) printAddressList(walletID, symbol string, list []*openwsdk.Address, password string) error { var ( isShowPrivateKey bool @@ -552,7 +552,7 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass for _, a := range list { balanceStr := "0" - cli.api.GetBalanceByAddress(a.Symbol, a.Address, "", + cli.api.GetBalanceByAddress(symbol, a.Address, "", true, func(status uint64, msg string, balance *openwsdk.BalanceResult) { if status == owtp.StatusSuccess { balanceStr = balance.Balance @@ -563,7 +563,7 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass if isShowPrivateKey && key != nil { - selectedSymbol, err := cli.GetSymbolInfo(a.Symbol) + selectedSymbol, err := cli.GetSymbolInfo(symbol) if err != nil { return err } @@ -588,7 +588,7 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass } t := gotabulate.Create(tableInfo) // Set Headers - t.SetHeaders([]string{"No.", "Address", "WalletID", "AccounttID", "Symbol", "Balance", "publicKey", "privateKey"}) + t.SetHeaders([]string{"ID", "Address", "WalletID", "AccounttID", "Symbol", "Balance", "publicKey", "privateKey"}) //打印信息 fmt.Println(t.Render("simple")) @@ -1224,7 +1224,7 @@ func (cli *CLI) IsTrustAddress(address, symbol string) bool { } // SignHash 哈希消息签名 -func (cli *CLI) SignHash(address *openwsdk.Address, message, password string, appendV bool) (string, error) { +func (cli *CLI) SignHash(address *openwsdk.Address, symbol, message, password string, appendV bool) (string, error) { wallet, err := cli.GetWalletByWalletID(address.WalletID) if err != nil { @@ -1237,7 +1237,7 @@ func (cli *CLI) SignHash(address *openwsdk.Address, message, password string, ap return "", err } - symbolInfo, err := cli.GetSymbolInfo(address.Symbol) + symbolInfo, err := cli.GetSymbolInfo(symbol) if err != nil { return "", err } @@ -1256,7 +1256,7 @@ func (cli *CLI) SignHash(address *openwsdk.Address, message, password string, ap if err != nil { return "", err } - + //log.Debugf("address = %+v", address) signature, v, sigErr := owcrypt.Signature(keyBytes, nil, hash, uint32(symbolInfo.Curve)) if sigErr != owcrypt.SUCCESS { return "", fmt.Errorf("sign hash message failed") diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index cce5687..554dc14 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -63,7 +63,7 @@ func TestCLI_GetAccountsOnServer(t *testing.T) { return } - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" + walletID := "WE72vaeN6moqQKvBjXjrZGmxWEFfRKbcC4" accounts, err := cli.GetAccountsOnServer(walletID) if err != nil { log.Error("GetAccountsOnServer error:", err) @@ -80,7 +80,7 @@ func TestCLI_GetAccountOnServer(t *testing.T) { return } - accountID := "A9PfM5Dr62WAtDEC3Pio6G1g27288gSUAJaLom68rSCZ" + accountID := "Eh2ALZguch6DS2JaoFz97ZspvBvv56FjB79CVVkqc1aA" account, err := cli.GetAccountByAccountID("ETH", accountID) if err != nil { log.Error("GetAccountByAccountID error:", err) @@ -112,8 +112,8 @@ func TestCLI_GetAddressesOnServer(t *testing.T) { return } - walletID := "WJ728uvSxc73m6BvfRsjM1v3jGfdimVEAr" - accountID := "A9PfM5Dr62WAtDEC3Pio6G1g27288gSUAJaLom68rSCZ" + walletID := "WE72vaeN6moqQKvBjXjrZGmxWEFfRKbcC4" + accountID := "Eh2ALZguch6DS2JaoFz97ZspvBvv56FjB79CVVkqc1aA" addresses, err := cli.GetAddressesOnServer(walletID, accountID, "ETH", 0, 50) if err != nil { @@ -134,15 +134,15 @@ func TestCLI_SearchAddressOnServer(t *testing.T) { return } - addr := "0x03463372a699f99775000edf9e89104af31c297f" - - address, err := cli.SearchAddressOnServer("ETH", addr) + addr := "0x282425dd54156902ead4a99ec7e80a21213d878d" + symbol := "MATIC" + address, err := cli.SearchAddressOnServer(symbol, addr) if err != nil { log.Error("SearchAddressOnServer error:", err) return } log.Info("address:", address) - cli.printAddressList(address.WalletID, []*openwsdk.Address{address}, "12345678") + cli.printAddressList(address.WalletID, symbol, []*openwsdk.Address{address}, "123456789") } func TestCLI_GetSymbolList(t *testing.T) { From b3ef98c9eb64f8a03e55e8b2bd4f3ebd87889260 Mon Sep 17 00:00:00 2001 From: MZQ Date: Sun, 25 Dec 2022 21:52:10 +0800 Subject: [PATCH 15/26] fix bugs --- go.mod | 2 +- openwcli/cli.go | 28 +++++++----- openwcli/summary_manager.go | 24 +++++----- openwcli/transaction_manager.go | 22 +++++----- openwcli/transaction_manager_test.go | 65 ++++++++++------------------ openwcli/trustserver_manager.go | 2 +- openwcli/wallet_manager.go | 26 +++++------ openwcli/wallet_manager_test.go | 28 ++++++------ 8 files changed, 93 insertions(+), 104 deletions(-) diff --git a/go.mod b/go.mod index cf86d1a..a303678 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.2.2 + github.com/blocktree/go-openw-sdk/v2 v2.4.0 github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 diff --git a/openwcli/cli.go b/openwcli/cli.go index a95398d..2d0a90b 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -344,12 +344,6 @@ func (cli *CLI) NewAddressFlow() error { return err } - // 输入symbol - symbol, err := console.InputText("Enter symbol: ", false) - if err != nil { - return err - } - // 输入地址数量 count, err := console.InputNumber("Enter the number of addresses you want: ", false) if err != nil { @@ -360,7 +354,7 @@ func (cli *CLI) NewAddressFlow() error { return fmt.Errorf("The number of addresses can not exceed %d ", maxAddresNum) } - err = cli.CreateAddressOnServer(account.WalletID, account.AccountID, symbol, count) + err = cli.CreateAddressOnServer(account.WalletID, account.AccountID, account.Symbol, count) if err != nil { return err } @@ -406,7 +400,7 @@ func (cli *CLI) SearchAddressFlow() error { //是否需要显示地址私钥,需要必须填入密码 show, _ := console.Stdin.PromptConfirm("Do want to show address token balance?") if show { - balances, err := cli.GetAllTokenContractBalanceByAddress(address.AccountID, address.Address, address.Symbol) + balances, err := cli.GetAllTokenContractBalanceByAddress(address.WalletID, address.AccountID, address.Address, address.Symbol) if err != nil { return err } @@ -430,6 +424,12 @@ func (cli *CLI) TransferFlow() error { return err } + // 等待用户输入symbol + symbol, err := console.InputText("Enter symbol: ", true) + if err != nil { + return err + } + // 等待用户输入合约地址 contractAddress, err := console.InputText("Enter contract address: ", false) if err != nil { @@ -473,7 +473,7 @@ func (cli *CLI) TransferFlow() error { //创建新交易单 sid := uuid.New().String() - _, _, exErr := cli.Transfer(wallet, account, contractAddress, to, amount, sid, feeRate, memo, password) + _, _, exErr := cli.Transfer(wallet, account, symbol, contractAddress, to, amount, sid, feeRate, memo, password) if exErr != nil { return exErr } @@ -495,6 +495,12 @@ func (cli *CLI) TransferAllFlow() error { return err } + // 等待用户输入symbol + symbol, err := console.InputText("Enter symbol: ", true) + if err != nil { + return err + } + // 等待用户输入合约地址 contractAddress, err := console.InputText("Enter contract address: ", false) if err != nil { @@ -532,7 +538,7 @@ func (cli *CLI) TransferAllFlow() error { //创建新交易单 sid := uuid.New().String() - err = cli.TransferAll(wallet, account, contractAddress, to, sid, feeRate, memo, password) + err = cli.TransferAll(wallet, account, symbol, contractAddress, to, sid, feeRate, memo, password) if err != nil { return err } @@ -947,7 +953,7 @@ func (cli *CLI) ListTokenBalanceFlow() error { return selectErr } - list, err := cli.GetAllTokenContractBalance(account.AccountID, "") + list, err := cli.GetAllTokenContractBalance(account.WalletID, account.AccountID, account.Symbol) if err != nil { return err } diff --git a/openwcli/summary_manager.go b/openwcli/summary_manager.go index 6d7e529..13566b3 100644 --- a/openwcli/summary_manager.go +++ b/openwcli/summary_manager.go @@ -15,7 +15,7 @@ import ( "time" ) -func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, contractAddress, to, sid, feeRate, memo, password string) error { +func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, symbol, contractAddress, to, sid, feeRate, memo, password string) error { var ( isContract bool @@ -48,7 +48,7 @@ func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, if len(contractAddress) > 0 { isContract = true - tokenBalance, findErr := cli.GetTokenBalanceByContractAddress(account, contractAddress) + tokenBalance, findErr := cli.GetTokenBalanceByContractAddress(account, symbol, contractAddress) if findErr != nil { return findErr } @@ -57,7 +57,7 @@ func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, balance = tokenBalance.Balance } else { balance = "0" - cli.api.GetBalanceByAccount(account.Symbol, account.AccountID, "", + cli.api.GetBalanceByAccount(symbol, account.AccountID, "", true, func(status uint64, msg string, accBalance *openwsdk.BalanceResult) { if status == owtp.StatusSuccess { balance = accBalance.Balance @@ -66,12 +66,12 @@ func (cli *CLI) TransferAll(wallet *openwsdk.Wallet, account *openwsdk.Account, } coin := openwsdk.Coin{ - Symbol: account.Symbol, + Symbol: symbol, IsContract: isContract, ContractID: contractID, } - log.Infof("Summary account[%s] Symbol: %s, token: %s ", account.AccountID, account.Symbol, tokenSymbol) + log.Infof("Summary account[%s] Symbol: %s, token: %s ", account.AccountID, symbol, tokenSymbol) //汇总账户 err = cli.summaryAccount(account, accountTask, key, balance, *accountTask.SummarySetting, coin, "", decimal.Zero) @@ -216,7 +216,7 @@ func (cli *CLI) SummaryAccountTokenContracts(accountTask *openwsdk.SummaryAccoun symbol = account.Symbol } - tokenBalances, err := cli.GetAllTokenContractBalance(account.AccountID, symbol) + tokenBalances, err := cli.GetAllTokenContractBalance(account.WalletID, account.AccountID, symbol) if err != nil { return err } @@ -272,11 +272,11 @@ func (cli *CLI) SummaryAccountTokenContracts(accountTask *openwsdk.SummaryAccoun ContractID: token.ContractID, } - log.Infof("Summary account[%s] Symbol: %s, token: %s start", account.AccountID, symbol, token.Token) + log.Infof("Summary account[%s] Symbol: %s, token: %s start", account.AccountID, symbol, token.ContractToken) - err = cli.summaryAccountProcess(account, accountTask, key, token.Balance.Balance, *contrackTask.SummarySetting, coin) + err = cli.summaryAccountProcess(account, accountTask, key, token.Balance, *contrackTask.SummarySetting, coin) - log.Infof("Summary account[%s] Symbol: %s, token: %s end", account.AccountID, symbol, token.Token) + log.Infof("Summary account[%s] Symbol: %s, token: %s end", account.AccountID, symbol, token.ContractToken) if err != nil { continue @@ -316,7 +316,7 @@ func (cli *CLI) summaryAccountProcess(account *openwsdk.Account, task *openwsdk. if len(contractAddress) == 0 { return fmt.Errorf("fees support account use token contract for fees, contract address is empty") } - tokenBalance, err := cli.GetTokenBalanceByContractAddress(feesSupportAccounInfo, task.FeesSupportAccount.ContractAddress) + tokenBalance, err := cli.GetTokenBalanceByContractAddress(feesSupportAccounInfo, task.Symbol, task.FeesSupportAccount.ContractAddress) if err == nil { feesSupportBalance, _ = decimal.NewFromString(tokenBalance.Balance) } @@ -404,10 +404,10 @@ func (cli *CLI) summaryAccount(account *openwsdk.Account, task *openwsdk.Summary task.FeeRate, sumSets.MinTransfer, sumSets.RetainedBalance, i, addressLimit, sumSets.Confirms, sid, task.FeesSupportAccount, task.Memo, true, func(status uint64, msg string, rawTxs []*openwsdk.RawTransaction) { - //log.Debugf("status: %d, msg: %s", status, msg) + log.Debugf("status: %d, msg: %s", status, msg) for _, rawTx := range rawTxs { //log.Debugf("rawTx.ErrorMsg: %s", rawTx.ErrorMsg.Err) - if rawTx.ErrorMsg != nil && rawTx.ErrorMsg.Code != 0 { + if rawTx.ErrorMsg != nil && rawTx.ErrorMsg.Code != "" { log.Warning(rawTx.ErrorMsg.Err) } else { diff --git a/openwcli/transaction_manager.go b/openwcli/transaction_manager.go index d278c7b..8ff786c 100644 --- a/openwcli/transaction_manager.go +++ b/openwcli/transaction_manager.go @@ -21,18 +21,18 @@ func (cli *CLI) GetTokenBalance(account *openwsdk.Account, contractID string) st } // GetTokenBalanceByContractAddress 通过代币合约的地址获取代币余额 -func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, address string) (*openwsdk.BalanceResult, error) { +func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, symbol, address string) (*openwsdk.BalanceResult, error) { var ( getBalance *openwsdk.BalanceResult callErr error ) - token, findErr := cli.GetTokenContractList("Symbol", account.Symbol, "Address", address) + token, findErr := cli.GetTokenContractList("Symbol", symbol, "Address", address) if findErr != nil { return nil, findErr } contractID := token[0].ContractID - err := cli.api.GetBalanceByAccount(account.Symbol, account.AccountID, contractID, true, + err := cli.api.GetBalanceByAccount(symbol, account.AccountID, contractID, true, func(status uint64, msg string, balance *openwsdk.BalanceResult) { if status == owtp.StatusSuccess { getBalance = balance @@ -51,12 +51,12 @@ func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, addr } // Transfer 转账交易 -func (cli *CLI) Transfer(wallet *openwsdk.Wallet, account *openwsdk.Account, contractAddress, to, amount, sid, feeRate, memo, password string) ([]*openwsdk.Transaction, []*openwsdk.FailedRawTransaction, *openwallet.Error) { - return cli.TransferExt(wallet, account, contractAddress, to, amount, sid, feeRate, memo, "", password) +func (cli *CLI) Transfer(wallet *openwsdk.Wallet, account *openwsdk.Account, symbol, contractAddress, to, amount, sid, feeRate, memo, password string) ([]*openwsdk.Transaction, []*openwsdk.FailedRawTransaction, *openwallet.Error) { + return cli.TransferExt(wallet, account, symbol, contractAddress, to, amount, sid, feeRate, memo, "", password) } // TransferExt 转账交易 + 扩展参数 -func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, contractAddress, to, amount, sid, feeRate, memo, extParam, password string) ([]*openwsdk.Transaction, []*openwsdk.FailedRawTransaction, *openwallet.Error) { +func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, symbol, contractAddress, to, amount, sid, feeRate, memo, extParam, password string) ([]*openwsdk.Transaction, []*openwsdk.FailedRawTransaction, *openwallet.Error) { var ( isContract bool @@ -70,7 +70,7 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, ) //:检查目标地址是否信任名单 - if !cli.IsTrustAddress(to, account.Symbol) { + if !cli.IsTrustAddress(to, symbol) { return nil, nil, openwallet.Errorf(openwallet.ErrUnknownException, "%s is not in trust address list", to) } @@ -86,7 +86,7 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, if len(contractAddress) > 0 { isContract = true - token, findErr := cli.GetTokenContractList("Symbol", account.Symbol, "Address", contractAddress) + token, findErr := cli.GetTokenContractList("Symbol", symbol, "Address", contractAddress) if findErr != nil { return nil, nil, openwallet.ConvertError(findErr) } @@ -94,13 +94,13 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, tokenSymbol = token[0].Token } coin := openwsdk.Coin{ - Symbol: account.Symbol, + Symbol: symbol, IsContract: isContract, ContractID: contractID, } api := cli.api - err = api.CreateTrade(account.AccountID, sid, coin, map[string]string{"to": amount}, feeRate, memo, extParam, true, + err = api.CreateTrade(account.AccountID, sid, coin, map[string]string{to: amount}, feeRate, memo, extParam, true, func(status uint64, msg string, rawTx *openwsdk.RawTransaction) { if status != owtp.StatusSuccess { createErr = openwallet.Errorf(status, msg) @@ -117,7 +117,7 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, //:打印交易单明细 log.Infof("-----------------------------------------------") - log.Infof("[%s %s Transfer]", account.Symbol, tokenSymbol) + log.Infof("[%s %s Transfer]", symbol, tokenSymbol) log.Infof("SID: %s", retRawTx.Sid) log.Infof("From Account: %s", account.AccountID) log.Infof("To Address: %s", to) diff --git a/openwcli/transaction_manager_test.go b/openwcli/transaction_manager_test.go index ad0fb11..32ed48e 100644 --- a/openwcli/transaction_manager_test.go +++ b/openwcli/transaction_manager_test.go @@ -31,7 +31,7 @@ func testCLITransfer(walletID, accountID, symbol, contractAddress, amount, to, m return openwallet.ConvertError(err) } - account, err := cli.GetAccountByAccountID(accountID, symbol) + account, err := cli.GetAccountByAccountID(symbol, accountID) if err != nil { //log.Error("GetAccountByAccountID error:", err) return openwallet.ConvertError(err) @@ -39,7 +39,7 @@ func testCLITransfer(walletID, accountID, symbol, contractAddress, amount, to, m if account != nil { sid := uuid.New().String() - _, _, exErr := cli.Transfer(wallet, account, contractAddress, to, amount, sid, "", memo, password) + _, _, exErr := cli.Transfer(wallet, account, symbol, contractAddress, to, amount, sid, "", memo, password) if exErr != nil { //log.Error("Transfer error code: %d, msg: %s", exErr.Code(), exErr.Error()) return exErr @@ -61,7 +61,7 @@ func testCLITransferAll(walletID, accountID, symbol, to, password string) *openw return openwallet.ConvertError(err) } - account, err := cli.GetAccountByAccountID(accountID, symbol) + account, err := cli.GetAccountByAccountID(symbol, accountID) if err != nil { //log.Error("GetAccountByAccountID error:", err) return openwallet.ConvertError(err) @@ -69,7 +69,7 @@ func testCLITransferAll(walletID, accountID, symbol, to, password string) *openw if account != nil { sid := uuid.New().String() - exErr := cli.TransferAll(wallet, account, "", to, sid, "", "", password) + exErr := cli.TransferAll(wallet, account, "MATIC", "", to, sid, "", "", password) if exErr != nil { //log.Error("Transfer error code: %d, msg: %s", exErr.Code(), exErr.Error()) return openwallet.ConvertError(err) @@ -92,50 +92,18 @@ func TestCLI_Transfer_LTC(t *testing.T) { } } -func TestCLI_TransferAll_LTC(t *testing.T) { - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" - accountID := "PgHCcfMbcw1zXRNZo23NFjRdBmcN5tzrb1j5McRLJbG" - to := "LcaFc1pmJBsS7MQyMvZaboppuuvGFubD49" - password := "12345678" - err := testCLITransferAll(walletID, accountID, "ETH", to, password) +func TestCLI_TransferAll_Coin(t *testing.T) { + walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" + accountID := "3BSJAseva4A2oZgmEuMEVtdSgnj5UXCunYzyWtK7dj4b" + to := "0x8C178b782fab1d0686D88bC16B31F80431098fa1" + password := "1234qwer" + err := testCLITransferAll(walletID, accountID, "MATIC", to, password) if err != nil { t.Errorf("Transfer All error code: %d, msg: %s", err.Code(), err.Error()) return } } -func TestCLI_Transfer_BTC(t *testing.T) { - cli := getTestOpenwCLI() - if cli == nil { - return - } - - wallets, err := cli.GetWalletsOnServer() - if err != nil { - log.Error("GetWalletsOnServer error:", err) - return - } - - if len(wallets) > 0 { - accounts, err := cli.GetAccountsOnServer(wallets[0].WalletID) - if err != nil { - log.Error("GetAccountsOnServer error:", err) - return - } - - account := testFindAccountByID("J3wiDj2jMGdp9aqmALhQtEkJQch4YN9e38TEXzRgZyKY", accounts) - - if account != nil { - sid := uuid.New().String() - _, _, exErr := cli.Transfer(wallets[0], accounts[0], "", "mp1JDsi7Dr2PkcWu1j4SUSTXJqXjFMaeVx", "0.023", sid, "", "", "12345678") - if err != nil { - log.Error("Transfer error code: %d, msg: %s", exErr.Code(), exErr.Error()) - return - } - } - } -} - func TestCLI_Summary_BTC(t *testing.T) { cli := getTestOpenwCLI() @@ -260,3 +228,16 @@ func TestCLI_Transfer_Token(t *testing.T) { } } + +func TestCLI_Transfer_MATIC(t *testing.T) { + walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" + accountID := "3BSJAseva4A2oZgmEuMEVtdSgnj5UXCunYzyWtK7dj4b" + amount := "0.01" + to := "0x8C178b782fab1d0686D88bC16B31F80431098fa1" + password := "1234qwer" + err := testCLITransfer(walletID, accountID, "MATIC", "", amount, to, "", password) + if err != nil { + t.Errorf("Transfer error code: %d, msg: %s", err.Code(), err.Error()) + return + } +} diff --git a/openwcli/trustserver_manager.go b/openwcli/trustserver_manager.go index d60a612..355415a 100644 --- a/openwcli/trustserver_manager.go +++ b/openwcli/trustserver_manager.go @@ -294,7 +294,7 @@ func (cli *CLI) sendTransactionViaTrustNode(ctx *owtp.Context) { } } - retTx, retFailed, exErr := cli.TransferExt(wallet, account, contractAddress, address, amount, sid, feeRate, memo, extParam, password) + retTx, retFailed, exErr := cli.TransferExt(wallet, account, symbol, contractAddress, address, amount, sid, feeRate, memo, extParam, password) if exErr != nil { ctx.Response(nil, exErr.Code(), exErr.Error()) return diff --git a/openwcli/wallet_manager.go b/openwcli/wallet_manager.go index a0c5571..ecd236b 100644 --- a/openwcli/wallet_manager.go +++ b/openwcli/wallet_manager.go @@ -315,7 +315,7 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { if list != nil && len(list) > 0 { tableInfo := make([][]interface{}, 0) - for _, w := range list { + for i, w := range list { //读取汇总信息 sumTips := "" @@ -338,13 +338,13 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { }) tableInfo = append(tableInfo, []interface{}{ - w.Id, w.Alias, w.AccountID, w.Symbol, balanceStr, w.AddressIndex + 1, sumTips, + i, w.Id, w.Alias, w.AccountID, w.Symbol, balanceStr, w.AddressIndex + 1, sumTips, }) } t := gotabulate.Create(tableInfo) // Set Headers - t.SetHeaders([]string{"ID", "Name", "AccountID", "Symbol", "Balance", "Addresses", + t.SetHeaders([]string{"No.", "ID", "Name", "AccountID", "Symbol", "Balance", "Addresses", "Setup summary info"}) //打印信息 @@ -909,14 +909,14 @@ func (cli *CLI) getLocalKeyByWallet(wallet *openwsdk.Wallet, password string) (* } // GetAllTokenContractBalance 查询账户合约余额 -func (cli *CLI) GetAllTokenContractBalance(accountID string, symbol string) ([]*openwsdk.TokenBalance, error) { +func (cli *CLI) GetAllTokenContractBalance(walletID, accountID string, symbol string) ([]*openwsdk.BalanceResult, error) { var ( getErr error - getBalances []*openwsdk.TokenBalance + getBalances []*openwsdk.BalanceResult ) - err := cli.api.GetAllTokenBalanceByAccount(accountID, symbol, true, - func(status uint64, msg string, balance []*openwsdk.TokenBalance) { + err := cli.api.GetAllTokenBalanceByAccount(walletID, accountID, symbol, true, + func(status uint64, msg string, balance []*openwsdk.BalanceResult) { if status == owtp.StatusSuccess { getBalances = balance } else { @@ -935,14 +935,14 @@ func (cli *CLI) GetAllTokenContractBalance(accountID string, symbol string) ([]* } // GetAllTokenContractBalanceByAddress 查询地址合约余额 -func (cli *CLI) GetAllTokenContractBalanceByAddress(accountID, address, symbol string) ([]*openwsdk.TokenBalance, error) { +func (cli *CLI) GetAllTokenContractBalanceByAddress(walletID, accountID, address, symbol string) ([]*openwsdk.BalanceResult, error) { var ( getErr error - getBalances []*openwsdk.TokenBalance + getBalances []*openwsdk.BalanceResult ) - err := cli.api.GetAllTokenBalanceByAddress(accountID, address, symbol, true, - func(status uint64, msg string, balance []*openwsdk.TokenBalance) { + err := cli.api.GetAllTokenBalanceByAddress(walletID, accountID, address, symbol, true, + func(status uint64, msg string, balance []*openwsdk.BalanceResult) { if status == owtp.StatusSuccess { getBalances = balance } else { @@ -970,7 +970,7 @@ func findTokenContractByID(tokenList []*openwsdk.TokenContract, contractID strin } // printTokenContractBalanceList 打印账户代币合约余额列表 -func (cli *CLI) printTokenContractBalanceList(list []*openwsdk.TokenBalance, symbol string) { +func (cli *CLI) printTokenContractBalanceList(list []*openwsdk.BalanceResult, symbol string) { if list != nil && len(list) > 0 { tableInfo := make([][]interface{}, 0) @@ -989,7 +989,7 @@ func (cli *CLI) printTokenContractBalanceList(list []*openwsdk.TokenBalance, sym } tableInfo = append(tableInfo, []interface{}{ - w.ContractID, token.Symbol, token.Name, w.Token, token.Address, token.Protocol, w.Balance.Balance, + w.ContractID, token.Symbol, token.Name, w.ContractToken, token.Address, token.Protocol, w.Balance, }) } diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index 554dc14..7f45cc5 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -41,7 +41,7 @@ func TestCLI_CreateAccountOnServer(t *testing.T) { if cli == nil { return } - walletID := "WJ728uvSxc73m6BvfRsjM1v3jGfdimVEAr" + walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" wallet, err := cli.GetWalletByWalletID(walletID) if err != nil { log.Error("GetWalletByWalletID error:", err) @@ -49,7 +49,7 @@ func TestCLI_CreateAccountOnServer(t *testing.T) { } if wallet != nil { - _, _, err = cli.CreateAccountOnServer("testETH", "12345678", "ETH", wallet) + _, _, err = cli.CreateAccountOnServer("test2MATIC", "1234qwer", "MATIC", wallet) if err != nil { log.Error("CreateAccountOnServer error:", err) return @@ -63,7 +63,7 @@ func TestCLI_GetAccountsOnServer(t *testing.T) { return } - walletID := "WE72vaeN6moqQKvBjXjrZGmxWEFfRKbcC4" + walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" accounts, err := cli.GetAccountsOnServer(walletID) if err != nil { log.Error("GetAccountsOnServer error:", err) @@ -80,8 +80,8 @@ func TestCLI_GetAccountOnServer(t *testing.T) { return } - accountID := "Eh2ALZguch6DS2JaoFz97ZspvBvv56FjB79CVVkqc1aA" - account, err := cli.GetAccountByAccountID("ETH", accountID) + accountID := "3BSJAseva4A2oZgmEuMEVtdSgnj5UXCunYzyWtK7dj4b" + account, err := cli.GetAccountByAccountID("MATIC", accountID) if err != nil { log.Error("GetAccountByAccountID error:", err) return @@ -239,13 +239,14 @@ func TestCLI_GetAllTokenContractBalance(t *testing.T) { if cli == nil { return } - accountID := "DCgKWqyefttTqWbyS4ihFsyyvL4jHcF4XBTa3KAGwEmF" - list, err := cli.GetAllTokenContractBalance(accountID, "") + walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" + accountID := "3BSJAseva4A2oZgmEuMEVtdSgnj5UXCunYzyWtK7dj4b" + list, err := cli.GetAllTokenContractBalance(walletID, accountID, "MATIC") if err != nil { log.Error("GetAllTokenContractBalance error:", err) return } - cli.printTokenContractBalanceList(list, "TRX") + cli.printTokenContractBalanceList(list, "MATIC") } func TestCLI_GetAllTokenContractBalanceByAddress(t *testing.T) { @@ -253,14 +254,15 @@ func TestCLI_GetAllTokenContractBalanceByAddress(t *testing.T) { if cli == nil { return } - accountID := "BBxgBEn7AoRhNqsS7vjD625B5SafFFdY1QMX7Zq8M9jn" - address := "WhWV4XcD7UJzt2bAcVe48PN1Cxwh8HAyoi" - list, err := cli.GetAllTokenContractBalanceByAddress(accountID, address, "WICC") + walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" + accountID := "3BSJAseva4A2oZgmEuMEVtdSgnj5UXCunYzyWtK7dj4b" + address := "0xc27992b757a3c00ed3cb1dfa7dfb1a59d70dbd0f" + list, err := cli.GetAllTokenContractBalanceByAddress(walletID, accountID, address, "MATIC") if err != nil { log.Error("GetAllTokenContractBalance error:", err) return } - cli.printTokenContractBalanceList(list, "WICC") + cli.printTokenContractBalanceList(list, "MATIC") } func TestCLI_printAccountSummaryInfo(t *testing.T) { @@ -279,7 +281,7 @@ func TestCLI_GetTokenBalanceByContractAddresss(t *testing.T) { accountID := "DCgKWqyefttTqWbyS4ihFsyyvL4jHcF4XBTa3KAGwEmF" address := "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur" account := &openwsdk.Account{Symbol: "TRX", AccountID: accountID} - balance, err := cli.GetTokenBalanceByContractAddress(account, address) + balance, err := cli.GetTokenBalanceByContractAddress(account, "TRX", address) if err != nil { t.Errorf("GetAllTokenContractBalance error: %v", err) return From 5bd482b951f8891f6b7eb474651576ca3fc7e654 Mon Sep 17 00:00:00 2001 From: MZQ Date: Mon, 26 Dec 2022 09:34:20 +0800 Subject: [PATCH 16/26] update workflows --- .github/workflows/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cc6f359..11640f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,9 +19,10 @@ jobs: echo "OPENWCLIBINARY=openw-cli-$(git describe --tags `git rev-list --tags --max-count=1`)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "OPENWCLILDFLAGS=-X github.com/blocktree/go-openw-cli/v2/openwcli.Version=$(git describe --tags `git rev-list --tags --max-count=1`) -X github.com/blocktree/go-openw-cli/v2/openwcli.GitRev=$(git rev-parse --short HEAD) -X github.com/blocktree/go-openw-cli/v2/openwcli.BuildTime=$(date +'%Y-%m-%d_%T')" >> $GITHUB_ENV - name: Build with xgo - uses: crazy-max/ghaction-xgo@v1.6.1 + uses: crazy-max/ghaction-xgo@v2 with: - go_version: 1.19.2 + xgo_version: latest + go_version: 1.18 dest: build/ prefix: ${{ env.OPENWCLIBINARY }} targets: darwin-10.10/amd64,linux/amd64,windows-6.0/* From 3c248051ba0e616bded898562c92e3ed8142230c Mon Sep 17 00:00:00 2001 From: MZQ Date: Mon, 26 Dec 2022 09:52:22 +0800 Subject: [PATCH 17/26] update workflows --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11640f6..28a1363 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: uses: crazy-max/ghaction-xgo@v2 with: xgo_version: latest - go_version: 1.18 + go_version: 1.12 dest: build/ prefix: ${{ env.OPENWCLIBINARY }} targets: darwin-10.10/amd64,linux/amd64,windows-6.0/* From 80e8c9d2013b1edae1ca81f97fe19a5ece0aeb57 Mon Sep 17 00:00:00 2001 From: ZQM Date: Mon, 26 Dec 2022 09:57:20 +0800 Subject: [PATCH 18/26] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 28a1363..11640f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: uses: crazy-max/ghaction-xgo@v2 with: xgo_version: latest - go_version: 1.12 + go_version: 1.18 dest: build/ prefix: ${{ env.OPENWCLIBINARY }} targets: darwin-10.10/amd64,linux/amd64,windows-6.0/* From 552571b3104ce7be800c3fd38ac2f0805e1c46dc Mon Sep 17 00:00:00 2001 From: MZQ Date: Thu, 29 Dec 2022 13:30:53 +0800 Subject: [PATCH 19/26] add command `listaddressbalance` --- commands/commands.go | 65 ++++++++++++++++++++++----------- go.mod | 2 +- openwcli/cli.go | 44 ++++++++++++++++++++++ openwcli/transaction_manager.go | 3 ++ openwcli/wallet_manager.go | 63 +++++++++++++++++++++++++++++++- openwcli/wallet_manager_test.go | 6 +-- 6 files changed, 156 insertions(+), 27 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 58a073c..7591b5b 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -251,6 +251,15 @@ var ( Category: "WALLET COMMANDS", Flags: []cli.Flag{}, }, + { + + Name: "listaddressbalance", + Usage: "show account all address native/token balance", + ArgsUsage: "", + Action: listaddressbalance, + Category: "WALLET COMMANDS", + Flags: []cli.Flag{}, + }, } ) @@ -275,7 +284,7 @@ func getCLI(c *cli.Context) *openwcli.CLI { return cli } -//register 注册 +// register 注册 func noderegister(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -288,7 +297,7 @@ func noderegister(c *cli.Context) error { return nil } -//nodeinfo +// nodeinfo func nodeinfo(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -302,7 +311,7 @@ func nodeinfo(c *cli.Context) error { return nil } -//newwallet 创建钱包 +// newwallet 创建钱包 func newwallet(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -316,7 +325,7 @@ func newwallet(c *cli.Context) error { return nil } -//listwallet 钱包配置 +// listwallet 钱包配置 func listwallet(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -330,7 +339,7 @@ func listwallet(c *cli.Context) error { return nil } -//newaccount 创建账户 +// newaccount 创建账户 func newaccount(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -344,7 +353,7 @@ func newaccount(c *cli.Context) error { return nil } -//listaccount 账户列表 +// listaccount 账户列表 func listaccount(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -358,7 +367,7 @@ func listaccount(c *cli.Context) error { return nil } -//newaddress 创建地址 +// newaddress 创建地址 func newaddress(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -372,7 +381,7 @@ func newaddress(c *cli.Context) error { return nil } -//searchaddress 查询地址 +// searchaddress 查询地址 func searchaddress(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -386,7 +395,7 @@ func searchaddress(c *cli.Context) error { return nil } -//transfer 转账交易 +// transfer 转账交易 func transfer(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -400,7 +409,7 @@ func transfer(c *cli.Context) error { return nil } -//transferall 转账全部资产交易 +// transferall 转账全部资产交易 func transferall(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -414,7 +423,7 @@ func transferall(c *cli.Context) error { return nil } -//setsum 设置汇总 +// setsum 设置汇总 func setsum(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -428,7 +437,7 @@ func setsum(c *cli.Context) error { return nil } -//startsum 定时汇总 +// startsum 定时汇总 func startsum(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -444,7 +453,7 @@ func startsum(c *cli.Context) error { return nil } -//updateinfo 更新区块链资料库 +// updateinfo 更新区块链资料库 func updateinfo(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -458,7 +467,7 @@ func updateinfo(c *cli.Context) error { return nil } -//listsymbol 查看所有币种信息列表 +// listsymbol 查看所有币种信息列表 func listsymbol(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -472,7 +481,7 @@ func listsymbol(c *cli.Context) error { return nil } -//listtokencontract 查看某个区块链所有代币合约信息列表 +// listtokencontract 查看某个区块链所有代币合约信息列表 func listtokencontract(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -486,7 +495,7 @@ func listtokencontract(c *cli.Context) error { return nil } -//listaddress 查看账户所有地址 +// listaddress 查看账户所有地址 func listaddress(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -500,7 +509,7 @@ func listaddress(c *cli.Context) error { return nil } -//trustserver 启动后台托管钱包服务 +// trustserver 启动后台托管钱包服务 func trustserver(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -539,7 +548,7 @@ func listsuminfo(c *cli.Context) error { return nil } -//listtokenbalance +// listtokenbalance func listtokenbalance(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -609,7 +618,7 @@ func disabletrustaddress(c *cli.Context) error { return nil } -//callabi 直接调用ABI +// callabi 直接调用ABI func callabi(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -623,7 +632,7 @@ func callabi(c *cli.Context) error { return nil } -//triggerabi 触发ABI上链交易 +// triggerabi 触发ABI上链交易 func triggerabi(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -637,7 +646,7 @@ func triggerabi(c *cli.Context) error { return nil } -//signhash 消息签名 +// signhash 消息签名 func signhash(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -650,3 +659,17 @@ func signhash(c *cli.Context) error { return nil } + +// listaddressbalance +func listaddressbalance(c *cli.Context) error { + + if cli := getCLI(c); cli != nil { + err := cli.ListAddressBalanceFlow() + if err != nil { + log.Error("unexpected error: ", err) + return err + } + } + + return nil +} diff --git a/go.mod b/go.mod index a303678..e82baeb 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.4.0 + github.com/blocktree/go-openw-sdk/v2 v2.4.1 github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 diff --git a/openwcli/cli.go b/openwcli/cli.go index 2d0a90b..2b8cdd2 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -1273,3 +1273,47 @@ func (cli *CLI) SignHashFlow() error { return nil } + +// ListAddressBalanceFlow +func (cli *CLI) ListAddressBalanceFlow() error { + + //:选择钱包 + wallet, err := cli.SelectWalletStep() + if err != nil { + return err + } + + //:选择账户 + account, err := cli.SelectAccountStep(wallet.WalletID) + if err != nil { + return err + } + + // 等待用户输入币种类型 + opType, err := console.InputNumber("Enter coin type(0: All, 1: Native, 2: Token): ", true) + if err != nil { + return err + } + + lastId, err := console.InputNumber("Enter last ID: ", true) + if err != nil { + return err + } + + limit, err := console.InputNumber("Enter limit: ", true) + if err != nil { + return err + } + + addresses, err := cli.GetAddressesBalance(account.WalletID, account.AccountID, account.Symbol, int(opType), int(lastId), int(limit)) + if err != nil { + return err + } + + err = cli.printAddressBalanceList(addresses) + if err != nil { + return err + } + + return nil +} diff --git a/openwcli/transaction_manager.go b/openwcli/transaction_manager.go index 8ff786c..cc962ec 100644 --- a/openwcli/transaction_manager.go +++ b/openwcli/transaction_manager.go @@ -90,6 +90,9 @@ func (cli *CLI) TransferExt(wallet *openwsdk.Wallet, account *openwsdk.Account, if findErr != nil { return nil, nil, openwallet.ConvertError(findErr) } + if len(token) == 0 { + return nil, nil, openwallet.Errorf(openwallet.ErrSystemException, "can not find contract address") + } contractID = token[0].ContractID tokenSymbol = token[0].Token } diff --git a/openwcli/wallet_manager.go b/openwcli/wallet_manager.go index ecd236b..8d0fb19 100644 --- a/openwcli/wallet_manager.go +++ b/openwcli/wallet_manager.go @@ -582,13 +582,39 @@ func (cli *CLI) printAddressList(walletID, symbol string, list []*openwsdk.Addre } tableInfo = append(tableInfo, []interface{}{ - a.Id, a.Address, a.WalletID, a.AccountID, a.Symbol, balanceStr, a.PublicKey, privatekey, + a.Id, a.Address, a.WalletID, a.AccountID, symbol, balanceStr, a.PublicKey, privatekey, }) } t := gotabulate.Create(tableInfo) // Set Headers - t.SetHeaders([]string{"ID", "Address", "WalletID", "AccounttID", "Symbol", "Balance", "publicKey", "privateKey"}) + t.SetHeaders([]string{"ID", "Address", "WalletID", "AccountID", "Symbol", "Balance", "publicKey", "privateKey"}) + + //打印信息 + fmt.Println(t.Render("simple")) + } else { + fmt.Println("No address was created locally. ") + } + + return nil +} + +// printAddressBalanceList 打印地址余额列表 +func (cli *CLI) printAddressBalanceList(list []*openwsdk.BalanceResult) error { + + if list != nil && len(list) > 0 { + tableInfo := make([][]interface{}, 0) + + for _, a := range list { + + tableInfo = append(tableInfo, []interface{}{ + a.ID, a.Address, a.Symbol, a.ContractToken, a.Balance, + }) + + } + t := gotabulate.Create(tableInfo) + // Set Headers + t.SetHeaders([]string{"ID", "Address", "Symbol", "Token", "Balance"}) //打印信息 fmt.Println(t.Render("simple")) @@ -1268,3 +1294,36 @@ func (cli *CLI) SignHash(address *openwsdk.Address, symbol, message, password st return hex.EncodeToString(signature), nil } + +// GetAddressesBalance +func (cli *CLI) GetAddressesBalance(walletID, accountID, symbol string, opType, lastId, limit int) ([]*openwsdk.BalanceResult, error) { + + var ( + retErr error + ) + + list := make([]*openwsdk.BalanceResult, 0) + + if len(accountID) == 0 { + return nil, fmt.Errorf("accountID is empty. ") + } + + if len(walletID) == 0 { + return nil, fmt.Errorf("walleID is empty. ") + } + + err := cli.api.GetAddressBalanceList(walletID, accountID, "", symbol, "", opType, lastId, limit, + true, func(status uint64, msg string, balances []*openwsdk.BalanceResult) { + if status == owtp.StatusSuccess { + list = balances + } else { + log.Error("get address on server failed, unexpected error:", msg) + retErr = openwallet.Errorf(status, msg) + } + }) + if err != nil { + return nil, err + } + + return list, retErr +} diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index 7f45cc5..ebecedd 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -134,7 +134,7 @@ func TestCLI_SearchAddressOnServer(t *testing.T) { return } - addr := "0x282425dd54156902ead4a99ec7e80a21213d878d" + addr := "0x4247f631804e9fbd5c9d27428617658bd70fa382" symbol := "MATIC" address, err := cli.SearchAddressOnServer(symbol, addr) if err != nil { @@ -142,7 +142,7 @@ func TestCLI_SearchAddressOnServer(t *testing.T) { return } log.Info("address:", address) - cli.printAddressList(address.WalletID, symbol, []*openwsdk.Address{address}, "123456789") + cli.printAddressList(address.WalletID, symbol, []*openwsdk.Address{address}, "") } func TestCLI_GetSymbolList(t *testing.T) { @@ -180,7 +180,7 @@ func TestCLI_GetTokenContractList(t *testing.T) { if cli == nil { return } - tokens, err := cli.GetTokenContractList("Symbol", "ETP", "Address", "dna") + tokens, err := cli.GetTokenContractList("Symbol", "MATIC", "Address", "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174") if err != nil { log.Error("GetTokenContractList error:", err) return From 112cb64464967b9049290d900c8c4de3f59c8ab0 Mon Sep 17 00:00:00 2001 From: MZQ Date: Fri, 6 Jan 2023 11:21:18 +0800 Subject: [PATCH 20/26] `triggerabi` command add `contract abi` param input --- openwcli/cli.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openwcli/cli.go b/openwcli/cli.go index 2b8cdd2..2674465 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -1154,6 +1154,12 @@ func (cli *CLI) TriggerABIFlow() error { return err } + // 等待用户输入合约ABI JSON + abiJSonInput, err := console.InputText("Enter Contract ABI:", false) + if err != nil { + return err + } + // 等待用户输入ABI参数 abiInput, err := console.InputText("Enter ABI parameters: ", false) if err != nil { @@ -1182,7 +1188,7 @@ func (cli *CLI) TriggerABIFlow() error { //创建新交易单 sid := uuid.New().String() - _, exErr := cli.TriggerABI(wallet, account, account.Symbol, contractAddress, "", "0", sid, feeRate, password, abiParam, "", 0, true) + _, exErr := cli.TriggerABI(wallet, account, account.Symbol, contractAddress, abiJSonInput, "0", sid, feeRate, password, abiParam, "", 0, true) if exErr != nil { return exErr } From db4f2af776291a1ceac5457945475f98ed43163c Mon Sep 17 00:00:00 2001 From: MZQ Date: Tue, 21 Mar 2023 18:19:31 +0800 Subject: [PATCH 21/26] update mod --- .github/workflows/main.yml | 1 + go.mod | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11640f6..4bf9156 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,7 @@ on: push: tags: - v* + workflow_dispatch: jobs: build: diff --git a/go.mod b/go.mod index e82baeb..18ddf9a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.4.1 + github.com/blocktree/go-openw-sdk/v2 v2.4.2 github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 From 42fb8aa47beeeac0868fb2321342bbc2a8ae03b9 Mon Sep 17 00:00:00 2001 From: MZQ Date: Tue, 21 Mar 2023 18:29:37 +0800 Subject: [PATCH 22/26] update main.yml --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4bf9156..8cef18d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,9 @@ jobs: echo "GITREV=$(git describe --tags `git rev-list --tags --max-count=1`)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "OPENWCLIBINARY=openw-cli-$(git describe --tags `git rev-list --tags --max-count=1`)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "OPENWCLILDFLAGS=-X github.com/blocktree/go-openw-cli/v2/openwcli.Version=$(git describe --tags `git rev-list --tags --max-count=1`) -X github.com/blocktree/go-openw-cli/v2/openwcli.GitRev=$(git rev-parse --short HEAD) -X github.com/blocktree/go-openw-cli/v2/openwcli.BuildTime=$(date +'%Y-%m-%d_%T')" >> $GITHUB_ENV + - name: go mod tidy + run: | + go mod tidy - name: Build with xgo uses: crazy-max/ghaction-xgo@v2 with: From d8b8615e1985d38fc05127d2e980343c90f651dd Mon Sep 17 00:00:00 2001 From: MZQ Date: Tue, 21 Mar 2023 18:45:50 +0800 Subject: [PATCH 23/26] update main.yml --- .github/workflows/main.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8cef18d..336bf42 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,10 +39,10 @@ jobs: - name: Compress artifacts run: | mkdir release - zip --junk-paths release/openw-cli-${{ env.GITREV }}-darwin-10.10-amd64.zip build/openw-cli-${{ env.GITREV }}-darwin-10.10-amd64 + zip --junk-paths release/openw-cli-${{ env.GITREV }}-darwin-amd64.zip build/openw-cli-${{ env.GITREV }}-darwin-amd64 zip --junk-paths release/openw-cli-${{ env.GITREV }}-linux-amd64.zip build/openw-cli-${{ env.GITREV }}-linux-amd64 - zip --junk-paths release/openw-cli-${{ env.GITREV }}-windows-6.0-386.exe.zip build/openw-cli-${{ env.GITREV }}-windows-6.0-386.exe - zip --junk-paths release/openw-cli-${{ env.GITREV }}-windows-6.0-amd64.exe.zip build/openw-cli-${{ env.GITREV }}-windows-6.0-amd64.exe + zip --junk-paths release/openw-cli-${{ env.GITREV }}-windows-386.exe.zip build/openw-cli-${{ env.GITREV }}-windows-386.exe + zip --junk-paths release/openw-cli-${{ env.GITREV }}-windows-amd64.exe.zip build/openw-cli-${{ env.GITREV }}-windows-amd64.exe - name: Create Release id: create_release uses: actions/create-release@v1.0.0 @@ -60,8 +60,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./release/openw-cli-${{ env.GITREV }}-darwin-10.10-amd64.zip - asset_name: openw-cli-${{ env.GITREV }}-darwin-10.10-amd64.zip + asset_path: ./release/openw-cli-${{ env.GITREV }}-darwin-amd64.zip + asset_name: openw-cli-${{ env.GITREV }}-darwin-amd64.zip asset_content_type: application/zip - name: Upload Release Asset (2/4) id: upload-release-asset-2 @@ -80,8 +80,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./release/openw-cli-${{ env.GITREV }}-windows-6.0-386.exe.zip - asset_name: openw-cli-${{ env.GITREV }}-windows-6.0-386.exe.zip + asset_path: ./release/openw-cli-${{ env.GITREV }}-windows-386.exe.zip + asset_name: openw-cli-${{ env.GITREV }}-windows-386.exe.zip asset_content_type: application/zip - name: Upload Release Asset (4/4) id: upload-release-asset-4 @@ -90,6 +90,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./release/openw-cli-${{ env.GITREV }}-windows-6.0-amd64.exe.zip - asset_name: openw-cli-${{ env.GITREV }}-windows-6.0-amd64.exe.zip + asset_path: ./release/openw-cli-${{ env.GITREV }}-windows-amd64.exe.zip + asset_name: openw-cli-${{ env.GITREV }}-windows-amd64.exe.zip asset_content_type: application/zip From 853284a7e6d91cdd76979619c23ca0a6df335593 Mon Sep 17 00:00:00 2001 From: MZQ Date: Mon, 27 Mar 2023 16:48:16 +0800 Subject: [PATCH 24/26] update mod --- go.mod | 2 +- openwcli/wallet_manager_test.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 18ddf9a..52cfdde 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DisposaBoy/JsonConfigReader v0.0.0-20171218180944-5ea4d0ddac55 github.com/asdine/storm v2.1.2+incompatible github.com/astaxie/beego v1.12.0 - github.com/blocktree/go-openw-sdk/v2 v2.4.2 + github.com/blocktree/go-openw-sdk/v2 v2.4.3 github.com/blocktree/go-owcrypt v1.1.9 github.com/blocktree/openwallet/v2 v2.4.3 github.com/bndr/gotabulate v1.1.2 diff --git a/openwcli/wallet_manager_test.go b/openwcli/wallet_manager_test.go index ebecedd..3d3b669 100644 --- a/openwcli/wallet_manager_test.go +++ b/openwcli/wallet_manager_test.go @@ -41,7 +41,7 @@ func TestCLI_CreateAccountOnServer(t *testing.T) { if cli == nil { return } - walletID := "W4W8i2F27c1YB63rMZswSquVSnS3265MAF" + walletID := "WMdec1yzEu5TGeJ5iCLyTZCvoDZ1CEMd3B" wallet, err := cli.GetWalletByWalletID(walletID) if err != nil { log.Error("GetWalletByWalletID error:", err) @@ -49,7 +49,7 @@ func TestCLI_CreateAccountOnServer(t *testing.T) { } if wallet != nil { - _, _, err = cli.CreateAccountOnServer("test2MATIC", "1234qwer", "MATIC", wallet) + _, _, err = cli.CreateAccountOnServer("test2MATIC", "12345678", "ETH", wallet) if err != nil { log.Error("CreateAccountOnServer error:", err) return @@ -375,13 +375,14 @@ func TestCLI_SetSummaryInfo(t *testing.T) { } obj := &openwsdk.SummarySetting{ - WalletID: "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx", - AccountID: "AEeBZy321NzbLWPFkjyGfFyUn8hHX2g93f4wMBVumin4", - SumAddress: "", - Threshold: "1", + WalletID: "WMdec1yzEu5TGeJ5iCLyTZCvoDZ1CEMd3B", + AccountID: "HK5gc7SSXAXKhExs8VUd63SgeG8juR1DiRJUGThdmZEV", + SumAddress: "0xfc2d581783c0c78a252e113f73c4a93108464bcc", + Threshold: "0", MinTransfer: "0", RetainedBalance: "0", Confirms: 1, + Symbol: "ETH", } err := cli.SetSummaryInfo(obj) From de688f8a7385ebec3c7210d9b7553c273fbbed55 Mon Sep 17 00:00:00 2001 From: MZQ Date: Mon, 27 Mar 2023 20:21:13 +0800 Subject: [PATCH 25/26] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8d5deb9..4aa6519 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,7 @@ $ ./openw-cli -c=./node.ini startsum -f=/usr/to/sum.json "switchSymbol": "ETH", //强制切换symbol(默认不设置,用于解决代币打错地址,需要切换网络汇总) "memo": "hello", //备注,适用于可添加备注的交易单 "addressLimit": 50, //地址分页数量限制,不填写,默认为200 + "symbol": "ETH", //汇总的资产类型 "contracts": { //汇总代币合约 "all": { //全部合约 "threshold": "1000", //账户总阈值 @@ -325,6 +326,7 @@ $ ./openw-cli -c=./node.ini startsum -f=/usr/to/sum.json }, "feesSupportAccount": { //主币余额不足时,可选择一个同钱包下的账户提供手续费 "accountID": "12323", //同钱包下的账户ID + "symbol": "ETH", //资产类型 "lowBalanceWarning": "0.5", //手续费账户余额过低警告阈值,打印警告 "lowBalanceStop": "0.1", //手续费账户余额过低停止工作阈值 "fixSupportAmount": "2", //手续费不足时,提供固定的数量支持 From ac871e2ee491b765b8dae091101fdfcfa895fe0e Mon Sep 17 00:00:00 2001 From: MZQ Date: Wed, 24 May 2023 17:05:00 +0800 Subject: [PATCH 26/26] add command: changepwd --- commands/commands.go | 23 +++++++++++++++++++++ openwcli/cli.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ openwcli/cli_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/commands/commands.go b/commands/commands.go index 7591b5b..7ffce32 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -260,6 +260,15 @@ var ( Category: "WALLET COMMANDS", Flags: []cli.Flag{}, }, + { + + Name: "changepwd", + Usage: "change wallet password", + ArgsUsage: "", + Action: changepwd, + Category: "WALLET COMMANDS", + Flags: []cli.Flag{}, + }, } ) @@ -673,3 +682,17 @@ func listaddressbalance(c *cli.Context) error { return nil } + +// changepwd +func changepwd(c *cli.Context) error { + + if cli := getCLI(c); cli != nil { + err := cli.ChangePwdFlow() + if err != nil { + log.Error("unexpected error: ", err) + return err + } + } + + return nil +} diff --git a/openwcli/cli.go b/openwcli/cli.go index 2674465..8d34d3d 100644 --- a/openwcli/cli.go +++ b/openwcli/cli.go @@ -1323,3 +1323,51 @@ func (cli *CLI) ListAddressBalanceFlow() error { return nil } + +// ChangePwdFlow +func (cli *CLI) ChangePwdFlow() error { + + //:选择钱包 + wallet, err := cli.SelectWalletStep() + if err != nil { + return err + } + + keystore := hdkeystore.NewHDKeystore( + cli.config.keydir, + hdkeystore.StandardScryptN, + hdkeystore.StandardScryptP, + ) + + //:输入钱包密码 + // 等待用户输入密码 + password, err := console.InputPassword(false, 3) + if err != nil { + return err + } + + // 解密钱包 + key, err := cli.getLocalKeyByWallet(wallet, password) + if err != nil { + return fmt.Errorf("wallet password invalid") + } + + log.Infof("Setup a new password for wallet: %s", key.FileName()) + + // 解密成功,设置新密码 + newPwd, err := console.InputPassword(true, 3) + if err != nil { + return err + } + + //用新密码加密 + filePath := keystore.JoinPath(hdkeystore.KeyFileName(key.Alias, key.KeyID) + ".key") + err = keystore.StoreKey(filePath, key, newPwd) + if err != nil { + return err + } + + log.Infof("Wallet: %s password changed successfully.", key.FileName()) + + return nil +} diff --git a/openwcli/cli_test.go b/openwcli/cli_test.go index 556a9f3..25afdb1 100644 --- a/openwcli/cli_test.go +++ b/openwcli/cli_test.go @@ -2,9 +2,12 @@ package openwcli import ( "github.com/astaxie/beego/config" + "github.com/blocktree/go-openw-sdk/v2/openwsdk" + "github.com/blocktree/openwallet/v2/hdkeystore" "github.com/blocktree/openwallet/v2/log" "github.com/blocktree/openwallet/v2/owtp" "path/filepath" + "testing" ) func init() { @@ -30,3 +33,48 @@ func getTestOpenwCLI() *CLI { return cli } + +func TestChangePwd(t *testing.T) { + cli := getTestOpenwCLI() + if cli == nil { + return + } + + keystore := hdkeystore.NewHDKeystore( + cli.config.keydir, + hdkeystore.StandardScryptN, + hdkeystore.StandardScryptP, + ) + + //随机生成keystore + key, filePath, err := hdkeystore.StoreHDKey( + cli.config.keydir, + "pwd", + "12345678", + hdkeystore.StandardScryptN, + hdkeystore.StandardScryptP, + ) + if err != nil { + log.Error("StoreHDKey error:", err) + return + } + + wallet := &openwsdk.Wallet{ + Alias: "pwd", + WalletID: key.KeyID, + } + + //用新密码加密 + err = keystore.StoreKey(filePath, key, "1234qwer") + if err != nil { + log.Error("StoreKey error:", err) + return + } + + // 解密钱包 + _, err = cli.getLocalKeyByWallet(wallet, "1234qwer") + if err != nil { + log.Error("can not use new password unlock wallet:", err) + return + } +}