Skip to content

Commit

Permalink
Merge pull request #262 from Tobeyw/dev-mindy
Browse files Browse the repository at this point in the history
fix  asset holders
  • Loading branch information
Tobeyw committed Aug 20, 2024
2 parents 2a7a60b + 8fb5a67 commit 3475667
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 40 deletions.
49 changes: 12 additions & 37 deletions neo3fura_http/biz/job/job.GetHoldersByContractHash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,28 @@ func (me T) GetHoldersByContractHash() error {
message := make(json.RawMessage, 0)
ret := &message
data := make([]bson.M, 0)
r1, _, err := me.Client.QueryAll(struct {

r0, err := me.Client.QueryAggregate(struct {
Collection string
Index string
Sort bson.M
Filter bson.M
Pipeline []bson.M
Query []string
Limit int64
Skip int64
}{
Collection: "Asset",
Collection: "Address-Asset",
Index: "GetHoldersByContractHash",
Sort: bson.M{},
Filter: bson.M{},
Query: []string{},
Pipeline: []bson.M{
bson.M{"$match": bson.M{"balance": bson.M{"$gt": 0}}},
bson.M{"$group": bson.M{"_id": "$asset", "count": bson.M{"$sum": 1}}},
},
Query: []string{},
}, ret)
if err != nil {
return err
}
for _, item := range r1 {
holders, count, err := me.Client.QueryAll(struct {
Collection string
Index string
Sort bson.M
Filter bson.M
Query []string
Limit int64
Skip int64
}{
Collection: "Address-Asset",
Index: "GetHoldersByContractHash",
Sort: bson.M{"balance": -1},
Filter: bson.M{"asset": item["hash"], "balance": bson.M{"$gt": 0}},
Query: []string{},
Limit: int64(1000),
}, ret)
if err != nil {
return err
}
f := make(map[string]interface{})
count = 0
for _, holder := range holders {
f[holder["address"].(string)] = 1
}
for _, _ = range f {
count = count + 1
}
data = append(data, bson.M{item["hash"].(string): count})

for _, item := range r0 {
data = append(data, bson.M{item["_id"].(string): item["count"]})
}
_, err = me.Client.SaveJob(struct {
Collection string
Expand Down
3 changes: 1 addition & 2 deletions neo3fura_http/lib/cli/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,11 @@ func (me *T) QueryAggregate(args struct {
Pipeline []bson.M
Query []string
}, ret *json.RawMessage) ([]map[string]interface{}, error) {

for _, v := range args.Pipeline {
limit := v["$limit"]
if limit != nil {
if limit.(int64) == 0 {
v["$limit"] = consts.DefaultLimit
// v["$limit"] = consts.DefaultLimit
}
if limit.(int64) > consts.MaxLimit {
v["$limit"] = consts.MaxLimit
Expand Down
2 changes: 1 addition & 1 deletion neo3fura_http/lib/type/consts/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const (
NEO = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5"
GAS = "0xd2a4cff31913016155e38e474a2c06d08be276cf"
DefaultLimit = 20
MaxLimit = 1000
MaxLimit = 2000
)

0 comments on commit 3475667

Please sign in to comment.