diff --git a/API.md b/API.md index 3fae946..cc32836 100644 --- a/API.md +++ b/API.md @@ -10,7 +10,7 @@ * [Get Batch Account Records Info](#get-batch-account-records-info) * [Get Batch Reverse Record Info](#Get-Batch-Reverse-Record-Info) * [Get Batch register Info](#get-batch-register-info) - * [Get Did List](#get-didcell-list) + * [Get Did Cell List](#get-did-cell-list) * [Get Account Records Info V2](#get-account-records-info-v2) * [Deprecated API List](#deprecated-api-list) @@ -259,15 +259,15 @@ or json rpc style: curl -X POST https://indexer-v1.did.id -d '{"jsonrpc": "2.0","id": 1,"method": "das_batchRegisterInfo","params": [{"batch_account": ["xxxxx", "test1.bit", "20230906.bit"]}]}' ``` -### Get Did List +### Get Did Cell List -batch get account register info, currently can only check whether the account can be registered +batch get .bit DOBs **Request** * host: `indexer-v1.did.id` * path: `/v1/did/list` * param: - * support up to max 50 account + * did_type: 0-all DOBs, 1-normal DOBs, 2-recyclable DOBs ```json { "type": "blockchain", @@ -293,9 +293,7 @@ batch get account register info, currently can only check whether the account ca "outpoint": "", "account_id": "", "account": "", - "args": "", - "expired_at": 0, - "did_cell_status": 1 + "expired_at": 0 } ] } @@ -308,6 +306,12 @@ batch get account register info, currently can only check whether the account ca curl -X POST https://indexer-v1.did.id/v1/did/list -d '{"type": "blockchain","key_info": {"coin_type": "", "key": ""},"page": 1,"size": 10,"did_type": 1}' ``` +or json rpc style: + +```shell +curl -X POST https://indexer-v1.did.id -d '{"jsonrpc": "2.0","id": 1,"method": "das_didCellList","params": [{"type": "blockchain","key_info": {"coin_type": "", "key": ""},"page": 1,"size": 10,"did_type": 1}]}' +``` + ### Get Record List batch get account register info, currently can only check whether the account can be registered diff --git a/go.mod b/go.mod index 43046d6..0c60da4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module das-account-indexer go 1.18 require ( - github.com/dotbitHQ/das-lib v1.1.1-0.20240708030850-9d23b21d2d0a + github.com/dotbitHQ/das-lib v1.1.1-0.20240708030808-05a81bf44632 github.com/fsnotify/fsnotify v1.5.4 github.com/gin-gonic/gin v1.9.1 github.com/go-redis/redis v6.15.9+incompatible @@ -27,8 +27,6 @@ require ( github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect - github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect - github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect diff --git a/go.sum b/go.sum index bf09040..0376772 100644 --- a/go.sum +++ b/go.sum @@ -80,13 +80,11 @@ github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufo github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= -github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= -github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -142,8 +140,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= -github.com/dotbitHQ/das-lib v1.1.1-0.20240708030850-9d23b21d2d0a h1:ypWzIvgnGQitqE0VTTXrDwDCfpjSBaEpFrX3OZBSGeg= -github.com/dotbitHQ/das-lib v1.1.1-0.20240708030850-9d23b21d2d0a/go.mod h1:XrDous4HH3jze59GLdmdKZaAQ8h3unTFUBsppph7IF8= +github.com/dotbitHQ/das-lib v1.1.1-0.20240708030808-05a81bf44632 h1:mL1cGpU7x8dvC+V9tXfHB9WXCG7DcWE6KANYWB2zOOg= +github.com/dotbitHQ/das-lib v1.1.1-0.20240708030808-05a81bf44632/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= diff --git a/http_server/code/method.go b/http_server/code/method.go index 6d4ece9..0ca4ba5 100644 --- a/http_server/code/method.go +++ b/http_server/code/method.go @@ -21,4 +21,5 @@ const ( MethodSubAccountList JsonRpcMethod = "das_subAccountList" MethodSubAccountVerify JsonRpcMethod = "das_subAccountVerify" + MethodDidCellList JsonRpcMethod = "das_didCellList" ) diff --git a/http_server/handle/account_info.go b/http_server/handle/account_info.go index e38aa4f..476f4d7 100644 --- a/http_server/handle/account_info.go +++ b/http_server/handle/account_info.go @@ -2,7 +2,6 @@ package handle import ( "das-account-indexer/config" - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -46,7 +45,7 @@ type AccountInfo struct { DisplayName string `json:"display_name"` } -func (h *HttpHandle) JsonRpcAccountInfo(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcAccountInfo(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqAccountInfo err := json.Unmarshal(p, &req) if err != nil { @@ -69,7 +68,7 @@ func (h *HttpHandle) AccountInfo(ctx *gin.Context) { var ( funcName = "AccountInfo" req ReqAccountInfo - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) @@ -89,7 +88,7 @@ func (h *HttpHandle) AccountInfo(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doAccountInfo(req *ReqAccountInfo, apiResp *code.ApiResp) error { +func (h *HttpHandle) doAccountInfo(req *ReqAccountInfo, apiResp *http_api.ApiResp) error { var resp RespAccountInfo accountId := req.AccountId @@ -198,7 +197,7 @@ func (h *HttpHandle) doAccountInfo(req *ReqAccountInfo, apiResp *code.ApiResp) e return nil } -func checkAccount(account string, apiResp *code.ApiResp) error { +func checkAccount(account string, apiResp *http_api.ApiResp) error { if account == "" || !strings.HasSuffix(account, common.DasAccountSuffix) || strings.Contains(account, " ") || strings.Contains(account, "_") { apiResp.ApiRespErr(http_api.ApiCodeAccountFormatInvalid, "account invalid") diff --git a/http_server/handle/account_list.go b/http_server/handle/account_list.go index ed2afaa..230b23d 100644 --- a/http_server/handle/account_list.go +++ b/http_server/handle/account_list.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -32,7 +31,7 @@ type RespAddressAccount struct { ExpiredAt uint64 `json:"expired_at"` } -func (h *HttpHandle) JsonRpcAccountList(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcAccountList(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqAccountList err := json.Unmarshal(p, &req) if err != nil { @@ -55,7 +54,7 @@ func (h *HttpHandle) AccountList(ctx *gin.Context) { var ( funcName = "AccountList" req ReqAccountList - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -74,7 +73,7 @@ func (h *HttpHandle) AccountList(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doAccountList(req *ReqAccountList, apiResp *code.ApiResp) error { +func (h *HttpHandle) doAccountList(req *ReqAccountList, apiResp *http_api.ApiResp) error { var resp RespAccountList resp.AccountList = make([]RespAddressAccount, 0) diff --git a/http_server/handle/account_records.go b/http_server/handle/account_records.go index 6f15bac..943b79a 100644 --- a/http_server/handle/account_records.go +++ b/http_server/handle/account_records.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -29,7 +28,7 @@ type DataRecord struct { TTL string `json:"ttl"` } -func (h *HttpHandle) JsonRpcAccountRecords(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcAccountRecords(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqAccountRecords err := json.Unmarshal(p, &req) if err != nil { @@ -52,7 +51,7 @@ func (h *HttpHandle) AccountRecords(ctx *gin.Context) { var ( funcName = "AccountRecords" req ReqAccountRecords - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) @@ -74,7 +73,7 @@ func (h *HttpHandle) AccountRecords(ctx *gin.Context) { type ConvertRecordsFunc func(string) string -func (h *HttpHandle) doAccountRecords(req *ReqAccountRecords, apiResp *code.ApiResp, convertRecordsFunc ConvertRecordsFunc) error { +func (h *HttpHandle) doAccountRecords(req *ReqAccountRecords, apiResp *http_api.ApiResp, convertRecordsFunc ConvertRecordsFunc) error { var resp RespAccountRecords resp.Records = make([]DataRecord, 0) diff --git a/http_server/handle/account_records_v2.go b/http_server/handle/account_records_v2.go index 3029738..0cf55a2 100644 --- a/http_server/handle/account_records_v2.go +++ b/http_server/handle/account_records_v2.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "encoding/json" "github.com/dotbitHQ/das-lib/common" "github.com/dotbitHQ/das-lib/http_api" @@ -10,7 +9,7 @@ import ( "net/http" ) -func (h *HttpHandle) JsonRpcAccountRecordsV2(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcAccountRecordsV2(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqAccountRecords err := json.Unmarshal(p, &req) if err != nil { @@ -33,7 +32,7 @@ func (h *HttpHandle) AccountRecordsV2(ctx *gin.Context) { var ( funcName = "AccountRecordsV2" req ReqAccountRecords - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) diff --git a/http_server/handle/account_reverse_address.go b/http_server/handle/account_reverse_address.go index 43f6bb8..02f4423 100644 --- a/http_server/handle/account_reverse_address.go +++ b/http_server/handle/account_reverse_address.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "encoding/json" "fmt" "github.com/dotbitHQ/das-lib/common" @@ -24,7 +23,7 @@ type RespAccountReverseAddress struct { type AccountReverseAddress struct { } -func (h *HttpHandle) JsonRpcAccountReverseAddress(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcAccountReverseAddress(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqAccountReverseAddress err := json.Unmarshal(p, &req) if err != nil { @@ -47,7 +46,7 @@ func (h *HttpHandle) AccountReverseAddress(ctx *gin.Context) { var ( funcName = "AccountReverseAddress" req ReqAccountReverseAddress - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -66,7 +65,7 @@ func (h *HttpHandle) AccountReverseAddress(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doAccountReverseAddress(req *ReqAccountReverseAddress, apiResp *code.ApiResp) error { +func (h *HttpHandle) doAccountReverseAddress(req *ReqAccountReverseAddress, apiResp *http_api.ApiResp) error { var resp RespAccountReverseAddress resp.List = make([]core.ChainTypeAddress, 0) diff --git a/http_server/handle/address_account.go b/http_server/handle/address_account.go index f057875..e2f8f80 100644 --- a/http_server/handle/address_account.go +++ b/http_server/handle/address_account.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "encoding/json" "fmt" "github.com/dotbitHQ/das-lib/common" @@ -17,7 +16,7 @@ type ReqAddressAccount struct { Address string `json:"address"` } -func (h *HttpHandle) JsonRpcAddressAccount(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcAddressAccount(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqAddressAccount err := json.Unmarshal(p, &req) if err != nil { @@ -46,7 +45,7 @@ func (h *HttpHandle) AddressAccount(ctx *gin.Context) { var ( funcName = "AddressAccount" req ReqAddressAccount - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) @@ -66,7 +65,7 @@ func (h *HttpHandle) AddressAccount(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doAddressAccount(req *ReqAddressAccount, apiResp *code.ApiResp) error { +func (h *HttpHandle) doAddressAccount(req *ReqAddressAccount, apiResp *http_api.ApiResp) error { var resp = make([]RespSearchAccount, 0) addrHex, err := formatAddress(h.DasCore.Daf(), req.Address) diff --git a/http_server/handle/batch_account_records.go b/http_server/handle/batch_account_records.go index fbaf8b6..d443b0b 100644 --- a/http_server/handle/batch_account_records.go +++ b/http_server/handle/batch_account_records.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -28,7 +27,7 @@ type BatchAccountRecord struct { ErrMsg string `json:"err_msg"` } -func (h *HttpHandle) JsonRpcBatchAccountRecords(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcBatchAccountRecords(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqBatchAccountRecords err := json.Unmarshal(p, &req) if err != nil { @@ -51,7 +50,7 @@ func (h *HttpHandle) BatchAccountRecords(ctx *gin.Context) { var ( funcName = "BatchAccountRecords" req ReqBatchAccountRecords - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -70,7 +69,7 @@ func (h *HttpHandle) BatchAccountRecords(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doBatchAccountRecords(req *ReqBatchAccountRecords, apiResp *code.ApiResp) error { +func (h *HttpHandle) doBatchAccountRecords(req *ReqBatchAccountRecords, apiResp *http_api.ApiResp) error { var resp RespBatchAccountRecords resp.List = make([]BatchAccountRecord, 0) diff --git a/http_server/handle/batch_register_info.go b/http_server/handle/batch_register_info.go index e41e1da..db62ff8 100644 --- a/http_server/handle/batch_register_info.go +++ b/http_server/handle/batch_register_info.go @@ -3,7 +3,6 @@ package handle import ( "bytes" "das-account-indexer/config" - "das-account-indexer/http_server/code" "encoding/binary" "encoding/json" "errors" @@ -34,7 +33,7 @@ func (h *HttpHandle) BatchRegisterInfo(ctx *gin.Context) { var ( funcName = "BatchRegisterInfo" req ReqBatchRegisterInfo - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -52,7 +51,7 @@ func (h *HttpHandle) BatchRegisterInfo(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) JsonRpcBatchRegisterInfo(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcBatchRegisterInfo(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqBatchRegisterInfo err := json.Unmarshal(p, &req) if err != nil { @@ -71,7 +70,7 @@ func (h *HttpHandle) JsonRpcBatchRegisterInfo(p json.RawMessage, apiResp *code.A } } -func (h *HttpHandle) doBatchRegisterInfo(req *ReqBatchRegisterInfo, apiResp *code.ApiResp) error { +func (h *HttpHandle) doBatchRegisterInfo(req *ReqBatchRegisterInfo, apiResp *http_api.ApiResp) error { accIds := make([]string, 0, len(req.BatchAccount)) for _, v := range req.BatchAccount { accIds = append(accIds, common.Bytes2Hex(common.GetAccountIdByAccount(v))) diff --git a/http_server/handle/batch_reverse_record.go b/http_server/handle/batch_reverse_record.go index 5c08b69..c7baeb4 100644 --- a/http_server/handle/batch_reverse_record.go +++ b/http_server/handle/batch_reverse_record.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -29,7 +28,7 @@ type BatchReverseRecord struct { ErrMsg string `json:"err_msg"` } -func (h *HttpHandle) JsonRpcBatchReverseRecord(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcBatchReverseRecord(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqBatchReverseRecord err := json.Unmarshal(p, &req) if err != nil { @@ -52,7 +51,7 @@ func (h *HttpHandle) BatchReverseRecord(ctx *gin.Context) { var ( funcName = "BatchReverseRecord" req ReqBatchReverseRecord - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -71,7 +70,7 @@ func (h *HttpHandle) BatchReverseRecord(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doBatchReverseRecord(req *ReqBatchReverseRecord, apiResp *code.ApiResp) error { +func (h *HttpHandle) doBatchReverseRecord(req *ReqBatchReverseRecord, apiResp *http_api.ApiResp) error { var resp RespBatchReverseRecord resp.List = make([]BatchReverseRecord, 0) @@ -109,7 +108,7 @@ func (h *HttpHandle) doBatchReverseRecord(req *ReqBatchReverseRecord, apiResp *c return nil } -func (h *HttpHandle) checkReverse(chainType common.ChainType, addressHex string, apiResp *code.ApiResp) (account, errMsg string) { +func (h *HttpHandle) checkReverse(chainType common.ChainType, addressHex string, apiResp *http_api.ApiResp) (account, errMsg string) { reverse, err := h.DbDao.FindLatestReverseRecord(chainType, addressHex, "") if err != nil { log.Error("FindLatestReverseRecord err: ", err.Error(), addressHex) diff --git a/http_server/handle/did_list.go b/http_server/handle/did_list.go index 6220769..b8d59db 100644 --- a/http_server/handle/did_list.go +++ b/http_server/handle/did_list.go @@ -3,6 +3,7 @@ package handle import ( "context" "das-account-indexer/tables" + "encoding/json" "fmt" "github.com/dotbitHQ/das-lib/common" "github.com/dotbitHQ/das-lib/core" @@ -24,12 +25,29 @@ type RespDidList struct { } type DidData struct { - Outpoint string `json:"outpoint"` - AccountId string `json:"account_id"` - Account string `json:"account"` - Args string `json:"args"` - ExpiredAt uint64 `json:"expired_at"` - DidCellStatus tables.DidCellStatus `json:"did_cell_status"` + Outpoint string `json:"outpoint"` + AccountId string `json:"account_id"` + Account string `json:"account"` + ExpiredAt uint64 `json:"expired_at"` +} + +func (h *HttpHandle) JsonRpcDidList(ctx *gin.Context, p json.RawMessage, apiResp *http_api.ApiResp) { + var req []ReqDidList + err := json.Unmarshal(p, &req) + if err != nil { + log.Error("json.Unmarshal err:", err.Error()) + apiResp.ApiRespErr(http_api.ApiCodeParamsInvalid, "params invalid") + return + } + if len(req) != 1 { + log.Error("len(req) is :", len(req)) + apiResp.ApiRespErr(http_api.ApiCodeParamsInvalid, "params invalid") + return + } + + if err = h.doDidList(ctx, &req[0], apiResp); err != nil { + log.Error("doDidList err:", err.Error()) + } } func (h *HttpHandle) DidList(ctx *gin.Context) { @@ -77,12 +95,10 @@ func (h *HttpHandle) doDidList(ctx context.Context, req *ReqDidList, apiResp *ht } for _, v := range res { temp := DidData{ - Outpoint: v.Outpoint, - Account: v.Account, - AccountId: v.AccountId, - Args: v.Args, - ExpiredAt: v.ExpiredAt, - DidCellStatus: req.DidType, + Outpoint: v.Outpoint, + Account: v.Account, + AccountId: v.AccountId, + ExpiredAt: v.ExpiredAt, } data = append(data, temp) } diff --git a/http_server/handle/query.go b/http_server/handle/query.go index 5c269fa..b301183 100644 --- a/http_server/handle/query.go +++ b/http_server/handle/query.go @@ -15,7 +15,7 @@ func (h *HttpHandle) Query(ctx *gin.Context) { var ( req http_api.JsonRequest resp http_api.JsonResponse - apiResp code.ApiResp + apiResp http_api.ApiResp clientIp = GetClientIp(ctx) ) resp.Result = &apiResp @@ -56,7 +56,7 @@ func (h *HttpHandle) QueryIndexer(ctx *gin.Context) { var ( req http_api.JsonRequest resp http_api.JsonResponse - apiResp code.ApiResp + apiResp http_api.ApiResp clientIp = GetClientIp(ctx) ) resp.Result = &apiResp @@ -106,6 +106,8 @@ func (h *HttpHandle) QueryIndexer(ctx *gin.Context) { h.JsonRpcSubAccountList(req.Params, &apiResp) case code.MethodSubAccountVerify: h.JsonRpcSubAccountVerify(req.Params, &apiResp) + case code.MethodDidCellList: + h.JsonRpcDidList(ctx, req.Params, &apiResp) default: log.Error("method not exist:", req.Method) apiResp.ApiRespErr(http_api.ApiCodeMethodNotExist, fmt.Sprintf("method [%s] not exits", req.Method)) @@ -119,7 +121,7 @@ func (h *HttpHandle) QueryReverse(ctx *gin.Context) { var ( req http_api.JsonRequest resp http_api.JsonResponse - apiResp code.ApiResp + apiResp http_api.ApiResp clientIp = GetClientIp(ctx) ) resp.Result = &apiResp diff --git a/http_server/handle/reverse_record.go b/http_server/handle/reverse_record.go index a90dd80..8a7631e 100644 --- a/http_server/handle/reverse_record.go +++ b/http_server/handle/reverse_record.go @@ -2,7 +2,6 @@ package handle import ( "das-account-indexer/config" - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -26,7 +25,7 @@ type RespReverseRecord struct { DisplayName string `json:"display_name"` } -func (h *HttpHandle) JsonRpcReverseRecord(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcReverseRecord(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqReverseRecord err := json.Unmarshal(p, &req) if err != nil { @@ -49,7 +48,7 @@ func (h *HttpHandle) ReverseRecord(ctx *gin.Context) { var ( funcName = "ReverseRecord" req ReqReverseRecord - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) @@ -69,7 +68,7 @@ func (h *HttpHandle) ReverseRecord(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func checkReqKeyInfo(daf *core.DasAddressFormat, req *core.ChainTypeAddress, apiResp *code.ApiResp) *core.DasAddressHex { +func checkReqKeyInfo(daf *core.DasAddressFormat, req *core.ChainTypeAddress, apiResp *http_api.ApiResp) *core.DasAddressHex { if req.Type != "blockchain" { apiResp.ApiRespErr(http_api.ApiCodeParamsInvalid, fmt.Sprintf("type [%s] is invalid", req.Type)) return nil @@ -115,7 +114,7 @@ func checkReqKeyInfo(daf *core.DasAddressFormat, req *core.ChainTypeAddress, api return &addrHex } -func (h *HttpHandle) doReverseRecord(req *ReqReverseRecord, apiResp *code.ApiResp) error { +func (h *HttpHandle) doReverseRecord(req *ReqReverseRecord, apiResp *http_api.ApiResp) error { var resp RespReverseRecord res := checkReqKeyInfo(h.DasCore.Daf(), &req.ChainTypeAddress, apiResp) if apiResp.ErrNo != http_api.ApiCodeSuccess { diff --git a/http_server/handle/search_account.go b/http_server/handle/search_account.go index c52d492..01fdc03 100644 --- a/http_server/handle/search_account.go +++ b/http_server/handle/search_account.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -43,7 +42,7 @@ type AccountData struct { DisplayName string `json:"display_name"` } -func (h *HttpHandle) JsonRpcSearchAccount(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcSearchAccount(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqSearchAccount err := json.Unmarshal(p, &req) if err != nil { @@ -72,7 +71,7 @@ func (h *HttpHandle) SearchAccount(ctx *gin.Context) { var ( funcName = "SearchAccount" req ReqSearchAccount - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) @@ -92,7 +91,7 @@ func (h *HttpHandle) SearchAccount(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doSearchAccount(req *ReqSearchAccount, apiResp *code.ApiResp) error { +func (h *HttpHandle) doSearchAccount(req *ReqSearchAccount, apiResp *http_api.ApiResp) error { var resp RespSearchAccount req.Account = strings.TrimSpace(req.Account) diff --git a/http_server/handle/server_info.go b/http_server/handle/server_info.go index 05eab4e..14705a9 100644 --- a/http_server/handle/server_info.go +++ b/http_server/handle/server_info.go @@ -2,9 +2,9 @@ package handle import ( "das-account-indexer/block_parser" - "das-account-indexer/http_server/code" "encoding/json" "github.com/dotbitHQ/das-lib/common" + "github.com/dotbitHQ/das-lib/http_api" "github.com/gin-gonic/gin" "net/http" ) @@ -15,7 +15,7 @@ type RespServerInfo struct { Chain string `json:"chain"` } -func (h *HttpHandle) JsonRpcServerInfo(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcServerInfo(p json.RawMessage, apiResp *http_api.ApiResp) { if err := h.doServerInfo(apiResp); err != nil { log.Error("doServerInfo err:", err.Error()) } @@ -24,7 +24,7 @@ func (h *HttpHandle) JsonRpcServerInfo(p json.RawMessage, apiResp *code.ApiResp) func (h *HttpHandle) ServerInfo(ctx *gin.Context) { var ( funcName = "ServerInfo" - apiResp code.ApiResp + apiResp http_api.ApiResp err error clientIp = GetClientIp(ctx) ) @@ -38,7 +38,7 @@ func (h *HttpHandle) ServerInfo(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doServerInfo(apiResp *code.ApiResp) error { +func (h *HttpHandle) doServerInfo(apiResp *http_api.ApiResp) error { var resp RespServerInfo resp.IsLatestBlockNumber = block_parser.IsLatestBlockNumber diff --git a/http_server/handle/sub_account_list.go b/http_server/handle/sub_account_list.go index f6ada31..3f978ff 100644 --- a/http_server/handle/sub_account_list.go +++ b/http_server/handle/sub_account_list.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "das-account-indexer/tables" "encoding/json" "fmt" @@ -40,7 +39,7 @@ type SubAccountInfo struct { DisplayName string `json:"display_name"` } -func (h *HttpHandle) JsonRpcSubAccountList(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcSubAccountList(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqSubAccountList err := json.Unmarshal(p, &req) if err != nil { @@ -63,7 +62,7 @@ func (h *HttpHandle) SubAccountList(ctx *gin.Context) { var ( funcName = "SubAccountList" req ReqSubAccountList - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -82,7 +81,7 @@ func (h *HttpHandle) SubAccountList(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doSubAccountList(req *ReqSubAccountList, apiResp *code.ApiResp) error { +func (h *HttpHandle) doSubAccountList(req *ReqSubAccountList, apiResp *http_api.ApiResp) error { var resp RespSubAccountList resp.SubAccountList = make([]SubAccountInfo, 0) diff --git a/http_server/handle/sub_account_verify.go b/http_server/handle/sub_account_verify.go index d4dc978..b2cdcad 100644 --- a/http_server/handle/sub_account_verify.go +++ b/http_server/handle/sub_account_verify.go @@ -1,7 +1,6 @@ package handle import ( - "das-account-indexer/http_server/code" "encoding/json" "fmt" "github.com/dotbitHQ/das-lib/common" @@ -22,7 +21,7 @@ type RespSubAccountVerify struct { IsSubdid bool `json:"is_subdid"` } -func (h *HttpHandle) JsonRpcSubAccountVerify(p json.RawMessage, apiResp *code.ApiResp) { +func (h *HttpHandle) JsonRpcSubAccountVerify(p json.RawMessage, apiResp *http_api.ApiResp) { var req []ReqSubAccountVerify err := json.Unmarshal(p, &req) if err != nil { @@ -44,7 +43,7 @@ func (h *HttpHandle) SubAccountVerify(ctx *gin.Context) { var ( funcName = "SubAccountList" req ReqSubAccountVerify - apiResp code.ApiResp + apiResp http_api.ApiResp err error ) @@ -63,7 +62,7 @@ func (h *HttpHandle) SubAccountVerify(ctx *gin.Context) { ctx.JSON(http.StatusOK, apiResp) } -func (h *HttpHandle) doSubAccountVerify(req *ReqSubAccountVerify, apiResp *code.ApiResp) error { +func (h *HttpHandle) doSubAccountVerify(req *ReqSubAccountVerify, apiResp *http_api.ApiResp) error { var resp RespSubAccountVerify accountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.Account)) var subAccountId string diff --git a/http_server/router.go b/http_server/router.go index a20067d..68417c0 100644 --- a/http_server/router.go +++ b/http_server/router.go @@ -36,7 +36,7 @@ func (h *HttpServer) initRouter() { 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("/did/list", code.DoMonitorLog("did_list"), cacheHandle, h.H.DidList) // v1Indexer.POST("/record/list", code.DoMonitorLog("records_list"), h.H.AccountRecords) // } v2Indexer := h.engineIndexer.Group("v2")