Skip to content

Commit

Permalink
Merge branch 'anylock' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Jun 3, 2024
2 parents 09e8cf1 + e553840 commit 1d1de77
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
92 changes: 92 additions & 0 deletions example/any_lock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package example

import (
"das-account-indexer/http_server/handle"
"fmt"
"github.com/dotbitHQ/das-lib/common"
"github.com/dotbitHQ/das-lib/core"
"github.com/dotbitHQ/das-lib/http_api"
"github.com/parnurzeal/gorequest"
"github.com/scorpiotzh/toolib"
"testing"
)

var (
TestUrl = "https://test-indexer.d.id/v1"
)

func doReq(url string, req, data interface{}) error {
var resp http_api.ApiResp
resp.Data = &data

_, _, errs := gorequest.New().Post(url).SendStruct(&req).EndStruct(&resp)
if errs != nil {
return fmt.Errorf("%v", errs)
}
if resp.ErrNo != http_api.ApiCodeSuccess {
return fmt.Errorf("%d - %s", resp.ErrNo, resp.ErrMsg)
}
return nil
}

func TestBatchReverseRecordV2(t *testing.T) {
req := handle.ReqBatchReverseRecordV2{
BatchKeyInfo: []core.ChainTypeAddress{
{
Type: "blockchain",
KeyInfo: core.KeyInfo{
CoinType: common.CoinTypeCKB,
Key: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgyumrp5k2es0d0hy5z6044zr2305pyzc97qqjec5vx",
},
},
{
Type: "blockchain",
KeyInfo: core.KeyInfo{
CoinType: common.CoinTypeBTC,
Key: "tb1qumrp5k2es0d0hy5z6044zr2305pyzc978qz0ju",
},
},
{
Type: "blockchain",
KeyInfo: core.KeyInfo{
CoinType: common.CoinTypeCKB,
Key: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgytmmrfg7aczevlxngqnr28npj2849erjyqqhe2guh",
},
},
{
Type: "blockchain",
KeyInfo: core.KeyInfo{
CoinType: common.CoinTypeBTC,
Key: "tb1pzl9nkuavvt303hly08u3ug0v55yd3a8x86d8g5jsrllsaell8j5s8gzedg",
},
},
},
}
url := TestUrl + "/batch/reverse/record"
var data handle.RespBatchReverseRecordV2
if err := doReq(url, req, &data); err != nil {
t.Fatal(err)
}
fmt.Println(toolib.JsonString(&data))
}

func TestReverseRecordV2(t *testing.T) {
req := handle.ReqReverseRecordV2{
ChainTypeAddress: core.ChainTypeAddress{
Type: "blockchain",
KeyInfo: core.KeyInfo{
CoinType: common.CoinTypeBTC,
Key: "tb1pzl9nkuavvt303hly08u3ug0v55yd3a8x86d8g5jsrllsaell8j5s8gzedg",
//Key: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgytmmrfg7aczevlxngqnr28npj2849erjyqqhe2guh",
//Key: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgjzk3ntzys3nuwmvnar2lrs54l9pat6wy3qq5glj65",
//Key: "0x15a33588908cF8Edb27D1AbE3852Bf287Abd3891",
},
},
}
url := TestUrl + "/reverse/record"
var data handle.RespReverseRecordV2
if err := doReq(url, req, &data); err != nil {
t.Fatal(err)
}
fmt.Println(toolib.JsonString(&data))
}
8 changes: 4 additions & 4 deletions http_server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func (h *HttpServer) initRouter() {
v1Indexer.POST("/account/list", code.DoMonitorLog(code.MethodAccountList), cacheHandle, h.H.AccountList)
v1Indexer.POST("/account/records", code.DoMonitorLog(code.MethodAccountRecords), cacheHandle, h.H.AccountRecords)
v1Indexer.POST("/account/reverse/address", code.DoMonitorLog(code.MethodAccountReverseAddress), cacheHandle, h.H.AccountReverseAddress)
v1Indexer.POST("/reverse/record", code.DoMonitorLog(code.MethodReverseRecord), cacheHandle, h.H.ReverseRecord)
v1Indexer.POST("/v2/reverse/record", code.DoMonitorLog(code.MethodReverseRecord), cacheHandle, h.H.ReverseRecordV2)
v1Indexer.POST("/reverse/record", code.DoMonitorLog(code.MethodReverseRecord), cacheHandle, h.H.ReverseRecordV2)
//v1Indexer.POST("/v2/reverse/record", code.DoMonitorLog(code.MethodReverseRecord), cacheHandle, h.H.ReverseRecordV2)
v1Indexer.POST("/sub/account/list", code.DoMonitorLog(code.MethodSubAccountList), cacheHandle, h.H.SubAccountList)
v1Indexer.POST("/sub/account/verify", code.DoMonitorLog(code.MethodSubAccountVerify), cacheHandle, h.H.SubAccountVerify)

v1Indexer.POST("/batch/account/records", code.DoMonitorLog(code.MethodBatchAccountRecords), cacheHandle, h.H.BatchAccountRecords)
v1Indexer.POST("/batch/reverse/record", code.DoMonitorLog(code.MethodBatchReverseRecord), cacheHandle, h.H.BatchReverseRecord)
v1Indexer.POST("/v1/batch/reverse/record", code.DoMonitorLog(code.MethodBatchReverseRecord), cacheHandle, h.H.BatchReverseRecordV2)
v1Indexer.POST("/batch/reverse/record", code.DoMonitorLog(code.MethodBatchReverseRecord), cacheHandle, h.H.BatchReverseRecordV2)
//v1Indexer.POST("/v2/batch/reverse/record", code.DoMonitorLog(code.MethodBatchReverseRecord), cacheHandle, h.H.BatchReverseRecordV2)
v1Indexer.POST("/batch/register/info", code.DoMonitorLog(code.MethodBatchRegisterInfo), cacheHandle, h.H.BatchRegisterInfo)
v1Indexer.POST("/did/list", code.DoMonitorLog("did_list"), h.H.DidList) //
v1Indexer.POST("/record/list", code.DoMonitorLog("records_list"), h.H.AccountRecords) //
Expand Down

0 comments on commit 1d1de77

Please sign in to comment.