-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from JackalLabs/marston/backport-api
Back-porting API
- Loading branch information
Showing
8 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ jobs: | |
- uses: actions/[email protected] | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.21.0 # The Go version to download (if necessary) and use. | ||
go-version: 1.22.2 # The Go version to download (if necessary) and use. | ||
- name: Build CLI | ||
run: go install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ jobs: | |
- uses: actions/[email protected] | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.21.0 # The Go version to download (if necessary) and use. | ||
go-version: 1.22.0 # The Go version to download (if necessary) and use. | ||
- name: Get Coverage | ||
run: | | ||
go test ./... -timeout=30m -cover -coverprofile coverage.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ jobs: | |
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.21.0 | ||
go-version: 1.22.2 | ||
- uses: actions/[email protected] | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ jobs: | |
- uses: actions/[email protected] | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.20.2 # The Go version to download (if necessary) and use. | ||
go-version: 1.22.2 # The Go version to download (if necessary) and use. | ||
- name: Build CLI | ||
shell: bash | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ jobs: | |
- uses: actions/[email protected] | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.20.2 # The Go version to download (if necessary) and use. | ||
go-version: 1.22.2 # The Go version to download (if necessary) and use. | ||
- name: Test | ||
shell: bash | ||
run: make test-unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/JackalLabs/sequoia/api/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/desmos-labs/cosmos-go-wallet/client" | ||
storageTypes "github.com/jackalLabs/canine-chain/v4/x/storage/types" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func SpaceHandler(c *client.Client, address string) func(http.ResponseWriter, *http.Request) { | ||
return func(w http.ResponseWriter, req *http.Request) { | ||
queryClient := storageTypes.NewQueryClient(c.GRPCConn) | ||
|
||
params := &storageTypes.QueryProvider{ | ||
Address: address, | ||
} | ||
res, err := queryClient.Provider(context.Background(), params) | ||
if err != nil { | ||
v := types.ErrorResponse{ | ||
Error: err.Error(), | ||
} | ||
w.WriteHeader(http.StatusInternalServerError) | ||
err = json.NewEncoder(w).Encode(v) | ||
if err != nil { | ||
log.Error().Err(err) | ||
} | ||
return | ||
} | ||
|
||
totalSpace := res.Provider.Totalspace | ||
|
||
fsparams := &storageTypes.QueryFreeSpace{ | ||
Address: address, | ||
} | ||
fsres, err := queryClient.FreeSpace(context.Background(), fsparams) | ||
if err != nil { | ||
v := types.ErrorResponse{ | ||
Error: err.Error(), | ||
} | ||
w.WriteHeader(http.StatusInternalServerError) | ||
err = json.NewEncoder(w).Encode(v) | ||
if err != nil { | ||
log.Error().Err(err) | ||
} | ||
return | ||
} | ||
|
||
freeSpace := fsres.Space | ||
|
||
ttint, ok := sdk.NewIntFromString(totalSpace) | ||
if !ok { | ||
return | ||
} | ||
|
||
v := types.SpaceResponse{ | ||
Total: ttint.Int64(), | ||
Free: freeSpace, | ||
Used: ttint.Int64() - freeSpace, | ||
} | ||
|
||
err = json.NewEncoder(w).Encode(v) | ||
if err != nil { | ||
log.Error().Err(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters