├── audits
└── Nilchain - Zellic Audit Report.pdf
├── params
├── params.go
├── encoding.go
├── doc.go
├── amino.go
├── proto.go
└── weights.go
├── x
└── meta
│ ├── types
│ ├── genesis.go
│ ├── keys.go
│ ├── codec.go
│ ├── expected_keepers.go
│ ├── genesis.pb.go
│ └── tx.pb.go
│ ├── autocli.go
│ ├── keeper
│ ├── genesis.go
│ ├── msg_server_test.go
│ ├── msg_server.go
│ ├── genesis_test.go
│ ├── keeper_test.go
│ └── keeper.go
│ ├── client
│ └── cli
│ │ ├── tx.go
│ │ └── tx_test.go
│ ├── README.md
│ ├── module.go
│ └── testutil
│ └── mocks.go
├── proto
├── buf.gen.gogo.yaml
├── nillion
│ └── meta
│ │ └── v1
│ │ ├── genesis.proto
│ │ └── tx.proto
├── buf.yaml
└── buf.lock
├── app
├── upgrades
│ ├── types.go
│ ├── upgrade_0_2_4.go
│ └── upgrade_0_2_1.go
├── genesis.go
├── upgrades.go
├── genesis_account.go
├── config.go
├── ante.go
├── test_helpers.go
├── export.go
└── app.go
├── .gitignore
├── nilchaind
├── main.go
└── cmd
│ └── root.go
├── scripts
├── protocgen.sh
├── init.sh
├── testnet.sh
└── hermes.sh
├── Dockerfile
├── tests
├── upgrades
│ └── upgrade_test.go
└── common
│ ├── gov.go
│ └── network.go
├── README.md
├── .github
└── workflows
│ ├── ibc-e2e.yml
│ └── cd-image.yml
├── docs
└── upgrades
│ └── checklist.md
├── Makefile
└── go.mod
/audits/Nilchain - Zellic Audit Report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NillionNetwork/nilchain/HEAD/audits/Nilchain - Zellic Audit Report.pdf
--------------------------------------------------------------------------------
/params/params.go:
--------------------------------------------------------------------------------
1 | package params
2 |
3 | // Simulation parameter constants
4 | const (
5 | StakePerAccount = "stake_per_account"
6 | InitiallyBondedValidators = "initially_bonded_validators"
7 | )
8 |
--------------------------------------------------------------------------------
/x/meta/types/genesis.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | func DefaultGenesisState() *GenesisState {
4 | return &GenesisState{}
5 | }
6 |
7 | func (gs *GenesisState) Validate() error {
8 | return nil
9 | }
10 |
--------------------------------------------------------------------------------
/proto/buf.gen.gogo.yaml:
--------------------------------------------------------------------------------
1 | version: v1
2 | plugins:
3 | - name: gocosmos
4 | out: ..
5 | opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm
6 | - name: grpc-gateway
7 | out: ..
8 | opt: logtostderr=true,allow_colon_final_segments=true
9 |
--------------------------------------------------------------------------------
/x/meta/autocli.go:
--------------------------------------------------------------------------------
1 | package meta
2 |
3 | import (
4 | autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
5 | )
6 |
7 | func (a AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
8 | return &autocliv1.ModuleOptions{
9 | Tx: &autocliv1.ServiceCommandDescriptor{
10 | EnhanceCustomCommand: true,
11 | },
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/upgrades/types.go:
--------------------------------------------------------------------------------
1 | package upgrades
2 |
3 | import (
4 | "cosmossdk.io/store/types"
5 | upgradetypes "cosmossdk.io/x/upgrade/types"
6 | "github.com/cosmos/cosmos-sdk/types/module"
7 | )
8 |
9 | type Upgrade struct {
10 | UpgradeName string
11 | CreateUpgradeHandler func(mm module.Manager, configurator module.Configurator) upgradetypes.UpgradeHandler
12 | StoreUpgrades types.StoreUpgrades
13 | }
14 |
--------------------------------------------------------------------------------
/x/meta/types/keys.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import "cosmossdk.io/collections"
4 |
5 | const (
6 | // ModuleName is the name of the module
7 | ModuleName = "meta"
8 |
9 | // StoreKey is the store key string for meta
10 | StoreKey = ModuleName
11 |
12 | // RouterKey is the message route for meta
13 | RouterKey = ModuleName
14 | )
15 |
16 | // KVStore keys
17 | var (
18 | ResourcesPrefix = collections.NewPrefix(1)
19 | )
20 |
--------------------------------------------------------------------------------
/x/meta/types/codec.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "github.com/cosmos/cosmos-sdk/codec/types"
5 | sdk "github.com/cosmos/cosmos-sdk/types"
6 | "github.com/cosmos/cosmos-sdk/types/msgservice"
7 | )
8 |
9 | func RegisterInterfaces(registry types.InterfaceRegistry) {
10 | registry.RegisterImplementations((*sdk.Msg)(nil),
11 | &MsgPayFor{},
12 | )
13 |
14 | msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
15 | }
16 |
--------------------------------------------------------------------------------
/proto/nillion/meta/v1/genesis.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package nillion.meta.v1;
3 |
4 | import "cosmos_proto/cosmos.proto";
5 |
6 | option go_package = "github.com/NillionNetwork/nilchain/x/meta/types";
7 |
8 | // GenesisState defines the meta module's genesis state.
9 | message GenesisState {
10 | repeated Resource resources = 1;
11 | }
12 |
13 | message Resource {
14 | string from_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
15 | bytes metadata = 2;
16 | }
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Executables
7 | *.exe
8 | *.out
9 |
10 | # Go binary
11 | *.test
12 |
13 | # Go build cache
14 | *.testcache
15 |
16 | # Vendor directory
17 | /vendor/
18 |
19 | # IDE-specific files
20 | .idea/
21 | .vscode/
22 |
23 | # Build output
24 | /build/
25 |
26 | # Log files
27 | *.log
28 |
29 | # Temporary files
30 | *.tmp
31 |
32 | # macOS specific files
33 | .DS_Store
34 |
35 | # Windows thumbnail cache files
36 | Thumbs.db
--------------------------------------------------------------------------------
/nilchaind/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "os"
5 |
6 | "cosmossdk.io/log"
7 |
8 | svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
9 |
10 | nillionapp "github.com/NillionNetwork/nilchain/app"
11 | "github.com/NillionNetwork/nilchain/nilchaind/cmd"
12 | )
13 |
14 | func main() {
15 | rootCmd := cmd.NewRootCmd()
16 | if err := svrcmd.Execute(rootCmd, "", nillionapp.DefaultNodeHome); err != nil {
17 | log.NewLogger(rootCmd.OutOrStderr()).Error("failure when running app", "err", err)
18 | os.Exit(1)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/params/encoding.go:
--------------------------------------------------------------------------------
1 | package params
2 |
3 | import (
4 | "github.com/cosmos/cosmos-sdk/client"
5 | "github.com/cosmos/cosmos-sdk/codec"
6 | "github.com/cosmos/cosmos-sdk/codec/types"
7 | )
8 |
9 | // EncodingConfig specifies the concrete encoding types to use for a given app.
10 | // This is provided for compatibility between protobuf and amino implementations.
11 | type EncodingConfig struct {
12 | InterfaceRegistry types.InterfaceRegistry
13 | Codec codec.Codec
14 | TxConfig client.TxConfig
15 | Amino *codec.LegacyAmino
16 | }
17 |
--------------------------------------------------------------------------------
/app/genesis.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "encoding/json"
5 | )
6 |
7 | // GenesisState of the blockchain is represented here as a map of raw json
8 | // messages key'd by an identifier string.
9 | // The identifier is used to determine which module genesis information belongs
10 | // to so it may be appropriately routed during init chain.
11 | // Within this application default genesis information is retrieved from
12 | // the ModuleBasicManager which populates json from each BasicModule
13 | // object provided to it during init.
14 | type GenesisState map[string]json.RawMessage
15 |
--------------------------------------------------------------------------------
/proto/buf.yaml:
--------------------------------------------------------------------------------
1 | version: v1
2 | name: buf.build/NillionNetwork/nillion-chain
3 | deps:
4 | - buf.build/cosmos/cosmos-proto
5 | - buf.build/cosmos/cosmos-sdk:v0.50.0
6 | - buf.build/cosmos/gogo-proto
7 | - buf.build/googleapis/googleapis
8 | breaking:
9 | use:
10 | - FILE
11 | lint:
12 | use:
13 | - DEFAULT
14 | - COMMENTS
15 | - FILE_LOWER_SNAKE_CASE
16 | except:
17 | - UNARY_RPC
18 | - COMMENT_FIELD
19 | - SERVICE_SUFFIX
20 | - PACKAGE_VERSION_SUFFIX
21 | - RPC_REQUEST_STANDARD_NAME
22 | - PACKAGE_DIRECTORY_MATCH
23 |
24 | ignore:
25 | - tendermint
--------------------------------------------------------------------------------
/app/upgrades/upgrade_0_2_4.go:
--------------------------------------------------------------------------------
1 | package upgrades
2 |
3 | import (
4 | "context"
5 |
6 | "cosmossdk.io/store/types"
7 | upgradetypes "cosmossdk.io/x/upgrade/types"
8 | "github.com/cosmos/cosmos-sdk/types/module"
9 | )
10 |
11 | var Upgrade_0_2_4 = Upgrade{
12 | UpgradeName: "v0.2.4-rc11",
13 | CreateUpgradeHandler: func(mm module.Manager, configurator module.Configurator) upgradetypes.UpgradeHandler {
14 | return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
15 | return mm.RunMigrations(ctx, configurator, fromVM)
16 | }
17 | },
18 | StoreUpgrades: types.StoreUpgrades{},
19 | }
20 |
--------------------------------------------------------------------------------
/scripts/protocgen.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -eo pipefail
4 |
5 | echo "Generating gogo proto code"
6 | cd proto
7 |
8 | proto_dirs=$(find . -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
9 | for dir in $proto_dirs; do
10 | for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
11 | if grep "option go_package" $file &> /dev/null ; then
12 | echo "Generating gogo proto code for $file"
13 | buf generate --template buf.gen.gogo.yaml $file
14 | fi
15 | done
16 | done
17 |
18 | cd ..
19 | # move proto files to the right places
20 | cp -r github.com/NillionNetwork/nilchain/* ./
21 | rm -rf github.com
22 |
--------------------------------------------------------------------------------
/x/meta/types/expected_keepers.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | context "context"
5 |
6 | sdk "github.com/cosmos/cosmos-sdk/types"
7 | )
8 |
9 | // BankKeeper defines the expected interface needed to retrieve account balances.
10 | type BankKeeper interface {
11 | SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
12 | BurnCoins(ctx context.Context, name string, amt sdk.Coins) error
13 | }
14 |
15 | // AccountKeeper defines the contract required for account APIs.
16 | type AccountKeeper interface {
17 | GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI
18 | }
19 |
--------------------------------------------------------------------------------
/params/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Package params defines the simulation parameters in the nillionapp.
3 |
4 | It contains the default weights used for each transaction used on the module's
5 | simulation. These weights define the chance for a transaction to be simulated at
6 | any given operation.
7 |
8 | You can replace the default values for the weights by providing a params.json
9 | file with the weights defined for each of the transaction operations:
10 |
11 | {
12 | "op_weight_msg_send": 60,
13 | "op_weight_msg_delegate": 100,
14 | }
15 |
16 | In the example above, the `MsgSend` has 60% chance to be simulated, while the
17 | `MsgDelegate` will always be simulated.
18 | */
19 | package params
20 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.22-alpine3.18 AS builder
2 |
3 | RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make;
4 |
5 | ENV GOPATH=""
6 |
7 | # Copy relevant files before go mod download. Replace directives to local paths break if local
8 | # files are not copied before go mod download.
9 | ADD app app
10 | ADD nilchaind nilchaind
11 | ADD params params
12 | ADD x x
13 |
14 | ADD .git .git
15 |
16 | ARG VERSION
17 | ENV VERSION=${VERSION}
18 |
19 | ADD .git .git
20 |
21 | COPY Makefile .
22 | COPY go.mod .
23 | COPY go.sum .
24 |
25 | RUN go mod download
26 |
27 | RUN make build
28 |
29 | FROM alpine:3.18
30 |
31 | COPY --from=builder /go/build/nilchaind /bin/nilchaind
32 |
33 | ENTRYPOINT ["nilchaind"]
34 |
--------------------------------------------------------------------------------
/app/upgrades/upgrade_0_2_1.go:
--------------------------------------------------------------------------------
1 | package upgrades
2 |
3 | import (
4 | "context"
5 | "cosmossdk.io/store/types"
6 | upgradetypes "cosmossdk.io/x/upgrade/types"
7 | metatypes "github.com/NillionNetwork/nilchain/x/meta/types"
8 | "github.com/cosmos/cosmos-sdk/types/module"
9 | )
10 |
11 | var Upgrade_0_2_1 = Upgrade{
12 | UpgradeName: "v0.2.1",
13 | CreateUpgradeHandler: func(mm module.Manager, configurator module.Configurator) upgradetypes.UpgradeHandler {
14 | return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
15 | return mm.RunMigrations(ctx, configurator, fromVM)
16 | }
17 | },
18 | StoreUpgrades: types.StoreUpgrades{
19 | Added: []string{
20 | metatypes.StoreKey,
21 | },
22 | },
23 | }
24 |
--------------------------------------------------------------------------------
/params/amino.go:
--------------------------------------------------------------------------------
1 | //go:build test_amino
2 | // +build test_amino
3 |
4 | package params
5 |
6 | import (
7 | "github.com/cosmos/cosmos-sdk/codec"
8 | "github.com/cosmos/cosmos-sdk/codec/types"
9 | "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
10 | )
11 |
12 | // MakeTestEncodingConfig creates an EncodingConfig for an amino based test configuration.
13 | // This function should be used only internally (in the SDK).
14 | // App user shouldn't create new codecs - use the app.AppCodec instead.
15 | // [DEPRECATED]
16 | func MakeTestEncodingConfig() EncodingConfig {
17 | cdc := codec.NewLegacyAmino()
18 | interfaceRegistry := types.NewInterfaceRegistry()
19 | marshaler := codec.NewAminoCodec(cdc)
20 |
21 | return EncodingConfig{
22 | InterfaceRegistry: interfaceRegistry,
23 | Marshaler: marshaler,
24 | TxConfig: legacytx.StdTxConfig{Cdc: cdc},
25 | Amino: cdc,
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/params/proto.go:
--------------------------------------------------------------------------------
1 | //go:build !test_amino
2 | // +build !test_amino
3 |
4 | package params
5 |
6 | import (
7 | "github.com/cosmos/cosmos-sdk/codec"
8 | "github.com/cosmos/cosmos-sdk/codec/types"
9 | "github.com/cosmos/cosmos-sdk/x/auth/tx"
10 | )
11 |
12 | // MakeTestEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
13 | // This function should be used only internally (in the SDK).
14 | // App user shouldn't create new codecs - use the app.AppCodec instead.
15 | // [DEPRECATED]
16 | func MakeTestEncodingConfig() EncodingConfig {
17 | cdc := codec.NewLegacyAmino()
18 | interfaceRegistry := types.NewInterfaceRegistry()
19 | protoCdc := codec.NewProtoCodec(interfaceRegistry)
20 |
21 | return EncodingConfig{
22 | InterfaceRegistry: interfaceRegistry,
23 | Codec: protoCdc,
24 | TxConfig: tx.NewTxConfig(protoCdc, tx.DefaultSignModes),
25 | Amino: cdc,
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/x/meta/keeper/genesis.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | sdk "github.com/cosmos/cosmos-sdk/types"
5 |
6 | metatypes "github.com/NillionNetwork/nilchain/x/meta/types"
7 | )
8 |
9 | func (k Keeper) InitGenesis(ctx sdk.Context, ak metatypes.AccountKeeper, genState *metatypes.GenesisState) {
10 | ak.GetModuleAccount(ctx, metatypes.ModuleName)
11 |
12 | for _, resource := range genState.Resources {
13 | addr := sdk.MustAccAddressFromBech32(resource.FromAddress)
14 | err := k.SaveResource(ctx, addr, resource.Metadata)
15 | if err != nil {
16 | panic(err)
17 | }
18 | }
19 | }
20 |
21 | func (k Keeper) ExportGenesis(ctx sdk.Context) *metatypes.GenesisState {
22 | var resources []*metatypes.Resource
23 | k.IterateResources(ctx, func(addr sdk.AccAddress, metadata []byte) {
24 | resources = append(resources, &metatypes.Resource{
25 | FromAddress: addr.String(),
26 | Metadata: metadata,
27 | })
28 | })
29 |
30 | return &metatypes.GenesisState{
31 | Resources: resources,
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/upgrades.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | upgradetypes "cosmossdk.io/x/upgrade/types"
5 | "fmt"
6 | "github.com/NillionNetwork/nilchain/app/upgrades"
7 | )
8 |
9 | var Upgrades = []upgrades.Upgrade{
10 | upgrades.Upgrade_0_2_1,
11 | upgrades.Upgrade_0_2_4,
12 | }
13 |
14 | func (app NillionApp) setupUpgradeHandlers() {
15 | for _, upgrade := range Upgrades {
16 | app.UpgradeKeeper.SetUpgradeHandler(
17 | upgrade.UpgradeName,
18 | upgrade.CreateUpgradeHandler(
19 | *app.ModuleManager,
20 | app.configurator,
21 | ),
22 | )
23 | }
24 | }
25 |
26 | func (app NillionApp) setupUpgradeStoreLoaders() {
27 | upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
28 | if err != nil {
29 | panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
30 | }
31 |
32 | if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
33 | return
34 | }
35 |
36 | for _, upgrade := range Upgrades {
37 | if upgradeInfo.Name == upgrade.UpgradeName {
38 | app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/upgrades/upgrade_test.go:
--------------------------------------------------------------------------------
1 | package upgrades
2 |
3 | import (
4 | "context"
5 | "cosmossdk.io/math"
6 | nillionapp "github.com/NillionNetwork/nilchain/app"
7 | "github.com/NillionNetwork/nilchain/app/upgrades"
8 | "github.com/NillionNetwork/nilchain/tests/common"
9 | "github.com/strangelove-ventures/interchaintest/v8"
10 | "testing"
11 |
12 | testifysuite "github.com/stretchr/testify/suite"
13 | )
14 |
15 | func init() {
16 | nillionapp.SetBech32AddressPrefixes()
17 | }
18 |
19 | func TestUpgradeTestSuite(t *testing.T) {
20 | testifysuite.Run(t, new(UpgradeTestSuite))
21 | }
22 |
23 | type UpgradeTestSuite struct {
24 | common.NetworkTestSuite
25 | }
26 |
27 | // TestUpgrade0_2_4 tests the upgrade from 0.2.1 to 0.2.4
28 | func (s *UpgradeTestSuite) TestUpgrade0_2_4() {
29 | oldVersion := "v0.2.1-test-only"
30 | newVersion := upgrades.Upgrade_0_2_4.UpgradeName
31 |
32 | s.InitChain(oldVersion, "nilliond")
33 |
34 | ctx := context.Background()
35 |
36 | users := interchaintest.GetAndFundTestUsers(s.T(), ctx, "nillion", math.NewInt(1000000000), s.Chain)
37 |
38 | s.UpgradeChain(ctx, s.Chain, users[0], newVersion)
39 | }
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # nilchain
2 |
3 | nilchain is the Coordination Layer for the Nillion Network. It coordinates the payment of blind
4 | computations and storage operations performed on the network. It is built using the [Cosmos
5 | SDK](https://github.com/cosmos/cosmos-sdk), a framework for building PoS blockchain applications,
6 | which was chosen for the interconnectivity, speed, and sovereignty its ecosystem provides.
7 |
8 | ## Building
9 |
10 | ```
11 | make install
12 | ```
13 |
14 | ```
15 | make build
16 | ```
17 |
18 | ### Cross-Compiling
19 |
20 | Use the `build-cross` target to cross-compile for the following platforms: linux/amd64, linux/arm64,
21 | darwin/amd64, darwin/arm64. Please note that building for linux/arm64 requires an arm64-compatible
22 | version of gcc installed. On Debian-based systems, this would be `aarch64-linux-gnu-gcc`.
23 |
24 | ### Scripts
25 |
26 | ```
27 | cd scripts
28 | ```
29 |
30 | ```
31 | # Setup and start single chain locally
32 | sh init.sh
33 | # Setup and start two chains locally and create an ibc client/connection/channel
34 | sh hermes.sh
35 | # Naive setup and start single chain for deploying devnet
36 | sh testnet.sh
37 | ```
38 |
--------------------------------------------------------------------------------
/proto/buf.lock:
--------------------------------------------------------------------------------
1 | # Generated by buf. DO NOT EDIT.
2 | version: v1
3 | deps:
4 | - remote: buf.build
5 | owner: cosmos
6 | repository: cosmos-proto
7 | commit: 04467658e59e44bbb22fe568206e1f70
8 | digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466
9 | - remote: buf.build
10 | owner: cosmos
11 | repository: cosmos-sdk
12 | commit: 5a6ab7bc14314acaa912d5e53aef1c2f
13 | digest: shake256:02c00c73493720055f9b57553a35b5550023a3c1914123b247956288a78fb913aff70e66552777ae14d759467e119079d484af081264a5dd607a94d9fbc8116b
14 | - remote: buf.build
15 | owner: cosmos
16 | repository: gogo-proto
17 | commit: 88ef6483f90f478fb938c37dde52ece3
18 | digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
19 | - remote: buf.build
20 | owner: googleapis
21 | repository: googleapis
22 | commit: 1f6ed065c9f04b5cb843d6e7603d6454
23 | digest: shake256:7149cf5e9955c692d381e557830555d4e93f205a0f1b8e2dfdae46d029369aa3fc1980e35df0d310f7cc3b622f93e19ad276769a283a967dd3065ddfd3a40e13
24 |
--------------------------------------------------------------------------------
/proto/nillion/meta/v1/tx.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package nillion.meta.v1;
3 |
4 | import "gogoproto/gogo.proto";
5 | import "cosmos/base/v1beta1/coin.proto";
6 | import "cosmos/bank/v1beta1/bank.proto";
7 | import "cosmos_proto/cosmos.proto";
8 | import "cosmos/msg/v1/msg.proto";
9 | import "amino/amino.proto";
10 |
11 | option go_package = "github.com/NillionNetwork/nilchain/x/meta/types";
12 |
13 | // Msg defines the meta Msg service.
14 | service Msg {
15 | option (cosmos.msg.v1.service) = true;
16 |
17 | // PayFor pays for a resource in the PET neteotk
18 | rpc PayFor(MsgPayFor) returns (MsgPayForResponse);
19 | }
20 |
21 | // MsgPayFor defines the Msg/PayFor request type.
22 | message MsgPayFor {
23 | option (cosmos.msg.v1.signer) = "from_address";
24 | bytes resource = 1;
25 | string from_address = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
26 | repeated cosmos.base.v1beta1.Coin amount = 3 [
27 | (gogoproto.nullable) = false,
28 | (amino.dont_omitempty) = true,
29 | (amino.encoding) = "legacy_coins",
30 | (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
31 | ];
32 | }
33 |
34 | // MsgPayForResponse defines the Msg/PayFor response type.
35 | message MsgPayForResponse {}
36 |
--------------------------------------------------------------------------------
/x/meta/keeper/msg_server_test.go:
--------------------------------------------------------------------------------
1 | package keeper_test
2 |
3 | import (
4 | "testing"
5 |
6 | "cosmossdk.io/math"
7 | "github.com/NillionNetwork/nilchain/x/meta/keeper"
8 | "github.com/NillionNetwork/nilchain/x/meta/types"
9 | types2 "github.com/cosmos/cosmos-sdk/types"
10 | "github.com/stretchr/testify/require"
11 | )
12 |
13 | func TestMsgServer_PayFor(t *testing.T) {
14 | f := initFixture(t)
15 |
16 | msg := &types.MsgPayFor{
17 | Resource: []byte("resource1"),
18 | FromAddress: "cosmos1kc068s88tkyjcc0lkx67x95dwc7hrfm44u8k55",
19 | Amount: []types2.Coin{
20 | {
21 | Denom: "coin1",
22 | Amount: math.NewInt(100),
23 | },
24 | },
25 | }
26 |
27 | fromAddress, err := types2.AccAddressFromBech32(msg.FromAddress)
28 | require.NoError(t, err)
29 |
30 | f.mockedBankKeeper.EXPECT().
31 | SendCoinsFromAccountToModule(f.ctx, fromAddress, types.ModuleName, msg.Amount)
32 |
33 | f.mockedBankKeeper.EXPECT().
34 | BurnCoins(f.ctx, types.ModuleName, msg.Amount)
35 |
36 | _, err = keeper.NewMsgServerImpl(f.keeper).PayFor(f.ctx, msg)
37 | require.NoError(t, err)
38 |
39 | // Check if the resource was saved
40 | exists := f.keeper.ResourceExists(f.ctx, fromAddress, msg.Resource)
41 | require.True(t, exists)
42 | }
43 |
--------------------------------------------------------------------------------
/scripts/init.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Set the home directory for your chain
4 | HOMEDIR="$HOME/.nillionapp"
5 |
6 | # Remove existing state to ensure a clean initialization
7 | rm -rf "$HOMEDIR"
8 |
9 | NILLIOND_BIN=$(which nilchaind)
10 |
11 | # Initialize the chain
12 | $NILLIOND_BIN init test --chain-id demo --default-denom unillion --home "$HOMEDIR"
13 |
14 | # Configure other settings (chain ID, keyring-backend)
15 | $NILLIOND_BIN config set client chain-id demo --home "$HOMEDIR"
16 | $NILLIOND_BIN config set client keyring-backend test --home "$HOMEDIR"
17 |
18 | # Add keys for users
19 | $NILLIOND_BIN keys add alice --home "$HOMEDIR"
20 | $NILLIOND_BIN keys add bob --home "$HOMEDIR"
21 |
22 | # Add genesis accounts and create a default validator
23 | $NILLIOND_BIN genesis add-genesis-account alice 10000000unillion --keyring-backend test --home "$HOMEDIR"
24 | $NILLIOND_BIN genesis add-genesis-account bob 1000unillion --keyring-backend test --home "$HOMEDIR"
25 |
26 | # Create a default validator and collect genesis transactions
27 | $NILLIOND_BIN genesis gentx alice 1000000unillion --chain-id demo --home "$HOMEDIR"
28 | $NILLIOND_BIN genesis collect-gentxs --home "$HOMEDIR"
29 |
30 | # Start the chain
31 | $NILLIOND_BIN start --home "$HOMEDIR"
--------------------------------------------------------------------------------
/params/weights.go:
--------------------------------------------------------------------------------
1 | package params
2 |
3 | // Default simulation operation weights for messages and gov proposals
4 | const (
5 | DefaultWeightMsgSend int = 100
6 | DefaultWeightMsgMultiSend int = 10
7 | DefaultWeightMsgSetWithdrawAddress int = 50
8 | DefaultWeightMsgWithdrawDelegationReward int = 50
9 | DefaultWeightMsgWithdrawValidatorCommission int = 50
10 | DefaultWeightMsgFundCommunityPool int = 50
11 | DefaultWeightMsgDeposit int = 100
12 | DefaultWeightMsgVote int = 67
13 | DefaultWeightMsgVoteWeighted int = 33
14 | DefaultWeightMsgUnjail int = 100
15 | DefaultWeightMsgCreateValidator int = 100
16 | DefaultWeightMsgEditValidator int = 5
17 | DefaultWeightMsgDelegate int = 100
18 | DefaultWeightMsgUndelegate int = 100
19 | DefaultWeightMsgBeginRedelegate int = 100
20 |
21 | DefaultWeightCommunitySpendProposal int = 5
22 | DefaultWeightTextProposal int = 5
23 | DefaultWeightParamChangeProposal int = 5
24 |
25 | // feegrant
26 | DefaultWeightGrantFeeAllowance int = 100
27 | DefaultWeightRevokeFeeAllowance int = 100
28 | )
29 |
--------------------------------------------------------------------------------
/x/meta/keeper/msg_server.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | "context"
5 | "fmt"
6 |
7 | sdk "github.com/cosmos/cosmos-sdk/types"
8 |
9 | "github.com/NillionNetwork/nilchain/x/meta/types"
10 | )
11 |
12 | var _ types.MsgServer = msgServer{}
13 |
14 | type msgServer struct {
15 | keeper Keeper
16 | }
17 |
18 | func NewMsgServerImpl(keeper Keeper) types.MsgServer {
19 | return &msgServer{keeper: keeper}
20 | }
21 |
22 | func (m msgServer) PayFor(ctx context.Context, payFor *types.MsgPayFor) (*types.MsgPayForResponse, error) {
23 | addr, err := sdk.AccAddressFromBech32(payFor.FromAddress)
24 | if err != nil {
25 | return nil, fmt.Errorf("invalid address: %w", err)
26 | }
27 |
28 | err = m.keeper.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, payFor.Amount)
29 | if err != nil {
30 | return nil, fmt.Errorf("failed to send coins: %w", err)
31 | }
32 |
33 | err = m.keeper.bankKeeper.BurnCoins(ctx, types.ModuleName, payFor.Amount)
34 | if err != nil {
35 | return nil, fmt.Errorf("failed to burn coins: %w", err)
36 | }
37 |
38 | err = m.keeper.SaveResource(ctx, addr, payFor.Resource)
39 | if err != nil {
40 | return nil, fmt.Errorf("failed to save resource: %w", err)
41 | }
42 |
43 | return &types.MsgPayForResponse{}, nil
44 | }
45 |
--------------------------------------------------------------------------------
/x/meta/keeper/genesis_test.go:
--------------------------------------------------------------------------------
1 | package keeper_test
2 |
3 | import (
4 | "testing"
5 |
6 | sdk "github.com/cosmos/cosmos-sdk/types"
7 | "github.com/stretchr/testify/require"
8 |
9 | metatypes "github.com/NillionNetwork/nilchain/x/meta/types"
10 | )
11 |
12 | func TestImportExportGenesis(t *testing.T) {
13 | f := initFixture(t)
14 |
15 | genesis := &metatypes.GenesisState{
16 | Resources: []*metatypes.Resource{
17 | {
18 | FromAddress: "cosmos1kc068s88tkyjcc0lkx67x95dwc7hrfm44u8k55",
19 | Metadata: []byte("resource1"),
20 | },
21 | {
22 | FromAddress: "cosmos1kc068s88tkyjcc0lkx67x95dwc7hrfm44u8k55",
23 | Metadata: []byte("resource2"),
24 | },
25 | },
26 | }
27 |
28 | f.mockedAccountKeeper.EXPECT().GetModuleAccount(f.ctx, metatypes.ModuleName).Return(nil).Times(1)
29 |
30 | f.keeper.InitGenesis(f.ctx, f.mockedAccountKeeper, genesis)
31 |
32 | exists := f.keeper.ResourceExists(
33 | f.ctx,
34 | sdk.MustAccAddressFromBech32(genesis.Resources[0].FromAddress),
35 | genesis.Resources[0].Metadata,
36 | )
37 | require.True(t, exists)
38 |
39 | exists = f.keeper.ResourceExists(
40 | f.ctx,
41 | sdk.MustAccAddressFromBech32(genesis.Resources[1].FromAddress),
42 | genesis.Resources[1].Metadata,
43 | )
44 | require.True(t, exists)
45 |
46 | exported := f.keeper.ExportGenesis(f.ctx)
47 | require.Equal(t, genesis, exported)
48 | }
49 |
--------------------------------------------------------------------------------
/scripts/testnet.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Set the home directory for your chain
4 | HOMEDIR="$HOME/.nillionapp"
5 | NODE_IP="0.0.0.0"
6 | RPC_LADDR="$NODE_IP:26648"
7 | GRPC_ADDR="$NODE_IP:9081"
8 |
9 | # Remove existing state to ensure a clean initialization
10 | rm -rf "$HOMEDIR"
11 |
12 | NILLIOND_BIN=$(which nilchaind)
13 |
14 | # Initialize the chain
15 | $NILLIOND_BIN init test --chain-id demo --default-denom unillion --home "$HOMEDIR"
16 |
17 | # Configure other settings (chain ID, keyring-backend)
18 | $NILLIOND_BIN config set client chain-id demo --home "$HOMEDIR"
19 | $NILLIOND_BIN config set client keyring-backend test --home "$HOMEDIR"
20 |
21 | # Add keys for users
22 | $NILLIOND_BIN keys add alice --home "$HOMEDIR"
23 | $NILLIOND_BIN keys add bob --home "$HOMEDIR"
24 |
25 | # Add genesis accounts and create a default validator
26 | $NILLIOND_BIN genesis add-genesis-account alice 10000000unillion --keyring-backend test --home "$HOMEDIR"
27 | $NILLIOND_BIN genesis add-genesis-account bob 1000unillion --keyring-backend test --home "$HOMEDIR"
28 |
29 | # Create a default validator and collect genesis transactions
30 | $NILLIOND_BIN genesis gentx alice 1000000unillion --chain-id demo --home "$HOMEDIR"
31 | $NILLIOND_BIN genesis collect-gentxs --home "$HOMEDIR"
32 |
33 | # Start the chain
34 | $NILLIOND_BIN start \
35 | --home "$HOMEDIR" \
36 | --rpc.laddr tcp://${RPC_LADDR} \
37 | --grpc.address ${GRPC_ADDR} \
38 | --address tcp://${NODE_IP}:26635 \
39 | --p2p.laddr tcp://${NODE_IP}:26636 \
40 | --grpc-web.enable=false \
41 | --log_level trace \
42 | --trace \
43 | &> $HOMEDIR/logs &
44 |
--------------------------------------------------------------------------------
/app/genesis_account.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "errors"
5 |
6 | sdk "github.com/cosmos/cosmos-sdk/types"
7 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
8 | )
9 |
10 | var _ authtypes.GenesisAccount = (*SimGenesisAccount)(nil)
11 |
12 | // SimGenesisAccount defines a type that implements the GenesisAccount interface
13 | // to be used for simulation accounts in the genesis state.
14 | type SimGenesisAccount struct {
15 | *authtypes.BaseAccount
16 |
17 | // vesting account fields
18 | OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"` // total vesting coins upon initialization
19 | DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"` // delegated vested coins at the time of delegation
20 | DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` // delegated vesting coins at the time of delegation
21 | StartTime int64 `json:"start_time" yaml:"start_time"` // vesting start time (UNIX Epoch time)
22 | EndTime int64 `json:"end_time" yaml:"end_time"` // vesting end time (UNIX Epoch time)
23 |
24 | // module account fields
25 | ModuleName string `json:"module_name" yaml:"module_name"` // name of the module account
26 | ModulePermissions []string `json:"module_permissions" yaml:"module_permissions"` // permissions of module account
27 | }
28 |
29 | // Validate checks for errors on the vesting and module account parameters
30 | func (sga SimGenesisAccount) Validate() error {
31 | if !sga.OriginalVesting.IsZero() {
32 | if sga.StartTime >= sga.EndTime {
33 | return errors.New("vesting start-time cannot be before end-time")
34 | }
35 | }
36 |
37 | if sga.ModuleName != "" {
38 | ma := authtypes.ModuleAccount{
39 | BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions,
40 | }
41 | if err := ma.Validate(); err != nil {
42 | return err
43 | }
44 | }
45 |
46 | return sga.BaseAccount.Validate()
47 | }
48 |
--------------------------------------------------------------------------------
/app/config.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "cosmossdk.io/errors"
5 | sdk "github.com/cosmos/cosmos-sdk/types"
6 | "github.com/cosmos/cosmos-sdk/types/address"
7 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8 | )
9 |
10 | const (
11 | // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address.
12 | Bech32PrefixAccAddr = "nillion"
13 | )
14 |
15 | var (
16 | // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key.
17 | Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub"
18 | // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address.
19 | Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper"
20 | // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key.
21 | Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub"
22 | // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address.
23 | Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons"
24 | // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key.
25 | Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub"
26 | )
27 |
28 | func init() {
29 | SetBech32AddressPrefixes()
30 | }
31 |
32 | func SetBech32AddressPrefixes() {
33 | config := sdk.GetConfig()
34 | config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
35 | config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
36 | config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
37 |
38 | // This is copied from the cosmos sdk v0.43.0-beta1
39 | // source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
40 | config.SetAddressVerifier(func(bytes []byte) error {
41 | if len(bytes) == 0 {
42 | return errors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
43 | }
44 |
45 | if len(bytes) > address.MaxAddrLen {
46 | return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
47 | }
48 |
49 | if len(bytes) != 20 && len(bytes) != 32 {
50 | return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
51 | }
52 |
53 | return nil
54 | })
55 | }
56 |
--------------------------------------------------------------------------------
/.github/workflows/ibc-e2e.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Run ibc E2E Tests
3 | on:
4 | workflow_dispatch:
5 | jobs:
6 | e2e:
7 | runs-on: ubuntu-latest
8 | strategy:
9 | fail-fast: false # ensure that a single test failure doesn't cause all tests to fail
10 | matrix:
11 | # entrypoint corresponds to the test function in the test files which fall under the e2e directory.
12 | # test is the name of the test function to be run.
13 | # see the e2e docs https://github.com/cosmos/ibc-go/tree/main/e2e for more details.
14 | include:
15 | # e2e ibc transfer
16 | - test: TestMsgTransfer_Succeeds_Nonincentivized
17 | entrypoint: TestTransferTestSuite
18 | steps:
19 | - name: Checkout the ibc-go repo.
20 | uses: actions/checkout@v3
21 | with:
22 | repository: cosmos/ibc-go
23 | ref: support-arbitrary-binaries-in-e2es
24 | path: ibc-go
25 |
26 | - name: Checkout nillion repo
27 | uses: actions/checkout@v3
28 | with:
29 | path: nillion
30 |
31 | - name: Install Go 1.22
32 | uses: actions/setup-go@v3
33 | with:
34 | go-version: 1.22
35 | # IBC requires building image locally for now. This can be changed in the future.
36 | - name: Build docker image
37 | run: |
38 | cd nillion
39 | docker build -t local-image:v8.2.0 .
40 |
41 | - name: Run E2E tests with custom chain image.
42 | run: |
43 | cd ibc-go
44 | cd e2e
45 | make e2e-test entrypoint=${{ matrix.entrypoint }} test=${{ matrix.test}}
46 | env:
47 | # Configure this however you like in order to specify your own custom image and tags.
48 | CHAIN_IMAGE: local-image
49 | # The following tags are used to specify the ibc-go version. This will be changed in the future.
50 | CHAIN_A_TAG: v8.2.0
51 | CHAIN_B_TAG: v8.2.0
52 | CHAIN_BINARY: nilchaind
53 | RELAYER_ID: hermes
54 | BECH32_PREFIX: nillion
--------------------------------------------------------------------------------
/docs/upgrades/checklist.md:
--------------------------------------------------------------------------------
1 | ## Upgrade Checklist Nillion
2 |
3 | ### Release structure
4 |
5 | - Tags/Versioning
6 | -
7 |
8 | **MAJOR** version when you make incompatible API changes and/or state machine breaking changes
9 | **MINOR** version when you add functionality in a backward compatible manner/non state machine breaking changes
10 | **PATCH** version when you make backward compatible bug fixes
11 |
12 | ### Engineering checklist pre-upgrade
13 |
14 | - [ ] Run IBC transfer e2e in CI on the latest tag
15 | - [ ] Write an upgrade test using the example test. This allows you to test the upgrade between two provided tags and run the test in CI easily.
16 | - [ ] Locally test upgrade with mainnet state ()
17 | - [ ] Manual QA of all newly added functionality
18 | - [ ] Run all previous e2e tests and unit tests locally/in CI
19 | - [ ] Provide sufficient release notes for validators/users/developers
20 | - [ ] If migrations are necessary, implement them and write tests.
21 |
22 | ### Logistics/Comms checklist for handling upgrade
23 |
24 | - [ ] Settle on the target upgrade height, use estimation based on current block time
25 | - [ ] Create Governance proposal with upgrade height, version etc. (chain will halt)
26 | - Example
27 |
28 | ```json
29 | {
30 | "title": "Update nillion to v0.2.1",
31 | "description": "Update to v0.2.1",
32 | "summary": "Update binary to version v0.2.1",
33 | "messages": [
34 | {
35 | "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
36 | "authority": "nillion10d07y265gmmuvt4z0w9aw880jnsr700jpzdkas",
37 | "plan": {
38 | "name": "v0.2.1",
39 | "time": "0001-01-01T00:00:00Z",
40 | "height": "1100000",
41 | "info": "{}",
42 | "upgraded_client_state": null
43 | }
44 | }
45 | ],
46 | "deposit": "5000000000unil",
47 | "expedited": true
48 | }
49 | ```
50 |
51 | - [ ] Make sure key stakeholders (validators etc. vote)
52 | - [ ] Communicate with Validators and specify tag or release to run for upgrade
53 |
54 | **Guides**:
55 |
56 | -
57 | -
58 |
--------------------------------------------------------------------------------
/x/meta/client/cli/tx.go:
--------------------------------------------------------------------------------
1 | package cli
2 |
3 | import (
4 | "os"
5 |
6 | "github.com/cosmos/cosmos-sdk/client"
7 | "github.com/cosmos/cosmos-sdk/client/flags"
8 | "github.com/cosmos/cosmos-sdk/client/tx"
9 | sdk "github.com/cosmos/cosmos-sdk/types"
10 | "github.com/spf13/cobra"
11 |
12 | "github.com/NillionNetwork/nilchain/x/meta/types"
13 | )
14 |
15 | func TxCmd() *cobra.Command {
16 | cmd := &cobra.Command{
17 | Use: types.ModuleName,
18 | Short: "Meta transactions subcommands",
19 | }
20 |
21 | cmd.AddCommand(
22 | CmdPayFor(),
23 | )
24 |
25 | return cmd
26 | }
27 |
28 | // CmdPayFor returns the command to pay for a resource.
29 | func CmdPayFor() *cobra.Command {
30 | cmd := &cobra.Command{
31 | Use: "pay-for [from_address] [amount] [resource-file-data]",
32 | Short: "Pay for a resource",
33 | Long: `
34 | Pay for a resource by sending coins to the module account and burning them.
35 | Usage:
36 | $ nillion-chaind tx meta pay-for [from_address] [amount] [resource-file-data]
37 |
38 | Where:
39 | - [from_address] is the address of the sender.
40 | - [amount] is the amount of coins to send.
41 | - [resource] is the resource to pay for.
42 | Example:
43 | $ nillion-chaind tx meta pay-for infinity1kc068s88tkyjcc0lkx67x95dwc7hrfm44u8k55 1000infinity resource1.json
44 |
45 | Where resource1.json contains the resource data.
46 | `,
47 | Args: cobra.ExactArgs(3),
48 | RunE: func(cmd *cobra.Command, args []string) error {
49 | err := cmd.Flags().Set(flags.FlagFrom, args[0])
50 | if err != nil {
51 | return err
52 | }
53 |
54 | clientCtx, err := client.GetClientTxContext(cmd)
55 | if err != nil {
56 | return err
57 | }
58 |
59 | coins, err := sdk.ParseCoinsNormalized(args[1])
60 | if err != nil {
61 | return err
62 | }
63 |
64 | metadata, err := parseMetadataFile(args[2])
65 | if err != nil {
66 | return err
67 | }
68 |
69 | msg := &types.MsgPayFor{
70 | FromAddress: clientCtx.GetFromAddress().String(),
71 | Amount: coins,
72 | Resource: metadata,
73 | }
74 |
75 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
76 | },
77 | }
78 |
79 | flags.AddTxFlagsToCmd(cmd)
80 |
81 | return cmd
82 | }
83 |
84 | func parseMetadataFile(file string) ([]byte, error) {
85 | metadata, err := os.ReadFile(file)
86 | if err != nil {
87 | return nil, err
88 | }
89 |
90 | return metadata, nil
91 | }
92 |
--------------------------------------------------------------------------------
/app/ante.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "errors"
5 |
6 | circuitante "cosmossdk.io/x/circuit/ante"
7 |
8 | sdk "github.com/cosmos/cosmos-sdk/types"
9 | "github.com/cosmos/cosmos-sdk/x/auth/ante"
10 |
11 | ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
12 | "github.com/cosmos/ibc-go/v8/modules/core/keeper"
13 | )
14 |
15 | // HandlerOptions are the options required for constructing a default SDK AnteHandler.
16 | type HandlerOptions struct {
17 | ante.HandlerOptions
18 | CircuitKeeper circuitante.CircuitBreaker
19 | IBCKeeper *keeper.Keeper
20 | }
21 |
22 | // NewAnteHandler returns an AnteHandler that checks and increments the sequence
23 | // numbers, checks signatures & account numbers, and deducts fees from the first
24 | // signer.
25 | func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
26 | if options.AccountKeeper == nil {
27 | return nil, errors.New("account keeper is required for ante builder")
28 | }
29 |
30 | if options.BankKeeper == nil {
31 | return nil, errors.New("bank keeper is required for ante builder")
32 | }
33 |
34 | if options.SignModeHandler == nil {
35 | return nil, errors.New("sign mode handler is required for ante builder")
36 | }
37 |
38 | anteDecorators := []sdk.AnteDecorator{
39 | ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
40 | circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
41 | ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
42 | ante.NewValidateBasicDecorator(),
43 | ante.NewTxTimeoutHeightDecorator(),
44 | ante.NewValidateMemoDecorator(options.AccountKeeper),
45 | ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
46 | ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
47 | ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
48 | ante.NewValidateSigCountDecorator(options.AccountKeeper),
49 | ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
50 | ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
51 | ante.NewIncrementSequenceDecorator(options.AccountKeeper),
52 | ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
53 | }
54 |
55 | return sdk.ChainAnteDecorators(anteDecorators...), nil
56 | }
57 |
--------------------------------------------------------------------------------
/x/meta/keeper/keeper_test.go:
--------------------------------------------------------------------------------
1 | package keeper_test
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/cosmos/cosmos-sdk/types"
7 | "go.uber.org/mock/gomock"
8 |
9 | storetypes "cosmossdk.io/store/types"
10 | cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
11 | "github.com/cosmos/cosmos-sdk/runtime"
12 | "github.com/cosmos/cosmos-sdk/testutil"
13 | moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
14 | "github.com/stretchr/testify/require"
15 |
16 | "github.com/NillionNetwork/nilchain/x/meta"
17 | "github.com/NillionNetwork/nilchain/x/meta/keeper"
18 | metatest "github.com/NillionNetwork/nilchain/x/meta/testutil"
19 | )
20 |
21 | type fixture struct {
22 | ctx types.Context
23 |
24 | keeper keeper.Keeper
25 |
26 | mockedBankKeeper *metatest.MockBankKeeper
27 | mockedAccountKeeper *metatest.MockAccountKeeper
28 | }
29 |
30 | func initFixture(t *testing.T) *fixture {
31 | encCfg := moduletestutil.MakeTestEncodingConfig(meta.AppModuleBasic{})
32 |
33 | mockStoreKey := storetypes.NewKVStoreKey("test")
34 | storeService := runtime.NewKVStoreService(mockStoreKey)
35 |
36 | ctrl := gomock.NewController(t)
37 | m := metatest.NewMockBankKeeper(ctrl)
38 | a := metatest.NewMockAccountKeeper(ctrl)
39 |
40 | k := keeper.NewKeeper(encCfg.Codec, storeService, m)
41 |
42 | return &fixture{
43 | ctx: testutil.DefaultContextWithDB(t, mockStoreKey, storetypes.NewTransientStoreKey("transient_test")).Ctx.WithBlockHeader(cmtproto.Header{}),
44 | keeper: k,
45 |
46 | mockedBankKeeper: m,
47 | mockedAccountKeeper: a,
48 | }
49 | }
50 |
51 | func TestSetResource(t *testing.T) {
52 | t.Parallel()
53 |
54 | f := initFixture(t)
55 |
56 | addr, err := types.AccAddressFromBech32("cosmos1kc068s88tkyjcc0lkx67x95dwc7hrfm44u8k55")
57 | require.NoError(t, err)
58 |
59 | err = f.keeper.SaveResource(f.ctx, addr, []byte("resource1"))
60 | require.NoError(t, err)
61 | }
62 |
63 | func TestResourceExists(t *testing.T) {
64 | t.Parallel()
65 |
66 | f := initFixture(t)
67 |
68 | addr, err := types.AccAddressFromBech32("cosmos1kc068s88tkyjcc0lkx67x95dwc7hrfm44u8k55")
69 | require.NoError(t, err)
70 |
71 | exists := f.keeper.ResourceExists(f.ctx, addr, []byte("resource1"))
72 | require.False(t, exists)
73 |
74 | err = f.keeper.SaveResource(f.ctx, addr, []byte("resource1"))
75 | require.NoError(t, err)
76 |
77 | exists = f.keeper.ResourceExists(f.ctx, addr, []byte("resource1"))
78 | require.True(t, exists)
79 | }
80 |
--------------------------------------------------------------------------------
/x/meta/keeper/keeper.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | "context"
5 | "crypto/sha256"
6 | "fmt"
7 |
8 | "cosmossdk.io/collections"
9 | "cosmossdk.io/core/store"
10 | metatypes "github.com/NillionNetwork/nilchain/x/meta/types"
11 | "github.com/cosmos/cosmos-sdk/codec"
12 | sdk "github.com/cosmos/cosmos-sdk/types"
13 | )
14 |
15 | type Keeper struct {
16 | cdc codec.BinaryCodec
17 | storeService store.KVStoreService
18 |
19 | bankKeeper metatypes.BankKeeper
20 |
21 | Schema collections.Schema
22 |
23 | // Resources contains the resources mapped by account and resource
24 | Resources collections.Map[collections.Pair[sdk.AccAddress, []byte], []byte]
25 | }
26 |
27 | func NewKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService, bankKeeper metatypes.BankKeeper) Keeper {
28 | sb := collections.NewSchemaBuilder(storeService)
29 |
30 | k := Keeper{
31 | cdc: cdc,
32 | storeService: storeService,
33 | Resources: collections.NewMap(
34 | sb,
35 | metatypes.ResourcesPrefix,
36 | "resources",
37 | collections.PairKeyCodec(sdk.AccAddressKey, collections.BytesKey),
38 | collections.BytesValue,
39 | ),
40 | bankKeeper: bankKeeper,
41 | }
42 |
43 | schema, err := sb.Build()
44 | if err != nil {
45 | panic(err)
46 | }
47 | k.Schema = schema
48 |
49 | return k
50 | }
51 |
52 | func (k Keeper) SaveResource(ctx context.Context, fromAddress sdk.AccAddress, resource []byte) error {
53 | err := k.Resources.Set(ctx, forgeResourceKey(fromAddress, resource), resource)
54 | if err != nil {
55 | return fmt.Errorf("failed to set resource: %w", err)
56 | }
57 |
58 | return nil
59 | }
60 |
61 | func (k Keeper) ResourceExists(ctx context.Context, fromAddress sdk.AccAddress, resource []byte) bool {
62 | exists, err := k.Resources.Has(ctx, forgeResourceKey(fromAddress, resource))
63 | if err != nil {
64 | return false
65 | }
66 |
67 | return exists
68 | }
69 |
70 | func (k Keeper) IterateResources(ctx context.Context, cb func(fromAddress sdk.AccAddress, resource []byte)) {
71 | iterate, err := k.Resources.Iterate(ctx, nil)
72 | if err != nil {
73 | panic(err)
74 | }
75 |
76 | for ; iterate.Valid(); iterate.Next() {
77 | kv, err := iterate.KeyValue()
78 | if err != nil {
79 | panic(err)
80 | }
81 |
82 | cb(kv.Key.K1(), kv.Value)
83 | }
84 | }
85 |
86 | func forgeResourceKey(fromAcc sdk.AccAddress, resource []byte) collections.Pair[sdk.AccAddress, []byte] {
87 | hashResource := sha256.Sum256(resource)
88 | return collections.Join(fromAcc, hashResource[:])
89 | }
90 |
--------------------------------------------------------------------------------
/x/meta/client/cli/tx_test.go:
--------------------------------------------------------------------------------
1 | package cli_test
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "testing"
7 |
8 | "github.com/NillionNetwork/nilchain/x/meta/client/cli"
9 | "github.com/cosmos/cosmos-sdk/client/flags"
10 | "github.com/stretchr/testify/require"
11 |
12 | "github.com/NillionNetwork/nilchain/x/meta"
13 | abci "github.com/cometbft/cometbft/abci/types"
14 | rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
15 | "github.com/cosmos/cosmos-sdk/client"
16 | "github.com/cosmos/cosmos-sdk/crypto/keyring"
17 | "github.com/cosmos/cosmos-sdk/testutil"
18 | clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
19 | sdk "github.com/cosmos/cosmos-sdk/types"
20 | testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
21 | "github.com/stretchr/testify/suite"
22 | )
23 |
24 | type CLITestSuite struct {
25 | suite.Suite
26 |
27 | kr keyring.Keyring
28 | encCfg testutilmod.TestEncodingConfig
29 | baseCtx client.Context
30 | clientCtx client.Context
31 | }
32 |
33 | func TestCLITestSuite(t *testing.T) {
34 | suite.Run(t, new(CLITestSuite))
35 | }
36 |
37 | func (s *CLITestSuite) SetupSuite() {
38 | s.encCfg = testutilmod.MakeTestEncodingConfig(meta.AppModule{})
39 | s.kr = keyring.NewInMemory(s.encCfg.Codec)
40 | s.baseCtx = client.Context{}.
41 | WithKeyring(s.kr).
42 | WithTxConfig(s.encCfg.TxConfig).
43 | WithCodec(s.encCfg.Codec).
44 | WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
45 | WithAccountRetriever(client.MockAccountRetriever{}).
46 | WithOutput(io.Discard).
47 | WithChainID("test-chain")
48 |
49 | ctxGen := func() client.Context {
50 | bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
51 | c := clitestutil.NewMockCometRPC(abci.ResponseQuery{
52 | Value: bz,
53 | })
54 | return s.baseCtx.WithClient(c)
55 | }
56 | s.clientCtx = ctxGen()
57 | }
58 |
59 | func (s *CLITestSuite) TestCmdPayFor() {
60 | val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
61 |
62 | someResource := `{
63 | "resource": "some resource"
64 | }`
65 | someResourceFile := testutil.WriteToNewTempFile(s.T(), someResource)
66 | defer someResourceFile.Close()
67 |
68 | cmd := cli.CmdPayFor()
69 | out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, []string{
70 | val[0].Address.String(),
71 | "1000infinity",
72 | someResourceFile.Name(),
73 | fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
74 | })
75 | require.NoError(s.T(), err)
76 | msg := &sdk.TxResponse{}
77 | s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), msg), out.String())
78 | }
79 |
--------------------------------------------------------------------------------
/x/meta/README.md:
--------------------------------------------------------------------------------
1 | # Meta
2 |
3 | ## Abstract
4 |
5 | Meta is a module that holds metadata related to resources paid for in the PET network.
6 |
7 | ## State
8 |
9 | ### Data
10 |
11 | MetaData is a map of information associated with resource consumption in the PET network. The data which is stored will not be verified. The module has no concept of what is valid or invalid with the associated data.
12 |
13 | * Data: `0x01 | sha256(data) (32 byte) | bytes(data) |`
14 |
15 | ## Messages
16 |
17 | Meta has a single transaction type. It is used to pay for resources in the PET network. All fields are required. The `from_address` is the address of the account that is paying for the resources. The `amount` is the amount of resources being paid for. The `resource` is the type of resource being paid for.
18 |
19 | The amount is burned instead of sent to another address at this point in time. In the future this will be changed to be sent to a module account in which the funds are pooled and paid out to workers in the PET network.
20 |
21 | ```protobuf
22 |
23 | message MsgPayFor {
24 | option (cosmos.msg.v1.signer) = "from_address";
25 | bytes resource = 1;
26 | string from_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
27 | repeated cosmos.base.v1beta1.Coin amount = 3 [
28 | (gogoproto.nullable) = false,
29 | (amino.dont_omitempty) = true,
30 | (amino.encoding) = "legacy_coins",
31 | (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
32 | ];
33 | }
34 | ```
35 |
36 | ```protobuf
37 | // MsgPayForResponse defines the Msg/PayFor response type.
38 | message MsgPayForResponse{}
39 | ```
40 |
41 | ## Queries
42 |
43 | ### MetaData
44 |
45 | Request:
46 |
47 | ```protobuf
48 | // QueryMetadataRequest defines the request type for metadata
49 | message QueryMetadataRequest {
50 | string identifier = 1;
51 | }
52 | ```
53 |
54 | The RESTAPI endpoint for this query is `/nillion/meta/v1/meta_data/{identifier}`
55 |
56 | Response:
57 |
58 | ```protobuf
59 | // QueryMetadataResponse defines the response type for metadata
60 | message QueryMetadataResponse {
61 | bytes metadata = 1;
62 | }
63 | ```
64 |
65 | ### AllMetaData
66 |
67 | Request:
68 |
69 | ```protobuf
70 | // QueryAllMetadataRequest defines the request type for all metadata
71 | message QueryAllMetadataRequest {
72 | cosmos.base.query.v1beta1.PageRequest pagination = 1;
73 | }
74 | ```
75 |
76 | The RESTAPI endpoint for this query is "/nillion/meta/v1/all_meta_data"
77 |
78 | ```protobuf
79 | // QueryAllMetadataResponse defines the response type for all metadata
80 | message QueryAllMetadataResponse {
81 | repeated bytes metadata = 1;
82 | }
83 | ```
84 |
85 | ### CLI
86 |
87 | ```
88 | nilchaind tx meta pay-for 1000anillion /path-to-resource/resource.json --from alice --node tcp://localhost:26657 --chain-id demo
89 | ```
90 |
--------------------------------------------------------------------------------
/tests/common/gov.go:
--------------------------------------------------------------------------------
1 | package common
2 |
3 | import (
4 | "context"
5 | upgradetypes "cosmossdk.io/x/upgrade/types"
6 | "fmt"
7 | sdk "github.com/cosmos/cosmos-sdk/types"
8 | "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
9 | "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
10 | "github.com/strangelove-ventures/interchaintest/v8/ibc"
11 | "time"
12 | )
13 |
14 | const VotingPeriod time.Duration = time.Second * 30
15 |
16 | // ExecuteGovProposal submits the given governance proposal using the provided user and uses all validators to vote yes on the proposal.
17 | // It ensure the proposal successfully passes.
18 | func (s *NetworkTestSuite) ExecuteGovProposal(ctx context.Context, chain *cosmos.CosmosChain, wallet ibc.Wallet, planName string, upgradeVersion string) {
19 | address, err := chain.GetAddress(ctx, wallet.KeyName())
20 | s.Require().NoError(err)
21 |
22 | addrString, err := sdk.Bech32ifyAddressBytes(chain.Config().Bech32Prefix, address)
23 | s.Require().NoError(err)
24 |
25 | prevVersion := chain.Nodes()[0].Image.Version
26 | plan := upgradetypes.Plan{
27 | Name: planName,
28 | Height: int64(haltHeight),
29 | Info: fmt.Sprintf("upgrade version test from %s to %s", prevVersion, upgradeVersion),
30 | }
31 | upgrade := upgradetypes.MsgSoftwareUpgrade{
32 | Authority: authority,
33 | Plan: plan,
34 | }
35 |
36 | proposal, err := chain.BuildProposal(
37 | []cosmos.ProtoMessage{&upgrade},
38 | fmt.Sprintf("upgrade from %s to %s", prevVersion, upgradeVersion),
39 | "upgrade chain E2E test",
40 | "",
41 | "50000000unillion",
42 | addrString,
43 | true,
44 | )
45 | s.Require().NoError(err)
46 |
47 | _, err = chain.SubmitProposal(ctx, wallet.KeyName(), proposal)
48 | s.Require().NoError(err)
49 |
50 | prop, err := chain.GovQueryProposal(ctx, 1)
51 | s.Require().NoError(err)
52 | s.Require().Equal(v1beta1.StatusVotingPeriod, prop.Status)
53 |
54 | err = chain.VoteOnProposalAllValidators(ctx, 1, cosmos.ProposalVoteYes)
55 | s.Require().NoError(err)
56 |
57 | // ensure voting period has not passed before validators finished voting
58 | prop, err = chain.GovQueryProposal(ctx, 1)
59 | s.Require().NoError(err)
60 | s.Require().Equal(v1beta1.StatusVotingPeriod, prop.Status)
61 |
62 | time.Sleep(VotingPeriod) // pass proposal
63 |
64 | prop, err = chain.GovQueryProposal(ctx, 1)
65 | s.Require().NoError(err)
66 | s.Require().Equal(v1beta1.StatusPassed, prop.Status)
67 | }
68 |
69 | // BroadcastMessages broadcasts the provided messages to the given chain and signs them on behalf of the provided user.
70 | // Once the broadcast response is returned, we wait for a few blocks to be created on both chain A and chain B.
71 | func (s *NetworkTestSuite) BroadcastMessages(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, msgs ...sdk.Msg) (sdk.TxResponse, error) {
72 | broadcaster := cosmos.NewBroadcaster(s.T(), chain)
73 | resp, err := cosmos.BroadcastTx(ctx, broadcaster, user, msgs...)
74 | if err != nil {
75 | return sdk.TxResponse{}, err
76 | }
77 |
78 | //chainA, chainB := s.GetChains()
79 | //err = test.WaitForBlocks(ctx, 2, chainA, chainB)
80 | return resp, err
81 | }
82 |
--------------------------------------------------------------------------------
/.github/workflows/cd-image.yml:
--------------------------------------------------------------------------------
1 | name: Publish nilchaind to GHCR
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | workflow_dispatch:
8 |
9 | concurrency:
10 | group: ${{ github.workflow }}-${{ github.ref }}
11 | cancel-in-progress: true
12 |
13 | permissions:
14 | contents: read
15 | packages: write # Required to push to GHCR
16 |
17 | jobs:
18 | build-and-push-arch:
19 | runs-on: ${{ matrix.runner }}
20 | strategy:
21 | fail-fast: false
22 | matrix:
23 | include:
24 | - arch: amd64
25 | platform: linux/amd64
26 | runner: ubuntu-latest
27 | - arch: arm64
28 | platform: linux/arm64
29 | runner: ubuntu-24.04-arm
30 | steps:
31 | - name: Checkout
32 | uses: actions/checkout@v4
33 | with:
34 | fetch-depth: 0
35 |
36 | - name: Log in to GitHub Container Registry
37 | uses: docker/login-action@v3
38 | with:
39 | registry: ghcr.io
40 | username: ${{ github.actor }}
41 | password: ${{ secrets.GITHUB_TOKEN }}
42 |
43 | - name: Set up Docker Buildx
44 | uses: docker/setup-buildx-action@v3
45 |
46 | - name: Extract metadata for version
47 | id: meta_tag
48 | uses: docker/metadata-action@v5
49 | with:
50 | images: ghcr.io/nillionnetwork/nilchaind
51 | tags: |
52 | type=ref,event=branch
53 | type=ref,event=tag
54 | type=sha,prefix=
55 | flavor: |
56 | latest=false
57 |
58 | - name: Build and push arch-specific image
59 | uses: docker/build-push-action@v6
60 | with:
61 | context: .
62 | platforms: ${{ matrix.platform }}
63 | push: true
64 | tags: ghcr.io/nillionnetwork/nilchaind:${{ github.sha }}-${{ matrix.arch }}
65 | build-args: |
66 | VERSION=${{ steps.meta_tag.outputs.version }}
67 | cache-from: type=gha
68 | cache-to: type=gha,mode=max
69 | provenance: false
70 |
71 | create-and-push-manifest:
72 | runs-on: ubuntu-latest
73 | needs: build-and-push-arch
74 | steps:
75 | - name: Log in to GitHub Container Registry
76 | uses: docker/login-action@v3
77 | with:
78 | registry: ghcr.io
79 | username: ${{ github.actor }}
80 | password: ${{ secrets.GITHUB_TOKEN }}
81 |
82 | - name: Extract final tags
83 | id: meta
84 | uses: docker/metadata-action@v5
85 | with:
86 | images: ghcr.io/nillionnetwork/nilchaind
87 | tags: |
88 | type=ref,event=branch
89 | type=ref,event=tag
90 | flavor: |
91 | latest=false
92 |
93 | - name: Create and push multi-arch manifest
94 | run: |
95 | echo "${{ steps.meta.outputs.tags }}" > tags.txt
96 |
97 | while IFS= read -r tag; do
98 | if [ -n "$tag" ]; then
99 | echo "Creating and pushing manifest for tag: $tag"
100 |
101 | docker manifest create "$tag" \
102 | ghcr.io/nillionnetwork/nilchaind:${{ github.sha }}-amd64 \
103 | ghcr.io/nillionnetwork/nilchaind:${{ github.sha }}-arm64
104 |
105 | docker manifest push "$tag"
106 | fi
107 | done < tags.txt
108 |
--------------------------------------------------------------------------------
/x/meta/module.go:
--------------------------------------------------------------------------------
1 | package meta
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "time"
7 |
8 | "cosmossdk.io/client/v2/autocli"
9 | "github.com/spf13/cobra"
10 |
11 | "cosmossdk.io/core/appmodule"
12 | "github.com/cosmos/cosmos-sdk/client"
13 | "github.com/cosmos/cosmos-sdk/codec"
14 | "github.com/cosmos/cosmos-sdk/codec/types"
15 | "github.com/cosmos/cosmos-sdk/telemetry"
16 | sdk "github.com/cosmos/cosmos-sdk/types"
17 | "github.com/cosmos/cosmos-sdk/types/module"
18 | "github.com/grpc-ecosystem/grpc-gateway/runtime"
19 |
20 | "github.com/NillionNetwork/nilchain/x/meta/client/cli"
21 | "github.com/NillionNetwork/nilchain/x/meta/keeper"
22 | metatypes "github.com/NillionNetwork/nilchain/x/meta/types"
23 | )
24 |
25 | var (
26 | _ module.AppModuleBasic = AppModule{}
27 | _ module.HasGenesis = AppModule{}
28 | _ module.HasServices = AppModule{}
29 | _ module.HasConsensusVersion = AppModule{}
30 | _ module.HasName = AppModule{}
31 | _ autocli.HasAutoCLIConfig = AppModule{}
32 | _ autocli.HasCustomTxCommand = AppModule{}
33 |
34 | _ appmodule.AppModule = AppModule{}
35 | )
36 |
37 | // ConsensusVersion defines the current meta module consensus version.
38 | const ConsensusVersion = 1
39 |
40 | type AppModuleBasic struct {
41 | }
42 |
43 | func (a AppModuleBasic) Name() string {
44 | return metatypes.ModuleName
45 | }
46 |
47 | func (a AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}
48 |
49 | func (a AppModuleBasic) RegisterInterfaces(registry types.InterfaceRegistry) {
50 | metatypes.RegisterInterfaces(registry)
51 | }
52 |
53 | func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
54 |
55 | func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
56 | return cdc.MustMarshalJSON(metatypes.DefaultGenesisState())
57 | }
58 |
59 | func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error {
60 | var genesisState metatypes.GenesisState
61 | if err := cdc.UnmarshalJSON(message, &genesisState); err != nil {
62 | return fmt.Errorf("failed to unmarshal %s genesis state: %w", metatypes.ModuleName, err)
63 | }
64 |
65 | return genesisState.Validate()
66 | }
67 |
68 | func (a AppModuleBasic) GetTxCmd() *cobra.Command {
69 | return cli.TxCmd()
70 | }
71 |
72 | type AppModule struct {
73 | AppModuleBasic
74 |
75 | ak metatypes.AccountKeeper
76 |
77 | keeper keeper.Keeper
78 | }
79 |
80 | func NewAppModule(keeper keeper.Keeper, ak metatypes.AccountKeeper) *AppModule {
81 | return &AppModule{
82 | AppModuleBasic: AppModuleBasic{},
83 | keeper: keeper,
84 | ak: ak,
85 | }
86 | }
87 |
88 | func (a AppModule) ConsensusVersion() uint64 {
89 | return ConsensusVersion
90 | }
91 |
92 | func (a AppModule) RegisterServices(configurator module.Configurator) {
93 | metatypes.RegisterMsgServer(configurator.MsgServer(), keeper.NewMsgServerImpl(a.keeper))
94 | }
95 |
96 | func (a AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
97 | start := time.Now()
98 | var genesisState metatypes.GenesisState
99 | cdc.MustUnmarshalJSON(data, &genesisState)
100 | telemetry.MeasureSince(start, "InitGenesis", "meta", "unmarshal")
101 |
102 | a.keeper.InitGenesis(ctx, a.ak, &genesisState)
103 | }
104 |
105 | func (a AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
106 | gs := a.keeper.ExportGenesis(ctx)
107 | return cdc.MustMarshalJSON(gs)
108 | }
109 |
110 | func (a AppModule) IsOnePerModuleType() {}
111 |
112 | func (a AppModule) IsAppModule() {}
113 |
--------------------------------------------------------------------------------
/tests/common/network.go:
--------------------------------------------------------------------------------
1 | package common
2 |
3 | import (
4 | "context"
5 | "time"
6 |
7 | "github.com/docker/docker/client"
8 | "github.com/strangelove-ventures/interchaintest/v8"
9 | "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
10 | "github.com/strangelove-ventures/interchaintest/v8/ibc"
11 | "github.com/strangelove-ventures/interchaintest/v8/testutil"
12 | "github.com/stretchr/testify/require"
13 | testifysuite "github.com/stretchr/testify/suite"
14 | "go.uber.org/zap/zaptest"
15 | )
16 |
17 | const (
18 | chainRepository = "ghcr.io/nillionnetwork/nilchaind"
19 | haltHeight = int64(50)
20 | authority = "nillion10d07y265gmmuvt4z0w9aw880jnsr700jpzdkas"
21 | blocksAfterUpgrade = int64(10)
22 | )
23 |
24 | type NetworkTestSuite struct {
25 | testifysuite.Suite
26 |
27 | Chain *cosmos.CosmosChain
28 | DockerClient *client.Client
29 | }
30 |
31 | // InitChain binary included because version 0.1.1 was a different binary name
32 | func (s *NetworkTestSuite) InitChain(version string, binary string) {
33 | t := s.T()
34 |
35 | if version == "v0.1.1" {
36 | binary = "nilliond"
37 | }
38 | binary = "nilchaind"
39 |
40 | client, network := interchaintest.DockerSetup(t)
41 | s.DockerClient = client
42 | factory := interchaintest.NewBuiltinChainFactory(
43 | zaptest.NewLogger(t),
44 | []*interchaintest.ChainSpec{
45 | {
46 | ChainConfig: ibc.ChainConfig{
47 | Type: "cosmos",
48 | Name: "nilliond",
49 | ChainID: "nillion-1",
50 | Images: []ibc.DockerImage{
51 | {
52 | Repository: chainRepository,
53 | Version: version,
54 | UidGid: "1025:1025",
55 | },
56 | },
57 | Bin: binary,
58 | Bech32Prefix: "nillion",
59 | Denom: "unillion",
60 | GasPrices: "0.00unillion",
61 | GasAdjustment: 1.3,
62 | TrustingPeriod: "508h",
63 | NoHostMount: false,
64 | ModifyGenesis: cosmos.ModifyGenesis(
65 | []cosmos.GenesisKV{
66 | cosmos.NewGenesisKV("app_state.gov.params.expedited_voting_period", "30s"),
67 | },
68 | ),
69 | },
70 | },
71 | },
72 | )
73 |
74 | chains, err := factory.Chains(t.Name())
75 | s.Require().NoError(err, "error creating chains")
76 |
77 | ic := interchaintest.NewInterchain().
78 | AddChain(chains[0])
79 |
80 | require.NoError(t, ic.Build(context.Background(), nil, interchaintest.InterchainBuildOptions{
81 | TestName: t.Name(),
82 | Client: client,
83 | NetworkID: network,
84 | BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(),
85 |
86 | SkipPathCreation: false,
87 | }))
88 |
89 | s.Chain = chains[0].(*cosmos.CosmosChain)
90 | }
91 |
92 | // UpgradeChain
93 | func (s *NetworkTestSuite) UpgradeChain(ctx context.Context, chain *cosmos.CosmosChain, wallet ibc.Wallet, upgradeVersion string) {
94 | planName := upgradeVersion
95 | s.ExecuteGovProposal(ctx, chain, wallet, planName, upgradeVersion)
96 |
97 | height, err := chain.Height(ctx)
98 | s.Require().NoError(err, "error fetching height before upgrade")
99 |
100 | timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Minute*2)
101 | defer timeoutCtxCancel()
102 |
103 | err = testutil.WaitForBlocks(timeoutCtx, int(haltHeight-height)+1, chain)
104 | s.Require().Error(err, "chain did not halt at halt height")
105 |
106 | err = chain.StopAllNodes(ctx)
107 | s.Require().NoError(err, "error stopping node(s)")
108 |
109 | chain.UpgradeVersion(ctx, s.DockerClient, chainRepository, upgradeVersion)
110 |
111 | err = chain.StartAllNodes(ctx)
112 | s.Require().NoError(err, "error starting upgraded node(s)")
113 |
114 | timeoutCtx, timeoutCtxCancel = context.WithTimeout(ctx, time.Minute*2)
115 | defer timeoutCtxCancel()
116 |
117 | err = testutil.WaitForBlocks(timeoutCtx, int(blocksAfterUpgrade), chain)
118 | s.Require().NoError(err, "chain did not produce blocks after upgrade")
119 |
120 | height, err = chain.Height(ctx)
121 | s.Require().NoError(err, "error fetching height after upgrade")
122 |
123 | s.Require().GreaterOrEqual(height, haltHeight+blocksAfterUpgrade, "height did not increment enough after upgrade")
124 | }
125 |
--------------------------------------------------------------------------------
/x/meta/testutil/mocks.go:
--------------------------------------------------------------------------------
1 | // Code generated by MockGen. DO NOT EDIT.
2 | // Source: x/meta/types/expected_keepers.go
3 | //
4 | // Generated by this command:
5 | //
6 | // mockgen -source x/meta/types/expected_keepers.go -package testutil -destination x/meta/testutil/mocks.go
7 | //
8 |
9 | // Package testutil is a generated GoMock package.
10 | package testutil
11 |
12 | import (
13 | context "context"
14 | reflect "reflect"
15 |
16 | types "github.com/cosmos/cosmos-sdk/types"
17 | gomock "go.uber.org/mock/gomock"
18 | )
19 |
20 | // MockBankKeeper is a mock of BankKeeper interface.
21 | type MockBankKeeper struct {
22 | ctrl *gomock.Controller
23 | recorder *MockBankKeeperMockRecorder
24 | }
25 |
26 | // MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper.
27 | type MockBankKeeperMockRecorder struct {
28 | mock *MockBankKeeper
29 | }
30 |
31 | // NewMockBankKeeper creates a new mock instance.
32 | func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper {
33 | mock := &MockBankKeeper{ctrl: ctrl}
34 | mock.recorder = &MockBankKeeperMockRecorder{mock}
35 | return mock
36 | }
37 |
38 | // EXPECT returns an object that allows the caller to indicate expected use.
39 | func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
40 | return m.recorder
41 | }
42 |
43 | // BurnCoins mocks base method.
44 | func (m *MockBankKeeper) BurnCoins(ctx context.Context, name string, amt types.Coins) error {
45 | m.ctrl.T.Helper()
46 | ret := m.ctrl.Call(m, "BurnCoins", ctx, name, amt)
47 | ret0, _ := ret[0].(error)
48 | return ret0
49 | }
50 |
51 | // BurnCoins indicates an expected call of BurnCoins.
52 | func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, name, amt any) *gomock.Call {
53 | mr.mock.ctrl.T.Helper()
54 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, name, amt)
55 | }
56 |
57 | // SendCoinsFromAccountToModule mocks base method.
58 | func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
59 | m.ctrl.T.Helper()
60 | ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
61 | ret0, _ := ret[0].(error)
62 | return ret0
63 | }
64 |
65 | // SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule.
66 | func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt any) *gomock.Call {
67 | mr.mock.ctrl.T.Helper()
68 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt)
69 | }
70 |
71 | // MockAccountKeeper is a mock of AccountKeeper interface.
72 | type MockAccountKeeper struct {
73 | ctrl *gomock.Controller
74 | recorder *MockAccountKeeperMockRecorder
75 | }
76 |
77 | // MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper.
78 | type MockAccountKeeperMockRecorder struct {
79 | mock *MockAccountKeeper
80 | }
81 |
82 | // NewMockAccountKeeper creates a new mock instance.
83 | func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper {
84 | mock := &MockAccountKeeper{ctrl: ctrl}
85 | mock.recorder = &MockAccountKeeperMockRecorder{mock}
86 | return mock
87 | }
88 |
89 | // EXPECT returns an object that allows the caller to indicate expected use.
90 | func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
91 | return m.recorder
92 | }
93 |
94 | // GetModuleAccount mocks base method.
95 | func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, moduleName string) types.ModuleAccountI {
96 | m.ctrl.T.Helper()
97 | ret := m.ctrl.Call(m, "GetModuleAccount", ctx, moduleName)
98 | ret0, _ := ret[0].(types.ModuleAccountI)
99 | return ret0
100 | }
101 |
102 | // GetModuleAccount indicates an expected call of GetModuleAccount.
103 | func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, moduleName any) *gomock.Call {
104 | mr.mock.ctrl.T.Helper()
105 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAccount), ctx, moduleName)
106 | }
107 |
--------------------------------------------------------------------------------
/app/test_helpers.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "encoding/json"
5 | "math/rand"
6 | "testing"
7 | "time"
8 |
9 | dbm "github.com/cosmos/cosmos-db"
10 | "github.com/stretchr/testify/require"
11 |
12 | "cosmossdk.io/log"
13 | sdkmath "cosmossdk.io/math"
14 |
15 | bam "github.com/cosmos/cosmos-sdk/baseapp"
16 | "github.com/cosmos/cosmos-sdk/client"
17 | "github.com/cosmos/cosmos-sdk/client/flags"
18 | "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
19 | cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
20 | "github.com/cosmos/cosmos-sdk/server"
21 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
22 | "github.com/cosmos/cosmos-sdk/testutil/mock"
23 | simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
24 | sdk "github.com/cosmos/cosmos-sdk/types"
25 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
26 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
27 |
28 | abci "github.com/cometbft/cometbft/abci/types"
29 | cmttypes "github.com/cometbft/cometbft/types"
30 | )
31 |
32 | // SetupOptions defines arguments that are passed into `Simapp` constructor.
33 | type SetupOptions struct {
34 | Logger log.Logger
35 | DB *dbm.MemDB
36 | AppOpts servertypes.AppOptions
37 | }
38 |
39 | // initSetup initializes a new NillionApp. A Nop logger is set in NillionApp.
40 | func initSetup(withGenesis bool, invCheckPeriod uint) (*NillionApp, GenesisState) {
41 | db := dbm.NewMemDB()
42 |
43 | appOptions := make(simtestutil.AppOptionsMap, 0)
44 | appOptions[flags.FlagHome] = DefaultNodeHome
45 | appOptions[server.FlagInvCheckPeriod] = invCheckPeriod
46 |
47 | app := NewNillionApp(log.NewNopLogger(), db, nil, true, appOptions)
48 | if withGenesis {
49 | return app, app.DefaultGenesis()
50 | }
51 | return app, GenesisState{}
52 | }
53 |
54 | // Setup initializes a new NillionApp. A Nop logger is set in NillionApp.
55 | func Setup(t *testing.T, isCheckTx bool) *NillionApp {
56 | t.Helper()
57 |
58 | privVal := mock.NewPV()
59 | pubKey, err := privVal.GetPubKey()
60 | require.NoError(t, err)
61 |
62 | // create validator set with single validator
63 | validator := cmttypes.NewValidator(pubKey, 1)
64 | valSet := cmttypes.NewValidatorSet([]*cmttypes.Validator{validator})
65 |
66 | // generate genesis account
67 | senderPrivKey := secp256k1.GenPrivKey()
68 | acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
69 | balance := banktypes.Balance{
70 | Address: acc.GetAddress().String(),
71 | Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
72 | }
73 |
74 | app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)
75 |
76 | return app
77 | }
78 |
79 | // SetupWithGenesisValSet initializes a new NillionApp with a validator set and genesis accounts
80 | // that also act as delegators. For simplicity, each validator is bonded with a delegation
81 | // of one consensus engine unit in the default token of the nillionapp from first genesis
82 | // account. A Nop logger is set in NillionApp.
83 | func SetupWithGenesisValSet(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *NillionApp {
84 | t.Helper()
85 |
86 | app, genesisState := initSetup(true, 5)
87 | genesisState, err := simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, genAccs, balances...)
88 | require.NoError(t, err)
89 |
90 | stateBytes, err := json.MarshalIndent(genesisState, "", " ")
91 | require.NoError(t, err)
92 |
93 | // init chain will set the validator set and initialize the genesis accounts
94 | _, err = app.InitChain(&abci.RequestInitChain{
95 | Validators: []abci.ValidatorUpdate{},
96 | ConsensusParams: simtestutil.DefaultConsensusParams,
97 | AppStateBytes: stateBytes,
98 | },
99 | )
100 | require.NoError(t, err)
101 |
102 | return app
103 | }
104 |
105 | // SignAndDeliver signs and delivers a transaction. No simulation occurs as the
106 | // ibc testing package causes checkState and deliverState to diverge in block time.
107 | //
108 | // CONTRACT: BeginBlock must be called before this function.
109 | func SignAndDeliver(
110 | tb testing.TB, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg,
111 | chainID string, accNums, accSeqs []uint64, expPass bool, blockTime time.Time, nextValHash []byte, priv ...cryptotypes.PrivKey,
112 | ) (*abci.ResponseFinalizeBlock, error) {
113 | tb.Helper()
114 | tx, err := simtestutil.GenSignedMockTx(
115 | rand.New(rand.NewSource(time.Now().UnixNano())),
116 | txCfg,
117 | msgs,
118 | sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
119 | simtestutil.DefaultGenTxGas,
120 | chainID,
121 | accNums,
122 | accSeqs,
123 | priv...,
124 | )
125 | require.NoError(tb, err)
126 |
127 | txBytes, err := txCfg.TxEncoder()(tx)
128 | require.NoError(tb, err)
129 |
130 | return app.FinalizeBlock(&abci.RequestFinalizeBlock{
131 | Height: app.LastBlockHeight() + 1,
132 | Time: blockTime,
133 | NextValidatorsHash: nextValHash,
134 | Txs: [][]byte{txBytes},
135 | })
136 | }
137 |
--------------------------------------------------------------------------------
/scripts/hermes.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Set the home directory for your chain
4 | NODE_IP="localhost"
5 | HOMEDIR="$HOME/.nillionapp"
6 | HOMEDIR1="$HOME/.nillionapp1"
7 | RPC_LADDR="$NODE_IP:26648"
8 | GRPC_ADDR="$NODE_IP:9081"
9 | RPC_LADDR1="$NODE_IP:26649"
10 | GRPC_ADDR1="$NODE_IP:9082"
11 |
12 | # Remove existing state to ensure a clean initialization
13 | rm -rf "$HOMEDIR"
14 | rm -rf "$HOMEDIR1"
15 |
16 | NILLIOND_BIN=$(which nilchaind)
17 |
18 | # Initialize the chain
19 | $NILLIOND_BIN init test --chain-id chainA --default-denom unillion --home "$HOMEDIR"
20 | $NILLIOND_BIN init test --chain-id chainB --default-denom unillion --home "$HOMEDIR1"
21 |
22 | # Configure other settings (chain ID, keyring-backend)
23 | $NILLIOND_BIN config set client chain-id chainA --home "$HOMEDIR"
24 | $NILLIOND_BIN config set client keyring-backend test --home "$HOMEDIR"
25 |
26 | $NILLIOND_BIN config set client chain-id chainB --home "$HOMEDIR1"
27 | $NILLIOND_BIN config set client keyring-backend test --home "$HOMEDIR1"
28 |
29 | # Add keys for users
30 | $NILLIOND_BIN keys add alice --home "$HOMEDIR"
31 | $NILLIOND_BIN keys add bob --home "$HOMEDIR"
32 | $NILLIOND_BIN keys add alice --home "$HOMEDIR1"
33 | $NILLIOND_BIN keys add bob --home "$HOMEDIR1"
34 |
35 | # Add genesis accounts and create a default validator
36 | $NILLIOND_BIN genesis add-genesis-account alice 10000000unillion --keyring-backend test --home "$HOMEDIR"
37 | $NILLIOND_BIN genesis add-genesis-account bob 1000unillion --keyring-backend test --home "$HOMEDIR"
38 |
39 | # Add genesis accounts and create a default validator
40 | $NILLIOND_BIN genesis add-genesis-account alice 10000000unillion --keyring-backend test --home "$HOMEDIR1"
41 | $NILLIOND_BIN genesis add-genesis-account bob 1000unillion --keyring-backend test --home "$HOMEDIR1"
42 |
43 | # Create a default validator and collect genesis transactions
44 | $NILLIOND_BIN genesis gentx alice 1000000unillion --chain-id chainA --home "$HOMEDIR"
45 | $NILLIOND_BIN genesis collect-gentxs --home "$HOMEDIR"
46 |
47 | # Create a default validator and collect genesis transactions
48 | $NILLIOND_BIN genesis gentx alice 1000000unillion --chain-id chainB --home "$HOMEDIR1"
49 | $NILLIOND_BIN genesis collect-gentxs --home "$HOMEDIR1"
50 |
51 | # Add account in genesis (required by Hermes)
52 | # Create user account keypair
53 | $NILLIOND_BIN keys add test --keyring-backend test --home $HOMEDIR --output json > $HOMEDIR/keypair.json 2>&1
54 | $NILLIOND_BIN genesis add-genesis-account $(jq -r .address $HOMEDIR/keypair.json) 1000000000stake --home $HOMEDIR
55 | $NILLIOND_BIN keys add test2 --keyring-backend test --home $HOMEDIR1 --output json > $HOMEDIR1/keypair.json 2>&1
56 | $NILLIOND_BIN genesis add-genesis-account $(jq -r .address $HOMEDIR1/keypair.json) 1000000000stake --home $HOMEDIR1
57 |
58 | # Start the chain
59 | $NILLIOND_BIN start \
60 | --home "$HOMEDIR" \
61 | --rpc.laddr tcp://${RPC_LADDR} \
62 | --grpc.address ${GRPC_ADDR} \
63 | --address tcp://${NODE_IP}:26635 \
64 | --p2p.laddr tcp://${NODE_IP}:26636 \
65 | --grpc.enable=true \
66 | --grpc-web.enable=true \
67 | --log_level trace \
68 | --trace \
69 | &> $HOMEDIR/logs &
70 |
71 | # Start the chain
72 | $NILLIOND_BIN start \
73 | --home "$HOMEDIR1" \
74 | --rpc.laddr tcp://${RPC_LADDR1} \
75 | --grpc.address ${GRPC_ADDR1} \
76 | --address tcp://${NODE_IP}:26634 \
77 | --grpc.enable=true \
78 | --p2p.laddr tcp://${NODE_IP}:26635 \
79 | --grpc-web.enable=true \
80 | --log_level trace \
81 | --trace \
82 | &> $HOMEDIR1/logs &
83 |
84 | sleep 10
85 |
86 | ######################################HERMES###################################
87 |
88 | # Setup Hermes in packet relayer mode
89 | killall hermes 2> /dev/null || true
90 | rm -rf ~/.hermes/
91 |
92 | mkdir ~/.hermes/
93 | touch ~/.hermes/config.toml
94 | tee ~/.hermes/config.toml< ~/.hermes/logs &
--------------------------------------------------------------------------------
/app/export.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "encoding/json"
5 | "errors"
6 | "log"
7 |
8 | storetypes "cosmossdk.io/store/types"
9 |
10 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
11 | sdk "github.com/cosmos/cosmos-sdk/types"
12 | slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
13 | "github.com/cosmos/cosmos-sdk/x/staking"
14 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
15 | )
16 |
17 | // ExportAppStateAndValidators exports the state of the application for a genesis
18 | // file.
19 | func (app *NillionApp) ExportAppStateAndValidators(
20 | forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
21 | ) (servertypes.ExportedApp, error) {
22 | // as if they could withdraw from the start of the next block
23 | ctx := app.NewContext(true)
24 |
25 | // We export at last height + 1, because that's the height at which
26 | // Tendermint will start InitChain.
27 | height := app.LastBlockHeight() + 1
28 | if forZeroHeight {
29 | height = 0
30 | app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
31 | }
32 |
33 | genState, err := app.ModuleManager.ExportGenesis(ctx, app.appCodec)
34 | if err != nil {
35 | return servertypes.ExportedApp{}, err
36 | }
37 | appState, err := json.MarshalIndent(genState, "", " ")
38 | if err != nil {
39 | return servertypes.ExportedApp{}, err
40 | }
41 |
42 | validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
43 | return servertypes.ExportedApp{
44 | AppState: appState,
45 | Validators: validators,
46 | Height: height,
47 | ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
48 | }, err
49 | }
50 |
51 | // prepare for fresh start at zero height
52 | // NOTE zero height genesis is a temporary feature that will be deprecated
53 | // in favour of export at a block height
54 | func (app *NillionApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
55 | applyAllowedAddrs := false
56 |
57 | // check if there is a allowed address list
58 | if len(jailAllowedAddrs) > 0 {
59 | applyAllowedAddrs = true
60 | }
61 |
62 | allowedAddrsMap := make(map[string]bool)
63 |
64 | for _, addr := range jailAllowedAddrs {
65 | _, err := sdk.ValAddressFromBech32(addr)
66 | if err != nil {
67 | log.Fatal(err)
68 | }
69 | allowedAddrsMap[addr] = true
70 | }
71 |
72 | /* Handle fee distribution state. */
73 |
74 | // withdraw all validator commission
75 | err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
76 | valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
77 | if err != nil {
78 | panic(err)
79 | }
80 | _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz)
81 | return false
82 | })
83 | if err != nil {
84 | panic(err)
85 | }
86 |
87 | // withdraw all delegator rewards
88 | dels, err := app.StakingKeeper.GetAllDelegations(ctx)
89 | if err != nil {
90 | panic(err)
91 | }
92 |
93 | for _, delegation := range dels {
94 | valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
95 | if err != nil {
96 | panic(err)
97 | }
98 |
99 | delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
100 | if err != nil {
101 | panic(err)
102 | }
103 | _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
104 | }
105 |
106 | // clear validator slash events
107 | app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
108 |
109 | // clear validator historical rewards
110 | app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
111 |
112 | // set context height to zero
113 | height := ctx.BlockHeight()
114 | ctx = ctx.WithBlockHeight(0)
115 |
116 | // reinitialize all validators
117 | err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
118 | valBz, err := sdk.ValAddressFromBech32(val.GetOperator())
119 | if err != nil {
120 | panic(err)
121 | }
122 | // donate any unwithdrawn outstanding reward fraction tokens to the community pool
123 | scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz)
124 | if err != nil {
125 | panic(err)
126 | }
127 | feePool, err := app.DistrKeeper.FeePool.Get(ctx)
128 | if err != nil {
129 | panic(err)
130 | }
131 | feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
132 | if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
133 | panic(err)
134 | }
135 |
136 | if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil {
137 | panic(err)
138 | }
139 | return false
140 | })
141 | if err != nil {
142 | panic(err)
143 | }
144 |
145 | // reinitialize all delegations
146 | for _, del := range dels {
147 | valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
148 | if err != nil {
149 | panic(err)
150 | }
151 | delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress)
152 | if err != nil {
153 | panic(err)
154 | }
155 | err = app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
156 | if err != nil {
157 | panic(err)
158 | }
159 | err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
160 | if err != nil {
161 | panic(err)
162 | }
163 | }
164 |
165 | // reset context height
166 | ctx = ctx.WithBlockHeight(height)
167 |
168 | /* Handle staking state. */
169 |
170 | // iterate through redelegations, reset creation height
171 | err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
172 | for i := range red.Entries {
173 | red.Entries[i].CreationHeight = 0
174 | }
175 | err = app.StakingKeeper.SetRedelegation(ctx, red)
176 | if err != nil {
177 | panic(err)
178 | }
179 | return false
180 | })
181 | if err != nil {
182 | panic(err)
183 | }
184 |
185 | // iterate through unbonding delegations, reset creation height
186 | err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
187 | for i := range ubd.Entries {
188 | ubd.Entries[i].CreationHeight = 0
189 | }
190 | err = app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
191 | if err != nil {
192 | panic(err)
193 | }
194 | return false
195 | })
196 | if err != nil {
197 | panic(err)
198 | }
199 |
200 | // Iterate through validators by power descending, reset bond heights, and
201 | // update bond intra-tx counters.
202 | store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
203 | iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
204 | counter := int16(0)
205 |
206 | for ; iter.Valid(); iter.Next() {
207 | addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
208 | validator, err := app.StakingKeeper.GetValidator(ctx, addr)
209 | if err != nil {
210 | panic(errors.New("expected validator, not found"))
211 | }
212 |
213 | validator.UnbondingHeight = 0
214 | if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
215 | validator.Jailed = true
216 | }
217 |
218 | err = app.StakingKeeper.SetValidator(ctx, validator)
219 | if err != nil {
220 | panic(errors.New("couldn't set validator"))
221 | }
222 | counter++
223 | }
224 |
225 | iter.Close()
226 |
227 | _, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
228 | if err != nil {
229 | log.Fatal(err)
230 | }
231 |
232 | /* Handle slashing state. */
233 |
234 | // reset start height on signing infos
235 | err = app.SlashingKeeper.IterateValidatorSigningInfos(
236 | ctx,
237 | func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
238 | info.StartHeight = 0
239 | err = app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
240 | if err != nil {
241 | panic(err)
242 | }
243 | return false
244 | },
245 | )
246 | if err != nil {
247 | log.Fatal(err)
248 | }
249 | }
250 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/make -f
2 |
3 | ifndef VERSION
4 | VERSION := $(shell echo $(shell git describe --always) | sed 's/^v//')
5 | endif
6 |
7 | export TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
8 | export COMMIT := $(shell git log -1 --format='%H')
9 |
10 | BUILDDIR ?= $(CURDIR)/build
11 | GOBIN ?= $(GOPATH)/bin
12 | NILLION_BINARY ?= nilchaind
13 | DOCKER := $(shell which docker)
14 | LEDGER_ENABLED := true
15 |
16 |
17 | # Default target executed when no arguments are given to make.
18 | default_target: all
19 |
20 | .PHONY: default_target
21 |
22 | # process build tags
23 | build_tags = netgo
24 | ifeq ($(LEDGER_ENABLED),true)
25 | ifeq ($(OS),Windows_NT)
26 | GCCEXE = $(shell where gcc.exe 2> NUL)
27 | ifeq ($(GCCEXE),)
28 | $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
29 | else
30 | build_tags += ledger
31 | endif
32 | else
33 | UNAME_S = $(shell uname -s)
34 | ifeq ($(UNAME_S),OpenBSD)
35 | $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
36 | else
37 | GCC = $(shell command -v gcc 2> /dev/null)
38 | ifeq ($(GCC),)
39 | $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
40 | else
41 | build_tags += ledger
42 | endif
43 | endif
44 | endif
45 | endif
46 |
47 | # Set Linux/arm64 compiler.
48 | UNAME_S = $(shell uname -s)
49 | ifeq ($(UNAME_S),Linux)
50 | UNAME_M = $(shell uname -m)
51 | ifneq ($(UNAME_M),aarch64)
52 | LINUX_ARM64_CC = "aarch64-linux-gnu-gcc"
53 | else
54 | LINUX_ARM64_CC = $(CC)
55 | endif
56 | else
57 | LINUX_ARM64_CC = $(CC)
58 | endif
59 |
60 | ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
61 | build_tags += gcc
62 | endif
63 | build_tags += $(BUILD_TAGS)
64 | build_tags := $(strip $(build_tags))
65 |
66 | ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=nilchain \
67 | -X github.com/cosmos/cosmos-sdk/version.AppName=nilchaind \
68 | -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
69 | -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
70 | -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
71 | -X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TMVERSION)
72 |
73 | ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
74 | ldflags += -w -s
75 | endif
76 | ldflags += $(LDFLAGS)
77 | ldflags := $(strip $(ldflags))
78 |
79 | # Build flags for compiling Go binaries
80 | BUILD_FLAGS = -tags '$(build_tags)' -ldflags '$(ldflags)'
81 |
82 | ###############################################################################
83 | ### Build ###
84 | ###############################################################################
85 |
86 | BUILD_TARGETS := build install
87 |
88 | build: BUILD_ARGS=-o $(BUILDDIR)/
89 | $(BUILD_TARGETS): go.sum $(BUILDDIR)/
90 | CGO_ENABLED="1" go $@ $(BUILD_FLAGS) $(BUILD_ARGS) ./...
91 |
92 | build-cross: go.sum $(BUILDDIR)/
93 | build-cross: build-darwin-amd64 build-darwin-arm64
94 | build-cross: build-linux-amd64 build-linux-arm64
95 |
96 | build-darwin-amd64 build-darwin-arm64: build-darwin-%:
97 | mkdir -p $(BUILDDIR)/darwin/$*
98 | GOOS=darwin GOARCH=$* go build $(BUILD_FLAGS) -o $(BUILDDIR)/darwin/$* ./...
99 |
100 | build-linux-amd64:
101 | mkdir -p $(BUILDDIR)/linux/amd64
102 | CGO_ENABLED="1" GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILDDIR)/linux/amd64 ./...
103 |
104 | build-linux-arm64:
105 | mkdir -p $(BUILDDIR)/linux/arm64
106 | test -z $(LINUX_ARM64_CC) || command -v $(LINUX_ARM64_CC) >/dev/null
107 | CC=$(LINUX_ARM64_CC) CGO_ENABLED="1" GOOS=linux GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILDDIR)/linux/arm64 ./...
108 |
109 | $(BUILDDIR)/:
110 | mkdir -p $(BUILDDIR)/
111 |
112 | clean:
113 | rm -rf \
114 | $(BUILDDIR)/ \
115 | artifacts/ \
116 | tmp-swagger-gen/
117 |
118 | all: build
119 |
120 | build-all: tools build lint test vulncheck
121 |
122 | .PHONY: distclean clean build-all
123 |
124 |
125 | ###############################################################################
126 | ### Run ###
127 | ###############################################################################
128 |
129 | init:
130 | cd scripts && sh init.sh
131 |
132 | ###############################################################################
133 | ### Protobuf ###
134 | ###############################################################################
135 |
136 | protoVer=latest
137 | protoImageName=cosmossdk-proto:$(protoVer)
138 | protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace --user 0 $(protoImageName)
139 |
140 | # ------
141 | # NOTE: If you are experiencing problems running these commands, try deleting
142 | # the docker images and execute the desired command again.
143 | #
144 | proto-all: proto-format proto-lint proto-gen proto-swagger-gen
145 |
146 | proto-gen:
147 | @echo "Generating Protobuf files"
148 | $(protoImage) sh ./scripts/protocgen.sh
149 |
150 | proto-swagger-gen:
151 | @echo "Downloading Protobuf dependencies"
152 | @make proto-download-deps
153 | @echo "Generating Protobuf Swagger"
154 | $(protoImage) sh ./scripts/protoc-swagger-gen.sh
155 |
156 | proto-format:
157 | @echo "Formatting Protobuf files"
158 | $(protoImage) find ./ -name *.proto -exec clang-format -i {} \;
159 |
160 | proto-lint:
161 | @echo "Linting Protobuf files"
162 | @$(protoImage) buf lint --error-format=json
163 |
164 | proto-check-breaking:
165 | @echo "Checking Protobuf files for breaking changes"
166 | $(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main
167 |
168 | SWAGGER_DIR=./swagger-proto
169 | THIRD_PARTY_DIR=$(SWAGGER_DIR)/third_party
170 |
171 | proto-download-deps:
172 | mkdir -p "$(THIRD_PARTY_DIR)/cosmos_tmp" && \
173 | cd "$(THIRD_PARTY_DIR)/cosmos_tmp" && \
174 | git init && \
175 | git remote add origin "https://github.com/evmos/cosmos-sdk.git" && \
176 | git config core.sparseCheckout true && \
177 | printf "proto\nthird_party\n" > .git/info/sparse-checkout && \
178 | git pull origin "$(DEPS_COSMOS_SDK_VERSION)" && \
179 | rm -f ./proto/buf.* && \
180 | mv ./proto/* ..
181 | rm -rf "$(THIRD_PARTY_DIR)/cosmos_tmp"
182 |
183 | mkdir -p "$(THIRD_PARTY_DIR)/ibc_tmp" && \
184 | cd "$(THIRD_PARTY_DIR)/ibc_tmp" && \
185 | git init && \
186 | git remote add origin "https://github.com/cosmos/ibc-go.git" && \
187 | git config core.sparseCheckout true && \
188 | printf "proto\n" > .git/info/sparse-checkout && \
189 | git pull origin "$(DEPS_IBC_GO_VERSION)" && \
190 | rm -f ./proto/buf.* && \
191 | mv ./proto/* ..
192 | rm -rf "$(THIRD_PARTY_DIR)/ibc_tmp"
193 |
194 | mkdir -p "$(THIRD_PARTY_DIR)/cosmos_proto_tmp" && \
195 | cd "$(THIRD_PARTY_DIR)/cosmos_proto_tmp" && \
196 | git init && \
197 | git remote add origin "https://github.com/cosmos/cosmos-proto.git" && \
198 | git config core.sparseCheckout true && \
199 | printf "proto\n" > .git/info/sparse-checkout && \
200 | git pull origin "$(DEPS_COSMOS_PROTO_VERSION)" && \
201 | rm -f ./proto/buf.* && \
202 | mv ./proto/* ..
203 | rm -rf "$(THIRD_PARTY_DIR)/cosmos_proto_tmp"
204 |
205 | mkdir -p "$(THIRD_PARTY_DIR)/gogoproto" && \
206 | curl -SSL "https://raw.githubusercontent.com/cosmos/gogoproto/$(DEPS_COSMOS_GOGOPROTO)/gogoproto/gogo.proto" > "$(THIRD_PARTY_DIR)/gogoproto/gogo.proto"
207 |
208 | mkdir -p "$(THIRD_PARTY_DIR)/google/api" && \
209 | curl -sSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/annotations.proto > "$(THIRD_PARTY_DIR)/google/api/annotations.proto"
210 | curl -sSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/http.proto > "$(THIRD_PARTY_DIR)/google/api/http.proto"
211 |
212 | mkdir -p "$(THIRD_PARTY_DIR)/cosmos/ics23/v1" && \
213 | curl -sSL "https://raw.githubusercontent.com/cosmos/ics23/$(DEPS_COSMOS_ICS23)/proto/cosmos/ics23/v1/proofs.proto" > "$(THIRD_PARTY_DIR)/cosmos/ics23/v1/proofs.proto"
214 |
215 |
216 | .PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking proto-swagger-gen
217 |
218 |
--------------------------------------------------------------------------------
/nilchaind/cmd/root.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "errors"
5 | "io"
6 | "os"
7 |
8 | dbm "github.com/cosmos/cosmos-db"
9 | "github.com/spf13/cobra"
10 | "github.com/spf13/viper"
11 |
12 | "cosmossdk.io/client/v2/autocli"
13 | "cosmossdk.io/log"
14 | confixcmd "cosmossdk.io/tools/confix/cmd"
15 |
16 | "github.com/cosmos/cosmos-sdk/client"
17 | "github.com/cosmos/cosmos-sdk/client/config"
18 | "github.com/cosmos/cosmos-sdk/client/debug"
19 | "github.com/cosmos/cosmos-sdk/client/flags"
20 | "github.com/cosmos/cosmos-sdk/client/keys"
21 | "github.com/cosmos/cosmos-sdk/client/pruning"
22 | "github.com/cosmos/cosmos-sdk/client/rpc"
23 | "github.com/cosmos/cosmos-sdk/client/snapshot"
24 | "github.com/cosmos/cosmos-sdk/codec"
25 | addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
26 | "github.com/cosmos/cosmos-sdk/crypto/keyring"
27 | "github.com/cosmos/cosmos-sdk/server"
28 | serverconfig "github.com/cosmos/cosmos-sdk/server/config"
29 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
30 | simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
31 | sdk "github.com/cosmos/cosmos-sdk/types"
32 | "github.com/cosmos/cosmos-sdk/types/module"
33 | "github.com/cosmos/cosmos-sdk/types/tx/signing"
34 | authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
35 | "github.com/cosmos/cosmos-sdk/x/auth/tx"
36 | txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
37 | "github.com/cosmos/cosmos-sdk/x/auth/types"
38 | "github.com/cosmos/cosmos-sdk/x/crisis"
39 | genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
40 |
41 | cmtcfg "github.com/cometbft/cometbft/config"
42 |
43 | nillionapp "github.com/NillionNetwork/nilchain/app"
44 | "github.com/NillionNetwork/nilchain/params"
45 | )
46 |
47 | // NewRootCmd creates a new root command for nilchaind. It is called once in the
48 | // main function.
49 | func NewRootCmd() *cobra.Command {
50 | // we "pre"-instantiate the application for getting the injected/configured encoding configuration
51 | // note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go)
52 | tempApp := nillionapp.NewNillionApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir()))
53 | encodingConfig := params.EncodingConfig{
54 | InterfaceRegistry: tempApp.InterfaceRegistry(),
55 | Codec: tempApp.AppCodec(),
56 | TxConfig: tempApp.TxConfig(),
57 | Amino: tempApp.LegacyAmino(),
58 | }
59 |
60 | initClientCtx := client.Context{}.
61 | WithCodec(encodingConfig.Codec).
62 | WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
63 | WithLegacyAmino(encodingConfig.Amino).
64 | WithTxConfig(encodingConfig.TxConfig).
65 | WithInput(os.Stdin).
66 | WithAccountRetriever(types.AccountRetriever{}).
67 | WithHomeDir(nillionapp.DefaultNodeHome).
68 | WithViper("") // In nillionapp, we don't use any prefix for env variables.
69 |
70 | rootCmd := &cobra.Command{
71 | Use: "nilchaind",
72 | Short: "nillion app chain",
73 | SilenceErrors: true,
74 | PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
75 | // set the default command outputs
76 | cmd.SetOut(cmd.OutOrStdout())
77 | cmd.SetErr(cmd.ErrOrStderr())
78 |
79 | initClientCtx = initClientCtx.WithCmdContext(cmd.Context())
80 | initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
81 | if err != nil {
82 | return err
83 | }
84 |
85 | initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
86 | if err != nil {
87 | return err
88 | }
89 |
90 | // This needs to go after ReadFromClientConfig, as that function
91 | // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode
92 | // is only available if the client is online.
93 | if !initClientCtx.Offline {
94 | txConfigOpts := tx.ConfigOptions{
95 | EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL),
96 | TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
97 | }
98 | txConfigWithTextual, err := tx.NewTxConfigWithOptions(
99 | codec.NewProtoCodec(encodingConfig.InterfaceRegistry),
100 | txConfigOpts,
101 | )
102 | if err != nil {
103 | return err
104 | }
105 | initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual)
106 | }
107 |
108 | if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
109 | return err
110 | }
111 |
112 | customAppTemplate, customAppConfig := initAppConfig()
113 | customCMTConfig := initCometBFTConfig()
114 |
115 | return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customCMTConfig)
116 | },
117 | }
118 |
119 | initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager)
120 |
121 | autoCliOpts, err := enrichAutoCliOpts(tempApp.AutoCliOpts(), initClientCtx)
122 | if err != nil {
123 | panic(err)
124 | }
125 |
126 | if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
127 | panic(err)
128 | }
129 |
130 | return rootCmd
131 | }
132 |
133 | func enrichAutoCliOpts(autoCliOpts autocli.AppOptions, clientCtx client.Context) (autocli.AppOptions, error) {
134 | autoCliOpts.AddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())
135 | autoCliOpts.ValidatorAddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())
136 | autoCliOpts.ConsensusAddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix())
137 |
138 | var err error
139 | clientCtx, err = config.ReadFromClientConfig(clientCtx)
140 | if err != nil {
141 | return autocli.AppOptions{}, err
142 | }
143 |
144 | autoCliOpts.ClientCtx = clientCtx
145 | autoCliOpts.Keyring, err = keyring.NewAutoCLIKeyring(clientCtx.Keyring)
146 | if err != nil {
147 | return autocli.AppOptions{}, err
148 | }
149 |
150 | return autoCliOpts, nil
151 | }
152 |
153 | // initCometBFTConfig helps to override default CometBFT Config values.
154 | // return cmtcfg.DefaultConfig if no custom configuration is required for the application.
155 | func initCometBFTConfig() *cmtcfg.Config {
156 | cfg := cmtcfg.DefaultConfig()
157 |
158 | // these values put a higher strain on node memory
159 | // cfg.P2P.MaxNumInboundPeers = 100
160 | // cfg.P2P.MaxNumOutboundPeers = 40
161 |
162 | return cfg
163 | }
164 |
165 | // initAppConfig helps to override default appConfig template and configs.
166 | // return "", nil if no custom configuration is required for the application.
167 | func initAppConfig() (string, interface{}) {
168 | // The following code snippet is just for reference.
169 |
170 | // WASMConfig defines the configuration for the wasm module.
171 | type WASMConfig struct {
172 | // This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
173 | QueryGasLimit uint64 `mapstructure:"query_gas_limit"`
174 |
175 | // Address defines the gRPC-web server to listen on
176 | LruSize uint64 `mapstructure:"lru_size"`
177 | }
178 |
179 | type CustomAppConfig struct {
180 | serverconfig.Config
181 |
182 | WASM WASMConfig `mapstructure:"wasm"`
183 | }
184 |
185 | // Optionally allow the chain developer to overwrite the SDK's default
186 | // server config.
187 | srvCfg := serverconfig.DefaultConfig()
188 | // The SDK's default minimum gas price is set to "" (empty value) inside
189 | // app.toml. If left empty by validators, the node will halt on startup.
190 | // However, the chain developer can set a default app.toml value for their
191 | // validators here.
192 | //
193 | // In summary:
194 | // - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
195 | // own app.toml config,
196 | // - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
197 | // own app.toml to override, or use this default value.
198 | //
199 | // In nillionapp, we set the min gas prices to 0.
200 | srvCfg.MinGasPrices = "0stake"
201 | // srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default
202 |
203 | customAppConfig := CustomAppConfig{
204 | Config: *srvCfg,
205 | WASM: WASMConfig{
206 | LruSize: 1,
207 | QueryGasLimit: 300000,
208 | },
209 | }
210 |
211 | customAppTemplate := serverconfig.DefaultConfigTemplate + `
212 | [wasm]
213 | # This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
214 | query_gas_limit = 300000
215 | # This is the number of wasm vm instances we keep cached in memory for speed-up
216 | # Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
217 | lru_size = 0`
218 |
219 | return customAppTemplate, customAppConfig
220 | }
221 |
222 | func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, basicManager module.BasicManager) {
223 | cfg := sdk.GetConfig()
224 | cfg.Seal()
225 |
226 | rootCmd.AddCommand(
227 | genutilcli.InitCmd(basicManager, nillionapp.DefaultNodeHome),
228 | debug.Cmd(),
229 | confixcmd.ConfigCommand(),
230 | pruning.Cmd(newApp, nillionapp.DefaultNodeHome),
231 | snapshot.Cmd(newApp),
232 | server.QueryBlockResultsCmd(),
233 | )
234 |
235 | server.AddCommands(rootCmd, nillionapp.DefaultNodeHome, newApp, appExport, addModuleInitFlags)
236 |
237 | // add keybase, auxiliary RPC, query, genesis, and tx child commands
238 | rootCmd.AddCommand(
239 | server.StatusCommand(),
240 | genesisCommand(encodingConfig, basicManager),
241 | txCommand(),
242 | queryCommand(),
243 | keys.Commands(),
244 | )
245 | }
246 |
247 | func addModuleInitFlags(startCmd *cobra.Command) {
248 | crisis.AddModuleInitFlags(startCmd)
249 | }
250 |
251 | func queryCommand() *cobra.Command {
252 | cmd := &cobra.Command{
253 | Use: "query",
254 | Aliases: []string{"q"},
255 | Short: "Querying subcommands",
256 | DisableFlagParsing: false,
257 | SuggestionsMinimumDistance: 2,
258 | RunE: client.ValidateCmd,
259 | }
260 |
261 | cmd.AddCommand(
262 | rpc.ValidatorCommand(),
263 | server.QueryBlockCmd(),
264 | authcmd.QueryTxsByEventsCmd(),
265 | server.QueryBlocksCmd(),
266 | authcmd.QueryTxCmd(),
267 | authcmd.GetSimulateCmd(),
268 | )
269 |
270 | return cmd
271 | }
272 |
273 | func txCommand() *cobra.Command {
274 | cmd := &cobra.Command{
275 | Use: "tx",
276 | Short: "Transactions subcommands",
277 | DisableFlagParsing: false,
278 | SuggestionsMinimumDistance: 2,
279 | RunE: client.ValidateCmd,
280 | }
281 |
282 | cmd.AddCommand(
283 | authcmd.GetSignCommand(),
284 | authcmd.GetSignBatchCommand(),
285 | authcmd.GetMultiSignCommand(),
286 | authcmd.GetMultiSignBatchCmd(),
287 | authcmd.GetValidateSignaturesCommand(),
288 | authcmd.GetBroadcastCommand(),
289 | authcmd.GetEncodeCommand(),
290 | authcmd.GetDecodeCommand(),
291 | authcmd.GetSimulateCmd(),
292 | )
293 |
294 | return cmd
295 | }
296 |
297 | // genesisCommand builds genesis-related `nilchaind genesis` command. Users may provide application specific commands as a parameter
298 | func genesisCommand(encodingConfig params.EncodingConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command {
299 | cmd := genutilcli.Commands(encodingConfig.TxConfig, basicManager, nillionapp.DefaultNodeHome)
300 |
301 | for _, subCmd := range cmds {
302 | cmd.AddCommand(subCmd)
303 | }
304 | return cmd
305 | }
306 |
307 | // newApp creates the application
308 | func newApp(
309 | logger log.Logger,
310 | db dbm.DB,
311 | traceStore io.Writer,
312 | appOpts servertypes.AppOptions,
313 | ) servertypes.Application {
314 | baseappOptions := server.DefaultBaseappOptions(appOpts)
315 |
316 | return nillionapp.NewNillionApp(
317 | logger, db, traceStore, true,
318 | appOpts,
319 | baseappOptions...,
320 | )
321 | }
322 |
323 | // appExport creates a new nillionapp (optionally at a given height) and exports state.
324 | func appExport(
325 | logger log.Logger,
326 | db dbm.DB,
327 | traceStore io.Writer,
328 | height int64,
329 | forZeroHeight bool,
330 | jailAllowedAddrs []string,
331 | appOpts servertypes.AppOptions,
332 | modulesToExport []string,
333 | ) (servertypes.ExportedApp, error) {
334 | var nillionApp *nillionapp.NillionApp
335 |
336 | // this check is necessary as we use the flag in x/upgrade.
337 | // we can exit more gracefully by checking the flag here.
338 | homePath, ok := appOpts.Get(flags.FlagHome).(string)
339 | if !ok || homePath == "" {
340 | return servertypes.ExportedApp{}, errors.New("application home not set")
341 | }
342 |
343 | viperAppOpts, ok := appOpts.(*viper.Viper)
344 | if !ok {
345 | return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
346 | }
347 |
348 | // overwrite the FlagInvCheckPeriod
349 | viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
350 | appOpts = viperAppOpts
351 |
352 | if height != -1 {
353 | nillionApp = nillionapp.NewNillionApp(logger, db, traceStore, false, appOpts)
354 |
355 | if err := nillionApp.LoadHeight(height); err != nil {
356 | return servertypes.ExportedApp{}, err
357 | }
358 | } else {
359 | nillionApp = nillionapp.NewNillionApp(logger, db, traceStore, true, appOpts)
360 | }
361 |
362 | return nillionApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
363 | }
364 |
365 | var tempDir = func() string {
366 | dir, err := os.MkdirTemp("", "nillionapp")
367 | if err != nil {
368 | dir = nillionapp.DefaultNodeHome
369 | }
370 | defer os.RemoveAll(dir)
371 |
372 | return dir
373 | }
374 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/NillionNetwork/nilchain
2 |
3 | go 1.22.2
4 |
5 | toolchain go1.22.4
6 |
7 | require (
8 | cosmossdk.io/api v0.7.6
9 | cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79
10 | cosmossdk.io/collections v0.4.0
11 | cosmossdk.io/core v0.11.0
12 | cosmossdk.io/errors v1.0.1
13 | cosmossdk.io/log v1.4.1
14 | cosmossdk.io/math v1.4.0
15 | cosmossdk.io/store v1.1.1
16 | cosmossdk.io/tools/confix v0.1.1
17 | cosmossdk.io/x/circuit v0.1.1
18 | cosmossdk.io/x/evidence v0.1.1
19 | cosmossdk.io/x/feegrant v0.1.1
20 | cosmossdk.io/x/tx v0.13.7
21 | cosmossdk.io/x/upgrade v0.1.2
22 | github.com/cometbft/cometbft v0.38.12
23 | github.com/cosmos/cosmos-db v1.1.0
24 | github.com/cosmos/cosmos-proto v1.0.0-beta.5
25 | github.com/cosmos/cosmos-sdk v0.50.11
26 | github.com/cosmos/gogoproto v1.7.0
27 | github.com/cosmos/ibc-go/modules/capability v1.0.0
28 | github.com/cosmos/ibc-go/v8 v8.2.1
29 | github.com/docker/docker v24.0.9+incompatible
30 | github.com/grpc-ecosystem/grpc-gateway v1.16.0
31 | github.com/spf13/cast v1.7.0
32 | github.com/spf13/cobra v1.8.1
33 | github.com/spf13/viper v1.19.0
34 | github.com/strangelove-ventures/interchaintest/v8 v8.4.0
35 | github.com/stretchr/testify v1.9.0
36 | go.uber.org/mock v0.4.0
37 | go.uber.org/zap v1.27.0
38 | google.golang.org/grpc v1.67.1
39 |
40 | )
41 |
42 | require (
43 | cloud.google.com/go v0.112.1 // indirect
44 | cloud.google.com/go/compute/metadata v0.5.0 // indirect
45 | cloud.google.com/go/iam v1.1.6 // indirect
46 | cloud.google.com/go/storage v1.38.0 // indirect
47 | cosmossdk.io/depinject v1.1.0 // indirect
48 | filippo.io/edwards25519 v1.0.0 // indirect
49 | github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
50 | github.com/99designs/keyring v1.2.2 // indirect
51 | github.com/BurntSushi/toml v1.4.0 // indirect
52 | github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
53 | github.com/ChainSafe/go-schnorrkel/1 v0.0.0-00010101000000-000000000000 // indirect
54 | github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 // indirect
55 | github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
56 | github.com/DataDog/zstd v1.5.5 // indirect
57 | github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
58 | github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
59 | github.com/Microsoft/go-winio v0.6.1 // indirect
60 | github.com/StirlingMarketingGroup/go-namecase v1.0.0 // indirect
61 | github.com/avast/retry-go/v4 v4.5.1 // indirect
62 | github.com/aws/aws-sdk-go v1.44.224 // indirect
63 | github.com/beorn7/perks v1.0.1 // indirect
64 | github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
65 | github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
66 | github.com/bits-and-blooms/bitset v1.10.0 // indirect
67 | github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
68 | github.com/cenkalti/backoff/v4 v4.1.3 // indirect
69 | github.com/cespare/xxhash v1.1.0 // indirect
70 | github.com/cespare/xxhash/v2 v2.3.0 // indirect
71 | github.com/chzyer/readline v1.5.1 // indirect
72 | github.com/cockroachdb/apd/v2 v2.0.2 // indirect
73 | github.com/cockroachdb/errors v1.11.3 // indirect
74 | github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
75 | github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
76 | github.com/cockroachdb/pebble v1.1.2 // indirect
77 | github.com/cockroachdb/redact v1.1.5 // indirect
78 | github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
79 | github.com/cometbft/cometbft-db v0.11.0 // indirect
80 | github.com/cosmos/btcutil v1.0.5 // indirect
81 | github.com/cosmos/go-bip39 v1.0.0 // indirect
82 | github.com/cosmos/gogogateway v1.2.0 // indirect
83 | github.com/cosmos/iavl v1.2.2 // indirect
84 | github.com/cosmos/ics23/go v0.11.0 // indirect
85 | github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74 // indirect
86 | github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
87 | github.com/creachadair/atomicfile v0.3.1 // indirect
88 | github.com/creachadair/tomledit v0.0.24 // indirect
89 | github.com/danieljoos/wincred v1.1.2 // indirect
90 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
91 | github.com/deckarep/golang-set v1.8.0 // indirect
92 | github.com/decred/base58 v1.0.4 // indirect
93 | github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
94 | github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.1 // indirect
95 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
96 | github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
97 | github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
98 | github.com/dgraph-io/ristretto v0.1.1 // indirect
99 | github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
100 | github.com/docker/distribution v2.8.2+incompatible // indirect
101 | github.com/docker/go-connections v0.5.0 // indirect
102 | github.com/docker/go-units v0.5.0 // indirect
103 | github.com/dustin/go-humanize v1.0.1 // indirect
104 | github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
105 | github.com/emicklei/dot v1.6.2 // indirect
106 | github.com/ethereum/go-ethereum v1.14.0 // indirect
107 | github.com/fatih/color v1.15.0 // indirect
108 | github.com/felixge/httpsnoop v1.0.4 // indirect
109 | github.com/fsnotify/fsnotify v1.7.0 // indirect
110 | github.com/getsentry/sentry-go v0.27.0 // indirect
111 | github.com/go-kit/kit v0.12.0 // indirect
112 | github.com/go-kit/log v0.2.1 // indirect
113 | github.com/go-logfmt/logfmt v0.6.0 // indirect
114 | github.com/go-logr/logr v1.4.1 // indirect
115 | github.com/go-logr/stdr v1.2.2 // indirect
116 | github.com/gobwas/httphead v0.1.0 // indirect
117 | github.com/gobwas/pool v0.2.1 // indirect
118 | github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
119 | github.com/gogo/googleapis v1.4.1 // indirect
120 | github.com/gogo/protobuf v1.3.3 // indirect
121 | github.com/golang/glog v1.2.2 // indirect
122 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
123 | github.com/golang/mock v1.6.0 // indirect
124 | github.com/golang/protobuf v1.5.4 // indirect
125 | github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
126 | github.com/google/btree v1.1.3 // indirect
127 | github.com/google/go-cmp v0.6.0 // indirect
128 | github.com/google/orderedcode v0.0.1 // indirect
129 | github.com/google/s2a-go v0.1.7 // indirect
130 | github.com/google/uuid v1.6.0 // indirect
131 | github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
132 | github.com/googleapis/gax-go/v2 v2.12.3 // indirect
133 | github.com/gorilla/handlers v1.5.2 // indirect
134 | github.com/gorilla/mux v1.8.1 // indirect
135 | github.com/gorilla/websocket v1.5.3 // indirect
136 | github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
137 | github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
138 | github.com/gtank/merlin v0.1.1 // indirect
139 | github.com/gtank/ristretto255 v0.1.2 // indirect
140 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
141 | github.com/hashicorp/go-getter v1.7.4 // indirect
142 | github.com/hashicorp/go-hclog v1.5.0 // indirect
143 | github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
144 | github.com/hashicorp/go-metrics v0.5.3 // indirect
145 | github.com/hashicorp/go-plugin v1.5.2 // indirect
146 | github.com/hashicorp/go-safetemp v1.0.0 // indirect
147 | github.com/hashicorp/go-version v1.6.0 // indirect
148 | github.com/hashicorp/golang-lru v1.0.2 // indirect
149 | github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
150 | github.com/hashicorp/hcl v1.0.0 // indirect
151 | github.com/hashicorp/yamux v0.1.1 // indirect
152 | github.com/hdevalence/ed25519consensus v0.1.0 // indirect
153 | github.com/holiman/uint256 v1.2.4 // indirect
154 | github.com/huandu/skiplist v1.2.0 // indirect
155 | github.com/iancoleman/strcase v0.3.0 // indirect
156 | github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845 // indirect
157 | github.com/improbable-eng/grpc-web v0.15.0 // indirect
158 | github.com/inconshreveable/mousetrap v1.1.0 // indirect
159 | github.com/ipfs/go-cid v0.4.1 // indirect
160 | github.com/jmespath/go-jmespath v0.4.0 // indirect
161 | github.com/jmhodges/levigo v1.0.0 // indirect
162 | github.com/klauspost/compress v1.17.9 // indirect
163 | github.com/klauspost/cpuid/v2 v2.2.7 // indirect
164 | github.com/kr/pretty v0.3.1 // indirect
165 | github.com/kr/text v0.2.0 // indirect
166 | github.com/lib/pq v1.10.7 // indirect
167 | github.com/libp2p/go-buffer-pool v0.1.0 // indirect
168 | github.com/libp2p/go-libp2p v0.31.0 // indirect
169 | github.com/linxGnu/grocksdb v1.8.14 // indirect
170 | github.com/magiconair/properties v1.8.7 // indirect
171 | github.com/manifoldco/promptui v0.9.0 // indirect
172 | github.com/mattn/go-colorable v0.1.13 // indirect
173 | github.com/mattn/go-isatty v0.0.20 // indirect
174 | github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect
175 | github.com/minio/highwayhash v1.0.2 // indirect
176 | github.com/minio/sha256-simd v1.0.1 // indirect
177 | github.com/misko9/go-substrate-rpc-client/v4 v4.0.0-20230913220906-b988ea7da0c2 // indirect
178 | github.com/mitchellh/go-homedir v1.1.0 // indirect
179 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect
180 | github.com/mitchellh/mapstructure v1.5.0 // indirect
181 | github.com/mr-tron/base58 v1.2.0 // indirect
182 | github.com/mtibben/percent v0.2.1 // indirect
183 | github.com/multiformats/go-base32 v0.1.0 // indirect
184 | github.com/multiformats/go-base36 v0.2.0 // indirect
185 | github.com/multiformats/go-multiaddr v0.11.0 // indirect
186 | github.com/multiformats/go-multibase v0.2.0 // indirect
187 | github.com/multiformats/go-multicodec v0.9.0 // indirect
188 | github.com/multiformats/go-multihash v0.2.3 // indirect
189 | github.com/multiformats/go-varint v0.0.7 // indirect
190 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
191 | github.com/ncruces/go-strftime v0.1.9 // indirect
192 | github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
193 | github.com/oklog/run v1.1.0 // indirect
194 | github.com/opencontainers/go-digest v1.0.0 // indirect
195 | github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
196 | github.com/pelletier/go-toml v1.9.5 // indirect
197 | github.com/pelletier/go-toml/v2 v2.2.2 // indirect
198 | github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
199 | github.com/pierrec/xxHash v0.1.5 // indirect
200 | github.com/pkg/errors v0.9.1 // indirect
201 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
202 | github.com/prometheus/client_golang v1.20.1 // indirect
203 | github.com/prometheus/client_model v0.6.1 // indirect
204 | github.com/prometheus/common v0.55.0 // indirect
205 | github.com/prometheus/procfs v0.15.1 // indirect
206 | github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
207 | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
208 | github.com/rogpeppe/go-internal v1.12.0 // indirect
209 | github.com/rs/cors v1.11.1 // indirect
210 | github.com/rs/zerolog v1.33.0 // indirect
211 | github.com/sagikazarmark/locafero v0.4.0 // indirect
212 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect
213 | github.com/sasha-s/go-deadlock v0.3.1 // indirect
214 | github.com/sourcegraph/conc v0.3.0 // indirect
215 | github.com/spaolacci/murmur3 v1.1.0 // indirect
216 | github.com/spf13/afero v1.11.0 // indirect
217 | github.com/spf13/pflag v1.0.5 // indirect
218 | github.com/subosito/gotenv v1.6.0 // indirect
219 | github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
220 | github.com/tendermint/go-amino v0.16.0 // indirect
221 | github.com/tidwall/btree v1.7.0 // indirect
222 | github.com/tyler-smith/go-bip32 v1.0.0 // indirect
223 | github.com/tyler-smith/go-bip39 v1.1.0 // indirect
224 | github.com/ulikunitz/xz v0.5.11 // indirect
225 | github.com/zondax/hid v0.9.2 // indirect
226 | github.com/zondax/ledger-go v0.14.3 // indirect
227 | go.etcd.io/bbolt v1.3.10 // indirect
228 | go.opencensus.io v0.24.0 // indirect
229 | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
230 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
231 | go.opentelemetry.io/otel v1.24.0 // indirect
232 | go.opentelemetry.io/otel/metric v1.24.0 // indirect
233 | go.opentelemetry.io/otel/trace v1.24.0 // indirect
234 | go.uber.org/multierr v1.11.0 // indirect
235 | golang.org/x/crypto v0.27.0 // indirect
236 | golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
237 | golang.org/x/mod v0.17.0 // indirect
238 | golang.org/x/net v0.29.0 // indirect
239 | golang.org/x/oauth2 v0.22.0 // indirect
240 | golang.org/x/sync v0.8.0 // indirect
241 | golang.org/x/sys v0.25.0 // indirect
242 | golang.org/x/term v0.24.0 // indirect
243 | golang.org/x/text v0.18.0 // indirect
244 | golang.org/x/time v0.5.0 // indirect
245 | golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
246 | google.golang.org/api v0.171.0 // indirect
247 | google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
248 | google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
249 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
250 | google.golang.org/protobuf v1.35.1 // indirect
251 | gopkg.in/ini.v1 v1.67.0 // indirect
252 | gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
253 | gopkg.in/yaml.v2 v2.4.0 // indirect
254 | gopkg.in/yaml.v3 v3.0.1 // indirect
255 | gotest.tools/v3 v3.5.1 // indirect
256 | lukechampine.com/blake3 v1.2.1 // indirect
257 | modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
258 | modernc.org/libc v1.49.3 // indirect
259 | modernc.org/mathutil v1.6.0 // indirect
260 | modernc.org/memory v1.8.0 // indirect
261 | modernc.org/sqlite v1.29.9 // indirect
262 | modernc.org/strutil v1.2.0 // indirect
263 | modernc.org/token v1.1.0 // indirect
264 | nhooyr.io/websocket v1.8.7 // indirect
265 | pgregory.net/rapid v1.1.0 // indirect
266 | sigs.k8s.io/yaml v1.4.0 // indirect
267 | )
268 |
269 | replace (
270 | github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
271 | github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0
272 | github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
273 | github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
274 | github.com/zondax/ledger-go => github.com/zondax/ledger-go v1.0.0
275 | )
276 |
--------------------------------------------------------------------------------
/x/meta/types/genesis.pb.go:
--------------------------------------------------------------------------------
1 | // Code generated by protoc-gen-gogo. DO NOT EDIT.
2 | // source: nillion/meta/v1/genesis.proto
3 |
4 | package types
5 |
6 | import (
7 | fmt "fmt"
8 | _ "github.com/cosmos/cosmos-proto"
9 | proto "github.com/cosmos/gogoproto/proto"
10 | io "io"
11 | math "math"
12 | math_bits "math/bits"
13 | )
14 |
15 | // Reference imports to suppress errors if they are not otherwise used.
16 | var _ = proto.Marshal
17 | var _ = fmt.Errorf
18 | var _ = math.Inf
19 |
20 | // This is a compile-time assertion to ensure that this generated file
21 | // is compatible with the proto package it is being compiled against.
22 | // A compilation error at this line likely means your copy of the
23 | // proto package needs to be updated.
24 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
25 |
26 | // GenesisState defines the meta module's genesis state.
27 | type GenesisState struct {
28 | Resources []*Resource `protobuf:"bytes,1,rep,name=resources,proto3" json:"resources,omitempty"`
29 | }
30 |
31 | func (m *GenesisState) Reset() { *m = GenesisState{} }
32 | func (m *GenesisState) String() string { return proto.CompactTextString(m) }
33 | func (*GenesisState) ProtoMessage() {}
34 | func (*GenesisState) Descriptor() ([]byte, []int) {
35 | return fileDescriptor_6875af70665fec96, []int{0}
36 | }
37 | func (m *GenesisState) XXX_Unmarshal(b []byte) error {
38 | return m.Unmarshal(b)
39 | }
40 | func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
41 | if deterministic {
42 | return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic)
43 | } else {
44 | b = b[:cap(b)]
45 | n, err := m.MarshalToSizedBuffer(b)
46 | if err != nil {
47 | return nil, err
48 | }
49 | return b[:n], nil
50 | }
51 | }
52 | func (m *GenesisState) XXX_Merge(src proto.Message) {
53 | xxx_messageInfo_GenesisState.Merge(m, src)
54 | }
55 | func (m *GenesisState) XXX_Size() int {
56 | return m.Size()
57 | }
58 | func (m *GenesisState) XXX_DiscardUnknown() {
59 | xxx_messageInfo_GenesisState.DiscardUnknown(m)
60 | }
61 |
62 | var xxx_messageInfo_GenesisState proto.InternalMessageInfo
63 |
64 | func (m *GenesisState) GetResources() []*Resource {
65 | if m != nil {
66 | return m.Resources
67 | }
68 | return nil
69 | }
70 |
71 | type Resource struct {
72 | FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"`
73 | Metadata []byte `protobuf:"bytes,2,opt,name=metadata,proto3" json:"metadata,omitempty"`
74 | }
75 |
76 | func (m *Resource) Reset() { *m = Resource{} }
77 | func (m *Resource) String() string { return proto.CompactTextString(m) }
78 | func (*Resource) ProtoMessage() {}
79 | func (*Resource) Descriptor() ([]byte, []int) {
80 | return fileDescriptor_6875af70665fec96, []int{1}
81 | }
82 | func (m *Resource) XXX_Unmarshal(b []byte) error {
83 | return m.Unmarshal(b)
84 | }
85 | func (m *Resource) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
86 | if deterministic {
87 | return xxx_messageInfo_Resource.Marshal(b, m, deterministic)
88 | } else {
89 | b = b[:cap(b)]
90 | n, err := m.MarshalToSizedBuffer(b)
91 | if err != nil {
92 | return nil, err
93 | }
94 | return b[:n], nil
95 | }
96 | }
97 | func (m *Resource) XXX_Merge(src proto.Message) {
98 | xxx_messageInfo_Resource.Merge(m, src)
99 | }
100 | func (m *Resource) XXX_Size() int {
101 | return m.Size()
102 | }
103 | func (m *Resource) XXX_DiscardUnknown() {
104 | xxx_messageInfo_Resource.DiscardUnknown(m)
105 | }
106 |
107 | var xxx_messageInfo_Resource proto.InternalMessageInfo
108 |
109 | func (m *Resource) GetFromAddress() string {
110 | if m != nil {
111 | return m.FromAddress
112 | }
113 | return ""
114 | }
115 |
116 | func (m *Resource) GetMetadata() []byte {
117 | if m != nil {
118 | return m.Metadata
119 | }
120 | return nil
121 | }
122 |
123 | func init() {
124 | proto.RegisterType((*GenesisState)(nil), "nillion.meta.v1.GenesisState")
125 | proto.RegisterType((*Resource)(nil), "nillion.meta.v1.Resource")
126 | }
127 |
128 | func init() { proto.RegisterFile("nillion/meta/v1/genesis.proto", fileDescriptor_6875af70665fec96) }
129 |
130 | var fileDescriptor_6875af70665fec96 = []byte{
131 | // 266 bytes of a gzipped FileDescriptorProto
132 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcd, 0xcb, 0xcc, 0xc9,
133 | 0xc9, 0xcc, 0xcf, 0xd3, 0xcf, 0x4d, 0x2d, 0x49, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b,
134 | 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x87, 0x4a, 0xeb, 0x81, 0xa4,
135 | 0xf5, 0xca, 0x0c, 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xe3, 0xc1, 0xd2, 0xfa, 0x10,
136 | 0x0e, 0x44, 0xad, 0x92, 0x3b, 0x17, 0x8f, 0x3b, 0x44, 0x73, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90,
137 | 0x39, 0x17, 0x67, 0x51, 0x6a, 0x71, 0x7e, 0x69, 0x51, 0x72, 0x6a, 0xb1, 0x04, 0xa3, 0x02, 0xb3,
138 | 0x06, 0xb7, 0x91, 0xa4, 0x1e, 0x9a, 0x79, 0x7a, 0x41, 0x50, 0x15, 0x41, 0x08, 0xb5, 0x4a, 0xc9,
139 | 0x5c, 0x1c, 0x30, 0x61, 0x21, 0x6b, 0x2e, 0x9e, 0xb4, 0xa2, 0xfc, 0xdc, 0xf8, 0xc4, 0x94, 0x94,
140 | 0xa2, 0xd4, 0x62, 0x90, 0x39, 0x8c, 0x1a, 0x9c, 0x4e, 0x12, 0x97, 0xb6, 0xe8, 0x8a, 0x40, 0x2d,
141 | 0x77, 0x84, 0xc8, 0x04, 0x97, 0x14, 0x65, 0xe6, 0xa5, 0x07, 0x71, 0x83, 0x54, 0x43, 0x85, 0x84,
142 | 0xa4, 0xb8, 0x38, 0x40, 0xf6, 0xa4, 0x24, 0x96, 0x24, 0x4a, 0x30, 0x29, 0x30, 0x6a, 0xf0, 0x04,
143 | 0xc1, 0xf9, 0x4e, 0x7e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c,
144 | 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x92,
145 | 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0xef, 0x07, 0x71, 0xae, 0x5f, 0x6a,
146 | 0x49, 0x79, 0x7e, 0x51, 0xb6, 0x3e, 0xd4, 0xf5, 0xba, 0xc9, 0x19, 0x89, 0x99, 0x79, 0xfa, 0x15,
147 | 0x90, 0x40, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x07, 0x82, 0x31, 0x20, 0x00, 0x00,
148 | 0xff, 0xff, 0xfd, 0xaf, 0xb3, 0x03, 0x51, 0x01, 0x00, 0x00,
149 | }
150 |
151 | func (m *GenesisState) Marshal() (dAtA []byte, err error) {
152 | size := m.Size()
153 | dAtA = make([]byte, size)
154 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
155 | if err != nil {
156 | return nil, err
157 | }
158 | return dAtA[:n], nil
159 | }
160 |
161 | func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) {
162 | size := m.Size()
163 | return m.MarshalToSizedBuffer(dAtA[:size])
164 | }
165 |
166 | func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
167 | i := len(dAtA)
168 | _ = i
169 | var l int
170 | _ = l
171 | if len(m.Resources) > 0 {
172 | for iNdEx := len(m.Resources) - 1; iNdEx >= 0; iNdEx-- {
173 | {
174 | size, err := m.Resources[iNdEx].MarshalToSizedBuffer(dAtA[:i])
175 | if err != nil {
176 | return 0, err
177 | }
178 | i -= size
179 | i = encodeVarintGenesis(dAtA, i, uint64(size))
180 | }
181 | i--
182 | dAtA[i] = 0xa
183 | }
184 | }
185 | return len(dAtA) - i, nil
186 | }
187 |
188 | func (m *Resource) Marshal() (dAtA []byte, err error) {
189 | size := m.Size()
190 | dAtA = make([]byte, size)
191 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
192 | if err != nil {
193 | return nil, err
194 | }
195 | return dAtA[:n], nil
196 | }
197 |
198 | func (m *Resource) MarshalTo(dAtA []byte) (int, error) {
199 | size := m.Size()
200 | return m.MarshalToSizedBuffer(dAtA[:size])
201 | }
202 |
203 | func (m *Resource) MarshalToSizedBuffer(dAtA []byte) (int, error) {
204 | i := len(dAtA)
205 | _ = i
206 | var l int
207 | _ = l
208 | if len(m.Metadata) > 0 {
209 | i -= len(m.Metadata)
210 | copy(dAtA[i:], m.Metadata)
211 | i = encodeVarintGenesis(dAtA, i, uint64(len(m.Metadata)))
212 | i--
213 | dAtA[i] = 0x12
214 | }
215 | if len(m.FromAddress) > 0 {
216 | i -= len(m.FromAddress)
217 | copy(dAtA[i:], m.FromAddress)
218 | i = encodeVarintGenesis(dAtA, i, uint64(len(m.FromAddress)))
219 | i--
220 | dAtA[i] = 0xa
221 | }
222 | return len(dAtA) - i, nil
223 | }
224 |
225 | func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
226 | offset -= sovGenesis(v)
227 | base := offset
228 | for v >= 1<<7 {
229 | dAtA[offset] = uint8(v&0x7f | 0x80)
230 | v >>= 7
231 | offset++
232 | }
233 | dAtA[offset] = uint8(v)
234 | return base
235 | }
236 | func (m *GenesisState) Size() (n int) {
237 | if m == nil {
238 | return 0
239 | }
240 | var l int
241 | _ = l
242 | if len(m.Resources) > 0 {
243 | for _, e := range m.Resources {
244 | l = e.Size()
245 | n += 1 + l + sovGenesis(uint64(l))
246 | }
247 | }
248 | return n
249 | }
250 |
251 | func (m *Resource) Size() (n int) {
252 | if m == nil {
253 | return 0
254 | }
255 | var l int
256 | _ = l
257 | l = len(m.FromAddress)
258 | if l > 0 {
259 | n += 1 + l + sovGenesis(uint64(l))
260 | }
261 | l = len(m.Metadata)
262 | if l > 0 {
263 | n += 1 + l + sovGenesis(uint64(l))
264 | }
265 | return n
266 | }
267 |
268 | func sovGenesis(x uint64) (n int) {
269 | return (math_bits.Len64(x|1) + 6) / 7
270 | }
271 | func sozGenesis(x uint64) (n int) {
272 | return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
273 | }
274 | func (m *GenesisState) Unmarshal(dAtA []byte) error {
275 | l := len(dAtA)
276 | iNdEx := 0
277 | for iNdEx < l {
278 | preIndex := iNdEx
279 | var wire uint64
280 | for shift := uint(0); ; shift += 7 {
281 | if shift >= 64 {
282 | return ErrIntOverflowGenesis
283 | }
284 | if iNdEx >= l {
285 | return io.ErrUnexpectedEOF
286 | }
287 | b := dAtA[iNdEx]
288 | iNdEx++
289 | wire |= uint64(b&0x7F) << shift
290 | if b < 0x80 {
291 | break
292 | }
293 | }
294 | fieldNum := int32(wire >> 3)
295 | wireType := int(wire & 0x7)
296 | if wireType == 4 {
297 | return fmt.Errorf("proto: GenesisState: wiretype end group for non-group")
298 | }
299 | if fieldNum <= 0 {
300 | return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire)
301 | }
302 | switch fieldNum {
303 | case 1:
304 | if wireType != 2 {
305 | return fmt.Errorf("proto: wrong wireType = %d for field Resources", wireType)
306 | }
307 | var msglen int
308 | for shift := uint(0); ; shift += 7 {
309 | if shift >= 64 {
310 | return ErrIntOverflowGenesis
311 | }
312 | if iNdEx >= l {
313 | return io.ErrUnexpectedEOF
314 | }
315 | b := dAtA[iNdEx]
316 | iNdEx++
317 | msglen |= int(b&0x7F) << shift
318 | if b < 0x80 {
319 | break
320 | }
321 | }
322 | if msglen < 0 {
323 | return ErrInvalidLengthGenesis
324 | }
325 | postIndex := iNdEx + msglen
326 | if postIndex < 0 {
327 | return ErrInvalidLengthGenesis
328 | }
329 | if postIndex > l {
330 | return io.ErrUnexpectedEOF
331 | }
332 | m.Resources = append(m.Resources, &Resource{})
333 | if err := m.Resources[len(m.Resources)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
334 | return err
335 | }
336 | iNdEx = postIndex
337 | default:
338 | iNdEx = preIndex
339 | skippy, err := skipGenesis(dAtA[iNdEx:])
340 | if err != nil {
341 | return err
342 | }
343 | if (skippy < 0) || (iNdEx+skippy) < 0 {
344 | return ErrInvalidLengthGenesis
345 | }
346 | if (iNdEx + skippy) > l {
347 | return io.ErrUnexpectedEOF
348 | }
349 | iNdEx += skippy
350 | }
351 | }
352 |
353 | if iNdEx > l {
354 | return io.ErrUnexpectedEOF
355 | }
356 | return nil
357 | }
358 | func (m *Resource) Unmarshal(dAtA []byte) error {
359 | l := len(dAtA)
360 | iNdEx := 0
361 | for iNdEx < l {
362 | preIndex := iNdEx
363 | var wire uint64
364 | for shift := uint(0); ; shift += 7 {
365 | if shift >= 64 {
366 | return ErrIntOverflowGenesis
367 | }
368 | if iNdEx >= l {
369 | return io.ErrUnexpectedEOF
370 | }
371 | b := dAtA[iNdEx]
372 | iNdEx++
373 | wire |= uint64(b&0x7F) << shift
374 | if b < 0x80 {
375 | break
376 | }
377 | }
378 | fieldNum := int32(wire >> 3)
379 | wireType := int(wire & 0x7)
380 | if wireType == 4 {
381 | return fmt.Errorf("proto: Resource: wiretype end group for non-group")
382 | }
383 | if fieldNum <= 0 {
384 | return fmt.Errorf("proto: Resource: illegal tag %d (wire type %d)", fieldNum, wire)
385 | }
386 | switch fieldNum {
387 | case 1:
388 | if wireType != 2 {
389 | return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType)
390 | }
391 | var stringLen uint64
392 | for shift := uint(0); ; shift += 7 {
393 | if shift >= 64 {
394 | return ErrIntOverflowGenesis
395 | }
396 | if iNdEx >= l {
397 | return io.ErrUnexpectedEOF
398 | }
399 | b := dAtA[iNdEx]
400 | iNdEx++
401 | stringLen |= uint64(b&0x7F) << shift
402 | if b < 0x80 {
403 | break
404 | }
405 | }
406 | intStringLen := int(stringLen)
407 | if intStringLen < 0 {
408 | return ErrInvalidLengthGenesis
409 | }
410 | postIndex := iNdEx + intStringLen
411 | if postIndex < 0 {
412 | return ErrInvalidLengthGenesis
413 | }
414 | if postIndex > l {
415 | return io.ErrUnexpectedEOF
416 | }
417 | m.FromAddress = string(dAtA[iNdEx:postIndex])
418 | iNdEx = postIndex
419 | case 2:
420 | if wireType != 2 {
421 | return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType)
422 | }
423 | var byteLen int
424 | for shift := uint(0); ; shift += 7 {
425 | if shift >= 64 {
426 | return ErrIntOverflowGenesis
427 | }
428 | if iNdEx >= l {
429 | return io.ErrUnexpectedEOF
430 | }
431 | b := dAtA[iNdEx]
432 | iNdEx++
433 | byteLen |= int(b&0x7F) << shift
434 | if b < 0x80 {
435 | break
436 | }
437 | }
438 | if byteLen < 0 {
439 | return ErrInvalidLengthGenesis
440 | }
441 | postIndex := iNdEx + byteLen
442 | if postIndex < 0 {
443 | return ErrInvalidLengthGenesis
444 | }
445 | if postIndex > l {
446 | return io.ErrUnexpectedEOF
447 | }
448 | m.Metadata = append(m.Metadata[:0], dAtA[iNdEx:postIndex]...)
449 | if m.Metadata == nil {
450 | m.Metadata = []byte{}
451 | }
452 | iNdEx = postIndex
453 | default:
454 | iNdEx = preIndex
455 | skippy, err := skipGenesis(dAtA[iNdEx:])
456 | if err != nil {
457 | return err
458 | }
459 | if (skippy < 0) || (iNdEx+skippy) < 0 {
460 | return ErrInvalidLengthGenesis
461 | }
462 | if (iNdEx + skippy) > l {
463 | return io.ErrUnexpectedEOF
464 | }
465 | iNdEx += skippy
466 | }
467 | }
468 |
469 | if iNdEx > l {
470 | return io.ErrUnexpectedEOF
471 | }
472 | return nil
473 | }
474 | func skipGenesis(dAtA []byte) (n int, err error) {
475 | l := len(dAtA)
476 | iNdEx := 0
477 | depth := 0
478 | for iNdEx < l {
479 | var wire uint64
480 | for shift := uint(0); ; shift += 7 {
481 | if shift >= 64 {
482 | return 0, ErrIntOverflowGenesis
483 | }
484 | if iNdEx >= l {
485 | return 0, io.ErrUnexpectedEOF
486 | }
487 | b := dAtA[iNdEx]
488 | iNdEx++
489 | wire |= (uint64(b) & 0x7F) << shift
490 | if b < 0x80 {
491 | break
492 | }
493 | }
494 | wireType := int(wire & 0x7)
495 | switch wireType {
496 | case 0:
497 | for shift := uint(0); ; shift += 7 {
498 | if shift >= 64 {
499 | return 0, ErrIntOverflowGenesis
500 | }
501 | if iNdEx >= l {
502 | return 0, io.ErrUnexpectedEOF
503 | }
504 | iNdEx++
505 | if dAtA[iNdEx-1] < 0x80 {
506 | break
507 | }
508 | }
509 | case 1:
510 | iNdEx += 8
511 | case 2:
512 | var length int
513 | for shift := uint(0); ; shift += 7 {
514 | if shift >= 64 {
515 | return 0, ErrIntOverflowGenesis
516 | }
517 | if iNdEx >= l {
518 | return 0, io.ErrUnexpectedEOF
519 | }
520 | b := dAtA[iNdEx]
521 | iNdEx++
522 | length |= (int(b) & 0x7F) << shift
523 | if b < 0x80 {
524 | break
525 | }
526 | }
527 | if length < 0 {
528 | return 0, ErrInvalidLengthGenesis
529 | }
530 | iNdEx += length
531 | case 3:
532 | depth++
533 | case 4:
534 | if depth == 0 {
535 | return 0, ErrUnexpectedEndOfGroupGenesis
536 | }
537 | depth--
538 | case 5:
539 | iNdEx += 4
540 | default:
541 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
542 | }
543 | if iNdEx < 0 {
544 | return 0, ErrInvalidLengthGenesis
545 | }
546 | if depth == 0 {
547 | return iNdEx, nil
548 | }
549 | }
550 | return 0, io.ErrUnexpectedEOF
551 | }
552 |
553 | var (
554 | ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling")
555 | ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow")
556 | ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
557 | )
558 |
--------------------------------------------------------------------------------
/x/meta/types/tx.pb.go:
--------------------------------------------------------------------------------
1 | // Code generated by protoc-gen-gogo. DO NOT EDIT.
2 | // source: nillion/meta/v1/tx.proto
3 |
4 | package types
5 |
6 | import (
7 | context "context"
8 | fmt "fmt"
9 | _ "github.com/cosmos/cosmos-proto"
10 | github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
11 | types "github.com/cosmos/cosmos-sdk/types"
12 | _ "github.com/cosmos/cosmos-sdk/types/msgservice"
13 | _ "github.com/cosmos/cosmos-sdk/types/tx/amino"
14 | _ "github.com/cosmos/cosmos-sdk/x/bank/types"
15 | _ "github.com/cosmos/gogoproto/gogoproto"
16 | grpc1 "github.com/cosmos/gogoproto/grpc"
17 | proto "github.com/cosmos/gogoproto/proto"
18 | grpc "google.golang.org/grpc"
19 | codes "google.golang.org/grpc/codes"
20 | status "google.golang.org/grpc/status"
21 | io "io"
22 | math "math"
23 | math_bits "math/bits"
24 | )
25 |
26 | // Reference imports to suppress errors if they are not otherwise used.
27 | var _ = proto.Marshal
28 | var _ = fmt.Errorf
29 | var _ = math.Inf
30 |
31 | // This is a compile-time assertion to ensure that this generated file
32 | // is compatible with the proto package it is being compiled against.
33 | // A compilation error at this line likely means your copy of the
34 | // proto package needs to be updated.
35 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
36 |
37 | // MsgPayFor defines the Msg/PayFor request type.
38 | type MsgPayFor struct {
39 | Resource []byte `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"`
40 | FromAddress string `protobuf:"bytes,2,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"`
41 | Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"`
42 | }
43 |
44 | func (m *MsgPayFor) Reset() { *m = MsgPayFor{} }
45 | func (m *MsgPayFor) String() string { return proto.CompactTextString(m) }
46 | func (*MsgPayFor) ProtoMessage() {}
47 | func (*MsgPayFor) Descriptor() ([]byte, []int) {
48 | return fileDescriptor_b5c2b216208307c1, []int{0}
49 | }
50 | func (m *MsgPayFor) XXX_Unmarshal(b []byte) error {
51 | return m.Unmarshal(b)
52 | }
53 | func (m *MsgPayFor) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
54 | if deterministic {
55 | return xxx_messageInfo_MsgPayFor.Marshal(b, m, deterministic)
56 | } else {
57 | b = b[:cap(b)]
58 | n, err := m.MarshalToSizedBuffer(b)
59 | if err != nil {
60 | return nil, err
61 | }
62 | return b[:n], nil
63 | }
64 | }
65 | func (m *MsgPayFor) XXX_Merge(src proto.Message) {
66 | xxx_messageInfo_MsgPayFor.Merge(m, src)
67 | }
68 | func (m *MsgPayFor) XXX_Size() int {
69 | return m.Size()
70 | }
71 | func (m *MsgPayFor) XXX_DiscardUnknown() {
72 | xxx_messageInfo_MsgPayFor.DiscardUnknown(m)
73 | }
74 |
75 | var xxx_messageInfo_MsgPayFor proto.InternalMessageInfo
76 |
77 | func (m *MsgPayFor) GetResource() []byte {
78 | if m != nil {
79 | return m.Resource
80 | }
81 | return nil
82 | }
83 |
84 | func (m *MsgPayFor) GetFromAddress() string {
85 | if m != nil {
86 | return m.FromAddress
87 | }
88 | return ""
89 | }
90 |
91 | func (m *MsgPayFor) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins {
92 | if m != nil {
93 | return m.Amount
94 | }
95 | return nil
96 | }
97 |
98 | // MsgPayForResponse defines the Msg/PayFor response type.
99 | type MsgPayForResponse struct {
100 | }
101 |
102 | func (m *MsgPayForResponse) Reset() { *m = MsgPayForResponse{} }
103 | func (m *MsgPayForResponse) String() string { return proto.CompactTextString(m) }
104 | func (*MsgPayForResponse) ProtoMessage() {}
105 | func (*MsgPayForResponse) Descriptor() ([]byte, []int) {
106 | return fileDescriptor_b5c2b216208307c1, []int{1}
107 | }
108 | func (m *MsgPayForResponse) XXX_Unmarshal(b []byte) error {
109 | return m.Unmarshal(b)
110 | }
111 | func (m *MsgPayForResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
112 | if deterministic {
113 | return xxx_messageInfo_MsgPayForResponse.Marshal(b, m, deterministic)
114 | } else {
115 | b = b[:cap(b)]
116 | n, err := m.MarshalToSizedBuffer(b)
117 | if err != nil {
118 | return nil, err
119 | }
120 | return b[:n], nil
121 | }
122 | }
123 | func (m *MsgPayForResponse) XXX_Merge(src proto.Message) {
124 | xxx_messageInfo_MsgPayForResponse.Merge(m, src)
125 | }
126 | func (m *MsgPayForResponse) XXX_Size() int {
127 | return m.Size()
128 | }
129 | func (m *MsgPayForResponse) XXX_DiscardUnknown() {
130 | xxx_messageInfo_MsgPayForResponse.DiscardUnknown(m)
131 | }
132 |
133 | var xxx_messageInfo_MsgPayForResponse proto.InternalMessageInfo
134 |
135 | func init() {
136 | proto.RegisterType((*MsgPayFor)(nil), "nillion.meta.v1.MsgPayFor")
137 | proto.RegisterType((*MsgPayForResponse)(nil), "nillion.meta.v1.MsgPayForResponse")
138 | }
139 |
140 | func init() { proto.RegisterFile("nillion/meta/v1/tx.proto", fileDescriptor_b5c2b216208307c1) }
141 |
142 | var fileDescriptor_b5c2b216208307c1 = []byte{
143 | // 426 bytes of a gzipped FileDescriptorProto
144 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x31, 0x6f, 0x13, 0x31,
145 | 0x14, 0xc7, 0x73, 0x44, 0x44, 0xf4, 0x1a, 0x09, 0xe5, 0xa8, 0xc4, 0xf5, 0x86, 0x6b, 0x94, 0x29,
146 | 0xaa, 0x14, 0x5b, 0x29, 0x4c, 0x30, 0x11, 0xa4, 0x8a, 0xa5, 0x11, 0x0a, 0x12, 0x03, 0x4b, 0xe4,
147 | 0x5c, 0x8c, 0x6b, 0x25, 0xf6, 0x8b, 0xfc, 0x9c, 0xd0, 0x6c, 0x88, 0x4f, 0xc0, 0xcc, 0x27, 0x40,
148 | 0x4c, 0x1d, 0xf8, 0x10, 0x1d, 0x2b, 0x26, 0x26, 0x40, 0xc9, 0xd0, 0x9d, 0x4f, 0x80, 0x7c, 0x76,
149 | 0x4f, 0x11, 0x88, 0xe5, 0xee, 0x9e, 0x7f, 0xfe, 0xff, 0xfd, 0xfe, 0x7e, 0x17, 0xa7, 0x5a, 0xce,
150 | 0xe7, 0x12, 0x34, 0x55, 0xdc, 0x32, 0xba, 0xea, 0x53, 0x7b, 0x41, 0x16, 0x06, 0x2c, 0x24, 0xf7,
151 | 0x03, 0x21, 0x8e, 0x90, 0x55, 0x3f, 0x3b, 0x10, 0x20, 0xa0, 0x64, 0xd4, 0x7d, 0xf9, 0x6d, 0x59,
152 | 0x5e, 0x00, 0x2a, 0x40, 0x3a, 0x61, 0xc8, 0xe9, 0xaa, 0x3f, 0xe1, 0x96, 0xf5, 0x69, 0x01, 0x52,
153 | 0xff, 0xc3, 0xf5, 0xac, 0xe2, 0xae, 0x08, 0xfc, 0xd0, 0xf3, 0xb1, 0x37, 0xf6, 0x45, 0x40, 0x0f,
154 | 0x83, 0x54, 0xa1, 0x70, 0x9d, 0x29, 0x14, 0x01, 0xb4, 0x98, 0x92, 0x1a, 0x68, 0xf9, 0xf4, 0x4b,
155 | 0x9d, 0xdf, 0x51, 0xbc, 0x77, 0x86, 0xe2, 0x25, 0x5b, 0x9f, 0x82, 0x49, 0xb2, 0xf8, 0x9e, 0xe1,
156 | 0x08, 0x4b, 0x53, 0xf0, 0x34, 0x6a, 0x47, 0xdd, 0xe6, 0xa8, 0xaa, 0x93, 0xa7, 0x71, 0xf3, 0xad,
157 | 0x01, 0x35, 0x66, 0xd3, 0xa9, 0xe1, 0x88, 0xe9, 0x9d, 0x76, 0xd4, 0xdd, 0x1b, 0xa4, 0xdf, 0xbe,
158 | 0xf6, 0x0e, 0xc2, 0xe9, 0xcf, 0x3c, 0x79, 0x65, 0x8d, 0xd4, 0x62, 0xb4, 0xef, 0x76, 0x87, 0xa5,
159 | 0x64, 0x1d, 0x37, 0x98, 0x82, 0xa5, 0xb6, 0x69, 0xbd, 0x5d, 0xef, 0xee, 0x9f, 0x1c, 0x92, 0xa0,
160 | 0x71, 0xf1, 0x49, 0x88, 0x47, 0x9e, 0x83, 0xd4, 0x83, 0xd3, 0xab, 0x1f, 0x47, 0xb5, 0x2f, 0x3f,
161 | 0x8f, 0xba, 0x42, 0xda, 0xf3, 0xe5, 0x84, 0x14, 0xa0, 0x42, 0xbc, 0xf0, 0xea, 0xe1, 0x74, 0x46,
162 | 0xed, 0x7a, 0xc1, 0xb1, 0x14, 0xe0, 0xa7, 0x9b, 0xcb, 0xe3, 0xe6, 0x9c, 0x0b, 0x56, 0xac, 0xc7,
163 | 0xee, 0x02, 0xf1, 0xf3, 0xcd, 0xe5, 0x71, 0x34, 0x0a, 0x07, 0x3e, 0x69, 0x7d, 0x70, 0x7c, 0xb7,
164 | 0xf5, 0xce, 0x83, 0xb8, 0x55, 0x65, 0x1e, 0x71, 0x5c, 0x80, 0x46, 0x7e, 0xf2, 0x3a, 0xae, 0x9f,
165 | 0xa1, 0x48, 0x5e, 0xc4, 0x8d, 0xdb, 0xcb, 0x20, 0x7f, 0x4d, 0x92, 0x54, 0xa2, 0xac, 0xf3, 0x7f,
166 | 0x76, 0x6b, 0x98, 0xdd, 0x7d, 0xef, 0xfa, 0x18, 0x0c, 0xaf, 0x36, 0x79, 0x74, 0xbd, 0xc9, 0xa3,
167 | 0x5f, 0x9b, 0x3c, 0xfa, 0xb8, 0xcd, 0x6b, 0xd7, 0xdb, 0xbc, 0xf6, 0x7d, 0x9b, 0xd7, 0xde, 0x3c,
168 | 0xde, 0x49, 0x38, 0xf4, 0x76, 0x43, 0x6e, 0xdf, 0x81, 0x99, 0xd1, 0xe0, 0xde, 0x2b, 0xce, 0x99,
169 | 0xd4, 0xf4, 0xc2, 0xff, 0x65, 0x65, 0xe6, 0x49, 0xa3, 0x1c, 0xdc, 0xa3, 0x3f, 0x01, 0x00, 0x00,
170 | 0xff, 0xff, 0xfc, 0x39, 0x6e, 0xbc, 0x82, 0x02, 0x00, 0x00,
171 | }
172 |
173 | // Reference imports to suppress errors if they are not otherwise used.
174 | var _ context.Context
175 | var _ grpc.ClientConn
176 |
177 | // This is a compile-time assertion to ensure that this generated file
178 | // is compatible with the grpc package it is being compiled against.
179 | const _ = grpc.SupportPackageIsVersion4
180 |
181 | // MsgClient is the client API for Msg service.
182 | //
183 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
184 | type MsgClient interface {
185 | // PayFor pays for a resource in the PET neteotk
186 | PayFor(ctx context.Context, in *MsgPayFor, opts ...grpc.CallOption) (*MsgPayForResponse, error)
187 | }
188 |
189 | type msgClient struct {
190 | cc grpc1.ClientConn
191 | }
192 |
193 | func NewMsgClient(cc grpc1.ClientConn) MsgClient {
194 | return &msgClient{cc}
195 | }
196 |
197 | func (c *msgClient) PayFor(ctx context.Context, in *MsgPayFor, opts ...grpc.CallOption) (*MsgPayForResponse, error) {
198 | out := new(MsgPayForResponse)
199 | err := c.cc.Invoke(ctx, "/nillion.meta.v1.Msg/PayFor", in, out, opts...)
200 | if err != nil {
201 | return nil, err
202 | }
203 | return out, nil
204 | }
205 |
206 | // MsgServer is the server API for Msg service.
207 | type MsgServer interface {
208 | // PayFor pays for a resource in the PET neteotk
209 | PayFor(context.Context, *MsgPayFor) (*MsgPayForResponse, error)
210 | }
211 |
212 | // UnimplementedMsgServer can be embedded to have forward compatible implementations.
213 | type UnimplementedMsgServer struct {
214 | }
215 |
216 | func (*UnimplementedMsgServer) PayFor(ctx context.Context, req *MsgPayFor) (*MsgPayForResponse, error) {
217 | return nil, status.Errorf(codes.Unimplemented, "method PayFor not implemented")
218 | }
219 |
220 | func RegisterMsgServer(s grpc1.Server, srv MsgServer) {
221 | s.RegisterService(&_Msg_serviceDesc, srv)
222 | }
223 |
224 | func _Msg_PayFor_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
225 | in := new(MsgPayFor)
226 | if err := dec(in); err != nil {
227 | return nil, err
228 | }
229 | if interceptor == nil {
230 | return srv.(MsgServer).PayFor(ctx, in)
231 | }
232 | info := &grpc.UnaryServerInfo{
233 | Server: srv,
234 | FullMethod: "/nillion.meta.v1.Msg/PayFor",
235 | }
236 | handler := func(ctx context.Context, req interface{}) (interface{}, error) {
237 | return srv.(MsgServer).PayFor(ctx, req.(*MsgPayFor))
238 | }
239 | return interceptor(ctx, in, info, handler)
240 | }
241 |
242 | var _Msg_serviceDesc = grpc.ServiceDesc{
243 | ServiceName: "nillion.meta.v1.Msg",
244 | HandlerType: (*MsgServer)(nil),
245 | Methods: []grpc.MethodDesc{
246 | {
247 | MethodName: "PayFor",
248 | Handler: _Msg_PayFor_Handler,
249 | },
250 | },
251 | Streams: []grpc.StreamDesc{},
252 | Metadata: "nillion/meta/v1/tx.proto",
253 | }
254 |
255 | func (m *MsgPayFor) Marshal() (dAtA []byte, err error) {
256 | size := m.Size()
257 | dAtA = make([]byte, size)
258 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
259 | if err != nil {
260 | return nil, err
261 | }
262 | return dAtA[:n], nil
263 | }
264 |
265 | func (m *MsgPayFor) MarshalTo(dAtA []byte) (int, error) {
266 | size := m.Size()
267 | return m.MarshalToSizedBuffer(dAtA[:size])
268 | }
269 |
270 | func (m *MsgPayFor) MarshalToSizedBuffer(dAtA []byte) (int, error) {
271 | i := len(dAtA)
272 | _ = i
273 | var l int
274 | _ = l
275 | if len(m.Amount) > 0 {
276 | for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- {
277 | {
278 | size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i])
279 | if err != nil {
280 | return 0, err
281 | }
282 | i -= size
283 | i = encodeVarintTx(dAtA, i, uint64(size))
284 | }
285 | i--
286 | dAtA[i] = 0x1a
287 | }
288 | }
289 | if len(m.FromAddress) > 0 {
290 | i -= len(m.FromAddress)
291 | copy(dAtA[i:], m.FromAddress)
292 | i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress)))
293 | i--
294 | dAtA[i] = 0x12
295 | }
296 | if len(m.Resource) > 0 {
297 | i -= len(m.Resource)
298 | copy(dAtA[i:], m.Resource)
299 | i = encodeVarintTx(dAtA, i, uint64(len(m.Resource)))
300 | i--
301 | dAtA[i] = 0xa
302 | }
303 | return len(dAtA) - i, nil
304 | }
305 |
306 | func (m *MsgPayForResponse) Marshal() (dAtA []byte, err error) {
307 | size := m.Size()
308 | dAtA = make([]byte, size)
309 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
310 | if err != nil {
311 | return nil, err
312 | }
313 | return dAtA[:n], nil
314 | }
315 |
316 | func (m *MsgPayForResponse) MarshalTo(dAtA []byte) (int, error) {
317 | size := m.Size()
318 | return m.MarshalToSizedBuffer(dAtA[:size])
319 | }
320 |
321 | func (m *MsgPayForResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
322 | i := len(dAtA)
323 | _ = i
324 | var l int
325 | _ = l
326 | return len(dAtA) - i, nil
327 | }
328 |
329 | func encodeVarintTx(dAtA []byte, offset int, v uint64) int {
330 | offset -= sovTx(v)
331 | base := offset
332 | for v >= 1<<7 {
333 | dAtA[offset] = uint8(v&0x7f | 0x80)
334 | v >>= 7
335 | offset++
336 | }
337 | dAtA[offset] = uint8(v)
338 | return base
339 | }
340 | func (m *MsgPayFor) Size() (n int) {
341 | if m == nil {
342 | return 0
343 | }
344 | var l int
345 | _ = l
346 | l = len(m.Resource)
347 | if l > 0 {
348 | n += 1 + l + sovTx(uint64(l))
349 | }
350 | l = len(m.FromAddress)
351 | if l > 0 {
352 | n += 1 + l + sovTx(uint64(l))
353 | }
354 | if len(m.Amount) > 0 {
355 | for _, e := range m.Amount {
356 | l = e.Size()
357 | n += 1 + l + sovTx(uint64(l))
358 | }
359 | }
360 | return n
361 | }
362 |
363 | func (m *MsgPayForResponse) Size() (n int) {
364 | if m == nil {
365 | return 0
366 | }
367 | var l int
368 | _ = l
369 | return n
370 | }
371 |
372 | func sovTx(x uint64) (n int) {
373 | return (math_bits.Len64(x|1) + 6) / 7
374 | }
375 | func sozTx(x uint64) (n int) {
376 | return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63))))
377 | }
378 | func (m *MsgPayFor) Unmarshal(dAtA []byte) error {
379 | l := len(dAtA)
380 | iNdEx := 0
381 | for iNdEx < l {
382 | preIndex := iNdEx
383 | var wire uint64
384 | for shift := uint(0); ; shift += 7 {
385 | if shift >= 64 {
386 | return ErrIntOverflowTx
387 | }
388 | if iNdEx >= l {
389 | return io.ErrUnexpectedEOF
390 | }
391 | b := dAtA[iNdEx]
392 | iNdEx++
393 | wire |= uint64(b&0x7F) << shift
394 | if b < 0x80 {
395 | break
396 | }
397 | }
398 | fieldNum := int32(wire >> 3)
399 | wireType := int(wire & 0x7)
400 | if wireType == 4 {
401 | return fmt.Errorf("proto: MsgPayFor: wiretype end group for non-group")
402 | }
403 | if fieldNum <= 0 {
404 | return fmt.Errorf("proto: MsgPayFor: illegal tag %d (wire type %d)", fieldNum, wire)
405 | }
406 | switch fieldNum {
407 | case 1:
408 | if wireType != 2 {
409 | return fmt.Errorf("proto: wrong wireType = %d for field Resource", wireType)
410 | }
411 | var byteLen int
412 | for shift := uint(0); ; shift += 7 {
413 | if shift >= 64 {
414 | return ErrIntOverflowTx
415 | }
416 | if iNdEx >= l {
417 | return io.ErrUnexpectedEOF
418 | }
419 | b := dAtA[iNdEx]
420 | iNdEx++
421 | byteLen |= int(b&0x7F) << shift
422 | if b < 0x80 {
423 | break
424 | }
425 | }
426 | if byteLen < 0 {
427 | return ErrInvalidLengthTx
428 | }
429 | postIndex := iNdEx + byteLen
430 | if postIndex < 0 {
431 | return ErrInvalidLengthTx
432 | }
433 | if postIndex > l {
434 | return io.ErrUnexpectedEOF
435 | }
436 | m.Resource = append(m.Resource[:0], dAtA[iNdEx:postIndex]...)
437 | if m.Resource == nil {
438 | m.Resource = []byte{}
439 | }
440 | iNdEx = postIndex
441 | case 2:
442 | if wireType != 2 {
443 | return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType)
444 | }
445 | var stringLen uint64
446 | for shift := uint(0); ; shift += 7 {
447 | if shift >= 64 {
448 | return ErrIntOverflowTx
449 | }
450 | if iNdEx >= l {
451 | return io.ErrUnexpectedEOF
452 | }
453 | b := dAtA[iNdEx]
454 | iNdEx++
455 | stringLen |= uint64(b&0x7F) << shift
456 | if b < 0x80 {
457 | break
458 | }
459 | }
460 | intStringLen := int(stringLen)
461 | if intStringLen < 0 {
462 | return ErrInvalidLengthTx
463 | }
464 | postIndex := iNdEx + intStringLen
465 | if postIndex < 0 {
466 | return ErrInvalidLengthTx
467 | }
468 | if postIndex > l {
469 | return io.ErrUnexpectedEOF
470 | }
471 | m.FromAddress = string(dAtA[iNdEx:postIndex])
472 | iNdEx = postIndex
473 | case 3:
474 | if wireType != 2 {
475 | return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType)
476 | }
477 | var msglen int
478 | for shift := uint(0); ; shift += 7 {
479 | if shift >= 64 {
480 | return ErrIntOverflowTx
481 | }
482 | if iNdEx >= l {
483 | return io.ErrUnexpectedEOF
484 | }
485 | b := dAtA[iNdEx]
486 | iNdEx++
487 | msglen |= int(b&0x7F) << shift
488 | if b < 0x80 {
489 | break
490 | }
491 | }
492 | if msglen < 0 {
493 | return ErrInvalidLengthTx
494 | }
495 | postIndex := iNdEx + msglen
496 | if postIndex < 0 {
497 | return ErrInvalidLengthTx
498 | }
499 | if postIndex > l {
500 | return io.ErrUnexpectedEOF
501 | }
502 | m.Amount = append(m.Amount, types.Coin{})
503 | if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
504 | return err
505 | }
506 | iNdEx = postIndex
507 | default:
508 | iNdEx = preIndex
509 | skippy, err := skipTx(dAtA[iNdEx:])
510 | if err != nil {
511 | return err
512 | }
513 | if (skippy < 0) || (iNdEx+skippy) < 0 {
514 | return ErrInvalidLengthTx
515 | }
516 | if (iNdEx + skippy) > l {
517 | return io.ErrUnexpectedEOF
518 | }
519 | iNdEx += skippy
520 | }
521 | }
522 |
523 | if iNdEx > l {
524 | return io.ErrUnexpectedEOF
525 | }
526 | return nil
527 | }
528 | func (m *MsgPayForResponse) Unmarshal(dAtA []byte) error {
529 | l := len(dAtA)
530 | iNdEx := 0
531 | for iNdEx < l {
532 | preIndex := iNdEx
533 | var wire uint64
534 | for shift := uint(0); ; shift += 7 {
535 | if shift >= 64 {
536 | return ErrIntOverflowTx
537 | }
538 | if iNdEx >= l {
539 | return io.ErrUnexpectedEOF
540 | }
541 | b := dAtA[iNdEx]
542 | iNdEx++
543 | wire |= uint64(b&0x7F) << shift
544 | if b < 0x80 {
545 | break
546 | }
547 | }
548 | fieldNum := int32(wire >> 3)
549 | wireType := int(wire & 0x7)
550 | if wireType == 4 {
551 | return fmt.Errorf("proto: MsgPayForResponse: wiretype end group for non-group")
552 | }
553 | if fieldNum <= 0 {
554 | return fmt.Errorf("proto: MsgPayForResponse: illegal tag %d (wire type %d)", fieldNum, wire)
555 | }
556 | switch fieldNum {
557 | default:
558 | iNdEx = preIndex
559 | skippy, err := skipTx(dAtA[iNdEx:])
560 | if err != nil {
561 | return err
562 | }
563 | if (skippy < 0) || (iNdEx+skippy) < 0 {
564 | return ErrInvalidLengthTx
565 | }
566 | if (iNdEx + skippy) > l {
567 | return io.ErrUnexpectedEOF
568 | }
569 | iNdEx += skippy
570 | }
571 | }
572 |
573 | if iNdEx > l {
574 | return io.ErrUnexpectedEOF
575 | }
576 | return nil
577 | }
578 | func skipTx(dAtA []byte) (n int, err error) {
579 | l := len(dAtA)
580 | iNdEx := 0
581 | depth := 0
582 | for iNdEx < l {
583 | var wire uint64
584 | for shift := uint(0); ; shift += 7 {
585 | if shift >= 64 {
586 | return 0, ErrIntOverflowTx
587 | }
588 | if iNdEx >= l {
589 | return 0, io.ErrUnexpectedEOF
590 | }
591 | b := dAtA[iNdEx]
592 | iNdEx++
593 | wire |= (uint64(b) & 0x7F) << shift
594 | if b < 0x80 {
595 | break
596 | }
597 | }
598 | wireType := int(wire & 0x7)
599 | switch wireType {
600 | case 0:
601 | for shift := uint(0); ; shift += 7 {
602 | if shift >= 64 {
603 | return 0, ErrIntOverflowTx
604 | }
605 | if iNdEx >= l {
606 | return 0, io.ErrUnexpectedEOF
607 | }
608 | iNdEx++
609 | if dAtA[iNdEx-1] < 0x80 {
610 | break
611 | }
612 | }
613 | case 1:
614 | iNdEx += 8
615 | case 2:
616 | var length int
617 | for shift := uint(0); ; shift += 7 {
618 | if shift >= 64 {
619 | return 0, ErrIntOverflowTx
620 | }
621 | if iNdEx >= l {
622 | return 0, io.ErrUnexpectedEOF
623 | }
624 | b := dAtA[iNdEx]
625 | iNdEx++
626 | length |= (int(b) & 0x7F) << shift
627 | if b < 0x80 {
628 | break
629 | }
630 | }
631 | if length < 0 {
632 | return 0, ErrInvalidLengthTx
633 | }
634 | iNdEx += length
635 | case 3:
636 | depth++
637 | case 4:
638 | if depth == 0 {
639 | return 0, ErrUnexpectedEndOfGroupTx
640 | }
641 | depth--
642 | case 5:
643 | iNdEx += 4
644 | default:
645 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
646 | }
647 | if iNdEx < 0 {
648 | return 0, ErrInvalidLengthTx
649 | }
650 | if depth == 0 {
651 | return iNdEx, nil
652 | }
653 | }
654 | return 0, io.ErrUnexpectedEOF
655 | }
656 |
657 | var (
658 | ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling")
659 | ErrIntOverflowTx = fmt.Errorf("proto: integer overflow")
660 | ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group")
661 | )
662 |
--------------------------------------------------------------------------------
/app/app.go:
--------------------------------------------------------------------------------
1 | package nillionapp
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "io"
7 | "os"
8 | "path/filepath"
9 |
10 | "github.com/NillionNetwork/nilchain/x/meta"
11 | "github.com/NillionNetwork/nilchain/x/meta/keeper"
12 | metatypes "github.com/NillionNetwork/nilchain/x/meta/types"
13 |
14 | dbm "github.com/cosmos/cosmos-db"
15 | "github.com/cosmos/gogoproto/proto"
16 | "github.com/spf13/cast"
17 |
18 | autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
19 | reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
20 | "cosmossdk.io/client/v2/autocli"
21 | "cosmossdk.io/core/appmodule"
22 | "cosmossdk.io/log"
23 | storetypes "cosmossdk.io/store/types"
24 | "cosmossdk.io/x/circuit"
25 | circuitkeeper "cosmossdk.io/x/circuit/keeper"
26 | circuittypes "cosmossdk.io/x/circuit/types"
27 | "cosmossdk.io/x/evidence"
28 | evidencekeeper "cosmossdk.io/x/evidence/keeper"
29 | evidencetypes "cosmossdk.io/x/evidence/types"
30 | "cosmossdk.io/x/feegrant"
31 | feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
32 | feegrantmodule "cosmossdk.io/x/feegrant/module"
33 | "cosmossdk.io/x/tx/signing"
34 | "cosmossdk.io/x/upgrade"
35 | upgradekeeper "cosmossdk.io/x/upgrade/keeper"
36 | upgradetypes "cosmossdk.io/x/upgrade/types"
37 | sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
38 | txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
39 |
40 | "github.com/cosmos/cosmos-sdk/baseapp"
41 | "github.com/cosmos/cosmos-sdk/client"
42 | "github.com/cosmos/cosmos-sdk/client/flags"
43 | "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
44 | nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
45 | "github.com/cosmos/cosmos-sdk/codec"
46 | "github.com/cosmos/cosmos-sdk/codec/address"
47 | "github.com/cosmos/cosmos-sdk/codec/types"
48 | "github.com/cosmos/cosmos-sdk/runtime"
49 | runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
50 | "github.com/cosmos/cosmos-sdk/server"
51 | "github.com/cosmos/cosmos-sdk/server/api"
52 | "github.com/cosmos/cosmos-sdk/server/config"
53 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
54 | "github.com/cosmos/cosmos-sdk/std"
55 | "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb"
56 | sdk "github.com/cosmos/cosmos-sdk/types"
57 | "github.com/cosmos/cosmos-sdk/types/module"
58 | "github.com/cosmos/cosmos-sdk/types/msgservice"
59 | "github.com/cosmos/cosmos-sdk/version"
60 | "github.com/cosmos/cosmos-sdk/x/auth"
61 | "github.com/cosmos/cosmos-sdk/x/auth/ante"
62 | authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
63 | authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
64 | "github.com/cosmos/cosmos-sdk/x/auth/posthandler"
65 | authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
66 | authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
67 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
68 | "github.com/cosmos/cosmos-sdk/x/auth/vesting"
69 | vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
70 | "github.com/cosmos/cosmos-sdk/x/authz"
71 | authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
72 | authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
73 | "github.com/cosmos/cosmos-sdk/x/bank"
74 | bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
75 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
76 | consensus "github.com/cosmos/cosmos-sdk/x/consensus"
77 | consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
78 | consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
79 | distr "github.com/cosmos/cosmos-sdk/x/distribution"
80 | distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
81 | distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
82 | "github.com/cosmos/cosmos-sdk/x/genutil"
83 | genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
84 | "github.com/cosmos/cosmos-sdk/x/gov"
85 | govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
86 | govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
87 | govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
88 | govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
89 | "github.com/cosmos/cosmos-sdk/x/group"
90 | "github.com/cosmos/cosmos-sdk/x/mint"
91 | mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
92 | minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
93 | "github.com/cosmos/cosmos-sdk/x/params"
94 | paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
95 | paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
96 | paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
97 | paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
98 | "github.com/cosmos/cosmos-sdk/x/slashing"
99 | slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
100 | slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
101 | "github.com/cosmos/cosmos-sdk/x/staking"
102 | stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
103 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
104 |
105 | abci "github.com/cometbft/cometbft/abci/types"
106 |
107 | "github.com/cosmos/ibc-go/modules/capability"
108 | capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
109 | capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
110 | ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
111 | icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
112 | icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
113 | icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
114 | icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
115 | icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
116 | ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee"
117 | ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
118 | ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
119 | transfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
120 | ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
121 | ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
122 | ibc "github.com/cosmos/ibc-go/v8/modules/core"
123 | ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
124 | ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
125 | ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
126 | porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
127 | ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
128 | ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
129 | ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
130 | ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"
131 | )
132 |
133 | const appName = "NillionApp"
134 |
135 | var (
136 | // DefaultNodeHome default home directories for the application daemon
137 | DefaultNodeHome string
138 |
139 | // module account permissions
140 | maccPerms = map[string][]string{
141 | authtypes.FeeCollectorName: nil,
142 | distrtypes.ModuleName: nil,
143 | minttypes.ModuleName: {authtypes.Minter},
144 | stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
145 | stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
146 | govtypes.ModuleName: {authtypes.Burner},
147 | ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
148 | ibcfeetypes.ModuleName: nil,
149 | icatypes.ModuleName: nil,
150 | metatypes.ModuleName: {authtypes.Burner},
151 | }
152 | )
153 |
154 | var (
155 | _ runtime.AppI = (*NillionApp)(nil)
156 | _ servertypes.Application = (*NillionApp)(nil)
157 | )
158 |
159 | // NillionApp extends an ABCI application, but with most of its parameters exported.
160 | // They are exported for convenience in creating helper functions, as object
161 | // capabilities aren't needed for testing.
162 | type NillionApp struct {
163 | *baseapp.BaseApp
164 | legacyAmino *codec.LegacyAmino
165 | appCodec codec.Codec
166 | txConfig client.TxConfig
167 | interfaceRegistry types.InterfaceRegistry
168 |
169 | // keys to access the substores
170 | keys map[string]*storetypes.KVStoreKey
171 | tkeys map[string]*storetypes.TransientStoreKey
172 | memKeys map[string]*storetypes.MemoryStoreKey
173 |
174 | // keepers
175 | AccountKeeper authkeeper.AccountKeeper
176 | BankKeeper bankkeeper.Keeper
177 | CapabilityKeeper *capabilitykeeper.Keeper
178 | StakingKeeper *stakingkeeper.Keeper
179 | SlashingKeeper slashingkeeper.Keeper
180 | MintKeeper mintkeeper.Keeper
181 | DistrKeeper distrkeeper.Keeper
182 | GovKeeper govkeeper.Keeper
183 | UpgradeKeeper *upgradekeeper.Keeper
184 | ParamsKeeper paramskeeper.Keeper
185 | AuthzKeeper authzkeeper.Keeper
186 | IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
187 | IBCFeeKeeper ibcfeekeeper.Keeper
188 | ICAControllerKeeper icacontrollerkeeper.Keeper
189 | EvidenceKeeper evidencekeeper.Keeper
190 | TransferKeeper ibctransferkeeper.Keeper
191 | FeeGrantKeeper feegrantkeeper.Keeper
192 | ConsensusParamsKeeper consensusparamkeeper.Keeper
193 | CircuitKeeper circuitkeeper.Keeper
194 | MetaKeeper keeper.Keeper
195 |
196 | // the module manager
197 | ModuleManager *module.Manager
198 | BasicModuleManager module.BasicManager
199 |
200 | // simulation manager
201 | simulationManager *module.SimulationManager
202 |
203 | // module configurator
204 | configurator module.Configurator
205 | }
206 |
207 | func init() {
208 | userHomeDir, err := os.UserHomeDir()
209 | if err != nil {
210 | panic(err)
211 | }
212 |
213 | DefaultNodeHome = filepath.Join(userHomeDir, ".nillionapp")
214 | }
215 |
216 | // NewNillionApp returns a reference to an initialized NillionApp.
217 | func NewNillionApp(
218 | logger log.Logger,
219 | db dbm.DB,
220 | traceStore io.Writer,
221 | loadLatest bool,
222 | appOpts servertypes.AppOptions,
223 | baseAppOptions ...func(*baseapp.BaseApp),
224 | ) *NillionApp {
225 | interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
226 | ProtoFiles: proto.HybridResolver,
227 | SigningOptions: signing.Options{
228 | AddressCodec: address.Bech32Codec{
229 | Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
230 | },
231 | ValidatorAddressCodec: address.Bech32Codec{
232 | Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
233 | },
234 | },
235 | })
236 | appCodec := codec.NewProtoCodec(interfaceRegistry)
237 | legacyAmino := codec.NewLegacyAmino()
238 | txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes)
239 |
240 | std.RegisterLegacyAminoCodec(legacyAmino)
241 | std.RegisterInterfaces(interfaceRegistry)
242 |
243 | // Below we could construct and set an application-specific mempool and
244 | // ABCI 1.0 PrepareProposal and ProcessProposal handlers. These defaults are
245 | // already set in the SDK's BaseApp, this shows an example of how to override
246 | // them.
247 | //
248 | // Example:
249 | //
250 | // bApp := baseapp.NewBaseApp(...)
251 | // nonceMempool := mempool.NewSenderNonceMempool()
252 | // abciPropHandler := NewDefaultProposalHandler(nonceMempool, bApp)
253 | //
254 | // bApp.SetMempool(nonceMempool)
255 | // bApp.SetPrepareProposal(abciPropHandler.PrepareProposalHandler())
256 | // bApp.SetProcessProposal(abciPropHandler.ProcessProposalHandler())
257 | //
258 | // Alternatively, you can construct BaseApp options, append those to
259 | // baseAppOptions and pass them to NewBaseApp.
260 | //
261 | // Example:
262 | //
263 | // prepareOpt = func(app *baseapp.BaseApp) {
264 | // abciPropHandler := baseapp.NewDefaultProposalHandler(nonceMempool, app)
265 | // app.SetPrepareProposal(abciPropHandler.PrepareProposalHandler())
266 | // }
267 | // baseAppOptions = append(baseAppOptions, prepareOpt)
268 |
269 | bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
270 | bApp.SetCommitMultiStoreTracer(traceStore)
271 | bApp.SetVersion(version.Version)
272 | bApp.SetInterfaceRegistry(interfaceRegistry)
273 | bApp.SetTxEncoder(txConfig.TxEncoder())
274 |
275 | keys := storetypes.NewKVStoreKeys(
276 | authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
277 | minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
278 | govtypes.StoreKey, group.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
279 | evidencetypes.StoreKey, ibctransfertypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey,
280 | authzkeeper.StoreKey, ibcfeetypes.StoreKey, consensusparamtypes.StoreKey, circuittypes.StoreKey, metatypes.StoreKey,
281 | )
282 |
283 | // register streaming services
284 | if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil {
285 | panic(err)
286 | }
287 |
288 | tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
289 | memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
290 |
291 | app := &NillionApp{
292 | BaseApp: bApp,
293 | legacyAmino: legacyAmino,
294 | appCodec: appCodec,
295 | txConfig: txConfig,
296 | interfaceRegistry: interfaceRegistry,
297 | keys: keys,
298 | tkeys: tkeys,
299 | memKeys: memKeys,
300 | }
301 |
302 | app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
303 |
304 | // set the BaseApp's parameter store
305 | app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{})
306 | bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)
307 |
308 | // add capability keeper and ScopeToModule for ibc module
309 | app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
310 |
311 | scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
312 | scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
313 | scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
314 |
315 | // seal capability keeper after scoping modules
316 | // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
317 | // their scoped modules in `NewApp` with `ScopeToModule`
318 | app.CapabilityKeeper.Seal()
319 |
320 | // SDK module keepers
321 |
322 | // add keepers
323 | app.AccountKeeper = authkeeper.NewAccountKeeper(
324 | appCodec,
325 | runtime.NewKVStoreService(keys[authtypes.StoreKey]),
326 | authtypes.ProtoBaseAccount,
327 | maccPerms,
328 | authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
329 | sdk.GetConfig().GetBech32AccountAddrPrefix(),
330 | authtypes.NewModuleAddress(govtypes.ModuleName).String(),
331 | )
332 |
333 | app.BankKeeper = bankkeeper.NewBaseKeeper(
334 | appCodec,
335 | runtime.NewKVStoreService(keys[banktypes.StoreKey]),
336 | app.AccountKeeper,
337 | BlockedAddresses(),
338 | authtypes.NewModuleAddress(govtypes.ModuleName).String(),
339 | logger,
340 | )
341 |
342 | // enable SignModeTextual
343 | enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
344 | txConfigOpts := authtx.ConfigOptions{
345 | EnabledSignModes: enabledSignModes,
346 | TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
347 | }
348 | txConfig, err := authtx.NewTxConfigWithOptions(
349 | appCodec,
350 | txConfigOpts,
351 | )
352 | if err != nil {
353 | panic(err)
354 | }
355 | app.txConfig = txConfig
356 |
357 | app.StakingKeeper = stakingkeeper.NewKeeper(
358 | appCodec,
359 | runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
360 | app.AccountKeeper,
361 | app.BankKeeper,
362 | authtypes.NewModuleAddress(govtypes.ModuleName).String(),
363 | authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
364 | authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
365 | )
366 |
367 | app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())
368 |
369 | app.DistrKeeper = distrkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())
370 |
371 | app.SlashingKeeper = slashingkeeper.NewKeeper(
372 | appCodec, legacyAmino, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
373 | )
374 |
375 | app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[feegrant.StoreKey]), app.AccountKeeper)
376 |
377 | // register the staking hooks
378 | // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
379 | app.StakingKeeper.SetHooks(
380 | stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
381 | )
382 |
383 | app.CircuitKeeper = circuitkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[circuittypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AccountKeeper.AddressCodec())
384 | app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper)
385 |
386 | app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AccountKeeper)
387 |
388 | // get skipUpgradeHeights from the app options
389 | skipUpgradeHeights := map[int64]bool{}
390 | for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
391 | skipUpgradeHeights[int64(h)] = true
392 | }
393 | homePath := cast.ToString(appOpts.Get(flags.FlagHome))
394 | // set the governance module account as the authority for conducting upgrades
395 | app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())
396 |
397 | // Upgrade the KVStoreKey after upgrade keeper initialization
398 | app.setupUpgradeStoreLoaders()
399 |
400 | app.IBCKeeper = ibckeeper.NewKeeper(
401 | appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
402 | )
403 | // Register the proposal types
404 | // Deprecated: Avoid adding new handlers, instead use the new proposal flow
405 | // by granting the governance module the right to execute the message.
406 | // See: https://docs.cosmos.network/main/modules/gov#proposal-messages
407 | govRouter := govv1beta1.NewRouter()
408 | govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
409 | AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
410 | AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
411 | govConfig := govtypes.DefaultConfig()
412 | /*
413 | Example of setting gov params:
414 | govConfig.MaxMetadataLen = 10000
415 | */
416 | govKeeper := govkeeper.NewKeeper(
417 | appCodec, runtime.NewKVStoreService(keys[govtypes.StoreKey]), app.AccountKeeper, app.BankKeeper,
418 | app.StakingKeeper, app.DistrKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
419 | )
420 |
421 | // Set legacy router for backwards compatibility with gov v1beta1
422 | govKeeper.SetLegacyRouter(govRouter)
423 |
424 | app.GovKeeper = *govKeeper.SetHooks(
425 | govtypes.NewMultiGovHooks(
426 | // register the governance hooks
427 | ),
428 | )
429 |
430 | // IBC Fee Module keeper
431 | app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
432 | appCodec, keys[ibcfeetypes.StoreKey],
433 | app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
434 | app.IBCKeeper.ChannelKeeper,
435 | app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper,
436 | )
437 |
438 | // ICA Controller keeper
439 | app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
440 | appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
441 | app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
442 | app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
443 | scopedICAControllerKeeper, app.MsgServiceRouter(),
444 | authtypes.NewModuleAddress(govtypes.ModuleName).String(),
445 | )
446 |
447 | // Create IBC Router
448 | ibcRouter := porttypes.NewRouter()
449 |
450 | // Middleware Stacks
451 |
452 | // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper
453 | // since fee middleware will wrap the IBCKeeper for underlying application.
454 | app.TransferKeeper = ibctransferkeeper.NewKeeper(
455 | appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
456 | app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
457 | app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
458 | app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
459 | authtypes.NewModuleAddress(govtypes.ModuleName).String(),
460 | )
461 |
462 | // Create Transfer Stack
463 | // SendPacket, since it is originating from the application to core IBC:
464 | // transferKeeper.SendPacket -> fee.SendPacket -> channel.SendPacket
465 |
466 | // RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way
467 | // channel.RecvPacket -> fee.OnRecvPacket -> transfer.OnRecvPacket
468 |
469 | // transfer stack contains (from top to bottom):
470 | // - IBC Fee Middleware
471 | // - Transfer
472 |
473 | // create IBC module from bottom to top of stack
474 | var transferStack porttypes.IBCModule
475 | transferStack = transfer.NewIBCModule(app.TransferKeeper)
476 | transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
477 |
478 | // Add transfer stack to IBC Router
479 | ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
480 |
481 | // Create Interchain Accounts Stack
482 | // SendPacket, since it is originating from the application to core IBC:
483 | // icaControllerKeeper.SendTx -> fee.SendPacket -> channel.SendPacket
484 |
485 | // initialize ICA module with mock module as the authentication module on the controller side
486 | var icaControllerStack porttypes.IBCModule
487 | icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper)
488 | icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
489 |
490 | // RecvPacket, message that originates from core IBC and goes down to app, the flow is:
491 | // channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
492 |
493 | // Add host, controller & ica auth modules to IBC router
494 | ibcRouter.
495 | // the ICA Controller middleware needs to be explicitly added to the IBC Router because the
496 | // ICA controller module owns the port capability for ICA. The ICA authentication module
497 | // owns the channel capability.
498 | AddRoute(icacontrollertypes.SubModuleName, icaControllerStack)
499 |
500 | // Create Mock IBC Fee module stack for testing
501 | // SendPacket, mock module cannot send packets
502 |
503 | // OnRecvPacket, message that originates from core IBC and goes down to app, the flow is the otherway
504 | // channel.RecvPacket -> fee.OnRecvPacket -> mockModule.OnRecvPacket
505 |
506 | // OnAcknowledgementPacket as this is where fee's are paid out
507 | // mockModule.OnAcknowledgementPacket -> fee.OnAcknowledgementPacket -> channel.OnAcknowledgementPacket
508 |
509 | // Seal the IBC Router
510 | app.IBCKeeper.SetRouter(ibcRouter)
511 |
512 | // create evidence keeper with router
513 | evidenceKeeper := evidencekeeper.NewKeeper(
514 | appCodec, runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), app.StakingKeeper, app.SlashingKeeper, app.AccountKeeper.AddressCodec(), runtime.ProvideCometInfoService(),
515 | )
516 | // If evidence needs to be handled for the app, set routes in router here and seal
517 | app.EvidenceKeeper = *evidenceKeeper
518 |
519 | app.MetaKeeper = keeper.NewKeeper(
520 | appCodec, runtime.NewKVStoreService(keys[metatypes.StoreKey]), app.BankKeeper,
521 | )
522 |
523 | // **** Module Options ****
524 |
525 | // NOTE: Any module instantiated in the module manager that is later modified
526 | // must be passed by reference here.
527 | app.ModuleManager = module.NewManager(
528 | genutil.NewAppModule(
529 | app.AccountKeeper, app.StakingKeeper, app,
530 | txConfig,
531 | ),
532 | auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
533 | vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
534 | bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
535 | capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
536 | feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
537 | gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
538 | mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
539 | slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry),
540 | distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
541 | staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
542 | upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()),
543 | evidence.NewAppModule(app.EvidenceKeeper),
544 | params.NewAppModule(app.ParamsKeeper),
545 | authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
546 | consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
547 | circuit.NewAppModule(appCodec, app.CircuitKeeper),
548 | meta.NewAppModule(app.MetaKeeper, app.AccountKeeper),
549 |
550 | // IBC modules
551 | ibc.NewAppModule(app.IBCKeeper),
552 | transfer.NewAppModule(app.TransferKeeper),
553 | ibcfee.NewAppModule(app.IBCFeeKeeper),
554 | ica.NewAppModule(&app.ICAControllerKeeper, nil),
555 |
556 | // IBC light clients
557 | ibctm.NewAppModule(),
558 | )
559 |
560 | // BasicModuleManager defines the module BasicManager is in charge of setting up basic,
561 | // non-dependant module elements, such as codec registration and genesis verification.
562 | // By default it is composed of all the modules from the module manager.
563 | // Additionally, app module basics can be overwritten by passing them as argument.
564 | app.BasicModuleManager = module.NewBasicManagerFromManager(
565 | app.ModuleManager,
566 | map[string]module.AppModuleBasic{
567 | genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
568 | govtypes.ModuleName: gov.NewAppModuleBasic(
569 | []govclient.ProposalHandler{
570 | paramsclient.ProposalHandler,
571 | },
572 | ),
573 | })
574 | app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
575 | app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
576 |
577 | // NOTE: upgrade module is required to be prioritized
578 | app.ModuleManager.SetOrderPreBlockers(
579 | upgradetypes.ModuleName,
580 | )
581 |
582 | // During begin block slashing happens after distr.BeginBlocker so that
583 | // there is nothing left over in the validator fee pool, so as to keep the
584 | // CanWithdrawInvariant invariant.
585 | // NOTE: staking module is required if HistoricalEntries param > 0
586 | // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
587 | app.ModuleManager.SetOrderBeginBlockers(
588 | capabilitytypes.ModuleName,
589 | minttypes.ModuleName,
590 | distrtypes.ModuleName,
591 | slashingtypes.ModuleName,
592 | evidencetypes.ModuleName,
593 | stakingtypes.ModuleName,
594 | ibcexported.ModuleName,
595 | ibctransfertypes.ModuleName,
596 | genutiltypes.ModuleName,
597 | authz.ModuleName,
598 | icatypes.ModuleName,
599 | ibcfeetypes.ModuleName,
600 | )
601 | app.ModuleManager.SetOrderEndBlockers(
602 | govtypes.ModuleName,
603 | stakingtypes.ModuleName,
604 | ibcexported.ModuleName,
605 | ibctransfertypes.ModuleName,
606 | capabilitytypes.ModuleName,
607 | genutiltypes.ModuleName,
608 | feegrant.ModuleName,
609 | icatypes.ModuleName,
610 | ibcfeetypes.ModuleName,
611 | group.ModuleName,
612 | )
613 |
614 | // NOTE: The genutils module must occur after staking so that pools are
615 | // properly initialized with tokens from genesis accounts.
616 | // NOTE: The genutils module must also occur after auth so that it can access the params from auth.
617 | // NOTE: Capability module must occur first so that it can initialize any capabilities
618 | // so that other modules that want to create or claim capabilities afterwards in InitChain
619 | // can do so safely.
620 | genesisModuleOrder := []string{
621 | capabilitytypes.ModuleName,
622 | authtypes.ModuleName,
623 | banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
624 | slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
625 | ibcexported.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName,
626 | icatypes.ModuleName, ibcfeetypes.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
627 | vestingtypes.ModuleName, group.ModuleName, consensusparamtypes.ModuleName, circuittypes.ModuleName,
628 | metatypes.ModuleName,
629 | }
630 | app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
631 | app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...)
632 |
633 | // Uncomment if you want to set a custom migration order here.
634 | // app.ModuleManager.SetOrderMigrations(custom order)
635 |
636 | app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
637 | err = app.ModuleManager.RegisterServices(app.configurator)
638 | if err != nil {
639 | panic(err)
640 | }
641 |
642 | // setupUpgradeHandlers is used for registering any on-chain upgrades.
643 | // Make sure it's called after `app.ModuleManager` and `app.configurator` are set.
644 | app.setupUpgradeHandlers()
645 |
646 | autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules))
647 |
648 | reflectionSvc, err := runtimeservices.NewReflectionService()
649 | if err != nil {
650 | panic(err)
651 | }
652 | reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
653 |
654 | // add test gRPC service for testing gRPC queries in isolation
655 | testpb.RegisterQueryServer(app.GRPCQueryRouter(), testpb.QueryImpl{})
656 |
657 | // create the simulation manager and define the order of the modules for deterministic simulations
658 | //
659 | // NOTE: this is not required apps that don't use the simulator for fuzz testing
660 | // transactions
661 | overrideModules := map[string]module.AppModuleSimulation{
662 | authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
663 | }
664 | app.simulationManager = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)
665 |
666 | app.simulationManager.RegisterStoreDecoders()
667 |
668 | // initialize stores
669 | app.MountKVStores(keys)
670 | app.MountTransientStores(tkeys)
671 | app.MountMemoryStores(memKeys)
672 |
673 | // initialize BaseApp
674 | app.SetInitChainer(app.InitChainer)
675 | app.SetPreBlocker(app.PreBlocker)
676 | app.SetBeginBlocker(app.BeginBlocker)
677 | app.SetEndBlocker(app.EndBlocker)
678 | app.setAnteHandler(txConfig)
679 |
680 | // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
681 | // antehandlers, but are run _after_ the `runMsgs` execution. They are also
682 | // defined as a chain, and have the same signature as antehandlers.
683 | //
684 | // In baseapp, postHandlers are run in the same store branch as `runMsgs`,
685 | // meaning that both `runMsgs` and `postHandler` state will be committed if
686 | // both are successful, and both will be reverted if any of the two fails.
687 | //
688 | // The SDK exposes a default postHandlers chain, which comprises of only
689 | // one decorator: the Transaction Tips decorator. However, some chains do
690 | // not need it by default, so feel free to comment the next line if you do
691 | // not need tips.
692 | // To read more about tips:
693 | // https://docs.cosmos.network/main/core/tips.html
694 | //
695 | // Please note that changing any of the anteHandler or postHandler chain is
696 | // likely to be a state-machine breaking change, which needs a coordinated
697 | // upgrade.
698 | app.setPostHandler()
699 |
700 | // At startup, after all modules have been registered, check that all proto
701 | // annotations are correct.
702 | protoFiles, err := proto.MergedRegistry()
703 | if err != nil {
704 | panic(err)
705 | }
706 | err = msgservice.ValidateProtoAnnotations(protoFiles)
707 | if err != nil {
708 | // Once we switch to using protoreflect-based antehandlers, we might
709 | // want to panic here instead of logging a warning.
710 | _, err := fmt.Fprintln(os.Stderr, err.Error())
711 | if err != nil {
712 | fmt.Println("could not write to stderr")
713 | }
714 | }
715 |
716 | if loadLatest {
717 | if err := app.LoadLatestVersion(); err != nil {
718 | panic(fmt.Errorf("error loading last version: %w", err))
719 | }
720 | }
721 |
722 | return app
723 | }
724 |
725 | func (app *NillionApp) setAnteHandler(txConfig client.TxConfig) {
726 | anteHandler, err := NewAnteHandler(
727 | HandlerOptions{
728 | ante.HandlerOptions{
729 | AccountKeeper: app.AccountKeeper,
730 | BankKeeper: app.BankKeeper,
731 | SignModeHandler: txConfig.SignModeHandler(),
732 | FeegrantKeeper: app.FeeGrantKeeper,
733 | SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
734 | },
735 | &app.CircuitKeeper,
736 | app.IBCKeeper,
737 | },
738 | )
739 | if err != nil {
740 | panic(err)
741 | }
742 |
743 | // Set the AnteHandler for the app
744 | app.SetAnteHandler(anteHandler)
745 | }
746 |
747 | func (app *NillionApp) setPostHandler() {
748 | postHandler, err := posthandler.NewPostHandler(
749 | posthandler.HandlerOptions{},
750 | )
751 | if err != nil {
752 | panic(err)
753 | }
754 |
755 | app.SetPostHandler(postHandler)
756 | }
757 |
758 | // Name returns the name of the App
759 | func (app *NillionApp) Name() string { return app.BaseApp.Name() }
760 |
761 | // PreBlocker application updates every pre block
762 | func (app *NillionApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
763 | return app.ModuleManager.PreBlock(ctx)
764 | }
765 |
766 | // BeginBlocker application updates every begin block
767 | func (app *NillionApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
768 | return app.ModuleManager.BeginBlock(ctx)
769 | }
770 |
771 | // EndBlocker application updates every end block
772 | func (app *NillionApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
773 | return app.ModuleManager.EndBlock(ctx)
774 | }
775 |
776 | // Configurator returns the configurator for the app
777 | func (app *NillionApp) Configurator() module.Configurator {
778 | return app.configurator
779 | }
780 |
781 | // InitChainer application update at chain initialization
782 | func (app *NillionApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
783 | var genesisState GenesisState
784 | if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
785 | panic(err)
786 | }
787 | if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil {
788 | panic(err)
789 | }
790 | return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
791 | }
792 |
793 | // LoadHeight loads a particular height
794 | func (app *NillionApp) LoadHeight(height int64) error {
795 | return app.LoadVersion(height)
796 | }
797 |
798 | // LegacyAmino returns NillionApp's amino codec.
799 | //
800 | // NOTE: This is solely to be used for testing purposes as it may be desirable
801 | // for modules to register their own custom testing types.
802 | func (app *NillionApp) LegacyAmino() *codec.LegacyAmino {
803 | return app.legacyAmino
804 | }
805 |
806 | // AppCodec returns NillionApp's app codec.
807 | //
808 | // NOTE: This is solely to be used for testing purposes as it may be desirable
809 | // for modules to register their own custom testing types.
810 | func (app *NillionApp) AppCodec() codec.Codec {
811 | return app.appCodec
812 | }
813 |
814 | // InterfaceRegistry returns NillionApp's InterfaceRegistry
815 | func (app *NillionApp) InterfaceRegistry() types.InterfaceRegistry {
816 | return app.interfaceRegistry
817 | }
818 |
819 | // TxConfig returns NillionApp's TxConfig
820 | func (app *NillionApp) TxConfig() client.TxConfig {
821 | return app.txConfig
822 | }
823 |
824 | // AutoCliOpts returns the autocli options for the app.
825 | func (app *NillionApp) AutoCliOpts() autocli.AppOptions {
826 | modules := make(map[string]appmodule.AppModule)
827 | for _, m := range app.ModuleManager.Modules {
828 | if moduleWithName, ok := m.(module.HasName); ok {
829 | moduleName := moduleWithName.Name()
830 | if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
831 | modules[moduleName] = appModule
832 | }
833 | }
834 | }
835 |
836 | return autocli.AppOptions{
837 | Modules: modules,
838 | ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
839 | }
840 | }
841 |
842 | // DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
843 | func (app *NillionApp) DefaultGenesis() map[string]json.RawMessage {
844 | return app.BasicModuleManager.DefaultGenesis(app.appCodec)
845 | }
846 |
847 | // GetKey returns the KVStoreKey for the provided store key.
848 | //
849 | // NOTE: This is solely to be used for testing purposes.
850 | func (app *NillionApp) GetKey(storeKey string) *storetypes.KVStoreKey {
851 | return app.keys[storeKey]
852 | }
853 |
854 | // GetStoreKeys returns all the stored store keys.
855 | func (app *NillionApp) GetStoreKeys() []storetypes.StoreKey {
856 | keys := make([]storetypes.StoreKey, len(app.keys))
857 | for _, key := range app.keys {
858 | keys = append(keys, key)
859 | }
860 |
861 | return keys
862 | }
863 |
864 | // GetSubspace returns a param subspace for a given module name.
865 | //
866 | // NOTE: This is solely to be used for testing purposes.
867 | func (app *NillionApp) GetSubspace(moduleName string) paramstypes.Subspace {
868 | subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
869 | return subspace
870 | }
871 |
872 | // SimulationManager implements the SimulationApp interface
873 | func (app *NillionApp) SimulationManager() *module.SimulationManager {
874 | return app.simulationManager
875 | }
876 |
877 | // RegisterAPIRoutes registers all application module routes with the provided
878 | // API server.
879 | func (app *NillionApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
880 | clientCtx := apiSvr.ClientCtx
881 | // Register new tx routes from grpc-gateway.
882 | authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
883 |
884 | // Register new CometBFT queries routes from grpc-gateway.
885 | cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
886 |
887 | // Register node gRPC service for grpc-gateway.
888 | nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
889 |
890 | // Register grpc-gateway routes for all modules.
891 | app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
892 |
893 | // register swagger API from root so that other applications can override easily
894 | if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
895 | panic(err)
896 | }
897 | }
898 |
899 | // RegisterTxService implements the Application.RegisterTxService method.
900 | func (app *NillionApp) RegisterTxService(clientCtx client.Context) {
901 | authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
902 | }
903 |
904 | // RegisterTendermintService implements the Application.RegisterTendermintService method.
905 | func (app *NillionApp) RegisterTendermintService(clientCtx client.Context) {
906 | cmtApp := server.NewCometABCIWrapper(app)
907 | cmtservice.RegisterTendermintService(
908 | clientCtx,
909 | app.BaseApp.GRPCQueryRouter(),
910 | app.interfaceRegistry,
911 | cmtApp.Query,
912 | )
913 | }
914 |
915 | func (app *NillionApp) RegisterNodeService(clientCtx client.Context, cfg config.Config) {
916 | nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
917 | }
918 |
919 | // GetMaccPerms returns a copy of the module account permissions
920 | //
921 | // NOTE: This is solely to be used for testing purposes.
922 | func GetMaccPerms() map[string][]string {
923 | dupMaccPerms := make(map[string][]string)
924 | for k, v := range maccPerms {
925 | dupMaccPerms[k] = v
926 | }
927 |
928 | return dupMaccPerms
929 | }
930 |
931 | // BlockedAddresses returns all the app's blocked account addresses.
932 | func BlockedAddresses() map[string]bool {
933 | modAccAddrs := make(map[string]bool)
934 | for acc := range GetMaccPerms() {
935 | modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
936 | }
937 |
938 | // allow the following addresses to receive funds
939 | delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
940 |
941 | return modAccAddrs
942 | }
943 |
944 | // initParamsKeeper init params keeper and its subspaces
945 | func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
946 | paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
947 |
948 | // register the key tables for legacy param subspaces
949 | keyTable := ibcclienttypes.ParamKeyTable()
950 | keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
951 | paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
952 | paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
953 | paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
954 | paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
955 |
956 | return paramsKeeper
957 | }
958 |
959 | // IBC TestingApp functions
960 |
961 | // GetBaseApp implements the TestingApp interface.
962 | func (app *NillionApp) GetBaseApp() *baseapp.BaseApp {
963 | return app.BaseApp
964 | }
965 |
966 | // GetStakingKeeper implements the TestingApp interface.
967 | func (app *NillionApp) GetStakingKeeper() ibctestingtypes.StakingKeeper {
968 | return app.StakingKeeper
969 | }
970 |
971 | // GetIBCKeeper implements the TestingApp interface.
972 | func (app *NillionApp) GetIBCKeeper() *ibckeeper.Keeper {
973 | return app.IBCKeeper
974 | }
975 |
976 | // GetTxConfig implements the TestingApp interface.
977 | func (app *NillionApp) GetTxConfig() client.TxConfig {
978 | return app.txConfig
979 | }
980 |
981 | // GetMemKey returns the MemStoreKey for the provided mem key.
982 | //
983 | // NOTE: This is solely used for testing purposes.
984 | func (app *NillionApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
985 | return app.memKeys[storeKey]
986 | }
987 |
--------------------------------------------------------------------------------