Skip to content

Commit

Permalink
Merge pull request #265 from Tobeyw/dev-mindy
Browse files Browse the repository at this point in the history
add tokenWidrawal for bridge
  • Loading branch information
Tobeyw authored Nov 13, 2024
2 parents 0966979 + 2ccc802 commit adcbee0
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 14 deletions.
35 changes: 27 additions & 8 deletions neo3fura_http/biz/api/bridge.GetBridgeTxByNonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package api
import (
"encoding/json"
"strconv"
"strings"

"github.com/joeqian10/neo3-gogogo/crypto"
"github.com/nspcc-dev/neo-go/pkg/util"
"go.mongodb.org/mongo-driver/bson"

"neo3fura_http/lib/type/h160"
Expand All @@ -12,15 +15,34 @@ import (

func (me *T) GetBridgeTxByNonce(args struct {
ContractHash h160.T
TokenHash h160.T
Nonce int64
Limit int64
Skip int64
Filter map[string]interface{}
}, ret *json.RawMessage) error {
var filter bson.M
nonceStr := strconv.FormatInt(args.Nonce, 10)
if args.ContractHash.Valid() == false {
return stderr.ErrInvalidArgs
}
nonceStr := strconv.FormatInt(args.Nonce, 10)

filter = bson.M{"contract": args.ContractHash.Val(),
"$or": []interface{}{bson.M{"eventname": "GasWithdrawal"}, bson.M{"eventname": "GasClaimable"}},
"state.value.0.value": nonceStr,
}

if args.TokenHash.Valid() == true && args.TokenHash.Val() != "0xd2a4cff31913016155e38e474a2c06d08be276cf" {
token, _ := util.Uint160DecodeStringLE(strings.TrimPrefix(args.TokenHash.Val(), "0x"))

encoded := crypto.Base64Encode(token.BytesBE())
filter = bson.M{"contract": args.ContractHash.Val(),
"$or": []interface{}{bson.M{"eventname": "TokenWithdrawal"}, bson.M{"eventname": "TokenClaimable"}},
"state.value.1.value": nonceStr,
"state.value.0.value": encoded,
}
}

r1, _, err := me.Client.QueryAll(struct {
Collection string
Index string
Expand All @@ -33,13 +55,10 @@ func (me *T) GetBridgeTxByNonce(args struct {
Collection: "Notification",
Index: "GetBridgeTxByNonce",
Sort: bson.M{"_id": -1},
Filter: bson.M{"contract": args.ContractHash.Val(),
"$or": []interface{}{bson.M{"eventname": "GasWithdrawal"}, bson.M{"eventname": "Claimable"}},
"state.value.0.value": nonceStr,
},
Query: []string{},
Limit: args.Limit,
Skip: args.Skip,
Filter: filter,
Query: []string{},
Limit: args.Limit,
Skip: args.Skip,
}, ret)

var result map[string]interface{}
Expand Down
36 changes: 33 additions & 3 deletions neo3fura_ws/home/ws.GetTransactionCount.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package home
import (
"context"
"encoding/json"
"log"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"log"
)

// Address
func (me *T) GetTransactionCount(ch *chan map[string]interface{}) error {
transactionCount, err := me.getTransactionCount()
transactionCount, err := me.getTransactionCount2()
if err != nil {
return err
}
Expand All @@ -31,7 +32,7 @@ func (me *T) GetTransactionCount(ch *chan map[string]interface{}) error {
if err != nil {
log.Fatal(err)
}
newTransactionCount, err := me.getTransactionCount()
newTransactionCount, err := me.getTransactionCount2()
if err != nil {
return err
}
Expand Down Expand Up @@ -64,3 +65,32 @@ func (me T) getTransactionCount() (map[string]interface{}, error) {
res["TransactionCount"] = r1
return res, nil
}

func (me T) getTransactionCount2() (map[string]interface{}, error) {
message := make(json.RawMessage, 0)
ret := &message
res := make(map[string]interface{})
r1, err := me.Client.QueryAggregate(
struct {
Collection string
Index string
Sort bson.M
Filter bson.M
Pipeline []bson.M
Query []string
}{Collection: "Transaction",
Index: "GetTransactionList",
Sort: bson.M{},
Filter: bson.M{},
Pipeline: []bson.M{
bson.M{"$group": bson.M{"_id": "$_id"}},
bson.M{"$count": "total counts"},
},
Query: []string{}}, ret)

if err != nil {
return nil, err
}
res["TransactionCount"] = r1[0]
return res, nil
}
37 changes: 34 additions & 3 deletions neo3fura_ws/home/ws.GetTransactionList.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package home
import (
"context"
"encoding/json"
"log"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"log"
)

// TransactionList
func (me *T) GetTransactionList(ch *chan map[string]interface{}) error {
transactionList, err := me.getTransactionList()
transactionList, err := me.getTransactionList2()
if err != nil {
return err
}
Expand All @@ -31,7 +32,7 @@ func (me *T) GetTransactionList(ch *chan map[string]interface{}) error {
if err != nil {
log.Fatal(err)
}
newTransactionList, err := me.getTransactionList()
newTransactionList, err := me.getTransactionList2()
if err != nil {
return err
}
Expand Down Expand Up @@ -70,3 +71,33 @@ func (me T) getTransactionList() (map[string]interface{}, error) {
res["TransactionList"] = r1
return res, nil
}

func (me T) getTransactionList2() (map[string]interface{}, error) {
message := make(json.RawMessage, 0)
ret := &message
res := make(map[string]interface{})
r1, err := me.Client.QueryAggregate(
struct {
Collection string
Index string
Sort bson.M
Filter bson.M
Pipeline []bson.M
Query []string
}{Collection: "Transaction",
Index: "GetTransactionList",
Sort: bson.M{},
Filter: bson.M{},
Pipeline: []bson.M{
bson.M{"$sort": bson.M{"blocktime": -1}},
bson.M{"$project": bson.M{"_id": 1, "size": 1, "blocktime": 1, "hash": 1, "sysfee": 1, "netfee": 1}},
bson.M{"$limit": 10},
},
Query: []string{}}, ret)

if err != nil {
return nil, err
}
res["TransactionList"] = r1
return res, nil
}

0 comments on commit adcbee0

Please sign in to comment.