Skip to content

Commit

Permalink
sync in RPC for get accounts by count
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhousanbu committed May 19, 2024
1 parent 47d8583 commit 4c19ccc
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 12 deletions.
33 changes: 31 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ const docTemplate = `{
}
],
"responses": {
"201": {
"description": "Created"
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/storage.Member"
}
}
}
}
}
Expand Down Expand Up @@ -158,6 +164,29 @@ const docTemplate = `{
"type": "string"
}
}
},
"storage.Member": {
"type": "object",
"properties": {
"hashedAccount": {
"type": "string"
},
"privateKeyVault": {
"type": "string"
},
"publicKey": {
"type": "string"
},
"rpcAddress": {
"type": "string"
},
"rpcPort": {
"type": "integer"
},
"version": {
"type": "integer"
}
}
}
},
"securityDefinitions": {
Expand Down
33 changes: 31 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@
}
],
"responses": {
"201": {
"description": "Created"
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/storage.Member"
}
}
}
}
}
Expand Down Expand Up @@ -147,6 +153,29 @@
"type": "string"
}
}
},
"storage.Member": {
"type": "object",
"properties": {
"hashedAccount": {
"type": "string"
},
"privateKeyVault": {
"type": "string"
},
"publicKey": {
"type": "string"
},
"rpcAddress": {
"type": "string"
},
"rpcPort": {
"type": "integer"
},
"version": {
"type": "integer"
}
}
}
},
"securityDefinitions": {
Expand Down
23 changes: 21 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ definitions:
apiKey:
type: string
type: object
storage.Member:
properties:
hashedAccount:
type: string
privateKeyVault:
type: string
publicKey:
type: string
rpcAddress:
type: string
rpcPort:
type: integer
version:
type: integer
type: object
info:
contact:
name: AAStar Support
Expand Down Expand Up @@ -51,8 +66,12 @@ paths:
produces:
- application/json
responses:
"201":
description: Created
"200":
description: OK
schema:
items:
$ref: '#/definitions/storage.Member'
type: array
security:
- JWT: []
tags:
Expand Down
7 changes: 4 additions & 3 deletions internal/community/storage/member_itor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/syndtr/goleveldb/leveldb/util"
)

func GetAllMembers(skip uint32) []Member {
func GetAllMembers(total uint32) []Member {
if ins, err := Open(); err != nil {
return nil
} else {
Expand All @@ -15,14 +15,15 @@ func GetAllMembers(skip uint32) []Member {
iter := db.NewIterator(&util.Range{
Start: []byte(MemberPrefix),
}, nil)
i := 1
i := 0
for iter.Next() {
if i >= int(skip) {
if i < int(total) {
if m, err := Unmarshal(iter.Value()); err != nil {
return nil
} else {
members = append(members, *m)
}
i++
}
}
iter.Release()
Expand Down
7 changes: 4 additions & 3 deletions internal/web_server/controllers/account/v1/sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package account_v1

import (
"another_node/internal/community/storage"
"another_node/internal/web_server/pkg"
"another_node/internal/web_server/pkg/response"

Expand All @@ -12,7 +13,7 @@ import (
// @Description download accounts
// @Accept json
// @Produce json
// @Success 201
// @Success 200 {array} storage.Member
// @Router /api/account/v1/sync [GET]
// @Param count query int true "how many accounts to download"
// @Security JWT
Expand All @@ -21,8 +22,8 @@ func Sync(ctx *gin.Context) {
response.BadRequest(ctx, err)
return
} else {
_ = count
members := storage.GetAllMembers(uint32(count))
//community.SyncAccounts(count)
response.Created(ctx, nil)
response.Success(ctx, members)
}
}
1 change: 1 addition & 0 deletions internal/web_server/routers/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ func buildRouters(router *gin.Engine) {
{
account := router.Group("/api/account")
account.POST("/v1/bind", account_v1.Bind)
account.GET("/v1/sync", account_v1.Sync)
}
}

0 comments on commit 4c19ccc

Please sign in to comment.