Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
699 changes: 320 additions & 379 deletions docs/docs.go

Large diffs are not rendered by default.

699 changes: 320 additions & 379 deletions docs/swagger.json

Large diffs are not rendered by default.

508 changes: 234 additions & 274 deletions docs/swagger.yaml

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import (
)

// @title Rubix Core
// @version 0.9
// @version 1.0
// @description Rubix core API to control & manage the node.

// @contact.name API Support
// @contact.email murali.c@ensurity.com

// @BasePath

// @securityDefinitions.apikey SessionToken
Expand Down
8 changes: 0 additions & 8 deletions server/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ func (s *Server) BasicResponse(req *ensweb.Request, status bool, msg string, res
return s.RenderJSON(req, &resp, http.StatusOK)
}

// ShowAccount godoc
// @Summary Start Core
// @Description It will setup the core if not done before
// @Tags Basic
// @Accept json
// @Produce json
// @Success 200 {object} model.BasicResponse
// @Router /api/start [get]
func (s *Server) APIStart(req *ensweb.Request) *ensweb.Result {
status, msg := s.c.Start()
return s.BasicResponse(req, status, msg, nil)
Expand Down
47 changes: 42 additions & 5 deletions server/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ func (s *Server) APIGetDIDChallenge(req *ensweb.Request) *ensweb.Result {
return s.RenderJSON(req, resp, http.StatusOK)
}

// APICreateDID will create new DID
// CreateDID godoc
// @Summary Create DID
// @Description Creates a new DID with the provided public key, password, and mnemonic.
// @Tags DID
// @Accept json
// @Produce json
// @Param request body types.DIDCreate true "Create DID Request"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/dids/create [post]
func (s *Server) APICreateDID(req *ensweb.Request) *ensweb.Result {
var didCreate types.DIDCreate
err := s.ParseJSON(req, &didCreate)
Expand Down Expand Up @@ -64,7 +73,15 @@ func (s *Server) APICreateDID(req *ensweb.Request) *ensweb.Result {
return s.BasicResponse(req, true, "DID created successfully", didResp)
}

// APIGetAllDID will get all DID
// GetAllDIDs godoc
// @Summary Get All DIDs
// @Description Retrieves a list of all DIDs.
// @Tags DID
// @Accept json
// @Produce json
// @Success 200 {object} model.BasicResponse
// @Failure 500 {object} model.BasicResponse
// @Router /rubix/v1/dids [get]
func (s *Server) APIGetAllDID(req *ensweb.Request) *ensweb.Result {
ok := s.validateAccess(req)
if !ok {
Expand Down Expand Up @@ -106,6 +123,16 @@ func (s *Server) didResponse(req *ensweb.Request, reqID string) *ensweb.Result {
return s.RenderJSON(req, &model.BasicResponse{Status: false, Message: "Invalid response"}, http.StatusOK)
}

// RegisterDID godoc
// @Summary Register DID
// @Description Registers a DID on the network.
// @Tags DID
// @Accept json
// @Produce json
// @Param did path string true "DID to register (e.g. did:bafybmih2cqn6okxy2sepgp75jq5dkopuohnbd3pfrrylmqnrz43ttihkky)"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/dids/{did}/register [post]
func (s *Server) APIRegisterDID(req *ensweb.Request) *ensweb.Result {
didStr := s.GetRouteVar(req, "did")
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(didStr)
Expand Down Expand Up @@ -171,7 +198,7 @@ func (s *Server) APISetupDID(req *ensweb.Request) *ensweb.Result {
// @Param input body model.ArbitrarySignRequest true "Arbitrary Signature Request"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /api/sign [post]
// @Router /rubix/v1/signature/arbitrary [post]
func (s *Server) APIArbitrarySignature(req *ensweb.Request) *ensweb.Result {
var signReq model.ArbitrarySignRequest
err := s.ParseJSON(req, &signReq)
Expand All @@ -197,7 +224,7 @@ func (s *Server) APIArbitrarySignature(req *ensweb.Request) *ensweb.Result {
// @Param signature query string true "Signature to verify"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /api/verify-signature [get]
// @Router /rubix/v1/signature/verify [get]
func (s *Server) APISignVerification(req *ensweb.Request) *ensweb.Result {
var verificationReq model.SignVerificationRequest
verificationReq.SignerDID = s.GetQuery(req, "signer_did")
Expand Down Expand Up @@ -237,6 +264,16 @@ func (s *Server) APIRemoveStaleDID(req *ensweb.Request) *ensweb.Result {
return s.didResponse(req, req.ID)
}

// GetDIDBalance godoc
// @Summary Get DID Balance
// @Description Retrieves the overall balance (RBT, FT, NFT) for a given DID.
// @Tags DID
// @Accept json
// @Produce json
// @Param did path string true "DID (e.g. did:bafybmih3l2emb4s7wbsgakwv4voaqngdirpg5f3kqlheqqsgdg7jthuwaq)"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/dids/{did}/balances [get]
func (s *Server) APIGetDIDBalance(req *ensweb.Request) *ensweb.Result {
did := s.GetRouteVar(req, "did")
if !s.validateDIDAccess(req, did) {
Expand All @@ -252,7 +289,7 @@ func (s *Server) APIGetDIDBalance(req *ensweb.Request) *ensweb.Result {
DID: did,
}
ac := model.BasicResponse{
Status: true,
Status: true,
}
rbtInfo, err := s.c.GetRbtByDid(did)
if err != nil {
Expand Down
26 changes: 9 additions & 17 deletions server/ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ func (s *Server) APICreateFT(req *ensweb.Request) *ensweb.Result {
return s.didResponse(req, req.ID)
}

// ShowAccount godoc
// @Summary Initiate an FT transfer
// @Description This API endpoint will initiate transfer of FTs.
// @Tags FT
// @Accept json
// @Produce json
// @Param input body TransferFTReqSwaggoInput true "Transfer FT"
// @Success 200 {object} model.BasicResponse
// @Router /api/initiate-ft-transfer [post]
func (s *Server) APIInitiateFTTransfer(req *ensweb.Request) *ensweb.Result {
var rbtReq model.TransferFTReq
err := s.ParseJSON(req, &rbtReq)
Expand All @@ -81,15 +72,16 @@ func (s *Server) APIInitiateFTTransfer(req *ensweb.Request) *ensweb.Result {
return s.didResponse(req, req.ID)
}

// ShowAccount godoc
// @Summary Get FT balance information for a given DID
// @Description This API endpoint retrieves the names and count of FTs of a given DID.
// @Tags FT
// GetFTBalance godoc
// @Summary Get FT Balance
// @Description Retrieves the Fungible Token (FT) balance for a given DID.
// @Tags DID
// @Accept json
// @Produce json
// @Param did query string true "User DID"
// @Success 200 {object} model.GetFTInfo
// @Router /api/get-ft-info-by-did [get]
// @Param did path string true "DID (e.g. did:bafybmih3l2emb4s7wbsgakwv4voaqngdirpg5f3kqlheqqsgdg7jthuwaq)"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/dids/{did}/balances/ft [get]
func (s *Server) APIGetFTInfo(req *ensweb.Request) *ensweb.Result {
did := s.GetRouteVar(req, "did")
if !s.validateDIDAccess(req, did) {
Expand Down Expand Up @@ -168,7 +160,7 @@ func (s *Server) APIGetFTCreatorStats(req *ensweb.Request) *ensweb.Result {
// ShowAccount godoc
// @Summary List FTs
// @Description This API endpoint will list FTs.
// @Tags fts
// @Tags FT
// @Accept json
// @Produce json
// @Success 200 {object} model.BasicResponse
Expand Down
15 changes: 8 additions & 7 deletions server/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,16 @@ type GetNFTSwaggoInput struct {
Did string `json:"did"`
}

// ShowAccount godoc
// @Summary Get NFTs owned by the particular did
// @Description This API will get all NFTs owned by the particular did
// @Tags NFT
// GetNFTBalance godoc
// @Summary Get NFT Balance
// @Description Retrieves the Non-Fungible Token (NFT) balance for a given DID.
// @Tags DID
// @Accept json
// @Produce json
// @Param input query GetNFTSwaggoInput true "Get nfts by did"
// @Success 200 {object} model.NFTList
// @Router /api/get-nfts-by-did [get]
// @Param did path string true "DID (e.g. did:bafybmih3l2emb4s7wbsgakwv4voaqngdirpg5f3kqlheqqsgdg7jthuwaq)"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/dids/{did}/balances/nft [get]
func (s *Server) APIGetNFTsByDid(req *ensweb.Request) *ensweb.Result {
did := s.GetQuery(req, "did")
resp, err := s.c.GetNFTsByDid(did)
Expand Down
9 changes: 0 additions & 9 deletions server/self_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ type RBTSelfTransferRequestSwaggoInput struct {
Type int `json:"type"`
}

// @Summary Initiate Self Transfer
// @Description This API will initiate self RBT transfer for a specific DID
// @Tags Account
// @ID initiate-self-transfer
// @Accept json
// @Produce json
// @Param input body RBTSelfTransferRequestSwaggoInput true "Intitate Self RBT transfer"
// @Success 200 {object} model.BasicResponse
// @Router /api/initiate-self-transfer [post]
func (s *Server) SelfTransferHandle(req *ensweb.Request) *ensweb.Result {
var selfTransferReq model.RBTTransferRequest
err := s.ParseJSON(req, &selfTransferReq)
Expand Down
48 changes: 17 additions & 31 deletions server/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ type RBTTransferRequestSwaggoInput struct {
Type int `json:"type"`
}

// ShowAccount godoc
// @Summary Check account balance
// @Description For a mentioned DID, check the account balance
// @Tags Account
// GetRBTBalance godoc
// @Summary Get RBT Balance
// @Description Retrieves the RBT token balance for a given DID.
// @Tags DID
// @Accept json
// @Produce json
// @Param did query string true "User DID"
// @Success 200 {object} model.BasicResponse
// @Router /api/get-account-info [get]
// @Param did path string true "DID (e.g. did:bafybmih3l2emb4s7wbsgakwv4voaqngdirpg5f3kqlheqqsgdg7jthuwaq)"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/dids/{did}/balances/rbt [get]
func (s *Server) APIGetRbtByDid(req *ensweb.Request) *ensweb.Result {
did := s.GetRouteVar(req, "did")
if !s.validateDIDAccess(req, did) {
Expand All @@ -84,10 +85,10 @@ func (s *Server) APIGetRbtByDid(req *ensweb.Request) *ensweb.Result {
return s.BasicResponse(req, false, err.Error(), nil)
}
ac := model.BasicResponse{
Status: true,
Message: "Got account info successfully",
Result: info,
}
Status: true,
Message: "Got account info successfully",
Result: info,
}
return s.RenderJSON(req, ac, http.StatusOK)
}

Expand All @@ -100,13 +101,14 @@ type SignatureResponseSwaggoInput struct {
// ShowAccount godoc
// @Summary Signature Response
// @Description This API is used to supply the password for the node along with the ID generated when Initiate RBT transfer is called.
// @Tags Account
// @Tags Signature
// @ID signature-response
// @Accept json
// @Produce json
// @Param input body SignatureResponseSwaggoInput true "Send input for requested signature"
// @Success 200 {object} model.BasicResponse
// @Router /api/signature-response [post]
// @Param input body types.SignRespData true "Send input for requested signature"
// @Success 200 {object} model.BasicResponse
// @Failure 400 {object} model.BasicResponse
// @Router /rubix/v1/signature [post]
func (s *Server) APISignatureResponse(req *ensweb.Request) *ensweb.Result {
var resp types.SignRespData
err := s.ParseJSON(req, &resp)
Expand All @@ -122,13 +124,6 @@ func (s *Server) APISignatureResponse(req *ensweb.Request) *ensweb.Result {
return s.didResponse(req, resp.ID)
}

// APIGetPledgedTokenDetails godoc
// @Summary Get details about the pledged tokens
// @Description This API allows the user to get details about the tokens the quorums have pledged i.e. which token is pledged for which token state
// @Tags Account
// @Produce json
// @Success 200 {object} model.TokenStateResponse
// @Router /api/get-pledgedtoken-details [get]
func (s *Server) APIGetPledgedTokenDetails(req *ensweb.Request) *ensweb.Result {
pledgedTokenInfo, err := s.c.GetPledgedInfo()
if err != nil {
Expand All @@ -145,15 +140,6 @@ func (s *Server) APIGetPledgedTokenDetails(req *ensweb.Request) *ensweb.Result {
return s.RenderJSON(req, tokenstateresponse, http.StatusOK)
}

// APICheckPinnedState godoc
// @Summary Check for exhausted token state hash
// @Description This API is used to check if the token state for which the token is pledged is exhausted or not.
// @Tags Account
// @Accept json
// @Produce json
// @Param tokenstatehash query string true "Token State Hash"
// @Success 200 {object} model.BasicResponse
// @Router /api/check-pinned-state [delete]
func (s *Server) APICheckPinnedState(req *ensweb.Request) *ensweb.Result {
tokenstatehash := s.GetQuery(req, "tokenstatehash")

Expand Down