diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 26c52a8..336bf42 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,7 @@ on: push: tags: - v* + workflow_dispatch: jobs: build: @@ -18,10 +19,14 @@ 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@v1.0.0 + uses: crazy-max/ghaction-xgo@v2 with: - go_version: 1.13.3 + xgo_version: latest + go_version: 1.18 dest: build/ prefix: ${{ env.OPENWCLIBINARY }} targets: darwin-10.10/amd64,linux/amd64,windows-6.0/* @@ -34,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 @@ -55,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 @@ -75,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 @@ -85,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 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/README.md b/README.md index a8cce23..4aa6519 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) ## 概述 @@ -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", //手续费不足时,提供固定的数量支持 @@ -366,6 +368,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..7ffce32 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -242,6 +242,33 @@ 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{}, + }, + { + + Name: "listaddressbalance", + Usage: "show account all address native/token balance", + ArgsUsage: "", + Action: listaddressbalance, + Category: "WALLET COMMANDS", + Flags: []cli.Flag{}, + }, + { + + Name: "changepwd", + Usage: "change wallet password", + ArgsUsage: "", + Action: changepwd, + Category: "WALLET COMMANDS", + Flags: []cli.Flag{}, + }, } ) @@ -266,7 +293,7 @@ func getCLI(c *cli.Context) *openwcli.CLI { return cli } -//register 注册 +// register 注册 func noderegister(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -279,7 +306,7 @@ func noderegister(c *cli.Context) error { return nil } -//nodeinfo +// nodeinfo func nodeinfo(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -293,7 +320,7 @@ func nodeinfo(c *cli.Context) error { return nil } -//newwallet 创建钱包 +// newwallet 创建钱包 func newwallet(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -307,7 +334,7 @@ func newwallet(c *cli.Context) error { return nil } -//listwallet 钱包配置 +// listwallet 钱包配置 func listwallet(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -321,7 +348,7 @@ func listwallet(c *cli.Context) error { return nil } -//newaccount 创建账户 +// newaccount 创建账户 func newaccount(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -335,7 +362,7 @@ func newaccount(c *cli.Context) error { return nil } -//listaccount 账户列表 +// listaccount 账户列表 func listaccount(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -349,7 +376,7 @@ func listaccount(c *cli.Context) error { return nil } -//newaddress 创建地址 +// newaddress 创建地址 func newaddress(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -363,7 +390,7 @@ func newaddress(c *cli.Context) error { return nil } -//searchaddress 查询地址 +// searchaddress 查询地址 func searchaddress(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -377,7 +404,7 @@ func searchaddress(c *cli.Context) error { return nil } -//transfer 转账交易 +// transfer 转账交易 func transfer(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -391,7 +418,7 @@ func transfer(c *cli.Context) error { return nil } -//transferall 转账全部资产交易 +// transferall 转账全部资产交易 func transferall(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -405,7 +432,7 @@ func transferall(c *cli.Context) error { return nil } -//setsum 设置汇总 +// setsum 设置汇总 func setsum(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -419,7 +446,7 @@ func setsum(c *cli.Context) error { return nil } -//startsum 定时汇总 +// startsum 定时汇总 func startsum(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -435,7 +462,7 @@ func startsum(c *cli.Context) error { return nil } -//updateinfo 更新区块链资料库 +// updateinfo 更新区块链资料库 func updateinfo(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -449,7 +476,7 @@ func updateinfo(c *cli.Context) error { return nil } -//listsymbol 查看所有币种信息列表 +// listsymbol 查看所有币种信息列表 func listsymbol(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -463,7 +490,7 @@ func listsymbol(c *cli.Context) error { return nil } -//listtokencontract 查看某个区块链所有代币合约信息列表 +// listtokencontract 查看某个区块链所有代币合约信息列表 func listtokencontract(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -477,7 +504,7 @@ func listtokencontract(c *cli.Context) error { return nil } -//listaddress 查看账户所有地址 +// listaddress 查看账户所有地址 func listaddress(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -491,7 +518,7 @@ func listaddress(c *cli.Context) error { return nil } -//trustserver 启动后台托管钱包服务 +// trustserver 启动后台托管钱包服务 func trustserver(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -530,7 +557,7 @@ func listsuminfo(c *cli.Context) error { return nil } -//listtokenbalance +// listtokenbalance func listtokenbalance(c *cli.Context) error { if cli := getCLI(c); cli != nil { @@ -600,7 +627,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 { @@ -614,7 +641,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 { @@ -627,3 +654,45 @@ 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 +} + +// 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 +} + +// 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/go.mod b/go.mod index 2fcc018..52cfdde 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.5 - github.com/blocktree/go-owcrypt v1.1.4 - github.com/blocktree/openwallet/v2 v2.1.0 + 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 - 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 94ce62a..8d34d3d 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 { //:选择钱包 @@ -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 } @@ -354,20 +354,26 @@ 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, account.Symbol, count) if err != nil { return err } 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,17 +390,17 @@ func (cli *CLI) SearchAddressFlow() error { } } - address, err := cli.SearchAddressOnServer(addr) + address, err := cli.SearchAddressOnServer(symbol, addr) if err != nil { 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?") 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 } @@ -404,7 +410,7 @@ func (cli *CLI) SearchAddressFlow() error { return nil } -//TransferFlow +// TransferFlow func (cli *CLI) TransferFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -413,7 +419,13 @@ func (cli *CLI) TransferFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) + if err != nil { + return err + } + + // 等待用户输入symbol + symbol, err := console.InputText("Enter symbol: ", true) if err != nil { return err } @@ -461,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 } @@ -469,7 +481,7 @@ func (cli *CLI) TransferFlow() error { return nil } -//TransferAllFlow +// TransferAllFlow func (cli *CLI) TransferAllFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -478,7 +490,13 @@ func (cli *CLI) TransferAllFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) + if err != nil { + return err + } + + // 等待用户输入symbol + symbol, err := console.InputText("Enter symbol: ", true) if err != nil { return err } @@ -520,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 } @@ -528,13 +546,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 { //:选择钱包 @@ -556,7 +574,7 @@ func (cli *CLI) SetSumFlow() error { //} //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -589,6 +607,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 +624,7 @@ func (cli *CLI) SetSumFlow() error { return nil } -//StartSumFlow +// StartSumFlow func (cli *CLI) StartSumFlow(file string) error { var ( @@ -668,7 +687,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 } @@ -746,7 +765,7 @@ func (cli *CLI) StartSumFlow(file string) error { return nil } -//UpdateInfoFlow +// UpdateInfoFlow func (cli *CLI) UpdateInfoFlow() error { err := cli.UpdateSymbols() @@ -759,7 +778,7 @@ func (cli *CLI) UpdateInfoFlow() error { return nil } -//ListSymbolFlow +// ListSymbolFlow func (cli *CLI) ListSymbolFlow() error { list, err := cli.GetSymbolList() if err != nil { @@ -769,7 +788,7 @@ func (cli *CLI) ListSymbolFlow() error { return nil } -//ListTokenContractFlow +// ListTokenContractFlow func (cli *CLI) ListTokenContractFlow() error { symbol, err := console.InputText("Enter symbol: ", true) @@ -785,7 +804,7 @@ func (cli *CLI) ListTokenContractFlow() error { return nil } -//ListAddressFlow +// ListAddressFlow func (cli *CLI) ListAddressFlow() error { //:选择钱包 @@ -795,12 +814,12 @@ func (cli *CLI) ListAddressFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } - offset, err := console.InputNumber("Enter offset: ", true) + lastId, err := console.InputNumber("Enter last ID: ", true) if err != nil { return err } @@ -810,12 +829,12 @@ 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 } - err = cli.printAddressList(account.WalletID, addresses, "") + err = cli.printAddressList(account.WalletID, account.Symbol, addresses, "") if err != nil { return err } @@ -823,7 +842,7 @@ func (cli *CLI) ListAddressFlow() error { return nil } -//StartTrustServerFlow +// StartTrustServerFlow func (cli *CLI) StartTrustServerFlow() error { var ( @@ -868,7 +887,7 @@ func (cli *CLI) StartTrustServerFlow() error { return nil } -//SelectWalletStep 选择钱包操作 +// SelectWalletStep 选择钱包操作 func (cli *CLI) SelectWalletStep() (*openwsdk.Wallet, error) { wallets, _ := cli.GetWalletsOnServer() @@ -893,8 +912,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) @@ -919,7 +938,7 @@ func (cli *CLI) selectAccountStep(walletID string) (*openwsdk.Account, error) { return account, nil } -//ListTokenBalanceFlow +// ListTokenBalanceFlow func (cli *CLI) ListTokenBalanceFlow() error { //:选择钱包 @@ -929,12 +948,12 @@ func (cli *CLI) ListTokenBalanceFlow() error { } //:选择账户 - account, selectErr := cli.selectAccountStep(wallet.WalletID) + account, selectErr := cli.SelectAccountStep(wallet.WalletID) if selectErr != nil { return selectErr } - list, err := cli.GetAllTokenContractBalance(account.AccountID, "") + list, err := cli.GetAllTokenContractBalance(account.WalletID, account.AccountID, account.Symbol) if err != nil { return err } @@ -942,7 +961,7 @@ func (cli *CLI) ListTokenBalanceFlow() error { return nil } -//unlockLocalWalletsByInputPassword 输入密码解锁钱包 +// unlockLocalWalletsByInputPassword 输入密码解锁钱包 func (cli *CLI) unlockLocalWalletsByInputPassword() error { localWallets, err := cli.GetWalletsOnServer() @@ -1115,8 +1134,7 @@ func ProcExsit(filePath string, processName string) error { return nil } - -//TriggerABIFlow +// TriggerABIFlow func (cli *CLI) TriggerABIFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -1125,7 +1143,7 @@ func (cli *CLI) TriggerABIFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -1136,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 { @@ -1164,7 +1188,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, abiJSonInput, "0", sid, feeRate, password, abiParam, "", 0, true) if exErr != nil { return exErr } @@ -1172,8 +1196,7 @@ func (cli *CLI) TriggerABIFlow() error { return nil } - -//CallABIFlow +// CallABIFlow func (cli *CLI) CallABIFlow() error { //:选择钱包 wallet, err := cli.SelectWalletStep() @@ -1182,7 +1205,7 @@ func (cli *CLI) CallABIFlow() error { } //:选择账户 - account, err := cli.selectAccountStep(wallet.WalletID) + account, err := cli.SelectAccountStep(wallet.WalletID) if err != nil { return err } @@ -1207,4 +1230,144 @@ 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 + } + + // 等待用户输入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(symbol, 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, symbol, 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 +} + +// 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 +} + +// 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 + } +} 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 5919429..fdbda5b 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,14 +70,14 @@ 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 } 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/summary_manager.go b/openwcli/summary_manager.go index 0c0830b..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,23 +48,30 @@ 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 } 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(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, + 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) @@ -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 ( @@ -201,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 } @@ -257,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 @@ -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) } @@ -300,14 +316,21 @@ 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.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 { @@ -365,6 +388,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) @@ -380,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 { @@ -429,6 +453,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 } @@ -481,12 +521,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 { @@ -508,6 +548,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)) } } } @@ -587,7 +634,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 { @@ -639,7 +686,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 { @@ -657,7 +704,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) } @@ -684,7 +731,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..cc962ec 100644 --- a/openwcli/transaction_manager.go +++ b/openwcli/transaction_manager.go @@ -8,34 +8,35 @@ 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, symbol, address string) (*openwsdk.BalanceResult, error) { var ( - getBalance *openwsdk.TokenBalance + 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.GetTokenBalanceByAccount(account.AccountID, contractID, true, - func(status uint64, msg string, balance *openwsdk.TokenBalance) { + err := cli.api.GetBalanceByAccount(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,13 +50,13 @@ func (cli *CLI) GetTokenBalanceByContractAddress(account *openwsdk.Account, addr return getBalance, nil } -//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) +// Transfer 转账交易 +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) { +// TransferExt 转账交易 + 扩展参数 +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 @@ -69,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) } @@ -85,21 +86,24 @@ 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) } + if len(token) == 0 { + return nil, nil, openwallet.Errorf(openwallet.ErrSystemException, "can not find contract address") + } contractID = token[0].ContractID 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, 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) @@ -116,7 +120,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) @@ -154,7 +158,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..32ed48e 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(symbol, accountID) if err != nil { //log.Error("GetAccountByAccountID error:", err) return openwallet.ConvertError(err) @@ -39,7 +39,7 @@ func testCLITransfer(walletID, accountID, contractAddress, amount, to, memo, pas 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 @@ -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(symbol, accountID) if err != nil { //log.Error("GetAccountByAccountID error:", err) return openwallet.ConvertError(err) @@ -69,7 +69,7 @@ func testCLITransferAll(walletID, accountID, to, password string) *openwallet.Er 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) @@ -85,57 +85,25 @@ 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 } } -func TestCLI_TransferAll_LTC(t *testing.T) { - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" - accountID := "PgHCcfMbcw1zXRNZo23NFjRdBmcN5tzrb1j5McRLJbG" - to := "LcaFc1pmJBsS7MQyMvZaboppuuvGFubD49" - password := "12345678" - err := testCLITransferAll(walletID, accountID, 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() @@ -251,7 +219,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 @@ -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 c6467ad..355415a 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 @@ -293,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 @@ -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 @@ -804,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 @@ -835,6 +837,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 { //钱包是否已经解锁 @@ -844,15 +847,15 @@ 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) + signature, err := cli.SignHash(addr, symbol, 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..8d0fb19 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,15 +326,25 @@ 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.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{"No.", "ID", "Name", "AccountID", "Symbol", "Balance", "Addresses", "Setup summary info"}) //打印信息 @@ -342,7 +354,7 @@ func (cli *CLI) printAccountList(list []*openwsdk.Account) { } } -//printAccountList 打印账户列表 +// printAccountList 打印账户列表 func (cli *CLI) printAccountSummaryInfo() { _, err := cli.getDB() @@ -375,8 +387,8 @@ func (cli *CLI) printAccountSummaryInfo() { fmt.Println(t.Render("simple")) } -//CreateAddressOnServer -func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) error { +// CreateAddressOnServer +func (cli *CLI) CreateAddressOnServer(walletID, accountID, symbol string, count uint64) error { var ( retErr error @@ -394,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)) //:保存到本地数据库,导出到文件夹 @@ -420,22 +432,22 @@ func (cli *CLI) CreateAddressOnServer(walletID, accountID string, count uint64) return retErr } -//exportAddressToFile 导出地址到文件中 -func (cli *CLI) exportAddressToFile(addresses []string, filePath string) bool { +// exportAddressToFile 导出地址到文件中 +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) } -//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,8 +508,8 @@ func (cli *CLI) GetAddressesOnServer(walletID, accountID string, offset, limit i return list, retErr } -//printAddressList 打印地址列表 -func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, password string) error { +// printAddressList 打印地址列表 +func (cli *CLI) printAddressList(walletID, symbol string, list []*openwsdk.Address, password string) error { var ( isShowPrivateKey bool @@ -537,11 +549,21 @@ 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(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 { - selectedSymbol, err := cli.GetSymbolInfo(a.Symbol) + selectedSymbol, err := cli.GetSymbolInfo(symbol) if err != nil { return err } @@ -560,13 +582,13 @@ 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, symbol, balanceStr, a.PublicKey, privatekey, }) } t := gotabulate.Create(tableInfo) // Set Headers - t.SetHeaders([]string{"No.", "Address", "WalletID", "AccounttID", "Symbol", "Balance", "publicKey", "privateKey"}) + t.SetHeaders([]string{"ID", "Address", "WalletID", "AccountID", "Symbol", "Balance", "publicKey", "privateKey"}) //打印信息 fmt.Println(t.Render("simple")) @@ -577,7 +599,33 @@ func (cli *CLI) printAddressList(walletID string, list []*openwsdk.Address, pass return nil } -//UpdateSymbols 更新主链 +// 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")) + } else { + fmt.Println("No address was created locally. ") + } + + return nil +} + +// UpdateSymbols 更新主链 func (cli *CLI) UpdateSymbols() error { const ( @@ -611,7 +659,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 +691,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 +727,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 +759,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 +767,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 +782,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 +791,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 +799,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 +845,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 +868,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 +885,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 +913,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,15 +934,15 @@ func (cli *CLI) getLocalKeyByWallet(wallet *openwsdk.Wallet, password string) (* return key, nil } -//GetAllTokenContractBalance 查询账户合约余额 -func (cli *CLI) GetAllTokenContractBalance(accountID string, symbol string) ([]*openwsdk.TokenBalance, error) { +// GetAllTokenContractBalance 查询账户合约余额 +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 { @@ -912,15 +960,15 @@ func (cli *CLI) GetAllTokenContractBalance(accountID string, symbol string) ([]* return getBalances, nil } -//GetAllTokenContractBalanceByAddress 查询地址合约余额 -func (cli *CLI) GetAllTokenContractBalanceByAddress(accountID, address, symbol string) ([]*openwsdk.TokenBalance, error) { +// GetAllTokenContractBalanceByAddress 查询地址合约余额 +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 { @@ -947,8 +995,8 @@ func findTokenContractByID(tokenList []*openwsdk.TokenContract, contractID strin return nil } -//printTokenContractBalanceList 打印账户代币合约余额列表 -func (cli *CLI) printTokenContractBalanceList(list []*openwsdk.TokenBalance, symbol string) { +// printTokenContractBalanceList 打印账户代币合约余额列表 +func (cli *CLI) printTokenContractBalanceList(list []*openwsdk.BalanceResult, symbol string) { if list != nil && len(list) > 0 { tableInfo := make([][]interface{}, 0) @@ -967,7 +1015,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, }) } @@ -996,7 +1044,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 +1085,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 +1127,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 } @@ -1202,7 +1250,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, symbol, message, password string, appendV bool) (string, error) { wallet, err := cli.GetWalletByWalletID(address.WalletID) if err != nil { @@ -1215,7 +1263,7 @@ func (cli *CLI) SignHash(address *openwsdk.Address, message, password string) (s return "", err } - symbolInfo, err := cli.GetSymbolInfo(address.Symbol) + symbolInfo, err := cli.GetSymbolInfo(symbol) if err != nil { return "", err } @@ -1234,13 +1282,48 @@ func (cli *CLI) SignHash(address *openwsdk.Address, message, password string) (s 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") } - signature = append(signature, v) + if appendV { + signature = append(signature, v) + } 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 28dfb48..3d3b669 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 := "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("mainnetQUORUM2", "12345678", "QUORUM", wallet) + _, _, err = cli.CreateAccountOnServer("test2MATIC", "12345678", "ETH", wallet) if err != nil { log.Error("CreateAccountOnServer error:", err) return @@ -63,7 +63,7 @@ func TestCLI_GetAccountsOnServer(t *testing.T) { return } - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" + 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 := "65Y9FgipAS2M7ankrt4o3MR2Z1EEPNZKBqyQNsKt9wnj" - account, err := cli.GetAccountByAccountID(accountID) + accountID := "3BSJAseva4A2oZgmEuMEVtdSgnj5UXCunYzyWtK7dj4b" + account, err := cli.GetAccountByAccountID("MATIC", accountID) if err != nil { log.Error("GetAccountByAccountID error:", err) return @@ -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,10 +112,10 @@ func TestCLI_GetAddressesOnServer(t *testing.T) { return } - walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx" - accountID := "7KgNQFx35ijMA43NgY89uaiwi9Tm4MH1PH68Kpnaqstu" + walletID := "WE72vaeN6moqQKvBjXjrZGmxWEFfRKbcC4" + accountID := "Eh2ALZguch6DS2JaoFz97ZspvBvv56FjB79CVVkqc1aA" - 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 @@ -134,15 +134,15 @@ func TestCLI_SearchAddressOnServer(t *testing.T) { return } - addr := "n4LX1HnPnM4Xwy61abUFFpzqoXctHsmmeJ" - - address, err := cli.SearchAddressOnServer(addr) + addr := "0x4247f631804e9fbd5c9d27428617658bd70fa382" + 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}, "") } func TestCLI_GetSymbolList(t *testing.T) { @@ -180,7 +180,7 @@ func TestCLI_GetTokenContractList(t *testing.T) { if cli == nil { return } - tokens, err := cli.GetTokenContractList() + tokens, err := cli.GetTokenContractList("Symbol", "MATIC", "Address", "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174") if err != nil { log.Error("GetTokenContractList 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 @@ -373,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)