diff --git a/example/any_lock_test.go b/example/any_lock_test.go new file mode 100644 index 0000000..c28bc42 --- /dev/null +++ b/example/any_lock_test.go @@ -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)) +} diff --git a/http_server/router.go b/http_server/router.go index 88e8d86..a20067d 100644 --- a/http_server/router.go +++ b/http_server/router.go @@ -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) //