Skip to content

Commit f2f78f5

Browse files
committed
account confirmation added for account list
Signed-off-by: kevin xu <cming.xu@gmail.com>
1 parent 106a949 commit f2f78f5

File tree

8 files changed

+35
-11
lines changed

8 files changed

+35
-11
lines changed

api/createaccount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (api *ApiServer) CreateAccount(c *gin.Context) {
3131
return
3232
}
3333

34-
if _, err := keeper.GetAccountInfo(account); err == nil {
34+
if _, err := keeper.GetAccountInfo(account, 0); err == nil {
3535
c.JSON(http.StatusBadRequest, R("account exists"))
3636
return
3737
}

api/getaccount.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package api
22

33
import (
4+
"fmt"
45
"net/http"
6+
"strconv"
57

68
"github.com/cmingxu/wallet-keeper/keeper"
79

@@ -20,7 +22,18 @@ func (api *ApiServer) GetAccountInfo(c *gin.Context) {
2022
return
2123
}
2224

23-
accountInfo, err := keeper.GetAccountInfo(account)
25+
confarg, found := c.GetQuery("minconf")
26+
if !found {
27+
confarg = "1"
28+
}
29+
30+
conf, err := strconv.ParseUint(confarg, 10, 32)
31+
if err != nil {
32+
c.JSON(http.StatusBadRequest, R(fmt.Sprint(err)))
33+
return
34+
}
35+
36+
accountInfo, err := keeper.GetAccountInfo(account, int(conf))
2437
if err != nil {
2538
c.JSON(http.StatusNotFound, R("account not found"))
2639
} else {

api/listaccounts.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package api
33
import (
44
"fmt"
55
"net/http"
6+
"strconv"
67

78
"github.com/cmingxu/wallet-keeper/keeper"
8-
"github.com/cmingxu/wallet-keeper/keeper/btc"
99

1010
"github.com/gin-gonic/gin"
1111
log "github.com/sirupsen/logrus"
@@ -16,7 +16,18 @@ func (api *ApiServer) ListAccounts(c *gin.Context) {
1616
value, _ := c.Get(KEEPER_KEY) // sure about the presence of this value
1717
keeper := value.(keeper.Keeper)
1818

19-
accounts, err := keeper.ListAccountsMinConf(btc.DEFAULT_CONFIRMATION)
19+
confarg, found := c.GetQuery("minconf")
20+
if !found {
21+
confarg = "6"
22+
}
23+
24+
conf, err := strconv.ParseUint(confarg, 10, 32)
25+
if err != nil {
26+
c.JSON(http.StatusBadRequest, R(fmt.Sprint(err)))
27+
return
28+
}
29+
30+
accounts, err := keeper.ListAccountsMinConf(int(conf))
2031
if err != nil {
2132
log.Error(err)
2233
c.JSON(http.StatusInternalServerError, R(fmt.Sprint(err)))

api/listunspentmin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func (api *ApiServer) ListUnspentMin(c *gin.Context) {
1616

1717
confarg, found := c.GetQuery("minconf")
1818
if !found {
19-
confarg = "0"
19+
confarg = "1"
2020
}
2121

2222
conf, err := strconv.ParseUint(confarg, 10, 32)
2323
if err != nil {
24-
c.JSON(http.StatusInternalServerError, R(fmt.Sprint(err)))
24+
c.JSON(http.StatusBadRequest, R(fmt.Sprint(err)))
2525
return
2626
}
2727

keeper/btc/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ func (client *Client) CreateAccount(account string) (keeper.Account, error) {
9898
}
9999

100100
// GetAccountInfo
101-
func (client *Client) GetAccountInfo(account string) (keeper.Account, error) {
101+
func (client *Client) GetAccountInfo(account string, minCon int) (keeper.Account, error) {
102102
var accountsMap map[string]float64
103103
var err error
104-
if accountsMap, err = client.ListAccountsMinConf(0); err != nil {
104+
if accountsMap, err = client.ListAccountsMinConf(minCon); err != nil {
105105
return keeper.Account{}, err
106106
}
107107

keeper/eth/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (client *Client) GetAddress(account string) (string, error) {
7474

7575
// Create Account
7676
// Returns customized account info
77-
func (client *Client) CreateAccount(account string) (keeper.Account, error) {
77+
func (client *Client) CreateAccount(account string, minConf int) (keeper.Account, error) {
7878
return nil, nil
7979
}
8080

keeper/keeper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Keeper interface {
3434

3535
// Get account, together with balance and address
3636
// return error if account not exist
37-
GetAccountInfo(account string) (Account, error)
37+
GetAccountInfo(account string, conf int) (Account, error)
3838

3939
// Returns address under accont, use default account if
4040
// not provided

keeper/usdt/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (client *Client) CreateAccount(account string) (keeper.Account, error) {
9999
}
100100

101101
// GetAccountInfo
102-
func (client *Client) GetAccountInfo(account string) (keeper.Account, error) {
102+
func (client *Client) GetAccountInfo(account string, minConf int) (keeper.Account, error) {
103103
addresses, err := client.GetAddressesByAccount(account)
104104
if err != nil {
105105
return keeper.Account{}, err

0 commit comments

Comments
 (0)