Skip to content

Commit

Permalink
add token withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobeyw committed Nov 13, 2024
1 parent 6e5599f commit 2ccc802
Showing 1 changed file with 27 additions and 8 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

0 comments on commit 2ccc802

Please sign in to comment.