Compare commits

...
Author SHA1 Message Date
aleem1314 8a575110bf chore: fix error message 2023-03-14 12:00:29 +05:30
aleem1314 c72302d078 wip: fix lint errors 2023-03-14 11:50:50 +05:30
aleem1314 ddd01ccd8a wip: fix lint 2023-03-14 11:29:38 +05:30
aleem1314 4b71df048e chore: fix lint errors 2023-03-14 11:05:23 +05:30
iszubok 5f6a9f56bb Merge pull request #98 from cerc-io/update-validator-doc-v0.8.0
update validator doc for v0.8.0 and laconic_81337-6
2023-03-10 08:49:01 +02:00
Ivan Zubok 71c15cd2eb update validator doc for v0.8.0 and laconic_81337-6 2023-03-10 06:35:33 +00:00
Michael c227a38e9a tests must be run against different chain configurations (#91)
* tests must be run against different chain configurations

* compose args order matters

* x bit not set on auction tests shell script

* always run docker compose down... possibly to avoid insufficient funds error after a failed run

* add arg to docker compose down for auction and nameservice-expiry

* switch to main branch
2023-02-10 14:44:27 -05:00
22 changed files with 304 additions and 188 deletions
+25 -2
View File
@@ -102,8 +102,31 @@ jobs:
run: docker compose up -d
- name: run-tests.sh
working-directory: tests/sdk_tests
run: ./run-all-tests.sh
run: ./run-tests.sh
- name: reset containers for auction tests
working-directory: tests/sdk_tests
if: always()
run: docker compose down
- name: start auction containers
working-directory: tests/sdk_tests
run: docker compose -f docker-compose-auctions.yml up -d
- name: run-acution-tests.sh
working-directory: tests/sdk_tests
run: ./run-auction-tests.sh
- name: reset containers for nameservice tests
working-directory: tests/sdk_tests
if: always()
run: docker compose -f docker-compose-auctions.yml down
- name: start auction containers
working-directory: tests/sdk_tests
run: docker compose -f docker-compose-nameservice.yml up -d
- name: run-nameservice-expiry-tests.sh
working-directory: tests/sdk_tests
run: ./run-nameservice-expiry-tests.sh
- name: reset containers for nameservice tests
working-directory: tests/sdk_tests
if: always()
run: docker compose -f docker-compose-nameservice.yml down
# integration_tests:
# runs-on: ubuntu-latest
+24 -15
View File
@@ -1,4 +1,4 @@
# Validator Guide for laconic_81337-5 Testnet
# Validator Guide for laconic_81337-6 Testnet
## Hardware Prerequisites
@@ -48,8 +48,8 @@ sudo apt install git curl build-essential make jq -y
# Remove any existing installation of `go`
sudo rm -rf /usr/local/go
# Install Go version 1.18.8
curl https://dl.google.com/go/go1.18.8.linux-amd64.tar.gz | sudo tar -C/usr/local -zxvf -
# Install Go version 1.19.7
curl https://dl.google.com/go/go1.19.7.linux-amd64.tar.gz | sudo tar -C/usr/local -zxvf -
# Update env variables to include go
cat <<'EOF' >>$HOME/.profile
@@ -67,7 +67,7 @@ Check the version of go installed
```sh
go version
# Should return something like: go version go1.17.2 linux/amd64
# Should return something like: go version go1.19.7 linux/amd64
```
---
@@ -80,16 +80,17 @@ cd laconicd
# Checkout main branch
git fetch --all
git checkout v0.6.0
git checkout v0.8.0
# Build and install laconic
make install
make VERSION=v0.8.0 install
```
Verify your installation
```sh
laconicd version --long
```
On running the above command, you should see a similar response like this. Make sure that the _version_ and _commit
@@ -122,13 +123,13 @@ Make sure the directory `~/.laconicd` does not exist or is empty
>In order to run the below commands in a docker container:
>```sh
>docker run -ti -v ~/.laconicd:/root/.laconicd \
>git.vdb.to/cerc-io/laconicd/laconicd:v0.6.0 /bin/sh
>git.vdb.to/cerc-io/laconicd/laconicd:v0.8.0 /bin/sh
>```
---
```sh
# Initialize the validator node
laconicd init <your-node-moniker> --chain-id laconic_81337-5
laconicd init <your-node-moniker> --chain-id laconic_81337-6
```
Running the above commands will initialize the validator node with default configuration. The config files will be saved in the default location (`~/.laconicd/config`).
@@ -168,7 +169,7 @@ Create Your `gentx` transaction file
```sh
laconicd gentx <key-name> 12900000000000000000000achk \
--pubkey=$(laconicd tendermint show-validator) \
--chain-id="laconic_81337-5" \
--chain-id="laconic_81337-6" \
--moniker="<your-moniker-name>" \
--website="<your-validator-website>" \
--details="<your-validator-description>" \
@@ -198,10 +199,10 @@ Submit your `gentx` file to the [https://github.com/cerc-io/laconic-testnet](htt
To submit the gentx file, follow the below process:
- Fork the [https://github.com/cerc-io/laconic-testnet](https://github.com/cerc-io/laconic-testnet) repository
- Upload your gentx file in the `laconic_81337-5/config/gentxs` folder
- Upload your gentx file in the `laconic_81337-6/config/gentxs` folder
- Submit Pull Request to [https://github.com/cerc-io/laconic-testnet](https://github.com/cerc-io/laconic-testnet) with name `ADD <your-moniker> gentx`
The genesis file will be published in the `laconic_81337-5/config/` folder within the [https://github.com/cerc-io/laconic-testnet](https://github.com/cerc-io/laconic-testnet) repository.
The genesis file will be published in the `laconic_81337-6/config/` folder within the [https://github.com/cerc-io/laconic-testnet](https://github.com/cerc-io/laconic-testnet) repository.
# CONTINUE WITH BELOW STEPS ONLY AFTER GENESIS FILE HAS BEEN PUBLISHED
@@ -271,25 +272,33 @@ journalctl -f -u laconicd
In this example the Tendermint RPC and Prometheus metrics ports are exposed only to localhost. You may want to change 127.0.0.1 to private or public network interface of your host if you need to access these ports remotely.
```sh
docker create --name laconic-testnet-5 -v ~/.laconicd:/root/.laconicd -p 26656:26656 -p 127.0.0.1:26657:26657 -p 127.0.0.1:26660:26660 git.vdb.to/cerc-io/laconicd/laconicd:v0.6.0 laconicd start --gql-playground --gql-server --log_level=warn
docker create \
--name laconic-testnet-6 \
--restart always \
-v ~/.laconicd:/root/.laconicd \
-p 26656:26656 \
-p 127.0.0.1:26657:26657 \
-p 127.0.0.1:26660:26660 \
git.vdb.to/cerc-io/laconicd/laconicd:v0.8.0 \
laconicd start --gql-playground --gql-server --log_level=warn
```
### Run validator node
```sh
docker start laconic-testnet-5
docker start laconic-testnet-6
```
### Check validator node logs
```sh
docker logs laconic-testnet-5
docker logs laconic-testnet-6
```
### Run shell inside docker container
```sh
docker exec -ti laconic-testnet-5 /bin/sh
docker exec -ti laconic-testnet-6 /bin/sh
```
---
## Helpful commands
-1
View File
@@ -47,7 +47,6 @@ WORKDIR /app
RUN \
git clone https://github.com/cerc-io/laconic-sdk.git \
&& cd laconic-sdk \
&& git checkout auction_nameservice_tests \
&& yarn install
WORKDIR /app/laconic-sdk
@@ -0,0 +1,31 @@
services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
environment:
- TEST_AUCTION_ENABLED=true
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
healthcheck:
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
interval: 1s
timeout: 5s
retries: 30
ports:
- "6060"
- "26657"
- "26656"
- "9473"
- "8545"
- "8546"
- "9090"
- "9091"
- "1317"
sdk-test-runner:
image: cerc-io/laconic-sdk-tester:local-test
depends_on:
laconicd:
condition: service_healthy
command: tail -F /dev/null
@@ -0,0 +1,31 @@
services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
environment:
- TEST_REGISTRY_EXPIRY=true
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
healthcheck:
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
interval: 1s
timeout: 5s
retries: 30
ports:
- "6060"
- "26657"
- "26656"
- "9473"
- "8545"
- "8546"
- "9090"
- "9091"
- "1317"
sdk-test-runner:
image: cerc-io/laconic-sdk-tester:local-test
depends_on:
laconicd:
condition: service_healthy
command: tail -F /dev/null
-3
View File
@@ -2,9 +2,6 @@ services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
environment:
- TEST_AUCTION_ENABLED=true
- TEST_REGISTRY_EXPIRY=true
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Get the key from laconicd
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
# Set parameters for the test suite
cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
# Run tests
docker network inspect sdk_tests_default
sleep 30s
docker logs sdk_tests-laconicd-1
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
@@ -11,8 +11,6 @@ laconicd_gql_endpoint=http://laconicd:9473/api
# Run tests
docker network inspect sdk_tests_default
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test"
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
docker logs sdk_tests-laconicd-1
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
+7 -6
View File
@@ -3,6 +3,7 @@ package keeper
import (
"context"
errors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -26,7 +27,7 @@ func (q Querier) Auctions(c context.Context, req *types.AuctionsRequest) (*types
func (q Querier) GetAuction(c context.Context, req *types.AuctionRequest) (*types.AuctionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.Id == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
}
resp := q.Keeper.GetAuction(ctx, req.Id)
@@ -37,10 +38,10 @@ func (q Querier) GetAuction(c context.Context, req *types.AuctionRequest) (*type
func (q Querier) GetBid(c context.Context, req *types.BidRequest) (*types.BidResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.AuctionId == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
}
if req.Bidder == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
}
resp := q.Keeper.GetBid(ctx, req.AuctionId, req.Bidder)
return &types.BidResponse{Bid: &resp}, nil
@@ -50,7 +51,7 @@ func (q Querier) GetBid(c context.Context, req *types.BidRequest) (*types.BidRes
func (q Querier) GetBids(c context.Context, req *types.BidsRequest) (*types.BidsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.AuctionId == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
}
resp := q.Keeper.GetBids(ctx, req.AuctionId)
return &types.BidsResponse{Bids: resp}, nil
@@ -60,7 +61,7 @@ func (q Querier) GetBids(c context.Context, req *types.BidsRequest) (*types.Bids
func (q Querier) AuctionsByBidder(c context.Context, req *types.AuctionsByBidderRequest) (*types.AuctionsByBidderResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.BidderAddress == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
}
resp := q.Keeper.QueryAuctionsByBidder(ctx, req.BidderAddress)
return &types.AuctionsByBidderResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
@@ -70,7 +71,7 @@ func (q Querier) AuctionsByBidder(c context.Context, req *types.AuctionsByBidder
func (q Querier) AuctionsByOwner(c context.Context, req *types.AuctionsByOwnerRequest) (*types.AuctionsByOwnerResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.OwnerAddress == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "owner address is required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "owner address is required")
}
resp := q.Keeper.QueryAuctionsByOwner(ctx, req.OwnerAddress)
return &types.AuctionsByOwnerResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
+19 -18
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"time"
errors "cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/auction/types"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
@@ -306,7 +307,7 @@ func (k Keeper) CreateAuction(ctx sdk.Context, msg types.MsgCreateAuction) (*typ
// Generate auction Id.
account := k.accountKeeper.GetAccount(ctx, signerAddress)
if account == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "Account not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidAddress, "account not found")
}
auctionID := types.AuctionID{
@@ -340,12 +341,12 @@ func (k Keeper) CreateAuction(ctx sdk.Context, msg types.MsgCreateAuction) (*typ
func (k Keeper) CommitBid(ctx sdk.Context, msg types.MsgCommitBid) (*types.Bid, error) {
if !k.HasAuction(ctx, msg.AuctionId) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction not found")
}
auction := k.GetAuction(ctx, msg.AuctionId)
if auction.Status != types.AuctionStatusCommitPhase {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in commit phase.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction is not in commit phase")
}
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
@@ -390,12 +391,12 @@ func (k Keeper) CommitBid(ctx sdk.Context, msg types.MsgCommitBid) (*types.Bid,
// RevealBid reeals a bid committed earlier.
func (k Keeper) RevealBid(ctx sdk.Context, msg types.MsgRevealBid) (*types.Auction, error) {
if !k.HasAuction(ctx, msg.AuctionId) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction not found")
}
auction := k.GetAuction(ctx, msg.AuctionId)
if auction.Status != types.AuctionStatusRevealPhase {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in reveal phase.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "auction is not in reveal phase")
}
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
@@ -404,65 +405,65 @@ func (k Keeper) RevealBid(ctx sdk.Context, msg types.MsgRevealBid) (*types.Aucti
}
if !k.HasBid(ctx, msg.AuctionId, signerAddress.String()) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bid not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bid not found")
}
bid := k.GetBid(ctx, auction.Id, signerAddress.String())
if bid.Status != types.BidStatusCommitted {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bid not in committed state.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bid not in committed state")
}
revealBytes, err := hex.DecodeString(msg.Reveal)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal string.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal string")
}
cid, err := wnsUtils.CIDFromJSONBytes(revealBytes)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal JSON.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal JSON")
}
if bid.CommitHash != cid {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "commit hash mismatch")
}
var reveal map[string]interface{}
err = json.Unmarshal(revealBytes, &reveal)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Reveal JSON unmarshal error.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "reveal JSON unmarshal error")
}
chainID, err := wnsUtils.GetAttributeAsString(reveal, "chainId")
if err != nil || chainID != ctx.ChainID() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal chainID.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal chainID")
}
auctionID, err := wnsUtils.GetAttributeAsString(reveal, "auctionId")
if err != nil || auctionID != msg.AuctionId {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal auction Id.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal auction Id")
}
bidderAddress, err := wnsUtils.GetAttributeAsString(reveal, "bidderAddress")
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid address.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal bid address")
}
if bidderAddress != signerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Reveal bid address mismatch.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "reveal bid address mismatch")
}
bidAmountStr, err := wnsUtils.GetAttributeAsString(reveal, "bidAmount")
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal bid amount")
}
bidAmount, err := sdk.ParseCoinNormalized(bidAmountStr)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal bid amount")
}
if bidAmount.IsLT(auction.MinimumBid) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bid is lower than minimum bid")
}
// Lock bid amount.
+11 -10
View File
@@ -1,6 +1,7 @@
package types
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@@ -32,19 +33,19 @@ func (msg MsgCreateAuction) Type() string { return "create" }
// ValidateBasic Implements Msg.
func (msg MsgCreateAuction) ValidateBasic() error {
if msg.Signer == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if msg.CommitsDuration <= 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "commit phase duration invalid.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "commit phase duration invalid")
}
if msg.RevealsDuration <= 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid")
}
if !msg.MinimumBid.IsPositive() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero")
}
return nil
@@ -79,15 +80,15 @@ func (msg MsgCommitBid) Type() string { return "commit" }
// ValidateBasic Implements Msg.
func (msg MsgCommitBid) ValidateBasic() error {
if msg.Signer == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address")
}
if msg.AuctionId == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID")
}
if msg.CommitHash == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash")
}
return nil
@@ -122,15 +123,15 @@ func (msg MsgRevealBid) Type() string { return "reveal" }
// ValidateBasic Implements Msg.
func (msg MsgRevealBid) ValidateBasic() error {
if msg.Signer == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address")
}
if msg.AuctionId == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID")
}
if msg.Reveal == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data")
}
return nil
+3 -2
View File
@@ -3,6 +3,7 @@ package keeper
import (
"context"
"cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/bond/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -30,7 +31,7 @@ func (q Querier) GetBondByID(c context.Context, req *types.QueryGetBondByIDReque
ctx := sdk.UnwrapSDKContext(c)
bondID := req.GetId()
if len(bondID) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
}
bond := q.Keeper.GetBond(ctx, req.GetId())
return &types.QueryGetBondByIDResponse{Bond: &bond}, nil
@@ -40,7 +41,7 @@ func (q Querier) GetBondsByOwner(c context.Context, req *types.QueryGetBondsByOw
ctx := sdk.UnwrapSDKContext(c)
owner := req.GetOwner()
if len(owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "owner id required")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "owner id required")
}
bonds := q.Keeper.QueryBondsByOwner(ctx, owner)
return &types.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
+16 -15
View File
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/bond/types"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
@@ -113,7 +114,7 @@ func (k Keeper) CreateBond(ctx sdk.Context, ownerAddress sdk.AccAddress, coins s
for _, coin := range coins {
balance := k.bankKeeper.HasBalance(ctx, ownerAddress, coin)
if !balance {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "failed to create bond; Insufficient funds")
return nil, errors.Wrap(sdkerrors.ErrInsufficientFunds, "failed to create bond; Insufficient funds")
}
}
@@ -129,7 +130,7 @@ func (k Keeper) CreateBond(ctx sdk.Context, ownerAddress sdk.AccAddress, coins s
bond := types.Bond{Id: bondID, Owner: ownerAddress.String(), Balance: coins}
if bond.Balance.IsAnyGT(maxBondAmount) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "max bond amount exceeded")
}
// Move funds into the bond account module.
@@ -221,18 +222,18 @@ func (k Keeper) QueryBondsByOwner(ctx sdk.Context, ownerAddress string) []types.
// RefillBond refills an existing bond.
func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
if !k.HasBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bond not found")
}
bond := k.GetBond(ctx, id)
if bond.Owner != ownerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
// Check if account has funds.
for _, coin := range coins {
if !k.bankKeeper.HasBalance(ctx, ownerAddress, coin) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
return nil, errors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient funds")
}
}
@@ -240,7 +241,7 @@ func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddre
updatedBalance := bond.Balance.Add(coins...)
if updatedBalance.IsAnyGT(maxBondAmount) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "max bond amount exceeded")
}
// Move funds into the bond account module.
@@ -259,17 +260,17 @@ func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddre
// WithdrawBond withdraws funds from a bond.
func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
if !k.HasBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bond not found")
}
bond := k.GetBond(ctx, id)
if bond.Owner != ownerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
updatedBalance, isNeg := bond.Balance.SafeSub(coins...)
if isNeg {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient bond balance.")
return nil, errors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient bond balance")
}
// Move funds from the bond into the account.
@@ -288,18 +289,18 @@ func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAdd
// CancelBond cancels a bond, returning funds to the owner.
func (k Keeper) CancelBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress) (*types.Bond, error) {
if !k.HasBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "bond not found")
}
bond := k.GetBond(ctx, id)
if bond.Owner != ownerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
// Check if bond is used in other modules.
for _, usageKeeper := range k.usageKeepers {
if usageKeeper.UsesBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("Bond in use by the '%s' module.", usageKeeper.ModuleName()))
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("bond in use by the '%s' module", usageKeeper.ModuleName()))
}
}
@@ -330,7 +331,7 @@ func (k Keeper) GetBondModuleBalances(ctx sdk.Context) sdk.Coins {
// TransferCoinsToModuleAccount moves funds from the bonds module account to another module account.
func (k Keeper) TransferCoinsToModuleAccount(ctx sdk.Context, id, moduleAccount string, coins sdk.Coins) error {
if !k.HasBond(ctx, id) {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond not found.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond not found")
}
bondObj := k.GetBond(ctx, id)
@@ -340,13 +341,13 @@ func (k Keeper) TransferCoinsToModuleAccount(ctx sdk.Context, id, moduleAccount
if isNeg {
// Check if bond has sufficient funds.
return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
return errors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient funds")
}
// Move funds from bond module to record rent module.
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, moduleAccount, coins)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "error transferring funds")
}
// Update bond balance.
+11 -10
View File
@@ -1,6 +1,7 @@
package types
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@@ -28,10 +29,10 @@ func (msg MsgCreateBond) Type() string { return "create" }
func (msg MsgCreateBond) ValidateBasic() error {
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
return errors.Wrap(sdkerrors.ErrInvalidCoins, "invalid amount")
}
return nil
}
@@ -64,13 +65,13 @@ func (msg MsgRefillBond) Type() string { return "refill" }
func (msg MsgRefillBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
return errors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
return errors.Wrap(sdkerrors.ErrInvalidCoins, "invalid amount")
}
return nil
}
@@ -103,13 +104,13 @@ func (msg MsgWithdrawBond) Type() string { return "withdraw" }
func (msg MsgWithdrawBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
return errors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
return errors.Wrap(sdkerrors.ErrInvalidCoins, "invalid amount")
}
return nil
}
@@ -141,10 +142,10 @@ func (msg MsgCancelBond) Type() string { return "cancel" }
func (msg MsgCancelBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
return errors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
return nil
}
+18 -18
View File
@@ -4,10 +4,10 @@ import (
"math/big"
"strings"
"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
@@ -91,61 +91,61 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.HomesteadBlock); err != nil {
return sdkerrors.Wrap(err, "homesteadBlock")
return errors.Wrap(err, "homesteadBlock")
}
if err := validateBlock(cc.DAOForkBlock); err != nil {
return sdkerrors.Wrap(err, "daoForkBlock")
return errors.Wrap(err, "daoForkBlock")
}
if err := validateBlock(cc.EIP150Block); err != nil {
return sdkerrors.Wrap(err, "eip150Block")
return errors.Wrap(err, "eip150Block")
}
if err := validateHash(cc.EIP150Hash); err != nil {
return err
}
if err := validateBlock(cc.EIP155Block); err != nil {
return sdkerrors.Wrap(err, "eip155Block")
return errors.Wrap(err, "eip155Block")
}
if err := validateBlock(cc.EIP158Block); err != nil {
return sdkerrors.Wrap(err, "eip158Block")
return errors.Wrap(err, "eip158Block")
}
if err := validateBlock(cc.ByzantiumBlock); err != nil {
return sdkerrors.Wrap(err, "byzantiumBlock")
return errors.Wrap(err, "byzantiumBlock")
}
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
return sdkerrors.Wrap(err, "constantinopleBlock")
return errors.Wrap(err, "constantinopleBlock")
}
if err := validateBlock(cc.PetersburgBlock); err != nil {
return sdkerrors.Wrap(err, "petersburgBlock")
return errors.Wrap(err, "petersburgBlock")
}
if err := validateBlock(cc.IstanbulBlock); err != nil {
return sdkerrors.Wrap(err, "istanbulBlock")
return errors.Wrap(err, "istanbulBlock")
}
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "muirGlacierBlock")
return errors.Wrap(err, "muirGlacierBlock")
}
if err := validateBlock(cc.BerlinBlock); err != nil {
return sdkerrors.Wrap(err, "berlinBlock")
return errors.Wrap(err, "berlinBlock")
}
if err := validateBlock(cc.LondonBlock); err != nil {
return sdkerrors.Wrap(err, "londonBlock")
return errors.Wrap(err, "londonBlock")
}
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "arrowGlacierBlock")
return errors.Wrap(err, "arrowGlacierBlock")
}
if err := validateBlock(cc.MergeForkBlock); err != nil {
return sdkerrors.Wrap(err, "mergeForkBlock")
return errors.Wrap(err, "mergeForkBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return sdkerrors.Wrap(err, "invalid config fork order")
return errors.Wrap(err, "invalid config fork order")
}
return nil
}
func validateHash(hex string) error {
if hex != "" && strings.TrimSpace(hex) == "" {
return sdkerrors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
return errors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
}
return nil
@@ -158,7 +158,7 @@ func validateBlock(block *sdkmath.Int) error {
}
if block.IsNegative() {
return sdkerrors.Wrapf(
return errors.Wrapf(
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
)
}
+18 -18
View File
@@ -4,12 +4,12 @@ import (
"math/big"
"strings"
"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/cerc-io/laconicd/x/evm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
@@ -90,61 +90,61 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.HomesteadBlock); err != nil {
return sdkerrors.Wrap(err, "homesteadBlock")
return errors.Wrap(err, "homesteadBlock")
}
if err := validateBlock(cc.DAOForkBlock); err != nil {
return sdkerrors.Wrap(err, "daoForkBlock")
return errors.Wrap(err, "daoForkBlock")
}
if err := validateBlock(cc.EIP150Block); err != nil {
return sdkerrors.Wrap(err, "eip150Block")
return errors.Wrap(err, "eip150Block")
}
if err := validateHash(cc.EIP150Hash); err != nil {
return err
}
if err := validateBlock(cc.EIP155Block); err != nil {
return sdkerrors.Wrap(err, "eip155Block")
return errors.Wrap(err, "eip155Block")
}
if err := validateBlock(cc.EIP158Block); err != nil {
return sdkerrors.Wrap(err, "eip158Block")
return errors.Wrap(err, "eip158Block")
}
if err := validateBlock(cc.ByzantiumBlock); err != nil {
return sdkerrors.Wrap(err, "byzantiumBlock")
return errors.Wrap(err, "byzantiumBlock")
}
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
return sdkerrors.Wrap(err, "constantinopleBlock")
return errors.Wrap(err, "constantinopleBlock")
}
if err := validateBlock(cc.PetersburgBlock); err != nil {
return sdkerrors.Wrap(err, "petersburgBlock")
return errors.Wrap(err, "petersburgBlock")
}
if err := validateBlock(cc.IstanbulBlock); err != nil {
return sdkerrors.Wrap(err, "istanbulBlock")
return errors.Wrap(err, "istanbulBlock")
}
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "muirGlacierBlock")
return errors.Wrap(err, "muirGlacierBlock")
}
if err := validateBlock(cc.BerlinBlock); err != nil {
return sdkerrors.Wrap(err, "berlinBlock")
return errors.Wrap(err, "berlinBlock")
}
if err := validateBlock(cc.LondonBlock); err != nil {
return sdkerrors.Wrap(err, "londonBlock")
return errors.Wrap(err, "londonBlock")
}
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "arrowGlacierBlock")
return errors.Wrap(err, "arrowGlacierBlock")
}
if err := validateBlock(cc.MergeForkBlock); err != nil {
return sdkerrors.Wrap(err, "mergeForkBlock")
return errors.Wrap(err, "mergeForkBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return sdkerrors.Wrap(err, "invalid config fork order")
return errors.Wrap(err, "invalid config fork order")
}
return nil
}
func validateHash(hex string) error {
if hex != "" && strings.TrimSpace(hex) == "" {
return sdkerrors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
return errors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
}
return nil
@@ -157,7 +157,7 @@ func validateBlock(block *sdkmath.Int) error {
}
if block.IsNegative() {
return sdkerrors.Wrapf(
return errors.Wrapf(
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
)
}
+5 -4
View File
@@ -3,6 +3,7 @@ package keeper
import (
"context"
"cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/registry/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -48,7 +49,7 @@ func (q Querier) GetRecord(c context.Context, req *types.QueryRecordByIDRequest)
ctx := sdk.UnwrapSDKContext(c)
id := req.GetId()
if !q.Keeper.HasRecord(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "Record not found.")
return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, "record not found")
}
record := q.Keeper.GetRecord(ctx, id)
return &types.QueryRecordByIDResponse{Record: record}, nil
@@ -86,11 +87,11 @@ func (q Querier) LookupCrn(c context.Context, req *types.QueryLookupCrn) (*types
ctx := sdk.UnwrapSDKContext(c)
crn := req.GetCrn()
if !q.Keeper.HasNameRecord(ctx, crn) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "CRN not found.")
return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, "crn not found")
}
nameRecord := q.Keeper.GetNameRecord(ctx, crn)
if nameRecord == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "name record not found.")
return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, "name record not found")
}
return &types.QueryLookupCrnResponse{Name: nameRecord}, nil
}
@@ -100,7 +101,7 @@ func (q Querier) ResolveCrn(c context.Context, req *types.QueryResolveCrn) (*typ
crn := req.GetCrn()
record := q.Keeper.ResolveCRN(ctx, crn)
if record == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "record not found.")
return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, "record not found")
}
return &types.QueryResolveCrnResponse{Record: record}, nil
}
+4 -3
View File
@@ -7,6 +7,7 @@ import (
"sort"
"time"
"cosmossdk.io/errors"
auctionkeeper "github.com/cerc-io/laconicd/x/auction/keeper"
bondkeeper "github.com/cerc-io/laconicd/x/bond/keeper"
"github.com/cerc-io/laconicd/x/registry/helpers"
@@ -240,7 +241,7 @@ func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*type
resourceSignBytes, _ := record.GetSignBytes()
cid, err := record.GetCID()
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid record JSON")
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid record JSON")
}
record.ID = cid
@@ -255,13 +256,13 @@ func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*type
pubKey, err := legacy.PubKeyFromBytes(helpers.BytesFromBase64(sig.PubKey))
if err != nil {
fmt.Println("Error decoding pubKey from bytes: ", err)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid public key.")
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "invalid public key")
}
sigOK := pubKey.VerifySignature(resourceSignBytes, helpers.BytesFromBase64(sig.Sig))
if !sigOK {
fmt.Println("Signature mismatch: ", sig.PubKey)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid signature.")
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "invalid signature")
}
record.Owners = append(record.Owners, pubKey.Address().String())
}
+19 -18
View File
@@ -7,6 +7,7 @@ import (
"strings"
"time"
"cosmossdk.io/errors"
auctiontypes "github.com/cerc-io/laconicd/x/auction/types"
"github.com/cerc-io/laconicd/x/registry/helpers"
"github.com/cerc-io/laconicd/x/registry/types"
@@ -112,12 +113,12 @@ func (k Keeper) updateBlockChangeSetForName(ctx sdk.Context, crn string) {
func (k Keeper) getAuthority(ctx sdk.Context, crn string) (string, *url.URL, *types.NameAuthority, error) {
parsedCRN, err := url.Parse(crn)
if err != nil {
return "", nil, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid CRN.")
return "", nil, nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid CRN")
}
name := parsedCRN.Host
if !k.HasNameAuthority(ctx, name) {
return name, nil, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
return name, nil, nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "name authority not found")
}
authority := k.GetNameAuthority(ctx, name)
return name, parsedCRN, &authority, nil
@@ -131,19 +132,19 @@ func (k Keeper) checkCRNAccess(ctx sdk.Context, signer sdk.AccAddress, crn strin
formattedCRN := fmt.Sprintf("crn://%s%s", name, parsedCRN.RequestURI())
if formattedCRN != crn {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid CRN.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid CRN")
}
if authority.OwnerAddress != signer.String() {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "access denied")
}
if authority.Status != types.AuthorityActive {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Authority is not active.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "authority is not active")
}
if authority.BondId == "" || len(authority.BondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Authority bond not found.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "authority bond not found")
}
if authority.OwnerPublicKey == "" {
@@ -323,13 +324,13 @@ func (k Keeper) ProcessReserveSubAuthority(ctx sdk.Context, name string, msg typ
// Check if parent authority exists.
if !k.HasNameAuthority(ctx, parent) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Parent authority not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "parent authority not found")
}
parentAuthority := k.GetNameAuthority(ctx, parent)
// Sub-authority creator needs to be the owner of the parent authority.
if parentAuthority.OwnerAddress != msg.Signer {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "access denied")
}
// Sub-authority owner defaults to parent authority owner.
@@ -362,17 +363,17 @@ func (k Keeper) createAuthority(ctx sdk.Context, name string, owner string, isRo
if k.HasNameAuthority(ctx, name) {
authority := k.GetNameAuthority(ctx, name)
if authority.Status != types.AuthorityExpired {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name already reserved.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "name already reserved")
}
}
ownerAddress, err := sdk.AccAddressFromBech32(owner)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid owner address.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid owner address")
}
ownerAccount := k.accountKeeper.GetAccount(ctx, ownerAddress)
if ownerAccount == nil {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "Account not found.")
return errors.Wrap(sdkerrors.ErrUnknownAddress, "account not found")
}
authority := types.NameAuthority{
@@ -430,11 +431,11 @@ func (k Keeper) ProcessReserveAuthority(ctx sdk.Context, msg types.MsgReserveAut
crn := fmt.Sprintf("crn://%s", msg.GetName())
parsedCrn, err := url.Parse(crn)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid name")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid name")
}
name := parsedCrn.Host
if fmt.Sprintf("crn://%s", name) != crn {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid name")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid name")
}
if strings.Contains(name, ".") {
return k.ProcessReserveSubAuthority(ctx, name, msg)
@@ -450,20 +451,20 @@ func (k Keeper) ProcessSetAuthorityBond(ctx sdk.Context, msg types.MsgSetAuthori
name := msg.GetName()
signer := msg.GetSigner()
if !k.HasNameAuthority(ctx, name) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "name authority not found")
}
authority := k.GetNameAuthority(ctx, name)
if authority.OwnerAddress != signer {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Access denied")
return errors.Wrap(sdkerrors.ErrUnauthorized, "access denied")
}
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "bond not found")
}
//
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
if bond.Owner != signer {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
// No-op if bond hasn't changed.
@@ -496,7 +497,7 @@ func (k Keeper) ProcessDeleteName(ctx sdk.Context, msg types.MsgDeleteNameAuthor
}
if !k.HasNameRecord(ctx, msg.Crn) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "name not found")
}
// Set CID to empty string.
+16 -15
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"time"
"cosmossdk.io/errors"
auctionkeeper "github.com/cerc-io/laconicd/x/auction/keeper"
auctiontypes "github.com/cerc-io/laconicd/x/auction/types"
bondtypes "github.com/cerc-io/laconicd/x/bond/types"
@@ -158,7 +159,7 @@ func (k RecordKeeper) QueryRecordsByBond(ctx sdk.Context, bondID string) []types
// ProcessRenewRecord renews a record.
func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) error {
if !k.HasRecord(ctx, msg.RecordId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record not found")
}
// Check if renewal is required (i.e. expired record marked as deleted).
@@ -169,7 +170,7 @@ func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) er
}
if !record.Deleted || expiryTime.After(ctx.BlockTime()) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Renewal not required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "renewal not required")
}
recordType := record.ToRecordType()
@@ -184,23 +185,23 @@ func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) er
// ProcessAssociateBond associates a record with a bond.
func (k Keeper) ProcessAssociateBond(ctx sdk.Context, msg types.MsgAssociateBond) error {
if !k.HasRecord(ctx, msg.RecordId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record not found")
}
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "bond not found")
}
// Check if already associated with a bond.
record := k.GetRecord(ctx, msg.RecordId)
if record.BondId != "" || len(record.BondId) != 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond already exists.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond already exists")
}
// Only the bond owner can associate a record with the bond.
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
if msg.Signer != bond.Owner {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
record.BondId = msg.BondId
@@ -218,20 +219,20 @@ func (k Keeper) ProcessAssociateBond(ctx sdk.Context, msg types.MsgAssociateBond
// ProcessDissociateBond dissociates a record from its bond.
func (k Keeper) ProcessDissociateBond(ctx sdk.Context, msg types.MsgDissociateBond) error {
if !k.HasRecord(ctx, msg.RecordId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record not found")
}
// Check if associated with a bond.
record := k.GetRecord(ctx, msg.RecordId)
bondID := record.BondId
if bondID == "" || len(bondID) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond not found.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond not found")
}
// Only the bond owner can dissociate a record from the bond.
bond := k.bondKeeper.GetBond(ctx, bondID)
if msg.Signer != bond.Owner {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
// Clear bond ID.
@@ -245,13 +246,13 @@ func (k Keeper) ProcessDissociateBond(ctx sdk.Context, msg types.MsgDissociateBo
// ProcessDissociateRecords dissociates all records associated with a given bond.
func (k Keeper) ProcessDissociateRecords(ctx sdk.Context, msg types.MsgDissociateRecords) error {
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "bond not found")
}
// Only the bond owner can dissociate all records from the bond.
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
if msg.Signer != bond.Owner {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond owner mismatch")
}
// Dissociate all records from the bond.
@@ -269,22 +270,22 @@ func (k Keeper) ProcessDissociateRecords(ctx sdk.Context, msg types.MsgDissociat
// ProcessReAssociateRecords switches records from and old to new bond.
func (k Keeper) ProcessReAssociateRecords(ctx sdk.Context, msg types.MsgReAssociateRecords) error {
if !k.bondKeeper.HasBond(ctx, msg.OldBondId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Old bond not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "old bond not found")
}
if !k.bondKeeper.HasBond(ctx, msg.NewBondId) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "New bond not found.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "new bond not found")
}
// Only the bond owner can re-associate all records.
oldBond := k.bondKeeper.GetBond(ctx, msg.OldBondId)
if msg.Signer != oldBond.Owner {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Old bond owner mismatch.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "old bond owner mismatch")
}
newBond := k.bondKeeper.GetBond(ctx, msg.NewBondId)
if msg.Signer != newBond.Owner {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "New bond owner mismatch.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "new bond owner mismatch")
}
// Re-associate all records.
+12 -11
View File
@@ -3,6 +3,7 @@ package types
import (
"net/url"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@@ -32,15 +33,15 @@ func (msg MsgSetName) Type() string { return "set-name" }
// ValidateBasic Implements Msg.
func (msg MsgSetName) ValidateBasic() error {
if msg.Crn == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "CRN is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "crn is required")
}
if msg.Cid == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "cid is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
@@ -76,11 +77,11 @@ func (msg MsgReserveAuthority) Type() string { return "reserve-authority" }
// ValidateBasic Implements Msg.
func (msg MsgReserveAuthority) ValidateBasic() error {
if len(msg.Name) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "name is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
@@ -116,15 +117,15 @@ func (msg MsgSetAuthorityBond) Type() string { return "authority-bond" }
// ValidateBasic Implements Msg.
func (msg MsgSetAuthorityBond) ValidateBasic() error {
if len(msg.Name) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "name is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
if len(msg.BondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required")
}
return nil
@@ -159,16 +160,16 @@ func (msg MsgDeleteNameAuthority) Type() string { return "delete-name" }
// ValidateBasic Implements Msg.
func (msg MsgDeleteNameAuthority) ValidateBasic() error {
if len(msg.Crn) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "crn is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "crn is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
_, err := url.Parse(msg.Crn)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid crn.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid crn")
}
return nil
+16 -15
View File
@@ -1,6 +1,7 @@
package types
import (
"cosmossdk.io/errors"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -34,17 +35,17 @@ func (msg MsgSetRecord) Type() string { return "set-record" }
func (msg MsgSetRecord) ValidateBasic() error {
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
owners := msg.Payload.Record.Owners
for _, owner := range owners {
if owner == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record owner not set.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record owner not set")
}
}
if len(msg.BondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond ID is required.")
return errors.Wrap(sdkerrors.ErrUnauthorized, "bond ID is required")
}
return nil
}
@@ -83,11 +84,11 @@ func (msg MsgRenewRecord) Type() string { return "renew-record" }
// ValidateBasic Implements Msg.
func (msg MsgRenewRecord) ValidateBasic() error {
if len(msg.RecordId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
@@ -123,13 +124,13 @@ func (msg MsgAssociateBond) Type() string { return "associate-bond" }
// ValidateBasic Implements Msg.
func (msg MsgAssociateBond) ValidateBasic() error {
if len(msg.RecordId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required")
}
if len(msg.BondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
@@ -164,10 +165,10 @@ func (msg MsgDissociateBond) Type() string { return "dissociate-bond" }
// ValidateBasic Implements Msg.
func (msg MsgDissociateBond) ValidateBasic() error {
if len(msg.RecordId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
@@ -202,10 +203,10 @@ func (msg MsgDissociateRecords) Type() string { return "dissociate-records" }
// ValidateBasic Implements Msg.
func (msg MsgDissociateRecords) ValidateBasic() error {
if len(msg.BondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
@@ -241,13 +242,13 @@ func (msg MsgReAssociateRecords) Type() string { return "reassociate-records" }
// ValidateBasic Implements Msg.
func (msg MsgReAssociateRecords) ValidateBasic() error {
if len(msg.OldBondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required")
}
if len(msg.NewBondId) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required.")
return errors.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required")
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
return errors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil