From 7aef762569a35fcd6ecd2759c99bbc82a318b650 Mon Sep 17 00:00:00 2001 From: Fabrice Bascoulergue <3663159+lebascou@users.noreply.github.com> Date: Mon, 22 May 2023 10:43:28 +0200 Subject: [PATCH] Brings to light the millions protocol (#23) * Brings to light the millions protocol * Sync with upstream --------- Co-authored-by: Fabrice Bascoulergue Co-authored-by: Segfault <5221072+Segfaultd@users.noreply.github.com> --- Dockerfile | 7 - Makefile | 22 +- app/app.go | 137 +- app/export.go | 3 + app/keepers.go | 274 +- app/params/config.go | 3 +- app/prefix.go | 1 + app/pubkey_replacement.go | 122 - app/test_helpers.go | 218 +- app/testing/helpers.go | 20 +- cmd/lumd/cmd/genaccounts.go | 6 +- cmd/lumd/cmd/root.go | 5 +- config.yml | 24 +- go.mod | 52 +- go.sum | 87 +- internal/tools/tools.go | 1 + proto/lum-network/dfract/proposal.proto | 5 +- .../icacallbacks/callback_data.proto | 13 + proto/lum-network/icacallbacks/genesis.proto | 15 + proto/lum-network/icacallbacks/packet.proto | 15 + proto/lum-network/icacallbacks/params.proto | 8 + proto/lum-network/icacallbacks/query.proto | 54 + proto/lum-network/icacallbacks/tx.proto | 10 + proto/lum-network/icqueries/genesis.proto | 39 + proto/lum-network/icqueries/query.proto | 27 + proto/lum-network/icqueries/tx.proto | 37 + proto/lum-network/millions/callbacks.proto | 57 + proto/lum-network/millions/deposit.proto | 40 + proto/lum-network/millions/draw.proto | 52 + .../lum-network/millions/draw_schedule.proto | 13 + proto/lum-network/millions/genesis.proto | 27 + proto/lum-network/millions/gov.proto | 61 + proto/lum-network/millions/params.proto | 26 + proto/lum-network/millions/pool.proto | 84 + proto/lum-network/millions/prize.proto | 44 + proto/lum-network/millions/prize_batch.proto | 12 + proto/lum-network/millions/prize_ref.proto | 14 + .../lum-network/millions/prize_strategy.proto | 12 + proto/lum-network/millions/query.proto | 286 + proto/lum-network/millions/tx.proto | 137 + proto/lum-network/millions/withdrawal.proto | 48 + readme.md | 2 - tools/.env | 3 +- tools/config/hermes.toml | 40 +- tools/docker-compose.yml | 28 +- tools/dockerfiles/Dockerfile.gaia | 2 +- tools/dockerfiles/Dockerfile.hermes | 2 +- tools/dockerfiles/Dockerfile.juno | 2 +- tools/dockerfiles/Dockerfile.osmosis | 4 +- x/airdrop/handler.go | 11 +- x/airdrop/keeper/keeper.go | 9 +- x/airdrop/keeper/keeper_test.go | 11 +- x/airdrop/keeper/params.go | 2 +- x/airdrop/module.go | 1 + x/airdrop/types/claim.pb.go | 2 +- x/airdrop/types/codec.go | 2 +- x/airdrop/types/errors.go | 1 - x/airdrop/types/events.go | 2 +- x/airdrop/types/genesis.pb.go | 5 +- x/airdrop/types/keys.go | 2 +- x/airdrop/types/params.go | 2 +- x/airdrop/types/params.pb.go | 5 +- x/airdrop/types/query.pb.go | 2 +- x/airdrop/types/query.pb.gw.go | 10 +- x/beam/keeper/keeper.go | 7 +- x/beam/types/beam.pb.go | 4 +- x/beam/types/genesis.go | 2 +- x/beam/types/genesis.pb.go | 2 +- x/beam/types/params.go | 4 +- x/beam/types/query.pb.gw.go | 6 +- x/beam/types/tx.pb.go | 2 +- x/dfract/keeper/keeper.go | 4 +- x/dfract/types/deposit.pb.go | 4 +- x/dfract/types/genesis.pb.go | 2 +- x/dfract/types/proposal.pb.go | 43 +- x/dfract/types/query.pb.go | 2 +- x/dfract/types/query.pb.gw.go | 8 +- x/dfract/types/tx.pb.go | 2 +- x/icacallbacks/README.md | 70 + x/icacallbacks/client/cli/query.go | 116 + x/icacallbacks/client/cli/tx.go | 26 + x/icacallbacks/genesis.go | 29 + x/icacallbacks/genesis_test.go | 42 + x/icacallbacks/handler.go | 29 + x/icacallbacks/icacallbacks.go | 86 + x/icacallbacks/icacallbacks_test.go | 242 + x/icacallbacks/keeper/callback_data.go | 62 + x/icacallbacks/keeper/grpc_query.go | 7 + .../keeper/grpc_query_callback_data.go | 57 + x/icacallbacks/keeper/grpc_query_params.go | 20 + x/icacallbacks/keeper/keeper.go | 156 + x/icacallbacks/keeper/msg_server.go | 17 + x/icacallbacks/keeper/params.go | 17 + x/icacallbacks/module.go | 179 + x/icacallbacks/module_ibc.go | 142 + x/icacallbacks/simulation/simap.go | 15 + .../types/acknowledgement_response.go | 15 + x/icacallbacks/types/callback_data.pb.go | 567 ++ x/icacallbacks/types/callbacks.go | 14 + x/icacallbacks/types/codec.go | 23 + x/icacallbacks/types/errors.go | 14 + x/icacallbacks/types/events_ibc.go | 11 + x/icacallbacks/types/expected_keepers.go | 18 + x/icacallbacks/types/genesis.go | 41 + x/icacallbacks/types/genesis.pb.go | 444 + x/icacallbacks/types/genesis_test.go | 63 + x/icacallbacks/types/key_callback_data.go | 25 + x/icacallbacks/types/keys.go | 37 + x/icacallbacks/types/packet.pb.go | 509 + x/icacallbacks/types/params.go | 39 + x/icacallbacks/types/params.pb.go | 270 + x/icacallbacks/types/query.pb.go | 1409 +++ x/icacallbacks/types/query.pb.gw.go | 337 + x/icacallbacks/types/tx.pb.go | 81 + x/icacallbacks/types/types.go | 1 + x/icqueries/client/cli/query.go | 97 + x/icqueries/genesis.go | 21 + x/icqueries/handler.go | 18 + x/icqueries/keeper/abci.go | 49 + x/icqueries/keeper/grpc_query.go | 32 + x/icqueries/keeper/keeper.go | 87 + x/icqueries/keeper/msg_server.go | 16 + .../keeper/msg_server_query_response.go | 159 + x/icqueries/keeper/queries.go | 117 + x/icqueries/module.go | 157 + x/icqueries/types/callbacks.go | 20 + x/icqueries/types/codec.go | 32 + x/icqueries/types/errors.go | 13 + x/icqueries/types/events.go | 14 + x/icqueries/types/genesis.go | 22 + x/icqueries/types/genesis.pb.go | 1233 +++ x/icqueries/types/keys.go | 41 + .../types/message_submit_query_response.go | 45 + x/icqueries/types/query.go | 37 + x/icqueries/types/query.pb.go | 892 ++ x/icqueries/types/query.pb.gw.go | 218 + x/icqueries/types/tx.pb.go | 762 ++ x/icqueries/types/tx.pb.gw.go | 169 + x/millions/abci.go | 22 + x/millions/client/cli/proposal.go | 308 + x/millions/client/cli/query.go | 1013 ++ x/millions/client/cli/tx.go | 374 + x/millions/client/proposal_handler.go | 12 + x/millions/client/rest/rest.go | 10 + x/millions/docs/relayer_setup.md | 76 + x/millions/genesis.go | 60 + x/millions/genesis_test.go | 386 + x/millions/handler.go | 48 + x/millions/handler_proposal.go | 75 + x/millions/handler_proposal_test.go | 372 + x/millions/keeper/callbacks.go | 57 + x/millions/keeper/callbacks_claim.go | 56 + x/millions/keeper/callbacks_claim_test.go | 48 + x/millions/keeper/callbacks_delegate.go | 53 + x/millions/keeper/callbacks_delegate_test.go | 59 + x/millions/keeper/callbacks_redelegate.go | 57 + .../keeper/callbacks_redelegate_test.go | 56 + .../keeper/callbacks_set_withdraw_address.go | 59 + .../callbacks_set_withdraw_address_test.go | 46 + .../keeper/callbacks_transfer_from_native.go | 69 + .../callbacks_transfer_from_native_test.go | 52 + .../keeper/callbacks_transfer_to_native.go | 53 + .../callbacks_transfer_to_native_test.go | 48 + x/millions/keeper/callbacks_undelegate.go | 103 + .../keeper/callbacks_undelegate_test.go | 59 + x/millions/keeper/grpc_query.go | 17 + x/millions/keeper/grpc_query_deposit.go | 171 + x/millions/keeper/grpc_query_draw.go | 96 + x/millions/keeper/grpc_query_params.go | 15 + x/millions/keeper/grpc_query_pool.go | 59 + x/millions/keeper/grpc_query_prize.go | 246 + x/millions/keeper/grpc_query_test.go | 595 ++ x/millions/keeper/grpc_query_withdrawal.go | 170 + x/millions/keeper/keeper.go | 101 + x/millions/keeper/keeper_blockers.go | 165 + x/millions/keeper/keeper_blockers_test.go | 363 + x/millions/keeper/keeper_deposit.go | 462 + x/millions/keeper/keeper_deposit_test.go | 1174 +++ x/millions/keeper/keeper_draw.go | 867 ++ x/millions/keeper/keeper_draw_test.go | 1557 +++ x/millions/keeper/keeper_fees.go | 60 + x/millions/keeper/keeper_fees_test.go | 119 + x/millions/keeper/keeper_params.go | 26 + x/millions/keeper/keeper_params_test.go | 72 + x/millions/keeper/keeper_pool.go | 693 ++ x/millions/keeper/keeper_pool_test.go | 885 ++ x/millions/keeper/keeper_prize.go | 286 + x/millions/keeper/keeper_prize_test.go | 524 ++ x/millions/keeper/keeper_test.go | 158 + x/millions/keeper/keeper_withdrawal.go | 524 ++ x/millions/keeper/keeper_withdrawal_test.go | 1320 +++ x/millions/keeper/msg_server.go | 15 + x/millions/keeper/msg_server_deposit.go | 185 + x/millions/keeper/msg_server_draw.go | 88 + x/millions/keeper/msg_server_pool.go | 55 + x/millions/keeper/msg_server_prize.go | 73 + x/millions/keeper/msg_server_test.go | 928 ++ x/millions/keeper/msg_server_withdrawal.go | 159 + x/millions/keeper/queries.go | 42 + x/millions/keeper/queries_balance.go | 70 + x/millions/middleware_ibc.go | 143 + x/millions/module.go | 165 + x/millions/module_ibc.go | 166 + x/millions/simulation/decoder.go | 16 + x/millions/types/callbacks.pb.go | 1953 ++++ x/millions/types/codec.go | 60 + x/millions/types/deposit.go | 39 + x/millions/types/deposit.pb.go | 850 ++ x/millions/types/draw.go | 17 + x/millions/types/draw.pb.go | 1005 ++ x/millions/types/draw_schedule.go | 64 + x/millions/types/draw_schedule.pb.go | 384 + x/millions/types/errors.go | 47 + x/millions/types/events.go | 28 + x/millions/types/genesis.go | 25 + x/millions/types/genesis.pb.go | 791 ++ x/millions/types/gov.pb.go | 2136 +++++ x/millions/types/keys.go | 189 + x/millions/types/message_claim_prize.go | 48 + x/millions/types/message_deposit.go | 66 + x/millions/types/message_deposit_retry.go | 46 + x/millions/types/message_draw_retry.go | 46 + .../message_restore_interchain_accounts.go | 43 + x/millions/types/message_withdraw_deposit.go | 51 + .../types/message_withdraw_deposit_retry.go | 46 + x/millions/types/params.go | 73 + x/millions/types/params.pb.go | 667 ++ x/millions/types/pool.go | 220 + x/millions/types/pool.pb.go | 2169 +++++ x/millions/types/pool_validator.go | 17 + x/millions/types/prize.go | 30 + x/millions/types/prize.pb.go | 1205 +++ x/millions/types/prize_batch.go | 68 + x/millions/types/prize_batch.pb.go | 394 + x/millions/types/prize_ref.pb.go | 413 + x/millions/types/prize_strategy.go | 59 + x/millions/types/prize_strategy.pb.go | 335 + x/millions/types/proposal_register_pool.go | 115 + x/millions/types/proposal_test.go | 26 + x/millions/types/proposal_update_params.go | 103 + x/millions/types/proposal_update_pool.go | 87 + x/millions/types/query.pb.go | 8307 +++++++++++++++++ x/millions/types/query.pb.gw.go | 2743 ++++++ x/millions/types/tx.pb.go | 5453 +++++++++++ x/millions/types/withdrawal.go | 39 + x/millions/types/withdrawal.pb.go | 1284 +++ 246 files changed, 59635 insertions(+), 408 deletions(-) delete mode 100644 app/pubkey_replacement.go create mode 100755 proto/lum-network/icacallbacks/callback_data.proto create mode 100755 proto/lum-network/icacallbacks/genesis.proto create mode 100755 proto/lum-network/icacallbacks/packet.proto create mode 100755 proto/lum-network/icacallbacks/params.proto create mode 100644 proto/lum-network/icacallbacks/query.proto create mode 100755 proto/lum-network/icacallbacks/tx.proto create mode 100644 proto/lum-network/icqueries/genesis.proto create mode 100644 proto/lum-network/icqueries/query.proto create mode 100644 proto/lum-network/icqueries/tx.proto create mode 100644 proto/lum-network/millions/callbacks.proto create mode 100644 proto/lum-network/millions/deposit.proto create mode 100644 proto/lum-network/millions/draw.proto create mode 100644 proto/lum-network/millions/draw_schedule.proto create mode 100644 proto/lum-network/millions/genesis.proto create mode 100644 proto/lum-network/millions/gov.proto create mode 100644 proto/lum-network/millions/params.proto create mode 100644 proto/lum-network/millions/pool.proto create mode 100644 proto/lum-network/millions/prize.proto create mode 100644 proto/lum-network/millions/prize_batch.proto create mode 100644 proto/lum-network/millions/prize_ref.proto create mode 100644 proto/lum-network/millions/prize_strategy.proto create mode 100644 proto/lum-network/millions/query.proto create mode 100644 proto/lum-network/millions/tx.proto create mode 100644 proto/lum-network/millions/withdrawal.proto create mode 100644 x/icacallbacks/README.md create mode 100644 x/icacallbacks/client/cli/query.go create mode 100644 x/icacallbacks/client/cli/tx.go create mode 100644 x/icacallbacks/genesis.go create mode 100644 x/icacallbacks/genesis_test.go create mode 100644 x/icacallbacks/handler.go create mode 100644 x/icacallbacks/icacallbacks.go create mode 100644 x/icacallbacks/icacallbacks_test.go create mode 100644 x/icacallbacks/keeper/callback_data.go create mode 100644 x/icacallbacks/keeper/grpc_query.go create mode 100644 x/icacallbacks/keeper/grpc_query_callback_data.go create mode 100644 x/icacallbacks/keeper/grpc_query_params.go create mode 100644 x/icacallbacks/keeper/keeper.go create mode 100644 x/icacallbacks/keeper/msg_server.go create mode 100644 x/icacallbacks/keeper/params.go create mode 100644 x/icacallbacks/module.go create mode 100644 x/icacallbacks/module_ibc.go create mode 100644 x/icacallbacks/simulation/simap.go create mode 100644 x/icacallbacks/types/acknowledgement_response.go create mode 100644 x/icacallbacks/types/callback_data.pb.go create mode 100644 x/icacallbacks/types/callbacks.go create mode 100644 x/icacallbacks/types/codec.go create mode 100644 x/icacallbacks/types/errors.go create mode 100644 x/icacallbacks/types/events_ibc.go create mode 100644 x/icacallbacks/types/expected_keepers.go create mode 100644 x/icacallbacks/types/genesis.go create mode 100644 x/icacallbacks/types/genesis.pb.go create mode 100644 x/icacallbacks/types/genesis_test.go create mode 100644 x/icacallbacks/types/key_callback_data.go create mode 100644 x/icacallbacks/types/keys.go create mode 100644 x/icacallbacks/types/packet.pb.go create mode 100644 x/icacallbacks/types/params.go create mode 100644 x/icacallbacks/types/params.pb.go create mode 100644 x/icacallbacks/types/query.pb.go create mode 100644 x/icacallbacks/types/query.pb.gw.go create mode 100644 x/icacallbacks/types/tx.pb.go create mode 100644 x/icacallbacks/types/types.go create mode 100644 x/icqueries/client/cli/query.go create mode 100644 x/icqueries/genesis.go create mode 100644 x/icqueries/handler.go create mode 100644 x/icqueries/keeper/abci.go create mode 100644 x/icqueries/keeper/grpc_query.go create mode 100644 x/icqueries/keeper/keeper.go create mode 100644 x/icqueries/keeper/msg_server.go create mode 100644 x/icqueries/keeper/msg_server_query_response.go create mode 100644 x/icqueries/keeper/queries.go create mode 100644 x/icqueries/module.go create mode 100644 x/icqueries/types/callbacks.go create mode 100644 x/icqueries/types/codec.go create mode 100644 x/icqueries/types/errors.go create mode 100644 x/icqueries/types/events.go create mode 100644 x/icqueries/types/genesis.go create mode 100644 x/icqueries/types/genesis.pb.go create mode 100644 x/icqueries/types/keys.go create mode 100644 x/icqueries/types/message_submit_query_response.go create mode 100644 x/icqueries/types/query.go create mode 100644 x/icqueries/types/query.pb.go create mode 100644 x/icqueries/types/query.pb.gw.go create mode 100644 x/icqueries/types/tx.pb.go create mode 100644 x/icqueries/types/tx.pb.gw.go create mode 100644 x/millions/abci.go create mode 100644 x/millions/client/cli/proposal.go create mode 100644 x/millions/client/cli/query.go create mode 100644 x/millions/client/cli/tx.go create mode 100644 x/millions/client/proposal_handler.go create mode 100644 x/millions/client/rest/rest.go create mode 100644 x/millions/docs/relayer_setup.md create mode 100644 x/millions/genesis.go create mode 100644 x/millions/genesis_test.go create mode 100644 x/millions/handler.go create mode 100644 x/millions/handler_proposal.go create mode 100644 x/millions/handler_proposal_test.go create mode 100644 x/millions/keeper/callbacks.go create mode 100644 x/millions/keeper/callbacks_claim.go create mode 100644 x/millions/keeper/callbacks_claim_test.go create mode 100644 x/millions/keeper/callbacks_delegate.go create mode 100644 x/millions/keeper/callbacks_delegate_test.go create mode 100644 x/millions/keeper/callbacks_redelegate.go create mode 100644 x/millions/keeper/callbacks_redelegate_test.go create mode 100644 x/millions/keeper/callbacks_set_withdraw_address.go create mode 100644 x/millions/keeper/callbacks_set_withdraw_address_test.go create mode 100644 x/millions/keeper/callbacks_transfer_from_native.go create mode 100644 x/millions/keeper/callbacks_transfer_from_native_test.go create mode 100644 x/millions/keeper/callbacks_transfer_to_native.go create mode 100644 x/millions/keeper/callbacks_transfer_to_native_test.go create mode 100644 x/millions/keeper/callbacks_undelegate.go create mode 100644 x/millions/keeper/callbacks_undelegate_test.go create mode 100644 x/millions/keeper/grpc_query.go create mode 100644 x/millions/keeper/grpc_query_deposit.go create mode 100644 x/millions/keeper/grpc_query_draw.go create mode 100644 x/millions/keeper/grpc_query_params.go create mode 100644 x/millions/keeper/grpc_query_pool.go create mode 100644 x/millions/keeper/grpc_query_prize.go create mode 100644 x/millions/keeper/grpc_query_test.go create mode 100644 x/millions/keeper/grpc_query_withdrawal.go create mode 100644 x/millions/keeper/keeper.go create mode 100644 x/millions/keeper/keeper_blockers.go create mode 100644 x/millions/keeper/keeper_blockers_test.go create mode 100644 x/millions/keeper/keeper_deposit.go create mode 100644 x/millions/keeper/keeper_deposit_test.go create mode 100644 x/millions/keeper/keeper_draw.go create mode 100644 x/millions/keeper/keeper_draw_test.go create mode 100644 x/millions/keeper/keeper_fees.go create mode 100644 x/millions/keeper/keeper_fees_test.go create mode 100644 x/millions/keeper/keeper_params.go create mode 100644 x/millions/keeper/keeper_params_test.go create mode 100644 x/millions/keeper/keeper_pool.go create mode 100644 x/millions/keeper/keeper_pool_test.go create mode 100644 x/millions/keeper/keeper_prize.go create mode 100644 x/millions/keeper/keeper_prize_test.go create mode 100644 x/millions/keeper/keeper_test.go create mode 100644 x/millions/keeper/keeper_withdrawal.go create mode 100644 x/millions/keeper/keeper_withdrawal_test.go create mode 100644 x/millions/keeper/msg_server.go create mode 100644 x/millions/keeper/msg_server_deposit.go create mode 100644 x/millions/keeper/msg_server_draw.go create mode 100644 x/millions/keeper/msg_server_pool.go create mode 100644 x/millions/keeper/msg_server_prize.go create mode 100644 x/millions/keeper/msg_server_test.go create mode 100644 x/millions/keeper/msg_server_withdrawal.go create mode 100644 x/millions/keeper/queries.go create mode 100644 x/millions/keeper/queries_balance.go create mode 100644 x/millions/middleware_ibc.go create mode 100644 x/millions/module.go create mode 100644 x/millions/module_ibc.go create mode 100644 x/millions/simulation/decoder.go create mode 100644 x/millions/types/callbacks.pb.go create mode 100644 x/millions/types/codec.go create mode 100644 x/millions/types/deposit.go create mode 100644 x/millions/types/deposit.pb.go create mode 100644 x/millions/types/draw.go create mode 100644 x/millions/types/draw.pb.go create mode 100644 x/millions/types/draw_schedule.go create mode 100644 x/millions/types/draw_schedule.pb.go create mode 100644 x/millions/types/errors.go create mode 100644 x/millions/types/events.go create mode 100644 x/millions/types/genesis.go create mode 100644 x/millions/types/genesis.pb.go create mode 100644 x/millions/types/gov.pb.go create mode 100644 x/millions/types/keys.go create mode 100644 x/millions/types/message_claim_prize.go create mode 100644 x/millions/types/message_deposit.go create mode 100644 x/millions/types/message_deposit_retry.go create mode 100644 x/millions/types/message_draw_retry.go create mode 100644 x/millions/types/message_restore_interchain_accounts.go create mode 100644 x/millions/types/message_withdraw_deposit.go create mode 100644 x/millions/types/message_withdraw_deposit_retry.go create mode 100644 x/millions/types/params.go create mode 100644 x/millions/types/params.pb.go create mode 100644 x/millions/types/pool.go create mode 100644 x/millions/types/pool.pb.go create mode 100644 x/millions/types/pool_validator.go create mode 100644 x/millions/types/prize.go create mode 100644 x/millions/types/prize.pb.go create mode 100644 x/millions/types/prize_batch.go create mode 100644 x/millions/types/prize_batch.pb.go create mode 100644 x/millions/types/prize_ref.pb.go create mode 100644 x/millions/types/prize_strategy.go create mode 100644 x/millions/types/prize_strategy.pb.go create mode 100644 x/millions/types/proposal_register_pool.go create mode 100644 x/millions/types/proposal_test.go create mode 100644 x/millions/types/proposal_update_params.go create mode 100644 x/millions/types/proposal_update_pool.go create mode 100644 x/millions/types/query.pb.go create mode 100644 x/millions/types/query.pb.gw.go create mode 100644 x/millions/types/tx.pb.go create mode 100644 x/millions/types/withdrawal.go create mode 100644 x/millions/types/withdrawal.pb.go diff --git a/Dockerfile b/Dockerfile index 6b99da2c..2eaa514b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,12 +40,5 @@ WORKDIR $CHAIN # Copy over binaries from the build-env COPY --from=build-env /go/bin/lumd /usr/bin/lumd -# Add the scripts -COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/init_node.py /usr/bin/init_node.py -COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_default_config.py /usr/bin/apply_default_config.py -COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_pruning_config.py /usr/bin/apply_pruning_config.py -COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_rpc_node_config.py /usr/bin/apply_rpc_node_config.py -COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_statesync_params.py /usr/bin/apply_statesync_params.py - # Run lumd by default, omit entrypoint to ease using container with chaincli CMD ["lumd"] \ No newline at end of file diff --git a/Makefile b/Makefile index ead3b81e..99e8c79e 100644 --- a/Makefile +++ b/Makefile @@ -42,30 +42,20 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=lum \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" -ifeq ($(LINK_STATICALLY),true) - ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static" -endif -ldflags += $(LDFLAGS) -ldflags := $(strip $(ldflags)) - BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' -check_version: -ifneq ($(GO_MINOR_VERSION),18) - @echo "ERROR: Go version 1.18 is required for this version of Lum Network. Go 1.19 has changes that are believed to break consensus." - exit 1 -endif +all: install -all: check_version install +format: + @gofmt -w . + +lint: + @golangci-lint run --skip-dirs='(x/beam|x/dfract)' install: go.sum @echo "--> Installing lumd" @go install -mod=readonly $(BUILD_FLAGS) ./cmd/lumd -build: go.sum - @echo "--> Building lumd" - @go build -mod=readonly $(BUILD_FLAGS) ./cmd/lumd - go.sum: go.mod @echo "--> Ensure dependencies have not been modified" GO111MODULE=on go mod verify diff --git a/app/app.go b/app/app.go index 615d70eb..783a48bd 100644 --- a/app/app.go +++ b/app/app.go @@ -2,19 +2,32 @@ package app import ( "fmt" + "io" + "net/http" + "os" + "path/filepath" + + "github.com/lum-network/chain/x/icqueries" + icqueriestypes "github.com/lum-network/chain/x/icqueries/types" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" govclient "github.com/cosmos/cosmos-sdk/x/gov/client" ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts" icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types" + ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper" + ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" + ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types" "github.com/lum-network/chain/x/dfract" dfractclient "github.com/lum-network/chain/x/dfract/client" - "io" - "net/http" - "os" - "path/filepath" + millionsclient "github.com/lum-network/chain/x/millions/client" + + "github.com/lum-network/chain/x/icacallbacks" + "github.com/lum-network/chain/x/millions" + millionstypes "github.com/lum-network/chain/x/millions/types" ibcconnectiontypes "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types" "github.com/gorilla/mux" @@ -92,6 +105,8 @@ import ( ibc "github.com/cosmos/ibc-go/v5/modules/core" ibcclientclient "github.com/cosmos/ibc-go/v5/modules/core/02-client/client" ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" + + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" ) var ( @@ -118,6 +133,9 @@ var ( ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, dfractclient.ProposalHandler, + millionsclient.RegisterPoolProposalHandler, + millionsclient.UpdatePoolProposalHandler, + millionsclient.UpdateParamsProposalHandler, }, ), params.AppModuleBasic{}, @@ -131,9 +149,12 @@ var ( transfer.AppModuleBasic{}, authzmodule.AppModuleBasic{}, vesting.AppModuleBasic{}, + icacallbacks.AppModuleBasic{}, + icqueries.AppModuleBasic{}, beam.AppModuleBasic{}, airdrop.AppModuleBasic{}, dfract.AppModuleBasic{}, + millions.AppModuleBasic{}, ) // module account permissions @@ -147,8 +168,10 @@ var ( govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, beamtypes.ModuleName: nil, + icqueriestypes.ModuleName: nil, airdroptypes.ModuleName: {authtypes.Minter, authtypes.Burner}, dfracttypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + millionstypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking}, } ) @@ -226,9 +249,10 @@ func New( keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, icahosttypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, - beamtypes.StoreKey, airdroptypes.StoreKey, dfracttypes.StoreKey, + icacallbackstypes.StoreKey, icqueriestypes.StoreKey, + beamtypes.StoreKey, airdroptypes.StoreKey, dfracttypes.StoreKey, millionstypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -280,10 +304,14 @@ func New( ica.NewAppModule(nil, app.ICAHostKeeper), params.NewAppModule(*app.ParamsKeeper), app.transferModule, + ica.NewAppModule(app.ICAControllerKeeper, app.ICAHostKeeper), authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), beam.NewAppModule(appCodec, *app.BeamKeeper), airdrop.NewAppModule(appCodec, *app.AirdropKeeper), dfract.NewAppModule(appCodec, *app.DFractKeeper), + millions.NewAppModule(appCodec, *app.MillionsKeeper), + icacallbacks.NewAppModule(appCodec, *app.ICACallbacksKeeper, app.AccountKeeper, app.BankKeeper), + icqueries.NewAppModule(appCodec, *app.ICQueriesKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -310,9 +338,12 @@ func New( paramstypes.ModuleName, vestingtypes.ModuleName, ibctransfertypes.ModuleName, + icqueriestypes.ModuleName, + icacallbackstypes.ModuleName, beamtypes.ModuleName, airdroptypes.ModuleName, dfracttypes.ModuleName, + millionstypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -335,9 +366,12 @@ func New( ibchost.ModuleName, icatypes.ModuleName, ibctransfertypes.ModuleName, + icqueriestypes.ModuleName, + icacallbackstypes.ModuleName, beamtypes.ModuleName, airdroptypes.ModuleName, dfracttypes.ModuleName, + millionstypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -365,9 +399,12 @@ func New( paramstypes.ModuleName, vestingtypes.ModuleName, authz.ModuleName, + icqueriestypes.ModuleName, + icacallbackstypes.ModuleName, beamtypes.ModuleName, airdroptypes.ModuleName, dfracttypes.ModuleName, + millionstypes.ModuleName, ) app.mm.RegisterInvariants(app.CrisisKeeper) @@ -393,6 +430,7 @@ func New( authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), beam.NewAppModule(appCodec, *app.BeamKeeper), dfract.NewAppModule(appCodec, *app.DFractKeeper), + millions.NewAppModule(appCodec, *app.MillionsKeeper), ) app.sm.RegisterStoreDecoders() @@ -428,6 +466,35 @@ func New( // Name returns the name of the App func (app *App) Name() string { return app.BaseApp.Name() } +// GetBaseApp returns the base app of the application +func (app *App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } + +// GetStakingKeeper implements the TestingApp interface. +func (app *App) GetStakingKeeper() ibctestingtypes.StakingKeeper { + return *app.StakingKeeper +} + +// GetTransferKeeper implements the TestingApp interface. +func (app *App) GetTransferKeeper() *ibctransferkeeper.Keeper { + return app.TransferKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *App) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.ScopedIBCKeeper +} + +// GetTxConfig implements the TestingApp interface. +func (app *App) GetTxConfig() client.TxConfig { + cfg := MakeEncodingConfig() + return cfg.TxConfig +} + // BeginBlocker application updates every begin block func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { return app.mm.BeginBlock(ctx, req) @@ -465,14 +532,7 @@ func (app *App) ModuleAccountAddrs() map[string]bool { // BlockedModuleAccountAddrs returns all the app's blocked module account addresses func (app *App) BlockedModuleAccountAddrs() map[string]bool { - // By default no one can receive funds - modAccAddrs := app.ModuleAccountAddrs() - - // Remove module accounts that are ALLOWED to receive funds - delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - delete(modAccAddrs, authtypes.NewModuleAddress(beamtypes.ModuleName).String()) - delete(modAccAddrs, authtypes.NewModuleAddress(dfracttypes.ModuleName).String()) - + modAccAddrs := make(map[string]bool) return modAccAddrs } @@ -648,10 +708,43 @@ func (app *App) registerUpgradeHandlers() { return app.mm.RunMigrations(ctx, app.configurator, fromVM) }) - app.UpgradeKeeper.SetUpgradeHandler("v1.3.1", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Apply the new dfract params map - app.DFractKeeper.SetParams(ctx, dfracttypes.DefaultParams()) - app.Logger().Info("v1.3.1 upgrade applied") + app.UpgradeKeeper.SetUpgradeHandler("v1.4.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // Get the actual params + icaHostParams := app.ICAHostKeeper.GetParams(ctx) + + // Patch the parameters - Enable the controller and patch the allowed messages for host + icaControllerParams := icacontrollertypes.Params{ + ControllerEnabled: true, + } + icaHostParams.AllowMessages = append(icaHostParams.AllowMessages, + // Change: added dfract and millions messages + sdk.MsgTypeURL(&dfracttypes.MsgDeposit{}), + sdk.MsgTypeURL(&millionstypes.MsgDeposit{}), + sdk.MsgTypeURL(&millionstypes.MsgDepositRetry{}), + sdk.MsgTypeURL(&millionstypes.MsgClaimPrize{}), + sdk.MsgTypeURL(&millionstypes.MsgWithdrawDeposit{}), + sdk.MsgTypeURL(&millionstypes.MsgWithdrawDepositRetry{}), + sdk.MsgTypeURL(&millionstypes.MsgDrawRetry{}), + ) + + // Apply patched parameters + app.ICAHostKeeper.SetParams(ctx, icaHostParams) + app.ICAControllerKeeper.SetParams(ctx, icaControllerParams) + + // Set the ICA Callbacks, ICQueries and Millions modules versions so InitGenesis is not run + fromVM[icacallbackstypes.ModuleName] = app.mm.Modules[icacallbackstypes.ModuleName].ConsensusVersion() + fromVM[icqueriestypes.ModuleName] = app.mm.Modules[icqueriestypes.ModuleName].ConsensusVersion() + fromVM[millionstypes.ModuleName] = app.mm.Modules[millionstypes.ModuleName].ConsensusVersion() + + // Apply initial millions state + genState := millionstypes.DefaultGenesisState() + app.MillionsKeeper.SetParams(ctx, genState.Params) + app.MillionsKeeper.SetNextPoolID(ctx, genState.NextPoolId) + app.MillionsKeeper.SetNextDepositID(ctx, genState.NextDepositId) + app.MillionsKeeper.SetNextPrizeID(ctx, genState.NextPrizeId) + app.MillionsKeeper.SetNextWithdrawalID(ctx, genState.NextWithdrawalId) + + app.Logger().Info("v1.4.0 upgrade applied: Millions module enabled and ICA configuration updated.") return app.mm.RunMigrations(ctx, app.configurator, fromVM) }) @@ -697,4 +790,12 @@ func (app *App) registerUpgradeHandlers() { } app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } + + if upgradeInfo.Name == "v1.4.0" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + // We create 3 new modules: ICA Callbacks, ICQueries, Millions + storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{icacallbackstypes.StoreKey, icqueriestypes.StoreKey, millionstypes.StoreKey}, + } + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } } diff --git a/app/export.go b/app/export.go index 5b73164b..72221573 100644 --- a/app/export.go +++ b/app/export.go @@ -108,13 +108,16 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) app.DistrKeeper.SetFeePool(ctx, feePool) + //nolint:errcheck app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) return false }) // reinitialize all delegations for _, del := range dels { + //nolint:errcheck app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + //nolint:errcheck app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) } diff --git a/app/keepers.go b/app/keepers.go index cd54cc3e..d83ef369 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -38,6 +38,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + icacontroller "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" icahost "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" @@ -58,6 +61,13 @@ import ( "github.com/lum-network/chain/x/dfract" dfractkeeper "github.com/lum-network/chain/x/dfract/keeper" dfracttypes "github.com/lum-network/chain/x/dfract/types" + icacallbackskeeper "github.com/lum-network/chain/x/icacallbacks/keeper" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + icquerieskeeper "github.com/lum-network/chain/x/icqueries/keeper" + icqueriestypes "github.com/lum-network/chain/x/icqueries/types" + "github.com/lum-network/chain/x/millions" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" ) type AppKeepers struct { @@ -68,30 +78,37 @@ type AppKeepers struct { UpgradeKeeper *upgradekeeper.Keeper // make scoped keepers public for test purposes - ScopedIBCKeeper capabilitykeeper.ScopedKeeper - ScopedICAHostKeeper capabilitykeeper.ScopedKeeper - ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedICAHostKeeper capabilitykeeper.ScopedKeeper + ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper + ScopedICACallbacksKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedMillionsKeeper capabilitykeeper.ScopedKeeper // Normal Keepers - AccountKeeper *authkeeper.AccountKeeper - BankKeeper *bankkeeper.BaseKeeper - AuthzKeeper *authzkeeper.Keeper - StakingKeeper *stakingkeeper.Keeper - DistrKeeper *distrkeeper.Keeper - SlashingKeeper *slashingkeeper.Keeper - IBCKeeper *ibckeeper.Keeper - IBCFeeKeeper ibcfeekeeper.Keeper - ICAHostKeeper *icahostkeeper.Keeper - TransferKeeper *ibctransferkeeper.Keeper - EvidenceKeeper *evidencekeeper.Keeper - MintKeeper *mintkeeper.Keeper - GovKeeper *govkeeper.Keeper - FeeGrantKeeper *feegrantkeeper.Keeper + AccountKeeper *authkeeper.AccountKeeper + BankKeeper *bankkeeper.BaseKeeper + AuthzKeeper *authzkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + DistrKeeper *distrkeeper.Keeper + SlashingKeeper *slashingkeeper.Keeper + IBCKeeper *ibckeeper.Keeper + IBCFeeKeeper *ibcfeekeeper.Keeper + ICAHostKeeper *icahostkeeper.Keeper + ICAControllerKeeper *icacontrollerkeeper.Keeper + TransferKeeper *ibctransferkeeper.Keeper + EvidenceKeeper *evidencekeeper.Keeper + MintKeeper *mintkeeper.Keeper + GovKeeper *govkeeper.Keeper + FeeGrantKeeper *feegrantkeeper.Keeper // Custom Keepers - AirdropKeeper *airdropkeeper.Keeper - BeamKeeper *beamkeeper.Keeper - DFractKeeper *dfractkeeper.Keeper + ICACallbacksKeeper *icacallbackskeeper.Keeper + ICQueriesKeeper *icquerieskeeper.Keeper + AirdropKeeper *airdropkeeper.Keeper + BeamKeeper *beamkeeper.Keeper + DFractKeeper *dfractkeeper.Keeper + MillionsKeeper *millionskeeper.Keeper } // InitSpecialKeepers Init the "special" keepers in the order of definition @@ -118,8 +135,11 @@ func (app *App) InitSpecialKeepers( // Add capability keeper and ScopeToModule for ibc module app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) app.ScopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + app.ScopedICAControllerKeeper = app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) app.ScopedICAHostKeeper = app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) + app.ScopedICACallbacksKeeper = app.CapabilityKeeper.ScopeToModule(icacallbackstypes.ModuleName) app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + app.ScopedMillionsKeeper = app.CapabilityKeeper.ScopeToModule(millionstypes.ModuleName) app.CapabilityKeeper.Seal() // Init the crisis keeper @@ -129,7 +149,14 @@ func (app *App) InitSpecialKeepers( app.CrisisKeeper = &crisisKeeper // Initialize the upgrade keeper - upgradeKeeper := upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, baseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + upgradeKeeper := upgradekeeper.NewKeeper( + skipUpgradeHeights, + keys[upgradetypes.StoreKey], + appCodec, + homePath, + baseApp, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) app.UpgradeKeeper = &upgradeKeeper // Register the upgrade handlers @@ -143,7 +170,14 @@ func (app *App) InitNormalKeepers() { keys := app.keys // Initialize the account keeper - accountKeeper := authkeeper.NewAccountKeeper(appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, AccountAddressPrefix) + accountKeeper := authkeeper.NewAccountKeeper( + appCodec, + keys[authtypes.StoreKey], + app.GetSubspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, + maccPerms, + AccountAddressPrefix, + ) app.AccountKeeper = &accountKeeper // Initialize the bank keeper @@ -178,39 +212,72 @@ func (app *App) InitNormalKeepers() { // Initialize the distribution keeper distrKeeper := distrkeeper.NewKeeper( appCodec, keys[distrtypes.StoreKey], - app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - app.StakingKeeper, authtypes.FeeCollectorName, + app.GetSubspace(distrtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, + authtypes.FeeCollectorName, ) app.DistrKeeper = &distrKeeper // Initialize the slashing keeper slashingKeeper := slashingkeeper.NewKeeper( - appCodec, keys[slashingtypes.StoreKey], app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), + appCodec, + keys[slashingtypes.StoreKey], + app.StakingKeeper, + app.GetSubspace(slashingtypes.ModuleName), ) app.SlashingKeeper = &slashingKeeper // Initialize the IBC Keeper app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, app.ScopedIBCKeeper, + appCodec, + keys[ibchost.StoreKey], + app.GetSubspace(ibchost.ModuleName), + app.StakingKeeper, + app.UpgradeKeeper, + app.ScopedIBCKeeper, ) // Initialize the IBC Fee keeper - app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( - appCodec, app.keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), + ibcFeeKeeper := ibcfeekeeper.NewKeeper( + appCodec, + app.keys[ibcfeetypes.StoreKey], + app.GetSubspace(ibcfeetypes.ModuleName), app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, ) + app.IBCFeeKeeper = &ibcFeeKeeper // Initialize the IBC transfer keeper transferKeeper := ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper, + appCodec, + keys[ibctransfertypes.StoreKey], + app.GetSubspace(ibctransfertypes.ModuleName), + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + app.ScopedTransferKeeper, ) app.TransferKeeper = &transferKeeper app.transferModule = transfer.NewAppModule(*app.TransferKeeper) - transferIBCModule := transfer.NewIBCModule(*app.TransferKeeper) + + // Initialize the ICA controller keeper + icaControllerKeeper := icacontrollerkeeper.NewKeeper( + appCodec, keys[icacontrollertypes.StoreKey], + app.GetSubspace(icacontrollertypes.SubModuleName), + app.IBCFeeKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.ScopedICAControllerKeeper, + app.MsgServiceRouter(), + ) + app.ICAControllerKeeper = &icaControllerKeeper // Initialize the ICA host keeper icaHostKeeper := icahostkeeper.NewKeeper( @@ -224,41 +291,137 @@ func (app *App) InitNormalKeepers() { app.MsgServiceRouter(), ) app.ICAHostKeeper = &icaHostKeeper - icaHostIBCModule := icahost.NewIBCModule(*app.ICAHostKeeper) - - // Create static IBC router, add transfer route, then set and seal it - ibcRouter := porttypes.NewRouter() - ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).AddRoute(ibctransfertypes.ModuleName, transferIBCModule) - app.IBCKeeper.SetRouter(ibcRouter) // Initialize the evidence keeper - app.EvidenceKeeper = evidencekeeper.NewKeeper(appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper) + app.EvidenceKeeper = evidencekeeper.NewKeeper( + appCodec, + keys[evidencetypes.StoreKey], + app.StakingKeeper, + app.SlashingKeeper, + ) // Initialize the mint keeper mintKeeper := mintkeeper.NewKeeper( - appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), app.StakingKeeper, - app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, + appCodec, + keys[minttypes.StoreKey], + app.GetSubspace(minttypes.ModuleName), + app.StakingKeeper, + app.AccountKeeper, + app.BankKeeper, + authtypes.FeeCollectorName, ) app.MintKeeper = &mintKeeper // Initialize the fee grant keeper - feeGrantKeeper := feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) + feeGrantKeeper := feegrantkeeper.NewKeeper( + appCodec, + keys[feegrant.StoreKey], + app.AccountKeeper, + ) app.FeeGrantKeeper = &feeGrantKeeper + // Initialize our ICA callbacks keeper + app.ICACallbacksKeeper = icacallbackskeeper.NewKeeper( + appCodec, + keys[icacallbackstypes.StoreKey], + keys[icacallbackstypes.MemStoreKey], + app.GetSubspace(icacallbackstypes.ModuleName), + app.ScopedICACallbacksKeeper, + *app.IBCKeeper, + *app.ICAControllerKeeper, + ) + + // Initialize our ICQueries keeper + app.ICQueriesKeeper = icquerieskeeper.NewKeeper(appCodec, keys[icqueriestypes.StoreKey], app.IBCKeeper) + // Initialize our custom beam keeper - beamKeeper := *beamkeeper.NewKeeper( - appCodec, keys[beamtypes.StoreKey], keys[beamtypes.MemStoreKey], - *app.AccountKeeper, app.BankKeeper, *app.StakingKeeper, + app.BeamKeeper = beamkeeper.NewKeeper( + appCodec, + keys[beamtypes.StoreKey], + keys[beamtypes.MemStoreKey], + *app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, ) - app.BeamKeeper = &beamKeeper // Initialize our custom airdrop keeper - airdropKeeper := airdropkeeper.NewKeeper(appCodec, keys[airdroptypes.StoreKey], keys[airdroptypes.MemStoreKey], *app.AccountKeeper, app.BankKeeper, *app.StakingKeeper, *app.DistrKeeper) - app.AirdropKeeper = airdropKeeper + app.AirdropKeeper = airdropkeeper.NewKeeper( + appCodec, + keys[airdroptypes.StoreKey], + keys[airdroptypes.MemStoreKey], + *app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, + app.DistrKeeper, + ) // Initialize our custom dfract keeper - dfractKeeper := dfractkeeper.NewKeeper(appCodec, keys[dfracttypes.StoreKey], keys[dfracttypes.StoreKey], app.GetSubspace(dfracttypes.ModuleName), *app.AccountKeeper, app.BankKeeper, *app.StakingKeeper) - app.DFractKeeper = dfractKeeper + app.DFractKeeper = dfractkeeper.NewKeeper( + appCodec, + keys[dfracttypes.StoreKey], + keys[dfracttypes.StoreKey], + app.GetSubspace(dfracttypes.ModuleName), + *app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, + ) + + // Initialize our custom millions keeper + app.MillionsKeeper = millionskeeper.NewKeeper( + appCodec, + keys[millionstypes.StoreKey], + app.GetSubspace(millionstypes.ModuleName), + app.ScopedMillionsKeeper, + *app.AccountKeeper, + *app.IBCKeeper, + *app.TransferKeeper, + *app.ICAControllerKeeper, + *app.ICACallbacksKeeper, + *app.ICQueriesKeeper, + app.BankKeeper, + app.DistrKeeper, + app.StakingKeeper, + ) + + // First stack contains + // - Transfer IBC Module + // - Millions IBC middleware + // - base app + transferIBCModule := transfer.NewIBCModule(*app.TransferKeeper) + transferStack := millions.NewIBCMiddleware(*app.MillionsKeeper, transferIBCModule) + + // Second stack contains + // - ICAHost IBC Module + // - base app + icaHostIBCModule := icahost.NewIBCModule(*app.ICAHostKeeper) + + // Third stack contains + // - Millions IBC Module + // - ICAController IBC Middleware + // - base app + millionsIBCModule := millions.NewIBCModule(*app.MillionsKeeper) + icaControllerIBCModule := icacontroller.NewIBCMiddleware(millionsIBCModule, *app.ICAControllerKeeper) + + // Register our ICACallbacks handlers + err := app.ICACallbacksKeeper.SetICACallbackHandler(millionstypes.ModuleName, app.MillionsKeeper.ICACallbackHandler()) + if err != nil { + panic(err) + } + + // Register our ICQueries handlers + err = app.ICQueriesKeeper.SetCallbackHandler(millionstypes.ModuleName, app.MillionsKeeper.ICQCallbackHandler()) + if err != nil { + panic(err) + } + + // Create static IBC router, then seal it + ibcRouter := porttypes.NewRouter() + ibcRouter. + AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). + AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule). + AddRoute(millionstypes.ModuleName, icaControllerIBCModule). + AddRoute(ibctransfertypes.ModuleName, transferStack) + app.IBCKeeper.SetRouter(ibcRouter) // Initialize the governance router govRouter := govtypesv1beta1.NewRouter() @@ -268,7 +431,8 @@ func (app *App) InitNormalKeepers() { AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(*app.UpgradeKeeper)). AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(dfracttypes.RouterKey, dfract.NewDFractProposalHandler(*app.DFractKeeper)) + AddRoute(dfracttypes.RouterKey, dfract.NewDFractProposalHandler(*app.DFractKeeper)). + AddRoute(millionstypes.RouterKey, millions.NewMillionsProposalHandler(*app.MillionsKeeper)) // Initialize the governance keeper govConfig := govtypes.DefaultConfig() @@ -293,6 +457,7 @@ func (app *App) SetupHooks() { func (app *App) InitParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + // Base modules paramsKeeper.Subspace(authtypes.ModuleName) paramsKeeper.Subspace(banktypes.ModuleName) paramsKeeper.Subspace(stakingtypes.ModuleName) @@ -303,12 +468,17 @@ func (app *App) InitParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec. paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(feegrant.ModuleName) paramsKeeper.Subspace(authz.ModuleName) + // Custom modules + paramsKeeper.Subspace(icacallbackstypes.ModuleName) + paramsKeeper.Subspace(icqueriestypes.ModuleName) paramsKeeper.Subspace(beamtypes.ModuleName) paramsKeeper.Subspace(dfracttypes.ModuleName) + paramsKeeper.Subspace(millionstypes.ModuleName) return paramsKeeper } diff --git a/app/params/config.go b/app/params/config.go index be75fc66..4218d576 100644 --- a/app/params/config.go +++ b/app/params/config.go @@ -1,8 +1,9 @@ package params import ( - serverconfig "github.com/cosmos/cosmos-sdk/server/config" "strings" + + serverconfig "github.com/cosmos/cosmos-sdk/server/config" ) func CustomConfigTemplate() string { diff --git a/app/prefix.go b/app/prefix.go index 16309702..d74cae13 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -24,6 +24,7 @@ func SetConfig() { config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix) config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix) config.SetCoinType(CoinType) + //nolint:staticcheck config.SetFullFundraiserPath("m/44'/880'/0'/0/0") config.Seal() } diff --git a/app/pubkey_replacement.go b/app/pubkey_replacement.go deleted file mode 100644 index faf0af22..00000000 --- a/app/pubkey_replacement.go +++ /dev/null @@ -1,122 +0,0 @@ -package app - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "log" - - "github.com/cosmos/cosmos-sdk/client" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" - "github.com/cosmos/cosmos-sdk/x/genutil/types" - slashing "github.com/cosmos/cosmos-sdk/x/slashing/types" - staking "github.com/cosmos/cosmos-sdk/x/staking/types" - cryptocodec "github.com/tendermint/tendermint/crypto/encoding" - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/pkg/errors" -) - -type replacementConfigs []replacementConfig - -func (r *replacementConfigs) isReplacedValidator(validatorAddress string) (int, replacementConfig) { - for i, replacement := range *r { - if replacement.ValidatorAddress == validatorAddress { - return i, replacement - } - } - - return -1, replacementConfig{} -} - -type replacementConfig struct { - Name string `json:"validator_name"` - ValidatorAddress string `json:"validator_address"` - ConsensusPubkey string `json:"stargate_consensus_public_key"` -} - -func loadKeydataFromFile(clientCtx client.Context, replacementrJSON string, genDoc *tmtypes.GenesisDoc) *tmtypes.GenesisDoc { - jsonReplacementBlob, err := ioutil.ReadFile(replacementrJSON) - if err != nil { - log.Fatal(errors.Wrapf(err, "failed to read replacement keys from file %s", replacementrJSON)) - } - - var replacementKeys replacementConfigs - - err = json.Unmarshal(jsonReplacementBlob, &replacementKeys) - - if err != nil { - log.Fatal("Could not unmarshal replacement keys ") - } - - var state types.AppMap - if err := json.Unmarshal(genDoc.AppState, &state); err != nil { - log.Fatal(errors.Wrap(err, "failed to JSON unmarshal initial genesis state")) - } - - var ( - stakingGenesis staking.GenesisState - slashingGenesis slashing.GenesisState - ) - - clientCtx.Codec.MustUnmarshalJSON(state[staking.ModuleName], &stakingGenesis) - clientCtx.Codec.MustUnmarshalJSON(state[slashing.ModuleName], &slashingGenesis) - - for i, val := range stakingGenesis.Validators { - idx, replacement := replacementKeys.isReplacedValidator(val.OperatorAddress) - - if idx != -1 { - toReplaceValConsAddress, _ := val.GetConsAddr() - - // nolint - consPubKey, err := legacybech32.UnmarshalPubKey(legacybech32.ConsPK, replacement.ConsensusPubkey) - if err != nil { - log.Fatal(fmt.Errorf("failed to decode key:%s %w", consPubKey, err)) - } - - val.ConsensusPubkey, err = codectypes.NewAnyWithValue(consPubKey) - if err != nil { - log.Fatal(fmt.Errorf("failed to decode key:%s %w", consPubKey, err)) - } - - replaceValConsAddress, _ := val.GetConsAddr() - protoReplaceValConsPubKey, _ := val.TmConsPublicKey() - replaceValConsPubKey, _ := cryptocodec.PubKeyFromProto(protoReplaceValConsPubKey) - - for i, signingInfo := range slashingGenesis.SigningInfos { - if signingInfo.Address == toReplaceValConsAddress.String() { - slashingGenesis.SigningInfos[i].Address = replaceValConsAddress.String() - slashingGenesis.SigningInfos[i].ValidatorSigningInfo.Address = replaceValConsAddress.String() - } - } - - for i, missedInfo := range slashingGenesis.MissedBlocks { - if missedInfo.Address == toReplaceValConsAddress.String() { - slashingGenesis.MissedBlocks[i].Address = replaceValConsAddress.String() - } - } - - for tmIdx, tmval := range genDoc.Validators { - if tmval.Address.String() == replaceValConsAddress.String() { - genDoc.Validators[tmIdx].Address = replaceValConsAddress.Bytes() - genDoc.Validators[tmIdx].PubKey = replaceValConsPubKey - - } - } - stakingGenesis.Validators[i] = val - - } - - } - state[staking.ModuleName] = clientCtx.Codec.MustMarshalJSON(&stakingGenesis) - state[slashing.ModuleName] = clientCtx.Codec.MustMarshalJSON(&slashingGenesis) - - genDoc.AppState, err = json.Marshal(state) - - if err != nil { - log.Fatal("Could not marshal App State") - } - return genDoc - -} diff --git a/app/test_helpers.go b/app/test_helpers.go index 8a60b602..958793f3 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -2,6 +2,10 @@ package app import ( "encoding/json" + "strings" + "time" + + "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -10,12 +14,17 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" + transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v5/testing" + "github.com/cosmos/ibc-go/v5/testing/simapp" + "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" - "time" ) // EmptyAppOptions is a stub implementing AppOptions @@ -26,6 +35,17 @@ func (ao EmptyAppOptions) Get(o string) interface{} { return nil } +var ( + LumChainID = "LUM-NETWORK" + TestIcaVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ + Version: icatypes.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, + })) +) + var DefaultConsensusParams = &abci.ConsensusParams{ Block: &abci.BlockParams{ MaxBytes: 200000, @@ -87,6 +107,12 @@ func SetupForTesting(isCheckTx bool) *App { return app } +// SetupForIBCTesting Configure the testing application and cast it as an IBC testing application +func SetupForIBCTesting() (ibctesting.TestingApp, map[string]json.RawMessage) { + app := SetupForTesting(false) + return app, NewDefaultGenesisState() +} + func GenesisStateWithValSet(app *App, genesisState GenesisState, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) GenesisState { validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators)) @@ -112,7 +138,6 @@ func GenesisStateWithValSet(app *App, genesisState GenesisState, valSet *tmtypes } validators = append(validators, validator) delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec())) - } // Initialize our delegations @@ -142,3 +167,192 @@ func GenesisStateWithValSet(app *App, genesisState GenesisState, valSet *tmtypes return genesisState } + +type TestPackage struct { + suite.Suite + App *App + HostApp *simapp.SimApp + + IbcEnabled bool + Coordinator *ibctesting.Coordinator + LumChain *ibctesting.TestChain + HostChain *ibctesting.TestChain + TransferPath *ibctesting.Path + + QueryHelper *baseapp.QueryServiceTestHelper + TestAccs []sdk.AccAddress + ICAAddresses map[string]string + Ctx sdk.Context +} + +func (p *TestPackage) Setup() { + p.App = SetupForTesting(false) + p.Ctx = p.App.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: LumChainID}) + p.QueryHelper = &baseapp.QueryServiceTestHelper{ + GRPCQueryRouter: p.App.GRPCQueryRouter(), + Ctx: p.Ctx, + } + p.IbcEnabled = false + p.ICAAddresses = make(map[string]string) +} + +// SetupIBC Initialize the IBC configuration for test environment +func (p *TestPackage) SetupIBC(hostChainID string) { + p.Coordinator = ibctesting.NewCoordinator(p.T(), 0) + + // Initialize a stride testing app by casting a LumApp -> TestingApp + ibctesting.DefaultTestingAppInit = SetupForIBCTesting + p.LumChain = ibctesting.NewTestChain(p.T(), p.Coordinator, LumChainID) + + // Initialize a host testing app using SimApp -> TestingApp + ibctesting.DefaultTestingAppInit = ibctesting.SetupTestingApp + p.HostChain = ibctesting.NewTestChain(p.T(), p.Coordinator, LumChainID) + + // Update coordinator + p.Coordinator.Chains = map[string]*ibctesting.TestChain{ + LumChainID: p.LumChain, + hostChainID: p.HostChain, + } + p.IbcEnabled = true +} + +// NewTransferPath Creates a transfer channel between two chains +func NewTransferPath(chainA *ibctesting.TestChain, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort + path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort + path.EndpointA.ChannelConfig.Order = channeltypes.UNORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.UNORDERED + path.EndpointA.ChannelConfig.Version = transfertypes.Version + path.EndpointB.ChannelConfig.Version = transfertypes.Version + return path +} + +// NewIcaPath Creates an ICA channel between two chains +func NewIcaPath(chainA *ibctesting.TestChain, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.ChannelConfig.PortID = icatypes.PortID + path.EndpointB.ChannelConfig.PortID = icatypes.PortID + path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointA.ChannelConfig.Version = TestIcaVersion + path.EndpointB.ChannelConfig.Version = TestIcaVersion + return path +} + +// CopyConnectionAndClientToPath +// In ibctesting, there's no easy way to create a new channel on an existing connection +// To get around this, this helper function will copy the client/connection info from an existing channel +// We use this when creating ICA channels, because we want to reuse the same connections/clients from the transfer channel +func CopyConnectionAndClientToPath(path *ibctesting.Path, pathToCopy *ibctesting.Path) *ibctesting.Path { + path.EndpointA.ClientID = pathToCopy.EndpointA.ClientID + path.EndpointB.ClientID = pathToCopy.EndpointB.ClientID + path.EndpointA.ConnectionID = pathToCopy.EndpointA.ConnectionID + path.EndpointB.ConnectionID = pathToCopy.EndpointB.ConnectionID + path.EndpointA.ClientConfig = pathToCopy.EndpointA.ClientConfig + path.EndpointB.ClientConfig = pathToCopy.EndpointB.ClientConfig + path.EndpointA.ConnectionConfig = pathToCopy.EndpointA.ConnectionConfig + path.EndpointB.ConnectionConfig = pathToCopy.EndpointB.ConnectionConfig + return path +} + +// CreateTransferChannel Creates clients, connections, and a transfer channel between Lum and a host chain +func (p *TestPackage) CreateTransferChannel(hostChainID string) { + // If we have yet to create the host chain, do that here + if !p.IbcEnabled { + p.SetupIBC(hostChainID) + } + + // Make sure the chain IDs are the same + p.Require().Equal(p.HostChain.ChainID, hostChainID, "The testing app has already been initialized with a different chainID (%s)", p.HostChain.ChainID) + + // Create clients, connections, and a transfer channel + p.TransferPath = NewTransferPath(p.LumChain, p.HostChain) + p.Coordinator.Setup(p.TransferPath) + + // Replace stride and host apps with those from TestingApp + p.App = p.LumChain.App.(*App) + p.HostApp = p.HostChain.GetSimApp() + p.Ctx = p.LumChain.GetContext() + + // Finally confirm the channel was configured properly + p.Require().Equal(ibctesting.FirstClientID, p.TransferPath.EndpointA.ClientID, "lum clientID") + p.Require().Equal(ibctesting.FirstConnectionID, p.TransferPath.EndpointA.ConnectionID, "lum connectionID") + p.Require().Equal(ibctesting.FirstChannelID, p.TransferPath.EndpointA.ChannelID, "lum transfer channelID") + + p.Require().Equal(ibctesting.FirstClientID, p.TransferPath.EndpointB.ClientID, "host clientID") + p.Require().Equal(ibctesting.FirstConnectionID, p.TransferPath.EndpointB.ConnectionID, "host connectionID") + p.Require().Equal(ibctesting.FirstChannelID, p.TransferPath.EndpointB.ChannelID, "host transfer channelID") +} + +// CreateICAChannel Creates an ICA channel through ibctesting, also creates a transfer channel if it hasn't been done yet +func (p *TestPackage) CreateICAChannel(owner string) string { + // If we have yet to create a client/connection (through creating a transfer channel), do that here + _, transferChannelExists := p.App.IBCKeeper.ChannelKeeper.GetChannel(p.Ctx, ibctesting.TransferPort, ibctesting.FirstChannelID) + if !transferChannelExists { + ownerSplit := strings.Split(owner, ".") + p.Require().Equal(2, len(ownerSplit), "owner should be of the form: {HostZone}.{AccountName}") + + hostChainID := ownerSplit[0] + p.CreateTransferChannel(hostChainID) + } + + // Create ICA Path and then copy over the client and connection from the transfer path + icaPath := NewIcaPath(p.LumChain, p.HostChain) + icaPath = CopyConnectionAndClientToPath(icaPath, p.TransferPath) + + // Register the ICA and complete the handshake + p.RegisterInterchainAccount(icaPath.EndpointA, owner) + + // Try to open the channel + err := icaPath.EndpointB.ChanOpenTry() + p.Require().NoError(err, "ChanOpenTry error") + + // Try to acknowledge channel opening + err = icaPath.EndpointA.ChanOpenAck() + p.Require().NoError(err, "ChanOpenAck error") + + // Try to confirm opening + err = icaPath.EndpointB.ChanOpenConfirm() + p.Require().NoError(err, "ChanOpenConfirm error") + + // Acquire the context from controller chain + p.Ctx = p.LumChain.GetContext() + + // Confirm the ICA channel was created properly + portID := icaPath.EndpointA.ChannelConfig.PortID + channelID := icaPath.EndpointA.ChannelID + _, found := p.App.IBCKeeper.ChannelKeeper.GetChannel(p.Ctx, portID, channelID) + p.Require().True(found, "Channel not found after creation, PortID: %s, ChannelID: %s", portID, channelID) + + // Store the account address + icaAddress, found := p.App.ICAControllerKeeper.GetInterchainAccountAddress(p.Ctx, ibctesting.FirstConnectionID, portID) + p.Require().True(found, "can't get ICA address") + p.ICAAddresses[owner] = icaAddress + + // Finally set the active channel + p.App.ICAControllerKeeper.SetActiveChannelID(p.Ctx, ibctesting.FirstConnectionID, portID, channelID) + return channelID +} + +// RegisterInterchainAccount Register's a new ICA account on the next channel available, this function assumes a connection already exists +func (p *TestPackage) RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) { + // Get the port ID from the owner name (i.e. "icacontroller-{owner}") + portID, err := icatypes.NewControllerPortID(owner) + p.Require().NoError(err, "owner to portID error") + + // Get the next channel available and register the ICA + channelSequence := p.App.IBCKeeper.ChannelKeeper.GetNextChannelSequence(p.Ctx) + + // Register the ICA account + err = p.App.ICAControllerKeeper.RegisterInterchainAccount(p.Ctx, endpoint.ConnectionID, owner, TestIcaVersion) + p.Require().NoError(err, "register interchain account error") + + // Commit the state + endpoint.Chain.App.Commit() + endpoint.Chain.NextBlock() + + // Update the endpoint object to the newly created port + channel + endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) + endpoint.ChannelConfig.PortID = portID +} diff --git a/app/testing/helpers.go b/app/testing/helpers.go index 4bd99553..8eefd26c 100644 --- a/app/testing/helpers.go +++ b/app/testing/helpers.go @@ -3,16 +3,19 @@ package testing import ( "bytes" "fmt" + "strconv" + + "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/lum-network/chain/app" - "strconv" ) // AddTestAddrs constructs and returns accNum amount of accounts with an // initial balance of accAmt in random order -func AddTestAddrsIncremental(app *app.App, ctx sdk.Context, accNum int, accAmt sdk.Int) []sdk.AccAddress { +func AddTestAddrsIncremental(app *app.App, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { return addTestAddrs(app, ctx, accNum, accAmt, createIncrementalAccounts) } @@ -59,17 +62,22 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress { return addresses } +func AddTestModuleAccount(app *app.App, ctx sdk.Context, addr sdk.AccAddress) { + acc := app.AccountKeeper.NewAccount(ctx, authtypes.NewModuleAccount(authtypes.NewBaseAccountWithAddress(addr), addr.String())) + app.AccountKeeper.SetAccount(ctx, acc) +} + // AddTestAddrs constructs and returns accNum amount of accounts with an // initial balance of accAmt in random order -func AddTestAddrs(app *app.App, ctx sdk.Context, accNum int, accAmt sdk.Int) []sdk.AccAddress { +func AddTestAddrs(app *app.App, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { return addTestAddrs(app, ctx, accNum, accAmt, createRandomAccounts) } -func AddTestAddrsWithDenom(app *app.App, ctx sdk.Context, accNum int, accAmt sdk.Int, denom string) []sdk.AccAddress { +func AddTestAddrsWithDenom(app *app.App, ctx sdk.Context, accNum int, accAmt math.Int, denom string) []sdk.AccAddress { return addTestAddrsWithDenom(app, ctx, accNum, accAmt, denom, createRandomAccounts) } -func addTestAddrsWithDenom(app *app.App, ctx sdk.Context, accNum int, accAmt sdk.Int, denom string, strategy GenerateAccountStrategy) []sdk.AccAddress { +func addTestAddrsWithDenom(app *app.App, ctx sdk.Context, accNum int, accAmt math.Int, denom string, strategy GenerateAccountStrategy) []sdk.AccAddress { testAddrs := strategy(accNum) initCoins := sdk.NewCoins(sdk.NewCoin(denom, accAmt)) @@ -81,7 +89,7 @@ func addTestAddrsWithDenom(app *app.App, ctx sdk.Context, accNum int, accAmt sdk return testAddrs } -func addTestAddrs(app *app.App, ctx sdk.Context, accNum int, accAmt sdk.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { +func addTestAddrs(app *app.App, ctx sdk.Context, accNum int, accAmt math.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { testAddrs := strategy(accNum) initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt)) diff --git a/cmd/lumd/cmd/genaccounts.go b/cmd/lumd/cmd/genaccounts.go index 8d2ae368..93e62b1b 100644 --- a/cmd/lumd/cmd/genaccounts.go +++ b/cmd/lumd/cmd/genaccounts.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -40,8 +39,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - depCdc := clientCtx.Codec - cdc := depCdc.(codec.Codec) + cdc := clientCtx.Codec serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config @@ -160,7 +158,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa appState[authtypes.ModuleName] = authGenStateBz - bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState) + bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState) bankGenState.Balances = append(bankGenState.Balances, balances) bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances) diff --git a/cmd/lumd/cmd/root.go b/cmd/lumd/cmd/root.go index 7f0f0403..f592670a 100644 --- a/cmd/lumd/cmd/root.go +++ b/cmd/lumd/cmd/root.go @@ -2,11 +2,12 @@ package cmd import ( "context" - "github.com/cosmos/cosmos-sdk/client/config" "io" "os" "path/filepath" + "github.com/cosmos/cosmos-sdk/client/config" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/snapshots" "github.com/lum-network/chain/app/params" @@ -219,6 +220,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty } snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") + //nolint:staticcheck snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir) if err != nil { panic(err) @@ -277,6 +279,7 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) { set := func(s *pflag.FlagSet, key, val string) { if f := s.Lookup(key); f != nil { f.DefValue = val + //nolint:errcheck f.Value.Set(val) } } diff --git a/config.yml b/config.yml index f48de6a0..5843c20f 100644 --- a/config.yml +++ b/config.yml @@ -1,12 +1,17 @@ version: 1 accounts: - name: user1 - coins: ["120000000000ulum"] + coins: ["120000000000ulum", 100000000000uatom] - name: user2 coins: ["100ulum"] + - name: relayer + coins: ["100000000ulum"] + mnemonic: "poem accuse sport census donor curious panther mean debris swap wire skin impose gym pretty dinosaur forget output dad steel venture farm gym pill" validators: - name: user1 bonded: "100000000ulum" + app: + pruning: "nothing" genesis: chain_id: "lumnetwork-testnet" app_state: @@ -21,11 +26,24 @@ genesis: bond_denom: "ulum" gov: deposit_params: - min_deposit: [{"amount": "1000000000", "denom": "ulum"}] + min_deposit: [{ "amount": "10000", "denom": "ulum" }] + max_deposit_period: "180s" + voting_params: + voting_period: "180s" dfract: params: min_deposit_amount: "1" - deposit_denom: "ulum" + deposit_denoms: ["ulum"] + millions: + params: + min_deposit_amount: "1000" + max_prize_strategy_batches: 100 + max_prize_batch_quantity: 1000 + min_draw_schedule_delta: "1h" + max_draw_schedule_delta: "8784h" # 366days + prize_expiration_delta: "720h" # 30days + fees_stakers: "0.10" + min_deposit_draw_delta: "60s" faucet: name: user1 coins: ["10ulum"] diff --git a/go.mod b/go.mod index f1e935f2..30f20410 100644 --- a/go.mod +++ b/go.mod @@ -3,35 +3,36 @@ module github.com/lum-network/chain go 1.18 require ( - github.com/cosmos/cosmos-proto v1.0.0-alpha7 + cosmossdk.io/errors v1.0.0-beta.7 + cosmossdk.io/math v1.0.0-beta.3 + github.com/Stride-Labs/stride/v6 v6.0.0 + github.com/cosmos/cosmos-proto v1.0.0-alpha8 github.com/cosmos/cosmos-sdk v0.46.7 - github.com/cosmos/gogoproto v1.4.2 - github.com/cosmos/ibc-go/v5 v5.0.1 + github.com/cosmos/ibc-go/v5 v5.1.0 github.com/gogo/protobuf v1.3.3 - github.com/golang/protobuf v1.5.2 + github.com/golang/protobuf v1.5.3 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 github.com/spf13/cast v1.5.0 - github.com/spf13/cobra v1.6.0 + github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.34.24 github.com/tendermint/tm-db v0.6.7 - google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 - google.golang.org/grpc v1.50.1 + google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 + google.golang.org/grpc v1.53.0 + google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 + gopkg.in/yaml.v2 v2.4.0 ) require ( - cloud.google.com/go v0.105.0 // indirect - cloud.google.com/go/compute v1.12.1 // indirect - cloud.google.com/go/compute/metadata v0.2.1 // indirect - cloud.google.com/go/iam v0.7.0 // indirect + cloud.google.com/go v0.107.0 // indirect + cloud.google.com/go/compute v1.18.0 // indirect + cloud.google.com/go/compute/metadata v0.2.3 // indirect + cloud.google.com/go/iam v0.11.0 // indirect cloud.google.com/go/storage v1.27.0 // indirect - cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/math v1.0.0-beta.3 // indirect filippo.io/edwards25519 v1.0.0-rc.1 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -45,7 +46,7 @@ require ( github.com/btcsuite/btcd v0.22.1 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect - github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect github.com/confio/ics23/go v0.9.0 // indirect @@ -78,8 +79,8 @@ require ( github.com/google/go-cmp v0.5.9 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect - github.com/googleapis/gax-go/v2 v2.6.0 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect + github.com/googleapis/gax-go/v2 v2.7.0 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -115,6 +116,7 @@ require ( github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect @@ -136,20 +138,18 @@ require ( github.com/zondax/hid v0.9.1 // indirect github.com/zondax/ledger-go v0.14.0 // indirect go.etcd.io/bbolt v1.3.6 // indirect - go.opencensus.io v0.23.0 // indirect + go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.2.0 // indirect golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect - golang.org/x/net v0.2.0 // indirect - golang.org/x/oauth2 v0.2.0 // indirect - golang.org/x/sys v0.2.0 // indirect - golang.org/x/term v0.2.0 // indirect - golang.org/x/text v0.4.0 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/oauth2 v0.5.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/term v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect - google.golang.org/api v0.102.0 // indirect + google.golang.org/api v0.110.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect sigs.k8s.io/yaml v1.3.0 // indirect diff --git a/go.sum b/go.sum index f03f30e3..334568ed 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHOb cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY= -cloud.google.com/go v0.105.0 h1:DNtEKRBAAzeS4KyIory52wWHuClNaXJ5x1F7xa4q+5Y= -cloud.google.com/go v0.105.0/go.mod h1:PrLgOJNe5nfE9UMxKxgXj4mD3voiP+YQ6gdt6KMFOKM= +cloud.google.com/go v0.107.0 h1:qkj22L7bgkl6vIeZDlOY2po43Mx/TIa2Wsa7VR+PEww= +cloud.google.com/go v0.107.0/go.mod h1:wpc2eNrD7hXUTy8EKS10jkxpZBjASrORK7goS+3YX2I= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -28,14 +28,14 @@ cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUM cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/bigtable v1.2.0/go.mod h1:JcVAOl45lrTmQfLj7T6TxyMzIN/3FGGcFm+2xVAli2o= -cloud.google.com/go/compute v1.12.1 h1:gKVJMEyqV5c/UnpzjjQbo3Rjvvqpr9B1DFSbJC4OXr0= -cloud.google.com/go/compute v1.12.1/go.mod h1:e8yNOBcBONZU1vJKCvCoDw/4JQsA0dpM4x/6PIIOocU= -cloud.google.com/go/compute/metadata v0.2.1 h1:efOwf5ymceDhK6PKMnnrTHP4pppY5L22mle96M1yP48= -cloud.google.com/go/compute/metadata v0.2.1/go.mod h1:jgHgmJd2RKBGzXqF5LR2EZMGxBkeanZ9wwa75XHJgOM= +cloud.google.com/go/compute v1.18.0 h1:FEigFqoDbys2cvFkZ9Fjq4gnHBP55anJ0yQyau2f9oY= +cloud.google.com/go/compute v1.18.0/go.mod h1:1X7yHxec2Ga+Ss6jPyjxRxpu2uu7PLgsOVXvgU0yacs= +cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/iam v0.7.0 h1:k4MuwOsS7zGJJ+QfZ5vBK8SgHBAvYN/23BWsiihJ1vs= -cloud.google.com/go/iam v0.7.0/go.mod h1:H5Br8wRaDGNc8XP3keLc4unfUUZeyH3Sfl9XpQEYOeg= +cloud.google.com/go/iam v0.11.0 h1:kwCWfKwB6ePZoZnGLwrd3B6Ru/agoHANTUBWpVNIdnM= +cloud.google.com/go/iam v0.11.0/go.mod h1:9PiLDanza5D+oWFZiH1uG+RnRCfEGKoyl6yo4cgWZGY= cloud.google.com/go/longrunning v0.3.0 h1:NjljC+FYPV3uh5/OwWT6pVU+doBqMg2x/rZlE+CamDs= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= @@ -82,6 +82,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/Stride-Labs/stride/v6 v6.0.0 h1:O2/pcl/VFXeKK3+VYFWveiqR73AYLUdnIRpV/0ho8FE= +github.com/Stride-Labs/stride/v6 v6.0.0/go.mod h1:8sqYiz9JogpNNenlRxXbI9XIpHvbDDxLpakeoCYhDb4= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= @@ -171,8 +173,9 @@ github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -207,8 +210,8 @@ github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= -github.com/cosmos/cosmos-proto v1.0.0-alpha7 h1:yqYUOHF2jopwZh4dVQp3xgqwftE5/2hkrwIV6vkUbO0= -github.com/cosmos/cosmos-proto v1.0.0-alpha7/go.mod h1:dosO4pSAbJF8zWCzCoTWP7nNsjcvSUBQmniFxDg5daw= +github.com/cosmos/cosmos-proto v1.0.0-alpha8 h1:d3pCRuMYYvGA5bM0ZbbjKn+AoQD4A7dyNG2wzwWalUw= +github.com/cosmos/cosmos-proto v1.0.0-alpha8/go.mod h1:6/p+Bc4O8JKeZqe0VqUGTX31eoYqemTT4C1hLCWsO7I= github.com/cosmos/cosmos-sdk v0.46.7 h1:dkGy9y2ewgqvawrUOuWb2oz3MdotVduokyreXC4bS0s= github.com/cosmos/cosmos-sdk v0.46.7/go.mod h1:fqKqz39U5IlEFb4nbQ72951myztsDzFKKDtffYJ63nk= github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 h1:iKclrn3YEOwk4jQHT2ulgzuXyxmzmPczUalMwW4XH9k= @@ -216,14 +219,12 @@ github.com/cosmos/cosmos-sdk/ics23/go v0.8.0/go.mod h1:2a4dBq88TUoqoWAU5eu0lGvpF github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= -github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAYw= -github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok= github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= -github.com/cosmos/ibc-go/v5 v5.0.1 h1:ZI5xCi6RDOL+hyu6Wx/w6JoAYFlOoK5hijsRTVWo+RA= -github.com/cosmos/ibc-go/v5 v5.0.1/go.mod h1:LX0DHLW3dfi/1e4BJzi8MGLWmQ4DSraPEgVjyo3VzAo= +github.com/cosmos/ibc-go/v5 v5.1.0 h1:m1NHXFkwwvNeJegZqtyox1WLinh+PMy4ivU/Cs9KjeA= +github.com/cosmos/ibc-go/v5 v5.1.0/go.mod h1:H6sV0/CkNRDtvSrhbsIgiog1WnSwhguGfg8x34MOVEk= github.com/cosmos/ledger-cosmos-go v0.12.1 h1:sMBxza5p/rNK/06nBSNmsI/WDqI0pVJFVNihy1Y984w= github.com/cosmos/ledger-cosmos-go v0.12.1/go.mod h1:dhO6kj+Y+AHIOgAe4L9HL/6NDdyyth4q238I9yFpD2g= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= @@ -342,8 +343,8 @@ github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8c github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -397,8 +398,9 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= @@ -420,7 +422,6 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= @@ -451,12 +452,12 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.2.0 h1:y8Yozv7SZtlU//QXbezB6QkpuE6jMD2/gfzk4AftXjs= -github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg= +github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9aurXEpJX+U6FLtpYTdC3R06k= +github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/googleapis/gax-go/v2 v2.6.0 h1:SXk3ABtQYDT/OH8jAyvEOQ58mgawq5C4o/4/89qN2ZU= -github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY= +github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ= +github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= @@ -862,8 +863,8 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI= -github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= +github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -963,8 +964,8 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= -go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= +go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -1095,8 +1096,8 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1108,8 +1109,8 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= -golang.org/x/oauth2 v0.2.0 h1:GtQkldQ9m7yvzCL1V+LrYow3Khe0eJH0w7RbX/VbaIU= -golang.org/x/oauth2 v0.2.0/go.mod h1:Cwn6afJ8jrQwYMxQDTpISoXmXW9I6qF6vDeuuoX3Ibs= +golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s= +golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1203,13 +1204,13 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1219,8 +1220,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1319,8 +1320,8 @@ google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz513 google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= -google.golang.org/api v0.102.0 h1:JxJl2qQ85fRMPNvlZY/enexbxpCjLwGhZUtgfGeQ51I= -google.golang.org/api v0.102.0/go.mod h1:3VFl6/fzoA+qNuS1N1/VfXY4LjoXN/wzeIp7TweWwGo= +google.golang.org/api v0.110.0 h1:l+rh0KYUooe9JGbGVx71tbFo4SMbMTXK3I3ia2QSEeU= +google.golang.org/api v0.110.0/go.mod h1:7FC4Vvx1Mooxh8C5HWjzZHcavuS2f6pmJpZx60ca7iI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -1374,8 +1375,8 @@ google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 h1:jCw9YRd2s40X9Vxi4zKsPRvSPlHWNqadVkpbMsCPzPQ= -google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= +google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 h1:znp6mq/drrY+6khTAlJUDNFFcDGV2ENLYKpMq8SyCds= +google.golang.org/genproto v0.0.0-20230223222841-637eb2293923/go.mod h1:3Dl5ZL0q0isWJt+FVcfpQyirqemEuLAK/iFvg1UP1Hw= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -1400,8 +1401,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY= -google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= +google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= +google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -1414,7 +1415,6 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 h1:KR8+MyP7/qOlV+8Af01LtjL04bu7on42eVsxT4EyBQk= google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -1464,7 +1464,6 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/internal/tools/tools.go b/internal/tools/tools.go index bc9435e5..0552bb27 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -1,3 +1,4 @@ +//go:build tools // +build tools package tools diff --git a/proto/lum-network/dfract/proposal.proto b/proto/lum-network/dfract/proposal.proto index 7f4132c5..5fddb5fa 100644 --- a/proto/lum-network/dfract/proposal.proto +++ b/proto/lum-network/dfract/proposal.proto @@ -6,16 +6,15 @@ import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; option go_package = "github.com/lum-network/chain/x/dfract/types"; -option (gogoproto.equal_all) = true; message WithdrawAndMintProposal { + option (gogoproto.equal) = true; option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; string title = 1; string description = 2; string withdrawal_address = 3; int64 micro_mint_rate = 4; -} \ No newline at end of file +} diff --git a/proto/lum-network/icacallbacks/callback_data.proto b/proto/lum-network/icacallbacks/callback_data.proto new file mode 100755 index 00000000..e5469518 --- /dev/null +++ b/proto/lum-network/icacallbacks/callback_data.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package lum.network.icacallbacks; + +option go_package = "github.com/lum-network/chain/x/icacallbacks/types"; + +message CallbackData { + string callback_key = 1; + string port_id = 2; + string channel_id = 3; + uint64 sequence = 4; + string callback_id = 5; + bytes callback_args = 6; +} diff --git a/proto/lum-network/icacallbacks/genesis.proto b/proto/lum-network/icacallbacks/genesis.proto new file mode 100755 index 00000000..26f3fe83 --- /dev/null +++ b/proto/lum-network/icacallbacks/genesis.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package lum.network.icacallbacks; + +option go_package = "github.com/lum-network/chain/x/icacallbacks/types"; +import "gogoproto/gogo.proto"; +import "lum-network/icacallbacks/params.proto"; +import "lum-network/icacallbacks/callback_data.proto"; + + +// GenesisState defines the icacallbacks module's genesis state. +message GenesisState { + Params params = 1 [ (gogoproto.nullable) = false ]; + string port_id = 2; + repeated CallbackData callback_data_list = 3 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/icacallbacks/packet.proto b/proto/lum-network/icacallbacks/packet.proto new file mode 100755 index 00000000..6427e283 --- /dev/null +++ b/proto/lum-network/icacallbacks/packet.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package lum.network.icacallbacks; + +option go_package = "github.com/lum-network/chain/x/icacallbacks/types"; + +message IcacallbacksPacketData { + oneof packet { + NoData no_data = 1; + // this line is used by starport scaffolding # ibc/packet/proto/field + } +} + +message NoData {} + +// this line is used by starport scaffolding # ibc/packet/proto/message diff --git a/proto/lum-network/icacallbacks/params.proto b/proto/lum-network/icacallbacks/params.proto new file mode 100755 index 00000000..ea15e601 --- /dev/null +++ b/proto/lum-network/icacallbacks/params.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package lum.network.icacallbacks; + +option go_package = "github.com/lum-network/chain/x/icacallbacks/types"; +import "gogoproto/gogo.proto"; + +// Params defines the parameters for the module. +message Params { option (gogoproto.goproto_stringer) = false; } diff --git a/proto/lum-network/icacallbacks/query.proto b/proto/lum-network/icacallbacks/query.proto new file mode 100644 index 00000000..eab17964 --- /dev/null +++ b/proto/lum-network/icacallbacks/query.proto @@ -0,0 +1,54 @@ +syntax = "proto3"; +package lum.network.icacallbacks; + +option go_package = "github.com/lum-network/chain/x/icacallbacks/types"; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "lum-network/icacallbacks/params.proto"; +import "lum-network/icacallbacks/callback_data.proto"; +// this line is used by starport scaffolding # 1 + +// Query defines the gRPC querier service. +service Query { + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/lum-network/icacallbacks/params"; + } + // Queries a CallbackData by index. + rpc CallbackData(QueryGetCallbackDataRequest) returns (QueryGetCallbackDataResponse) { + option (google.api.http).get = "/lum-network/icacallbacks/callback_data/{callback_key}"; + } + + // Queries a list of CallbackData items. + rpc CallbackDataAll(QueryAllCallbackDataRequest)returns (QueryAllCallbackDataResponse) { + option (google.api.http).get = "/lum-network/icacallbacks/callback_data"; + } +} + +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryGetCallbackDataRequest { string callback_key = 1; } + +message QueryGetCallbackDataResponse { + CallbackData callback_data = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryAllCallbackDataRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllCallbackDataResponse { + repeated CallbackData callback_data = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// this line is used by starport scaffolding # 3 diff --git a/proto/lum-network/icacallbacks/tx.proto b/proto/lum-network/icacallbacks/tx.proto new file mode 100755 index 00000000..6d5e9b5f --- /dev/null +++ b/proto/lum-network/icacallbacks/tx.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package lum.network.icacallbacks; + +option go_package = "github.com/lum-network/chain/x/icacallbacks/types"; + +service Msg { + // this line is used by starport scaffolding # proto/tx/rpc +} + +// this line is used by starport scaffolding # proto/tx/message diff --git a/proto/lum-network/icqueries/genesis.proto b/proto/lum-network/icqueries/genesis.proto new file mode 100644 index 00000000..cd44b84f --- /dev/null +++ b/proto/lum-network/icqueries/genesis.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; +package stride.interchainquery.v1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/lum-network/chain/x/icqueries/types"; + +message Query { + string id = 1; + string connection_id = 2; + string chain_id = 3; + string query_type = 4; + bytes request = 5; + string callback_id = 8; + uint64 ttl = 9; + bool request_sent = 11; + string extra_id = 12; +} + +message DataPoint { + string id = 1; + string remote_height = 2 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + string local_height = 3 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + bytes value = 4 [ (gogoproto.jsontag) = "result,omitempty" ]; +} + +// GenesisState defines the epochs module's genesis state. +message GenesisState { + repeated Query queries = 1 [ (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/lum-network/icqueries/query.proto b/proto/lum-network/icqueries/query.proto new file mode 100644 index 00000000..43ad4075 --- /dev/null +++ b/proto/lum-network/icqueries/query.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; +package stride.interchainquery.v1; + +import "lum-network/icqueries/genesis.proto"; +import "google/api/annotations.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/lum-network/chain/x/icqueries/types"; + +service QueryService { + rpc Queries(QueryQueriesRequest) returns (QueryQueriesResponse) { + option (google.api.http).get = "/lum-network/icqueries/queries"; + }; + rpc PendingQueries(QueryPendingQueriesRequest) returns (QueryPendingQueriesResponse) { + option (google.api.http).get = "/lum-network/icqueries/pending_queries"; + }; +} + +message QueryPendingQueriesRequest {} +message QueryPendingQueriesResponse { + repeated Query pending_queries = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryQueriesRequest {} +message QueryQueriesResponse { + repeated Query queries = 1 [ (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/lum-network/icqueries/tx.proto b/proto/lum-network/icqueries/tx.proto new file mode 100644 index 00000000..5040373f --- /dev/null +++ b/proto/lum-network/icqueries/tx.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; +package stride.interchainquery.v1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/api/annotations.proto"; +import "tendermint/crypto/proof.proto"; + +option go_package = "github.com/lum-network/chain/x/icqueries/types"; + +// Msg defines the icqueries Msg service. +service Msg { + // SubmitQueryResponse defines a method for submit query responses. + rpc SubmitQueryResponse(MsgSubmitQueryResponse) returns (MsgSubmitQueryResponseResponse) { + option (google.api.http) = { + post : "/interchainquery/tx/v1beta1/submitquery" + body : "*" + }; + }; +} + +// MsgSubmitQueryResponse represents a message type to fulfil a query request. +message MsgSubmitQueryResponse { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = true; + + string chain_id = 1 [ (gogoproto.moretags) = "yaml:\"chain_id\"" ]; + string query_id = 2 [ (gogoproto.moretags) = "yaml:\"query_id\"" ]; + bytes result = 3 [ (gogoproto.moretags) = "yaml:\"result\"" ]; + tendermint.crypto.ProofOps proof_ops = 4 [ (gogoproto.moretags) = "yaml:\"proof_ops\"" ]; + int64 height = 5 [ (gogoproto.moretags) = "yaml:\"height\"" ]; + string from_address = 6 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +// MsgSubmitQueryResponseResponse defines the MsgSubmitQueryResponse response type. +message MsgSubmitQueryResponseResponse {} \ No newline at end of file diff --git a/proto/lum-network/millions/callbacks.proto b/proto/lum-network/millions/callbacks.proto new file mode 100644 index 00000000..65978f8e --- /dev/null +++ b/proto/lum-network/millions/callbacks.proto @@ -0,0 +1,57 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +enum TransferType { + option (gogoproto.goproto_enum_prefix) = true; + + TRANSFER_TYPE_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "Unspecified" ]; + TRANSFER_TYPE_CLAIM = 1 [ (gogoproto.enumvalue_customname) = "Claim" ]; + TRANSFER_TYPE_WITHDRAW = 2 [ (gogoproto.enumvalue_customname) = "Withdraw" ]; +} + +message SplitDelegation { + string validator_address = 1; + string amount = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; +} + +message DelegateCallback { + uint64 pool_id = 1; + uint64 deposit_id = 2; + repeated SplitDelegation split_delegations = 3; +} + +message UndelegateCallback { + uint64 pool_id = 1; + uint64 withdrawal_id = 2; + repeated SplitDelegation split_delegations = 3; +} + +message RedelegateCallback { + uint64 pool_id = 1; + SplitDelegation split_delegation = 2; +} + +message ClaimRewardsCallback { + uint64 pool_id = 1; + uint64 draw_id = 2; +} + +message TransferToNativeCallback { + uint64 pool_id = 1; + uint64 deposit_id = 2; +} + +message TransferFromNativeCallback { + TransferType type = 1; + uint64 pool_id = 2; + uint64 draw_id = 3; + uint64 withdrawal_id = 4; +} + +message SetWithdrawAddressCallback { + uint64 pool_id = 1; +} \ No newline at end of file diff --git a/proto/lum-network/millions/deposit.proto b/proto/lum-network/millions/deposit.proto new file mode 100644 index 00000000..1088edfa --- /dev/null +++ b/proto/lum-network/millions/deposit.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +enum DepositState { + option (gogoproto.goproto_enum_prefix) = true; + + DEPOSIT_STATE_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "Unspecified" ]; + DEPOSIT_STATE_IBC_TRANSFER = 1 [ (gogoproto.enumvalue_customname) = "IbcTransfer" ]; + DEPOSIT_STATE_ICA_DELEGATE = 2 [ (gogoproto.enumvalue_customname) = "IcaDelegate" ]; + DEPOSIT_STATE_SUCCESS = 3 [ (gogoproto.enumvalue_customname) = "Success" ]; + DEPOSIT_STATE_FAILURE = 4 [ (gogoproto.enumvalue_customname) = "Failure" ]; +} + +message Deposit { + uint64 pool_id = 1; + uint64 deposit_id = 2; + + DepositState state = 3; + DepositState error_state = 4; + + string depositor_address = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + cosmos.base.v1beta1.Coin amount = 6 [ (gogoproto.nullable) = false ]; + + string winner_address = 7 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + bool is_sponsor = 8; + reserved 9; + + int64 created_at_height = 10; + int64 updated_at_height = 11; + google.protobuf.Timestamp created_at = 12 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Timestamp updated_at = 13 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/draw.proto b/proto/lum-network/millions/draw.proto new file mode 100644 index 00000000..357a7b37 --- /dev/null +++ b/proto/lum-network/millions/draw.proto @@ -0,0 +1,52 @@ +syntax = "proto3"; +package lum.network.millions; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +import "lum-network/millions/prize_ref.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +enum DrawState { + option (gogoproto.goproto_enum_prefix) = true; + + DRAW_STATE_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "Unspecified" ]; + DRAW_STATE_ICA_WITHDRAWREWARDS = 1 [ (gogoproto.enumvalue_customname) = "IcaWithdrawRewards" ]; + DRAW_STATE_QUERY_BALANCE = 2 [ (gogoproto.enumvalue_customname) = "IcqBalance" ]; + DRAW_STATE_IBC_TRANSFER = 3 [ (gogoproto.enumvalue_customname) = "IbcTransfer" ]; + DRAW_STATE_DRAWING = 4 [ (gogoproto.enumvalue_customname) = "Drawing" ]; + DRAW_STATE_SUCCESS = 5 [ (gogoproto.enumvalue_customname) = "Success" ]; + DRAW_STATE_FAILURE = 6 [ (gogoproto.enumvalue_customname) = "Failure" ]; +} + +message Draw { + // Draw IDs + uint64 pool_id = 1; + uint64 draw_id = 2; + + // Draw states + // error_state is only set in case of failure + DrawState state = 3; + DrawState error_state = 4; + + // Draw state done data + int64 rand_seed = 5; + cosmos.base.v1beta1.Coin prize_pool = 6 [ (gogoproto.nullable) = false ]; + string prize_pool_fresh_amount = 7 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + string prize_pool_remains_amount = 8 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + reserved 9; + reserved 10; + + repeated PrizeRef prizes_refs = 11 [ (gogoproto.nullable) = false ]; + uint64 total_win_count = 12; + string total_win_amount = 13 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + reserved 14; + + // Draw creation and updates + int64 created_at_height = 15; + int64 updated_at_height = 16; + google.protobuf.Timestamp created_at = 17 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Timestamp updated_at = 18 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/draw_schedule.proto b/proto/lum-network/millions/draw_schedule.proto new file mode 100644 index 00000000..a9833165 --- /dev/null +++ b/proto/lum-network/millions/draw_schedule.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message DrawSchedule { + google.protobuf.Timestamp initial_draw_at = 1 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Duration draw_delta = 2 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/genesis.proto b/proto/lum-network/millions/genesis.proto new file mode 100644 index 00000000..a326b908 --- /dev/null +++ b/proto/lum-network/millions/genesis.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; + +import "lum-network/millions/deposit.proto"; +import "lum-network/millions/draw.proto"; +import "lum-network/millions/params.proto"; +import "lum-network/millions/pool.proto"; +import "lum-network/millions/prize.proto"; +import "lum-network/millions/withdrawal.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message GenesisState { + Params params = 1 [ (gogoproto.moretags) = "yaml:\"params\"", (gogoproto.nullable) = false ]; + + uint64 next_pool_id = 2; + uint64 next_deposit_id = 3; + uint64 next_prize_id = 4; + uint64 next_withdrawal_id = 5; + repeated Pool pools = 6 [ (gogoproto.nullable) = false ]; + repeated Deposit deposits = 7 [ (gogoproto.nullable) = false ]; + repeated Draw draws = 8 [ (gogoproto.nullable) = false ]; + repeated Prize prizes = 9 [ (gogoproto.nullable) = false ]; + repeated Withdrawal withdrawals = 10 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/gov.proto b/proto/lum-network/millions/gov.proto new file mode 100644 index 00000000..fe380b6b --- /dev/null +++ b/proto/lum-network/millions/gov.proto @@ -0,0 +1,61 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; + +import "cosmos_proto/cosmos.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +import "lum-network/millions/draw_schedule.proto"; +import "lum-network/millions/prize_strategy.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message ProposalRegisterPool { + option (gogoproto.goproto_stringer) = false; + + string title = 1; + string description = 2; + + string chain_id = 3; + string denom = 4; + string native_denom = 5; + string connection_id = 6; + repeated string validators = 7; + string min_deposit_amount = 8 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + DrawSchedule draw_schedule = 9 [ (gogoproto.nullable) = false ]; + PrizeStrategy prize_strategy = 10 [ (gogoproto.nullable) = false ]; + string bech32_prefix_acc_addr = 11; + string bech32_prefix_val_addr = 12; + string transfer_channel_id = 13; +} + +message ProposalUpdatePool { + option (gogoproto.goproto_stringer) = false; + + string title = 1; + string description = 2; + + uint64 pool_id = 3; + repeated string validators = 4 [ (gogoproto.nullable) = true ]; + string min_deposit_amount = 5 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + DrawSchedule draw_schedule = 6 [ (gogoproto.nullable) = true ]; + PrizeStrategy prize_strategy = 7 [ (gogoproto.nullable) = true ]; +} + +message ProposalUpdateParams { + option (gogoproto.goproto_stringer) = false; + + string title = 1; + string description = 2; + + string min_deposit_amount = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + string max_prize_strategy_batches = 4 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + string max_prize_batch_quantity = 5 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + google.protobuf.Duration min_draw_schedule_delta = 6 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + google.protobuf.Duration max_draw_schedule_delta = 7 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + google.protobuf.Duration prize_expiration_delta = 8 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + string fees_stakers = 9 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = true ]; + google.protobuf.Duration min_deposit_draw_delta = 10 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; +} \ No newline at end of file diff --git a/proto/lum-network/millions/params.proto b/proto/lum-network/millions/params.proto new file mode 100644 index 00000000..99528409 --- /dev/null +++ b/proto/lum-network/millions/params.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message Params { + // min_deposit_amount the minimum deposit amount accepted by pool configurations + string min_deposit_amount = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + // max_prize_strategy_batches the maximum prize strategy batches accepted by pool configurations + uint64 max_prize_strategy_batches = 2; + // max_prize_batch_quantity the maximum prize batch quantity accepted by pool configurations + uint64 max_prize_batch_quantity = 3; + // min_draw_schedule_delta the minimum delta between draws accepted by pool configurations + google.protobuf.Duration min_draw_schedule_delta = 4 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ]; + // max_draw_schedule_delta the maximum delta between draws accepted by pool configurations + google.protobuf.Duration max_draw_schedule_delta = 5 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ]; + // prize_expiration_delta the prize clawback expiration delta (common to all pools) + google.protobuf.Duration prize_expiration_delta = 6 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ]; + // fees_stakers the fees distributed by stakers over prize won (common to all pools) + string fees_stakers = 7 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; + // min_deposit_draw_delta the minimum delta before a draw for a deposit to be accepted during the time weighted balance computation for a draw + google.protobuf.Duration min_deposit_draw_delta = 8 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/pool.proto b/proto/lum-network/millions/pool.proto new file mode 100644 index 00000000..f1d39634 --- /dev/null +++ b/proto/lum-network/millions/pool.proto @@ -0,0 +1,84 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; + +import "lum-network/millions/draw.proto"; +import "lum-network/millions/draw_schedule.proto"; +import "lum-network/millions/prize_strategy.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +// PoolState the state of a Pool +// Deposits are only accepted for Pools in a Ready state +// +// TODO: +// Pool states PAUSED and KILLED are not available in the current implementation +// Introduce the capability to: +// - Pause a Pool in case of Interchain issues or via Governance proposal +// - Kill a Pool and withdraw or migrate all deposits to another Pool via Governance proposal +enum PoolState { + option (gogoproto.goproto_enum_prefix) = true; + + POOL_STATE_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "Unspecified" ]; + POOL_STATE_CREATED = 1 [ (gogoproto.enumvalue_customname) = "Created" ]; + POOL_STATE_READY = 2 [ (gogoproto.enumvalue_customname) = "Ready" ]; + POOL_STATE_PAUSED = 3 [ (gogoproto.enumvalue_customname) = "Paused" ]; + POOL_STATE_KILLED = 4 [ (gogoproto.enumvalue_customname) = "Killed" ]; +} + +message Pool { + uint64 pool_id = 1; + string denom = 2; + string native_denom = 3; + string chain_id = 4; + string connection_id = 5; + string transfer_channel_id = 6; + string ica_deposit_port_id = 7; + string ica_prizepool_port_id = 8; + reserved 9; + + map validators = 10; + string bech32_prefix_acc_addr = 11; + string bech32_prefix_val_addr = 12; + + string min_deposit_amount = 13 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + DrawSchedule draw_schedule = 14 [ (gogoproto.nullable) = false ]; + PrizeStrategy prize_strategy = 15 [ (gogoproto.nullable) = false ]; + reserved 16; + reserved 17; + + string local_address = 18 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string ica_deposit_address = 19 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string ica_prizepool_address = 20 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + reserved 21; + + uint64 next_draw_id = 22; + string tvl_amount = 23 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + uint64 depositors_count = 24; + string sponsorship_amount = 25 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + reserved 26; + + google.protobuf.Timestamp last_draw_created_at = 27 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = true ]; + DrawState last_draw_state = 28; + cosmos.base.v1beta1.Coin available_prize_pool = 29 [ (gogoproto.nullable) = false ]; + reserved 30; + reserved 31; + + PoolState state = 32; + + int64 created_at_height = 33; + int64 updated_at_height = 34; + google.protobuf.Timestamp created_at = 35 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Timestamp updated_at = 36 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; +} + +message PoolValidator { + string operator_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + bool is_enabled = 2; + string bonded_amount = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/prize.proto b/proto/lum-network/millions/prize.proto new file mode 100644 index 00000000..ea656f55 --- /dev/null +++ b/proto/lum-network/millions/prize.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +enum PrizeState { + option (gogoproto.goproto_enum_prefix) = true; + + PRIZE_STATE_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "Unspecified" ]; + PRIZE_STATE_PENDING = 1 [ (gogoproto.enumvalue_customname) = "Pending" ]; +} + +message Prize { + uint64 pool_id = 1; + uint64 draw_id = 2; + uint64 prize_id = 3; + + PrizeState state = 4; + + string winner_address = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + cosmos.base.v1beta1.Coin amount = 6 [ (gogoproto.nullable) = false ]; + + int64 created_at_height = 7; + int64 updated_at_height = 8; + google.protobuf.Timestamp expires_at = 9 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Timestamp created_at = 10 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Timestamp updated_at = 11 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; +} + +message PrizeIDs { + uint64 pool_id = 1; + uint64 draw_id = 2; + uint64 prize_id = 3; +} + +message PrizeIDsCollection { + repeated PrizeIDs prizes_ids = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/prize_batch.proto b/proto/lum-network/millions/prize_batch.proto new file mode 100644 index 00000000..a479f76a --- /dev/null +++ b/proto/lum-network/millions/prize_batch.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message PrizeBatch { + uint64 pool_percent = 1; + uint64 quantity = 2; + string draw_probability = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/prize_ref.proto b/proto/lum-network/millions/prize_ref.proto new file mode 100644 index 00000000..2f0b1a2e --- /dev/null +++ b/proto/lum-network/millions/prize_ref.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; + +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message PrizeRef { + string amount = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + uint64 prize_id = 2 [ (gogoproto.nullable) = true ]; + string winner_address = 3 [ (gogoproto.nullable) = true, (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} diff --git a/proto/lum-network/millions/prize_strategy.proto b/proto/lum-network/millions/prize_strategy.proto new file mode 100644 index 00000000..374ec5d3 --- /dev/null +++ b/proto/lum-network/millions/prize_strategy.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; + +import "lum-network/millions/prize_batch.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +message PrizeStrategy { + repeated PrizeBatch prize_batches = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/lum-network/millions/query.proto b/proto/lum-network/millions/query.proto new file mode 100644 index 00000000..e6bbdab9 --- /dev/null +++ b/proto/lum-network/millions/query.proto @@ -0,0 +1,286 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; + +import "cosmos/base/query/v1beta1/pagination.proto"; + +import "lum-network/millions/deposit.proto"; +import "lum-network/millions/draw.proto"; +import "lum-network/millions/params.proto"; +import "lum-network/millions/pool.proto"; +import "lum-network/millions/prize.proto"; +import "lum-network/millions/withdrawal.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +service Query { + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/lum-network/millions/params"; + } + + rpc Pools(QueryPoolsRequest) returns (QueryPoolsResponse) { + option (google.api.http).get = "/lum-network/millions/pools"; + } + + rpc Pool(QueryPoolRequest) returns (QueryPoolResponse) { + option (google.api.http).get = "/lum-network/millions/pools/{pool_id}"; + } + + rpc Deposits(QueryDepositsRequest) returns (QueryDepositsResponse) { + option (google.api.http).get = "/lum-network/millions/deposits"; + } + + rpc PoolDeposits(QueryPoolDepositsRequest) returns (QueryDepositsResponse) { + option (google.api.http).get = "/lum-network/millions/deposits/{pool_id}"; + } + + rpc PoolDeposit(QueryPoolDepositRequest) returns (QueryDepositResponse) { + option (google.api.http).get = "/lum-network/millions/deposits/{pool_id}/{deposit_id}"; + } + + rpc AccountDeposits(QueryAccountDepositsRequest) returns (QueryDepositsResponse) { + option (google.api.http).get = "/lum-network/millions/account/{depositor_address}/deposits"; + } + + rpc AccountPoolDeposits(QueryAccountPoolDepositsRequest) returns (QueryDepositsResponse) { + option (google.api.http).get = "/lum-network/millions/account/{depositor_address}/deposits/{pool_id}"; + } + + rpc Draws(QueryDrawsRequest) returns (QueryDrawsResponse) { + option (google.api.http).get = "/lum-network/millions/draws"; + } + + rpc PoolDraws(QueryPoolDrawsRequest) returns (QueryDrawsResponse) { + option (google.api.http).get = "/lum-network/millions/draws/{pool_id}"; + } + + rpc PoolDraw(QueryPoolDrawRequest) returns (QueryDrawResponse) { + option (google.api.http).get = "/lum-network/millions/draws/{pool_id}/{draw_id}"; + } + + rpc Prizes(QueryPrizesRequest) returns (QueryPrizesResponse) { + option (google.api.http).get = "/lum-network/millions/prizes"; + } + + rpc PoolPrizes(QueryPoolPrizesRequest) returns (QueryPrizesResponse) { + option (google.api.http).get = "/lum-network/millions/prizes/{pool_id}"; + } + + rpc PoolDrawPrizes(QueryPoolDrawPrizesRequest) returns (QueryPrizesResponse) { + option (google.api.http).get = "/lum-network/millions/prizes/{pool_id}/{draw_id}"; + } + + rpc PoolDrawPrize(QueryPoolDrawPrizeRequest) returns (QueryPrizeResponse) { + option (google.api.http).get = "/lum-network/millions/prizes/{pool_id}/{draw_id}/{prize_id}"; + } + + rpc AccountPrizes(QueryAccountPrizesRequest) returns (QueryPrizesResponse) { + option (google.api.http).get = "/lum-network/millions/account/{winner_address}/prizes"; + } + + rpc AccountPoolPrizes(QueryAccountPoolPrizesRequest) returns (QueryPrizesResponse) { + option (google.api.http).get = "/lum-network/millions/account/{winner_address}/prizes/{pool_id}"; + } + + rpc AccountPoolDrawPrizes(QueryAccountPoolDrawPrizesRequest) returns (QueryPrizesResponse) { + option (google.api.http).get = "/lum-network/millions/account/{winner_address}/prizes/{pool_id}/{draw_id}"; + } + + rpc Withdrawals(QueryWithdrawalsRequest) returns (QueryWithdrawalsResponse) { + option (google.api.http).get = "/lum-network/millions/withdrawals"; + } + + rpc PoolWithdrawals(QueryPoolWithdrawalsRequest) returns (QueryWithdrawalsResponse) { + option (google.api.http).get = "/lum-network/millions/withdrawals/{pool_id}"; + } + + rpc PoolWithdrawal(QueryPoolWithdrawalRequest) returns (QueryWithdrawalResponse) { + option (google.api.http).get = "/lum-network/millions/withdrawals/{pool_id}/{withdrawal_id}"; + } + + rpc AccountWithdrawals(QueryAccountWithdrawalsRequest) returns (QueryWithdrawalsResponse) { + option (google.api.http).get = "/lum-network/millions/account/{depositor_address}/withdrawals"; + } + + rpc AccountPoolWithdrawals(QueryAccountPoolWithdrawalsRequest) returns (QueryWithdrawalsResponse) { + option (google.api.http).get = "/lum-network/millions/account/{depositor_address}/withdrawals/{pool_id}"; + } +} + +// Params + +message QueryParamsResponse { + Params params = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryParamsRequest { +} + +// Pools + +message QueryPoolResponse { + Pool pool = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryPoolsResponse { + repeated Pool pools = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryPoolRequest { + uint64 pool_id = 1; +} + +message QueryPoolsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// Deposits + +message QueryDepositResponse { + Deposit deposit = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryDepositsResponse { + repeated Deposit deposits = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryDepositsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryPoolDepositRequest { + uint64 pool_id = 1; + uint64 deposit_id = 2; +} + +message QueryPoolDepositsRequest { + uint64 pool_id = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryAccountDepositsRequest { + string depositor_address = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryAccountPoolDepositsRequest { + string depositor_address = 1; + uint64 pool_id = 2; + cosmos.base.query.v1beta1.PageRequest pagination = 3; +} + + +// Draws + +message QueryDrawResponse { + Draw draw = 1; +} + +message QueryDrawsResponse { + repeated Draw draws = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryDrawsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryPoolDrawsRequest { + uint64 pool_id = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryPoolDrawRequest { + uint64 pool_id = 1; + uint64 draw_id = 2; +} + +// Prizes + +message QueryPrizeResponse { + Prize prize = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryPrizesResponse { + repeated Prize prizes = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryPoolDrawPrizeRequest { + uint64 pool_id = 1; + uint64 draw_id = 2; + uint64 prize_id = 3; +} + +message QueryPrizesRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryPoolPrizesRequest { + uint64 pool_id = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryPoolDrawPrizesRequest { + uint64 pool_id = 1; + uint64 draw_id = 2; + cosmos.base.query.v1beta1.PageRequest pagination = 3; +} + +message QueryAccountPrizesRequest { + string winner_address = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryAccountPoolPrizesRequest { + string winner_address = 1; + uint64 pool_id = 2; + cosmos.base.query.v1beta1.PageRequest pagination = 3; +} + +message QueryAccountPoolDrawPrizesRequest { + string winner_address = 1; + uint64 pool_id = 2; + uint64 draw_id = 3; + cosmos.base.query.v1beta1.PageRequest pagination = 4; +} + +// Withdrawals + +message QueryWithdrawalResponse { + Withdrawal withdrawal = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryWithdrawalsResponse { + repeated Withdrawal withdrawals = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +message QueryPoolWithdrawalRequest { + uint64 pool_id = 1; + uint64 withdrawal_id = 2; +} + +message QueryWithdrawalsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryPoolWithdrawalsRequest { + uint64 pool_id = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryAccountWithdrawalsRequest { + string depositor_address = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +message QueryAccountPoolWithdrawalsRequest { + string depositor_address = 1; + uint64 pool_id = 2; + cosmos.base.query.v1beta1.PageRequest pagination = 3; +} diff --git a/proto/lum-network/millions/tx.proto b/proto/lum-network/millions/tx.proto new file mode 100644 index 00000000..4b8c1b3c --- /dev/null +++ b/proto/lum-network/millions/tx.proto @@ -0,0 +1,137 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; + +import "lum-network/millions/draw_schedule.proto"; +import "lum-network/millions/pool.proto"; +import "lum-network/millions/prize_strategy.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +service Msg { + rpc Deposit(MsgDeposit) returns (MsgDepositResponse); + rpc DepositRetry(MsgDepositRetry) returns (MsgDepositRetryResponse); + rpc ClaimPrize(MsgClaimPrize) returns (MsgClaimPrizeResponse); + rpc WithdrawDeposit(MsgWithdrawDeposit) returns (MsgWithdrawDepositResponse); + rpc WithdrawDepositRetry(MsgWithdrawDepositRetry) returns (MsgWithdrawDepositRetryResponse); + rpc DrawRetry(MsgDrawRetry) returns (MsgDrawRetryResponse); + rpc RestoreInterchainAccounts(MsgRestoreInterchainAccounts) returns (MsgRestoreInterchainAccountsResponse); +} + +message MsgUpdateParams { + string min_deposit_amount = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + string max_prize_strategy_batches = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + string max_prize_batch_quantity = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + google.protobuf.Duration min_draw_schedule_delta = 4 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + google.protobuf.Duration max_draw_schedule_delta = 5 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + google.protobuf.Duration prize_expiration_delta = 6 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + string fees_stakers = 7 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = true ]; + google.protobuf.Duration min_deposit_draw_delta = 8 [ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ]; + string updater_address = 9 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgUpdateParamsResponse { +} + +message MsgRegisterPool { + string chain_id = 1; + string denom = 2; + string native_denom = 3; + string connection_id = 4; + repeated string validators = 5; + string min_deposit_amount = 6 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + DrawSchedule draw_schedule = 7 [ (gogoproto.nullable) = false ]; + PrizeStrategy prize_strategy = 8 [ (gogoproto.nullable) = false ]; + string bech32_prefix_acc_addr = 9; + string bech32_prefix_val_addr = 10; + string creator_address = 11 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgRegisterPoolResponse { + uint64 pool_id = 1; +} + +message MsgUpdatePool { + uint64 pool_id = 1; + repeated string validators = 2 [ (gogoproto.nullable) = true ]; + string min_deposit_amount = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = true ]; + DrawSchedule draw_schedule = 4 [ (gogoproto.nullable) = true ]; + PrizeStrategy prize_strategy = 5 [ (gogoproto.nullable) = true ]; + string updater_address = 6 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgUpdatePoolResponse { +} + + +message MsgDeposit { + uint64 pool_id = 1; + cosmos.base.v1beta1.Coin amount = 2 [ (gogoproto.nullable) = false ]; + string depositor_address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string winner_address = 4 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + bool is_sponsor = 5; +} + +message MsgDepositResponse { + uint64 deposit_id = 1; +} + +message MsgDepositRetry { + uint64 pool_id = 1; + uint64 deposit_id = 2; + string depositor_address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgDepositRetryResponse { +} + +message MsgClaimPrize { + uint64 pool_id = 1; + uint64 draw_id = 2; + uint64 prize_id = 3; + string winner_address = 4 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgClaimPrizeResponse { +} + +message MsgWithdrawDeposit { + uint64 pool_id = 1; + uint64 deposit_id = 2; + string depositor_address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string to_address = 4 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgWithdrawDepositResponse { + uint64 withdrawal_id = 1; +} + +message MsgWithdrawDepositRetry { + uint64 pool_id = 1; + uint64 withdrawal_id = 2; + string depositor_address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgWithdrawDepositRetryResponse { +} + +message MsgDrawRetry { + uint64 pool_id = 1; + uint64 draw_id = 2; + string draw_retry_address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgDrawRetryResponse { +} + +message MsgRestoreInterchainAccounts { + uint64 pool_id = 1; + string restorer_address = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgRestoreInterchainAccountsResponse {} \ No newline at end of file diff --git a/proto/lum-network/millions/withdrawal.proto b/proto/lum-network/millions/withdrawal.proto new file mode 100644 index 00000000..b6933cf4 --- /dev/null +++ b/proto/lum-network/millions/withdrawal.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; +package lum.network.millions; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/lum-network/chain/x/millions/types"; + +enum WithdrawalState { + option (gogoproto.goproto_enum_prefix) = true; + + WITHDRAWAL_STATE_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "Unspecified" ]; + WITHDRAWAL_STATE_ICA_UNDELEGATE = 1 [ (gogoproto.enumvalue_customname) = "IcaUndelegate" ]; + WITHDRAWAL_STATE_ICA_UNBONDING = 2 [ (gogoproto.enumvalue_customname) = "IcaUnbonding" ]; + WITHDRAWAL_STATE_IBC_TRANSFER = 3 [ (gogoproto.enumvalue_customname) = "IbcTransfer" ]; + WITHDRAWAL_STATE_FAILURE = 4 [ (gogoproto.enumvalue_customname) = "Failure" ]; +} + +message Withdrawal { + uint64 pool_id = 1; + uint64 deposit_id = 2; + uint64 withdrawal_id = 3; + + WithdrawalState state = 4; + WithdrawalState error_state = 5; + + string depositor_address = 6 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string to_address = 7 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + cosmos.base.v1beta1.Coin amount = 8 [ (gogoproto.nullable) = false ]; + + int64 created_at_height = 9; + int64 updated_at_height = 10; + google.protobuf.Timestamp unbonding_ends_at = 11 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = true ]; + google.protobuf.Timestamp created_at = 12 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + google.protobuf.Timestamp updated_at = 13 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; +} + +message WithdrawalIDs { + uint64 pool_id = 1; + uint64 withdrawal_id = 2; +} + +message WithdrawalIDsCollection { + repeated WithdrawalIDs withdrawals_ids = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/readme.md b/readme.md index c735c9eb..f15bc734 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,6 @@ # Chain - Lum Network Implementation The first implementation of the Lum Network protocol, built on top of the Cosmos SDK. -Lum Network is a customer reward protocol and introduces mutable data channel in immutable ledgers. - [![codecov](https://codecov.io/gh/lum-network/chain/branch/master/graph/badge.svg)](https://codecov.io/gh/lum-network/chain) [![Go Report Card](https://goreportcard.com/badge/github.com/lum-network/chain)](https://goreportcard.com/report/github.com/lum-network/chain) [![license](https://img.shields.io/github/license/lum-network/chain.svg)](https://github.com/lum-network/chain/blob/main/LICENSE) diff --git a/tools/.env b/tools/.env index 3a9d8271..0d1eec37 100644 --- a/tools/.env +++ b/tools/.env @@ -1,3 +1,4 @@ GAIA_MNEMONIC=fiction inquiry pear evolve choose scatter spring weird cancel exile monster creek focus enforce celery object mistake desk glory broom welcome report car ritual JUNO_MNEMONIC=trim ginger ask swift allow pair wait hollow nephew diet during couple ignore exclude network gentle giant machine deliver iron fall bachelor notice scheme -OSMOSIS_MNEMONIC=write away right various pilot tongue lava spray disease false series found shiver bright citizen unable daring fat funny inquiry decide skill fragile yellow \ No newline at end of file +OSMOSIS_MNEMONIC=write away right various pilot tongue lava spray disease false series found shiver bright citizen unable daring fat funny inquiry decide skill fragile yellow +LUM_MNEMONIC=poem accuse sport census donor curious panther mean debris swap wire skin impose gym pretty dinosaur forget output dad steel venture farm gym pill \ No newline at end of file diff --git a/tools/config/hermes.toml b/tools/config/hermes.toml index 0616cf17..909eba7a 100644 --- a/tools/config/hermes.toml +++ b/tools/config/hermes.toml @@ -14,6 +14,7 @@ enabled = true enabled = true clear_interval = 100 clear_on_start = true +tx_confirmation = true [rest] enabled = true @@ -35,14 +36,14 @@ account_prefix = 'cosmos' key_name = 'hrly1' store_prefix = 'ibc' default_gas = 100000 -max_gas = 3000000 -gas_price = { price = 0.000, denom = 'uatom' } +max_gas = 5000000 +gas_price = { price = 0.001, denom = 'uatom' } gas_multiplier = 1.1 max_msg_num = 30 max_tx_size = 2097152 clock_drift = '5s' max_block_time = '10s' -trusting_period = '119s' +trusting_period = '14d' trust_threshold = { numerator = '1', denominator = '3' } address_type = { derivation = 'cosmos' } @@ -56,14 +57,14 @@ account_prefix = 'juno' key_name = 'hrly2' store_prefix = 'ibc' default_gas = 100000 -max_gas = 3000000 -gas_price = { price = 0.000, denom = 'ujuno' } +max_gas = 5000000 +gas_price = { price = 0.001, denom = 'ujuno' } gas_multiplier = 1.1 max_msg_num = 30 max_tx_size = 2097152 clock_drift = '5s' max_block_time = '10s' -trusting_period = '119s' +trusting_period = '14d' trust_threshold = { numerator = '1', denominator = '3' } address_type = { derivation = 'cosmos' } @@ -77,13 +78,34 @@ account_prefix = 'osmo' key_name = 'hrly3' store_prefix = 'ibc' default_gas = 100000 -max_gas = 3000000 -gas_price = { price = 0.000, denom = 'uosmo' } +max_gas = 5000000 +gas_price = { price = 0.001, denom = 'uosmo' } gas_multiplier = 1.1 max_msg_num = 30 max_tx_size = 2097152 clock_drift = '5s' max_block_time = '10s' -trusting_period = '119s' +trusting_period = '14d' +trust_threshold = { numerator = '1', denominator = '3' } +address_type = { derivation = 'cosmos' } + +[[chains]] +id = 'lumnetwork-testnet' +rpc_addr = 'http://host.docker.internal:26657' +grpc_addr = 'http://host.docker.internal:9090' +websocket_addr = 'ws://host.docker.internal:26657/websocket' +rpc_timeout = '10s' +account_prefix = 'lum' +key_name = 'hrly4' +store_prefix = 'ibc' +default_gas = 100000 +max_gas = 5000000 +gas_price = { price = 0.001, denom = 'ulum' } +gas_multiplier = 1.1 +max_msg_num = 30 +max_tx_size = 2097152 +clock_drift = '5s' +max_block_time = '10s' +trusting_period = '14d' trust_threshold = { numerator = '1', denominator = '3' } address_type = { derivation = 'cosmos' } \ No newline at end of file diff --git a/tools/docker-compose.yml b/tools/docker-compose.yml index 4baf5c52..3da7f8b5 100644 --- a/tools/docker-compose.yml +++ b/tools/docker-compose.yml @@ -5,17 +5,19 @@ services: build: context: . dockerfile: dockerfiles/Dockerfile.juno - image: juno-gaia + image: lum-juno ports: - - "26657:26657" - - "1317:1317" - - "9090:9090" + - "26757:26657" + - "1417:1317" + - "9190:9090" healthcheck: test: [ "CMD", "curl", "-f", "http://localhost:26657" ] interval: 10s timeout: 10s retries: 5 start_period: 20s + extra_hosts: + - "host.docker.internal:host-gateway" env_file: - .env command: @@ -40,7 +42,8 @@ services: sed -i 's/timeout_precommit = "1s"/timeout_precommit = "300ms"/g' /home/juno/.juno/config/config.toml sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "200ms"/g' /home/juno/.juno/config/config.toml sed -i 's/timeout_commit = "5s"/timeout_commit = "2s"/g' /home/juno/.juno/config/config.toml - junod start --rpc.laddr tcp://0.0.0.0:26657 + sed -i 's/\("allow_messages": \)\[[^]]*\]/\1["\/cosmos.bank.v1beta1.MsgSend", "\/cosmos.bank.v1beta1.MsgMultiSend", "\/cosmos.staking.v1beta1.MsgDelegate", "\/cosmos.staking.v1beta1.MsgUndelegate", "\/cosmos.staking.v1beta1.MsgBeginRedelegate", "\/cosmos.staking.v1beta1.MsgRedeemTokensforShares", "\/cosmos.staking.v1beta1.MsgTokenizeShares", "\/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", "\/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", "\/ibc.applications.transfer.v1.MsgTransfer"]/' /home/juno/.juno/config/genesis.json + junod start --rpc.laddr tcp://0.0.0.0:26657 --pruning nothing gaia-local-net: build: @@ -57,6 +60,8 @@ services: timeout: 10s retries: 5 start_period: 20s + extra_hosts: + - "host.docker.internal:host-gateway" env_file: - .env command: @@ -81,7 +86,8 @@ services: sed -i 's/timeout_precommit = "1s"/timeout_precommit = "300ms"/g' /home/gaia/.gaia/config/config.toml sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "200ms"/g' /home/gaia/.gaia/config/config.toml sed -i 's/timeout_commit = "5s"/timeout_commit = "2s"/g' /home/gaia/.gaia/config/config.toml - gaiad start --rpc.laddr tcp://0.0.0.0:26657 + sed -i 's/\("allow_messages": \)\[[^]]*\]/\1["\/cosmos.bank.v1beta1.MsgSend", "\/cosmos.bank.v1beta1.MsgMultiSend", "\/cosmos.staking.v1beta1.MsgDelegate", "\/cosmos.staking.v1beta1.MsgUndelegate", "\/cosmos.staking.v1beta1.MsgBeginRedelegate", "\/cosmos.staking.v1beta1.MsgRedeemTokensforShares", "\/cosmos.staking.v1beta1.MsgTokenizeShares", "\/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", "\/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", "\/ibc.applications.transfer.v1.MsgTransfer"]/' /home/gaia/.gaia/config/genesis.json + gaiad start --rpc.laddr tcp://0.0.0.0:26657 --pruning nothing osmosis-local-net: build: @@ -98,6 +104,8 @@ services: timeout: 10s retries: 5 start_period: 20s + extra_hosts: + - "host.docker.internal:host-gateway" env_file: - .env command: @@ -122,7 +130,8 @@ services: sed -i 's/timeout_precommit = "1s"/timeout_precommit = "300ms"/g' /home/osmosis/.osmosisd/config/config.toml sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "200ms"/g' /home/osmosis/.osmosisd/config/config.toml sed -i 's/timeout_commit = "5s"/timeout_commit = "2s"/g' /home/osmosis/.osmosisd/config/config.toml - osmosisd start --rpc.laddr tcp://0.0.0.0:26657 + sed -i 's/\("allow_messages": \)\[[^]]*\]/\1["\/cosmos.bank.v1beta1.MsgSend", "\/cosmos.bank.v1beta1.MsgMultiSend", "\/cosmos.staking.v1beta1.MsgDelegate", "\/cosmos.staking.v1beta1.MsgUndelegate", "\/cosmos.staking.v1beta1.MsgBeginRedelegate", "\/cosmos.staking.v1beta1.MsgRedeemTokensforShares", "\/cosmos.staking.v1beta1.MsgTokenizeShares", "\/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", "\/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", "\/ibc.applications.transfer.v1.MsgTransfer"]/' /home/osmosis/.osmosisd/config/genesis.json + osmosisd start --rpc.laddr tcp://0.0.0.0:26657 --pruning nothing relayer-local-net: build: @@ -133,12 +142,15 @@ services: - .env ports: - "12000:3000" + - "13000:3001" healthcheck: test: [ "CMD", "curl", "-f", "http://localhost:3000/version" ] interval: 10s timeout: 10s retries: 5 start_period: 20s + extra_hosts: + - "host.docker.internal:host-gateway" depends_on: juno-local-net: condition: service_healthy @@ -161,4 +173,6 @@ services: hermes keys add --key-name hrly2 --chain juno-devnet --mnemonic-file juno.txt --overwrite echo $OSMOSIS_MNEMONIC > osmosis.txt hermes keys add --key-name hrly3 --chain osmosis-devnet --mnemonic-file osmosis.txt --overwrite + echo $LUM_MNEMONIC > lum.txt + hermes keys add --key-name hrly4 --chain lumnetwork-testnet --mnemonic-file lum.txt --overwrite --hd-path "m/44'/880'/0'/0/0" hermes start \ No newline at end of file diff --git a/tools/dockerfiles/Dockerfile.gaia b/tools/dockerfiles/Dockerfile.gaia index 551899a4..88bc7a0d 100644 --- a/tools/dockerfiles/Dockerfile.gaia +++ b/tools/dockerfiles/Dockerfile.gaia @@ -4,7 +4,7 @@ WORKDIR /opt RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev python3 -ENV COMMIT_HASH=v7.1.0 +ENV COMMIT_HASH=v9.0.1 RUN git clone https://github.com/cosmos/gaia.git gaia-install \ && cd gaia-install \ diff --git a/tools/dockerfiles/Dockerfile.hermes b/tools/dockerfiles/Dockerfile.hermes index 0461a4d7..59077ede 100644 --- a/tools/dockerfiles/Dockerfile.hermes +++ b/tools/dockerfiles/Dockerfile.hermes @@ -4,7 +4,7 @@ WORKDIR /opt RUN apt update && apt install git bash curl -y -ENV COMMIT_HASH=v1.2.0 +ENV COMMIT_HASH=v1.4.1 RUN git clone https://github.com/informalsystems/ibc-rs \ && cd ibc-rs \ && git checkout $COMMIT_HASH \ diff --git a/tools/dockerfiles/Dockerfile.juno b/tools/dockerfiles/Dockerfile.juno index 4336794d..0895ab80 100644 --- a/tools/dockerfiles/Dockerfile.juno +++ b/tools/dockerfiles/Dockerfile.juno @@ -6,7 +6,7 @@ RUN set -eux; apk add --no-cache ca-certificates build-base git; RUN git clone https://github.com/CosmosContracts/juno.git \ && cd juno \ - && git checkout v11.0.0 + && git checkout v13.0.0 WORKDIR /opt/juno diff --git a/tools/dockerfiles/Dockerfile.osmosis b/tools/dockerfiles/Dockerfile.osmosis index 949512bd..5f40df5a 100644 --- a/tools/dockerfiles/Dockerfile.osmosis +++ b/tools/dockerfiles/Dockerfile.osmosis @@ -1,10 +1,10 @@ -FROM golang:1.18-alpine3.15 AS builder +FROM golang:1.19-alpine3.15 AS builder WORKDIR /opt/ RUN set -eux; apk add --no-cache ca-certificates build-base; apk add git linux-headers -ENV COMMIT_HASH=v13.1.0 +ENV COMMIT_HASH=v15.0.0 RUN git clone https://github.com/osmosis-labs/osmosis.git \ && cd osmosis \ diff --git a/x/airdrop/handler.go b/x/airdrop/handler.go index 39a16b92..16ee292c 100644 --- a/x/airdrop/handler.go +++ b/x/airdrop/handler.go @@ -3,6 +3,7 @@ package airdrop import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/lum-network/chain/x/airdrop/keeper" @@ -14,13 +15,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { // this line is used by starport scaffolding # handler/msgServer return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - // this line is used by starport scaffolding # 1 - default: - errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - } + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } diff --git a/x/airdrop/keeper/keeper.go b/x/airdrop/keeper/keeper.go index 8e93b87c..8c5b4fe9 100644 --- a/x/airdrop/keeper/keeper.go +++ b/x/airdrop/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "errors" "fmt" + "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -27,8 +28,8 @@ type ( memKey storetypes.StoreKey AuthKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper - StakingKeeper stakingkeeper.Keeper - DistrKeeper distrkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + DistrKeeper *distrkeeper.Keeper } ) @@ -38,8 +39,8 @@ func NewKeeper( memKey storetypes.StoreKey, ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, - sk stakingkeeper.Keeper, - dk distrkeeper.Keeper, + sk *stakingkeeper.Keeper, + dk *distrkeeper.Keeper, ) *Keeper { return &Keeper{ diff --git a/x/airdrop/keeper/keeper_test.go b/x/airdrop/keeper/keeper_test.go index a032b621..de68a545 100644 --- a/x/airdrop/keeper/keeper_test.go +++ b/x/airdrop/keeper/keeper_test.go @@ -1,11 +1,12 @@ package keeper_test import ( - "github.com/lum-network/chain/app" - testing2 "github.com/lum-network/chain/app/testing" "testing" "time" + "github.com/lum-network/chain/app" + testing2 "github.com/lum-network/chain/app/testing" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -174,7 +175,8 @@ func (suite *KeeperTestSuite) TestHookAfterAirdropEnd() { suite.Require().NoError(err) suite.ctx = suite.ctx.WithBlockTime(params.AirdropStartTime.Add(params.DurationUntilDecay).Add(params.DurationOfDecay)) - suite.app.AirdropKeeper.EndAirdrop(suite.ctx) + err = suite.app.AirdropKeeper.EndAirdrop(suite.ctx) + suite.Require().NoError(err) suite.Require().NotPanics(func() { suite.app.AirdropKeeper.AfterProposalVote(suite.ctx, 12, addr1) @@ -290,7 +292,8 @@ func (suite *KeeperTestSuite) TestDelegationAutoWithdrawAndDelegateMore() { validator, err := stakingtypes.NewValidator(sdk.ValAddress(addrs[0]), pub1, stakingtypes.Description{}) suite.Require().NoError(err) validator = stakingkeeper.TestingUpdateValidator(*suite.app.StakingKeeper, suite.ctx, validator, true) - suite.app.StakingKeeper.AfterValidatorCreated(suite.ctx, validator.GetOperator()) + err = suite.app.StakingKeeper.AfterValidatorCreated(suite.ctx, validator.GetOperator()) + suite.Require().NoError(err) validator, _ = validator.AddTokensFromDel(sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction)) delAmount := sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction) diff --git a/x/airdrop/keeper/params.go b/x/airdrop/keeper/params.go index 61aca3ce..50c42ee3 100644 --- a/x/airdrop/keeper/params.go +++ b/x/airdrop/keeper/params.go @@ -23,4 +23,4 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { } store.Set([]byte(types.ParamsKey), bz) return nil -} \ No newline at end of file +} diff --git a/x/airdrop/module.go b/x/airdrop/module.go index 6fae3bce..05d2d022 100644 --- a/x/airdrop/module.go +++ b/x/airdrop/module.go @@ -134,6 +134,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // Register migration mig := keeper.NewMigrator(am.keeper) + //nolint:errcheck cfg.RegisterMigration(types.ModuleName, 2, mig.Migrate2to3) } diff --git a/x/airdrop/types/claim.pb.go b/x/airdrop/types/claim.pb.go index 6e28338a..54a6b38f 100644 --- a/x/airdrop/types/claim.pb.go +++ b/x/airdrop/types/claim.pb.go @@ -7,7 +7,7 @@ import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/airdrop/types/codec.go b/x/airdrop/types/codec.go index 133646fd..5fc2d08e 100644 --- a/x/airdrop/types/codec.go +++ b/x/airdrop/types/codec.go @@ -3,6 +3,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + // this line is used by starport scaffolding # 1 "github.com/cosmos/cosmos-sdk/types/msgservice" ) @@ -18,6 +19,5 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - amino = codec.NewLegacyAmino() ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) ) diff --git a/x/airdrop/types/errors.go b/x/airdrop/types/errors.go index 3db846eb..5c3965cb 100644 --- a/x/airdrop/types/errors.go +++ b/x/airdrop/types/errors.go @@ -1,4 +1,3 @@ package types // DONTCOVER - diff --git a/x/airdrop/types/events.go b/x/airdrop/types/events.go index 649b8526..0931a8b6 100644 --- a/x/airdrop/types/events.go +++ b/x/airdrop/types/events.go @@ -1,5 +1,5 @@ package types const ( - EventTypeClaim = "claim" + EventTypeClaim = "claim" ) diff --git a/x/airdrop/types/genesis.pb.go b/x/airdrop/types/genesis.pb.go index 10ba0da4..0cf3eb10 100644 --- a/x/airdrop/types/genesis.pb.go +++ b/x/airdrop/types/genesis.pb.go @@ -6,9 +6,10 @@ package types import ( fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/airdrop/types/keys.go b/x/airdrop/types/keys.go index bbd13ce6..8b08570d 100644 --- a/x/airdrop/types/keys.go +++ b/x/airdrop/types/keys.go @@ -24,4 +24,4 @@ const ( // ActionKey defines the store key to store user accomplished actions ActionKey = "action" -) \ No newline at end of file +) diff --git a/x/airdrop/types/params.go b/x/airdrop/types/params.go index 19c39aef..cc31cbfe 100644 --- a/x/airdrop/types/params.go +++ b/x/airdrop/types/params.go @@ -8,4 +8,4 @@ var ( DefaultClaimDenom = "ulum" DefaultDurationUntilDecay = time.Hour DefaultDurationOfDecay = time.Hour * 5 -) \ No newline at end of file +) diff --git a/x/airdrop/types/params.pb.go b/x/airdrop/types/params.pb.go index a72d7ae9..c9798f00 100644 --- a/x/airdrop/types/params.pb.go +++ b/x/airdrop/types/params.pb.go @@ -5,10 +5,11 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/airdrop/types/query.pb.go b/x/airdrop/types/query.pb.go index 2cf2ba54..256b5405 100644 --- a/x/airdrop/types/query.pb.go +++ b/x/airdrop/types/query.pb.go @@ -9,7 +9,7 @@ import ( github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/airdrop/types/query.pb.gw.go b/x/airdrop/types/query.pb.gw.go index e8a352d5..dfb0a656 100644 --- a/x/airdrop/types/query.pb.gw.go +++ b/x/airdrop/types/query.pb.gw.go @@ -525,15 +525,15 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_ModuleAccountBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "claim", "v1beta1", "module_account_balance"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_ModuleAccountBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "claim", "v1beta1", "module_account_balance"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "claim", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "claim", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_ClaimRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "claim", "v1beta1", "claim_record", "address"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_ClaimRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "claim", "v1beta1", "claim_record", "address"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_ClaimableForAction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"osmosis", "claim", "v1beta1", "claimable_for_action", "address", "action"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_ClaimableForAction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"osmosis", "claim", "v1beta1", "claimable_for_action", "address", "action"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_TotalClaimable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "claim", "v1beta1", "total_claimable", "address"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_TotalClaimable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "claim", "v1beta1", "total_claimable", "address"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/x/beam/keeper/keeper.go b/x/beam/keeper/keeper.go index c743436c..a72aa4a8 100644 --- a/x/beam/keeper/keeper.go +++ b/x/beam/keeper/keeper.go @@ -2,6 +2,8 @@ package keeper import ( "fmt" + "strings" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -10,7 +12,6 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/lum-network/chain/utils" "github.com/tendermint/tendermint/libs/log" - "strings" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,12 +25,12 @@ type ( memKey storetypes.StoreKey AuthKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper - StakingKeeper stakingkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper } ) // NewKeeper Create a new keeper instance and return the pointer -func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey, auth authkeeper.AccountKeeper, bank bankkeeper.Keeper, sk stakingkeeper.Keeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey, auth authkeeper.AccountKeeper, bank bankkeeper.Keeper, sk *stakingkeeper.Keeper) *Keeper { return &Keeper{ cdc: cdc, storeKey: storeKey, diff --git a/x/beam/types/beam.pb.go b/x/beam/types/beam.pb.go index 61619326..5c847e8d 100644 --- a/x/beam/types/beam.pb.go +++ b/x/beam/types/beam.pb.go @@ -7,10 +7,10 @@ import ( encoding_binary "encoding/binary" fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/beam/types/genesis.go b/x/beam/types/genesis.go index 33c04fa9..ef6d3224 100644 --- a/x/beam/types/genesis.go +++ b/x/beam/types/genesis.go @@ -9,7 +9,7 @@ import ( // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - Beams: []*Beam{}, + Beams: []*Beam{}, ModuleAccountBalance: sdk.NewCoin(DefaultBeamDenom, sdk.ZeroInt()), } } diff --git a/x/beam/types/genesis.pb.go b/x/beam/types/genesis.pb.go index 22920c67..0468d692 100644 --- a/x/beam/types/genesis.pb.go +++ b/x/beam/types/genesis.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/beam/types/params.go b/x/beam/types/params.go index dab3f8bc..f079aafe 100644 --- a/x/beam/types/params.go +++ b/x/beam/types/params.go @@ -1,5 +1,5 @@ package types var ( - DefaultBeamDenom = "ulum" -) \ No newline at end of file + DefaultBeamDenom = "ulum" +) diff --git a/x/beam/types/query.pb.gw.go b/x/beam/types/query.pb.gw.go index 84eaf867..5ed58730 100644 --- a/x/beam/types/query.pb.gw.go +++ b/x/beam/types/query.pb.gw.go @@ -339,11 +339,11 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Beam_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"lum-network", "beams", "id"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Beam_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"lum-network", "beams", "id"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Beams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"lum-network", "beams"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Beams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"lum-network", "beams"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_BeamsOpenQueue_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"lum-network", "beams-open-queue"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_BeamsOpenQueue_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"lum-network", "beams-open-queue"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/x/beam/types/tx.pb.go b/x/beam/types/tx.pb.go index e74715a8..2f6b2d0a 100644 --- a/x/beam/types/tx.pb.go +++ b/x/beam/types/tx.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/dfract/keeper/keeper.go b/x/dfract/keeper/keeper.go index aa0c58ef..50b82d4e 100644 --- a/x/dfract/keeper/keeper.go +++ b/x/dfract/keeper/keeper.go @@ -40,12 +40,12 @@ type ( AuthKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper GovKeeper govkeeper.Keeper - StakingKeeper stakingkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper } ) // NewKeeper Create a new keeper instance and return the pointer -func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey, paramSpace paramtypes.Subspace, auth authkeeper.AccountKeeper, bank bankkeeper.Keeper, sk stakingkeeper.Keeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey, paramSpace paramtypes.Subspace, auth authkeeper.AccountKeeper, bank bankkeeper.Keeper, sk *stakingkeeper.Keeper) *Keeper { moduleAddr, perms := auth.GetModuleAddressAndPermissions(types.ModuleName) if moduleAddr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) diff --git a/x/dfract/types/deposit.pb.go b/x/dfract/types/deposit.pb.go index 84f29207..cf10db0a 100644 --- a/x/dfract/types/deposit.pb.go +++ b/x/dfract/types/deposit.pb.go @@ -6,10 +6,10 @@ package types import ( fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/dfract/types/genesis.pb.go b/x/dfract/types/genesis.pb.go index 01e21674..fd25868b 100644 --- a/x/dfract/types/genesis.pb.go +++ b/x/dfract/types/genesis.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/dfract/types/proposal.pb.go b/x/dfract/types/proposal.pb.go index 3601d80e..46bc5057 100644 --- a/x/dfract/types/proposal.pb.go +++ b/x/dfract/types/proposal.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" _ "github.com/cosmos/cosmos-proto" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -70,27 +70,26 @@ func init() { func init() { proto.RegisterFile("lum-network/dfract/proposal.proto", fileDescriptor_772837b20d238e17) } var fileDescriptor_772837b20d238e17 = []byte{ - // 319 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x4e, 0xeb, 0x30, - 0x14, 0x86, 0xe3, 0xdb, 0x0b, 0x12, 0x41, 0x08, 0x61, 0x55, 0x22, 0x74, 0x70, 0x0b, 0x43, 0x55, - 0x09, 0x35, 0x51, 0xc5, 0xc6, 0x56, 0x98, 0x18, 0x90, 0x50, 0x17, 0x24, 0x96, 0xc8, 0x4d, 0x4c, - 0x6a, 0x11, 0xfb, 0x44, 0xf6, 0x69, 0x0b, 0x6f, 0xc0, 0xc8, 0xc8, 0xd8, 0x91, 0x07, 0xe0, 0x21, - 0x10, 0x53, 0x47, 0x46, 0x94, 0xbe, 0x08, 0x6a, 0x1c, 0x44, 0x37, 0x9f, 0xff, 0xfb, 0x64, 0xfb, - 0xfc, 0xfe, 0x71, 0x3e, 0x55, 0x7d, 0x2d, 0x70, 0x0e, 0xe6, 0x21, 0x4a, 0xef, 0x0d, 0x4f, 0x30, - 0x2a, 0x0c, 0x14, 0x60, 0x79, 0x1e, 0x16, 0x06, 0x10, 0x28, 0xcd, 0xa7, 0x2a, 0xac, 0x95, 0xd0, - 0x29, 0xad, 0x66, 0x06, 0x19, 0x54, 0x38, 0x5a, 0x9f, 0x9c, 0xd9, 0x3a, 0x4a, 0xc0, 0x2a, 0xb0, - 0xb1, 0x03, 0x6e, 0x70, 0xe8, 0x64, 0x49, 0xfc, 0xc3, 0x5b, 0x89, 0x93, 0xd4, 0xf0, 0xf9, 0x50, - 0xa7, 0xd7, 0x52, 0xe3, 0x4d, 0xfd, 0x0c, 0x6d, 0xfa, 0x5b, 0x28, 0x31, 0x17, 0x01, 0xe9, 0x90, - 0xde, 0xce, 0xc8, 0x0d, 0xb4, 0xe3, 0xef, 0xa6, 0xc2, 0x26, 0x46, 0x16, 0x28, 0x41, 0x07, 0xff, - 0x2a, 0xb6, 0x19, 0xd1, 0xbe, 0x4f, 0xe7, 0xf5, 0x95, 0x3c, 0x8f, 0x79, 0x9a, 0x1a, 0x61, 0x6d, - 0xd0, 0xa8, 0xc4, 0x83, 0x3f, 0x32, 0x74, 0x80, 0x76, 0xfd, 0x7d, 0x25, 0x13, 0x03, 0xb1, 0x92, - 0x1a, 0x63, 0xc3, 0x51, 0x04, 0xff, 0x3b, 0xa4, 0xd7, 0x18, 0xed, 0x55, 0xf1, 0xfa, 0x4b, 0x23, - 0x8e, 0xe2, 0xbc, 0xfb, 0xbc, 0x68, 0x7b, 0xaf, 0x8b, 0xb6, 0xf7, 0xf9, 0xde, 0x6f, 0xd5, 0x4b, - 0x64, 0x30, 0x0b, 0x67, 0x83, 0xb1, 0x40, 0x3e, 0x08, 0x2f, 0x41, 0xa3, 0xd0, 0x78, 0x71, 0xf5, - 0x56, 0x32, 0xf2, 0x51, 0x32, 0xb2, 0x2c, 0x19, 0xf9, 0x2e, 0x19, 0x79, 0x59, 0x31, 0x6f, 0xb9, - 0x62, 0xde, 0xd7, 0x8a, 0x79, 0x77, 0xa7, 0x99, 0xc4, 0xc9, 0x74, 0x1c, 0x26, 0xa0, 0xa2, 0xcd, - 0x8e, 0x93, 0x09, 0x97, 0x3a, 0x7a, 0xfc, 0xed, 0x1a, 0x9f, 0x0a, 0x61, 0xc7, 0xdb, 0x55, 0x49, - 0x67, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x81, 0xe3, 0xfa, 0xbd, 0x8e, 0x01, 0x00, 0x00, + // 297 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x31, 0x4b, 0x33, 0x31, + 0x1c, 0xc6, 0x2f, 0x6f, 0x5f, 0x05, 0xa3, 0x22, 0x86, 0x82, 0x67, 0x87, 0xb4, 0x3a, 0x48, 0x41, + 0x7a, 0x37, 0xb8, 0xb9, 0x55, 0x70, 0x14, 0xa4, 0x8b, 0xe0, 0x72, 0xa4, 0x49, 0x6c, 0x83, 0x97, + 0xfc, 0x8f, 0xe4, 0x5f, 0xaa, 0xdf, 0xc0, 0xd1, 0xd1, 0xb1, 0x9f, 0xc2, 0xcf, 0xe0, 0xd8, 0xd1, + 0x51, 0xda, 0xc5, 0x8f, 0x21, 0xbd, 0x54, 0xec, 0x96, 0xe7, 0xf9, 0xfd, 0x48, 0xc2, 0x43, 0x4f, + 0xca, 0x89, 0xed, 0x39, 0x8d, 0x53, 0xf0, 0x8f, 0xb9, 0x7a, 0xf0, 0x42, 0x62, 0x5e, 0x79, 0xa8, + 0x20, 0x88, 0x32, 0xab, 0x3c, 0x20, 0x30, 0x56, 0x4e, 0x6c, 0xb6, 0x56, 0xb2, 0xa8, 0xb4, 0x9a, + 0x23, 0x18, 0x41, 0x8d, 0xf3, 0xd5, 0x29, 0x9a, 0xad, 0x63, 0x09, 0xc1, 0x42, 0x28, 0x22, 0x88, + 0x21, 0xa2, 0xd3, 0x77, 0x42, 0x8f, 0xee, 0x0c, 0x8e, 0x95, 0x17, 0xd3, 0xbe, 0x53, 0x37, 0xc6, + 0xe1, 0xed, 0xfa, 0x19, 0xd6, 0xa4, 0x5b, 0x68, 0xb0, 0xd4, 0x29, 0xe9, 0x90, 0xee, 0xce, 0x20, + 0x06, 0xd6, 0xa1, 0xbb, 0x4a, 0x07, 0xe9, 0x4d, 0x85, 0x06, 0x5c, 0xfa, 0xaf, 0x66, 0x9b, 0x15, + 0xeb, 0x51, 0x36, 0x5d, 0x5f, 0x29, 0xca, 0x42, 0x28, 0xe5, 0x75, 0x08, 0x69, 0xa3, 0x16, 0x0f, + 0xff, 0x48, 0x3f, 0x02, 0x76, 0x46, 0x0f, 0xac, 0x91, 0x1e, 0x0a, 0x6b, 0x1c, 0x16, 0x5e, 0xa0, + 0x4e, 0xff, 0x77, 0x48, 0xb7, 0x31, 0xd8, 0xaf, 0xeb, 0xd5, 0x97, 0x06, 0x02, 0xf5, 0xe5, 0xde, + 0xcb, 0xac, 0x9d, 0xbc, 0xcd, 0xda, 0xc9, 0xf7, 0xac, 0x4d, 0xae, 0xae, 0x3f, 0x16, 0x9c, 0xcc, + 0x17, 0x9c, 0x7c, 0x2d, 0x38, 0x79, 0x5d, 0xf2, 0x64, 0xbe, 0xe4, 0xc9, 0xe7, 0x92, 0x27, 0xf7, + 0xe7, 0x23, 0x83, 0xe3, 0xc9, 0x30, 0x93, 0x60, 0xf3, 0xcd, 0x15, 0xe5, 0x58, 0x18, 0x97, 0x3f, + 0xfd, 0xae, 0x89, 0xcf, 0x95, 0x0e, 0xc3, 0xed, 0x7a, 0x86, 0x8b, 0x9f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x22, 0xd6, 0x2e, 0x56, 0x70, 0x01, 0x00, 0x00, } func (this *WithdrawAndMintProposal) Equal(that interface{}) bool { diff --git a/x/dfract/types/query.pb.go b/x/dfract/types/query.pb.go index 8dbb2d09..d9ef8515 100644 --- a/x/dfract/types/query.pb.go +++ b/x/dfract/types/query.pb.go @@ -9,7 +9,7 @@ import ( github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/dfract/types/query.pb.gw.go b/x/dfract/types/query.pb.gw.go index 71982b6a..ccd9d891 100644 --- a/x/dfract/types/query.pb.gw.go +++ b/x/dfract/types/query.pb.gw.go @@ -382,13 +382,13 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_ModuleAccountBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "dfract", "module_account_balance"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_ModuleAccountBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "dfract", "module_account_balance"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "dfract", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "dfract", "params"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_GetDepositsForAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "dfract", "deposits", "address"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetDepositsForAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "dfract", "deposits", "address"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_FetchDeposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "dfract", "deposits"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_FetchDeposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "dfract", "deposits"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/x/dfract/types/tx.pb.go b/x/dfract/types/tx.pb.go index a0c4c1d9..1e1617eb 100644 --- a/x/dfract/types/tx.pb.go +++ b/x/dfract/types/tx.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" diff --git a/x/icacallbacks/README.md b/x/icacallbacks/README.md new file mode 100644 index 00000000..d762e9fe --- /dev/null +++ b/x/icacallbacks/README.md @@ -0,0 +1,70 @@ +--- +title: "Icacallbacks" +excerpt: "" +category: 6392913957c533007128548e +--- + +# The ICACallbacks Module + +Add `icacallbacks` module. Interchain accounts are very useful, but ICA calls triggered by automated logic on Stride are limited in functionality and difficult to work with due to a lack of callbacks. Most of Stride's interchain account logic is triggered epochly from the `BeginBlocker`, and state updates on Stride must be made after ICA calls are issued, based on the success / failure of those calls. + +The challenges faced before creating the icacallbacks modules were: +(1) Messages must be handled one-off (by matching on message type) - really what we want to do is update state in acks based on the _transaction_ sent +(2) Message responses are almost always empty, e.g. `MsgDelegateResponse`, which leads to +(3) Matching processed messages to state on the controller is very challenging (sometimes impossible) based on the attributes of the message sent. For example, given the following type + +``` +type Gift struct { + from string + to string + amount int + reason string +} +``` + +two ICA bank sends associated with gifts that have the same `from`, `to` and `amount` but _different_ `reasons` are indistinguishable today in acks. + +`icacontroller` solves the issues as follows + +- Callbacks can be registered to process data associated with a particular IBC packet, per module (solves 1) +- ICA auth modules can store callback data using `icacallbacks`, passing in both a callback and args +- Arguments to the callback can be (un)marshaled and contain arbitrary keys, allowing for updates to data on the controller chain based on the success / failure of the ICA call (solves 2 / 3) + +### Technical notes + +- Callbacks are uniquely identifiable through `portId/channelId/sequence` keys +- Only modules that have registered callbacks can invoke them +- `icacallbacks` doesn't have a message server / handler (it can only be called by other modules) +- `icacallbacks` does authentication by fetching the module associated with a packet (containing the registered callbacks) by calling `ChannelKeeper.LookupModuleByChannel` (it's permissioned at the module level) +- `icacallbacks` is an interchain account auth module, although it's possible this design could be generalized to work with other IBC modules +- in case of a timeout, callbacks are still executed with the ack set to an empty byte array +- We're using protos to serialize / deserialize callback arguments + +The flow to add callbacks is to call `ICACallbacksKeeper.SetCallbackData` after sending an IBC transaction. When the ack returns + +- the callback is fetched using the callback key +- the module is fetched using the portId / channelId +and the callback is invoked and deleted. + +The middleware structure is as follows +![middleware](https://user-images.githubusercontent.com/1331345/183272460-5225d67d-95ee-47e2-8200-11de013a0695.png) + +### Invariants + +- `portId, channelId` pair map to a unique module (important for fetching the correct `CallbackHandler` from a received packet) +- callback ids are unique within modules (they don't have to be unique between modules, because `CallICACallback` is scoped to a module) + +## Keeper functions + +- `CallRegisteredICACallback()`: invokes the relevant callback asssociated with an ICA + +## State + +- `CallbackData`: stores the callback type, arguments and associated packet +- `CallbackHandler` +- `Callbacks` +- `Callback` + +## Events + +The `icacallbacks` module does not currently emit any events. diff --git a/x/icacallbacks/client/cli/query.go b/x/icacallbacks/client/cli/query.go new file mode 100644 index 00000000..f861a285 --- /dev/null +++ b/x/icacallbacks/client/cli/query.go @@ -0,0 +1,116 @@ +package cli + +import ( + "context" + "fmt" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group icacallbacks queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdListCallbackData()) + cmd.AddCommand(CmdShowCallbackData()) + return cmd +} + +func CmdListCallbackData() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-callback-data", + Short: "list all callback-data", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllCallbackDataRequest{ + Pagination: pageReq, + } + + res, err := queryClient.CallbackDataAll(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowCallbackData() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-callback-data [callback-key]", + Short: "shows a callback-data", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + argCallbackKey := args[0] + + params := &types.QueryGetCallbackDataRequest{ + CallbackKey: argCallbackKey, + } + + res, err := queryClient.CallbackData(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/icacallbacks/client/cli/tx.go b/x/icacallbacks/client/cli/tx.go new file mode 100644 index 00000000..533a5ee9 --- /dev/null +++ b/x/icacallbacks/client/cli/tx.go @@ -0,0 +1,26 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + // "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + // this line is used by starport scaffolding # 1 + + return cmd +} diff --git a/x/icacallbacks/genesis.go b/x/icacallbacks/genesis.go new file mode 100644 index 00000000..32df7b41 --- /dev/null +++ b/x/icacallbacks/genesis.go @@ -0,0 +1,29 @@ +package icacallbacks + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lum-network/chain/x/icacallbacks/keeper" + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set all the callbackData + for _, elem := range genState.CallbackDataList { + k.SetCallbackData(ctx, elem) + } + // this line is used by starport scaffolding # genesis/module/init + k.SetParams(ctx, genState.Params) +} + +// ExportGenesis returns the capability module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + genesis.CallbackDataList = k.GetAllCallbackData(ctx) + // this line is used by starport scaffolding # genesis/module/export + + return genesis +} diff --git a/x/icacallbacks/genesis_test.go b/x/icacallbacks/genesis_test.go new file mode 100644 index 00000000..1e07e06a --- /dev/null +++ b/x/icacallbacks/genesis_test.go @@ -0,0 +1,42 @@ +package icacallbacks_test + +import ( + apptypes "github.com/lum-network/chain/app" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Stride-Labs/stride/v6/testutil/nullify" + "github.com/lum-network/chain/x/icacallbacks" + "github.com/lum-network/chain/x/icacallbacks/types" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + PortId: types.PortID, + CallbackDataList: []types.CallbackData{ + { + CallbackKey: "0", + }, + { + CallbackKey: "1", + }, + }, + // this line is used by starport scaffolding # genesis/test/state + } + + app := apptypes.SetupForTesting(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + icacallbacks.InitGenesis(ctx, *app.ICACallbacksKeeper, genesisState) + got := icacallbacks.ExportGenesis(ctx, *app.ICACallbacksKeeper) + require.NotNil(t, got) + + nullify.Fill(&genesisState) + nullify.Fill(got) + + require.Equal(t, genesisState.PortId, got.PortId) + + require.ElementsMatch(t, genesisState.CallbackDataList, got.CallbackDataList) +} diff --git a/x/icacallbacks/handler.go b/x/icacallbacks/handler.go new file mode 100644 index 00000000..55692838 --- /dev/null +++ b/x/icacallbacks/handler.go @@ -0,0 +1,29 @@ +package icacallbacks + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/lum-network/chain/x/icacallbacks/keeper" + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// NewHandler ... +func NewHandler(k keeper.Keeper) sdk.Handler { + // this line is used by starport scaffolding # handler/msgServer + + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + _ = ctx + + switch msg := msg.(type) { + // this line is used by starport scaffolding # 1 + default: + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } + } +} diff --git a/x/icacallbacks/icacallbacks.go b/x/icacallbacks/icacallbacks.go new file mode 100644 index 00000000..27a46679 --- /dev/null +++ b/x/icacallbacks/icacallbacks.go @@ -0,0 +1,86 @@ +package icacallbacks + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + "github.com/gogo/protobuf/proto" + "github.com/tendermint/tendermint/libs/log" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// Parses ICA tx responses and returns a list of each serialized response +// The format of the raw ack differs depending on which version of ibc-go is used +// For v4 and prior, the message responses are stored under the `Data` attribute of TxMsgData +// For v5 and later, the message responses are stored under the `MsgResponse` attribute of TxMsgdata +func ParseTxMsgData(acknowledgementResult []byte) ([][]byte, error) { + txMsgData := &sdk.TxMsgData{} + if err := proto.Unmarshal(acknowledgementResult, txMsgData); err != nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %s", err.Error()) + } + + // Unpack all the message responses based on the sdk version (determined from the length of txMsgData.Data) + switch len(txMsgData.Data) { + case 0: + // for SDK 0.46 and above + msgResponses := make([][]byte, len(txMsgData.MsgResponses)) + for i, msgResponse := range txMsgData.MsgResponses { + msgResponses[i] = msgResponse.GetValue() + } + return msgResponses, nil + default: + // for SDK 0.45 and below + var msgResponses = make([][]byte, len(txMsgData.Data)) + for i, msgData := range txMsgData.Data { + msgResponses[i] = msgData.Data + } + return msgResponses, nil + } +} + +// UnpackAcknowledgementResponse unmarshals IBC Acknowledgements, determines the status of the acknowledgement (success or failure) +// and, if applicable, assembles the message responses +// +// ICA transactions have associated messages responses. IBC transfer do not. +// With ICA transactions, the schema of the response differs depending on the version of ibc-go used, +// however, this function unifies the format into a common response (a slice of byte arrays) +func UnpackAcknowledgementResponse(ctx sdk.Context, logger log.Logger, ack []byte, isICA bool) (*types.AcknowledgementResponse, error) { + // Unmarshal the raw ack response + var acknowledgement channeltypes.Acknowledgement + if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(ack, &acknowledgement); err != nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %s", err.Error()) + } + + // The ack can come back as either AcknowledgementResult or AcknowledgementError + // If it comes back as AcknowledgementResult, the messages are encoded differently depending on the SDK version + switch response := acknowledgement.Response.(type) { + case *channeltypes.Acknowledgement_Result: + if len(response.Result) == 0 { + return nil, errorsmod.Wrapf(channeltypes.ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") + } + + // If this is an ack from a non-ICA transaction (e.g. an IBC transfer), there is no need to decode the data field + if !isICA { + logger.Info(fmt.Sprintf("IBC transfer acknowledgement success: %+v", response)) + return &types.AcknowledgementResponse{Status: types.AckResponseStatus_SUCCESS}, nil + } + + // Otherwise, if this ack is from an ICA, unmarshal the message data from within the ack + msgResponses, err := ParseTxMsgData(acknowledgement.GetResult()) + if err != nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot parse TxMsgData from ICA acknowledgement packet: %s", err.Error()) + } + return &types.AcknowledgementResponse{Status: types.AckResponseStatus_SUCCESS, MsgResponses: msgResponses}, nil + + case *channeltypes.Acknowledgement_Error: + logger.Error(fmt.Sprintf("acknowledgement error: %s", response.Error)) + return &types.AcknowledgementResponse{Status: types.AckResponseStatus_FAILURE, Error: response.Error}, nil + default: + return nil, errorsmod.Wrapf(channeltypes.ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", response) + } +} diff --git a/x/icacallbacks/icacallbacks_test.go b/x/icacallbacks/icacallbacks_test.go new file mode 100644 index 00000000..89d69d4b --- /dev/null +++ b/x/icacallbacks/icacallbacks_test.go @@ -0,0 +1,242 @@ +package icacallbacks_test + +import ( + "bytes" + "errors" + "strconv" + "testing" + "time" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + "github.com/gogo/protobuf/proto" + "github.com/tendermint/tendermint/libs/log" + + "github.com/stretchr/testify/require" + + "github.com/lum-network/chain/x/icacallbacks" + icacallbacktypes "github.com/lum-network/chain/x/icacallbacks/types" +) + +// Constructs an ICA Packet Acknowledgement compatible with ibc-go v5+ +func ICAPacketAcknowledgement(t *testing.T, msgType string, msgResponses []proto.Message) channeltypes.Acknowledgement { + txMsgData := &sdk.TxMsgData{ + MsgResponses: make([]*codectypes.Any, len(msgResponses)), + } + for i, msgResponse := range msgResponses { + var value []byte + var err error + if msgResponse != nil { + value, err = proto.Marshal(msgResponse) + require.NoError(t, err, "marshal error") + } + + txMsgData.MsgResponses[i] = &codectypes.Any{ + TypeUrl: msgType, + Value: value, + } + } + marshalledTxMsgData, err := proto.Marshal(txMsgData) + require.NoError(t, err) + ack := channeltypes.NewResultAcknowledgement(marshalledTxMsgData) + return ack +} + +// Constructs an legacy ICA Packet Acknowledgement compatible with ibc-go version v4 and lower +func ICAPacketAcknowledgementLegacy(t *testing.T, msgType string, msgResponses []proto.Message) channeltypes.Acknowledgement { + txMsgData := &sdk.TxMsgData{ + Data: make([]*sdk.MsgData, len(msgResponses)), //nolint:staticcheck + } + for i, msgResponse := range msgResponses { + var data []byte + var err error + if msgResponse != nil { + data, err = proto.Marshal(msgResponse) + require.NoError(t, err, "marshal error") + } + + txMsgData.Data[i] = &sdk.MsgData{ //nolint:staticcheck + MsgType: msgType, + Data: data, + } + } + marshalledTxMsgData, err := proto.Marshal(txMsgData) + require.NoError(t, err) + ack := channeltypes.NewResultAcknowledgement(marshalledTxMsgData) + return ack +} + +func TestParseTxMsgDataCurrent(t *testing.T) { + expectedMessages := [][]byte{{1}, {2, 2}, {3, 3}} + + msgData := &sdk.TxMsgData{ + MsgResponses: make([]*codectypes.Any, len(expectedMessages)), + } + for i, msgBytes := range expectedMessages { + typeUrl := "type" + strconv.Itoa(i) + msgData.MsgResponses[i] = &codectypes.Any{ + TypeUrl: typeUrl, + Value: msgBytes, + } + } + + msgDataBz, err := proto.Marshal(msgData) + require.NoError(t, err, "marshaling of current messages should not error") + + parsedMsgResponses, err := icacallbacks.ParseTxMsgData(msgDataBz) + require.NoError(t, err, "parsing tx message data for current messages should not error") + + require.ElementsMatch(t, expectedMessages, parsedMsgResponses, "parsed current messages") +} + +func TestParseTxMsgDataLegacy(t *testing.T) { + expectedMessages := [][]byte{{1}, {2, 2}, {3, 3}} + + msgData := &sdk.TxMsgData{ + Data: make([]*sdk.MsgData, len(expectedMessages)), //nolint:staticcheck + } + for i, msgBytes := range expectedMessages { + typeUrl := "type" + strconv.Itoa(i) + msgData.Data[i] = &sdk.MsgData{ //nolint:staticcheck + MsgType: typeUrl, + Data: msgBytes, + } + } + + msgDataBz, err := proto.Marshal(msgData) + require.NoError(t, err, "marshaling of legacy messages should not error") + + parsedMsgResponses, err := icacallbacks.ParseTxMsgData(msgDataBz) + require.NoError(t, err, "parsing tx message data for legacy messages should not error") + + require.ElementsMatch(t, expectedMessages, parsedMsgResponses, "parsed legacy messages") +} + +func TestUnwrapAcknowledgement(t *testing.T) { + msgDelegate := "/cosmos.staking.v1beta1.MsgDelegate" + msgUndelegate := "/cosmos.staking.v1beta1.MsgUndelegate" + exampleAckError := errors.New("ABCI code: 1: error handling packet: see events for details") + + testCases := []struct { + name string + isICA bool + ack channeltypes.Acknowledgement + expectedStatus icacallbacktypes.AckResponseStatus + expectedNumMessages int + packetError string + functionError string + }{ + { + name: "ibc_transfer_success", + isICA: false, + ack: channeltypes.NewResultAcknowledgement([]byte{1}), + expectedStatus: icacallbacktypes.AckResponseStatus_SUCCESS, + }, + { + name: "ibc_transfer_failure", + isICA: false, + ack: channeltypes.NewErrorAcknowledgement(exampleAckError), + expectedStatus: icacallbacktypes.AckResponseStatus_FAILURE, + packetError: exampleAckError.Error(), + }, + { + name: "ica_delegate_success", + isICA: true, + ack: ICAPacketAcknowledgement( + t, + msgDelegate, + []proto.Message{nil, nil}, + ), + expectedStatus: icacallbacktypes.AckResponseStatus_SUCCESS, + expectedNumMessages: 2, + }, + { + name: "ica_undelegate_success", + isICA: true, + ack: ICAPacketAcknowledgement( + t, + msgUndelegate, + []proto.Message{ + &stakingtypes.MsgUndelegateResponse{CompletionTime: time.Now()}, + &stakingtypes.MsgUndelegateResponse{CompletionTime: time.Now().Add(time.Duration(10))}, + }, + ), + expectedStatus: icacallbacktypes.AckResponseStatus_SUCCESS, + expectedNumMessages: 2, + }, + { + name: "ica_delegate_success_legacy", + isICA: true, + ack: ICAPacketAcknowledgementLegacy( + t, + msgDelegate, + []proto.Message{nil, nil}, + ), + expectedStatus: icacallbacktypes.AckResponseStatus_SUCCESS, + expectedNumMessages: 2, + }, + { + name: "ica_undelegate_success_legacy", + isICA: true, + ack: ICAPacketAcknowledgementLegacy( + t, + msgUndelegate, + []proto.Message{ + &stakingtypes.MsgUndelegateResponse{CompletionTime: time.Now()}, + &stakingtypes.MsgUndelegateResponse{CompletionTime: time.Now().Add(time.Duration(10))}, + }, + ), + expectedStatus: icacallbacktypes.AckResponseStatus_SUCCESS, + expectedNumMessages: 2, + }, + { + name: "ica_failure", + isICA: true, + ack: channeltypes.NewErrorAcknowledgement(exampleAckError), + expectedStatus: icacallbacktypes.AckResponseStatus_FAILURE, + packetError: exampleAckError.Error(), + }, + { + name: "ack_unmarshal_failure", + isICA: false, + ack: channeltypes.Acknowledgement{}, + functionError: "cannot unmarshal ICS-20 transfer packet acknowledgement", + }, + { + name: "ack_empty_result", + isICA: false, + ack: ICAPacketAcknowledgementLegacy(t, "", []proto.Message{}), + functionError: "acknowledgement result cannot be empty", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // If the ack is not empty, marshal it + var err error + var ackBz []byte + if !bytes.Equal(tc.ack.Acknowledgement(), []byte("{}")) { + ackBz, err = ibctransfertypes.ModuleCdc.MarshalJSON(&tc.ack) + require.NoError(t, err, "no error expected when marshalling ack") + } + + // Call unpack ack response and check error + ackResponse, err := icacallbacks.UnpackAcknowledgementResponse(sdk.Context{}, log.NewNopLogger(), ackBz, tc.isICA) + if tc.functionError != "" { + require.ErrorContains(t, err, tc.functionError, "unpacking acknowledgement reponse should have resulted in a function error") + return + } + require.NoError(t, err, "no error expected when unpacking ack") + + // Confirm the response and error status + require.Equal(t, tc.expectedStatus, ackResponse.Status, "Acknowledgement response status") + require.Equal(t, tc.packetError, ackResponse.Error, "AcknowledgementError") + + // Confirm expected messages + require.Len(t, ackResponse.MsgResponses, tc.expectedNumMessages) + }) + } +} diff --git a/x/icacallbacks/keeper/callback_data.go b/x/icacallbacks/keeper/callback_data.go new file mode 100644 index 00000000..ad16842e --- /dev/null +++ b/x/icacallbacks/keeper/callback_data.go @@ -0,0 +1,62 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// SetCallbackData set a specific callbackData in the store from its index +func (k Keeper) SetCallbackData(ctx sdk.Context, callbackData types.CallbackData) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.CallbackDataKeyPrefix)) + b := k.cdc.MustMarshal(&callbackData) + store.Set(types.CallbackDataKey( + callbackData.CallbackKey, + ), b) +} + +// GetCallbackData returns a callbackData from its index +func (k Keeper) GetCallbackData( + ctx sdk.Context, + callbackKey string, +) (val types.CallbackData, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.CallbackDataKeyPrefix)) + + b := store.Get(types.CallbackDataKey( + callbackKey, + )) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveCallbackData removes a callbackData from the store +func (k Keeper) RemoveCallbackData( + ctx sdk.Context, + callbackKey string, +) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.CallbackDataKeyPrefix)) + store.Delete(types.CallbackDataKey( + callbackKey, + )) +} + +// GetAllCallbackData returns all callbackData +func (k Keeper) GetAllCallbackData(ctx sdk.Context) (list []types.CallbackData) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.CallbackDataKeyPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.CallbackData + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} diff --git a/x/icacallbacks/keeper/grpc_query.go b/x/icacallbacks/keeper/grpc_query.go new file mode 100644 index 00000000..44d44c9a --- /dev/null +++ b/x/icacallbacks/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/lum-network/chain/x/icacallbacks/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/icacallbacks/keeper/grpc_query_callback_data.go b/x/icacallbacks/keeper/grpc_query_callback_data.go new file mode 100644 index 00000000..34883540 --- /dev/null +++ b/x/icacallbacks/keeper/grpc_query_callback_data.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +func (k Keeper) CallbackDataAll(c context.Context, req *types.QueryAllCallbackDataRequest) (*types.QueryAllCallbackDataResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + var callbackDatas []types.CallbackData + ctx := sdk.UnwrapSDKContext(c) + + store := ctx.KVStore(k.storeKey) + callbackDataStore := prefix.NewStore(store, types.KeyPrefix(types.CallbackDataKeyPrefix)) + + pageRes, err := query.Paginate(callbackDataStore, req.Pagination, func(key []byte, value []byte) error { + var callbackData types.CallbackData + if err := k.cdc.Unmarshal(value, &callbackData); err != nil { + return err + } + + callbackDatas = append(callbackDatas, callbackData) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryAllCallbackDataResponse{CallbackData: callbackDatas, Pagination: pageRes}, nil +} + +func (k Keeper) CallbackData(c context.Context, req *types.QueryGetCallbackDataRequest) (*types.QueryGetCallbackDataResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + val, found := k.GetCallbackData( + ctx, + req.CallbackKey, + ) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryGetCallbackDataResponse{CallbackData: val}, nil +} diff --git a/x/icacallbacks/keeper/grpc_query_params.go b/x/icacallbacks/keeper/grpc_query_params.go new file mode 100644 index 00000000..65f4210c --- /dev/null +++ b/x/icacallbacks/keeper/grpc_query_params.go @@ -0,0 +1,20 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/icacallbacks/keeper/keeper.go b/x/icacallbacks/keeper/keeper.go new file mode 100644 index 00000000..2105647a --- /dev/null +++ b/x/icacallbacks/keeper/keeper.go @@ -0,0 +1,156 @@ +package keeper + +import ( + "fmt" + + millionstypes "github.com/lum-network/chain/x/millions/types" + + "github.com/tendermint/tendermint/libs/log" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" + + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + "github.com/lum-network/chain/x/icacallbacks/types" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + icacontrollerkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + scopedKeeper capabilitykeeper.ScopedKeeper + icacallbacks map[string]types.ICACallbackHandler + IBCKeeper ibckeeper.Keeper + ICAControllerKeeper icacontrollerkeeper.Keeper + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + ps paramtypes.Subspace, + scopedKeeper capabilitykeeper.ScopedKeeper, + ibcKeeper ibckeeper.Keeper, + icacontrollerkeeper icacontrollerkeeper.Keeper, +) *Keeper { + // set KeyTable if it has not already been set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + scopedKeeper: scopedKeeper, + icacallbacks: make(map[string]types.ICACallbackHandler), + IBCKeeper: ibcKeeper, + ICAControllerKeeper: icacontrollerkeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +func (k *Keeper) SetICACallbackHandler(module string, handler types.ICACallbackHandler) error { + _, found := k.icacallbacks[module] + if found { + return fmt.Errorf("callback handler already set for %s", module) + } + k.icacallbacks[module] = handler.RegisterICACallbacks() + return nil +} + +func (k *Keeper) GetICACallbackHandler(module string) (types.ICACallbackHandler, error) { + callback, found := k.icacallbacks[module] + if !found { + return nil, fmt.Errorf("no callback handler found for %s", module) + } + return callback, nil +} + +// ClaimCapability claims the channel capability passed via the OnOpenChanInit callback +func (k *Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { + return k.scopedKeeper.ClaimCapability(ctx, cap, name) +} + +func (k Keeper) GetCallbackDataFromPacket(ctx sdk.Context, modulePacket channeltypes.Packet, callbackDataKey string) (cbd *types.CallbackData, found bool) { + // get the relevant module from the channel and port + portID := modulePacket.GetSourcePort() + channelID := modulePacket.GetSourceChannel() + // fetch the callback data + callbackData, found := k.GetCallbackData(ctx, callbackDataKey) + if !found { + k.Logger(ctx).Info(fmt.Sprintf("callback data not found for portID: %s, channelID: %s, sequence: %d", portID, channelID, modulePacket.Sequence)) + return nil, false + } else { + k.Logger(ctx).Info(fmt.Sprintf("callback data found for portID: %s, channelID: %s, sequence: %d", portID, channelID, modulePacket.Sequence)) + } + return &callbackData, true +} + +func (k Keeper) GetICACallbackHandlerFromPacket(ctx sdk.Context, modulePacket channeltypes.Packet) (*types.ICACallbackHandler, error) { + module, _, err := k.IBCKeeper.ChannelKeeper.LookupModuleByChannel(ctx, modulePacket.GetSourcePort(), modulePacket.GetSourceChannel()) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("error LookupModuleByChannel for portID: %s, channelID: %s, sequence: %d", modulePacket.GetSourcePort(), modulePacket.GetSourceChannel(), modulePacket.Sequence)) + return nil, err + } + + // redirect transfer callbacks to the records module + // is there a better way to do this? + if module == "transfer" { + module = millionstypes.ModuleName + } + + // fetch the callback function + callbackHandler, err := k.GetICACallbackHandler(module) + if err != nil { + return nil, errorsmod.Wrapf(types.ErrCallbackHandlerNotFound, "Callback handler does not exist for module %s | err: %s", module, err.Error()) + } + return &callbackHandler, nil +} + +func (k Keeper) CallRegisteredICACallback(ctx sdk.Context, modulePacket channeltypes.Packet, ackResponse *types.AcknowledgementResponse) error { + callbackDataKey := types.PacketID(modulePacket.GetSourcePort(), modulePacket.GetSourceChannel(), modulePacket.Sequence) + callbackData, found := k.GetCallbackDataFromPacket(ctx, modulePacket, callbackDataKey) + if !found { + return nil + } + callbackHandler, err := k.GetICACallbackHandlerFromPacket(ctx, modulePacket) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("GetICACallbackHandlerFromPacket %s", err.Error())) + return err + } + + // call the callback + if (*callbackHandler).HasICACallback(callbackData.CallbackId) { + k.Logger(ctx).Info(fmt.Sprintf("Calling callback for %s", callbackData.CallbackId)) + // if acknowledgement is empty, then it is a timeout + err := (*callbackHandler).CallICACallback(ctx, callbackData.CallbackId, modulePacket, ackResponse, callbackData.CallbackArgs) + if err != nil { + errMsg := fmt.Sprintf("Error occured while calling ICACallback (%s) | err: %s", callbackData.CallbackId, err.Error()) + k.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(types.ErrCallbackFailed, errMsg) + } + } else { + k.Logger(ctx).Error(fmt.Sprintf("Callback %v has no associated callback", callbackData)) + } + + // remove the callback data + k.RemoveCallbackData(ctx, callbackDataKey) + return nil +} diff --git a/x/icacallbacks/keeper/msg_server.go b/x/icacallbacks/keeper/msg_server.go new file mode 100644 index 00000000..4a2340a0 --- /dev/null +++ b/x/icacallbacks/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/lum-network/chain/x/icacallbacks/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/icacallbacks/keeper/params.go b/x/icacallbacks/keeper/params.go new file mode 100644 index 00000000..b391c920 --- /dev/null +++ b/x/icacallbacks/keeper/params.go @@ -0,0 +1,17 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams() +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} diff --git a/x/icacallbacks/module.go b/x/icacallbacks/module.go new file mode 100644 index 00000000..a63fe101 --- /dev/null +++ b/x/icacallbacks/module.go @@ -0,0 +1,179 @@ +package icacallbacks + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/lum-network/chain/x/icacallbacks/client/cli" + "github.com/lum-network/chain/x/icacallbacks/keeper" + "github.com/lum-network/chain/x/icacallbacks/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + panic(err) + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the capability module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the capability module's Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 2 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/icacallbacks/module_ibc.go b/x/icacallbacks/module_ibc.go new file mode 100644 index 00000000..3952c5dc --- /dev/null +++ b/x/icacallbacks/module_ibc.go @@ -0,0 +1,142 @@ +package icacallbacks + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" + + "github.com/lum-network/chain/x/icacallbacks/keeper" +) + +// IBCModule implements the ICS26 interface for interchain accounts controller chains +type IBCModule struct { + keeper keeper.Keeper + app porttypes.IBCModule +} + +// NewIBCModule creates a new IBCModule given the keeper +func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule { + return IBCModule{ + keeper: k, + app: app, + } +} + +// func(ctx, order, connectionHops []string, portID string, channelID string, chanCap, counterparty, version string) (string, error) +// func(ctx , order , connectionHops []string, portID string, channelID string, channelCap , counterparty , version string) error) +func (im IBCModule) OnChanOpenInit( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + channelCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version string, +) (string, error) { + // Note: The channel capability is claimed by the underlying app. + // call underlying app's OnChanOpenInit callback with the appVersion + version, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, + channelCap, counterparty, version) + return version, err +} + +// OnChanOpenAck implements the IBCModule interface +func (im IBCModule) OnChanOpenAck( + ctx sdk.Context, + portID, + channelID string, + counterpartyChannelID string, + counterpartyVersion string, +) error { + // call underlying app's OnChanOpenAck callback with the counterparty app version. + return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (im IBCModule) OnAcknowledgementPacket( + ctx sdk.Context, + modulePacket channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + // call underlying app's OnAcknowledgementPacket callback. + return im.app.OnAcknowledgementPacket(ctx, modulePacket, acknowledgement, relayer) +} + +// OnTimeoutPacket implements the IBCModule interface +func (im IBCModule) OnTimeoutPacket( + ctx sdk.Context, + modulePacket channeltypes.Packet, + relayer sdk.AccAddress, +) error { + return im.app.OnTimeoutPacket(ctx, modulePacket, relayer) +} + +func (im IBCModule) NegotiateAppVersion( + ctx sdk.Context, + order channeltypes.Order, + connectionID string, + portID string, + counterparty channeltypes.Counterparty, + proposedVersion string, +) (version string, err error) { + return proposedVersion, nil +} + +// ################################################################################### +// Required functions to satisfy interface but not implemented for ICA auth modules +// ################################################################################### + +// OnChanCloseConfirm implements the IBCModule interface +func (im IBCModule) OnChanCloseConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + // icacontroller calls OnChanCloseConfirm but doesn't call the underlying app's OnChanCloseConfirm callback. + return nil +} + +// OnChanOpenTry implements the IBCModule interface +func (im IBCModule) OnChanOpenTry( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + counterpartyVersion string, +) (string, error) { + panic("UNIMPLEMENTED") +} + +// OnChanOpenConfirm implements the IBCModule interface +func (im IBCModule) OnChanOpenConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + panic("UNIMPLEMENTED") +} + +// OnChanCloseInit implements the IBCModule interface +func (im IBCModule) OnChanCloseInit( + ctx sdk.Context, + portID, + channelID string, +) error { + panic("UNIMPLEMENTED") +} + +// OnRecvPacket implements the IBCModule interface +func (im IBCModule) OnRecvPacket( + ctx sdk.Context, + modulePacket channeltypes.Packet, + relayer sdk.AccAddress, +) ibcexported.Acknowledgement { + panic("UNIMPLEMENTED") +} diff --git a/x/icacallbacks/simulation/simap.go b/x/icacallbacks/simulation/simap.go new file mode 100644 index 00000000..92c437c0 --- /dev/null +++ b/x/icacallbacks/simulation/simap.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/icacallbacks/types/acknowledgement_response.go b/x/icacallbacks/types/acknowledgement_response.go new file mode 100644 index 00000000..5cd79b01 --- /dev/null +++ b/x/icacallbacks/types/acknowledgement_response.go @@ -0,0 +1,15 @@ +package types + +type AckResponseStatus int + +const ( + AckResponseStatus_SUCCESS AckResponseStatus = iota + AckResponseStatus_TIMEOUT + AckResponseStatus_FAILURE +) + +type AcknowledgementResponse struct { + Status AckResponseStatus + MsgResponses [][]byte + Error string +} diff --git a/x/icacallbacks/types/callback_data.pb.go b/x/icacallbacks/types/callback_data.pb.go new file mode 100644 index 00000000..3d7c2da6 --- /dev/null +++ b/x/icacallbacks/types/callback_data.pb.go @@ -0,0 +1,567 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icacallbacks/callback_data.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type CallbackData struct { + CallbackKey string `protobuf:"bytes,1,opt,name=callback_key,json=callbackKey,proto3" json:"callback_key,omitempty"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + ChannelId string `protobuf:"bytes,3,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + Sequence uint64 `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"` + CallbackId string `protobuf:"bytes,5,opt,name=callback_id,json=callbackId,proto3" json:"callback_id,omitempty"` + CallbackArgs []byte `protobuf:"bytes,6,opt,name=callback_args,json=callbackArgs,proto3" json:"callback_args,omitempty"` +} + +func (m *CallbackData) Reset() { *m = CallbackData{} } +func (m *CallbackData) String() string { return proto.CompactTextString(m) } +func (*CallbackData) ProtoMessage() {} +func (*CallbackData) Descriptor() ([]byte, []int) { + return fileDescriptor_37ca585895abb0e4, []int{0} +} +func (m *CallbackData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CallbackData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CallbackData.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CallbackData) XXX_Merge(src proto.Message) { + xxx_messageInfo_CallbackData.Merge(m, src) +} +func (m *CallbackData) XXX_Size() int { + return m.Size() +} +func (m *CallbackData) XXX_DiscardUnknown() { + xxx_messageInfo_CallbackData.DiscardUnknown(m) +} + +var xxx_messageInfo_CallbackData proto.InternalMessageInfo + +func (m *CallbackData) GetCallbackKey() string { + if m != nil { + return m.CallbackKey + } + return "" +} + +func (m *CallbackData) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *CallbackData) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *CallbackData) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +func (m *CallbackData) GetCallbackId() string { + if m != nil { + return m.CallbackId + } + return "" +} + +func (m *CallbackData) GetCallbackArgs() []byte { + if m != nil { + return m.CallbackArgs + } + return nil +} + +func init() { + proto.RegisterType((*CallbackData)(nil), "lum.network.icacallbacks.CallbackData") +} + +func init() { + proto.RegisterFile("lum-network/icacallbacks/callback_data.proto", fileDescriptor_37ca585895abb0e4) +} + +var fileDescriptor_37ca585895abb0e4 = []byte{ + // 268 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x50, 0xbb, 0x4e, 0xb4, 0x40, + 0x14, 0x66, 0xfe, 0x7f, 0x45, 0xf7, 0x88, 0xcd, 0x34, 0x12, 0x13, 0x47, 0xd4, 0x86, 0x42, 0x21, + 0xc6, 0x27, 0xf0, 0xd2, 0x90, 0xed, 0x28, 0x6d, 0x36, 0x87, 0x61, 0x02, 0x84, 0xab, 0x30, 0x44, + 0x79, 0x0b, 0x1f, 0xcb, 0xc4, 0x66, 0x4b, 0x4b, 0x03, 0x2f, 0x62, 0x20, 0x30, 0x59, 0xbb, 0xf3, + 0xdd, 0xce, 0x39, 0xf9, 0xe0, 0x26, 0x6b, 0xf3, 0xdb, 0x42, 0xc8, 0xb7, 0xb2, 0x4e, 0xdd, 0x84, + 0x23, 0xc7, 0x2c, 0x0b, 0x90, 0xa7, 0x8d, 0xbb, 0x4c, 0xdb, 0x10, 0x25, 0x3a, 0x55, 0x5d, 0xca, + 0x92, 0x9a, 0x59, 0x9b, 0x3b, 0xb3, 0xdb, 0xd9, 0x77, 0x5f, 0x7d, 0x11, 0x30, 0x9e, 0x66, 0xf4, + 0x8c, 0x12, 0xe9, 0x25, 0x18, 0x6a, 0x43, 0x2a, 0x3a, 0x93, 0x58, 0xc4, 0x5e, 0xfb, 0xc7, 0x0b, + 0xb7, 0x11, 0x1d, 0x3d, 0x85, 0xc3, 0xaa, 0xac, 0xe5, 0x36, 0x09, 0xcd, 0x7f, 0x93, 0xaa, 0x8f, + 0xd0, 0x0b, 0xe9, 0x39, 0x00, 0x8f, 0xb1, 0x28, 0x44, 0x36, 0x6a, 0xff, 0x27, 0x6d, 0x3d, 0x33, + 0x5e, 0x48, 0xcf, 0xe0, 0xa8, 0x11, 0xaf, 0xad, 0x28, 0xb8, 0x30, 0x57, 0x16, 0xb1, 0x57, 0xbe, + 0xc2, 0xf4, 0x02, 0xd4, 0x89, 0x31, 0x7b, 0x30, 0x65, 0x61, 0xa1, 0xbc, 0x90, 0x5e, 0xc3, 0x89, + 0x32, 0x60, 0x1d, 0x35, 0xa6, 0x6e, 0x11, 0xdb, 0xf0, 0xd5, 0xb3, 0x0f, 0x75, 0xd4, 0x3c, 0x6e, + 0x3e, 0x7b, 0x46, 0x76, 0x3d, 0x23, 0x3f, 0x3d, 0x23, 0x1f, 0x03, 0xd3, 0x76, 0x03, 0xd3, 0xbe, + 0x07, 0xa6, 0xbd, 0xdc, 0x45, 0x89, 0x8c, 0xdb, 0xc0, 0xe1, 0x65, 0xee, 0xee, 0x57, 0xc7, 0x63, + 0x4c, 0x0a, 0xf7, 0xfd, 0x6f, 0x85, 0xb2, 0xab, 0x44, 0x13, 0xe8, 0x53, 0x77, 0xf7, 0xbf, 0x01, + 0x00, 0x00, 0xff, 0xff, 0xec, 0x85, 0x07, 0x28, 0x6b, 0x01, 0x00, 0x00, +} + +func (m *CallbackData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CallbackData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CallbackData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CallbackArgs) > 0 { + i -= len(m.CallbackArgs) + copy(dAtA[i:], m.CallbackArgs) + i = encodeVarintCallbackData(dAtA, i, uint64(len(m.CallbackArgs))) + i-- + dAtA[i] = 0x32 + } + if len(m.CallbackId) > 0 { + i -= len(m.CallbackId) + copy(dAtA[i:], m.CallbackId) + i = encodeVarintCallbackData(dAtA, i, uint64(len(m.CallbackId))) + i-- + dAtA[i] = 0x2a + } + if m.Sequence != 0 { + i = encodeVarintCallbackData(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x20 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintCallbackData(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x1a + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintCallbackData(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0x12 + } + if len(m.CallbackKey) > 0 { + i -= len(m.CallbackKey) + copy(dAtA[i:], m.CallbackKey) + i = encodeVarintCallbackData(dAtA, i, uint64(len(m.CallbackKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintCallbackData(dAtA []byte, offset int, v uint64) int { + offset -= sovCallbackData(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *CallbackData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CallbackKey) + if l > 0 { + n += 1 + l + sovCallbackData(uint64(l)) + } + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovCallbackData(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovCallbackData(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovCallbackData(uint64(m.Sequence)) + } + l = len(m.CallbackId) + if l > 0 { + n += 1 + l + sovCallbackData(uint64(l)) + } + l = len(m.CallbackArgs) + if l > 0 { + n += 1 + l + sovCallbackData(uint64(l)) + } + return n +} + +func sovCallbackData(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCallbackData(x uint64) (n int) { + return sovCallbackData(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *CallbackData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CallbackData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CallbackData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCallbackData + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCallbackData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCallbackData + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCallbackData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCallbackData + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCallbackData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCallbackData + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCallbackData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackArgs", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbackData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCallbackData + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCallbackData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackArgs = append(m.CallbackArgs[:0], dAtA[iNdEx:postIndex]...) + if m.CallbackArgs == nil { + m.CallbackArgs = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCallbackData(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbackData + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbackData + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCallbackData(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCallbackData + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCallbackData + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCallbackData + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCallbackData + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCallbackData + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCallbackData + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCallbackData = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCallbackData = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCallbackData = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icacallbacks/types/callbacks.go b/x/icacallbacks/types/callbacks.go new file mode 100644 index 00000000..8b9098a4 --- /dev/null +++ b/x/icacallbacks/types/callbacks.go @@ -0,0 +1,14 @@ +package types + +import ( + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type ICACallbackHandler interface { + AddICACallback(id string, fn interface{}) ICACallbackHandler + RegisterICACallbacks() ICACallbackHandler + CallICACallback(ctx sdk.Context, id string, packet channeltypes.Packet, ackResponse *AcknowledgementResponse, args []byte) error + HasICACallback(id string) bool +} diff --git a/x/icacallbacks/types/codec.go b/x/icacallbacks/types/codec.go new file mode 100644 index 00000000..844157a8 --- /dev/null +++ b/x/icacallbacks/types/codec.go @@ -0,0 +1,23 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + // this line is used by starport scaffolding # 1 + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + // this line is used by starport scaffolding # 2 +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + // this line is used by starport scaffolding # 3 + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/icacallbacks/types/errors.go b/x/icacallbacks/types/errors.go new file mode 100644 index 00000000..a0341869 --- /dev/null +++ b/x/icacallbacks/types/errors.go @@ -0,0 +1,14 @@ +package types + +// DONTCOVER + +import ( + errorsmod "cosmossdk.io/errors" +) + +// x/icacallbacks module sentinel errors +var ( + ErrCallbackHandlerNotFound = errorsmod.Register(ModuleName, 1502, "icacallback handler not found") + ErrCallbackFailed = errorsmod.Register(ModuleName, 1504, "icacallback failed") + ErrInvalidAcknowledgement = errorsmod.Register(ModuleName, 1507, "invalid acknowledgement") +) diff --git a/x/icacallbacks/types/events_ibc.go b/x/icacallbacks/types/events_ibc.go new file mode 100644 index 00000000..07c66a43 --- /dev/null +++ b/x/icacallbacks/types/events_ibc.go @@ -0,0 +1,11 @@ +package types + +// IBC events +const ( + EventTypeTimeout = "timeout" + // this line is used by starport scaffolding # ibc/packet/event + + AttributeKeyAckSuccess = "success" + AttributeKeyAck = "acknowledgement" + AttributeKeyAckError = "error" +) diff --git a/x/icacallbacks/types/expected_keepers.go b/x/icacallbacks/types/expected_keepers.go new file mode 100644 index 00000000..6aa6e977 --- /dev/null +++ b/x/icacallbacks/types/expected_keepers.go @@ -0,0 +1,18 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here +} diff --git a/x/icacallbacks/types/genesis.go b/x/icacallbacks/types/genesis.go new file mode 100644 index 00000000..a8cd5d12 --- /dev/null +++ b/x/icacallbacks/types/genesis.go @@ -0,0 +1,41 @@ +package types + +import ( + "fmt" + + host "github.com/cosmos/ibc-go/v5/modules/core/24-host" +) + +// DefaultIndex is the default capability global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + PortId: PortID, + CallbackDataList: []CallbackData{}, + // this line is used by starport scaffolding # genesis/types/default + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + if err := host.PortIdentifierValidator(gs.PortId); err != nil { + return err + } + // Check for duplicated index in callbackData + callbackDataIndexMap := make(map[string]struct{}) + + for _, elem := range gs.CallbackDataList { + index := string(CallbackDataKey(elem.CallbackKey)) + if _, ok := callbackDataIndexMap[index]; ok { + return fmt.Errorf("duplicated index for callbackData") + } + callbackDataIndexMap[index] = struct{}{} + } + // this line is used by starport scaffolding # genesis/types/validate + + return gs.Params.Validate() +} diff --git a/x/icacallbacks/types/genesis.pb.go b/x/icacallbacks/types/genesis.pb.go new file mode 100644 index 00000000..a6ea5003 --- /dev/null +++ b/x/icacallbacks/types/genesis.pb.go @@ -0,0 +1,444 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icacallbacks/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the icacallbacks module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + CallbackDataList []CallbackData `protobuf:"bytes,3,rep,name=callback_data_list,json=callbackDataList,proto3" json:"callback_data_list"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_0ea203eeb04d788b, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *GenesisState) GetCallbackDataList() []CallbackData { + if m != nil { + return m.CallbackDataList + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "lum.network.icacallbacks.GenesisState") +} + +func init() { + proto.RegisterFile("lum-network/icacallbacks/genesis.proto", fileDescriptor_0ea203eeb04d788b) +} + +var fileDescriptor_0ea203eeb04d788b = []byte{ + // 281 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcb, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0x4c, 0x4e, 0x4c, 0x4e, 0xcc, 0xc9, 0x49, + 0x4a, 0x4c, 0xce, 0x2e, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, + 0x2f, 0xc9, 0x17, 0x92, 0xc8, 0x29, 0xcd, 0xd5, 0x83, 0xaa, 0xd3, 0x43, 0x56, 0x27, 0x25, 0x92, + 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x4b, 0xa9, 0xe2, 0x34, 0xb7, 0x20, + 0xb1, 0x28, 0x31, 0x17, 0x6a, 0xac, 0x94, 0x0e, 0x4e, 0x65, 0x30, 0x56, 0x7c, 0x4a, 0x62, 0x49, + 0x22, 0x44, 0xb5, 0xd2, 0x61, 0x46, 0x2e, 0x1e, 0x77, 0x88, 0xb3, 0x82, 0x4b, 0x12, 0x4b, 0x52, + 0x85, 0xec, 0xb8, 0xd8, 0x20, 0xc6, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x29, 0xe8, 0xe1, + 0x72, 0xa6, 0x5e, 0x00, 0x58, 0x9d, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x50, 0x5d, 0x42, + 0xe2, 0x5c, 0xec, 0x05, 0xf9, 0x45, 0x25, 0xf1, 0x99, 0x29, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x9c, + 0x41, 0x6c, 0x20, 0xae, 0x67, 0x8a, 0x50, 0x14, 0x97, 0x10, 0x8a, 0x03, 0xe2, 0x73, 0x32, 0x8b, + 0x4b, 0x24, 0x98, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0xd4, 0x70, 0x5b, 0xe2, 0x0c, 0x65, 0xb9, 0x24, + 0x96, 0x24, 0x42, 0xad, 0x12, 0x48, 0x46, 0x12, 0xf3, 0xc9, 0x2c, 0x2e, 0x71, 0xf2, 0x3e, 0xf1, + 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xc3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, + 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xe4, 0x80, 0x49, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xaf, 0x40, 0x0d, + 0xa0, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0xc8, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, + 0xff, 0xc9, 0xd9, 0x1f, 0xcc, 0xc8, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CallbackDataList) > 0 { + for iNdEx := len(m.CallbackDataList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CallbackDataList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.CallbackDataList) > 0 { + for _, e := range m.CallbackDataList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackDataList", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackDataList = append(m.CallbackDataList, CallbackData{}) + if err := m.CallbackDataList[len(m.CallbackDataList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icacallbacks/types/genesis_test.go b/x/icacallbacks/types/genesis_test.go new file mode 100644 index 00000000..dd5a9019 --- /dev/null +++ b/x/icacallbacks/types/genesis_test.go @@ -0,0 +1,63 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/lum-network/chain/x/icacallbacks/types" +) + +func TestGenesisState_Validate(t *testing.T) { + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + PortId: types.PortID, + CallbackDataList: []types.CallbackData{ + { + CallbackKey: "0", + }, + { + CallbackKey: "1", + }, + }, + // this line is used by starport scaffolding # types/genesis/validField + }, + valid: true, + }, + { + desc: "duplicated callbackData", + genState: &types.GenesisState{ + CallbackDataList: []types.CallbackData{ + { + CallbackKey: "0", + }, + { + CallbackKey: "0", + }, + }, + }, + valid: false, + }, + // this line is used by starport scaffolding # types/genesis/testcase + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/icacallbacks/types/key_callback_data.go b/x/icacallbacks/types/key_callback_data.go new file mode 100644 index 00000000..e878dcb6 --- /dev/null +++ b/x/icacallbacks/types/key_callback_data.go @@ -0,0 +1,25 @@ +package types + +import ( + "encoding/binary" +) + +var _ binary.ByteOrder + +const ( + // CallbackDataKeyPrefix is the prefix to retrieve all CallbackData + CallbackDataKeyPrefix = "CallbackData/value/" +) + +// CallbackDataKey returns the store key to retrieve a CallbackData from the index fields +func CallbackDataKey( + callbackKey string, +) []byte { + var key []byte + + callbackKeyBytes := []byte(callbackKey) + key = append(key, callbackKeyBytes...) + key = append(key, []byte("/")...) + + return key +} diff --git a/x/icacallbacks/types/keys.go b/x/icacallbacks/types/keys.go new file mode 100644 index 00000000..d5332e8b --- /dev/null +++ b/x/icacallbacks/types/keys.go @@ -0,0 +1,37 @@ +package types + +import fmt "fmt" + +const ( + // ModuleName defines the module name + ModuleName = "icacallbacks" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_icacallbacks" + + // Version defines the current version the IBC module supports + Version = "icacallbacks-1" + + // PortID is the default port id that module binds to + PortID = "icacallbacks" +) + +// PortKey defines the key to store the port ID in store +var PortKey = KeyPrefix("icacallbacks-port-") + +func KeyPrefix(p string) []byte { + return []byte(p) +} + +func PacketID(portID string, channelID string, sequence uint64) string { + return fmt.Sprintf("%s.%s.%d", portID, channelID, sequence) +} diff --git a/x/icacallbacks/types/packet.pb.go b/x/icacallbacks/types/packet.pb.go new file mode 100644 index 00000000..33aa70c7 --- /dev/null +++ b/x/icacallbacks/types/packet.pb.go @@ -0,0 +1,509 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icacallbacks/packet.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type IcacallbacksPacketData struct { + // Types that are valid to be assigned to Packet: + // *IcacallbacksPacketData_NoData + Packet isIcacallbacksPacketData_Packet `protobuf_oneof:"packet"` +} + +func (m *IcacallbacksPacketData) Reset() { *m = IcacallbacksPacketData{} } +func (m *IcacallbacksPacketData) String() string { return proto.CompactTextString(m) } +func (*IcacallbacksPacketData) ProtoMessage() {} +func (*IcacallbacksPacketData) Descriptor() ([]byte, []int) { + return fileDescriptor_fbd0ebf37b2118fd, []int{0} +} +func (m *IcacallbacksPacketData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IcacallbacksPacketData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IcacallbacksPacketData.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IcacallbacksPacketData) XXX_Merge(src proto.Message) { + xxx_messageInfo_IcacallbacksPacketData.Merge(m, src) +} +func (m *IcacallbacksPacketData) XXX_Size() int { + return m.Size() +} +func (m *IcacallbacksPacketData) XXX_DiscardUnknown() { + xxx_messageInfo_IcacallbacksPacketData.DiscardUnknown(m) +} + +var xxx_messageInfo_IcacallbacksPacketData proto.InternalMessageInfo + +type isIcacallbacksPacketData_Packet interface { + isIcacallbacksPacketData_Packet() + MarshalTo([]byte) (int, error) + Size() int +} + +type IcacallbacksPacketData_NoData struct { + NoData *NoData `protobuf:"bytes,1,opt,name=no_data,json=noData,proto3,oneof" json:"no_data,omitempty"` +} + +func (*IcacallbacksPacketData_NoData) isIcacallbacksPacketData_Packet() {} + +func (m *IcacallbacksPacketData) GetPacket() isIcacallbacksPacketData_Packet { + if m != nil { + return m.Packet + } + return nil +} + +func (m *IcacallbacksPacketData) GetNoData() *NoData { + if x, ok := m.GetPacket().(*IcacallbacksPacketData_NoData); ok { + return x.NoData + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*IcacallbacksPacketData) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*IcacallbacksPacketData_NoData)(nil), + } +} + +type NoData struct { +} + +func (m *NoData) Reset() { *m = NoData{} } +func (m *NoData) String() string { return proto.CompactTextString(m) } +func (*NoData) ProtoMessage() {} +func (*NoData) Descriptor() ([]byte, []int) { + return fileDescriptor_fbd0ebf37b2118fd, []int{1} +} +func (m *NoData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NoData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_NoData.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *NoData) XXX_Merge(src proto.Message) { + xxx_messageInfo_NoData.Merge(m, src) +} +func (m *NoData) XXX_Size() int { + return m.Size() +} +func (m *NoData) XXX_DiscardUnknown() { + xxx_messageInfo_NoData.DiscardUnknown(m) +} + +var xxx_messageInfo_NoData proto.InternalMessageInfo + +func init() { + proto.RegisterType((*IcacallbacksPacketData)(nil), "lum.network.icacallbacks.IcacallbacksPacketData") + proto.RegisterType((*NoData)(nil), "lum.network.icacallbacks.NoData") +} + +func init() { + proto.RegisterFile("lum-network/icacallbacks/packet.proto", fileDescriptor_fbd0ebf37b2118fd) +} + +var fileDescriptor_fbd0ebf37b2118fd = []byte{ + // 197 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0x4c, 0x4e, 0x4c, 0x4e, 0xcc, 0xc9, 0x49, + 0x4a, 0x4c, 0xce, 0x2e, 0xd6, 0x2f, 0x48, 0x4c, 0xce, 0x4e, 0x2d, 0xd1, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x92, 0xc8, 0x29, 0xcd, 0xd5, 0x83, 0x2a, 0xd3, 0x43, 0x56, 0xa6, 0x14, 0xcf, 0x25, + 0xe6, 0x89, 0xc4, 0x0f, 0x00, 0xeb, 0x72, 0x49, 0x2c, 0x49, 0x14, 0xb2, 0xe6, 0x62, 0xcf, 0xcb, + 0x8f, 0x4f, 0x49, 0x2c, 0x49, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd0, 0xc3, 0x65, + 0x8a, 0x9e, 0x5f, 0x3e, 0x48, 0x8b, 0x07, 0x43, 0x10, 0x5b, 0x1e, 0x98, 0xe5, 0xc4, 0xc1, 0xc5, + 0x06, 0x71, 0x80, 0x12, 0x07, 0x17, 0x1b, 0x44, 0xd6, 0xc9, 0xfb, 0xc4, 0x23, 0x39, 0xc6, 0x0b, + 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, + 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x0c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, + 0xf5, 0x91, 0x3d, 0x94, 0x9c, 0x91, 0x98, 0x99, 0xa7, 0x5f, 0x81, 0xea, 0xb1, 0x92, 0xca, 0x82, + 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0xc7, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xec, 0x99, 0xab, + 0x38, 0x01, 0x01, 0x00, 0x00, +} + +func (m *IcacallbacksPacketData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IcacallbacksPacketData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IcacallbacksPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Packet != nil { + { + size := m.Packet.Size() + i -= size + if _, err := m.Packet.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *IcacallbacksPacketData_NoData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IcacallbacksPacketData_NoData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.NoData != nil { + { + size, err := m.NoData.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPacket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *NoData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *NoData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NoData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintPacket(dAtA []byte, offset int, v uint64) int { + offset -= sovPacket(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *IcacallbacksPacketData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Packet != nil { + n += m.Packet.Size() + } + return n +} + +func (m *IcacallbacksPacketData_NoData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NoData != nil { + l = m.NoData.Size() + n += 1 + l + sovPacket(uint64(l)) + } + return n +} +func (m *NoData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovPacket(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPacket(x uint64) (n int) { + return sovPacket(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *IcacallbacksPacketData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IcacallbacksPacketData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IcacallbacksPacketData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NoData", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &NoData{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Packet = &IcacallbacksPacketData_NoData{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPacket(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPacket + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPacket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *NoData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: NoData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NoData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipPacket(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPacket + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPacket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPacket(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPacket + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPacket + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPacket + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPacket + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPacket + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPacket + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPacket = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPacket = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPacket = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icacallbacks/types/params.go b/x/icacallbacks/types/params.go new file mode 100644 index 00000000..357196ad --- /dev/null +++ b/x/icacallbacks/types/params.go @@ -0,0 +1,39 @@ +package types + +import ( + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams() +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/icacallbacks/types/params.pb.go b/x/icacallbacks/types/params.pb.go new file mode 100644 index 00000000..4f81d162 --- /dev/null +++ b/x/icacallbacks/types/params.pb.go @@ -0,0 +1,270 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icacallbacks/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_9835aac210868f9e, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "lum.network.icacallbacks.Params") +} + +func init() { + proto.RegisterFile("lum-network/icacallbacks/params.proto", fileDescriptor_9835aac210868f9e) +} + +var fileDescriptor_9835aac210868f9e = []byte{ + // 163 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0x4c, 0x4e, 0x4c, 0x4e, 0xcc, 0xc9, 0x49, + 0x4a, 0x4c, 0xce, 0x2e, 0xd6, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x92, 0xc8, 0x29, 0xcd, 0xd5, 0x83, 0x2a, 0xd3, 0x43, 0x56, 0x26, 0x25, 0x92, 0x9e, + 0x9f, 0x9e, 0x0f, 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x2b, 0xf1, 0x71, 0xb1, 0x05, 0x80, 0xf5, + 0x5b, 0xb1, 0xcc, 0x58, 0x20, 0xcf, 0xe0, 0xe4, 0x7d, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, + 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, + 0x72, 0x0c, 0x51, 0x86, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc8, + 0x6e, 0x49, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xaf, 0x40, 0x75, 0x53, 0x49, 0x65, 0x41, 0x6a, 0x71, + 0x12, 0x1b, 0xd8, 0x0e, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x67, 0x1c, 0x36, 0xbc, + 0x00, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icacallbacks/types/query.pb.go b/x/icacallbacks/types/query.pb.go new file mode 100644 index 00000000..8d46845e --- /dev/null +++ b/x/icacallbacks/types/query.pb.go @@ -0,0 +1,1409 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icacallbacks/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c36ffa27d3ef6d67, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c36ffa27d3ef6d67, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryGetCallbackDataRequest struct { + CallbackKey string `protobuf:"bytes,1,opt,name=callback_key,json=callbackKey,proto3" json:"callback_key,omitempty"` +} + +func (m *QueryGetCallbackDataRequest) Reset() { *m = QueryGetCallbackDataRequest{} } +func (m *QueryGetCallbackDataRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetCallbackDataRequest) ProtoMessage() {} +func (*QueryGetCallbackDataRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c36ffa27d3ef6d67, []int{2} +} +func (m *QueryGetCallbackDataRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetCallbackDataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetCallbackDataRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetCallbackDataRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetCallbackDataRequest.Merge(m, src) +} +func (m *QueryGetCallbackDataRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetCallbackDataRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetCallbackDataRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetCallbackDataRequest proto.InternalMessageInfo + +func (m *QueryGetCallbackDataRequest) GetCallbackKey() string { + if m != nil { + return m.CallbackKey + } + return "" +} + +type QueryGetCallbackDataResponse struct { + CallbackData CallbackData `protobuf:"bytes,1,opt,name=callback_data,json=callbackData,proto3" json:"callback_data"` +} + +func (m *QueryGetCallbackDataResponse) Reset() { *m = QueryGetCallbackDataResponse{} } +func (m *QueryGetCallbackDataResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetCallbackDataResponse) ProtoMessage() {} +func (*QueryGetCallbackDataResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c36ffa27d3ef6d67, []int{3} +} +func (m *QueryGetCallbackDataResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetCallbackDataResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetCallbackDataResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetCallbackDataResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetCallbackDataResponse.Merge(m, src) +} +func (m *QueryGetCallbackDataResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetCallbackDataResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetCallbackDataResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetCallbackDataResponse proto.InternalMessageInfo + +func (m *QueryGetCallbackDataResponse) GetCallbackData() CallbackData { + if m != nil { + return m.CallbackData + } + return CallbackData{} +} + +type QueryAllCallbackDataRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllCallbackDataRequest) Reset() { *m = QueryAllCallbackDataRequest{} } +func (m *QueryAllCallbackDataRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllCallbackDataRequest) ProtoMessage() {} +func (*QueryAllCallbackDataRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c36ffa27d3ef6d67, []int{4} +} +func (m *QueryAllCallbackDataRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllCallbackDataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllCallbackDataRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllCallbackDataRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllCallbackDataRequest.Merge(m, src) +} +func (m *QueryAllCallbackDataRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllCallbackDataRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllCallbackDataRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllCallbackDataRequest proto.InternalMessageInfo + +func (m *QueryAllCallbackDataRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllCallbackDataResponse struct { + CallbackData []CallbackData `protobuf:"bytes,1,rep,name=callback_data,json=callbackData,proto3" json:"callback_data"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllCallbackDataResponse) Reset() { *m = QueryAllCallbackDataResponse{} } +func (m *QueryAllCallbackDataResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllCallbackDataResponse) ProtoMessage() {} +func (*QueryAllCallbackDataResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c36ffa27d3ef6d67, []int{5} +} +func (m *QueryAllCallbackDataResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllCallbackDataResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllCallbackDataResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllCallbackDataResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllCallbackDataResponse.Merge(m, src) +} +func (m *QueryAllCallbackDataResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllCallbackDataResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllCallbackDataResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllCallbackDataResponse proto.InternalMessageInfo + +func (m *QueryAllCallbackDataResponse) GetCallbackData() []CallbackData { + if m != nil { + return m.CallbackData + } + return nil +} + +func (m *QueryAllCallbackDataResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "lum.network.icacallbacks.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "lum.network.icacallbacks.QueryParamsResponse") + proto.RegisterType((*QueryGetCallbackDataRequest)(nil), "lum.network.icacallbacks.QueryGetCallbackDataRequest") + proto.RegisterType((*QueryGetCallbackDataResponse)(nil), "lum.network.icacallbacks.QueryGetCallbackDataResponse") + proto.RegisterType((*QueryAllCallbackDataRequest)(nil), "lum.network.icacallbacks.QueryAllCallbackDataRequest") + proto.RegisterType((*QueryAllCallbackDataResponse)(nil), "lum.network.icacallbacks.QueryAllCallbackDataResponse") +} + +func init() { + proto.RegisterFile("lum-network/icacallbacks/query.proto", fileDescriptor_c36ffa27d3ef6d67) +} + +var fileDescriptor_c36ffa27d3ef6d67 = []byte{ + // 520 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xc1, 0x6b, 0x13, 0x41, + 0x14, 0xc6, 0x33, 0xb5, 0x06, 0x9c, 0x56, 0x84, 0xb1, 0x87, 0x12, 0xcb, 0x1a, 0x07, 0xb5, 0x55, + 0xda, 0x19, 0x52, 0xb1, 0x78, 0x2a, 0xb6, 0x8a, 0x3d, 0xf4, 0xd2, 0x06, 0xbc, 0x78, 0x91, 0xd9, + 0x75, 0xd8, 0x2e, 0x99, 0xdd, 0xd9, 0x64, 0x66, 0xd5, 0x20, 0x5e, 0xbc, 0x8b, 0x82, 0x7f, 0x89, + 0x57, 0xc1, 0x7b, 0x8f, 0x05, 0x2f, 0x9e, 0x44, 0x12, 0xff, 0x10, 0xc9, 0xcc, 0x24, 0xee, 0xd2, + 0x5d, 0x36, 0xd2, 0xdb, 0x32, 0xf9, 0xde, 0xfb, 0x7e, 0xdf, 0xbc, 0x37, 0x81, 0xb7, 0x45, 0x16, + 0x6f, 0x25, 0x5c, 0xbf, 0x91, 0x83, 0x1e, 0x8d, 0x02, 0x16, 0x30, 0x21, 0x7c, 0x16, 0xf4, 0x14, + 0xed, 0x67, 0x7c, 0x30, 0x24, 0xe9, 0x40, 0x6a, 0x89, 0x56, 0x45, 0x16, 0x13, 0xa7, 0x22, 0x79, + 0x55, 0x6b, 0x25, 0x94, 0xa1, 0x34, 0x22, 0x3a, 0xf9, 0xb2, 0xfa, 0xd6, 0x5a, 0x28, 0x65, 0x28, + 0x38, 0x65, 0x69, 0x44, 0x59, 0x92, 0x48, 0xcd, 0x74, 0x24, 0x13, 0xe5, 0x7e, 0xbd, 0x1f, 0x48, + 0x15, 0x4b, 0x45, 0x7d, 0xa6, 0xb8, 0xb5, 0xa1, 0xaf, 0x3b, 0x3e, 0xd7, 0xac, 0x43, 0x53, 0x16, + 0x46, 0x89, 0x11, 0x3b, 0xed, 0x9d, 0x4a, 0xbe, 0x94, 0x0d, 0x58, 0x3c, 0x6d, 0xb9, 0x59, 0x29, + 0x9b, 0x7e, 0xbd, 0x7c, 0xc5, 0x34, 0xb3, 0x6a, 0xbc, 0x02, 0xd1, 0xf1, 0xc4, 0xf6, 0xc8, 0xb4, + 0xe8, 0xf2, 0x7e, 0xc6, 0x95, 0xc6, 0xcf, 0xe1, 0xf5, 0xc2, 0xa9, 0x4a, 0x65, 0xa2, 0x38, 0xda, + 0x85, 0x4d, 0x6b, 0xb5, 0x0a, 0xda, 0x60, 0x63, 0x69, 0xbb, 0x4d, 0xaa, 0x2e, 0x83, 0xd8, 0xca, + 0xfd, 0xc5, 0xd3, 0x5f, 0x37, 0x1b, 0x5d, 0x57, 0x85, 0x1f, 0xc3, 0x1b, 0xa6, 0xed, 0x01, 0xd7, + 0x4f, 0x9c, 0xf2, 0x29, 0xd3, 0xcc, 0xb9, 0xa2, 0x5b, 0x70, 0x79, 0x86, 0xd8, 0xe3, 0x43, 0x63, + 0x72, 0xa5, 0xbb, 0x34, 0x3d, 0x3b, 0xe4, 0x43, 0xdc, 0x87, 0x6b, 0xe5, 0x1d, 0x1c, 0xe1, 0x31, + 0xbc, 0x5a, 0x48, 0xe9, 0x40, 0xef, 0x56, 0x83, 0xe6, 0xdb, 0x38, 0xdc, 0x19, 0xc5, 0xe4, 0x0c, + 0x73, 0x07, 0xbd, 0x27, 0x44, 0x19, 0xf4, 0x33, 0x08, 0xff, 0x4d, 0x6a, 0x66, 0x67, 0xc7, 0x4a, + 0x26, 0x63, 0x25, 0x76, 0x7b, 0xdc, 0x58, 0xc9, 0x11, 0x0b, 0xb9, 0xab, 0xed, 0xe6, 0x2a, 0xf1, + 0x37, 0xe0, 0xa2, 0x9d, 0xf3, 0xa9, 0x8e, 0x76, 0xe9, 0x62, 0xd1, 0xd0, 0x41, 0x81, 0x7d, 0xc1, + 0xb0, 0xaf, 0xd7, 0xb2, 0x5b, 0x9e, 0x3c, 0xfc, 0xf6, 0xc7, 0x45, 0x78, 0xd9, 0xc0, 0xa3, 0x4f, + 0x00, 0x36, 0xed, 0xec, 0xd1, 0x66, 0x35, 0xd9, 0xf9, 0x95, 0x6b, 0x6d, 0xcd, 0xa9, 0xb6, 0xee, + 0x78, 0xe3, 0xc3, 0x8f, 0x3f, 0x5f, 0x16, 0x30, 0x6a, 0xd3, 0x9a, 0x57, 0x81, 0xbe, 0x03, 0xb8, + 0x9c, 0xbf, 0x09, 0xf4, 0xb0, 0xc6, 0xa9, 0x7c, 0x3b, 0x5b, 0x3b, 0xff, 0x5b, 0xe6, 0x48, 0x77, + 0x0d, 0xe9, 0x23, 0xb4, 0x43, 0xe7, 0x7b, 0x98, 0xf4, 0x5d, 0xfe, 0x11, 0xbc, 0x47, 0x5f, 0x01, + 0xbc, 0x96, 0x6f, 0xbc, 0x27, 0x44, 0x6d, 0x84, 0xf2, 0x5d, 0xad, 0x8d, 0x50, 0xb1, 0x7a, 0x98, + 0x9a, 0x08, 0xf7, 0xd0, 0xfa, 0x9c, 0x11, 0xf6, 0x0f, 0x4f, 0x47, 0x1e, 0x38, 0x1b, 0x79, 0xe0, + 0xf7, 0xc8, 0x03, 0x9f, 0xc7, 0x5e, 0xe3, 0x6c, 0xec, 0x35, 0x7e, 0x8e, 0xbd, 0xc6, 0x8b, 0x4e, + 0x18, 0xe9, 0x93, 0xcc, 0x27, 0x81, 0x8c, 0x0b, 0xcd, 0x82, 0x13, 0x16, 0x25, 0xf4, 0x6d, 0xb1, + 0xa9, 0x1e, 0xa6, 0x5c, 0xf9, 0x4d, 0xf3, 0x4f, 0xf5, 0xe0, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x89, 0xe2, 0x06, 0xd4, 0xa0, 0x05, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Queries a CallbackData by index. + CallbackData(ctx context.Context, in *QueryGetCallbackDataRequest, opts ...grpc.CallOption) (*QueryGetCallbackDataResponse, error) + // Queries a list of CallbackData items. + CallbackDataAll(ctx context.Context, in *QueryAllCallbackDataRequest, opts ...grpc.CallOption) (*QueryAllCallbackDataResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/lum.network.icacallbacks.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) CallbackData(ctx context.Context, in *QueryGetCallbackDataRequest, opts ...grpc.CallOption) (*QueryGetCallbackDataResponse, error) { + out := new(QueryGetCallbackDataResponse) + err := c.cc.Invoke(ctx, "/lum.network.icacallbacks.Query/CallbackData", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) CallbackDataAll(ctx context.Context, in *QueryAllCallbackDataRequest, opts ...grpc.CallOption) (*QueryAllCallbackDataResponse, error) { + out := new(QueryAllCallbackDataResponse) + err := c.cc.Invoke(ctx, "/lum.network.icacallbacks.Query/CallbackDataAll", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // Queries a CallbackData by index. + CallbackData(context.Context, *QueryGetCallbackDataRequest) (*QueryGetCallbackDataResponse, error) + // Queries a list of CallbackData items. + CallbackDataAll(context.Context, *QueryAllCallbackDataRequest) (*QueryAllCallbackDataResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) CallbackData(ctx context.Context, req *QueryGetCallbackDataRequest) (*QueryGetCallbackDataResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CallbackData not implemented") +} +func (*UnimplementedQueryServer) CallbackDataAll(ctx context.Context, req *QueryAllCallbackDataRequest) (*QueryAllCallbackDataResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CallbackDataAll not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.icacallbacks.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_CallbackData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetCallbackDataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).CallbackData(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.icacallbacks.Query/CallbackData", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).CallbackData(ctx, req.(*QueryGetCallbackDataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_CallbackDataAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllCallbackDataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).CallbackDataAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.icacallbacks.Query/CallbackDataAll", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).CallbackDataAll(ctx, req.(*QueryAllCallbackDataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "lum.network.icacallbacks.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "CallbackData", + Handler: _Query_CallbackData_Handler, + }, + { + MethodName: "CallbackDataAll", + Handler: _Query_CallbackDataAll_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lum-network/icacallbacks/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryGetCallbackDataRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetCallbackDataRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetCallbackDataRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CallbackKey) > 0 { + i -= len(m.CallbackKey) + copy(dAtA[i:], m.CallbackKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.CallbackKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetCallbackDataResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetCallbackDataResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetCallbackDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.CallbackData.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAllCallbackDataRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllCallbackDataRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllCallbackDataRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllCallbackDataResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllCallbackDataResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllCallbackDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.CallbackData) > 0 { + for iNdEx := len(m.CallbackData) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CallbackData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryGetCallbackDataRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CallbackKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetCallbackDataResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.CallbackData.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAllCallbackDataRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllCallbackDataResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CallbackData) > 0 { + for _, e := range m.CallbackData { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetCallbackDataRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetCallbackDataRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetCallbackDataRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetCallbackDataResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetCallbackDataResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetCallbackDataResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackData", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CallbackData.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllCallbackDataRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllCallbackDataRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllCallbackDataRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllCallbackDataResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllCallbackDataResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllCallbackDataResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackData", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackData = append(m.CallbackData, CallbackData{}) + if err := m.CallbackData[len(m.CallbackData)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icacallbacks/types/query.pb.gw.go b/x/icacallbacks/types/query.pb.gw.go new file mode 100644 index 00000000..1c31c3b7 --- /dev/null +++ b/x/icacallbacks/types/query.pb.gw.go @@ -0,0 +1,337 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lum-network/icacallbacks/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_CallbackData_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetCallbackDataRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["callback_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "callback_key") + } + + protoReq.CallbackKey, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "callback_key", err) + } + + msg, err := client.CallbackData(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_CallbackData_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetCallbackDataRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["callback_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "callback_key") + } + + protoReq.CallbackKey, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "callback_key", err) + } + + msg, err := server.CallbackData(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_CallbackDataAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_CallbackDataAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllCallbackDataRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CallbackDataAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CallbackDataAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_CallbackDataAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllCallbackDataRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CallbackDataAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CallbackDataAll(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CallbackData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_CallbackData_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CallbackData_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CallbackDataAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_CallbackDataAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CallbackDataAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CallbackData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_CallbackData_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CallbackData_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CallbackDataAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_CallbackDataAll_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CallbackDataAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "icacallbacks", "params"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_CallbackData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "icacallbacks", "callback_data", "callback_key"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_CallbackDataAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "icacallbacks", "callback_data"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_CallbackData_0 = runtime.ForwardResponseMessage + + forward_Query_CallbackDataAll_0 = runtime.ForwardResponseMessage +) diff --git a/x/icacallbacks/types/tx.pb.go b/x/icacallbacks/types/tx.pb.go new file mode 100644 index 00000000..b60c4dfc --- /dev/null +++ b/x/icacallbacks/types/tx.pb.go @@ -0,0 +1,81 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icacallbacks/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +func init() { proto.RegisterFile("lum-network/icacallbacks/tx.proto", fileDescriptor_71abee54076e42aa) } + +var fileDescriptor_71abee54076e42aa = []byte{ + // 138 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0x4c, 0x4e, 0x4c, 0x4e, 0xcc, 0xc9, 0x49, + 0x4a, 0x4c, 0xce, 0x2e, 0xd6, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xc8, + 0x29, 0xcd, 0xd5, 0x83, 0x2a, 0xd1, 0x43, 0x56, 0x62, 0xc4, 0xca, 0xc5, 0xec, 0x5b, 0x9c, 0xee, + 0xe4, 0x7d, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, + 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x86, 0xe9, 0x99, 0x25, + 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc8, 0x16, 0x25, 0x67, 0x24, 0x66, 0xe6, 0xe9, + 0x57, 0xa0, 0x59, 0x58, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xb6, 0xd4, 0x18, 0x10, 0x00, 0x00, + 0xff, 0xff, 0xd6, 0xf9, 0x8f, 0xdf, 0x99, 0x00, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "lum.network.icacallbacks.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{}, + Metadata: "lum-network/icacallbacks/tx.proto", +} diff --git a/x/icacallbacks/types/types.go b/x/icacallbacks/types/types.go new file mode 100644 index 00000000..ab1254f4 --- /dev/null +++ b/x/icacallbacks/types/types.go @@ -0,0 +1 @@ +package types diff --git a/x/icqueries/client/cli/query.go b/x/icqueries/client/cli/query.go new file mode 100644 index 00000000..f22605e2 --- /dev/null +++ b/x/icqueries/client/cli/query.go @@ -0,0 +1,97 @@ +package cli + +import ( + "context" + "fmt" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + "github.com/lum-network/chain/x/icqueries/types" + "github.com/spf13/cobra" + "strings" +) + +// GetQueryCmd returns the cli query commands for this module. +func GetQueryCmd() *cobra.Command { + // Group lockup queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + GetCmdListQueries(), + GetCmdListPendingQueries(), + ) + + return cmd +} + +// GetCmdListQueries provides a list of all pending queries (queries that have not have been requested but have not received a response) +func GetCmdListQueries() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-queries", + Short: "Query all queries", + Example: strings.TrimSpace( + fmt.Sprintf(`$ %s query icqueries list-queries`, + version.AppName, + ), + ), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryServiceClient(clientCtx) + + req := &types.QueryQueriesRequest{} + + res, err := queryClient.Queries(context.Background(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// GetCmdListPendingQueries provides a list of all pending queries (queries that have not have been requested but have not received a response) +func GetCmdListPendingQueries() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-pending-queries", + Short: "Query all pending queries", + Example: strings.TrimSpace( + fmt.Sprintf(`$ %s query icqueries list-pending-queries`, + version.AppName, + ), + ), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryServiceClient(clientCtx) + + req := &types.QueryPendingQueriesRequest{} + + res, err := queryClient.PendingQueries(context.Background(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/icqueries/genesis.go b/x/icqueries/genesis.go new file mode 100644 index 00000000..f6f94fbb --- /dev/null +++ b/x/icqueries/genesis.go @@ -0,0 +1,21 @@ +package icqueries + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lum-network/chain/x/icqueries/keeper" + "github.com/lum-network/chain/x/icqueries/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + for _, query := range genState.Queries { + k.SetQuery(ctx, query) + } +} + +// ExportGenesis returns the capability module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + return &types.GenesisState{ + Queries: k.AllQueries(ctx), + } +} diff --git a/x/icqueries/handler.go b/x/icqueries/handler.go new file mode 100644 index 00000000..73bd1e32 --- /dev/null +++ b/x/icqueries/handler.go @@ -0,0 +1,18 @@ +package icqueries + +import ( + errorsmod "cosmossdk.io/errors" + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/lum-network/chain/x/icqueries/keeper" + "github.com/lum-network/chain/x/icqueries/types" +) + +// NewHandler returns a handler for interchainquery module messages +func NewHandler(k keeper.Keeper) sdk.Handler { + return func(_ sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } +} diff --git a/x/icqueries/keeper/abci.go b/x/icqueries/keeper/abci.go new file mode 100644 index 00000000..74ce4e1a --- /dev/null +++ b/x/icqueries/keeper/abci.go @@ -0,0 +1,49 @@ +package keeper + +import ( + "encoding/hex" + "fmt" + "github.com/lum-network/chain/x/icqueries/types" + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// EndBlocker of icqueries module +func (k *Keeper) EndBlocker(ctx sdk.Context) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + logger := k.Logger(ctx).With("ctx", "blocker_icq") + + // Loop through queries and emit them + k.IterateQueries(ctx, func(_ int64, query types.Query) (stop bool) { + if !query.RequestSent { + events := sdk.Events{} + logger.Info(fmt.Sprintf("InterchainQuery event emitted %s", query.Id)) + // QUESTION: Do we need to emit this event twice? + event := sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeValueQuery), + sdk.NewAttribute(types.AttributeKeyQueryId, query.Id), + sdk.NewAttribute(types.AttributeKeyChainId, query.ChainId), + sdk.NewAttribute(types.AttributeKeyConnectionId, query.ConnectionId), + sdk.NewAttribute(types.AttributeKeyType, query.QueryType), + sdk.NewAttribute(types.AttributeKeyHeight, "0"), + sdk.NewAttribute(types.AttributeKeyRequest, hex.EncodeToString(query.Request)), + ) + events = append(events, event) + + event.Type = "query_request" + events = append(events, event) + + query.RequestSent = true + k.SetQuery(ctx, query) + + // Emit events, it will append + ctx.EventManager().EmitEvents(events) + logger.Info(fmt.Sprintf("[ICQ] Emitted a total of %d events, on block %d for query %s", len(events), ctx.BlockHeight(), query.Id)) + } + return false + }) +} diff --git a/x/icqueries/keeper/grpc_query.go b/x/icqueries/keeper/grpc_query.go new file mode 100644 index 00000000..8b41c5c1 --- /dev/null +++ b/x/icqueries/keeper/grpc_query.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "context" + "github.com/lum-network/chain/x/icqueries/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ types.QueryServiceServer = Keeper{} + +// PendingQueries Query all queries that have been requested but have not received a response +func (k Keeper) PendingQueries(c context.Context, req *types.QueryPendingQueriesRequest) (*types.QueryPendingQueriesResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + pendingQueries := []types.Query{} + for _, query := range k.AllQueries(ctx) { + if query.RequestSent { + pendingQueries = append(pendingQueries, query) + } + } + + return &types.QueryPendingQueriesResponse{PendingQueries: pendingQueries}, nil +} + +// Queries Query all queries that have been requested but have not received a response +func (k Keeper) Queries(c context.Context, req *types.QueryQueriesRequest) (*types.QueryQueriesResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + queries := k.AllQueries(ctx) + return &types.QueryQueriesResponse{Queries: queries}, nil +} diff --git a/x/icqueries/keeper/keeper.go b/x/icqueries/keeper/keeper.go new file mode 100644 index 00000000..9296514f --- /dev/null +++ b/x/icqueries/keeper/keeper.go @@ -0,0 +1,87 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + "fmt" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" + "github.com/lum-network/chain/x/icqueries/types" + "github.com/tendermint/tendermint/libs/log" + "strings" +) + +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + callbacks map[string]types.QueryCallbacks + IBCKeeper *ibckeeper.Keeper +} + +func NewKeeper(cdc codec.Codec, storeKey storetypes.StoreKey, ibckeeper *ibckeeper.Keeper) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + callbacks: make(map[string]types.QueryCallbacks), + IBCKeeper: ibckeeper, + } +} + +func (k *Keeper) SetCallbackHandler(module string, handler types.QueryCallbacks) error { + _, found := k.callbacks[module] + if found { + return fmt.Errorf("callback handler already set for %s", module) + } + k.callbacks[module] = handler.RegisterICQCallbacks() + return nil +} + +// Logger returns a module-specific logger. +func (k *Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +func (k *Keeper) MakeRequest(ctx sdk.Context, module string, callbackId string, chainId string, connectionId string, extraId string, queryType string, request []byte, ttl uint64) error { + k.Logger(ctx).Info(fmt.Sprintf("Submitting ICQ Request - module=%s, callbackId=%s, connectionId=%s, queryType=%s, ttl=%d", module, callbackId, connectionId, queryType, ttl)) + + // Confirm the connectionId and chainId are valid + if connectionId == "" { + errMsg := "[ICQ Validation Check] Failed! connection id cannot be empty" + k.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + } + if !strings.HasPrefix(connectionId, "connection") { + errMsg := "[ICQ Validation Check] Failed! connection id must begin with 'connection'" + k.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + } + if chainId == "" { + errMsg := "[ICQ Validation Check] Failed! chain_id cannot be empty" + k.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + } + + // Confirm the module and callbackId exist + if module != "" { + if _, exists := k.callbacks[module]; !exists { + err := fmt.Errorf("no callback handler registered for module %s", module) + k.Logger(ctx).Error(err.Error()) + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "no callback handler registered for module") + } + if exists := k.callbacks[module].HasICQCallback(callbackId); !exists { + err := fmt.Errorf("no callback %s registered for module %s", callbackId, module) + k.Logger(ctx).Error(err.Error()) + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "no callback handler registered for module") + } + } + + // Save the query to the store + // If the same query is re-requested, it will get replace in the store with an updated TTL + // and the RequestSent bool reset to false + query := k.NewQuery(ctx, module, callbackId, chainId, connectionId, extraId, queryType, request, ttl) + k.SetQuery(ctx, *query) + + return nil +} diff --git a/x/icqueries/keeper/msg_server.go b/x/icqueries/keeper/msg_server.go new file mode 100644 index 00000000..fd79500d --- /dev/null +++ b/x/icqueries/keeper/msg_server.go @@ -0,0 +1,16 @@ +package keeper + +import ( + "github.com/lum-network/chain/x/icqueries/types" +) + +type msgServer struct { + *Keeper +} + +// NewMsgServerImpl returns an implementation of the bank MsgServer interface for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: &keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/icqueries/keeper/msg_server_query_response.go b/x/icqueries/keeper/msg_server_query_response.go new file mode 100644 index 00000000..9788d2d3 --- /dev/null +++ b/x/icqueries/keeper/msg_server_query_response.go @@ -0,0 +1,159 @@ +package keeper + +import ( + "context" + errorsmod "cosmossdk.io/errors" + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" + commitmenttypes "github.com/cosmos/ibc-go/v5/modules/core/23-commitment/types" + tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/lum-network/chain/x/icqueries/types" + "github.com/spf13/cast" + "net/url" + "sort" + "strings" +) + +// VerifyKeyProof check if the query requires proving; if it does, verify it! +func (k *Keeper) VerifyKeyProof(ctx sdk.Context, msg *types.MsgSubmitQueryResponse, query types.Query) error { + pathParts := strings.Split(query.QueryType, "/") + + // the query does NOT have an associated proof, so no need to verify it. + if pathParts[len(pathParts)-1] != "key" { + return nil + } + + // If the query is a "key" proof query, verify the results are valid by checking the poof + if msg.ProofOps == nil { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to validate proof. No proof submitted") + } + + // Get the client consensus state at the height 1 block above the message height + msgHeight, err := cast.ToUint64E(msg.Height) + if err != nil { + return err + } + height := clienttypes.NewHeight(clienttypes.ParseChainID(query.ChainId), msgHeight+1) + + // Get the client state and consensus state from the connection Id + connection, found := k.IBCKeeper.ConnectionKeeper.GetConnection(ctx, query.ConnectionId) + if !found { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "ConnectionId %s does not exist", query.ConnectionId) + } + consensusState, found := k.IBCKeeper.ClientKeeper.GetClientConsensusState(ctx, connection.ClientId, height) + if !found { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Consensus state not found for client %s and height %d", connection.ClientId, height) + } + clientState, found := k.IBCKeeper.ClientKeeper.GetClientState(ctx, connection.ClientId) + if !found { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to fetch client state for client %s", connection.ClientId) + } + tmClientState, ok := clientState.(*tmclienttypes.ClientState) + if !ok { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Client state is not tendermint") + } + + // Get the merkle path and merkle proof + path := commitmenttypes.NewMerklePath([]string{pathParts[1], url.PathEscape(string(query.Request))}...) + merkleProof, err := commitmenttypes.ConvertProofs(msg.ProofOps) + if err != nil { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Error converting proofs: %s", err.Error()) + } + + // If we got a non-nil response, verify inclusion proof + if len(msg.Result) != 0 { + if err := merkleProof.VerifyMembership(tmClientState.ProofSpecs, consensusState.GetRoot(), path, msg.Result); err != nil { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to verify membership proof: %s", err.Error()) + } + + } else { + // if we got a nil query response, verify non inclusion proof. + if err := merkleProof.VerifyNonMembership(tmClientState.ProofSpecs, consensusState.GetRoot(), path); err != nil { + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to verify non-membership proof: %s", err.Error()) + } + } + + return nil +} + +// InvokeCallback call the query's associated callback function +func (k Keeper) InvokeCallback(ctx sdk.Context, msg *types.MsgSubmitQueryResponse, query types.Query, status types.QueryResponseStatus) error { + // get all the callback handlers and sort them for determinism (each module has their own callback handler) + moduleNames := []string{} + for moduleName := range k.callbacks { + moduleNames = append(moduleNames, moduleName) + } + sort.Strings(moduleNames) + + // Loop through each module until the callbackId is found in one of the module handlers + for _, moduleName := range moduleNames { + moduleCallbackHandler := k.callbacks[moduleName] + + // Once the callback is found, invoke the function + if moduleCallbackHandler.HasICQCallback(query.CallbackId) { + return moduleCallbackHandler.CallICQCallback(ctx, query.CallbackId, msg.Result, query, status) + } + } + + // If no callback was found, return an error + return types.ErrICQCallbackNotFound +} + +// SubmitQueryResponse Handle ICQ query responses by validating the proof, and calling the query's corresponding callback +func (k msgServer) SubmitQueryResponse(goCtx context.Context, msg *types.MsgSubmitQueryResponse) (*types.MsgSubmitQueryResponseResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if the response has an associated query stored on Lum + query, found := k.GetQuery(ctx, msg.QueryId) + if !found { + k.Logger(ctx).Info("ICQ RESPONSE | Ignoring non-existent query response (note: duplicate responses are nonexistent)") + return &types.MsgSubmitQueryResponseResponse{}, nil // technically this is an error, but will cause the entire tx to fail if we have one 'bad' message, so we can just no-op here. + } + + defer ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyQueryId, query.Id), + ), + sdk.NewEvent( + "query_response", + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyQueryId, query.Id), + sdk.NewAttribute(types.AttributeKeyChainId, query.ChainId), + ), + }) + + // Verify the response's proof, if one exists + err := k.VerifyKeyProof(ctx, msg, query) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("QUERY PROOF VERIFICATION FAILED - QueryId: %s, Error: %s", query.Id, err.Error())) + if err = k.InvokeCallback(ctx, msg, query, types.QueryResponseStatus_FAILURE); err != nil { + return nil, err + } + return nil, err + } + + // Immediately delete the query so it cannot process again + k.DeleteQuery(ctx, query.Id) + + // Verify the query hasn't expired (if the block time is greater than the TTL timestamp, the query is expired) + currBlockTime, err := cast.ToUint64E(ctx.BlockTime().UnixNano()) + if err != nil { + return nil, err + } + if query.Ttl < currBlockTime { + if err = k.InvokeCallback(ctx, msg, query, types.QueryResponseStatus_TIMEOUT); err != nil { + return nil, err + } + return &types.MsgSubmitQueryResponseResponse{}, nil + } + + // Call the query's associated callback function + if err = k.InvokeCallback(ctx, msg, query, types.QueryResponseStatus_SUCCESS); err != nil { + return nil, err + } + + return &types.MsgSubmitQueryResponseResponse{}, nil +} diff --git a/x/icqueries/keeper/queries.go b/x/icqueries/keeper/queries.go new file mode 100644 index 00000000..b84c23be --- /dev/null +++ b/x/icqueries/keeper/queries.go @@ -0,0 +1,117 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/lum-network/chain/x/icqueries/types" + "github.com/tendermint/tendermint/crypto" +) + +// GenerateQueryHash Serialize the query parameters into a hash to give to the relayer +func GenerateQueryHash(connectionId string, chainId string, extraId string, queryType string, request []byte, module string, callbackId string) string { + return fmt.Sprintf("%x", crypto.Sha256(append([]byte(module+connectionId+chainId+extraId+queryType+callbackId), request...))) +} + +// NewQuery Build a new query structure +func (k *Keeper) NewQuery(ctx sdk.Context, module string, callbackId string, chainId string, connectionId string, extraId string, queryType string, request []byte, ttl uint64) *types.Query { + return &types.Query{ + Id: GenerateQueryHash(connectionId, chainId, extraId, queryType, request, module, callbackId), + ConnectionId: connectionId, + ChainId: chainId, + ExtraId: extraId, + QueryType: queryType, + Request: request, + CallbackId: callbackId, + Ttl: ttl, + RequestSent: false, + } +} + +// GetQuery returns query +func (k *Keeper) GetQuery(ctx sdk.Context, id string) (types.Query, bool) { + query := types.Query{} + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixQuery) + bz := store.Get([]byte(id)) + if len(bz) == 0 { + return query, false + } + k.cdc.MustUnmarshal(bz, &query) + return query, true +} + +// SetQuery set query info +func (k *Keeper) SetQuery(ctx sdk.Context, query types.Query) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixQuery) + bz := k.cdc.MustMarshal(&query) + store.Set([]byte(query.Id), bz) +} + +// DeleteQuery delete query info +func (k *Keeper) DeleteQuery(ctx sdk.Context, id string) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixQuery) + store.Delete([]byte(id)) +} + +// IterateQueries iterate through queries +func (k *Keeper) IterateQueries(ctx sdk.Context, fn func(index int64, queryInfo types.Query) (stop bool)) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixQuery) + iterator := sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + + i := int64(0) + for ; iterator.Valid(); iterator.Next() { + query := types.Query{} + k.cdc.MustUnmarshal(iterator.Value(), &query) + stop := fn(i, query) + + if stop { + break + } + i++ + } +} + +// AllQueries returns every queryInfo in the store +func (k *Keeper) AllQueries(ctx sdk.Context) []types.Query { + queries := []types.Query{} + k.IterateQueries(ctx, func(_ int64, queryInfo types.Query) (stop bool) { + queries = append(queries, queryInfo) + return false + }) + return queries +} + +// UnmarshalAmountFromBalanceQuery Helper function to unmarshal a Balance query response across SDK versions +// Before SDK v46, the query response returned a sdk.Coin type. SDK v46 returns an int type +// https://github.com/cosmos/cosmos-sdk/pull/9832 +func UnmarshalAmountFromBalanceQuery(cdc codec.BinaryCodec, queryResponseBz []byte) (amount sdkmath.Int, err error) { + // If the query response is empty, that means the account was never registed (and thus has a 0 balance) + if len(queryResponseBz) == 0 { + return sdkmath.ZeroInt(), nil + } + + // First attempt to unmarshal as an Int (for SDK v46+) + // If the result was serialized as a `Coin` type, it should contain a string (representing the denom) + // which will cause the unmarshalling to throw an error + intError := amount.Unmarshal(queryResponseBz) + if intError == nil { + return amount, nil + } + + // If the Int unmarshaling was unsuccessful, attempt again using a Coin type (for SDK v45 and below) + // If successful, return the amount field from the coin (if the coin is not nil) + var coin sdk.Coin + coinError := cdc.Unmarshal(queryResponseBz, &coin) + if coinError == nil { + return coin.Amount, nil + } + + // If it failed unmarshaling with either data structure, return an error with the failure messages combined + return sdkmath.Int{}, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unable to unmarshal balance query response %v as sdkmath.Int (err: %s) or sdk.Coin (err: %s)", queryResponseBz, intError.Error(), coinError.Error()) +} diff --git a/x/icqueries/module.go b/x/icqueries/module.go new file mode 100644 index 00000000..65c08a75 --- /dev/null +++ b/x/icqueries/module.go @@ -0,0 +1,157 @@ +package icqueries + +import ( + "context" + "encoding/json" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/lum-network/chain/x/icqueries/client/cli" + "github.com/lum-network/chain/x/icqueries/keeper" + "github.com/lum-network/chain/x/icqueries/types" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.Codec +} + +// NewAppModuleBasic return a new AppModuleBasic +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterCodec registers a legacy amino codec +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterLegacyAminoCodec registers a legacy amino codec +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + // RegisterInterfaces registers interfaces and implementations of the bank module. + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + return nil +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryServiceHandlerClient(context.Background(), mux, types.NewQueryServiceClient(clientCtx)) + if err != nil { + panic(err) + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + keeper keeper.Keeper +} + +// NewAppModule return a new AppModule +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the capability module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the capability module's Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServiceServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + InitGenesis(ctx, am.keeper, genState) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { +} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + am.keeper.EndBlocker(ctx) + return []abci.ValidatorUpdate{} +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return types.ModuleVersion } diff --git a/x/icqueries/types/callbacks.go b/x/icqueries/types/callbacks.go new file mode 100644 index 00000000..610c8b4f --- /dev/null +++ b/x/icqueries/types/callbacks.go @@ -0,0 +1,20 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type QueryResponseStatus int + +const ( + QueryResponseStatus_SUCCESS QueryResponseStatus = iota + QueryResponseStatus_TIMEOUT + QueryResponseStatus_FAILURE +) + +type QueryCallbacks interface { + AddICQCallback(id string, fn interface{}) QueryCallbacks + RegisterICQCallbacks() QueryCallbacks + CallICQCallback(ctx sdk.Context, id string, args []byte, query Query, status QueryResponseStatus) error + HasICQCallback(id string) bool +} diff --git a/x/icqueries/types/codec.go b/x/icqueries/types/codec.go new file mode 100644 index 00000000..f9f6557f --- /dev/null +++ b/x/icqueries/types/codec.go @@ -0,0 +1,32 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgSubmitQueryResponse{}, "/stride.interchainquery.MsgSubmitQueryResponse", nil) +} + +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgSubmitQueryResponse{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/icqueries/types/errors.go b/x/icqueries/types/errors.go new file mode 100644 index 00000000..d604c5cf --- /dev/null +++ b/x/icqueries/types/errors.go @@ -0,0 +1,13 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +var ( + ErrAlreadyFulfilled = errorsmod.Register(ModuleName, 1001, "query already fulfilled") + ErrSucceededNoDelete = errorsmod.Register(ModuleName, 1002, "query succeeded; do not not execute default behavior") + ErrInvalidICQProof = errorsmod.Register(ModuleName, 1003, "icq query response failed") + ErrICQCallbackNotFound = errorsmod.Register(ModuleName, 1004, "icq callback id not found") + ErrInvalidQuery = errorsmod.Register(ModuleName, 1005, "Query has an invalid parameter") +) diff --git a/x/icqueries/types/events.go b/x/icqueries/types/events.go new file mode 100644 index 00000000..d5dec6cc --- /dev/null +++ b/x/icqueries/types/events.go @@ -0,0 +1,14 @@ +package types + +const ( + AttributeKeyQueryId = "query_id" + AttributeKeyChainId = "chain_id" + AttributeKeyConnectionId = "connection_id" + AttributeKeyType = "type" + AttributeKeyParams = "parameters" + AttributeKeyRequest = "request" + AttributeKeyHeight = "height" + + AttributeValueCategory = ModuleName + AttributeValueQuery = "query" +) diff --git a/x/icqueries/types/genesis.go b/x/icqueries/types/genesis.go new file mode 100644 index 00000000..d519d19a --- /dev/null +++ b/x/icqueries/types/genesis.go @@ -0,0 +1,22 @@ +package types + +func NewGenesisState(queries []Query) *GenesisState { + return &GenesisState{Queries: queries} +} + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { + var queries []Query + return NewGenesisState(queries) +} + +// Validate performs basic genesis state validation returning an error upon any failure. +func (gs GenesisState) Validate() error { + // Loop through all queries and validate them + for _, query := range gs.GetQueries() { + if err := query.ValidateBasic(); err != nil { + return err + } + } + return nil +} diff --git a/x/icqueries/types/genesis.pb.go b/x/icqueries/types/genesis.pb.go new file mode 100644 index 00000000..90d95d41 --- /dev/null +++ b/x/icqueries/types/genesis.pb.go @@ -0,0 +1,1233 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icqueries/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Query struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + QueryType string `protobuf:"bytes,4,opt,name=query_type,json=queryType,proto3" json:"query_type,omitempty"` + Request []byte `protobuf:"bytes,5,opt,name=request,proto3" json:"request,omitempty"` + CallbackId string `protobuf:"bytes,8,opt,name=callback_id,json=callbackId,proto3" json:"callback_id,omitempty"` + Ttl uint64 `protobuf:"varint,9,opt,name=ttl,proto3" json:"ttl,omitempty"` + RequestSent bool `protobuf:"varint,11,opt,name=request_sent,json=requestSent,proto3" json:"request_sent,omitempty"` + ExtraId string `protobuf:"bytes,12,opt,name=extra_id,json=extraId,proto3" json:"extra_id,omitempty"` +} + +func (m *Query) Reset() { *m = Query{} } +func (m *Query) String() string { return proto.CompactTextString(m) } +func (*Query) ProtoMessage() {} +func (*Query) Descriptor() ([]byte, []int) { + return fileDescriptor_399613b68058de67, []int{0} +} +func (m *Query) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Query) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Query.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Query) XXX_Merge(src proto.Message) { + xxx_messageInfo_Query.Merge(m, src) +} +func (m *Query) XXX_Size() int { + return m.Size() +} +func (m *Query) XXX_DiscardUnknown() { + xxx_messageInfo_Query.DiscardUnknown(m) +} + +var xxx_messageInfo_Query proto.InternalMessageInfo + +func (m *Query) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Query) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *Query) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *Query) GetQueryType() string { + if m != nil { + return m.QueryType + } + return "" +} + +func (m *Query) GetRequest() []byte { + if m != nil { + return m.Request + } + return nil +} + +func (m *Query) GetCallbackId() string { + if m != nil { + return m.CallbackId + } + return "" +} + +func (m *Query) GetTtl() uint64 { + if m != nil { + return m.Ttl + } + return 0 +} + +func (m *Query) GetRequestSent() bool { + if m != nil { + return m.RequestSent + } + return false +} + +func (m *Query) GetExtraId() string { + if m != nil { + return m.ExtraId + } + return "" +} + +type DataPoint struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + RemoteHeight github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=remote_height,json=remoteHeight,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"remote_height"` + LocalHeight github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=local_height,json=localHeight,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"local_height"` + Value []byte `protobuf:"bytes,4,opt,name=value,proto3" json:"result,omitempty"` +} + +func (m *DataPoint) Reset() { *m = DataPoint{} } +func (m *DataPoint) String() string { return proto.CompactTextString(m) } +func (*DataPoint) ProtoMessage() {} +func (*DataPoint) Descriptor() ([]byte, []int) { + return fileDescriptor_399613b68058de67, []int{1} +} +func (m *DataPoint) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DataPoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DataPoint.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DataPoint) XXX_Merge(src proto.Message) { + xxx_messageInfo_DataPoint.Merge(m, src) +} +func (m *DataPoint) XXX_Size() int { + return m.Size() +} +func (m *DataPoint) XXX_DiscardUnknown() { + xxx_messageInfo_DataPoint.DiscardUnknown(m) +} + +var xxx_messageInfo_DataPoint proto.InternalMessageInfo + +func (m *DataPoint) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *DataPoint) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +// GenesisState defines the epochs module's genesis state. +type GenesisState struct { + Queries []Query `protobuf:"bytes,1,rep,name=queries,proto3" json:"queries"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_399613b68058de67, []int{2} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetQueries() []Query { + if m != nil { + return m.Queries + } + return nil +} + +func init() { + proto.RegisterType((*Query)(nil), "stride.interchainquery.v1.Query") + proto.RegisterType((*DataPoint)(nil), "stride.interchainquery.v1.DataPoint") + proto.RegisterType((*GenesisState)(nil), "stride.interchainquery.v1.GenesisState") +} + +func init() { + proto.RegisterFile("lum-network/icqueries/genesis.proto", fileDescriptor_399613b68058de67) +} + +var fileDescriptor_399613b68058de67 = []byte{ + // 500 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0xb1, 0x8e, 0xd3, 0x40, + 0x10, 0x8d, 0x93, 0x0b, 0x49, 0x36, 0x3e, 0x74, 0x5a, 0x5d, 0xe1, 0x9c, 0x84, 0x63, 0x72, 0x12, + 0x8a, 0x10, 0x71, 0x04, 0xb4, 0x14, 0x28, 0x42, 0xe2, 0xdc, 0x1d, 0x3e, 0x2a, 0x1a, 0xcb, 0xb1, + 0x47, 0xce, 0x2a, 0xf6, 0x6e, 0xce, 0x3b, 0x3e, 0x2e, 0x25, 0x35, 0x0d, 0x1f, 0xc3, 0x47, 0x5c, + 0x79, 0xa2, 0x42, 0x14, 0x11, 0x4a, 0x3a, 0xbe, 0x02, 0xed, 0xae, 0x23, 0x22, 0x21, 0x3a, 0xaa, + 0xec, 0xcc, 0x9b, 0x79, 0xf3, 0x66, 0xf2, 0x4c, 0xce, 0xf3, 0xaa, 0x98, 0x70, 0xc0, 0x8f, 0xa2, + 0x5c, 0x4e, 0x59, 0x72, 0x5d, 0x41, 0xc9, 0x40, 0x4e, 0x33, 0xe0, 0x20, 0x99, 0xf4, 0x57, 0xa5, + 0x40, 0x41, 0x07, 0x12, 0x4b, 0x96, 0x82, 0xcf, 0x38, 0x42, 0x99, 0x2c, 0x62, 0xc6, 0x55, 0xdd, + 0xda, 0xbf, 0x79, 0x7e, 0x76, 0x9a, 0x89, 0x4c, 0xe8, 0xaa, 0xa9, 0x7a, 0x99, 0x86, 0xb3, 0x41, + 0x22, 0x64, 0x21, 0x64, 0x64, 0x00, 0x13, 0x18, 0x68, 0xf4, 0xa9, 0x49, 0xda, 0xef, 0x54, 0x37, + 0x7d, 0x48, 0x9a, 0x2c, 0x75, 0x2c, 0xcf, 0x1a, 0xf7, 0xc2, 0x26, 0x4b, 0xe9, 0x39, 0x39, 0x4e, + 0x04, 0xe7, 0x90, 0x20, 0x13, 0x3c, 0x62, 0xa9, 0xd3, 0xd4, 0x90, 0xfd, 0x27, 0x19, 0xa4, 0x74, + 0x40, 0xba, 0x5a, 0x80, 0xc2, 0x5b, 0x1a, 0xef, 0xe8, 0x38, 0x48, 0xe9, 0x23, 0x42, 0xb4, 0xac, + 0x08, 0xd7, 0x2b, 0x70, 0x8e, 0x34, 0xd8, 0xd3, 0x99, 0xf7, 0xeb, 0x15, 0x50, 0x87, 0x74, 0x4a, + 0xb8, 0xae, 0x40, 0xa2, 0xd3, 0xf6, 0xac, 0xb1, 0x1d, 0xee, 0x43, 0x3a, 0x24, 0xfd, 0x24, 0xce, + 0xf3, 0x79, 0x9c, 0x2c, 0x15, 0x6d, 0x57, 0x77, 0x92, 0x7d, 0x2a, 0x48, 0xe9, 0x09, 0x69, 0x21, + 0xe6, 0x4e, 0xcf, 0xb3, 0xc6, 0x47, 0xa1, 0x7a, 0xd2, 0xc7, 0xc4, 0xae, 0xbb, 0x23, 0x09, 0x1c, + 0x9d, 0xbe, 0x67, 0x8d, 0xbb, 0x61, 0xbf, 0xce, 0x5d, 0x01, 0x47, 0xa5, 0x14, 0x6e, 0xb1, 0x8c, + 0x15, 0xa5, 0x6d, 0x94, 0xea, 0x38, 0x48, 0x47, 0x9f, 0x9b, 0xa4, 0xf7, 0x26, 0xc6, 0xf8, 0x52, + 0x30, 0x8e, 0x7f, 0xdd, 0x21, 0x26, 0xc7, 0x25, 0x14, 0x02, 0x21, 0x5a, 0x00, 0xcb, 0x16, 0x68, + 0xee, 0x30, 0x7b, 0x75, 0xb7, 0x19, 0x36, 0x7e, 0x6c, 0x86, 0x4f, 0x32, 0x86, 0x8b, 0x6a, 0xee, + 0x27, 0xa2, 0xa8, 0x2f, 0x5b, 0xff, 0x4c, 0x64, 0xba, 0x9c, 0xaa, 0xdd, 0xa5, 0x1f, 0x70, 0xfc, + 0xf6, 0x75, 0x42, 0xea, 0xc3, 0x07, 0x1c, 0x43, 0xdb, 0x50, 0x5e, 0x68, 0x46, 0x1a, 0x11, 0x3b, + 0x17, 0x49, 0x9c, 0xef, 0x27, 0xb4, 0xfe, 0xc3, 0x84, 0xbe, 0x66, 0xac, 0x07, 0x3c, 0x25, 0xed, + 0x9b, 0x38, 0xaf, 0xcc, 0xdf, 0x60, 0xcf, 0x4e, 0x7f, 0x6d, 0x86, 0x27, 0x25, 0xc8, 0x2a, 0xc7, + 0x67, 0xa2, 0x60, 0x08, 0xc5, 0x0a, 0xd7, 0xa1, 0x29, 0x19, 0x5d, 0x12, 0xfb, 0xad, 0xb1, 0xdb, + 0x15, 0xc6, 0x08, 0xf4, 0x35, 0xe9, 0xd4, 0x36, 0x74, 0x2c, 0xaf, 0x35, 0xee, 0xbf, 0xf0, 0xfc, + 0x7f, 0xfa, 0xcf, 0xd7, 0x56, 0x9a, 0x1d, 0x29, 0xe5, 0xe1, 0xbe, 0x6d, 0x76, 0x71, 0xb7, 0x75, + 0xad, 0xfb, 0xad, 0x6b, 0xfd, 0xdc, 0xba, 0xd6, 0x97, 0x9d, 0xdb, 0xb8, 0xdf, 0xb9, 0x8d, 0xef, + 0x3b, 0xb7, 0xf1, 0xc1, 0x3f, 0x58, 0xed, 0xd0, 0xf9, 0x9a, 0x74, 0x7a, 0x7b, 0xf0, 0x05, 0xe8, + 0x35, 0xe7, 0x0f, 0xb4, 0x69, 0x5f, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x68, 0xa8, 0x29, + 0x27, 0x03, 0x00, 0x00, +} + +func (m *Query) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Query) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Query) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ExtraId) > 0 { + i -= len(m.ExtraId) + copy(dAtA[i:], m.ExtraId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ExtraId))) + i-- + dAtA[i] = 0x62 + } + if m.RequestSent { + i-- + if m.RequestSent { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x58 + } + if m.Ttl != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Ttl)) + i-- + dAtA[i] = 0x48 + } + if len(m.CallbackId) > 0 { + i -= len(m.CallbackId) + copy(dAtA[i:], m.CallbackId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.CallbackId))) + i-- + dAtA[i] = 0x42 + } + if len(m.Request) > 0 { + i -= len(m.Request) + copy(dAtA[i:], m.Request) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Request))) + i-- + dAtA[i] = 0x2a + } + if len(m.QueryType) > 0 { + i -= len(m.QueryType) + copy(dAtA[i:], m.QueryType) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.QueryType))) + i-- + dAtA[i] = 0x22 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x1a + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x12 + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DataPoint) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DataPoint) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DataPoint) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x22 + } + { + size := m.LocalHeight.Size() + i -= size + if _, err := m.LocalHeight.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.RemoteHeight.Size() + i -= size + if _, err := m.RemoteHeight.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Queries) > 0 { + for iNdEx := len(m.Queries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Queries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Query) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.QueryType) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.Request) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.CallbackId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Ttl != 0 { + n += 1 + sovGenesis(uint64(m.Ttl)) + } + if m.RequestSent { + n += 2 + } + l = len(m.ExtraId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *DataPoint) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.RemoteHeight.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.LocalHeight.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = len(m.Value) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Queries) > 0 { + for _, e := range m.Queries { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Query) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Query: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Query: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QueryType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Request = append(m.Request[:0], dAtA[iNdEx:postIndex]...) + if m.Request == nil { + m.Request = []byte{} + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CallbackId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CallbackId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Ttl", wireType) + } + m.Ttl = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Ttl |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RequestSent", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.RequestSent = bool(v != 0) + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExtraId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExtraId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DataPoint) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DataPoint: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DataPoint: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RemoteHeight", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RemoteHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LocalHeight", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LocalHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) + if m.Value == nil { + m.Value = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Queries", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Queries = append(m.Queries, Query{}) + if err := m.Queries[len(m.Queries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqueries/types/keys.go b/x/icqueries/types/keys.go new file mode 100644 index 00000000..4e5a6a74 --- /dev/null +++ b/x/icqueries/types/keys.go @@ -0,0 +1,41 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "interchainquery" + + // ModuleVersion defines the module version + ModuleVersion = 1 + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName +) + +// prefix bytes for the icqueries persistent store +const ( + prefixData = iota + 1 + prefixQuery = iota + 1 +) + +// keys for proof queries to various stores, note: there's an implicit assumption here that +// the stores on the counterparty chain are prefixed with the standard cosmos-sdk module names +// this might not be true for all IBC chains, and is something we should verify before onboarding a new chain + +const ( + BANK_STORE_QUERY_WITH_PROOF = "store/bank/key" +) + +var ( + KeyPrefixData = []byte{prefixData} + KeyPrefixQuery = []byte{prefixQuery} +) + +func KeyPrefix(p string) []byte { + return []byte(p) +} diff --git a/x/icqueries/types/message_submit_query_response.go b/x/icqueries/types/message_submit_query_response.go new file mode 100644 index 00000000..18cbf9dd --- /dev/null +++ b/x/icqueries/types/message_submit_query_response.go @@ -0,0 +1,45 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + TypeMsgSubmitQueryResponse = "submitqueryresponse" +) + +var _ sdk.Msg = &MsgSubmitQueryResponse{} + +// Route Implements Msg. +func (msg *MsgSubmitQueryResponse) Route() string { return RouterKey } + +// Type Implements Msg. +func (msg *MsgSubmitQueryResponse) Type() string { return TypeMsgSubmitQueryResponse } + +// ValidateBasic Implements Msg. +func (msg *MsgSubmitQueryResponse) ValidateBasic() error { + // check from address + _, err := sdk.AccAddressFromBech32(msg.FromAddress) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid fromAddress in ICQ response (%s)", err) + } + // check chain_id is not empty + if msg.ChainId == "" { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "chain_id cannot be empty in ICQ response") + } + + return nil +} + +// GetSignBytes Implements Msg. +func (msg *MsgSubmitQueryResponse) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +// GetSigners Implements Msg. +func (msg *MsgSubmitQueryResponse) GetSigners() []sdk.AccAddress { + fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{fromAddress} +} diff --git a/x/icqueries/types/query.go b/x/icqueries/types/query.go new file mode 100644 index 00000000..cb2da89d --- /dev/null +++ b/x/icqueries/types/query.go @@ -0,0 +1,37 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + "strings" +) + +func (query *Query) ValidateBasic() error { + if len(query.GetId()) <= 0 { + return errorsmod.Wrapf(ErrInvalidQuery, "query id is required") + } + + if len(query.GetConnectionId()) <= 0 { + return errorsmod.Wrapf(ErrInvalidQuery, "connection id is required") + } + + if !strings.HasPrefix(query.GetConnectionId(), "connection") { + return errorsmod.Wrapf(ErrInvalidQuery, "connection id must start with connection") + } + + if len(query.GetChainId()) <= 0 { + return errorsmod.Wrapf(ErrInvalidQuery, "chain id is required") + } + + if len(query.GetQueryType()) <= 0 { + return errorsmod.Wrapf(ErrInvalidQuery, "query type is required") + } + + if len(query.GetRequest()) <= 0 { + return errorsmod.Wrapf(ErrInvalidQuery, "query request is required") + } + + if len(query.GetCallbackId()) <= 0 { + return errorsmod.Wrapf(ErrInvalidQuery, "callback id is required") + } + return nil +} diff --git a/x/icqueries/types/query.pb.go b/x/icqueries/types/query.pb.go new file mode 100644 index 00000000..da42e0e0 --- /dev/null +++ b/x/icqueries/types/query.pb.go @@ -0,0 +1,892 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icqueries/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryPendingQueriesRequest struct { +} + +func (m *QueryPendingQueriesRequest) Reset() { *m = QueryPendingQueriesRequest{} } +func (m *QueryPendingQueriesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPendingQueriesRequest) ProtoMessage() {} +func (*QueryPendingQueriesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1933117f413049ed, []int{0} +} +func (m *QueryPendingQueriesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPendingQueriesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPendingQueriesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPendingQueriesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPendingQueriesRequest.Merge(m, src) +} +func (m *QueryPendingQueriesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPendingQueriesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPendingQueriesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPendingQueriesRequest proto.InternalMessageInfo + +type QueryPendingQueriesResponse struct { + PendingQueries []Query `protobuf:"bytes,1,rep,name=pending_queries,json=pendingQueries,proto3" json:"pending_queries"` +} + +func (m *QueryPendingQueriesResponse) Reset() { *m = QueryPendingQueriesResponse{} } +func (m *QueryPendingQueriesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPendingQueriesResponse) ProtoMessage() {} +func (*QueryPendingQueriesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1933117f413049ed, []int{1} +} +func (m *QueryPendingQueriesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPendingQueriesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPendingQueriesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPendingQueriesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPendingQueriesResponse.Merge(m, src) +} +func (m *QueryPendingQueriesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPendingQueriesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPendingQueriesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPendingQueriesResponse proto.InternalMessageInfo + +func (m *QueryPendingQueriesResponse) GetPendingQueries() []Query { + if m != nil { + return m.PendingQueries + } + return nil +} + +type QueryQueriesRequest struct { +} + +func (m *QueryQueriesRequest) Reset() { *m = QueryQueriesRequest{} } +func (m *QueryQueriesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryQueriesRequest) ProtoMessage() {} +func (*QueryQueriesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1933117f413049ed, []int{2} +} +func (m *QueryQueriesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryQueriesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryQueriesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryQueriesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryQueriesRequest.Merge(m, src) +} +func (m *QueryQueriesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryQueriesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryQueriesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryQueriesRequest proto.InternalMessageInfo + +type QueryQueriesResponse struct { + Queries []Query `protobuf:"bytes,1,rep,name=queries,proto3" json:"queries"` +} + +func (m *QueryQueriesResponse) Reset() { *m = QueryQueriesResponse{} } +func (m *QueryQueriesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryQueriesResponse) ProtoMessage() {} +func (*QueryQueriesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1933117f413049ed, []int{3} +} +func (m *QueryQueriesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryQueriesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryQueriesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryQueriesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryQueriesResponse.Merge(m, src) +} +func (m *QueryQueriesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryQueriesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryQueriesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryQueriesResponse proto.InternalMessageInfo + +func (m *QueryQueriesResponse) GetQueries() []Query { + if m != nil { + return m.Queries + } + return nil +} + +func init() { + proto.RegisterType((*QueryPendingQueriesRequest)(nil), "stride.interchainquery.v1.QueryPendingQueriesRequest") + proto.RegisterType((*QueryPendingQueriesResponse)(nil), "stride.interchainquery.v1.QueryPendingQueriesResponse") + proto.RegisterType((*QueryQueriesRequest)(nil), "stride.interchainquery.v1.QueryQueriesRequest") + proto.RegisterType((*QueryQueriesResponse)(nil), "stride.interchainquery.v1.QueryQueriesResponse") +} + +func init() { proto.RegisterFile("lum-network/icqueries/query.proto", fileDescriptor_1933117f413049ed) } + +var fileDescriptor_1933117f413049ed = []byte{ + // 364 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xc1, 0x4a, 0xc3, 0x30, + 0x1c, 0xc6, 0xdb, 0x29, 0x0e, 0xa2, 0x4c, 0xa8, 0x13, 0xb4, 0x8e, 0x3a, 0x2b, 0x8c, 0x5d, 0x4c, + 0x70, 0xa2, 0x67, 0xd9, 0xc9, 0x9b, 0x6e, 0x5e, 0xc4, 0x8b, 0x74, 0xdd, 0x9f, 0x2e, 0xb8, 0x25, + 0x5d, 0x93, 0x4e, 0x77, 0xf5, 0x09, 0x44, 0x1f, 0xc4, 0xd7, 0xd8, 0x71, 0x20, 0x82, 0x27, 0x91, + 0xcd, 0x07, 0x91, 0xa6, 0x1d, 0xd8, 0xb1, 0x31, 0xf5, 0xd4, 0x90, 0xaf, 0xdf, 0xf7, 0xfd, 0xc2, + 0xff, 0x8f, 0xf6, 0xda, 0x61, 0xe7, 0x80, 0x81, 0xbc, 0xe3, 0xc1, 0x2d, 0xa1, 0x6e, 0x37, 0x84, + 0x80, 0x82, 0x20, 0xd1, 0xb7, 0x8f, 0xfd, 0x80, 0x4b, 0x6e, 0x6c, 0x0b, 0x19, 0xd0, 0x26, 0x60, + 0xca, 0x24, 0x04, 0x6e, 0xcb, 0xa1, 0x2c, 0x56, 0x7b, 0x87, 0xe6, 0xfe, 0x6c, 0xb7, 0x07, 0x0c, + 0x04, 0x15, 0xb1, 0xdf, 0x2c, 0x78, 0x9c, 0x7b, 0x6d, 0x20, 0x8e, 0x4f, 0x89, 0xc3, 0x18, 0x97, + 0x8e, 0xa4, 0x9c, 0x4d, 0xd4, 0xbc, 0xc7, 0x3d, 0xae, 0x8e, 0x24, 0x3a, 0xc5, 0xb7, 0x76, 0x01, + 0x99, 0xb5, 0xa8, 0xe4, 0x02, 0x58, 0x93, 0x32, 0xaf, 0x16, 0x07, 0xd7, 0xa1, 0x1b, 0x82, 0x90, + 0x36, 0x43, 0x3b, 0x33, 0x55, 0xe1, 0x73, 0x26, 0xc0, 0x38, 0x47, 0xeb, 0x7e, 0xac, 0xdc, 0x24, + 0x44, 0x5b, 0x7a, 0x71, 0xa9, 0xbc, 0x5a, 0x29, 0xe2, 0xb9, 0x4f, 0xc1, 0x2a, 0xb0, 0xba, 0x3c, + 0xf8, 0xd8, 0xd5, 0xea, 0x39, 0x3f, 0x15, 0x6c, 0x6f, 0xa2, 0x0d, 0x25, 0x4f, 0x61, 0x5c, 0xa1, + 0x7c, 0xfa, 0x3a, 0xe9, 0x3f, 0x45, 0xd9, 0xff, 0xf5, 0x4e, 0x6c, 0x95, 0xb7, 0x0c, 0x5a, 0x53, + 0xc2, 0x25, 0x04, 0x3d, 0xea, 0x82, 0xf1, 0xa4, 0xa3, 0x6c, 0x52, 0x63, 0xe0, 0x45, 0x69, 0x69, + 0x4c, 0x93, 0xfc, 0xfa, 0xff, 0x98, 0xdf, 0x2e, 0x3d, 0xbc, 0x7e, 0x3d, 0x67, 0x8a, 0x86, 0x45, + 0xe6, 0x2f, 0x47, 0x04, 0xf2, 0xa2, 0xa3, 0x5c, 0x7a, 0x04, 0xc6, 0xf1, 0xa2, 0xae, 0x99, 0x03, + 0x35, 0x4f, 0xfe, 0x6a, 0x4b, 0x48, 0xb1, 0x22, 0x2d, 0x1b, 0xa5, 0x39, 0xa4, 0x53, 0x6b, 0x50, + 0x3d, 0x1b, 0x8c, 0x2c, 0x7d, 0x38, 0xb2, 0xf4, 0xcf, 0x91, 0xa5, 0x3f, 0x8e, 0x2d, 0x6d, 0x38, + 0xb6, 0xb4, 0xf7, 0xb1, 0xa5, 0x5d, 0x63, 0x8f, 0xca, 0x56, 0xd8, 0xc0, 0x2e, 0xef, 0xa4, 0xb2, + 0x14, 0x0b, 0xb9, 0xff, 0x91, 0x29, 0xfb, 0x3e, 0x88, 0xc6, 0x8a, 0xda, 0xd3, 0xa3, 0xef, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xf4, 0x97, 0xf8, 0xf2, 0x40, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryServiceClient is the client API for QueryService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryServiceClient interface { + Queries(ctx context.Context, in *QueryQueriesRequest, opts ...grpc.CallOption) (*QueryQueriesResponse, error) + PendingQueries(ctx context.Context, in *QueryPendingQueriesRequest, opts ...grpc.CallOption) (*QueryPendingQueriesResponse, error) +} + +type queryServiceClient struct { + cc grpc1.ClientConn +} + +func NewQueryServiceClient(cc grpc1.ClientConn) QueryServiceClient { + return &queryServiceClient{cc} +} + +func (c *queryServiceClient) Queries(ctx context.Context, in *QueryQueriesRequest, opts ...grpc.CallOption) (*QueryQueriesResponse, error) { + out := new(QueryQueriesResponse) + err := c.cc.Invoke(ctx, "/stride.interchainquery.v1.QueryService/Queries", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryServiceClient) PendingQueries(ctx context.Context, in *QueryPendingQueriesRequest, opts ...grpc.CallOption) (*QueryPendingQueriesResponse, error) { + out := new(QueryPendingQueriesResponse) + err := c.cc.Invoke(ctx, "/stride.interchainquery.v1.QueryService/PendingQueries", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServiceServer is the server API for QueryService service. +type QueryServiceServer interface { + Queries(context.Context, *QueryQueriesRequest) (*QueryQueriesResponse, error) + PendingQueries(context.Context, *QueryPendingQueriesRequest) (*QueryPendingQueriesResponse, error) +} + +// UnimplementedQueryServiceServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServiceServer struct { +} + +func (*UnimplementedQueryServiceServer) Queries(ctx context.Context, req *QueryQueriesRequest) (*QueryQueriesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Queries not implemented") +} +func (*UnimplementedQueryServiceServer) PendingQueries(ctx context.Context, req *QueryPendingQueriesRequest) (*QueryPendingQueriesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PendingQueries not implemented") +} + +func RegisterQueryServiceServer(s grpc1.Server, srv QueryServiceServer) { + s.RegisterService(&_QueryService_serviceDesc, srv) +} + +func _QueryService_Queries_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryQueriesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServiceServer).Queries(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.interchainquery.v1.QueryService/Queries", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServiceServer).Queries(ctx, req.(*QueryQueriesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _QueryService_PendingQueries_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPendingQueriesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServiceServer).PendingQueries(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.interchainquery.v1.QueryService/PendingQueries", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServiceServer).PendingQueries(ctx, req.(*QueryPendingQueriesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _QueryService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.interchainquery.v1.QueryService", + HandlerType: (*QueryServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Queries", + Handler: _QueryService_Queries_Handler, + }, + { + MethodName: "PendingQueries", + Handler: _QueryService_PendingQueries_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lum-network/icqueries/query.proto", +} + +func (m *QueryPendingQueriesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPendingQueriesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPendingQueriesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryPendingQueriesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPendingQueriesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPendingQueriesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PendingQueries) > 0 { + for iNdEx := len(m.PendingQueries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PendingQueries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryQueriesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryQueriesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryQueriesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryQueriesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryQueriesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryQueriesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Queries) > 0 { + for iNdEx := len(m.Queries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Queries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryPendingQueriesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryPendingQueriesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PendingQueries) > 0 { + for _, e := range m.PendingQueries { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryQueriesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryQueriesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Queries) > 0 { + for _, e := range m.Queries { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryPendingQueriesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPendingQueriesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPendingQueriesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPendingQueriesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPendingQueriesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPendingQueriesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PendingQueries", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PendingQueries = append(m.PendingQueries, Query{}) + if err := m.PendingQueries[len(m.PendingQueries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryQueriesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryQueriesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryQueriesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryQueriesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryQueriesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryQueriesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Queries", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Queries = append(m.Queries, Query{}) + if err := m.Queries[len(m.Queries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqueries/types/query.pb.gw.go b/x/icqueries/types/query.pb.gw.go new file mode 100644 index 00000000..9c3a6e27 --- /dev/null +++ b/x/icqueries/types/query.pb.gw.go @@ -0,0 +1,218 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lum-network/icqueries/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_QueryService_Queries_0(ctx context.Context, marshaler runtime.Marshaler, client QueryServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryQueriesRequest + var metadata runtime.ServerMetadata + + msg, err := client.Queries(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_QueryService_Queries_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryQueriesRequest + var metadata runtime.ServerMetadata + + msg, err := server.Queries(ctx, &protoReq) + return msg, metadata, err + +} + +func request_QueryService_PendingQueries_0(ctx context.Context, marshaler runtime.Marshaler, client QueryServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPendingQueriesRequest + var metadata runtime.ServerMetadata + + msg, err := client.PendingQueries(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_QueryService_PendingQueries_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPendingQueriesRequest + var metadata runtime.ServerMetadata + + msg, err := server.PendingQueries(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryServiceHandlerServer registers the http handlers for service QueryService to "mux". +// UnaryRPC :call QueryServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryServiceHandlerFromEndpoint instead. +func RegisterQueryServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServiceServer) error { + + mux.Handle("GET", pattern_QueryService_Queries_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_QueryService_Queries_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_QueryService_Queries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_QueryService_PendingQueries_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_QueryService_PendingQueries_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_QueryService_PendingQueries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryServiceHandlerFromEndpoint is same as RegisterQueryServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryServiceHandler(ctx, mux, conn) +} + +// RegisterQueryServiceHandler registers the http handlers for service QueryService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryServiceHandlerClient(ctx, mux, NewQueryServiceClient(conn)) +} + +// RegisterQueryServiceHandlerClient registers the http handlers for service QueryService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryServiceClient" to call the correct interceptors. +func RegisterQueryServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryServiceClient) error { + + mux.Handle("GET", pattern_QueryService_Queries_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_QueryService_Queries_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_QueryService_Queries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_QueryService_PendingQueries_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_QueryService_PendingQueries_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_QueryService_PendingQueries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_QueryService_Queries_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "icqueries", "queries"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_QueryService_PendingQueries_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "icqueries", "pending_queries"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_QueryService_Queries_0 = runtime.ForwardResponseMessage + + forward_QueryService_PendingQueries_0 = runtime.ForwardResponseMessage +) diff --git a/x/icqueries/types/tx.pb.go b/x/icqueries/types/tx.pb.go new file mode 100644 index 00000000..88cf4f37 --- /dev/null +++ b/x/icqueries/types/tx.pb.go @@ -0,0 +1,762 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/icqueries/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgSubmitQueryResponse represents a message type to fulfil a query request. +type MsgSubmitQueryResponse struct { + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty" yaml:"chain_id"` + QueryId string `protobuf:"bytes,2,opt,name=query_id,json=queryId,proto3" json:"query_id,omitempty" yaml:"query_id"` + Result []byte `protobuf:"bytes,3,opt,name=result,proto3" json:"result,omitempty" yaml:"result"` + ProofOps *crypto.ProofOps `protobuf:"bytes,4,opt,name=proof_ops,json=proofOps,proto3" json:"proof_ops,omitempty" yaml:"proof_ops"` + Height int64 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty" yaml:"height"` + FromAddress string `protobuf:"bytes,6,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` +} + +func (m *MsgSubmitQueryResponse) Reset() { *m = MsgSubmitQueryResponse{} } +func (m *MsgSubmitQueryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitQueryResponse) ProtoMessage() {} +func (*MsgSubmitQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_372a17fce0f9aeb9, []int{0} +} +func (m *MsgSubmitQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitQueryResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSubmitQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitQueryResponse.Merge(m, src) +} +func (m *MsgSubmitQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitQueryResponse proto.InternalMessageInfo + +// MsgSubmitQueryResponseResponse defines the MsgSubmitQueryResponse response type. +type MsgSubmitQueryResponseResponse struct { +} + +func (m *MsgSubmitQueryResponseResponse) Reset() { *m = MsgSubmitQueryResponseResponse{} } +func (m *MsgSubmitQueryResponseResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitQueryResponseResponse) ProtoMessage() {} +func (*MsgSubmitQueryResponseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_372a17fce0f9aeb9, []int{1} +} +func (m *MsgSubmitQueryResponseResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitQueryResponseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitQueryResponseResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSubmitQueryResponseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitQueryResponseResponse.Merge(m, src) +} +func (m *MsgSubmitQueryResponseResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitQueryResponseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitQueryResponseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitQueryResponseResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgSubmitQueryResponse)(nil), "stride.interchainquery.v1.MsgSubmitQueryResponse") + proto.RegisterType((*MsgSubmitQueryResponseResponse)(nil), "stride.interchainquery.v1.MsgSubmitQueryResponseResponse") +} + +func init() { proto.RegisterFile("lum-network/icqueries/tx.proto", fileDescriptor_372a17fce0f9aeb9) } + +var fileDescriptor_372a17fce0f9aeb9 = []byte{ + // 508 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xbf, 0x8f, 0xd3, 0x30, + 0x14, 0xc7, 0xeb, 0x16, 0x7a, 0x77, 0xb9, 0x22, 0x20, 0x57, 0xa1, 0x5c, 0x81, 0xa4, 0xf2, 0x42, + 0x41, 0x9c, 0xad, 0x96, 0x89, 0x32, 0xd1, 0x89, 0x1b, 0x8e, 0x1f, 0xb9, 0x8d, 0xa5, 0x4a, 0x1b, + 0x5f, 0x6a, 0xd1, 0xd8, 0xc1, 0x76, 0x8e, 0x76, 0x65, 0x62, 0x44, 0x62, 0x61, 0xec, 0x1f, 0x81, + 0xc4, 0xc8, 0xca, 0x78, 0x82, 0x85, 0xa9, 0x42, 0x2d, 0x03, 0xac, 0xfd, 0x0b, 0x50, 0xec, 0x04, + 0xaa, 0x53, 0x19, 0x98, 0xfc, 0xf2, 0xbe, 0x9f, 0xf7, 0xfc, 0xbe, 0xb1, 0x6d, 0xb9, 0xe3, 0x34, + 0x3e, 0x60, 0x44, 0xbd, 0xe2, 0xe2, 0x05, 0xa6, 0xc3, 0x97, 0x29, 0x11, 0x94, 0x48, 0xac, 0x26, + 0x28, 0x11, 0x5c, 0x71, 0x7b, 0x5f, 0x2a, 0x41, 0x43, 0x82, 0x28, 0x53, 0x44, 0x0c, 0x47, 0x01, + 0x65, 0x19, 0x32, 0x45, 0xa7, 0xed, 0x46, 0x3d, 0xe2, 0x11, 0xd7, 0x14, 0xce, 0x22, 0x53, 0xd0, + 0xd8, 0x1f, 0x72, 0x19, 0x73, 0xd9, 0x37, 0x82, 0xf9, 0xc8, 0xa5, 0x1b, 0x11, 0xe7, 0xd1, 0x98, + 0xe0, 0x20, 0xa1, 0x38, 0x60, 0x8c, 0xab, 0x40, 0x51, 0xce, 0x0a, 0xf5, 0xa6, 0x22, 0x2c, 0x24, + 0x22, 0xa6, 0x4c, 0xe1, 0xa1, 0x98, 0x26, 0x8a, 0xe3, 0x44, 0x70, 0x7e, 0x62, 0x64, 0xf8, 0xab, + 0x6c, 0x5d, 0x3b, 0x92, 0xd1, 0x71, 0x3a, 0x88, 0xa9, 0x7a, 0x96, 0xcd, 0xe0, 0x13, 0x99, 0x70, + 0x26, 0x89, 0x8d, 0xac, 0x6d, 0x3d, 0x59, 0x9f, 0x86, 0x0e, 0x68, 0x82, 0xd6, 0x4e, 0x6f, 0x6f, + 0x35, 0xf7, 0x2e, 0x4f, 0x83, 0x78, 0xdc, 0x85, 0x85, 0x02, 0xfd, 0x2d, 0x1d, 0x1e, 0x86, 0x19, + 0xaf, 0x4d, 0x64, 0x7c, 0xf9, 0x3c, 0x5f, 0x28, 0xd0, 0xdf, 0xd2, 0xe1, 0x61, 0x68, 0xdf, 0xb6, + 0xaa, 0x82, 0xc8, 0x74, 0xac, 0x9c, 0x4a, 0x13, 0xb4, 0x6a, 0xbd, 0xab, 0xab, 0xb9, 0x77, 0xc9, + 0xd0, 0x26, 0x0f, 0xfd, 0x1c, 0xb0, 0x1f, 0x5b, 0x3b, 0x7a, 0xe8, 0x3e, 0x4f, 0xa4, 0x73, 0xa1, + 0x09, 0x5a, 0xbb, 0x9d, 0xeb, 0xe8, 0xaf, 0x31, 0x64, 0x8c, 0xa1, 0xa7, 0x19, 0xf3, 0x24, 0x91, + 0xbd, 0xfa, 0x6a, 0xee, 0x5d, 0x31, 0xad, 0xfe, 0xd4, 0x41, 0x7f, 0x3b, 0xc9, 0xf5, 0x6c, 0xeb, + 0x11, 0xa1, 0xd1, 0x48, 0x39, 0x17, 0x9b, 0xa0, 0x55, 0x59, 0xdf, 0xda, 0xe4, 0xa1, 0x9f, 0x03, + 0xf6, 0x03, 0xab, 0x76, 0x22, 0x78, 0xdc, 0x0f, 0xc2, 0x50, 0x10, 0x29, 0x9d, 0xaa, 0x76, 0xe6, + 0x7c, 0xf9, 0x70, 0x50, 0xcf, 0x4f, 0xe1, 0xa1, 0x51, 0x8e, 0x95, 0xa0, 0x2c, 0xf2, 0x77, 0x33, + 0x3a, 0x4f, 0x75, 0x6b, 0x6f, 0x66, 0x5e, 0xe9, 0xfd, 0xcc, 0x03, 0x3f, 0x67, 0x5e, 0x09, 0x36, + 0x2d, 0x77, 0xf3, 0xaf, 0x2e, 0xd6, 0xce, 0x27, 0x60, 0x55, 0x8e, 0x64, 0x64, 0x7f, 0x04, 0xd6, + 0xde, 0xa6, 0x23, 0x69, 0xa3, 0x7f, 0xde, 0x1b, 0xb4, 0xb9, 0x75, 0xe3, 0xfe, 0x7f, 0x97, 0x14, + 0x2b, 0xec, 0xbc, 0xfe, 0xfa, 0xe3, 0x5d, 0xf9, 0x2e, 0xbc, 0x85, 0xcf, 0xd5, 0x62, 0x35, 0xc1, + 0xa7, 0xed, 0x01, 0x51, 0x41, 0x1b, 0x4b, 0xdd, 0x40, 0xa7, 0xbb, 0xe0, 0x4e, 0xef, 0xd1, 0xe7, + 0x85, 0x0b, 0xce, 0x16, 0x2e, 0xf8, 0xbe, 0x70, 0xc1, 0xdb, 0xa5, 0x5b, 0x3a, 0x5b, 0xba, 0xa5, + 0x6f, 0x4b, 0xb7, 0xf4, 0x1c, 0x45, 0x54, 0x8d, 0xd2, 0x01, 0x1a, 0xf2, 0x18, 0xaf, 0xbf, 0x0e, + 0xdd, 0x16, 0x4f, 0xd6, 0x5f, 0xc9, 0x34, 0x21, 0x72, 0x50, 0xd5, 0x17, 0xf4, 0xde, 0xef, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x9e, 0xf7, 0x95, 0xde, 0x4b, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // SubmitQueryResponse defines a method for submit query responses. + SubmitQueryResponse(ctx context.Context, in *MsgSubmitQueryResponse, opts ...grpc.CallOption) (*MsgSubmitQueryResponseResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) SubmitQueryResponse(ctx context.Context, in *MsgSubmitQueryResponse, opts ...grpc.CallOption) (*MsgSubmitQueryResponseResponse, error) { + out := new(MsgSubmitQueryResponseResponse) + err := c.cc.Invoke(ctx, "/stride.interchainquery.v1.Msg/SubmitQueryResponse", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // SubmitQueryResponse defines a method for submit query responses. + SubmitQueryResponse(context.Context, *MsgSubmitQueryResponse) (*MsgSubmitQueryResponseResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) SubmitQueryResponse(ctx context.Context, req *MsgSubmitQueryResponse) (*MsgSubmitQueryResponseResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SubmitQueryResponse not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_SubmitQueryResponse_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSubmitQueryResponse) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SubmitQueryResponse(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.interchainquery.v1.Msg/SubmitQueryResponse", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SubmitQueryResponse(ctx, req.(*MsgSubmitQueryResponse)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.interchainquery.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SubmitQueryResponse", + Handler: _Msg_SubmitQueryResponse_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lum-network/icqueries/tx.proto", +} + +func (m *MsgSubmitQueryResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSubmitQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.FromAddress) > 0 { + i -= len(m.FromAddress) + copy(dAtA[i:], m.FromAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) + i-- + dAtA[i] = 0x32 + } + if m.Height != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x28 + } + if m.ProofOps != nil { + { + size, err := m.ProofOps.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if len(m.Result) > 0 { + i -= len(m.Result) + copy(dAtA[i:], m.Result) + i = encodeVarintTx(dAtA, i, uint64(len(m.Result))) + i-- + dAtA[i] = 0x1a + } + if len(m.QueryId) > 0 { + i -= len(m.QueryId) + copy(dAtA[i:], m.QueryId) + i = encodeVarintTx(dAtA, i, uint64(len(m.QueryId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSubmitQueryResponseResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSubmitQueryResponseResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitQueryResponseResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgSubmitQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.QueryId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Result) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.ProofOps != nil { + l = m.ProofOps.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovTx(uint64(m.Height)) + } + l = len(m.FromAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSubmitQueryResponseResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgSubmitQueryResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgSubmitQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitQueryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QueryId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Result = append(m.Result[:0], dAtA[iNdEx:postIndex]...) + if m.Result == nil { + m.Result = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofOps", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ProofOps == nil { + m.ProofOps = &crypto.ProofOps{} + } + if err := m.ProofOps.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FromAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSubmitQueryResponseResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgSubmitQueryResponseResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitQueryResponseResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqueries/types/tx.pb.gw.go b/x/icqueries/types/tx.pb.gw.go new file mode 100644 index 00000000..ca67a419 --- /dev/null +++ b/x/icqueries/types/tx.pb.gw.go @@ -0,0 +1,169 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lum-network/icqueries/tx.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Msg_SubmitQueryResponse_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgSubmitQueryResponse + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.SubmitQueryResponse(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Msg_SubmitQueryResponse_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgSubmitQueryResponse + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.SubmitQueryResponse(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". +// UnaryRPC :call MsgServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { + + mux.Handle("POST", pattern_Msg_SubmitQueryResponse_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Msg_SubmitQueryResponse_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_SubmitQueryResponse_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterMsgHandlerFromEndpoint is same as RegisterMsgHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterMsgHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterMsgHandler(ctx, mux, conn) +} + +// RegisterMsgHandler registers the http handlers for service Msg to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterMsgHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterMsgHandlerClient(ctx, mux, NewMsgClient(conn)) +} + +// RegisterMsgHandlerClient registers the http handlers for service Msg +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MsgClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MsgClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "MsgClient" to call the correct interceptors. +func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgClient) error { + + mux.Handle("POST", pattern_Msg_SubmitQueryResponse_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Msg_SubmitQueryResponse_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_SubmitQueryResponse_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Msg_SubmitQueryResponse_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchainquery", "tx", "v1beta1", "submitquery"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Msg_SubmitQueryResponse_0 = runtime.ForwardResponseMessage +) diff --git a/x/millions/abci.go b/x/millions/abci.go new file mode 100644 index 00000000..b4451e7d --- /dev/null +++ b/x/millions/abci.go @@ -0,0 +1,22 @@ +package millions + +import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/keeper" + "github.com/lum-network/chain/x/millions/types" +) + +func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + keeper.BlockPoolUpdates(ctx) +} + +func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + keeper.BlockPrizeUpdates(ctx) + keeper.BlockWithdrawalUpdates(ctx) +} diff --git a/x/millions/client/cli/proposal.go b/x/millions/client/cli/proposal.go new file mode 100644 index 00000000..49447055 --- /dev/null +++ b/x/millions/client/cli/proposal.go @@ -0,0 +1,308 @@ +package cli + +import ( + "fmt" + "os" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/lum-network/chain/x/millions/types" + "github.com/spf13/cobra" +) + +func parseRegisterPoolProposalFile(cdc codec.JSONCodec, proposalFile string) (proposal types.ProposalRegisterPool, err error) { + contents, err := os.ReadFile(proposalFile) + if err != nil { + return proposal, err + } + + if err = cdc.UnmarshalJSON(contents, &proposal); err != nil { + return proposal, err + } + return proposal, nil +} + +func parseUpdatePoolProposalFile(cdc codec.JSONCodec, proposalFile string) (proposal types.ProposalUpdatePool, err error) { + contents, err := os.ReadFile(proposalFile) + if err != nil { + return proposal, err + } + + if err = cdc.UnmarshalJSON(contents, &proposal); err != nil { + return proposal, err + } + return proposal, nil +} + +func parseUpdateParamsProposalFile(cdc codec.JSONCodec, proposalFile string) (proposal types.ProposalUpdateParams, err error) { + contents, err := os.ReadFile(proposalFile) + if err != nil { + return proposal, err + } + + if err = cdc.UnmarshalJSON(contents, &proposal); err != nil { + return proposal, err + } + return proposal, nil +} + +func CmdProposalRegisterPool() *cobra.Command { + cmd := &cobra.Command{ + Use: "millions-register-pool [proposal-file]", + Short: "Submit a millions register pool proposal", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a RegisterPool proposal along with an initial deposit. +The proposal details must be supplied via a JSON file. + +Example: +$ %s tx gov submit-legacy-proposal millions-register-pool --from= + +Where proposal.json contains: +{ + "title": "My new pool", + "description": "This is my new pool", + "chain_id": "lumnetwork-testnet", + "denom": "ulum", + "native_denom": "ulum", + "connection_id": "", + "validators": ["lumvaloper1wf6alkrpjn4zhcnag3afqz34mlanplzwx6v8qz"], + "min_deposit_amount": "1000000", + "draw_schedule": { + "draw_delta": "3600s", + "initial_draw_at": "2023-04-19T00:23:41.242670441Z" + }, + "prize_strategy": { + "prize_batches": [{ + "draw_probability": "1.000000000000000000", + "pool_percent": "100", + "quantity": "100" + }] + }, + "bech32_prefix_acc_addr": "lum", + "bech32_prefix_val_addr": "lumvaloper", + "transfer_channel_id": "" +} +`, version.AppName), + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + // Parse the proposal file + proposal, err := parseRegisterPoolProposalFile(clientCtx.Codec, args[0]) + if err != nil { + return err + } + + if err := proposal.ValidateBasic(); err != nil { + return err + } + + // Grab the parameters + from := clientCtx.GetFromAddress() + + // Grab the deposit + depositStr, err := cmd.Flags().GetString(govcli.FlagDeposit) + if err != nil { + return err + } + + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + msg, err := govtypes.NewMsgSubmitProposal(&proposal, deposit, from) + if err != nil { + return err + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + // Generate the transaction + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(govcli.FlagDeposit, "1ulum", "deposit of proposal") + if err := cmd.MarkFlagRequired(govcli.FlagDeposit); err != nil { + panic(err) + } + return cmd +} + +func CmdProposalUpdatePool() *cobra.Command { + cmd := &cobra.Command{ + Use: "millions-update-pool [proposal-file]", + Short: "Submit a millions update pool proposal", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit an UpdatePool proposal along with an initial deposit. +The proposal details must be supplied via a JSON file. + +Example: +$ %s tx gov submit-legacy-proposal millions-update-pool --from= + +Where proposal.json contains: +{ + "title": "Update my pool", + "description": "This is my updated pool", + "pool_id": 1, + "validators": ["lumvaloper1wf6alkrpjn4zhcnag3afqz34mlanplzwx6v8qz"], + "min_deposit_amount": "2000000", + "draw_schedule": { + "draw_delta": "3600s", + "initial_draw_at": "2023-04-19T00:23:41.242670441Z" + }, + "prize_strategy": { + "prize_batches": [{ + "draw_probability": "1.000000000000000000", + "pool_percent": "100", + "quantity": "100" + }] + } +} +`, version.AppName), + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + // Parse the proposal file + proposal, err := parseUpdatePoolProposalFile(clientCtx.Codec, args[0]) + if err != nil { + return err + } + + if err := proposal.ValidateBasic(); err != nil { + return err + } + + // Grab the parameters + from := clientCtx.GetFromAddress() + + // Grab the deposit + depositStr, err := cmd.Flags().GetString(govcli.FlagDeposit) + if err != nil { + return err + } + + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + msg, err := govtypes.NewMsgSubmitProposal(&proposal, deposit, from) + if err != nil { + return err + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + // Generate the transaction + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(govcli.FlagDeposit, "1ulum", "deposit of proposal") + if err := cmd.MarkFlagRequired(govcli.FlagDeposit); err != nil { + panic(err) + } + return cmd +} + +func CmdProposalUpdateParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "millions-update-params [proposal-file]", + Short: "Submit a millions update params proposal", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit an UpdateParams proposal along with an initial deposit. +The proposal details must be supplied via a JSON file. + +Example: +$ %s tx gov submit-legacy-proposal millions-update-params --from= + +Where proposal.json contains: +{ + "title": "Update my params", + "description": "This is my updated params", + "min_deposit_amount": "1", + "min_deposit_draw_delta": "60s", + "max_prize_strategy_batches": "100", + "max_prize_batch_quantity": "1000", + "min_draw_schedule_delta": "3600s", + "max_draw_schedule_delta": "31622400s", + "prize_expiration_delta": "2592000s", + "fees_stakers": "0.000000000000000000" +} +`, version.AppName), + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + // Parse the proposal file + proposal, err := parseUpdateParamsProposalFile(clientCtx.Codec, args[0]) + if err != nil { + return err + } + + if err := proposal.ValidateBasic(); err != nil { + return err + } + + // Grab the parameters + from := clientCtx.GetFromAddress() + + // Grab the deposit + depositStr, err := cmd.Flags().GetString(govcli.FlagDeposit) + if err != nil { + return err + } + + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + msg, err := govtypes.NewMsgSubmitProposal(&proposal, deposit, from) + if err != nil { + return err + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + // Generate the transaction + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(govcli.FlagDeposit, "1ulum", "deposit of proposal") + if err := cmd.MarkFlagRequired(govcli.FlagDeposit); err != nil { + panic(err) + } + return cmd +} diff --git a/x/millions/client/cli/query.go b/x/millions/client/cli/query.go new file mode 100644 index 00000000..f120c6e2 --- /dev/null +++ b/x/millions/client/cli/query.go @@ -0,0 +1,1013 @@ +package cli + +import ( + "context" + "fmt" + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/lum-network/chain/x/millions/types" +) + +func GetQueryCmd(queryRoute string) *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + groupAll := &cobra.Group{Title: "All Commands:", ID: fmt.Sprintf("%s/%s", cmd.Use, "all")} + groupPool := &cobra.Group{Title: "Pool Commands:", ID: fmt.Sprintf("%s/%s", cmd.Use, "pool")} + groupDraw := &cobra.Group{Title: "Draw Commands:", ID: fmt.Sprintf("%s/%s", cmd.Use, "draw")} + groupAccount := &cobra.Group{Title: "Account Commands:", ID: fmt.Sprintf("%s/%s", cmd.Use, "account")} + cmd.AddGroup( + groupAll, + groupPool, + groupDraw, + groupAccount, + ) + + cmd.AddCommand( + GetCmdParams(), + GetCmdPools(groupAll.ID), + GetCmdPool(groupPool.ID), + GetCmdDeposits(groupAll.ID), + GetCmdPoolDeposits(groupPool.ID), + GetCmdPoolDeposit(groupPool.ID), + GetCmdAccountDeposits(groupAccount.ID), + GetCmdAccountPoolDeposits(groupAccount.ID), + GetCmdDraws(groupAll.ID), + GetCmdPoolDraws(groupPool.ID), + GetCmdPoolDraw(groupDraw.ID), + GetCmdPrizes(groupAll.ID), + GetCmdPoolPrizes(groupPool.ID), + GetCmdPoolDrawPrizes(groupDraw.ID), + GetCmdPoolDrawPrize(groupDraw.ID), + GetCmdAccountPrizes(groupAccount.ID), + GetCmdAccountPoolPrizes(groupAccount.ID), + GetCmdAccountPoolDrawPrizes(groupAccount.ID), + GetCmdWithdrawals(groupAll.ID), + GetCmdPoolWithdrawals(groupPool.ID), + GetCmdPoolWithdrawal(groupPool.ID), + GetCmdAccountWithdrawals(groupAccount.ID), + GetCmdAccountPoolWithdrawals(groupAccount.ID), + ) + + return cmd +} + +func GetCmdParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Query the millions parameters", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryParamsRequest{} + res, err := queryClient.Params(context.Background(), params) + + if err != nil { + return err + } + + return clientCtx.PrintProto(&res.Params) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +func GetCmdPools(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pools", + Short: "Query the millions pools", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryPoolsRequest{ + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.Pools(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all pools") + return cmd +} + +func GetCmdPool(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool ", + Short: "Query a millions pool", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the query client + queryClient := types.NewQueryClient(clientCtx) + + // Construct the payload + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + + params := &types.QueryPoolRequest{ + PoolId: poolID, + } + + // Post and acquire the response + res, err := queryClient.Pool(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +func GetCmdDeposits(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "deposits", + Short: "Query the deposits from all the pools", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryDepositsRequest{ + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.Deposits(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all deposits") + return cmd +} + +func GetCmdPoolDeposits(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool-deposits ", + Short: "Query the deposits for a given poolID", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolId, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolDepositsRequest{ + PoolId: poolId, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.PoolDeposits(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all deposits by pool") + return cmd +} + +func GetCmdPoolDeposit(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool-deposit ", + Short: "Query a deposit by ID for a given poolID", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + depositID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolDepositRequest{ + PoolId: poolID, + DepositId: depositID, + } + + // Construct the query + res, err := queryClient.PoolDeposit(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +func GetCmdAccountDeposits(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-deposits
", + Short: "Query deposits for a given account address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryAccountDepositsRequest{ + DepositorAddress: args[0], + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountDeposits(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all deposits by pool") + return cmd +} + +func GetCmdAccountPoolDeposits(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-pool-deposits
", + Short: "Query the pool deposits for a given account address", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryAccountPoolDepositsRequest{ + DepositorAddress: args[0], + PoolId: poolID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountPoolDeposits(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all deposits by address and pool") + return cmd +} + +func GetCmdDraws(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "draws", + Short: "Query the draws from all pools", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryDrawsRequest{ + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.Draws(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all draws") + return cmd +} + +func GetCmdPoolDraws(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool-draws ", + Short: "Query the draws for a given pool", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryPoolDrawsRequest{ + PoolId: poolID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.PoolDraws(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all draws by pool") + return cmd +} + +func GetCmdPoolDraw(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "draw ", + Short: "Query a pool draw by ID", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + + drawID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryPoolDrawRequest{ + PoolId: poolID, + DrawId: drawID, + } + + // Construct the query + res, err := queryClient.PoolDraw(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +func GetCmdPrizes(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "prizes", + Short: "Query all prizes from all draws and all pools", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryPrizesRequest{ + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.Prizes(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all prizes") + return cmd +} + +func GetCmdPoolPrizes(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool-prizes ", + Short: "Query all prizes from all draws for a given pool", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolPrizesRequest{ + PoolId: poolID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.PoolPrizes(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all prizes by pool") + return cmd +} + +func GetCmdPoolDrawPrizes(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "draw-prizes ", + Short: "Query all prizes from a pool draw", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + drawID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolDrawPrizesRequest{ + PoolId: poolID, + DrawId: drawID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.PoolDrawPrizes(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all prizes by draw") + return cmd +} + +func GetCmdPoolDrawPrize(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "draw-prize ", + Short: "Query a prize from a pool draw", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + drawID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + prizeID, err := strconv.ParseUint(args[2], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolDrawPrizeRequest{ + PoolId: poolID, + DrawId: drawID, + PrizeId: prizeID, + } + + // Construct the query + res, err := queryClient.PoolDrawPrize(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +func GetCmdAccountPrizes(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-prizes
", + Short: "Query all prizes for a given account address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryAccountPrizesRequest{ + WinnerAddress: args[0], + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountPrizes(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all prizes for a given address") + return cmd +} + +func GetCmdAccountPoolPrizes(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-pool-prizes
", + Short: "Query the pool prizes for a given account address", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryAccountPoolPrizesRequest{ + WinnerAddress: args[0], + PoolId: poolID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountPoolPrizes(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all pool prizes by address") + return cmd +} + +func GetCmdAccountPoolDrawPrizes(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-pool-draw-prizes
", + Short: "Query the draw prizes for a pool and a given account address", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + drawID, err := strconv.ParseUint(args[2], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryAccountPoolDrawPrizesRequest{ + WinnerAddress: args[0], + PoolId: poolID, + DrawId: drawID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountPoolDrawPrizes(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all pool draw prizes by address") + return cmd +} + +func GetCmdWithdrawals(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "withdrawals", + Short: "Query all withdrawals from all pools", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryWithdrawalsRequest{ + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.Withdrawals(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all withdrawals") + return cmd +} + +func GetCmdPoolWithdrawals(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool-withdrawals ", + Short: "Query all withdrawals for a given pool", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolWithdrawalsRequest{ + PoolId: poolID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.PoolWithdrawals(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all withdrawals by pool") + return cmd +} + +func GetCmdPoolWithdrawal(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "pool-withdrawal ", + Short: "Query withdrawal by ID for a given pool", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + return err + } + withdrawalID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryPoolWithdrawalRequest{ + PoolId: poolID, + WithdrawalId: withdrawalID, + } + + // Construct the query + res, err := queryClient.PoolWithdrawal(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +func GetCmdAccountWithdrawals(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-withdrawals
", + Short: "Query withdrawals for a given account address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + // Construct the params payload + params := &types.QueryAccountWithdrawalsRequest{ + DepositorAddress: args[0], + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountWithdrawals(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all withdrawals by address") + return cmd +} + +func GetCmdAccountPoolWithdrawals(groupID string) *cobra.Command { + cmd := &cobra.Command{ + GroupID: groupID, + Use: "account-pool-withdrawals
", + Short: "Query the pool withdrawals for a given account address", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client instance + clientCtx := client.GetClientContextFromCmd(cmd) + + // Acquire the pagination + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + // Acquire the query client from the context + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := strconv.ParseUint(args[1], 0, 64) + if err != nil { + return err + } + + // Construct the params payload + params := &types.QueryAccountPoolWithdrawalsRequest{ + DepositorAddress: args[0], + PoolId: poolID, + Pagination: pageReq, + } + + // Construct the query + res, err := queryClient.AccountPoolWithdrawals(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all withdrawals by address and pool") + return cmd +} diff --git a/x/millions/client/cli/tx.go b/x/millions/client/cli/tx.go new file mode 100644 index 00000000..599392f2 --- /dev/null +++ b/x/millions/client/cli/tx.go @@ -0,0 +1,374 @@ +package cli + +import ( + "fmt" + "strconv" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + "github.com/lum-network/chain/x/millions/types" +) + +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transaction subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdTxDeposit(), + CmdTxDepositRetry(), + CmdTxClaimPrize(), + CmdTxDrawRetry(), + CmdTxWithdrawDeposit(), + CmdTxWithdrawDepositRetry(), + CmdTxRestoreInterchainAccounts(), + ) + return cmd +} + +func CmdTxDeposit() *cobra.Command { + cmd := &cobra.Command{ + Use: "deposit ", + Short: "Deposit funds into a millions pool", + Long: strings.TrimSpace( + fmt.Sprintf(`Deposit funds into a millions pool. + +Examples: +To create a classic deposit +$ %s tx %s deposit + +To create a delegated deposit (delegate drawing chances to another address) +$ %s tx %s deposit --winner_address=
+ +To create a sponsorship deposit (no drawing chances at all) +$ %s tx %s deposit --sponsor=true`, + version.AppName, types.ModuleName, version.AppName, types.ModuleName, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolId, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + amount, err := sdk.ParseCoinNormalized(args[1]) + if err != nil { + return err + } + + // Acquire optional arguments + winnerAddress, err := cmd.Flags().GetString("winner_address") + if err != nil { + return err + } + isSponsor, err := cmd.Flags().GetBool("sponsor") + if err != nil { + return err + } + + // Build the message + msg := types.NewMsgDeposit(clientCtx.GetFromAddress().String(), amount, poolId) + msg.WinnerAddress = winnerAddress + msg.IsSponsor = isSponsor + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + cmd.Flags().String("winner_address", "", "(optional) winner address to direct the draw prizes to") + cmd.Flags().Bool("sponsor", false, "(optional) active sponsor mode and waive this deposit draw chances") + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} + +func CmdTxDepositRetry() *cobra.Command { + cmd := &cobra.Command{ + Use: "deposit-retry ", + Short: "Retry a failed deposit", + Long: strings.TrimSpace( + fmt.Sprintf(`Retry a deposit stuck in a faulty state (ex: interchain tx issues). + +Example: +$ %s tx %s deposit-retry `, + version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + + depositID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + // Build the message + msg := types.NewMsgDepositRetry(clientCtx.GetFromAddress().String(), poolID, depositID) + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} + +func CmdTxClaimPrize() *cobra.Command { + cmd := &cobra.Command{ + Use: "claim-prize ", + Short: "Claim a millions prize", + Long: strings.TrimSpace( + fmt.Sprintf(`Claim a millions prize to send the funds to the prize winner address. + +Example: +$ %s tx %s claim-prize `, + version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + drawID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + prizeID, err := strconv.ParseUint(args[2], 10, 64) + if err != nil { + return err + } + + // Build the message + msg := types.NewMsgMsgClaimPrize(clientCtx.GetFromAddress().String(), poolID, drawID, prizeID) + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} + +func CmdTxWithdrawDeposit() *cobra.Command { + cmd := &cobra.Command{ + Use: "withdraw-deposit ", + Short: "Withdraw a deposit", + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw a deposit. +Launches the unbonding of the deposit and wait for its completion in order to send the funds to the specified withdrawal address. + +Examples: +To withdraw a deposit to the depositor address +$ %s tx %s withdraw-deposit + +To withdraw a deposit to another address +$ %s tx %s withdraw-deposit --to_address=
`, + version.AppName, types.ModuleName, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + + depositID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + destAddr, err := cmd.Flags().GetString("to_address") + if err != nil { + return err + } + if destAddr == "" { + destAddr = clientCtx.GetFromAddress().String() + } + + // Build the message + msg := types.NewMsgWithdrawDeposit(clientCtx.GetFromAddress().String(), destAddr, poolID, depositID) + msg.ToAddress = destAddr + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + cmd.Flags().String("to_address", "", "(optional) address to send the deposit back") + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} + +func CmdTxWithdrawDepositRetry() *cobra.Command { + cmd := &cobra.Command{ + Use: "withdraw-deposit-retry ", + Short: "Retry a failed withdrawal", + Long: strings.TrimSpace( + fmt.Sprintf(`Retry a withdrawal stuck in a faulty state (ex: interchain tx issues). + +Example: +$ %s tx %s withdraw-deposit-retry `, + version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + withdrawalID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + // Build the message + msg := types.NewMsgWithdrawDepositRetry(clientCtx.GetFromAddress().String(), poolID, withdrawalID) + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} + +func CmdTxDrawRetry() *cobra.Command { + cmd := &cobra.Command{ + Use: "draw-retry ", + Short: "Retry a failed draw", + Long: strings.TrimSpace( + fmt.Sprintf(`Retry a draw stuck in a faulty state (ex: interchain tx issues). +Draws are only launched by the protocol itself but can be retried (if in a faulty state) by anyone. + +Example: +$ %s tx %s draw-retry `, + version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + + drawID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + // Build the message + msg := types.NewMsgDrawRetry(clientCtx.GetFromAddress().String(), poolID, drawID) + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} + +func CmdTxRestoreInterchainAccounts() *cobra.Command { + cmd := &cobra.Command{ + Use: "restore-interchain-accounts ", + Short: "Try to restore the interchain accounts of a given pool after one closed", + Args: cobra.MinimumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Acquire the client context + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + // Acquire the command arguments + poolId, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + + // Build the message + msg := types.NewMsgRestoreInterchainAccounts(clientCtx.GetFromAddress().String(), poolId) + if err := msg.ValidateBasic(); err != nil { + return err + } + + // Generate the transaction + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + _ = cmd.MarkFlagRequired(flags.FlagFrom) + return cmd +} diff --git a/x/millions/client/proposal_handler.go b/x/millions/client/proposal_handler.go new file mode 100644 index 00000000..39c1b52d --- /dev/null +++ b/x/millions/client/proposal_handler.go @@ -0,0 +1,12 @@ +package client + +import ( + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + "github.com/lum-network/chain/x/millions/client/cli" +) + +var ( + RegisterPoolProposalHandler = govclient.NewProposalHandler(cli.CmdProposalRegisterPool) + UpdatePoolProposalHandler = govclient.NewProposalHandler(cli.CmdProposalUpdatePool) + UpdateParamsProposalHandler = govclient.NewProposalHandler(cli.CmdProposalUpdateParams) +) diff --git a/x/millions/client/rest/rest.go b/x/millions/client/rest/rest.go new file mode 100644 index 00000000..a6ad2400 --- /dev/null +++ b/x/millions/client/rest/rest.go @@ -0,0 +1,10 @@ +package rest + +import ( + "github.com/gorilla/mux" + + "github.com/cosmos/cosmos-sdk/client" +) + +func RegisterRoutes(clientCtx client.Context, r *mux.Router) { +} diff --git a/x/millions/docs/relayer_setup.md b/x/millions/docs/relayer_setup.md new file mode 100644 index 00000000..5afc4b3e --- /dev/null +++ b/x/millions/docs/relayer_setup.md @@ -0,0 +1,76 @@ +## Starting the project + +Before doing the following, please make sure you have a running instance of the lum binary, either via ignite or as a daemon + +Run the docker compose in a separate terminal + +`docker-compose -f tools/docker-compose.yml up -d` + +Wait for the containers to be health, then the relayer will start, you can check this by doing: + +`docker ps` + +Once the containers are healthy, the relayer container will pop up. + +## Create the links between chains + +First, enter the lum-relayer container bash + +Grab the lum-relayer container id by doing `docker ps` then do (and replace the id inside): + +`docker exec -it b60875bae07a bash` + +Once inside, you can type the following to create the links (repeat for each chain) + +### Create link for Gaia <=> Lum + +`hermes create connection --a-chain lum-millions-1 --b-chain gaia-devnet` + +`hermes create channel --a-chain lum-millions-1 --a-connection connection-0 --a-port transfer --b-port transfer` + +Transactions may fail but will succeed at some point. + +### Create link Juno <=> Lum + +`hermes create connection --a-chain lumnetwork-testnet --b-chain juno-devnet` + +`hermes create channel --a-chain lumnetwork-testnet --a-connection connection-1 --a-port transfer --b-port transfer` + +### Create link Osmosis <=> Lum + +`hermes create connection --a-chain lumnetwork-testnet --b-chain osmosis-devnet` + +`hermes create channel --a-chain lumnetwork-testnet --a-connection connection-2 --a-port transfer --b-port transfer` + +## Sending coins from Gaia to local Lum one + +Find the ID of the Gaia container: + +`docker ps` then search for "lum-gaia" + +Then enter the container (replace ID inside) + +`docker exec -it 773da473109d bash` + +Then type + +`gaiad tx ibc-transfer transfer transfer channel-0 lum16rlynj5wvzwts5lqep0je5q4m3eaepn58hmzu5 1000000uatom --from genesis_key --keyring-backend test --chain-id gaia-devnet --fees 200uatom` + +If you type + +`lumd query bank balances lum1vvhncsjsdy2d7cnge2773kd49pkvvv9wsrt8ra` + +You should see something like this with the IBC denom from Gaia + +``` +balances: +- amount: "1000000" + denom: ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 +- amount: "100000000000" + denom: uatom +- amount: "119900000000" + denom: ulum +pagination: + next_key: null + total: "0" +``` \ No newline at end of file diff --git a/x/millions/genesis.go b/x/millions/genesis.go new file mode 100644 index 00000000..986ded79 --- /dev/null +++ b/x/millions/genesis.go @@ -0,0 +1,60 @@ +package millions + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/keeper" + "github.com/lum-network/chain/x/millions/types" +) + +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + k.SetParams(ctx, genState.Params) + k.SetNextPoolID(ctx, genState.NextPoolId) + k.SetNextDepositID(ctx, genState.NextDepositId) + k.SetNextPrizeID(ctx, genState.NextPrizeId) + k.SetNextWithdrawalID(ctx, genState.NextWithdrawalId) + + for _, pool := range genState.Pools { + // Voluntary reset TvlAmount, DepositorsCount and SponsorshipAmount since they will be recomputed from deposits + pool.TvlAmount = sdk.ZeroInt() + pool.DepositorsCount = 0 + pool.SponsorshipAmount = sdk.ZeroInt() + k.AddPool(ctx, &pool) + } + + // Import deposits + for _, deposit := range genState.Deposits { + k.AddDeposit(ctx, &deposit) + } + + // Import draws + for _, draw := range genState.Draws { + k.SetPoolDraw(ctx, draw) + } + + // Import prizes + for _, prize := range genState.Prizes { + k.AddPrize(ctx, prize) + } + + // Import withdrawals + for _, withdrawal := range genState.Withdrawals { + k.AddWithdrawal(ctx, withdrawal) + } +} + +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + params := k.GetParams(ctx) + return &types.GenesisState{ + Params: params, + NextPoolId: k.GetNextPoolID(ctx), + NextDepositId: k.GetNextDepositID(ctx), + NextPrizeId: k.GetNextPrizeID(ctx), + NextWithdrawalId: k.GetNextWithdrawalID(ctx), + Pools: k.ListPools(ctx), + Deposits: k.ListDeposits(ctx), + Draws: k.ListDraws(ctx), + Prizes: k.ListPrizes(ctx), + Withdrawals: k.ListWithdrawals(ctx), + } +} diff --git a/x/millions/genesis_test.go b/x/millions/genesis_test.go new file mode 100644 index 00000000..998d3252 --- /dev/null +++ b/x/millions/genesis_test.go @@ -0,0 +1,386 @@ +package millions_test + +import ( + "sort" + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + apptypes "github.com/lum-network/chain/app" + "github.com/lum-network/chain/x/millions" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +var ( + now = time.Now().UTC() + future = now.Add(10 * time.Second) + testAccs = []string{ + "lum19vp4wqsdyw8gftvkat0vrfqzvdrlp9wxp6fevr", + "lum1s3zyjkd79tf83jew2f4cu4zhc9e5y53faqv3te", + "lum1hag45rj53nfpj6357ql7nzq3p678s7lx3gpmyu", + "lum1xutdwytajz6zn338wq7n4wx6m95076nepyu5zl", + "lum10dtsxdl0uj0pw58yvlmsuy8p5mvzvewga5dgl8", + "lum17p728nwzmkg5038pepfzeavxfu063aej0shwc8", + } + defaultValidators = map[string]*millionstypes.PoolValidator{ + "lumvaloper1qx2dts3tglxcu0jh47k7ghstsn4nactufgmmlk": { + OperatorAddress: "lumvaloper1qx2dts3tglxcu0jh47k7ghstsn4nactufgmmlk", + BondedAmount: sdk.ZeroInt(), + }, + } + defaultSchedule = millionstypes.DrawSchedule{DrawDelta: 404 * time.Hour, InitialDrawAt: now} + defaultPrizeStrat = millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 1, DrawProbability: sdk.NewDec(1)}}} +) + +var testGenesis = millionstypes.GenesisState{ + Params: millionstypes.Params{ + MinDepositAmount: sdk.NewInt(1_000_000), + MaxPrizeStrategyBatches: 10, + MaxPrizeBatchQuantity: 1000, + MinDrawScheduleDelta: 1 * time.Hour, + MaxDrawScheduleDelta: 366 * 24 * time.Hour, // 366 days + PrizeExpirationDelta: 30 * 24 * time.Hour, // 30 days + FeesStakers: sdk.NewDec(0), + MinDepositDrawDelta: 5 * time.Minute, + }, + NextPoolId: 6, + NextDepositId: 6, + NextPrizeId: 6, + NextWithdrawalId: 6, + Pools: []millionstypes.Pool{ + {PoolId: 1, TvlAmount: sdk.NewInt(510), DepositorsCount: 3, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-1", NativeDenom: "denom-1", NextDrawId: 3, + ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), AvailablePrizePool: sdk.NewCoin("denom-1", sdk.ZeroInt()), + DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat, + State: millionstypes.PoolState_Created, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper", + }, + {PoolId: 2, TvlAmount: sdk.NewInt(603), DepositorsCount: 2, SponsorshipAmount: sdk.NewInt(401), Denom: "denom-2", NativeDenom: "denom-2", NextDrawId: 2, + ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), AvailablePrizePool: sdk.NewCoin("denom-2", sdk.ZeroInt()), + DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat, + State: millionstypes.PoolState_Ready, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper", + }, + {PoolId: 3, TvlAmount: sdk.NewInt(601), DepositorsCount: 1, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-3", NativeDenom: "denom-3", NextDrawId: 1, + ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), AvailablePrizePool: sdk.NewCoin("denom-3", sdk.ZeroInt()), + DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat, + State: millionstypes.PoolState_Killed, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper", + }, + {PoolId: 4, TvlAmount: sdk.NewInt(400), DepositorsCount: 1, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-4", NativeDenom: "denom-4", NextDrawId: 1, + ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), AvailablePrizePool: sdk.NewCoin("denom-4", sdk.ZeroInt()), + DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat, + State: millionstypes.PoolState_Created, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper", + }, + {PoolId: 5, TvlAmount: sdk.NewInt(0), DepositorsCount: 0, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-5", NativeDenom: "denom-5", NextDrawId: 1, + ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), AvailablePrizePool: sdk.NewCoin("denom-5", sdk.ZeroInt()), + DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat, + State: millionstypes.PoolState_Killed, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper", + }, + }, + Deposits: []millionstypes.Deposit{ + {PoolId: 1, DepositId: 1, DepositorAddress: testAccs[0], WinnerAddress: testAccs[0], Amount: sdk.NewCoin("denom-1", sdk.NewInt(100)), State: millionstypes.DepositState_IbcTransfer}, + {PoolId: 1, DepositId: 2, DepositorAddress: testAccs[0], WinnerAddress: testAccs[0], Amount: sdk.NewCoin("denom-1", sdk.NewInt(101)), State: millionstypes.DepositState_IcaDelegate}, + {PoolId: 1, DepositId: 3, DepositorAddress: testAccs[1], WinnerAddress: testAccs[1], Amount: sdk.NewCoin("denom-1", sdk.NewInt(102)), State: millionstypes.DepositState_Success}, + {PoolId: 1, DepositId: 4, DepositorAddress: testAccs[1], WinnerAddress: testAccs[1], Amount: sdk.NewCoin("denom-1", sdk.NewInt(103)), State: millionstypes.DepositState_Failure}, + {PoolId: 1, DepositId: 5, DepositorAddress: testAccs[2], WinnerAddress: testAccs[2], Amount: sdk.NewCoin("denom-1", sdk.NewInt(104)), State: millionstypes.DepositState_IbcTransfer}, + {PoolId: 2, DepositId: 6, DepositorAddress: testAccs[2], WinnerAddress: testAccs[2], Amount: sdk.NewCoin("denom-2", sdk.NewInt(200)), IsSponsor: true, State: millionstypes.DepositState_IbcTransfer}, + {PoolId: 2, DepositId: 7, DepositorAddress: testAccs[3], WinnerAddress: testAccs[3], Amount: sdk.NewCoin("denom-2", sdk.NewInt(201)), IsSponsor: true, State: millionstypes.DepositState_IbcTransfer}, + {PoolId: 2, DepositId: 8, DepositorAddress: testAccs[3], WinnerAddress: testAccs[3], Amount: sdk.NewCoin("denom-2", sdk.NewInt(202)), State: millionstypes.DepositState_IbcTransfer}, + {PoolId: 3, DepositId: 9, DepositorAddress: testAccs[4], WinnerAddress: testAccs[4], Amount: sdk.NewCoin("denom-3", sdk.NewInt(300)), State: millionstypes.DepositState_Success}, + {PoolId: 3, DepositId: 10, DepositorAddress: testAccs[4], WinnerAddress: testAccs[4], Amount: sdk.NewCoin("denom-3", sdk.NewInt(301)), State: millionstypes.DepositState_Success}, + {PoolId: 4, DepositId: 11, DepositorAddress: testAccs[5], WinnerAddress: testAccs[5], Amount: sdk.NewCoin("denom-4", sdk.NewInt(400)), State: millionstypes.DepositState_Success}, + }, + Draws: []millionstypes.Draw{ + {PoolId: 1, DrawId: 1, RandSeed: 10, TotalWinCount: 100, TotalWinAmount: sdk.NewInt(1000)}, + {PoolId: 1, DrawId: 2, RandSeed: 20, TotalWinCount: 200, TotalWinAmount: sdk.NewInt(2000)}, + {PoolId: 2, DrawId: 1, RandSeed: 30, TotalWinCount: 300, TotalWinAmount: sdk.NewInt(3000)}, + }, + Prizes: []millionstypes.Prize{ + {PoolId: 1, DrawId: 1, PrizeId: 1, State: millionstypes.PrizeState_Pending, WinnerAddress: testAccs[0], Amount: sdk.NewCoin("denom-1", sdk.NewInt(1)), ExpiresAt: future}, + {PoolId: 1, DrawId: 2, PrizeId: 2, State: millionstypes.PrizeState_Pending, WinnerAddress: testAccs[1], Amount: sdk.NewCoin("denom-1", sdk.NewInt(1)), ExpiresAt: now}, + {PoolId: 2, DrawId: 1, PrizeId: 3, State: millionstypes.PrizeState_Pending, WinnerAddress: testAccs[2], Amount: sdk.NewCoin("denom-2", sdk.NewInt(1)), ExpiresAt: now}, + }, + Withdrawals: []millionstypes.Withdrawal{ + {PoolId: 1, DepositId: 3, WithdrawalId: 1, DepositorAddress: testAccs[1], ToAddress: testAccs[1], Amount: sdk.NewCoin("denom-1", sdk.NewInt(102)), State: millionstypes.WithdrawalState_IcaUnbonding, UnbondingEndsAt: &now}, + {PoolId: 3, DepositId: 9, WithdrawalId: 2, DepositorAddress: testAccs[4], ToAddress: testAccs[4], Amount: sdk.NewCoin("denom-3", sdk.NewInt(300)), State: millionstypes.WithdrawalState_IcaUnbonding, UnbondingEndsAt: &future}, + {PoolId: 3, DepositId: 10, WithdrawalId: 3, DepositorAddress: testAccs[4], ToAddress: testAccs[4], Amount: sdk.NewCoin("denom-3", sdk.NewInt(301)), State: millionstypes.WithdrawalState_IcaUnbonding, UnbondingEndsAt: &future}, + {PoolId: 4, DepositId: 11, WithdrawalId: 4, DepositorAddress: testAccs[5], ToAddress: testAccs[5], Amount: sdk.NewCoin("denom-4", sdk.NewInt(400)), State: millionstypes.WithdrawalState_IcaUnbonding, UnbondingEndsAt: &now}, + }, +} + +func TestInitGenesis(t *testing.T) { + app := apptypes.SetupForTesting(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx = ctx.WithBlockTime(now.Add(time.Second)) + + // Init the module genesis state + millions.InitGenesis(ctx, *app.MillionsKeeper, testGenesis) + + // Make sure params match + params := app.MillionsKeeper.GetParams(ctx) + require.Equal(t, testGenesis.Params, params) + require.Equal(t, testGenesis.Params.MinDepositAmount, params.MinDepositAmount) + require.Equal(t, testGenesis.Params.MaxPrizeStrategyBatches, params.MaxPrizeStrategyBatches) + require.Equal(t, testGenesis.Params.MaxPrizeBatchQuantity, params.MaxPrizeBatchQuantity) + require.Equal(t, testGenesis.Params.MinDrawScheduleDelta, params.MinDrawScheduleDelta) + require.Equal(t, testGenesis.Params.MaxDrawScheduleDelta, params.MaxDrawScheduleDelta) + require.Equal(t, testGenesis.Params.PrizeExpirationDelta, params.PrizeExpirationDelta) + require.Equal(t, testGenesis.Params.FeesStakers, params.FeesStakers) + require.Equal(t, testGenesis.Params.MinDepositDrawDelta, params.MinDepositDrawDelta) + + // Make sure genesis next poolID matches + nextPoolID := app.MillionsKeeper.GetNextPoolID(ctx) + require.Equal(t, testGenesis.NextPoolId, nextPoolID) + + // Make sure genesis next depositID matches + nextDepositID := app.MillionsKeeper.GetNextDepositID(ctx) + require.Equal(t, testGenesis.NextDepositId, nextDepositID) + + // Make sure genesis next prizeID matches + nextPrizeID := app.MillionsKeeper.GetNextPrizeID(ctx) + require.Equal(t, testGenesis.NextPrizeId, nextPrizeID) + + // Make sure genesis next withdrawalID matches + nextWithdrawalID := app.MillionsKeeper.GetNextWithdrawalID(ctx) + require.Equal(t, testGenesis.NextWithdrawalId, nextWithdrawalID) + + // Pools should all have been imported + pools := app.MillionsKeeper.ListPools(ctx) + require.Len(t, pools, len(testGenesis.Pools)) + for i, p := range pools { + require.Equal(t, testGenesis.Pools[i].PoolId, p.PoolId) + require.Equal(t, testGenesis.Pools[i].TvlAmount.Int64(), p.TvlAmount.Int64()) + require.Equal(t, testGenesis.Pools[i].DepositorsCount, p.DepositorsCount) + require.Equal(t, testGenesis.Pools[i].SponsorshipAmount.Int64(), p.SponsorshipAmount.Int64()) + require.Equal(t, testGenesis.Pools[i].Denom, p.Denom) + require.Equal(t, testGenesis.Pools[i].NextDrawId, p.NextDrawId) + // Pool deposits should all have been imported + deposits := app.MillionsKeeper.ListPoolDeposits(ctx, p.PoolId) + if p.PoolId == 1 { + require.Len(t, deposits, 5) + } else if p.PoolId == 2 { + require.Len(t, deposits, 3) + } else if p.PoolId == 3 { + require.Len(t, deposits, 2) + } else if p.PoolId == 4 { + require.Len(t, deposits, 1) + } else if p.PoolId == 5 { + require.Len(t, deposits, 0) + } + } + + // Deposits should all have been imported + deposits := app.MillionsKeeper.ListDeposits(ctx) + require.Len(t, deposits, len(testGenesis.Deposits)) + sort.Slice(deposits, func(i, j int) bool { + return deposits[i].DepositId < deposits[j].DepositId + }) + for i, d := range deposits { + require.Equal(t, testGenesis.Deposits[i].PoolId, d.PoolId) + require.Equal(t, testGenesis.Deposits[i].DepositId, d.DepositId) + require.Equal(t, testGenesis.Deposits[i].DepositorAddress, d.DepositorAddress) + require.Equal(t, testGenesis.Deposits[i].WinnerAddress, d.WinnerAddress) + require.Equal(t, testGenesis.Deposits[i].Amount, d.Amount) + require.Equal(t, testGenesis.Deposits[i].IsSponsor, d.IsSponsor) + require.Equal(t, testGenesis.Deposits[i].State, d.State) + } + + // Account deposits should all have been imported + for i := 0; i < len(testAccs); i++ { + addr := sdk.MustAccAddressFromBech32(testAccs[i]) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, addr) + if i == len(testAccs)-1 { + require.Len(t, deposits, 1) + } else { + require.Len(t, deposits, 2) + } + } + + // Draws should have been imported + draws := app.MillionsKeeper.ListDraws(ctx) + require.Len(t, draws, len(testGenesis.Draws)) + for i, d := range draws { + require.Equal(t, testGenesis.Draws[i].PoolId, d.PoolId) + require.Equal(t, testGenesis.Draws[i].DrawId, d.DrawId) + require.Equal(t, int64(10*(i+1)), d.RandSeed) + require.Equal(t, uint64(100*(i+1)), d.TotalWinCount) + require.Equal(t, sdk.NewInt(1000*int64(i+1)), d.TotalWinAmount) + } + + // ListPoolDraws should have been imported + for _, pd := range testGenesis.Draws { + poolDraws := app.MillionsKeeper.ListPoolDraws(ctx, pd.PoolId) + if pd.PoolId == 1 { + require.Len(t, poolDraws, 2) + } else { + require.Len(t, poolDraws, 1) + } + } + + // Prizes should have been imported + prizes := app.MillionsKeeper.ListPrizes(ctx) + + require.Len(t, prizes, len(testGenesis.Prizes)) + for i, pz := range prizes { + require.Equal(t, testGenesis.Prizes[i].PoolId, pz.PoolId) + require.Equal(t, testGenesis.Prizes[i].DrawId, pz.DrawId) + require.Equal(t, testGenesis.Prizes[i].PrizeId, pz.PrizeId) + require.Equal(t, testGenesis.Prizes[i].State, pz.State) + require.Equal(t, testGenesis.Prizes[i].WinnerAddress, pz.WinnerAddress) + require.Equal(t, testGenesis.Prizes[i].Amount, pz.Amount) + } + + // ListAccountPrizes should have been imported + for _, ap := range testGenesis.Prizes { + addr := sdk.MustAccAddressFromBech32(ap.WinnerAddress) + accPrizes := app.MillionsKeeper.ListAccountPrizes(ctx, addr) + require.Len(t, accPrizes, 1) + } + + // Test Expired Prizes Queue Import + for i := 0; i < len(testGenesis.Withdrawals); i++ { + col := app.MillionsKeeper.GetPrizeIDsEPCBQueue(ctx, now) + require.Len(t, col.PrizesIds, 2) + for i, pid := range col.PrizesIds { + require.Equal(t, col.PrizesIds[i].PoolId, pid.PoolId) + require.Equal(t, col.PrizesIds[i].PrizeId, pid.PrizeId) + } + } + + // Withdrawals + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + require.Len(t, withdrawals, len(testGenesis.Withdrawals)) + for i, w := range withdrawals { + require.Equal(t, testGenesis.Withdrawals[i].PoolId, w.PoolId) + require.Equal(t, testGenesis.Withdrawals[i].DepositId, w.DepositId) + require.Equal(t, testGenesis.Withdrawals[i].WithdrawalId, w.WithdrawalId) + require.Equal(t, testGenesis.Withdrawals[i].WithdrawalId, w.WithdrawalId) + require.Equal(t, testGenesis.Withdrawals[i].DepositorAddress, w.DepositorAddress) + require.Equal(t, testGenesis.Withdrawals[i].ToAddress, w.ToAddress) + require.Equal(t, testGenesis.Withdrawals[i].Amount, w.Amount) + require.Equal(t, testGenesis.Withdrawals[i].State, w.State) + } + + // Account withdrawals should have been imported + for _, aw := range testGenesis.Withdrawals { + addr := sdk.MustAccAddressFromBech32(aw.DepositorAddress) + accWithdrawals := app.MillionsKeeper.ListAccountWithdrawals(ctx, addr) + if aw.PoolId == 1 { + require.Len(t, accWithdrawals, 1) + } else if aw.PoolId == 3 { + require.Len(t, accWithdrawals, 2) + } else { + require.Len(t, accWithdrawals, 1) + } + } + + // Test Matured Withdrawal Queue Import + for i := 0; i < len(testGenesis.Withdrawals); i++ { + col := app.MillionsKeeper.GetWithdrawalIDsMaturedQueue(ctx, now) + require.Len(t, col.WithdrawalsIds, 2) + for i, wid := range col.WithdrawalsIds { + require.Equal(t, col.WithdrawalsIds[i].PoolId, wid.PoolId) + require.Equal(t, col.WithdrawalsIds[i].WithdrawalId, wid.WithdrawalId) + } + } +} + +func TestExportGenesis(t *testing.T) { + app := apptypes.SetupForTesting(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx = ctx.WithBlockTime(now.Add(time.Second)) + + millions.InitGenesis(ctx, *app.MillionsKeeper, testGenesis) + exportGenesis := millions.ExportGenesis(ctx, *app.MillionsKeeper) + + // Test params export + require.Equal(t, exportGenesis.Params, testGenesis.Params) + require.Equal(t, exportGenesis.Params.MinDepositAmount, testGenesis.Params.MinDepositAmount) + require.Equal(t, exportGenesis.Params.MaxPrizeStrategyBatches, testGenesis.Params.MaxPrizeStrategyBatches) + require.Equal(t, exportGenesis.Params.MaxPrizeBatchQuantity, testGenesis.Params.MaxPrizeBatchQuantity) + require.Equal(t, exportGenesis.Params.MinDrawScheduleDelta, testGenesis.Params.MinDrawScheduleDelta) + require.Equal(t, exportGenesis.Params.MaxDrawScheduleDelta, testGenesis.Params.MaxDrawScheduleDelta) + require.Equal(t, exportGenesis.Params.PrizeExpirationDelta, testGenesis.Params.PrizeExpirationDelta) + require.Equal(t, exportGenesis.Params.FeesStakers, testGenesis.Params.FeesStakers) + require.Equal(t, exportGenesis.Params.MinDepositDrawDelta, testGenesis.Params.MinDepositDrawDelta) + + // Test IDs export + require.Equal(t, exportGenesis.NextPoolId, testGenesis.NextPoolId) + require.Equal(t, exportGenesis.NextDepositId, testGenesis.NextDepositId) + require.Equal(t, exportGenesis.NextPrizeId, testGenesis.NextPrizeId) + require.Equal(t, exportGenesis.NextWithdrawalId, testGenesis.NextWithdrawalId) + + // Test Pools export + require.Len(t, exportGenesis.Pools, len(testGenesis.Pools)) + for i, p := range testGenesis.Pools { + require.Equal(t, exportGenesis.Pools[i].PoolId, p.PoolId) + require.Equal(t, exportGenesis.Pools[i].TvlAmount.Int64(), p.TvlAmount.Int64()) + require.Equal(t, exportGenesis.Pools[i].DepositorsCount, p.DepositorsCount) + require.Equal(t, exportGenesis.Pools[i].SponsorshipAmount.Int64(), p.SponsorshipAmount.Int64()) + require.Equal(t, exportGenesis.Pools[i].Denom, p.Denom) + require.Equal(t, exportGenesis.Pools[i].NextDrawId, p.NextDrawId) + // Pool deposits should all have been exported + deposits := app.MillionsKeeper.ListPoolDeposits(ctx, p.PoolId) + if p.PoolId == 1 { + require.Len(t, deposits, 5) + } else if p.PoolId == 2 { + require.Len(t, deposits, 3) + } else if p.PoolId == 3 { + require.Len(t, deposits, 2) + } else if p.PoolId == 4 { + require.Len(t, deposits, 1) + } else if p.PoolId == 5 { + require.Len(t, deposits, 0) + } + } + + // Test deposits export + require.Len(t, exportGenesis.Deposits, len(testGenesis.Deposits)) + sort.Slice(exportGenesis.Deposits, func(i, j int) bool { + return exportGenesis.Deposits[i].DepositId < exportGenesis.Deposits[j].DepositId + }) + for i, d := range testGenesis.Deposits { + require.Equal(t, exportGenesis.Deposits[i].PoolId, d.PoolId) + require.Equal(t, exportGenesis.Deposits[i].DepositId, d.DepositId) + require.Equal(t, exportGenesis.Deposits[i].DepositorAddress, d.DepositorAddress) + require.Equal(t, exportGenesis.Deposits[i].WinnerAddress, d.WinnerAddress) + require.Equal(t, exportGenesis.Deposits[i].Amount, d.Amount) + require.Equal(t, exportGenesis.Deposits[i].IsSponsor, d.IsSponsor) + require.Equal(t, exportGenesis.Deposits[i].State, d.State) + } + + // Test draws export + require.Len(t, exportGenesis.Draws, len(testGenesis.Draws)) + for i, dw := range testGenesis.Draws { + require.Equal(t, exportGenesis.Draws[i].PoolId, dw.PoolId) + require.Equal(t, exportGenesis.Draws[i].DrawId, dw.DrawId) + require.Equal(t, int64(10*(i+1)), dw.RandSeed) + require.Equal(t, uint64(100*(i+1)), dw.TotalWinCount) + require.Equal(t, sdk.NewInt(1000*int64(i+1)), dw.TotalWinAmount) + } + + // Test prizes export + require.Len(t, exportGenesis.Prizes, len(testGenesis.Prizes)) + for i, pz := range testGenesis.Prizes { + require.Equal(t, exportGenesis.Prizes[i].PoolId, pz.PoolId) + require.Equal(t, exportGenesis.Prizes[i].DrawId, pz.DrawId) + require.Equal(t, exportGenesis.Prizes[i].PrizeId, pz.PrizeId) + require.Equal(t, exportGenesis.Prizes[i].State, pz.State) + require.Equal(t, exportGenesis.Prizes[i].WinnerAddress, pz.WinnerAddress) + require.Equal(t, exportGenesis.Prizes[i].Amount, pz.Amount) + } + + // Test withdrawals export + require.Len(t, exportGenesis.Withdrawals, len(testGenesis.Withdrawals)) + for i, w := range testGenesis.Withdrawals { + require.Equal(t, exportGenesis.Withdrawals[i].PoolId, w.PoolId) + require.Equal(t, exportGenesis.Withdrawals[i].DepositId, w.DepositId) + require.Equal(t, exportGenesis.Withdrawals[i].WithdrawalId, w.WithdrawalId) + require.Equal(t, exportGenesis.Withdrawals[i].WithdrawalId, w.WithdrawalId) + require.Equal(t, exportGenesis.Withdrawals[i].DepositorAddress, w.DepositorAddress) + require.Equal(t, exportGenesis.Withdrawals[i].ToAddress, w.ToAddress) + require.Equal(t, exportGenesis.Withdrawals[i].Amount, w.Amount) + require.Equal(t, exportGenesis.Withdrawals[i].State, w.State) + } +} diff --git a/x/millions/handler.go b/x/millions/handler.go new file mode 100644 index 00000000..6f7e9e47 --- /dev/null +++ b/x/millions/handler.go @@ -0,0 +1,48 @@ +package millions + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/lum-network/chain/x/millions/keeper" + "github.com/lum-network/chain/x/millions/types" +) + +func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(k) + + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + goCtx := sdk.WrapSDKContext(ctx) + + switch msg := msg.(type) { + case *types.MsgDeposit: + res, err := msgServer.Deposit(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgDepositRetry: + res, err := msgServer.DepositRetry(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgClaimPrize: + res, err := msgServer.ClaimPrize(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgDrawRetry: + res, err := msgServer.DrawRetry(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgWithdrawDeposit: + res, err := msgServer.WithdrawDeposit(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgWithdrawDepositRetry: + res, err := msgServer.WithdrawDepositRetry(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgRestoreInterchainAccounts: + res, err := msgServer.RestoreInterchainAccounts(goCtx, msg) + return sdk.WrapServiceResult(ctx, res, err) + default: + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } + } +} diff --git a/x/millions/handler_proposal.go b/x/millions/handler_proposal.go new file mode 100644 index 00000000..0a7a121d --- /dev/null +++ b/x/millions/handler_proposal.go @@ -0,0 +1,75 @@ +package millions + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/lum-network/chain/x/millions/keeper" + "github.com/lum-network/chain/x/millions/types" +) + +func NewMillionsProposalHandler(k keeper.Keeper) govtypes.Handler { + return func(ctx sdk.Context, content govtypes.Content) error { + switch c := content.(type) { + case *types.ProposalUpdatePool: + { + return k.UpdatePool(ctx, c.PoolId, c.Validators, c.MinDepositAmount, c.DrawSchedule, c.PrizeStrategy) + } + case *types.ProposalRegisterPool: + { + _, err := k.RegisterPool( + ctx, + c.GetDenom(), + c.GetNativeDenom(), + c.GetChainId(), + c.GetConnectionId(), + c.GetTransferChannelId(), + c.GetValidators(), + c.GetBech32PrefixAccAddr(), + c.GetBech32PrefixValAddr(), + c.MinDepositAmount, + c.GetDrawSchedule(), + c.GetPrizeStrategy(), + ) + return err + } + case *types.ProposalUpdateParams: + { + params := k.GetParams(ctx) + if c.MinDepositAmount != nil { + params.MinDepositAmount = *c.MinDepositAmount + } + if c.MaxPrizeStrategyBatches != nil { + params.MaxPrizeStrategyBatches = c.MaxPrizeStrategyBatches.Uint64() + } + if c.MaxPrizeBatchQuantity != nil { + params.MaxPrizeBatchQuantity = c.MaxPrizeBatchQuantity.Uint64() + } + if c.MinDrawScheduleDelta != nil { + params.MinDrawScheduleDelta = *c.MinDrawScheduleDelta + } + if c.MaxDrawScheduleDelta != nil { + params.MaxDrawScheduleDelta = *c.MaxDrawScheduleDelta + } + if c.PrizeExpirationDelta != nil { + params.PrizeExpirationDelta = *c.PrizeExpirationDelta + } + if c.FeesStakers != nil { + params.FeesStakers = *c.FeesStakers + } + if c.MinDepositDrawDelta != nil { + params.MinDepositDrawDelta = *c.MinDepositDrawDelta + } + if err := params.ValidateBasics(); err != nil { + // Prevent panic in case of invalid params + return err + } + k.SetParams(ctx, params) + return nil + } + default: + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized millions proposal content type: %T", c) + } + } +} diff --git a/x/millions/handler_proposal_test.go b/x/millions/handler_proposal_test.go new file mode 100644 index 00000000..f981aa31 --- /dev/null +++ b/x/millions/handler_proposal_test.go @@ -0,0 +1,372 @@ +package millions_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/suite" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/lum-network/chain/app" + apptesting "github.com/lum-network/chain/app/testing" + "github.com/lum-network/chain/x/millions" + millionstypes "github.com/lum-network/chain/x/millions/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +type HandlerTestSuite struct { + suite.Suite + + app *app.App + ctx sdk.Context + addrs []sdk.AccAddress + pool millionstypes.Pool + + handler govtypesv1beta1.Handler +} + +func (suite *HandlerTestSuite) SetupTest() { + app := app.SetupForTesting(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{ChainID: "lum-network-devnet"}) + + suite.app = app + suite.ctx = ctx + suite.handler = millions.NewMillionsProposalHandler(*app.MillionsKeeper) + suite.addrs = apptesting.AddTestAddrsWithDenom(app, ctx, 2, sdk.NewInt(300000000), "ulum") + + // Initialize dummy pool + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, &millionstypes.Pool{ + Denom: "ulum", + NativeDenom: "ulum", + ChainId: "lum-network-devnet", + Bech32PrefixValAddr: "lumvaloper", + Bech32PrefixAccAddr: "lum", + Validators: map[string]*millionstypes.PoolValidator{ + "lumvaloper16rlynj5wvzwts5lqep0je5q4m3eaepn5cqj38s": {IsEnabled: true, BondedAmount: sdk.NewInt(10), OperatorAddress: "lumvaloper16rlynj5wvzwts5lqep0je5q4m3eaepn5cqj38s"}, + }, + MinDepositAmount: sdk.NewInt(1000000), + State: millionstypes.PoolState_Ready, + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: sdk.NewDecWithPrec(int64(0.00*1_000_000), 6)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + }) + suite.pool, _ = app.MillionsKeeper.GetPool(suite.ctx, poolID) +} + +func (suite *HandlerTestSuite) TestProposal_RegisterPool() { + validPrizeStrategy := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 90, DrawProbability: sdk.NewDec(1), Quantity: 10}, + {PoolPercent: 10, DrawProbability: sdk.NewDec(1), Quantity: 10}, + }, + } + + invalidPrizeStrategy := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 90, DrawProbability: sdk.NewDec(1), Quantity: 10}, + }, + } + + emptyPrizeStrategy := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{}, + } + + validDrawSchedule := millionstypes.DrawSchedule{ + DrawDelta: 1 * time.Hour, + InitialDrawAt: time.Now().Add(1 * time.Hour), + } + + invalidDrawSchedule := millionstypes.DrawSchedule{ + DrawDelta: millionstypes.MinAcceptableDrawDelta - 1, + InitialDrawAt: time.Time{}, + } + + validValidatorSet := []string{"lumvaloper16rlynj5wvzwts5lqep0je5q4m3eaepn5cqj38s"} + invalidValidatorSet := []string{"lumvaloper16rlynj5wvzw"} + var emptyValidatorSet []string + + cases := []struct { + name string + proposal govtypesv1beta1.Content + expectPreError bool + expectPostError bool + }{ + { + "Title cannot be empty", + millionstypes.NewRegisterPoolProposal("", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + true, + false, + }, + { + "Description cannot be empty", + millionstypes.NewRegisterPoolProposal("Test", "", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + true, + false, + }, + { + "Chain ID cannot be empty", + millionstypes.NewRegisterPoolProposal("Test", "Test", "", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + true, + true, + }, + { + "Bech 32 acc prefix cannot be empty", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + true, + true, + }, + { + "Bech 32 val prefix cannot be empty", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + true, + true, + }, + { + "Validators list cannot be empty", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", emptyValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + true, + true, + }, + { + "Validators list cannot be invalid", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", invalidValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + false, + true, + }, + { + "Min deposit amount cannot be less than min acceptable amount", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(millionstypes.MinAcceptableDepositAmount-1), validPrizeStrategy, validDrawSchedule), + true, + true, + }, + { + "Prize strategy cannot be empty", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), emptyPrizeStrategy, validDrawSchedule), + true, + true, + }, + { + "Prize strategy cannot be invalid", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), invalidPrizeStrategy, validDrawSchedule), + false, + true, + }, + { + "Draw Schedule cannot be invalid", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, invalidDrawSchedule), + true, + true, + }, + { + "Fine should be fine", + millionstypes.NewRegisterPoolProposal("Test", "Test", "lum-network-devnet", "ulum", "ulum", "connection-0", "lum", "lumvaloper", validValidatorSet, sdk.NewInt(1000000), validPrizeStrategy, validDrawSchedule), + false, + false, + }, + } + + for _, tc := range cases { + tc := tc + suite.Run(tc.name, func() { + preError := tc.proposal.ValidateBasic() + if tc.expectPreError { + suite.Require().Error(preError) + } else { + suite.Require().NoError(preError) + } + err := suite.handler(suite.ctx, tc.proposal) + if tc.expectPostError { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func (suite *HandlerTestSuite) TestProposal_UpdatePool() { + validPrizeStrategy := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 90, DrawProbability: sdk.NewDec(1), Quantity: 10}, + {PoolPercent: 10, DrawProbability: sdk.NewDec(1), Quantity: 10}, + }, + } + + invalidPrizeStrategy := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 90, DrawProbability: sdk.NewDec(1), Quantity: 10}, + }, + } + + emptyPrizeStrategy := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{}, + } + + validDrawSchedule := millionstypes.DrawSchedule{ + DrawDelta: 1 * time.Hour, + InitialDrawAt: time.Now().Add(1 * time.Hour), + } + + invalidDrawSchedule := millionstypes.DrawSchedule{ + DrawDelta: 0, + InitialDrawAt: time.Time{}, + } + + validValidatorSet := []string{"lumvaloper16rlynj5wvzwts5lqep0je5q4m3eaepn5cqj38s"} + invalidValidatorSet := []string{"lumvaloper16rlynj5wvzw"} + + validMinDepositAmount := millionstypes.DefaultParams().MinDepositAmount + invalidMinDepositAmount := sdk.NewInt(millionstypes.MinAcceptableDepositAmount - 1) + + cases := []struct { + name string + proposal govtypesv1beta1.Content + expectPreError bool + expectPostError bool + }{ + { + "Title cannot be empty", + millionstypes.NewUpdatePoolProposal("", "Test", suite.pool.GetPoolId(), validValidatorSet, &validMinDepositAmount, &validPrizeStrategy, &validDrawSchedule), + true, + false, + }, + { + "Description cannot be empty", + millionstypes.NewUpdatePoolProposal("Test", "", suite.pool.GetPoolId(), validValidatorSet, &validMinDepositAmount, &validPrizeStrategy, &validDrawSchedule), + true, + false, + }, + { + "Validators list can be empty", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), nil, &validMinDepositAmount, &validPrizeStrategy, &validDrawSchedule), + false, + false, + }, + { + "Validators list cannot be invalid", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), invalidValidatorSet, &validMinDepositAmount, &validPrizeStrategy, &validDrawSchedule), + false, + true, + }, + { + "Min deposit amount cannot be less than 1000000 (default params)", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), validValidatorSet, &invalidMinDepositAmount, &validPrizeStrategy, &validDrawSchedule), + true, + true, + }, + { + "Prize strategy cannot be empty", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), validValidatorSet, &validMinDepositAmount, &emptyPrizeStrategy, &validDrawSchedule), + true, + true, + }, + { + "Prize strategy cannot be invalid", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), validValidatorSet, &validMinDepositAmount, &invalidPrizeStrategy, &validDrawSchedule), + false, + true, + }, + { + "Draw Schedule cannot be invalid", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), validValidatorSet, &validMinDepositAmount, &validPrizeStrategy, &invalidDrawSchedule), + true, + true, + }, + { + "Fine should be fine", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), validValidatorSet, &validMinDepositAmount, &validPrizeStrategy, &validDrawSchedule), + false, + false, + }, + { + "Partial should be fine", + millionstypes.NewUpdatePoolProposal("Test", "Test", suite.pool.GetPoolId(), validValidatorSet, nil, nil, nil), + false, + false, + }, + } + + for _, tc := range cases { + tc := tc + suite.Run(tc.name, func() { + preError := tc.proposal.ValidateBasic() + if tc.expectPreError { + suite.Require().Error(preError) + } else { + suite.Require().NoError(preError) + } + err := suite.handler(suite.ctx, tc.proposal) + if tc.expectPostError { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func (suite *HandlerTestSuite) TestProposal_UpdateParams() { + validMinDepositAmount := sdk.NewInt(millionstypes.MinAcceptableDepositAmount) + validFees := sdk.NewDecWithPrec(int64(0.5*1_000_000), 6) + + prizeDelta := 5 * time.Hour + depositDelta := 2 * time.Hour + minDrawDelta := 1 * time.Hour + maxDrawDelta := 10 * time.Hour + maxBatchQuantity := sdk.NewInt(100) + maxStrategyBatches := sdk.NewInt(50) + + cases := []struct { + name string + proposal govtypesv1beta1.Content + expectPreError bool + expectPostError bool + }{ + { + "Full update should be fine", + millionstypes.NewUpdateParamsProposal("Test", "Test", &validMinDepositAmount, &validFees, &prizeDelta, &depositDelta, &minDrawDelta, &maxDrawDelta, &maxBatchQuantity, &maxStrategyBatches), + false, + false, + }, + { + "Partial update should be fine", + millionstypes.NewUpdateParamsProposal("Test", "Test", nil, nil, nil, nil, nil, nil, nil, nil), + false, + false, + }, + } + + for _, tc := range cases { + tc := tc + suite.Run(tc.name, func() { + preError := tc.proposal.ValidateBasic() + if tc.expectPreError { + suite.Require().Error(preError) + } else { + suite.Require().NoError(preError) + } + err := suite.handler(suite.ctx, tc.proposal) + if tc.expectPostError { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func TestHandlerSuite(t *testing.T) { + suite.Run(t, new(HandlerTestSuite)) +} diff --git a/x/millions/keeper/callbacks.go b/x/millions/keeper/callbacks.go new file mode 100644 index 00000000..16a129d2 --- /dev/null +++ b/x/millions/keeper/callbacks.go @@ -0,0 +1,57 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" +) + +const ( + ICACallbackID_Delegate = "delegate" + ICACallbackID_Claim = "claim" + ICACallbackID_Undelegate = "undelegate" + ICACallbackID_Redelegate = "redelegate" + ICACallbackID_TransferToNative = "transfer_to_native" + ICACallbackID_TransferFromNative = "transfer_from_native" + ICACallbackID_SetWithdrawAddress = "set_withdraw_address" +) + +// ICACallback wrapper struct for millions keeper +type ICACallback func(Keeper, sdk.Context, channeltypes.Packet, *icacallbackstypes.AcknowledgementResponse, []byte) error + +type ICACallbacks struct { + k Keeper + callbacks map[string]ICACallback +} + +var _ icacallbackstypes.ICACallbackHandler = ICACallbacks{} + +func (k Keeper) ICACallbackHandler() ICACallbacks { + return ICACallbacks{k, make(map[string]ICACallback)} +} + +func (c ICACallbacks) CallICACallback(ctx sdk.Context, id string, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + return c.callbacks[id](c.k, ctx, packet, ackResponse, args) +} + +func (c ICACallbacks) HasICACallback(id string) bool { + _, found := c.callbacks[id] + return found +} + +func (c ICACallbacks) AddICACallback(id string, fn interface{}) icacallbackstypes.ICACallbackHandler { + c.callbacks[id] = fn.(ICACallback) + return c +} + +func (c ICACallbacks) RegisterICACallbacks() icacallbackstypes.ICACallbackHandler { + a := c.AddICACallback(ICACallbackID_Delegate, ICACallback(DelegateCallback)). + AddICACallback(ICACallbackID_Undelegate, ICACallback(UndelegateCallback)). + AddICACallback(ICACallbackID_Redelegate, ICACallback(RedelegateCallback)). + AddICACallback(ICACallbackID_Claim, ICACallback(ClaimCallback)). + AddICACallback(ICACallbackID_TransferFromNative, ICACallback(TransferFromNativeCallback)). + AddICACallback(ICACallbackID_TransferToNative, ICACallback(TransferToNativeCallback)). + AddICACallback(ICACallbackID_SetWithdrawAddress, ICACallback(SetWithdrawAddressCallback)) + return a.(ICACallbacks) +} diff --git a/x/millions/keeper/callbacks_claim.go b/x/millions/keeper/callbacks_claim.go new file mode 100644 index 00000000..40c0fb61 --- /dev/null +++ b/x/millions/keeper/callbacks_claim.go @@ -0,0 +1,56 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalClaimCallbackArgs Marshal claim ClaimCallback arguments +func (k Keeper) MarshalClaimCallbackArgs(ctx sdk.Context, claimCallback types.ClaimRewardsCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&claimCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalClaimCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalClaimCallbackArgs Marshal claim callback arguments into a ClaimCallback struct +func (k Keeper) UnmarshalClaimCallbackArgs(ctx sdk.Context, claimCallback []byte) (*types.ClaimRewardsCallback, error) { + unmarshalledClaimCallback := types.ClaimRewardsCallback{} + if err := k.cdc.Unmarshal(claimCallback, &unmarshalledClaimCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalClaimCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledClaimCallback, nil +} + +func ClaimCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + claimCallback, err := k.UnmarshalClaimCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal claim callback args: %s", err.Error())) + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for a claim packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for a claim packet") + _, err = k.OnClaimRewardsOnNativeChainCompleted(ctx, claimCallback.GetPoolId(), claimCallback.GetDrawId(), true) + return err + + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for a claim packet") + _, err = k.OnClaimRewardsOnNativeChainCompleted(ctx, claimCallback.GetPoolId(), claimCallback.GetDrawId(), false) + return err + } + return nil +} diff --git a/x/millions/keeper/callbacks_claim_test.go b/x/millions/keeper/callbacks_claim_test.go new file mode 100644 index 00000000..58cf23c2 --- /dev/null +++ b/x/millions/keeper/callbacks_claim_test.go @@ -0,0 +1,48 @@ +package keeper_test + +import ( + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_Claims() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.ClaimRewardsCallback{ + PoolId: pool.GetPoolId(), + DrawId: 1, + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalClaimCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_Claim, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalClaimCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) + suite.Require().Equal(callbackData.DrawId, unmarshalledCallbackData.DrawId) +} diff --git a/x/millions/keeper/callbacks_delegate.go b/x/millions/keeper/callbacks_delegate.go new file mode 100644 index 00000000..69e5d8d4 --- /dev/null +++ b/x/millions/keeper/callbacks_delegate.go @@ -0,0 +1,53 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalDelegateCallbackArgs Marshal delegate DelegateCallback arguments +func (k Keeper) MarshalDelegateCallbackArgs(ctx sdk.Context, delegateCallback types.DelegateCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&delegateCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalDelegateCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalDelegateCallbackArgs Marshal delegate callback arguments into a DelegateCallback struct +func (k Keeper) UnmarshalDelegateCallbackArgs(ctx sdk.Context, delegateCallback []byte) (*types.DelegateCallback, error) { + unmarshalledDelegateCallback := types.DelegateCallback{} + if err := k.cdc.Unmarshal(delegateCallback, &unmarshalledDelegateCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalDelegateCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledDelegateCallback, nil +} + +func DelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + delegateCallback, err := k.UnmarshalDelegateCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal delegate callback args: %s", err.Error())) + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for a delegate packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for a delegate packet") + return k.OnDelegateDepositOnNativeChainCompleted(ctx, delegateCallback.GetPoolId(), delegateCallback.GetDepositId(), delegateCallback.GetSplitDelegations(), true) + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for a delegate packet") + return k.OnDelegateDepositOnNativeChainCompleted(ctx, delegateCallback.GetPoolId(), delegateCallback.GetDepositId(), delegateCallback.GetSplitDelegations(), false) + } + return nil +} diff --git a/x/millions/keeper/callbacks_delegate_test.go b/x/millions/keeper/callbacks_delegate_test.go new file mode 100644 index 00000000..d4feee8a --- /dev/null +++ b/x/millions/keeper/callbacks_delegate_test.go @@ -0,0 +1,59 @@ +package keeper_test + +import ( + "cosmossdk.io/math" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_Delegates() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + // Prepare delegations split + splits := pool.ComputeSplitDelegations(suite.ctx, math.NewInt(100)) + suite.Require().Greater(len(splits), 0) + suite.Require().Equal(uint64(100), splits[0].Amount.Uint64()) + suite.Require().Greater(len(splits[0].ValidatorAddress), 0) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.DelegateCallback{ + PoolId: pool.GetPoolId(), + DepositId: 1, + SplitDelegations: splits, + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalDelegateCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_Delegate, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalDelegateCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) + suite.Require().Equal(callbackData.DepositId, unmarshalledCallbackData.DepositId) + suite.Require().Equal(len(callbackData.SplitDelegations), len(unmarshalledCallbackData.SplitDelegations)) + suite.Require().Equal(callbackData.SplitDelegations[0].ValidatorAddress, unmarshalledCallbackData.SplitDelegations[0].ValidatorAddress) + suite.Require().Equal(callbackData.SplitDelegations[0].Amount.Int64(), unmarshalledCallbackData.SplitDelegations[0].Amount.Int64()) +} diff --git a/x/millions/keeper/callbacks_redelegate.go b/x/millions/keeper/callbacks_redelegate.go new file mode 100644 index 00000000..fd6e8d59 --- /dev/null +++ b/x/millions/keeper/callbacks_redelegate.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalRedelegateCallbackArgs Marshal delegate RedelegateCallback arguments +func (k Keeper) MarshalRedelegateCallbackArgs(ctx sdk.Context, redelegateCallback types.RedelegateCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&redelegateCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalRedelegateCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalRedelegateCallbackArgs Marshal delegate callback arguments into a RedelegateCallback struct +func (k Keeper) UnmarshalRedelegateCallbackArgs(ctx sdk.Context, redelegateCallback []byte) (*types.RedelegateCallback, error) { + unmarshalledRedelegateCallback := types.RedelegateCallback{} + if err := k.cdc.Unmarshal(redelegateCallback, &unmarshalledRedelegateCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalRedelegateCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledRedelegateCallback, nil +} + +func RedelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + redelegateCallback, err := k.UnmarshalRedelegateCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal redelegate callback args: %s", err.Error())) + } + + // Acquire the pool instance from the callback + _, err = k.GetPool(ctx, redelegateCallback.GetPoolId()) + if err != nil { + return err + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for a redelegate packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for a redelegate packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for a redelegate packet") + } + return nil +} diff --git a/x/millions/keeper/callbacks_redelegate_test.go b/x/millions/keeper/callbacks_redelegate_test.go new file mode 100644 index 00000000..70e82d9e --- /dev/null +++ b/x/millions/keeper/callbacks_redelegate_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "cosmossdk.io/math" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_Redelegates() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + // Prepare delegations split + splits := pool.ComputeSplitDelegations(suite.ctx, math.NewInt(100)) + suite.Require().Greater(len(splits), 0) + suite.Require().Equal(uint64(100), splits[0].Amount.Uint64()) + suite.Require().Greater(len(splits[0].ValidatorAddress), 0) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.RedelegateCallback{ + PoolId: pool.GetPoolId(), + SplitDelegation: splits[0], + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalRedelegateCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_Redelegate, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalRedelegateCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) + suite.Require().Equal(callbackData.SplitDelegation.ValidatorAddress, unmarshalledCallbackData.SplitDelegation.ValidatorAddress) + suite.Require().Equal(callbackData.SplitDelegation.Amount.Int64(), unmarshalledCallbackData.SplitDelegation.Amount.Int64()) +} diff --git a/x/millions/keeper/callbacks_set_withdraw_address.go b/x/millions/keeper/callbacks_set_withdraw_address.go new file mode 100644 index 00000000..b82b838f --- /dev/null +++ b/x/millions/keeper/callbacks_set_withdraw_address.go @@ -0,0 +1,59 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalSetWithdrawAddressCallbackArgs Marshal delegate RedelegateCallback arguments +func (k Keeper) MarshalSetWithdrawAddressCallbackArgs(ctx sdk.Context, setWithdrawAddrCallback types.SetWithdrawAddressCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&setWithdrawAddrCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalSetWithdrawAddressCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalSetWithdrawAddressCallbackArgs Marshal delegate callback arguments into a RedelegateCallback struct +func (k Keeper) UnmarshalSetWithdrawAddressCallbackArgs(ctx sdk.Context, setWithdrawAddrCallback []byte) (*types.SetWithdrawAddressCallback, error) { + unmarshalledWithdrawAddrCallback := types.SetWithdrawAddressCallback{} + if err := k.cdc.Unmarshal(setWithdrawAddrCallback, &unmarshalledWithdrawAddrCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalSetWithdrawAddressCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledWithdrawAddrCallback, nil +} + +func SetWithdrawAddressCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + setWithdrawAddressCallback, err := k.UnmarshalSetWithdrawAddressCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal set withdraw address callback args: %s", err.Error())) + } + + // Acquire the pool instance from the callback + pool, err := k.GetPool(ctx, setWithdrawAddressCallback.GetPoolId()) + if err != nil { + return err + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for a set withdraw address packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for a set withdraw address packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for a set withdraw address packet") + _, err := k.OnSetupPoolWithdrawalAddressCompleted(ctx, pool.PoolId) + return err + } + return nil +} diff --git a/x/millions/keeper/callbacks_set_withdraw_address_test.go b/x/millions/keeper/callbacks_set_withdraw_address_test.go new file mode 100644 index 00000000..b7814b4b --- /dev/null +++ b/x/millions/keeper/callbacks_set_withdraw_address_test.go @@ -0,0 +1,46 @@ +package keeper_test + +import ( + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_WithdrawAddress() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.SetWithdrawAddressCallback{ + PoolId: pool.GetPoolId(), + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalSetWithdrawAddressCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_SetWithdrawAddress, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalSetWithdrawAddressCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) +} diff --git a/x/millions/keeper/callbacks_transfer_from_native.go b/x/millions/keeper/callbacks_transfer_from_native.go new file mode 100644 index 00000000..1f614fb2 --- /dev/null +++ b/x/millions/keeper/callbacks_transfer_from_native.go @@ -0,0 +1,69 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalTransferFromNativeCallbackArgs Marshal TransferFromNativeCallback arguments +func (k Keeper) MarshalTransferFromNativeCallbackArgs(ctx sdk.Context, transferCallback types.TransferFromNativeCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&transferCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalTransferFromNativeCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalTransferFromNativeCallbackArgs Marshal callback arguments into a TransferFromNativeCallback struct +func (k Keeper) UnmarshalTransferFromNativeCallbackArgs(ctx sdk.Context, transferCallback []byte) (*types.TransferFromNativeCallback, error) { + unmarshalledTransferCallback := types.TransferFromNativeCallback{} + if err := k.cdc.Unmarshal(transferCallback, &unmarshalledTransferCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalTransferFromNativeCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledTransferCallback, nil +} + +func TransferFromNativeCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + transferCallback, err := k.UnmarshalTransferFromNativeCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal transfer from native callback args: %s", err.Error())) + } + + // Acquire the pool instance from the callback + _, err = k.GetPool(ctx, transferCallback.GetPoolId()) + if err != nil { + return err + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for a transfer from native packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for a transfer from native packet") + if transferCallback.Type == types.TransferType_Claim { + _, err := k.OnTransferRewardsToLocalChainCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetDrawId(), true) + return err + } else if transferCallback.Type == types.TransferType_Withdraw { + return k.OnTransferWithdrawalToLocalChainCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetWithdrawalId(), true) + } + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for a transfer from native packet") + if transferCallback.Type == types.TransferType_Claim { + _, err := k.OnTransferRewardsToLocalChainCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetDrawId(), false) + return err + } else if transferCallback.Type == types.TransferType_Withdraw { + return k.OnTransferWithdrawalToLocalChainCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetWithdrawalId(), false) + } + } + return nil +} diff --git a/x/millions/keeper/callbacks_transfer_from_native_test.go b/x/millions/keeper/callbacks_transfer_from_native_test.go new file mode 100644 index 00000000..9ef98ac0 --- /dev/null +++ b/x/millions/keeper/callbacks_transfer_from_native_test.go @@ -0,0 +1,52 @@ +package keeper_test + +import ( + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_TransfersFromNative() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.TransferFromNativeCallback{ + PoolId: pool.GetPoolId(), + WithdrawalId: 1, + DrawId: 1, + Type: millionstypes.TransferType_Claim, + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalTransferFromNativeCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_TransferToNative, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalTransferFromNativeCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) + suite.Require().Equal(callbackData.WithdrawalId, unmarshalledCallbackData.WithdrawalId) + suite.Require().Equal(callbackData.DrawId, unmarshalledCallbackData.DrawId) + suite.Require().Equal(callbackData.Type, unmarshalledCallbackData.Type) +} diff --git a/x/millions/keeper/callbacks_transfer_to_native.go b/x/millions/keeper/callbacks_transfer_to_native.go new file mode 100644 index 00000000..bf3e4b42 --- /dev/null +++ b/x/millions/keeper/callbacks_transfer_to_native.go @@ -0,0 +1,53 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalTransferToNativeCallbackArgs Marshal TransferToNativeCallback arguments +func (k Keeper) MarshalTransferToNativeCallbackArgs(ctx sdk.Context, transferCallback types.TransferToNativeCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&transferCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalTransferToNativeCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalTransferToNativeCallbackArgs Marshal callback arguments into a TransferToNativeCallback struct +func (k Keeper) UnmarshalTransferToNativeCallbackArgs(ctx sdk.Context, transferCallback []byte) (*types.TransferToNativeCallback, error) { + unmarshalledTransferCallback := types.TransferToNativeCallback{} + if err := k.cdc.Unmarshal(transferCallback, &unmarshalledTransferCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalTransferToNativeCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledTransferCallback, nil +} + +func TransferToNativeCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + transferCallback, err := k.UnmarshalTransferToNativeCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal transfer to native callback args: %s", err.Error())) + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for a transfer to native packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for a transfer to native packet") + return k.OnTransferDepositToNativeChainCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetDepositId(), true) + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for a transfer to native packet.") + return k.OnTransferDepositToNativeChainCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetDepositId(), false) + } + return nil +} diff --git a/x/millions/keeper/callbacks_transfer_to_native_test.go b/x/millions/keeper/callbacks_transfer_to_native_test.go new file mode 100644 index 00000000..c4638174 --- /dev/null +++ b/x/millions/keeper/callbacks_transfer_to_native_test.go @@ -0,0 +1,48 @@ +package keeper_test + +import ( + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_TransfersToNative() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.TransferToNativeCallback{ + PoolId: pool.GetPoolId(), + DepositId: 1, + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalTransferToNativeCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_TransferToNative, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalTransferToNativeCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) + suite.Require().Equal(callbackData.DepositId, unmarshalledCallbackData.DepositId) +} diff --git a/x/millions/keeper/callbacks_undelegate.go b/x/millions/keeper/callbacks_undelegate.go new file mode 100644 index 00000000..0f8d416a --- /dev/null +++ b/x/millions/keeper/callbacks_undelegate.go @@ -0,0 +1,103 @@ +package keeper + +import ( + "fmt" + "time" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + "github.com/lum-network/chain/x/millions/types" +) + +// MarshalUndelegateCallbackArgs Marshal delegate UndelegateCallback arguments +func (k Keeper) MarshalUndelegateCallbackArgs(ctx sdk.Context, undelegateCallback types.UndelegateCallback) ([]byte, error) { + out, err := k.cdc.Marshal(&undelegateCallback) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("MarshalUndelegateCallbackArgs %v", err.Error())) + return nil, err + } + return out, nil +} + +// UnmarshalUndelegateCallbackArgs Marshal delegate callback arguments into a UndelegateCallback struct +func (k Keeper) UnmarshalUndelegateCallbackArgs(ctx sdk.Context, undelegateCallback []byte) (*types.UndelegateCallback, error) { + unmarshalledUndelegateCallback := types.UndelegateCallback{} + if err := k.cdc.Unmarshal(undelegateCallback, &unmarshalledUndelegateCallback); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("UnmarshalUndelegateCallbackArgs %v", err.Error())) + return nil, err + } + return &unmarshalledUndelegateCallback, nil +} + +// Get the latest completion time across each MsgUndelegate in the ICA transaction +func (k Keeper) GetLatestUnbondingCompletionTime(ctx sdk.Context, msgResponses [][]byte) (*time.Time, error) { + // Update the completion time using the latest completion time across each message within the transaction + latestCompletionTime := time.Time{} + + for _, msgResponse := range msgResponses { + // unmarshall the ack response into a MsgUndelegateResponse and grab the completion time + var undelegateResponse stakingtypes.MsgUndelegateResponse + err := k.cdc.Unmarshal(msgResponse, &undelegateResponse) + if err != nil { + return nil, errorsmod.Wrapf(types.ErrUnmarshalFailure, "Unable to unmarshal undelegation tx response: %s", err.Error()) + } + if undelegateResponse.CompletionTime.After(latestCompletionTime) { + latestCompletionTime = undelegateResponse.CompletionTime + } + } + + if latestCompletionTime.IsZero() { + return nil, errorsmod.Wrapf(types.ErrInvalidPacketCompletionTime, "Invalid completion time (%s) from txMsg", latestCompletionTime.String()) + } + return &latestCompletionTime, nil +} + +func UndelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error { + // Deserialize the callback args + undelegateCallback, err := k.UnmarshalUndelegateCallbackArgs(ctx, args) + if err != nil { + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal undelegate callback args: %s", err.Error())) + } + + // Acquire the pool instance from the callback + _, err = k.GetPool(ctx, undelegateCallback.GetPoolId()) + if err != nil { + return err + } + + // If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed. + // We just log it out and return no error + if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { + k.Logger(ctx).Debug("Received timeout for an undelegate packet") + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE { + k.Logger(ctx).Debug("Received failure for an undelegate packet") + // Failed OnUndelegateWithdrawalOnNativeChainCompleted + return k.OnUndelegateWithdrawalOnNativeChainCompleted( + ctx, + undelegateCallback.GetPoolId(), + undelegateCallback.GetWithdrawalId(), + undelegateCallback.GetSplitDelegations(), + nil, + true, + ) + } else if ackResponse.Status == icacallbackstypes.AckResponseStatus_SUCCESS { + k.Logger(ctx).Debug("Received success for an undelegate packet") + unbondingEndsAt, err := k.GetLatestUnbondingCompletionTime(ctx, ackResponse.MsgResponses) + if err != nil { + return err + } + return k.OnUndelegateWithdrawalOnNativeChainCompleted( + ctx, + undelegateCallback.GetPoolId(), + undelegateCallback.GetWithdrawalId(), + undelegateCallback.GetSplitDelegations(), + unbondingEndsAt, + false, + ) + } + return nil +} diff --git a/x/millions/keeper/callbacks_undelegate_test.go b/x/millions/keeper/callbacks_undelegate_test.go new file mode 100644 index 00000000..1fc90551 --- /dev/null +++ b/x/millions/keeper/callbacks_undelegate_test.go @@ -0,0 +1,59 @@ +package keeper_test + +import ( + "cosmossdk.io/math" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestCallbacks_Undelegates() { + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + // Prepare delegations split + splits := pool.ComputeSplitDelegations(suite.ctx, math.NewInt(100)) + suite.Require().Greater(len(splits), 0) + suite.Require().Equal(uint64(100), splits[0].Amount.Uint64()) + suite.Require().Greater(len(splits[0].ValidatorAddress), 0) + + portID := "icacontroller-pool1" + channelID := "channel-0" + sequence := uint64(5) + + // Construct our callback data + callbackData := millionstypes.UndelegateCallback{ + PoolId: pool.GetPoolId(), + WithdrawalId: 1, + SplitDelegations: splits, + } + + // Serialize our callback + marshalledCallbackArgs, err := suite.app.MillionsKeeper.MarshalUndelegateCallbackArgs(suite.ctx, callbackData) + suite.Require().NoError(err) + + // Store inside the local datastore + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: millionskeeper.ICACallbackID_Undelegate, + CallbackArgs: marshalledCallbackArgs, + } + suite.app.ICACallbacksKeeper.SetCallbackData(suite.ctx, callback) + + // Grab from the local datastore + data, found := suite.app.ICACallbacksKeeper.GetCallbackData(suite.ctx, icacallbackstypes.PacketID(portID, channelID, sequence)) + suite.Require().True(found) + + // Deserialize our callback data + unmarshalledCallbackData, err := suite.app.MillionsKeeper.UnmarshalUndelegateCallbackArgs(suite.ctx, data.CallbackArgs) + suite.Require().NoError(err) + + // Make sure it matches + suite.Require().Equal(callbackData.PoolId, unmarshalledCallbackData.PoolId) + suite.Require().Equal(callbackData.WithdrawalId, unmarshalledCallbackData.WithdrawalId) + suite.Require().Equal(len(callbackData.SplitDelegations), len(unmarshalledCallbackData.SplitDelegations)) + suite.Require().Equal(callbackData.SplitDelegations[0].ValidatorAddress, unmarshalledCallbackData.SplitDelegations[0].ValidatorAddress) + suite.Require().Equal(callbackData.SplitDelegations[0].Amount.Int64(), unmarshalledCallbackData.SplitDelegations[0].Amount.Int64()) +} diff --git a/x/millions/keeper/grpc_query.go b/x/millions/keeper/grpc_query.go new file mode 100644 index 00000000..0759aa17 --- /dev/null +++ b/x/millions/keeper/grpc_query.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/lum-network/chain/x/millions/types" +) + +type queryServer struct { + Keeper +} + +// NewQueryServerImpl returns an implementation of the QueryServer interface +// for the provided Keeper. +func NewQueryServerImpl(keeper Keeper) types.QueryServer { + return queryServer{Keeper: keeper} +} + +var _ types.QueryServer = queryServer{} diff --git a/x/millions/keeper/grpc_query_deposit.go b/x/millions/keeper/grpc_query_deposit.go new file mode 100644 index 00000000..492c3585 --- /dev/null +++ b/x/millions/keeper/grpc_query_deposit.go @@ -0,0 +1,171 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k queryServer) Deposits(goCtx context.Context, req *types.QueryDepositsRequest) (*types.QueryDepositsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + depositStore := prefix.NewStore(store, types.GetDepositsKey()) + + // Make the paginated query + var deposits []types.Deposit + pageRes, err := query.Paginate(depositStore, req.Pagination, func(key []byte, value []byte) error { + var deposit types.Deposit + if err := k.cdc.Unmarshal(value, &deposit); err != nil { + return err + } + + deposits = append(deposits, deposit) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryDepositsResponse{Deposits: deposits, Pagination: pageRes}, nil +} + +func (k queryServer) PoolDeposits(goCtx context.Context, req *types.QueryPoolDepositsRequest) (*types.QueryDepositsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + depositStore := prefix.NewStore(store, types.GetPoolDepositsKey(req.GetPoolId())) + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + // Make the paginated query + var deposits []types.Deposit + pageRes, err := query.Paginate(depositStore, req.Pagination, func(key []byte, value []byte) error { + var deposit types.Deposit + if err := k.cdc.Unmarshal(value, &deposit); err != nil { + return err + } + + deposits = append(deposits, deposit) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryDepositsResponse{Deposits: deposits, Pagination: pageRes}, nil +} + +func (k queryServer) PoolDeposit(goCtx context.Context, req *types.QueryPoolDepositRequest) (*types.QueryDepositResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + deposit, err := k.GetPoolDeposit(ctx, req.GetPoolId(), req.GetDepositId()) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + return &types.QueryDepositResponse{Deposit: deposit}, nil +} + +func (k queryServer) AccountDeposits(goCtx context.Context, req *types.QueryAccountDepositsRequest) (*types.QueryDepositsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetDepositorAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + depositStore := prefix.NewStore(store, types.GetAccountDepositsKey(addr)) + + // Make the paginated query + var deposits []types.Deposit + pageRes, err := query.Paginate(depositStore, req.Pagination, func(key []byte, value []byte) error { + var deposit types.Deposit + if err := k.cdc.Unmarshal(value, &deposit); err != nil { + return err + } + + deposits = append(deposits, deposit) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryDepositsResponse{Deposits: deposits, Pagination: pageRes}, nil +} + +func (k queryServer) AccountPoolDeposits(goCtx context.Context, req *types.QueryAccountPoolDepositsRequest) (*types.QueryDepositsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetDepositorAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + depositStore := prefix.NewStore(store, types.GetAccountPoolDepositsKey(addr, req.PoolId)) + + // Make the paginated query + var deposits []types.Deposit + pageRes, err := query.Paginate(depositStore, req.Pagination, func(key []byte, value []byte) error { + var deposit types.Deposit + if err := k.cdc.Unmarshal(value, &deposit); err != nil { + return err + } + + deposits = append(deposits, deposit) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryDepositsResponse{Deposits: deposits, Pagination: pageRes}, nil +} diff --git a/x/millions/keeper/grpc_query_draw.go b/x/millions/keeper/grpc_query_draw.go new file mode 100644 index 00000000..59dc8052 --- /dev/null +++ b/x/millions/keeper/grpc_query_draw.go @@ -0,0 +1,96 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k queryServer) Draws(goCtx context.Context, req *types.QueryDrawsRequest) (*types.QueryDrawsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + drawStore := prefix.NewStore(store, types.DrawPrefix) + + // Make the paginated query + var draws []types.Draw + pageRes, err := query.Paginate(drawStore, req.Pagination, func(key []byte, value []byte) error { + var draw types.Draw + if err := k.cdc.Unmarshal(value, &draw); err != nil { + return err + } + + draws = append(draws, draw) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryDrawsResponse{Draws: draws, Pagination: pageRes}, nil +} + +func (k queryServer) PoolDraws(goCtx context.Context, req *types.QueryPoolDrawsRequest) (*types.QueryDrawsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + drawStore := prefix.NewStore(store, types.GetPoolDrawsKey(req.GetPoolId())) + + // Make the paginated query + var draws []types.Draw + pageRes, err := query.Paginate(drawStore, req.Pagination, func(key []byte, value []byte) error { + var draw types.Draw + if err := k.cdc.Unmarshal(value, &draw); err != nil { + return err + } + + draws = append(draws, draw) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryDrawsResponse{Draws: draws, Pagination: pageRes}, nil +} + +func (k queryServer) PoolDraw(goCtx context.Context, req *types.QueryPoolDrawRequest) (*types.QueryDrawResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + draw, err := k.GetPoolDraw(ctx, req.GetPoolId(), req.GetDrawId()) + if err != nil { + return &types.QueryDrawResponse{}, err + } + + return &types.QueryDrawResponse{Draw: &draw}, nil +} diff --git a/x/millions/keeper/grpc_query_params.go b/x/millions/keeper/grpc_query_params.go new file mode 100644 index 00000000..b0a12681 --- /dev/null +++ b/x/millions/keeper/grpc_query_params.go @@ -0,0 +1,15 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k queryServer) Params(goCtx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + params := k.GetParams(ctx) + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/x/millions/keeper/grpc_query_pool.go b/x/millions/keeper/grpc_query_pool.go new file mode 100644 index 00000000..6adcd1e2 --- /dev/null +++ b/x/millions/keeper/grpc_query_pool.go @@ -0,0 +1,59 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k queryServer) Pools(goCtx context.Context, req *types.QueryPoolsRequest) (*types.QueryPoolsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + poolStore := prefix.NewStore(store, types.PoolPrefix) + + // Make the paginated query + var pools []types.Pool + pageRes, err := query.Paginate(poolStore, req.Pagination, func(key []byte, value []byte) error { + var pool types.Pool + if err := k.cdc.Unmarshal(value, &pool); err != nil { + return err + } + + pools = append(pools, pool) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPoolsResponse{Pools: pools, Pagination: pageRes}, nil +} + +func (k queryServer) Pool(goCtx context.Context, req *types.QueryPoolRequest) (*types.QueryPoolResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + pool, err := k.GetPool(ctx, req.GetPoolId()) + if err != nil { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + return &types.QueryPoolResponse{Pool: pool}, nil +} diff --git a/x/millions/keeper/grpc_query_prize.go b/x/millions/keeper/grpc_query_prize.go new file mode 100644 index 00000000..502a69ad --- /dev/null +++ b/x/millions/keeper/grpc_query_prize.go @@ -0,0 +1,246 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k queryServer) Prizes(goCtx context.Context, req *types.QueryPrizesRequest) (*types.QueryPrizesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + prizeStore := prefix.NewStore(store, types.GetPrizesKey()) + + // Make the paginated query + var prizes []types.Prize + pageRes, err := query.Paginate(prizeStore, req.Pagination, func(key []byte, value []byte) error { + var prize types.Prize + if err := k.cdc.Unmarshal(value, &prize); err != nil { + return err + } + + prizes = append(prizes, prize) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPrizesResponse{Prizes: prizes, Pagination: pageRes}, nil +} + +func (k queryServer) PoolPrizes(goCtx context.Context, req *types.QueryPoolPrizesRequest) (*types.QueryPrizesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + prizeStore := prefix.NewStore(store, types.GetPoolPrizesKey(req.GetPoolId())) + + // Make the paginated query + var prizes []types.Prize + pageRes, err := query.Paginate(prizeStore, req.Pagination, func(key []byte, value []byte) error { + var prize types.Prize + if err := k.cdc.Unmarshal(value, &prize); err != nil { + return err + } + + prizes = append(prizes, prize) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPrizesResponse{Prizes: prizes, Pagination: pageRes}, nil +} + +func (k queryServer) PoolDrawPrizes(goCtx context.Context, req *types.QueryPoolDrawPrizesRequest) (*types.QueryPrizesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPoolDraw(ctx, req.PoolId, req.GetDrawId()) { + return nil, status.Error(codes.NotFound, types.ErrPoolDrawNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + prizeStore := prefix.NewStore(store, types.GetPoolDrawPrizesKey(req.GetPoolId(), req.GetDrawId())) + + // Make the paginated query + var prizes []types.Prize + pageRes, err := query.Paginate(prizeStore, req.Pagination, func(key []byte, value []byte) error { + var prize types.Prize + if err := k.cdc.Unmarshal(value, &prize); err != nil { + return err + } + + prizes = append(prizes, prize) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPrizesResponse{Prizes: prizes, Pagination: pageRes}, nil +} + +func (k queryServer) PoolDrawPrize(goCtx context.Context, req *types.QueryPoolDrawPrizeRequest) (*types.QueryPrizeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + prize, err := k.GetPoolDrawPrize(ctx, req.GetPoolId(), req.GetDrawId(), req.GetPrizeId()) + if err != nil { + return &types.QueryPrizeResponse{}, err + } + + return &types.QueryPrizeResponse{Prize: prize}, nil +} + +func (k queryServer) AccountPrizes(goCtx context.Context, req *types.QueryAccountPrizesRequest) (*types.QueryPrizesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetWinnerAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + prizeStore := prefix.NewStore(store, types.GetAccountPrizesKey(addr)) + + // Make the paginated query + var prizes []types.Prize + pageRes, err := query.Paginate(prizeStore, req.Pagination, func(key []byte, value []byte) error { + var prize types.Prize + if err := k.cdc.Unmarshal(value, &prize); err != nil { + return err + } + + prizes = append(prizes, prize) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPrizesResponse{Prizes: prizes, Pagination: pageRes}, nil +} + +func (k queryServer) AccountPoolPrizes(goCtx context.Context, req *types.QueryAccountPoolPrizesRequest) (*types.QueryPrizesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetWinnerAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + prizeStore := prefix.NewStore(store, types.GetAccountPoolPrizesKey(addr, req.GetPoolId())) + + // Make the paginated query + var prizes []types.Prize + pageRes, err := query.Paginate(prizeStore, req.Pagination, func(key []byte, value []byte) error { + var prize types.Prize + if err := k.cdc.Unmarshal(value, &prize); err != nil { + return err + } + + prizes = append(prizes, prize) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPrizesResponse{Prizes: prizes, Pagination: pageRes}, nil +} + +func (k queryServer) AccountPoolDrawPrizes(goCtx context.Context, req *types.QueryAccountPoolDrawPrizesRequest) (*types.QueryPrizesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetWinnerAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPoolDraw(ctx, req.PoolId, req.DrawId) { + return nil, status.Error(codes.NotFound, types.ErrPoolDrawNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + prizeStore := prefix.NewStore(store, types.GetAccountPoolDrawPrizesKey(addr, req.GetPoolId(), req.GetDrawId())) + + // Make the paginated query + var prizes []types.Prize + pageRes, err := query.Paginate(prizeStore, req.Pagination, func(key []byte, value []byte) error { + var prize types.Prize + if err := k.cdc.Unmarshal(value, &prize); err != nil { + return err + } + + prizes = append(prizes, prize) + return nil + }) + + // Was there any error while acquiring the list of pools + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPrizesResponse{Prizes: prizes, Pagination: pageRes}, nil +} diff --git a/x/millions/keeper/grpc_query_test.go b/x/millions/keeper/grpc_query_test.go new file mode 100644 index 00000000..6bfd3cd3 --- /dev/null +++ b/x/millions/keeper/grpc_query_test.go @@ -0,0 +1,595 @@ +package keeper_test + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestGRPC_Params runs simple Params GRPCs integration tests +func (suite *KeeperTestSuite) TestGRPC_Query_Params() { + app := suite.app + ctx := suite.ctx + queryServer := millionskeeper.NewQueryServerImpl(*app.MillionsKeeper) + + // Get ctx params + initialParams := app.MillionsKeeper.GetParams(ctx) + + // Get query params + paramsRes, err := queryServer.Params(ctx, &millionstypes.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().Equal(initialParams.FeesStakers, paramsRes.Params.FeesStakers) + suite.Require().Equal(initialParams.MaxDrawScheduleDelta, paramsRes.Params.MaxDrawScheduleDelta) + suite.Require().Equal(initialParams.MaxPrizeBatchQuantity, paramsRes.Params.MaxPrizeBatchQuantity) + suite.Require().Equal(initialParams.MinDepositAmount, paramsRes.Params.MinDepositAmount) + suite.Require().Equal(initialParams.MinDepositDrawDelta, paramsRes.Params.MinDepositDrawDelta) + suite.Require().Equal(initialParams.MinDrawScheduleDelta, paramsRes.Params.MinDrawScheduleDelta) + suite.Require().Equal(initialParams.PrizeExpirationDelta, paramsRes.Params.PrizeExpirationDelta) +} + +// TestGRPC_Query_Pool runs simple integration tests for pools and pool +func (suite *KeeperTestSuite) TestGRPC_Query_Pool() { + app := suite.app + ctx := suite.ctx + queryServer := millionskeeper.NewQueryServerImpl(*app.MillionsKeeper) + + nbrItems := 4 + // Test run generates + // - 5 pools + for i := 0; i < nbrItems; i++ { + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + {PoolPercent: 50, Quantity: 4, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + // Force the available pool prize + pool.AvailablePrizePool = sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaPrizepoolAddress), sdk.NewCoins(pool.AvailablePrizePool)) + suite.Require().NoError(err) + + app.MillionsKeeper.AddPool(ctx, pool) + } + + // Test Pools + poolsRes, err := queryServer.Pools(ctx, &millionstypes.QueryPoolsRequest{}) + suite.Require().NoError(err) + suite.Require().Len(poolsRes.GetPools(), nbrItems) + suite.Require().Equal(uint64(1), poolsRes.GetPools()[0].PoolId) + suite.Require().Equal(uint64(nbrItems), poolsRes.GetPools()[nbrItems-1].PoolId) + // Test Pools with pagination + poolsResPaginated, err := queryServer.Pools(ctx, &millionstypes.QueryPoolsRequest{Pagination: &query.PageRequest{Offset: 1, Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(poolsResPaginated.GetPools(), 2) + suite.Require().Equal(poolsRes.GetPools()[1].PoolId, poolsResPaginated.GetPools()[0].PoolId) + suite.Require().Equal(poolsRes.GetPools()[2].PoolId, poolsResPaginated.GetPools()[1].PoolId) + + // Test Pool with wrong poolID + _, err = queryServer.Pool(ctx, &millionstypes.QueryPoolRequest{PoolId: 0}) + suite.Require().Error(err) + // Test Pool + poolRes, err := queryServer.Pool(ctx, &millionstypes.QueryPoolRequest{PoolId: 1}) + suite.Require().NoError(err) + suite.Require().Equal(uint64(1), poolRes.GetPool().PoolId) + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Equal(sdk.NewCoin(pools[0].Denom, sdk.NewInt(1_000_000)), pools[0].AvailablePrizePool) +} + +// TestGRPC_Query_Deposit runs simple integration tests for deposits and pools +func (suite *KeeperTestSuite) TestGRPC_Query_Deposit() { + app := suite.app + ctx := suite.ctx + queryServer := millionskeeper.NewQueryServerImpl(*app.MillionsKeeper) + + nbrItems := 4 + // Test run generates + // - 5 pools + // - 5 accounts + // - 32 deposits + for i := 0; i < nbrItems; i++ { + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + {PoolPercent: 50, Quantity: 4, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + + // Force the available pool prize + pool.AvailablePrizePool = sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaPrizepoolAddress), sdk.NewCoins(pool.AvailablePrizePool)) + suite.Require().NoError(err) + + app.MillionsKeeper.AddPool(ctx, pool) + + // Create deposits + for i := 0; i < nbrItems; i++ { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + State: millionstypes.DepositState_Success, + }) + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(500_000)), + State: millionstypes.DepositState_Success, + }) + } + } + + // Test Deposits + depositorsRes, err := queryServer.Deposits(ctx, &millionstypes.QueryDepositsRequest{}) + suite.Require().NoError(err) + poolsFound := map[uint64]interface{}{} + depositsFound := map[string]interface{}{} + for _, depositor := range depositorsRes.GetDeposits() { + poolsFound[depositor.PoolId] = true + depositsFound[fmt.Sprintf("%s-%d-%d", depositor.DepositorAddress, depositor.GetPoolId(), depositor.GetAmount().Amount.Int64())] = true + + } + suite.Require().Len(poolsFound, nbrItems) // 5 pools + suite.Require().Len(depositsFound, nbrItems*nbrItems*2) // 5 pools * 5 accounts * 2 deposits + + depositorsRes, err = queryServer.Deposits(ctx, &millionstypes.QueryDepositsRequest{}) + suite.Require().NoError(err) + suite.Require().Len(depositorsRes.GetDeposits(), nbrItems*nbrItems*2) + // Test Deposits with pagination + depositorsResPaginated, err := queryServer.Deposits(ctx, &millionstypes.QueryDepositsRequest{Pagination: &query.PageRequest{Offset: 1, Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(depositorsResPaginated.GetDeposits(), 2) + suite.Require().Equal(depositorsRes.GetDeposits()[1].DepositId, depositorsResPaginated.GetDeposits()[0].DepositId) + suite.Require().Equal(depositorsRes.GetDeposits()[2].DepositId, depositorsResPaginated.GetDeposits()[1].DepositId) + + // Test AccountDeposits with wrong depositorAddr + _, err = queryServer.AccountDeposits(ctx, &millionstypes.QueryAccountDepositsRequest{DepositorAddress: ""}) + suite.Require().Error(err) + // Test AccountDeposits + accountDeposits, err := queryServer.AccountDeposits(ctx, &millionstypes.QueryAccountDepositsRequest{DepositorAddress: suite.addrs[0].String()}) + suite.Require().NoError(err) + suite.Require().Len(accountDeposits.GetDeposits(), nbrItems*2) // 1 account 8 deposits + // Test AccountDeposits with pagination + accountDepositsPaginated, err := queryServer.AccountDeposits(ctx, &millionstypes.QueryAccountDepositsRequest{DepositorAddress: suite.addrs[0].String(), Pagination: &query.PageRequest{Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(accountDepositsPaginated.GetDeposits(), 2) + suite.Require().Equal(accountDeposits.GetDeposits()[0].DepositId, accountDepositsPaginated.GetDeposits()[0].DepositId) + suite.Require().Equal(accountDeposits.GetDeposits()[1].DepositId, accountDepositsPaginated.GetDeposits()[1].DepositId) + + // Test PoolDeposits with wrong poolID + _, err = queryServer.PoolDeposits(ctx, &millionstypes.QueryPoolDepositsRequest{PoolId: 0}) + suite.Require().Error(err) + // Test PoolDeposits + poolDepositsRes, err := queryServer.PoolDeposits(ctx, &millionstypes.QueryPoolDepositsRequest{PoolId: 1}) + suite.Require().NoError(err) + suite.Require().Len(poolDepositsRes.GetDeposits(), nbrItems*2) // 1 pool * 8 deposits + // Test PoolDeposits with pagination + poolDepositsResPaginated, err := queryServer.PoolDeposits(ctx, &millionstypes.QueryPoolDepositsRequest{PoolId: 1, Pagination: &query.PageRequest{Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(poolDepositsResPaginated.GetDeposits(), 2) + suite.Require().Equal(poolDepositsRes.GetDeposits()[0].DepositId, poolDepositsResPaginated.GetDeposits()[0].DepositId) + suite.Require().Equal(poolDepositsRes.GetDeposits()[1].DepositId, poolDepositsResPaginated.GetDeposits()[1].DepositId) + + // Test PoolDeposit with wrong poolID + _, err = queryServer.PoolDeposit(ctx, &millionstypes.QueryPoolDepositRequest{PoolId: 0, DepositId: 1}) + suite.Require().Error(err) + // Test PoolDeposit with wrong depositID + _, err = queryServer.PoolDeposit(ctx, &millionstypes.QueryPoolDepositRequest{PoolId: 1, DepositId: 0}) + suite.Require().Error(err) + // Test PoolDeposit + poolDeposit, err := queryServer.PoolDeposit(ctx, &millionstypes.QueryPoolDepositRequest{PoolId: 1, DepositId: 1}) + suite.Require().NoError(err) + suite.Require().Equal(poolDeposit.Deposit.DepositId, uint64(1)) + + // Test AccountPoolDeposits with wrong depositorAddr + _, err = queryServer.AccountPoolDeposits(ctx, &millionstypes.QueryAccountPoolDepositsRequest{DepositorAddress: "", PoolId: 1}) + suite.Require().Error(err) + // Test AccountPoolDeposits with wrong poolID + _, err = queryServer.AccountPoolDeposits(ctx, &millionstypes.QueryAccountPoolDepositsRequest{DepositorAddress: suite.addrs[0].String(), PoolId: 0}) + suite.Require().Error(err) + // Test AccountPoolDeposits + accountPoolDeposits, err := queryServer.AccountPoolDeposits(ctx, &millionstypes.QueryAccountPoolDepositsRequest{DepositorAddress: suite.addrs[0].String(), PoolId: 1}) + suite.Require().NoError(err) + suite.Require().Len(accountPoolDeposits.GetDeposits(), 2) // 1 account * 2 deposits + // Test AccountPoolDeposits with pagination + accountPoolDepositsPaginated, err := queryServer.AccountPoolDeposits(ctx, &millionstypes.QueryAccountPoolDepositsRequest{DepositorAddress: suite.addrs[0].String(), PoolId: 1, Pagination: &query.PageRequest{Offset: 0, Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(accountPoolDepositsPaginated.GetDeposits(), 2) + suite.Require().Equal(accountPoolDeposits.GetDeposits()[0].DepositId, accountPoolDepositsPaginated.GetDeposits()[0].DepositId) + suite.Require().Equal(accountPoolDeposits.GetDeposits()[1].DepositId, accountPoolDepositsPaginated.GetDeposits()[1].DepositId) +} + +// TestGRPC_Query_Draw runs simple integration tests on draws and pools +func (suite *KeeperTestSuite) TestGRPC_Query_Draw() { + app := suite.app + ctx := suite.ctx + queryServer := millionskeeper.NewQueryServerImpl(*app.MillionsKeeper) + + nbrItems := 4 + // Test run generates + // - 5 pools + // - 5 accounts + // - 32 deposits + // - 16 draws + for i := 0; i < nbrItems; i++ { + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + {PoolPercent: 50, Quantity: 4, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + + // Force the available pool prize + pool.AvailablePrizePool = sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaPrizepoolAddress), sdk.NewCoins(pool.AvailablePrizePool)) + suite.Require().NoError(err) + + app.MillionsKeeper.AddPool(ctx, pool) + + // Create deposits + for i := 0; i < nbrItems; i++ { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + State: millionstypes.DepositState_Success, + }) + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(500_000)), + State: millionstypes.DepositState_Success, + }) + } + + // Launch new draw + for i := 0; i < nbrItems; i++ { + draw, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(draw.PrizePool.Amount.Int64(), draw.TotalWinAmount.Int64()) + } + } + + // Test Draws + drawsRes, err := queryServer.Draws(ctx, &millionstypes.QueryDrawsRequest{}) + suite.Require().NoError(err) + suite.Require().Len(drawsRes.GetDraws(), nbrItems*nbrItems) + suite.Require().Equal(uint64(1), drawsRes.GetDraws()[0].PoolId) + suite.Require().Equal(uint64(nbrItems), drawsRes.GetDraws()[nbrItems*nbrItems-1].PoolId) + // Test Draws with pagination + drawsResPaginated, err := queryServer.Draws(ctx, &millionstypes.QueryDrawsRequest{Pagination: &query.PageRequest{Offset: 1, Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(drawsResPaginated.GetDraws(), 2) + suite.Require().Equal(drawsRes.GetDraws()[1].DrawId, drawsResPaginated.GetDraws()[0].DrawId) + suite.Require().Equal(drawsRes.GetDraws()[2].DrawId, drawsResPaginated.GetDraws()[1].DrawId) + + // Test PoolDraws with wrong poolID + _, err = queryServer.PoolDraws(ctx, &millionstypes.QueryPoolDrawsRequest{PoolId: 0}) + suite.Require().Error(err) + // Test PoolDraws + poolDrawsRes, err := queryServer.PoolDraws(ctx, &millionstypes.QueryPoolDrawsRequest{PoolId: 1}) + suite.Require().NoError(err) + suite.Require().Len(poolDrawsRes.GetDraws(), nbrItems) + suite.Require().Equal(uint64(1), poolDrawsRes.GetDraws()[0].PoolId) + suite.Require().Equal(uint64(1), poolDrawsRes.GetDraws()[nbrItems-1].PoolId) + // Test PoolDraws with pagination + poolDrawsResPaginated, err := queryServer.PoolDraws(ctx, &millionstypes.QueryPoolDrawsRequest{PoolId: 1, Pagination: &query.PageRequest{Offset: 2, Limit: 3}}) + suite.Require().NoError(err) + suite.Require().Len(poolDrawsResPaginated.GetDraws(), 2) + suite.Require().Equal(poolDrawsRes.GetDraws()[2].DrawId, poolDrawsResPaginated.GetDraws()[0].DrawId) + suite.Require().Equal(poolDrawsRes.GetDraws()[3].DrawId, poolDrawsResPaginated.GetDraws()[1].DrawId) + + // Test PoolDraw with wrong poolID + _, err = queryServer.PoolDraw(ctx, &millionstypes.QueryPoolDrawRequest{PoolId: 0, DrawId: 1}) + suite.Require().Error(err) + // Test PoolDraw with wrong drawID + _, err = queryServer.PoolDraw(ctx, &millionstypes.QueryPoolDrawRequest{PoolId: 1, DrawId: 0}) + suite.Require().Error(err) + // Test PoolDraw + poolDrawRes, err := queryServer.PoolDraw(ctx, &millionstypes.QueryPoolDrawRequest{PoolId: 1, DrawId: 1}) + suite.Require().NoError(err) + suite.Require().Equal(uint64(1), poolDrawRes.GetDraw().PoolId) + suite.Require().Equal(uint64(1), poolDrawRes.GetDraw().DrawId) + // Test PoolDraw with different id + poolDrawRes, err = queryServer.PoolDraw(ctx, &millionstypes.QueryPoolDrawRequest{PoolId: uint64(nbrItems), DrawId: uint64(nbrItems)}) + suite.Require().NoError(err) + suite.Require().Equal(uint64(nbrItems), poolDrawRes.GetDraw().PoolId) + suite.Require().Equal(uint64(nbrItems), poolDrawRes.GetDraw().DrawId) +} + +// TestGRPC_Query_Prize runs simple integration tests on prizes, pools and draws +func (suite *KeeperTestSuite) TestGRPC_Query_Prize() { + app := suite.app + ctx := suite.ctx + queryServer := millionskeeper.NewQueryServerImpl(*app.MillionsKeeper) + + nbrItems := 4 + // Test run generates + // - 5 pools + // - 5 accounts + // - 32 deposits + // - 16 draws + for i := 0; i < nbrItems; i++ { + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + {PoolPercent: 50, Quantity: 4, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + + // Force the available pool prize + pool.AvailablePrizePool = sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaPrizepoolAddress), sdk.NewCoins(pool.AvailablePrizePool)) + suite.Require().NoError(err) + + app.MillionsKeeper.AddPool(ctx, pool) + + // Create deposits + for i := 0; i < nbrItems; i++ { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + State: millionstypes.DepositState_Success, + }) + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(500_000)), + State: millionstypes.DepositState_Success, + }) + } + + // Launch new draw + for i := 0; i < nbrItems; i++ { + draw, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(draw.PrizePool.Amount.Int64(), draw.TotalWinAmount.Int64()) + } + } + + // Test Prizes + prizeRes, err := queryServer.Prizes(ctx, &millionstypes.QueryPrizesRequest{}) + suite.Require().NoError(err) + suite.Require().Len(prizeRes.GetPrizes(), nbrItems*5) + // Test Prizes with pagination + prizeResPaginated, err := queryServer.Prizes(ctx, &millionstypes.QueryPrizesRequest{Pagination: &query.PageRequest{Offset: 1, Limit: 3}}) + suite.Require().NoError(err) + suite.Require().Len(prizeResPaginated.GetPrizes(), 3) + suite.Require().Equal(prizeRes.GetPrizes()[1].PrizeId, prizeResPaginated.GetPrizes()[0].PrizeId) + suite.Require().Equal(prizeRes.GetPrizes()[2].PrizeId, prizeResPaginated.GetPrizes()[1].PrizeId) + suite.Require().Equal(prizeRes.GetPrizes()[3].PrizeId, prizeResPaginated.GetPrizes()[2].PrizeId) + + // Test AccountPrizes with wrong winnerAddr + _, err = queryServer.AccountPrizes(ctx, &millionstypes.QueryAccountPrizesRequest{WinnerAddress: ""}) + suite.Require().Error(err) + // Test AccountPrizes + accountPrizes, err := queryServer.AccountPrizes(ctx, &millionstypes.QueryAccountPrizesRequest{WinnerAddress: suite.addrs[2].String()}) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPrizes.GetPrizes()), 0) + // Test AccountPrizes with pagination + accountPrizesPaginated, err := queryServer.AccountPrizes(ctx, &millionstypes.QueryAccountPrizesRequest{WinnerAddress: suite.addrs[2].String(), Pagination: &query.PageRequest{Limit: 2}}) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPrizesPaginated.GetPrizes()), 0) + + // Test PoolPrizes with wrong poolID + _, err = queryServer.PoolPrizes(ctx, &millionstypes.QueryPoolPrizesRequest{PoolId: 0}) + suite.Require().Error(err) + // Test PoolPrizes + poolPrizes, err := queryServer.PoolPrizes(ctx, &millionstypes.QueryPoolPrizesRequest{PoolId: 3}) + suite.Require().NoError(err) + suite.Require().Len(poolPrizes.GetPrizes(), 5) + // Test PoolPrizes with pagination + poolPrizesPaginated, err := queryServer.PoolPrizes(ctx, &millionstypes.QueryPoolPrizesRequest{PoolId: 3, Pagination: &query.PageRequest{Offset: 1, Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(poolPrizesPaginated.GetPrizes(), 2) + suite.Require().Equal(poolPrizes.GetPrizes()[1].PrizeId, poolPrizesPaginated.GetPrizes()[0].PrizeId) + suite.Require().Equal(poolPrizes.GetPrizes()[2].PrizeId, poolPrizesPaginated.GetPrizes()[1].PrizeId) + + // Test AccountPoolPrizes with wrong winnerAddr + _, err = queryServer.AccountPoolPrizes(ctx, &millionstypes.QueryAccountPoolPrizesRequest{WinnerAddress: "", PoolId: 1}) + suite.Require().Error(err) + // Test AccountPoolPrizes with wrong poolID + _, err = queryServer.AccountPoolPrizes(ctx, &millionstypes.QueryAccountPoolPrizesRequest{WinnerAddress: suite.addrs[0].String(), PoolId: 0}) + suite.Require().Error(err) + // Test AccountPoolPrizes + accountPoolPrizes, err := queryServer.AccountPoolPrizes(ctx, &millionstypes.QueryAccountPoolPrizesRequest{WinnerAddress: suite.addrs[0].String(), PoolId: 1}) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPoolPrizes.GetPrizes()), 0) + // Test AccountPoolPrizes with pagination + accountPoolPrizesPaginated, err := queryServer.AccountPoolPrizes(ctx, &millionstypes.QueryAccountPoolPrizesRequest{WinnerAddress: suite.addrs[0].String(), PoolId: 1, Pagination: &query.PageRequest{Limit: 2}}) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPoolPrizesPaginated.GetPrizes()), 0) + + // Test PoolDrawPrizes with wrong poolID + _, err = queryServer.PoolDrawPrizes(ctx, &millionstypes.QueryPoolDrawPrizesRequest{PoolId: 0, DrawId: 1}) + suite.Require().Error(err) + // Test PoolDrawPrizes with wrong drawID + _, err = queryServer.PoolDrawPrizes(ctx, &millionstypes.QueryPoolDrawPrizesRequest{PoolId: 1, DrawId: 0}) + suite.Require().Error(err) + // Test PoolDrawPrizes + poolDrawPrizes, err := queryServer.PoolDrawPrizes(ctx, &millionstypes.QueryPoolDrawPrizesRequest{PoolId: 1, DrawId: 1}) + suite.Require().NoError(err) + suite.Require().Len(poolDrawPrizes.GetPrizes(), 5) + // Test PoolDrawPrizes with pagination + poolDrawPrizesPaginated, err := queryServer.PoolDrawPrizes(ctx, &millionstypes.QueryPoolDrawPrizesRequest{PoolId: 1, DrawId: 1, Pagination: &query.PageRequest{Offset: 1, Limit: 2}}) + suite.Require().NoError(err) + suite.Require().Len(poolDrawPrizesPaginated.GetPrizes(), 2) + suite.Require().Equal(poolDrawPrizes.GetPrizes()[1].PrizeId, poolDrawPrizesPaginated.GetPrizes()[0].PrizeId) + suite.Require().Equal(poolDrawPrizes.GetPrizes()[2].PrizeId, poolDrawPrizesPaginated.GetPrizes()[1].PrizeId) + + // Test PoolDrawPrize with wrong poolID + _, err = queryServer.PoolDrawPrize(ctx, &millionstypes.QueryPoolDrawPrizeRequest{PoolId: 0, DrawId: 1, PrizeId: 1}) + suite.Require().Error(err) + // Test PoolDrawPrize with wrong drawID + _, err = queryServer.PoolDrawPrize(ctx, &millionstypes.QueryPoolDrawPrizeRequest{PoolId: 1, DrawId: 0, PrizeId: 1}) + suite.Require().Error(err) + // Test PoolDrawPrize with wrong prizeID + _, err = queryServer.PoolDrawPrize(ctx, &millionstypes.QueryPoolDrawPrizeRequest{PoolId: 1, DrawId: 1, PrizeId: 0}) + suite.Require().Error(err) + // Test PoolDrawPrize + poolDrawPrize, err := queryServer.PoolDrawPrize(ctx, &millionstypes.QueryPoolDrawPrizeRequest{PoolId: 1, DrawId: 1, PrizeId: 1}) + suite.Require().NoError(err) + suite.Require().Equal(poolDrawPrize.Prize.PrizeId, uint64(1)) + + // Test AccountPoolDrawPrizes with wrong winnerAddr + _, err = queryServer.AccountPoolDrawPrizes(ctx, &millionstypes.QueryAccountPoolDrawPrizesRequest{WinnerAddress: "", PoolId: 1, DrawId: 1}) + suite.Require().Error(err) + // Test AccountPoolDrawPrizes with wrong poolID + _, err = queryServer.AccountPoolDrawPrizes(ctx, &millionstypes.QueryAccountPoolDrawPrizesRequest{WinnerAddress: suite.addrs[1].String(), PoolId: 0, DrawId: 1}) + suite.Require().Error(err) + // Test AccountPoolDrawPrizes with wrong drawID + _, err = queryServer.AccountPoolDrawPrizes(ctx, &millionstypes.QueryAccountPoolDrawPrizesRequest{WinnerAddress: suite.addrs[1].String(), PoolId: 1, DrawId: 0}) + suite.Require().Error(err) + // Test AccountPoolDrawPrizes + accountPoolDrawPrizes, err := queryServer.AccountPoolDrawPrizes(ctx, &millionstypes.QueryAccountPoolDrawPrizesRequest{WinnerAddress: suite.addrs[1].String(), PoolId: 1, DrawId: 1}) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPoolDrawPrizes.GetPrizes()), 0) + // Test AccountPoolDrawPrizes with pagination + accountPoolDrawPrizesPaginated, err := queryServer.AccountPoolDrawPrizes(ctx, &millionstypes.QueryAccountPoolDrawPrizesRequest{WinnerAddress: suite.addrs[1].String(), PoolId: 1, DrawId: 1, Pagination: &query.PageRequest{Limit: 2}}) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPoolDrawPrizesPaginated.GetPrizes()), 0) +} + +// TestGRPC_Query_Withdrawal runs simple integration tests for withdrawals and pools +func (suite *KeeperTestSuite) TestGRPC_Query_Withdrawal() { + app := suite.app + ctx := suite.ctx + queryServer := millionskeeper.NewQueryServerImpl(*app.MillionsKeeper) + + nbrItems := 4 + // Test run generates + // - 5 pools + // - 5 accounts + // - 32 deposits + // - 6 withdrawals + for i := 0; i < nbrItems; i++ { + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + {PoolPercent: 50, Quantity: 4, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + + // Force the available pool prize + pool.AvailablePrizePool = sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaPrizepoolAddress), sdk.NewCoins(pool.AvailablePrizePool)) + suite.Require().NoError(err) + + app.MillionsKeeper.AddPool(ctx, pool) + + // Create deposits + for i := 0; i < nbrItems; i++ { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + State: millionstypes.DepositState_Success, + }) + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + DepositorAddress: suite.addrs[i].String(), + WinnerAddress: suite.addrs[i].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(500_000)), + State: millionstypes.DepositState_Success, + }) + } + } + + // For this test case, we get the deposits and take the first 6 to generate withdrawals + deposits := app.MillionsKeeper.ListDeposits(ctx) + deposits = deposits[:6] + for i, deposit := range deposits { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: suite.addrs[i].String(), + Amount: sdk.NewCoin(deposit.Amount.Denom, deposit.Amount.Amount), + State: millionstypes.WithdrawalState_IbcTransfer, + }) + } + + // Test Withdrawals + withdrawalRes, err := queryServer.Withdrawals(ctx, &millionstypes.QueryWithdrawalsRequest{}) + suite.Require().NoError(err) + suite.Require().Len(withdrawalRes.GetWithdrawals(), 6) + // Test Withdrawals with pagination + withdrawalResPaginated, err := queryServer.Withdrawals(ctx, &millionstypes.QueryWithdrawalsRequest{Pagination: &query.PageRequest{Offset: 1, Limit: 3}}) + suite.Require().NoError(err) + suite.Require().Len(withdrawalResPaginated.GetWithdrawals(), 3) + suite.Require().Equal(withdrawalRes.GetWithdrawals()[1].WithdrawalId, withdrawalResPaginated.GetWithdrawals()[0].WithdrawalId) + suite.Require().Equal(withdrawalRes.GetWithdrawals()[2].WithdrawalId, withdrawalResPaginated.GetWithdrawals()[1].WithdrawalId) + suite.Require().Equal(withdrawalRes.GetWithdrawals()[3].WithdrawalId, withdrawalResPaginated.GetWithdrawals()[2].WithdrawalId) + + // Test PoolWithdrawals with wrong poolID + _, err = queryServer.PoolWithdrawals(ctx, &millionstypes.QueryPoolWithdrawalsRequest{PoolId: 0}) + suite.Require().Error(err) + // Test PoolWithdrawals + poolWithdrawals, err := queryServer.PoolWithdrawals(ctx, &millionstypes.QueryPoolWithdrawalsRequest{PoolId: 1}) + suite.Require().NoError(err) + suite.Require().Len(poolWithdrawals.GetWithdrawals(), 6) + // Test PoolWithdrawals with pagination + poolWithdrawalsPaginated, err := queryServer.PoolWithdrawals(ctx, &millionstypes.QueryPoolWithdrawalsRequest{PoolId: 1, Pagination: &query.PageRequest{Offset: 1, Limit: 3}}) + suite.Require().NoError(err) + suite.Require().Len(poolWithdrawalsPaginated.GetWithdrawals(), 3) + suite.Require().Equal(poolWithdrawals.GetWithdrawals()[1].WithdrawalId, poolWithdrawalsPaginated.GetWithdrawals()[0].WithdrawalId) + suite.Require().Equal(poolWithdrawals.GetWithdrawals()[2].WithdrawalId, poolWithdrawalsPaginated.GetWithdrawals()[1].WithdrawalId) + suite.Require().Equal(poolWithdrawals.GetWithdrawals()[3].WithdrawalId, poolWithdrawalsPaginated.GetWithdrawals()[2].WithdrawalId) + + // Test PoolWithdrawal with wrong poolID + _, err = queryServer.PoolWithdrawal(ctx, &millionstypes.QueryPoolWithdrawalRequest{PoolId: 0}) + suite.Require().Error(err) + // Test PoolWithdrawal + poolWithdrawal, err := queryServer.PoolWithdrawal(ctx, &millionstypes.QueryPoolWithdrawalRequest{PoolId: 1, WithdrawalId: 1}) + suite.Require().NoError(err) + suite.Require().Equal(poolWithdrawal.Withdrawal.State, millionstypes.WithdrawalState_IbcTransfer) + + // Test AccountWithdrawals with wrong depositorAddr + _, err = queryServer.AccountWithdrawals(ctx, &millionstypes.QueryAccountWithdrawalsRequest{DepositorAddress: ""}) + suite.Require().Error(err) + // Test AccountWithdrawals + accountWithdrawals, err := queryServer.AccountWithdrawals(ctx, &millionstypes.QueryAccountWithdrawalsRequest{DepositorAddress: suite.addrs[0].String()}) + suite.Require().NoError(err) + suite.Require().Len(accountWithdrawals.GetWithdrawals(), 1) + // Test AccountWithdrawals with pagination + accountWithdrawalsPaginated, err := queryServer.AccountWithdrawals(ctx, &millionstypes.QueryAccountWithdrawalsRequest{DepositorAddress: suite.addrs[0].String(), Pagination: &query.PageRequest{Limit: 1}}) + suite.Require().NoError(err) + suite.Require().Len(accountWithdrawalsPaginated.GetWithdrawals(), 1) + suite.Require().Equal(accountWithdrawals.GetWithdrawals()[0].WithdrawalId, accountWithdrawalsPaginated.GetWithdrawals()[0].WithdrawalId) + + // Test AccountPoolWithdrawals with wrong depositorAddr + _, err = queryServer.AccountPoolWithdrawals(ctx, &millionstypes.QueryAccountPoolWithdrawalsRequest{DepositorAddress: "", PoolId: 1}) + suite.Require().Error(err) + // Test AccountPoolWithdrawals with wrong poolID + _, err = queryServer.AccountPoolWithdrawals(ctx, &millionstypes.QueryAccountPoolWithdrawalsRequest{DepositorAddress: suite.addrs[0].String(), PoolId: 0}) + suite.Require().Error(err) + // Test AccountPoolWithdrawals + accountPoolWithdrawals, err := queryServer.AccountPoolWithdrawals(ctx, &millionstypes.QueryAccountPoolWithdrawalsRequest{DepositorAddress: suite.addrs[0].String(), PoolId: 1}) + suite.Require().NoError(err) + suite.Require().Len(accountPoolWithdrawals.GetWithdrawals(), 1) + // Test AccountPoolWithdrawals with pagination + accountPoolWithdrawalsPaginated, err := queryServer.AccountPoolWithdrawals(ctx, &millionstypes.QueryAccountPoolWithdrawalsRequest{DepositorAddress: suite.addrs[0].String(), PoolId: 1, Pagination: &query.PageRequest{Limit: 1}}) + suite.Require().NoError(err) + suite.Require().Len(accountPoolWithdrawalsPaginated.GetWithdrawals(), 1) + suite.Require().Equal(accountPoolWithdrawals.GetWithdrawals()[0].WithdrawalId, accountPoolWithdrawalsPaginated.GetWithdrawals()[0].WithdrawalId) +} diff --git a/x/millions/keeper/grpc_query_withdrawal.go b/x/millions/keeper/grpc_query_withdrawal.go new file mode 100644 index 00000000..8ef7da41 --- /dev/null +++ b/x/millions/keeper/grpc_query_withdrawal.go @@ -0,0 +1,170 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k queryServer) Withdrawals(goCtx context.Context, req *types.QueryWithdrawalsRequest) (*types.QueryWithdrawalsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + withdrawalStore := prefix.NewStore(store, types.GetWithdrawalsKey()) + + // Make the paginated query + var withdrawals []types.Withdrawal + pageRes, err := query.Paginate(withdrawalStore, req.Pagination, func(key []byte, value []byte) error { + var withdrawal types.Withdrawal + if err := k.cdc.Unmarshal(value, &withdrawal); err != nil { + return err + } + + withdrawals = append(withdrawals, withdrawal) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryWithdrawalsResponse{Withdrawals: withdrawals, Pagination: pageRes}, nil +} + +func (k queryServer) PoolWithdrawals(goCtx context.Context, req *types.QueryPoolWithdrawalsRequest) (*types.QueryWithdrawalsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + withdrawalStore := prefix.NewStore(store, types.GetPoolWithdrawalsKey(req.GetPoolId())) + + // Make the paginated query + var withdrawals []types.Withdrawal + pageRes, err := query.Paginate(withdrawalStore, req.Pagination, func(key []byte, value []byte) error { + var withdrawal types.Withdrawal + if err := k.cdc.Unmarshal(value, &withdrawal); err != nil { + return err + } + + withdrawals = append(withdrawals, withdrawal) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryWithdrawalsResponse{Withdrawals: withdrawals, Pagination: pageRes}, nil +} + +func (k queryServer) PoolWithdrawal(goCtx context.Context, req *types.QueryPoolWithdrawalRequest) (*types.QueryWithdrawalResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Make sure context request is valid + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + withdrawal, err := k.GetPoolWithdrawal(ctx, req.GetPoolId(), req.GetWithdrawalId()) + if err != nil { + return &types.QueryWithdrawalResponse{}, err + } + + return &types.QueryWithdrawalResponse{Withdrawal: withdrawal}, nil +} + +func (k queryServer) AccountWithdrawals(goCtx context.Context, req *types.QueryAccountWithdrawalsRequest) (*types.QueryWithdrawalsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetDepositorAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + store := ctx.KVStore(k.storeKey) + withdrawalStore := prefix.NewStore(store, types.GetAccountWithdrawalsKey(addr)) + + // Make the paginated query + var withdrawals []types.Withdrawal + pageRes, err := query.Paginate(withdrawalStore, req.Pagination, func(key []byte, value []byte) error { + var withdrawal types.Withdrawal + if err := k.cdc.Unmarshal(value, &withdrawal); err != nil { + return err + } + + withdrawals = append(withdrawals, withdrawal) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryWithdrawalsResponse{Withdrawals: withdrawals, Pagination: pageRes}, nil +} + +func (k queryServer) AccountPoolWithdrawals(goCtx context.Context, req *types.QueryAccountPoolWithdrawalsRequest) (*types.QueryWithdrawalsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + addr, err := sdk.AccAddressFromBech32(req.GetDepositorAddress()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if !k.HasPool(ctx, req.PoolId) { + return nil, status.Error(codes.NotFound, types.ErrPoolNotFound.Error()) + } + + store := ctx.KVStore(k.storeKey) + withdrawalStore := prefix.NewStore(store, types.GetAccountPoolWithdrawalsKey(addr, req.GetPoolId())) + + // Make the paginated query + var withdrawals []types.Withdrawal + pageRes, err := query.Paginate(withdrawalStore, req.Pagination, func(key []byte, value []byte) error { + var withdrawal types.Withdrawal + if err := k.cdc.Unmarshal(value, &withdrawal); err != nil { + return err + } + + withdrawals = append(withdrawals, withdrawal) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryWithdrawalsResponse{Withdrawals: withdrawals, Pagination: pageRes}, nil +} diff --git a/x/millions/keeper/keeper.go b/x/millions/keeper/keeper.go new file mode 100644 index 00000000..ec43a495 --- /dev/null +++ b/x/millions/keeper/keeper.go @@ -0,0 +1,101 @@ +package keeper + +import ( + "fmt" + icquerieskeeper "github.com/lum-network/chain/x/icqueries/keeper" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + account "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + icacontrollerkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" + ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper" + ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" + ibctmtypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/tendermint/tendermint/libs/log" + + icacallbackskeeper "github.com/lum-network/chain/x/icacallbacks/keeper" + "github.com/lum-network/chain/x/millions/types" +) + +type Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + paramSpace paramtypes.Subspace + scopedKeeper capabilitykeeper.ScopedKeeper + AccountKeeper account.AccountKeeper + IBCKeeper ibckeeper.Keeper + IBCTransferKeeper ibctransferkeeper.Keeper + ICAControllerKeeper icacontrollerkeeper.Keeper + ICACallbacksKeeper icacallbackskeeper.Keeper + ICQueriesKeeper icquerieskeeper.Keeper + BankKeeper bankkeeper.Keeper + DistributionKeeper *distributionkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper +} + +// NewKeeper Initialize the keeper with the base params +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, scopedKeeper capabilitykeeper.ScopedKeeper, + accountKeeper account.AccountKeeper, ibcKeeper ibckeeper.Keeper, ibcTransferKeeper ibctransferkeeper.Keeper, icaKeeper icacontrollerkeeper.Keeper, icaCallbacksKeeper icacallbackskeeper.Keeper, + icqueriesKeeper icquerieskeeper.Keeper, bank bankkeeper.Keeper, distribution *distributionkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + paramSpace: paramSpace, + scopedKeeper: scopedKeeper, + AccountKeeper: accountKeeper, + IBCKeeper: ibcKeeper, + IBCTransferKeeper: ibcTransferKeeper, + ICAControllerKeeper: icaKeeper, + ICACallbacksKeeper: icaCallbacksKeeper, + ICQueriesKeeper: icqueriesKeeper, + BankKeeper: bank, + DistributionKeeper: distribution, + StakingKeeper: stakingKeeper, + } +} + +// Logger Return a keeper logger instance +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// ClaimCapability claims the channel capability passed via the OnOpenChanInit callback +func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { + return k.scopedKeeper.ClaimCapability(ctx, cap, name) +} + +// GetChainID Return the chain ID fetched from the ibc connection layer +func (k Keeper) GetChainID(ctx sdk.Context, connectionID string) (string, error) { + conn, found := k.IBCKeeper.ConnectionKeeper.GetConnection(ctx, connectionID) + if !found { + return "", fmt.Errorf(fmt.Sprintf("invalid connection id, %s not found", connectionID)) + } + clientState, found := k.IBCKeeper.ClientKeeper.GetClientState(ctx, conn.ClientId) + if !found { + return "", fmt.Errorf(fmt.Sprintf("client id %s not found for connection %s", conn.ClientId, connectionID)) + } + client, ok := clientState.(*ibctmtypes.ClientState) + if !ok { + return "", fmt.Errorf(fmt.Sprintf("invalid client state for client %s on connection %s", conn.ClientId, connectionID)) + } + + return client.ChainId, nil +} + +func (k Keeper) GetConnectionID(ctx sdk.Context, portId string) (string, error) { + icas := k.ICAControllerKeeper.GetAllInterchainAccounts(ctx) + for _, ica := range icas { + if ica.PortId == portId { + return ica.ConnectionId, nil + } + } + return "", fmt.Errorf(fmt.Sprintf("portId %s has no associated connectionId", portId)) +} diff --git a/x/millions/keeper/keeper_blockers.go b/x/millions/keeper/keeper_blockers.go new file mode 100644 index 00000000..cc7e0fd9 --- /dev/null +++ b/x/millions/keeper/keeper_blockers.go @@ -0,0 +1,165 @@ +package keeper + +import ( + "fmt" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// BlockPoolUpdates runs all pool updates and draws +// Called in each BeginBlock +func (k Keeper) BlockPoolUpdates(ctx sdk.Context) (successCount, errorCount int) { + logger := k.Logger(ctx).With("ctx", "blocker_pools") + + // Launch all mature draws + poolsToDraw := k.ListPoolsToDraw(ctx) + for _, pool := range poolsToDraw { + // Initiate a dedicated cache context to avoid creating draws if they fail at their very creation + cacheCtx, writeCache := ctx.CacheContext() + draw, err := k.LaunchNewDraw(cacheCtx, pool.GetPoolId()) + if err != nil { + // Do not commit changes in case of failure + logger.Error( + fmt.Sprintf("failed to launch draw: %v", err), + "pool_id", pool.PoolId, + "draw_id", pool.GetNextDrawId(), + ) + errorCount++ + } else { + // Commit succesful changes (draw and pool updates) + logger.Info( + "draw launched with success", + "pool_id", pool.PoolId, + "draw_id", pool.GetNextDrawId(), + ) + writeCache() + successCount++ + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeNewDraw, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(draw.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDrawID, strconv.FormatUint(draw.DrawId, 10)), + ), + }) + } + } + if successCount+errorCount > 0 { + logger.Info( + "draws launched", + "nbr_success", successCount, + "nbr_error", errorCount, + ) + } + return +} + +// BlockPrizeUpdates runs all prize updates (clawback) +// Called in each EndBlock +func (k Keeper) BlockPrizeUpdates(ctx sdk.Context) (successCount, errorCount int) { + logger := k.Logger(ctx).With("ctx", "blocker_prizes") + + // Expired unclaimed prizes + prizesIDsToClawback := k.DequeueEPCBQueue(ctx, ctx.BlockTime()) + for _, pid := range prizesIDsToClawback { + prize, err := k.GetPoolDrawPrize(ctx, pid.PoolId, pid.DrawId, pid.PrizeId) + if err == nil { + // Fetch master entity and ignore not found issues since we cannot recover it + if err := k.ClawBackPrize(ctx, prize.PoolId, prize.DrawId, prize.PrizeId); err != nil { + logger.Error( + fmt.Sprintf("failed to clawback draw: %v", err), + "pool_id", prize.PoolId, + "draw_id", prize.DrawId, + "prize_id", prize.PrizeId, + ) + errorCount++ + } else { + successCount++ + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeClawbackPrize, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(prize.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDrawID, strconv.FormatUint(prize.DrawId, 10)), + sdk.NewAttribute(types.AttributeKeyPrizeID, strconv.FormatUint(prize.PrizeId, 10)), + sdk.NewAttribute(types.AttributeKeyWinner, prize.WinnerAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, prize.Amount.String()), + ), + }) + } + } else { + logger.Error( + fmt.Sprintf("failed to acquire prize: %v", err), + "pool_id", pid.PoolId, + "draw_id", pid.DrawId, + "prize_id", pid.PrizeId, + ) + errorCount++ + } + } + if successCount+errorCount > 0 { + logger.Info( + "prizes clawed back", + "nbr_success", successCount, + "nbr_error", errorCount, + ) + } + return +} + +// BlockWithdrawalUpdates runs all matured withdrawals updates (transfer post unbonding) +// Called in each EndBlock +func (k Keeper) BlockWithdrawalUpdates(ctx sdk.Context) (successCount, errorCount int) { + logger := k.Logger(ctx).With("ctx", "blocker_withdrawals") + + // Matured withdrawals + withdrawalsIDs := k.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime()) + for _, wid := range withdrawalsIDs { + withdrawal, err := k.GetPoolWithdrawal(ctx, wid.PoolId, wid.WithdrawalId) + // Fetch master entity and ignore not found issues since we cannot recover it + if err == nil && withdrawal.State == types.WithdrawalState_IcaUnbonding { + // Initiate a dedicated cache context to avoid partial withdrawal commits + cacheCtx, writeCache := ctx.CacheContext() + k.UpdateWithdrawalStatus(cacheCtx, withdrawal.PoolId, withdrawal.WithdrawalId, types.WithdrawalState_IbcTransfer, nil, false) + if err := k.TransferWithdrawalToLocalChain(cacheCtx, withdrawal.PoolId, withdrawal.WithdrawalId); err != nil { + logger.Error( + fmt.Sprintf("failed to launch transfer withdrawal amount to local zone: %v", err), + "pool_id", withdrawal.PoolId, + "withdrawal_id", withdrawal.WithdrawalId, + ) + // Commit failing state using base context to make retries possible + k.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, types.WithdrawalState_IbcTransfer, nil, true) + errorCount++ + } else { + // Commit succesful changes + writeCache() + successCount++ + } + } else { + logger.Error( + fmt.Sprintf("failed to acquire withdrawal: %v", err), + "pool_id", wid.PoolId, + "withdrawal_id", wid.WithdrawalId, + ) + errorCount++ + } + } + if successCount+errorCount > 0 { + logger.Info( + "withdrawals transfers started", + "nbr_success", successCount, + "nbr_error", errorCount, + ) + } + return +} diff --git a/x/millions/keeper/keeper_blockers_test.go b/x/millions/keeper/keeper_blockers_test.go new file mode 100644 index 00000000..a2cea2fa --- /dev/null +++ b/x/millions/keeper/keeper_blockers_test.go @@ -0,0 +1,363 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestBlockers_PoolUpdates tests block based pool updates (draw launches) +func (suite *KeeperTestSuite) TestBlockers_PoolUpdates() { + app := suite.app + ctx := suite.ctx.WithBlockHeight(0).WithBlockTime(time.Now().UTC()) + + // Pool1 should always be able to Draw + poolID1 := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID1, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + + // Pool2 should not be able to create any draw (invalid hardset validators configuration) + poolID2 := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta2 := 2 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID2, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta2), + DrawDelta: drawDelta2, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + Validators: map[string]*millionstypes.PoolValidator{ + "lumvaloper1qx2dts3tglxcu0jh47k7ghstsn4nactufgmmlk": { + OperatorAddress: "lumvaloper1qx2dts3tglxcu0jh47k7ghstsn4nactufgmmlk", + IsEnabled: true, + BondedAmount: math.NewInt(1_000_000), + }, + }, + })) + + // Pool3 should be able to draw (until we hardset faulty draw config) + poolID3 := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta3 := 3 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID3, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta3), + DrawDelta: drawDelta3, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + + // We should have 3 pools and 0 draws + suite.Require().Len(app.MillionsKeeper.ListPools(ctx), 3) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 0) + + // Block pool updates should have no effect until a pool is ready to draw + sc, ec := app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 0) + ctx = ctx.WithBlockHeight(1).WithBlockTime(ctx.BlockTime().Add(60 * time.Second)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 0) + + // Shoud launch pool1 draw1 with success + ctx = ctx.WithBlockHeight(2).WithBlockTime(ctx.BlockTime().Add(drawDelta1)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(1, sc) + suite.Require().Equal(0, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 1) + p1, err := app.MillionsKeeper.GetPool(ctx, poolID1) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+2, p1.NextDrawId) + suite.Require().NotNil(p1.LastDrawCreatedAt) + suite.Require().Equal(ctx.BlockTime(), *p1.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Success, p1.LastDrawState) + p2, err := app.MillionsKeeper.GetPool(ctx, poolID2) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+1, p2.NextDrawId) + suite.Require().Nil(p2.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Unspecified, p2.LastDrawState) + p3, err := app.MillionsKeeper.GetPool(ctx, poolID3) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+1, p3.NextDrawId) + suite.Require().Nil(p3.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Unspecified, p3.LastDrawState) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 1) + ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(60 * time.Second)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 1) + + // Should trigger p1d2, p2d1 (error without draw creation) + ctx = ctx.WithBlockHeight(4).WithBlockTime(ctx.BlockTime().Add(1 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(1, sc) + suite.Require().Equal(1, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 2) + p1, err = app.MillionsKeeper.GetPool(ctx, poolID1) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+3, p1.NextDrawId) + suite.Require().NotNil(p1.LastDrawCreatedAt) + suite.Require().Equal(ctx.BlockTime(), *p1.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Success, p1.LastDrawState) + p2, err = app.MillionsKeeper.GetPool(ctx, poolID2) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+1, p2.NextDrawId) + suite.Require().Nil(p2.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Unspecified, p2.LastDrawState) + p3, err = app.MillionsKeeper.GetPool(ctx, poolID3) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+1, p3.NextDrawId) + suite.Require().Nil(p3.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Unspecified, p3.LastDrawState) + + // Should trigger p2d1 (error without draw creation) + ctx = ctx.WithBlockHeight(5).WithBlockTime(ctx.BlockTime().Add(60 * time.Second)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(1, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 2) + + // Should trigger p1d3, p2d1 (error without draw creation) and p3d1 + ctx = ctx.WithBlockHeight(6).WithBlockTime(ctx.BlockTime().Add(1 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(2, sc) + suite.Require().Equal(1, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 4) + p1, err = app.MillionsKeeper.GetPool(ctx, poolID1) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+4, p1.NextDrawId) + suite.Require().NotNil(p1.LastDrawCreatedAt) + suite.Require().Equal(ctx.BlockTime(), *p1.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Success, p1.LastDrawState) + p2, err = app.MillionsKeeper.GetPool(ctx, poolID2) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+1, p2.NextDrawId) + suite.Require().Nil(p2.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Unspecified, p2.LastDrawState) + p3, err = app.MillionsKeeper.GetPool(ctx, poolID3) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.UnknownID+2, p3.NextDrawId) + suite.Require().NotNil(p3.LastDrawCreatedAt) + suite.Require().Equal(ctx.BlockTime(), *p3.LastDrawCreatedAt) + suite.Require().Equal(millionstypes.DrawState_Success, p3.LastDrawState) + + // Should trigger p2d1 (error without draw creation) + ctx = ctx.WithBlockHeight(7).WithBlockTime(ctx.BlockTime().Add(60 * time.Second)) + sc, ec = app.MillionsKeeper.BlockPoolUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(1, ec) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 4) +} + +// TestBlockers_PrizeUpdates tests block based prizes updates (clawbacks) +func (suite *KeeperTestSuite) TestBlockers_PrizeUpdates() { + app := suite.app + ctx := suite.ctx.WithBlockHeight(0).WithBlockTime(time.Now().UTC()) + + // Add pool with ID 1 to make its prizes work + poolID1 := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID1, + })) + app.MillionsKeeper.SetPoolDraw(ctx, millionstypes.Draw{PoolId: poolID1, DrawId: millionstypes.UnknownID + 1}) + + // Add expirable prizes with various expiration times + for i := 0; i < 10; i++ { + for j := 0; j < 10; j++ { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: uint64(i + 1), + DrawId: millionstypes.UnknownID + 1, + PrizeId: suite.app.MillionsKeeper.GetNextPrizeIdAndIncrement(ctx), + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Hour), + }) + } + } + + // Should clawback the first 10 prizes with success (poolID1 has been created) + ctx = ctx.WithBlockHeight(1).WithBlockTime(ctx.BlockTime().Add(1 * time.Second)) + sc, ec := app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(10, sc) + suite.Require().Equal(0, ec) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + + // Should clawback the next 10 prizes (should silently ignore the errors since pool will not be found) + ctx = ctx.WithBlockHeight(2).WithBlockTime(ctx.BlockTime().Add(1 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(10, ec) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + + // Should clawback the next 50 prizes + ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(5 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(50, ec) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + + // Should clawback all remaining prizes + ctx = ctx.WithBlockHeight(4).WithBlockTime(ctx.BlockTime().Add(5 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(30, ec) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + ctx = ctx.WithBlockHeight(5).WithBlockTime(ctx.BlockTime().Add(10 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + ctx = ctx.WithBlockHeight(6).WithBlockTime(ctx.BlockTime().Add(-100 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockPrizeUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) +} + +// TestBlockers_WithdrawalUpdates tests block based withdrawal updates (unbonding completed) +func (suite *KeeperTestSuite) TestBlockers_WithdrawalUpdates() { + app := suite.app + ctx := suite.ctx.WithBlockHeight(0).WithBlockTime(time.Now().UTC()) + + // Add pool with ID 1 to make its withdrawals work + p1 := newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx), + }) + app.MillionsKeeper.AddPool(ctx, p1) + + // Add pool with ID 2 to make withdrawal work on pool level but fail at transfer level + p2 := newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx), + IcaDepositAddress: suite.moduleAddrs[4].String(), + }) + app.MillionsKeeper.AddPool(ctx, p2) + + // Add withdrawals with various unbonding times + for i := 0; i < 10; i++ { + for j := 0; j < 10; j++ { + t := ctx.BlockTime().Add(time.Duration(i) * time.Hour) + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: uint64(i + 1), + DepositId: millionstypes.UnknownID + 1, + WithdrawalId: app.MillionsKeeper.GetNextWithdrawalIdAndIncrement(ctx), + State: millionstypes.WithdrawalState_IcaUnbonding, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1)), + UnbondingEndsAt: &t, + }) + } + } + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(p1.IcaDepositAddress), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1_000)))) + suite.Require().NoError(err) + + // Should complete the first 10 withdrawals with success (poolID1 has been created and funded) + ctx = ctx.WithBlockHeight(1).WithBlockTime(ctx.BlockTime().Add(1 * time.Second)) + sc, ec := app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(10, sc) + suite.Require().Equal(0, ec) + // State updates should have been committed (verify first entity of the batch) + // After successful completion we delete the withdrawal + _, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, p1.PoolId, millionstypes.UnknownID+1) + suite.Require().ErrorIs(err, millionstypes.ErrWithdrawalNotFound) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + + // Should complete the next 10 withdrawals (should silently ignore the errors since pool module account is not funded for the transfers) + ctx = ctx.WithBlockHeight(2).WithBlockTime(ctx.BlockTime().Add(1 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(10, ec) + // State updates should have been committed (verify first entity of the batch) + w, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, p2.PoolId, millionstypes.UnknownID+11) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.WithdrawalState_Failure, w.State) + suite.Require().Equal(millionstypes.WithdrawalState_IbcTransfer, w.ErrorState) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + + // Should complete the next 50 withdrawals (should silently ignore the errors since pool will not be found) + ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(5 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(50, ec) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + + // Should complete all remaining withdrawals + ctx = ctx.WithBlockHeight(4).WithBlockTime(ctx.BlockTime().Add(5 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(30, ec) + + // Should do nothing + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + ctx = ctx.WithBlockHeight(5).WithBlockTime(ctx.BlockTime().Add(10 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) + ctx = ctx.WithBlockHeight(6).WithBlockTime(ctx.BlockTime().Add(-100 * time.Hour)) + sc, ec = app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + suite.Require().Equal(0, sc) + suite.Require().Equal(0, ec) +} diff --git a/x/millions/keeper/keeper_deposit.go b/x/millions/keeper/keeper_deposit.go new file mode 100644 index 00000000..f129a8fd --- /dev/null +++ b/x/millions/keeper/keeper_deposit.go @@ -0,0 +1,462 @@ +package keeper + +import ( + "fmt" + + gogotypes "github.com/gogo/protobuf/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + "github.com/lum-network/chain/x/millions/types" +) + +// TransferDepositToNativeChain Transfer a deposit to a native chain +// - wait for the ICA callback to move to OnTransferDepositToNativeChainCompleted +// - or go to OnTransferDepositToNativeChainCompleted directly if local zone +func (k Keeper) TransferDepositToNativeChain(ctx sdk.Context, poolID uint64, depositID uint64) error { + logger := k.Logger(ctx).With("ctx", "deposit_transfer") + + // Acquire pool config + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + if pool.IsLocalZone(ctx) { + return k.OnTransferDepositToNativeChainCompleted(ctx, poolID, depositID, false) + } + + // Acquire the deposit + deposit, err := k.GetPoolDeposit(ctx, poolID, depositID) + if err != nil { + return err + } + if deposit.State != types.DepositState_IbcTransfer { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DepositState_IbcTransfer.String(), deposit.State.String()) + } + + // Construct our callback + transferToNativeCallback := types.TransferToNativeCallback{ + PoolId: poolID, + DepositId: depositID, + } + marshalledCallbackData, err := k.MarshalTransferToNativeCallbackArgs(ctx, transferToNativeCallback) + if err != nil { + return err + } + + // Request funds transfer + msg, msgResponse, err := k.TransferAmountFromPoolToNativeChain(ctx, poolID, deposit.GetAmount()) + if err != nil { + // Return with error here since it is the first operation and nothing needs to be saved to state + logger.Error( + fmt.Sprintf("failed to dispatch IBC transfer: %v", err), + "pool_id", poolID, + "deposit_id", depositID, + "chain_id", pool.GetChainId(), + "sequence", msgResponse.GetSequence(), + ) + return err + } + logger.Debug( + "IBC transfer dispatched", + "pool_id", poolID, + "deposit_id", depositID, + "chain_id", pool.GetChainId(), + "sequence", msgResponse.GetSequence(), + ) + + // Store the callback data + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(msg.SourcePort, msg.SourceChannel, msgResponse.GetSequence()), + PortId: msg.SourcePort, + ChannelId: msg.SourceChannel, + Sequence: msgResponse.GetSequence(), + CallbackId: ICACallbackID_TransferToNative, + CallbackArgs: marshalledCallbackData, + } + k.ICACallbacksKeeper.SetCallbackData(ctx, callback) + + return nil +} + +// OnTransferDepositToNativeChainCompleted Acknowledge the IBC transfer to the native chain response +// then moves to DelegateDepositOnNativeChain in case of success +func (k Keeper) OnTransferDepositToNativeChainCompleted(ctx sdk.Context, poolID uint64, depositID uint64, isError bool) error { + // Acquire the deposit + deposit, err := k.GetPoolDeposit(ctx, poolID, depositID) + if err != nil { + return err + } + + // Verify deposit state + if deposit.State != types.DepositState_IbcTransfer { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DepositState_IbcTransfer.String(), deposit.State.String()) + } + + if isError { + k.UpdateDepositStatus(ctx, poolID, depositID, types.DepositState_IbcTransfer, true) + return nil + } + + k.UpdateDepositStatus(ctx, poolID, depositID, types.DepositState_IcaDelegate, false) + return k.DelegateDepositOnNativeChain(ctx, poolID, depositID) +} + +// DelegateDepositOnNativeChain Delegates a deposit to the native chain validators +// - wait for the ICA callback to move to OnDelegateDepositOnNativeChainCompleted +// - or go to OnDelegateDepositOnNativeChainCompleted directly if local zone +func (k Keeper) DelegateDepositOnNativeChain(ctx sdk.Context, poolID uint64, depositID uint64) error { + logger := k.Logger(ctx).With("ctx", "deposit_delegate") + + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + + deposit, err := k.GetPoolDeposit(ctx, poolID, depositID) + if err != nil { + return err + } + if deposit.State != types.DepositState_IcaDelegate { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DepositState_IcaDelegate.String(), deposit.State.String()) + } + + // Prepare delegations split + splits := pool.ComputeSplitDelegations(ctx, deposit.GetAmount().Amount) + if len(splits) == 0 { + return types.ErrPoolEmptySplitDelegations + } + + // If pool is local, we just process operation in place + // Otherwise we trigger IBC / ICA transactions + if pool.IsLocalZone(ctx) { + for _, split := range splits { + valAddr, err := sdk.ValAddressFromBech32(split.ValidatorAddress) + if err != nil { + return err + } + validator, found := k.StakingKeeper.GetValidator(ctx, valAddr) + if !found { + return errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "%s", valAddr.String()) + } + if _, err := k.StakingKeeper.Delegate( + ctx, + sdk.MustAccAddressFromBech32(pool.GetIcaDepositAddress()), + split.Amount, + stakingtypes.Unbonded, + validator, + true, + ); err != nil { + return errorsmod.Wrapf(err, "%s", valAddr.String()) + } + } + return k.OnDelegateDepositOnNativeChainCompleted(ctx, poolID, depositID, splits, false) + } + + // Construct our callback data + callbackData := types.DelegateCallback{ + PoolId: poolID, + DepositId: depositID, + SplitDelegations: splits, + } + marshalledCallbackData, err := k.MarshalDelegateCallbackArgs(ctx, callbackData) + if err != nil { + return err + } + + // Build delegation tx + var msgs []sdk.Msg + for _, split := range splits { + msgs = append(msgs, &stakingtypes.MsgDelegate{ + DelegatorAddress: pool.GetIcaDepositAddress(), + ValidatorAddress: split.ValidatorAddress, + Amount: sdk.NewCoin(pool.NativeDenom, split.Amount), + }) + } + + // Dispatch our message with a timeout of 30 minutes in nanos + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + types.IBCTransferTimeoutNanos + sequence, err := k.BroadcastICAMessages(ctx, poolID, types.ICATypeDeposit, msgs, timeoutTimestamp, ICACallbackID_Delegate, marshalledCallbackData) + if err != nil { + // Save error state since we cannot simply recover from a failure at this stage + // A subsequent call to DepositRetry will be made possible by setting an error state and not returning an error here + logger.Error( + fmt.Sprintf("failed to dispatch ICA delegation: %v", err), + "pool_id", poolID, + "deposit_id", depositID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return k.OnDelegateDepositOnNativeChainCompleted(ctx, poolID, depositID, splits, true) + } + logger.Debug( + "ICA delegation dispatched", + "pool_id", poolID, + "deposit_id", depositID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return nil +} + +// OnDelegateDepositOnNativeChainCompleted Acknowledge the ICA delegate to the native chain validators response +func (k Keeper) OnDelegateDepositOnNativeChainCompleted(ctx sdk.Context, poolID uint64, depositID uint64, splits []*types.SplitDelegation, isError bool) error { + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + deposit, err := k.GetPoolDeposit(ctx, poolID, depositID) + if err != nil { + return err + } + + // Verify deposit state + if deposit.State != types.DepositState_IcaDelegate { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DepositState_IcaDelegate.String(), deposit.State.String()) + } + + if isError { + k.UpdateDepositStatus(ctx, poolID, depositID, types.DepositState_IcaDelegate, true) + return nil + } + + // Update validators + pool.ApplySplitDelegate(ctx, splits) + k.updatePool(ctx, &pool) + k.UpdateDepositStatus(ctx, poolID, depositID, types.DepositState_Success, false) + return nil +} + +// GetNextDepositID gets the next deposit ID +func (k Keeper) GetNextDepositID(ctx sdk.Context) uint64 { + store := ctx.KVStore(k.storeKey) + nextDepositId := gogotypes.UInt64Value{} + + b := store.Get(types.NextDepositPrefix) + if b == nil { + panic(fmt.Errorf("getting at key (%v) should not have been nil", types.NextDepositPrefix)) + } + k.cdc.MustUnmarshal(b, &nextDepositId) + return nextDepositId.GetValue() +} + +// GetNextDepositIdAndIncrement gets the next deposit ID and store the incremented ID +func (k Keeper) GetNextDepositIdAndIncrement(ctx sdk.Context) uint64 { + nextDepositId := k.GetNextDepositID(ctx) + k.SetNextDepositID(ctx, nextDepositId+1) + return nextDepositId +} + +// SetNextDepositID sets next deposit ID +func (k Keeper) SetNextDepositID(ctx sdk.Context, depositId uint64) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: depositId}) + store.Set(types.NextDepositPrefix, bz) +} + +// GetPoolDeposit returns a deposit by ID for a given poolID +func (k Keeper) GetPoolDeposit(ctx sdk.Context, poolID uint64, depositID uint64) (types.Deposit, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetPoolDepositKey(poolID, depositID)) + if bz == nil { + return types.Deposit{}, types.ErrDepositNotFound + } + + var deposit types.Deposit + if err := k.cdc.Unmarshal(bz, &deposit); err != nil { + return types.Deposit{}, err + } + + return deposit, nil +} + +// AddDeposit adds a deposit to a pool and account +// A new depositID is generated if not provided +// - adds it to the pool {pool_id, deposit_id} +// - adds it to the account {address, pool_id, deposit_id} deposits +func (k Keeper) AddDeposit(ctx sdk.Context, deposit *types.Deposit) { + // Automatically affect ID if missing + if deposit.GetDepositId() == types.UnknownID { + deposit.DepositId = k.GetNextDepositIdAndIncrement(ctx) + } + // Ensure payload is valid + if err := deposit.ValidateBasic(); err != nil { + panic(err) + } + // Ensure we never override an existing entity + if _, err := k.GetPoolDeposit(ctx, deposit.GetPoolId(), deposit.GetDepositId()); err == nil { + panic(errorsmod.Wrapf(types.ErrEntityOverride, "ID %d", deposit.GetDepositId())) + } + + isFirstAccountDeposit := !k.hasPoolDeposit(ctx, deposit.DepositorAddress, deposit.PoolId) + + // Update pool deposits + k.setPoolDeposit(ctx, deposit) + + // Update account deposits + k.setAccountDeposit(ctx, deposit) + + // Update pool TVL and Depositors Count + pool, err := k.GetPool(ctx, deposit.PoolId) + if err != nil { + panic(err) + } + pool.TvlAmount = pool.TvlAmount.Add(deposit.GetAmount().Amount) + if deposit.IsSponsor { + if pool.SponsorshipAmount.IsNil() { + pool.SponsorshipAmount = sdk.ZeroInt() + } + pool.SponsorshipAmount = pool.SponsorshipAmount.Add(deposit.GetAmount().Amount) + } + + if isFirstAccountDeposit { + // First deposit for account added + pool.DepositorsCount++ + } + + k.updatePool(ctx, &pool) +} + +// RemoveDeposit removes a deposit from a pool +// - removes it from the {pool_id, deposit_id} +// - removes it from the {address, pool_id, deposit_id} deposits +func (k Keeper) RemoveDeposit(ctx sdk.Context, deposit *types.Deposit) { + // Ensure payload is valid + if err := deposit.ValidateBasic(); err != nil { + panic(err) + } + store := ctx.KVStore(k.storeKey) + + addr := sdk.MustAccAddressFromBech32(deposit.DepositorAddress) + store.Delete(types.GetPoolDepositKey(deposit.PoolId, deposit.DepositId)) + store.Delete(types.GetAccountPoolDepositKey(addr, deposit.PoolId, deposit.DepositId)) + + // Update pool TVL and Depositors Count + pool, err := k.GetPool(ctx, deposit.PoolId) + if err != nil { + panic(err) + } + pool.TvlAmount = pool.TvlAmount.Sub(deposit.GetAmount().Amount) + if deposit.IsSponsor { + pool.SponsorshipAmount = pool.SponsorshipAmount.Sub(deposit.GetAmount().Amount) + } + + if !k.hasPoolDeposit(ctx, deposit.DepositorAddress, deposit.PoolId) { + // Last deposit for account removed + pool.DepositorsCount-- + } + + k.updatePool(ctx, &pool) +} + +// UpdateDepositStatus Update a given deposit status by its ID +func (k Keeper) UpdateDepositStatus(ctx sdk.Context, poolID uint64, depositID uint64, status types.DepositState, isError bool) { + deposit, err := k.GetPoolDeposit(ctx, poolID, depositID) + if err != nil { + panic(err) + } + + if isError { + deposit.State = types.DepositState_Failure + deposit.ErrorState = status + } else { + deposit.State = status + deposit.ErrorState = types.DepositState_Unspecified + } + + deposit.UpdatedAtHeight = ctx.BlockHeight() + deposit.UpdatedAt = ctx.BlockTime() + k.setAccountDeposit(ctx, &deposit) + k.setPoolDeposit(ctx, &deposit) +} + +// setPoolDeposit sets a deposit to the pool deposit key +func (k Keeper) setPoolDeposit(ctx sdk.Context, deposit *types.Deposit) { + store := ctx.KVStore(k.storeKey) + key := types.GetPoolDepositKey(deposit.PoolId, deposit.DepositId) + encodedDeposit := k.cdc.MustMarshal(deposit) + store.Set(key, encodedDeposit) +} + +// setAccountDeposit set the deposit for the Account deposit key +func (k Keeper) setAccountDeposit(ctx sdk.Context, deposit *types.Deposit) { + store := ctx.KVStore(k.storeKey) + depositorAddress := sdk.MustAccAddressFromBech32(deposit.DepositorAddress) + key := types.GetAccountPoolDepositKey(depositorAddress, deposit.PoolId, deposit.DepositId) + encodedDeposit := k.cdc.MustMarshal(deposit) + store.Set(key, encodedDeposit) +} + +// hasPoolDeposit returns whether or not an account has at least one deposit for a given pool +func (k Keeper) hasPoolDeposit(ctx sdk.Context, address string, poolID uint64) bool { + addr := sdk.MustAccAddressFromBech32(address) + + kvStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(kvStore, types.GetAccountPoolDepositsKey(addr, poolID)) + + defer iterator.Close() + return iterator.Valid() +} + +// ListPoolDeposits returns all deposits for a given poolID +// Warning: expensive operation +func (k Keeper) ListPoolDeposits(ctx sdk.Context, poolID uint64) (deposits []types.Deposit) { + depositStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(depositStore, types.GetPoolDepositsKey(poolID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var deposit types.Deposit + k.cdc.MustUnmarshal(iterator.Value(), &deposit) + deposits = append(deposits, deposit) + } + return +} + +// ListAccountPoolDeposits return all the deposits for and address and a poolID +// Warning: expensive operation +func (k Keeper) ListAccountPoolDeposits(ctx sdk.Context, addr sdk.Address, poolID uint64) (deposits []types.Deposit) { + depositStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(depositStore, types.GetAccountPoolDepositsKey(addr, poolID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var deposit types.Deposit + k.cdc.MustUnmarshal(iterator.Value(), &deposit) + deposits = append(deposits, deposit) + } + return +} + +// ListAccountDeposits return deposits all the deposits for an address +// Warning: expensive operation +func (k Keeper) ListAccountDeposits(ctx sdk.Context, addr sdk.Address) (deposits []types.Deposit) { + depositStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(depositStore, types.GetAccountDepositsKey(addr)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var deposit types.Deposit + k.cdc.MustUnmarshal(iterator.Value(), &deposit) + deposits = append(deposits, deposit) + } + return +} + +// ListDeposits return all the deposits for and address +// Warning: expensive operation +func (k Keeper) ListDeposits(ctx sdk.Context) (deposits []types.Deposit) { + depositStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(depositStore, types.GetDepositsKey()) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var deposit types.Deposit + k.cdc.MustUnmarshal(iterator.Value(), &deposit) + deposits = append(deposits, deposit) + } + return +} diff --git a/x/millions/keeper/keeper_deposit_test.go b/x/millions/keeper/keeper_deposit_test.go new file mode 100644 index 00000000..6adc181d --- /dev/null +++ b/x/millions/keeper/keeper_deposit_test.go @@ -0,0 +1,1174 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + apptesting "github.com/lum-network/chain/app/testing" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestDeposit_IDsGeneration tests that the depositID is properly incremented for each new deposit +func (suite *KeeperTestSuite) TestDeposit_IDsGeneration() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + // Add 10 deposits + for i := 0; i < 10; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + depositID := app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{PoolId: poolID})) + + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + // Test that depositID is incremented + suite.Require().Equal(uint64(i+1), depositID) + // Test that we never override an existing entity + panicF := func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + } +} + +// TestDeposit_AddDeposit tests the logic of adding a deposit to the store +func (suite *KeeperTestSuite) TestDeposit_AddDeposit() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + + depositsBefore := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(depositsBefore, 0) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 0) + + // Track poolTVLBefore + var poolTvlBefore math.Int + // Track poolDepositorsCount + var poolDepositorCountBefore uint64 + // Add 5 deposits + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + // Retrieve the pool from the state + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + // Test poolTVLBefore + poolTvlBefore = pool.TvlAmount + suite.Require().Equal(int64(0), poolTvlBefore.Int64()) + + // Test poolDepositorCount + poolDepositorCountBefore = pool.DepositorsCount + suite.Require().Equal(uint64(0), poolDepositorCountBefore) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + + // - Test that deposits with unknown IDs have a new depositIDs reassigned + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + for i, deposit := range deposits { + suite.Require().NotEqual(uint64(0), deposit.DepositId) + suite.Require().Equal(uint64(i+1), deposit.DepositId) + } + + // - Test the validate basics + // -- Test one successful deposit with all correct validate basics + panicF := func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: suite.addrs[1].String(), + WinnerAddress: suite.addrs[1].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().NotPanics(panicF) + // -- Test that the deposit validation panics with an invalid pool ID + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: uint64(0), + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid depositID + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + deposits[7].DepositId = 0 + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid state + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Unspecified, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid DepositorAddress + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: "", + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid WinnerAddress + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: "", + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + + // - Test that we never override an existing entity (double deposit) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + + // - Test that the pool deposits and account deposits are correctly updated + depositsAccount := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Equal(len(depositsBefore)+5, len(depositsAccount)) + depositsAccount = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[1]) + suite.Require().Equal(len(depositsBefore)+1, len(depositsAccount)) + deposits = app.MillionsKeeper.ListDeposits(ctx) + suite.Require().Equal(len(depositsBefore)+6, len(deposits)) + + pools := app.MillionsKeeper.ListPools(ctx) + + for i, pool := range pools { + // Test that the first 4 pools are updated + if i <= 3 { + depositsAccountPool := app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[0], pool.PoolId) + suite.Require().Equal(len(depositsBefore)+1, len(depositsAccountPool)) + + depositsPool := app.MillionsKeeper.ListPoolDeposits(ctx, pool.PoolId) + suite.Require().Equal(len(depositsBefore)+1, len(depositsPool)) + // - Test that the TVL is added to the pool by the amount of the deposit + suite.Require().Equal(poolTvlBefore.Int64()+1_000_000, pool.TvlAmount.Int64()) + // - Test that the deposit count is correctly incremented if it's a new depositor + suite.Require().Equal(poolDepositorCountBefore+1, pool.DepositorsCount) + + // Test GetPoolDeposit + poolDeposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, pool.PoolId, deposits[i].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(deposits[i].Amount.Amount.Int64(), poolDeposit.Amount.Amount.Int64()) + suite.Require().Equal(deposits[i].PoolId, poolDeposit.PoolId) + + // Test that the last pool is updated accordingly + } else if i == len(pools)-1 { + depositsPool := app.MillionsKeeper.ListPoolDeposits(ctx, pool.PoolId) + suite.Require().Equal(len(depositsBefore)+2, len(depositsPool)) + depositsAccountPool := app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[1], pool.PoolId) + suite.Require().Equal(len(depositsBefore)+1, len(depositsAccountPool)) + // - Test that the TVL is added to the pool by the amount of the deposit for the last pool + suite.Require().Equal(poolTvlBefore.Int64()+2_000_000, pool.TvlAmount.Int64()) + // - Test that the deposit count is correctly incremented if it's a new depositor for the last pool + suite.Require().Equal(poolDepositorCountBefore+2, pool.DepositorsCount) + + // Test GetPoolDeposit + poolDeposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, pool.PoolId, deposits[i].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(deposits[i].Amount.Amount.Int64(), poolDeposit.Amount.Amount.Int64()) + suite.Require().Equal(deposits[i].PoolId, poolDeposit.PoolId) + } + } +} + +// TestDeposit_RemoveDeposit tests the logic of removing a deposit from the store +func (suite *KeeperTestSuite) TestDeposit_RemoveDeposit() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + + depositsBefore := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(depositsBefore, 0) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 0) + + // Track poolTVLBefore + var poolTvlBefore math.Int + // Track poolDepositorsCount + var poolDepositorCountBefore uint64 + + // Add 5 deposits + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + // Retrieve the pool from the state + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + // Test poolTVLBefore + poolTvlBefore = pool.TvlAmount + suite.Require().Equal(int64(0), poolTvlBefore.Int64()) + + // Test poolDepositorCountBefore + poolDepositorCountBefore = pool.DepositorsCount + suite.Require().Equal(uint64(0), poolDepositorCountBefore) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + + deposits = app.MillionsKeeper.ListDeposits(ctx) + // - Test the validate basics + // -- Test one successful deposit with all correct validate basics + panicF := func() { + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().NotPanics(panicF) + // -- Test that the deposit validation panics with an invalid pool ID + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: uint64(0), + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid depositID + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + deposits[7].DepositId = 0 + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid state + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Unspecified, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid DepositorAddress + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: "", + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the deposit validation panics with an invalid WinnerAddress + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: "", + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + + // - Test that the store is delete for pool deposits and account deposits + // List all pools + pools := app.MillionsKeeper.ListPools(ctx) + + for i, pool := range pools { + if i <= 3 { + depositsAccountPool := app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[0], pool.PoolId) + suite.Require().Equal(len(depositsBefore)+1, len(depositsAccountPool)) + + depositsPool := app.MillionsKeeper.ListPoolDeposits(ctx, pool.PoolId) + suite.Require().Equal(len(depositsBefore)+1, len(depositsPool)) + // - Test that the TVL is added to the pool by the amount of the deposit + suite.Require().Equal(poolTvlBefore.Int64()+1_000_000, pool.TvlAmount.Int64()) + // - Test that the deposit count is correctly incremented if it's a new depositor + suite.Require().Equal(poolDepositorCountBefore+1, pool.DepositorsCount) + // Check that deposit was removed from last pool + } else if i == len(pools)-1 { + depositsPool := app.MillionsKeeper.ListPoolDeposits(ctx, pool.PoolId) + suite.Require().Equal(len(depositsBefore), len(depositsPool)) + depositsAccountPool := app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[0], pool.PoolId) + suite.Require().Equal(len(depositsBefore), len(depositsAccountPool)) + // - Test that the TVL is added to the pool by the amount of the deposit for the last pool + suite.Require().Equal(poolTvlBefore.Int64(), pool.TvlAmount.Int64()) + // - Test that the deposit count is correctly incremented if it's a new depositor for the last pool + suite.Require().Equal(poolDepositorCountBefore, pool.DepositorsCount) + + } + } + + for _, deposit := range deposits { + // Get the pool before remove deposit + poolBefore, err := app.MillionsKeeper.GetPool(ctx, deposit.PoolId) + suite.Require().NoError(err) + // Get the Account deposit before remove deposit + addr := sdk.MustAccAddressFromBech32(deposit.DepositorAddress) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, addr) + // Get the Account pool deposit before remove deposit + depositsAccountPoolBefore := app.MillionsKeeper.ListAccountPoolDeposits(ctx, addr, poolBefore.PoolId) + // Get the pool deposit before remove deposit + depositsPoolBefore := app.MillionsKeeper.ListPoolDeposits(ctx, poolBefore.PoolId) + + // Test GetPoolDeposit + poolDeposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + suite.Require().Equal(deposit.Amount.Amount.Int64(), poolDeposit.Amount.Amount.Int64()) + suite.Require().Equal(deposit.PoolId, poolDeposit.PoolId) + + // Remove the deposit + app.MillionsKeeper.RemoveDeposit(ctx, &deposit) + + // Decrement by 1 for each loop + depositsAccount := app.MillionsKeeper.ListAccountDeposits(ctx, addr) + suite.Require().Equal(len(deposits)-1, len(depositsAccount)) + + // Decrement by 1 for each loop + depositsAccountPool := app.MillionsKeeper.ListAccountPoolDeposits(ctx, addr, deposit.PoolId) + suite.Require().Equal(len(depositsAccountPoolBefore)-1, len(depositsAccountPool)) + + // Decrement by 1 for each loop + depositsPool := app.MillionsKeeper.ListPoolDeposits(ctx, deposit.PoolId) + suite.Require().Equal(len(depositsPoolBefore)-1, len(depositsPool)) + // Get the pool + pool, err := app.MillionsKeeper.GetPool(ctx, deposit.PoolId) + suite.Require().NoError(err) + // Test that the pool tvl is deducted by the deposit amount + suite.Require().Equal(poolBefore.TvlAmount.Int64()-deposit.Amount.Amount.Int64(), pool.TvlAmount.Int64()) + // - Test that the pool count is correctly decremented for each removed deposit + poolBefore.DepositorsCount-- + suite.Require().Equal(poolBefore.DepositorsCount, pool.DepositorsCount) + } + + depositsAll := app.MillionsKeeper.ListDeposits(ctx) + suite.Require().Equal(len(depositsBefore), len(depositsAll)) +} + +// TestDeposit_UpdateDepositStatus tests the logic of updating a deposit from the store +func (suite *KeeperTestSuite) TestDeposit_UpdateDepositStatus() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + + // Add 5 deposits + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + // Retrieve the pool from the state + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + } + + // - Test if the deposit exist + // Retrived deposits + deposits := app.MillionsKeeper.ListDeposits(ctx) + // Retrieve the pool from the state + pools := app.MillionsKeeper.ListPools(ctx) + for i, pool := range pools { + app.MillionsKeeper.UpdateDepositStatus(ctx, pool.PoolId, deposits[i].DepositId, millionstypes.DepositState_IcaDelegate, false) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, pool.PoolId, deposits[i].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + } + deposits = app.MillionsKeeper.ListDeposits(ctx) + // Trigger panic on wrong poolID + panicF := func() { + _, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[10].PoolId, uint64(5)) + suite.Require().NoError(err) + } + suite.Require().Panics(panicF) + // Trigger panic on wrong depositID + panicF = func() { + _, err := app.MillionsKeeper.GetPoolDeposit(ctx, uint64(5), deposits[10].PoolId) + suite.Require().NoError(err) + } + suite.Require().Panics(panicF) + + // - Test Error Management + deposits = app.MillionsKeeper.ListDeposits(ctx) + // Retrieve the pool from the state + pools = app.MillionsKeeper.ListPools(ctx) + for i, pool := range pools { + app.MillionsKeeper.UpdateDepositStatus(ctx, pool.PoolId, deposits[i].DepositId, millionstypes.DepositState_IcaDelegate, true) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, pool.PoolId, deposits[i].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_Failure, deposit.State) + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposit.ErrorState) + } + + // - Test that the account deposit was updated + // - Test that the pool deposit was updated + pools = app.MillionsKeeper.ListPools(ctx) + for i, pool := range pools { + depositsAccounts := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Equal(ctx.BlockTime(), depositsAccounts[i].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), depositsAccounts[i].UpdatedAtHeight) + + depositsPoolAccount := app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[0], pool.PoolId) + suite.Require().Equal(ctx.BlockTime(), depositsPoolAccount[0].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), depositsPoolAccount[0].UpdatedAtHeight) + + depositsPool := app.MillionsKeeper.ListPoolDeposits(ctx, pool.PoolId) + suite.Require().Equal(ctx.BlockTime(), depositsPool[0].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), depositsPool[0].UpdatedAtHeight) + } +} + +// TestDeposit_TransferDeposit tests the full flow from the transfer till the delegation point +func (suite *KeeperTestSuite) TestDeposit_TransferDeposit() { + // Set the app context + app := suite.app + ctx := suite.ctx + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + uatomAddresses := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), "uatom") + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: "cosmosvaloper", + ChainId: "cosmos", + Denom: "uatom", + NativeDenom: "uatom", + ConnectionId: "connection-id", + TransferChannelId: "transferChannel-id", + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin("uatom", math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 1) + + // - Test the full deposit process from the transfer till the delegation point + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[0].Validators[cosmosPoolValidator].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[0].Validators[cosmosPoolValidator].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin("uatom", sdk.NewInt(1_000_000)), + }) + err := app.BankKeeper.SendCoins(ctx, uatomAddresses[0], sdk.MustAccAddressFromBech32(pools[0].LocalAddress), sdk.Coins{sdk.NewCoin(pools[0].Denom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + + // Test that the pool is not local + suite.Require().Equal(false, pools[0].IsLocalZone(ctx)) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IbcTransfer, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 1) + + // Simulate failed ackResponse AckResponseStatus_FAILURE + err = app.MillionsKeeper.OnTransferDepositToNativeChainCompleted(ctx, deposits[0].GetPoolId(), deposits[0].GetDepositId(), true) + suite.Require().NoError(err) + + // List deposits to get latest status + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 1) + // Failed Transfer should set the errorState to DepositState_IbcTransfer and state to DepositState_Failure + suite.Require().Equal(millionstypes.DepositState_Failure, deposits[0].State) + suite.Require().Equal(millionstypes.DepositState_IbcTransfer, deposits[0].ErrorState) + + // Update status to simulate that the state is initially on DepositState_IbcTransfer + app.MillionsKeeper.UpdateDepositStatus(ctx, deposits[0].PoolId, deposits[0].DepositId, millionstypes.DepositState_IbcTransfer, false) + + // Simulate succesful ackResponse AckResponseStatus_SUCCESS + err = app.MillionsKeeper.OnTransferDepositToNativeChainCompleted(ctx, deposits[0].GetPoolId(), deposits[0].GetDepositId(), false) + suite.Require().NoError(err) + + // List deposits to get latest state + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 1) + // The deposit will reached the sequence, err := k.BroadcastICAMessages an fail on OnDelegateDepositOnNativeChainCompleted as we don't BroadcastICAMessages in our test + suite.Require().Equal(millionstypes.DepositState_Failure, deposits[0].State) + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposits[0].ErrorState) + + // Test local pool + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + // local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: "ulum", + NativeDenom: "ulum", + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + pools = app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 2) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[1].Validators[suite.valAddrs[0].String()].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[1].Validators[suite.valAddrs[0].String()].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), sdk.Coins{sdk.NewCoin(pools[1].Denom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 1) + + // Test that the pool is local + suite.Require().Equal(true, pools[1].IsLocalZone(ctx)) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IbcTransfer, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + // Trigger the Transfer deposit to native chain + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Success, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) +} + +// TestDeposit_DelegateDeposit tests the delegate deposit from the transfer point till the final delegation +func (suite *KeeperTestSuite) TestDeposit_DelegateDeposit() { + // Set the app context + app := suite.app + ctx := suite.ctx + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + uatomAddresses := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), "uatom") + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: "cosmosvaloper", + ChainId: "cosmos", + Denom: "uatom", + NativeDenom: "uatom", + ConnectionId: "connection-id", + TransferChannelId: "transferChannel-id", + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin("uatom", math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 1) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[0].Validators[cosmosPoolValidator].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[0].Validators[cosmosPoolValidator].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_IcaDelegate, + Amount: sdk.NewCoin("uatom", sdk.NewInt(1_000_000)), + }) + err := app.BankKeeper.SendCoins(ctx, uatomAddresses[0], sdk.MustAccAddressFromBech32(pools[0].LocalAddress), sdk.Coins{sdk.NewCoin(pools[0].Denom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 1) + + // Test that the pool is not local + suite.Require().Equal(false, pools[0].IsLocalZone(ctx)) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + // Simulate a failed DelegateDepositOnNativeChain + err = app.MillionsKeeper.DelegateDepositOnNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + // The deposit will reached the sequence, err := k.BroadcastICAMessages and fail on OnDelegateDepositOnNativeChainCompleted as we don't BroadcastICAMessages in our test + suite.Require().Equal(millionstypes.DepositState_Failure, deposit.State) + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposit.ErrorState) + + // Update status to simulate that the state is initially on DepositState_IcaDelegate + app.MillionsKeeper.UpdateDepositStatus(ctx, deposit.PoolId, deposit.DepositId, millionstypes.DepositState_IcaDelegate, false) + + splits := []*millionstypes.SplitDelegation{{ValidatorAddress: cosmosPoolValidator, Amount: sdk.NewInt(int64(1_000_000))}} + + // Now trigger a successfull Delegation to simulate icacallbackstypes.AckResponseStatus_SUCCESS + err = app.MillionsKeeper.OnDelegateDepositOnNativeChainCompleted(ctx, deposit.PoolId, deposit.DepositId, splits, false) + suite.Require().NoError(err) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Success, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + // Test local pool + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + // local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: "ulum", + NativeDenom: "ulum", + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(denom, math.NewInt(1000)), + })) + pools = app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 2) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[1].Validators[suite.valAddrs[0].String()].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[1].Validators[suite.valAddrs[0].String()].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IcaDelegate, + Amount: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), sdk.Coins{sdk.NewCoin(pools[1].Denom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 1) + + pools = app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 2) + + // Test that the pool is local + suite.Require().Equal(true, pools[1].IsLocalZone(ctx)) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + // As it's local pool trigger a DelegateDepositOnNativeChain for the new deposit + err = app.MillionsKeeper.DelegateDepositOnNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Success, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) +} + +// TestDeposit_BalanceDeposit tests the balance in case of success or failed deposit +func (suite *KeeperTestSuite) TestDeposit_BalanceDeposit() { + // Set the app context + app := suite.app + ctx := suite.ctx + drawDelta1 := 1 * time.Hour + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + uatomAddresses := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), "uatom") + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: "cosmosvaloper", + ChainId: "cosmos", + Denom: "uatom", + NativeDenom: "uatom", + ConnectionId: "connection-id", + TransferChannelId: "transferChannel-id", + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin("uatom", math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 1) + + // Initialize balance before + balanceBefore := app.BankKeeper.GetBalance(ctx, uatomAddresses[0], "uatom") + suite.Require().Equal(int64(1_000_000_000_0), balanceBefore.Amount.Int64()) + // Initialize balance module account + balanceModuleAccBefore := app.BankKeeper.GetBalance(ctx, suite.moduleAddrs[7], "uatom") + suite.Require().Equal(int64(0), balanceModuleAccBefore.Amount.Int64()) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[0].Validators[cosmosPoolValidator].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[0].Validators[cosmosPoolValidator].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin("uatom", sdk.NewInt(1_000_000)), + }) + + err := app.BankKeeper.SendCoins(ctx, uatomAddresses[0], sdk.MustAccAddressFromBech32(pools[0].LocalAddress), sdk.Coins{sdk.NewCoin(pools[0].Denom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + // Balance should have decreased by one deposit + balance := app.BankKeeper.GetBalance(ctx, uatomAddresses[0], "uatom") + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balance.Amount.Int64()) + // Module Acc should have increased by one deposit + balanceModuleAcc := app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[0].LocalAddress), "uatom") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64()+1_000_000, balanceModuleAcc.Amount.Int64()) + + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 1) + + app.MillionsKeeper.UpdateDepositStatus(ctx, deposits[0].PoolId, deposits[0].DepositId, millionstypes.DepositState_IcaDelegate, false) + + suite.Require().Equal(false, pools[0].IsLocalZone(ctx)) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IcaDelegate, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + splits := []*millionstypes.SplitDelegation{{ValidatorAddress: cosmosPoolValidator, Amount: sdk.NewInt(int64(1_000_000))}} + + // Now trigger a successfull Delegation to simulate icacallbackstypes.AckResponseStatus_SUCCESS + err = app.MillionsKeeper.OnDelegateDepositOnNativeChainCompleted(ctx, deposit.PoolId, deposit.DepositId, splits, false) + suite.Require().NoError(err) + + // For remote pools we don't reach the success as k.BroadcastICAMessages fails on OnDelegateDepositOnNativeChainCompleted + + // Balance should remain unchanged + balance = app.BankKeeper.GetBalance(ctx, uatomAddresses[0], "uatom") + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balance.Amount.Int64()) + // Module Account should have the deposit amount + balanceModuleAcc = app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[0].LocalAddress), "uatom") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64()+1_000_000, balanceModuleAcc.Amount.Int64()) + + // There should no delegation shares + delegationAmount := app.StakingKeeper.GetDelegatorDelegations(ctx, sdk.MustAccAddressFromBech32(pools[0].LocalAddress), 10) + suite.Require().Len(delegationAmount, 0) + + // Test local pool + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + // local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: "ulum", + NativeDenom: "ulum", + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + pools = app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 2) + + // Initialize balance before + balanceBefore = app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(int64(1_000_000_000_0), balanceBefore.Amount.Int64()) + // Initialize balance module account + balanceModuleAccBefore = app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), "ulum") + suite.Require().Equal(int64(0), balanceModuleAccBefore.Amount.Int64()) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[1].Validators[suite.valAddrs[0].String()].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[1].Validators[suite.valAddrs[0].String()].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(2_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), sdk.Coins{sdk.NewCoin(pools[1].Denom, sdk.NewInt(2_000_000))}) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 1) + + // Balance should have decreased by two deposits + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + // Module Acc should have increased by two deposits + balanceModuleAcc = app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), "ulum") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64()+2_000_000, balanceModuleAcc.Amount.Int64()) + + // There should be no delegation shares yet + delegationAmount = app.StakingKeeper.GetDelegatorDelegations(ctx, suite.moduleAddrs[0], 10) + suite.Require().Len(delegationAmount, 0) + + suite.Require().Equal(true, pools[1].IsLocalZone(ctx)) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IbcTransfer, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + err = app.MillionsKeeper.OnTransferDepositToNativeChainCompleted(ctx, deposit.PoolId, deposit.DepositId, true) + suite.Require().NoError(err) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Failure, deposit.State) + suite.Require().Equal(millionstypes.DepositState_IbcTransfer, deposit.ErrorState) + + // Balance should be unchanged + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + // Module Acc should have still the deposited amount + balanceModuleAcc = app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), "ulum") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64()+2_000_000, balanceModuleAcc.Amount.Int64()) + + // There should be no delegation shares yet + delegationAmount = app.StakingKeeper.GetDelegatorDelegations(ctx, sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), 10) + suite.Require().Len(delegationAmount, 0) + + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + // Update the status to trigger successful DepositToNativeChain + app.MillionsKeeper.UpdateDepositStatus(ctx, deposit.PoolId, deposit.DepositId, millionstypes.DepositState_IbcTransfer, false) + + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Success, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + // Balance should be unchanged + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + // Module Acc should have delegated the deposit + balanceModuleAcc = app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), "ulum") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64(), balanceModuleAcc.Amount.Int64()) + + // The delegation amount should reflect the shares delegated - client precision + delegationAmount = app.StakingKeeper.GetDelegatorDelegations(ctx, sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), 10) + depositToShare := sdk.NewDecFromInt(sdk.NewInt(deposit.Amount.Amount.Int64() / 1_000_000)) + suite.Require().Equal(depositToShare, delegationAmount[0].Shares) +} + +// TestDeposit_FullDepositProcess tests the complete logic for deposits for a local pool +func (suite *KeeperTestSuite) TestDeposit_FullDepositProcess() { + // Set the app context + app := suite.app + ctx := suite.ctx + drawDelta1 := 1 * time.Hour + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + + // - Test the full deposit process for a local pool + denom := app.StakingKeeper.BondDenom(ctx) + // local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Denom: "ulum", + NativeDenom: "ulum", + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 1) + + // Initialize balance before + balanceBefore := app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(int64(1_000_000_000_0), balanceBefore.Amount.Int64()) + // Initialize balance module account + balanceModuleAccBefore := app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), "ulum") + suite.Require().Equal(int64(0), balanceModuleAccBefore.Amount.Int64()) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[0].Validators[suite.valAddrs[0].String()].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[0].Validators[suite.valAddrs[0].String()].BondedAmount) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), sdk.Coins{sdk.NewCoin(pools[0].Denom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 1) + + // Balance should have decreased by one deposit + balance := app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balance.Amount.Int64()) + // Module Acc should have increased by one deposit + balanceModuleAcc := app.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), "ulum") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64()+1_000_000, balanceModuleAcc.Amount.Int64()) + + // There should no delegation shares + delegationAmount := app.StakingKeeper.GetDelegatorDelegations(ctx, sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), 10) + suite.Require().Len(delegationAmount, 0) + + // Test if it's a local pool + suite.Require().Equal(true, pools[0].IsLocalZone(ctx)) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.DepositState_IbcTransfer, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Success, deposit.State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposit.ErrorState) + + // Balance should be unchanged + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], "ulum") + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balance.Amount.Int64()) + // Module Acc should have delegated the deposit + balanceModuleAcc = app.BankKeeper.GetBalance(ctx, suite.moduleAddrs[0], "ulum") + suite.Require().Equal(balanceModuleAccBefore.Amount.Int64(), balanceModuleAcc.Amount.Int64()) + + // The delegation amount should reflect the shares delegated - client precision + delegationAmount = app.StakingKeeper.GetDelegatorDelegations(ctx, sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), 10) + depositToShare := sdk.NewDecFromInt(sdk.NewInt(deposit.Amount.Amount.Int64() / 1_000_000)) + suite.Require().Equal(depositToShare, delegationAmount[0].Shares) +} diff --git a/x/millions/keeper/keeper_draw.go b/x/millions/keeper/keeper_draw.go new file mode 100644 index 00000000..224f36b3 --- /dev/null +++ b/x/millions/keeper/keeper_draw.go @@ -0,0 +1,867 @@ +package keeper + +import ( + "crypto/sha256" + "fmt" + "math" + "math/rand" + "sort" + "strconv" + "time" + + errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + ibctypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" + + "github.com/lum-network/chain/x/millions/types" +) + +type draw struct { + PrizeIdx int + DrawValue sdk.Dec +} + +type DepositTWB struct { + Address string + Amount sdkmath.Int +} + +type PrizeDraw struct { + Amount sdkmath.Int + Winner *DepositTWB +} + +type DrawResult struct { + PrizeDraws []PrizeDraw + TotalWinCount uint64 + TotalWinAmount sdkmath.Int +} + +// LaunchNewDraw initiates a new draw and triggers the ICA get reward phase +// See UpdateDrawAtStateICAOp for next phase +func (k Keeper) LaunchNewDraw(ctx sdk.Context, poolID uint64) (*types.Draw, error) { + // Acquire Pool + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + if pool.LastDrawState != types.DrawState_Unspecified && pool.LastDrawState != types.DrawState_Success { + // This check is also performed using the last draw entity + return nil, types.ErrPoolDrawNotDone + } + + // Initiate new draw procedure + drawID := pool.GetNextDrawId() + draw := types.Draw{ + PoolId: poolID, + DrawId: drawID, + State: types.DrawState_IcaWithdrawRewards, + PrizePool: sdk.NewCoin(pool.Denom, sdk.ZeroInt()), + CreatedAtHeight: ctx.BlockHeight(), + UpdatedAtHeight: ctx.BlockHeight(), + CreatedAt: ctx.BlockTime(), + UpdatedAt: ctx.BlockTime(), + } + k.SetPoolDraw(ctx, draw) + + // Update pool with latest draw info + t := ctx.BlockTime() + pool.NextDrawId++ + pool.LastDrawCreatedAt = &t + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + + return k.ClaimRewardsOnNativeChain(ctx, poolID, drawID) +} + +// ClaimRewardsOnNativeChain Claim staking rewards from the native chain validators +// - wait for the ICA callback to move to OnClaimRewardsOnNativeChainCompleted +// - or go to OnClaimRewardsOnNativeChainCompleted directly upon claim rewards success if local zone +func (k Keeper) ClaimRewardsOnNativeChain(ctx sdk.Context, poolID uint64, drawID uint64) (*types.Draw, error) { + logger := k.Logger(ctx).With("func", "draw_claim_rewards") + + // Acquire pool config + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + + if pool.IsLocalZone(ctx) { + coins := sdk.Coins{} + for _, validator := range pool.GetValidators() { + if validator.IsBonded() { + rewardCoins, err := k.DistributionKeeper.WithdrawDelegationRewards( + ctx, + sdk.MustAccAddressFromBech32(pool.GetIcaDepositAddress()), + validator.MustValAddressFromBech32(), + ) + if err != nil { + // Return with error here since it is the first operation and nothing needs to be saved to state + return &draw, errorsmod.Wrapf(err, "%s", validator.OperatorAddress) + } + coins = coins.Add(rewardCoins...) + } + } + return k.OnClaimRewardsOnNativeChainCompleted(ctx, poolID, drawID, false) + } else { + var msgs []sdk.Msg + for _, validator := range pool.GetValidators() { + if validator.IsBonded() { + msgs = append(msgs, &distributiontypes.MsgWithdrawDelegatorReward{ + DelegatorAddress: pool.GetIcaDepositAddress(), + ValidatorAddress: validator.OperatorAddress, + }) + } + } + if len(msgs) == 0 { + // Special case - no bonded validator + // Does not need to do any ICA call + return k.OnClaimRewardsOnNativeChainCompleted(ctx, poolID, drawID, false) + } + callbackData := types.ClaimRewardsCallback{ + PoolId: poolID, + DrawId: drawID, + } + marshalledCallbackData, err := k.MarshalClaimCallbackArgs(ctx, callbackData) + if err != nil { + return &draw, err + } + + // Dispatch our message with a timeout of 30 minutes in nanos + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + types.IBCTransferTimeoutNanos + sequence, err := k.BroadcastICAMessages(ctx, poolID, types.ICATypeDeposit, msgs, timeoutTimestamp, ICACallbackID_Claim, marshalledCallbackData) + if err != nil { + // Return with error here since it is the first operation and nothing needs to be saved to state + logger.Error( + fmt.Sprintf("failed to dispatch ICA claim delegator rewards: %v", err), + "pool_id", poolID, + "draw_id", drawID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return &draw, err + } + logger.Debug( + "ICA claim delegator rewards dispatched", + "pool_id", poolID, + "draw_id", drawID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + } + return &draw, nil +} + +// OnClaimRewardsOnNativeChainCompleted Acknowledge the ICA claim rewards from the native chain validators response and trigger an ICQ if success +func (k Keeper) OnClaimRewardsOnNativeChainCompleted(ctx sdk.Context, poolID uint64, drawID uint64, isError bool) (*types.Draw, error) { + // Acquire pool config + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + if draw.State != types.DrawState_IcaWithdrawRewards { + return &draw, errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DrawState_IcaWithdrawRewards.String(), draw.State.String()) + } + + // Abort on errors + if isError { + draw.State = types.DrawState_Failure + draw.ErrorState = types.DrawState_IcaWithdrawRewards + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, draw) + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + return &draw, nil + } + + draw.State = types.DrawState_IcqBalance + draw.ErrorState = types.DrawState_Unspecified + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, draw) + + // Update pool with latest draw info + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + + // Trigger the balance query + return k.QueryBalance(ctx, poolID, drawID) +} + +func (k Keeper) OnQueryRewardsOnNativeChainCompleted(ctx sdk.Context, poolID uint64, drawID uint64, coins sdk.Coins, isError bool) (*types.Draw, error) { + // Acquire pool config + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + if draw.State != types.DrawState_IcqBalance { + return &draw, errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DrawState_IcqBalance.String(), draw.State.String()) + } + + // Abort on errors + if isError { + draw.State = types.DrawState_Failure + draw.ErrorState = types.DrawState_IcqBalance + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, draw) + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + return &draw, nil + } + + // Save new draw state + freshPrizePool := sdk.NewCoin(pool.Denom, sdk.ZeroInt()) + for _, c := range coins { + if c.Denom == pool.NativeDenom { + // Do not use Add directly here since we change the coin native denom into the local denom + // This is due to the fact that the coins params comes from an ICA callback (except for local pools where Denom == NativeDenom) + freshPrizePool = freshPrizePool.AddAmount(c.Amount) + } + // TODO: handle other denoms here ? + // - in the case of Lum we will receive here the stakers fees as well (inception) + // - in the case of other zones we might receive other tokens as well + // - TBD: do something with it at some point + } + + draw.State = types.DrawState_IbcTransfer + draw.ErrorState = types.DrawState_Unspecified + draw.PrizePoolFreshAmount = freshPrizePool.Amount + draw.PrizePool = draw.PrizePool.Add(freshPrizePool) + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, draw) + + // Update pool with latest draw info + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + + return k.TransferRewardsToLocalChain(ctx, poolID, drawID) +} + +// TransferRewardsToLocalChain Transfer the claimed rewards to the local chain +// - wait for the ICA callback to move to OnTransferRewardsToLocalChainCompleted +// - or go to OnTransferRewardsToLocalChainCompleted directly if local zone +func (k Keeper) TransferRewardsToLocalChain(ctx sdk.Context, poolID uint64, drawID uint64) (*types.Draw, error) { + logger := k.Logger(ctx).With("ctx", "draw_transfer_rewards") + + // Acquire Pool + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + if draw.State != types.DrawState_IbcTransfer { + return &draw, errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DrawState_IbcTransfer.String(), draw.State.String()) + } + + // Nothing to transfer + if draw.PrizePoolFreshAmount.IsZero() { + return k.OnTransferRewardsToLocalChainCompleted(ctx, poolID, drawID, false) + } + + // Converts the local ibc Denom into the native chain Denom + amount := sdk.NewCoin(pool.NativeDenom, draw.PrizePoolFreshAmount) + + if pool.IsLocalZone(ctx) { + // Move coins locally to keep a proper funds segregation + if err := k.BankKeeper.SendCoins( + ctx, + sdk.MustAccAddressFromBech32(pool.GetIcaPrizepoolAddress()), + sdk.MustAccAddressFromBech32(pool.GetLocalAddress()), + sdk.NewCoins(amount), + ); err != nil { + logger.Error( + fmt.Sprintf("failed to move funds from prize pool address to local address: %v", err), + "pool_id", poolID, + "draw_id", drawID, + ) + return k.OnTransferRewardsToLocalChainCompleted(ctx, poolID, drawID, true) + } + return k.OnTransferRewardsToLocalChainCompleted(ctx, poolID, drawID, false) + } + + var msgs []sdk.Msg + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + types.IBCTransferTimeoutNanos + msgs = append(msgs, ibctypes.NewMsgTransfer( + ibctypes.PortID, + pool.GetTransferChannelId(), + amount, + pool.GetIcaPrizepoolAddress(), + pool.GetLocalAddress(), + clienttypes.Height{}, + timeoutTimestamp, + )) + + // Construct our callback data + callbackData := types.TransferFromNativeCallback{ + Type: types.TransferType_Claim, + PoolId: poolID, + DrawId: drawID, + } + marshalledCallbackData, err := k.MarshalTransferFromNativeCallbackArgs(ctx, callbackData) + if err != nil { + return &draw, err + } + + // Dispatch our message with a timeout of 30 minutes in nanos + sequence, err := k.BroadcastICAMessages(ctx, poolID, types.ICATypePrizePool, msgs, timeoutTimestamp, ICACallbackID_TransferFromNative, marshalledCallbackData) + if err != nil { + // Save error state since we cannot simply recover from a failure at this stage + // A subsequent call to DrawRetry will be made possible by setting an error state and not returning an error here + logger.Error( + fmt.Sprintf("failed to dispatch ICA transfer: %v", err), + "pool_id", poolID, + "draw_id", drawID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return k.OnTransferRewardsToLocalChainCompleted(ctx, poolID, drawID, true) + } + logger.Debug( + "ICA transfer dispatched", + "pool_id", poolID, + "draw_id", drawID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return &draw, nil +} + +// OnTransferRewardsToLocalChainCompleted Acknowledge the transfer of the claimed rewards +// finalises the Draw if success +func (k Keeper) OnTransferRewardsToLocalChainCompleted(ctx sdk.Context, poolID uint64, drawID uint64, isError bool) (*types.Draw, error) { + logger := k.Logger(ctx).With("ctx", "draw_finalise") + + // Acquire Pool + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + if draw.State != types.DrawState_IbcTransfer { + return &draw, errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DrawState_IbcTransfer.String(), draw.State.String()) + } + + if isError { + draw.State = types.DrawState_Failure + draw.ErrorState = types.DrawState_IbcTransfer + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, draw) + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + return &draw, nil + } + + draw.State = types.DrawState_Drawing + draw.ErrorState = types.DrawState_Unspecified + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, draw) + pool.LastDrawState = draw.State + k.updatePool(ctx, &pool) + + // Voluntary exit the current cache context here since: + // - the pool draw rewards have been transfered to the local chain + // - the ExecuteDraw errors are not part of the transfer context + // - we do not want to partially commit any state of the execute draw phase by not returning an error + cacheCtx, writeCache := ctx.CacheContext() + fDraw, err := k.ExecuteDraw(cacheCtx, poolID, drawID) + if err != nil { + // DO NOT commit ExecuteDraw changes in case of failures + // Re-apply draw state changes (errors) and exit without error + logger.Error( + fmt.Sprintf("Failed to execute draw phase: %v", err), + "pool_id", poolID, + "draw_id", drawID, + ) + if fDraw == nil { + // Case not theoretically possible but necessary to respect implementation safety + fDraw = &draw + } + //nolint:errcheck // error check is not necessary here since we handled it before + k.OnExecuteDrawCompeleted(ctx, &pool, fDraw, err) + return fDraw, nil + } else { + // Commit ExecuteDraw changes in case of success + logger.Debug( + "Draw execution completed", + "pool_id", poolID, + "draw_id", drawID, + ) + writeCache() + } + + return fDraw, nil +} + +// ExecuteDraw completes the draw phases by effectively drawing prizes +// This is the last phase of a Draw +// WARNING: this method can eventually commit critical partial store updates if the caller does not return on error +func (k Keeper) ExecuteDraw(ctx sdk.Context, poolID uint64, drawID uint64) (*types.Draw, error) { + // Acquire Pool + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + if draw.State != types.DrawState_Drawing { + return &draw, errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.DrawState_Drawing.String(), draw.State.String()) + } + + // Generate draw random seed + hashBytes := sha256.Sum256(append(ctx.BlockHeader().AppHash, []byte(strconv.Itoa(int(ctx.BlockTime().UnixNano())))...)) + bytesToInt64 := func(bytes []byte) int64 { + var value int64 + for i := 0; i < 8; i++ { + value = (value << 8) | int64(bytes[i]) + } + for i := 8; i < 32; i++ { + value = (value << 8) | int64(bytes[i]&0x7F) + if bytes[i]&0x80 != 0 { + value = -value + } + } + return value + } + draw.RandSeed = bytesToInt64(hashBytes[:]) + + // Acquire TWB deposits + depositorsTWB := k.ComputeDepositsTWB( + ctx, + ctx.BlockTime().Add(-pool.DrawSchedule.DrawDelta), + ctx.BlockTime(), + k.ListPoolDeposits(ctx, poolID), + ) + + // Acquire available amount from pool to compute final prize pool amount + draw.PrizePoolRemainsAmount = pool.AvailablePrizePool.Amount + draw.PrizePool = draw.PrizePool.Add(pool.AvailablePrizePool) + + // Draw prizes + dRes, err := k.RunDrawPrizes( + ctx, + draw.PrizePool, + pool.PrizeStrategy, + depositorsTWB, + draw.RandSeed, + ) + if err != nil { + return k.OnExecuteDrawCompeleted( + ctx, + &pool, + &draw, + errorsmod.Wrapf(err, "failed to draw prizes for pool %d draw %d", poolID, drawID), + ) + } + + // Update draw result + draw.TotalWinCount = dRes.TotalWinCount + draw.TotalWinAmount = dRes.TotalWinAmount + + // Update pool available prize pool + pool.AvailablePrizePool = draw.PrizePool.SubAmount(draw.TotalWinAmount) + + // Save draw state before prize distrib in case we don't have prizeRefs + k.SetPoolDraw(ctx, draw) + + // Distribute prizes and collect fees + fc := k.NewFeeCollector(ctx, pool) + if err := k.DistributePrizes(ctx, fc, dRes, draw); err != nil { + return k.OnExecuteDrawCompeleted( + ctx, + &pool, + &draw, + errorsmod.Wrapf(err, "failed to distribute prizes for pool %d draw %d", poolID, drawID), + ) + } + + // Get the updated draw prizeRefs after DistributePrizes if we have potential winners + draw, err = k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + + // Send collected fees + if err := fc.SendCollectedFees(ctx); err != nil { + return k.OnExecuteDrawCompeleted( + ctx, + &pool, + &draw, + errorsmod.Wrapf(err, "failed to send collected fees for pool %d draw %d", poolID, drawID), + ) + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeDrawSuccess, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(draw.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDrawID, strconv.FormatUint(draw.DrawId, 10)), + sdk.NewAttribute(types.AttributeKeyPrizePool, draw.PrizePool.String()), + sdk.NewAttribute(types.AttributeKeyTotalWinners, strconv.FormatUint(draw.TotalWinCount, 10)), + sdk.NewAttribute(types.AttributeKeyTotalWinAmount, draw.TotalWinAmount.String()), + ), + }) + + return k.OnExecuteDrawCompeleted(ctx, &pool, &draw, nil) +} + +// OnExecuteDrawCompeleted wrappers for draw state update upon drawing phase completion +// returns the error specified in parameters and does not produce any internal error +func (k Keeper) OnExecuteDrawCompeleted(ctx sdk.Context, pool *types.Pool, draw *types.Draw, err error) (*types.Draw, error) { + if err != nil { + draw.State = types.DrawState_Failure + draw.ErrorState = types.DrawState_Drawing + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, *draw) + pool.LastDrawState = draw.State + k.updatePool(ctx, pool) + return draw, err + } + draw.State = types.DrawState_Success + draw.ErrorState = types.DrawState_Unspecified + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + k.SetPoolDraw(ctx, *draw) + pool.LastDrawState = draw.State + k.updatePool(ctx, pool) + return draw, err +} + +// ComputeDepositsTWB takes deposits and computes the weight based on their deposit time and the draw duration +// It essentially compute the Time Weighted Balance of each deposit for the DrawPrizes phase +func (k Keeper) ComputeDepositsTWB(ctx sdk.Context, depositStartAt time.Time, drawAt time.Time, deposits []types.Deposit) []DepositTWB { + params := k.GetParams(ctx) + + totalElapsed := drawAt.Unix() - depositStartAt.Unix() + if totalElapsed < 0 { + totalElapsed = 0 + } + + var depositsTWB []DepositTWB + for _, d := range deposits { + twb := d.Amount.Amount + if d.State != types.DepositState_Success { + // Only take into account completed deposits + continue + } else if d.IsSponsor { + // Sponsors waive their drawing chances + continue + } + if d.CreatedAt.After(depositStartAt) { + // Apply Time Weight for deposits within the draw deposit delta + elapsed := drawAt.Unix() - d.CreatedAt.Unix() + if elapsed < int64(params.MinDepositDrawDelta.Seconds()) { + // Consider deposits which do not abide to the min deposit to draw delta to be 0 + elapsed = 0 + } + twb = sdkmath.LegacyNewDec(int64(elapsed)).QuoInt64(int64(totalElapsed)).MulInt(d.Amount.Amount).RoundInt() + } + dtwb := DepositTWB{ + Address: d.WinnerAddress, + Amount: twb, + } + depositsTWB = append(depositsTWB, dtwb) + } + + return depositsTWB +} + +// RunDrawPrizes computes available prizes and draws the prizes and their potential winners based on the specified prize strategy +// this method does not store nor send anything, it only computes the DrawResult +func (k Keeper) RunDrawPrizes(ctx sdk.Context, prizePool sdk.Coin, prizeStrat types.PrizeStrategy, deposits []DepositTWB, randSeed int64) (result DrawResult, err error) { + result.TotalWinAmount = sdk.ZeroInt() + + // Compute all prizes probs + prizes, _, _, err := prizeStrat.ComputePrizesProbs(prizePool) + if err != nil { + return result, err + } + + // Create deposits buffer and mapping + // - drawBuffer is a representation of the deposits as if we put them on a line with the distance between them being their deposited amount + // - bufferToDeposit is the link between the deposit position on the line and the actual deposit + // Visual representation: + // - drawBuffer = deposits weighted position A(2), B(5), C(3): ..A.....B...C,,,,, + // - bufferToDeposit = {2: A, 7: B, 12: C} + // - note that the positions marked by commas (,) instead of dots (.) are outside of the depositors owned area (no winner zone) + drawBuffer := []sdkmath.Int{} + bufferToDeposit := map[sdkmath.Int]DepositTWB{} + totalDeposits := sdk.ZeroInt() + for _, d := range deposits { + if d.Amount.LTE(sdk.ZeroInt()) { + // Ignore 0 deposits just in case since it would break the draw logic + // can happen due to rounding approximation (TWB) + continue + } + totalDeposits = totalDeposits.Add(d.Amount) + drawBuffer = append(drawBuffer, totalDeposits) + bufferToDeposit[totalDeposits] = d + } + + // Initialise rand source + rnd := rand.New(rand.NewSource(randSeed)) + + // Compute each prize draw and sort by drawValue ascending in order to only iterate forward on the deposits buffer + // We maintain the draw order here since we do not want to mess with the individual probabilities of prizes + var draws []draw + for i := range prizes { + draws = append(draws, draw{ + DrawValue: sdk.NewDec(rnd.Int63()).QuoInt64(math.MaxInt64), + PrizeIdx: i, + }) + } + sort.Slice(draws, func(i, j int) bool { + return draws[i].DrawValue.LT(draws[j].DrawValue) + }) + + // Compute each prize winner based on the price draw and the deposit position in the buffer + // - No winner if the drawValue >= drawProbability + // Visual representation (no winner case): + // - drawBuffer : ..A.....B...C,,,,,,,,,, + // - drawPosition: .............,,,,,,x,,, + // - no winner since x is outside the buffer owned by depositors + // + // Otherwise the winner is the one which owns the position in the buffer + // Visual representation (winner case): + // - drawBuffer : ..A.....B...C,,,,,,,,,, + // - drawPosition: .....x.......,,,,,,,,,, + // - winner is depositor B since they own the range from A) to B] + i := 0 + result.PrizeDraws = make([]PrizeDraw, len(prizes)) + for _, d := range draws { + p := prizes[d.PrizeIdx] + nowinner := false + winner := false + if totalDeposits.GT(sdk.ZeroInt()) && d.DrawValue.LT(p.DrawProbability) { + // Prize draw has a winner (inside the buffer owned by depositors) + // normalize draw position to make it a portion of the depositors owned buffer and ignore the potential extra unassigned buffer part + drawPosition := d.DrawValue.Quo(p.DrawProbability).MulInt(totalDeposits).RoundInt() + for i < len(drawBuffer) { + // keep iterating in the buffer + // winner is the one owning the current portion of the buffer + if drawPosition.LTE(drawBuffer[i]) { + dep := bufferToDeposit[drawBuffer[i]] + result.PrizeDraws[d.PrizeIdx] = PrizeDraw{ + Amount: prizes[d.PrizeIdx].Amount, + Winner: &dep, + } + result.TotalWinAmount = result.TotalWinAmount.Add(prizes[d.PrizeIdx].Amount) + result.TotalWinCount++ + winner = true + break + } else { + i++ + } + } + } else { + // Prize draw has no winner + result.PrizeDraws[d.PrizeIdx] = PrizeDraw{ + Amount: prizes[d.PrizeIdx].Amount, + Winner: nil, + } + nowinner = true + } + if !winner && !nowinner { + // This should never happen except in case of algorithm failure + return result, fmt.Errorf("failed to find an outcome for prize draw") + } + } + + return result, err +} + +// DistributePrizes distributes the prizes if they have a winner +func (k Keeper) DistributePrizes(ctx sdk.Context, fc feeCollector, dRes DrawResult, draw types.Draw) error { + var prizeRefs []types.PrizeRef + for _, pd := range dRes.PrizeDraws { + if pd.Winner != nil { + winnerAddress, err := sdk.AccAddressFromBech32(pd.Winner.Address) + if err != nil { + return types.ErrInvalidWinnerAddress + } + + nextPrizeId := k.GetNextPrizeIdAndIncrement(ctx) + + coin := sdk.NewCoin(draw.PrizePool.Denom, sdk.NewInt(pd.Amount.Int64())) + prize := types.Prize{ + PoolId: draw.PoolId, + DrawId: draw.DrawId, + PrizeId: nextPrizeId, + State: types.PrizeState_Pending, + WinnerAddress: winnerAddress.String(), + Amount: coin, + CreatedAtHeight: ctx.BlockHeight(), + UpdatedAtHeight: ctx.BlockHeight(), + ExpiresAt: ctx.BlockTime().Add(k.GetParams(ctx).PrizeExpirationDelta), + CreatedAt: ctx.BlockTime(), + UpdatedAt: ctx.BlockTime(), + } + + pz := types.PrizeRef{ + Amount: pd.Amount, + WinnerAddress: pd.Winner.Address, + PrizeId: prize.PrizeId, + } + prizeRefs = append(prizeRefs, pz) + + fc.CollectPrizeFees(ctx, &prize) + k.AddPrize(ctx, prize) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeNewPrize, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(prize.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDrawID, strconv.FormatUint(prize.DrawId, 10)), + sdk.NewAttribute(types.AttributeKeyPrizeID, strconv.FormatUint(prize.PrizeId, 10)), + sdk.NewAttribute(types.AttributeKeyWinner, prize.WinnerAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, prize.Amount.String()), + ), + }) + } + } + // Only update if we have a winner + if len(prizeRefs) > 0 { + draw.PrizesRefs = prizeRefs + draw.UpdatedAt = ctx.BlockTime() + draw.UpdatedAtHeight = ctx.BlockHeight() + // Update PoolDraw state with correct PrizesRefs + k.SetPoolDraw(ctx, draw) + } + + return nil +} + +// HasPoolDraw Returns a boolean that indicates if the given poolID and drawID combination exists in the KVStore or not +func (k Keeper) HasPoolDraw(ctx sdk.Context, poolID uint64, drawID uint64) bool { + store := ctx.KVStore(k.storeKey) + return store.Has(types.GetPoolDrawIDKey(poolID, drawID)) +} + +// SetPoolDraw Sets a draw result in the KVStore for a given poolID and drawID +func (k Keeper) SetPoolDraw(ctx sdk.Context, draw types.Draw) { + store := ctx.KVStore(k.storeKey) + encodedDraw := k.cdc.MustMarshal(&draw) + store.Set(types.GetPoolDrawIDKey(draw.GetPoolId(), draw.GetDrawId()), encodedDraw) +} + +// GetPoolDraw Returns a draw instance for the given poolID and drawID combination +func (k Keeper) GetPoolDraw(ctx sdk.Context, poolID uint64, drawID uint64) (types.Draw, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetPoolDrawIDKey(poolID, drawID)) + if bz == nil { + return types.Draw{}, errorsmod.Wrapf(types.ErrPoolDrawNotFound, "%d/%d", poolID, drawID) + } + + var draw types.Draw + if err := k.cdc.Unmarshal(bz, &draw); err != nil { + return types.Draw{}, err + } + + return draw, nil +} + +// PoolDrawsIterator Return a ready to use iterator for a pool draws store +func (k Keeper) PoolDrawsIterator(ctx sdk.Context, poolID uint64) sdk.Iterator { + kvStore := ctx.KVStore(k.storeKey) + return sdk.KVStorePrefixIterator(kvStore, types.GetPoolDrawsKey(poolID)) +} + +// IteratePoolDraws Iterates over a pool draws store, and for each entry call the callback +func (k Keeper) IteratePoolDraws(ctx sdk.Context, poolID uint64, cb func(draw types.Draw) bool) { + iterator := k.PoolDrawsIterator(ctx, poolID) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var draw types.Draw + k.cdc.MustUnmarshal(iterator.Value(), &draw) + + if cb(draw) { + break + } + } +} + +// ListPoolDraws return the full pool draws list +// expensive operation that should only be used by Genesis like features and unittests +func (k Keeper) ListPoolDraws(ctx sdk.Context, poolID uint64) (draws []types.Draw) { + k.IteratePoolDraws(ctx, poolID, func(draw types.Draw) bool { + draws = append(draws, draw) + return false + }) + return +} + +// DrawsIterator Return a ready to use iterator for the draws store (all draws from all pools) +func (k Keeper) DrawsIterator(ctx sdk.Context) sdk.Iterator { + kvStore := ctx.KVStore(k.storeKey) + return sdk.KVStorePrefixIterator(kvStore, types.DrawPrefix) +} + +// IterateDraws Iterate over the draws store (all draws from all pools), and for each entry call the callback +func (k Keeper) IterateDraws(ctx sdk.Context, cb func(draw types.Draw) bool) { + iterator := k.DrawsIterator(ctx) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var draw types.Draw + k.cdc.MustUnmarshal(iterator.Value(), &draw) + + if cb(draw) { + break + } + } +} + +// ListDraws return the full draws list (all draws from all pools) +// expensive operation that should only be used by Genesis like features +func (k Keeper) ListDraws(ctx sdk.Context) (draws []types.Draw) { + k.IterateDraws(ctx, func(draw types.Draw) bool { + draws = append(draws, draw) + return false + }) + return +} diff --git a/x/millions/keeper/keeper_draw_test.go b/x/millions/keeper/keeper_draw_test.go new file mode 100644 index 00000000..adf4f41d --- /dev/null +++ b/x/millions/keeper/keeper_draw_test.go @@ -0,0 +1,1557 @@ +package keeper_test + +import ( + "fmt" + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + distribtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/staking" + + apptesting "github.com/lum-network/chain/app/testing" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestDraw_NoPrizeToWin tests cases where no prize can be computed and therefore no winner +func (suite *KeeperTestSuite) TestDraw_NoPrizeToWin() { + app := suite.app + ctx := suite.ctx + + seed := int64(42) + + // Empty prize pool should return 0 prizes + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.ZeroInt()) + result, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + []millionskeeper.DepositTWB{}, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), result.TotalWinAmount) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 0) + + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[2].String(), Amount: sdk.NewInt(1_000_000)}, + }, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), result.TotalWinAmount) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 0) + + // No depositors should return prizes without winners + prizePool = sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)) + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + []millionskeeper.DepositTWB{}, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), result.TotalWinAmount) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 3) +} + +// TestDraw_NoPrizesWon tests the outcome of winnable prizes without winners +func (suite *KeeperTestSuite) TestDraw_NoPrizesWon() { + app := suite.app + ctx := suite.ctx + + seed := int64(84) + + // No depositors should return prizes without winners + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)) + result, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + []millionskeeper.DepositTWB{}, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), result.TotalWinAmount) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 3) + suite.Require().Nil(result.PrizeDraws[0].Winner) + suite.Require().Nil(result.PrizeDraws[1].Winner) + suite.Require().Nil(result.PrizeDraws[2].Winner) + + // Unlikely odds to win despite a large number of draws (deterministic due to the seed used) + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1000, DrawProbability: floatToDec(0.00001)}, + {PoolPercent: 30, Quantity: 100, DrawProbability: floatToDec(0.00001)}, + {PoolPercent: 50, Quantity: 10, DrawProbability: floatToDec(0.00001)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[2].String(), Amount: sdk.NewInt(1_000_000)}, + }, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), result.TotalWinAmount) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 1110) + for i, pd := range result.PrizeDraws { + suite.Require().Nil(pd.Winner, "prize draw %d unexpected winner", i) + } +} + +// TestDraw_PrizeComputation tests rounding approximation on prizes computations +func (suite *KeeperTestSuite) TestDraw_PrizeComputation() { + app := suite.app + ctx := suite.ctx + params := app.MillionsKeeper.GetParams(ctx) + + denom := app.StakingKeeper.BondDenom(ctx) + + pb1 := millionstypes.PrizeBatch{PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(1.0)} + suite.Require().NoError(pb1.Validate(params)) + suite.Require().Equal(int64(0), pb1.GetTotalPrizesAmount(sdk.NewCoin(denom, sdk.NewInt(0))).Int64()) + suite.Require().Equal(int64(100), pb1.GetTotalPrizesAmount(sdk.NewCoin(denom, sdk.NewInt(100))).Int64()) + suite.Require().Equal(int64(0), pb1.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(0))).Int64()) + suite.Require().Equal(int64(100), pb1.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(100))).Int64()) + + pb2 := millionstypes.PrizeBatch{PoolPercent: 100, Quantity: 100, DrawProbability: floatToDec(1.0)} + suite.Require().NoError(pb1.Validate(params)) + suite.Require().Equal(int64(0), pb2.GetTotalPrizesAmount(sdk.NewCoin(denom, sdk.NewInt(0))).Int64()) + suite.Require().Equal(int64(100), pb2.GetTotalPrizesAmount(sdk.NewCoin(denom, sdk.NewInt(100))).Int64()) + suite.Require().Equal(int64(0), pb2.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(0))).Int64()) + suite.Require().Equal(int64(1), pb2.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(100))).Int64()) + suite.Require().Equal(int64(0), pb2.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(99))).Int64()) + suite.Require().Equal(int64(1), pb2.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(101))).Int64()) + suite.Require().Equal(int64(9), pb2.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(990))).Int64()) + + pb3 := millionstypes.PrizeBatch{PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)} + suite.Require().NoError(pb1.Validate(params)) + suite.Require().Equal(int64(0), pb3.GetTotalPrizesAmount(sdk.NewCoin(denom, sdk.NewInt(0))).Int64()) + suite.Require().Equal(int64(1), pb3.GetTotalPrizesAmount(sdk.NewCoin(denom, sdk.NewInt(100))).Int64()) + suite.Require().Equal(int64(0), pb3.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(0))).Int64()) + suite.Require().Equal(int64(1), pb3.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(100))).Int64()) + suite.Require().Equal(int64(0), pb3.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(99))).Int64()) + suite.Require().Equal(int64(1), pb3.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(101))).Int64()) + suite.Require().Equal(int64(9), pb3.GetPrizeAmount(sdk.NewCoin(denom, sdk.NewInt(990))).Int64()) + + // We expect the prizes to be rounded down as a safety measure + // The rounding happens at total prize batch computation and at prize unit value computation + // Meaning that: + // - pb1 -> 990 * 98 / 100 = 970 -> 970 / 100 = 9 + // - pb2 -> 990 * 1 / 100 = 9 -> 9 / 10 = 0 + // - pb3 -> 990 * 1 / 100 = 9 -> 9 / 1 = 9 + // Totals: + // - pb1 -> 100 items for 900 total value + // - pb2 -> 0 items for 0 total value + // - pb3 -> 1 item for 9 total value + ps1 := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 98, Quantity: 100, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 1, Quantity: 10, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)}, + }, + } + suite.Require().NoError(ps1.Validate(params)) + ps1PrizesProbs, usedAmount, remainingAmount, err := ps1.ComputePrizesProbs(sdk.NewCoin(denom, sdk.NewInt(990))) + ps1PrizesSum := int64(0) + for _, p := range ps1PrizesProbs { + ps1PrizesSum += p.Amount.Int64() + } + suite.Require().NoError(err) + suite.Require().Len(ps1PrizesProbs, 101) + suite.Require().Equal(usedAmount.Int64(), ps1PrizesSum) + suite.Require().Equal(int64(909), usedAmount.Int64()) + suite.Require().Equal(int64(81), remainingAmount.Int64()) + + // Same configuration with large numbers should not result in rounding approximation + ps2 := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 98, Quantity: 100, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 1, Quantity: 10, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)}, + }, + } + suite.Require().NoError(ps1.Validate(params)) + ps2PrizesProbs, usedAmount, remainingAmount, err := ps2.ComputePrizesProbs(sdk.NewCoin(denom, sdk.NewInt(990000))) + ps2PrizesSum := int64(0) + for _, p := range ps2PrizesProbs { + ps2PrizesSum += p.Amount.Int64() + } + suite.Require().NoError(err) + suite.Require().Len(ps2PrizesProbs, 111) + suite.Require().Equal(usedAmount.Int64(), ps2PrizesSum) + suite.Require().Equal(int64(990000), usedAmount.Int64()) + suite.Require().Equal(int64(0), remainingAmount.Int64()) +} + +// TestDraw_UnusualPrizeCases tests if unusual cases lead to predictable behaviours +func (suite *KeeperTestSuite) TestDraw_UnusualPrizeCases() { + app := suite.app + ctx := suite.ctx + + seed := int64(336) + + // No depositors post TWB should result in no winner + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)) + result, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 100, DrawProbability: floatToDec(1.0)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(0)}, + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(0)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(0)}, + }, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 100) + for _, pd := range result.PrizeDraws { + suite.Require().Nil(pd.Winner) + } + + // Lone depositors should win with certainty + prizePool = sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)) + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 100, DrawProbability: floatToDec(1.0)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1_000_000)}, + }, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(uint64(100), result.TotalWinCount) + suite.Require().Len(result.PrizeDraws, 100) + for _, pd := range result.PrizeDraws { + suite.Require().NotNil(pd.Winner) + suite.Require().Equal(suite.addrs[0].String(), pd.Winner.Address) + } + + // Small deposits and prize pool should be possible even though they are not recommended + prizePool = sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)) + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 98, Quantity: 100, DrawProbability: floatToDec(1.0)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(1)}, + {Address: suite.addrs[2].String(), Amount: sdk.NewInt(1)}, + }, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(uint64(0), result.TotalWinCount) + suite.Require().Equal(int64(0), result.TotalWinAmount.Int64()) + + prizePool = sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(100)) + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 1, Quantity: 1, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 98, Quantity: 100, DrawProbability: floatToDec(1.0)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(1)}, + {Address: suite.addrs[2].String(), Amount: sdk.NewInt(1)}, + }, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(uint64(2), result.TotalWinCount) + suite.Require().Equal(int64(2), result.TotalWinAmount.Int64()) + + // Large deposits and prize pool should work as expected + prizePool = sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(int64(^uint64(0)>>1))) + result, err = app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 2, Quantity: 1, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 3, Quantity: 1, DrawProbability: floatToDec(1.0)}, + {PoolPercent: 95, Quantity: 1_000_000, DrawProbability: floatToDec(0.0)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: prizePool.Amount.QuoRaw(3)}, + {Address: suite.addrs[1].String(), Amount: prizePool.Amount.QuoRaw(3)}, + {Address: suite.addrs[2].String(), Amount: prizePool.Amount.QuoRaw(3)}, + }, + seed, + ) + suite.Require().Equal(int64(8762203435012), millionstypes.PrizeBatch{PoolPercent: 95, Quantity: 1_000_000, DrawProbability: floatToDec(0.0)}.GetPrizeAmount(prizePool).Int64()) + suite.Require().NoError(err) + suite.Require().Equal(uint64(2), result.TotalWinCount) + suite.Require().Equal(prizePool.Amount.QuoRaw(100).MulRaw(5).Int64(), result.TotalWinAmount.Int64()) +} + +// TestDraw_PrizesOrdering tests prizes descending ordering by amount +func (suite *KeeperTestSuite) TestDraw_PrizesOrdering() { + app := suite.app + ctx := suite.ctx + + seed := int64(168) + + // Prizes should always be order by value descending + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)) + result, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1000, DrawProbability: floatToDec(0.60)}, + {PoolPercent: 30, Quantity: 1000, DrawProbability: floatToDec(0.60)}, + {PoolPercent: 50, Quantity: 1000, DrawProbability: floatToDec(0.60)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[2].String(), Amount: sdk.NewInt(1_000_000)}, + }, + seed, + ) + suite.Require().NoError(err) + // wins should likely to be >= 55% <= 65% since all draws have 60% win chance + // not a very strong test condition but still helpful to debug early faulty implementations + suite.Require().True(result.TotalWinAmount.GTE(prizePool.Amount.MulRaw(55).QuoRaw(100))) + suite.Require().True(result.TotalWinAmount.LTE(prizePool.Amount.MulRaw(65).QuoRaw(100))) + suite.Require().True(result.TotalWinCount >= 3000*55/100) + suite.Require().True(result.TotalWinCount <= 3000*65/100) + suite.Require().Len(result.PrizeDraws, 3000) + for i := 1; i < len(result.PrizeDraws); i++ { + suite.Require().True(result.PrizeDraws[i].Amount.LTE(result.PrizeDraws[i-1].Amount)) + } +} + +// TestDraw_PrizesDrawDeterminism tests prizes draw determinism using the same input parameters +// Each draw using the same parameters should be identical (deterministic) +func (suite *KeeperTestSuite) TestDraw_PrizesDrawDeterminism() { + app := suite.app + ctx := suite.ctx + + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(42_000_000_000)) + depositors := []millionskeeper.DepositTWB{} + for i := 0; i < 100; i++ { + uid := fmt.Sprintf("small_%d", i) + depositors = append(depositors, millionskeeper.DepositTWB{Address: uid, Amount: sdk.NewInt(1_000_000)}) + } + + // Init stable strategy for all draws + strat := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 100, DrawProbability: floatToDec(1.0)}, + }, + } + + seed := int64(42) + firstDraw, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + strat, + depositors, + seed, + ) + suite.Require().NoError(err) + + for i := 0; i < 100; i++ { + draw, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + strat, + depositors, + seed, + ) + suite.Require().NoError(err) + suite.Require().Equal(firstDraw.TotalWinAmount.Int64(), draw.TotalWinAmount.Int64()) + suite.Require().Equal(firstDraw.TotalWinCount, draw.TotalWinCount) + suite.Require().Equal(len(firstDraw.PrizeDraws), len(draw.PrizeDraws)) + for j, pd := range draw.PrizeDraws { + suite.Require().Equal(firstDraw.PrizeDraws[j].Amount.Int64(), pd.Amount.Int64()) + if firstDraw.PrizeDraws[j].Winner == nil { + suite.Require().Nil(pd.Winner) + } else { + suite.Require().Equal(firstDraw.PrizeDraws[j].Winner.Address, pd.Winner.Address) + suite.Require().Equal(firstDraw.PrizeDraws[j].Winner.Amount.Int64(), pd.Winner.Amount.Int64()) + } + } + } +} + +// TestDraw_PrizePoolPersistence tests propagation of prize pool sources (fresh, clawback, remains) for subsequent draws +func (suite *KeeperTestSuite) TestDraw_PrizePoolPersistence() { + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + // Force save test pools + p := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 100, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + newID, err := app.MillionsKeeper.RegisterPool( + ctx, + p.Denom, p.NativeDenom, p.ChainId, p.ConnectionId, p.TransferChannelId, + []string{suite.valAddrs[0].String()}, + p.Bech32PrefixAccAddr, p.Bech32PrefixValAddr, + p.MinDepositAmount, + p.DrawSchedule, + p.PrizeStrategy, + ) + suite.Require().NoError(err) + pool1, err := app.MillionsKeeper.GetPool(ctx, newID) + suite.Require().NoError(err) + + p = newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.00)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + newID, err = app.MillionsKeeper.RegisterPool( + ctx, + p.Denom, p.NativeDenom, p.ChainId, p.ConnectionId, p.TransferChannelId, + []string{suite.valAddrs[0].String()}, + p.Bech32PrefixAccAddr, p.Bech32PrefixValAddr, + p.MinDepositAmount, + p.DrawSchedule, + p.PrizeStrategy, + ) + suite.Require().NoError(err) + pool2, err := app.MillionsKeeper.GetPool(ctx, newID) + suite.Require().NoError(err) + + // Pools should have 0 draw + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 0) + + // Run 2 draws for pool #2 + // - Create one deposit for pool #2 which will allow to draw prizes (no prize pool = no prizes) + // - Run reward distribution + // - Run draw #1 which should attribute 50% of the rewards + // - Run draw #2 which has no reward but should get the 50% rewards remaining from draw #1 + resp, err := msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(pool2.Denom, sdk.NewInt(1_000_000)), + pool2.PoolId, + )) + suite.Require().NoError(err) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, pool2.PoolId, resp.DepositId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DepositState_Success, deposit.State) + pool2Delegations := app.StakingKeeper.GetDelegatorDelegations(ctx, sdk.MustAccAddressFromBech32(pool2.IcaDepositAddress), 100) + suite.Require().Len(pool2Delegations, 1) + + // Move to next block and next draw + ctx = ctx.WithBlockTime(ctx.BlockTime().Add(pool2.DrawSchedule.DrawDelta)).WithBlockHeight(ctx.BlockHeight() + 1) + + // Manually trigger reward distribution phases + for _, val := range pool2.Validators { + validator, found := app.StakingKeeper.GetValidator(ctx, val.MustValAddressFromBech32()) + suite.Require().True(found) + + // Attribute delegation + staking.EndBlocker(ctx, *app.StakingKeeper) + err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, sdk.MustAccAddressFromBech32(pool2.IcaDepositAddress), val.MustValAddressFromBech32()) + suite.Require().NoError(err) + + // Simulate inflation minted + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin(pool2.Denom, sdk.NewInt(1_000_000)))) + suite.Require().NoError(err) + err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, distribtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(pool2.Denom, sdk.NewInt(1_000_000)))) + suite.Require().NoError(err) + app.DistrKeeper.AllocateTokensToValidator(ctx, validator, sdk.NewDecCoins(sdk.NewDecCoin(pool2.Denom, sdk.NewInt(1_000_000)))) + } + + // Move to next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // Run draw #1 + p2Draw1, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool2.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, p2Draw1.State) + suite.Require().Equal(pool2.PoolId, p2Draw1.PoolId) + suite.Require().Len(p2Draw1.PrizesRefs, 200) + suite.Require().Equal(200, int(p2Draw1.TotalWinCount)) + suite.Require().Equal(p2Draw1.PrizePool.Amount.Int64()/2, p2Draw1.TotalWinAmount.Int64()) + + // Run draw #2 + p2Draw2, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool2.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, p2Draw2.State) + suite.Require().Equal(pool2.PoolId, p2Draw2.PoolId) + suite.Require().Len(p2Draw2.PrizesRefs, 200) + suite.Require().Equal(200, int(p2Draw2.TotalWinCount)) + suite.Require().Equal(p2Draw1.PrizePool.Amount.Int64()/2, p2Draw2.PrizePoolRemainsAmount.Int64()) + suite.Require().Equal(p2Draw2.PrizePool.Amount.Int64()/2, p2Draw2.TotalWinAmount.Int64()) + suite.Require().Equal(p2Draw1.PrizePool.Amount.Int64()/4, p2Draw2.TotalWinAmount.Int64()) + + _, err = app.MillionsKeeper.GetPoolDraw(ctx, pool2.PoolId, 3) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 2) + suite.Require().Len(app.MillionsKeeper.ListPoolDraws(ctx, pool2.PoolId), 2) + + // Pool #1 should have 0 draw + suite.Require().Len(app.MillionsKeeper.ListPoolDraws(ctx, pool1.PoolId), 0) + + // Run 3 draws for pool #1 which should have no effect since their is no depositor + _, err = msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(pool1.Denom, sdk.NewInt(1_000_000)), + pool1.PoolId, + )) + suite.Require().NoError(err) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1_000) + p1Draw1, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool1.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, p1Draw1.State) + + _, err = msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(pool1.Denom, sdk.NewInt(1_000_000)), + pool1.PoolId, + )) + suite.Require().NoError(err) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1_000) + p1Draw2, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool1.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, p1Draw2.State) + + _, err = msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(pool1.Denom, sdk.NewInt(1_000_000)), + pool1.PoolId, + )) + suite.Require().NoError(err) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1_000) + p1Draw3, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool1.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, p1Draw3.State) + + for i := 1; i <= 3; i++ { + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pool1.PoolId, uint64(i)) + suite.Require().NoError(err) + suite.Require().Equal(pool1.PoolId, draw.PoolId) + suite.Require().Equal(uint64(i), draw.DrawId) + suite.Require().NotEqual(int64(0), draw.RandSeed) + suite.Require().Len(draw.PrizesRefs, 0) + suite.Require().Equal(uint64(0), draw.TotalWinCount) + suite.Require().Equal(sdk.ZeroInt(), draw.TotalWinAmount) + } + _, err = app.MillionsKeeper.GetPoolDraw(ctx, pool1.PoolId, 4) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + suite.Require().Len(app.MillionsKeeper.ListDraws(ctx), 5) + suite.Require().Len(app.MillionsKeeper.ListPoolDraws(ctx, pool1.PoolId), 3) + + // Pool #2 should still have 2 draws + for i := 1; i <= 2; i++ { + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pool2.PoolId, uint64(i)) + suite.Require().NoError(err) + suite.Require().Equal(pool2.PoolId, draw.PoolId) + suite.Require().Equal(uint64(i), draw.DrawId) + suite.Require().NotEqual(int64(0), draw.RandSeed) + } + _, err = app.MillionsKeeper.GetPoolDraw(ctx, pool2.PoolId, 3) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + suite.Require().Len(app.MillionsKeeper.ListPoolDraws(ctx, pool2.PoolId), 2) + + // Draws should be ordered by alphabetical order (poolID then drawID) + allDraws := app.MillionsKeeper.ListDraws(ctx) + suite.Require().Equal(pool1.PoolId, allDraws[0].PoolId) + suite.Require().Equal(uint64(1), allDraws[0].DrawId) + suite.Require().Equal(pool1.PoolId, allDraws[1].PoolId) + suite.Require().Equal(uint64(2), allDraws[1].DrawId) + suite.Require().Equal(pool1.PoolId, allDraws[2].PoolId) + suite.Require().Equal(uint64(3), allDraws[2].DrawId) + suite.Require().Equal(pool2.PoolId, allDraws[3].PoolId) + suite.Require().Equal(uint64(1), allDraws[3].DrawId) + suite.Require().Equal(pool2.PoolId, allDraws[4].PoolId) + suite.Require().Equal(uint64(2), allDraws[4].DrawId) + + draws1 := app.MillionsKeeper.ListPoolDraws(ctx, pool1.PoolId) + suite.Require().Equal(pool1.PoolId, draws1[0].PoolId) + suite.Require().Equal(uint64(1), draws1[0].DrawId) + suite.Require().Equal(pool1.PoolId, draws1[1].PoolId) + suite.Require().Equal(uint64(2), draws1[1].DrawId) + suite.Require().Equal(pool1.PoolId, draws1[2].PoolId) + suite.Require().Equal(uint64(3), draws1[2].DrawId) + + draws2 := app.MillionsKeeper.ListPoolDraws(ctx, pool2.PoolId) + suite.Require().Equal(pool2.PoolId, draws2[0].PoolId) + suite.Require().Equal(uint64(1), draws2[0].DrawId) + suite.Require().Equal(pool2.PoolId, draws2[1].PoolId) + suite.Require().Equal(uint64(2), draws2[1].DrawId) +} + +// TestDraw_TimeWeightedBalance tests TWB enforcement at draw level +func (suite *KeeperTestSuite) TestDraw_TimeWeightedBalance() { + app := suite.app + ctx := suite.ctx + + // Init fake pool + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.50)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(0.70)}, + }, + }, + }) + app.MillionsKeeper.AddPool(ctx, pool) + + // Simulate deposits at various time for first draw + t0 := time.Now().UTC() + denom := app.StakingKeeper.BondDenom(ctx) + dState := millionstypes.DepositState_Success + depositsTWB := app.MillionsKeeper.ComputeDepositsTWB( + ctx, + t0.Add(-1_000_000*time.Second), + t0, + []millionstypes.Deposit{ + {State: dState, CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-1_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-500_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-250_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(0 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(1_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, IsSponsor: true, WinnerAddress: "6", DepositorAddress: "6", CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, WinnerAddress: "8", DepositorAddress: "7", CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: millionstypes.DepositState_Failure, CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + }, + ) + suite.Require().Equal(int64(1_000_000), depositsTWB[0].Amount.Int64()) + suite.Require().Equal(int64(1_000_000), depositsTWB[1].Amount.Int64()) + suite.Require().Equal(int64(500_000), depositsTWB[2].Amount.Int64()) + suite.Require().Equal(int64(250_000), depositsTWB[3].Amount.Int64()) + suite.Require().Equal(int64(0), depositsTWB[4].Amount.Int64()) + suite.Require().Equal(int64(0), depositsTWB[5].Amount.Int64()) + // TWB should not return sponsors since they waive their drawing chances + suite.Require().Len(depositsTWB, 7) + suite.Require().Equal("8", depositsTWB[6].Address) + + // Simulate deposits at various time for a subsequent draw + params := app.MillionsKeeper.GetParams(ctx) + lastDrawAt := t0.Add(-500_000 * time.Second) + depositsTWB = app.MillionsKeeper.ComputeDepositsTWB( + ctx, + lastDrawAt, + t0, + []millionstypes.Deposit{ + {State: dState, CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-1_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-500_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-250_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-params.MinDepositDrawDelta), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(-params.MinDepositDrawDelta + 1*time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(0 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, CreatedAt: t0.Add(1_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, IsSponsor: true, WinnerAddress: "6", DepositorAddress: "6", CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: dState, WinnerAddress: "8", DepositorAddress: "7", CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + {State: millionstypes.DepositState_IbcTransfer, CreatedAt: t0.Add(-2_000_000 * time.Second), Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000))}, + }, + ) + suite.Require().Equal(int64(1_000_000), depositsTWB[0].Amount.Int64()) + suite.Require().Equal(int64(1_000_000), depositsTWB[1].Amount.Int64()) + suite.Require().Equal(int64(1_000_000), depositsTWB[2].Amount.Int64()) + suite.Require().Equal(int64(500_000), depositsTWB[3].Amount.Int64()) + suite.Require().Greater(depositsTWB[4].Amount.Int64(), int64(0)) + suite.Require().Equal(int64(0), depositsTWB[5].Amount.Int64()) + suite.Require().Equal(int64(0), depositsTWB[6].Amount.Int64()) + suite.Require().Equal(int64(0), depositsTWB[7].Amount.Int64()) + // TWB should not return sponsors since they waive their drawing chances + suite.Require().Len(depositsTWB, 9) + suite.Require().Equal("8", depositsTWB[8].Address) +} + +// TestDraw_PrizeDistribution tests draw prize distribution phase +func (suite *KeeperTestSuite) TestDraw_PrizeDistribution() { + app := suite.app + ctx := suite.ctx + + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + + seed := int64(84) + + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)) + drawRes, err := app.MillionsKeeper.RunDrawPrizes(ctx, + prizePool, + millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + []millionskeeper.DepositTWB{ + {Address: suite.addrs[0].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[1].String(), Amount: sdk.NewInt(1_000_000)}, + {Address: suite.addrs[2].String(), Amount: sdk.NewInt(1_000_000)}, + }, + seed, + ) + suite.Require().NoError(err) + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.5)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(0.7)}, + }, + }, + }) + app.MillionsKeeper.AddPool(ctx, pool) + + app.MillionsKeeper.SetPoolDraw(ctx, millionstypes.Draw{ + PoolId: poolID, + DrawId: pool.GetNextDrawId(), + State: millionstypes.DrawState_Drawing, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + }) + + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, poolID, pool.GetNextDrawId()) + suite.Require().NoError(err) + + err = app.MillionsKeeper.DistributePrizes(ctx, app.MillionsKeeper.NewFeeCollector(ctx, *pool), drawRes, draw) + suite.Require().NoError(err) + + for _, pd := range drawRes.PrizeDraws { + if pd.Winner != nil { + winnerAddress, err := sdk.AccAddressFromBech32(pd.Winner.Address) + suite.Require().NoError(err) + accountPrizes := app.MillionsKeeper.ListAccountPoolPrizes(ctx, winnerAddress, poolID) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(accountPrizes), 1) + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, poolID, pool.GetNextDrawId()) + suite.Require().NoError(err) + suite.Require().GreaterOrEqual(len(draw.PrizesRefs), 1) + } + } + +} + +// TestDraw_TriggerAndPrizePool tests draw triggered by block updates and prize pool computation +func (suite *KeeperTestSuite) TestDraw_TriggerAndPrizePool() { + app := suite.app + ctx := suite.ctx + + // Create pool with a fake amount already available + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour), + DrawDelta: 24 * time.Hour, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + + // First draw should pick up the available prize pool amount but return it to the pool (no winner) + app.MillionsKeeper.BlockPoolUpdates(ctx.WithBlockTime(ctx.BlockTime().Add(25 * time.Hour))) + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(math.NewInt(1000), pool.AvailablePrizePool.Amount) + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pool.PoolId, pool.NextDrawId-1) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + suite.Require().Equal(math.NewInt(1000), draw.PrizePoolRemainsAmount) + suite.Require().Equal(sdk.ZeroInt(), draw.PrizePoolFreshAmount) + suite.Require().Equal(math.NewInt(1000), draw.PrizePool.Amount) + + // Simulate a prize clawback + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: poolID, + DrawId: pool.NextDrawId, + PrizeId: 1, + Amount: sdk.NewCoin(pool.Denom, math.NewInt(200)), + WinnerAddress: suite.addrs[1].String(), + CreatedAt: ctx.BlockTime(), + ExpiresAt: ctx.BlockTime().Add(1 * time.Second), + State: millionstypes.PrizeState_Pending, + }) + app.MillionsKeeper.BlockPrizeUpdates(ctx.WithBlockTime(ctx.BlockTime().Add(50 * time.Hour))) + + // Pool should have clawed back the amount + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(math.NewInt(1200), pool.AvailablePrizePool.Amount) + + // Next draw should pick the new available amount but return it to the pool (still no winner) + app.MillionsKeeper.BlockPoolUpdates(ctx.WithBlockTime(ctx.BlockTime().Add(50 * time.Hour))) + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().Equal(math.NewInt(1200), pool.AvailablePrizePool.Amount) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pool.PoolId, pool.NextDrawId-1) + suite.Require().NoError(err) + suite.Require().NoError(err) + suite.Require().Equal(math.NewInt(1200), draw.PrizePoolRemainsAmount) + suite.Require().Equal(math.NewInt(0), draw.PrizePoolFreshAmount) + suite.Require().Equal(math.NewInt(1200), draw.PrizePool.Amount) +} + +// TestDraw_EvenPrizeDistributionLLN tests if the prize distribution abides by the law of large numbers +// A large number of draws should converge to the expected drawing probabilities +// In this case an even distribution for depositors with similar amounts +func (suite *KeeperTestSuite) TestDraw_EvenPrizeDistributionLLN() { + app := suite.app + ctx := suite.ctx + + type balanceControl struct { + address string + deposit math.Int + inflationGains math.Int + millionsGains math.Int + millionsDrawn int + } + + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(0)) + // Prepare expected inflation + yearlyInflation := 0.34 + weeklyInflation := math.LegacyNewDecWithPrec(int64(yearlyInflation/52.0*1_000_000), 6) + // Prepare depositors + depositors := []millionskeeper.DepositTWB{} + balancesControls := map[string]*balanceControl{} + for i := 0; i < 100; i++ { + uid := fmt.Sprintf("small_%d", i) + deposit := sdk.NewCoin(prizePool.Denom, sdk.NewInt(1_000_000)) + depositors = append(depositors, millionskeeper.DepositTWB{Address: uid, Amount: deposit.Amount}) + balancesControls[uid] = &balanceControl{address: uid, deposit: deposit.Amount, inflationGains: math.ZeroInt(), millionsGains: math.ZeroInt()} + } + + // Init stable strategy for all draws + strat := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 100, DrawProbability: floatToDec(1.0)}, + }, + } + + // Simulate 52,000 weekly draws (1000 years) + totalInf := math.ZeroInt() + totalWinAmount := math.ZeroInt() + totalWinners := 0 + remainsFromLastDraw := math.ZeroInt() + drawCount := 52_000 + for i := 0; i < drawCount; i++ { + seed := int64(42 * (i + 1)) + + // Attribute inflation gains and compute prizePool + prizePool := math.ZeroInt().Add(remainsFromLastDraw) + for i := range balancesControls { + inf := weeklyInflation.MulInt(balancesControls[i].deposit).RoundInt() + balancesControls[i].inflationGains = balancesControls[i].inflationGains.Add(inf) + prizePool = prizePool.Add(inf) + totalInf = totalInf.Add(inf) + } + + // DrawPrizes and save results + results, err := app.MillionsKeeper.RunDrawPrizes(ctx, + sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), prizePool), + strat, + depositors, + seed, + ) + suite.Require().NoError(err, "error at draw %d: %v", i, err) + totalWinAmount = totalWinAmount.Add(results.TotalWinAmount) + totalWinners += int(results.TotalWinCount) + remainsFromLastDraw = prizePool.Sub(results.TotalWinAmount) + for _, d := range results.PrizeDraws { + if d.Winner != nil { + balancesControls[d.Winner.Address].millionsGains = balancesControls[d.Winner.Address].millionsGains.Add(d.Amount) + balancesControls[d.Winner.Address].millionsDrawn++ + } + } + } + + // Number of wins should be close to probabilities (less than 0.01% difference) + probaTotalWinners := float64(0) + for _, pb := range strat.PrizeBatches { + drawProb, err := pb.DrawProbability.Float64() + suite.Require().NoError(err) + probaTotalWinners += float64(pb.Quantity) * drawProb * float64(drawCount) + } + + suite.Require().Greater(float64(totalWinners)/float64(probaTotalWinners), 0.999) + suite.Require().Less(float64(totalWinners)/float64(probaTotalWinners), 1.001) + // Draws outcome + remains should be equal to inflation + suite.Require().Equal(totalInf.Int64(), totalWinAmount.Add(remainsFromLastDraw).Int64()) + // Draws outcome should be close to inflation (less than 0.01% difference) + suite.Require().Greater(float64(totalWinAmount.Int64())/float64(totalInf.Int64()), 0.999) + suite.Require().Less(float64(totalWinAmount.Int64())/float64(totalInf.Int64()), 1.001) + + // Each depositor gains should be close to inflation (less than 0.1% difference) since they are all identical + for _, b := range balancesControls { + suite.Require().Greater(float64(b.millionsGains.Int64())/float64(b.inflationGains.Int64()), float64(0.99)) + suite.Require().Less(float64(b.millionsGains.Int64())/float64(b.inflationGains.Int64()), float64(1.01)) + } +} + +// TestDraw_WeightedPrizeDistributionLLN tests if the prize distribution abides by the law of large numbers +// A large number of draws should converge to the expected drawing probabilities +// In this case a weighted distribution based on each depositor stakes +func (suite *KeeperTestSuite) TestDraw_WeightedPrizeDistributionLLN() { + app := suite.app + ctx := suite.ctx + + type balanceControl struct { + address string + deposit math.Int + inflationGains math.Int + millionsGains math.Int + millionsDrawn int + } + + prizePool := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(0)) + // Prepare expected inflation + yearlyInflation := 0.34 + weeklyInflation := math.LegacyNewDecWithPrec(int64(yearlyInflation/52.0*1_000_000), 6) + // Prepare depositors + depositors := []millionskeeper.DepositTWB{} + balancesControls := map[string]*balanceControl{} + // large depositors + for i := 0; i < 10; i++ { + uid := fmt.Sprintf("large_%d", i) + deposit := sdk.NewCoin(prizePool.Denom, sdk.NewInt(100_000_000)) + depositors = append(depositors, millionskeeper.DepositTWB{Address: uid, Amount: deposit.Amount}) + balancesControls[uid] = &balanceControl{address: uid, deposit: deposit.Amount, inflationGains: math.ZeroInt(), millionsGains: math.ZeroInt()} + } + // medium depositors + for i := 0; i < 20; i++ { + uid := fmt.Sprintf("medium_%d", i) + deposit := sdk.NewCoin(prizePool.Denom, sdk.NewInt(10_000_000)) + depositors = append(depositors, millionskeeper.DepositTWB{Address: uid, Amount: deposit.Amount}) + balancesControls[uid] = &balanceControl{address: uid, deposit: deposit.Amount, inflationGains: math.ZeroInt(), millionsGains: math.ZeroInt()} + } + // small depositors + for i := 0; i < 40; i++ { + uid := fmt.Sprintf("small_%d", i) + deposit := sdk.NewCoin(prizePool.Denom, sdk.NewInt(1_000_000)) + depositors = append(depositors, millionskeeper.DepositTWB{Address: uid, Amount: deposit.Amount}) + balancesControls[uid] = &balanceControl{address: uid, deposit: deposit.Amount, inflationGains: math.ZeroInt(), millionsGains: math.ZeroInt()} + } + + // Init stable strategy for all draws + strat := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 200, DrawProbability: floatToDec(0.80)}, + }, + } + + // Simulate 52,000 weekly draws (1000 years) + totalInf := math.ZeroInt() + totalWinAmount := math.ZeroInt() + totalWinners := 0 + remainsFromLastDraw := math.ZeroInt() + drawCount := 52_000 + for i := 0; i < drawCount; i++ { + seed := int64(84 * (i + 1)) + + // Attribute inflation gains and compute prizePool + prizePool := math.ZeroInt().Add(remainsFromLastDraw) + for i := range balancesControls { + inf := weeklyInflation.MulInt(balancesControls[i].deposit).RoundInt() + balancesControls[i].inflationGains = balancesControls[i].inflationGains.Add(inf) + prizePool = prizePool.Add(inf) + totalInf = totalInf.Add(inf) + } + + // DrawPrizes and save results + results, err := app.MillionsKeeper.RunDrawPrizes(ctx, + sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), prizePool), + strat, + depositors, + seed, + ) + suite.Require().NoError(err, "error at draw %d: %v", i, err) + totalWinAmount = totalWinAmount.Add(results.TotalWinAmount) + totalWinners += int(results.TotalWinCount) + remainsFromLastDraw = prizePool.Sub(results.TotalWinAmount) + for _, d := range results.PrizeDraws { + if d.Winner != nil { + balancesControls[d.Winner.Address].millionsGains = balancesControls[d.Winner.Address].millionsGains.Add(d.Amount) + balancesControls[d.Winner.Address].millionsDrawn++ + } + } + } + + // Number of wins should be close to probabilities (less than 0.01% difference) + probaTotalWinners := float64(0) + for _, pb := range strat.PrizeBatches { + drawProb, err := pb.DrawProbability.Float64() + suite.Require().NoError(err) + probaTotalWinners += float64(pb.Quantity) * drawProb * float64(drawCount) + } + + suite.Require().Greater(float64(totalWinners)/float64(probaTotalWinners), 0.999) + suite.Require().Less(float64(totalWinners)/float64(probaTotalWinners), 1.001) + // Draws outcome + remains should be equal to inflation + suite.Require().Equal(totalInf.Int64(), totalWinAmount.Add(remainsFromLastDraw).Int64()) + // Draws outcome should be close to inflation (less than 0.01% difference) + suite.Require().Greater(float64(totalWinAmount.Int64())/float64(totalInf.Int64()), 0.999) + suite.Require().Less(float64(totalWinAmount.Int64())/float64(totalInf.Int64()), 1.00) + + // Each depositor gains should be close to inflation (less than 5% difference) + // A higher difference from inflation is understandable here especially for small depositors for which a win + // is less likely but has a higher impact on their final balance + for _, b := range balancesControls { + suite.Require().Greater(float64(b.millionsGains.Int64())/float64(b.inflationGains.Int64()), float64(0.95)) + suite.Require().Less(float64(b.millionsGains.Int64())/float64(b.inflationGains.Int64()), float64(1.05)) + } +} + +// TestDraw_IDsGeneration test that drawID is always incremented for a new draw +func (suite *KeeperTestSuite) TestDraw_IDsGeneration() { + app := suite.app + ctx := suite.ctx + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: uint64(1), + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 10, DrawProbability: floatToDec(1.00)}, + }, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1_000_000)), + }) + app.MillionsKeeper.AddPool(ctx, pool) + // Launch 10 new draws + for i := 0; i < 10; i++ { + poolDraw, err := app.MillionsKeeper.LaunchNewDraw(ctx, pool.PoolId) + suite.Require().NoError(err) + // drawID should increment by 1 + suite.Require().Equal(uint64(i+1), poolDraw.DrawId) + } +} + +// TestDraw_SetPoolDraw tests that a draw result is set in the KVStore for a given poolID and drawID +func (suite *KeeperTestSuite) TestDraw_SetPoolDraw() { + app := suite.app + ctx := suite.ctx + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: uint64(1), + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 10, DrawProbability: floatToDec(1.00)}, + }, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1_000_000)), + }) + draw1 := millionstypes.Draw{ + PoolId: pool.PoolId, + DrawId: uint64(1), + State: millionstypes.DrawState_Drawing, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + // List draws + app.MillionsKeeper.SetPoolDraw(ctx, draw1) + draws := app.MillionsKeeper.ListDraws(ctx) + suite.Require().Len(draws, 1) + draws = app.MillionsKeeper.ListPoolDraws(ctx, pool.PoolId) + suite.Require().Len(draws, 1) + + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pool.PoolId, draw1.DrawId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Drawing, draw.State) + // Update the same draw + draw1.State = millionstypes.DrawState_Success + app.MillionsKeeper.SetPoolDraw(ctx, draw1) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pool.PoolId, draw1.DrawId) + suite.Require().NoError(err) + + // Verify the state was updated + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + + // Create second draw + draw2 := millionstypes.Draw{ + PoolId: pool.PoolId, + DrawId: uint64(2), + State: millionstypes.DrawState_Success, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw2) + draws = app.MillionsKeeper.ListDraws(ctx) + suite.Require().Len(draws, 2) + draws = app.MillionsKeeper.ListPoolDraws(ctx, pool.PoolId) + suite.Require().Len(draws, 2) + + // Create third draw + draw3 := millionstypes.Draw{ + PoolId: pool.PoolId, + DrawId: uint64(3), + State: millionstypes.DrawState_Success, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw3) + draws = app.MillionsKeeper.ListDraws(ctx) + suite.Require().Len(draws, 3) + draws = app.MillionsKeeper.ListPoolDraws(ctx, pool.PoolId) + suite.Require().Len(draws, 3) +} + +// TestDraw_ClaimRewardsOnNativeChain tests claim of staking rewards from the native chain validators +func (suite *KeeperTestSuite) TestDraw_ClaimRewardsOnNativeChain() { + app := suite.app + ctx := suite.ctx + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + goCtx := sdk.WrapSDKContext(ctx) + + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + uatomAddress7 := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), remotePoolDenom) + suite.addrs = append(suite.addrs, uatomAddress7...) + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: remoteBech32PrefixValAddr, + ChainId: remoteChainId, + Denom: remotePoolDenom, + NativeDenom: remotePoolDenom, + ConnectionId: remoteConnectionId, + TransferChannelId: remoteTransferChannelId, + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(remotePoolDenom, math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + + draw1 := millionstypes.Draw{ + PoolId: pools[0].PoolId, + DrawId: pools[0].GetNextDrawId(), + State: millionstypes.DrawState_IcaWithdrawRewards, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw1) + // Test to acquire a pool with wrong poolID + _, err := app.MillionsKeeper.ClaimRewardsOnNativeChain(ctx, uint64(0), pools[0].NextDrawId) + suite.Require().ErrorIs(err, millionstypes.ErrPoolNotFound) + // Test to acquire a draw with wrong drawID + _, err = app.MillionsKeeper.ClaimRewardsOnNativeChain(ctx, pools[0].PoolId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + // Test state before callBack + suite.Require().Equal(millionstypes.DrawState_IcaWithdrawRewards, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + // Simulate failed callBack + _, err = app.MillionsKeeper.OnClaimRewardsOnNativeChainCompleted(ctx, draw.PoolId, draw.DrawId, true) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + // Test state after callBack + suite.Require().Equal(millionstypes.DrawState_Failure, draw.State) + suite.Require().Equal(millionstypes.DrawState_IcaWithdrawRewards, draw.ErrorState) + // Update draw state to do a retrial + draw.State = millionstypes.DrawState_IcaWithdrawRewards + draw.ErrorState = millionstypes.DrawState_Unspecified + app.MillionsKeeper.SetPoolDraw(ctx, draw) + // Simulate successful ICA callback + // Move to ICQ phase (query available prize pool) + _, err = app.MillionsKeeper.OnClaimRewardsOnNativeChainCompleted(ctx, draw.PoolId, draw.DrawId, false) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_IcqBalance, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + // Simulate succesful ICQ callback + // Should complete the Draw since no coins was found by the simulated callback (skip transfer phase) + _, err = app.MillionsKeeper.OnQueryRewardsOnNativeChainCompleted(ctx, draw.PoolId, draw.DrawId, sdk.NewCoins(), false) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + + // Test claimrewards for local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + // List pools + pools = app.MillionsKeeper.ListPools(ctx) + _, err = msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + pools[1].PoolId, + )) + suite.Require().NoError(err) + + draw2 := millionstypes.Draw{ + PoolId: pools[1].PoolId, + DrawId: pools[1].GetNextDrawId(), + State: millionstypes.DrawState_IcaWithdrawRewards, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw2) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_IcaWithdrawRewards, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + + // Trigger ClaimRewardsOnNativeChain + _, err = app.MillionsKeeper.ClaimRewardsOnNativeChain(ctx, draw.PoolId, draw.DrawId) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) +} + +// TestDraw_TransferRewardsToLocalChain tests the transfer of the claimed rewards to the local chain +func (suite *KeeperTestSuite) TestDraw_TransferRewardsToLocalChain() { + app := suite.app + ctx := suite.ctx + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + goCtx := sdk.WrapSDKContext(ctx) + + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + uatomAddress7 := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), remotePoolDenom) + suite.addrs = append(suite.addrs, uatomAddress7...) + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: remoteBech32PrefixValAddr, + ChainId: remoteChainId, + Denom: remotePoolDenom, + NativeDenom: remotePoolDenom, + ConnectionId: remoteConnectionId, + TransferChannelId: remoteTransferChannelId, + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(remotePoolDenom, math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + + draw1 := millionstypes.Draw{ + PoolId: pools[0].PoolId, + DrawId: pools[0].GetNextDrawId(), + State: millionstypes.DrawState_IbcTransfer, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw1) + // Test to acquire a pool with wrong poolID + _, err := app.MillionsKeeper.TransferRewardsToLocalChain(ctx, uint64(0), pools[0].NextDrawId) + suite.Require().ErrorIs(err, millionstypes.ErrPoolNotFound) + // Test to acquire a draw with wrong drawID + _, err = app.MillionsKeeper.TransferRewardsToLocalChain(ctx, pools[0].PoolId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + // Test state before failed callBack + suite.Require().Equal(millionstypes.DrawState_IbcTransfer, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + // Simulate failed callBack + _, err = app.MillionsKeeper.OnTransferRewardsToLocalChainCompleted(ctx, draw.PoolId, draw.DrawId, true) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + // Test state after callBack + suite.Require().Equal(millionstypes.DrawState_Failure, draw.State) + suite.Require().Equal(millionstypes.DrawState_IbcTransfer, draw.ErrorState) + // Update draw state to do a retrial + draw.State = millionstypes.DrawState_IbcTransfer + draw.ErrorState = millionstypes.DrawState_Unspecified + app.MillionsKeeper.SetPoolDraw(ctx, draw) + // Simulate successful callBack + _, err = app.MillionsKeeper.OnTransferRewardsToLocalChainCompleted(ctx, draw.PoolId, draw.DrawId, false) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().NoError(err) + // Test state after successful callback + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + + // Test transferRewards for local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + // List pools + pools = app.MillionsKeeper.ListPools(ctx) + _, err = msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + pools[1].PoolId, + )) + suite.Require().NoError(err) + + draw2 := millionstypes.Draw{ + PoolId: pools[1].PoolId, + DrawId: pools[1].GetNextDrawId(), + State: millionstypes.DrawState_IbcTransfer, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw2) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + // Test state before TransferRewardsToLocalChain + suite.Require().Equal(millionstypes.DrawState_IbcTransfer, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + + // Trigger TransferRewardsToLocalChain + _, err = app.MillionsKeeper.TransferRewardsToLocalChain(ctx, draw.PoolId, draw.DrawId) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + // Test state after TransferRewardsToLocalChain + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) +} + +// TestDraw_ExecuteDraw test the last draw phases by drawing prizes +func (suite *KeeperTestSuite) TestDraw_ExecuteDraw() { + app := suite.app + ctx := suite.ctx + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + goCtx := sdk.WrapSDKContext(ctx) + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: uint64(1), + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 2, DrawProbability: floatToDec(1.00)}, + }, + }, + }) + app.MillionsKeeper.AddPool(ctx, pool) + pools := app.MillionsKeeper.ListPools(ctx) + + draw1 := millionstypes.Draw{ + PoolId: pools[0].PoolId, + DrawId: pools[0].GetNextDrawId(), + State: millionstypes.DrawState_IbcTransfer, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw1) + // Test to acquire a pool with wrong poolID + _, err := app.MillionsKeeper.ExecuteDraw(ctx, uint64(0), pools[0].NextDrawId) + suite.Require().ErrorIs(err, millionstypes.ErrPoolNotFound) + // Test to acquire a draw with wrong drawID + _, err = app.MillionsKeeper.ExecuteDraw(ctx, pools[0].PoolId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + // Test to acquire that the draw has a valid state + _, err = app.MillionsKeeper.ExecuteDraw(ctx, pools[0].PoolId, pools[0].NextDrawId) + suite.Require().ErrorIs(err, millionstypes.ErrIllegalStateOperation) + + pool = newValidPool(suite, millionstypes.Pool{ + PoolId: uint64(2), + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.00)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(1.00)}, + }, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1_000_000)), + }) + app.MillionsKeeper.AddPool(ctx, pool) + pools = app.MillionsKeeper.ListPools(ctx) + + _, err = msgServer.Deposit(goCtx, millionstypes.NewMsgDeposit( + suite.addrs[0].String(), + sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + pools[1].PoolId, + )) + suite.Require().NoError(err) + + // Create new draw + draw2 := millionstypes.Draw{ + PoolId: pools[1].PoolId, + DrawId: pools[1].GetNextDrawId(), + State: millionstypes.DrawState_Drawing, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + UpdatedAtHeight: ctx.BlockHeight(), + UpdatedAt: ctx.BlockTime(), + } + + app.MillionsKeeper.SetPoolDraw(ctx, draw2) + + // Test draw before draw execution + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + suite.Require().Zero(draw.RandSeed) + suite.Require().Equal(int64(0), draw.PrizePoolRemainsAmount.Int64()) + suite.Require().Equal(int64(1_000_000), draw.PrizePool.Amount.Int64()) + + _, err = app.MillionsKeeper.ExecuteDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, pools[1].PoolId, pools[1].NextDrawId) + suite.Require().NoError(err) + // Test properties after successful draw execution + suite.Require().Equal(millionstypes.DrawState_Success, draw.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw.ErrorState) + suite.Require().NotZero(draw.RandSeed) + suite.Require().Equal(int64(1_000_000), draw.PrizePoolRemainsAmount.Int64()) + suite.Require().Equal(int64(2_000_000), draw.PrizePool.Amount.Int64()) +} diff --git a/x/millions/keeper/keeper_fees.go b/x/millions/keeper/keeper_fees.go new file mode 100644 index 00000000..429ed704 --- /dev/null +++ b/x/millions/keeper/keeper_fees.go @@ -0,0 +1,60 @@ +package keeper + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/lum-network/chain/x/millions/types" +) + +type feeCollector struct { + keeper Keeper + pool types.Pool + feesStakers sdk.Dec + stakersAmount sdk.Coin +} + +// NewFeeCollector creates a new fee collector for the specified pool +func (k Keeper) NewFeeCollector(ctx sdk.Context, pool types.Pool) feeCollector { + params := k.GetParams(ctx) + feesStaker := params.FeesStakers + if feesStaker.IsNil() { + feesStaker = sdk.ZeroDec() + } + return feeCollector{ + keeper: k, + pool: pool, + feesStakers: feesStaker, + stakersAmount: sdk.NewCoin(pool.Denom, math.ZeroInt()), + } +} + +// CollectedAmount returns the collected and not sent amount +func (fc *feeCollector) CollectedAmount() sdk.Coin { + return fc.stakersAmount +} + +// CollectPrizeFees computes and collects the fees for a prize and updates its final amount +func (fc *feeCollector) CollectPrizeFees(ctx sdk.Context, prize *types.Prize) (newAmount, fees math.Int) { + fees = fc.feesStakers.MulInt(prize.Amount.Amount).RoundInt() + fc.stakersAmount = fc.stakersAmount.AddAmount(fees) + prize.Amount = prize.Amount.SubAmount(fees) + return prize.Amount.Amount, fees +} + +// SendCollectedFees effectively sends the collected fees (if any) to their destination +func (fc *feeCollector) SendCollectedFees(ctx sdk.Context) (err error) { + if fc.stakersAmount.Amount.GT(math.ZeroInt()) { + err = fc.keeper.BankKeeper.SendCoinsFromAccountToModule( + ctx, + sdk.MustAccAddressFromBech32(fc.pool.GetLocalAddress()), + authtypes.FeeCollectorName, + sdk.NewCoins(fc.stakersAmount), + ) + } + if err == nil { + fc.stakersAmount.Amount = math.ZeroInt() + } + return err +} diff --git a/x/millions/keeper/keeper_fees_test.go b/x/millions/keeper/keeper_fees_test.go new file mode 100644 index 00000000..1c063607 --- /dev/null +++ b/x/millions/keeper/keeper_fees_test.go @@ -0,0 +1,119 @@ +package keeper_test + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestFees_FeeCollector() { + app := suite.app + ctx := suite.ctx + + // Fees should start at 0 and have the pool denom + denom := app.StakingKeeper.BondDenom(ctx) + feeAddr := app.AccountKeeper.GetModuleAccount(ctx, authtypes.FeeCollectorName).GetAddress() + fc := app.MillionsKeeper.NewFeeCollector(ctx, types.Pool{Denom: denom, LocalAddress: suite.addrs[0].String()}) + suite.Require().Equal(math.ZeroInt(), fc.CollectedAmount().Amount) + suite.Require().Equal(denom, fc.CollectedAmount().Denom) + + // 0 fees should do nothing + params := app.MillionsKeeper.GetParams(ctx) + params.FeesStakers = sdk.ZeroDec() + app.MillionsKeeper.SetParams(ctx, params) + + fc = app.MillionsKeeper.NewFeeCollector(ctx, types.Pool{Denom: denom, LocalAddress: suite.addrs[0].String()}) + prize := &types.Prize{Amount: sdk.NewCoin(denom, math.ZeroInt())} + a, f := fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.ZeroInt(), a) + suite.Require().Equal(math.ZeroInt(), f) + + prize.Amount.Amount = math.NewInt(123) + a, f = fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.NewInt(123), a) + suite.Require().Equal(math.ZeroInt(), f) + + // 10% fees should store collected fees (if possible) and update prize amount + params.FeesStakers = floatToDec(0.1) + app.MillionsKeeper.SetParams(ctx, params) + fc = app.MillionsKeeper.NewFeeCollector(ctx, types.Pool{Denom: denom, LocalAddress: suite.addrs[0].String()}) + + prize.Amount.Amount = math.NewInt(0) + a, f = fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.NewInt(0), f) + suite.Require().Equal(math.NewInt(0), a) + suite.Require().Equal(a, prize.Amount.Amount) + + prize.Amount.Amount = math.NewInt(100) + a, f = fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.NewInt(10), f) + suite.Require().Equal(math.NewInt(90), a) + suite.Require().Equal(a, prize.Amount.Amount) + + prize.Amount.Amount = math.NewInt(1000) + a, f = fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.NewInt(100), f) + suite.Require().Equal(math.NewInt(900), a) + suite.Require().Equal(a, prize.Amount.Amount) + + // Fees should add up in the collected but pending send value + suite.Require().Equal(math.NewInt(110), fc.CollectedAmount().Amount) + + // Fees should use a closest round up or down logic in case of floating approximation + prize.Amount.Amount = math.NewInt(99) + a, f = fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.NewInt(10), f) + suite.Require().Equal(math.NewInt(89), a) + suite.Require().Equal(a, prize.Amount.Amount) + + prize.Amount.Amount = math.NewInt(91) + a, f = fc.CollectPrizeFees(ctx, prize) + suite.Require().Equal(math.NewInt(9), f) + suite.Require().Equal(math.NewInt(82), a) + suite.Require().Equal(a, prize.Amount.Amount) + + // Fees should add up in the collected but pending send value + suite.Require().Equal(math.NewInt(129), fc.CollectedAmount().Amount) + + // Succeeding at sending collected fees should send and clear the collected amount + poolBalanceBefore := app.BankKeeper.GetBalance(ctx, suite.addrs[0], denom) + feeCollectorBalanceBefore := app.BankKeeper.GetBalance(ctx, feeAddr, denom) + collectedAmount := sdk.NewInt(123_456) + fc.CollectPrizeFees(ctx, &types.Prize{Amount: sdk.NewCoin(denom, collectedAmount.MulRaw(10).SubRaw(1290))}) + suite.Require().Equal(denom, fc.CollectedAmount().Denom) + suite.Require().Equal(collectedAmount, fc.CollectedAmount().Amount) + err := fc.SendCollectedFees(ctx) + suite.Require().NoError(err) + suite.Require().Equal(math.NewInt(0), fc.CollectedAmount().Amount) + suite.Require().Equal(poolBalanceBefore.SubAmount(collectedAmount), app.BankKeeper.GetBalance(ctx, suite.addrs[0], denom)) + suite.Require().Equal(feeCollectorBalanceBefore.AddAmount(collectedAmount), app.BankKeeper.GetBalance(ctx, feeAddr, denom)) + + // Trying to send collected fees again should result in a no-op + err = fc.SendCollectedFees(ctx) + suite.Require().NoError(err) + suite.Require().Equal(math.NewInt(0), fc.CollectedAmount().Amount) + suite.Require().Equal(poolBalanceBefore.SubAmount(collectedAmount), app.BankKeeper.GetBalance(ctx, suite.addrs[0], denom)) + suite.Require().Equal(feeCollectorBalanceBefore.AddAmount(collectedAmount), app.BankKeeper.GetBalance(ctx, feeAddr, denom)) + + // Stakers should receive their share of the collected fees upon send success + // Community tax should apply as well + vals := app.StakingKeeper.GetAllValidators(ctx) + consAddr0, err := vals[0].GetConsAddr() + suite.Require().NoError(err) + + suite.Require().Equal(sdk.ZeroDec(), app.DistrKeeper.GetTotalRewards(ctx).AmountOf(denom)) + suite.Require().Equal(sdk.ZeroDec(), app.DistrKeeper.GetFeePoolCommunityCoins(ctx).AmountOf(denom)) + votes := []abci.VoteInfo{ + { + Validator: abci.Validator{Address: consAddr0.Bytes(), Power: 100}, + SignedLastBlock: true, + }, + } + app.DistrKeeper.AllocateTokens(ctx, 100, 100, consAddr0, votes) + comTax := app.DistrKeeper.GetCommunityTax(ctx) + suite.Require().Equal(sdk.NewDec(1).MulInt(collectedAmount).Sub(comTax.MulInt(collectedAmount)), app.DistrKeeper.GetTotalRewards(ctx).AmountOf(denom)) + suite.Require().Equal(comTax.MulInt(collectedAmount), app.DistrKeeper.GetFeePoolCommunityCoins(ctx).AmountOf(denom)) +} diff --git a/x/millions/keeper/keeper_params.go b/x/millions/keeper/keeper_params.go new file mode 100644 index 00000000..a00b6241 --- /dev/null +++ b/x/millions/keeper/keeper_params.go @@ -0,0 +1,26 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsPrefix) + if bz == nil { + return types.DefaultParams() + } + var params types.Params + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + if err := params.ValidateBasics(); err != nil { + panic(err) + } + store := ctx.KVStore(k.storeKey) + store.Set(types.ParamsPrefix, k.cdc.MustMarshal(¶ms)) +} diff --git a/x/millions/keeper/keeper_params_test.go b/x/millions/keeper/keeper_params_test.go new file mode 100644 index 00000000..743aa487 --- /dev/null +++ b/x/millions/keeper/keeper_params_test.go @@ -0,0 +1,72 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func (suite *KeeperTestSuite) TestParams_Validation() { + app := suite.app + ctx := suite.ctx + + params := app.MillionsKeeper.GetParams(ctx) + suite.Require().NoError(params.ValidateBasics()) + + // MinDepositAmount should always be gte than MinAcceptableDepositAmount + params.MinDepositAmount = sdk.NewInt(millionstypes.MinAcceptableDepositAmount - 1) + suite.Require().Error(params.ValidateBasics()) + params.MinDepositAmount = sdk.NewInt(millionstypes.MinAcceptableDepositAmount) + suite.Require().NoError(params.ValidateBasics()) + + // MaxPrizeStrategyBatches should always be gt 0 + params.MaxPrizeStrategyBatches = 0 + suite.Require().Error(params.ValidateBasics()) + params.MaxPrizeStrategyBatches = 1 + suite.Require().NoError(params.ValidateBasics()) + + // MaxPrizeBatchQuantity should always be gt 0 + params.MaxPrizeBatchQuantity = 0 + suite.Require().Error(params.ValidateBasics()) + params.MaxPrizeBatchQuantity = 1 + suite.Require().NoError(params.ValidateBasics()) + + // MinDrawScheduleDelta should always be gte MinAcceptableDrawDelta + params.MinDrawScheduleDelta = millionstypes.MinAcceptableDrawDelta - 1 + suite.Require().Error(params.ValidateBasics()) + params.MinDrawScheduleDelta = millionstypes.MinAcceptableDrawDelta + suite.Require().NoError(params.ValidateBasics()) + + // MaxDrawScheduleDelta should always be gte MinDrawScheduleDelta + params.MaxDrawScheduleDelta = params.MinDrawScheduleDelta - 1 + suite.Require().Error(params.ValidateBasics()) + params.MaxDrawScheduleDelta = params.MinDrawScheduleDelta + suite.Require().NoError(params.ValidateBasics()) + + // PrizeExpirationDelta should always be gte MinAcceptablePrizeExpirationDelta + params.PrizeExpirationDelta = millionstypes.MinAcceptablePrizeExpirationDelta - 1 + suite.Require().Error(params.ValidateBasics()) + params.PrizeExpirationDelta = millionstypes.MinAcceptablePrizeExpirationDelta + suite.Require().NoError(params.ValidateBasics()) + + // Default FeesStakers should be equal to default 10% value + suite.Require().Equal(0.1, millionstypes.DefaultParams().FeesStakers.MustFloat64()) + // FeesStakers should always be gte 0 and lte MaxAcceptableFeesStakers + params.FeesStakers = sdk.NewDec(-1) + suite.Require().Error(params.ValidateBasics()) + maxFees := sdk.NewDecWithPrec(millionstypes.MaxAcceptableFeesStakers, 2) + maxFeesFloat, err := maxFees.Float64() + suite.Require().NoError(err) + suite.Require().Equal(0.5, maxFeesFloat) + suite.Require().NoError(err) + params.FeesStakers = sdk.NewDecWithPrec(millionstypes.MaxAcceptableFeesStakers+1, 2) + suite.Require().Error(params.ValidateBasics()) + params.FeesStakers = maxFees + suite.Require().NoError(params.ValidateBasics()) + + // MinDepositDrawDelta should always be gte MinAcceptableDepositDrawDelta + params.MinDepositDrawDelta = millionstypes.MinAcceptableDepositDrawDelta - 1 + suite.Require().Error(params.ValidateBasics()) + params.MinDepositDrawDelta = millionstypes.MinAcceptableDepositDrawDelta + suite.Require().NoError(params.ValidateBasics()) +} diff --git a/x/millions/keeper/keeper_pool.go b/x/millions/keeper/keeper_pool.go new file mode 100644 index 00000000..2c62cc4e --- /dev/null +++ b/x/millions/keeper/keeper_pool.go @@ -0,0 +1,693 @@ +package keeper + +import ( + "fmt" + "strconv" + "time" + + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/types/bech32" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distribtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + icqueriestypes "github.com/lum-network/chain/x/icqueries/types" + + gogotypes "github.com/gogo/protobuf/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" + ibctypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v5/modules/core/24-host" + icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// SetupPoolICA registers the ICA account on the native chain +// - waits for the ICA callback to move to OnSetupPoolICACompleted +// - or go to OnSetupPoolICACompleted directly if local zone +func (k Keeper) SetupPoolICA(ctx sdk.Context, poolID uint64) (*types.Pool, error) { + // Acquire and deserialize our pool entity + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + + if pool.IsLocalZone(ctx) { + // Skip ICA setup for local pools + return k.SetupPoolWithdrawalAddress(ctx, poolID) + } + + // Get the chain ID from the connection + chainID, err := k.GetChainID(ctx, pool.GetConnectionId()) + if err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, "unable to obtain chain id from connection %s, err: %v", pool.GetConnectionId(), err) + } + if chainID != pool.ChainId { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, "provided chain id %s differs from the connection chain id %s", pool.ChainId, chainID) + } + + // Compute the app version structure for ICA registration + appVersion, err := k.getPoolAppVersion(ctx, pool) + if err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, err.Error()) + } + + // Register the accounts deposit account first + // Wait for this account to be setup to register the prize pool account + // This is done to avoid race conditions for the last setup step (SetWithdrawAddress) + icaDepositPortName := string(types.NewPoolName(pool.GetPoolId(), types.ICATypeDeposit)) + pool.IcaDepositPortId, err = icatypes.NewControllerPortID(icaDepositPortName) + if err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, fmt.Sprintf("Unable to create deposit account port id, err: %s", err.Error())) + } + if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, pool.GetConnectionId(), icaDepositPortName, appVersion); err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, fmt.Sprintf("Unable to trigger deposit account registration, err: %s", err.Error())) + } + + k.updatePool(ctx, &pool) + return &pool, nil +} + +// OnPoolICASetupCompleted Acknowledge the ICA account creation on the native chain +// then moves to SetupPoolWithdrawalAddress once all ICA accounts have been created +// TODO: error management based on the callback response +func (k Keeper) OnSetupPoolICACompleted(ctx sdk.Context, poolID uint64, icaType string, icaAddress string) (*types.Pool, error) { + // Grab our local pool instance + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + + // Make sure our pool is in state created, otherwise just continue without error + if pool.GetState() != types.PoolState_Created { + return &pool, nil + } + + // If it's a local pool, not further processing required + if pool.IsLocalZone(ctx) { + // Ignore this step for local pools + return k.SetupPoolWithdrawalAddress(ctx, poolID) + } + + if pool.IcaDepositAddress == "" && icaType == types.ICATypeDeposit && len(icaAddress) > 0 { + // Assign the ICA deposit address + pool.IcaDepositAddress = icaAddress + + // Trigger the registration of the ICA prize pool address + appVersion, err := k.getPoolAppVersion(ctx, pool) + if err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, err.Error()) + } + icaPrizePoolPortName := string(types.NewPoolName(pool.GetPoolId(), types.ICATypePrizePool)) + pool.IcaPrizepoolPortId, err = icatypes.NewControllerPortID(icaPrizePoolPortName) + if err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, fmt.Sprintf("Unable to create prizepool account port id, err: %s", err.Error())) + } + if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, pool.GetConnectionId(), icaPrizePoolPortName, appVersion); err != nil { + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, fmt.Sprintf("Unable to trigger prizepool account registration, err: %s", err.Error())) + } + // Save pool state + k.updatePool(ctx, &pool) + } else if pool.IcaPrizepoolAddress == "" && icaType == types.ICATypePrizePool && len(icaAddress) > 0 { + // Assign the ICA prize pool address + pool.IcaPrizepoolAddress = icaAddress + k.updatePool(ctx, &pool) + } + + if len(pool.IcaDepositAddress) > 0 && len(pool.IcaPrizepoolAddress) > 0 { + // Move to next step since both accounts have been created + return k.SetupPoolWithdrawalAddress(ctx, poolID) + } + + return &pool, nil +} + +// SetupPoolWithdrawalAddress sets the PrizePoolAddress as the Staking withdrawal address for the DepositAddress +// - waits for the ICA callback to move to OnSetupPoolWithdrawalAddressCompleted +// - or go to OnSetupPoolWithdrawalAddressCompleted directly upon setting up the withdrawal address if local zone +func (k Keeper) SetupPoolWithdrawalAddress(ctx sdk.Context, poolID uint64) (*types.Pool, error) { + logger := k.Logger(ctx).With("ctx", "pool_setup_withdrawal") + + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + + if pool.GetState() != types.PoolState_Created { + return &pool, nil + } + + if pool.IsLocalZone(ctx) { + if err := k.DistributionKeeper.SetWithdrawAddr( + ctx, + sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), + sdk.MustAccAddressFromBech32(pool.IcaPrizepoolAddress), + ); err != nil { + logger.Error( + fmt.Sprintf("failed to dispatch set withdrawal address for local pool: %v", err), + "pool_id", poolID, + "chain_id", pool.GetChainId(), + ) + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, err.Error()) + } + return k.OnSetupPoolWithdrawalAddressCompleted(ctx, poolID) + } + + callbackData := types.SetWithdrawAddressCallback{ + PoolId: poolID, + } + marshalledCallbackData, err := k.MarshalSetWithdrawAddressCallbackArgs(ctx, callbackData) + if err != nil { + return &pool, err + } + msgs := []sdk.Msg{&distribtypes.MsgSetWithdrawAddress{ + DelegatorAddress: pool.GetIcaDepositAddress(), + WithdrawAddress: pool.GetIcaPrizepoolAddress(), + }} + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + types.IBCTransferTimeoutNanos + sequence, err := k.BroadcastICAMessages(ctx, poolID, types.ICATypeDeposit, msgs, timeoutTimestamp, ICACallbackID_SetWithdrawAddress, marshalledCallbackData) + if err != nil { + logger.Error( + fmt.Sprintf("failed to dispatch ICA set withdraw address: %v", err), + "pool_id", poolID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return &pool, errorsmod.Wrapf(types.ErrFailedToRegisterPool, err.Error()) + } else { + logger.Debug( + "ICA set withdraw address dispatched", + "pool_id", poolID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + } + + return &pool, nil +} + +// OnSetupPoolWithdrawalAddressCompleted Acknowledge the withdrawal address configuration on the native chain +// then sets the pool to status ready in case of success +func (k Keeper) OnSetupPoolWithdrawalAddressCompleted(ctx sdk.Context, poolID uint64) (*types.Pool, error) { + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + if pool.GetState() != types.PoolState_Created { + return &pool, nil + } + pool.State = types.PoolState_Ready + k.updatePool(ctx, &pool) + return &pool, nil +} + +// GetNextPoolID Return the next pool id to be used +func (k Keeper) GetNextPoolID(ctx sdk.Context) uint64 { + store := ctx.KVStore(k.storeKey) + nextPoolId := gogotypes.UInt64Value{} + + b := store.Get(types.NextPoolIdPrefix) + if b == nil { + panic(fmt.Errorf("getting at key (%v) should not have been nil", types.NextPoolIdPrefix)) + } + k.cdc.MustUnmarshal(b, &nextPoolId) + return nextPoolId.GetValue() +} + +// SetNextPoolID sets next pool ID +func (k Keeper) SetNextPoolID(ctx sdk.Context, poolId uint64) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: poolId}) + store.Set(types.NextPoolIdPrefix, bz) +} + +func (k Keeper) GetNextPoolIDAndIncrement(ctx sdk.Context) uint64 { + nextPoolId := k.GetNextPoolID(ctx) + k.SetNextPoolID(ctx, nextPoolId+1) + return nextPoolId +} + +// HasPool Returns a boolean that indicates if the given poolID exists in the KVStore or not +func (k Keeper) HasPool(ctx sdk.Context, poolID uint64) bool { + store := ctx.KVStore(k.storeKey) + return store.Has(types.GetPoolKey(poolID)) +} + +// AddPool Set a pool structure in the KVStore for a given pool ID +func (k Keeper) AddPool(ctx sdk.Context, pool *types.Pool) { + // Automatically affect ID if missing + if pool.GetPoolId() == types.UnknownID { + pool.PoolId = k.GetNextPoolIDAndIncrement(ctx) + } + // Ensure payload is valid + if err := pool.ValidateBasic(k.GetParams(ctx)); err != nil { + panic(err) + } + // Ensure we never override an existing entity + if k.HasPool(ctx, pool.GetPoolId()) { + panic(errorsmod.Wrapf(types.ErrEntityOverride, "ID %d", pool.GetPoolId())) + } + store := ctx.KVStore(k.storeKey) + encodedPool := k.cdc.MustMarshal(pool) + store.Set(types.GetPoolKey(pool.GetPoolId()), encodedPool) +} + +// RegisterPool Register a given pool from the transaction message +func (k Keeper) RegisterPool( + ctx sdk.Context, + denom, nativeDenom, chainId, connectionId, transferChannelId string, + vals []string, + bech32Acc, bech32Val string, + minDepositAmount math.Int, + drawSchedule types.DrawSchedule, + prizeStrategy types.PrizeStrategy, +) (uint64, error) { + + // Acquire new pool ID + poolID := k.GetNextPoolIDAndIncrement(ctx) + + // Initialize validators + validators := make(map[string]*types.PoolValidator) + for _, addr := range vals { + validators[addr] = &types.PoolValidator{ + OperatorAddress: addr, + IsEnabled: true, + } + } + + // Initialize our local deposit address + localAddress := types.NewPoolAddress(poolID, types.ICATypeDeposit) + poolAccount := k.AccountKeeper.NewAccount(ctx, authtypes.NewModuleAccount(authtypes.NewBaseAccountWithAddress(localAddress), localAddress.String())) + k.AccountKeeper.SetAccount(ctx, poolAccount) + + // Prepare new pool + var pool = types.Pool{ + PoolId: poolID, + Denom: denom, + NativeDenom: nativeDenom, + ChainId: chainId, + ConnectionId: connectionId, + Validators: validators, + Bech32PrefixAccAddr: bech32Acc, + Bech32PrefixValAddr: bech32Val, + MinDepositAmount: minDepositAmount, + DrawSchedule: drawSchedule.Sanitized(), + PrizeStrategy: prizeStrategy, + LocalAddress: localAddress.String(), + NextDrawId: 1, + TvlAmount: sdk.ZeroInt(), + DepositorsCount: 0, + SponsorshipAmount: sdk.ZeroInt(), + AvailablePrizePool: sdk.NewCoin(denom, sdk.ZeroInt()), + State: types.PoolState_Created, + TransferChannelId: transferChannelId, + CreatedAtHeight: ctx.BlockHeight(), + UpdatedAtHeight: ctx.BlockHeight(), + CreatedAt: ctx.BlockTime(), + UpdatedAt: ctx.BlockTime(), + } + + // Validate pool configuration + if err := pool.ValidateBasic(k.GetParams(ctx)); err != nil { + return 0, errorsmod.Wrapf(types.ErrFailedToRegisterPool, err.Error()) + } + + // If it's a local zone, we have more setup steps for module accounts + if pool.IsLocalZone(ctx) { + // Set the deposit address to the local module account address + pool.IcaDepositAddress = localAddress.String() + + // Initialize our local prizepool address + icaPrizePoolAddress := types.NewPoolAddress(poolID, types.ICATypePrizePool) + icaPrizePoolAccount := k.AccountKeeper.NewAccount(ctx, authtypes.NewModuleAccount(authtypes.NewBaseAccountWithAddress(icaPrizePoolAddress), icaPrizePoolAddress.String())) + k.AccountKeeper.SetAccount(ctx, icaPrizePoolAccount) + + pool.IcaPrizepoolAddress = icaPrizePoolAddress.String() + } + + // Commit the pool to the KVStore + k.AddPool(ctx, &pool) + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeRegisterPool, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(pool.PoolId, 10)), + ), + }) + + // Remote zone pool + _, err := k.SetupPoolICA(ctx, poolID) + if err != nil { + return poolID, err + } + + return poolID, nil +} + +// UpdatePool Update the updatable properties of a pool from the transaction message +func (k Keeper) UpdatePool( + ctx sdk.Context, + poolID uint64, + vals []string, + minDepositAmount *math.Int, + drawSchedule *types.DrawSchedule, + prizeStrategy *types.PrizeStrategy, +) error { + // Acquire and deserialize our pool entity + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + + // Update enabled validators + if len(vals) > 0 { + for addr := range pool.Validators { + pool.Validators[addr].IsEnabled = false + } + for _, addr := range vals { + if _, exists := pool.Validators[addr]; exists { + pool.Validators[addr].IsEnabled = true + } else { + pool.Validators[addr] = &types.PoolValidator{ + OperatorAddress: addr, + IsEnabled: true, + } + } + } + } + + // Only a few properties can be updated + if minDepositAmount != nil { + pool.MinDepositAmount = *minDepositAmount + } + if drawSchedule != nil { + pool.DrawSchedule = *drawSchedule + if pool.DrawSchedule.InitialDrawAt.After(ctx.BlockTime()) { + // Specifying a new valid InitialDrawAt resets the Pool draw timing to this date + // Also useful for governance to change the timing of Draws in case of time drift + pool.LastDrawCreatedAt = nil + } + } + if prizeStrategy != nil { + pool.PrizeStrategy = *prizeStrategy + } + + // Validate pool configuration + if err := pool.ValidateBasic(k.GetParams(ctx)); err != nil { + return errorsmod.Wrapf(types.ErrFailedToUpdatePool, err.Error()) + } + + // Commit the pool to the KVStore + k.updatePool(ctx, &pool) + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeUpdatePool, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(pool.PoolId, 10)), + ), + }) + + return nil +} + +func (k Keeper) updatePool(ctx sdk.Context, pool *types.Pool) { + pool.UpdatedAt = ctx.BlockTime() + pool.UpdatedAtHeight = ctx.BlockHeight() + // Ensure payload is valid + if err := pool.ValidateBasic(k.GetParams(ctx)); err != nil { + panic(err) + } + store := ctx.KVStore(k.storeKey) + encodedPool := k.cdc.MustMarshal(pool) + store.Set(types.GetPoolKey(pool.GetPoolId()), encodedPool) +} + +// GetPool Returns a pool instance for the given poolID +func (k Keeper) GetPool(ctx sdk.Context, poolID uint64) (types.Pool, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetPoolKey(poolID)) + if bz == nil { + return types.Pool{}, errorsmod.Wrapf(types.ErrPoolNotFound, "%d", poolID) + } + + var pool types.Pool + if err := k.cdc.Unmarshal(bz, &pool); err != nil { + return types.Pool{}, err + } + + return pool, nil +} + +func (k Keeper) GetPoolForChainID(ctx sdk.Context, chainID string) (types.Pool, bool) { + var pool = types.Pool{} + found := false + k.IteratePools(ctx, func(p types.Pool) bool { + if p.GetChainId() == chainID { + pool = p + found = true + return true + } + return false + }) + + return pool, found +} + +func (k Keeper) GetPoolForConnectionID(ctx sdk.Context, connectionID string) (types.Pool, bool) { + var pool = types.Pool{} + found := false + k.IteratePools(ctx, func(p types.Pool) bool { + if p.GetConnectionId() == connectionID { + pool = p + found = true + return true + } + return false + }) + + return pool, found +} + +func (k Keeper) GetPoolForControllerPortID(ctx sdk.Context, controllerPortID string) (types.Pool, bool) { + var pool = types.Pool{} + found := false + k.IteratePools(ctx, func(p types.Pool) bool { + if p.GetIcaDepositPortId() == controllerPortID || p.GetIcaPrizepoolPortId() == controllerPortID { + pool = p + found = true + return true + } + return false + }) + + return pool, found +} + +// IteratePools Iterate over the pools, and for each entry call the callback +func (k Keeper) IteratePools(ctx sdk.Context, callback func(pool types.Pool) (stop bool)) { + iterator := k.PoolsIterator(ctx) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var pool types.Pool + k.cdc.MustUnmarshal(iterator.Value(), &pool) + if callback(pool) { + break + } + } +} + +// PoolsIterator Return a ready to use iterator for the pools store +func (k Keeper) PoolsIterator(ctx sdk.Context) sdk.Iterator { + kvStore := ctx.KVStore(k.storeKey) + return sdk.KVStorePrefixIterator(kvStore, types.PoolPrefix) +} + +// ListPools Return the pools +func (k Keeper) ListPools(ctx sdk.Context) (pools []types.Pool) { + k.IteratePools(ctx, func(pool types.Pool) bool { + pools = append(pools, pool) + return false + }) + return pools +} + +// ListPoolsToDraw Returns the pools which should be launching a Draw +func (k Keeper) ListPoolsToDraw(ctx sdk.Context) (pools []types.Pool) { + allPools := k.ListPools(ctx) + for _, p := range allPools { + if p.ShouldDraw(ctx) { + pools = append(pools, p) + } + } + return pools +} + +// TransferAmountFromPoolToNativeChain Transfer a given amount to the native chain ICA account from the local module account +// amount denom must be based on pool.Denom +func (k Keeper) TransferAmountFromPoolToNativeChain(ctx sdk.Context, poolID uint64, amount sdk.Coin) (*ibctypes.MsgTransfer, *ibctypes.MsgTransferResponse, error) { + // Acquire our pool instance + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, nil, err + } + + // Pool must be ready to process those kind of operations + if pool.GetState() != types.PoolState_Ready { + return nil, nil, types.ErrPoolNotReady + } + + // Timeout is now plus 5 minutes in nanoseconds + // We use the standard transfer port ID and not the one opened for ICA + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano() + 5*time.Minute.Nanoseconds()) + msg := ibctypes.NewMsgTransfer(ibctypes.PortID, pool.GetTransferChannelId(), amount, pool.GetLocalAddress(), pool.GetIcaDepositAddress(), clienttypes.Height{}, timeoutTimestamp) + + // Broadcast the transfer + msgResponse, err := k.IBCTransferKeeper.Transfer(ctx, msg) + if err != nil { + return nil, nil, err + } + + return msg, msgResponse, nil +} + +func (k Keeper) BroadcastICAMessages(ctx sdk.Context, poolID uint64, accountType string, msgs []sdk.Msg, timeoutTimestamp uint64, callbackId string, callbackArgs []byte) (uint64, error) { + // Acquire our pool instance + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return 0, err + } + + // Compute the port ID + var portID string + if accountType == types.ICATypeDeposit { + portID = pool.GetIcaDepositPortId() + } else if accountType == types.ICATypePrizePool { + portID = pool.GetIcaPrizepoolPortId() + } + + // Acquire the channel capacities + channelID, found := k.ICAControllerKeeper.GetOpenActiveChannel(ctx, pool.GetConnectionId(), portID) + if !found { + return 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve open active channel for port %s", portID) + } + chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) + if !found { + return 0, errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } + + // Serialize the data and construct the packet to send + data, err := icatypes.SerializeCosmosTx(k.cdc, msgs) + if err != nil { + return 0, err + } + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: data, + Memo: "Cosmos Millions ICA", + } + + // Broadcast the messages + sequence, err := k.ICAControllerKeeper.SendTx(ctx, chanCap, pool.GetConnectionId(), portID, packetData, timeoutTimestamp) + if err != nil { + return 0, err + } + + // Store the callback data + if callbackId != "" && callbackArgs != nil { + callback := icacallbackstypes.CallbackData{ + CallbackKey: icacallbackstypes.PacketID(portID, channelID, sequence), + PortId: portID, + ChannelId: channelID, + Sequence: sequence, + CallbackId: callbackId, + CallbackArgs: callbackArgs, + } + k.ICACallbacksKeeper.SetCallbackData(ctx, callback) + } + + k.Logger(ctx).Debug(fmt.Sprintf("Broadcasted ICA messages with sequence %d", sequence)) + return sequence, nil +} + +func (k Keeper) QueryBalance(ctx sdk.Context, poolID uint64, drawID uint64) (*types.Draw, error) { + logger := k.Logger(ctx).With("ctx", "pool_query_balance") + + // Acquire our pool instance + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return nil, err + } + + // Pool must be ready to process those kind of operations + if pool.GetState() != types.PoolState_Ready { + return nil, types.ErrPoolNotReady + } + + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return nil, err + } + + // If it's a local pool, proceed with local balance fetch and synchronously return + if pool.IsLocalZone(ctx) { + moduleAccAddress := sdk.MustAccAddressFromBech32(pool.GetIcaPrizepoolAddress()) + balance := k.BankKeeper.GetBalance(ctx, moduleAccAddress, pool.GetNativeDenom()) + return k.OnQueryRewardsOnNativeChainCompleted(ctx, poolID, drawID, sdk.NewCoins(balance), false) + } + + // Encode the ica address for query + _, icaAddressBz, err := bech32.DecodeAndConvert(pool.GetIcaPrizepoolAddress()) + if err != nil { + panic(err) + } + + // Construct the query data and timeout timestamp (now + 5 minutes) + queryData := append(banktypes.CreateAccountBalancesPrefix(icaAddressBz), []byte(pool.GetNativeDenom())...) + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano() + 5*time.Minute.Nanoseconds()) + + // Submit the ICQ + extraId := types.CombineStringKeys(strconv.FormatUint(poolID, 10), strconv.FormatUint(drawID, 10)) + err = k.ICQueriesKeeper.MakeRequest(ctx, types.ModuleName, ICQCallbackID_Balance, pool.GetChainId(), pool.GetConnectionId(), extraId, icqueriestypes.BANK_STORE_QUERY_WITH_PROOF, queryData, timeoutTimestamp) + if err != nil { + logger.Error( + fmt.Sprintf("failed to dispatch icq query to fetch prize pool balance: %v", err), + "pool_id", poolID, + "draw_id", drawID, + ) + return k.OnQueryRewardsOnNativeChainCompleted(ctx, poolID, drawID, sdk.NewCoins(), true) + } + + return &draw, nil +} + +// getPoolAppVersion returns the ICA app version for the pool connection +func (k Keeper) getPoolAppVersion(ctx sdk.Context, pool types.Pool) (string, error) { + connectionEnd, found := k.IBCKeeper.ConnectionKeeper.GetConnection(ctx, pool.GetConnectionId()) + if !found { + return "", fmt.Errorf("connection with id %s not found", pool.GetConnectionId()) + } + return string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ + Version: icatypes.Version, + ControllerConnectionId: pool.GetConnectionId(), + HostConnectionId: connectionEnd.Counterparty.GetConnectionID(), + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, + })), nil +} diff --git a/x/millions/keeper/keeper_pool_test.go b/x/millions/keeper/keeper_pool_test.go new file mode 100644 index 00000000..5533bc4b --- /dev/null +++ b/x/millions/keeper/keeper_pool_test.go @@ -0,0 +1,885 @@ +package keeper_test + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +func splitDelegationSliceToMap(vals []*millionstypes.SplitDelegation) map[string]*millionstypes.SplitDelegation { + m := map[string]*millionstypes.SplitDelegation{} + for _, v := range vals { + m[v.ValidatorAddress] = v + } + return m +} + +func (suite *KeeperTestSuite) TestPool_IDsGeneration() { + app := suite.app + ctx := suite.ctx + + for i := 0; i < 10; i++ { + nextPoolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{PoolId: nextPoolID})) + suite.Require().Equal(uint64(i+1), nextPoolID) + } +} + +func (suite *KeeperTestSuite) TestPool_ValidatorsBasics() { + params := suite.app.MillionsKeeper.GetParams(suite.ctx) + + pool := newValidPool(suite, millionstypes.Pool{PoolId: 1}) + + // Both prefixes are required + pool.Bech32PrefixAccAddr = "" + pool.Bech32PrefixValAddr = "" + suite.Require().Error(pool.ValidateBasic(params)) + suite.Require().ErrorIs(pool.ValidateBasic(params), millionstypes.ErrInvalidPoolParams) + pool.Bech32PrefixAccAddr = "lum" + suite.Require().Error(pool.ValidateBasic(params)) + suite.Require().ErrorIs(pool.ValidateBasic(params), millionstypes.ErrInvalidPoolParams) + pool.Bech32PrefixValAddr = "lumvaloper" + suite.Require().NoError(pool.ValidateBasic(params)) + + // Prefix should match validators config + pool.Bech32PrefixValAddr = "cosmosvaloper" + suite.Require().Error(pool.ValidateBasic(params)) + suite.Require().ErrorIs(pool.ValidateBasic(params), millionstypes.ErrInvalidPoolParams) + pool.Validators = map[string]*millionstypes.PoolValidator{ + "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn": { + OperatorAddress: "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn", + BondedAmount: sdk.ZeroInt(), + }, + } + suite.Require().NoError(pool.ValidateBasic(params)) +} + +// TestPool_DrawSchedule validates draw schedule configuration and implementation +func (suite *KeeperTestSuite) TestPool_DrawScheduleBasics() { + ctx := suite.ctx + + now := time.Now().UTC() + ctx = ctx.WithBlockTime(now) + params := suite.app.MillionsKeeper.GetParams(ctx) + params.MinDrawScheduleDelta = 24 * time.Hour + suite.app.MillionsKeeper.SetParams(ctx, params) + + // Draw delta must be >= 24 hours + ds := millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour), DrawDelta: 0} + suite.Require().Error(ds.ValidateNew(ctx, params)) + ds = millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour), DrawDelta: 1 * time.Second} + suite.Require().Error(ds.ValidateNew(ctx, params)) + + // Initial Draw must be in the future + delta hours + ds = millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(-1 * time.Second), DrawDelta: 24 * time.Hour} + suite.Require().Error(ds.ValidateNew(ctx, params)) + ds = millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(1 * time.Second), DrawDelta: 24 * time.Hour} + suite.Require().Error(ds.ValidateNew(ctx, params)) + ds = millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(23 * time.Hour), DrawDelta: 24 * time.Hour} + suite.Require().Error(ds.ValidateNew(ctx, params)) + + // Initial Draw gets rounded to the minute upon sanitization + ds = millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(23 * time.Hour), DrawDelta: 24 * time.Hour} + dsSan := ds.Sanitized() + suite.Require().Equal(ds.GetInitialDrawAt().Year(), dsSan.GetInitialDrawAt().Year()) + suite.Require().Equal(ds.GetInitialDrawAt().Month(), dsSan.GetInitialDrawAt().Month()) + suite.Require().Equal(ds.GetInitialDrawAt().Day(), dsSan.GetInitialDrawAt().Day()) + suite.Require().Equal(ds.GetInitialDrawAt().Hour(), dsSan.GetInitialDrawAt().Hour()) + suite.Require().Equal(ds.GetInitialDrawAt().Minute(), dsSan.GetInitialDrawAt().Minute()) + suite.Require().Equal(0, dsSan.GetInitialDrawAt().Second()) + suite.Require().Equal(0, dsSan.GetInitialDrawAt().Nanosecond()) + + // Subsequent draw should trigger as soon as the draw delta is elapsed + // In other words, we should be able to launch a draw even if the elasped time is not passed draw delta depending + // on the initial launch time to prevent pool draw time drift (ex: if chain stalling for a while) + dsNow := time.Date(2000, 10, 10, 10, 10, 0, 0, time.UTC) + dsCtx := ctx.WithBlockTime(dsNow) + dsSan = millionstypes.DrawSchedule{InitialDrawAt: dsNow.Add(1 * time.Hour), DrawDelta: 1 * time.Hour}.Sanitized() + suite.Require().False(dsSan.ShouldDraw(dsCtx, nil)) + suite.Require().False(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(45*time.Minute)), nil)) + suite.Require().False(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(50*time.Minute)), nil)) + // First draw schedule should be exactly the stanitized InitialDrawAt + suite.Require().True(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(60*time.Minute)), nil)) + // Subsequent draws should be able to be scheduled earlier than the expected draw delta to re-align timing with initial draw + // simulate last draw drifted by 5 min from expected time - should allow next draw 5min earlier + dsNow = dsNow.Add(65 * time.Minute) + suite.Require().False(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(45*time.Minute)), &dsNow)) + suite.Require().False(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(50*time.Minute)), &dsNow)) + suite.Require().True(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(55*time.Minute)), &dsNow)) + suite.Require().True(dsSan.ShouldDraw(dsCtx.WithBlockTime(dsNow.Add(155*time.Minute)), &dsNow)) + + // Pools draw should be defined by their state and the draw schedule + pool := newValidPool(suite, millionstypes.Pool{ + DrawSchedule: millionstypes.DrawSchedule{InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour), DrawDelta: 24 * time.Hour}, + CreatedAt: ctx.BlockTime(), + }) + + // Fresh pool should have 0 elapsed time and should not draw + suite.Require().NoError(pool.DrawSchedule.ValidateNew(ctx, params)) + suite.Require().False(pool.ShouldDraw(ctx)) + + // Moving forward by 12 hours - same situation with a duration of 12h + ctx = ctx.WithBlockTime(now.Add(12 * time.Hour)) + suite.Require().False(pool.ShouldDraw(ctx)) + + // Moving forward by 12 hours - first draw should be able to occur + ctx = ctx.WithBlockTime(now.Add(24 * time.Hour)) + suite.Require().True(pool.ShouldDraw(ctx)) + + // Simulate draw status which should never allow another draw + ld := ctx.BlockTime() + pool.LastDrawCreatedAt = &ld + for _, s := range []millionstypes.DrawState{ + millionstypes.DrawState_Failure, + millionstypes.DrawState_IcaWithdrawRewards, + millionstypes.DrawState_IbcTransfer, + } { + pool.LastDrawState = s + suite.Require().False(pool.ShouldDraw(ctx.WithBlockTime(now.Add(48 * time.Hour)))) + } + + // Simulate first draw success which should make the pool accept a new draw depending on the previous one creation time + pool.LastDrawState = millionstypes.DrawState_Success + suite.Require().False(pool.ShouldDraw(ctx.WithBlockTime((*pool.LastDrawCreatedAt).Add(-5 * time.Hour)))) + suite.Require().False(pool.ShouldDraw(ctx.WithBlockTime((*pool.LastDrawCreatedAt).Add(0 * time.Hour)))) + suite.Require().False(pool.ShouldDraw(ctx.WithBlockTime((*pool.LastDrawCreatedAt).Add(12 * time.Hour)))) + suite.Require().True(pool.ShouldDraw(ctx.WithBlockTime((*pool.LastDrawCreatedAt).Add(24 * time.Hour)))) + suite.Require().True(pool.ShouldDraw(ctx.WithBlockTime((*pool.LastDrawCreatedAt).Add(48 * time.Hour)))) + + // Test pool not ready states which should not allow any draw + pool.State = millionstypes.PoolState_Killed + suite.Require().False(pool.ShouldDraw(ctx.WithBlockTime(now.Add(48 * time.Hour)))) + + pool.State = millionstypes.PoolState_Created + pool.LastDrawCreatedAt = nil + pool.LastDrawState = millionstypes.DrawState_Unspecified + suite.Require().False(pool.ShouldDraw(ctx.WithBlockTime(now.Add(48 * time.Hour)))) +} + +func (suite *KeeperTestSuite) TestPool_PrizeStrategiesBasics() { + params := suite.app.MillionsKeeper.GetParams(suite.ctx) + + // PoolPercent should sum up to 100 + err := millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{}, + }.Validate(params) + suite.Require().Error(err) + + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 25, Quantity: 1, DrawProbability: floatToDec(0.1)}, + }, + }.Validate(params) + suite.Require().Error(err) + + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 101, Quantity: 1, DrawProbability: floatToDec(0.1)}, + }, + }.Validate(params) + suite.Require().Error(err) + + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 25, Quantity: 1, DrawProbability: floatToDec(0.1)}, + {PoolPercent: 80, Quantity: 1, DrawProbability: floatToDec(0.1)}, + }, + }.Validate(params) + suite.Require().Error(err) + + // DrawProbability should be [0, 1] + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.01)}, + }, + }.Validate(params) + suite.Require().Error(err) + + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 1, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(-1.01)}, + }, + }.Validate(params) + suite.Require().Error(err) + + // Quantity should be > 0 + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 0, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }.Validate(params) + suite.Require().Error(err) + + err = millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 20, Quantity: 0, DrawProbability: floatToDec(0.01)}, + {PoolPercent: 30, Quantity: 1, DrawProbability: floatToDec(0.11)}, + {PoolPercent: 50, Quantity: 1, DrawProbability: floatToDec(1.00)}, + }, + }.Validate(params) + suite.Require().Error(err) +} + +func (suite *KeeperTestSuite) TestPool_DepositorsCountAndTVL() { + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + denom := app.StakingKeeper.BondDenom(ctx) + poolID, err := app.MillionsKeeper.RegisterPool(ctx, + "ulum", + "ulum", + testChainID, + "", + "", + []string{suite.valAddrs[0].String()}, + "lum", + "lumvaloper", + app.MillionsKeeper.GetParams(ctx).MinDepositAmount, + millionstypes.DrawSchedule{DrawDelta: 24 * time.Hour, InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour)}, + millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 100, DrawProbability: sdk.NewDec(1)}}}, + ) + suite.Require().NoError(err) + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + // Deposit with 3 accounts + for i := 0; i < 5; i++ { + _, err := msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + DepositorAddress: suite.addrs[0].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(denom, sdk.NewInt(1_000_000)), + }) + suite.Require().NoError(err) + } + pool, err = app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(uint64(1), pool.DepositorsCount) + suite.Require().Equal(sdk.NewInt(5_000_000), pool.TvlAmount) + + for i := 0; i < 10; i++ { + _, err := msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + DepositorAddress: suite.addrs[1].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(denom, sdk.NewInt(2_000_000)), + }) + suite.Require().NoError(err) + } + pool, err = app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(uint64(2), pool.DepositorsCount) + suite.Require().Equal(sdk.NewInt(5_000_000+20_000_000), pool.TvlAmount) + + for i := 0; i < 20; i++ { + _, err := msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + DepositorAddress: suite.addrs[2].String(), + PoolId: pool.PoolId, + Amount: sdk.NewCoin(denom, sdk.NewInt(4_000_000)), + }) + suite.Require().NoError(err) + } + pool, err = app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(uint64(3), pool.DepositorsCount) + suite.Require().Equal(sdk.NewInt(5_000_000+20_000_000+80_000_000), pool.TvlAmount) + + // Remove all deposits from all accounts + deposits := app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[0], pool.PoolId) + for i, d := range deposits { + app.MillionsKeeper.RemoveDeposit(ctx, &d) + pool, err = app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + if i == len(deposits)-1 { + suite.Require().Equal(uint64(2), pool.DepositorsCount) + } else { + suite.Require().Equal(uint64(3), pool.DepositorsCount) + } + suite.Require().Equal(sdk.NewInt(1_000_000*int64(5-i-1)+20_000_000+80_000_000), pool.TvlAmount) + } + + deposits = app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[1], pool.PoolId) + for i, d := range deposits { + app.MillionsKeeper.RemoveDeposit(ctx, &d) + pool, err = app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + if i == len(deposits)-1 { + suite.Require().Equal(uint64(1), pool.DepositorsCount) + } else { + suite.Require().Equal(uint64(2), pool.DepositorsCount) + } + suite.Require().Equal(sdk.NewInt(2_000_000*int64(10-i-1)+80_000_000), pool.TvlAmount) + } + + deposits = app.MillionsKeeper.ListAccountPoolDeposits(ctx, suite.addrs[1], pool.PoolId) + for i, d := range deposits { + app.MillionsKeeper.RemoveDeposit(ctx, &d) + pool, err = app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + if i == len(deposits)-1 { + suite.Require().Equal(uint64(0), pool.DepositorsCount) + } else { + suite.Require().Equal(uint64(1), pool.DepositorsCount) + } + suite.Require().Equal(sdk.NewInt(4_000_000*int64(20-i-1)), pool.TvlAmount) + } +} + +// TestPool_ValidatorsSplitDelegate test pool validator set split delegations +func (suite *KeeperTestSuite) TestPool_ValidatorsSplitDelegate() { + app := suite.app + ctx := suite.ctx + + valAddrs := []string{ + "cosmosvaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcvrj90c", + "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn", + "cosmosvaloper1fsg635n5vgc7jazz9sx5725wnc3xqgr7awxaag", + "cosmosvaloper1gpx52r9h3zeul45amvcy2pysgvcwddxrgx6cnv", + "cosmosvaloper1vvwtk805lxehwle9l4yudmq6mn0g32px9xtkhc", + } + + // valSet1 make validator 0 inactive + valSet1 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + } + // valSet2 make validator 0 active + valSet2 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + } + // valSet3 adds 3 more validators active and one inactive + valSet3 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[1]: { + OperatorAddress: valAddrs[1], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[2]: { + OperatorAddress: valAddrs[2], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[3]: { + OperatorAddress: valAddrs[3], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[4]: { + OperatorAddress: valAddrs[4], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + } + // valSet4 disables validators 0 and 1 + valSet4 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + valAddrs[1]: { + OperatorAddress: valAddrs[1], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + valAddrs[2]: { + OperatorAddress: valAddrs[2], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[3]: { + OperatorAddress: valAddrs[3], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[4]: { + OperatorAddress: valAddrs[4], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + } + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx), + Bech32PrefixValAddr: "cosmosvaloper", + ChainId: "cosmos", + Denom: "uatom", + NativeDenom: "uatom", + ConnectionId: "connection-id", + TransferChannelId: "transferChannel-id", + Validators: valSet1, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + State: millionstypes.PoolState_Ready, + }) + + amount := sdk.NewInt(1_000_000) + + // Splits should return nil (error case) values if no validator set available + sDel := pool.ComputeSplitDelegations(ctx, amount) + suite.Require().Nil(sDel) + + // Update pool to make val[0] active + pool.Validators = valSet2 + + // Split delegate should evenly distribute amount + sDel = pool.ComputeSplitDelegations(ctx, amount) + suite.Require().Len(sDel, 1) + suite.Require().Equal(valAddrs[0], sDel[0].ValidatorAddress) + suite.Require().Equal(amount, sDel[0].Amount) + + // Update pool to add 3 more validators active and one inactive + pool.Validators = valSet3 + + // Split delegate should evenly distribute amount to active validators + sDel = pool.ComputeSplitDelegations(ctx, amount) + suite.Require().Len(sDel, 4) + sdMap := splitDelegationSliceToMap(sDel) + suite.Require().Equal(amount.Quo(sdk.NewInt(4)), sdMap[valAddrs[0]].Amount) + suite.Require().Equal(amount.Quo(sdk.NewInt(4)), sdMap[valAddrs[1]].Amount) + suite.Require().Equal(amount.Quo(sdk.NewInt(4)), sdMap[valAddrs[2]].Amount) + suite.Require().Equal(amount.Quo(sdk.NewInt(4)), sdMap[valAddrs[3]].Amount) + + // Update pool to add make val[2] and val[3] the only active ones + pool.Validators = valSet4 + + // Split delegate should evenly distribute amount to active validators + sDel = pool.ComputeSplitDelegations(ctx, amount) + suite.Require().Len(sDel, 2) + sdMap = splitDelegationSliceToMap(sDel) + suite.Require().Equal(amount.Quo(sdk.NewInt(2)), sdMap[valAddrs[2]].Amount) + suite.Require().Equal(amount.Quo(sdk.NewInt(2)), sdMap[valAddrs[3]].Amount) + + // Split delegate should distribute rests to the last validator in the set in case of rounding approximation + amountNotMultipleOf2 := sdk.NewInt(1_000_001) + sDel = pool.ComputeSplitDelegations(ctx, amountNotMultipleOf2) + suite.Require().Len(sDel, 2) + sdMap = splitDelegationSliceToMap(sDel) + suite.Require().GreaterOrEqual(sdMap[valAddrs[2]].Amount.Int64(), amountNotMultipleOf2.Quo(sdk.NewInt(2)).Int64()) + suite.Require().GreaterOrEqual(sdMap[valAddrs[3]].Amount.Int64(), amountNotMultipleOf2.Quo(sdk.NewInt(2)).Int64()) + suite.Require().Equal(amountNotMultipleOf2, sdMap[valAddrs[2]].Amount.Add(sdMap[valAddrs[3]].Amount)) +} + +// TestPool_ValidatorsSplitUndelegate test pool validator set split undelegations +func (suite *KeeperTestSuite) TestPool_ValidatorsSplitUndelegate() { + app := suite.app + ctx := suite.ctx + + valAddrs := []string{ + "cosmosvaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcvrj90c", + "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn", + "cosmosvaloper1fsg635n5vgc7jazz9sx5725wnc3xqgr7awxaag", + "cosmosvaloper1gpx52r9h3zeul45amvcy2pysgvcwddxrgx6cnv", + "cosmosvaloper1vvwtk805lxehwle9l4yudmq6mn0g32px9xtkhc", + } + + // valSet1 make validator 0 inactive + valSet1 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + } + // valSet2 make validator 0 active + valSet2 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + } + // valSet3 adds 3 more validators active and one inactive + valSet3 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[1]: { + OperatorAddress: valAddrs[1], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[2]: { + OperatorAddress: valAddrs[2], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[3]: { + OperatorAddress: valAddrs[3], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[4]: { + OperatorAddress: valAddrs[4], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + } + // valSet4 disables validators 0 and 1 + valSet4 := map[string]*millionstypes.PoolValidator{ + valAddrs[0]: { + OperatorAddress: valAddrs[0], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + valAddrs[1]: { + OperatorAddress: valAddrs[1], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + valAddrs[2]: { + OperatorAddress: valAddrs[2], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[3]: { + OperatorAddress: valAddrs[3], + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + valAddrs[4]: { + OperatorAddress: valAddrs[4], + BondedAmount: sdk.NewInt(0), + IsEnabled: false, + }, + } + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx), + Bech32PrefixValAddr: "cosmosvaloper", + ChainId: "cosmos", + Denom: "uatom", + NativeDenom: "uatom", + ConnectionId: "connection-id", + TransferChannelId: "transferChannel-id", + Validators: valSet1, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + State: millionstypes.PoolState_Ready, + }) + + amount := sdk.NewInt(1_000_000) + + // Splits should return nil (error case) values if no validator bonded + sUndel := pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Nil(sUndel) + + // Splits should return nil (error case) values if bonded validators don't have enough to undelegate + pool.Validators[valAddrs[0]].BondedAmount = amount.Sub(sdk.NewInt(1)) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Nil(sUndel) + + // Splits should return ok values if bonded amount is enough even if validator set is fully disabled + pool.Validators[valAddrs[0]].BondedAmount = amount + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 1) + suite.Require().Equal(valAddrs[0], sUndel[0].ValidatorAddress) + suite.Require().Equal(amount, sUndel[0].Amount) + + // Update pool to make val[0] active + pool.Validators = valSet2 + + // Splits should have the same behaviour regardless of the activation status of the validator + pool.Validators[valAddrs[0]].BondedAmount = amount.Sub(sdk.NewInt(1)) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Nil(sUndel) + pool.Validators[valAddrs[0]].BondedAmount = amount + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 1) + suite.Require().Equal(valAddrs[0], sUndel[0].ValidatorAddress) + suite.Require().Equal(amount, sUndel[0].Amount) + + // Update pool to add 3 more validators active and one inactive + pool.Validators = valSet3 + + // Splits should return nil (error case) values if no bonded valitors or not enough bonded amount + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Nil(sUndel) + + pool.Validators[valAddrs[0]].BondedAmount = sdk.NewInt(1) + pool.Validators[valAddrs[1]].BondedAmount = sdk.NewInt(1) + pool.Validators[valAddrs[2]].BondedAmount = sdk.NewInt(1) + pool.Validators[valAddrs[3]].BondedAmount = sdk.NewInt(1) + pool.Validators[valAddrs[4]].BondedAmount = sdk.NewInt(1) + + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Nil(sUndel) + + // Update pool to add make val[2] and val[3] the only active ones + pool.Validators = valSet4 + + // Splits should prioritize inactive validators + // Disabled set + pool.Validators[valAddrs[0]].BondedAmount = sdk.NewInt(1_000) + pool.Validators[valAddrs[1]].BondedAmount = sdk.NewInt(100) + pool.Validators[valAddrs[4]].BondedAmount = sdk.NewInt(10) + // Enabled set + pool.Validators[valAddrs[2]].BondedAmount = sdk.NewInt(100) + pool.Validators[valAddrs[3]].BondedAmount = sdk.NewInt(10) + + // Will pick up all val[0] + amount = sdk.NewInt(1_000) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 1) + suMap := splitDelegationSliceToMap(sUndel) + suite.Require().Equal(amount, suMap[valAddrs[0]].Amount) + + // Will pick up all val[0] then val[1] + amount = sdk.NewInt(1_105) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 3) + suMap = splitDelegationSliceToMap(sUndel) + suite.Require().Equal(pool.Validators[valAddrs[0]].BondedAmount, suMap[valAddrs[0]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[1]].BondedAmount, suMap[valAddrs[1]].Amount) + suite.Require().Equal(sdk.NewInt(5), suMap[valAddrs[4]].Amount) + + // Will pick up inactive vals then split the remaining on all active validators + amount = sdk.NewInt(1_111) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 4) + suMap = splitDelegationSliceToMap(sUndel) + suite.Require().Equal(pool.Validators[valAddrs[0]].BondedAmount, suMap[valAddrs[0]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[1]].BondedAmount, suMap[valAddrs[1]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[4]].BondedAmount, suMap[valAddrs[4]].Amount) + suite.Require().Equal(sdk.NewInt(1), suMap[valAddrs[2]].Amount) + + amount = sdk.NewInt(1_112) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 5) + suMap = splitDelegationSliceToMap(sUndel) + suite.Require().Equal(pool.Validators[valAddrs[0]].BondedAmount, suMap[valAddrs[0]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[1]].BondedAmount, suMap[valAddrs[1]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[4]].BondedAmount, suMap[valAddrs[4]].Amount) + suite.Require().Equal(sdk.NewInt(1), suMap[valAddrs[2]].Amount) + suite.Require().Equal(sdk.NewInt(1), suMap[valAddrs[3]].Amount) + + amount = sdk.NewInt(1_122) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 5) + suMap = splitDelegationSliceToMap(sUndel) + suite.Require().Equal(pool.Validators[valAddrs[0]].BondedAmount, suMap[valAddrs[0]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[1]].BondedAmount, suMap[valAddrs[1]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[4]].BondedAmount, suMap[valAddrs[4]].Amount) + suite.Require().Equal(sdk.NewInt(6), suMap[valAddrs[2]].Amount) + suite.Require().Equal(sdk.NewInt(6), suMap[valAddrs[3]].Amount) + + amount = sdk.NewInt(1_150) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 5) + suMap = splitDelegationSliceToMap(sUndel) + suite.Require().Equal(pool.Validators[valAddrs[0]].BondedAmount, suMap[valAddrs[0]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[1]].BondedAmount, suMap[valAddrs[1]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[4]].BondedAmount, suMap[valAddrs[4]].Amount) + suite.Require().Equal(sdk.NewInt(30), suMap[valAddrs[2]].Amount) + suite.Require().Equal(sdk.NewInt(10), suMap[valAddrs[3]].Amount) + + amount = sdk.NewInt(1_220) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Len(sUndel, 5) + suMap = splitDelegationSliceToMap(sUndel) + suite.Require().Equal(pool.Validators[valAddrs[0]].BondedAmount, suMap[valAddrs[0]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[1]].BondedAmount, suMap[valAddrs[1]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[4]].BondedAmount, suMap[valAddrs[4]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[2]].BondedAmount, suMap[valAddrs[2]].Amount) + suite.Require().Equal(pool.Validators[valAddrs[3]].BondedAmount, suMap[valAddrs[3]].Amount) + + // Will fail due to missing amount + amount = sdk.NewInt(1_221) + sUndel = pool.ComputeSplitUndelegations(ctx, amount) + suite.Require().Nil(sUndel) +} + +// TestPool_ValidatorsSplitConsistency test pool validator set bonded amount consistency and associated race conditions +func (suite *KeeperTestSuite) TestPool_ValidatorsSplitConsistency() { + app := suite.app + ctx := suite.ctx + + valAddr := "cosmosvaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcvrj90c" + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: "cosmosvaloper", + ChainId: "cosmos", + Denom: "uatom", + NativeDenom: "uatom", + ConnectionId: "connection-id", + TransferChannelId: "transferChannel-id", + Validators: map[string]*millionstypes.PoolValidator{ + valAddr: { + OperatorAddress: valAddr, + BondedAmount: sdk.NewInt(0), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + State: millionstypes.PoolState_Ready, + })) + + // Start deposit d1, d2 and d3 + d1 := millionstypes.Deposit{ + PoolId: poolID, + DepositId: app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx), + State: millionstypes.DepositState_IbcTransfer, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin("uatom", sdk.NewInt(111)), + } + app.MillionsKeeper.AddDeposit(ctx, &d1) + d2 := millionstypes.Deposit{ + PoolId: poolID, + DepositId: app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx), + State: millionstypes.DepositState_IbcTransfer, + DepositorAddress: suite.addrs[1].String(), + WinnerAddress: suite.addrs[1].String(), + Amount: sdk.NewCoin("uatom", sdk.NewInt(222)), + } + app.MillionsKeeper.AddDeposit(ctx, &d2) + d3 := millionstypes.Deposit{ + PoolId: poolID, + DepositId: app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx), + State: millionstypes.DepositState_IbcTransfer, + DepositorAddress: suite.addrs[2].String(), + WinnerAddress: suite.addrs[2].String(), + Amount: sdk.NewCoin("uatom", sdk.NewInt(333)), + } + app.MillionsKeeper.AddDeposit(ctx, &d3) + + // Validators bounded amount should still be 0 (not delegated yet) + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), pool.Validators[valAddr].BondedAmount) + + // Simulate coin transfer for d1 and d2 + failure on d3 + err = app.MillionsKeeper.OnTransferDepositToNativeChainCompleted(ctx, poolID, d1.DepositId, false) + suite.Require().NoError(err) + err = app.MillionsKeeper.OnTransferDepositToNativeChainCompleted(ctx, poolID, d2.DepositId, false) + suite.Require().NoError(err) + err = app.MillionsKeeper.OnTransferDepositToNativeChainCompleted(ctx, poolID, d3.DepositId, true) + suite.Require().NoError(err) + + // Force fix deposits statuses since they will fail due to missing remote chain + app.MillionsKeeper.UpdateDepositStatus(ctx, poolID, d1.DepositId, millionstypes.DepositState_IcaDelegate, false) + app.MillionsKeeper.UpdateDepositStatus(ctx, poolID, d2.DepositId, millionstypes.DepositState_IcaDelegate, false) + app.MillionsKeeper.UpdateDepositStatus(ctx, poolID, d3.DepositId, millionstypes.DepositState_IcaDelegate, false) + + // Validators bounded amount should still be 0 (not delegated yet) + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), pool.Validators[valAddr].BondedAmount) + + // Simulate delegate success for d1 + failure on d2 + sd := pool.ComputeSplitDelegations(ctx, d1.Amount.Amount) + suite.Require().Len(sd, 1) + err = app.MillionsKeeper.OnDelegateDepositOnNativeChainCompleted(ctx, poolID, d1.DepositId, sd, false) + suite.Require().NoError(err) + sd = pool.ComputeSplitDelegations(ctx, d2.Amount.Amount) + suite.Require().Len(sd, 1) + err = app.MillionsKeeper.OnDelegateDepositOnNativeChainCompleted(ctx, poolID, d2.DepositId, sd, true) + suite.Require().NoError(err) + + // Validators bounded amount should be d1 amount now + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(d1.Amount.Amount, pool.Validators[valAddr].BondedAmount) + + // Simulate delegate success for d2 + sd = pool.ComputeSplitDelegations(ctx, d2.Amount.Amount) + suite.Require().Len(sd, 1) + app.MillionsKeeper.UpdateDepositStatus(ctx, poolID, d2.DepositId, millionstypes.DepositState_IcaDelegate, false) + err = app.MillionsKeeper.OnDelegateDepositOnNativeChainCompleted(ctx, poolID, d2.DepositId, sd, false) + suite.Require().NoError(err) + + // Validators bounded amount should be d1+d2 amount now + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(d1.Amount.Amount.Add(d2.Amount.Amount), pool.Validators[valAddr].BondedAmount) + + // Start withdrawal d1 and d2 + w1 := millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: d1.DepositId, + WithdrawalId: app.MillionsKeeper.GetNextWithdrawalIdAndIncrement(ctx), + State: millionstypes.WithdrawalState_IcaUndelegate, + DepositorAddress: d1.DepositorAddress, + ToAddress: d1.DepositorAddress, + Amount: d1.Amount, + } + app.MillionsKeeper.AddWithdrawal(ctx, w1) + su1 := pool.ComputeSplitUndelegations(ctx, w1.Amount.Amount) + suite.Require().Len(su1, 1) + + w2 := millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: d2.DepositId, + WithdrawalId: app.MillionsKeeper.GetNextWithdrawalIdAndIncrement(ctx), + State: millionstypes.WithdrawalState_IcaUndelegate, + DepositorAddress: d2.DepositorAddress, + ToAddress: d2.DepositorAddress, + Amount: d2.Amount, + } + app.MillionsKeeper.AddWithdrawal(ctx, w2) + su2 := pool.ComputeSplitUndelegations(ctx, w2.Amount.Amount) + suite.Require().Len(su2, 1) + + // Simulate undelegate launched with success for d1 + d2 (ignore error voluntarely here) + err = app.MillionsKeeper.UndelegateWithdrawalOnNativeChain(ctx, poolID, w1.WithdrawalId) + suite.Require().Error(err) + err = app.MillionsKeeper.UndelegateWithdrawalOnNativeChain(ctx, poolID, w2.WithdrawalId) + suite.Require().Error(err) + + // Force fix withdrawals statuses since they will fail due to missing remote chain + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, poolID, w1.WithdrawalId, millionstypes.WithdrawalState_IcaUndelegate, nil, false) + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, poolID, w2.WithdrawalId, millionstypes.WithdrawalState_IcaUndelegate, nil, false) + + // Validators bounded amount should be 0 now + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), pool.Validators[valAddr].BondedAmount) + + // Simulate undelegate success for d1 + failure on d2 + t := time.Now() + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, poolID, w1.WithdrawalId, su1, &t, false) + suite.Require().NoError(err) + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, poolID, w2.WithdrawalId, su2, &t, true) + suite.Require().NoError(err) + + // Validators bounded amount should be d2 now since d2 undelegate request failed + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(d2.Amount.Amount, pool.Validators[valAddr].BondedAmount) + + // Simulate undelegate success for d2 + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, poolID, w2.WithdrawalId, millionstypes.WithdrawalState_IcaUndelegate, nil, false) + err = app.MillionsKeeper.UndelegateWithdrawalOnNativeChain(ctx, poolID, w2.WithdrawalId) + suite.Require().Error(err) + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, poolID, w2.WithdrawalId, su2, &t, false) + suite.Require().NoError(err) + + // Validators bounded amount should be 0 now + pool, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + suite.Require().Equal(sdk.ZeroInt(), pool.Validators[valAddr].BondedAmount) +} diff --git a/x/millions/keeper/keeper_prize.go b/x/millions/keeper/keeper_prize.go new file mode 100644 index 00000000..8d099e77 --- /dev/null +++ b/x/millions/keeper/keeper_prize.go @@ -0,0 +1,286 @@ +package keeper + +import ( + "fmt" + "time" + + gogotypes "github.com/gogo/protobuf/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// ClawBackPrize claw backs a prize by adding its amount to the clawback prize pool +func (k Keeper) ClawBackPrize(ctx sdk.Context, poolID uint64, drawID uint64, prizeID uint64) error { + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + prize, err := k.GetPoolDrawPrize(ctx, poolID, drawID, prizeID) + if err != nil { + return err + } + if prize.State != types.PrizeState_Pending { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "expecting %s but state is %s", types.PrizeState_Pending, prize.State) + } + + pool.AvailablePrizePool = pool.AvailablePrizePool.Add(prize.Amount) + k.updatePool(ctx, &pool) + + if err := k.RemovePrize(ctx, prize); err != nil { + return err + } + + return nil +} + +// AddPrizes adds a prize to a pool and an account +// A new prizeID is generated if not provided +// - adds it to the pool {pool_id, draw_id, prize_id} +// - adds it to the account {winner_address, pool_id, draw_id} prizes +func (k Keeper) AddPrize(ctx sdk.Context, prize types.Prize) { + // Automatically affect ID if missing + if prize.GetPrizeId() == types.UnknownID { + prize.PrizeId = k.GetNextPrizeIdAndIncrement(ctx) + } + + // Ensure payload is valid + if err := prize.ValidateBasic(); err != nil { + panic(err) + } + // Ensure we never override an existing entity + if _, err := k.GetPoolDrawPrize(ctx, prize.GetPoolId(), prize.GetDrawId(), prize.GetPrizeId()); err == nil { + panic(errorsmod.Wrapf(types.ErrEntityOverride, "ID %d", prize.GetPrizeId())) + } + + // Update pool prize + k.setPoolPrize(ctx, prize) + // Update account prize + k.setAccountPrize(ctx, prize) + // Add prize to EPCB queue if needed + if prize.State == types.PrizeState_Pending { + k.addPrizeToEPCBQueue(ctx, prize) + } +} + +// GetNextPrizeID gets the next prize ID +func (k Keeper) GetNextPrizeID(ctx sdk.Context) uint64 { + store := ctx.KVStore(k.storeKey) + nextPrizeId := gogotypes.UInt64Value{} + + b := store.Get(types.NextPrizePrefix) + if b == nil { + panic(fmt.Errorf("getting at key (%v) should not have been nil", types.NextPrizePrefix)) + } + k.cdc.MustUnmarshal(b, &nextPrizeId) + return nextPrizeId.GetValue() +} + +// GetNextPrizeIdAndIncrement gets the next prize ID and store the incremented ID +func (k Keeper) GetNextPrizeIdAndIncrement(ctx sdk.Context) uint64 { + nextPrizeId := k.GetNextPrizeID(ctx) + k.SetNextPrizeID(ctx, nextPrizeId+1) + return nextPrizeId +} + +// SetNextPrizeID sets next prize ID +func (k Keeper) SetNextPrizeID(ctx sdk.Context, prizeID uint64) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: prizeID}) + store.Set(types.NextPrizePrefix, bz) +} + +// GetPoolDrawPrize returns a prize by poolID, drawID, prizeID +func (k Keeper) GetPoolDrawPrize(ctx sdk.Context, poolID uint64, drawID uint64, prizeID uint64) (types.Prize, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetPoolDrawPrizeKey(poolID, drawID, prizeID)) + if bz == nil { + return types.Prize{}, types.ErrPrizeNotFound + } + + var prize types.Prize + if err := k.cdc.Unmarshal(bz, &prize); err != nil { + return types.Prize{}, err + } + + return prize, nil +} + +// RemovePrize removes a prize from the store +func (k Keeper) RemovePrize(ctx sdk.Context, prize types.Prize) error { + // Ensure payload is valid + if err := prize.ValidateBasic(); err != nil { + return err + } + + // Ensure prize entity exists + prize, err := k.GetPoolDrawPrize(ctx, prize.PoolId, prize.DrawId, prize.PrizeId) + if err != nil { + return err + } + + k.removePrizeFromEPCBQueue(ctx, prize) + + store := ctx.KVStore(k.storeKey) + + addr := sdk.MustAccAddressFromBech32(prize.WinnerAddress) + store.Delete(types.GetPoolDrawPrizeKey(prize.PoolId, prize.DrawId, prize.PrizeId)) + store.Delete(types.GetAccountPoolDrawPrizeKey(addr, prize.PoolId, prize.DrawId, prize.PrizeId)) + + return nil +} + +// setPoolPrize sets a prize to the pool prize key +func (k Keeper) setPoolPrize(ctx sdk.Context, prize types.Prize) { + store := ctx.KVStore(k.storeKey) + key := types.GetPoolDrawPrizeKey(prize.PoolId, prize.DrawId, prize.PrizeId) + encodedPrize := k.cdc.MustMarshal(&prize) + store.Set(key, encodedPrize) +} + +// setAccountPrize set the prize for the Account prize key +func (k Keeper) setAccountPrize(ctx sdk.Context, prize types.Prize) { + store := ctx.KVStore(k.storeKey) + winnerAddress := sdk.MustAccAddressFromBech32(prize.WinnerAddress) + key := types.GetAccountPoolDrawPrizeKey(winnerAddress, prize.PoolId, prize.DrawId, prize.PrizeId) + encodedPrize := k.cdc.MustMarshal(&prize) + store.Set(key, encodedPrize) +} + +// addPrizeToEPCBQueue adds a prize to the EPCB queue +func (k Keeper) addPrizeToEPCBQueue(ctx sdk.Context, prize types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + col := k.GetPrizeIDsEPCBQueue(ctx, prize.ExpiresAt) + col.PrizesIds = append(col.PrizesIds, types.PrizeIDs{ + PoolId: prize.PoolId, + DrawId: prize.DrawId, + PrizeId: prize.PrizeId, + }) + prizeStore.Set(types.GetExpiringPrizeTimeKey(prize.ExpiresAt), k.cdc.MustMarshal(&col)) +} + +// removePrizeFromEPCBQueue removes a prize from the EPCB queue +func (k Keeper) removePrizeFromEPCBQueue(ctx sdk.Context, prize types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + col := k.GetPrizeIDsEPCBQueue(ctx, prize.ExpiresAt) + for i, pid := range col.PrizesIds { + if pid.PoolId == prize.PoolId && pid.DrawId == prize.DrawId && pid.PrizeId == prize.PrizeId { + col.PrizesIds = append(col.PrizesIds[:i], col.PrizesIds[i+1:]...) + prizeStore.Set(types.GetExpiringPrizeTimeKey(prize.ExpiresAt), k.cdc.MustMarshal(&col)) + break + } + } + prizeStore.Set(types.GetExpiringPrizeTimeKey(prize.ExpiresAt), k.cdc.MustMarshal(&col)) +} + +// GetPrizeIDsEPCBQueue gets a prize IDs collection for the expiring timestamp +func (k Keeper) GetPrizeIDsEPCBQueue(ctx sdk.Context, timestamp time.Time) (col types.PrizeIDsCollection) { + prizeStore := ctx.KVStore(k.storeKey) + bz := prizeStore.Get(types.GetExpiringPrizeTimeKey(timestamp)) + if bz == nil { + return + } + k.cdc.MustUnmarshal(bz, &col) + return +} + +// EPCBQueueIterator returns an iterator for the EPCB queue up to the specified endTime +func (k Keeper) EPCBQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator { + prizeStore := ctx.KVStore(k.storeKey) + // Add end bytes to ensure the last item gets included in the iterator + return prizeStore.Iterator(types.PrizeExpirationTimePrefix, append(types.GetExpiringPrizeTimeKey(endTime), byte(0x00))) +} + +// DequeueEPCBQueue return all the Expired Prizes to Claw Back and remove them from the queue +func (k Keeper) DequeueEPCBQueue(ctx sdk.Context, endTime time.Time) (prizes []types.PrizeIDs) { + prizeStore := ctx.KVStore(k.storeKey) + + iterator := k.EPCBQueueIterator(ctx, endTime) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var col types.PrizeIDsCollection + k.cdc.MustUnmarshal(iterator.Value(), &col) + prizes = append(prizes, col.PrizesIds...) + prizeStore.Delete(iterator.Key()) + } + + return +} + +// ListAccountPoolPrizes return all the prizes for an account and a pool +// Warning: expensive operation +func (k Keeper) ListAccountPoolPrizes(ctx sdk.Context, addr sdk.Address, poolID uint64) (prizes []types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(prizeStore, types.GetAccountPoolPrizesKey(addr, poolID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var prize types.Prize + k.cdc.MustUnmarshal(iterator.Value(), &prize) + prizes = append(prizes, prize) + } + return +} + +// ListAccountPrizes return all the prizes for an account +// Warning: expensive operation +func (k Keeper) ListAccountPrizes(ctx sdk.Context, addr sdk.Address) (prizes []types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(prizeStore, types.GetAccountPrizesKey(addr)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var prize types.Prize + k.cdc.MustUnmarshal(iterator.Value(), &prize) + prizes = append(prizes, prize) + } + return +} + +// ListPoolDrawPrizes return all the prizes for a pool draw +// Warning: expensive operation +func (k Keeper) ListPoolDrawPrizes(ctx sdk.Context, poolID uint64, drawID uint64) (prizes []types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(prizeStore, types.GetPoolDrawPrizesKey(poolID, drawID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var prize types.Prize + k.cdc.MustUnmarshal(iterator.Value(), &prize) + prizes = append(prizes, prize) + } + return +} + +// ListPoolPrizes return all the prizes for a pool +// Warning: expensive operation +func (k Keeper) ListPoolPrizes(ctx sdk.Context, poolID uint64) (prizes []types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(prizeStore, types.GetPoolPrizesKey(poolID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var prize types.Prize + k.cdc.MustUnmarshal(iterator.Value(), &prize) + prizes = append(prizes, prize) + } + return +} + +// ListPrizes return all the prizes for an address +// Warning: expensive operation +func (k Keeper) ListPrizes(ctx sdk.Context) (prizes []types.Prize) { + prizeStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(prizeStore, types.GetPrizesKey()) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var prize types.Prize + k.cdc.MustUnmarshal(iterator.Value(), &prize) + prizes = append(prizes, prize) + } + return +} diff --git a/x/millions/keeper/keeper_prize_test.go b/x/millions/keeper/keeper_prize_test.go new file mode 100644 index 00000000..9763d00e --- /dev/null +++ b/x/millions/keeper/keeper_prize_test.go @@ -0,0 +1,524 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestPrize_IDsGeneration runs test related to prizeID generation +func (suite *KeeperTestSuite) TestPrize_IDsGeneration() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Add 10 Prizes + for i := 0; i < 10; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + prizeID := app.MillionsKeeper.GetNextPrizeID(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{PoolId: poolID})) + + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: poolID, + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // Test that prizeID is incremented + suite.Require().Equal(uint64(i+1), prizeID) + + // Test that we never override an existing entity + panicF := func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: poolID, + DrawId: pool.NextDrawId, + PrizeId: prizeID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + } +} + +// TestPrize_AddPrize tests the logic of adding a prize to the store +func (suite *KeeperTestSuite) TestPrize_AddPrize() { + // Set the app context + app := suite.app + ctx := suite.ctx + + prizesBefore := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizesBefore, 0) + // Initialize prizeBefore + var prizesAccountPoolBefore []millionstypes.Prize + var prizesAccountBefore []millionstypes.Prize + var prizesPoolDrawBefore []millionstypes.Prize + var prizesPoolBefore []millionstypes.Prize + + // Add 5 prizes + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + // Retrieve the pool from the state + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + prizesAccountPoolBefore = app.MillionsKeeper.ListAccountPrizes(ctx, suite.addrs[i]) + prizesAccountBefore = app.MillionsKeeper.ListAccountPoolPrizes(ctx, suite.addrs[i], pool.PoolId) + prizesPoolDrawBefore = app.MillionsKeeper.ListPoolDrawPrizes(ctx, pool.PoolId, pool.NextDrawId) + prizesPoolBefore = app.MillionsKeeper.ListPoolPrizes(ctx, pool.PoolId) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[i].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + prizes := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizes, 5) + pool, err := app.MillionsKeeper.GetPool(ctx, prizes[0].PoolId) + suite.Require().NoError(err) + // - Test validateBasics + // -- Test that the prize validation panics with an invalid pool ID + panicF := func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: uint64(0), + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the prize validation panics with an invalid draw ID + panicF = func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: uint64(0), + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the prize validation panics with an invalid prize ID + panicF = func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + PrizeId: uint64(1), + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + prizes = app.MillionsKeeper.ListPrizes(ctx) + prizes[0].PrizeId = 0 + } + suite.Require().Panics(panicF) + // -- Test that the prize validation panics with an invalid state + panicF = func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Unspecified, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the prize validation panics with an invalid winnerAddress + panicF = func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Unspecified, + WinnerAddress: "", + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the prize validation panics with an invalid prize amount + panicF = func() { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Unspecified, + WinnerAddress: "", + Amount: sdk.NewCoin(localPoolDenom, sdk.ZeroInt()), + }) + } + suite.Require().Panics(panicF) + // - Test List Methods to verify AddPrize was correctly added + prizes = app.MillionsKeeper.ListPrizes(ctx) + + for _, prize := range prizes { + addr := sdk.MustAccAddressFromBech32(prize.WinnerAddress) + // Test ListAccountPrizes + prizesAccountPrize := app.MillionsKeeper.ListAccountPrizes(ctx, addr) + suite.Require().Equal(len(prizesAccountBefore)+1, len(prizesAccountPrize)) + // Test ListAccountPoolPrizes + prizesAccountPool := app.MillionsKeeper.ListAccountPoolPrizes(ctx, addr, prize.PoolId) + suite.Require().Equal(len(prizesAccountPoolBefore)+1, len(prizesAccountPool)) + // Test ListPoolDrawPrizes + prizesPoolDraw := app.MillionsKeeper.ListPoolDrawPrizes(ctx, prize.PoolId, prize.DrawId) + suite.Require().Equal(len(prizesPoolDrawBefore)+1, len(prizesPoolDraw)) + // Test ListPoolPrizes + prizesPool := app.MillionsKeeper.ListPoolPrizes(ctx, prize.PoolId) + suite.Require().Equal(len(prizesPoolBefore)+1, len(prizesPool)) + + // Test GetPoolDrawPrize + poolDrawPrize, err := app.MillionsKeeper.GetPoolDrawPrize(ctx, prize.PoolId, prize.DrawId, prize.PrizeId) + suite.Require().NoError(err) + suite.Require().Equal(poolDrawPrize.PoolId, prize.PoolId) + } +} + +// TestPrize_RemovePrize tests the logic of removing a prize from the store +func (suite *KeeperTestSuite) TestPrize_RemovePrize() { + // Set the app context + app := suite.app + ctx := suite.ctx + + prizesBefore := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizesBefore, 0) + // Initialize prize before + var prizesAccountPoolBefore []millionstypes.Prize + var prizesAccountBefore []millionstypes.Prize + var prizesPoolDrawBefore []millionstypes.Prize + var prizesPoolBefore []millionstypes.Prize + + // Add 5 prizes + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + // Retrieve the pool from the state + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + prizesAccountPoolBefore = app.MillionsKeeper.ListAccountPrizes(ctx, suite.addrs[i]) + prizesAccountBefore = app.MillionsKeeper.ListAccountPoolPrizes(ctx, suite.addrs[i], pool.PoolId) + prizesPoolDrawBefore = app.MillionsKeeper.ListPoolDrawPrizes(ctx, pool.PoolId, pool.NextDrawId) + prizesPoolBefore = app.MillionsKeeper.ListPoolPrizes(ctx, pool.PoolId) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[i].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + prizes := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizes, 5) + pool, err := app.MillionsKeeper.GetPool(ctx, prizes[0].PoolId) + suite.Require().NoError(err) + // - Test validateBasics + // -- Test that the prize validation return an error with an invalid pool ID + err = app.MillionsKeeper.RemovePrize(ctx, millionstypes.Prize{ + PoolId: uint64(0), + DrawId: pool.NextDrawId, + PrizeId: prizes[0].PrizeId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + // -- Test that the prize validation return an error with an invalid draw ID + err = app.MillionsKeeper.RemovePrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: uint64(0), + PrizeId: prizes[0].PrizeId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + // -- Test that the prize validation return an error with an invalid prize ID + err = app.MillionsKeeper.RemovePrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + PrizeId: uint64(0), + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + // -- Test that the prize validation return an error with an invalid state + err = app.MillionsKeeper.RemovePrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + PrizeId: prizes[0].PrizeId, + State: millionstypes.PrizeState_Unspecified, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidPrizeState) + // -- Test that the prize validation panics with an invalid winnerAddress + err = app.MillionsKeeper.RemovePrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + PrizeId: prizes[0].PrizeId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: "", + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidWinnerAddress) + // -- Test that the prize validation return an error with an invalid prize amount + err = app.MillionsKeeper.RemovePrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: pool.NextDrawId, + PrizeId: prizes[0].PrizeId, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.ZeroInt()), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidPrizeAmount) + // - Test List Methods to verify AddPrize was correctly added + prizes = app.MillionsKeeper.ListPrizes(ctx) + + for _, prize := range prizes { + addr := sdk.MustAccAddressFromBech32(prize.WinnerAddress) + prizesAccountPrize := app.MillionsKeeper.ListAccountPrizes(ctx, addr) + suite.Require().Equal(len(prizesAccountBefore)+1, len(prizesAccountPrize)) + // Test ListAccountPoolPrizes before RemovePrize + prizesAccountPool := app.MillionsKeeper.ListAccountPoolPrizes(ctx, addr, prize.PoolId) + suite.Require().Equal(len(prizesAccountPoolBefore)+1, len(prizesAccountPool)) + // Test ListPoolDrawPrizes before RemovePrize + prizesPoolDraw := app.MillionsKeeper.ListPoolDrawPrizes(ctx, prize.PoolId, prize.DrawId) + suite.Require().Equal(len(prizesPoolDrawBefore)+1, len(prizesPoolDraw)) + // Test ListPoolPrizes before RemovePrize + prizesPool := app.MillionsKeeper.ListPoolPrizes(ctx, prize.PoolId) + suite.Require().Equal(len(prizesPoolBefore)+1, len(prizesPool)) + + // Test GetPoolDrawPrize + poolDrawPrize, err := app.MillionsKeeper.GetPoolDrawPrize(ctx, prize.PoolId, prize.DrawId, prize.PrizeId) + suite.Require().NoError(err) + suite.Require().Equal(poolDrawPrize.PoolId, prize.PoolId) + + // Remove prize + err = app.MillionsKeeper.RemovePrize(ctx, prize) + suite.Require().NoError(err) + // Test ListAccountPrizes after RemovePrize + prizesAccountPool = app.MillionsKeeper.ListAccountPrizes(ctx, addr) + suite.Require().Equal(len(prizesAccountBefore), len(prizesAccountPool)) + // Test ListAccountPoolPrizes after RemovePrize + prizesAccountPool = app.MillionsKeeper.ListAccountPoolPrizes(ctx, addr, prize.PoolId) + suite.Require().Equal(len(prizesAccountPoolBefore), len(prizesAccountPool)) + // Test ListPoolDrawPrizes after RemovePrize + prizesPoolDraw = app.MillionsKeeper.ListPoolDrawPrizes(ctx, prize.PoolId, prize.DrawId) + suite.Require().Equal(len(prizesPoolDrawBefore), len(prizesPoolDraw)) + // Test ListPoolPrizes after RemovePrize + prizesPool = app.MillionsKeeper.ListPoolPrizes(ctx, prize.PoolId) + suite.Require().Equal(len(prizesPoolBefore), len(prizesPool)) + } +} + +// TestPrize_ClawBackPrize test the logic of the prize clawback +func (suite *KeeperTestSuite) TestPrize_ClawBackPrize() { + app := suite.app + ctx := suite.ctx + + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.5)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(0.7)}, + }, + }, + }) + app.MillionsKeeper.AddPool(ctx, pool) + + // Create prizes with various expiration time + drawID := pool.NextDrawId + for i := 1; i <= 5; i++ { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: drawID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Second), + }) + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: drawID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Second), + }) + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: drawID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Second), + }) + } + + prizes := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizes, 15) + + // Test invalid prize with wrong PoolID + err := app.MillionsKeeper.ClawBackPrize(ctx, uint64(0), prizes[0].DrawId, prizes[0].PrizeId) + suite.Require().ErrorIs(err, millionstypes.ErrPoolNotFound) + + // Test invalid prize with wrong drawID + err = app.MillionsKeeper.ClawBackPrize(ctx, prizes[0].PoolId, uint64(0), prizes[0].PrizeId) + suite.Require().ErrorIs(err, millionstypes.ErrPrizeNotFound) + + // Test invalid pool with wrong prizeID + err = app.MillionsKeeper.ClawBackPrize(ctx, prizes[0].PoolId, prizes[0].DrawId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrPrizeNotFound) + + for _, prize := range prizes { + // Get pool before clawedBack + pool, err := app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + // Get prize before clawedBack + prizes = app.MillionsKeeper.ListPrizes(ctx) + // ClawBackPrize + err = app.MillionsKeeper.ClawBackPrize(ctx, prize.PoolId, prize.DrawId, prize.PrizeId) + suite.Require().NoError(err) + // Get pool after clawedBack + poolAftrCB, err := app.MillionsKeeper.GetPool(ctx, pool.PoolId) + suite.Require().NoError(err) + suite.Require().Equal(pool.AvailablePrizePool.Add(prize.Amount), poolAftrCB.AvailablePrizePool) + // Get prize after clawedBack + prizesAftrCB := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().NoError(err) + suite.Require().Equal(len(prizes)-1, len(prizesAftrCB)) + } + // List prize should be empty + prizes = app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizes, 0) +} + +// TestPrize_ClawbackQueueExpiration tests the Dequeueing of expired prizes +func (suite *KeeperTestSuite) TestPrize_ClawbackQueueExpiration() { + app := suite.app + ctx := suite.ctx + + pool := newValidPool(suite, millionstypes.Pool{ + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.5)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(0.7)}, + }, + }, + }) + app.MillionsKeeper.AddPool(ctx, pool) + + // Create prizes with various expiration time + drawID := pool.NextDrawId + for i := 1; i <= 5; i++ { + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: drawID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Second), + }) + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: drawID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Second), + }) + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: pool.PoolId, + DrawId: drawID, + State: millionstypes.PrizeState_Pending, + WinnerAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + ExpiresAt: ctx.BlockTime().Add(time.Duration(i) * time.Second), + }) + } + + // EPCB queue should contain the prizes at their expiration time + curPrizeId := millionstypes.UnknownID + 1 + for i := 1; i <= 5; i++ { + col := app.MillionsKeeper.GetPrizeIDsEPCBQueue(ctx, ctx.BlockTime().Add(time.Duration(i)*time.Second)) + suite.Require().Len(col.PrizesIds, 3) + for _, pid := range col.PrizesIds { + suite.Require().Equal(pool.PoolId, pid.PoolId) + suite.Require().Equal(drawID, pid.DrawId) + suite.Require().Equal(curPrizeId, pid.PrizeId) + curPrizeId += 1 + } + } + + // Dequeueing EPCBQueue at endTime should dequeue all items up to endTime + curPrizeId = millionstypes.UnknownID + 1 + + // Should do nothing - 15 remaining prizes + prizesToDequeue := app.MillionsKeeper.DequeueEPCBQueue(ctx, ctx.BlockTime().Add(time.Duration(0)*time.Second)) + suite.Require().Len(prizesToDequeue, 0) + + // Should dequeue 6 prizes - 9 remaining prizes + prizesToDequeue = app.MillionsKeeper.DequeueEPCBQueue(ctx, ctx.BlockTime().Add(time.Duration(2)*time.Second)) + suite.Require().Len(prizesToDequeue, 6) + for _, prize := range prizesToDequeue { + suite.Require().Equal(curPrizeId, prize.PrizeId) + curPrizeId += 1 + } + + // Should dequeue 6 more prizes - 3 remaing prizes + prizesToDequeue = app.MillionsKeeper.DequeueEPCBQueue(ctx, ctx.BlockTime().Add(time.Duration(4)*time.Second)) + suite.Require().Len(prizesToDequeue, 6) + for _, prize := range prizesToDequeue { + suite.Require().Equal(curPrizeId, prize.PrizeId) + curPrizeId += 1 + } + + // Should dequeue all remaining prizes + prizesToDequeue = app.MillionsKeeper.DequeueEPCBQueue(ctx, ctx.BlockTime().Add(1_000_000*time.Second)) + suite.Require().Len(prizesToDequeue, 3) + for _, prize := range prizesToDequeue { + suite.Require().Equal(curPrizeId, prize.PrizeId) + curPrizeId += 1 + } +} diff --git a/x/millions/keeper/keeper_test.go b/x/millions/keeper/keeper_test.go new file mode 100644 index 00000000..97694d81 --- /dev/null +++ b/x/millions/keeper/keeper_test.go @@ -0,0 +1,158 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + apptesting "github.com/lum-network/chain/app/testing" + millionstypes "github.com/lum-network/chain/x/millions/types" + + "github.com/lum-network/chain/app" +) + +const testChainID = "lum-network-devnet-1" + +var ( + cosmosPoolValidator = "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn" + cosmosIcaDepositAddress = "cosmos1clpqr4nrk4khgkxj78fcwwh6dl3uw4ep4tgu9q" + cosmosIcaPrizePoolAddress = "cosmos196ax4vc0lwpxndu9dyhvca7jhxp70rmcfhxsrt" + localPoolDenom = "ulum" + remotePoolDenom = "uatom" + remoteBech32PrefixValAddr = "cosmosvaloper" + remoteChainId = "cosmos" + remoteConnectionId = "connection-id" + remoteTransferChannelId = "transfer" +) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + app *app.App + addrs []sdk.AccAddress + moduleAddrs []sdk.AccAddress + valAddrs []sdk.ValAddress +} + +func TestKeeperSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +func (suite *KeeperTestSuite) SetupTest() { + app := app.SetupForTesting(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + // Setup the default application + suite.app = app + suite.ctx = ctx.WithChainID(testChainID).WithBlockTime(time.Now().UTC()) + + // Setup test account addresses + suite.addrs = apptesting.AddTestAddrsWithDenom(app, ctx, 6, sdk.NewInt(1_000_0000_000), app.StakingKeeper.BondDenom(ctx)) + for i := 0; i < 6; i++ { + poolAddress := millionstypes.NewPoolAddress(uint64(i+1), "unused-in-test") + apptesting.AddTestModuleAccount(app, ctx, poolAddress) + suite.moduleAddrs = append(suite.moduleAddrs, poolAddress) + } + + // Setup vals for pools + vals := app.StakingKeeper.GetAllValidators(ctx) + suite.valAddrs = []sdk.ValAddress{} + for _, v := range vals { + addr, err := sdk.ValAddressFromBech32(v.OperatorAddress) + suite.Require().NoError(err) + suite.valAddrs = append(suite.valAddrs, addr) + } + + // Setup test params + suite.app.MillionsKeeper.SetParams(ctx, millionstypes.Params{ + MinDepositAmount: sdk.NewInt(millionstypes.MinAcceptableDepositAmount), + MaxPrizeStrategyBatches: 1_000, + MaxPrizeBatchQuantity: 1_000_000, + MinDrawScheduleDelta: 1 * time.Hour, + MaxDrawScheduleDelta: 366 * 24 * time.Hour, + PrizeExpirationDelta: 30 * 24 * time.Hour, + FeesStakers: sdk.ZeroDec(), + MinDepositDrawDelta: millionstypes.MinAcceptableDepositDrawDelta, + }) +} + +// floatToDec simple helper to create sdk.Dec with a precision of 6 +func floatToDec(v float64) sdk.Dec { + return sdk.NewDecWithPrec(int64(v*1_000_000), 6) +} + +// newValidPool fills up missing params to the pool to make it valid in order to ease testing +func newValidPool(suite *KeeperTestSuite, pool millionstypes.Pool) *millionstypes.Pool { + params := suite.app.MillionsKeeper.GetParams(suite.ctx) + + if pool.Denom == "" { + pool.Denom = suite.app.StakingKeeper.BondDenom(suite.ctx) + } + if pool.NativeDenom == "" { + pool.NativeDenom = suite.app.StakingKeeper.BondDenom(suite.ctx) + } + if pool.ChainId == "" { + pool.ChainId = testChainID + } + if pool.Validators == nil { + pool.Validators = map[string]*millionstypes.PoolValidator{} + for _, addr := range suite.valAddrs { + pool.Validators[addr.String()] = &millionstypes.PoolValidator{ + OperatorAddress: addr.String(), + BondedAmount: sdk.ZeroInt(), + IsEnabled: true, + } + } + } + if pool.Bech32PrefixAccAddr == "" { + pool.Bech32PrefixAccAddr = sdk.GetConfig().GetBech32AccountAddrPrefix() + } + if pool.Bech32PrefixValAddr == "" { + pool.Bech32PrefixValAddr = sdk.GetConfig().GetBech32ValidatorAddrPrefix() + } + if pool.MinDepositAmount.IsNil() { + pool.MinDepositAmount = params.MinDepositAmount + } + if err := pool.DrawSchedule.ValidateBasic(params); err != nil { + pool.DrawSchedule = millionstypes.DrawSchedule{DrawDelta: 1 * time.Hour, InitialDrawAt: time.Now().UTC()} + } + if err := pool.PrizeStrategy.Validate(params); err != nil { + pool.PrizeStrategy = millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 1, DrawProbability: sdk.NewDec(1)}}} + } + if pool.LocalAddress == "" { + pool.LocalAddress = suite.moduleAddrs[0].String() + } + if pool.IcaDepositAddress == "" { + pool.IcaDepositAddress = suite.moduleAddrs[1].String() + } + if pool.IcaPrizepoolAddress == "" { + pool.IcaPrizepoolAddress = suite.moduleAddrs[2].String() + } + if pool.NextDrawId == millionstypes.UnknownID { + pool.NextDrawId = millionstypes.UnknownID + 1 + } + if pool.TvlAmount.IsNil() { + pool.TvlAmount = sdk.ZeroInt() + } + if pool.SponsorshipAmount.IsNil() { + pool.SponsorshipAmount = sdk.ZeroInt() + } + if pool.AvailablePrizePool.IsNil() { + pool.AvailablePrizePool = sdk.NewCoin(pool.Denom, sdk.ZeroInt()) + } + if pool.State == millionstypes.PoolState_Unspecified { + pool.State = millionstypes.PoolState_Ready + } + if pool.CreatedAt.IsZero() { + pool.CreatedAt = suite.ctx.BlockTime() + } + if pool.UpdatedAt.IsZero() { + pool.UpdatedAt = suite.ctx.BlockTime() + } + return &pool +} diff --git a/x/millions/keeper/keeper_withdrawal.go b/x/millions/keeper/keeper_withdrawal.go new file mode 100644 index 00000000..45e9185f --- /dev/null +++ b/x/millions/keeper/keeper_withdrawal.go @@ -0,0 +1,524 @@ +package keeper + +import ( + "fmt" + "time" + + gogotypes "github.com/gogo/protobuf/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ibctypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// UndelegateWithdrawalOnNativeChain Undelegates a withdrawal from the native chain validators +// - go to OnUndelegateWithdrawalOnNativeChainCompleted directly upon undelegate success if local zone +// - or wait for the ICA callback to move to OnUndelegateWithdrawalOnNativeChainCompleted +func (k Keeper) UndelegateWithdrawalOnNativeChain(ctx sdk.Context, poolID uint64, withdrawalID uint64) error { + logger := k.Logger(ctx).With("ctx", "withdrawal_undelegate") + + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + + withdrawal, err := k.GetPoolWithdrawal(ctx, poolID, withdrawalID) + if err != nil { + return err + } + if withdrawal.State != types.WithdrawalState_IcaUndelegate { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.WithdrawalState_IcaUndelegate.String(), withdrawal.State.String()) + } + + if pool.IsLocalZone(ctx) { + modAddr := sdk.MustAccAddressFromBech32(pool.GetIcaDepositAddress()) + splits := pool.ComputeSplitUndelegations(ctx, withdrawal.GetAmount().Amount) + if len(splits) == 0 { + return types.ErrPoolEmptySplitDelegations + } + var unbondingEndsAt *time.Time + for _, split := range splits { + valAddr, err := sdk.ValAddressFromBech32(split.ValidatorAddress) + if err != nil { + return err + } + shares, err := k.StakingKeeper.ValidateUnbondAmount( + ctx, + modAddr, + valAddr, + split.Amount, + ) + if err != nil { + return errorsmod.Wrapf(err, "%s", valAddr.String()) + } + + // Trigger undelegate + endsAt, err := k.StakingKeeper.Undelegate(ctx, modAddr, valAddr, shares) + if err != nil { + return errorsmod.Wrapf(err, "%s", valAddr.String()) + } + if unbondingEndsAt == nil || endsAt.After(*unbondingEndsAt) { + unbondingEndsAt = &endsAt + } + } + // Apply undelegate pool validators update + pool.ApplySplitUndelegate(ctx, splits) + k.updatePool(ctx, &pool) + return k.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, poolID, withdrawalID, splits, unbondingEndsAt, false) + } + + // Prepare undelegate split + splits := pool.ComputeSplitUndelegations(ctx, withdrawal.GetAmount().Amount) + if len(splits) == 0 { + return types.ErrPoolEmptySplitDelegations + } + + // Construct our callback data + callbackData := types.UndelegateCallback{ + PoolId: poolID, + WithdrawalId: withdrawalID, + SplitDelegations: splits, + } + marshalledCallbackData, err := k.MarshalUndelegateCallbackArgs(ctx, callbackData) + if err != nil { + return err + } + + // Build undelegate tx + var msgs []sdk.Msg + for _, split := range splits { + msgs = append(msgs, &stakingtypes.MsgUndelegate{ + DelegatorAddress: pool.GetIcaDepositAddress(), + ValidatorAddress: split.ValidatorAddress, + Amount: sdk.NewCoin(pool.NativeDenom, split.Amount), + }) + } + + // Apply undelegate pool validators update + pool.ApplySplitUndelegate(ctx, splits) + k.updatePool(ctx, &pool) + + // Dispatch our message with a timeout of 30 minutes in nanos + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + types.IBCTransferTimeoutNanos + sequence, err := k.BroadcastICAMessages(ctx, poolID, types.ICATypeDeposit, msgs, timeoutTimestamp, ICACallbackID_Undelegate, marshalledCallbackData) + if err != nil { + // Return with error here since it is the first operation and nothing needs to be saved to state + logger.Error( + fmt.Sprintf("failed to dispatch ICA undelegate: %v", err), + "pool_id", poolID, + "withdrawal_id", withdrawalID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return err + } + logger.Debug( + "ICA undelegate dispatched", + "pool_id", poolID, + "withdrawal_id", withdrawalID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return nil +} + +// OnUndelegateWithdrawalOnNativeChainCompleted Acknowledge the ICA undelegate from the native chain validators response +// once unbonding ends one can call TransferWithdrawalToLocalChain to transfer the withdrawn amount to the requested account +func (k Keeper) OnUndelegateWithdrawalOnNativeChainCompleted(ctx sdk.Context, poolID uint64, withdrawalID uint64, splits []*types.SplitDelegation, unbondingEndsAt *time.Time, isError bool) error { + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + withdrawal, err := k.GetPoolWithdrawal(ctx, poolID, withdrawalID) + if err != nil { + return err + } + + // Check withdrawal state + if withdrawal.State != types.WithdrawalState_IcaUndelegate { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.WithdrawalState_IcaUndelegate.String(), withdrawal.State.String()) + } + + if isError { + // Revert undelegate pool validators update + pool.ApplySplitDelegate(ctx, splits) + k.updatePool(ctx, &pool) + k.UpdateWithdrawalStatus(ctx, poolID, withdrawalID, types.WithdrawalState_IcaUndelegate, nil, true) + return nil + } + + // Set the unbondingEndsAt and add withdrawal to matured queue + withdrawal.UnbondingEndsAt = unbondingEndsAt + k.UpdateWithdrawalStatus(ctx, poolID, withdrawalID, types.WithdrawalState_IcaUnbonding, unbondingEndsAt, false) + k.addWithdrawalToMaturedQueue(ctx, withdrawal) + return nil +} + +// TransferWithdrawalToLocalChain Transfer a withdrawal from the native chain to the local chain +// - wait for the ICA callback to move to OnTransferWithdrawalToLocalChainCompleted +// - or go to OnTransferWithdrawalToLocalChainCompleted directly if local zone already +func (k Keeper) TransferWithdrawalToLocalChain(ctx sdk.Context, poolID uint64, withdrawalID uint64) error { + logger := k.Logger(ctx).With("ctx", "withdrawal_transfer") + + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return err + } + withdrawal, err := k.GetPoolWithdrawal(ctx, poolID, withdrawalID) + if err != nil { + return err + } + + // Check state ibc transfer and unbonding condition + if withdrawal.State != types.WithdrawalState_IbcTransfer { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.WithdrawalState_IbcTransfer.String(), withdrawal.State.String()) + } else if withdrawal.UnbondingEndsAt == nil || withdrawal.UnbondingEndsAt.After(ctx.BlockTime()) { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "unbonding in progress") + } + + if pool.IsLocalZone(ctx) { + // Move funds + if err := k.BankKeeper.SendCoins(ctx, + sdk.MustAccAddressFromBech32(pool.GetIcaDepositAddress()), + sdk.MustAccAddressFromBech32(withdrawal.ToAddress), + sdk.NewCoins(withdrawal.Amount), + ); err != nil { + // Return with error here and let the caller manage the state changes if needed + return err + } + return k.OnTransferWithdrawalToLocalChainCompleted(ctx, poolID, withdrawalID, false) + } + + // Construct our callback data + callbackData := types.TransferFromNativeCallback{ + Type: types.TransferType_Withdraw, + PoolId: poolID, + WithdrawalId: withdrawalID, + } + marshalledCallbackData, err := k.MarshalTransferFromNativeCallbackArgs(ctx, callbackData) + if err != nil { + return err + } + + // Converts the local ibc Denom into the native chain Denom + amount := sdk.NewCoin(pool.NativeDenom, withdrawal.Amount.Amount) + // Build transfer tx + var msgs []sdk.Msg + timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + types.IBCTransferTimeoutNanos + msgs = append(msgs, ibctypes.NewMsgTransfer( + ibctypes.PortID, + pool.GetTransferChannelId(), + amount, + pool.GetIcaDepositAddress(), + withdrawal.GetToAddress(), + clienttypes.Height{}, + timeoutTimestamp, + )) + + // Dispatch our message with a timeout of 30 minutes in nanos + sequence, err := k.BroadcastICAMessages(ctx, poolID, types.ICATypeDeposit, msgs, timeoutTimestamp, ICACallbackID_TransferFromNative, marshalledCallbackData) + if err != nil { + // Return with error here and let the caller manage the state changes if needed + logger.Error( + fmt.Sprintf("failed to dispatch ICA transfer: %v", err), + "pool_id", poolID, + "withdrawal_id", withdrawalID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return err + } + logger.Debug( + "ICA transfer dispatched", + "pool_id", poolID, + "withdrawal_id", withdrawalID, + "chain_id", pool.GetChainId(), + "sequence", sequence, + ) + return nil +} + +// OnTransferWithdrawalToLocalChainCompleted Acknowledge the IBC transfer to the local chain response +func (k Keeper) OnTransferWithdrawalToLocalChainCompleted(ctx sdk.Context, poolID uint64, withdrawalID uint64, isError bool) error { + withdrawal, err := k.GetPoolWithdrawal(ctx, poolID, withdrawalID) + if err != nil { + return err + } + + if withdrawal.State != types.WithdrawalState_IbcTransfer { + return errorsmod.Wrapf(types.ErrIllegalStateOperation, "state should be %s but is %s", types.WithdrawalState_IbcTransfer.String(), withdrawal.State.String()) + } + + if isError { + k.UpdateWithdrawalStatus(ctx, poolID, withdrawalID, types.WithdrawalState_IbcTransfer, withdrawal.UnbondingEndsAt, true) + return nil + } + + if err := k.RemoveWithdrawal(ctx, withdrawal); err != nil { + return err + } + return nil +} + +// GetNextWithdrawalID gets the next withdrawal deposit ID +func (k Keeper) GetNextWithdrawalID(ctx sdk.Context) uint64 { + store := ctx.KVStore(k.storeKey) + nextWithdrawalId := gogotypes.UInt64Value{} + + b := store.Get(types.NextWithdrawalPrefix) + if b == nil { + panic(fmt.Errorf("getting at key (%v) should not have been nil", types.NextWithdrawalPrefix)) + } + k.cdc.MustUnmarshal(b, &nextWithdrawalId) + return nextWithdrawalId.GetValue() +} + +// GetNextWithdrawalIdAndIncrement gets the next withdrawal ID and store the incremented ID +func (k Keeper) GetNextWithdrawalIdAndIncrement(ctx sdk.Context) uint64 { + nextWithdrawlId := k.GetNextWithdrawalID(ctx) + k.SetNextWithdrawalID(ctx, nextWithdrawlId+1) + return nextWithdrawlId +} + +// SetNextWithdrawalID sets next withdrawal ID +func (k Keeper) SetNextWithdrawalID(ctx sdk.Context, withdrawalID uint64) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: withdrawalID}) + store.Set(types.NextWithdrawalPrefix, bz) +} + +// GetPoolWithdrawal returns a withdrawal by poolID, withdrawalID +func (k Keeper) GetPoolWithdrawal(ctx sdk.Context, poolID uint64, withdrawalID uint64) (types.Withdrawal, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetPoolWithdrawalKey(poolID, withdrawalID)) + if bz == nil { + return types.Withdrawal{}, types.ErrWithdrawalNotFound + } + + var withdrawal types.Withdrawal + if err := k.cdc.Unmarshal(bz, &withdrawal); err != nil { + return types.Withdrawal{}, err + } + + return withdrawal, nil +} + +// RemoveWithdrawal removes a successful withdrawal for a given account and pool +func (k Keeper) RemoveWithdrawal(ctx sdk.Context, withdrawal types.Withdrawal) error { + // Ensure payload is valid + if err := withdrawal.ValidateBasic(); err != nil { + return err + } + + // Ensure withdrawal entity exists + withdrawal, err := k.GetPoolWithdrawal(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + if err != nil { + return err + } + + if withdrawal.UnbondingEndsAt != nil { + k.removeWithdrawalFromMaturedQueue(ctx, withdrawal) + } + + store := ctx.KVStore(k.storeKey) + addr := sdk.MustAccAddressFromBech32(withdrawal.DepositorAddress) + store.Delete(types.GetPoolWithdrawalKey(withdrawal.PoolId, withdrawal.WithdrawalId)) + store.Delete(types.GetAccountPoolWithdrawalKey(addr, withdrawal.PoolId, withdrawal.WithdrawalId)) + + return nil +} + +// UpdateWithdrawalStatus Update a given withdrawal status by its ID +func (k Keeper) UpdateWithdrawalStatus(ctx sdk.Context, poolID uint64, withdrawalID uint64, status types.WithdrawalState, unbondingEndsAt *time.Time, isError bool) { + withdrawal, err := k.GetPoolWithdrawal(ctx, poolID, withdrawalID) + if err != nil { + panic(err) + } + + if isError { + withdrawal.State = types.WithdrawalState_Failure + withdrawal.ErrorState = status + } else { + withdrawal.State = status + withdrawal.ErrorState = types.WithdrawalState_Unspecified + } + + withdrawal.UpdatedAtHeight = ctx.BlockHeight() + withdrawal.UpdatedAt = ctx.BlockTime() + if unbondingEndsAt != nil { + withdrawal.UnbondingEndsAt = unbondingEndsAt + } + // Update pool withdraw deposit + k.setPoolWithdrawal(ctx, withdrawal) + // Update account withdraw deposit + k.setAccountWithdrawal(ctx, withdrawal) +} + +// AddWithdrawal adds a withdrawDeposit to a pool and account +// - adds it to the pool {pool_id, withdrawal_id} +// - adds it to the account {depositor_address, pool_id, withdrawal_id} withdrawDeposits +func (k Keeper) AddWithdrawal(ctx sdk.Context, withdrawal types.Withdrawal) { + // Automatically affect ID if missing + if withdrawal.GetWithdrawalId() == types.UnknownID { + withdrawal.WithdrawalId = k.GetNextWithdrawalIdAndIncrement(ctx) + } + // Ensure payload is valid + if err := withdrawal.ValidateBasic(); err != nil { + panic(err) + } + + // Ensure we never override an existing entity + if _, err := k.GetPoolWithdrawal(ctx, withdrawal.GetPoolId(), withdrawal.GetWithdrawalId()); err == nil { + panic(errorsmod.Wrapf(types.ErrEntityOverride, "ID %d", withdrawal.GetWithdrawalId())) + } + + // Update pool withdraw deposit + k.setPoolWithdrawal(ctx, withdrawal) + // Update account withdraw deposit + k.setAccountWithdrawal(ctx, withdrawal) + // Add withdrawal to unbonding queue if needed + if withdrawal.State == types.WithdrawalState_IcaUnbonding { + k.addWithdrawalToMaturedQueue(ctx, withdrawal) + } +} + +// setPoolWithdrawal sets a withdraw deposit to the pool withdrawal key +func (k Keeper) setPoolWithdrawal(ctx sdk.Context, withdrawal types.Withdrawal) { + store := ctx.KVStore(k.storeKey) + key := types.GetPoolWithdrawalKey(withdrawal.PoolId, withdrawal.WithdrawalId) + encodedWithDrawal := k.cdc.MustMarshal(&withdrawal) + store.Set(key, encodedWithDrawal) +} + +// setAccountWithdrawal sets a withdraw deposit to the account withdrawal key +func (k Keeper) setAccountWithdrawal(ctx sdk.Context, withdrawal types.Withdrawal) { + store := ctx.KVStore(k.storeKey) + withdrawAddress := sdk.MustAccAddressFromBech32(withdrawal.DepositorAddress) + key := types.GetAccountPoolWithdrawalKey(withdrawAddress, withdrawal.PoolId, withdrawal.WithdrawalId) + encodedWithDrawal := k.cdc.MustMarshal(&withdrawal) + store.Set(key, encodedWithDrawal) +} + +// addWithdrawalToMaturedQueue adds a withdrawal to the WithrawalMatured queue +func (k Keeper) addWithdrawalToMaturedQueue(ctx sdk.Context, withdrawal types.Withdrawal) { + withdrawalStore := ctx.KVStore(k.storeKey) + col := k.GetWithdrawalIDsMaturedQueue(ctx, *withdrawal.UnbondingEndsAt) + col.WithdrawalsIds = append(col.WithdrawalsIds, types.WithdrawalIDs{ + PoolId: withdrawal.PoolId, + WithdrawalId: withdrawal.WithdrawalId, + }) + withdrawalStore.Set(types.GetMaturedWithdrawalTimeKey(*withdrawal.UnbondingEndsAt), k.cdc.MustMarshal(&col)) +} + +// removeWithdrawalFromMaturedQueue removed a withdrawal from the WithrawalMatured queue +func (k Keeper) removeWithdrawalFromMaturedQueue(ctx sdk.Context, withdrawal types.Withdrawal) { + withdrawalStore := ctx.KVStore(k.storeKey) + col := k.GetWithdrawalIDsMaturedQueue(ctx, *withdrawal.UnbondingEndsAt) + for i, wid := range col.WithdrawalsIds { + if wid.PoolId == withdrawal.PoolId && wid.WithdrawalId == withdrawal.WithdrawalId { + col.WithdrawalsIds = append(col.WithdrawalsIds[:i], col.WithdrawalsIds[i+1:]...) + withdrawalStore.Set(types.GetMaturedWithdrawalTimeKey(*withdrawal.UnbondingEndsAt), k.cdc.MustMarshal(&col)) + break + } + } + withdrawalStore.Set(types.GetMaturedWithdrawalTimeKey(*withdrawal.UnbondingEndsAt), k.cdc.MustMarshal(&col)) +} + +// GetWithdrawalIDsMaturedQueue gets a withdrawal IDs collection for the matured unbonding timestamp +func (k Keeper) GetWithdrawalIDsMaturedQueue(ctx sdk.Context, timestamp time.Time) (col types.WithdrawalIDsCollection) { + withdrawalStore := ctx.KVStore(k.storeKey) + bz := withdrawalStore.Get(types.GetMaturedWithdrawalTimeKey(timestamp)) + if bz == nil { + return + } + k.cdc.MustUnmarshal(bz, &col) + return +} + +// MaturedWithdrawalQueueIterator returns an iterator for the Withdrawal Matured queue up to the specified endTime +func (k Keeper) MaturedWithdrawalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator { + withdrawalStore := ctx.KVStore(k.storeKey) + // Add end bytes to ensure the last item gets included in the iterator + return withdrawalStore.Iterator(types.WithdrawalMaturationTimePrefix, append(types.GetMaturedWithdrawalTimeKey(endTime), byte(0x00))) +} + +// DequeueMaturedWithdrawalQueue return all the Matured Withdrawals that can be transfered and can be removed from the queue +func (k Keeper) DequeueMaturedWithdrawalQueue(ctx sdk.Context, endTime time.Time) (withdrawalsIDs []types.WithdrawalIDs) { + withdrawalStore := ctx.KVStore(k.storeKey) + + iterator := k.MaturedWithdrawalQueueIterator(ctx, endTime) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var col types.WithdrawalIDsCollection + k.cdc.MustUnmarshal(iterator.Value(), &col) + withdrawalsIDs = append(withdrawalsIDs, col.WithdrawalsIds...) + withdrawalStore.Delete(iterator.Key()) + } + + return +} + +// ListWithdrawals return all the withdrawals +// Warning: expensive operation +func (k Keeper) ListWithdrawals(ctx sdk.Context) (withdrawals []types.Withdrawal) { + withdrawDepositStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(withdrawDepositStore, types.GetWithdrawalsKey()) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var withdrawal types.Withdrawal + k.cdc.MustUnmarshal(iterator.Value(), &withdrawal) + withdrawals = append(withdrawals, withdrawal) + } + return +} + +// ListAccountWithdrawals return all the withdraw deposits account +// Warning: expensive operation +func (k Keeper) ListAccountWithdrawals(ctx sdk.Context, addr sdk.Address) (withdrawals []types.Withdrawal) { + withdrawDepositStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(withdrawDepositStore, types.GetAccountWithdrawalsKey(addr)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var withdrawal types.Withdrawal + k.cdc.MustUnmarshal(iterator.Value(), &withdrawal) + withdrawals = append(withdrawals, withdrawal) + } + return +} + +// ListAccountPoolWithdrawals return all the withdrawals for and address and a poolID +// Warning: expensive operation +func (k Keeper) ListAccountPoolWithdrawals(ctx sdk.Context, addr sdk.Address, poolID uint64) (withdrawals []types.Withdrawal) { + withdrawalStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(withdrawalStore, types.GetAccountPoolWithdrawalsKey(addr, poolID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var withdrawal types.Withdrawal + k.cdc.MustUnmarshal(iterator.Value(), &withdrawal) + withdrawals = append(withdrawals, withdrawal) + } + return +} + +// ListPoolWithdrawals returns all withdrawals for a given poolID +// Warning: expensive operation +func (k Keeper) ListPoolWithdrawals(ctx sdk.Context, poolID uint64) (withdrawals []types.Withdrawal) { + withdrawalStore := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(withdrawalStore, types.GetPoolWithdrawalsKey(poolID)) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var withdrawal types.Withdrawal + k.cdc.MustUnmarshal(iterator.Value(), &withdrawal) + withdrawals = append(withdrawals, withdrawal) + } + return +} diff --git a/x/millions/keeper/keeper_withdrawal_test.go b/x/millions/keeper/keeper_withdrawal_test.go new file mode 100644 index 00000000..447e7ec3 --- /dev/null +++ b/x/millions/keeper/keeper_withdrawal_test.go @@ -0,0 +1,1320 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + apptesting "github.com/lum-network/chain/app/testing" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestWithdrawal_IDsGeneration tests the withdrawal ID generation +func (suite *KeeperTestSuite) TestWithdrawal_IDsGeneration() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Add 10 deposits + for i := 0; i < 10; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + depositID := app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx) + withdrawalID := app.MillionsKeeper.GetNextWithdrawalIdAndIncrement(ctx) + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{PoolId: poolID})) + + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: suite.addrs[0].String(), + WithdrawalId: withdrawalID, + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // Test that withdrawalID is incremented + suite.Require().Equal(uint64(i+1), withdrawalID) + + // Test that we never override an existing entity + panicF := func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: depositID, + WithdrawalId: withdrawalID, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + } +} + +// TestWithdrawal_AddWithdrawal tests the logic of adding a withdrawal to the store +func (suite *KeeperTestSuite) TestWithdrawal_AddWithdrawal() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Initialize the pool + poolID, err := app.MillionsKeeper.RegisterPool(ctx, + "ulum", + "ulum", + testChainID, + "", + "", + []string{suite.valAddrs[0].String()}, + "lum", + "lumvaloper", + app.MillionsKeeper.GetParams(ctx).MinDepositAmount, + millionstypes.DrawSchedule{DrawDelta: 24 * time.Hour, InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour)}, + millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 100, DrawProbability: sdk.NewDec(1)}}}, + ) + suite.Require().NoError(err) + _, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + withdrawalsBefore := app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(withdrawalsBefore, 0) + withdrawals := app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(withdrawals, 0) + + // Add 5 deposits + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + // Retrieve the pool from the state + pool, err := app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 5) + + // Add 4 withdrawals (keep 1 deposit) + for i := 0; i < 4; i++ { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[i].PoolId, + DepositId: deposits[i].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(withdrawals, 4) + + // Remove the deposit associated witht the previous withdrawals to respect flow logic + for _, withdrawal := range withdrawals { + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: withdrawal.PoolId, + DepositId: withdrawal.DepositId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + // Only 1 deposit should remain + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 1) + + // - Test the validate basics + // -- Test one successful withdrawal with all correct validate basics + panicF := func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().NotPanics(panicF) + // Simulate the remove deposit affter a successful withdrawal + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 5) + // -- Test that the withdrawal validation panics with an invalid pool ID + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + panicF = func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: uint64(0), + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the withdrawal validation panics with an invalid withdrawalID + panicF = func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + WithdrawalId: uint64(4), + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_Unspecified, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + withdrawals[len(withdrawals)-1].WithdrawalId = 0 + } + suite.Require().Panics(panicF) + // -- Test that the withdrawal validation panics with an invalid state + panicF = func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_Unspecified, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the withdrawal validation panics with an invalid DepositorAddress + panicF = func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: "", + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + suite.Require().Panics(panicF) + // -- Test that the withdrawal validation panics with an invalid withdrawal amount + panicF = func() { + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[len(deposits)-1].PoolId, + DepositId: deposits[len(deposits)-1].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(0)), + }) + } + suite.Require().Panics(panicF) + + // Verify that there is no more deposits + deposits = app.MillionsKeeper.ListDeposits(ctx) + suite.Require().Len(deposits, 0) + + // Test all withdrawals + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Equal(len(withdrawalsBefore)+5, len(withdrawals)) + // - Test that the account withdrawals are correctly updated + accountWithdrawals := app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Equal(len(withdrawalsBefore)+5, len(accountWithdrawals)) + + // - Test that the pool withdrawals are correctly updated + for _, withdrawal := range withdrawals { + addr := sdk.MustAccAddressFromBech32(withdrawal.DepositorAddress) + // Test ListAccountPoolWithdrawals + withdrawalsAccountPool := app.MillionsKeeper.ListAccountPoolWithdrawals(ctx, addr, withdrawal.PoolId) + suite.Require().Equal(len(withdrawalsBefore)+1, len(withdrawalsAccountPool)) + // Test ListPoolWithdrawals + withdrawalsPool := app.MillionsKeeper.ListPoolWithdrawals(ctx, withdrawal.PoolId) + suite.Require().Equal(len(withdrawalsBefore)+1, len(withdrawalsPool)) + // Test GetPoolWithdrawal + poolWithdrawal, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(poolWithdrawal.Amount.Amount.Int64(), withdrawal.Amount.Amount.Int64()) + suite.Require().Equal(poolWithdrawal.PoolId, withdrawal.PoolId) + } +} + +// TestWithdrawal_RemoveWithdrawal tests the logic of removing a withdrawal from the store +func (suite *KeeperTestSuite) TestWithdrawal_RemoveWithdrawal() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Initialize the withdrawals + withdrawalsBefore := app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawalsBefore, 0) + accountwithdrawalsBefore := app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(accountwithdrawalsBefore, 0) + + // - Test that withdrawals with wrong poolID, withdrawalID cannot be removed from the pool withdrawal + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + depositID := app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + // Test RemoveWithdrawal with incorrect poolID + withdrawal := millionstypes.Withdrawal{ + PoolId: uint64(0), + DepositId: uint64(1), + WithdrawalId: uint64(1), + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + err := app.MillionsKeeper.RemoveWithdrawal(ctx, withdrawal) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + + // Test RemoveWithdrawal with incorrect withdrawalID + withdrawal = millionstypes.Withdrawal{ + PoolId: uint64(1), + DepositId: uint64(1), + WithdrawalId: uint64(0), + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + err = app.MillionsKeeper.RemoveWithdrawal(ctx, withdrawal) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + + // Test RemoveWithdrawal with incorrect DepositorAddress + withdrawal = millionstypes.Withdrawal{ + PoolId: uint64(1), + DepositId: uint64(1), + WithdrawalId: uint64(1), + DepositorAddress: "no-address", + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + err = app.MillionsKeeper.RemoveWithdrawal(ctx, withdrawal) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidWithdrawalDepositorAddress) + // Test RemoveWithdrawal with incorrect amount + withdrawal = millionstypes.Withdrawal{ + PoolId: uint64(1), + DepositId: uint64(1), + WithdrawalId: uint64(1), + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(0)), + } + err = app.MillionsKeeper.RemoveWithdrawal(ctx, withdrawal) + suite.Require().ErrorIs(err, millionstypes.ErrDepositAlreadyWithdrawn) + + // - Test list All withdrawals + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 5) + // - Test account withdrawals + accountWithdrawals := app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(accountWithdrawals, 5) + // - Test pool withdrawals + pools := app.MillionsKeeper.ListPools(ctx) + for _, pool := range pools { + // Test ListAccountPoolWithdrawals + withdrawalsAccountPool := app.MillionsKeeper.ListAccountPoolWithdrawals(ctx, suite.addrs[0], pool.PoolId) + suite.Require().Equal(len(withdrawalsBefore)+1, len(withdrawalsAccountPool)) + // Test ListPoolWithdrawals + withdrawalsPool := app.MillionsKeeper.ListPoolWithdrawals(ctx, pool.PoolId) + suite.Require().Equal(len(withdrawalsBefore)+1, len(withdrawalsPool)) + } + + // - Test remove withdrawals + for _, withdrawal := range withdrawals { + // Get the pool before remove withdrawal + poolBefore, err := app.MillionsKeeper.GetPool(ctx, withdrawal.PoolId) + suite.Require().NoError(err) + // Get the Account withdrawal before remove withdrawal + addr := sdk.MustAccAddressFromBech32(withdrawal.DepositorAddress) + accountWithdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, addr) + // Get the Account pool deposit before remove deposit + withdrawalsAccountPoolBefore := app.MillionsKeeper.ListAccountPoolWithdrawals(ctx, addr, poolBefore.PoolId) + // Get the pool deposit before remove deposit + withdrawalsPoolBefore := app.MillionsKeeper.ListPoolWithdrawals(ctx, poolBefore.PoolId) + // Test GetPoolWithdrawal + poolDeposit, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(withdrawal.Amount.Amount.Int64(), poolDeposit.Amount.Amount.Int64()) + suite.Require().Equal(withdrawal.PoolId, poolDeposit.PoolId) + // Remove the withdrawals + err = app.MillionsKeeper.RemoveWithdrawal(ctx, withdrawal) + suite.Require().NoError(err) + // Decrement by 1 for each loop + withdrawalsAccount := app.MillionsKeeper.ListAccountWithdrawals(ctx, addr) + suite.Require().Equal(len(accountWithdrawals)-1, len(withdrawalsAccount)) + // Decrement by 1 for each loop + withdrawalsAccountPool := app.MillionsKeeper.ListAccountPoolWithdrawals(ctx, addr, withdrawal.PoolId) + suite.Require().Equal(len(withdrawalsAccountPoolBefore)-1, len(withdrawalsAccountPool)) + // Decrement by 1 for each loop + withdrawalsPool := app.MillionsKeeper.ListPoolWithdrawals(ctx, withdrawal.PoolId) + suite.Require().Equal(len(withdrawalsPoolBefore)-1, len(withdrawalsPool)) + } + + // - Test list All withdrawals + // The last withdrawal has status WithdrawalState_IbcTransfer + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 0) +} + +// TestWithdrawal_UpdateWithdrawalStatus test the logic of updating a withdrawal to the store +func (suite *KeeperTestSuite) TestWithdrawal_UpdateWithdrawalStatus() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Generate 5 withdrawals + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + depositID := app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), math.NewInt(1000)), + })) + + // Create a new deposit and add it to the state + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + } + + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + // - Test the error if we cannot find the withdrawal with wrong poolID + panicF := func() { + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, uint64(0), withdrawals[0].WithdrawalId, millionstypes.WithdrawalState_IcaUndelegate, &time.Time{}, false) + } + suite.Require().Panics(panicF) + // - Test the error if we cannot find the withdrawal with wrong withdrawalID + panicF = func() { + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawals[0].PoolId, uint64(0), millionstypes.WithdrawalState_IcaUndelegate, &time.Time{}, false) + } + suite.Require().Panics(panicF) + // - Test the error management in case of true event + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + for _, withdrawal := range withdrawals { + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, millionstypes.WithdrawalState_IcaUndelegate, &time.Time{}, true) + } + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + for i, withdrawal := range withdrawals { + addr := sdk.MustAccAddressFromBech32(withdrawal.DepositorAddress) + // Test GetPoolWithdrawal + poolWithdrawal, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(poolWithdrawal.Amount.Amount.Int64(), withdrawal.Amount.Amount.Int64()) + suite.Require().Equal(poolWithdrawal.PoolId, withdrawal.PoolId) + // Test ListAccountWithdrawals + withdrawalsAccounts := app.MillionsKeeper.ListAccountWithdrawals(ctx, addr) + suite.Require().Equal(ctx.BlockTime(), withdrawalsAccounts[i].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), withdrawalsAccounts[i].UpdatedAtHeight) + suite.Require().Equal(millionstypes.WithdrawalState_Failure, withdrawals[i].State) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawals[i].ErrorState) + // Test ListAccountPoolWithdrawals + withdrawalsPoolAccounts := app.MillionsKeeper.ListAccountPoolWithdrawals(ctx, addr, withdrawal.PoolId) + suite.Require().Equal(ctx.BlockTime(), withdrawalsPoolAccounts[0].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), withdrawalsPoolAccounts[0].UpdatedAtHeight) + suite.Require().Equal(millionstypes.WithdrawalState_Failure, withdrawals[i].State) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawals[i].ErrorState) + // Test ListPoolWithdrawals + withdrawalsPool := app.MillionsKeeper.ListPoolWithdrawals(ctx, withdrawal.PoolId) + suite.Require().Equal(ctx.BlockTime(), withdrawalsPool[0].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), withdrawalsPool[0].UpdatedAtHeight) + suite.Require().Equal(millionstypes.WithdrawalState_Failure, withdrawals[i].State) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawals[i].ErrorState) + } + + // - Test the error management in case of false event + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + for _, withdrawal := range withdrawals { + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, millionstypes.WithdrawalState_IcaUndelegate, &time.Time{}, false) + } + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + for i, withdrawal := range withdrawals { + // Test GetPoolWithdrawal + poolWithdrawal, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(poolWithdrawal.Amount.Amount.Int64(), withdrawal.Amount.Amount.Int64()) + suite.Require().Equal(poolWithdrawal.PoolId, withdrawal.PoolId) + // Test ListAccountWithdrawals + withdrawalsAccounts := app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Equal(ctx.BlockTime(), withdrawalsAccounts[i].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), withdrawalsAccounts[i].UpdatedAtHeight) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawals[i].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[i].ErrorState) + // Test ListAccountPoolWithdrawals + withdrawalsPoolAccounts := app.MillionsKeeper.ListAccountPoolWithdrawals(ctx, suite.addrs[0], withdrawal.PoolId) + suite.Require().Equal(ctx.BlockTime(), withdrawalsPoolAccounts[0].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), withdrawalsPoolAccounts[0].UpdatedAtHeight) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawals[i].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[i].ErrorState) + // Test ListPoolWithdrawals + withdrawalsPool := app.MillionsKeeper.ListPoolWithdrawals(ctx, withdrawal.PoolId) + suite.Require().Equal(ctx.BlockTime(), withdrawalsPool[0].UpdatedAt) + suite.Require().Equal(ctx.BlockHeight(), withdrawalsPool[0].UpdatedAtHeight) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawals[i].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[i].ErrorState) + } +} + +// TestWithdrawal_UndelegateWithdrawal tests the flow from the undelegation till the transfer +func (suite *KeeperTestSuite) TestWithdrawal_UndelegateWithdrawal() { + // Set the app context + app := suite.app + ctx := suite.ctx + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + uatomAddresses := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), remotePoolDenom) + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: remoteBech32PrefixValAddr, + ChainId: remoteChainId, + Denom: remotePoolDenom, + NativeDenom: remotePoolDenom, + ConnectionId: remoteConnectionId, + TransferChannelId: remoteTransferChannelId, + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(remotePoolDenom, math.NewInt(1000)), + })) + + // List the pools + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 1) + + // Verify that the validators is enabled and the bondedamount + suite.Require().Equal(true, pools[0].Validators[cosmosPoolValidator].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[0].Validators[cosmosPoolValidator].BondedAmount) + + // Create a new deposit and simulate successful transfered deposit + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_IcaDelegate, + Amount: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + }) + + err := app.BankKeeper.SendCoins(ctx, uatomAddresses[0], sdk.MustAccAddressFromBech32(pools[0].LocalAddress), sdk.Coins{sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + // Simulate a delegation on native chain for remote pool + splits := []*millionstypes.SplitDelegation{{ValidatorAddress: cosmosPoolValidator, Amount: sdk.NewInt(int64(1_000_000))}} + err = app.MillionsKeeper.OnDelegateDepositOnNativeChainCompleted(ctx, deposit.PoolId, deposit.DepositId, splits, false) + suite.Require().NoError(err) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + // Add withdrawal to the state + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: uatomAddresses[0].String(), + ToAddress: uatomAddresses[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + }) + + withdrawals := app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + suite.Require().Len(withdrawals, 1) + + // Remove deposit to simulate flow + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + }) + + // There should be ne more deposits + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 0) + + // Test if pool is remote + suite.Require().Equal(false, pools[0].IsLocalZone(ctx)) + withdrawal, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + suite.Require().NotNil(deposit, "Not nil") + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawal.State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawal.ErrorState) + + // Simulate failed ackResponse AckResponseStatus_FAILURE + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, withdrawal.GetPoolId(), withdrawal.GetWithdrawalId(), splits, &time.Time{}, true) + suite.Require().NoError(err) + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.WithdrawalState_Failure, withdrawal.State) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawal.ErrorState) + + undbondingTime := ctx.BlockTime().Add(time.Second) + + // Update status to simulate a WithdrawalState_IcaUndelegate + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.DepositId, millionstypes.WithdrawalState_IcaUndelegate, &undbondingTime, false) + + // Simulate failed ackResponse AckResponseStatus_Success + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, withdrawal.GetPoolId(), withdrawal.GetWithdrawalId(), splits, &undbondingTime, false) + suite.Require().NoError(err) + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawal.State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawal.ErrorState) + suite.Require().WithinDuration(*withdrawal.UnbondingEndsAt, undbondingTime, time.Second) + + // Test local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + // List pools + pools = app.MillionsKeeper.ListPools(ctx) + + // - Test if the validator is enabled and bondedamount + suite.Require().Equal(true, pools[1].Validators[suite.valAddrs[0].String()].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[1].Validators[suite.valAddrs[0].String()].BondedAmount) + + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + // Simulate the transfer to native chain + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().NoError(err) + + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + // Add withdrawal + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUndelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(withdrawals, 1) + + // Remove deposit to respect the flow + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // There should be ne more deposits + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 0) + + // Test local pool + suite.Require().Equal(true, pools[1].IsLocalZone(ctx)) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUndelegate, withdrawal.State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawal.ErrorState) + + // Simulate successful undelegation flow + err = app.MillionsKeeper.UndelegateWithdrawalOnNativeChain(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + suite.Require().NoError(err) + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawal.State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawal.ErrorState) + // There is 21 days unbonding time + suite.Require().WithinDuration(*withdrawal.UnbondingEndsAt, undbondingTime, 21*24*time.Hour) +} + +// TestWithdrawal_TransferWithdrawal tests from the undelegation point till the transfer to Local is completed +func (suite *KeeperTestSuite) TestWithdrawal_TransferWithdrawal() { + // Set the app context + app := suite.app + ctx := suite.ctx + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + uatomAddresses := apptesting.AddTestAddrsWithDenom(app, ctx, 7, sdk.NewInt(1_000_0000_000), remotePoolDenom) + + // Remote pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Bech32PrefixValAddr: remoteBech32PrefixValAddr, + ChainId: remoteChainId, + Denom: remotePoolDenom, + NativeDenom: remotePoolDenom, + ConnectionId: remoteConnectionId, + TransferChannelId: remoteTransferChannelId, + Validators: map[string]*millionstypes.PoolValidator{ + cosmosPoolValidator: { + OperatorAddress: cosmosPoolValidator, + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + IcaDepositAddress: cosmosIcaDepositAddress, + IcaPrizepoolAddress: cosmosIcaPrizePoolAddress, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(remotePoolDenom, math.NewInt(1000)), + })) + + // List pools + pools := app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 1) + + // Verify that the validators is enabled and the bondedamount + suite.Require().Equal(true, pools[0].Validators[cosmosPoolValidator].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[0].Validators[cosmosPoolValidator].BondedAmount) + + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + }) + err := app.BankKeeper.SendCoins(ctx, uatomAddresses[0], sdk.MustAccAddressFromBech32(pools[0].LocalAddress), sdk.Coins{sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + unbondingTime := ctx.BlockTime().Add(-2 * time.Second) + + // Simulate that we reached the unbonding step already (done in previous test) + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: uatomAddresses[0].String(), + ToAddress: uatomAddresses[0].String(), + State: millionstypes.WithdrawalState_IcaUnbonding, + Amount: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + UnbondingEndsAt: &unbondingTime, + }) + + withdrawals := app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + suite.Require().Len(withdrawals, 1) + + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: uatomAddresses[0].String(), + WinnerAddress: uatomAddresses[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(remotePoolDenom, sdk.NewInt(1_000_000)), + }) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, uatomAddresses[0]) + suite.Require().Len(deposits, 0) + + withdrawal, err := app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + + // Update status to simulate transfer from to local chain + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, millionstypes.WithdrawalState_IbcTransfer, withdrawal.UnbondingEndsAt, false) + + // Simulate failed ackResponse AckResponseStatus_FAILURE + err = app.MillionsKeeper.OnTransferWithdrawalToLocalChainCompleted(ctx, withdrawal.GetPoolId(), withdrawal.GetWithdrawalId(), true) + suite.Require().NoError(err) + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.WithdrawalState_Failure, withdrawal.State) + suite.Require().Equal(millionstypes.WithdrawalState_IbcTransfer, withdrawal.ErrorState) + + // Update status to simulate transfer from to local chain + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, millionstypes.WithdrawalState_IbcTransfer, withdrawal.UnbondingEndsAt, false) + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId) + suite.Require().NoError(err) + + // Simulate failed ackResponse AckResponseStatus_Success + err = app.MillionsKeeper.OnTransferWithdrawalToLocalChainCompleted(ctx, withdrawal.GetPoolId(), withdrawal.GetWithdrawalId(), false) + suite.Require().NoError(err) + // There should be no more withdrawal if successfully processed + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, uatomAddresses[0]) + suite.Require().Len(withdrawals, 0) + + // Test local pool + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + pools = app.MillionsKeeper.ListPools(ctx) + suite.Require().Len(pools, 2) + + // - Test if the validator is enabled and bonded amount + suite.Require().Equal(true, pools[1].Validators[suite.valAddrs[0].String()].IsEnabled) + suite.Require().Equal(sdk.NewInt(1_000_000), pools[1].Validators[suite.valAddrs[0].String()].BondedAmount) + + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + // Add withdrawal + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + State: millionstypes.WithdrawalState_IcaUnbonding, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + UnbondingEndsAt: &unbondingTime, + }) + + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(withdrawals, 1) + + // Remove deposit to respect the flow + app.MillionsKeeper.RemoveDeposit(ctx, &millionstypes.Deposit{ + PoolId: deposit.PoolId, + DepositId: deposit.DepositId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + + // There should be no more deposits + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 0) + + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].DepositId) + suite.Require().NoError(err) + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, millionstypes.WithdrawalState_IbcTransfer, withdrawal.UnbondingEndsAt, false) + withdrawal, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, withdrawals[0].DepositId) + suite.Require().NoError(err) + + err = app.MillionsKeeper.TransferWithdrawalToLocalChain(ctx, withdrawal.PoolId, withdrawal.WithdrawalId) + suite.Require().NoError(err) + + // There should no more withdrawal if successfully processed + withdrawals = app.MillionsKeeper.ListAccountWithdrawals(ctx, suite.addrs[0]) + suite.Require().Len(withdrawals, 0) +} + +// TestWithdrawal_DequeueMaturedWithdrawal tests the dequeue process of matured withdrawals +func (suite *KeeperTestSuite) TestWithdrawal_DequeueMaturedWithdrawal() { + // Set the app context + app := suite.app + ctx := suite.ctx + + // Add 4 withdrawals + for i := 0; i < 4; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + depositID := app.MillionsKeeper.GetNextDepositIdAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + + unbondingTime := ctx.BlockTime().Add(2 * time.Second) + + // Status WithdrawalState_IcaUnbonding pushes directly into the queue + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: depositID, + State: millionstypes.WithdrawalState_IcaUnbonding, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(1_000_000))), + UnbondingEndsAt: &unbondingTime, + }) + } + + // 1 second before the queue should be empty + maturedQueue := app.MillionsKeeper.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime().Add(time.Second)) + suite.Require().Len(maturedQueue, 0) + + // 2 seconds after the queue should contain the withdrawals + maturedQueue = app.MillionsKeeper.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime().Add(2*time.Second)) + suite.Require().Len(maturedQueue, 4) +} + +// TestWithdrawal_BalanceWithdrawal test the depositor balance after a transfer back to local chain +func (suite *KeeperTestSuite) TestWithdrawal_BalanceWithdrawal() { + // Set the app context + app := suite.app + ctx := suite.ctx + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + var now = time.Now().UTC() + + // Initialize the local pool + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + }) + app.MillionsKeeper.AddPool(ctx, pool) + + // Initialize the balance + balanceBefore := app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(int64(1_000_000_000_0), balanceBefore.Amount.Int64()) + + // Create deposit + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: poolID, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // Send coin + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + // Create deposit + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: poolID, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // Send coin + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + // Deposits will be used to create withdrawals + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + + for i, deposit := range deposits { + // We set one unbondingEndsAt in the past and one in the future + var unbondingEndsAt time.Time + if i == 0 { + unbondingEndsAt = ctx.BlockTime().Add(-10 * time.Second) + } else { + unbondingEndsAt = ctx.BlockTime().Add(10 * time.Second) + } + // Add the withdrawal with the modified unbonding time + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: deposit.DepositId, + State: millionstypes.WithdrawalState_IcaUndelegate, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(1_000_000))), + UnbondingEndsAt: &unbondingEndsAt, + }) + } + + // Test that there is 2 withdrawals + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 2) + + // Test that the balance of the depositor has 2 deposits less + balance := app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + + // Trigger undelegation flow + for _, w := range withdrawals { + // Split undelegations + splits := []*millionstypes.SplitDelegation{{ValidatorAddress: suite.valAddrs[0].String(), Amount: sdk.NewInt(int64(1_000_000))}} + // Trigger the undelegation + err := app.MillionsKeeper.UndelegateWithdrawalOnNativeChain(ctx, w.PoolId, w.WithdrawalId) + suite.Require().Error(err) + // Trigger the successful undelegation to force the unbonding + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, w.PoolId, w.WithdrawalId, splits, w.UnbondingEndsAt, false) + suite.Require().NoError(err) + } + + // Test that the balance should remain unchanged + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + + // Test that there is only one withdrawal to dequeue as only one deposit has unbondingEndsAt = ctx.BlockTime().Add(-10 * time.Second) + maturedWithdrawals := app.MillionsKeeper.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime()) + suite.Require().Len(maturedWithdrawals, 1) + + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + + // Dequeue matured withdrawals and trigger the transfer to the local chain + for i, mw := range maturedWithdrawals { + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, mw.GetPoolId(), mw.GetWithdrawalId(), millionstypes.WithdrawalState_IbcTransfer, withdrawals[i].UnbondingEndsAt, false) + err = app.MillionsKeeper.TransferWithdrawalToLocalChain(ctx, mw.GetPoolId(), mw.GetWithdrawalId()) + // Test that there should be no error + suite.Require().NoError(err) + } + + // Test that there should be no matured withdrawal left + maturedWithdrawals = app.MillionsKeeper.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime()) + suite.Require().Len(maturedWithdrawals, 0) + + // Test that the balance should compensate 1 deposit transfered back + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balance.Amount.Int64()) + + // Move ctx.BlockTime forward to simulate the second Dequeue by testing directly the EndBlock method + ctx = ctx.WithBlockTime(now.Add(10 * time.Second)) + app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + + // Test that the balance should compensate 1 more deposit transfered back + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64(), balance.Amount.Int64()) +} + +// TestWithdrawal_FullWithdrawalProcess complete the full from the undelegation till the transfer to the local chain for a local pool +func (suite *KeeperTestSuite) TestWithdrawal_FullWithdrawalProcess() { + // Set the app context + app := suite.app + ctx := suite.ctx + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + var now = time.Now().UTC() + + // Initialize the local pool + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + }) + app.MillionsKeeper.AddPool(ctx, pool) + + // Initialize the balance + balanceBefore := app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(int64(1_000_000_000_0), balanceBefore.Amount.Int64()) + + // Create deposit + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: poolID, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // Send coin + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().Error(err) + + // Create deposit + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: poolID, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Success, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // Send coin + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + deposit, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId) + suite.Require().Error(err) + + for i, deposit := range deposits { + // We set one unbondingEndsAt in the past and one in the future + var unbondingEndsAt time.Time + if i == 0 { + unbondingEndsAt = ctx.BlockTime().Add(-10 * time.Second) + } else { + unbondingEndsAt = ctx.BlockTime().Add(10 * time.Second) + } + // Add the withdrawal with the modified unbonding time + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: poolID, + DepositId: deposit.DepositId, + State: millionstypes.WithdrawalState_IcaUndelegate, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(1_000_000))), + UnbondingEndsAt: &unbondingEndsAt, + }) + } + + // Test that there is 2 withdrawals + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 2) + + // Remove deposits to respect the flow + for i := 0; i < len(withdrawals); i++ { + app.MillionsKeeper.RemoveDeposit(ctx, &deposit) + } + + // Test that the balance of the depositor has 2 deposits less + balance := app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + + // Trigger undelegation flow + for _, w := range withdrawals { + // Split undelegations + splits := []*millionstypes.SplitDelegation{{ValidatorAddress: suite.valAddrs[0].String(), Amount: sdk.NewInt(int64(1_000_000))}} + // Trigger the undelegation + err := app.MillionsKeeper.UndelegateWithdrawalOnNativeChain(ctx, w.PoolId, w.WithdrawalId) + suite.Require().Error(err) + // Trigger the successful undelegation to force the unbonding + err = app.MillionsKeeper.OnUndelegateWithdrawalOnNativeChainCompleted(ctx, w.PoolId, w.WithdrawalId, splits, w.UnbondingEndsAt, false) + suite.Require().NoError(err) + } + + // Test that the balance should remain unchanged + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-2_000_000, balance.Amount.Int64()) + + // Test that for both withdrawals withdrawal.State should be WithdrawalState_IcaUnbonding + // Test that for both withdrawals withdrawal.ErrorState should be WithdrawalState_Unspecified + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawals[0].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[0].ErrorState) + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawals[1].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[1].ErrorState) + + // Test that there is only one withdrawal to dequeue as only one deposit has unbondingEndsAt = ctx.BlockTime().Add(-10 * time.Second) + maturedWithdrawals := app.MillionsKeeper.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime()) + suite.Require().Len(maturedWithdrawals, 1) + // Test that the matured withdrawal corresponds to the first withdrawal + suite.Require().Equal(withdrawals[0].WithdrawalId, maturedWithdrawals[0].WithdrawalId) + + // Dequeue matured withdrawals and trigger the transfer to the local chain + for i, mw := range maturedWithdrawals { + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, mw.GetPoolId(), mw.GetWithdrawalId(), millionstypes.WithdrawalState_IbcTransfer, withdrawals[i].UnbondingEndsAt, false) + err = app.MillionsKeeper.TransferWithdrawalToLocalChain(ctx, mw.GetPoolId(), mw.GetWithdrawalId()) + suite.Require().NoError(err) + } + + // Test that there should be no matured withdrawal left + maturedWithdrawals = app.MillionsKeeper.DequeueMaturedWithdrawalQueue(ctx, ctx.BlockTime()) + suite.Require().Len(maturedWithdrawals, 0) + + // Test that the balance should compensate 1 deposit transfered back + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balance.Amount.Int64()) + + // Test that there is 1 withdrawal upon successful completion + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 1) + // Test that the second withdrawal has withdrawal.State WithdrawalState_IcaUnbonding + // Test that the second withdrawal has withdrawal.ErrorState WithdrawalState_Unspecified + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawals[0].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[0].ErrorState) + + // Move ctx.BlockTime forward to simulate the second Dequeue by testing directly the EndBlock method + ctx = ctx.WithBlockTime(now.Add(10 * time.Second)) + app.MillionsKeeper.BlockWithdrawalUpdates(ctx) + + // Test that the balance should compensate 1 more deposit transfered back + balance = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64(), balance.Amount.Int64()) + + // Test that there is no more withdrawals upon successful completion + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 0) +} diff --git a/x/millions/keeper/msg_server.go b/x/millions/keeper/msg_server.go new file mode 100644 index 00000000..7738e671 --- /dev/null +++ b/x/millions/keeper/msg_server.go @@ -0,0 +1,15 @@ +package keeper + +import "github.com/lum-network/chain/x/millions/types" + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/millions/keeper/msg_server_deposit.go b/x/millions/keeper/msg_server_deposit.go new file mode 100644 index 00000000..38429ab3 --- /dev/null +++ b/x/millions/keeper/msg_server_deposit.go @@ -0,0 +1,185 @@ +package keeper + +import ( + "context" + "strconv" + "strings" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// Deposit creates a deposit from the transaction message +func (k msgServer) Deposit(goCtx context.Context, msg *types.MsgDeposit) (*types.MsgDepositResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Get the pool to validate id and denom + pool, err := k.GetPool(ctx, msg.GetPoolId()) + if err != nil { + return nil, types.ErrPoolNotFound + } + if pool.State != types.PoolState_Ready { + return nil, types.ErrPoolNotReady + } + + depositorAddr, err := sdk.AccAddressFromBech32(msg.GetDepositorAddress()) + if err != nil { + return nil, types.ErrInvalidDepositorAddress + } + + if msg.Amount.Denom != pool.Denom { + return nil, types.ErrInvalidDepositDenom + } + + // Make sure the deposit is sufficient + if msg.GetAmount().Amount.LT(pool.MinDepositAmount) { + return nil, types.ErrInsufficientDepositAmount + } + + winnerAddress := depositorAddr + if strings.TrimSpace(msg.GetWinnerAddress()) != "" { + winnerAddress, err = sdk.AccAddressFromBech32(msg.GetWinnerAddress()) + if err != nil { + return nil, types.ErrInvalidWinnerAddress + } + } + + if !depositorAddr.Equals(winnerAddress) && msg.GetIsSponsor() { + return nil, types.ErrInvalidSponsorWinnerCombo + } + + // New deposit instance + deposit := types.Deposit{ + PoolId: pool.PoolId, + State: types.DepositState_IbcTransfer, + DepositorAddress: depositorAddr.String(), + Amount: msg.Amount, + WinnerAddress: winnerAddress.String(), + IsSponsor: msg.GetIsSponsor(), + CreatedAtHeight: ctx.BlockHeight(), + UpdatedAtHeight: ctx.BlockHeight(), + CreatedAt: ctx.BlockTime(), + UpdatedAt: ctx.BlockTime(), + } + + // Move funds + if pool.IsLocalZone(ctx) { + // Directly send funds to the local deposit address in case of local pool + if err := k.BankKeeper.SendCoins( + ctx, + depositorAddr, + sdk.MustAccAddressFromBech32(pool.GetIcaDepositAddress()), + sdk.NewCoins(msg.Amount), + ); err != nil { + return nil, err + } + } else { + if err := k.BankKeeper.SendCoins( + ctx, + depositorAddr, + sdk.MustAccAddressFromBech32(pool.GetLocalAddress()), + sdk.NewCoins(msg.Amount), + ); err != nil { + return nil, err + } + } + + // Store deposit + k.AddDeposit(ctx, &deposit) + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeDeposit, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(deposit.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositID, strconv.FormatUint(deposit.DepositId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositor, deposit.DepositorAddress), + sdk.NewAttribute(types.AttributeKeyWinner, deposit.WinnerAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, deposit.Amount.String()), + ), + }) + + if err := k.TransferDepositToNativeChain(ctx, deposit.GetPoolId(), deposit.GetDepositId()); err != nil { + return nil, err + } + return &types.MsgDepositResponse{DepositId: deposit.DepositId}, nil +} + +func (k msgServer) DepositRetry(goCtx context.Context, msg *types.MsgDepositRetry) (*types.MsgDepositRetryResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Ensure msg received is valid + if err := msg.ValidateDepositRetryBasic(); err != nil { + return nil, err + } + + deposit, err := k.GetPoolDeposit(ctx, msg.PoolId, msg.DepositId) + if err != nil { + return nil, err + } + + depositorAddr, err := sdk.AccAddressFromBech32(msg.GetDepositorAddress()) + if err != nil { + return nil, types.ErrInvalidDepositorAddress + } + + // Verify that the depositorAddr msg is the same as the entity depositor + if depositorAddr.String() != deposit.DepositorAddress { + return nil, types.ErrInvalidDepositorAddress + } + + // State should be set to failure in order to retry something + if deposit.State != types.DepositState_Failure { + return nil, errorsmod.Wrapf( + types.ErrInvalidDepositState, + "state is %s instead of %s", + deposit.State.String(), types.DepositState_Failure.String(), + ) + } + + newState := types.DepositState_Unspecified + if deposit.ErrorState == types.DepositState_IbcTransfer { + newState = types.DepositState_IbcTransfer + k.UpdateDepositStatus(ctx, deposit.PoolId, deposit.DepositId, newState, false) + if err := k.TransferDepositToNativeChain(ctx, deposit.PoolId, deposit.DepositId); err != nil { + return nil, err + } + } else if deposit.ErrorState == types.DepositState_IcaDelegate { + newState = types.DepositState_IcaDelegate + k.UpdateDepositStatus(ctx, deposit.PoolId, deposit.DepositId, newState, false) + if err := k.DelegateDepositOnNativeChain(ctx, deposit.PoolId, deposit.DepositId); err != nil { + return nil, err + } + } else { + return nil, errorsmod.Wrapf( + types.ErrInvalidDepositState, + "error_state is %s instead of %s or %s", + deposit.ErrorState.String(), types.DepositState_IbcTransfer.String(), types.DepositState_IcaDelegate.String(), + ) + } + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeDepositRetry, + sdk.NewAttribute(types.AttributeKeyState, newState.String()), + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(deposit.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositID, strconv.FormatUint(deposit.DepositId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositor, deposit.DepositorAddress), + sdk.NewAttribute(types.AttributeKeyWinner, deposit.WinnerAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, deposit.Amount.String()), + ), + }) + + return &types.MsgDepositRetryResponse{}, nil +} diff --git a/x/millions/keeper/msg_server_draw.go b/x/millions/keeper/msg_server_draw.go new file mode 100644 index 00000000..d3ad8ac9 --- /dev/null +++ b/x/millions/keeper/msg_server_draw.go @@ -0,0 +1,88 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// DrawRetry allows to retry a failed draw +func (k msgServer) DrawRetry(goCtx context.Context, msg *types.MsgDrawRetry) (*types.MsgDrawRetryResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Ensure msg received is valid + if err := msg.ValidateDrawRetryBasic(); err != nil { + return nil, err + } + + if !k.HasPool(ctx, msg.PoolId) { + return nil, types.ErrPoolNotFound + } + + // Acquire Draw + draw, err := k.GetPoolDraw(ctx, msg.PoolId, msg.DrawId) + if err != nil { + return nil, err + } + + // State should be set to failure in order to retry something + if draw.State != types.DrawState_Failure { + return nil, errorsmod.Wrapf( + types.ErrInvalidDrawState, + "state is %s instead of %s", + draw.State.String(), types.DrawState_Failure.String(), + ) + } + + // DrawState_IcaWithdrawRewards refers to the failed ica callback if OnClaimRewardsOnNativeChainCompleted fails + if draw.ErrorState == types.DrawState_IcaWithdrawRewards { + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + draw.State = types.DrawState_IcaWithdrawRewards + draw.ErrorState = types.DrawState_Unspecified + k.SetPoolDraw(ctx, draw) + if _, err := k.ClaimRewardsOnNativeChain(ctx, draw.PoolId, draw.DrawId); err != nil { + return nil, err + } + // DrawState_IcqRewards refers to the failed icq callback + } else if draw.ErrorState == types.DrawState_IcqBalance { + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + draw.State = types.DrawState_IcqBalance + draw.ErrorState = types.DrawState_Unspecified + k.SetPoolDraw(ctx, draw) + if _, err := k.QueryBalance(ctx, draw.GetPoolId(), draw.GetDrawId()); err != nil { + return nil, err + } + // DrawState_IbcTransfer refers to the failed ibc call if OnTransferRewardsToLocalChainCompleted fails + } else if draw.ErrorState == types.DrawState_IbcTransfer { + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + draw.State = types.DrawState_IbcTransfer + draw.ErrorState = types.DrawState_Unspecified + k.SetPoolDraw(ctx, draw) + if _, err := k.TransferRewardsToLocalChain(ctx, draw.PoolId, draw.DrawId); err != nil { + return nil, err + } + } else if draw.ErrorState == types.DrawState_Drawing { + draw.UpdatedAtHeight = ctx.BlockHeight() + draw.UpdatedAt = ctx.BlockTime() + draw.State = types.DrawState_Drawing + draw.ErrorState = types.DrawState_Unspecified + k.SetPoolDraw(ctx, draw) + if _, err := k.ExecuteDraw(ctx, draw.PoolId, draw.DrawId); err != nil { + return nil, err + } + } else { + return nil, errorsmod.Wrapf( + types.ErrInvalidDrawState, + "error_state is %s instead of %s or %s", + draw.ErrorState.String(), types.DrawState_IcaWithdrawRewards.String(), types.DrawState_IbcTransfer.String(), + ) + } + + return &types.MsgDrawRetryResponse{}, nil +} diff --git a/x/millions/keeper/msg_server_pool.go b/x/millions/keeper/msg_server_pool.go new file mode 100644 index 00000000..74fa9189 --- /dev/null +++ b/x/millions/keeper/msg_server_pool.go @@ -0,0 +1,55 @@ +package keeper + +import ( + "context" + errorsmod "cosmossdk.io/errors" + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lum-network/chain/x/millions/types" +) + +func (k msgServer) RestoreInterchainAccounts(goCtx context.Context, msg *types.MsgRestoreInterchainAccounts) (*types.MsgRestoreInterchainAccountsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Grab our pool instance, otherwise just return error + pool, err := k.GetPool(ctx, msg.GetPoolId()) + if err != nil { + return nil, types.ErrPoolNotFound + } + + // We always want our pool to be ready + if pool.State == types.PoolState_Created { + return nil, types.ErrPoolNotReady + } + + // Grab the app version to use + appVersion, err := k.getPoolAppVersion(ctx, pool) + if err != nil { + return nil, errorsmod.Wrapf(types.ErrFailedToRestorePool, err.Error()) + } + + // We don't want to run this against a local pool + if pool.IsLocalZone(ctx) { + return nil, errorsmod.Wrapf(types.ErrFailedToRestorePool, "Pool is local") + } + + // Regenerate our deposit port only if required (open active channel not found) + _, found := k.ICAControllerKeeper.GetOpenActiveChannel(ctx, pool.GetConnectionId(), pool.GetIcaDepositPortId()) + if !found { + icaDepositPortName := string(types.NewPoolName(pool.GetPoolId(), types.ICATypeDeposit)) + if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, pool.GetConnectionId(), icaDepositPortName, appVersion); err != nil { + return nil, errorsmod.Wrapf(types.ErrFailedToRestorePool, fmt.Sprintf("Unable to trigger deposit account registration, err: %s", err.Error())) + } + } + + // Regenerate our prizepool port only if required (open active channel not found) + _, found = k.ICAControllerKeeper.GetOpenActiveChannel(ctx, pool.GetConnectionId(), pool.GetIcaPrizepoolPortId()) + if !found { + icaPrizePoolPortName := string(types.NewPoolName(pool.GetPoolId(), types.ICATypePrizePool)) + if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, pool.GetConnectionId(), icaPrizePoolPortName, appVersion); err != nil { + return nil, errorsmod.Wrapf(types.ErrFailedToRestorePool, fmt.Sprintf("Unable to trigger prizepool account registration, err: %s", err.Error())) + } + } + + return &types.MsgRestoreInterchainAccountsResponse{}, nil +} diff --git a/x/millions/keeper/msg_server_prize.go b/x/millions/keeper/msg_server_prize.go new file mode 100644 index 00000000..3d7ba3b6 --- /dev/null +++ b/x/millions/keeper/msg_server_prize.go @@ -0,0 +1,73 @@ +package keeper + +import ( + "context" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// ClaimPrize claim a prize from the transaction message +func (k msgServer) ClaimPrize(goCtx context.Context, msg *types.MsgClaimPrize) (*types.MsgClaimPrizeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Verify address + winnerAddr, err := sdk.AccAddressFromBech32(msg.GetWinnerAddress()) + if err != nil { + return nil, types.ErrInvalidWinnerAddress + } + + prize, err := k.GetPoolDrawPrize(ctx, msg.PoolId, msg.DrawId, msg.PrizeId) + if err != nil { + return nil, types.ErrPrizeNotFound + } + + // msg.WinnerAddress should always match the prize.WinnerAddress + if winnerAddr.String() != prize.WinnerAddress { + return nil, types.ErrInvalidWinnerAddress + } + + if prize.State != types.PrizeState_Pending { + return nil, types.ErrInvalidPrizeState + } + + // Get pool + pool, err := k.GetPool(ctx, msg.PoolId) + if err != nil { + return nil, types.ErrPoolNotFound + } + + // Move funds + if err := k.BankKeeper.SendCoins( + ctx, + sdk.MustAccAddressFromBech32(pool.GetLocalAddress()), + winnerAddr, + sdk.NewCoins(prize.Amount), + ); err != nil { + return nil, err + } + + if err := k.RemovePrize(ctx, prize); err != nil { + return nil, err + } + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeClaimPrize, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(prize.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyDrawID, strconv.FormatUint(prize.DrawId, 10)), + sdk.NewAttribute(types.AttributeKeyPrizeID, strconv.FormatUint(prize.PrizeId, 10)), + sdk.NewAttribute(types.AttributeKeyWinner, prize.WinnerAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, prize.Amount.String()), + ), + }) + + return &types.MsgClaimPrizeResponse{}, nil +} diff --git a/x/millions/keeper/msg_server_test.go b/x/millions/keeper/msg_server_test.go new file mode 100644 index 00000000..1801996a --- /dev/null +++ b/x/millions/keeper/msg_server_test.go @@ -0,0 +1,928 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + millionskeeper "github.com/lum-network/chain/x/millions/keeper" + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +// TestMsgServer_DrawRetry runs draw retry related tests +func (suite *KeeperTestSuite) TestMsgServer_DrawRetry() { + // Set the app context + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + // Add 5 pools + for i := 0; i < 5; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + } + + // Retrieve the pool from the state + pools := app.MillionsKeeper.ListPools(ctx) + + // Create a new draw + draw1 := millionstypes.Draw{ + PoolId: pools[0].PoolId, + DrawId: uint64(10), + State: millionstypes.DrawState_Failure, + ErrorState: millionstypes.DrawState_IcaWithdrawRewards, + PrizePoolRemainsAmount: sdk.NewInt(1_000_000), + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + app.MillionsKeeper.SetPoolDraw(ctx, draw1) + + // Test GetPoolDraw + draw, err := app.MillionsKeeper.GetPoolDraw(ctx, draw1.PoolId, draw1.DrawId) + suite.Require().NoError(err) + // - Test GetPoolDraw with wrong poolID + _, err = app.MillionsKeeper.GetPoolDraw(ctx, uint64(0), draw.DrawId) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + // - Test GetPoolDraw with wrong drawID + _, err = app.MillionsKeeper.GetPoolDraw(ctx, draw.PoolId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrPoolDrawNotFound) + + // Test ValidateDrawRetryBasic + // - Test unknown poolID + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: uint64(0), + DrawId: draw.DrawId, + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + // - Test unknown drawID + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: draw.PoolId, + DrawId: uint64(0), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + + // - Test unknown drawID + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: uint64(10), + DrawId: draw.DrawId, + }) + suite.Require().ErrorIs(err, millionstypes.ErrPoolNotFound) + + draw, err = app.MillionsKeeper.GetPoolDraw(ctx, draw.PoolId, draw.DrawId) + suite.Require().NoError(err) + suite.Require().Equal(millionstypes.DrawState_Failure, draw.State) + suite.Require().Equal(millionstypes.DrawState_IcaWithdrawRewards, draw.ErrorState) + + pools = app.MillionsKeeper.ListPools(ctx) + + // Create a new draw to test DrawState_IcaWithdrawRewards ErrorState + draw2 := millionstypes.Draw{ + PoolId: pools[1].PoolId, + DrawId: uint64(20), + State: millionstypes.DrawState_Failure, + ErrorState: millionstypes.DrawState_IcaWithdrawRewards, + PrizePoolRemainsAmount: sdk.NewInt(1_000_000), + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + app.MillionsKeeper.SetPoolDraw(ctx, draw2) + + draw2, err = app.MillionsKeeper.GetPoolDraw(ctx, draw2.PoolId, draw2.DrawId) + suite.Require().NoError(err) + + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: draw2.PoolId, + DrawId: draw2.DrawId, + }) + suite.Require().NoError(err) + + draw2, err = app.MillionsKeeper.GetPoolDraw(ctx, draw2.PoolId, draw2.DrawId) + suite.Require().NoError(err) + + // Test that the msg retry is success + suite.Require().Equal(millionstypes.DrawState_Success, draw2.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw2.ErrorState) + suite.Require().Equal(ctx.BlockHeight(), draw2.UpdatedAtHeight) + suite.Require().Equal(ctx.BlockTime(), draw2.UpdatedAt) + + pools = app.MillionsKeeper.ListPools(ctx) + + // Create a new draw to test DrawState_IbcTransfer ErrorState + draw3 := millionstypes.Draw{ + PoolId: pools[2].PoolId, + DrawId: uint64(30), + State: millionstypes.DrawState_Failure, + ErrorState: millionstypes.DrawState_IbcTransfer, + PrizePoolRemainsAmount: sdk.NewInt(1_000_000), + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + app.MillionsKeeper.SetPoolDraw(ctx, draw3) + + draw3, err = app.MillionsKeeper.GetPoolDraw(ctx, draw3.PoolId, draw3.DrawId) + suite.Require().NoError(err) + + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: draw3.PoolId, + DrawId: draw3.DrawId, + }) + suite.Require().NoError(err) + + draw3, err = app.MillionsKeeper.GetPoolDraw(ctx, draw3.PoolId, draw3.DrawId) + suite.Require().NoError(err) + + // Test that the msg retry is success + suite.Require().Equal(millionstypes.DrawState_Success, draw3.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw3.ErrorState) + suite.Require().Equal(ctx.BlockHeight(), draw3.UpdatedAtHeight) + suite.Require().Equal(ctx.BlockTime(), draw3.UpdatedAt) + + // Create a new draw to test DrawState_Drawing ErrorState + draw4 := millionstypes.Draw{ + PoolId: pools[3].PoolId, + DrawId: uint64(40), + State: millionstypes.DrawState_Failure, + ErrorState: millionstypes.DrawState_Drawing, + PrizePoolRemainsAmount: sdk.NewInt(1_000_000), + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + app.MillionsKeeper.SetPoolDraw(ctx, draw4) + + draw4, err = app.MillionsKeeper.GetPoolDraw(ctx, draw4.PoolId, draw4.DrawId) + suite.Require().NoError(err) + + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: draw4.PoolId, + DrawId: draw4.DrawId, + }) + suite.Require().NoError(err) + + draw4, err = app.MillionsKeeper.GetPoolDraw(ctx, draw4.PoolId, draw4.DrawId) + suite.Require().NoError(err) + + suite.Require().Equal(millionstypes.DrawState_Success, draw4.State) + suite.Require().Equal(millionstypes.DrawState_Unspecified, draw4.ErrorState) + suite.Require().Equal(ctx.BlockHeight(), draw4.UpdatedAtHeight) + suite.Require().Equal(ctx.BlockTime(), draw4.UpdatedAt) + + // Create a new draw to test DrawState_Unspecified ErrorState + draw5 := millionstypes.Draw{ + PoolId: pools[4].PoolId, + DrawId: uint64(50), + State: millionstypes.DrawState_Failure, + ErrorState: millionstypes.DrawState_Unspecified, + PrizePoolRemainsAmount: sdk.NewInt(1_000_000), + PrizePool: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + } + app.MillionsKeeper.SetPoolDraw(ctx, draw5) + + draw5, err = app.MillionsKeeper.GetPoolDraw(ctx, draw5.PoolId, draw5.DrawId) + suite.Require().NoError(err) + + _, err = msgServer.DrawRetry(goCtx, &millionstypes.MsgDrawRetry{ + PoolId: draw5.PoolId, + DrawId: draw5.DrawId, + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDrawState) +} + +// TestMsgServer_Deposit runs deposit related tests +func (suite *KeeperTestSuite) TestMsgServer_Deposit() { + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + // Create pool + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + + pools := app.MillionsKeeper.ListPools(ctx) + + // Invalid pool ID + _, err := msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: uint64(0), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrPoolNotFound) + + // Invalid depositor address + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: poolID, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(1_000_000))), + DepositorAddress: "", + }) + suite.Require().Error(err) + suite.Require().Equal(err, millionstypes.ErrInvalidDepositorAddress) + + // Invalid deposit denom + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: poolID, + Amount: sdk.NewCoin("ufaketoken", sdk.NewInt(1_000_000)), + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDepositDenom) + + // Invalid amount + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: poolID, + Amount: sdk.NewCoin(localPoolDenom, pools[0].MinDepositAmount.Sub(sdk.NewInt(1))), + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrInsufficientDepositAmount) + + // Invalid winner address + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: poolID, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(1_000_000))), + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: "no-address", + }) + suite.Require().Error(err) + suite.Require().Equal(err, millionstypes.ErrInvalidWinnerAddress) + + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: poolID, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(123456))), + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[1].String(), + IsSponsor: true, + }) + suite.Require().Error(err) + suite.Require().Equal(err, millionstypes.ErrInvalidSponsorWinnerCombo) + + // Register real pool and apply real deposits + poolID, err = app.MillionsKeeper.RegisterPool(ctx, + "ulum", + "ulum", + testChainID, + "", + "", + []string{suite.valAddrs[0].String()}, + "lum", + "lumvaloper", + app.MillionsKeeper.GetParams(ctx).MinDepositAmount, + millionstypes.DrawSchedule{DrawDelta: 24 * time.Hour, InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour)}, + millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 100, DrawProbability: sdk.NewDec(1)}}}, + ) + suite.Require().NoError(err) + _, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + // Create pool and deposits + // Operate basic checks to verify if deposit is created + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: app.MillionsKeeper.GetNextPoolID(ctx), + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + pools = app.MillionsKeeper.ListPools(ctx) + + pool, err := app.MillionsKeeper.GetPool(ctx, pools[1].PoolId) + suite.Require().NoError(err) + + balanceBefore := app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: pool.GetPoolId(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(int64(1_000_000))), + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + balanceNow := app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-1_000_000, balanceNow.Amount.Int64()) + + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: pool.GetPoolId(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(int64(2_000_000))), + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[1].String(), + }) + suite.Require().NoError(err) + balanceNow = app.BankKeeper.GetBalance(ctx, suite.addrs[0], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-3_000_000, balanceNow.Amount.Int64()) + + balanceBefore = app.BankKeeper.GetBalance(ctx, suite.addrs[2], localPoolDenom) + _, err = msgServer.Deposit(goCtx, &millionstypes.MsgDeposit{ + PoolId: pool.GetPoolId(), + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(int64(5_000_000))), + DepositorAddress: suite.addrs[2].String(), + IsSponsor: true, + }) + suite.Require().NoError(err) + balanceNow = app.BankKeeper.GetBalance(ctx, suite.addrs[2], localPoolDenom) + suite.Require().Equal(balanceBefore.Amount.Int64()-5_000_000, balanceNow.Amount.Int64()) + + // Compare pool tvl and depositors count state + suite.Require().Equal(sdk.NewInt(0), pool.TvlAmount) + suite.Require().Equal(uint64(0), pool.DepositorsCount) + pool, err = app.MillionsKeeper.GetPool(ctx, pool.GetPoolId()) + suite.Require().NoError(err) + suite.Require().Equal(sdk.NewInt(8_000_000), pool.TvlAmount) + suite.Require().Equal(uint64(2), pool.DepositorsCount) + suite.Require().Equal(sdk.NewInt(int64(5_000_000)), pool.SponsorshipAmount) +} + +// TestMsgServer_DepositRetry tests the retry of a failed deposit +func (suite *KeeperTestSuite) TestMsgServer_DepositRetry() { + // Set the app context + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + // Set the denom + denom := app.StakingKeeper.BondDenom(ctx) + // Initialize the pool + poolID, err := app.MillionsKeeper.RegisterPool(ctx, + denom, + denom, + testChainID, + "", + "", + []string{suite.valAddrs[0].String()}, + "lum", + "lumvaloper", + app.MillionsKeeper.GetParams(ctx).MinDepositAmount, + millionstypes.DrawSchedule{DrawDelta: 24 * time.Hour, InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour)}, + millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 100, DrawProbability: sdk.NewDec(1)}}}, + ) + suite.Require().NoError(err) + _, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + // Add 3 pools + for i := 0; i < 3; i++ { + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + } + + // Retrieve the pool from the state + pools := app.MillionsKeeper.ListPools(ctx) + + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[0].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Failure, + ErrorState: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + // - Test GetPoolDraw with wrong poolID + _, err = app.MillionsKeeper.GetPoolDeposit(ctx, uint64(0), deposits[0].DepositId) + suite.Require().ErrorIs(err, millionstypes.ErrDepositNotFound) + // - Test GetPoolDraw with wrong drawID + _, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrDepositNotFound) + + // Test validate Basics + // - Test unknown poolID + _, err = msgServer.DepositRetry(goCtx, &millionstypes.MsgDepositRetry{ + PoolId: uint64(0), + DepositId: deposits[0].DepositId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + // - Test unknown depositID + _, err = msgServer.DepositRetry(goCtx, &millionstypes.MsgDepositRetry{ + PoolId: deposits[0].PoolId, + DepositId: uint64(0), + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + + // Should throw error if depositor Addr msg is different than entity msg + _, err = msgServer.DepositRetry(goCtx, &millionstypes.MsgDepositRetry{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + DepositorAddress: "different-address", + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDepositorAddress) + + // Test DepositState_IbcTransfer ErrorState + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + _, err = app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + + _, err = msgServer.DepositRetry(goCtx, &millionstypes.MsgDepositRetry{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Equal(millionstypes.DepositState_Success, deposits[0].State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposits[0].ErrorState) + + // Test DepositState_IcaDelegate ErrorState + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[1].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Failure, + ErrorState: millionstypes.DepositState_IcaDelegate, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[1].IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + _, err = msgServer.DepositRetry(goCtx, &millionstypes.MsgDepositRetry{ + PoolId: deposits[1].PoolId, + DepositId: deposits[1].DepositId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Equal(millionstypes.DepositState_Success, deposits[1].State) + suite.Require().Equal(millionstypes.DepositState_Unspecified, deposits[1].ErrorState) + + // Test DepositState_Unspecified ErrorState + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pools[2].PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Failure, + ErrorState: millionstypes.DepositState_Unspecified, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], suite.moduleAddrs[0], sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + + deposits = app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + + _, err = msgServer.DepositRetry(goCtx, &millionstypes.MsgDepositRetry{ + PoolId: deposits[2].PoolId, + DepositId: deposits[2].DepositId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDepositState) +} + +// TestMsgServer_WithdrawDeposit runs withdrawal deposit related tests +func (suite *KeeperTestSuite) TestMsgServer_WithdrawDeposit() { + // Set the app context + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + // Initialize the pool + poolID, err := app.MillionsKeeper.RegisterPool(ctx, + "ulum", + "ulum", + testChainID, + "", + "", + []string{suite.valAddrs[0].String()}, + "lum", + "lumvaloper", + app.MillionsKeeper.GetParams(ctx).MinDepositAmount, + millionstypes.DrawSchedule{DrawDelta: 24 * time.Hour, InitialDrawAt: ctx.BlockTime().Add(24 * time.Hour)}, + millionstypes.PrizeStrategy{PrizeBatches: []millionstypes.PrizeBatch{{PoolPercent: 100, Quantity: 100, DrawProbability: sdk.NewDec(1)}}}, + ) + suite.Require().NoError(err) + _, err = app.MillionsKeeper.GetPool(ctx, poolID) + suite.Require().NoError(err) + poolID = app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + drawDelta1 := 1 * time.Hour + app.MillionsKeeper.AddPool(ctx, newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + })) + pools := app.MillionsKeeper.ListPools(ctx) + pool, err := app.MillionsKeeper.GetPool(ctx, pools[0].PoolId) + suite.Require().NoError(err) + + // Create 2 successful deposits + for i := 0; i < 2; i++ { + // Create second deposit + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pools[0].IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + // Trigger the Transfer deposit to native chain + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposits[i].PoolId, deposits[i].DepositId) + suite.Require().NoError(err) + } + // Create deposit with failure state + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_Failure, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + // List deposits + deposits := app.MillionsKeeper.ListAccountDeposits(ctx, suite.addrs[0]) + suite.Require().Len(deposits, 3) + + // Create invalid Withdraw request + // - Wrong depositorAddress + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + DepositorAddress: "", + ToAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDepositorAddress) + + // - Wrong to_address + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: "", + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDestinationAddress) + + // - Wrong deposit_id + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: pool.PoolId, + DepositId: uint64(0), + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrDepositNotFound) + + // - Wrong state + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: deposits[2].PoolId, + DepositId: deposits[2].DepositId, + DepositorAddress: deposits[2].DepositorAddress, + ToAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDepositState) + + // - Wront depositor and withdraw address + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: pool.PoolId, + DepositId: deposits[1].DepositId, + DepositorAddress: suite.addrs[3].String(), + ToAddress: suite.addrs[3].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidWithdrawalDepositorAddress) + + // Add a successful withdrawal should remove a deposit + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + // Make sure we have the correct number of withdrawals + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 1) + // State should be unbonding + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawals[0].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[0].ErrorState) + + // Two deposits only should remain + deposits = app.MillionsKeeper.ListDeposits(ctx) + suite.Require().Len(deposits, 2) + + // Add a successful withdrawal should remove a deposit + _, err = msgServer.WithdrawDeposit(goCtx, &millionstypes.MsgWithdrawDeposit{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + + // Make sure we have the correct number of withdrawals + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 2) + // State should be unbonding + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawals[1].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[1].ErrorState) + + // One deposit only should remain + deposits = app.MillionsKeeper.ListDeposits(ctx) + suite.Require().Len(deposits, 1) +} + +// TestMsgServer_WithdrawDepositRetry runs withdrawal retry related tests +func (suite *KeeperTestSuite) TestMsgServer_WithdrawDepositRetry() { + // Set the app context + app := suite.app + ctx := suite.ctx + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + drawDelta1 := 1 * time.Hour + var now = time.Now().UTC() + + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: uint64(1), + Denom: localPoolDenom, + NativeDenom: localPoolDenom, + Validators: map[string]*millionstypes.PoolValidator{ + suite.valAddrs[0].String(): { + OperatorAddress: suite.valAddrs[0].String(), + BondedAmount: sdk.NewInt(1_000_000), + IsEnabled: true, + }, + }, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 100, Quantity: 1, DrawProbability: floatToDec(0.00)}, + }, + }, + DrawSchedule: millionstypes.DrawSchedule{ + InitialDrawAt: ctx.BlockTime().Add(drawDelta1), + DrawDelta: drawDelta1, + }, + AvailablePrizePool: sdk.NewCoin(localPoolDenom, math.NewInt(1000)), + }) + app.MillionsKeeper.AddPool(ctx, pool) + + app.MillionsKeeper.AddDeposit(ctx, &millionstypes.Deposit{ + PoolId: pool.PoolId, + DepositorAddress: suite.addrs[0].String(), + WinnerAddress: suite.addrs[0].String(), + State: millionstypes.DepositState_IbcTransfer, + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000)), + }) + err := app.BankKeeper.SendCoins(ctx, suite.addrs[0], sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), sdk.Coins{sdk.NewCoin(localPoolDenom, sdk.NewInt(1_000_000))}) + suite.Require().NoError(err) + deposits := app.MillionsKeeper.ListDeposits(ctx) + // Simulate transfer deposit and delegate to native chain + err = app.MillionsKeeper.TransferDepositToNativeChain(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + deposits = app.MillionsKeeper.ListDeposits(ctx) + err = app.MillionsKeeper.DelegateDepositOnNativeChain(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().Error(err) + + deposits = app.MillionsKeeper.ListDeposits(ctx) + + app.MillionsKeeper.AddWithdrawal(ctx, millionstypes.Withdrawal{ + PoolId: deposits[0].PoolId, + DepositId: deposits[0].DepositId, + State: millionstypes.WithdrawalState_Failure, + ErrorState: millionstypes.WithdrawalState_IcaUndelegate, + DepositorAddress: suite.addrs[0].String(), + ToAddress: suite.addrs[0].String(), + Amount: sdk.NewCoin(localPoolDenom, sdk.NewInt(int64(1_000_000))), + UnbondingEndsAt: &time.Time{}, + }) + + deposit, err := app.MillionsKeeper.GetPoolDeposit(ctx, deposits[0].PoolId, deposits[0].DepositId) + suite.Require().NoError(err) + // Remove deposit to respect the flow + app.MillionsKeeper.RemoveDeposit(ctx, &deposit) + + withdrawals := app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 1) + + // Test ValidateWithdrawDepositRetryBasic + // Test withdrawal retry with invalid poolID + // - Test unknown poolID + _, err = msgServer.WithdrawDepositRetry(goCtx, &millionstypes.MsgWithdrawDepositRetry{ + PoolId: uint64(0), + WithdrawalId: withdrawals[0].WithdrawalId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + + // - Test unknown withdrawalID + _, err = msgServer.WithdrawDepositRetry(goCtx, &millionstypes.MsgWithdrawDepositRetry{ + PoolId: withdrawals[0].PoolId, + WithdrawalId: uint64(0), + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidID) + + // Test GetPoolWithdrawal + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 1) + + // Test GetPoolWithdrawal with wrong poolID + _, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, uint64(0), withdrawals[0].WithdrawalId) + suite.Require().ErrorIs(err, millionstypes.ErrWithdrawalNotFound) + + // Test GetPoolWithdrawal with wrong withdrawalID + _, err = app.MillionsKeeper.GetPoolWithdrawal(ctx, withdrawals[0].PoolId, uint64(0)) + suite.Require().ErrorIs(err, millionstypes.ErrWithdrawalNotFound) + + // Test if depositorAddr msg is the same as pool withdrawal depositor entity + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + _, err = msgServer.WithdrawDepositRetry(goCtx, &millionstypes.MsgWithdrawDepositRetry{ + PoolId: withdrawals[0].PoolId, + WithdrawalId: withdrawals[0].PoolId, + DepositorAddress: "different-address", + }) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidDepositorAddress) + + // Test WithdrawalState_IcaUndelegate ErrorState + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 1) + + _, err = msgServer.WithdrawDepositRetry(goCtx, &millionstypes.MsgWithdrawDepositRetry{ + PoolId: withdrawals[0].PoolId, + WithdrawalId: withdrawals[0].WithdrawalId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + suite.Require().Len(withdrawals, 1) + + // Should have the correct state + suite.Require().Equal(millionstypes.WithdrawalState_IcaUnbonding, withdrawals[0].State) + suite.Require().Equal(millionstypes.WithdrawalState_Unspecified, withdrawals[0].ErrorState) + + app.MillionsKeeper.UpdateWithdrawalStatus(ctx, withdrawals[0].PoolId, withdrawals[0].WithdrawalId, millionstypes.WithdrawalState_IbcTransfer, withdrawals[0].UnbondingEndsAt, true) + + // move 21 days unbonding onwards and force unbonding + ctx = ctx.WithBlockTime(now.Add(21 * 24 * time.Hour)) + goCtx = ctx + _, err = app.StakingKeeper.CompleteUnbonding(ctx, sdk.MustAccAddressFromBech32(pool.IcaDepositAddress), suite.valAddrs[0]) + suite.Require().NoError(err) + + // Test WithdrawalState_IbcTransfer ErrorState + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + _, err = msgServer.WithdrawDepositRetry(goCtx, &millionstypes.MsgWithdrawDepositRetry{ + PoolId: withdrawals[0].PoolId, + WithdrawalId: withdrawals[0].WithdrawalId, + DepositorAddress: suite.addrs[0].String(), + }) + suite.Require().NoError(err) + withdrawals = app.MillionsKeeper.ListWithdrawals(ctx) + // Withdrawals should be removed upon completion + suite.Require().Len(withdrawals, 0) +} + +// TestMsgServer_ClaimPrize runs prize claim related tests +func (suite *KeeperTestSuite) TestMsgServer_ClaimPrize() { + app := suite.app + ctx := suite.ctx + params := app.MillionsKeeper.GetParams(ctx) + goCtx := sdk.WrapSDKContext(ctx) + msgServer := millionskeeper.NewMsgServerImpl(*app.MillionsKeeper) + + // Create pool and simulate module account address + poolID := app.MillionsKeeper.GetNextPoolIDAndIncrement(ctx) + pool := newValidPool(suite, millionstypes.Pool{ + PoolId: poolID, + PrizeStrategy: millionstypes.PrizeStrategy{ + PrizeBatches: []millionstypes.PrizeBatch{ + {PoolPercent: 50, Quantity: 100, DrawProbability: floatToDec(0.5)}, + {PoolPercent: 50, Quantity: 200, DrawProbability: floatToDec(0.7)}, + }, + }, + }) + app.MillionsKeeper.AddPool(ctx, pool) + + // Create prizes at various stages + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: poolID, + DrawId: pool.NextDrawId, + PrizeId: 1, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(1_000_000)), + WinnerAddress: suite.addrs[1].String(), + CreatedAt: ctx.BlockTime(), + ExpiresAt: ctx.BlockTime().Add(params.PrizeExpirationDelta), + State: millionstypes.PrizeState_Pending, + }) + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: poolID, + DrawId: pool.NextDrawId, + PrizeId: 2, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(2_000_000)), + WinnerAddress: suite.addrs[1].String(), + CreatedAt: ctx.BlockTime(), + ExpiresAt: ctx.BlockTime().Add(params.PrizeExpirationDelta), + State: millionstypes.PrizeState_Pending, + }) + app.MillionsKeeper.AddPrize(ctx, millionstypes.Prize{ + PoolId: poolID, + DrawId: pool.NextDrawId, + PrizeId: 3, + Amount: sdk.NewCoin(pool.Denom, sdk.NewInt(3_000_000)), + WinnerAddress: suite.addrs[1].String(), + CreatedAt: ctx.BlockTime(), + ExpiresAt: ctx.BlockTime().Add(params.PrizeExpirationDelta), + State: millionstypes.PrizeState_Pending, + }) + + // List Prizes + prizes := app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizes, 3) + suite.Require().Equal(millionstypes.PrizeState_Pending, prizes[0].State) + suite.Require().Equal(millionstypes.PrizeState_Pending, prizes[1].State) + suite.Require().Equal(millionstypes.PrizeState_Pending, prizes[2].State) + + // Send required amounts to pool account + modAddr, err := sdk.AccAddressFromBech32(pool.GetLocalAddress()) + suite.Require().NoError(err) + err = app.BankKeeper.SendCoins(ctx, suite.addrs[0], modAddr, sdk.NewCoins(prizes[0].Amount.Add(prizes[1].Amount).Add(prizes[2].Amount))) + suite.Require().NoError(err) + + // Test invalid claim requests + _, err = msgServer.ClaimPrize(goCtx, millionstypes.NewMsgMsgClaimPrize("", prizes[0].PoolId, prizes[0].DrawId, prizes[0].PrizeId)) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidWinnerAddress) + _, err = msgServer.ClaimPrize(goCtx, millionstypes.NewMsgMsgClaimPrize(suite.addrs[0].String(), prizes[0].PoolId, prizes[0].DrawId, prizes[0].PrizeId)) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrInvalidWinnerAddress) + + _, err = msgServer.ClaimPrize(goCtx, millionstypes.NewMsgMsgClaimPrize(suite.addrs[1].String(), prizes[0].PoolId+1, prizes[0].DrawId, prizes[0].PrizeId)) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrPrizeNotFound) + _, err = msgServer.ClaimPrize(goCtx, millionstypes.NewMsgMsgClaimPrize(suite.addrs[1].String(), prizes[0].PoolId, prizes[0].DrawId+1, prizes[0].PrizeId)) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrPrizeNotFound) + _, err = msgServer.ClaimPrize(goCtx, millionstypes.NewMsgMsgClaimPrize(suite.addrs[1].String(), prizes[0].PoolId, prizes[0].DrawId, prizes[2].PrizeId+1)) + suite.Require().Error(err) + suite.Require().ErrorIs(err, millionstypes.ErrPrizeNotFound) + + prizes = app.MillionsKeeper.ListPrizes(ctx) + + for _, prize := range prizes { + addr := sdk.MustAccAddressFromBech32(prize.WinnerAddress) + // Get the module balance before claimPrize + moduleBalanceBefore := app.BankKeeper.GetBalance(ctx, modAddr, pool.Denom) + // Get the balance before claimPrize + balanceBefore := app.BankKeeper.GetBalance(ctx, addr, pool.Denom) + // claimPrize + _, err = msgServer.ClaimPrize(goCtx, millionstypes.NewMsgMsgClaimPrize(addr.String(), prize.PoolId, prize.DrawId, prize.PrizeId)) + suite.Require().NoError(err) + // Compare the new balance with the expected balance + balance := app.BankKeeper.GetBalance(ctx, addr, pool.Denom) + expectedBalance := balanceBefore.Add(prize.Amount) + suite.Require().True(expectedBalance.Equal(balance)) + // Compare the new module balance with the expected module balance + expectedModuleBalance := moduleBalanceBefore.Sub(prize.Amount) + moduleBalance := app.BankKeeper.GetBalance(ctx, modAddr, pool.Denom) + suite.Require().True(expectedModuleBalance.Equal(moduleBalance)) + } + // There should be no more prizes + prizes = app.MillionsKeeper.ListPrizes(ctx) + suite.Require().Len(prizes, 0) +} diff --git a/x/millions/keeper/msg_server_withdrawal.go b/x/millions/keeper/msg_server_withdrawal.go new file mode 100644 index 00000000..80b184ae --- /dev/null +++ b/x/millions/keeper/msg_server_withdrawal.go @@ -0,0 +1,159 @@ +package keeper + +import ( + "context" + "strconv" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/lum-network/chain/x/millions/types" +) + +// WithdrawDeposit withdraw a deposit from the transaction message +func (k msgServer) WithdrawDeposit(goCtx context.Context, msg *types.MsgWithdrawDeposit) (*types.MsgWithdrawDepositResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Verify address + depositorAddr, err := sdk.AccAddressFromBech32(msg.DepositorAddress) + if err != nil { + return nil, types.ErrInvalidDepositorAddress + } + + toAddr, err := sdk.AccAddressFromBech32(msg.ToAddress) + if err != nil { + return nil, types.ErrInvalidDestinationAddress + } + + // Get the pool deposit + deposit, err := k.GetPoolDeposit(ctx, msg.PoolId, msg.DepositId) + if err != nil { + return nil, types.ErrDepositNotFound + } + + // Verify that the incoming message withdrawAddr matches the deposit depositor_address + if depositorAddr.String() != deposit.DepositorAddress { + return nil, types.ErrInvalidWithdrawalDepositorAddress + } + + // Verify that the deposit can be withdrawn + if deposit.State != types.DepositState_Success { + return nil, types.ErrInvalidDepositState + } + + // Prepare the withdrawal instance + withdrawal := types.Withdrawal{ + PoolId: msg.PoolId, + DepositId: msg.DepositId, + WithdrawalId: k.GetNextWithdrawalIdAndIncrement(ctx), + State: types.WithdrawalState_IcaUndelegate, + DepositorAddress: deposit.DepositorAddress, + ToAddress: toAddr.String(), + Amount: deposit.Amount, + CreatedAtHeight: ctx.BlockHeight(), + UpdatedAtHeight: ctx.BlockHeight(), + CreatedAt: ctx.BlockTime(), + UpdatedAt: ctx.BlockTime(), + } + + // Adds the withdrawal and remove the deposit + k.AddWithdrawal(ctx, withdrawal) + k.RemoveDeposit(ctx, &deposit) + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeWithdrawDeposit, + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(withdrawal.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyWithdrawalID, strconv.FormatUint(withdrawal.WithdrawalId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositID, strconv.FormatUint(deposit.DepositId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositor, withdrawal.DepositorAddress), + sdk.NewAttribute(types.AttributeKeyRecipient, withdrawal.ToAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, withdrawal.Amount.String()), + ), + }) + + if err := k.UndelegateWithdrawalOnNativeChain(ctx, withdrawal.GetPoolId(), withdrawal.GetWithdrawalId()); err != nil { + return nil, err + } + + return &types.MsgWithdrawDepositResponse{WithdrawalId: withdrawal.WithdrawalId}, err +} + +// WithdrawDepositRetry allows the user to manually trigger the withdrawal of their deposit in case of failure +func (k msgServer) WithdrawDepositRetry(goCtx context.Context, msg *types.MsgWithdrawDepositRetry) (*types.MsgWithdrawDepositRetryResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Ensure msg received is valid + if err := msg.ValidateWithdrawDepositRetryBasic(); err != nil { + return nil, err + } + + withdrawal, err := k.GetPoolWithdrawal(ctx, msg.PoolId, msg.WithdrawalId) + if err != nil { + return nil, err + } + + depositorAddr, err := sdk.AccAddressFromBech32(msg.DepositorAddress) + if err != nil { + return nil, types.ErrInvalidDepositorAddress + } + + // Verify that the depositorAddress msg is the same as the entity pool withdrawal depositor + if depositorAddr.String() != withdrawal.DepositorAddress { + return nil, types.ErrInvalidDepositorAddress + } + + // State should be set to failure in order to retry something + if withdrawal.State != types.WithdrawalState_Failure { + return nil, errorsmod.Wrapf( + types.ErrInvalidWithdrawalState, + "state is %s instead of %s", + withdrawal.State.String(), types.WithdrawalState_Failure.String(), + ) + } + + newState := types.WithdrawalState_Unspecified + if withdrawal.ErrorState == types.WithdrawalState_IcaUndelegate { + newState = types.WithdrawalState_IcaUndelegate + k.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, newState, withdrawal.UnbondingEndsAt, false) + if err := k.UndelegateWithdrawalOnNativeChain(ctx, withdrawal.PoolId, withdrawal.WithdrawalId); err != nil { + return nil, err + } + } else if withdrawal.ErrorState == types.WithdrawalState_IbcTransfer { + newState = types.WithdrawalState_IbcTransfer + k.UpdateWithdrawalStatus(ctx, withdrawal.PoolId, withdrawal.WithdrawalId, newState, withdrawal.UnbondingEndsAt, false) + if err := k.TransferWithdrawalToLocalChain(ctx, withdrawal.PoolId, withdrawal.WithdrawalId); err != nil { + return nil, err + } + } else { + return nil, errorsmod.Wrapf( + types.ErrInvalidWithdrawalState, + "error_state is %s instead of %s or %s", + withdrawal.ErrorState.String(), types.WithdrawalState_IcaUndelegate.String(), types.WithdrawalState_IbcTransfer.String(), + ) + } + + // Emit event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + sdk.NewEvent( + types.EventTypeWithdrawDepositRetry, + sdk.NewAttribute(types.AttributeKeyState, newState.String()), + sdk.NewAttribute(types.AttributeKeyPoolID, strconv.FormatUint(withdrawal.PoolId, 10)), + sdk.NewAttribute(types.AttributeKeyWithdrawalID, strconv.FormatUint(withdrawal.WithdrawalId, 10)), + sdk.NewAttribute(types.AttributeKeyDepositor, withdrawal.DepositorAddress), + sdk.NewAttribute(types.AttributeKeyRecipient, withdrawal.ToAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, withdrawal.Amount.String()), + ), + }) + + return &types.MsgWithdrawDepositRetryResponse{}, nil +} diff --git a/x/millions/keeper/queries.go b/x/millions/keeper/queries.go new file mode 100644 index 00000000..4ae24352 --- /dev/null +++ b/x/millions/keeper/queries.go @@ -0,0 +1,42 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + icqueriestypes "github.com/lum-network/chain/x/icqueries/types" +) + +const ( + ICQCallbackID_Balance = "balance" +) + +// ICQCallback wrapper struct for millions keeper +type ICQCallback func(Keeper, sdk.Context, []byte, icqueriestypes.Query, icqueriestypes.QueryResponseStatus) error + +type ICQCallbacks struct { + k Keeper + callbacks map[string]ICQCallback +} + +var _ icqueriestypes.QueryCallbacks = ICQCallbacks{} + +func (k Keeper) ICQCallbackHandler() ICQCallbacks { + return ICQCallbacks{k, make(map[string]ICQCallback)} +} + +func (c ICQCallbacks) CallICQCallback(ctx sdk.Context, id string, args []byte, query icqueriestypes.Query, status icqueriestypes.QueryResponseStatus) error { + return c.callbacks[id](c.k, ctx, args, query, status) +} + +func (c ICQCallbacks) HasICQCallback(id string) bool { + _, found := c.callbacks[id] + return found +} + +func (c ICQCallbacks) AddICQCallback(id string, fn interface{}) icqueriestypes.QueryCallbacks { + c.callbacks[id] = fn.(ICQCallback) + return c +} + +func (c ICQCallbacks) RegisterICQCallbacks() icqueriestypes.QueryCallbacks { + return c.AddICQCallback(ICQCallbackID_Balance, ICQCallback(BalanceCallback)) +} diff --git a/x/millions/keeper/queries_balance.go b/x/millions/keeper/queries_balance.go new file mode 100644 index 00000000..eb8b74a3 --- /dev/null +++ b/x/millions/keeper/queries_balance.go @@ -0,0 +1,70 @@ +package keeper + +import ( + "fmt" + "strconv" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + icquerieskeeper "github.com/lum-network/chain/x/icqueries/keeper" + icqueriestypes "github.com/lum-network/chain/x/icqueries/types" + "github.com/lum-network/chain/x/millions/types" +) + +func BalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icqueriestypes.Query, status icqueriestypes.QueryResponseStatus) error { + // Extract our keys from the extra id + keys := types.DecombineStringKeys(query.ExtraId) + if len(keys) != 2 { + return errorsmod.Wrapf(types.ErrPoolNotFound, "keys is invalid, must contain two keys (pool ID and draw ID)") + } + poolID, err := strconv.ParseUint(keys[0], 10, 64) + if err != nil { + return err + } + drawID, err := strconv.ParseUint(keys[1], 10, 64) + if err != nil { + return err + } + + // Confirm host exists + pool, err := k.GetPool(ctx, poolID) + if err != nil { + return errorsmod.Wrapf(types.ErrPoolNotFound, "no registered pool for queried chain ID (%s) or combined keys (%s)", query.ChainId, query.ExtraId) + } + + // Confirm draw exists + draw, err := k.GetPoolDraw(ctx, poolID, drawID) + if err != nil { + return errorsmod.Wrapf(types.ErrPoolNotFound, "no registered draw %d for pool %d", drawID, poolID) + } + + // Based on type, we want different processing + if status == icqueriestypes.QueryResponseStatus_TIMEOUT { + k.Logger(ctx).Error(fmt.Sprintf("QUERY TIMEOUT - QueryId: %s, TTL: %d, BlockTime: %d", query.Id, query.Ttl, ctx.BlockHeader().Time.UnixNano())) + _, err := k.OnQueryRewardsOnNativeChainCompleted(ctx, pool.GetPoolId(), draw.GetDrawId(), sdk.NewCoins(), true) + if err != nil { + return err + } + } else if status == icqueriestypes.QueryResponseStatus_FAILURE { + k.Logger(ctx).Error(fmt.Sprintf("QUERY FAILURE - QueryId: %s, TTL: %d, BlockTime: %d", query.Id, query.Ttl, ctx.BlockHeader().Time.UnixNano())) + _, err := k.OnQueryRewardsOnNativeChainCompleted(ctx, pool.GetPoolId(), draw.GetDrawId(), sdk.NewCoins(), true) + if err != nil { + return err + } + } else if status == icqueriestypes.QueryResponseStatus_SUCCESS { + // Unmarshal query response + balanceAmount, err := icquerieskeeper.UnmarshalAmountFromBalanceQuery(k.cdc, args) + if err != nil { + return errorsmod.Wrap(err, "unable to determine balance from query response") + } + + k.Logger(ctx).Info(fmt.Sprintf("Query response - Rewards Balance: %d %s", balanceAmount, pool.GetNativeDenom())) + + // Notify the internal systems + _, err = k.OnQueryRewardsOnNativeChainCompleted(ctx, pool.GetPoolId(), draw.GetDrawId(), sdk.NewCoins(sdk.NewCoin(pool.GetNativeDenom(), balanceAmount)), false) + if err != nil { + return err + } + } + return nil +} diff --git a/x/millions/middleware_ibc.go b/x/millions/middleware_ibc.go new file mode 100644 index 00000000..dc0436bc --- /dev/null +++ b/x/millions/middleware_ibc.go @@ -0,0 +1,143 @@ +package millions + +import ( + "fmt" + + porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" + + "github.com/lum-network/chain/x/icacallbacks" + icacallbacktypes "github.com/lum-network/chain/x/icacallbacks/types" + "github.com/lum-network/chain/x/millions/keeper" +) + +// IBCMiddleware Declare our IBCMiddleware structure +type IBCMiddleware struct { + keeper keeper.Keeper + app porttypes.IBCModule +} + +// NewIBCMiddleware Initialize a new IBCModule instance +func NewIBCMiddleware(k keeper.Keeper, app porttypes.IBCModule) IBCMiddleware { + return IBCMiddleware{ + keeper: k, + app: app, + } +} + +// OnChanOpenInit implements the IBCModule interface +func (im IBCMiddleware) OnChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string) (string, error) { + return im.app.OnChanOpenInit( + ctx, + order, + connectionHops, + portID, + channelID, + channelCap, + counterparty, + version, + ) +} + +// OnChanOpenTry implements the IBCModule interface +func (im IBCMiddleware) OnChanOpenTry(ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string) (string, error) { + return im.app.OnChanOpenTry( + ctx, + order, + connectionHops, + portID, + channelID, + chanCap, + counterparty, + counterpartyVersion, + ) +} + +// OnChanOpenAck implements the IBCModule interface +func (im IBCMiddleware) OnChanOpenAck(ctx sdk.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string) error { + return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) +} + +// OnChanOpenConfirm implements the IBCModule interface +func (im IBCMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { + return im.app.OnChanOpenConfirm(ctx, portID, channelID) +} + +// OnChanCloseInit implements the IBCModule interface +func (im IBCMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { + return im.app.OnChanCloseInit(ctx, portID, channelID) +} + +// OnChanCloseConfirm implements the IBCModule interface +func (im IBCMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { + return im.app.OnChanCloseConfirm(ctx, portID, channelID) +} + +// OnRecvPacket implements the IBCModule interface. A successful acknowledgement +// is returned if the packet data is successfully decoded and the receive application +// logic returns without error. +func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement { + return im.app.OnRecvPacket(ctx, packet, relayer) +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (im IBCMiddleware) OnAcknowledgementPacket(ctx sdk.Context, modulePacket channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { + im.keeper.Logger(ctx).Debug(fmt.Sprintf("OnAcknowledgementPacket (millions) - packet: %+v, relayer: %v", modulePacket, relayer)) + + // Unpack the response + ackResponse, err := icacallbacks.UnpackAcknowledgementResponse(ctx, im.keeper.Logger(ctx), acknowledgement, false) + if err != nil { + errMsg := fmt.Sprintf("Unable to unpack message data from acknowledgement, Sequence %d, from %s %s, to %s %s: %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort, err.Error()) + im.keeper.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrInvalidAcknowledgement, errMsg) + } + + // Print in the logs for easier debugging + ackInfo := fmt.Sprintf("sequence #%d, from %s %s, to %s %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort) + im.keeper.Logger(ctx).Debug(fmt.Sprintf("Acknowledgement was successfully unmarshalled: ackInfo: %s", ackInfo)) + + // Emit the events + eventType := "ack" + ctx.EventManager().EmitEvent( + sdk.NewEvent( + eventType, + sdk.NewAttribute(sdk.AttributeKeyModule, transfertypes.ModuleName), + sdk.NewAttribute(transfertypes.AttributeKeyAck, ackInfo), + ), + ) + + // Notify the registered callbacks + err = im.keeper.ICACallbacksKeeper.CallRegisteredICACallback(ctx, modulePacket, ackResponse) + if err != nil { + errMsg := fmt.Sprintf("Unable to call registered callback from OnAcknowledgePacket | Sequence %d, from %s %s, to %s %s => %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort, err.Error()) + im.keeper.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrCallbackFailed, errMsg) + } + + return im.app.OnAcknowledgementPacket(ctx, modulePacket, acknowledgement, relayer) +} + +// OnTimeoutPacket implements the IBCModule interface +func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, modulePacket channeltypes.Packet, relayer sdk.AccAddress) error { + im.keeper.Logger(ctx).Debug(fmt.Sprintf("OnTimeoutPacket: packet %v, relayer %v", modulePacket, relayer)) + + // Construct the timeout response + ackResponse := icacallbacktypes.AcknowledgementResponse{Status: icacallbacktypes.AckResponseStatus_TIMEOUT} + + // Notify the callbacks + err := im.keeper.ICACallbacksKeeper.CallRegisteredICACallback(ctx, modulePacket, &ackResponse) + if err != nil { + return err + } + return im.app.OnTimeoutPacket(ctx, modulePacket, relayer) +} + +func (im IBCMiddleware) NegotiateAppVersion(ctx sdk.Context, order channeltypes.Order, connectionID string, portID string, counterparty channeltypes.Counterparty, proposedVersion string) (version string, err error) { + return proposedVersion, nil +} diff --git a/x/millions/module.go b/x/millions/module.go new file mode 100644 index 00000000..f0583ede --- /dev/null +++ b/x/millions/module.go @@ -0,0 +1,165 @@ +package millions + +import ( + "context" + "encoding/json" + "fmt" + "math/rand" + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/lum-network/chain/x/millions/client/cli" + "github.com/lum-network/chain/x/millions/client/rest" + "github.com/lum-network/chain/x/millions/keeper" + "github.com/lum-network/chain/x/millions/simulation" + "github.com/lum-network/chain/x/millions/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +type AppModuleBasic struct { + cdc codec.Codec +} + +/* AppModuleBasic definitions */ + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +func (a AppModuleBasic) DefaultGenesis(jsonCodec codec.JSONCodec) json.RawMessage { + return jsonCodec.MustMarshalJSON(types.DefaultGenesisState()) +} + +func (a AppModuleBasic) ValidateGenesis(jsonCodec codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error { + var data types.GenesisState + if err := jsonCodec.UnmarshalJSON(message, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return nil +} + +func (a AppModuleBasic) RegisterRESTRoutes(context client.Context, router *mux.Router) { + rest.RegisterRoutes(context, router) +} + +func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +func (a AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +/* AppModule definitions */ + +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +func (a AppModule) Name() string { + return a.AppModuleBasic.Name() +} + +func (a AppModule) InitGenesis(context sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + jsonCodec.MustUnmarshalJSON(message, &genState) + + InitGenesis(context, a.keeper, genState) + return []abci.ValidatorUpdate{} +} + +func (a AppModule) ExportGenesis(context sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(context, a.keeper) + return jsonCodec.MustMarshalJSON(genState) +} + +func (a AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {} + +func (a AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(a.keeper)) +} + +func (a AppModule) QuerierRoute() string { + return types.QuerierRoute +} + +func (a AppModule) LegacyQuerierHandler(amino *codec.LegacyAmino) sdk.Querier { + return nil +} + +func (a AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(a.keeper)) +} + +func (a AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + BeginBlocker(ctx, a.keeper) +} + +func (a AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + EndBlocker(ctx, a.keeper) + return []abci.ValidatorUpdate{} +} + +func (a AppModule) ConsensusVersion() uint64 { + return types.ModuleVersion +} + +func (a AppModule) GenerateGenesisState(input *module.SimulationState) {} + +func (a AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +func (a AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return nil +} + +func (a AppModule) RegisterStoreDecoder(registry sdk.StoreDecoderRegistry) { + registry[types.StoreKey] = simulation.NewDecodeStore(a.cdc) +} + +func (a AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/x/millions/module_ibc.go b/x/millions/module_ibc.go new file mode 100644 index 00000000..142372b2 --- /dev/null +++ b/x/millions/module_ibc.go @@ -0,0 +1,166 @@ +package millions + +import ( + "fmt" + "github.com/lum-network/chain/x/millions/types" + + porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v5/modules/core/24-host" + ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" + + "github.com/lum-network/chain/x/icacallbacks" + icacallbacktypes "github.com/lum-network/chain/x/icacallbacks/types" + "github.com/lum-network/chain/x/millions/keeper" +) + +// Map the interface +var _ porttypes.IBCModule = IBCModule{} + +// IBCModule Declare our IBCModule structure +type IBCModule struct { + keeper keeper.Keeper +} + +// NewIBCModule Initialize a new IBCModule instance +func NewIBCModule(k keeper.Keeper) IBCModule { + return IBCModule{ + keeper: k, + } +} + +// OnChanOpenInit implements the IBCModule interface +func (im IBCModule) OnChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string) (string, error) { + im.keeper.Logger(ctx).Debug(fmt.Sprintf("OnChanOpenInit: portID %s, channelID %s", portID, channelID)) + return version, im.keeper.ClaimCapability(ctx, channelCap, host.ChannelCapabilityPath(portID, channelID)) +} + +// OnChanOpenTry implements the IBCModule interface +func (im IBCModule) OnChanOpenTry(ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string) (string, error) { + return "", nil +} + +// OnChanOpenAck implements the IBCModule interface +func (im IBCModule) OnChanOpenAck(ctx sdk.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string) error { + im.keeper.Logger(ctx).Debug(fmt.Sprintf("OnChanOpenAck: portID %s, channelID %s, counterpartyChannelID %s, counterpartyVersion %s", portID, channelID, counterpartyChannelID, counterpartyVersion)) + + // Grab the controller connection ID for the port + controllerConnectionId, err := im.keeper.GetConnectionID(ctx, portID) + if err != nil { + ctx.Logger().Error(fmt.Sprintf("Unable to get connection for port: %s", portID)) + return err + } + + // Extract the interchain account from the connection ID & port + interchainAccountAddress, found := im.keeper.ICAControllerKeeper.GetInterchainAccountAddress(ctx, controllerConnectionId, portID) + if !found { + ctx.Logger().Error("Failed to find the interchain account") + return nil + } + + // Get the pool for the matching controller port + pool, found := im.keeper.GetPoolForControllerPortID(ctx, portID) + if !found { + ctx.Logger().Error(fmt.Sprintf("Failed to get pool for controller port id %s", portID)) + return nil + } + + // Handle which of the ICA addresses has been initialized + depositAddressPortID := pool.GetIcaDepositPortId() + prizePoolAddressPortID := pool.GetIcaPrizepoolPortId() + + var accountType string + if portID == depositAddressPortID { + accountType = types.ICATypeDeposit + } else if portID == prizePoolAddressPortID { + accountType = types.ICATypePrizePool + } + + // Call our internal callback + if _, err := im.keeper.OnSetupPoolICACompleted(ctx, pool.PoolId, accountType, interchainAccountAddress); err != nil { + return err + } + im.keeper.Logger(ctx).Info(fmt.Sprintf("OnChanOpenAck: Found pool %d, set interchain account type %s address %s", pool.GetPoolId(), accountType, interchainAccountAddress)) + return nil +} + +// OnChanOpenConfirm implements the IBCModule interface +func (im IBCModule) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { + return nil +} + +// OnChanCloseInit implements the IBCModule interface +func (im IBCModule) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { + return nil +} + +// OnChanCloseConfirm implements the IBCModule interface +func (im IBCModule) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { + return nil +} + +// OnRecvPacket implements the IBCModule interface. A successful acknowledgement +// is returned if the packet data is successfully decoded and the received application logic returns without error. +func (im IBCModule) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement { + panic("UNIMPLEMENTED") +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (im IBCModule) OnAcknowledgementPacket(ctx sdk.Context, modulePacket channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { + im.keeper.Logger(ctx).Debug(fmt.Sprintf("OnAcknowledgementPacket (millions) - packet: %+v, relayer: %v", modulePacket, relayer)) + + // Unpack the response + ackResponse, err := icacallbacks.UnpackAcknowledgementResponse(ctx, im.keeper.Logger(ctx), acknowledgement, true) + if err != nil { + errMsg := fmt.Sprintf("Unable to unpack message data from acknowledgement, Sequence %d, from %s %s, to %s %s: %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort, err.Error()) + im.keeper.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrInvalidAcknowledgement, errMsg) + } + + // Print in the logs for easier debugging + ackInfo := fmt.Sprintf("sequence #%d, from %s %s, to %s %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort) + im.keeper.Logger(ctx).Debug(fmt.Sprintf("Acknowledgement was successfully unmarshalled: ackInfo: %s", ackInfo)) + + // Emit the events + eventType := "ack" + ctx.EventManager().EmitEvent( + sdk.NewEvent( + eventType, + sdk.NewAttribute(sdk.AttributeKeyModule, transfertypes.ModuleName), + sdk.NewAttribute(transfertypes.AttributeKeyAck, ackInfo), + ), + ) + + // Notify the registered callbacks + err = im.keeper.ICACallbacksKeeper.CallRegisteredICACallback(ctx, modulePacket, ackResponse) + if err != nil { + errMsg := fmt.Sprintf("Unable to call registered callback from OnAcknowledgePacket | Sequence %d, from %s %s, to %s %s => %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort, err.Error()) + im.keeper.Logger(ctx).Error(errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrCallbackFailed, errMsg) + } + return nil +} + +// OnTimeoutPacket implements the IBCModule interface +func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, modulePacket channeltypes.Packet, relayer sdk.AccAddress) error { + im.keeper.Logger(ctx).Debug(fmt.Sprintf("OnTimeoutPacket: packet %v, relayer %v", modulePacket, relayer)) + + // Construct the timeout response + ackResponse := icacallbacktypes.AcknowledgementResponse{Status: icacallbacktypes.AckResponseStatus_TIMEOUT} + + // Notify the callbacks + err := im.keeper.ICACallbacksKeeper.CallRegisteredICACallback(ctx, modulePacket, &ackResponse) + if err != nil { + return err + } + return nil +} + +func (im IBCModule) NegotiateAppVersion(ctx sdk.Context, order channeltypes.Order, connectionID string, portID string, counterparty channeltypes.Counterparty, proposedVersion string) (version string, err error) { + return proposedVersion, nil +} diff --git a/x/millions/simulation/decoder.go b/x/millions/simulation/decoder.go new file mode 100644 index 00000000..efc556c7 --- /dev/null +++ b/x/millions/simulation/decoder.go @@ -0,0 +1,16 @@ +package simulation + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/kv" + + "github.com/lum-network/chain/x/millions/types" +) + +func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { + return func(kvA, kvB kv.Pair) string { + panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + } +} diff --git a/x/millions/types/callbacks.pb.go b/x/millions/types/callbacks.pb.go new file mode 100644 index 00000000..a23a147c --- /dev/null +++ b/x/millions/types/callbacks.pb.go @@ -0,0 +1,1953 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/callbacks.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type TransferType int32 + +const ( + TransferType_Unspecified TransferType = 0 + TransferType_Claim TransferType = 1 + TransferType_Withdraw TransferType = 2 +) + +var TransferType_name = map[int32]string{ + 0: "TRANSFER_TYPE_UNSPECIFIED", + 1: "TRANSFER_TYPE_CLAIM", + 2: "TRANSFER_TYPE_WITHDRAW", +} + +var TransferType_value = map[string]int32{ + "TRANSFER_TYPE_UNSPECIFIED": 0, + "TRANSFER_TYPE_CLAIM": 1, + "TRANSFER_TYPE_WITHDRAW": 2, +} + +func (x TransferType) String() string { + return proto.EnumName(TransferType_name, int32(x)) +} + +func (TransferType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{0} +} + +type SplitDelegation struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` +} + +func (m *SplitDelegation) Reset() { *m = SplitDelegation{} } +func (m *SplitDelegation) String() string { return proto.CompactTextString(m) } +func (*SplitDelegation) ProtoMessage() {} +func (*SplitDelegation) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{0} +} +func (m *SplitDelegation) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SplitDelegation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SplitDelegation.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SplitDelegation) XXX_Merge(src proto.Message) { + xxx_messageInfo_SplitDelegation.Merge(m, src) +} +func (m *SplitDelegation) XXX_Size() int { + return m.Size() +} +func (m *SplitDelegation) XXX_DiscardUnknown() { + xxx_messageInfo_SplitDelegation.DiscardUnknown(m) +} + +var xxx_messageInfo_SplitDelegation proto.InternalMessageInfo + +func (m *SplitDelegation) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +type DelegateCallback struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` + SplitDelegations []*SplitDelegation `protobuf:"bytes,3,rep,name=split_delegations,json=splitDelegations,proto3" json:"split_delegations,omitempty"` +} + +func (m *DelegateCallback) Reset() { *m = DelegateCallback{} } +func (m *DelegateCallback) String() string { return proto.CompactTextString(m) } +func (*DelegateCallback) ProtoMessage() {} +func (*DelegateCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{1} +} +func (m *DelegateCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelegateCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelegateCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DelegateCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelegateCallback.Merge(m, src) +} +func (m *DelegateCallback) XXX_Size() int { + return m.Size() +} +func (m *DelegateCallback) XXX_DiscardUnknown() { + xxx_messageInfo_DelegateCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_DelegateCallback proto.InternalMessageInfo + +func (m *DelegateCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *DelegateCallback) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +func (m *DelegateCallback) GetSplitDelegations() []*SplitDelegation { + if m != nil { + return m.SplitDelegations + } + return nil +} + +type UndelegateCallback struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + WithdrawalId uint64 `protobuf:"varint,2,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` + SplitDelegations []*SplitDelegation `protobuf:"bytes,3,rep,name=split_delegations,json=splitDelegations,proto3" json:"split_delegations,omitempty"` +} + +func (m *UndelegateCallback) Reset() { *m = UndelegateCallback{} } +func (m *UndelegateCallback) String() string { return proto.CompactTextString(m) } +func (*UndelegateCallback) ProtoMessage() {} +func (*UndelegateCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{2} +} +func (m *UndelegateCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UndelegateCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UndelegateCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *UndelegateCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_UndelegateCallback.Merge(m, src) +} +func (m *UndelegateCallback) XXX_Size() int { + return m.Size() +} +func (m *UndelegateCallback) XXX_DiscardUnknown() { + xxx_messageInfo_UndelegateCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_UndelegateCallback proto.InternalMessageInfo + +func (m *UndelegateCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *UndelegateCallback) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +func (m *UndelegateCallback) GetSplitDelegations() []*SplitDelegation { + if m != nil { + return m.SplitDelegations + } + return nil +} + +type RedelegateCallback struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + SplitDelegation *SplitDelegation `protobuf:"bytes,2,opt,name=split_delegation,json=splitDelegation,proto3" json:"split_delegation,omitempty"` +} + +func (m *RedelegateCallback) Reset() { *m = RedelegateCallback{} } +func (m *RedelegateCallback) String() string { return proto.CompactTextString(m) } +func (*RedelegateCallback) ProtoMessage() {} +func (*RedelegateCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{3} +} +func (m *RedelegateCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RedelegateCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RedelegateCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RedelegateCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_RedelegateCallback.Merge(m, src) +} +func (m *RedelegateCallback) XXX_Size() int { + return m.Size() +} +func (m *RedelegateCallback) XXX_DiscardUnknown() { + xxx_messageInfo_RedelegateCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_RedelegateCallback proto.InternalMessageInfo + +func (m *RedelegateCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *RedelegateCallback) GetSplitDelegation() *SplitDelegation { + if m != nil { + return m.SplitDelegation + } + return nil +} + +type ClaimRewardsCallback struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` +} + +func (m *ClaimRewardsCallback) Reset() { *m = ClaimRewardsCallback{} } +func (m *ClaimRewardsCallback) String() string { return proto.CompactTextString(m) } +func (*ClaimRewardsCallback) ProtoMessage() {} +func (*ClaimRewardsCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{4} +} +func (m *ClaimRewardsCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClaimRewardsCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClaimRewardsCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClaimRewardsCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClaimRewardsCallback.Merge(m, src) +} +func (m *ClaimRewardsCallback) XXX_Size() int { + return m.Size() +} +func (m *ClaimRewardsCallback) XXX_DiscardUnknown() { + xxx_messageInfo_ClaimRewardsCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_ClaimRewardsCallback proto.InternalMessageInfo + +func (m *ClaimRewardsCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *ClaimRewardsCallback) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +type TransferToNativeCallback struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` +} + +func (m *TransferToNativeCallback) Reset() { *m = TransferToNativeCallback{} } +func (m *TransferToNativeCallback) String() string { return proto.CompactTextString(m) } +func (*TransferToNativeCallback) ProtoMessage() {} +func (*TransferToNativeCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{5} +} +func (m *TransferToNativeCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TransferToNativeCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TransferToNativeCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TransferToNativeCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_TransferToNativeCallback.Merge(m, src) +} +func (m *TransferToNativeCallback) XXX_Size() int { + return m.Size() +} +func (m *TransferToNativeCallback) XXX_DiscardUnknown() { + xxx_messageInfo_TransferToNativeCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_TransferToNativeCallback proto.InternalMessageInfo + +func (m *TransferToNativeCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *TransferToNativeCallback) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +type TransferFromNativeCallback struct { + Type TransferType `protobuf:"varint,1,opt,name=type,proto3,enum=lum.network.millions.TransferType" json:"type,omitempty"` + PoolId uint64 `protobuf:"varint,2,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,3,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + WithdrawalId uint64 `protobuf:"varint,4,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` +} + +func (m *TransferFromNativeCallback) Reset() { *m = TransferFromNativeCallback{} } +func (m *TransferFromNativeCallback) String() string { return proto.CompactTextString(m) } +func (*TransferFromNativeCallback) ProtoMessage() {} +func (*TransferFromNativeCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{6} +} +func (m *TransferFromNativeCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TransferFromNativeCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TransferFromNativeCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TransferFromNativeCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_TransferFromNativeCallback.Merge(m, src) +} +func (m *TransferFromNativeCallback) XXX_Size() int { + return m.Size() +} +func (m *TransferFromNativeCallback) XXX_DiscardUnknown() { + xxx_messageInfo_TransferFromNativeCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_TransferFromNativeCallback proto.InternalMessageInfo + +func (m *TransferFromNativeCallback) GetType() TransferType { + if m != nil { + return m.Type + } + return TransferType_Unspecified +} + +func (m *TransferFromNativeCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *TransferFromNativeCallback) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *TransferFromNativeCallback) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +type SetWithdrawAddressCallback struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` +} + +func (m *SetWithdrawAddressCallback) Reset() { *m = SetWithdrawAddressCallback{} } +func (m *SetWithdrawAddressCallback) String() string { return proto.CompactTextString(m) } +func (*SetWithdrawAddressCallback) ProtoMessage() {} +func (*SetWithdrawAddressCallback) Descriptor() ([]byte, []int) { + return fileDescriptor_0a83e36a657ed814, []int{7} +} +func (m *SetWithdrawAddressCallback) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SetWithdrawAddressCallback) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SetWithdrawAddressCallback.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SetWithdrawAddressCallback) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetWithdrawAddressCallback.Merge(m, src) +} +func (m *SetWithdrawAddressCallback) XXX_Size() int { + return m.Size() +} +func (m *SetWithdrawAddressCallback) XXX_DiscardUnknown() { + xxx_messageInfo_SetWithdrawAddressCallback.DiscardUnknown(m) +} + +var xxx_messageInfo_SetWithdrawAddressCallback proto.InternalMessageInfo + +func (m *SetWithdrawAddressCallback) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func init() { + proto.RegisterEnum("lum.network.millions.TransferType", TransferType_name, TransferType_value) + proto.RegisterType((*SplitDelegation)(nil), "lum.network.millions.SplitDelegation") + proto.RegisterType((*DelegateCallback)(nil), "lum.network.millions.DelegateCallback") + proto.RegisterType((*UndelegateCallback)(nil), "lum.network.millions.UndelegateCallback") + proto.RegisterType((*RedelegateCallback)(nil), "lum.network.millions.RedelegateCallback") + proto.RegisterType((*ClaimRewardsCallback)(nil), "lum.network.millions.ClaimRewardsCallback") + proto.RegisterType((*TransferToNativeCallback)(nil), "lum.network.millions.TransferToNativeCallback") + proto.RegisterType((*TransferFromNativeCallback)(nil), "lum.network.millions.TransferFromNativeCallback") + proto.RegisterType((*SetWithdrawAddressCallback)(nil), "lum.network.millions.SetWithdrawAddressCallback") +} + +func init() { + proto.RegisterFile("lum-network/millions/callbacks.proto", fileDescriptor_0a83e36a657ed814) +} + +var fileDescriptor_0a83e36a657ed814 = []byte{ + // 597 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x4d, 0x4f, 0xdb, 0x4c, + 0x10, 0xc7, 0xb3, 0x21, 0x4f, 0x78, 0x58, 0x68, 0x31, 0x2e, 0x2a, 0xa9, 0xa5, 0x9a, 0xc8, 0x7d, + 0x11, 0x6a, 0x85, 0x2d, 0x51, 0xb5, 0xf7, 0x10, 0x92, 0x62, 0xa9, 0x45, 0x68, 0x13, 0x84, 0xda, + 0x4b, 0xb4, 0x78, 0x97, 0xb0, 0x62, 0xed, 0xb5, 0xbc, 0x1b, 0x52, 0x4e, 0xbd, 0x55, 0x15, 0xa7, + 0xaa, 0x77, 0x7a, 0xa9, 0xd4, 0x4b, 0xbf, 0x08, 0x47, 0x8e, 0x55, 0x0f, 0xa8, 0x4a, 0xbe, 0x48, + 0x65, 0xe3, 0xbc, 0x42, 0x45, 0xa4, 0xaa, 0x27, 0x7b, 0x67, 0xfe, 0x1e, 0xff, 0xe6, 0xef, 0xf1, + 0xc0, 0x87, 0xbc, 0xe5, 0xaf, 0x06, 0x54, 0xb5, 0x45, 0x74, 0xe8, 0xf8, 0x8c, 0x73, 0x26, 0x02, + 0xe9, 0x78, 0x98, 0xf3, 0x3d, 0xec, 0x1d, 0x4a, 0x3b, 0x8c, 0x84, 0x12, 0xfa, 0x22, 0x6f, 0xf9, + 0x76, 0xaa, 0xb2, 0x7b, 0x2a, 0x63, 0xb1, 0x29, 0x9a, 0x22, 0x11, 0x38, 0xf1, 0xdd, 0xa5, 0xd6, + 0xfa, 0x00, 0xe0, 0x7c, 0x2d, 0xe4, 0x4c, 0x6d, 0x50, 0x4e, 0x9b, 0x58, 0x31, 0x11, 0xe8, 0x4f, + 0xe1, 0xc2, 0x11, 0xe6, 0x8c, 0x60, 0x25, 0xa2, 0x06, 0x26, 0x24, 0xa2, 0x52, 0x16, 0x40, 0x11, + 0xac, 0xcc, 0x20, 0xad, 0x9f, 0x28, 0x5d, 0xc6, 0xf5, 0x2a, 0xcc, 0x63, 0x5f, 0xb4, 0x02, 0x55, + 0xc8, 0xc6, 0x8a, 0x75, 0xfb, 0xec, 0x62, 0x39, 0xf3, 0xf3, 0x62, 0xf9, 0x71, 0x93, 0xa9, 0x83, + 0xd6, 0x9e, 0xed, 0x09, 0xdf, 0xf1, 0x84, 0xf4, 0x85, 0x4c, 0x2f, 0xab, 0x92, 0x1c, 0x3a, 0xea, + 0x38, 0xa4, 0xd2, 0x76, 0x03, 0x85, 0xd2, 0xa7, 0xad, 0x2f, 0x00, 0x6a, 0x29, 0x03, 0x2d, 0xa7, + 0x0d, 0xe9, 0x4b, 0x70, 0x3a, 0x14, 0x82, 0x37, 0x18, 0x49, 0xde, 0x9f, 0x43, 0xf9, 0xf8, 0xe8, + 0x12, 0xfd, 0x3e, 0x84, 0x84, 0x86, 0x42, 0x32, 0x15, 0xe7, 0xb2, 0x49, 0x6e, 0x26, 0x8d, 0xb8, + 0x44, 0x47, 0x70, 0x41, 0xc6, 0x4d, 0x35, 0x48, 0xbf, 0x2b, 0x59, 0x98, 0x2a, 0x4e, 0xad, 0xcc, + 0xae, 0x3d, 0xb2, 0xaf, 0x73, 0xc7, 0x1e, 0xf3, 0x00, 0x69, 0x72, 0x34, 0x20, 0xad, 0x6f, 0x00, + 0xea, 0x3b, 0x01, 0x99, 0x18, 0xf1, 0x01, 0xbc, 0xd5, 0x66, 0xea, 0x80, 0x44, 0xb8, 0x8d, 0xf9, + 0x80, 0x72, 0x6e, 0x10, 0xfc, 0x47, 0xa0, 0xef, 0xa1, 0x8e, 0xe8, 0xe4, 0x9c, 0xdb, 0x50, 0x1b, + 0x47, 0x48, 0x50, 0x27, 0x26, 0x98, 0x1f, 0x23, 0xb0, 0x36, 0xe1, 0x62, 0x99, 0x63, 0xe6, 0x23, + 0xda, 0xc6, 0x11, 0x91, 0x37, 0x23, 0x2c, 0xc1, 0xe9, 0xd8, 0x91, 0x81, 0x49, 0xf9, 0xf8, 0xe8, + 0x12, 0x0b, 0xc1, 0x42, 0x3d, 0xc2, 0x81, 0xdc, 0xa7, 0x51, 0x5d, 0x6c, 0x61, 0xc5, 0x8e, 0xfe, + 0x7a, 0x36, 0xac, 0xef, 0x00, 0x1a, 0xbd, 0xa2, 0xd5, 0x48, 0xf8, 0x63, 0x65, 0x5f, 0xc0, 0x5c, + 0x3c, 0x9c, 0x49, 0xcd, 0xdb, 0x6b, 0xd6, 0xf5, 0x16, 0xf4, 0xa1, 0x8e, 0x43, 0x8a, 0x12, 0xfd, + 0x30, 0x4e, 0xf6, 0x4f, 0xcd, 0x4d, 0x0d, 0x37, 0x77, 0x75, 0x40, 0x72, 0x57, 0x07, 0xc4, 0x7a, + 0x0e, 0x8d, 0x1a, 0x55, 0xbb, 0x69, 0x28, 0xfd, 0xe9, 0x6e, 0xf4, 0xe0, 0xc9, 0x67, 0x00, 0xe7, + 0x86, 0x21, 0x75, 0x1b, 0xde, 0xab, 0xa3, 0xd2, 0x56, 0xad, 0x5a, 0x41, 0x8d, 0xfa, 0x9b, 0xed, + 0x4a, 0x63, 0x67, 0xab, 0xb6, 0x5d, 0x29, 0xbb, 0x55, 0xb7, 0xb2, 0xa1, 0x65, 0x8c, 0xf9, 0x93, + 0xd3, 0xe2, 0xec, 0x4e, 0x20, 0x43, 0xea, 0xb1, 0x7d, 0x46, 0x89, 0x6e, 0xc1, 0x3b, 0xa3, 0xfa, + 0xf2, 0xab, 0x92, 0xfb, 0x5a, 0x03, 0xc6, 0xcc, 0xc9, 0x69, 0xf1, 0xbf, 0xe4, 0xf3, 0xea, 0x2b, + 0xf0, 0xee, 0xa8, 0x66, 0xd7, 0xad, 0x6f, 0x6e, 0xa0, 0xd2, 0xae, 0x96, 0x35, 0xe6, 0x4e, 0x4e, + 0x8b, 0xff, 0xf7, 0xb0, 0x8d, 0xdc, 0xc7, 0xaf, 0x26, 0x58, 0x7f, 0x79, 0xd6, 0x31, 0xc1, 0x79, + 0xc7, 0x04, 0xbf, 0x3a, 0x26, 0xf8, 0xd4, 0x35, 0x33, 0xe7, 0x5d, 0x33, 0xf3, 0xa3, 0x6b, 0x66, + 0xde, 0xae, 0x0e, 0x2d, 0x8b, 0xe1, 0x15, 0xe7, 0x1d, 0x60, 0x16, 0x38, 0xef, 0x06, 0xab, 0x2e, + 0xd9, 0x1b, 0x7b, 0xf9, 0x64, 0x77, 0x3d, 0xfb, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xf2, 0xd0, 0x1f, + 0xdc, 0x0f, 0x05, 0x00, 0x00, +} + +func (m *SplitDelegation) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SplitDelegation) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SplitDelegation) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCallbacks(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintCallbacks(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DelegateCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DelegateCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelegateCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SplitDelegations) > 0 { + for iNdEx := len(m.SplitDelegations) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SplitDelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCallbacks(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.DepositId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *UndelegateCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UndelegateCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UndelegateCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SplitDelegations) > 0 { + for iNdEx := len(m.SplitDelegations) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SplitDelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCallbacks(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.WithdrawalId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *RedelegateCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RedelegateCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RedelegateCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SplitDelegation != nil { + { + size, err := m.SplitDelegation.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCallbacks(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ClaimRewardsCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClaimRewardsCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClaimRewardsCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DrawId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *TransferToNativeCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TransferToNativeCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TransferToNativeCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DepositId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *TransferFromNativeCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TransferFromNativeCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TransferFromNativeCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.WithdrawalId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x20 + } + if m.DrawId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x18 + } + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x10 + } + if m.Type != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *SetWithdrawAddressCallback) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SetWithdrawAddressCallback) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SetWithdrawAddressCallback) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PoolId != 0 { + i = encodeVarintCallbacks(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintCallbacks(dAtA []byte, offset int, v uint64) int { + offset -= sovCallbacks(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SplitDelegation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovCallbacks(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovCallbacks(uint64(l)) + return n +} + +func (m *DelegateCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovCallbacks(uint64(m.DepositId)) + } + if len(m.SplitDelegations) > 0 { + for _, e := range m.SplitDelegations { + l = e.Size() + n += 1 + l + sovCallbacks(uint64(l)) + } + } + return n +} + +func (m *UndelegateCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + if m.WithdrawalId != 0 { + n += 1 + sovCallbacks(uint64(m.WithdrawalId)) + } + if len(m.SplitDelegations) > 0 { + for _, e := range m.SplitDelegations { + l = e.Size() + n += 1 + l + sovCallbacks(uint64(l)) + } + } + return n +} + +func (m *RedelegateCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + if m.SplitDelegation != nil { + l = m.SplitDelegation.Size() + n += 1 + l + sovCallbacks(uint64(l)) + } + return n +} + +func (m *ClaimRewardsCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovCallbacks(uint64(m.DrawId)) + } + return n +} + +func (m *TransferToNativeCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovCallbacks(uint64(m.DepositId)) + } + return n +} + +func (m *TransferFromNativeCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovCallbacks(uint64(m.Type)) + } + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovCallbacks(uint64(m.DrawId)) + } + if m.WithdrawalId != 0 { + n += 1 + sovCallbacks(uint64(m.WithdrawalId)) + } + return n +} + +func (m *SetWithdrawAddressCallback) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovCallbacks(uint64(m.PoolId)) + } + return n +} + +func sovCallbacks(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCallbacks(x uint64) (n int) { + return sovCallbacks(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *SplitDelegation) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SplitDelegation: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SplitDelegation: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCallbacks + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCallbacks + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCallbacks + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCallbacks + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DelegateCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DelegateCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelegateCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SplitDelegations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCallbacks + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCallbacks + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SplitDelegations = append(m.SplitDelegations, &SplitDelegation{}) + if err := m.SplitDelegations[len(m.SplitDelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UndelegateCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UndelegateCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UndelegateCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SplitDelegations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCallbacks + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCallbacks + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SplitDelegations = append(m.SplitDelegations, &SplitDelegation{}) + if err := m.SplitDelegations[len(m.SplitDelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RedelegateCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RedelegateCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RedelegateCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SplitDelegation", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCallbacks + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCallbacks + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SplitDelegation == nil { + m.SplitDelegation = &SplitDelegation{} + } + if err := m.SplitDelegation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ClaimRewardsCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClaimRewardsCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClaimRewardsCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TransferToNativeCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TransferToNativeCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TransferToNativeCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TransferFromNativeCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TransferFromNativeCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TransferFromNativeCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= TransferType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SetWithdrawAddressCallback) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SetWithdrawAddressCallback: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SetWithdrawAddressCallback: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCallbacks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCallbacks(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCallbacks + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCallbacks(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCallbacks + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCallbacks + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCallbacks + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCallbacks + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCallbacks + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCallbacks + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCallbacks = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCallbacks = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCallbacks = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/codec.go b/x/millions/types/codec.go new file mode 100644 index 00000000..855aa1d4 --- /dev/null +++ b/x/millions/types/codec.go @@ -0,0 +1,60 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +// RegisterLegacyAminoCodec Register the codec for the message passing +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + // Messages + cdc.RegisterConcrete(&MsgDeposit{}, "lum-network/millions/MsgDeposit", nil) + cdc.RegisterConcrete(&MsgDepositRetry{}, "lum-network/millions/MsgDepositRetry", nil) + cdc.RegisterConcrete(&MsgClaimPrize{}, "lum-network/millions/MsgClaimPrize", nil) + cdc.RegisterConcrete(&MsgDrawRetry{}, "lum-network/millions/MsgDrawRetry", nil) + cdc.RegisterConcrete(&MsgWithdrawDeposit{}, "lum-network/millions/MsgWithdrawDeposit", nil) + cdc.RegisterConcrete(&MsgWithdrawDepositRetry{}, "lum-network/millions/MsgWithdrawDepositRetry", nil) + cdc.RegisterConcrete(&MsgRestoreInterchainAccounts{}, "lum-network/millions/MsgRestoreInterchainAccounts", nil) + + // Proposals + cdc.RegisterConcrete(&ProposalUpdateParams{}, "lum-network/millions/ProposalUpdateParams", nil) + cdc.RegisterConcrete(&ProposalRegisterPool{}, "lum-network/millions/ProposalRegisterPool", nil) + cdc.RegisterConcrete(&ProposalUpdatePool{}, "lum-network/millions/ProposalUpdatePool", nil) +} + +// RegisterInterfaces Register the implementations for the given codecs +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + // Messages + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgDeposit{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgDepositRetry{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgClaimPrize{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgDrawRetry{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgWithdrawDeposit{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgWithdrawDepositRetry{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRestoreInterchainAccounts{}) + + // Proposals + registry.RegisterImplementations((*govtypes.Content)(nil), &ProposalUpdateParams{}) + registry.RegisterImplementations((*govtypes.Content)(nil), &ProposalRegisterPool{}) + registry.RegisterImplementations((*govtypes.Content)(nil), &ProposalUpdatePool{}) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + amino.Seal() + + RegisterLegacyAminoCodec(legacy.Cdc) +} diff --git a/x/millions/types/deposit.go b/x/millions/types/deposit.go new file mode 100644 index 00000000..347c676b --- /dev/null +++ b/x/millions/types/deposit.go @@ -0,0 +1,39 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ValidateBasic validates if a deposit has a valid poolID, depositID and depositorAddress +// meaning that it can be stored +func (deposit *Deposit) ValidateBasic() error { + if deposit.PoolId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "pool ID") + } + if deposit.DepositId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "deposit ID") + } + if deposit.State == DepositState_Unspecified { + return errorsmod.Wrapf(ErrInvalidDepositState, "no state specified") + } + if _, err := sdk.AccAddressFromBech32(deposit.DepositorAddress); err != nil { + return errorsmod.Wrapf(ErrInvalidDepositorAddress, err.Error()) + } + if _, err := sdk.AccAddressFromBech32(deposit.WinnerAddress); err != nil { + return errorsmod.Wrapf(ErrInvalidWinnerAddress, err.Error()) + } + return nil +} + +// ValidateDepositRetryBasic validates the incoming message for a deposit retry +func (msg *MsgDepositRetry) ValidateDepositRetryBasic() error { + if msg.PoolId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "pool ID") + } + if msg.DepositId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "deposit ID") + } + + return nil +} diff --git a/x/millions/types/deposit.pb.go b/x/millions/types/deposit.pb.go new file mode 100644 index 00000000..583b1bc0 --- /dev/null +++ b/x/millions/types/deposit.pb.go @@ -0,0 +1,850 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/deposit.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type DepositState int32 + +const ( + DepositState_Unspecified DepositState = 0 + DepositState_IbcTransfer DepositState = 1 + DepositState_IcaDelegate DepositState = 2 + DepositState_Success DepositState = 3 + DepositState_Failure DepositState = 4 +) + +var DepositState_name = map[int32]string{ + 0: "DEPOSIT_STATE_UNSPECIFIED", + 1: "DEPOSIT_STATE_IBC_TRANSFER", + 2: "DEPOSIT_STATE_ICA_DELEGATE", + 3: "DEPOSIT_STATE_SUCCESS", + 4: "DEPOSIT_STATE_FAILURE", +} + +var DepositState_value = map[string]int32{ + "DEPOSIT_STATE_UNSPECIFIED": 0, + "DEPOSIT_STATE_IBC_TRANSFER": 1, + "DEPOSIT_STATE_ICA_DELEGATE": 2, + "DEPOSIT_STATE_SUCCESS": 3, + "DEPOSIT_STATE_FAILURE": 4, +} + +func (x DepositState) String() string { + return proto.EnumName(DepositState_name, int32(x)) +} + +func (DepositState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_28137b89894fde94, []int{0} +} + +type Deposit struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` + State DepositState `protobuf:"varint,3,opt,name=state,proto3,enum=lum.network.millions.DepositState" json:"state,omitempty"` + ErrorState DepositState `protobuf:"varint,4,opt,name=error_state,json=errorState,proto3,enum=lum.network.millions.DepositState" json:"error_state,omitempty"` + DepositorAddress string `protobuf:"bytes,5,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + Amount types.Coin `protobuf:"bytes,6,opt,name=amount,proto3" json:"amount"` + WinnerAddress string `protobuf:"bytes,7,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` + IsSponsor bool `protobuf:"varint,8,opt,name=is_sponsor,json=isSponsor,proto3" json:"is_sponsor,omitempty"` + CreatedAtHeight int64 `protobuf:"varint,10,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` + UpdatedAtHeight int64 `protobuf:"varint,11,opt,name=updated_at_height,json=updatedAtHeight,proto3" json:"updated_at_height,omitempty"` + CreatedAt time.Time `protobuf:"bytes,12,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` + UpdatedAt time.Time `protobuf:"bytes,13,opt,name=updated_at,json=updatedAt,proto3,stdtime" json:"updated_at"` +} + +func (m *Deposit) Reset() { *m = Deposit{} } +func (m *Deposit) String() string { return proto.CompactTextString(m) } +func (*Deposit) ProtoMessage() {} +func (*Deposit) Descriptor() ([]byte, []int) { + return fileDescriptor_28137b89894fde94, []int{0} +} +func (m *Deposit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Deposit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Deposit.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Deposit) XXX_Merge(src proto.Message) { + xxx_messageInfo_Deposit.Merge(m, src) +} +func (m *Deposit) XXX_Size() int { + return m.Size() +} +func (m *Deposit) XXX_DiscardUnknown() { + xxx_messageInfo_Deposit.DiscardUnknown(m) +} + +var xxx_messageInfo_Deposit proto.InternalMessageInfo + +func (m *Deposit) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *Deposit) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +func (m *Deposit) GetState() DepositState { + if m != nil { + return m.State + } + return DepositState_Unspecified +} + +func (m *Deposit) GetErrorState() DepositState { + if m != nil { + return m.ErrorState + } + return DepositState_Unspecified +} + +func (m *Deposit) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *Deposit) GetAmount() types.Coin { + if m != nil { + return m.Amount + } + return types.Coin{} +} + +func (m *Deposit) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func (m *Deposit) GetIsSponsor() bool { + if m != nil { + return m.IsSponsor + } + return false +} + +func (m *Deposit) GetCreatedAtHeight() int64 { + if m != nil { + return m.CreatedAtHeight + } + return 0 +} + +func (m *Deposit) GetUpdatedAtHeight() int64 { + if m != nil { + return m.UpdatedAtHeight + } + return 0 +} + +func (m *Deposit) GetCreatedAt() time.Time { + if m != nil { + return m.CreatedAt + } + return time.Time{} +} + +func (m *Deposit) GetUpdatedAt() time.Time { + if m != nil { + return m.UpdatedAt + } + return time.Time{} +} + +func init() { + proto.RegisterEnum("lum.network.millions.DepositState", DepositState_name, DepositState_value) + proto.RegisterType((*Deposit)(nil), "lum.network.millions.Deposit") +} + +func init() { + proto.RegisterFile("lum-network/millions/deposit.proto", fileDescriptor_28137b89894fde94) +} + +var fileDescriptor_28137b89894fde94 = []byte{ + // 659 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xcb, 0x4e, 0xdb, 0x4c, + 0x18, 0x86, 0x63, 0x08, 0x39, 0x4c, 0x38, 0x04, 0x8b, 0x5f, 0xbf, 0x89, 0x84, 0xb1, 0x58, 0x54, + 0x11, 0x12, 0xb6, 0xa0, 0x8b, 0x76, 0x57, 0x25, 0x8e, 0x43, 0x5d, 0x21, 0x8a, 0x6c, 0x67, 0xd3, + 0x8d, 0xe5, 0xd8, 0x83, 0x33, 0xaa, 0xed, 0xb1, 0x3c, 0xe3, 0xd2, 0xde, 0x01, 0x62, 0xc5, 0x0d, + 0xb0, 0xea, 0x2d, 0xf4, 0x22, 0x58, 0xa2, 0xae, 0xba, 0x6a, 0x2b, 0xb8, 0x87, 0xae, 0x2b, 0x7b, + 0x26, 0x09, 0xb4, 0x48, 0x6d, 0x77, 0x33, 0xdf, 0xfb, 0xbc, 0xdf, 0x61, 0x66, 0x34, 0x60, 0x27, + 0xca, 0xe3, 0xbd, 0x04, 0xd2, 0x33, 0x9c, 0xbd, 0xd5, 0x62, 0x14, 0x45, 0x08, 0x27, 0x44, 0x0b, + 0x60, 0x8a, 0x09, 0xa2, 0x6a, 0x9a, 0x61, 0x8a, 0xc5, 0x8d, 0x28, 0x8f, 0x55, 0xce, 0xa8, 0x53, + 0xa6, 0xb3, 0x11, 0xe2, 0x10, 0x97, 0x80, 0x56, 0xac, 0x18, 0xdb, 0xd9, 0x0e, 0x31, 0x0e, 0x23, + 0xa8, 0x95, 0xbb, 0x71, 0x7e, 0xaa, 0x51, 0x14, 0x43, 0x42, 0xbd, 0x38, 0xe5, 0x80, 0xec, 0x63, + 0x12, 0x63, 0xa2, 0x8d, 0x3d, 0x02, 0xb5, 0x77, 0xfb, 0x63, 0x48, 0xbd, 0x7d, 0xcd, 0xc7, 0x28, + 0xe1, 0xfa, 0x26, 0xd3, 0x5d, 0x96, 0x99, 0x6d, 0x98, 0xb4, 0x73, 0xbe, 0x04, 0xea, 0x03, 0xd6, + 0x99, 0xf8, 0x3f, 0xa8, 0xa7, 0x18, 0x47, 0x2e, 0x0a, 0x24, 0x41, 0x11, 0xba, 0x55, 0xab, 0x56, + 0x6c, 0xcd, 0x40, 0xdc, 0x02, 0x80, 0x77, 0x5f, 0x68, 0x0b, 0xa5, 0xd6, 0xe4, 0x11, 0x33, 0x10, + 0x9f, 0x83, 0x25, 0x42, 0x3d, 0x0a, 0xa5, 0x45, 0x45, 0xe8, 0xae, 0x1e, 0xec, 0xa8, 0x8f, 0xcd, + 0xa6, 0xf2, 0x2a, 0x76, 0x41, 0x5a, 0xcc, 0x20, 0xea, 0xa0, 0x05, 0xb3, 0x0c, 0x67, 0x2e, 0xf3, + 0x57, 0xff, 0xda, 0x0f, 0x4a, 0x5b, 0xb9, 0x16, 0x0d, 0xb0, 0xce, 0x7b, 0xc1, 0x99, 0xeb, 0x05, + 0x41, 0x06, 0x09, 0x91, 0x96, 0x14, 0xa1, 0xdb, 0xec, 0x4b, 0x9f, 0x3f, 0xed, 0x6d, 0xf0, 0x79, + 0x7b, 0x4c, 0xb1, 0x69, 0x86, 0x92, 0xd0, 0x6a, 0xcf, 0x2c, 0x3c, 0x2e, 0x3e, 0x03, 0x35, 0x2f, + 0xc6, 0x79, 0x42, 0xa5, 0x9a, 0x22, 0x74, 0x5b, 0x07, 0x9b, 0x2a, 0x37, 0x16, 0xa7, 0xaa, 0xf2, + 0x53, 0x55, 0x75, 0x8c, 0x92, 0x7e, 0xf5, 0xfa, 0xeb, 0x76, 0xc5, 0xe2, 0xb8, 0xf8, 0x02, 0xac, + 0x9e, 0xa1, 0x24, 0x81, 0xf3, 0xe2, 0xf5, 0x3f, 0x14, 0x5f, 0x61, 0xfc, 0xb4, 0xf2, 0x16, 0x00, + 0x88, 0xb8, 0x24, 0xc5, 0x09, 0xc1, 0x99, 0xd4, 0x50, 0x84, 0x6e, 0xc3, 0x6a, 0x22, 0x62, 0xb3, + 0x80, 0xb8, 0x0b, 0xd6, 0xfd, 0x0c, 0x7a, 0x14, 0x06, 0xae, 0x47, 0xdd, 0x09, 0x44, 0xe1, 0x84, + 0x4a, 0x40, 0x11, 0xba, 0x8b, 0xd6, 0x1a, 0x17, 0x7a, 0xf4, 0x65, 0x19, 0x2e, 0xd8, 0x3c, 0x0d, + 0x7e, 0x61, 0x5b, 0x8c, 0xe5, 0xc2, 0x8c, 0xd5, 0x01, 0x98, 0xe7, 0x95, 0x96, 0xcb, 0xa1, 0x3b, + 0x2a, 0x7b, 0x6b, 0xea, 0xf4, 0xad, 0xa9, 0xce, 0xf4, 0xad, 0xf5, 0x1b, 0xc5, 0xd4, 0x97, 0xdf, + 0xb6, 0x05, 0xab, 0x39, 0x2b, 0x5b, 0x24, 0x99, 0x17, 0x94, 0x56, 0xfe, 0x25, 0xc9, 0xac, 0x9f, + 0x57, 0xd5, 0x46, 0xb3, 0x0d, 0x76, 0x7f, 0x08, 0x60, 0xf9, 0xfe, 0x25, 0x8b, 0x2a, 0xd8, 0x1c, + 0x18, 0x27, 0xaf, 0x6d, 0xd3, 0x71, 0x6d, 0xa7, 0xe7, 0x18, 0xee, 0xe8, 0xd8, 0x3e, 0x31, 0x74, + 0x73, 0x68, 0x1a, 0x83, 0x76, 0xa5, 0xb3, 0x76, 0x71, 0xa5, 0xb4, 0x46, 0x09, 0x49, 0xa1, 0x8f, + 0x4e, 0x11, 0x0c, 0x44, 0x0d, 0x74, 0x1e, 0xf2, 0x66, 0x5f, 0x77, 0x1d, 0xab, 0x77, 0x6c, 0x0f, + 0x0d, 0xab, 0x2d, 0x30, 0x83, 0x39, 0xf6, 0x9d, 0xcc, 0x4b, 0xc8, 0x29, 0xcc, 0x1e, 0x31, 0xe8, + 0x3d, 0x77, 0x60, 0x1c, 0x19, 0x87, 0x3d, 0xc7, 0x68, 0x2f, 0x70, 0x83, 0xef, 0x0d, 0x60, 0x04, + 0xc3, 0xa2, 0xa3, 0x27, 0xe0, 0xbf, 0x87, 0x06, 0x7b, 0xa4, 0xeb, 0x86, 0x6d, 0xb7, 0x17, 0x3b, + 0xad, 0x8b, 0x2b, 0xa5, 0x6e, 0xe7, 0xbe, 0x5f, 0xdc, 0xe8, 0x6f, 0xdc, 0xb0, 0x67, 0x1e, 0x8d, + 0x2c, 0xa3, 0x5d, 0x65, 0xdc, 0xd0, 0x43, 0x51, 0x9e, 0xc1, 0x4e, 0xf5, 0xfc, 0xa3, 0x2c, 0xf4, + 0x0f, 0xaf, 0x6f, 0x65, 0xe1, 0xe6, 0x56, 0x16, 0xbe, 0xdf, 0xca, 0xc2, 0xe5, 0x9d, 0x5c, 0xb9, + 0xb9, 0x93, 0x2b, 0x5f, 0xee, 0xe4, 0xca, 0x9b, 0xbd, 0x10, 0xd1, 0x49, 0x3e, 0x56, 0x7d, 0x1c, + 0x6b, 0xf7, 0x3f, 0x15, 0x7f, 0xe2, 0xa1, 0x44, 0x7b, 0x3f, 0xff, 0x5c, 0xe8, 0x87, 0x14, 0x92, + 0x71, 0xad, 0x3c, 0xf0, 0xa7, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x45, 0x1b, 0xc1, 0x8c, 0x81, + 0x04, 0x00, 0x00, +} + +func (m *Deposit) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Deposit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Deposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpdatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintDeposit(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x6a + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintDeposit(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x62 + if m.UpdatedAtHeight != 0 { + i = encodeVarintDeposit(dAtA, i, uint64(m.UpdatedAtHeight)) + i-- + dAtA[i] = 0x58 + } + if m.CreatedAtHeight != 0 { + i = encodeVarintDeposit(dAtA, i, uint64(m.CreatedAtHeight)) + i-- + dAtA[i] = 0x50 + } + if m.IsSponsor { + i-- + if m.IsSponsor { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x40 + } + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintDeposit(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0x3a + } + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDeposit(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintDeposit(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0x2a + } + if m.ErrorState != 0 { + i = encodeVarintDeposit(dAtA, i, uint64(m.ErrorState)) + i-- + dAtA[i] = 0x20 + } + if m.State != 0 { + i = encodeVarintDeposit(dAtA, i, uint64(m.State)) + i-- + dAtA[i] = 0x18 + } + if m.DepositId != 0 { + i = encodeVarintDeposit(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintDeposit(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintDeposit(dAtA []byte, offset int, v uint64) int { + offset -= sovDeposit(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Deposit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovDeposit(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovDeposit(uint64(m.DepositId)) + } + if m.State != 0 { + n += 1 + sovDeposit(uint64(m.State)) + } + if m.ErrorState != 0 { + n += 1 + sovDeposit(uint64(m.ErrorState)) + } + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovDeposit(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovDeposit(uint64(l)) + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovDeposit(uint64(l)) + } + if m.IsSponsor { + n += 2 + } + if m.CreatedAtHeight != 0 { + n += 1 + sovDeposit(uint64(m.CreatedAtHeight)) + } + if m.UpdatedAtHeight != 0 { + n += 1 + sovDeposit(uint64(m.UpdatedAtHeight)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) + n += 1 + l + sovDeposit(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt) + n += 1 + l + sovDeposit(uint64(l)) + return n +} + +func sovDeposit(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDeposit(x uint64) (n int) { + return sovDeposit(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Deposit) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Deposit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Deposit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + m.State = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.State |= DepositState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ErrorState", wireType) + } + m.ErrorState = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ErrorState |= DepositState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDeposit + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDeposit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDeposit + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDeposit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDeposit + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDeposit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsSponsor", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsSponsor = bool(v != 0) + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) + } + m.CreatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAtHeight", wireType) + } + m.UpdatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDeposit + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDeposit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDeposit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDeposit + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDeposit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.UpdatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDeposit(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDeposit + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthDeposit + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDeposit(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDeposit + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDeposit + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDeposit + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDeposit + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDeposit + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDeposit + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDeposit = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDeposit = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDeposit = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/draw.go b/x/millions/types/draw.go new file mode 100644 index 00000000..95047eda --- /dev/null +++ b/x/millions/types/draw.go @@ -0,0 +1,17 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +// ValidateDrawRetryBasic validates the incoming message for a draw retry +func (msg *MsgDrawRetry) ValidateDrawRetryBasic() error { + if msg.PoolId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "pool ID") + } + if msg.DrawId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "draw ID") + } + + return nil +} diff --git a/x/millions/types/draw.pb.go b/x/millions/types/draw.pb.go new file mode 100644 index 00000000..2f2f8bf2 --- /dev/null +++ b/x/millions/types/draw.pb.go @@ -0,0 +1,1005 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/draw.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type DrawState int32 + +const ( + DrawState_Unspecified DrawState = 0 + DrawState_IcaWithdrawRewards DrawState = 1 + DrawState_IcqBalance DrawState = 2 + DrawState_IbcTransfer DrawState = 3 + DrawState_Drawing DrawState = 4 + DrawState_Success DrawState = 5 + DrawState_Failure DrawState = 6 +) + +var DrawState_name = map[int32]string{ + 0: "DRAW_STATE_UNSPECIFIED", + 1: "DRAW_STATE_ICA_WITHDRAWREWARDS", + 2: "DRAW_STATE_QUERY_BALANCE", + 3: "DRAW_STATE_IBC_TRANSFER", + 4: "DRAW_STATE_DRAWING", + 5: "DRAW_STATE_SUCCESS", + 6: "DRAW_STATE_FAILURE", +} + +var DrawState_value = map[string]int32{ + "DRAW_STATE_UNSPECIFIED": 0, + "DRAW_STATE_ICA_WITHDRAWREWARDS": 1, + "DRAW_STATE_QUERY_BALANCE": 2, + "DRAW_STATE_IBC_TRANSFER": 3, + "DRAW_STATE_DRAWING": 4, + "DRAW_STATE_SUCCESS": 5, + "DRAW_STATE_FAILURE": 6, +} + +func (x DrawState) String() string { + return proto.EnumName(DrawState_name, int32(x)) +} + +func (DrawState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d950767559d38481, []int{0} +} + +type Draw struct { + // Draw IDs + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + // Draw states + // error_state is only set in case of failure + State DrawState `protobuf:"varint,3,opt,name=state,proto3,enum=lum.network.millions.DrawState" json:"state,omitempty"` + ErrorState DrawState `protobuf:"varint,4,opt,name=error_state,json=errorState,proto3,enum=lum.network.millions.DrawState" json:"error_state,omitempty"` + // Draw state done data + RandSeed int64 `protobuf:"varint,5,opt,name=rand_seed,json=randSeed,proto3" json:"rand_seed,omitempty"` + PrizePool types.Coin `protobuf:"bytes,6,opt,name=prize_pool,json=prizePool,proto3" json:"prize_pool"` + PrizePoolFreshAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=prize_pool_fresh_amount,json=prizePoolFreshAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"prize_pool_fresh_amount"` + PrizePoolRemainsAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,8,opt,name=prize_pool_remains_amount,json=prizePoolRemainsAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"prize_pool_remains_amount"` + PrizesRefs []PrizeRef `protobuf:"bytes,11,rep,name=prizes_refs,json=prizesRefs,proto3" json:"prizes_refs"` + TotalWinCount uint64 `protobuf:"varint,12,opt,name=total_win_count,json=totalWinCount,proto3" json:"total_win_count,omitempty"` + TotalWinAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,13,opt,name=total_win_amount,json=totalWinAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"total_win_amount"` + // Draw creation and updates + CreatedAtHeight int64 `protobuf:"varint,15,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` + UpdatedAtHeight int64 `protobuf:"varint,16,opt,name=updated_at_height,json=updatedAtHeight,proto3" json:"updated_at_height,omitempty"` + CreatedAt time.Time `protobuf:"bytes,17,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` + UpdatedAt time.Time `protobuf:"bytes,18,opt,name=updated_at,json=updatedAt,proto3,stdtime" json:"updated_at"` +} + +func (m *Draw) Reset() { *m = Draw{} } +func (m *Draw) String() string { return proto.CompactTextString(m) } +func (*Draw) ProtoMessage() {} +func (*Draw) Descriptor() ([]byte, []int) { + return fileDescriptor_d950767559d38481, []int{0} +} +func (m *Draw) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Draw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Draw.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Draw) XXX_Merge(src proto.Message) { + xxx_messageInfo_Draw.Merge(m, src) +} +func (m *Draw) XXX_Size() int { + return m.Size() +} +func (m *Draw) XXX_DiscardUnknown() { + xxx_messageInfo_Draw.DiscardUnknown(m) +} + +var xxx_messageInfo_Draw proto.InternalMessageInfo + +func (m *Draw) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *Draw) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *Draw) GetState() DrawState { + if m != nil { + return m.State + } + return DrawState_Unspecified +} + +func (m *Draw) GetErrorState() DrawState { + if m != nil { + return m.ErrorState + } + return DrawState_Unspecified +} + +func (m *Draw) GetRandSeed() int64 { + if m != nil { + return m.RandSeed + } + return 0 +} + +func (m *Draw) GetPrizePool() types.Coin { + if m != nil { + return m.PrizePool + } + return types.Coin{} +} + +func (m *Draw) GetPrizesRefs() []PrizeRef { + if m != nil { + return m.PrizesRefs + } + return nil +} + +func (m *Draw) GetTotalWinCount() uint64 { + if m != nil { + return m.TotalWinCount + } + return 0 +} + +func (m *Draw) GetCreatedAtHeight() int64 { + if m != nil { + return m.CreatedAtHeight + } + return 0 +} + +func (m *Draw) GetUpdatedAtHeight() int64 { + if m != nil { + return m.UpdatedAtHeight + } + return 0 +} + +func (m *Draw) GetCreatedAt() time.Time { + if m != nil { + return m.CreatedAt + } + return time.Time{} +} + +func (m *Draw) GetUpdatedAt() time.Time { + if m != nil { + return m.UpdatedAt + } + return time.Time{} +} + +func init() { + proto.RegisterEnum("lum.network.millions.DrawState", DrawState_name, DrawState_value) + proto.RegisterType((*Draw)(nil), "lum.network.millions.Draw") +} + +func init() { proto.RegisterFile("lum-network/millions/draw.proto", fileDescriptor_d950767559d38481) } + +var fileDescriptor_d950767559d38481 = []byte{ + // 829 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcd, 0x6e, 0xdb, 0x46, + 0x10, 0xc7, 0x45, 0x5b, 0xb6, 0xa5, 0x55, 0x63, 0x31, 0x84, 0x61, 0x33, 0x2a, 0x40, 0x11, 0x6d, + 0x11, 0x08, 0x69, 0x4c, 0x22, 0x2e, 0x7a, 0xe9, 0xa1, 0x28, 0x45, 0x53, 0x09, 0x8d, 0xc0, 0x70, + 0x97, 0x12, 0xd4, 0xf6, 0x42, 0xac, 0xc8, 0x95, 0xb4, 0x08, 0xc9, 0x55, 0x77, 0x57, 0x55, 0xdb, + 0x27, 0x28, 0x7c, 0xca, 0x0b, 0xe8, 0xd4, 0x67, 0x29, 0x90, 0x63, 0x8e, 0x45, 0x0f, 0x69, 0x61, + 0xbf, 0x48, 0xb1, 0x24, 0xf5, 0x01, 0xc3, 0x87, 0xd6, 0x27, 0xee, 0xee, 0xfc, 0x66, 0xfe, 0x33, + 0xb3, 0x3b, 0x04, 0xed, 0x64, 0x9e, 0x9e, 0x66, 0x58, 0x2c, 0x28, 0x7b, 0x63, 0xa7, 0x24, 0x49, + 0x08, 0xcd, 0xb8, 0x1d, 0x33, 0xb4, 0xb0, 0x66, 0x8c, 0x0a, 0xaa, 0x1d, 0x25, 0xf3, 0xd4, 0x2a, + 0x01, 0x6b, 0x05, 0xb4, 0x8c, 0x88, 0xf2, 0x94, 0x72, 0x7b, 0x84, 0x38, 0xb6, 0x7f, 0x7a, 0x31, + 0xc2, 0x02, 0xbd, 0xb0, 0x23, 0x4a, 0xb2, 0xc2, 0xab, 0x75, 0x34, 0xa1, 0x13, 0x9a, 0x2f, 0x6d, + 0xb9, 0x2a, 0x4f, 0xdb, 0x13, 0x4a, 0x27, 0x09, 0xb6, 0xf3, 0xdd, 0x68, 0x3e, 0xb6, 0x05, 0x49, + 0x31, 0x17, 0x28, 0x9d, 0x95, 0xc0, 0x67, 0xf7, 0x66, 0x33, 0x63, 0xe4, 0x57, 0x1c, 0x32, 0x3c, + 0x2e, 0xa8, 0x4f, 0x96, 0x07, 0xa0, 0x7a, 0xce, 0xd0, 0x42, 0x3b, 0x01, 0x07, 0x33, 0x4a, 0x93, + 0x90, 0xc4, 0xba, 0x62, 0x2a, 0x9d, 0x2a, 0xdc, 0x97, 0x5b, 0x3f, 0x96, 0x06, 0x59, 0x82, 0x34, + 0xec, 0x14, 0x06, 0xb9, 0xf5, 0x63, 0xed, 0x4b, 0xb0, 0xc7, 0x05, 0x12, 0x58, 0xdf, 0x35, 0x95, + 0xce, 0xe1, 0x59, 0xdb, 0xba, 0xaf, 0x3a, 0x4b, 0x06, 0x0f, 0x24, 0x06, 0x0b, 0x5a, 0xfb, 0x06, + 0x34, 0x30, 0x63, 0x94, 0x85, 0x85, 0x73, 0xf5, 0xbf, 0x39, 0x83, 0xdc, 0x27, 0x5f, 0x6b, 0x1f, + 0x83, 0x3a, 0x43, 0x59, 0x1c, 0x72, 0x8c, 0x63, 0x7d, 0xcf, 0x54, 0x3a, 0xbb, 0xb0, 0x26, 0x0f, + 0x02, 0x8c, 0x63, 0xed, 0x6b, 0x00, 0x8a, 0x1a, 0x65, 0xfa, 0xfa, 0xbe, 0xa9, 0x74, 0x1a, 0x67, + 0x4f, 0xac, 0xa2, 0xc5, 0x96, 0x6c, 0xb1, 0x55, 0xb6, 0xd8, 0x72, 0x29, 0xc9, 0xba, 0xd5, 0x77, + 0x1f, 0xda, 0x15, 0x58, 0xcf, 0x5d, 0xae, 0x28, 0x4d, 0x34, 0x0c, 0x4e, 0x36, 0xfe, 0xe1, 0x98, + 0x61, 0x3e, 0x0d, 0x51, 0x4a, 0xe7, 0x99, 0xd0, 0x0f, 0x4c, 0xa5, 0x53, 0xef, 0x5a, 0xd2, 0xe3, + 0xaf, 0x0f, 0xed, 0xa7, 0x13, 0x22, 0xa6, 0xf3, 0x91, 0x15, 0xd1, 0xd4, 0x2e, 0x6f, 0xb0, 0xf8, + 0x9c, 0xf2, 0xf8, 0x8d, 0x2d, 0x7e, 0x99, 0x61, 0x6e, 0xf9, 0x99, 0x80, 0x47, 0xeb, 0xd8, 0x3d, + 0x19, 0xcc, 0xc9, 0x63, 0x69, 0x04, 0x3c, 0xd9, 0x92, 0x61, 0x38, 0x45, 0x24, 0xe3, 0x2b, 0xa1, + 0xda, 0x83, 0x84, 0x8e, 0xd7, 0x42, 0xb0, 0x08, 0x57, 0x4a, 0x79, 0xa0, 0x91, 0x5b, 0xb8, 0xbc, + 0x76, 0xae, 0x37, 0xcc, 0xdd, 0x4e, 0xe3, 0xcc, 0xb8, 0xbf, 0xe1, 0x57, 0x12, 0x84, 0x78, 0x5c, + 0xf6, 0xa5, 0x68, 0x25, 0x87, 0x78, 0xcc, 0xb5, 0xa7, 0xa0, 0x29, 0xa8, 0x40, 0x49, 0xb8, 0x20, + 0x59, 0x18, 0xe5, 0x79, 0x7e, 0x94, 0xbf, 0x87, 0x47, 0xf9, 0xf1, 0x90, 0x64, 0x6e, 0x2e, 0xf7, + 0x1d, 0x50, 0x37, 0x5c, 0x59, 0xd0, 0xa3, 0x07, 0x15, 0x74, 0xb8, 0x0a, 0x5c, 0x16, 0xf2, 0x0c, + 0x3c, 0x8e, 0x18, 0x46, 0x02, 0xc7, 0x21, 0x12, 0xe1, 0x14, 0x93, 0xc9, 0x54, 0xe8, 0xcd, 0xfc, + 0xfe, 0x9b, 0xa5, 0xc1, 0x11, 0xaf, 0xf2, 0x63, 0xc9, 0xce, 0x67, 0xf1, 0x1d, 0x56, 0x2d, 0xd8, + 0xd2, 0xb0, 0x66, 0x5d, 0x00, 0x36, 0x71, 0xf5, 0xc7, 0xf9, 0x93, 0x69, 0x59, 0xc5, 0x7c, 0x59, + 0xab, 0xf9, 0xb2, 0xfa, 0xab, 0xf9, 0xea, 0xd6, 0x64, 0x1d, 0x6f, 0xff, 0x6e, 0x2b, 0xb0, 0xbe, + 0x96, 0x95, 0x41, 0x36, 0x82, 0xba, 0xf6, 0x7f, 0x82, 0xac, 0xf3, 0xb9, 0xa8, 0xd6, 0xea, 0x2a, + 0xb8, 0xa8, 0xd6, 0x80, 0xda, 0xb8, 0xa8, 0xd6, 0x0e, 0xd5, 0xe6, 0xb3, 0x3f, 0x76, 0x40, 0x7d, + 0x3d, 0x05, 0xda, 0xe7, 0xe0, 0xf8, 0x1c, 0x3a, 0xc3, 0x30, 0xe8, 0x3b, 0x7d, 0x2f, 0x1c, 0x5c, + 0x06, 0x57, 0x9e, 0xeb, 0xf7, 0x7c, 0xef, 0x5c, 0xad, 0xb4, 0x9a, 0xd7, 0x4b, 0xb3, 0x31, 0xc8, + 0xf8, 0x0c, 0x47, 0x64, 0x4c, 0x70, 0xac, 0x7d, 0x05, 0x8c, 0x2d, 0xd8, 0x77, 0x9d, 0x70, 0xe8, + 0xf7, 0x5f, 0xc9, 0x23, 0xe8, 0x0d, 0x1d, 0x78, 0x1e, 0xa8, 0x4a, 0xeb, 0xf8, 0x7a, 0x69, 0x6a, + 0x7e, 0x84, 0x86, 0x44, 0x4c, 0xe5, 0x58, 0x43, 0xbc, 0x40, 0x2c, 0xe6, 0xda, 0x73, 0xa0, 0x6f, + 0xf9, 0x7e, 0x3b, 0xf0, 0xe0, 0xf7, 0x61, 0xd7, 0x79, 0xed, 0x5c, 0xba, 0x9e, 0xba, 0xd3, 0x3a, + 0xbc, 0x5e, 0x9a, 0xc0, 0x8f, 0x7e, 0xec, 0xa2, 0x04, 0x65, 0x11, 0xd6, 0x9e, 0x83, 0x93, 0x6d, + 0xa5, 0xae, 0x1b, 0xf6, 0xa1, 0x73, 0x19, 0xf4, 0x3c, 0xa8, 0xee, 0x16, 0x79, 0xf9, 0xa3, 0xa8, + 0xcf, 0x50, 0xc6, 0xc7, 0x98, 0x69, 0x9f, 0x02, 0x6d, 0x8b, 0x96, 0x4b, 0xff, 0xf2, 0xa5, 0x5a, + 0x6d, 0x35, 0xae, 0x97, 0xe6, 0x81, 0xac, 0x95, 0x64, 0x93, 0x3b, 0x50, 0x30, 0x70, 0x5d, 0x2f, + 0x08, 0xd4, 0xbd, 0x02, 0x0a, 0xe6, 0x51, 0x84, 0x39, 0xbf, 0x03, 0xf5, 0x1c, 0xff, 0xf5, 0x00, + 0x7a, 0xea, 0x7e, 0x01, 0xf5, 0x10, 0x49, 0xe6, 0x0c, 0xb7, 0xaa, 0xbf, 0xfd, 0x6e, 0x28, 0xdd, + 0x97, 0xef, 0x6e, 0x0c, 0xe5, 0xfd, 0x8d, 0xa1, 0xfc, 0x73, 0x63, 0x28, 0x6f, 0x6f, 0x8d, 0xca, + 0xfb, 0x5b, 0xa3, 0xf2, 0xe7, 0xad, 0x51, 0xf9, 0xe1, 0x74, 0xeb, 0x35, 0x6e, 0xff, 0x32, 0xa3, + 0x29, 0x22, 0x99, 0xfd, 0xf3, 0xe6, 0xd7, 0x99, 0x3f, 0xcc, 0xd1, 0x7e, 0x7e, 0x97, 0x5f, 0xfc, + 0x1b, 0x00, 0x00, 0xff, 0xff, 0x1a, 0x2d, 0xb5, 0x81, 0xed, 0x05, 0x00, 0x00, +} + +func (m *Draw) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Draw) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Draw) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpdatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintDraw(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x92 + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintDraw(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x8a + if m.UpdatedAtHeight != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.UpdatedAtHeight)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x80 + } + if m.CreatedAtHeight != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.CreatedAtHeight)) + i-- + dAtA[i] = 0x78 + } + { + size := m.TotalWinAmount.Size() + i -= size + if _, err := m.TotalWinAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDraw(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x6a + if m.TotalWinCount != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.TotalWinCount)) + i-- + dAtA[i] = 0x60 + } + if len(m.PrizesRefs) > 0 { + for iNdEx := len(m.PrizesRefs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PrizesRefs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDraw(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a + } + } + { + size := m.PrizePoolRemainsAmount.Size() + i -= size + if _, err := m.PrizePoolRemainsAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDraw(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + { + size := m.PrizePoolFreshAmount.Size() + i -= size + if _, err := m.PrizePoolFreshAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDraw(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + size, err := m.PrizePool.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDraw(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if m.RandSeed != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.RandSeed)) + i-- + dAtA[i] = 0x28 + } + if m.ErrorState != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.ErrorState)) + i-- + dAtA[i] = 0x20 + } + if m.State != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.State)) + i-- + dAtA[i] = 0x18 + } + if m.DrawId != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintDraw(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintDraw(dAtA []byte, offset int, v uint64) int { + offset -= sovDraw(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Draw) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovDraw(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovDraw(uint64(m.DrawId)) + } + if m.State != 0 { + n += 1 + sovDraw(uint64(m.State)) + } + if m.ErrorState != 0 { + n += 1 + sovDraw(uint64(m.ErrorState)) + } + if m.RandSeed != 0 { + n += 1 + sovDraw(uint64(m.RandSeed)) + } + l = m.PrizePool.Size() + n += 1 + l + sovDraw(uint64(l)) + l = m.PrizePoolFreshAmount.Size() + n += 1 + l + sovDraw(uint64(l)) + l = m.PrizePoolRemainsAmount.Size() + n += 1 + l + sovDraw(uint64(l)) + if len(m.PrizesRefs) > 0 { + for _, e := range m.PrizesRefs { + l = e.Size() + n += 1 + l + sovDraw(uint64(l)) + } + } + if m.TotalWinCount != 0 { + n += 1 + sovDraw(uint64(m.TotalWinCount)) + } + l = m.TotalWinAmount.Size() + n += 1 + l + sovDraw(uint64(l)) + if m.CreatedAtHeight != 0 { + n += 1 + sovDraw(uint64(m.CreatedAtHeight)) + } + if m.UpdatedAtHeight != 0 { + n += 2 + sovDraw(uint64(m.UpdatedAtHeight)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) + n += 2 + l + sovDraw(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt) + n += 2 + l + sovDraw(uint64(l)) + return n +} + +func sovDraw(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDraw(x uint64) (n int) { + return sovDraw(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Draw) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Draw: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Draw: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + m.State = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.State |= DrawState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ErrorState", wireType) + } + m.ErrorState = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ErrorState |= DrawState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RandSeed", wireType) + } + m.RandSeed = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RandSeed |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizePool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PrizePool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizePoolFreshAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PrizePoolFreshAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizePoolRemainsAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PrizePoolRemainsAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizesRefs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrizesRefs = append(m.PrizesRefs, PrizeRef{}) + if err := m.PrizesRefs[len(m.PrizesRefs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalWinCount", wireType) + } + m.TotalWinCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TotalWinCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalWinAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalWinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) + } + m.CreatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 16: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAtHeight", wireType) + } + m.UpdatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 17: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 18: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDraw + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDraw + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDraw + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.UpdatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDraw(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDraw + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthDraw + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDraw(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDraw + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDraw + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDraw + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDraw + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDraw + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDraw + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDraw = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDraw = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDraw = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/draw_schedule.go b/x/millions/types/draw_schedule.go new file mode 100644 index 00000000..412feb03 --- /dev/null +++ b/x/millions/types/draw_schedule.go @@ -0,0 +1,64 @@ +package types + +import ( + "fmt" + time "time" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (ps DrawSchedule) ValidateBasic(params Params) error { + if ps.DrawDelta < params.MinDrawScheduleDelta { + return fmt.Errorf("draw delta cannot be lower than %s", params.MinDrawScheduleDelta.String()) + } + if ps.DrawDelta > params.MaxDrawScheduleDelta { + return fmt.Errorf("draw delta cannot be higher than %s", params.MaxDrawScheduleDelta.String()) + } + return nil +} + +// ValidateNew drawSchedule validation at pool creation time +func (ps DrawSchedule) ValidateNew(ctx sdk.Context, params Params) error { + if ps.DrawDelta < params.MinDrawScheduleDelta { + return fmt.Errorf("draw delta cannot be lower than %s", params.MinDrawScheduleDelta.String()) + } + if ps.DrawDelta > params.MaxDrawScheduleDelta { + return fmt.Errorf("draw delta cannot be higher than %s", params.MaxDrawScheduleDelta.String()) + } + if ps.InitialDrawAt.Before(ctx.BlockTime().Add(ps.DrawDelta)) { + return fmt.Errorf("initial draw must be in the future and at least after draw delta") + } + return nil +} + +// sanitizeTime returns the time rounded to the minute +func (ps DrawSchedule) sanitizeTime(t time.Time) time.Time { + return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), 0, 0, t.Location()) +} + +// Sanitized returns the draw schedule with time rounded to the minute +func (ps DrawSchedule) Sanitized() DrawSchedule { + return DrawSchedule{ + InitialDrawAt: ps.sanitizeTime(ps.GetInitialDrawAt()), + DrawDelta: ps.GetDrawDelta(), + } +} + +// ShouldDraw returns whether or not the current block time is past the next draw time (= time to launch draw) +func (ps DrawSchedule) ShouldDraw(ctx sdk.Context, lastDrawAt *time.Time) bool { + if lastDrawAt == nil { + return !ctx.BlockTime().Before(ps.InitialDrawAt) + } + // Simulate lda as if it did run at the appropriate minute to prevent small time drifts + saneLda := time.Date( + lastDrawAt.Year(), + lastDrawAt.Month(), + lastDrawAt.Day(), + lastDrawAt.Hour(), + ps.InitialDrawAt.Minute(), + 0, + 0, + lastDrawAt.Location(), + ) + return !ctx.BlockTime().Before(saneLda.Add(ps.DrawDelta)) +} diff --git a/x/millions/types/draw_schedule.pb.go b/x/millions/types/draw_schedule.pb.go new file mode 100644 index 00000000..18bbbaa9 --- /dev/null +++ b/x/millions/types/draw_schedule.pb.go @@ -0,0 +1,384 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/draw_schedule.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type DrawSchedule struct { + InitialDrawAt time.Time `protobuf:"bytes,1,opt,name=initial_draw_at,json=initialDrawAt,proto3,stdtime" json:"initial_draw_at"` + DrawDelta time.Duration `protobuf:"bytes,2,opt,name=draw_delta,json=drawDelta,proto3,stdduration" json:"draw_delta"` +} + +func (m *DrawSchedule) Reset() { *m = DrawSchedule{} } +func (m *DrawSchedule) String() string { return proto.CompactTextString(m) } +func (*DrawSchedule) ProtoMessage() {} +func (*DrawSchedule) Descriptor() ([]byte, []int) { + return fileDescriptor_41b134257d72f380, []int{0} +} +func (m *DrawSchedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DrawSchedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DrawSchedule.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DrawSchedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_DrawSchedule.Merge(m, src) +} +func (m *DrawSchedule) XXX_Size() int { + return m.Size() +} +func (m *DrawSchedule) XXX_DiscardUnknown() { + xxx_messageInfo_DrawSchedule.DiscardUnknown(m) +} + +var xxx_messageInfo_DrawSchedule proto.InternalMessageInfo + +func (m *DrawSchedule) GetInitialDrawAt() time.Time { + if m != nil { + return m.InitialDrawAt + } + return time.Time{} +} + +func (m *DrawSchedule) GetDrawDelta() time.Duration { + if m != nil { + return m.DrawDelta + } + return 0 +} + +func init() { + proto.RegisterType((*DrawSchedule)(nil), "lum.network.millions.DrawSchedule") +} + +func init() { + proto.RegisterFile("lum-network/millions/draw_schedule.proto", fileDescriptor_41b134257d72f380) +} + +var fileDescriptor_41b134257d72f380 = []byte{ + // 285 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x90, 0xb1, 0x4e, 0x84, 0x30, + 0x18, 0xc7, 0xa9, 0x83, 0x51, 0xd4, 0x98, 0x90, 0x1b, 0x4e, 0x86, 0x62, 0x9c, 0x6e, 0xb9, 0x36, + 0xd1, 0x27, 0x90, 0x90, 0xb8, 0x38, 0xa9, 0x93, 0xcb, 0xa5, 0x40, 0x85, 0xc6, 0x96, 0x12, 0xf8, + 0x1a, 0xf4, 0x2d, 0x6e, 0x74, 0xf4, 0x71, 0x6e, 0xbc, 0xd1, 0x49, 0x0d, 0xbc, 0x88, 0xa1, 0x40, + 0x34, 0xde, 0xd6, 0xe6, 0xfb, 0xfd, 0x7f, 0xdf, 0x3f, 0x9f, 0xbb, 0x90, 0x46, 0x2d, 0x0b, 0x0e, + 0x8d, 0xae, 0x9e, 0xa9, 0x12, 0x52, 0x0a, 0x5d, 0xd4, 0x34, 0xad, 0x58, 0xb3, 0xaa, 0x93, 0x9c, + 0xa7, 0x46, 0x72, 0x52, 0x56, 0x1a, 0xb4, 0x37, 0x93, 0x46, 0x91, 0x91, 0x24, 0x13, 0xe9, 0xcf, + 0x32, 0x9d, 0x69, 0x0b, 0xd0, 0xfe, 0x35, 0xb0, 0x3e, 0xce, 0xb4, 0xce, 0x24, 0xa7, 0xf6, 0x17, + 0x9b, 0x27, 0x9a, 0x9a, 0x8a, 0x81, 0xd0, 0xc5, 0x38, 0x0f, 0xfe, 0xcf, 0x41, 0x28, 0x5e, 0x03, + 0x53, 0xe5, 0x00, 0x5c, 0xbc, 0x23, 0xf7, 0x38, 0xaa, 0x58, 0x73, 0x3f, 0x76, 0xf0, 0x6e, 0xdd, + 0x53, 0x51, 0x08, 0x10, 0x4c, 0xae, 0x6c, 0x39, 0x06, 0x73, 0x74, 0x8e, 0x16, 0x47, 0x97, 0x3e, + 0x19, 0x5c, 0x64, 0x72, 0x91, 0x87, 0xc9, 0x15, 0x1e, 0x6c, 0x3e, 0x03, 0x67, 0xfd, 0x15, 0xa0, + 0xbb, 0x93, 0x31, 0xdc, 0x3b, 0xaf, 0xc1, 0x0b, 0x5d, 0xd7, 0x5a, 0x52, 0x2e, 0x81, 0xcd, 0xf7, + 0xac, 0xe8, 0x6c, 0x47, 0x14, 0x8d, 0xa5, 0x07, 0xcf, 0x5b, 0xef, 0x39, 0xec, 0x63, 0x51, 0x9f, + 0x0a, 0x6f, 0x36, 0x2d, 0x46, 0xdb, 0x16, 0xa3, 0xef, 0x16, 0xa3, 0x75, 0x87, 0x9d, 0x6d, 0x87, + 0x9d, 0x8f, 0x0e, 0x3b, 0x8f, 0xcb, 0x4c, 0x40, 0x6e, 0x62, 0x92, 0x68, 0x45, 0xff, 0x9e, 0x37, + 0xc9, 0x99, 0x28, 0xe8, 0xcb, 0xef, 0x99, 0xe1, 0xb5, 0xe4, 0x75, 0xbc, 0x6f, 0x17, 0x5e, 0xfd, + 0x04, 0x00, 0x00, 0xff, 0xff, 0x50, 0x72, 0x2d, 0xa2, 0x8b, 0x01, 0x00, 0x00, +} + +func (m *DrawSchedule) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DrawSchedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DrawSchedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.DrawDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.DrawDelta):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintDrawSchedule(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x12 + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.InitialDrawAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.InitialDrawAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintDrawSchedule(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintDrawSchedule(dAtA []byte, offset int, v uint64) int { + offset -= sovDrawSchedule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *DrawSchedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.InitialDrawAt) + n += 1 + l + sovDrawSchedule(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.DrawDelta) + n += 1 + l + sovDrawSchedule(uint64(l)) + return n +} + +func sovDrawSchedule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDrawSchedule(x uint64) (n int) { + return sovDrawSchedule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DrawSchedule) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrawSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DrawSchedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DrawSchedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InitialDrawAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrawSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDrawSchedule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDrawSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.InitialDrawAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrawSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDrawSchedule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDrawSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.DrawDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDrawSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDrawSchedule + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthDrawSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDrawSchedule(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDrawSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDrawSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDrawSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDrawSchedule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDrawSchedule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDrawSchedule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDrawSchedule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDrawSchedule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDrawSchedule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/errors.go b/x/millions/types/errors.go new file mode 100644 index 00000000..c4b19b36 --- /dev/null +++ b/x/millions/types/errors.go @@ -0,0 +1,47 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +var ( + ErrUnmarshalFailure = errorsmod.Register(ModuleName, 1001, "unable to unmarshal data structure") + ErrInvalidID = errorsmod.Register(ModuleName, 1002, "invalid unknown ID provided") + ErrEntityOverride = errorsmod.Register(ModuleName, 1003, "ID already exists") + ErrIllegalStateOperation = errorsmod.Register(ModuleName, 1004, "Operation not allowed for the entity state") + ErrInvalidParams = errorsmod.Register(ModuleName, 1005, "Invalid params") + ErrPoolNotFound = errorsmod.Register(ModuleName, 1100, "Pool not found") + ErrFailedToRegisterPool = errorsmod.Register(ModuleName, 1101, "Failed to register pool") + ErrPoolNotReady = errorsmod.Register(ModuleName, 1102, "Pool not ready") + ErrPoolKilled = errorsmod.Register(ModuleName, 1103, "Pool killed") + ErrInvalidPoolParams = errorsmod.Register(ModuleName, 1104, "Invalid pool params") + ErrPoolEmptySplitDelegations = errorsmod.Register(ModuleName, 1105, "Failed to compute split delegation") + ErrPoolInvalidSplit = errorsmod.Register(ModuleName, 1106, "Invalid split provided") + ErrFailedToUpdatePool = errorsmod.Register(ModuleName, 1107, "Failed to update pool") + ErrPoolIsLocal = errorsmod.Register(ModuleName, 1108, "Pool is local") + ErrFailedToRestorePool = errorsmod.Register(ModuleName, 1109, "Failed to restore pool") + ErrInvalidDepositAmount = errorsmod.Register(ModuleName, 1200, "Deposit amount must be positive") + ErrInvalidDepositDenom = errorsmod.Register(ModuleName, 1201, "Invalid deposit denom") + ErrInvalidDepositorAddress = errorsmod.Register(ModuleName, 1202, "Invalid depositor address") + ErrInsufficientFunds = errorsmod.Register(ModuleName, 1203, "Insufficient funds") + ErrDepositNotFound = errorsmod.Register(ModuleName, 1204, "Deposit not found") + ErrInsufficientDepositAmount = errorsmod.Register(ModuleName, 1205, "Amount is less than minimum deposit amount") + ErrInvalidWinnerAddress = errorsmod.Register(ModuleName, 1206, "Invalid winner address") + ErrInvalidSponsorWinnerCombo = errorsmod.Register(ModuleName, 1207, "A sponsor cannot designate another winner address") + ErrInvalidDepositState = errorsmod.Register(ModuleName, 1208, "Deposit is in an invalid state") + ErrInvalidPoolAccountAddress = errorsmod.Register(ModuleName, 1209, "Invalid pool module account address") + ErrInvalidRestorerAddress = errorsmod.Register(ModuleName, 1210, "Invalid restorer address") + ErrPoolDrawNotFound = errorsmod.Register(ModuleName, 1300, "Pool draw not found") + ErrPoolDrawNotDone = errorsmod.Register(ModuleName, 1301, "Cannot launch a new draw until the previous one is done") + ErrInvalidDrawState = errorsmod.Register(ModuleName, 1302, "Invalid draw state") + ErrInvalidDrawRetryAddress = errorsmod.Register(ModuleName, 1303, "Invalid draw retry address") + ErrPrizeNotFound = errorsmod.Register(ModuleName, 1400, "Prize not found") + ErrInvalidPrizeState = errorsmod.Register(ModuleName, 1401, "Prize is in an invalid state") + ErrInvalidPrizeAmount = errorsmod.Register(ModuleName, 1402, "Prize amount cannot be less than 1") + ErrInvalidDestinationAddress = errorsmod.Register(ModuleName, 1500, "Invalid destination address") + ErrInvalidWithdrawalDepositorAddress = errorsmod.Register(ModuleName, 1600, "Invalid withdraw depositor address") + ErrDepositAlreadyWithdrawn = errorsmod.Register(ModuleName, 1601, "Deposit has already been withdrawn") + ErrInvalidWithdrawalState = errorsmod.Register(ModuleName, 1602, "Invalid withdrawal state") + ErrWithdrawalNotFound = errorsmod.Register(ModuleName, 1603, "Withdrawal not found") + ErrInvalidPacketCompletionTime = errorsmod.Register(ModuleName, 1604, "Invalid packet completion time for withdrawal undelegate") +) diff --git a/x/millions/types/events.go b/x/millions/types/events.go new file mode 100644 index 00000000..e30e9aef --- /dev/null +++ b/x/millions/types/events.go @@ -0,0 +1,28 @@ +package types + +const ( + EventTypeRegisterPool = "pool_new" + EventTypeUpdatePool = "pool_update" + EventTypeNewDraw = "draw_new" + EventTypeDrawSuccess = "draw_success" + EventTypeDeposit = "deposit" + EventTypeDepositRetry = "deposit_retry" + EventTypeNewPrize = "prize_new" + EventTypeClaimPrize = "prize_claim" + EventTypeClawbackPrize = "prize_clawback" + EventTypeWithdrawDeposit = "withdraw_deposit" + EventTypeWithdrawDepositRetry = "withdraw_deposit_retry" + + AttributeKeyPoolID = "pool_id" + AttributeKeyDrawID = "draw_id" + AttributeKeyPrizeID = "prize_id" + AttributeKeyDepositID = "deposit_id" + AttributeKeyWithdrawalID = "withdrawal_id" + AttributeKeyState = "state" + AttributeKeyDepositor = "depositor" + AttributeKeyWinner = "winner" + AttributeKeyRecipient = "recipient" + AttributeKeyPrizePool = "prize_pool" + AttributeKeyTotalWinners = "total_winners" + AttributeKeyTotalWinAmount = "total_win_amount" +) diff --git a/x/millions/types/genesis.go b/x/millions/types/genesis.go new file mode 100644 index 00000000..c3c60e68 --- /dev/null +++ b/x/millions/types/genesis.go @@ -0,0 +1,25 @@ +package types + +func NewGenesisState(params Params, nextPoolID uint64, nextDepositID uint64, nextPrizeID uint64, nexWithdrawalID uint64) *GenesisState { + return &GenesisState{ + Params: params, + NextPoolId: nextPoolID, + NextDepositId: nextDepositID, + NextPrizeId: nextPrizeID, + NextWithdrawalId: nexWithdrawalID, + } +} + +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + NextPoolId: 1, + NextDepositId: 1, + NextPrizeId: 1, + NextWithdrawalId: 1, + } +} + +func ValidateGenesis(data GenesisState) error { + return nil +} diff --git a/x/millions/types/genesis.pb.go b/x/millions/types/genesis.pb.go new file mode 100644 index 00000000..5393c440 --- /dev/null +++ b/x/millions/types/genesis.pb.go @@ -0,0 +1,791 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params" yaml:"params"` + NextPoolId uint64 `protobuf:"varint,2,opt,name=next_pool_id,json=nextPoolId,proto3" json:"next_pool_id,omitempty"` + NextDepositId uint64 `protobuf:"varint,3,opt,name=next_deposit_id,json=nextDepositId,proto3" json:"next_deposit_id,omitempty"` + NextPrizeId uint64 `protobuf:"varint,4,opt,name=next_prize_id,json=nextPrizeId,proto3" json:"next_prize_id,omitempty"` + NextWithdrawalId uint64 `protobuf:"varint,5,opt,name=next_withdrawal_id,json=nextWithdrawalId,proto3" json:"next_withdrawal_id,omitempty"` + Pools []Pool `protobuf:"bytes,6,rep,name=pools,proto3" json:"pools"` + Deposits []Deposit `protobuf:"bytes,7,rep,name=deposits,proto3" json:"deposits"` + Draws []Draw `protobuf:"bytes,8,rep,name=draws,proto3" json:"draws"` + Prizes []Prize `protobuf:"bytes,9,rep,name=prizes,proto3" json:"prizes"` + Withdrawals []Withdrawal `protobuf:"bytes,10,rep,name=withdrawals,proto3" json:"withdrawals"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_89b4a7e300e0ff3a, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetNextPoolId() uint64 { + if m != nil { + return m.NextPoolId + } + return 0 +} + +func (m *GenesisState) GetNextDepositId() uint64 { + if m != nil { + return m.NextDepositId + } + return 0 +} + +func (m *GenesisState) GetNextPrizeId() uint64 { + if m != nil { + return m.NextPrizeId + } + return 0 +} + +func (m *GenesisState) GetNextWithdrawalId() uint64 { + if m != nil { + return m.NextWithdrawalId + } + return 0 +} + +func (m *GenesisState) GetPools() []Pool { + if m != nil { + return m.Pools + } + return nil +} + +func (m *GenesisState) GetDeposits() []Deposit { + if m != nil { + return m.Deposits + } + return nil +} + +func (m *GenesisState) GetDraws() []Draw { + if m != nil { + return m.Draws + } + return nil +} + +func (m *GenesisState) GetPrizes() []Prize { + if m != nil { + return m.Prizes + } + return nil +} + +func (m *GenesisState) GetWithdrawals() []Withdrawal { + if m != nil { + return m.Withdrawals + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "lum.network.millions.GenesisState") +} + +func init() { + proto.RegisterFile("lum-network/millions/genesis.proto", fileDescriptor_89b4a7e300e0ff3a) +} + +var fileDescriptor_89b4a7e300e0ff3a = []byte{ + // 449 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x41, 0x6b, 0xd4, 0x40, + 0x14, 0xc7, 0x13, 0x9b, 0xc6, 0x3a, 0xe9, 0xa2, 0x0c, 0x15, 0xc2, 0xaa, 0xd9, 0x18, 0x50, 0xf6, + 0x60, 0x13, 0xa8, 0x20, 0xe8, 0x45, 0x58, 0x0a, 0x35, 0x78, 0x29, 0xeb, 0x41, 0xf0, 0x52, 0xa6, + 0xcd, 0x90, 0x1d, 0x9c, 0x64, 0x42, 0x66, 0x96, 0xb4, 0x7e, 0x0a, 0xbf, 0x88, 0xdf, 0xa3, 0xc7, + 0x1e, 0x3d, 0x15, 0xd9, 0xfd, 0x06, 0x7e, 0x82, 0xf2, 0x26, 0xd3, 0xa6, 0x87, 0xe9, 0xde, 0x86, + 0x37, 0xbf, 0xff, 0xff, 0xfd, 0xdf, 0xe3, 0xa1, 0x84, 0x2f, 0xab, 0xfd, 0x9a, 0xaa, 0x4e, 0xb4, + 0x3f, 0xb3, 0x8a, 0x71, 0xce, 0x44, 0x2d, 0xb3, 0x92, 0xd6, 0x54, 0x32, 0x99, 0x36, 0xad, 0x50, + 0x02, 0xef, 0xf1, 0x65, 0x95, 0x1a, 0x26, 0xbd, 0x65, 0xc6, 0x7b, 0xa5, 0x28, 0x85, 0x06, 0x32, + 0x78, 0xf5, 0xec, 0xd8, 0xee, 0x57, 0xd0, 0x46, 0x48, 0xa6, 0x0c, 0x33, 0xb1, 0x33, 0x2d, 0xe9, + 0x0c, 0xf0, 0xda, 0x0a, 0x34, 0xa4, 0x25, 0x95, 0xdc, 0xe8, 0xd1, 0x08, 0xc1, 0x0d, 0x10, 0xdb, + 0x81, 0x96, 0xfd, 0xa2, 0x86, 0x78, 0x63, 0x25, 0x3a, 0xa6, 0x16, 0x10, 0x85, 0x18, 0xa3, 0xe4, + 0x8f, 0x87, 0x76, 0x8f, 0xfa, 0x7d, 0x7c, 0x53, 0x44, 0x51, 0xfc, 0x15, 0xf9, 0x7d, 0x94, 0xd0, + 0x8d, 0xdd, 0x69, 0x70, 0xf0, 0x32, 0xb5, 0xed, 0x27, 0x3d, 0xd6, 0xcc, 0xec, 0xf9, 0xe5, 0xf5, + 0xc4, 0xf9, 0x7f, 0x3d, 0x19, 0x5d, 0x90, 0x8a, 0x7f, 0x4a, 0x7a, 0x65, 0x32, 0x37, 0x16, 0x38, + 0x46, 0xbb, 0x35, 0x3d, 0x57, 0x27, 0x90, 0xfc, 0x84, 0x15, 0xe1, 0xa3, 0xd8, 0x9d, 0x7a, 0x73, + 0x04, 0xb5, 0x63, 0x21, 0x78, 0x5e, 0xe0, 0xb7, 0xe8, 0xa9, 0x26, 0xcc, 0x0e, 0x01, 0xda, 0xd2, + 0xd0, 0x08, 0xca, 0x87, 0x7d, 0x35, 0x2f, 0x70, 0x82, 0x46, 0xbd, 0x13, 0x8c, 0x08, 0x94, 0xa7, + 0xa9, 0x40, 0x5b, 0x41, 0x2d, 0x2f, 0xf0, 0x3b, 0x84, 0x35, 0x33, 0x0c, 0x09, 0xe0, 0xb6, 0x06, + 0x9f, 0xc1, 0xcf, 0xf7, 0xbb, 0x8f, 0xbc, 0xc0, 0x1f, 0xd0, 0x36, 0xc4, 0x92, 0xa1, 0x1f, 0x6f, + 0x4d, 0x83, 0x83, 0xf1, 0x03, 0x73, 0x0a, 0xc1, 0x67, 0x1e, 0x4c, 0x39, 0xef, 0x71, 0xfc, 0x19, + 0xed, 0x98, 0xb0, 0x32, 0x7c, 0xac, 0xa5, 0xaf, 0xec, 0x52, 0x13, 0xde, 0xa8, 0xef, 0x44, 0xd0, + 0x18, 0x42, 0xc8, 0x70, 0x67, 0x53, 0xe3, 0xc3, 0x96, 0x74, 0xb7, 0x8d, 0x35, 0x8e, 0x3f, 0x22, + 0x5f, 0x4f, 0x2f, 0xc3, 0x27, 0x5a, 0xf8, 0xe2, 0x81, 0xc4, 0xc0, 0x18, 0xa5, 0x11, 0xe0, 0x2f, + 0x28, 0x18, 0x96, 0x22, 0x43, 0xa4, 0xf5, 0xb1, 0x5d, 0x3f, 0x2c, 0xc9, 0x98, 0xdc, 0x97, 0xce, + 0x8e, 0x2e, 0x57, 0x91, 0x7b, 0xb5, 0x8a, 0xdc, 0x7f, 0xab, 0xc8, 0xfd, 0xbd, 0x8e, 0x9c, 0xab, + 0x75, 0xe4, 0xfc, 0x5d, 0x47, 0xce, 0x8f, 0xfd, 0x92, 0xa9, 0xc5, 0xf2, 0x34, 0x3d, 0x13, 0x55, + 0x76, 0xff, 0xf6, 0xce, 0x16, 0x84, 0xd5, 0xd9, 0xf9, 0x70, 0x83, 0xea, 0xa2, 0xa1, 0xf2, 0xd4, + 0xd7, 0xf7, 0xf7, 0xfe, 0x26, 0x00, 0x00, 0xff, 0xff, 0xa2, 0x80, 0xfb, 0x69, 0xa3, 0x03, 0x00, + 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Withdrawals) > 0 { + for iNdEx := len(m.Withdrawals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Withdrawals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + } + } + if len(m.Prizes) > 0 { + for iNdEx := len(m.Prizes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Prizes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + } + } + if len(m.Draws) > 0 { + for iNdEx := len(m.Draws) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Draws[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + } + } + if len(m.Deposits) > 0 { + for iNdEx := len(m.Deposits) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Deposits[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + } + if len(m.Pools) > 0 { + for iNdEx := len(m.Pools) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Pools[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if m.NextWithdrawalId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextWithdrawalId)) + i-- + dAtA[i] = 0x28 + } + if m.NextPrizeId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextPrizeId)) + i-- + dAtA[i] = 0x20 + } + if m.NextDepositId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextDepositId)) + i-- + dAtA[i] = 0x18 + } + if m.NextPoolId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextPoolId)) + i-- + dAtA[i] = 0x10 + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if m.NextPoolId != 0 { + n += 1 + sovGenesis(uint64(m.NextPoolId)) + } + if m.NextDepositId != 0 { + n += 1 + sovGenesis(uint64(m.NextDepositId)) + } + if m.NextPrizeId != 0 { + n += 1 + sovGenesis(uint64(m.NextPrizeId)) + } + if m.NextWithdrawalId != 0 { + n += 1 + sovGenesis(uint64(m.NextWithdrawalId)) + } + if len(m.Pools) > 0 { + for _, e := range m.Pools { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Deposits) > 0 { + for _, e := range m.Deposits { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Draws) > 0 { + for _, e := range m.Draws { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Prizes) > 0 { + for _, e := range m.Prizes { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Withdrawals) > 0 { + for _, e := range m.Withdrawals { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextPoolId", wireType) + } + m.NextPoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextPoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextDepositId", wireType) + } + m.NextDepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextDepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextPrizeId", wireType) + } + m.NextPrizeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextPrizeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextWithdrawalId", wireType) + } + m.NextWithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextWithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pools", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Pools = append(m.Pools, Pool{}) + if err := m.Pools[len(m.Pools)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Deposits", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Deposits = append(m.Deposits, Deposit{}) + if err := m.Deposits[len(m.Deposits)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Draws", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Draws = append(m.Draws, Draw{}) + if err := m.Draws[len(m.Draws)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Prizes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Prizes = append(m.Prizes, Prize{}) + if err := m.Prizes[len(m.Prizes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Withdrawals", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Withdrawals = append(m.Withdrawals, Withdrawal{}) + if err := m.Withdrawals[len(m.Withdrawals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/gov.pb.go b/x/millions/types/gov.pb.go new file mode 100644 index 00000000..97294508 --- /dev/null +++ b/x/millions/types/gov.pb.go @@ -0,0 +1,2136 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/gov.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type ProposalRegisterPool struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Denom string `protobuf:"bytes,4,opt,name=denom,proto3" json:"denom,omitempty"` + NativeDenom string `protobuf:"bytes,5,opt,name=native_denom,json=nativeDenom,proto3" json:"native_denom,omitempty"` + ConnectionId string `protobuf:"bytes,6,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + Validators []string `protobuf:"bytes,7,rep,name=validators,proto3" json:"validators,omitempty"` + MinDepositAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,8,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount"` + DrawSchedule DrawSchedule `protobuf:"bytes,9,opt,name=draw_schedule,json=drawSchedule,proto3" json:"draw_schedule"` + PrizeStrategy PrizeStrategy `protobuf:"bytes,10,opt,name=prize_strategy,json=prizeStrategy,proto3" json:"prize_strategy"` + Bech32PrefixAccAddr string `protobuf:"bytes,11,opt,name=bech32_prefix_acc_addr,json=bech32PrefixAccAddr,proto3" json:"bech32_prefix_acc_addr,omitempty"` + Bech32PrefixValAddr string `protobuf:"bytes,12,opt,name=bech32_prefix_val_addr,json=bech32PrefixValAddr,proto3" json:"bech32_prefix_val_addr,omitempty"` + TransferChannelId string `protobuf:"bytes,13,opt,name=transfer_channel_id,json=transferChannelId,proto3" json:"transfer_channel_id,omitempty"` +} + +func (m *ProposalRegisterPool) Reset() { *m = ProposalRegisterPool{} } +func (*ProposalRegisterPool) ProtoMessage() {} +func (*ProposalRegisterPool) Descriptor() ([]byte, []int) { + return fileDescriptor_8678e5486331acc1, []int{0} +} +func (m *ProposalRegisterPool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProposalRegisterPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProposalRegisterPool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProposalRegisterPool) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProposalRegisterPool.Merge(m, src) +} +func (m *ProposalRegisterPool) XXX_Size() int { + return m.Size() +} +func (m *ProposalRegisterPool) XXX_DiscardUnknown() { + xxx_messageInfo_ProposalRegisterPool.DiscardUnknown(m) +} + +var xxx_messageInfo_ProposalRegisterPool proto.InternalMessageInfo + +func (m *ProposalRegisterPool) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *ProposalRegisterPool) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *ProposalRegisterPool) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *ProposalRegisterPool) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *ProposalRegisterPool) GetNativeDenom() string { + if m != nil { + return m.NativeDenom + } + return "" +} + +func (m *ProposalRegisterPool) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *ProposalRegisterPool) GetValidators() []string { + if m != nil { + return m.Validators + } + return nil +} + +func (m *ProposalRegisterPool) GetDrawSchedule() DrawSchedule { + if m != nil { + return m.DrawSchedule + } + return DrawSchedule{} +} + +func (m *ProposalRegisterPool) GetPrizeStrategy() PrizeStrategy { + if m != nil { + return m.PrizeStrategy + } + return PrizeStrategy{} +} + +func (m *ProposalRegisterPool) GetBech32PrefixAccAddr() string { + if m != nil { + return m.Bech32PrefixAccAddr + } + return "" +} + +func (m *ProposalRegisterPool) GetBech32PrefixValAddr() string { + if m != nil { + return m.Bech32PrefixValAddr + } + return "" +} + +func (m *ProposalRegisterPool) GetTransferChannelId() string { + if m != nil { + return m.TransferChannelId + } + return "" +} + +type ProposalUpdatePool struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + PoolId uint64 `protobuf:"varint,3,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Validators []string `protobuf:"bytes,4,rep,name=validators,proto3" json:"validators,omitempty"` + MinDepositAmount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount,omitempty"` + DrawSchedule *DrawSchedule `protobuf:"bytes,6,opt,name=draw_schedule,json=drawSchedule,proto3" json:"draw_schedule,omitempty"` + PrizeStrategy *PrizeStrategy `protobuf:"bytes,7,opt,name=prize_strategy,json=prizeStrategy,proto3" json:"prize_strategy,omitempty"` +} + +func (m *ProposalUpdatePool) Reset() { *m = ProposalUpdatePool{} } +func (*ProposalUpdatePool) ProtoMessage() {} +func (*ProposalUpdatePool) Descriptor() ([]byte, []int) { + return fileDescriptor_8678e5486331acc1, []int{1} +} +func (m *ProposalUpdatePool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProposalUpdatePool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProposalUpdatePool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProposalUpdatePool) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProposalUpdatePool.Merge(m, src) +} +func (m *ProposalUpdatePool) XXX_Size() int { + return m.Size() +} +func (m *ProposalUpdatePool) XXX_DiscardUnknown() { + xxx_messageInfo_ProposalUpdatePool.DiscardUnknown(m) +} + +var xxx_messageInfo_ProposalUpdatePool proto.InternalMessageInfo + +func (m *ProposalUpdatePool) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *ProposalUpdatePool) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *ProposalUpdatePool) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *ProposalUpdatePool) GetValidators() []string { + if m != nil { + return m.Validators + } + return nil +} + +func (m *ProposalUpdatePool) GetDrawSchedule() *DrawSchedule { + if m != nil { + return m.DrawSchedule + } + return nil +} + +func (m *ProposalUpdatePool) GetPrizeStrategy() *PrizeStrategy { + if m != nil { + return m.PrizeStrategy + } + return nil +} + +type ProposalUpdateParams struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + MinDepositAmount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount,omitempty"` + MaxPrizeStrategyBatches *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=max_prize_strategy_batches,json=maxPrizeStrategyBatches,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_prize_strategy_batches,omitempty"` + MaxPrizeBatchQuantity *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=max_prize_batch_quantity,json=maxPrizeBatchQuantity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_prize_batch_quantity,omitempty"` + MinDrawScheduleDelta *time.Duration `protobuf:"bytes,6,opt,name=min_draw_schedule_delta,json=minDrawScheduleDelta,proto3,stdduration" json:"min_draw_schedule_delta,omitempty"` + MaxDrawScheduleDelta *time.Duration `protobuf:"bytes,7,opt,name=max_draw_schedule_delta,json=maxDrawScheduleDelta,proto3,stdduration" json:"max_draw_schedule_delta,omitempty"` + PrizeExpirationDelta *time.Duration `protobuf:"bytes,8,opt,name=prize_expiration_delta,json=prizeExpirationDelta,proto3,stdduration" json:"prize_expiration_delta,omitempty"` + FeesStakers *github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=fees_stakers,json=feesStakers,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"fees_stakers,omitempty"` + MinDepositDrawDelta *time.Duration `protobuf:"bytes,10,opt,name=min_deposit_draw_delta,json=minDepositDrawDelta,proto3,stdduration" json:"min_deposit_draw_delta,omitempty"` +} + +func (m *ProposalUpdateParams) Reset() { *m = ProposalUpdateParams{} } +func (*ProposalUpdateParams) ProtoMessage() {} +func (*ProposalUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_8678e5486331acc1, []int{2} +} +func (m *ProposalUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProposalUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProposalUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProposalUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProposalUpdateParams.Merge(m, src) +} +func (m *ProposalUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *ProposalUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_ProposalUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_ProposalUpdateParams proto.InternalMessageInfo + +func (m *ProposalUpdateParams) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *ProposalUpdateParams) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *ProposalUpdateParams) GetMinDrawScheduleDelta() *time.Duration { + if m != nil { + return m.MinDrawScheduleDelta + } + return nil +} + +func (m *ProposalUpdateParams) GetMaxDrawScheduleDelta() *time.Duration { + if m != nil { + return m.MaxDrawScheduleDelta + } + return nil +} + +func (m *ProposalUpdateParams) GetPrizeExpirationDelta() *time.Duration { + if m != nil { + return m.PrizeExpirationDelta + } + return nil +} + +func (m *ProposalUpdateParams) GetMinDepositDrawDelta() *time.Duration { + if m != nil { + return m.MinDepositDrawDelta + } + return nil +} + +func init() { + proto.RegisterType((*ProposalRegisterPool)(nil), "lum.network.millions.ProposalRegisterPool") + proto.RegisterType((*ProposalUpdatePool)(nil), "lum.network.millions.ProposalUpdatePool") + proto.RegisterType((*ProposalUpdateParams)(nil), "lum.network.millions.ProposalUpdateParams") +} + +func init() { proto.RegisterFile("lum-network/millions/gov.proto", fileDescriptor_8678e5486331acc1) } + +var fileDescriptor_8678e5486331acc1 = []byte{ + // 833 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x41, 0x6f, 0x23, 0x35, + 0x14, 0xc7, 0x33, 0x34, 0x4d, 0x5a, 0x37, 0x45, 0xe0, 0x86, 0x76, 0xda, 0xc3, 0xb4, 0x74, 0x11, + 0x2a, 0x87, 0xce, 0x68, 0xb7, 0x37, 0x6e, 0x2d, 0x41, 0x28, 0x07, 0xa4, 0x6c, 0x2a, 0x10, 0xac, + 0x90, 0x2c, 0xc7, 0x76, 0x27, 0x56, 0x66, 0xec, 0xc1, 0x76, 0xd2, 0x94, 0x0f, 0xc0, 0x79, 0x8f, + 0x7b, 0xe4, 0xe3, 0xf4, 0xb8, 0x47, 0xc4, 0x61, 0x41, 0xed, 0x17, 0x41, 0xb6, 0x27, 0x9b, 0x09, + 0x8d, 0xc4, 0x66, 0xb7, 0xa7, 0xe4, 0xf9, 0xbd, 0xf7, 0x7b, 0x2f, 0xef, 0xfd, 0x63, 0x83, 0x28, + 0x1b, 0xe7, 0xa7, 0x82, 0x99, 0x6b, 0xa9, 0x46, 0x49, 0xce, 0xb3, 0x8c, 0x4b, 0xa1, 0x93, 0x54, + 0x4e, 0xe2, 0x42, 0x49, 0x23, 0x61, 0x3b, 0x1b, 0xe7, 0x71, 0xe9, 0x8f, 0x67, 0xfe, 0x83, 0x76, + 0x2a, 0x53, 0xe9, 0x02, 0x12, 0xfb, 0xcd, 0xc7, 0x1e, 0x44, 0xa9, 0x94, 0x69, 0xc6, 0x12, 0x67, + 0x0d, 0xc6, 0x57, 0x09, 0x1d, 0x2b, 0x6c, 0xb8, 0x14, 0xa5, 0x7f, 0x9f, 0x48, 0x9d, 0x4b, 0x8d, + 0x7c, 0xa2, 0x37, 0x66, 0xa9, 0xde, 0x4a, 0x06, 0x58, 0xb3, 0x64, 0xf2, 0x74, 0xc0, 0x0c, 0x7e, + 0x9a, 0x10, 0xc9, 0x67, 0xa9, 0x27, 0x4b, 0xdb, 0xa4, 0x0a, 0x5f, 0x23, 0x4d, 0x86, 0x8c, 0x8e, + 0x33, 0x56, 0x46, 0x7e, 0xb5, 0x34, 0xb2, 0x50, 0xfc, 0x37, 0x86, 0xb4, 0x51, 0xd8, 0xb0, 0xf4, + 0xc6, 0x87, 0x1e, 0xff, 0xbe, 0x0e, 0xda, 0x3d, 0x25, 0x0b, 0xa9, 0x71, 0xd6, 0x67, 0x29, 0xd7, + 0x86, 0xa9, 0x9e, 0x94, 0x19, 0x6c, 0x83, 0x75, 0xc3, 0x4d, 0xc6, 0xc2, 0xe0, 0x28, 0x38, 0xd9, + 0xec, 0x7b, 0x03, 0x1e, 0x81, 0x2d, 0xca, 0x34, 0x51, 0xbc, 0xb0, 0xbf, 0x29, 0xfc, 0xc8, 0xf9, + 0xaa, 0x47, 0x70, 0x1f, 0x6c, 0x90, 0x21, 0xe6, 0x02, 0x71, 0x1a, 0xae, 0x39, 0x77, 0xd3, 0xd9, + 0x5d, 0x6a, 0x91, 0x94, 0x09, 0x99, 0x87, 0x75, 0x8f, 0x74, 0x06, 0xfc, 0x1c, 0xb4, 0x04, 0x36, + 0x7c, 0xc2, 0x90, 0x77, 0xae, 0x7b, 0xa6, 0x3f, 0xeb, 0xb8, 0x90, 0x27, 0x60, 0x9b, 0x48, 0x21, + 0x18, 0xb1, 0x15, 0x2c, 0xb8, 0xe1, 0x62, 0x5a, 0xf3, 0xc3, 0x2e, 0x85, 0x11, 0x00, 0x13, 0x9c, + 0x71, 0x8a, 0x8d, 0x54, 0x3a, 0x6c, 0x1e, 0xad, 0x9d, 0x6c, 0xf6, 0x2b, 0x27, 0xf0, 0x17, 0x00, + 0x73, 0x2e, 0x10, 0x65, 0x85, 0xd4, 0xdc, 0x20, 0x9c, 0xcb, 0xb1, 0x30, 0xe1, 0x86, 0x25, 0x5d, + 0xc4, 0xb7, 0x6f, 0x0e, 0x6b, 0x7f, 0xbd, 0x39, 0xfc, 0x32, 0xe5, 0x66, 0x38, 0x1e, 0xc4, 0x44, + 0xe6, 0xe5, 0x6e, 0xca, 0x8f, 0x53, 0x4d, 0x47, 0x89, 0xb9, 0x29, 0x98, 0x8e, 0xbb, 0xc2, 0xf4, + 0x3f, 0xc9, 0xb9, 0xe8, 0x78, 0xd0, 0xb9, 0xe3, 0xc0, 0xef, 0xc1, 0xf6, 0xc2, 0x26, 0xc2, 0xcd, + 0xa3, 0xe0, 0x64, 0xeb, 0xd9, 0x71, 0xbc, 0x4c, 0x3b, 0x71, 0x47, 0xe1, 0xeb, 0xcb, 0x32, 0xf2, + 0xa2, 0x6e, 0x8b, 0xf7, 0x5b, 0xb4, 0x72, 0x06, 0x7b, 0xe0, 0xe3, 0xc5, 0x75, 0x85, 0xc0, 0xf1, + 0x9e, 0x2c, 0xe7, 0xf5, 0x6c, 0xec, 0x65, 0x19, 0x5a, 0x02, 0xb7, 0x8b, 0xea, 0x21, 0x3c, 0x03, + 0xbb, 0x03, 0x46, 0x86, 0x67, 0xcf, 0x50, 0xa1, 0xd8, 0x15, 0x9f, 0x22, 0x4c, 0x08, 0xc2, 0x94, + 0xaa, 0x70, 0xcb, 0x0d, 0x73, 0xc7, 0x7b, 0x7b, 0xce, 0x79, 0x4e, 0xc8, 0x39, 0xa5, 0xea, 0x61, + 0xd2, 0x04, 0x67, 0x3e, 0xa9, 0xf5, 0x30, 0xe9, 0x47, 0x9c, 0xb9, 0xa4, 0x18, 0xec, 0x18, 0x85, + 0x85, 0xbe, 0x62, 0x0a, 0x91, 0x21, 0x16, 0x82, 0x65, 0x76, 0x67, 0xdb, 0x2e, 0xe3, 0xd3, 0x99, + 0xeb, 0x1b, 0xef, 0xe9, 0xd2, 0xaf, 0xeb, 0xaf, 0xfe, 0x38, 0xac, 0x1d, 0xbf, 0x5c, 0x03, 0x70, + 0x26, 0xc4, 0x1f, 0x0a, 0x8a, 0x0d, 0xfb, 0x20, 0x19, 0xee, 0x81, 0x66, 0x21, 0x65, 0x36, 0x53, + 0x61, 0xbd, 0xdf, 0xb0, 0x66, 0x97, 0xc2, 0x2f, 0x16, 0x64, 0x52, 0xb7, 0x32, 0x71, 0x03, 0x0b, + 0xde, 0x41, 0x2c, 0xeb, 0x6f, 0xc5, 0x12, 0x3c, 0xae, 0x58, 0x1a, 0x2b, 0x89, 0x25, 0xf8, 0x5f, + 0xb1, 0x34, 0x57, 0x13, 0x4b, 0xf0, 0x1f, 0xb1, 0x94, 0x2b, 0xb9, 0x6d, 0xcc, 0xef, 0x86, 0x72, + 0x25, 0x58, 0xe1, 0x5c, 0xbf, 0xf7, 0x52, 0x96, 0x4f, 0x75, 0xed, 0x91, 0xa6, 0x3a, 0x02, 0x07, + 0x39, 0x9e, 0xa2, 0xc5, 0x51, 0xa0, 0x01, 0x36, 0x64, 0xc8, 0xb4, 0xbf, 0x73, 0x56, 0xae, 0xb2, + 0x97, 0xe3, 0xe9, 0xe2, 0xbc, 0x3c, 0x0e, 0xa6, 0x20, 0x9c, 0x17, 0x73, 0x35, 0xd0, 0xaf, 0x63, + 0x2c, 0x0c, 0x37, 0x37, 0xef, 0x29, 0x93, 0xcf, 0x66, 0xa5, 0x5c, 0x89, 0xe7, 0x25, 0x0c, 0xbe, + 0x00, 0x7b, 0x6e, 0x66, 0x55, 0xbd, 0x20, 0xca, 0x32, 0x83, 0x4b, 0xd5, 0xec, 0xc7, 0xfe, 0xc9, + 0x89, 0x67, 0x4f, 0x4e, 0xdc, 0x29, 0x9f, 0x9c, 0x8b, 0x0d, 0xdb, 0xc2, 0xab, 0xbf, 0x0f, 0x83, + 0x7e, 0xdb, 0x4e, 0xab, 0xa2, 0x99, 0x8e, 0x05, 0x38, 0x36, 0x9e, 0x2e, 0x65, 0x37, 0x57, 0x61, + 0xe3, 0xe9, 0x43, 0xf6, 0xcf, 0x60, 0xd7, 0x0f, 0x87, 0x4d, 0x0b, 0xee, 0x73, 0x4a, 0xf4, 0xc6, + 0x0a, 0x68, 0x87, 0xf8, 0xf6, 0x2d, 0xc1, 0xa3, 0x9f, 0x83, 0xd6, 0x15, 0x63, 0x1a, 0x69, 0x83, + 0x47, 0x4c, 0x69, 0x77, 0xd5, 0xae, 0x36, 0xef, 0x0e, 0x23, 0xfd, 0x2d, 0xcb, 0xb8, 0xf4, 0x08, + 0xf8, 0x13, 0xd8, 0xad, 0x2a, 0xd3, 0x4d, 0xc4, 0x77, 0x0b, 0xde, 0xbd, 0xdb, 0x9d, 0xb9, 0x24, + 0xed, 0x3c, 0x5c, 0xb3, 0xfe, 0xaf, 0x74, 0xf1, 0xdd, 0xed, 0x5d, 0x14, 0xbc, 0xbe, 0x8b, 0x82, + 0x7f, 0xee, 0xa2, 0xe0, 0xe5, 0x7d, 0x54, 0x7b, 0x7d, 0x1f, 0xd5, 0xfe, 0xbc, 0x8f, 0x6a, 0x2f, + 0x4e, 0x2b, 0xed, 0x56, 0x9f, 0x6d, 0xf7, 0x68, 0x26, 0xd3, 0xf9, 0xf3, 0xed, 0x3a, 0x1f, 0x34, + 0x5c, 0x03, 0x67, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xd8, 0xea, 0x26, 0xb4, 0x08, 0x00, + 0x00, +} + +func (m *ProposalRegisterPool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProposalRegisterPool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProposalRegisterPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TransferChannelId) > 0 { + i -= len(m.TransferChannelId) + copy(dAtA[i:], m.TransferChannelId) + i = encodeVarintGov(dAtA, i, uint64(len(m.TransferChannelId))) + i-- + dAtA[i] = 0x6a + } + if len(m.Bech32PrefixValAddr) > 0 { + i -= len(m.Bech32PrefixValAddr) + copy(dAtA[i:], m.Bech32PrefixValAddr) + i = encodeVarintGov(dAtA, i, uint64(len(m.Bech32PrefixValAddr))) + i-- + dAtA[i] = 0x62 + } + if len(m.Bech32PrefixAccAddr) > 0 { + i -= len(m.Bech32PrefixAccAddr) + copy(dAtA[i:], m.Bech32PrefixAccAddr) + i = encodeVarintGov(dAtA, i, uint64(len(m.Bech32PrefixAccAddr))) + i-- + dAtA[i] = 0x5a + } + { + size, err := m.PrizeStrategy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + { + size, err := m.DrawSchedule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + if len(m.Validators) > 0 { + for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Validators[iNdEx]) + copy(dAtA[i:], m.Validators[iNdEx]) + i = encodeVarintGov(dAtA, i, uint64(len(m.Validators[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintGov(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x32 + } + if len(m.NativeDenom) > 0 { + i -= len(m.NativeDenom) + copy(dAtA[i:], m.NativeDenom) + i = encodeVarintGov(dAtA, i, uint64(len(m.NativeDenom))) + i-- + dAtA[i] = 0x2a + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintGov(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x22 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintGov(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ProposalUpdatePool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProposalUpdatePool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProposalUpdatePool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PrizeStrategy != nil { + { + size, err := m.PrizeStrategy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + if m.DrawSchedule != nil { + { + size, err := m.DrawSchedule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + if m.MinDepositAmount != nil { + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if len(m.Validators) > 0 { + for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Validators[iNdEx]) + copy(dAtA[i:], m.Validators[iNdEx]) + i = encodeVarintGov(dAtA, i, uint64(len(m.Validators[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if m.PoolId != 0 { + i = encodeVarintGov(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x18 + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ProposalUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProposalUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProposalUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MinDepositDrawDelta != nil { + n5, err5 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.MinDepositDrawDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDepositDrawDelta):]) + if err5 != nil { + return 0, err5 + } + i -= n5 + i = encodeVarintGov(dAtA, i, uint64(n5)) + i-- + dAtA[i] = 0x52 + } + if m.FeesStakers != nil { + { + size := m.FeesStakers.Size() + i -= size + if _, err := m.FeesStakers.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + } + if m.PrizeExpirationDelta != nil { + n6, err6 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.PrizeExpirationDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.PrizeExpirationDelta):]) + if err6 != nil { + return 0, err6 + } + i -= n6 + i = encodeVarintGov(dAtA, i, uint64(n6)) + i-- + dAtA[i] = 0x42 + } + if m.MaxDrawScheduleDelta != nil { + n7, err7 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.MaxDrawScheduleDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MaxDrawScheduleDelta):]) + if err7 != nil { + return 0, err7 + } + i -= n7 + i = encodeVarintGov(dAtA, i, uint64(n7)) + i-- + dAtA[i] = 0x3a + } + if m.MinDrawScheduleDelta != nil { + n8, err8 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.MinDrawScheduleDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDrawScheduleDelta):]) + if err8 != nil { + return 0, err8 + } + i -= n8 + i = encodeVarintGov(dAtA, i, uint64(n8)) + i-- + dAtA[i] = 0x32 + } + if m.MaxPrizeBatchQuantity != nil { + { + size := m.MaxPrizeBatchQuantity.Size() + i -= size + if _, err := m.MaxPrizeBatchQuantity.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.MaxPrizeStrategyBatches != nil { + { + size := m.MaxPrizeStrategyBatches.Size() + i -= size + if _, err := m.MaxPrizeStrategyBatches.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.MinDepositAmount != nil { + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintGov(dAtA []byte, offset int, v uint64) int { + offset -= sovGov(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ProposalRegisterPool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.NativeDenom) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + if len(m.Validators) > 0 { + for _, s := range m.Validators { + l = len(s) + n += 1 + l + sovGov(uint64(l)) + } + } + l = m.MinDepositAmount.Size() + n += 1 + l + sovGov(uint64(l)) + l = m.DrawSchedule.Size() + n += 1 + l + sovGov(uint64(l)) + l = m.PrizeStrategy.Size() + n += 1 + l + sovGov(uint64(l)) + l = len(m.Bech32PrefixAccAddr) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Bech32PrefixValAddr) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.TransferChannelId) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + return n +} + +func (m *ProposalUpdatePool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + if m.PoolId != 0 { + n += 1 + sovGov(uint64(m.PoolId)) + } + if len(m.Validators) > 0 { + for _, s := range m.Validators { + l = len(s) + n += 1 + l + sovGov(uint64(l)) + } + } + if m.MinDepositAmount != nil { + l = m.MinDepositAmount.Size() + n += 1 + l + sovGov(uint64(l)) + } + if m.DrawSchedule != nil { + l = m.DrawSchedule.Size() + n += 1 + l + sovGov(uint64(l)) + } + if m.PrizeStrategy != nil { + l = m.PrizeStrategy.Size() + n += 1 + l + sovGov(uint64(l)) + } + return n +} + +func (m *ProposalUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + if m.MinDepositAmount != nil { + l = m.MinDepositAmount.Size() + n += 1 + l + sovGov(uint64(l)) + } + if m.MaxPrizeStrategyBatches != nil { + l = m.MaxPrizeStrategyBatches.Size() + n += 1 + l + sovGov(uint64(l)) + } + if m.MaxPrizeBatchQuantity != nil { + l = m.MaxPrizeBatchQuantity.Size() + n += 1 + l + sovGov(uint64(l)) + } + if m.MinDrawScheduleDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDrawScheduleDelta) + n += 1 + l + sovGov(uint64(l)) + } + if m.MaxDrawScheduleDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MaxDrawScheduleDelta) + n += 1 + l + sovGov(uint64(l)) + } + if m.PrizeExpirationDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.PrizeExpirationDelta) + n += 1 + l + sovGov(uint64(l)) + } + if m.FeesStakers != nil { + l = m.FeesStakers.Size() + n += 1 + l + sovGov(uint64(l)) + } + if m.MinDepositDrawDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDepositDrawDelta) + n += 1 + l + sovGov(uint64(l)) + } + return n +} + +func sovGov(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGov(x uint64) (n int) { + return sovGov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ProposalRegisterPool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProposalRegisterPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProposalRegisterPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NativeDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NativeDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validators = append(m.Validators, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawSchedule", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DrawSchedule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeStrategy", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PrizeStrategy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32PrefixAccAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32PrefixAccAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32PrefixValAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32PrefixValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TransferChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TransferChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGov(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProposalUpdatePool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProposalUpdatePool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProposalUpdatePool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validators = append(m.Validators, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MinDepositAmount = &v + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawSchedule", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.DrawSchedule == nil { + m.DrawSchedule = &DrawSchedule{} + } + if err := m.DrawSchedule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeStrategy", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PrizeStrategy == nil { + m.PrizeStrategy = &PrizeStrategy{} + } + if err := m.PrizeStrategy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGov(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProposalUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProposalUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProposalUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MinDepositAmount = &v + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPrizeStrategyBatches", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MaxPrizeStrategyBatches = &v + if err := m.MaxPrizeStrategyBatches.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPrizeBatchQuantity", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MaxPrizeBatchQuantity = &v + if err := m.MaxPrizeBatchQuantity.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDrawScheduleDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MinDrawScheduleDelta == nil { + m.MinDrawScheduleDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.MinDrawScheduleDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxDrawScheduleDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MaxDrawScheduleDelta == nil { + m.MaxDrawScheduleDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.MaxDrawScheduleDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeExpirationDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PrizeExpirationDelta == nil { + m.PrizeExpirationDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.PrizeExpirationDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeesStakers", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Dec + m.FeesStakers = &v + if err := m.FeesStakers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositDrawDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MinDepositDrawDelta == nil { + m.MinDepositDrawDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.MinDepositDrawDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGov(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGov(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGov + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGov + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGov + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGov + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGov + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGov + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGov = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGov = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGov = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/keys.go b/x/millions/types/keys.go new file mode 100644 index 00000000..b1a57550 --- /dev/null +++ b/x/millions/types/keys.go @@ -0,0 +1,189 @@ +package types + +import ( + "bytes" + "fmt" + "strconv" + "strings" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" +) + +const ( + ModuleName = "millions" + + ModuleVersion = 1 + + StoreKey = ModuleName + + RouterKey = ModuleName + + QuerierRoute = ModuleName +) + +const ( + IBCTransferTimeoutNanos = 1_800_000_000_000 +) + +const ( + UnknownID uint64 = 0 +) + +const ( + ICATypeDeposit = "deposit" + ICATypePrizePool = "prizepool" +) + +var ( + NextPoolIdPrefix = []byte{0x01} + PoolPrefix = []byte{0x02} + NextDepositPrefix = []byte{0x03} + PoolDepositPrefix = []byte{0x04} + AccountPoolDepositPrefix = []byte{0x05} + DrawPrefix = []byte{0x06} + PoolPrizePrefix = []byte{0x07} + AccountPoolPrizePrefix = []byte{0x08} + NextPrizePrefix = []byte{0x09} + PoolWithdrawalPrefix = []byte{0x10} + AccountPoolWithdrawalPrefix = []byte{0x11} + NextWithdrawalPrefix = []byte{0x12} + PrizeExpirationTimePrefix = []byte{0x13} + WithdrawalMaturationTimePrefix = []byte{0x14} + ParamsPrefix = []byte{0x20} + // KeyIndexSeparator separator between combined keys + KeyIndexSeparator = []byte{0xFF} +) + +// CombineKeys combine bytes array into a single bytes. +func CombineKeys(keys ...[]byte) []byte { + return bytes.Join(keys, KeyIndexSeparator) +} + +func CombineStringKeys(keys ...string) string { + return strings.Join(keys, string(KeyIndexSeparator)) +} + +func DecombineStringKeys(combined string) []string { + return strings.Split(combined, string(KeyIndexSeparator)) +} + +// Pool + +func GetPoolKey(poolID uint64) []byte { + return CombineKeys(PoolPrefix, strconv.AppendUint([]byte{}, poolID, 10)) +} + +func NewPoolName(poolID uint64, addressType string) []byte { + key := []byte(fmt.Sprintf("pool%d.%s", poolID, addressType)) + return key +} + +func NewPoolAddress(poolID uint64, addressType string) sdk.AccAddress { + return address.Module(ModuleName, NewPoolName(poolID, addressType)) +} + +// Deposits + +func GetDepositsKey() []byte { + return PoolDepositPrefix +} + +func GetPoolDepositKey(poolID uint64, depositID uint64) []byte { + return CombineKeys(PoolDepositPrefix, strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, depositID, 10)) +} + +func GetPoolDepositsKey(poolID uint64) []byte { + return CombineKeys(PoolDepositPrefix, strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetAccountPoolDepositKey(addr sdk.Address, poolID uint64, depositID uint64) []byte { + return CombineKeys(AccountPoolDepositPrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, depositID, 10)) +} + +func GetAccountPoolDepositsKey(addr sdk.Address, poolID uint64) []byte { + return CombineKeys(AccountPoolDepositPrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetAccountDepositsKey(addr sdk.Address) []byte { + return CombineKeys(AccountPoolDepositPrefix, addr.Bytes()) +} + +// Prizes + +func GetPrizesKey() []byte { + return PoolPrizePrefix +} + +func GetPoolPrizesKey(poolID uint64) []byte { + return CombineKeys(PoolPrizePrefix, strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetPoolDrawPrizesKey(poolID uint64, drawID uint64) []byte { + return CombineKeys(PoolPrizePrefix, strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, drawID, 10)) +} + +func GetPoolDrawPrizeKey(poolID uint64, drawID uint64, prizeID uint64) []byte { + return CombineKeys(PoolPrizePrefix, strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, drawID, 10), strconv.AppendUint([]byte{}, prizeID, 10)) +} + +func GetAccountPrizesKey(addr sdk.Address) []byte { + return CombineKeys(AccountPoolPrizePrefix, addr.Bytes()) +} + +func GetAccountPoolPrizesKey(addr sdk.Address, poolID uint64) []byte { + return CombineKeys(AccountPoolPrizePrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetAccountPoolDrawPrizesKey(addr sdk.Address, poolID uint64, drawID uint64) []byte { + return CombineKeys(AccountPoolPrizePrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, drawID, 10)) +} + +func GetAccountPoolDrawPrizeKey(addr sdk.Address, poolID uint64, drawID uint64, prizeID uint64) []byte { + return CombineKeys(AccountPoolPrizePrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, drawID, 10), strconv.AppendUint([]byte{}, prizeID, 10)) +} + +func GetExpiringPrizeTimeKey(timestamp time.Time) []byte { + return CombineKeys(PrizeExpirationTimePrefix, sdk.FormatTimeBytes(timestamp)) +} + +// Draws + +func GetPoolDrawsKey(poolID uint64) []byte { + return CombineKeys(DrawPrefix, strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetPoolDrawIDKey(poolID uint64, drawID uint64) []byte { + return CombineKeys(DrawPrefix, strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, drawID, 10)) +} + +// Withdrawals + +func GetWithdrawalsKey() []byte { + return PoolWithdrawalPrefix +} + +func GetPoolWithdrawalKey(poolID uint64, withdrawalID uint64) []byte { + return CombineKeys(PoolWithdrawalPrefix, strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, withdrawalID, 10)) +} + +func GetPoolWithdrawalsKey(poolID uint64) []byte { + return CombineKeys(PoolWithdrawalPrefix, strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetAccountPoolWithdrawalKey(addr sdk.Address, poolID uint64, withdrawalID uint64) []byte { + return CombineKeys(AccountPoolWithdrawalPrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10), strconv.AppendUint([]byte{}, withdrawalID, 10)) +} + +func GetAccountPoolWithdrawalsKey(addr sdk.Address, poolID uint64) []byte { + return CombineKeys(AccountPoolWithdrawalPrefix, addr.Bytes(), strconv.AppendUint([]byte{}, poolID, 10)) +} + +func GetAccountWithdrawalsKey(addr sdk.Address) []byte { + return CombineKeys(AccountPoolWithdrawalPrefix, addr.Bytes()) +} + +func GetMaturedWithdrawalTimeKey(timestamp time.Time) []byte { + return CombineKeys(WithdrawalMaturationTimePrefix, sdk.FormatTimeBytes(timestamp)) +} diff --git a/x/millions/types/message_claim_prize.go b/x/millions/types/message_claim_prize.go new file mode 100644 index 00000000..d4d1928d --- /dev/null +++ b/x/millions/types/message_claim_prize.go @@ -0,0 +1,48 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgClaimPrize{} + +func NewMsgMsgClaimPrize(winnerAddress string, poolID uint64, drawID uint64, prizeID uint64) *MsgClaimPrize { + return &MsgClaimPrize{ + PoolId: poolID, + DrawId: drawID, + PrizeId: prizeID, + WinnerAddress: winnerAddress, + } +} + +func (msg MsgClaimPrize) Route() string { + return RouterKey +} + +func (msg MsgClaimPrize) Type() string { + return "ClaimPrize" +} + +func (msg *MsgClaimPrize) GetSigners() []sdk.AccAddress { + addr := sdk.MustAccAddressFromBech32(msg.GetWinnerAddress()) + return []sdk.AccAddress{addr} +} + +func (msg *MsgClaimPrize) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgClaimPrize) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + _, err := sdk.AccAddressFromBech32(msg.GetWinnerAddress()) + if err != nil { + return ErrInvalidWinnerAddress + } + + if msg.GetPoolId() == UnknownID || msg.GetDrawId() == UnknownID || msg.GetPrizeId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/message_deposit.go b/x/millions/types/message_deposit.go new file mode 100644 index 00000000..ae2e26d6 --- /dev/null +++ b/x/millions/types/message_deposit.go @@ -0,0 +1,66 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgDeposit{} + +func NewMsgDeposit(depositor string, amount sdk.Coin, poolID uint64) *MsgDeposit { + return &MsgDeposit{ + PoolId: poolID, + Amount: amount, + DepositorAddress: depositor, + } +} + +func (msg MsgDeposit) Route() string { + return RouterKey +} + +func (msg MsgDeposit) Type() string { + return "Deposit" +} + +func (msg *MsgDeposit) GetSigners() []sdk.AccAddress { + depositor := sdk.MustAccAddressFromBech32(msg.GetDepositorAddress()) + return []sdk.AccAddress{depositor} +} + +func (msg *MsgDeposit) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgDeposit) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + if _, err := sdk.AccAddressFromBech32(msg.GetDepositorAddress()); err != nil { + return ErrInvalidDepositorAddress + } + + // ensure denom is valid + if err := sdk.ValidateDenom(msg.Amount.Denom); err != nil { + return ErrInvalidDepositDenom + } + + // If we have an amount, make sure it is not negative nor zero + if msg.Amount.IsNil() || msg.Amount.Amount.LT(sdk.NewInt(MinAcceptableDepositAmount)) { + return ErrInvalidDepositAmount + } + + if msg.GetWinnerAddress() != "" { + if _, err := sdk.AccAddressFromBech32(msg.GetWinnerAddress()); err != nil { + return ErrInvalidWinnerAddress + } + } + + if msg.WinnerAddress != "" && msg.WinnerAddress != msg.DepositorAddress && msg.IsSponsor { + return ErrInvalidSponsorWinnerCombo + } + + if msg.GetPoolId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/message_deposit_retry.go b/x/millions/types/message_deposit_retry.go new file mode 100644 index 00000000..05825d90 --- /dev/null +++ b/x/millions/types/message_deposit_retry.go @@ -0,0 +1,46 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgDepositRetry{} + +func NewMsgDepositRetry(depositorAddr string, poolID uint64, depositID uint64) *MsgDepositRetry { + return &MsgDepositRetry{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: depositorAddr, + } +} + +func (msg MsgDepositRetry) Route() string { + return RouterKey +} + +func (msg MsgDepositRetry) Type() string { + return "DepositRetry" +} + +func (msg *MsgDepositRetry) GetSigners() []sdk.AccAddress { + depositor := sdk.MustAccAddressFromBech32(msg.GetDepositorAddress()) + return []sdk.AccAddress{depositor} +} + +func (msg *MsgDepositRetry) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgDepositRetry) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + if _, err := sdk.AccAddressFromBech32(msg.GetDepositorAddress()); err != nil { + return ErrInvalidDepositorAddress + } + + if msg.GetPoolId() == UnknownID || msg.GetDepositId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/message_draw_retry.go b/x/millions/types/message_draw_retry.go new file mode 100644 index 00000000..07cdf95c --- /dev/null +++ b/x/millions/types/message_draw_retry.go @@ -0,0 +1,46 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgDrawRetry{} + +func NewMsgDrawRetry(drawRetryAddr string, poolID uint64, drawID uint64) *MsgDrawRetry { + return &MsgDrawRetry{ + DrawRetryAddress: drawRetryAddr, + PoolId: poolID, + DrawId: drawID, + } +} + +func (msg MsgDrawRetry) Route() string { + return RouterKey +} + +func (msg MsgDrawRetry) Type() string { + return "DrawRetry" +} + +func (msg *MsgDrawRetry) GetSigners() []sdk.AccAddress { + depositor := sdk.MustAccAddressFromBech32(msg.GetDrawRetryAddress()) + return []sdk.AccAddress{depositor} +} + +func (msg *MsgDrawRetry) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgDrawRetry) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + if _, err := sdk.AccAddressFromBech32(msg.GetDrawRetryAddress()); err != nil { + return ErrInvalidDrawRetryAddress + } + + if msg.GetPoolId() == UnknownID || msg.GetDrawId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/message_restore_interchain_accounts.go b/x/millions/types/message_restore_interchain_accounts.go new file mode 100644 index 00000000..13a57362 --- /dev/null +++ b/x/millions/types/message_restore_interchain_accounts.go @@ -0,0 +1,43 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +var _ sdk.Msg = &MsgRestoreInterchainAccounts{} + +func NewMsgRestoreInterchainAccounts(restorerAddress string, poolID uint64) *MsgRestoreInterchainAccounts { + return &MsgRestoreInterchainAccounts{ + RestorerAddress: restorerAddress, + PoolId: poolID, + } +} + +func (msg MsgRestoreInterchainAccounts) Route() string { + return RouterKey +} + +func (msg MsgRestoreInterchainAccounts) Type() string { + return "RestoreInterchainAccounts" +} + +func (msg *MsgRestoreInterchainAccounts) GetSigners() []sdk.AccAddress { + depositor := sdk.MustAccAddressFromBech32(msg.GetRestorerAddress()) + return []sdk.AccAddress{depositor} +} + +func (msg *MsgRestoreInterchainAccounts) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRestoreInterchainAccounts) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + if _, err := sdk.AccAddressFromBech32(msg.GetRestorerAddress()); err != nil { + return ErrInvalidRestorerAddress + } + + if msg.GetPoolId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/message_withdraw_deposit.go b/x/millions/types/message_withdraw_deposit.go new file mode 100644 index 00000000..3cd53459 --- /dev/null +++ b/x/millions/types/message_withdraw_deposit.go @@ -0,0 +1,51 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgWithdrawDeposit{} + +func NewMsgWithdrawDeposit(depositor string, toAddress string, poolID uint64, depositID uint64) *MsgWithdrawDeposit { + return &MsgWithdrawDeposit{ + PoolId: poolID, + DepositId: depositID, + DepositorAddress: depositor, + ToAddress: toAddress, + } +} + +func (msg MsgWithdrawDeposit) Route() string { + return RouterKey +} + +func (msg MsgWithdrawDeposit) Type() string { + return "WithdrawDeposit" +} + +func (msg *MsgWithdrawDeposit) GetSigners() []sdk.AccAddress { + depositor := sdk.MustAccAddressFromBech32(msg.GetDepositorAddress()) + return []sdk.AccAddress{depositor} +} + +func (msg *MsgWithdrawDeposit) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgWithdrawDeposit) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + if _, err := sdk.AccAddressFromBech32(msg.GetDepositorAddress()); err != nil { + return ErrInvalidDepositorAddress + } + + if _, err := sdk.AccAddressFromBech32(msg.GetToAddress()); err != nil { + return ErrInvalidDestinationAddress + } + + if msg.GetPoolId() == UnknownID || msg.GetDepositId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/message_withdraw_deposit_retry.go b/x/millions/types/message_withdraw_deposit_retry.go new file mode 100644 index 00000000..64453e8e --- /dev/null +++ b/x/millions/types/message_withdraw_deposit_retry.go @@ -0,0 +1,46 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgWithdrawDepositRetry{} + +func NewMsgWithdrawDepositRetry(depositorAddr string, poolID uint64, withdrawalID uint64) *MsgWithdrawDepositRetry { + return &MsgWithdrawDepositRetry{ + PoolId: poolID, + WithdrawalId: withdrawalID, + DepositorAddress: depositorAddr, + } +} + +func (msg MsgWithdrawDepositRetry) Route() string { + return RouterKey +} + +func (msg MsgWithdrawDepositRetry) Type() string { + return "WithdrawDepositRetry" +} + +func (msg *MsgWithdrawDepositRetry) GetSigners() []sdk.AccAddress { + depositor := sdk.MustAccAddressFromBech32(msg.GetDepositorAddress()) + return []sdk.AccAddress{depositor} +} + +func (msg *MsgWithdrawDepositRetry) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgWithdrawDepositRetry) ValidateBasic() error { + // Ensure the address is correct and that we are able to acquire it + if _, err := sdk.AccAddressFromBech32(msg.GetDepositorAddress()); err != nil { + return ErrInvalidDepositorAddress + } + + if msg.GetPoolId() == UnknownID || msg.GetWithdrawalId() == UnknownID { + return ErrInvalidID + } + + return nil +} diff --git a/x/millions/types/params.go b/x/millions/types/params.go new file mode 100644 index 00000000..e9273e51 --- /dev/null +++ b/x/millions/types/params.go @@ -0,0 +1,73 @@ +package types + +import ( + time "time" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + MinAcceptableDepositAmount = 1_000 + MinAcceptableDrawDelta = 1 * time.Hour + MinAcceptableDepositDrawDelta = 1 * time.Minute + MinAcceptablePrizeExpirationDelta = 1 * time.Hour + MaxAcceptableFeesStakers = 50 // 50% + + defaultMinDepositAmount = 100_000 + defaultMaxPrizeStrategyBatches = 10 + defaultMaxPrizeBatchQuantity = 1000 + defaultMinDrawScheduleDelta = 1 * time.Hour + defaultMaxDrawScheduleDelta = 366 * 24 * time.Hour // 366 days + defaultPrizeExpirationDelta = 30 * 24 * time.Hour // 30 days + defaultFeesStakers = 10 // 10% + defaultMinDepositDrawDelta = 5 * time.Minute +) + +func DefaultParams() Params { + return Params{ + MinDepositAmount: sdk.NewInt(defaultMinDepositAmount), + MaxPrizeStrategyBatches: defaultMaxPrizeStrategyBatches, + MaxPrizeBatchQuantity: defaultMaxPrizeBatchQuantity, + MinDrawScheduleDelta: defaultMinDrawScheduleDelta, + MaxDrawScheduleDelta: defaultMaxDrawScheduleDelta, + PrizeExpirationDelta: defaultPrizeExpirationDelta, + FeesStakers: sdk.NewDecWithPrec(defaultFeesStakers, 2), + MinDepositDrawDelta: defaultMinDepositDrawDelta, + } +} + +func (p *Params) ValidateBasics() error { + if p.MinDepositAmount.IsNil() { + return errorsmod.Wrapf(ErrInvalidParams, "min deposit amount required") + } else if p.MinDepositAmount.LT(sdk.NewInt(MinAcceptableDepositAmount)) { + return errorsmod.Wrapf(ErrInvalidParams, "min deposit amount must be gte %d, got: %d", MinAcceptableDepositAmount, p.MinDepositAmount.Int64()) + } + if p.MaxPrizeStrategyBatches <= 0 { + return errorsmod.Wrapf(ErrInvalidParams, "max prize strategy batches must be gt 0, got: %d", p.MaxPrizeStrategyBatches) + } + if p.MaxPrizeBatchQuantity <= 0 { + return errorsmod.Wrapf(ErrInvalidParams, "max prize batch quantity must be gt 0, got: %d", p.MaxPrizeBatchQuantity) + } + if p.MinDrawScheduleDelta < MinAcceptableDrawDelta { + return errorsmod.Wrapf(ErrInvalidParams, "min draw schedule delta must be gte %s, got: %s", MinAcceptableDrawDelta.String(), p.MinDrawScheduleDelta.String()) + } + if p.MaxDrawScheduleDelta < MinAcceptableDrawDelta { + return errorsmod.Wrapf(ErrInvalidParams, "max draw schedule delta must be gte %s, got %s", MinAcceptableDrawDelta.String(), p.MaxDrawScheduleDelta.String()) + } + if p.MaxDrawScheduleDelta < p.MinDrawScheduleDelta { + return errorsmod.Wrapf(ErrInvalidParams, "max draw schedule delta must be gte min draw schedule delta") + } + if p.PrizeExpirationDelta < MinAcceptablePrizeExpirationDelta { + return errorsmod.Wrapf(ErrInvalidParams, "prize clawback delta must be gte %s, got: %s", MinAcceptablePrizeExpirationDelta.String(), p.PrizeExpirationDelta.String()) + } + if p.FeesStakers.IsNil() { + return errorsmod.Wrapf(ErrInvalidParams, "stakers fees required") + } else if p.FeesStakers.LT(sdk.NewDec(0)) || p.FeesStakers.GT(sdk.NewDecWithPrec(MaxAcceptableFeesStakers, 2)) { + return errorsmod.Wrapf(ErrInvalidParams, "stakers fees must be gte 0 and lte %d/100, got: %f", MaxAcceptableFeesStakers, p.FeesStakers.MustFloat64()) + } + if p.MinDepositDrawDelta < MinAcceptableDepositDrawDelta { + return errorsmod.Wrapf(ErrInvalidParams, "min deposit draw delta must be gte %s, got: %s", MinAcceptableDepositDrawDelta.String(), p.MinDepositDrawDelta.String()) + } + return nil +} diff --git a/x/millions/types/params.pb.go b/x/millions/types/params.pb.go new file mode 100644 index 00000000..4161361e --- /dev/null +++ b/x/millions/types/params.pb.go @@ -0,0 +1,667 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/params.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Params struct { + // min_deposit_amount the minimum deposit amount accepted by pool configurations + MinDepositAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount"` + // max_prize_strategy_batches the maximum prize strategy batches accepted by pool configurations + MaxPrizeStrategyBatches uint64 `protobuf:"varint,2,opt,name=max_prize_strategy_batches,json=maxPrizeStrategyBatches,proto3" json:"max_prize_strategy_batches,omitempty"` + // max_prize_batch_quantity the maximum prize batch quantity accepted by pool configurations + MaxPrizeBatchQuantity uint64 `protobuf:"varint,3,opt,name=max_prize_batch_quantity,json=maxPrizeBatchQuantity,proto3" json:"max_prize_batch_quantity,omitempty"` + // min_draw_schedule_delta the minimum delta between draws accepted by pool configurations + MinDrawScheduleDelta time.Duration `protobuf:"bytes,4,opt,name=min_draw_schedule_delta,json=minDrawScheduleDelta,proto3,stdduration" json:"min_draw_schedule_delta"` + // max_draw_schedule_delta the maximum delta between draws accepted by pool configurations + MaxDrawScheduleDelta time.Duration `protobuf:"bytes,5,opt,name=max_draw_schedule_delta,json=maxDrawScheduleDelta,proto3,stdduration" json:"max_draw_schedule_delta"` + // prize_expiration_delta the prize clawback expiration delta (common to all pools) + PrizeExpirationDelta time.Duration `protobuf:"bytes,6,opt,name=prize_expiration_delta,json=prizeExpirationDelta,proto3,stdduration" json:"prize_expiration_delta"` + // fees_stakers the fees distributed by stakers over prize won (common to all pools) + FeesStakers github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=fees_stakers,json=feesStakers,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"fees_stakers"` + // min_deposit_draw_delta the minimum delta before a draw for a deposit to be accepted during the time weighted balance computation for a draw + MinDepositDrawDelta time.Duration `protobuf:"bytes,8,opt,name=min_deposit_draw_delta,json=minDepositDrawDelta,proto3,stdduration" json:"min_deposit_draw_delta"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_d1ed4b8d9ab1e917, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMaxPrizeStrategyBatches() uint64 { + if m != nil { + return m.MaxPrizeStrategyBatches + } + return 0 +} + +func (m *Params) GetMaxPrizeBatchQuantity() uint64 { + if m != nil { + return m.MaxPrizeBatchQuantity + } + return 0 +} + +func (m *Params) GetMinDrawScheduleDelta() time.Duration { + if m != nil { + return m.MinDrawScheduleDelta + } + return 0 +} + +func (m *Params) GetMaxDrawScheduleDelta() time.Duration { + if m != nil { + return m.MaxDrawScheduleDelta + } + return 0 +} + +func (m *Params) GetPrizeExpirationDelta() time.Duration { + if m != nil { + return m.PrizeExpirationDelta + } + return 0 +} + +func (m *Params) GetMinDepositDrawDelta() time.Duration { + if m != nil { + return m.MinDepositDrawDelta + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "lum.network.millions.Params") +} + +func init() { proto.RegisterFile("lum-network/millions/params.proto", fileDescriptor_d1ed4b8d9ab1e917) } + +var fileDescriptor_d1ed4b8d9ab1e917 = []byte{ + // 461 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x31, 0x8f, 0xd3, 0x30, + 0x1c, 0xc5, 0x1b, 0xb8, 0x2b, 0x87, 0x8f, 0x01, 0x85, 0x72, 0x17, 0x3a, 0xa4, 0x85, 0x01, 0x75, + 0xa9, 0x23, 0xc1, 0xc0, 0xc0, 0x44, 0x55, 0x84, 0xd8, 0xee, 0xda, 0x05, 0x4e, 0x48, 0xd6, 0xbf, + 0x89, 0x2f, 0xb1, 0x1a, 0xdb, 0xc1, 0x76, 0xd4, 0x94, 0x4f, 0xc1, 0xc8, 0xc0, 0x07, 0xba, 0xf1, + 0x46, 0xc4, 0x70, 0xa0, 0xf6, 0x8b, 0xa0, 0xd8, 0x29, 0xad, 0x04, 0xc3, 0x75, 0x6a, 0xa3, 0xff, + 0x7b, 0xbf, 0xbc, 0xff, 0x8b, 0x8d, 0x9e, 0xe6, 0x25, 0x1f, 0x0a, 0x6a, 0x16, 0x52, 0xcd, 0x23, + 0xce, 0xf2, 0x9c, 0x49, 0xa1, 0xa3, 0x02, 0x14, 0x70, 0x8d, 0x0b, 0x25, 0x8d, 0xf4, 0x3b, 0x79, + 0xc9, 0x71, 0x23, 0xc1, 0x1b, 0x49, 0xb7, 0x93, 0xca, 0x54, 0x5a, 0x41, 0x54, 0xff, 0x73, 0xda, + 0x6e, 0x98, 0x4a, 0x99, 0xe6, 0x34, 0xb2, 0x4f, 0xb3, 0xf2, 0x32, 0x4a, 0x4a, 0x05, 0x86, 0x49, + 0xe1, 0xe6, 0xcf, 0xbe, 0x1f, 0xa2, 0xf6, 0x99, 0x85, 0xfb, 0x9f, 0x90, 0xcf, 0x99, 0x20, 0x09, + 0x2d, 0xa4, 0x66, 0x86, 0x00, 0x97, 0xa5, 0x30, 0x81, 0xd7, 0xf7, 0x06, 0xf7, 0x47, 0xf8, 0xea, + 0xa6, 0xd7, 0xfa, 0x79, 0xd3, 0x7b, 0x9e, 0x32, 0x93, 0x95, 0x33, 0x1c, 0x4b, 0x1e, 0xc5, 0x52, + 0x73, 0xa9, 0x9b, 0x9f, 0xa1, 0x4e, 0xe6, 0x91, 0x59, 0x16, 0x54, 0xe3, 0xf7, 0xc2, 0x4c, 0x1e, + 0x72, 0x26, 0xc6, 0x0e, 0xf4, 0xc6, 0x72, 0xfc, 0xd7, 0xa8, 0xcb, 0xa1, 0x22, 0x85, 0x62, 0x5f, + 0x28, 0xd1, 0x46, 0x81, 0xa1, 0xe9, 0x92, 0xcc, 0xc0, 0xc4, 0x19, 0xd5, 0xc1, 0x9d, 0xbe, 0x37, + 0x38, 0x98, 0x9c, 0x72, 0xa8, 0xce, 0x6a, 0xc1, 0xb4, 0x99, 0x8f, 0xdc, 0xd8, 0x7f, 0x85, 0x82, + 0xad, 0xd9, 0x7a, 0xc8, 0xe7, 0x12, 0x84, 0x61, 0x66, 0x19, 0xdc, 0xb5, 0xd6, 0xc7, 0x1b, 0xab, + 0xb5, 0x9c, 0x37, 0x43, 0xff, 0x02, 0x9d, 0xda, 0x9d, 0x14, 0x2c, 0x88, 0x8e, 0x33, 0x9a, 0x94, + 0x39, 0x25, 0x09, 0xcd, 0x0d, 0x04, 0x07, 0x7d, 0x6f, 0x70, 0xfc, 0xe2, 0x09, 0x76, 0x05, 0xe1, + 0x4d, 0x41, 0x78, 0xdc, 0x14, 0x34, 0x3a, 0xaa, 0x77, 0xfe, 0xf6, 0xab, 0xe7, 0x4d, 0x3a, 0xf5, + 0x36, 0x0a, 0x16, 0xd3, 0x86, 0x30, 0xae, 0x01, 0x96, 0x0d, 0xd5, 0x7f, 0xd9, 0x87, 0xfb, 0xb0, + 0xa1, 0xfa, 0x97, 0xfd, 0x11, 0x9d, 0xb8, 0x65, 0x69, 0x55, 0x30, 0xe7, 0x69, 0xd0, 0xed, 0x3d, + 0xd0, 0x16, 0xf1, 0xf6, 0x2f, 0xc1, 0xa1, 0xcf, 0xd1, 0x83, 0x4b, 0x4a, 0x35, 0xd1, 0x06, 0xe6, + 0x54, 0xe9, 0xe0, 0xde, 0xde, 0x1f, 0x78, 0x4c, 0xe3, 0xc9, 0x71, 0xcd, 0x98, 0x3a, 0x84, 0xff, + 0x01, 0x9d, 0xec, 0x9e, 0x1c, 0xdb, 0x88, 0x4b, 0x7b, 0x74, 0xfb, 0xb4, 0x8f, 0xb6, 0x47, 0xa6, + 0xee, 0xc3, 0x86, 0x1d, 0xbd, 0xbb, 0x5a, 0x85, 0xde, 0xf5, 0x2a, 0xf4, 0x7e, 0xaf, 0x42, 0xef, + 0xeb, 0x3a, 0x6c, 0x5d, 0xaf, 0xc3, 0xd6, 0x8f, 0x75, 0xd8, 0xba, 0x18, 0xee, 0x04, 0xdd, 0xbd, + 0x32, 0x71, 0x06, 0x4c, 0x44, 0xd5, 0xf6, 0xea, 0xd8, 0xcc, 0xb3, 0xb6, 0x7d, 0xf5, 0xcb, 0x3f, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x0a, 0xa2, 0x6c, 0xd6, 0x5f, 0x03, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MinDepositDrawDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MinDepositDrawDelta):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x42 + { + size := m.FeesStakers.Size() + i -= size + if _, err := m.FeesStakers.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.PrizeExpirationDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.PrizeExpirationDelta):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintParams(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x32 + n3, err3 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MaxDrawScheduleDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxDrawScheduleDelta):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintParams(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x2a + n4, err4 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MinDrawScheduleDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MinDrawScheduleDelta):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintParams(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x22 + if m.MaxPrizeBatchQuantity != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MaxPrizeBatchQuantity)) + i-- + dAtA[i] = 0x18 + } + if m.MaxPrizeStrategyBatches != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MaxPrizeStrategyBatches)) + i-- + dAtA[i] = 0x10 + } + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MinDepositAmount.Size() + n += 1 + l + sovParams(uint64(l)) + if m.MaxPrizeStrategyBatches != 0 { + n += 1 + sovParams(uint64(m.MaxPrizeStrategyBatches)) + } + if m.MaxPrizeBatchQuantity != 0 { + n += 1 + sovParams(uint64(m.MaxPrizeBatchQuantity)) + } + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.MinDrawScheduleDelta) + n += 1 + l + sovParams(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxDrawScheduleDelta) + n += 1 + l + sovParams(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.PrizeExpirationDelta) + n += 1 + l + sovParams(uint64(l)) + l = m.FeesStakers.Size() + n += 1 + l + sovParams(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.MinDepositDrawDelta) + n += 1 + l + sovParams(uint64(l)) + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPrizeStrategyBatches", wireType) + } + m.MaxPrizeStrategyBatches = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxPrizeStrategyBatches |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPrizeBatchQuantity", wireType) + } + m.MaxPrizeBatchQuantity = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxPrizeBatchQuantity |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDrawScheduleDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.MinDrawScheduleDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxDrawScheduleDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.MaxDrawScheduleDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeExpirationDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.PrizeExpirationDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeesStakers", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FeesStakers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositDrawDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.MinDepositDrawDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/pool.go b/x/millions/types/pool.go new file mode 100644 index 00000000..7aac7a5a --- /dev/null +++ b/x/millions/types/pool.go @@ -0,0 +1,220 @@ +package types + +import ( + "sort" + "strings" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ValidateBasic validates if a pool has a valid configuration +// meaning that it can be stored +func (pool *Pool) ValidateBasic(params Params) error { + if pool.PoolId == UnknownID { + return ErrInvalidID + } + if pool.State == PoolState_Unspecified { + return errorsmod.Wrapf(ErrInvalidPoolParams, "no state specified") + } + if err := sdk.ValidateDenom(pool.Denom); err != nil { + return errorsmod.Wrapf(ErrInvalidPoolParams, err.Error()) + } + if err := sdk.ValidateDenom(pool.NativeDenom); err != nil { + return errorsmod.Wrapf(ErrInvalidPoolParams, err.Error()) + } + if strings.TrimSpace(pool.ChainId) == "" { + return errorsmod.Wrapf(ErrInvalidPoolParams, "empty chain ID") + } + if strings.TrimSpace(pool.Bech32PrefixAccAddr) == "" { + return errorsmod.Wrapf(ErrInvalidPoolParams, "empty bech32 prefix account address") + } + if strings.TrimSpace(pool.Bech32PrefixValAddr) == "" { + return errorsmod.Wrapf(ErrInvalidPoolParams, "empty bech32 prefix validator address") + } + if len(pool.Validators) == 0 { + return errorsmod.Wrapf(ErrInvalidPoolParams, "empty validators set") + } else { + for _, val := range pool.Validators { + bz, err := sdk.GetFromBech32(val.OperatorAddress, pool.Bech32PrefixValAddr) + if err != nil { + return errorsmod.Wrapf(ErrInvalidPoolParams, "invalid validator address %s: %v", val.OperatorAddress, err) + } + err = sdk.VerifyAddressFormat(bz) + if err != nil { + return errorsmod.Wrapf(ErrInvalidPoolParams, "invalid validator address %s: %v", val.OperatorAddress, err) + } + } + } + if pool.MinDepositAmount.IsNil() || pool.MinDepositAmount.LT(params.MinDepositAmount) { + return errorsmod.Wrapf(ErrInvalidPoolParams, "min deposit denom must be gte %d", params.MinDepositAmount.Int64()) + } + if pool.AvailablePrizePool.IsNil() || pool.AvailablePrizePool.Denom != pool.Denom { + return errorsmod.Wrapf(ErrInvalidPoolParams, "clawback prize pool must be initialized") + } + if err := pool.DrawSchedule.ValidateBasic(params); err != nil { + return errorsmod.Wrapf(ErrInvalidPoolParams, err.Error()) + } + if err := pool.PrizeStrategy.Validate(params); err != nil { + return errorsmod.Wrapf(ErrInvalidPoolParams, err.Error()) + } + return nil +} + +func (p *Pool) IsLocalZone(ctx sdk.Context) bool { + return p.ChainId == ctx.ChainID() +} + +func (p *Pool) ShouldDraw(ctx sdk.Context) bool { + if p.State == PoolState_Ready && (p.LastDrawState == DrawState_Unspecified || p.LastDrawState == DrawState_Success) { + return p.DrawSchedule.ShouldDraw(ctx, p.LastDrawCreatedAt) + } + return false +} + +// ActiveValidators returns currently enabled validators +func (p *Pool) ActiveValidators() (vals []*PoolValidator) { + for _, v := range p.Validators { + if v.IsEnabled { + vals = append(vals, v) + } + } + return +} + +// BondedValidators returns active and inactive validators with a bonded amount > 0 for +func (p *Pool) BondedValidators() (activeVals, inactiveVals []*PoolValidator) { + for _, v := range p.Validators { + if v.IsBonded() { + if v.IsEnabled { + activeVals = append(activeVals, v) + } else { + inactiveVals = append(inactiveVals, v) + } + } + } + return +} + +// ComputeSplitDelegations computes the delegation split to enforce based on the active validators in the set +// amount is divided evenly to all active validators +func (p *Pool) ComputeSplitDelegations(ctx sdk.Context, amount math.Int) (splits []*SplitDelegation) { + activeValidators := p.ActiveValidators() + if len(activeValidators) <= 0 { + return nil + } + used := math.ZeroInt() + valShare := amount.QuoRaw(int64(len(activeValidators))) + + for i, v := range activeValidators { + // Compute the amount to use + var relativeAmount math.Int + if i == len(activeValidators)-1 { + relativeAmount = amount.Sub(used) + } else { + relativeAmount = valShare + } + + // Append to the destination structure + splits = append(splits, &SplitDelegation{ + ValidatorAddress: v.OperatorAddress, + Amount: relativeAmount, + }) + used = used.Add(relativeAmount) + } + + if !used.Equal(amount) { + // Returns nil in case we did something sketchy when computing amount + return nil + } + + return +} + +// ComputeSplitUndelegations compute the undelegation split to enforce based on the bonded validators in the set +// disabled validators are prioritized and remaining amount is divided evenly between all validators +func (p *Pool) ComputeSplitUndelegations(ctx sdk.Context, amount math.Int) (splits []*SplitDelegation) { + bondedActiveVals, bondedInactiveVals := p.BondedValidators() + if len(bondedActiveVals) <= 0 && len(bondedInactiveVals) <= 0 { + return nil + } + used := math.ZeroInt() + + // Sort vals by bonded amount descending to ensure we can fulfill the request + sort.Slice(bondedInactiveVals, func(i, j int) bool { + return bondedInactiveVals[i].BondedAmount.GT(bondedInactiveVals[j].BondedAmount) + }) + for _, v := range bondedInactiveVals { + // Undelegate as much as we can + relativeAmount := math.MinInt(v.BondedAmount, amount.Sub(used)) + if relativeAmount.LTE(sdk.ZeroInt()) { + continue + } + + // Append to the destination structure + splits = append(splits, &SplitDelegation{ + ValidatorAddress: v.OperatorAddress, + Amount: relativeAmount, + }) + used = used.Add(relativeAmount) + + if used.Equal(amount) { + break + } + } + + if !used.Equal(amount) { + // Sort vals by bonded amount ascending to ensure we can fulfill the request + sort.Slice(bondedActiveVals, func(i, j int) bool { + return bondedActiveVals[j].BondedAmount.GT(bondedActiveVals[i].BondedAmount) + }) + + // Undelegate from active validator set + for i, v := range bondedActiveVals { + // Compute the amount to use each round to ensure fairness + valShare := amount.Sub(used).QuoRaw(int64(len(bondedActiveVals) - i)) + relativeAmount := math.MinInt(v.BondedAmount, valShare) + if i == len(bondedActiveVals)-1 && v.BondedAmount.GTE(amount.Sub(used)) { + // Take remaining amount + relativeAmount = amount.Sub(used) + } + if relativeAmount.LTE(sdk.ZeroInt()) { + continue + } + + // Append to the destination structure + splits = append(splits, &SplitDelegation{ + ValidatorAddress: v.OperatorAddress, + Amount: relativeAmount, + }) + used = used.Add(relativeAmount) + + if used.Equal(amount) { + break + } + } + } + + if !used.Equal(amount) { + // Returns nil in case we cannot consume the whole amount + return nil + } + + return +} + +func (p *Pool) ApplySplitDelegate(ctx sdk.Context, splits []*SplitDelegation) { + for _, split := range splits { + p.Validators[split.ValidatorAddress].BondedAmount = p.Validators[split.ValidatorAddress].BondedAmount.Add(split.Amount) + } +} + +func (p *Pool) ApplySplitUndelegate(ctx sdk.Context, splits []*SplitDelegation) { + for _, split := range splits { + p.Validators[split.ValidatorAddress].BondedAmount = p.Validators[split.ValidatorAddress].BondedAmount.Sub(split.Amount) + if p.Validators[split.ValidatorAddress].BondedAmount.LT(sdk.ZeroInt()) { + panic(ErrPoolInvalidSplit) + } + } +} diff --git a/x/millions/types/pool.pb.go b/x/millions/types/pool.pb.go new file mode 100644 index 00000000..ccbeaccf --- /dev/null +++ b/x/millions/types/pool.pb.go @@ -0,0 +1,2169 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/pool.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// PoolState the state of a Pool +// Deposits are only accepted for Pools in a Ready state +// +// TODO: +// Pool states PAUSED and KILLED are not available in the current implementation +// Introduce the capability to: +// - Pause a Pool in case of Interchain issues or via Governance proposal +// - Kill a Pool and withdraw or migrate all deposits to another Pool via Governance proposal +type PoolState int32 + +const ( + PoolState_Unspecified PoolState = 0 + PoolState_Created PoolState = 1 + PoolState_Ready PoolState = 2 + PoolState_Paused PoolState = 3 + PoolState_Killed PoolState = 4 +) + +var PoolState_name = map[int32]string{ + 0: "POOL_STATE_UNSPECIFIED", + 1: "POOL_STATE_CREATED", + 2: "POOL_STATE_READY", + 3: "POOL_STATE_PAUSED", + 4: "POOL_STATE_KILLED", +} + +var PoolState_value = map[string]int32{ + "POOL_STATE_UNSPECIFIED": 0, + "POOL_STATE_CREATED": 1, + "POOL_STATE_READY": 2, + "POOL_STATE_PAUSED": 3, + "POOL_STATE_KILLED": 4, +} + +func (x PoolState) String() string { + return proto.EnumName(PoolState_name, int32(x)) +} + +func (PoolState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_1ae6867ade255d94, []int{0} +} + +type Pool struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` + NativeDenom string `protobuf:"bytes,3,opt,name=native_denom,json=nativeDenom,proto3" json:"native_denom,omitempty"` + ChainId string `protobuf:"bytes,4,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + ConnectionId string `protobuf:"bytes,5,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + TransferChannelId string `protobuf:"bytes,6,opt,name=transfer_channel_id,json=transferChannelId,proto3" json:"transfer_channel_id,omitempty"` + IcaDepositPortId string `protobuf:"bytes,7,opt,name=ica_deposit_port_id,json=icaDepositPortId,proto3" json:"ica_deposit_port_id,omitempty"` + IcaPrizepoolPortId string `protobuf:"bytes,8,opt,name=ica_prizepool_port_id,json=icaPrizepoolPortId,proto3" json:"ica_prizepool_port_id,omitempty"` + Validators map[string]*PoolValidator `protobuf:"bytes,10,rep,name=validators,proto3" json:"validators,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Bech32PrefixAccAddr string `protobuf:"bytes,11,opt,name=bech32_prefix_acc_addr,json=bech32PrefixAccAddr,proto3" json:"bech32_prefix_acc_addr,omitempty"` + Bech32PrefixValAddr string `protobuf:"bytes,12,opt,name=bech32_prefix_val_addr,json=bech32PrefixValAddr,proto3" json:"bech32_prefix_val_addr,omitempty"` + MinDepositAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,13,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount"` + DrawSchedule DrawSchedule `protobuf:"bytes,14,opt,name=draw_schedule,json=drawSchedule,proto3" json:"draw_schedule"` + PrizeStrategy PrizeStrategy `protobuf:"bytes,15,opt,name=prize_strategy,json=prizeStrategy,proto3" json:"prize_strategy"` + LocalAddress string `protobuf:"bytes,18,opt,name=local_address,json=localAddress,proto3" json:"local_address,omitempty"` + IcaDepositAddress string `protobuf:"bytes,19,opt,name=ica_deposit_address,json=icaDepositAddress,proto3" json:"ica_deposit_address,omitempty"` + IcaPrizepoolAddress string `protobuf:"bytes,20,opt,name=ica_prizepool_address,json=icaPrizepoolAddress,proto3" json:"ica_prizepool_address,omitempty"` + NextDrawId uint64 `protobuf:"varint,22,opt,name=next_draw_id,json=nextDrawId,proto3" json:"next_draw_id,omitempty"` + TvlAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,23,opt,name=tvl_amount,json=tvlAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"tvl_amount"` + DepositorsCount uint64 `protobuf:"varint,24,opt,name=depositors_count,json=depositorsCount,proto3" json:"depositors_count,omitempty"` + SponsorshipAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,25,opt,name=sponsorship_amount,json=sponsorshipAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"sponsorship_amount"` + LastDrawCreatedAt *time.Time `protobuf:"bytes,27,opt,name=last_draw_created_at,json=lastDrawCreatedAt,proto3,stdtime" json:"last_draw_created_at,omitempty"` + LastDrawState DrawState `protobuf:"varint,28,opt,name=last_draw_state,json=lastDrawState,proto3,enum=lum.network.millions.DrawState" json:"last_draw_state,omitempty"` + AvailablePrizePool types.Coin `protobuf:"bytes,29,opt,name=available_prize_pool,json=availablePrizePool,proto3" json:"available_prize_pool"` + State PoolState `protobuf:"varint,32,opt,name=state,proto3,enum=lum.network.millions.PoolState" json:"state,omitempty"` + CreatedAtHeight int64 `protobuf:"varint,33,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` + UpdatedAtHeight int64 `protobuf:"varint,34,opt,name=updated_at_height,json=updatedAtHeight,proto3" json:"updated_at_height,omitempty"` + CreatedAt time.Time `protobuf:"bytes,35,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` + UpdatedAt time.Time `protobuf:"bytes,36,opt,name=updated_at,json=updatedAt,proto3,stdtime" json:"updated_at"` +} + +func (m *Pool) Reset() { *m = Pool{} } +func (m *Pool) String() string { return proto.CompactTextString(m) } +func (*Pool) ProtoMessage() {} +func (*Pool) Descriptor() ([]byte, []int) { + return fileDescriptor_1ae6867ade255d94, []int{0} +} +func (m *Pool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Pool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Pool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Pool) XXX_Merge(src proto.Message) { + xxx_messageInfo_Pool.Merge(m, src) +} +func (m *Pool) XXX_Size() int { + return m.Size() +} +func (m *Pool) XXX_DiscardUnknown() { + xxx_messageInfo_Pool.DiscardUnknown(m) +} + +var xxx_messageInfo_Pool proto.InternalMessageInfo + +func (m *Pool) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *Pool) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *Pool) GetNativeDenom() string { + if m != nil { + return m.NativeDenom + } + return "" +} + +func (m *Pool) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *Pool) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *Pool) GetTransferChannelId() string { + if m != nil { + return m.TransferChannelId + } + return "" +} + +func (m *Pool) GetIcaDepositPortId() string { + if m != nil { + return m.IcaDepositPortId + } + return "" +} + +func (m *Pool) GetIcaPrizepoolPortId() string { + if m != nil { + return m.IcaPrizepoolPortId + } + return "" +} + +func (m *Pool) GetValidators() map[string]*PoolValidator { + if m != nil { + return m.Validators + } + return nil +} + +func (m *Pool) GetBech32PrefixAccAddr() string { + if m != nil { + return m.Bech32PrefixAccAddr + } + return "" +} + +func (m *Pool) GetBech32PrefixValAddr() string { + if m != nil { + return m.Bech32PrefixValAddr + } + return "" +} + +func (m *Pool) GetDrawSchedule() DrawSchedule { + if m != nil { + return m.DrawSchedule + } + return DrawSchedule{} +} + +func (m *Pool) GetPrizeStrategy() PrizeStrategy { + if m != nil { + return m.PrizeStrategy + } + return PrizeStrategy{} +} + +func (m *Pool) GetLocalAddress() string { + if m != nil { + return m.LocalAddress + } + return "" +} + +func (m *Pool) GetIcaDepositAddress() string { + if m != nil { + return m.IcaDepositAddress + } + return "" +} + +func (m *Pool) GetIcaPrizepoolAddress() string { + if m != nil { + return m.IcaPrizepoolAddress + } + return "" +} + +func (m *Pool) GetNextDrawId() uint64 { + if m != nil { + return m.NextDrawId + } + return 0 +} + +func (m *Pool) GetDepositorsCount() uint64 { + if m != nil { + return m.DepositorsCount + } + return 0 +} + +func (m *Pool) GetLastDrawCreatedAt() *time.Time { + if m != nil { + return m.LastDrawCreatedAt + } + return nil +} + +func (m *Pool) GetLastDrawState() DrawState { + if m != nil { + return m.LastDrawState + } + return DrawState_Unspecified +} + +func (m *Pool) GetAvailablePrizePool() types.Coin { + if m != nil { + return m.AvailablePrizePool + } + return types.Coin{} +} + +func (m *Pool) GetState() PoolState { + if m != nil { + return m.State + } + return PoolState_Unspecified +} + +func (m *Pool) GetCreatedAtHeight() int64 { + if m != nil { + return m.CreatedAtHeight + } + return 0 +} + +func (m *Pool) GetUpdatedAtHeight() int64 { + if m != nil { + return m.UpdatedAtHeight + } + return 0 +} + +func (m *Pool) GetCreatedAt() time.Time { + if m != nil { + return m.CreatedAt + } + return time.Time{} +} + +func (m *Pool) GetUpdatedAt() time.Time { + if m != nil { + return m.UpdatedAt + } + return time.Time{} +} + +type PoolValidator struct { + OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` + IsEnabled bool `protobuf:"varint,2,opt,name=is_enabled,json=isEnabled,proto3" json:"is_enabled,omitempty"` + BondedAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=bonded_amount,json=bondedAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"bonded_amount"` +} + +func (m *PoolValidator) Reset() { *m = PoolValidator{} } +func (m *PoolValidator) String() string { return proto.CompactTextString(m) } +func (*PoolValidator) ProtoMessage() {} +func (*PoolValidator) Descriptor() ([]byte, []int) { + return fileDescriptor_1ae6867ade255d94, []int{1} +} +func (m *PoolValidator) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PoolValidator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PoolValidator.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PoolValidator) XXX_Merge(src proto.Message) { + xxx_messageInfo_PoolValidator.Merge(m, src) +} +func (m *PoolValidator) XXX_Size() int { + return m.Size() +} +func (m *PoolValidator) XXX_DiscardUnknown() { + xxx_messageInfo_PoolValidator.DiscardUnknown(m) +} + +var xxx_messageInfo_PoolValidator proto.InternalMessageInfo + +func (m *PoolValidator) GetOperatorAddress() string { + if m != nil { + return m.OperatorAddress + } + return "" +} + +func (m *PoolValidator) GetIsEnabled() bool { + if m != nil { + return m.IsEnabled + } + return false +} + +func init() { + proto.RegisterEnum("lum.network.millions.PoolState", PoolState_name, PoolState_value) + proto.RegisterType((*Pool)(nil), "lum.network.millions.Pool") + proto.RegisterMapType((map[string]*PoolValidator)(nil), "lum.network.millions.Pool.ValidatorsEntry") + proto.RegisterType((*PoolValidator)(nil), "lum.network.millions.PoolValidator") +} + +func init() { proto.RegisterFile("lum-network/millions/pool.proto", fileDescriptor_1ae6867ade255d94) } + +var fileDescriptor_1ae6867ade255d94 = []byte{ + // 1224 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xd1, 0x6e, 0x1a, 0x47, + 0x14, 0xf5, 0xc6, 0xd8, 0x86, 0x31, 0x98, 0x65, 0x4c, 0x9c, 0x35, 0x69, 0x60, 0xe3, 0x54, 0x15, + 0x49, 0xe5, 0x45, 0x71, 0x54, 0xa9, 0xad, 0xd4, 0x07, 0x0c, 0x34, 0x81, 0x38, 0x0d, 0x5d, 0xec, + 0x48, 0xad, 0x5a, 0xad, 0x86, 0x9d, 0x31, 0x8c, 0xb2, 0xec, 0xac, 0x76, 0x07, 0x12, 0xf7, 0x0b, + 0x2a, 0x3f, 0xe5, 0x07, 0xfc, 0xd4, 0x5f, 0xe8, 0x47, 0x58, 0xed, 0x4b, 0xd4, 0xa7, 0xaa, 0x0f, + 0x69, 0x95, 0xfc, 0x48, 0x35, 0x33, 0xbb, 0x80, 0x1d, 0x27, 0x69, 0xfd, 0x04, 0x73, 0xef, 0xb9, + 0x67, 0xee, 0x9c, 0x7b, 0xef, 0xcc, 0x82, 0x8a, 0x37, 0x1e, 0x6d, 0xfb, 0x84, 0x3f, 0x63, 0xe1, + 0xd3, 0xda, 0x88, 0x7a, 0x1e, 0x65, 0x7e, 0x54, 0x0b, 0x18, 0xf3, 0xac, 0x20, 0x64, 0x9c, 0xc1, + 0xa2, 0x37, 0x1e, 0x59, 0x31, 0xc0, 0x4a, 0x00, 0xa5, 0xe2, 0x80, 0x0d, 0x98, 0x04, 0xd4, 0xc4, + 0x3f, 0x85, 0x2d, 0x55, 0x06, 0x8c, 0x0d, 0x3c, 0x52, 0x93, 0xab, 0xfe, 0xf8, 0xb0, 0xc6, 0xe9, + 0x88, 0x44, 0x1c, 0x8d, 0x82, 0x18, 0x50, 0x76, 0x59, 0x34, 0x62, 0x51, 0xad, 0x8f, 0x22, 0x52, + 0x9b, 0xdc, 0xed, 0x13, 0x8e, 0xee, 0xd6, 0x5c, 0x46, 0xfd, 0xd8, 0xbf, 0xa9, 0xfc, 0x8e, 0x62, + 0x56, 0x8b, 0x84, 0xfb, 0xc2, 0x44, 0x71, 0x88, 0x9e, 0xc5, 0x80, 0xea, 0x3b, 0x01, 0x4e, 0xe4, + 0x0e, 0x09, 0x1e, 0x7b, 0x24, 0x46, 0xde, 0xbe, 0xf8, 0xcc, 0x21, 0xfd, 0x89, 0x38, 0x11, 0x0f, + 0x11, 0x27, 0x83, 0x23, 0x05, 0xdd, 0xfa, 0x7d, 0x0d, 0xa4, 0xba, 0x8c, 0x79, 0xf0, 0x1a, 0x58, + 0x11, 0xa2, 0x38, 0x14, 0x1b, 0x9a, 0xa9, 0x55, 0x53, 0xf6, 0xb2, 0x58, 0xb6, 0x31, 0x2c, 0x82, + 0x25, 0x4c, 0x7c, 0x36, 0x32, 0xae, 0x98, 0x5a, 0x35, 0x63, 0xab, 0x05, 0xbc, 0x09, 0xb2, 0x3e, + 0xe2, 0x74, 0x42, 0x1c, 0xe5, 0x5c, 0x94, 0xce, 0x55, 0x65, 0x6b, 0x4a, 0xc8, 0x26, 0x48, 0xbb, + 0x43, 0x44, 0x7d, 0x41, 0x99, 0x92, 0xee, 0x15, 0xb9, 0x6e, 0x63, 0x78, 0x0b, 0xe4, 0x5c, 0xe6, + 0xfb, 0xc4, 0xe5, 0x94, 0x49, 0xff, 0x92, 0xf4, 0x67, 0x67, 0xc6, 0x36, 0x86, 0x16, 0x58, 0xe7, + 0x21, 0xf2, 0xa3, 0x43, 0x12, 0x3a, 0xee, 0x10, 0xf9, 0x3e, 0x91, 0xd9, 0x2d, 0x4b, 0x68, 0x21, + 0x71, 0x35, 0x94, 0xa7, 0x8d, 0xe1, 0x36, 0x58, 0xa7, 0x2e, 0x72, 0x30, 0x09, 0x58, 0x44, 0xb9, + 0x13, 0xb0, 0x90, 0x0b, 0xfc, 0x8a, 0xc4, 0xeb, 0xd4, 0x45, 0x4d, 0xe5, 0xe9, 0xb2, 0x90, 0xb7, + 0x31, 0xbc, 0x0b, 0xae, 0x0a, 0xb8, 0x54, 0x45, 0x9e, 0x3c, 0x09, 0x48, 0xcb, 0x00, 0x48, 0x5d, + 0xd4, 0x4d, 0x7c, 0x71, 0x48, 0x07, 0x80, 0x09, 0xf2, 0x28, 0x46, 0x9c, 0x85, 0x91, 0x01, 0xcc, + 0xc5, 0xea, 0xea, 0xce, 0x1d, 0xeb, 0xa2, 0xfe, 0xb1, 0x84, 0xa6, 0xd6, 0x93, 0x29, 0xb8, 0xe5, + 0xf3, 0xf0, 0xc8, 0x9e, 0x8b, 0x86, 0xf7, 0xc0, 0x46, 0x9f, 0xb8, 0xc3, 0x7b, 0x3b, 0x4e, 0x10, + 0x92, 0x43, 0xfa, 0xdc, 0x41, 0xae, 0xeb, 0x20, 0x8c, 0x43, 0x63, 0x55, 0xee, 0xbf, 0xae, 0xbc, + 0x5d, 0xe9, 0xac, 0xbb, 0x6e, 0x1d, 0xe3, 0xf0, 0xed, 0xa0, 0x09, 0xf2, 0x54, 0x50, 0xf6, 0xed, + 0xa0, 0x27, 0xc8, 0x93, 0x41, 0x3f, 0x00, 0x38, 0xa2, 0xfe, 0x54, 0x17, 0x34, 0x62, 0x63, 0x9f, + 0x1b, 0x39, 0x11, 0xb0, 0x6b, 0x9d, 0xbe, 0xaa, 0x2c, 0xfc, 0xf5, 0xaa, 0xf2, 0xc9, 0x80, 0xf2, + 0xe1, 0xb8, 0x6f, 0xb9, 0x6c, 0x14, 0x77, 0x65, 0xfc, 0xb3, 0x1d, 0xe1, 0xa7, 0x35, 0x7e, 0x14, + 0x90, 0xc8, 0x6a, 0xfb, 0xdc, 0xd6, 0x47, 0xd4, 0x8f, 0x65, 0xac, 0x4b, 0x1e, 0xf8, 0x08, 0xe4, + 0xce, 0xb4, 0xa0, 0xb1, 0x66, 0x6a, 0xd5, 0xd5, 0x9d, 0xad, 0x8b, 0x65, 0x69, 0x86, 0xe8, 0x59, + 0x2f, 0x46, 0xee, 0xa6, 0xc4, 0xe6, 0x76, 0x16, 0xcf, 0xd9, 0x60, 0x17, 0xac, 0x9d, 0xed, 0x53, + 0x23, 0x2f, 0xf9, 0x6e, 0xbd, 0x43, 0x66, 0x81, 0xed, 0xc5, 0xd0, 0x98, 0x30, 0x17, 0xcc, 0x1b, + 0xe1, 0x57, 0x20, 0xe7, 0x31, 0x37, 0xd6, 0x89, 0x44, 0x91, 0x01, 0xe5, 0xc9, 0x8d, 0x3f, 0x7e, + 0xdd, 0x2e, 0xc6, 0x03, 0x58, 0x57, 0x9e, 0x1e, 0x0f, 0xa9, 0x3f, 0xb0, 0xb3, 0x12, 0x1e, 0xdb, + 0xe0, 0x83, 0xb3, 0x5d, 0x95, 0x90, 0xac, 0x7f, 0x80, 0xa4, 0x30, 0xeb, 0xb7, 0x84, 0x69, 0xef, + 0x7c, 0xc3, 0x25, 0x5c, 0xc5, 0x0f, 0x70, 0xad, 0xcf, 0xb7, 0x62, 0xc2, 0x66, 0x82, 0xac, 0x4f, + 0x9e, 0x73, 0x47, 0x8a, 0x4f, 0xb1, 0xb1, 0x21, 0x87, 0x16, 0x08, 0x9b, 0x10, 0xb9, 0x8d, 0xe1, + 0x23, 0x00, 0xf8, 0xc4, 0x4b, 0xea, 0x7d, 0xed, 0x52, 0xf5, 0xce, 0xf0, 0x89, 0x17, 0x17, 0xfa, + 0x36, 0xd0, 0x63, 0x11, 0x58, 0x18, 0x39, 0xae, 0x24, 0x35, 0xe4, 0xa6, 0xf9, 0x99, 0xbd, 0x21, + 0xa1, 0x3f, 0x02, 0x18, 0x05, 0xcc, 0x8f, 0x58, 0x18, 0x0d, 0x69, 0x90, 0x64, 0xb0, 0x79, 0xa9, + 0x0c, 0x0a, 0x73, 0x4c, 0x71, 0x26, 0x07, 0xa0, 0xe8, 0xa1, 0x28, 0x3e, 0xba, 0x1b, 0x12, 0xc4, + 0x09, 0x76, 0x10, 0x37, 0xae, 0xcb, 0x4e, 0x29, 0x59, 0xea, 0x92, 0xb6, 0x92, 0x4b, 0xda, 0xda, + 0x4f, 0x2e, 0xe9, 0xdd, 0xf4, 0xe9, 0xab, 0x8a, 0xf6, 0xe2, 0xef, 0x8a, 0x66, 0x17, 0x04, 0x83, + 0x10, 0xaa, 0xa1, 0xe2, 0xeb, 0x1c, 0xde, 0x07, 0xf9, 0x19, 0x6d, 0xc4, 0x11, 0x27, 0xc6, 0x47, + 0xa6, 0x56, 0x5d, 0xdb, 0xa9, 0xbc, 0xa7, 0x97, 0x05, 0xcc, 0xce, 0x25, 0x64, 0x72, 0x09, 0xbf, + 0x05, 0x45, 0x34, 0x41, 0xd4, 0x43, 0x7d, 0x8f, 0xa8, 0x72, 0x3b, 0xa2, 0x72, 0xc6, 0x0d, 0x99, + 0xdf, 0xa6, 0x15, 0x17, 0x59, 0xbc, 0x11, 0x56, 0xfc, 0x46, 0x58, 0x0d, 0x46, 0xfd, 0xb8, 0x7f, + 0xe1, 0x34, 0x58, 0x16, 0x5d, 0xde, 0xce, 0x9f, 0x81, 0x25, 0x95, 0x91, 0xf9, 0xbe, 0x8c, 0x04, + 0x54, 0x65, 0xa4, 0xd0, 0xf0, 0x0e, 0x28, 0xcc, 0xf4, 0x71, 0x86, 0x84, 0x0e, 0x86, 0xdc, 0xb8, + 0x69, 0x6a, 0xd5, 0x45, 0x3b, 0xef, 0x26, 0x07, 0x7f, 0x20, 0xcd, 0x02, 0x3b, 0x0e, 0xf0, 0x39, + 0xec, 0x96, 0xc2, 0xc6, 0x8e, 0x29, 0xb6, 0x01, 0xc0, 0x9c, 0xee, 0xb7, 0xfe, 0x93, 0xee, 0x0b, + 0x52, 0xf7, 0xcc, 0x74, 0x5b, 0x41, 0x32, 0xdb, 0xd0, 0xf8, 0xf8, 0xff, 0x90, 0x4c, 0xf3, 0x29, + 0xf5, 0x41, 0xfe, 0xdc, 0x2d, 0x0b, 0x75, 0xb0, 0xf8, 0x94, 0x1c, 0xc9, 0x57, 0x2c, 0x63, 0x8b, + 0xbf, 0xf0, 0x0b, 0xb0, 0x34, 0x41, 0xde, 0x98, 0xc8, 0x27, 0xec, 0xdd, 0x77, 0x09, 0x63, 0xde, + 0x94, 0xcb, 0x56, 0x11, 0x5f, 0x5e, 0xf9, 0x5c, 0xeb, 0xa4, 0xd2, 0x19, 0x1d, 0x74, 0x52, 0x69, + 0x5d, 0x2f, 0x74, 0x52, 0xe9, 0x82, 0x0e, 0x3b, 0xa9, 0xf4, 0x55, 0x7d, 0xa3, 0x93, 0x4a, 0x97, + 0xf4, 0xeb, 0x9d, 0x54, 0xba, 0xac, 0x57, 0x3a, 0xa9, 0x74, 0x45, 0x37, 0xb7, 0x4e, 0x35, 0x90, + 0x3b, 0x43, 0x03, 0x1b, 0x40, 0x67, 0x01, 0x09, 0xc5, 0xff, 0xe9, 0xbc, 0x6b, 0x1f, 0x98, 0xf7, + 0x7c, 0x12, 0x91, 0xcc, 0xfa, 0x0d, 0x00, 0x68, 0xe4, 0x10, 0x5f, 0xf4, 0x04, 0x96, 0x87, 0x48, + 0xdb, 0x19, 0x1a, 0xb5, 0x94, 0x01, 0xf6, 0x40, 0xae, 0xcf, 0x7c, 0x2c, 0x74, 0x54, 0x93, 0xb6, + 0x78, 0xa9, 0x49, 0xcb, 0x2a, 0x12, 0x35, 0x64, 0x77, 0x7e, 0xd3, 0x40, 0x66, 0xda, 0x4f, 0xf0, + 0x53, 0xb0, 0xd1, 0x7d, 0xfc, 0x78, 0xcf, 0xe9, 0xed, 0xd7, 0xf7, 0x5b, 0xce, 0xc1, 0x37, 0xbd, + 0x6e, 0xab, 0xd1, 0xfe, 0xba, 0xdd, 0x6a, 0xea, 0x0b, 0xa5, 0xfc, 0xf1, 0x89, 0xb9, 0x7a, 0xe0, + 0x47, 0x01, 0x71, 0xe9, 0x21, 0x25, 0xe2, 0x75, 0x87, 0x73, 0xe0, 0x86, 0xdd, 0xaa, 0xef, 0xb7, + 0x9a, 0xba, 0x56, 0x5a, 0x3d, 0x3e, 0x31, 0x57, 0xe2, 0x79, 0x83, 0x15, 0xa0, 0xcf, 0x81, 0xec, + 0x56, 0xbd, 0xf9, 0x9d, 0x7e, 0xa5, 0x94, 0x39, 0x3e, 0x31, 0x97, 0x6c, 0x82, 0xf0, 0x11, 0xbc, + 0x09, 0x0a, 0x73, 0x80, 0x6e, 0xfd, 0xa0, 0xd7, 0x6a, 0xea, 0x8b, 0x25, 0x70, 0x7c, 0x62, 0x2e, + 0x77, 0xd1, 0x38, 0x22, 0xf8, 0x1c, 0xe4, 0x61, 0x7b, 0x6f, 0xaf, 0xd5, 0xd4, 0x53, 0x0a, 0xf2, + 0x90, 0x7a, 0x1e, 0xc1, 0xa5, 0xd4, 0xcf, 0xbf, 0x94, 0xb5, 0xdd, 0xfb, 0xa7, 0xaf, 0xcb, 0xda, + 0xcb, 0xd7, 0x65, 0xed, 0x9f, 0xd7, 0x65, 0xed, 0xc5, 0x9b, 0xf2, 0xc2, 0xcb, 0x37, 0xe5, 0x85, + 0x3f, 0xdf, 0x94, 0x17, 0xbe, 0xdf, 0x9e, 0x13, 0x67, 0xfe, 0xab, 0x49, 0x7e, 0xa9, 0xd4, 0x9e, + 0xcf, 0xbe, 0x9e, 0xa4, 0x4e, 0xfd, 0x65, 0xd9, 0x97, 0xf7, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, + 0xac, 0xa8, 0x6f, 0xb6, 0x56, 0x0a, 0x00, 0x00, +} + +func (m *Pool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Pool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpdatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintPool(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0xa2 + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintPool(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x9a + if m.UpdatedAtHeight != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.UpdatedAtHeight)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x90 + } + if m.CreatedAtHeight != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.CreatedAtHeight)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x88 + } + if m.State != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.State)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x80 + } + { + size, err := m.AvailablePrizePool.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xea + if m.LastDrawState != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.LastDrawState)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xe0 + } + if m.LastDrawCreatedAt != nil { + n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.LastDrawCreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(*m.LastDrawCreatedAt):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintPool(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xda + } + { + size := m.SponsorshipAmount.Size() + i -= size + if _, err := m.SponsorshipAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xca + if m.DepositorsCount != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.DepositorsCount)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc0 + } + { + size := m.TvlAmount.Size() + i -= size + if _, err := m.TvlAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xba + if m.NextDrawId != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.NextDrawId)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb0 + } + if len(m.IcaPrizepoolAddress) > 0 { + i -= len(m.IcaPrizepoolAddress) + copy(dAtA[i:], m.IcaPrizepoolAddress) + i = encodeVarintPool(dAtA, i, uint64(len(m.IcaPrizepoolAddress))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa2 + } + if len(m.IcaDepositAddress) > 0 { + i -= len(m.IcaDepositAddress) + copy(dAtA[i:], m.IcaDepositAddress) + i = encodeVarintPool(dAtA, i, uint64(len(m.IcaDepositAddress))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x9a + } + if len(m.LocalAddress) > 0 { + i -= len(m.LocalAddress) + copy(dAtA[i:], m.LocalAddress) + i = encodeVarintPool(dAtA, i, uint64(len(m.LocalAddress))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x92 + } + { + size, err := m.PrizeStrategy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x7a + { + size, err := m.DrawSchedule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x72 + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x6a + if len(m.Bech32PrefixValAddr) > 0 { + i -= len(m.Bech32PrefixValAddr) + copy(dAtA[i:], m.Bech32PrefixValAddr) + i = encodeVarintPool(dAtA, i, uint64(len(m.Bech32PrefixValAddr))) + i-- + dAtA[i] = 0x62 + } + if len(m.Bech32PrefixAccAddr) > 0 { + i -= len(m.Bech32PrefixAccAddr) + copy(dAtA[i:], m.Bech32PrefixAccAddr) + i = encodeVarintPool(dAtA, i, uint64(len(m.Bech32PrefixAccAddr))) + i-- + dAtA[i] = 0x5a + } + if len(m.Validators) > 0 { + for k := range m.Validators { + v := m.Validators[k] + baseI := i + if v != nil { + { + size, err := v.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + i -= len(k) + copy(dAtA[i:], k) + i = encodeVarintPool(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = encodeVarintPool(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x52 + } + } + if len(m.IcaPrizepoolPortId) > 0 { + i -= len(m.IcaPrizepoolPortId) + copy(dAtA[i:], m.IcaPrizepoolPortId) + i = encodeVarintPool(dAtA, i, uint64(len(m.IcaPrizepoolPortId))) + i-- + dAtA[i] = 0x42 + } + if len(m.IcaDepositPortId) > 0 { + i -= len(m.IcaDepositPortId) + copy(dAtA[i:], m.IcaDepositPortId) + i = encodeVarintPool(dAtA, i, uint64(len(m.IcaDepositPortId))) + i-- + dAtA[i] = 0x3a + } + if len(m.TransferChannelId) > 0 { + i -= len(m.TransferChannelId) + copy(dAtA[i:], m.TransferChannelId) + i = encodeVarintPool(dAtA, i, uint64(len(m.TransferChannelId))) + i-- + dAtA[i] = 0x32 + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintPool(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x2a + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintPool(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x22 + } + if len(m.NativeDenom) > 0 { + i -= len(m.NativeDenom) + copy(dAtA[i:], m.NativeDenom) + i = encodeVarintPool(dAtA, i, uint64(len(m.NativeDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintPool(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PoolValidator) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PoolValidator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PoolValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.BondedAmount.Size() + i -= size + if _, err := m.BondedAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.IsEnabled { + i-- + if m.IsEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if len(m.OperatorAddress) > 0 { + i -= len(m.OperatorAddress) + copy(dAtA[i:], m.OperatorAddress) + i = encodeVarintPool(dAtA, i, uint64(len(m.OperatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPool(dAtA []byte, offset int, v uint64) int { + offset -= sovPool(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Pool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovPool(uint64(m.PoolId)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.NativeDenom) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.TransferChannelId) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.IcaDepositPortId) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.IcaPrizepoolPortId) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + if len(m.Validators) > 0 { + for k, v := range m.Validators { + _ = k + _ = v + l = 0 + if v != nil { + l = v.Size() + l += 1 + sovPool(uint64(l)) + } + mapEntrySize := 1 + len(k) + sovPool(uint64(len(k))) + l + n += mapEntrySize + 1 + sovPool(uint64(mapEntrySize)) + } + } + l = len(m.Bech32PrefixAccAddr) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.Bech32PrefixValAddr) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = m.MinDepositAmount.Size() + n += 1 + l + sovPool(uint64(l)) + l = m.DrawSchedule.Size() + n += 1 + l + sovPool(uint64(l)) + l = m.PrizeStrategy.Size() + n += 1 + l + sovPool(uint64(l)) + l = len(m.LocalAddress) + if l > 0 { + n += 2 + l + sovPool(uint64(l)) + } + l = len(m.IcaDepositAddress) + if l > 0 { + n += 2 + l + sovPool(uint64(l)) + } + l = len(m.IcaPrizepoolAddress) + if l > 0 { + n += 2 + l + sovPool(uint64(l)) + } + if m.NextDrawId != 0 { + n += 2 + sovPool(uint64(m.NextDrawId)) + } + l = m.TvlAmount.Size() + n += 2 + l + sovPool(uint64(l)) + if m.DepositorsCount != 0 { + n += 2 + sovPool(uint64(m.DepositorsCount)) + } + l = m.SponsorshipAmount.Size() + n += 2 + l + sovPool(uint64(l)) + if m.LastDrawCreatedAt != nil { + l = github_com_gogo_protobuf_types.SizeOfStdTime(*m.LastDrawCreatedAt) + n += 2 + l + sovPool(uint64(l)) + } + if m.LastDrawState != 0 { + n += 2 + sovPool(uint64(m.LastDrawState)) + } + l = m.AvailablePrizePool.Size() + n += 2 + l + sovPool(uint64(l)) + if m.State != 0 { + n += 2 + sovPool(uint64(m.State)) + } + if m.CreatedAtHeight != 0 { + n += 2 + sovPool(uint64(m.CreatedAtHeight)) + } + if m.UpdatedAtHeight != 0 { + n += 2 + sovPool(uint64(m.UpdatedAtHeight)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) + n += 2 + l + sovPool(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt) + n += 2 + l + sovPool(uint64(l)) + return n +} + +func (m *PoolValidator) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OperatorAddress) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + if m.IsEnabled { + n += 2 + } + l = m.BondedAmount.Size() + n += 1 + l + sovPool(uint64(l)) + return n +} + +func sovPool(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPool(x uint64) (n int) { + return sovPool(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Pool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Pool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Pool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NativeDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NativeDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TransferChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TransferChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IcaDepositPortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IcaDepositPortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IcaPrizepoolPortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IcaPrizepoolPortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Validators == nil { + m.Validators = make(map[string]*PoolValidator) + } + var mapkey string + var mapvalue *PoolValidator + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthPool + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthPool + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthPool + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthPool + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &PoolValidator{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Validators[mapkey] = mapvalue + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32PrefixAccAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32PrefixAccAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32PrefixValAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32PrefixValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 14: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawSchedule", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DrawSchedule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeStrategy", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PrizeStrategy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 18: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LocalAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LocalAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 19: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IcaDepositAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IcaDepositAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 20: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IcaPrizepoolAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IcaPrizepoolAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 22: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextDrawId", wireType) + } + m.NextDrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextDrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 23: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TvlAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TvlAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 24: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorsCount", wireType) + } + m.DepositorsCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositorsCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 25: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SponsorshipAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SponsorshipAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 27: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastDrawCreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.LastDrawCreatedAt == nil { + m.LastDrawCreatedAt = new(time.Time) + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(m.LastDrawCreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 28: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LastDrawState", wireType) + } + m.LastDrawState = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LastDrawState |= DrawState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 29: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AvailablePrizePool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AvailablePrizePool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 32: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + m.State = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.State |= PoolState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 33: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) + } + m.CreatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 34: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAtHeight", wireType) + } + m.UpdatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 35: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 36: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.UpdatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PoolValidator) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PoolValidator: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PoolValidator: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OperatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OperatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsEnabled = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BondedAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BondedAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPool(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPool + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPool + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPool + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPool + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPool + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPool + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPool = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPool = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPool = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/pool_validator.go b/x/millions/types/pool_validator.go new file mode 100644 index 00000000..0594a5c4 --- /dev/null +++ b/x/millions/types/pool_validator.go @@ -0,0 +1,17 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (val *PoolValidator) MustValAddressFromBech32() sdk.ValAddress { + valAddr, err := sdk.ValAddressFromBech32(val.OperatorAddress) + if err != nil { + panic(err) + } + return valAddr +} + +func (val *PoolValidator) IsBonded() bool { + return !val.BondedAmount.IsZero() +} diff --git a/x/millions/types/prize.go b/x/millions/types/prize.go new file mode 100644 index 00000000..565cd0c6 --- /dev/null +++ b/x/millions/types/prize.go @@ -0,0 +1,30 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ValidateBasic validates if a prize is complete and valid +func (prize *Prize) ValidateBasic() error { + if prize.PoolId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "pool ID") + } + if prize.DrawId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "draw ID") + } + if prize.PrizeId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "prize ID") + } + if prize.State == PrizeState_Unspecified { + return errorsmod.Wrapf(ErrInvalidPrizeState, "no state specified") + } + if _, err := sdk.AccAddressFromBech32(prize.WinnerAddress); err != nil { + return errorsmod.Wrapf(ErrInvalidWinnerAddress, err.Error()) + } + if prize.Amount.IsNil() || prize.Amount.Amount.LTE(sdk.ZeroInt()) { + return ErrInvalidPrizeAmount + } + + return nil +} diff --git a/x/millions/types/prize.pb.go b/x/millions/types/prize.pb.go new file mode 100644 index 00000000..92eba1ad --- /dev/null +++ b/x/millions/types/prize.pb.go @@ -0,0 +1,1205 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/prize.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type PrizeState int32 + +const ( + PrizeState_Unspecified PrizeState = 0 + PrizeState_Pending PrizeState = 1 +) + +var PrizeState_name = map[int32]string{ + 0: "PRIZE_STATE_UNSPECIFIED", + 1: "PRIZE_STATE_PENDING", +} + +var PrizeState_value = map[string]int32{ + "PRIZE_STATE_UNSPECIFIED": 0, + "PRIZE_STATE_PENDING": 1, +} + +func (x PrizeState) String() string { + return proto.EnumName(PrizeState_name, int32(x)) +} + +func (PrizeState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_e724d952968386cf, []int{0} +} + +type Prize struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + PrizeId uint64 `protobuf:"varint,3,opt,name=prize_id,json=prizeId,proto3" json:"prize_id,omitempty"` + State PrizeState `protobuf:"varint,4,opt,name=state,proto3,enum=lum.network.millions.PrizeState" json:"state,omitempty"` + WinnerAddress string `protobuf:"bytes,5,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` + Amount types.Coin `protobuf:"bytes,6,opt,name=amount,proto3" json:"amount"` + CreatedAtHeight int64 `protobuf:"varint,7,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` + UpdatedAtHeight int64 `protobuf:"varint,8,opt,name=updated_at_height,json=updatedAtHeight,proto3" json:"updated_at_height,omitempty"` + ExpiresAt time.Time `protobuf:"bytes,9,opt,name=expires_at,json=expiresAt,proto3,stdtime" json:"expires_at"` + CreatedAt time.Time `protobuf:"bytes,10,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` + UpdatedAt time.Time `protobuf:"bytes,11,opt,name=updated_at,json=updatedAt,proto3,stdtime" json:"updated_at"` +} + +func (m *Prize) Reset() { *m = Prize{} } +func (m *Prize) String() string { return proto.CompactTextString(m) } +func (*Prize) ProtoMessage() {} +func (*Prize) Descriptor() ([]byte, []int) { + return fileDescriptor_e724d952968386cf, []int{0} +} +func (m *Prize) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Prize) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Prize.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Prize) XXX_Merge(src proto.Message) { + xxx_messageInfo_Prize.Merge(m, src) +} +func (m *Prize) XXX_Size() int { + return m.Size() +} +func (m *Prize) XXX_DiscardUnknown() { + xxx_messageInfo_Prize.DiscardUnknown(m) +} + +var xxx_messageInfo_Prize proto.InternalMessageInfo + +func (m *Prize) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *Prize) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *Prize) GetPrizeId() uint64 { + if m != nil { + return m.PrizeId + } + return 0 +} + +func (m *Prize) GetState() PrizeState { + if m != nil { + return m.State + } + return PrizeState_Unspecified +} + +func (m *Prize) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func (m *Prize) GetAmount() types.Coin { + if m != nil { + return m.Amount + } + return types.Coin{} +} + +func (m *Prize) GetCreatedAtHeight() int64 { + if m != nil { + return m.CreatedAtHeight + } + return 0 +} + +func (m *Prize) GetUpdatedAtHeight() int64 { + if m != nil { + return m.UpdatedAtHeight + } + return 0 +} + +func (m *Prize) GetExpiresAt() time.Time { + if m != nil { + return m.ExpiresAt + } + return time.Time{} +} + +func (m *Prize) GetCreatedAt() time.Time { + if m != nil { + return m.CreatedAt + } + return time.Time{} +} + +func (m *Prize) GetUpdatedAt() time.Time { + if m != nil { + return m.UpdatedAt + } + return time.Time{} +} + +type PrizeIDs struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + PrizeId uint64 `protobuf:"varint,3,opt,name=prize_id,json=prizeId,proto3" json:"prize_id,omitempty"` +} + +func (m *PrizeIDs) Reset() { *m = PrizeIDs{} } +func (m *PrizeIDs) String() string { return proto.CompactTextString(m) } +func (*PrizeIDs) ProtoMessage() {} +func (*PrizeIDs) Descriptor() ([]byte, []int) { + return fileDescriptor_e724d952968386cf, []int{1} +} +func (m *PrizeIDs) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrizeIDs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrizeIDs.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PrizeIDs) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrizeIDs.Merge(m, src) +} +func (m *PrizeIDs) XXX_Size() int { + return m.Size() +} +func (m *PrizeIDs) XXX_DiscardUnknown() { + xxx_messageInfo_PrizeIDs.DiscardUnknown(m) +} + +var xxx_messageInfo_PrizeIDs proto.InternalMessageInfo + +func (m *PrizeIDs) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *PrizeIDs) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *PrizeIDs) GetPrizeId() uint64 { + if m != nil { + return m.PrizeId + } + return 0 +} + +type PrizeIDsCollection struct { + PrizesIds []PrizeIDs `protobuf:"bytes,1,rep,name=prizes_ids,json=prizesIds,proto3" json:"prizes_ids"` +} + +func (m *PrizeIDsCollection) Reset() { *m = PrizeIDsCollection{} } +func (m *PrizeIDsCollection) String() string { return proto.CompactTextString(m) } +func (*PrizeIDsCollection) ProtoMessage() {} +func (*PrizeIDsCollection) Descriptor() ([]byte, []int) { + return fileDescriptor_e724d952968386cf, []int{2} +} +func (m *PrizeIDsCollection) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrizeIDsCollection) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrizeIDsCollection.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PrizeIDsCollection) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrizeIDsCollection.Merge(m, src) +} +func (m *PrizeIDsCollection) XXX_Size() int { + return m.Size() +} +func (m *PrizeIDsCollection) XXX_DiscardUnknown() { + xxx_messageInfo_PrizeIDsCollection.DiscardUnknown(m) +} + +var xxx_messageInfo_PrizeIDsCollection proto.InternalMessageInfo + +func (m *PrizeIDsCollection) GetPrizesIds() []PrizeIDs { + if m != nil { + return m.PrizesIds + } + return nil +} + +func init() { + proto.RegisterEnum("lum.network.millions.PrizeState", PrizeState_name, PrizeState_value) + proto.RegisterType((*Prize)(nil), "lum.network.millions.Prize") + proto.RegisterType((*PrizeIDs)(nil), "lum.network.millions.PrizeIDs") + proto.RegisterType((*PrizeIDsCollection)(nil), "lum.network.millions.PrizeIDsCollection") +} + +func init() { proto.RegisterFile("lum-network/millions/prize.proto", fileDescriptor_e724d952968386cf) } + +var fileDescriptor_e724d952968386cf = []byte{ + // 608 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x4f, 0xd4, 0x40, + 0x18, 0xc6, 0x77, 0x64, 0xd9, 0x3f, 0xb3, 0x11, 0xb0, 0x92, 0x50, 0xf6, 0x50, 0x1a, 0xe2, 0x61, + 0x43, 0xa4, 0x0d, 0x98, 0xe8, 0xd1, 0xec, 0x3f, 0xb1, 0x17, 0xb2, 0xe9, 0x42, 0x8c, 0x5c, 0x9a, + 0x6e, 0x67, 0xe8, 0x4e, 0x6c, 0x67, 0x9a, 0xce, 0x54, 0xd0, 0x4f, 0x60, 0x38, 0xf1, 0x05, 0x38, + 0x79, 0xf6, 0xe6, 0x87, 0xe0, 0x48, 0x3c, 0x79, 0x52, 0x03, 0x5f, 0xc4, 0x4c, 0x67, 0x96, 0x25, + 0xc6, 0x98, 0x90, 0x78, 0xeb, 0x3b, 0xcf, 0x6f, 0xde, 0x3e, 0x33, 0xcf, 0x9b, 0x81, 0x76, 0x52, + 0xa4, 0xdb, 0x14, 0x8b, 0x13, 0x96, 0xbf, 0x73, 0x53, 0x92, 0x24, 0x84, 0x51, 0xee, 0x66, 0x39, + 0xf9, 0x88, 0x9d, 0x2c, 0x67, 0x82, 0x19, 0xab, 0x49, 0x91, 0x3a, 0x9a, 0x70, 0x66, 0x44, 0x7b, + 0x35, 0x66, 0x31, 0x2b, 0x01, 0x57, 0x7e, 0x29, 0xb6, 0xbd, 0x11, 0x33, 0x16, 0x27, 0xd8, 0x2d, + 0xab, 0x49, 0x71, 0xec, 0x0a, 0x92, 0x62, 0x2e, 0xc2, 0x34, 0xd3, 0x80, 0x15, 0x31, 0x9e, 0x32, + 0xee, 0x4e, 0x42, 0x8e, 0xdd, 0xf7, 0x3b, 0x13, 0x2c, 0xc2, 0x1d, 0x37, 0x62, 0x84, 0x6a, 0x7d, + 0x5d, 0xe9, 0x81, 0xea, 0xac, 0x0a, 0x25, 0x6d, 0x7e, 0xa9, 0xc2, 0xc5, 0x91, 0xf4, 0x65, 0xac, + 0xc1, 0x7a, 0xc6, 0x58, 0x12, 0x10, 0x64, 0x02, 0x1b, 0x74, 0xaa, 0x7e, 0x4d, 0x96, 0x1e, 0x92, + 0x02, 0xca, 0xc3, 0x13, 0x29, 0x3c, 0x50, 0x82, 0x2c, 0x3d, 0x64, 0xac, 0xc3, 0x46, 0x79, 0x24, + 0xa9, 0x2c, 0x94, 0x4a, 0xbd, 0xac, 0x3d, 0x64, 0x3c, 0x87, 0x8b, 0x5c, 0x84, 0x02, 0x9b, 0x55, + 0x1b, 0x74, 0x96, 0x76, 0x6d, 0xe7, 0x6f, 0xc7, 0x75, 0xca, 0x1f, 0x8f, 0x25, 0xe7, 0x2b, 0xdc, + 0x78, 0x09, 0x97, 0x4e, 0x08, 0xa5, 0x38, 0x0f, 0x42, 0x84, 0x72, 0xcc, 0xb9, 0xb9, 0x68, 0x83, + 0x4e, 0xb3, 0x67, 0x7e, 0xfb, 0xba, 0xbd, 0xaa, 0x8d, 0x77, 0x95, 0x32, 0x16, 0x39, 0xa1, 0xb1, + 0xff, 0x50, 0xf1, 0x7a, 0xd1, 0x78, 0x01, 0x6b, 0x61, 0xca, 0x0a, 0x2a, 0xcc, 0x9a, 0x0d, 0x3a, + 0xad, 0xdd, 0x75, 0x47, 0xef, 0x92, 0x77, 0xe3, 0xe8, 0xbb, 0x71, 0xfa, 0x8c, 0xd0, 0x5e, 0xf5, + 0xf2, 0xc7, 0x46, 0xc5, 0xd7, 0xb8, 0xb1, 0x05, 0x1f, 0x45, 0x39, 0x0e, 0x05, 0x46, 0x41, 0x28, + 0x82, 0x29, 0x26, 0xf1, 0x54, 0x98, 0x75, 0x1b, 0x74, 0x16, 0xfc, 0x65, 0x2d, 0x74, 0xc5, 0xeb, + 0x72, 0x59, 0xb2, 0x45, 0x86, 0xfe, 0x60, 0x1b, 0x8a, 0xd5, 0xc2, 0x2d, 0xdb, 0x87, 0x10, 0x9f, + 0x66, 0x24, 0xc7, 0x3c, 0x08, 0x85, 0xd9, 0x2c, 0x4d, 0xb5, 0x1d, 0x95, 0xa8, 0x33, 0x4b, 0xd4, + 0x39, 0x98, 0x25, 0xda, 0x6b, 0x48, 0x57, 0xe7, 0x3f, 0x37, 0x80, 0xdf, 0xd4, 0xfb, 0xba, 0x65, + 0x93, 0xb9, 0x39, 0x13, 0xde, 0xa7, 0xc9, 0xad, 0x77, 0xd9, 0x64, 0xee, 0xda, 0x6c, 0xdd, 0xa7, + 0xc9, 0xed, 0xa1, 0x36, 0xdf, 0xc0, 0x46, 0x99, 0x9a, 0x37, 0xe0, 0xff, 0x75, 0x62, 0x36, 0xdf, + 0x42, 0x63, 0xd6, 0xb8, 0xcf, 0x92, 0x04, 0x47, 0x82, 0x30, 0x2a, 0x3d, 0x97, 0x00, 0x0f, 0x08, + 0xe2, 0x26, 0xb0, 0x17, 0x3a, 0xad, 0x5d, 0xeb, 0x1f, 0xc3, 0xe4, 0x0d, 0xb8, 0xce, 0xb5, 0xa9, + 0xf6, 0x79, 0x88, 0x6f, 0x1d, 0x43, 0x38, 0x9f, 0x34, 0xe3, 0x29, 0x5c, 0x1b, 0xf9, 0xde, 0xd1, + 0x30, 0x18, 0x1f, 0x74, 0x0f, 0x86, 0xc1, 0xe1, 0xfe, 0x78, 0x34, 0xec, 0x7b, 0xaf, 0xbc, 0xe1, + 0x60, 0xa5, 0xd2, 0x5e, 0x3e, 0xbb, 0xb0, 0x5b, 0x87, 0x94, 0x67, 0x38, 0x22, 0xc7, 0x04, 0x23, + 0xe3, 0x09, 0x7c, 0x7c, 0x97, 0x1e, 0x0d, 0xf7, 0x07, 0xde, 0xfe, 0xde, 0x0a, 0x68, 0xb7, 0xce, + 0x2e, 0xec, 0xfa, 0x08, 0x53, 0x44, 0x68, 0xdc, 0xae, 0x7e, 0xfa, 0x6c, 0x81, 0xde, 0xde, 0xe5, + 0xb5, 0x05, 0xae, 0xae, 0x2d, 0xf0, 0xeb, 0xda, 0x02, 0xe7, 0x37, 0x56, 0xe5, 0xea, 0xc6, 0xaa, + 0x7c, 0xbf, 0xb1, 0x2a, 0x47, 0xdb, 0x31, 0x11, 0xd3, 0x62, 0xe2, 0x44, 0x2c, 0x75, 0xef, 0x3e, + 0x0d, 0xd1, 0x34, 0x24, 0xd4, 0x3d, 0x9d, 0x3f, 0x11, 0xe2, 0x43, 0x86, 0xf9, 0xa4, 0x56, 0xa6, + 0xf1, 0xec, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x52, 0xbf, 0x86, 0x47, 0x04, 0x00, 0x00, +} + +func (m *Prize) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Prize) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Prize) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpdatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintPrize(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x5a + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintPrize(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x52 + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.ExpiresAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiresAt):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintPrize(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x4a + if m.UpdatedAtHeight != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.UpdatedAtHeight)) + i-- + dAtA[i] = 0x40 + } + if m.CreatedAtHeight != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.CreatedAtHeight)) + i-- + dAtA[i] = 0x38 + } + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrize(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintPrize(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0x2a + } + if m.State != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.State)) + i-- + dAtA[i] = 0x20 + } + if m.PrizeId != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.PrizeId)) + i-- + dAtA[i] = 0x18 + } + if m.DrawId != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PrizeIDs) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrizeIDs) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrizeIDs) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PrizeId != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.PrizeId)) + i-- + dAtA[i] = 0x18 + } + if m.DrawId != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintPrize(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PrizeIDsCollection) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrizeIDsCollection) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrizeIDsCollection) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PrizesIds) > 0 { + for iNdEx := len(m.PrizesIds) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PrizesIds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrize(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintPrize(dAtA []byte, offset int, v uint64) int { + offset -= sovPrize(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Prize) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovPrize(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovPrize(uint64(m.DrawId)) + } + if m.PrizeId != 0 { + n += 1 + sovPrize(uint64(m.PrizeId)) + } + if m.State != 0 { + n += 1 + sovPrize(uint64(m.State)) + } + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovPrize(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovPrize(uint64(l)) + if m.CreatedAtHeight != 0 { + n += 1 + sovPrize(uint64(m.CreatedAtHeight)) + } + if m.UpdatedAtHeight != 0 { + n += 1 + sovPrize(uint64(m.UpdatedAtHeight)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiresAt) + n += 1 + l + sovPrize(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) + n += 1 + l + sovPrize(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt) + n += 1 + l + sovPrize(uint64(l)) + return n +} + +func (m *PrizeIDs) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovPrize(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovPrize(uint64(m.DrawId)) + } + if m.PrizeId != 0 { + n += 1 + sovPrize(uint64(m.PrizeId)) + } + return n +} + +func (m *PrizeIDsCollection) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PrizesIds) > 0 { + for _, e := range m.PrizesIds { + l = e.Size() + n += 1 + l + sovPrize(uint64(l)) + } + } + return n +} + +func sovPrize(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrize(x uint64) (n int) { + return sovPrize(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Prize) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Prize: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Prize: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeId", wireType) + } + m.PrizeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PrizeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + m.State = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.State |= PrizeState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrize + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrize + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrize + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrize + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) + } + m.CreatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAtHeight", wireType) + } + m.UpdatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExpiresAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrize + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrize + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.ExpiresAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrize + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrize + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrize + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrize + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.UpdatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrize(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrize + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPrize + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PrizeIDs) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrizeIDs: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrizeIDs: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeId", wireType) + } + m.PrizeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PrizeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipPrize(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrize + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPrize + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PrizeIDsCollection) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrizeIDsCollection: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrizeIDsCollection: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizesIds", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrize + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrize + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrize + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrizesIds = append(m.PrizesIds, PrizeIDs{}) + if err := m.PrizesIds[len(m.PrizesIds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrize(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrize + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPrize + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrize(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrize + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrize + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrize + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPrize + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrize + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrize + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrize = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrize = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrize = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/prize_batch.go b/x/millions/types/prize_batch.go new file mode 100644 index 00000000..094ee72a --- /dev/null +++ b/x/millions/types/prize_batch.go @@ -0,0 +1,68 @@ +package types + +import ( + fmt "fmt" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type PrizeProb struct { + Amount math.Int + DrawProbability sdk.Dec +} + +// Validate prizeBatch validation +// - poolPercent must be [0, 100] +// - quantity must be >= 0 +// - drawProbability must be [0, 1] +func (pb PrizeBatch) Validate(params Params) error { + if pb.PoolPercent == 0 || pb.PoolPercent > 100 { + return fmt.Errorf("prize batch pool percentrage must be gt 0 and lte 100") + } + if pb.Quantity == 0 { + return fmt.Errorf("prize batch quantity must be gt 0") + } else if pb.Quantity > params.MaxPrizeBatchQuantity { + return fmt.Errorf("prize batch quantity must be lte %d", params.MaxPrizeBatchQuantity) + } + if pb.DrawProbability.LT(sdk.NewDec(0)) || pb.DrawProbability.GT(sdk.NewDec(1)) { + return fmt.Errorf("prize batch draw probability must be gte 0 and lte 1") + } + return nil +} + +func (pb PrizeBatch) GetTotalPrizesAmount(prizePool sdk.Coin) math.Int { + return math.LegacyNewDec(int64(pb.PoolPercent)).QuoInt64(int64(100)).MulInt(prizePool.Amount).TruncateInt() +} + +func (pb PrizeBatch) GetPrizeAmount(prizePool sdk.Coin) math.Int { + return pb.GetTotalPrizesAmount(prizePool).QuoRaw(int64(pb.Quantity)) +} + +// ComputePrizesProbs computes batch prizes probs list based on the batch percentage of the prizePool +// Returns as much prize up to quantity as possible, until the total batch amount has been fully consumed or is +// not enough to create another prize +// Each prize is identical and the usedAmount and remainingAmount are returned upon computation +func (pb PrizeBatch) ComputePrizesProbs(prizePool sdk.Coin) (prizesProbs []PrizeProb, usedAmount math.Int, remainingAmount math.Int) { + usedAmount = math.ZeroInt() + remainingAmount = pb.GetTotalPrizesAmount(prizePool) + prizeAmount := pb.GetPrizeAmount(prizePool) + + if prizeAmount.LTE(math.ZeroInt()) { + return nil, math.ZeroInt(), remainingAmount + } + + for q := uint64(0); q < pb.Quantity; q++ { + if remainingAmount.LT(prizeAmount) { + break + } + prizesProbs = append(prizesProbs, PrizeProb{ + Amount: prizeAmount, + DrawProbability: pb.DrawProbability, + }) + remainingAmount = remainingAmount.Sub(prizeAmount) + usedAmount = usedAmount.Add(prizeAmount) + } + + return prizesProbs, usedAmount, remainingAmount +} diff --git a/x/millions/types/prize_batch.pb.go b/x/millions/types/prize_batch.pb.go new file mode 100644 index 00000000..1322f1cb --- /dev/null +++ b/x/millions/types/prize_batch.pb.go @@ -0,0 +1,394 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/prize_batch.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type PrizeBatch struct { + PoolPercent uint64 `protobuf:"varint,1,opt,name=pool_percent,json=poolPercent,proto3" json:"pool_percent,omitempty"` + Quantity uint64 `protobuf:"varint,2,opt,name=quantity,proto3" json:"quantity,omitempty"` + DrawProbability github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=draw_probability,json=drawProbability,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"draw_probability"` +} + +func (m *PrizeBatch) Reset() { *m = PrizeBatch{} } +func (m *PrizeBatch) String() string { return proto.CompactTextString(m) } +func (*PrizeBatch) ProtoMessage() {} +func (*PrizeBatch) Descriptor() ([]byte, []int) { + return fileDescriptor_c7480d35abae7e06, []int{0} +} +func (m *PrizeBatch) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrizeBatch) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrizeBatch.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PrizeBatch) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrizeBatch.Merge(m, src) +} +func (m *PrizeBatch) XXX_Size() int { + return m.Size() +} +func (m *PrizeBatch) XXX_DiscardUnknown() { + xxx_messageInfo_PrizeBatch.DiscardUnknown(m) +} + +var xxx_messageInfo_PrizeBatch proto.InternalMessageInfo + +func (m *PrizeBatch) GetPoolPercent() uint64 { + if m != nil { + return m.PoolPercent + } + return 0 +} + +func (m *PrizeBatch) GetQuantity() uint64 { + if m != nil { + return m.Quantity + } + return 0 +} + +func init() { + proto.RegisterType((*PrizeBatch)(nil), "lum.network.millions.PrizeBatch") +} + +func init() { + proto.RegisterFile("lum-network/millions/prize_batch.proto", fileDescriptor_c7480d35abae7e06) +} + +var fileDescriptor_c7480d35abae7e06 = []byte{ + // 271 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcb, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0xcd, 0xcc, 0xc9, 0xc9, 0xcc, 0xcf, 0x2b, + 0xd6, 0x2f, 0x28, 0xca, 0xac, 0x4a, 0x8d, 0x4f, 0x4a, 0x2c, 0x49, 0xce, 0xd0, 0x2b, 0x28, 0xca, + 0x2f, 0xc9, 0x17, 0x12, 0xc9, 0x29, 0xcd, 0xd5, 0x83, 0xaa, 0xd3, 0x83, 0xa9, 0x93, 0x12, 0x49, + 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0x95, 0x96, 0x31, 0x72, 0x71, 0x05, + 0x80, 0x4c, 0x70, 0x02, 0x19, 0x20, 0xa4, 0xc8, 0xc5, 0x53, 0x90, 0x9f, 0x9f, 0x13, 0x5f, 0x90, + 0x5a, 0x94, 0x9c, 0x9a, 0x57, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x12, 0xc4, 0x0d, 0x12, 0x0b, + 0x80, 0x08, 0x09, 0x49, 0x71, 0x71, 0x14, 0x96, 0x26, 0xe6, 0x95, 0x64, 0x96, 0x54, 0x4a, 0x30, + 0x81, 0xa5, 0xe1, 0x7c, 0xa1, 0x48, 0x2e, 0x81, 0x94, 0xa2, 0xc4, 0xf2, 0xf8, 0x82, 0xa2, 0xfc, + 0xa4, 0xc4, 0xa4, 0xcc, 0x1c, 0x90, 0x1a, 0x66, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0xbd, 0x13, 0xf7, + 0xe4, 0x19, 0x6e, 0xdd, 0x93, 0x57, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x86, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x25, 0x95, + 0x05, 0xa9, 0xc5, 0x7a, 0x2e, 0xa9, 0xc9, 0x41, 0xfc, 0x20, 0x73, 0x02, 0x10, 0xc6, 0x38, 0xb9, + 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, + 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x2e, 0x92, 0x91, 0xc8, 0x21, + 0x94, 0x9c, 0x91, 0x98, 0x99, 0xa7, 0x5f, 0x81, 0x08, 0x29, 0xb0, 0xe9, 0x49, 0x6c, 0x60, 0x8f, + 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x39, 0x9d, 0x39, 0x85, 0x4e, 0x01, 0x00, 0x00, +} + +func (m *PrizeBatch) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrizeBatch) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrizeBatch) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.DrawProbability.Size() + i -= size + if _, err := m.DrawProbability.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPrizeBatch(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.Quantity != 0 { + i = encodeVarintPrizeBatch(dAtA, i, uint64(m.Quantity)) + i-- + dAtA[i] = 0x10 + } + if m.PoolPercent != 0 { + i = encodeVarintPrizeBatch(dAtA, i, uint64(m.PoolPercent)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintPrizeBatch(dAtA []byte, offset int, v uint64) int { + offset -= sovPrizeBatch(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PrizeBatch) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolPercent != 0 { + n += 1 + sovPrizeBatch(uint64(m.PoolPercent)) + } + if m.Quantity != 0 { + n += 1 + sovPrizeBatch(uint64(m.Quantity)) + } + l = m.DrawProbability.Size() + n += 1 + l + sovPrizeBatch(uint64(l)) + return n +} + +func sovPrizeBatch(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrizeBatch(x uint64) (n int) { + return sovPrizeBatch(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PrizeBatch) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrizeBatch: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrizeBatch: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolPercent", wireType) + } + m.PoolPercent = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolPercent |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Quantity", wireType) + } + m.Quantity = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Quantity |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawProbability", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrizeBatch + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrizeBatch + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DrawProbability.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrizeBatch(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrizeBatch + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPrizeBatch + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrizeBatch(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeBatch + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPrizeBatch + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrizeBatch + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrizeBatch + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrizeBatch = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrizeBatch = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrizeBatch = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/prize_ref.pb.go b/x/millions/types/prize_ref.pb.go new file mode 100644 index 00000000..82c97806 --- /dev/null +++ b/x/millions/types/prize_ref.pb.go @@ -0,0 +1,413 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/prize_ref.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type PrizeRef struct { + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + PrizeId uint64 `protobuf:"varint,2,opt,name=prize_id,json=prizeId,proto3" json:"prize_id,omitempty"` + WinnerAddress string `protobuf:"bytes,3,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` +} + +func (m *PrizeRef) Reset() { *m = PrizeRef{} } +func (m *PrizeRef) String() string { return proto.CompactTextString(m) } +func (*PrizeRef) ProtoMessage() {} +func (*PrizeRef) Descriptor() ([]byte, []int) { + return fileDescriptor_f27a7fbca983118c, []int{0} +} +func (m *PrizeRef) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrizeRef) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrizeRef.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PrizeRef) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrizeRef.Merge(m, src) +} +func (m *PrizeRef) XXX_Size() int { + return m.Size() +} +func (m *PrizeRef) XXX_DiscardUnknown() { + xxx_messageInfo_PrizeRef.DiscardUnknown(m) +} + +var xxx_messageInfo_PrizeRef proto.InternalMessageInfo + +func (m *PrizeRef) GetPrizeId() uint64 { + if m != nil { + return m.PrizeId + } + return 0 +} + +func (m *PrizeRef) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func init() { + proto.RegisterType((*PrizeRef)(nil), "lum.network.millions.PrizeRef") +} + +func init() { + proto.RegisterFile("lum-network/millions/prize_ref.proto", fileDescriptor_f27a7fbca983118c) +} + +var fileDescriptor_f27a7fbca983118c = []byte{ + // 293 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0xcd, 0xcc, 0xc9, 0xc9, 0xcc, 0xcf, 0x2b, + 0xd6, 0x2f, 0x28, 0xca, 0xac, 0x4a, 0x8d, 0x2f, 0x4a, 0x4d, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0xc9, 0x29, 0xcd, 0xd5, 0x83, 0xaa, 0xd2, 0x83, 0xa9, 0x92, 0x12, 0x49, 0xcf, 0x4f, + 0xcf, 0x07, 0x2b, 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, + 0xe3, 0x21, 0x12, 0x10, 0x0e, 0x44, 0x4a, 0x69, 0x07, 0x23, 0x17, 0x47, 0x00, 0xc8, 0xe8, 0xa0, + 0xd4, 0x34, 0x21, 0x37, 0x2e, 0xb6, 0xc4, 0xdc, 0xfc, 0xd2, 0xbc, 0x12, 0x09, 0x46, 0x05, 0x46, + 0x0d, 0x4e, 0x27, 0xbd, 0x13, 0xf7, 0xe4, 0x19, 0x6e, 0xdd, 0x93, 0x57, 0x4b, 0xcf, 0x2c, 0xc9, + 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x85, 0xea, 0x86, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x25, + 0x95, 0x05, 0xa9, 0xc5, 0x7a, 0x9e, 0x79, 0x25, 0x41, 0x50, 0xdd, 0x42, 0xf2, 0x5c, 0x1c, 0x10, + 0xe7, 0x66, 0xa6, 0x48, 0x30, 0x29, 0x30, 0x6a, 0xb0, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x18, + 0xc4, 0x0e, 0x16, 0xf5, 0x4c, 0x11, 0x72, 0xe6, 0xe2, 0x2b, 0xcf, 0xcc, 0xcb, 0x4b, 0x2d, 0x8a, + 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x96, 0x60, 0x06, 0x5b, 0x28, 0x03, 0x52, 0x76, 0x69, + 0x8b, 0xae, 0x08, 0xd4, 0x8d, 0x8e, 0x10, 0xd9, 0xe0, 0x92, 0xa2, 0xcc, 0xbc, 0xf4, 0x20, 0x5e, + 0x88, 0x1e, 0xa8, 0xa0, 0x93, 0xfb, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, + 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, + 0xe9, 0x22, 0xb9, 0x17, 0x39, 0x30, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x2b, 0x10, 0x81, 0x0a, + 0x76, 0x7a, 0x12, 0x1b, 0x38, 0x28, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0x82, 0x6b, + 0x52, 0x79, 0x01, 0x00, 0x00, +} + +func (m *PrizeRef) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrizeRef) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrizeRef) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintPrizeRef(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0x1a + } + if m.PrizeId != 0 { + i = encodeVarintPrizeRef(dAtA, i, uint64(m.PrizeId)) + i-- + dAtA[i] = 0x10 + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPrizeRef(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintPrizeRef(dAtA []byte, offset int, v uint64) int { + offset -= sovPrizeRef(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PrizeRef) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovPrizeRef(uint64(l)) + if m.PrizeId != 0 { + n += 1 + sovPrizeRef(uint64(m.PrizeId)) + } + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovPrizeRef(uint64(l)) + } + return n +} + +func sovPrizeRef(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrizeRef(x uint64) (n int) { + return sovPrizeRef(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PrizeRef) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrizeRef: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrizeRef: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrizeRef + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrizeRef + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeId", wireType) + } + m.PrizeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PrizeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrizeRef + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrizeRef + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrizeRef(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrizeRef + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPrizeRef + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrizeRef(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeRef + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPrizeRef + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrizeRef + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrizeRef + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrizeRef = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrizeRef = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrizeRef = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/prize_strategy.go b/x/millions/types/prize_strategy.go new file mode 100644 index 00000000..91464c3d --- /dev/null +++ b/x/millions/types/prize_strategy.go @@ -0,0 +1,59 @@ +package types + +import ( + "fmt" + "sort" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Validate prizeStrategy validation +// - validate strategy based on params +// - validate each batch individually +// - validate total number of prizes > 0 +// - validate total percentage of prize pool = 100 +func (ps PrizeStrategy) Validate(params Params) error { + if uint64(len(ps.PrizeBatches)) > params.MaxPrizeStrategyBatches { + return fmt.Errorf("prize strategy must have maximum %d batches", params.MaxPrizeStrategyBatches) + } + totalPrizes := uint64(0) + totalPercent := uint64(0) + for _, batch := range ps.PrizeBatches { + totalPrizes += batch.Quantity + totalPercent += batch.PoolPercent + if err := batch.Validate(params); err != nil { + return err + } + } + if totalPrizes <= 0 { + return fmt.Errorf("prize strategy must contain at least one prize") + } + if totalPercent != 100 { + return fmt.Errorf("prize batches pool percentage must be equal to 100") + } + return nil +} + +// ComputePrizesProbs computes final prizes probs list based on each prizeBatch configuration +// always sort the prizes by most valuable to least valuable +// error triggered if the prizeStrategy does not pass its internal validation function +func (ps PrizeStrategy) ComputePrizesProbs(prizePool sdk.Coin) (prizesProbs []PrizeProb, usedAmount math.Int, remainingAmount math.Int, err error) { + usedAmount = sdk.ZeroInt() + remainingAmount = prizePool.Amount + sortedBatches := append([]PrizeBatch{}, ps.PrizeBatches...) + sort.Slice(sortedBatches, func(i, j int) bool { + return sortedBatches[i].GetPrizeAmount(prizePool).GT(sortedBatches[j].GetPrizeAmount(prizePool)) + }) + + // Iterate over each prize batch + for _, batch := range sortedBatches { + // For each batch compute batch prizes + bPrizesProbs, bUsed, _ := batch.ComputePrizesProbs(prizePool) + prizesProbs = append(prizesProbs, bPrizesProbs...) + usedAmount = usedAmount.Add(bUsed) + remainingAmount = remainingAmount.Sub(bUsed) + } + + return prizesProbs, usedAmount, remainingAmount, nil +} diff --git a/x/millions/types/prize_strategy.pb.go b/x/millions/types/prize_strategy.pb.go new file mode 100644 index 00000000..47d2a4c6 --- /dev/null +++ b/x/millions/types/prize_strategy.pb.go @@ -0,0 +1,335 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/prize_strategy.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type PrizeStrategy struct { + PrizeBatches []PrizeBatch `protobuf:"bytes,1,rep,name=prize_batches,json=prizeBatches,proto3" json:"prize_batches"` +} + +func (m *PrizeStrategy) Reset() { *m = PrizeStrategy{} } +func (m *PrizeStrategy) String() string { return proto.CompactTextString(m) } +func (*PrizeStrategy) ProtoMessage() {} +func (*PrizeStrategy) Descriptor() ([]byte, []int) { + return fileDescriptor_365013a33704a6de, []int{0} +} +func (m *PrizeStrategy) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrizeStrategy) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrizeStrategy.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PrizeStrategy) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrizeStrategy.Merge(m, src) +} +func (m *PrizeStrategy) XXX_Size() int { + return m.Size() +} +func (m *PrizeStrategy) XXX_DiscardUnknown() { + xxx_messageInfo_PrizeStrategy.DiscardUnknown(m) +} + +var xxx_messageInfo_PrizeStrategy proto.InternalMessageInfo + +func (m *PrizeStrategy) GetPrizeBatches() []PrizeBatch { + if m != nil { + return m.PrizeBatches + } + return nil +} + +func init() { + proto.RegisterType((*PrizeStrategy)(nil), "lum.network.millions.PrizeStrategy") +} + +func init() { + proto.RegisterFile("lum-network/millions/prize_strategy.proto", fileDescriptor_365013a33704a6de) +} + +var fileDescriptor_365013a33704a6de = []byte{ + // 213 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcc, 0x29, 0xcd, 0xd5, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0xcd, 0xcc, 0xc9, 0xc9, 0xcc, 0xcf, 0x2b, + 0xd6, 0x2f, 0x28, 0xca, 0xac, 0x4a, 0x8d, 0x2f, 0x2e, 0x29, 0x4a, 0x2c, 0x49, 0x4d, 0xaf, 0xd4, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xc9, 0x29, 0xcd, 0xd5, 0x83, 0x2a, 0xd5, 0x83, 0x29, + 0x95, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0xa5, 0xd4, 0xf0, + 0x18, 0x9b, 0x94, 0x58, 0x92, 0x9c, 0x01, 0x51, 0xa7, 0x14, 0xc3, 0xc5, 0x1b, 0x00, 0x12, 0x0c, + 0x86, 0x5a, 0x25, 0xe4, 0xcd, 0xc5, 0x8b, 0xa4, 0x2a, 0xb5, 0x58, 0x82, 0x51, 0x81, 0x59, 0x83, + 0xdb, 0x48, 0x41, 0x0f, 0x9b, 0xe5, 0x7a, 0x60, 0xbd, 0x4e, 0x20, 0x95, 0x4e, 0x2c, 0x27, 0xee, + 0xc9, 0x33, 0x04, 0xf1, 0x14, 0xc0, 0x45, 0x52, 0x8b, 0x9d, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, + 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, + 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, + 0x57, 0x1f, 0xd9, 0xa9, 0xc9, 0x19, 0x89, 0x99, 0x79, 0xfa, 0x15, 0x08, 0x27, 0x97, 0x54, 0x16, + 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x5d, 0x6b, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x6f, 0x64, 0x86, + 0xcc, 0x2e, 0x01, 0x00, 0x00, +} + +func (m *PrizeStrategy) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrizeStrategy) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrizeStrategy) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PrizeBatches) > 0 { + for iNdEx := len(m.PrizeBatches) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PrizeBatches[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrizeStrategy(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintPrizeStrategy(dAtA []byte, offset int, v uint64) int { + offset -= sovPrizeStrategy(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PrizeStrategy) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PrizeBatches) > 0 { + for _, e := range m.PrizeBatches { + l = e.Size() + n += 1 + l + sovPrizeStrategy(uint64(l)) + } + } + return n +} + +func sovPrizeStrategy(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrizeStrategy(x uint64) (n int) { + return sovPrizeStrategy(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PrizeStrategy) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeStrategy + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrizeStrategy: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrizeStrategy: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeBatches", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrizeStrategy + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrizeStrategy + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrizeStrategy + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrizeBatches = append(m.PrizeBatches, PrizeBatch{}) + if err := m.PrizeBatches[len(m.PrizeBatches)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrizeStrategy(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrizeStrategy + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPrizeStrategy + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrizeStrategy(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeStrategy + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeStrategy + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrizeStrategy + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPrizeStrategy + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrizeStrategy + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrizeStrategy + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrizeStrategy = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrizeStrategy = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrizeStrategy = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/proposal_register_pool.go b/x/millions/types/proposal_register_pool.go new file mode 100644 index 00000000..c29b64c4 --- /dev/null +++ b/x/millions/types/proposal_register_pool.go @@ -0,0 +1,115 @@ +package types + +import ( + "fmt" + "strings" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +const ( + ProposalTypeRegisterPool = "RegisterPool" +) + +var ( + _ govtypes.Content = &ProposalRegisterPool{} +) + +func init() { + govtypes.RegisterProposalType(ProposalTypeRegisterPool) +} + +func NewRegisterPoolProposal(title, description, chainID string, denom string, nativeDenom string, connectionId string, bech32PrefixAccAddr string, bech32PrefixValAddr string, validators []string, minDepositAmount math.Int, prizeStrategy PrizeStrategy, drawSchedule DrawSchedule) govtypes.Content { + return &ProposalRegisterPool{ + Title: title, + Description: description, + ChainId: chainID, + Denom: denom, + NativeDenom: nativeDenom, + ConnectionId: connectionId, + Validators: validators, + MinDepositAmount: minDepositAmount, + Bech32PrefixAccAddr: bech32PrefixAccAddr, + Bech32PrefixValAddr: bech32PrefixValAddr, + PrizeStrategy: prizeStrategy, + DrawSchedule: drawSchedule, + } +} + +func (p *ProposalRegisterPool) ProposalRoute() string { return RouterKey } + +func (p *ProposalRegisterPool) ProposalType() string { + return ProposalTypeRegisterPool +} + +func (p *ProposalRegisterPool) ValidateBasic() error { + // Validate root proposal content + err := govtypes.ValidateAbstract(p) + if err != nil { + return err + } + + // Validate payload + if len(strings.TrimSpace(p.ChainId)) <= 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Chain ID is required") + } + if err := sdk.ValidateDenom(p.Denom); err != nil { + return errorsmod.Wrapf(err, "a valid denom is required") + } + if err := sdk.ValidateDenom(p.NativeDenom); err != nil { + return errorsmod.Wrapf(err, "a valid native_denom is required") + } + if len(p.Validators) <= 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "at least one validator is required") + } + if p.MinDepositAmount.IsNil() || p.MinDepositAmount.LT(sdk.NewInt(MinAcceptableDepositAmount)) { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "min deposit denom must be gte %d", MinAcceptableDepositAmount) + } + if len(strings.TrimSpace(p.Bech32PrefixAccAddr)) <= 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "bech32 acc prefix is required") + } + if len(strings.TrimSpace(p.Bech32PrefixValAddr)) <= 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "bech32 val prefix is required") + } + if len(p.PrizeStrategy.PrizeBatches) <= 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "at least one prize strategy batch is required") + } + if p.DrawSchedule.DrawDelta < MinAcceptableDrawDelta { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "draw delta cannot be lower than %s", MinAcceptableDrawDelta) + } + return nil +} + +func (p ProposalRegisterPool) String() string { + return fmt.Sprintf(`Register Pool Proposal: + Title: %s + Description: %s + ChainID: %s + Denom: %s + Native Denom: %s + Connection ID %s + Validators: %+v + Min Deposit Amount: %d + Bech32 Acc Prefix: %s + Bech32 Val Prefix: %s + Transfer Channel ID: %s + ======Draw Schedule====== + %s + ======Prize Strategy====== + %s + `, + p.Title, p.Description, + p.ChainId, p.Denom, p.NativeDenom, + p.ConnectionId, + p.Validators, + p.MinDepositAmount.Int64(), + p.Bech32PrefixAccAddr, p.Bech32PrefixValAddr, + p.TransferChannelId, + p.DrawSchedule.String(), + p.PrizeStrategy.String(), + ) +} diff --git a/x/millions/types/proposal_test.go b/x/millions/types/proposal_test.go new file mode 100644 index 00000000..2d12f88c --- /dev/null +++ b/x/millions/types/proposal_test.go @@ -0,0 +1,26 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + millionstypes "github.com/lum-network/chain/x/millions/types" +) + +type ProposalTestSuite struct { + suite.Suite +} + +func TestProposalTestSuite(t *testing.T) { + suite.Run(t, new(ProposalTestSuite)) +} + +func (suite *ProposalTestSuite) TestKeysTypes() { + suite.Require().Equal("millions", (&millionstypes.ProposalRegisterPool{}).ProposalRoute()) + suite.Require().Equal("RegisterPool", (&millionstypes.ProposalRegisterPool{}).ProposalType()) + suite.Require().Equal("millions", (&millionstypes.ProposalUpdatePool{}).ProposalRoute()) + suite.Require().Equal("UpdatePool", (&millionstypes.ProposalUpdatePool{}).ProposalType()) + suite.Require().Equal("millions", (&millionstypes.ProposalUpdatePool{}).ProposalRoute()) + suite.Require().Equal("UpdateParams", (&millionstypes.ProposalUpdateParams{}).ProposalType()) +} diff --git a/x/millions/types/proposal_update_params.go b/x/millions/types/proposal_update_params.go new file mode 100644 index 00000000..ec5d4181 --- /dev/null +++ b/x/millions/types/proposal_update_params.go @@ -0,0 +1,103 @@ +package types + +import ( + "fmt" + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +const ( + ProposalTypeUpdateParams = "UpdateParams" +) + +var ( + _ govtypes.Content = &ProposalUpdateParams{} +) + +func init() { + govtypes.RegisterProposalType(ProposalTypeUpdateParams) +} + +func NewUpdateParamsProposal(title, description string, minDepositAmount *math.Int, fees *sdk.Dec, prizeDelta *time.Duration, minDepDrawDelta *time.Duration, minDrawDelta *time.Duration, maxDrawDelta *time.Duration, maxBatchQuantity *math.Int, maxStrategyBatches *math.Int) govtypes.Content { + return &ProposalUpdateParams{ + Title: title, + Description: description, + MinDepositAmount: minDepositAmount, + FeesStakers: fees, + PrizeExpirationDelta: prizeDelta, + MinDrawScheduleDelta: minDrawDelta, + MaxDrawScheduleDelta: maxDrawDelta, + MaxPrizeBatchQuantity: maxBatchQuantity, + MaxPrizeStrategyBatches: maxStrategyBatches, + MinDepositDrawDelta: minDepDrawDelta, + } +} + +func (p *ProposalUpdateParams) ProposalRoute() string { return RouterKey } + +func (p *ProposalUpdateParams) ProposalType() string { + return ProposalTypeUpdateParams +} + +func (p *ProposalUpdateParams) ValidateBasic() error { + // Validate root proposal content + err := govtypes.ValidateAbstract(p) + if err != nil { + return err + } + + // Validate payload + params := DefaultParams() + if p.MinDepositAmount != nil { + params.MinDepositAmount = *p.MinDepositAmount + } + if p.MaxPrizeStrategyBatches != nil { + params.MaxPrizeStrategyBatches = p.MaxPrizeStrategyBatches.Uint64() + } + if p.MaxPrizeBatchQuantity != nil { + params.MaxPrizeBatchQuantity = p.MaxPrizeBatchQuantity.Uint64() + } + if p.MinDrawScheduleDelta != nil { + params.MinDrawScheduleDelta = *p.MinDrawScheduleDelta + } + if p.MaxDrawScheduleDelta != nil { + params.MaxDrawScheduleDelta = *p.MaxDrawScheduleDelta + } + if p.PrizeExpirationDelta != nil { + params.PrizeExpirationDelta = *p.PrizeExpirationDelta + } + if p.FeesStakers != nil { + params.FeesStakers = *p.FeesStakers + } + if p.MinDepositDrawDelta != nil { + params.MinDepositDrawDelta = *p.MinDepositDrawDelta + } + return params.ValidateBasics() +} + +func (p ProposalUpdateParams) String() string { + return fmt.Sprintf(`Update Params Proposal: + Title: %s + Description: %s + Min Deposit Amount: %d + Max Prize Strategy Batches %d + Max Prize Batch Quantity %d + Min Draw Schedule Delta %s + Max Draw Schedule Delta %s + Prize Expiration Delta %s + Fees Stakers %s + Min Deposit Draw Delta %s + `, + p.Title, p.Description, + p.MinDepositAmount.Int64(), + p.MaxPrizeStrategyBatches.Int64(), + p.MaxPrizeBatchQuantity.Int64(), + p.MinDrawScheduleDelta.String(), + p.MaxDrawScheduleDelta.String(), + p.PrizeExpirationDelta.String(), + p.FeesStakers.String(), + p.MinDepositDrawDelta.String()) +} diff --git a/x/millions/types/proposal_update_pool.go b/x/millions/types/proposal_update_pool.go new file mode 100644 index 00000000..7d144979 --- /dev/null +++ b/x/millions/types/proposal_update_pool.go @@ -0,0 +1,87 @@ +package types + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +const ( + ProposalTypeUpdatePool = "UpdatePool" +) + +var ( + _ govtypes.Content = &ProposalUpdatePool{} +) + +func init() { + govtypes.RegisterProposalType(ProposalTypeUpdatePool) +} + +func NewUpdatePoolProposal(title, description string, poolId uint64, validators []string, minDepositAmount *math.Int, prizeStrategy *PrizeStrategy, drawSchedule *DrawSchedule) govtypes.Content { + return &ProposalUpdatePool{ + Title: title, + Description: description, + PoolId: poolId, + Validators: validators, + MinDepositAmount: minDepositAmount, + PrizeStrategy: prizeStrategy, + DrawSchedule: drawSchedule, + } +} + +func (p *ProposalUpdatePool) ProposalRoute() string { return RouterKey } + +func (p *ProposalUpdatePool) ProposalType() string { + return ProposalTypeUpdatePool +} + +func (p *ProposalUpdatePool) ValidateBasic() error { + // Validate root proposal content + err := govtypes.ValidateAbstract(p) + if err != nil { + return err + } + + if p.MinDepositAmount != nil { + if p.MinDepositAmount.IsNil() || p.MinDepositAmount.LT(sdk.NewInt(MinAcceptableDepositAmount)) { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "min deposit denom must be gte %d", MinAcceptableDepositAmount) + } + } + if p.PrizeStrategy != nil { + if len(p.PrizeStrategy.PrizeBatches) <= 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "at least one prize strategy batch is required") + } + } + if p.DrawSchedule != nil { + if p.DrawSchedule.DrawDelta < MinAcceptableDrawDelta { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "draw delta cannot be lower than %s", MinAcceptableDrawDelta.String()) + } + } + return nil +} + +func (p ProposalUpdatePool) String() string { + return fmt.Sprintf(`Update Pool Proposal: + Title: %s + Description: %s + Pool ID: %d + Validators: %+v + Min Deposit Amount: %d + ======Draw Schedule====== + %s + ======Prize Strategy====== + %s + `, + p.Title, p.Description, + p.PoolId, + p.Validators, + p.MinDepositAmount.Int64(), + p.DrawSchedule.String(), + p.PrizeStrategy.String(), + ) +} diff --git a/x/millions/types/query.pb.go b/x/millions/types/query.pb.go new file mode 100644 index 00000000..ad08c94f --- /dev/null +++ b/x/millions/types/query.pb.go @@ -0,0 +1,8307 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryParamsResponse struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{0} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{1} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +type QueryPoolResponse struct { + Pool Pool `protobuf:"bytes,1,opt,name=pool,proto3" json:"pool"` +} + +func (m *QueryPoolResponse) Reset() { *m = QueryPoolResponse{} } +func (m *QueryPoolResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPoolResponse) ProtoMessage() {} +func (*QueryPoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{2} +} +func (m *QueryPoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolResponse.Merge(m, src) +} +func (m *QueryPoolResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolResponse proto.InternalMessageInfo + +func (m *QueryPoolResponse) GetPool() Pool { + if m != nil { + return m.Pool + } + return Pool{} +} + +type QueryPoolsResponse struct { + Pools []Pool `protobuf:"bytes,1,rep,name=pools,proto3" json:"pools"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolsResponse) Reset() { *m = QueryPoolsResponse{} } +func (m *QueryPoolsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPoolsResponse) ProtoMessage() {} +func (*QueryPoolsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{3} +} +func (m *QueryPoolsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolsResponse.Merge(m, src) +} +func (m *QueryPoolsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolsResponse proto.InternalMessageInfo + +func (m *QueryPoolsResponse) GetPools() []Pool { + if m != nil { + return m.Pools + } + return nil +} + +func (m *QueryPoolsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` +} + +func (m *QueryPoolRequest) Reset() { *m = QueryPoolRequest{} } +func (m *QueryPoolRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolRequest) ProtoMessage() {} +func (*QueryPoolRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{4} +} +func (m *QueryPoolRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolRequest.Merge(m, src) +} +func (m *QueryPoolRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolRequest proto.InternalMessageInfo + +func (m *QueryPoolRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +type QueryPoolsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolsRequest) Reset() { *m = QueryPoolsRequest{} } +func (m *QueryPoolsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolsRequest) ProtoMessage() {} +func (*QueryPoolsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{5} +} +func (m *QueryPoolsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolsRequest.Merge(m, src) +} +func (m *QueryPoolsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolsRequest proto.InternalMessageInfo + +func (m *QueryPoolsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryDepositResponse struct { + Deposit Deposit `protobuf:"bytes,1,opt,name=deposit,proto3" json:"deposit"` +} + +func (m *QueryDepositResponse) Reset() { *m = QueryDepositResponse{} } +func (m *QueryDepositResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDepositResponse) ProtoMessage() {} +func (*QueryDepositResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{6} +} +func (m *QueryDepositResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDepositResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDepositResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDepositResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDepositResponse.Merge(m, src) +} +func (m *QueryDepositResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDepositResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDepositResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDepositResponse proto.InternalMessageInfo + +func (m *QueryDepositResponse) GetDeposit() Deposit { + if m != nil { + return m.Deposit + } + return Deposit{} +} + +type QueryDepositsResponse struct { + Deposits []Deposit `protobuf:"bytes,1,rep,name=deposits,proto3" json:"deposits"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryDepositsResponse) Reset() { *m = QueryDepositsResponse{} } +func (m *QueryDepositsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDepositsResponse) ProtoMessage() {} +func (*QueryDepositsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{7} +} +func (m *QueryDepositsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDepositsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDepositsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDepositsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDepositsResponse.Merge(m, src) +} +func (m *QueryDepositsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDepositsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDepositsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDepositsResponse proto.InternalMessageInfo + +func (m *QueryDepositsResponse) GetDeposits() []Deposit { + if m != nil { + return m.Deposits + } + return nil +} + +func (m *QueryDepositsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryDepositsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryDepositsRequest) Reset() { *m = QueryDepositsRequest{} } +func (m *QueryDepositsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDepositsRequest) ProtoMessage() {} +func (*QueryDepositsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{8} +} +func (m *QueryDepositsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDepositsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDepositsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDepositsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDepositsRequest.Merge(m, src) +} +func (m *QueryDepositsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDepositsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDepositsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDepositsRequest proto.InternalMessageInfo + +func (m *QueryDepositsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolDepositRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` +} + +func (m *QueryPoolDepositRequest) Reset() { *m = QueryPoolDepositRequest{} } +func (m *QueryPoolDepositRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolDepositRequest) ProtoMessage() {} +func (*QueryPoolDepositRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{9} +} +func (m *QueryPoolDepositRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolDepositRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolDepositRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolDepositRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolDepositRequest.Merge(m, src) +} +func (m *QueryPoolDepositRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolDepositRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolDepositRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolDepositRequest proto.InternalMessageInfo + +func (m *QueryPoolDepositRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolDepositRequest) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +type QueryPoolDepositsRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolDepositsRequest) Reset() { *m = QueryPoolDepositsRequest{} } +func (m *QueryPoolDepositsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolDepositsRequest) ProtoMessage() {} +func (*QueryPoolDepositsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{10} +} +func (m *QueryPoolDepositsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolDepositsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolDepositsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolDepositsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolDepositsRequest.Merge(m, src) +} +func (m *QueryPoolDepositsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolDepositsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolDepositsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolDepositsRequest proto.InternalMessageInfo + +func (m *QueryPoolDepositsRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolDepositsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountDepositsRequest struct { + DepositorAddress string `protobuf:"bytes,1,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountDepositsRequest) Reset() { *m = QueryAccountDepositsRequest{} } +func (m *QueryAccountDepositsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountDepositsRequest) ProtoMessage() {} +func (*QueryAccountDepositsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{11} +} +func (m *QueryAccountDepositsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountDepositsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountDepositsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountDepositsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountDepositsRequest.Merge(m, src) +} +func (m *QueryAccountDepositsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountDepositsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountDepositsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountDepositsRequest proto.InternalMessageInfo + +func (m *QueryAccountDepositsRequest) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *QueryAccountDepositsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountPoolDepositsRequest struct { + DepositorAddress string `protobuf:"bytes,1,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + PoolId uint64 `protobuf:"varint,2,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountPoolDepositsRequest) Reset() { *m = QueryAccountPoolDepositsRequest{} } +func (m *QueryAccountPoolDepositsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountPoolDepositsRequest) ProtoMessage() {} +func (*QueryAccountPoolDepositsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{12} +} +func (m *QueryAccountPoolDepositsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountPoolDepositsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountPoolDepositsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountPoolDepositsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountPoolDepositsRequest.Merge(m, src) +} +func (m *QueryAccountPoolDepositsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountPoolDepositsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountPoolDepositsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountPoolDepositsRequest proto.InternalMessageInfo + +func (m *QueryAccountPoolDepositsRequest) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *QueryAccountPoolDepositsRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryAccountPoolDepositsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryDrawResponse struct { + Draw *Draw `protobuf:"bytes,1,opt,name=draw,proto3" json:"draw,omitempty"` +} + +func (m *QueryDrawResponse) Reset() { *m = QueryDrawResponse{} } +func (m *QueryDrawResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDrawResponse) ProtoMessage() {} +func (*QueryDrawResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{13} +} +func (m *QueryDrawResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDrawResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDrawResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDrawResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDrawResponse.Merge(m, src) +} +func (m *QueryDrawResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDrawResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDrawResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDrawResponse proto.InternalMessageInfo + +func (m *QueryDrawResponse) GetDraw() *Draw { + if m != nil { + return m.Draw + } + return nil +} + +type QueryDrawsResponse struct { + Draws []Draw `protobuf:"bytes,1,rep,name=draws,proto3" json:"draws"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryDrawsResponse) Reset() { *m = QueryDrawsResponse{} } +func (m *QueryDrawsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDrawsResponse) ProtoMessage() {} +func (*QueryDrawsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{14} +} +func (m *QueryDrawsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDrawsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDrawsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDrawsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDrawsResponse.Merge(m, src) +} +func (m *QueryDrawsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDrawsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDrawsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDrawsResponse proto.InternalMessageInfo + +func (m *QueryDrawsResponse) GetDraws() []Draw { + if m != nil { + return m.Draws + } + return nil +} + +func (m *QueryDrawsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryDrawsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryDrawsRequest) Reset() { *m = QueryDrawsRequest{} } +func (m *QueryDrawsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDrawsRequest) ProtoMessage() {} +func (*QueryDrawsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{15} +} +func (m *QueryDrawsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDrawsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDrawsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDrawsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDrawsRequest.Merge(m, src) +} +func (m *QueryDrawsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDrawsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDrawsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDrawsRequest proto.InternalMessageInfo + +func (m *QueryDrawsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolDrawsRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolDrawsRequest) Reset() { *m = QueryPoolDrawsRequest{} } +func (m *QueryPoolDrawsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolDrawsRequest) ProtoMessage() {} +func (*QueryPoolDrawsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{16} +} +func (m *QueryPoolDrawsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolDrawsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolDrawsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolDrawsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolDrawsRequest.Merge(m, src) +} +func (m *QueryPoolDrawsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolDrawsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolDrawsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolDrawsRequest proto.InternalMessageInfo + +func (m *QueryPoolDrawsRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolDrawsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolDrawRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` +} + +func (m *QueryPoolDrawRequest) Reset() { *m = QueryPoolDrawRequest{} } +func (m *QueryPoolDrawRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolDrawRequest) ProtoMessage() {} +func (*QueryPoolDrawRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{17} +} +func (m *QueryPoolDrawRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolDrawRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolDrawRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolDrawRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolDrawRequest.Merge(m, src) +} +func (m *QueryPoolDrawRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolDrawRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolDrawRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolDrawRequest proto.InternalMessageInfo + +func (m *QueryPoolDrawRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolDrawRequest) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +type QueryPrizeResponse struct { + Prize Prize `protobuf:"bytes,1,opt,name=prize,proto3" json:"prize"` +} + +func (m *QueryPrizeResponse) Reset() { *m = QueryPrizeResponse{} } +func (m *QueryPrizeResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPrizeResponse) ProtoMessage() {} +func (*QueryPrizeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{18} +} +func (m *QueryPrizeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPrizeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPrizeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPrizeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPrizeResponse.Merge(m, src) +} +func (m *QueryPrizeResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPrizeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPrizeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPrizeResponse proto.InternalMessageInfo + +func (m *QueryPrizeResponse) GetPrize() Prize { + if m != nil { + return m.Prize + } + return Prize{} +} + +type QueryPrizesResponse struct { + Prizes []Prize `protobuf:"bytes,1,rep,name=prizes,proto3" json:"prizes"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPrizesResponse) Reset() { *m = QueryPrizesResponse{} } +func (m *QueryPrizesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPrizesResponse) ProtoMessage() {} +func (*QueryPrizesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{19} +} +func (m *QueryPrizesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPrizesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPrizesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPrizesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPrizesResponse.Merge(m, src) +} +func (m *QueryPrizesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPrizesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPrizesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPrizesResponse proto.InternalMessageInfo + +func (m *QueryPrizesResponse) GetPrizes() []Prize { + if m != nil { + return m.Prizes + } + return nil +} + +func (m *QueryPrizesResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolDrawPrizeRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + PrizeId uint64 `protobuf:"varint,3,opt,name=prize_id,json=prizeId,proto3" json:"prize_id,omitempty"` +} + +func (m *QueryPoolDrawPrizeRequest) Reset() { *m = QueryPoolDrawPrizeRequest{} } +func (m *QueryPoolDrawPrizeRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolDrawPrizeRequest) ProtoMessage() {} +func (*QueryPoolDrawPrizeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{20} +} +func (m *QueryPoolDrawPrizeRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolDrawPrizeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolDrawPrizeRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolDrawPrizeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolDrawPrizeRequest.Merge(m, src) +} +func (m *QueryPoolDrawPrizeRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolDrawPrizeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolDrawPrizeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolDrawPrizeRequest proto.InternalMessageInfo + +func (m *QueryPoolDrawPrizeRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolDrawPrizeRequest) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *QueryPoolDrawPrizeRequest) GetPrizeId() uint64 { + if m != nil { + return m.PrizeId + } + return 0 +} + +type QueryPrizesRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPrizesRequest) Reset() { *m = QueryPrizesRequest{} } +func (m *QueryPrizesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPrizesRequest) ProtoMessage() {} +func (*QueryPrizesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{21} +} +func (m *QueryPrizesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPrizesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPrizesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPrizesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPrizesRequest.Merge(m, src) +} +func (m *QueryPrizesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPrizesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPrizesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPrizesRequest proto.InternalMessageInfo + +func (m *QueryPrizesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolPrizesRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolPrizesRequest) Reset() { *m = QueryPoolPrizesRequest{} } +func (m *QueryPoolPrizesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolPrizesRequest) ProtoMessage() {} +func (*QueryPoolPrizesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{22} +} +func (m *QueryPoolPrizesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolPrizesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolPrizesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolPrizesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolPrizesRequest.Merge(m, src) +} +func (m *QueryPoolPrizesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolPrizesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolPrizesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolPrizesRequest proto.InternalMessageInfo + +func (m *QueryPoolPrizesRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolPrizesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolDrawPrizesRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolDrawPrizesRequest) Reset() { *m = QueryPoolDrawPrizesRequest{} } +func (m *QueryPoolDrawPrizesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolDrawPrizesRequest) ProtoMessage() {} +func (*QueryPoolDrawPrizesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{23} +} +func (m *QueryPoolDrawPrizesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolDrawPrizesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolDrawPrizesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolDrawPrizesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolDrawPrizesRequest.Merge(m, src) +} +func (m *QueryPoolDrawPrizesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolDrawPrizesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolDrawPrizesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolDrawPrizesRequest proto.InternalMessageInfo + +func (m *QueryPoolDrawPrizesRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolDrawPrizesRequest) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *QueryPoolDrawPrizesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountPrizesRequest struct { + WinnerAddress string `protobuf:"bytes,1,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountPrizesRequest) Reset() { *m = QueryAccountPrizesRequest{} } +func (m *QueryAccountPrizesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountPrizesRequest) ProtoMessage() {} +func (*QueryAccountPrizesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{24} +} +func (m *QueryAccountPrizesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountPrizesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountPrizesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountPrizesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountPrizesRequest.Merge(m, src) +} +func (m *QueryAccountPrizesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountPrizesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountPrizesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountPrizesRequest proto.InternalMessageInfo + +func (m *QueryAccountPrizesRequest) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func (m *QueryAccountPrizesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountPoolPrizesRequest struct { + WinnerAddress string `protobuf:"bytes,1,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` + PoolId uint64 `protobuf:"varint,2,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountPoolPrizesRequest) Reset() { *m = QueryAccountPoolPrizesRequest{} } +func (m *QueryAccountPoolPrizesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountPoolPrizesRequest) ProtoMessage() {} +func (*QueryAccountPoolPrizesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{25} +} +func (m *QueryAccountPoolPrizesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountPoolPrizesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountPoolPrizesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountPoolPrizesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountPoolPrizesRequest.Merge(m, src) +} +func (m *QueryAccountPoolPrizesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountPoolPrizesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountPoolPrizesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountPoolPrizesRequest proto.InternalMessageInfo + +func (m *QueryAccountPoolPrizesRequest) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func (m *QueryAccountPoolPrizesRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryAccountPoolPrizesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountPoolDrawPrizesRequest struct { + WinnerAddress string `protobuf:"bytes,1,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` + PoolId uint64 `protobuf:"varint,2,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,3,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,4,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountPoolDrawPrizesRequest) Reset() { *m = QueryAccountPoolDrawPrizesRequest{} } +func (m *QueryAccountPoolDrawPrizesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountPoolDrawPrizesRequest) ProtoMessage() {} +func (*QueryAccountPoolDrawPrizesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{26} +} +func (m *QueryAccountPoolDrawPrizesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountPoolDrawPrizesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountPoolDrawPrizesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountPoolDrawPrizesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountPoolDrawPrizesRequest.Merge(m, src) +} +func (m *QueryAccountPoolDrawPrizesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountPoolDrawPrizesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountPoolDrawPrizesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountPoolDrawPrizesRequest proto.InternalMessageInfo + +func (m *QueryAccountPoolDrawPrizesRequest) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func (m *QueryAccountPoolDrawPrizesRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryAccountPoolDrawPrizesRequest) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *QueryAccountPoolDrawPrizesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryWithdrawalResponse struct { + Withdrawal Withdrawal `protobuf:"bytes,1,opt,name=withdrawal,proto3" json:"withdrawal"` +} + +func (m *QueryWithdrawalResponse) Reset() { *m = QueryWithdrawalResponse{} } +func (m *QueryWithdrawalResponse) String() string { return proto.CompactTextString(m) } +func (*QueryWithdrawalResponse) ProtoMessage() {} +func (*QueryWithdrawalResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{27} +} +func (m *QueryWithdrawalResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryWithdrawalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryWithdrawalResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryWithdrawalResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryWithdrawalResponse.Merge(m, src) +} +func (m *QueryWithdrawalResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryWithdrawalResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryWithdrawalResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryWithdrawalResponse proto.InternalMessageInfo + +func (m *QueryWithdrawalResponse) GetWithdrawal() Withdrawal { + if m != nil { + return m.Withdrawal + } + return Withdrawal{} +} + +type QueryWithdrawalsResponse struct { + Withdrawals []Withdrawal `protobuf:"bytes,1,rep,name=withdrawals,proto3" json:"withdrawals"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryWithdrawalsResponse) Reset() { *m = QueryWithdrawalsResponse{} } +func (m *QueryWithdrawalsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryWithdrawalsResponse) ProtoMessage() {} +func (*QueryWithdrawalsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{28} +} +func (m *QueryWithdrawalsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryWithdrawalsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryWithdrawalsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryWithdrawalsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryWithdrawalsResponse.Merge(m, src) +} +func (m *QueryWithdrawalsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryWithdrawalsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryWithdrawalsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryWithdrawalsResponse proto.InternalMessageInfo + +func (m *QueryWithdrawalsResponse) GetWithdrawals() []Withdrawal { + if m != nil { + return m.Withdrawals + } + return nil +} + +func (m *QueryWithdrawalsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolWithdrawalRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + WithdrawalId uint64 `protobuf:"varint,2,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` +} + +func (m *QueryPoolWithdrawalRequest) Reset() { *m = QueryPoolWithdrawalRequest{} } +func (m *QueryPoolWithdrawalRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolWithdrawalRequest) ProtoMessage() {} +func (*QueryPoolWithdrawalRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{29} +} +func (m *QueryPoolWithdrawalRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolWithdrawalRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolWithdrawalRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolWithdrawalRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolWithdrawalRequest.Merge(m, src) +} +func (m *QueryPoolWithdrawalRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolWithdrawalRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolWithdrawalRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolWithdrawalRequest proto.InternalMessageInfo + +func (m *QueryPoolWithdrawalRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolWithdrawalRequest) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +type QueryWithdrawalsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryWithdrawalsRequest) Reset() { *m = QueryWithdrawalsRequest{} } +func (m *QueryWithdrawalsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryWithdrawalsRequest) ProtoMessage() {} +func (*QueryWithdrawalsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{30} +} +func (m *QueryWithdrawalsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryWithdrawalsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryWithdrawalsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryWithdrawalsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryWithdrawalsRequest.Merge(m, src) +} +func (m *QueryWithdrawalsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryWithdrawalsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryWithdrawalsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryWithdrawalsRequest proto.InternalMessageInfo + +func (m *QueryWithdrawalsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryPoolWithdrawalsRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolWithdrawalsRequest) Reset() { *m = QueryPoolWithdrawalsRequest{} } +func (m *QueryPoolWithdrawalsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolWithdrawalsRequest) ProtoMessage() {} +func (*QueryPoolWithdrawalsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{31} +} +func (m *QueryPoolWithdrawalsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolWithdrawalsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolWithdrawalsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPoolWithdrawalsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolWithdrawalsRequest.Merge(m, src) +} +func (m *QueryPoolWithdrawalsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolWithdrawalsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolWithdrawalsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolWithdrawalsRequest proto.InternalMessageInfo + +func (m *QueryPoolWithdrawalsRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryPoolWithdrawalsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountWithdrawalsRequest struct { + DepositorAddress string `protobuf:"bytes,1,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountWithdrawalsRequest) Reset() { *m = QueryAccountWithdrawalsRequest{} } +func (m *QueryAccountWithdrawalsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountWithdrawalsRequest) ProtoMessage() {} +func (*QueryAccountWithdrawalsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{32} +} +func (m *QueryAccountWithdrawalsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountWithdrawalsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountWithdrawalsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountWithdrawalsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountWithdrawalsRequest.Merge(m, src) +} +func (m *QueryAccountWithdrawalsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountWithdrawalsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountWithdrawalsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountWithdrawalsRequest proto.InternalMessageInfo + +func (m *QueryAccountWithdrawalsRequest) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *QueryAccountWithdrawalsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAccountPoolWithdrawalsRequest struct { + DepositorAddress string `protobuf:"bytes,1,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + PoolId uint64 `protobuf:"varint,2,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountPoolWithdrawalsRequest) Reset() { *m = QueryAccountPoolWithdrawalsRequest{} } +func (m *QueryAccountPoolWithdrawalsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountPoolWithdrawalsRequest) ProtoMessage() {} +func (*QueryAccountPoolWithdrawalsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7d97bcdbb61e68b1, []int{33} +} +func (m *QueryAccountPoolWithdrawalsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountPoolWithdrawalsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountPoolWithdrawalsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAccountPoolWithdrawalsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountPoolWithdrawalsRequest.Merge(m, src) +} +func (m *QueryAccountPoolWithdrawalsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountPoolWithdrawalsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountPoolWithdrawalsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountPoolWithdrawalsRequest proto.InternalMessageInfo + +func (m *QueryAccountPoolWithdrawalsRequest) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *QueryAccountPoolWithdrawalsRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QueryAccountPoolWithdrawalsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsResponse)(nil), "lum.network.millions.QueryParamsResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "lum.network.millions.QueryParamsRequest") + proto.RegisterType((*QueryPoolResponse)(nil), "lum.network.millions.QueryPoolResponse") + proto.RegisterType((*QueryPoolsResponse)(nil), "lum.network.millions.QueryPoolsResponse") + proto.RegisterType((*QueryPoolRequest)(nil), "lum.network.millions.QueryPoolRequest") + proto.RegisterType((*QueryPoolsRequest)(nil), "lum.network.millions.QueryPoolsRequest") + proto.RegisterType((*QueryDepositResponse)(nil), "lum.network.millions.QueryDepositResponse") + proto.RegisterType((*QueryDepositsResponse)(nil), "lum.network.millions.QueryDepositsResponse") + proto.RegisterType((*QueryDepositsRequest)(nil), "lum.network.millions.QueryDepositsRequest") + proto.RegisterType((*QueryPoolDepositRequest)(nil), "lum.network.millions.QueryPoolDepositRequest") + proto.RegisterType((*QueryPoolDepositsRequest)(nil), "lum.network.millions.QueryPoolDepositsRequest") + proto.RegisterType((*QueryAccountDepositsRequest)(nil), "lum.network.millions.QueryAccountDepositsRequest") + proto.RegisterType((*QueryAccountPoolDepositsRequest)(nil), "lum.network.millions.QueryAccountPoolDepositsRequest") + proto.RegisterType((*QueryDrawResponse)(nil), "lum.network.millions.QueryDrawResponse") + proto.RegisterType((*QueryDrawsResponse)(nil), "lum.network.millions.QueryDrawsResponse") + proto.RegisterType((*QueryDrawsRequest)(nil), "lum.network.millions.QueryDrawsRequest") + proto.RegisterType((*QueryPoolDrawsRequest)(nil), "lum.network.millions.QueryPoolDrawsRequest") + proto.RegisterType((*QueryPoolDrawRequest)(nil), "lum.network.millions.QueryPoolDrawRequest") + proto.RegisterType((*QueryPrizeResponse)(nil), "lum.network.millions.QueryPrizeResponse") + proto.RegisterType((*QueryPrizesResponse)(nil), "lum.network.millions.QueryPrizesResponse") + proto.RegisterType((*QueryPoolDrawPrizeRequest)(nil), "lum.network.millions.QueryPoolDrawPrizeRequest") + proto.RegisterType((*QueryPrizesRequest)(nil), "lum.network.millions.QueryPrizesRequest") + proto.RegisterType((*QueryPoolPrizesRequest)(nil), "lum.network.millions.QueryPoolPrizesRequest") + proto.RegisterType((*QueryPoolDrawPrizesRequest)(nil), "lum.network.millions.QueryPoolDrawPrizesRequest") + proto.RegisterType((*QueryAccountPrizesRequest)(nil), "lum.network.millions.QueryAccountPrizesRequest") + proto.RegisterType((*QueryAccountPoolPrizesRequest)(nil), "lum.network.millions.QueryAccountPoolPrizesRequest") + proto.RegisterType((*QueryAccountPoolDrawPrizesRequest)(nil), "lum.network.millions.QueryAccountPoolDrawPrizesRequest") + proto.RegisterType((*QueryWithdrawalResponse)(nil), "lum.network.millions.QueryWithdrawalResponse") + proto.RegisterType((*QueryWithdrawalsResponse)(nil), "lum.network.millions.QueryWithdrawalsResponse") + proto.RegisterType((*QueryPoolWithdrawalRequest)(nil), "lum.network.millions.QueryPoolWithdrawalRequest") + proto.RegisterType((*QueryWithdrawalsRequest)(nil), "lum.network.millions.QueryWithdrawalsRequest") + proto.RegisterType((*QueryPoolWithdrawalsRequest)(nil), "lum.network.millions.QueryPoolWithdrawalsRequest") + proto.RegisterType((*QueryAccountWithdrawalsRequest)(nil), "lum.network.millions.QueryAccountWithdrawalsRequest") + proto.RegisterType((*QueryAccountPoolWithdrawalsRequest)(nil), "lum.network.millions.QueryAccountPoolWithdrawalsRequest") +} + +func init() { proto.RegisterFile("lum-network/millions/query.proto", fileDescriptor_7d97bcdbb61e68b1) } + +var fileDescriptor_7d97bcdbb61e68b1 = []byte{ + // 1561 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x59, 0xdb, 0x6f, 0x1b, 0xc5, + 0x17, 0xce, 0x24, 0xce, 0xa5, 0x27, 0x4d, 0x2f, 0xa7, 0xe9, 0xcd, 0x6d, 0xdc, 0x74, 0xfb, 0x6b, + 0x92, 0x36, 0xbf, 0xec, 0x36, 0xbd, 0x90, 0x52, 0x88, 0xaa, 0x5e, 0x48, 0x6a, 0x01, 0xa2, 0x89, + 0x84, 0x90, 0x5a, 0x44, 0xb5, 0x89, 0x57, 0x8e, 0x85, 0xed, 0x71, 0xbd, 0x36, 0x69, 0x89, 0x4c, + 0x25, 0x90, 0x78, 0x80, 0x17, 0x2e, 0x0a, 0x97, 0x07, 0x1e, 0x78, 0xaa, 0x40, 0x42, 0x95, 0x90, + 0xe0, 0x89, 0x17, 0x24, 0x24, 0xfa, 0x84, 0x2a, 0xf5, 0x85, 0x27, 0x84, 0x12, 0xfe, 0x01, 0xfe, + 0x03, 0x34, 0xb3, 0xb3, 0xbb, 0xb3, 0xf6, 0x66, 0x77, 0xbd, 0xde, 0xc0, 0x5b, 0xbc, 0x7b, 0x66, + 0xce, 0x77, 0xbe, 0x39, 0xf3, 0xcd, 0x7c, 0x1b, 0x18, 0x2d, 0xd6, 0x4b, 0x53, 0x65, 0xa3, 0xb6, + 0x4a, 0xab, 0x6f, 0x6a, 0xa5, 0x42, 0xb1, 0x58, 0xa0, 0x65, 0x53, 0xbb, 0x5b, 0x37, 0xaa, 0xf7, + 0xd5, 0x4a, 0x95, 0xd6, 0x28, 0x0e, 0x17, 0xeb, 0x25, 0x55, 0x44, 0xa8, 0x76, 0x44, 0x7a, 0x38, + 0x4f, 0xf3, 0x94, 0x07, 0x68, 0xec, 0x2f, 0x2b, 0x36, 0x7d, 0x34, 0x4f, 0x69, 0xbe, 0x68, 0x68, + 0x7a, 0xa5, 0xa0, 0xe9, 0xe5, 0x32, 0xad, 0xe9, 0x35, 0x16, 0x2d, 0xde, 0x9e, 0x5e, 0xa6, 0x66, + 0x89, 0x9a, 0xda, 0x92, 0x6e, 0x1a, 0x56, 0x0a, 0xed, 0xad, 0xe9, 0x25, 0xa3, 0xa6, 0x4f, 0x6b, + 0x15, 0x3d, 0x5f, 0x28, 0xf3, 0x60, 0x11, 0xab, 0xf8, 0xe2, 0xca, 0x19, 0x15, 0x6a, 0x16, 0x6a, + 0x22, 0xe6, 0x98, 0x7f, 0x4c, 0x55, 0x5f, 0x15, 0x01, 0xc7, 0x7d, 0x03, 0x2a, 0x7a, 0x55, 0x2f, + 0x99, 0x81, 0x73, 0x54, 0x28, 0x2d, 0x8a, 0x00, 0x7f, 0x82, 0x2a, 0xd5, 0xc2, 0xdb, 0x86, 0x88, + 0x38, 0xe9, 0x1b, 0xb1, 0x5a, 0xa8, 0xad, 0x30, 0x28, 0xba, 0x98, 0x48, 0x59, 0x80, 0x7d, 0x0b, + 0xac, 0xe6, 0x9b, 0x3c, 0xfd, 0xa2, 0x61, 0x56, 0x68, 0xd9, 0x34, 0xf0, 0x12, 0xf4, 0x59, 0x80, + 0x0e, 0x91, 0x51, 0x32, 0x31, 0x78, 0xf6, 0xa8, 0xea, 0xc7, 0xb7, 0x6a, 0x8d, 0xba, 0x9a, 0x7a, + 0xfc, 0xc7, 0xb1, 0xae, 0x45, 0x31, 0x42, 0x19, 0x06, 0xf4, 0x4c, 0x79, 0xb7, 0x6e, 0x98, 0x35, + 0x25, 0x0b, 0x7b, 0xad, 0xa7, 0x94, 0x16, 0x9d, 0x34, 0xe7, 0x21, 0xc5, 0x8a, 0x12, 0x49, 0xd2, + 0x5b, 0x24, 0xa1, 0xb4, 0x28, 0x52, 0xf0, 0x68, 0x65, 0x9d, 0xd8, 0x19, 0x28, 0x2d, 0xba, 0x98, + 0x9f, 0x81, 0x5e, 0xf6, 0x9a, 0x41, 0xee, 0x89, 0x34, 0x9b, 0x15, 0x8e, 0xf3, 0x00, 0xee, 0x42, + 0x1f, 0xea, 0xe6, 0x50, 0xc6, 0x55, 0xab, 0x2b, 0x54, 0xd6, 0x15, 0xaa, 0xd5, 0x78, 0xa2, 0x2b, + 0xd4, 0x9b, 0x7a, 0xde, 0xb0, 0x93, 0x2e, 0x4a, 0x43, 0x95, 0x49, 0xd8, 0x23, 0x95, 0xc8, 0xcb, + 0xc6, 0x83, 0xd0, 0xcf, 0xb2, 0xdc, 0x29, 0xe4, 0x78, 0x91, 0xa9, 0xc5, 0x3e, 0xf6, 0x33, 0x9b, + 0x53, 0x6e, 0x4b, 0x7c, 0xd8, 0x24, 0xe1, 0x9c, 0x07, 0x8a, 0xc5, 0xca, 0x58, 0x28, 0x14, 0x3e, + 0xd6, 0x83, 0xe4, 0x55, 0x18, 0xe6, 0x93, 0x5f, 0xb7, 0x3a, 0xd3, 0xa1, 0x68, 0x16, 0xfa, 0x45, + 0xb3, 0x8a, 0xc9, 0x47, 0xfc, 0x49, 0x12, 0xe3, 0x04, 0x4f, 0xf6, 0x18, 0xe5, 0x6b, 0x02, 0xfb, + 0xe5, 0x79, 0x5d, 0xee, 0x2f, 0xc3, 0x80, 0x08, 0xb2, 0xe9, 0x8f, 0x34, 0xb3, 0x33, 0x28, 0xb9, + 0x45, 0x78, 0xc3, 0x5b, 0x7a, 0xe2, 0xd4, 0x2e, 0xc0, 0x41, 0x67, 0xdd, 0x1c, 0x7a, 0x83, 0xd7, + 0x1a, 0x47, 0x00, 0x44, 0xa1, 0xec, 0x5d, 0x37, 0x7f, 0xb7, 0x43, 0x3c, 0xc9, 0xe6, 0x94, 0x35, + 0x38, 0xd4, 0x3c, 0xa5, 0x19, 0x3a, 0xe7, 0x9c, 0x0f, 0x61, 0x71, 0xea, 0xf9, 0x84, 0xc0, 0x11, + 0x9e, 0xfd, 0xca, 0xf2, 0x32, 0xad, 0x97, 0x6b, 0xcd, 0x00, 0x26, 0x61, 0xaf, 0x40, 0x4a, 0xab, + 0x77, 0xf4, 0x5c, 0xae, 0x6a, 0x98, 0x96, 0x28, 0xec, 0x58, 0xdc, 0xe3, 0xbc, 0xb8, 0x62, 0x3d, + 0x4f, 0x0c, 0xd4, 0x23, 0x02, 0xc7, 0x64, 0x50, 0x7e, 0xcc, 0xb4, 0x05, 0x4c, 0xa2, 0xb1, 0x3b, + 0x80, 0xc6, 0x9e, 0xd8, 0x88, 0xaf, 0x89, 0xed, 0x7c, 0xbd, 0xaa, 0xaf, 0x3a, 0xbb, 0x42, 0x85, + 0x14, 0x13, 0xdb, 0x60, 0x79, 0xe3, 0x23, 0x78, 0x9c, 0x2b, 0x6c, 0xec, 0x99, 0x47, 0xd8, 0xd8, + 0xeb, 0x10, 0x61, 0x63, 0x63, 0x6c, 0x61, 0xe3, 0xe1, 0xc9, 0xed, 0xa9, 0xdb, 0x52, 0x71, 0x89, + 0x6f, 0xa8, 0x7b, 0x42, 0x53, 0xf8, 0x1a, 0xcb, 0x09, 0xb6, 0xbd, 0xf5, 0x6f, 0x08, 0xa9, 0xb0, + 0x33, 0x87, 0x26, 0x3e, 0x08, 0xfd, 0x8c, 0x59, 0xa9, 0x8b, 0xd8, 0xcf, 0x6c, 0x4e, 0x79, 0xd9, + 0x3e, 0x90, 0xd8, 0x01, 0xec, 0xac, 0xdb, 0x0c, 0xf4, 0xf2, 0x13, 0x59, 0x90, 0x73, 0x64, 0x8b, + 0x03, 0x89, 0x85, 0x38, 0x27, 0x12, 0xfb, 0xa1, 0x7c, 0x49, 0xec, 0x53, 0x99, 0xfd, 0x74, 0x1b, + 0xe1, 0x59, 0xe8, 0xe3, 0x01, 0x76, 0x27, 0x44, 0x98, 0x51, 0x0c, 0x48, 0xae, 0x17, 0x56, 0xe0, + 0xb0, 0x87, 0x34, 0x51, 0x72, 0x4c, 0xe6, 0xf0, 0x30, 0x0c, 0x70, 0x84, 0xec, 0x4d, 0x0f, 0x7f, + 0xd3, 0xcf, 0x7f, 0x67, 0x73, 0xca, 0xeb, 0x32, 0xa9, 0x89, 0xb7, 0xdd, 0x7d, 0x38, 0xe0, 0xd4, + 0xe1, 0xcd, 0xb0, 0xed, 0x7d, 0xf7, 0x19, 0x81, 0x74, 0x2b, 0x87, 0x66, 0x7c, 0x12, 0x93, 0x12, + 0xb1, 0x0f, 0x88, 0x58, 0x5c, 0x5b, 0x76, 0x3d, 0xb8, 0x4e, 0xc2, 0xae, 0xd5, 0x42, 0xb9, 0x6c, + 0x34, 0xab, 0xed, 0x90, 0xf5, 0x34, 0xe9, 0x33, 0xe0, 0x21, 0x81, 0x91, 0xe6, 0x33, 0x20, 0x16, + 0xa0, 0x6d, 0xd7, 0xfe, 0x5f, 0x08, 0x1c, 0x6f, 0x39, 0xad, 0x5a, 0x96, 0xb5, 0x53, 0xb4, 0xd2, + 0xea, 0xf7, 0x04, 0xac, 0x7e, 0x2a, 0x76, 0x19, 0xba, 0xb8, 0xd9, 0xbc, 0xe6, 0x78, 0x04, 0x47, + 0x78, 0xe6, 0x00, 0x5c, 0xe7, 0x20, 0x36, 0xdd, 0xa8, 0xbf, 0xf8, 0xb8, 0xa3, 0x85, 0x02, 0x49, + 0x23, 0x95, 0xef, 0x88, 0xb8, 0xea, 0xb8, 0x51, 0xae, 0xba, 0xdd, 0x80, 0x41, 0x37, 0xd4, 0x96, + 0xb8, 0xa8, 0x59, 0xe4, 0xa1, 0xc9, 0x89, 0xdd, 0x2d, 0x69, 0xa3, 0xca, 0xb4, 0x84, 0x6c, 0xd4, + 0x13, 0x30, 0xe4, 0xc2, 0x71, 0x57, 0x72, 0xa7, 0xfb, 0x30, 0x9b, 0xf3, 0xa1, 0x3b, 0x71, 0x8d, + 0x7b, 0x47, 0x5c, 0xed, 0xbc, 0xf0, 0xff, 0x3d, 0xa1, 0x5b, 0x27, 0x90, 0x91, 0x37, 0x86, 0x0f, + 0x86, 0xff, 0xe4, 0x7a, 0xf9, 0x3d, 0x01, 0xa5, 0x79, 0xc3, 0x76, 0x8a, 0x6d, 0xbb, 0x55, 0xe6, + 0xec, 0xdf, 0x23, 0xd0, 0xcb, 0x41, 0xe3, 0x7b, 0x04, 0xfa, 0x2c, 0x73, 0x8d, 0x13, 0xfe, 0xdb, + 0xa3, 0xd5, 0x7f, 0xa7, 0x4f, 0x45, 0x88, 0xb4, 0x76, 0x80, 0xf2, 0xbf, 0x77, 0x9f, 0xfe, 0xf5, + 0x69, 0x77, 0x06, 0x8f, 0x6a, 0x01, 0x5f, 0x2a, 0xf0, 0x01, 0xf4, 0x72, 0xef, 0x8a, 0xe3, 0x41, + 0x33, 0x4b, 0xee, 0x36, 0x3d, 0x11, 0x1e, 0x28, 0x10, 0x9c, 0xe0, 0x08, 0x46, 0xf0, 0x88, 0xb6, + 0xe5, 0x87, 0x10, 0x13, 0xdf, 0x27, 0x90, 0x62, 0xc3, 0x70, 0x2c, 0x64, 0x5e, 0x3b, 0xff, 0x78, + 0x68, 0x9c, 0x48, 0x3f, 0xc5, 0xd3, 0x8f, 0xe3, 0xc9, 0x80, 0xf4, 0xda, 0x9a, 0x58, 0xee, 0x06, + 0x7e, 0x48, 0x60, 0xc0, 0x76, 0x27, 0x78, 0x3a, 0x20, 0x49, 0x93, 0x85, 0x49, 0x4f, 0x46, 0x8a, + 0x15, 0xa0, 0xc6, 0x38, 0xa8, 0x51, 0xcc, 0x68, 0x41, 0x1f, 0xa1, 0x4c, 0xfc, 0x8a, 0xc0, 0x4e, + 0xd9, 0x2f, 0xa1, 0x1a, 0x52, 0x76, 0x47, 0xa8, 0xce, 0x70, 0x54, 0xa7, 0x71, 0x22, 0x18, 0x95, + 0xc4, 0xd6, 0x43, 0x02, 0x83, 0x52, 0x5a, 0x9c, 0x8a, 0x06, 0xcf, 0x46, 0x17, 0x81, 0x5f, 0x07, + 0xdc, 0x2c, 0x07, 0x37, 0x83, 0x17, 0xa2, 0x82, 0xd3, 0xd6, 0x5c, 0x9f, 0xde, 0xc0, 0x1f, 0x08, + 0xec, 0x6e, 0x72, 0xc5, 0x38, 0x1d, 0x90, 0xde, 0xdf, 0x41, 0xb7, 0xc7, 0xe7, 0x55, 0x0e, 0xf9, + 0x79, 0xbc, 0xe4, 0x0f, 0x59, 0xb7, 0x52, 0x38, 0x38, 0x5d, 0x61, 0x6a, 0xb8, 0x1d, 0xf0, 0x2b, + 0x81, 0x7d, 0x3e, 0xc6, 0x19, 0x2f, 0x84, 0x63, 0xef, 0xb8, 0x1f, 0x5e, 0xe2, 0xf8, 0xe7, 0xf0, + 0x7a, 0x7c, 0xfc, 0x52, 0xaf, 0x3c, 0x80, 0x5e, 0x6e, 0x09, 0x03, 0x35, 0x46, 0x36, 0x8d, 0x81, + 0x1a, 0xe3, 0x71, 0xd5, 0x61, 0x1a, 0x63, 0x59, 0xe8, 0x8f, 0x09, 0xec, 0x70, 0x8c, 0x29, 0x4e, + 0x86, 0xb5, 0x6a, 0x3c, 0x24, 0x21, 0x72, 0xc3, 0x91, 0x48, 0xa4, 0x7c, 0x41, 0x60, 0xc0, 0xce, + 0x16, 0x28, 0x37, 0x4d, 0xbe, 0x36, 0x1d, 0x46, 0xa2, 0x03, 0x68, 0x86, 0x03, 0x9a, 0x46, 0x2d, + 0x12, 0x20, 0x6d, 0x4d, 0xdc, 0x4b, 0x1b, 0xd6, 0xc9, 0x64, 0x19, 0xce, 0x40, 0xb1, 0x97, 0x2f, + 0xc6, 0xc1, 0x27, 0x93, 0xc7, 0x00, 0x87, 0x9e, 0x4c, 0x56, 0xea, 0x75, 0x02, 0xe0, 0xba, 0x05, + 0xfc, 0x7f, 0x08, 0x45, 0xb1, 0xd1, 0xa8, 0x1c, 0xcd, 0x04, 0x8e, 0x05, 0xa1, 0xf1, 0x2a, 0xdf, + 0x2e, 0xaf, 0x37, 0xc0, 0x33, 0x11, 0x96, 0x2f, 0x36, 0xbe, 0x8b, 0x1c, 0xdf, 0x59, 0x3c, 0x13, + 0x0d, 0x9f, 0xb4, 0x8e, 0x8f, 0x08, 0x0c, 0x79, 0xd2, 0xa3, 0x16, 0x15, 0x68, 0xa4, 0xc3, 0x5e, + 0xfe, 0x4c, 0xa2, 0x5c, 0xe3, 0x30, 0x67, 0xf1, 0xb9, 0x76, 0x61, 0x6a, 0x6b, 0xf6, 0xa7, 0x83, + 0x06, 0x7e, 0x4b, 0x60, 0xc8, 0xe3, 0x5a, 0x03, 0x11, 0xfb, 0xf9, 0xdb, 0x76, 0x98, 0x0d, 0x39, + 0x58, 0x1c, 0x95, 0xf3, 0x1a, 0xbe, 0x86, 0xdd, 0xa0, 0x3f, 0x11, 0xd8, 0xdb, 0xe2, 0x6a, 0xf1, + 0x5c, 0x34, 0x79, 0x8e, 0x0d, 0x7a, 0x9e, 0x83, 0xbe, 0x82, 0x97, 0x63, 0x81, 0x96, 0xfa, 0xf8, + 0x37, 0x02, 0xfb, 0x7d, 0xad, 0x2e, 0xce, 0x44, 0x3c, 0x61, 0x3a, 0xe9, 0xea, 0x05, 0x5e, 0xc6, + 0x8b, 0x98, 0xed, 0xb0, 0x0c, 0xa9, 0xdd, 0x3f, 0x27, 0x30, 0x28, 0xdd, 0xff, 0x03, 0xaf, 0x24, + 0xad, 0x3e, 0x21, 0xad, 0x46, 0x0d, 0x17, 0x15, 0x9c, 0xe2, 0x15, 0x9c, 0xc0, 0xe3, 0x5a, 0xc8, + 0xff, 0xe8, 0x4c, 0xfc, 0x86, 0xc0, 0xee, 0x26, 0x77, 0x12, 0x78, 0x05, 0xf1, 0x77, 0x32, 0x6d, + 0x23, 0x3c, 0xc7, 0x11, 0x4e, 0xe1, 0x64, 0x28, 0x42, 0xa9, 0x2d, 0x7e, 0x14, 0xf2, 0xe6, 0x4e, + 0x18, 0x2a, 0x6f, 0x2d, 0x9e, 0x3a, 0x1d, 0x8d, 0xfa, 0xa8, 0xda, 0xe1, 0x0b, 0x94, 0xb5, 0x86, + 0x64, 0xce, 0x1b, 0xf8, 0x33, 0x01, 0x6c, 0x75, 0xa8, 0x78, 0x3e, 0xbc, 0x99, 0x13, 0xa0, 0xfa, + 0x05, 0x5e, 0xc1, 0x65, 0x9c, 0x6d, 0xff, 0xc2, 0x24, 0x37, 0xca, 0x53, 0x02, 0x07, 0xfc, 0xdd, + 0x2c, 0x5e, 0x8c, 0xb6, 0x29, 0x13, 0xa8, 0xe5, 0x15, 0x5e, 0x4b, 0x16, 0xe7, 0x3b, 0xaa, 0xc5, + 0x5d, 0xa9, 0xab, 0xf3, 0x8f, 0x37, 0x32, 0xe4, 0xc9, 0x46, 0x86, 0xfc, 0xb9, 0x91, 0x21, 0x1f, + 0x6d, 0x66, 0xba, 0x9e, 0x6c, 0x66, 0xba, 0x7e, 0xdf, 0xcc, 0x74, 0xdd, 0x9a, 0xca, 0x17, 0x6a, + 0x2b, 0xf5, 0x25, 0x75, 0x99, 0x96, 0x3c, 0xc9, 0x96, 0x57, 0xf4, 0x42, 0x59, 0xbb, 0xe7, 0x26, + 0xad, 0xdd, 0xaf, 0x18, 0xe6, 0x52, 0x1f, 0xff, 0x6f, 0xf7, 0xb9, 0x7f, 0x02, 0x00, 0x00, 0xff, + 0xff, 0xd6, 0x3f, 0xde, 0x1d, 0x59, 0x20, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + Pools(ctx context.Context, in *QueryPoolsRequest, opts ...grpc.CallOption) (*QueryPoolsResponse, error) + Pool(ctx context.Context, in *QueryPoolRequest, opts ...grpc.CallOption) (*QueryPoolResponse, error) + Deposits(ctx context.Context, in *QueryDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) + PoolDeposits(ctx context.Context, in *QueryPoolDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) + PoolDeposit(ctx context.Context, in *QueryPoolDepositRequest, opts ...grpc.CallOption) (*QueryDepositResponse, error) + AccountDeposits(ctx context.Context, in *QueryAccountDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) + AccountPoolDeposits(ctx context.Context, in *QueryAccountPoolDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) + Draws(ctx context.Context, in *QueryDrawsRequest, opts ...grpc.CallOption) (*QueryDrawsResponse, error) + PoolDraws(ctx context.Context, in *QueryPoolDrawsRequest, opts ...grpc.CallOption) (*QueryDrawsResponse, error) + PoolDraw(ctx context.Context, in *QueryPoolDrawRequest, opts ...grpc.CallOption) (*QueryDrawResponse, error) + Prizes(ctx context.Context, in *QueryPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) + PoolPrizes(ctx context.Context, in *QueryPoolPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) + PoolDrawPrizes(ctx context.Context, in *QueryPoolDrawPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) + PoolDrawPrize(ctx context.Context, in *QueryPoolDrawPrizeRequest, opts ...grpc.CallOption) (*QueryPrizeResponse, error) + AccountPrizes(ctx context.Context, in *QueryAccountPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) + AccountPoolPrizes(ctx context.Context, in *QueryAccountPoolPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) + AccountPoolDrawPrizes(ctx context.Context, in *QueryAccountPoolDrawPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) + Withdrawals(ctx context.Context, in *QueryWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) + PoolWithdrawals(ctx context.Context, in *QueryPoolWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) + PoolWithdrawal(ctx context.Context, in *QueryPoolWithdrawalRequest, opts ...grpc.CallOption) (*QueryWithdrawalResponse, error) + AccountWithdrawals(ctx context.Context, in *QueryAccountWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) + AccountPoolWithdrawals(ctx context.Context, in *QueryAccountPoolWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Pools(ctx context.Context, in *QueryPoolsRequest, opts ...grpc.CallOption) (*QueryPoolsResponse, error) { + out := new(QueryPoolsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Pools", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Pool(ctx context.Context, in *QueryPoolRequest, opts ...grpc.CallOption) (*QueryPoolResponse, error) { + out := new(QueryPoolResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Pool", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Deposits(ctx context.Context, in *QueryDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) { + out := new(QueryDepositsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Deposits", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolDeposits(ctx context.Context, in *QueryPoolDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) { + out := new(QueryDepositsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolDeposits", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolDeposit(ctx context.Context, in *QueryPoolDepositRequest, opts ...grpc.CallOption) (*QueryDepositResponse, error) { + out := new(QueryDepositResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolDeposit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountDeposits(ctx context.Context, in *QueryAccountDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) { + out := new(QueryDepositsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountDeposits", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountPoolDeposits(ctx context.Context, in *QueryAccountPoolDepositsRequest, opts ...grpc.CallOption) (*QueryDepositsResponse, error) { + out := new(QueryDepositsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountPoolDeposits", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Draws(ctx context.Context, in *QueryDrawsRequest, opts ...grpc.CallOption) (*QueryDrawsResponse, error) { + out := new(QueryDrawsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Draws", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolDraws(ctx context.Context, in *QueryPoolDrawsRequest, opts ...grpc.CallOption) (*QueryDrawsResponse, error) { + out := new(QueryDrawsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolDraws", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolDraw(ctx context.Context, in *QueryPoolDrawRequest, opts ...grpc.CallOption) (*QueryDrawResponse, error) { + out := new(QueryDrawResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolDraw", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Prizes(ctx context.Context, in *QueryPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) { + out := new(QueryPrizesResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Prizes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolPrizes(ctx context.Context, in *QueryPoolPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) { + out := new(QueryPrizesResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolPrizes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolDrawPrizes(ctx context.Context, in *QueryPoolDrawPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) { + out := new(QueryPrizesResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolDrawPrizes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolDrawPrize(ctx context.Context, in *QueryPoolDrawPrizeRequest, opts ...grpc.CallOption) (*QueryPrizeResponse, error) { + out := new(QueryPrizeResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolDrawPrize", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountPrizes(ctx context.Context, in *QueryAccountPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) { + out := new(QueryPrizesResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountPrizes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountPoolPrizes(ctx context.Context, in *QueryAccountPoolPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) { + out := new(QueryPrizesResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountPoolPrizes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountPoolDrawPrizes(ctx context.Context, in *QueryAccountPoolDrawPrizesRequest, opts ...grpc.CallOption) (*QueryPrizesResponse, error) { + out := new(QueryPrizesResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountPoolDrawPrizes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Withdrawals(ctx context.Context, in *QueryWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) { + out := new(QueryWithdrawalsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/Withdrawals", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolWithdrawals(ctx context.Context, in *QueryPoolWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) { + out := new(QueryWithdrawalsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolWithdrawals", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolWithdrawal(ctx context.Context, in *QueryPoolWithdrawalRequest, opts ...grpc.CallOption) (*QueryWithdrawalResponse, error) { + out := new(QueryWithdrawalResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/PoolWithdrawal", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountWithdrawals(ctx context.Context, in *QueryAccountWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) { + out := new(QueryWithdrawalsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountWithdrawals", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AccountPoolWithdrawals(ctx context.Context, in *QueryAccountPoolWithdrawalsRequest, opts ...grpc.CallOption) (*QueryWithdrawalsResponse, error) { + out := new(QueryWithdrawalsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Query/AccountPoolWithdrawals", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + Pools(context.Context, *QueryPoolsRequest) (*QueryPoolsResponse, error) + Pool(context.Context, *QueryPoolRequest) (*QueryPoolResponse, error) + Deposits(context.Context, *QueryDepositsRequest) (*QueryDepositsResponse, error) + PoolDeposits(context.Context, *QueryPoolDepositsRequest) (*QueryDepositsResponse, error) + PoolDeposit(context.Context, *QueryPoolDepositRequest) (*QueryDepositResponse, error) + AccountDeposits(context.Context, *QueryAccountDepositsRequest) (*QueryDepositsResponse, error) + AccountPoolDeposits(context.Context, *QueryAccountPoolDepositsRequest) (*QueryDepositsResponse, error) + Draws(context.Context, *QueryDrawsRequest) (*QueryDrawsResponse, error) + PoolDraws(context.Context, *QueryPoolDrawsRequest) (*QueryDrawsResponse, error) + PoolDraw(context.Context, *QueryPoolDrawRequest) (*QueryDrawResponse, error) + Prizes(context.Context, *QueryPrizesRequest) (*QueryPrizesResponse, error) + PoolPrizes(context.Context, *QueryPoolPrizesRequest) (*QueryPrizesResponse, error) + PoolDrawPrizes(context.Context, *QueryPoolDrawPrizesRequest) (*QueryPrizesResponse, error) + PoolDrawPrize(context.Context, *QueryPoolDrawPrizeRequest) (*QueryPrizeResponse, error) + AccountPrizes(context.Context, *QueryAccountPrizesRequest) (*QueryPrizesResponse, error) + AccountPoolPrizes(context.Context, *QueryAccountPoolPrizesRequest) (*QueryPrizesResponse, error) + AccountPoolDrawPrizes(context.Context, *QueryAccountPoolDrawPrizesRequest) (*QueryPrizesResponse, error) + Withdrawals(context.Context, *QueryWithdrawalsRequest) (*QueryWithdrawalsResponse, error) + PoolWithdrawals(context.Context, *QueryPoolWithdrawalsRequest) (*QueryWithdrawalsResponse, error) + PoolWithdrawal(context.Context, *QueryPoolWithdrawalRequest) (*QueryWithdrawalResponse, error) + AccountWithdrawals(context.Context, *QueryAccountWithdrawalsRequest) (*QueryWithdrawalsResponse, error) + AccountPoolWithdrawals(context.Context, *QueryAccountPoolWithdrawalsRequest) (*QueryWithdrawalsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) Pools(ctx context.Context, req *QueryPoolsRequest) (*QueryPoolsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Pools not implemented") +} +func (*UnimplementedQueryServer) Pool(ctx context.Context, req *QueryPoolRequest) (*QueryPoolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Pool not implemented") +} +func (*UnimplementedQueryServer) Deposits(ctx context.Context, req *QueryDepositsRequest) (*QueryDepositsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Deposits not implemented") +} +func (*UnimplementedQueryServer) PoolDeposits(ctx context.Context, req *QueryPoolDepositsRequest) (*QueryDepositsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolDeposits not implemented") +} +func (*UnimplementedQueryServer) PoolDeposit(ctx context.Context, req *QueryPoolDepositRequest) (*QueryDepositResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolDeposit not implemented") +} +func (*UnimplementedQueryServer) AccountDeposits(ctx context.Context, req *QueryAccountDepositsRequest) (*QueryDepositsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountDeposits not implemented") +} +func (*UnimplementedQueryServer) AccountPoolDeposits(ctx context.Context, req *QueryAccountPoolDepositsRequest) (*QueryDepositsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountPoolDeposits not implemented") +} +func (*UnimplementedQueryServer) Draws(ctx context.Context, req *QueryDrawsRequest) (*QueryDrawsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Draws not implemented") +} +func (*UnimplementedQueryServer) PoolDraws(ctx context.Context, req *QueryPoolDrawsRequest) (*QueryDrawsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolDraws not implemented") +} +func (*UnimplementedQueryServer) PoolDraw(ctx context.Context, req *QueryPoolDrawRequest) (*QueryDrawResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolDraw not implemented") +} +func (*UnimplementedQueryServer) Prizes(ctx context.Context, req *QueryPrizesRequest) (*QueryPrizesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Prizes not implemented") +} +func (*UnimplementedQueryServer) PoolPrizes(ctx context.Context, req *QueryPoolPrizesRequest) (*QueryPrizesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolPrizes not implemented") +} +func (*UnimplementedQueryServer) PoolDrawPrizes(ctx context.Context, req *QueryPoolDrawPrizesRequest) (*QueryPrizesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolDrawPrizes not implemented") +} +func (*UnimplementedQueryServer) PoolDrawPrize(ctx context.Context, req *QueryPoolDrawPrizeRequest) (*QueryPrizeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolDrawPrize not implemented") +} +func (*UnimplementedQueryServer) AccountPrizes(ctx context.Context, req *QueryAccountPrizesRequest) (*QueryPrizesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountPrizes not implemented") +} +func (*UnimplementedQueryServer) AccountPoolPrizes(ctx context.Context, req *QueryAccountPoolPrizesRequest) (*QueryPrizesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountPoolPrizes not implemented") +} +func (*UnimplementedQueryServer) AccountPoolDrawPrizes(ctx context.Context, req *QueryAccountPoolDrawPrizesRequest) (*QueryPrizesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountPoolDrawPrizes not implemented") +} +func (*UnimplementedQueryServer) Withdrawals(ctx context.Context, req *QueryWithdrawalsRequest) (*QueryWithdrawalsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Withdrawals not implemented") +} +func (*UnimplementedQueryServer) PoolWithdrawals(ctx context.Context, req *QueryPoolWithdrawalsRequest) (*QueryWithdrawalsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolWithdrawals not implemented") +} +func (*UnimplementedQueryServer) PoolWithdrawal(ctx context.Context, req *QueryPoolWithdrawalRequest) (*QueryWithdrawalResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolWithdrawal not implemented") +} +func (*UnimplementedQueryServer) AccountWithdrawals(ctx context.Context, req *QueryAccountWithdrawalsRequest) (*QueryWithdrawalsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountWithdrawals not implemented") +} +func (*UnimplementedQueryServer) AccountPoolWithdrawals(ctx context.Context, req *QueryAccountPoolWithdrawalsRequest) (*QueryWithdrawalsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AccountPoolWithdrawals not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Pools_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Pools(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Pools", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Pools(ctx, req.(*QueryPoolsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Pool_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Pool(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Pool", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Pool(ctx, req.(*QueryPoolRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Deposits_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDepositsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Deposits(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Deposits", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Deposits(ctx, req.(*QueryDepositsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolDeposits_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolDepositsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolDeposits(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolDeposits", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolDeposits(ctx, req.(*QueryPoolDepositsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolDeposit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolDepositRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolDeposit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolDeposit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolDeposit(ctx, req.(*QueryPoolDepositRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountDeposits_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountDepositsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountDeposits(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountDeposits", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountDeposits(ctx, req.(*QueryAccountDepositsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountPoolDeposits_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountPoolDepositsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountPoolDeposits(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountPoolDeposits", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountPoolDeposits(ctx, req.(*QueryAccountPoolDepositsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Draws_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDrawsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Draws(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Draws", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Draws(ctx, req.(*QueryDrawsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolDraws_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolDrawsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolDraws(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolDraws", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolDraws(ctx, req.(*QueryPoolDrawsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolDraw_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolDrawRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolDraw(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolDraw", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolDraw(ctx, req.(*QueryPoolDrawRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Prizes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPrizesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Prizes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Prizes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Prizes(ctx, req.(*QueryPrizesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolPrizes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolPrizesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolPrizes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolPrizes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolPrizes(ctx, req.(*QueryPoolPrizesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolDrawPrizes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolDrawPrizesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolDrawPrizes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolDrawPrizes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolDrawPrizes(ctx, req.(*QueryPoolDrawPrizesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolDrawPrize_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolDrawPrizeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolDrawPrize(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolDrawPrize", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolDrawPrize(ctx, req.(*QueryPoolDrawPrizeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountPrizes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountPrizesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountPrizes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountPrizes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountPrizes(ctx, req.(*QueryAccountPrizesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountPoolPrizes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountPoolPrizesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountPoolPrizes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountPoolPrizes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountPoolPrizes(ctx, req.(*QueryAccountPoolPrizesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountPoolDrawPrizes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountPoolDrawPrizesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountPoolDrawPrizes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountPoolDrawPrizes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountPoolDrawPrizes(ctx, req.(*QueryAccountPoolDrawPrizesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Withdrawals_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryWithdrawalsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Withdrawals(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/Withdrawals", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Withdrawals(ctx, req.(*QueryWithdrawalsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolWithdrawals_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolWithdrawalsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolWithdrawals(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolWithdrawals", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolWithdrawals(ctx, req.(*QueryPoolWithdrawalsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolWithdrawal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolWithdrawalRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolWithdrawal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/PoolWithdrawal", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolWithdrawal(ctx, req.(*QueryPoolWithdrawalRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountWithdrawals_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountWithdrawalsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountWithdrawals(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountWithdrawals", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountWithdrawals(ctx, req.(*QueryAccountWithdrawalsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AccountPoolWithdrawals_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountPoolWithdrawalsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AccountPoolWithdrawals(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Query/AccountPoolWithdrawals", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AccountPoolWithdrawals(ctx, req.(*QueryAccountPoolWithdrawalsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "lum.network.millions.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "Pools", + Handler: _Query_Pools_Handler, + }, + { + MethodName: "Pool", + Handler: _Query_Pool_Handler, + }, + { + MethodName: "Deposits", + Handler: _Query_Deposits_Handler, + }, + { + MethodName: "PoolDeposits", + Handler: _Query_PoolDeposits_Handler, + }, + { + MethodName: "PoolDeposit", + Handler: _Query_PoolDeposit_Handler, + }, + { + MethodName: "AccountDeposits", + Handler: _Query_AccountDeposits_Handler, + }, + { + MethodName: "AccountPoolDeposits", + Handler: _Query_AccountPoolDeposits_Handler, + }, + { + MethodName: "Draws", + Handler: _Query_Draws_Handler, + }, + { + MethodName: "PoolDraws", + Handler: _Query_PoolDraws_Handler, + }, + { + MethodName: "PoolDraw", + Handler: _Query_PoolDraw_Handler, + }, + { + MethodName: "Prizes", + Handler: _Query_Prizes_Handler, + }, + { + MethodName: "PoolPrizes", + Handler: _Query_PoolPrizes_Handler, + }, + { + MethodName: "PoolDrawPrizes", + Handler: _Query_PoolDrawPrizes_Handler, + }, + { + MethodName: "PoolDrawPrize", + Handler: _Query_PoolDrawPrize_Handler, + }, + { + MethodName: "AccountPrizes", + Handler: _Query_AccountPrizes_Handler, + }, + { + MethodName: "AccountPoolPrizes", + Handler: _Query_AccountPoolPrizes_Handler, + }, + { + MethodName: "AccountPoolDrawPrizes", + Handler: _Query_AccountPoolDrawPrizes_Handler, + }, + { + MethodName: "Withdrawals", + Handler: _Query_Withdrawals_Handler, + }, + { + MethodName: "PoolWithdrawals", + Handler: _Query_PoolWithdrawals_Handler, + }, + { + MethodName: "PoolWithdrawal", + Handler: _Query_PoolWithdrawal_Handler, + }, + { + MethodName: "AccountWithdrawals", + Handler: _Query_AccountWithdrawals_Handler, + }, + { + MethodName: "AccountPoolWithdrawals", + Handler: _Query_AccountPoolWithdrawals_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lum-network/millions/query.proto", +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryPoolResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Pool.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryPoolsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Pools) > 0 { + for iNdEx := len(m.Pools) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Pools[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDepositResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDepositResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDepositResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Deposit.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryDepositsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDepositsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDepositsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Deposits) > 0 { + for iNdEx := len(m.Deposits) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Deposits[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryDepositsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDepositsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDepositsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolDepositRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolDepositRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolDepositRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DepositId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolDepositsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolDepositsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolDepositsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountDepositsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountDepositsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountDepositsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountPoolDepositsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountPoolDepositsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountPoolDepositsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x10 + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDrawResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDrawResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDrawResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Draw != nil { + { + size, err := m.Draw.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDrawsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDrawsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDrawsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Draws) > 0 { + for iNdEx := len(m.Draws) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Draws[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryDrawsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDrawsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDrawsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolDrawsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolDrawsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolDrawsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolDrawRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolDrawRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolDrawRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DrawId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPrizeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPrizeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPrizeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Prize.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryPrizesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPrizesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPrizesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Prizes) > 0 { + for iNdEx := len(m.Prizes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Prizes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolDrawPrizeRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolDrawPrizeRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolDrawPrizeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PrizeId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PrizeId)) + i-- + dAtA[i] = 0x18 + } + if m.DrawId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPrizesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPrizesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPrizesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolPrizesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolPrizesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolPrizesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolDrawPrizesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolDrawPrizesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolDrawPrizesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.DrawId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountPrizesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountPrizesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountPrizesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountPoolPrizesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountPoolPrizesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountPoolPrizesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x10 + } + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountPoolDrawPrizesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountPoolDrawPrizesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountPoolDrawPrizesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.DrawId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x18 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x10 + } + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryWithdrawalResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryWithdrawalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryWithdrawalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Withdrawal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryWithdrawalsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryWithdrawalsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryWithdrawalsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Withdrawals) > 0 { + for iNdEx := len(m.Withdrawals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Withdrawals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolWithdrawalRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolWithdrawalRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolWithdrawalRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.WithdrawalId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryWithdrawalsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryWithdrawalsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryWithdrawalsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolWithdrawalsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPoolWithdrawalsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolWithdrawalsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountWithdrawalsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountWithdrawalsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountWithdrawalsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountPoolWithdrawalsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAccountPoolWithdrawalsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountPoolWithdrawalsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x10 + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryPoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Pool.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPoolsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Pools) > 0 { + for _, e := range m.Pools { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + return n +} + +func (m *QueryPoolsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDepositResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Deposit.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryDepositsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Deposits) > 0 { + for _, e := range m.Deposits { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDepositsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolDepositRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovQuery(uint64(m.DepositId)) + } + return n +} + +func (m *QueryPoolDepositsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountDepositsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountPoolDepositsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDrawResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Draw != nil { + l = m.Draw.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDrawsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Draws) > 0 { + for _, e := range m.Draws { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDrawsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolDrawsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolDrawRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovQuery(uint64(m.DrawId)) + } + return n +} + +func (m *QueryPrizeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Prize.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPrizesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Prizes) > 0 { + for _, e := range m.Prizes { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolDrawPrizeRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovQuery(uint64(m.DrawId)) + } + if m.PrizeId != 0 { + n += 1 + sovQuery(uint64(m.PrizeId)) + } + return n +} + +func (m *QueryPrizesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolPrizesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolDrawPrizesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovQuery(uint64(m.DrawId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountPrizesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountPoolPrizesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountPoolDrawPrizesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovQuery(uint64(m.DrawId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryWithdrawalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Withdrawal.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryWithdrawalsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Withdrawals) > 0 { + for _, e := range m.Withdrawals { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolWithdrawalRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.WithdrawalId != 0 { + n += 1 + sovQuery(uint64(m.WithdrawalId)) + } + return n +} + +func (m *QueryWithdrawalsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolWithdrawalsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountWithdrawalsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountPoolWithdrawalsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Pool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pools", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Pools = append(m.Pools, Pool{}) + if err := m.Pools[len(m.Pools)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDepositResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDepositResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDepositResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Deposit", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Deposit.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDepositsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDepositsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDepositsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Deposits", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Deposits = append(m.Deposits, Deposit{}) + if err := m.Deposits[len(m.Deposits)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDepositsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDepositsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDepositsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolDepositRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolDepositRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolDepositRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolDepositsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolDepositsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolDepositsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountDepositsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountDepositsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountDepositsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountPoolDepositsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountPoolDepositsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountPoolDepositsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDrawResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDrawResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDrawResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Draw", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Draw == nil { + m.Draw = &Draw{} + } + if err := m.Draw.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDrawsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDrawsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDrawsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Draws", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Draws = append(m.Draws, Draw{}) + if err := m.Draws[len(m.Draws)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDrawsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDrawsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDrawsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolDrawsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolDrawsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolDrawsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolDrawRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolDrawRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolDrawRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPrizeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPrizeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPrizeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Prize", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Prize.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPrizesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPrizesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPrizesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Prizes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Prizes = append(m.Prizes, Prize{}) + if err := m.Prizes[len(m.Prizes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolDrawPrizeRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolDrawPrizeRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolDrawPrizeRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeId", wireType) + } + m.PrizeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PrizeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPrizesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPrizesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPrizesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolPrizesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolPrizesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolPrizesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolDrawPrizesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolDrawPrizesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolDrawPrizesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountPrizesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountPrizesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountPrizesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountPoolPrizesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountPoolPrizesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountPoolPrizesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountPoolDrawPrizesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountPoolDrawPrizesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountPoolDrawPrizesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryWithdrawalResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryWithdrawalResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryWithdrawalResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Withdrawal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Withdrawal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryWithdrawalsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryWithdrawalsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryWithdrawalsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Withdrawals", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Withdrawals = append(m.Withdrawals, Withdrawal{}) + if err := m.Withdrawals[len(m.Withdrawals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolWithdrawalRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolWithdrawalRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolWithdrawalRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryWithdrawalsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryWithdrawalsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryWithdrawalsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPoolWithdrawalsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPoolWithdrawalsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolWithdrawalsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountWithdrawalsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountWithdrawalsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountWithdrawalsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountPoolWithdrawalsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAccountPoolWithdrawalsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountPoolWithdrawalsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/query.pb.gw.go b/x/millions/types/query.pb.gw.go new file mode 100644 index 00000000..5815240f --- /dev/null +++ b/x/millions/types/query.pb.gw.go @@ -0,0 +1,2743 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lum-network/millions/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Pools_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Pools_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Pools_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Pools(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Pools_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Pools_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Pools(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Pool_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + msg, err := client.Pool(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Pool_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + msg, err := server.Pool(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Deposits_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Deposits_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDepositsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Deposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Deposits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Deposits_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDepositsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Deposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Deposits(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PoolDeposits_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_PoolDeposits_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDepositsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolDeposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PoolDeposits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolDeposits_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDepositsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolDeposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PoolDeposits(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PoolDeposit_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDepositRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["deposit_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "deposit_id") + } + + protoReq.DepositId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "deposit_id", err) + } + + msg, err := client.PoolDeposit(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolDeposit_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDepositRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["deposit_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "deposit_id") + } + + protoReq.DepositId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "deposit_id", err) + } + + msg, err := server.PoolDeposit(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountDeposits_0 = &utilities.DoubleArray{Encoding: map[string]int{"depositor_address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_AccountDeposits_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountDepositsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountDeposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountDeposits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountDeposits_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountDepositsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountDeposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountDeposits(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountPoolDeposits_0 = &utilities.DoubleArray{Encoding: map[string]int{"depositor_address": 0, "pool_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Query_AccountPoolDeposits_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolDepositsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolDeposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountPoolDeposits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountPoolDeposits_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolDepositsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolDeposits_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountPoolDeposits(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Draws_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Draws_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDrawsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Draws_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Draws(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Draws_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDrawsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Draws_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Draws(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PoolDraws_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_PoolDraws_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolDraws_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PoolDraws(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolDraws_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolDraws_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PoolDraws(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PoolDraw_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + msg, err := client.PoolDraw(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolDraw_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + msg, err := server.PoolDraw(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Prizes_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Prizes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPrizesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Prizes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Prizes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPrizesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Prizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Prizes(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PoolPrizes_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_PoolPrizes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PoolPrizes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolPrizes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PoolPrizes(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PoolDrawPrizes_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0, "draw_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Query_PoolDrawPrizes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolDrawPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PoolDrawPrizes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolDrawPrizes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolDrawPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PoolDrawPrizes(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PoolDrawPrize_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawPrizeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + val, ok = pathParams["prize_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "prize_id") + } + + protoReq.PrizeId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "prize_id", err) + } + + msg, err := client.PoolDrawPrize(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolDrawPrize_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolDrawPrizeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + val, ok = pathParams["prize_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "prize_id") + } + + protoReq.PrizeId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "prize_id", err) + } + + msg, err := server.PoolDrawPrize(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountPrizes_0 = &utilities.DoubleArray{Encoding: map[string]int{"winner_address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_AccountPrizes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["winner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "winner_address") + } + + protoReq.WinnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "winner_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountPrizes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountPrizes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["winner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "winner_address") + } + + protoReq.WinnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "winner_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountPrizes(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountPoolPrizes_0 = &utilities.DoubleArray{Encoding: map[string]int{"winner_address": 0, "pool_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Query_AccountPoolPrizes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["winner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "winner_address") + } + + protoReq.WinnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "winner_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountPoolPrizes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountPoolPrizes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["winner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "winner_address") + } + + protoReq.WinnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "winner_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountPoolPrizes(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountPoolDrawPrizes_0 = &utilities.DoubleArray{Encoding: map[string]int{"winner_address": 0, "pool_id": 1, "draw_id": 2}, Base: []int{1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 1, 2, 3, 4}} +) + +func request_Query_AccountPoolDrawPrizes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolDrawPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["winner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "winner_address") + } + + protoReq.WinnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "winner_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolDrawPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountPoolDrawPrizes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountPoolDrawPrizes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolDrawPrizesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["winner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "winner_address") + } + + protoReq.WinnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "winner_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["draw_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "draw_id") + } + + protoReq.DrawId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "draw_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolDrawPrizes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountPoolDrawPrizes(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Withdrawals_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Withdrawals_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryWithdrawalsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Withdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Withdrawals(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Withdrawals_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryWithdrawalsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Withdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Withdrawals(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PoolWithdrawals_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_PoolWithdrawals_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolWithdrawalsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolWithdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PoolWithdrawals(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolWithdrawals_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolWithdrawalsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PoolWithdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PoolWithdrawals(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PoolWithdrawal_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolWithdrawalRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["withdrawal_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "withdrawal_id") + } + + protoReq.WithdrawalId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "withdrawal_id", err) + } + + msg, err := client.PoolWithdrawal(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolWithdrawal_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolWithdrawalRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + val, ok = pathParams["withdrawal_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "withdrawal_id") + } + + protoReq.WithdrawalId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "withdrawal_id", err) + } + + msg, err := server.PoolWithdrawal(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountWithdrawals_0 = &utilities.DoubleArray{Encoding: map[string]int{"depositor_address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_AccountWithdrawals_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountWithdrawalsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountWithdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountWithdrawals(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountWithdrawals_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountWithdrawalsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountWithdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountWithdrawals(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AccountPoolWithdrawals_0 = &utilities.DoubleArray{Encoding: map[string]int{"depositor_address": 0, "pool_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Query_AccountPoolWithdrawals_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolWithdrawalsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolWithdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AccountPoolWithdrawals(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AccountPoolWithdrawals_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountPoolWithdrawalsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["depositor_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "depositor_address") + } + + protoReq.DepositorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "depositor_address", err) + } + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AccountPoolWithdrawals_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AccountPoolWithdrawals(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Pools_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Pools_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Pools_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Pool_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Pool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Deposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Deposits_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Deposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDeposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolDeposits_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDeposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDeposit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolDeposit_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDeposit_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountDeposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountDeposits_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountDeposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolDeposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountPoolDeposits_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolDeposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Draws_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Draws_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Draws_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDraws_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolDraws_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDraws_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDraw_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolDraw_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDraw_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Prizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Prizes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Prizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolPrizes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDrawPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolDrawPrizes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDrawPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDrawPrize_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolDrawPrize_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDrawPrize_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountPrizes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountPoolPrizes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolDrawPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountPoolDrawPrizes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolDrawPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Withdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Withdrawals_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Withdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolWithdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolWithdrawals_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolWithdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolWithdrawal_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PoolWithdrawal_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolWithdrawal_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountWithdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountWithdrawals_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountWithdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolWithdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AccountPoolWithdrawals_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolWithdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Pools_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Pools_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Pools_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Pool_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Pool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Deposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Deposits_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Deposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDeposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolDeposits_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDeposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDeposit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolDeposit_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDeposit_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountDeposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountDeposits_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountDeposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolDeposits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountPoolDeposits_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolDeposits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Draws_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Draws_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Draws_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDraws_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolDraws_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDraws_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDraw_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolDraw_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDraw_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Prizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Prizes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Prizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolPrizes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDrawPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolDrawPrizes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDrawPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolDrawPrize_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolDrawPrize_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolDrawPrize_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountPrizes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountPoolPrizes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolDrawPrizes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountPoolDrawPrizes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolDrawPrizes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Withdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Withdrawals_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Withdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolWithdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolWithdrawals_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolWithdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolWithdrawal_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PoolWithdrawal_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PoolWithdrawal_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountWithdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountWithdrawals_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountWithdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AccountPoolWithdrawals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AccountPoolWithdrawals_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AccountPoolWithdrawals_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "millions", "params"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Pools_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "millions", "pools"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Pool_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "millions", "pools", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Deposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "millions", "deposits"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolDeposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "millions", "deposits", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolDeposit_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"lum-network", "millions", "deposits", "pool_id", "deposit_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountDeposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"lum-network", "millions", "account", "depositor_address", "deposits"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountPoolDeposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"lum-network", "millions", "account", "depositor_address", "deposits", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Draws_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "millions", "draws"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolDraws_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "millions", "draws", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolDraw_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"lum-network", "millions", "draws", "pool_id", "draw_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Prizes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "millions", "prizes"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolPrizes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "millions", "prizes", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolDrawPrizes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"lum-network", "millions", "prizes", "pool_id", "draw_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolDrawPrize_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"lum-network", "millions", "prizes", "pool_id", "draw_id", "prize_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountPrizes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"lum-network", "millions", "account", "winner_address", "prizes"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountPoolPrizes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"lum-network", "millions", "account", "winner_address", "prizes", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountPoolDrawPrizes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5, 1, 0, 4, 1, 5, 6}, []string{"lum-network", "millions", "account", "winner_address", "prizes", "pool_id", "draw_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Withdrawals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"lum-network", "millions", "withdrawals"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolWithdrawals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"lum-network", "millions", "withdrawals", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_PoolWithdrawal_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"lum-network", "millions", "withdrawals", "pool_id", "withdrawal_id"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountWithdrawals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"lum-network", "millions", "account", "depositor_address", "withdrawals"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AccountPoolWithdrawals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"lum-network", "millions", "account", "depositor_address", "withdrawals", "pool_id"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_Pools_0 = runtime.ForwardResponseMessage + + forward_Query_Pool_0 = runtime.ForwardResponseMessage + + forward_Query_Deposits_0 = runtime.ForwardResponseMessage + + forward_Query_PoolDeposits_0 = runtime.ForwardResponseMessage + + forward_Query_PoolDeposit_0 = runtime.ForwardResponseMessage + + forward_Query_AccountDeposits_0 = runtime.ForwardResponseMessage + + forward_Query_AccountPoolDeposits_0 = runtime.ForwardResponseMessage + + forward_Query_Draws_0 = runtime.ForwardResponseMessage + + forward_Query_PoolDraws_0 = runtime.ForwardResponseMessage + + forward_Query_PoolDraw_0 = runtime.ForwardResponseMessage + + forward_Query_Prizes_0 = runtime.ForwardResponseMessage + + forward_Query_PoolPrizes_0 = runtime.ForwardResponseMessage + + forward_Query_PoolDrawPrizes_0 = runtime.ForwardResponseMessage + + forward_Query_PoolDrawPrize_0 = runtime.ForwardResponseMessage + + forward_Query_AccountPrizes_0 = runtime.ForwardResponseMessage + + forward_Query_AccountPoolPrizes_0 = runtime.ForwardResponseMessage + + forward_Query_AccountPoolDrawPrizes_0 = runtime.ForwardResponseMessage + + forward_Query_Withdrawals_0 = runtime.ForwardResponseMessage + + forward_Query_PoolWithdrawals_0 = runtime.ForwardResponseMessage + + forward_Query_PoolWithdrawal_0 = runtime.ForwardResponseMessage + + forward_Query_AccountWithdrawals_0 = runtime.ForwardResponseMessage + + forward_Query_AccountPoolWithdrawals_0 = runtime.ForwardResponseMessage +) diff --git a/x/millions/types/tx.pb.go b/x/millions/types/tx.pb.go new file mode 100644 index 00000000..39486819 --- /dev/null +++ b/x/millions/types/tx.pb.go @@ -0,0 +1,5453 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MsgUpdateParams struct { + MinDepositAmount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount,omitempty"` + MaxPrizeStrategyBatches *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=max_prize_strategy_batches,json=maxPrizeStrategyBatches,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_prize_strategy_batches,omitempty"` + MaxPrizeBatchQuantity *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=max_prize_batch_quantity,json=maxPrizeBatchQuantity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_prize_batch_quantity,omitempty"` + MinDrawScheduleDelta *time.Duration `protobuf:"bytes,4,opt,name=min_draw_schedule_delta,json=minDrawScheduleDelta,proto3,stdduration" json:"min_draw_schedule_delta,omitempty"` + MaxDrawScheduleDelta *time.Duration `protobuf:"bytes,5,opt,name=max_draw_schedule_delta,json=maxDrawScheduleDelta,proto3,stdduration" json:"max_draw_schedule_delta,omitempty"` + PrizeExpirationDelta *time.Duration `protobuf:"bytes,6,opt,name=prize_expiration_delta,json=prizeExpirationDelta,proto3,stdduration" json:"prize_expiration_delta,omitempty"` + FeesStakers *github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=fees_stakers,json=feesStakers,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"fees_stakers,omitempty"` + MinDepositDrawDelta *time.Duration `protobuf:"bytes,8,opt,name=min_deposit_draw_delta,json=minDepositDrawDelta,proto3,stdduration" json:"min_deposit_draw_delta,omitempty"` + UpdaterAddress string `protobuf:"bytes,9,opt,name=updater_address,json=updaterAddress,proto3" json:"updater_address,omitempty"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetMinDrawScheduleDelta() *time.Duration { + if m != nil { + return m.MinDrawScheduleDelta + } + return nil +} + +func (m *MsgUpdateParams) GetMaxDrawScheduleDelta() *time.Duration { + if m != nil { + return m.MaxDrawScheduleDelta + } + return nil +} + +func (m *MsgUpdateParams) GetPrizeExpirationDelta() *time.Duration { + if m != nil { + return m.PrizeExpirationDelta + } + return nil +} + +func (m *MsgUpdateParams) GetMinDepositDrawDelta() *time.Duration { + if m != nil { + return m.MinDepositDrawDelta + } + return nil +} + +func (m *MsgUpdateParams) GetUpdaterAddress() string { + if m != nil { + return m.UpdaterAddress + } + return "" +} + +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +type MsgRegisterPool struct { + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` + NativeDenom string `protobuf:"bytes,3,opt,name=native_denom,json=nativeDenom,proto3" json:"native_denom,omitempty"` + ConnectionId string `protobuf:"bytes,4,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + Validators []string `protobuf:"bytes,5,rep,name=validators,proto3" json:"validators,omitempty"` + MinDepositAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount"` + DrawSchedule DrawSchedule `protobuf:"bytes,7,opt,name=draw_schedule,json=drawSchedule,proto3" json:"draw_schedule"` + PrizeStrategy PrizeStrategy `protobuf:"bytes,8,opt,name=prize_strategy,json=prizeStrategy,proto3" json:"prize_strategy"` + Bech32PrefixAccAddr string `protobuf:"bytes,9,opt,name=bech32_prefix_acc_addr,json=bech32PrefixAccAddr,proto3" json:"bech32_prefix_acc_addr,omitempty"` + Bech32PrefixValAddr string `protobuf:"bytes,10,opt,name=bech32_prefix_val_addr,json=bech32PrefixValAddr,proto3" json:"bech32_prefix_val_addr,omitempty"` + CreatorAddress string `protobuf:"bytes,11,opt,name=creator_address,json=creatorAddress,proto3" json:"creator_address,omitempty"` +} + +func (m *MsgRegisterPool) Reset() { *m = MsgRegisterPool{} } +func (m *MsgRegisterPool) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterPool) ProtoMessage() {} +func (*MsgRegisterPool) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{2} +} +func (m *MsgRegisterPool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterPool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRegisterPool) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterPool.Merge(m, src) +} +func (m *MsgRegisterPool) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterPool) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterPool.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterPool proto.InternalMessageInfo + +func (m *MsgRegisterPool) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *MsgRegisterPool) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *MsgRegisterPool) GetNativeDenom() string { + if m != nil { + return m.NativeDenom + } + return "" +} + +func (m *MsgRegisterPool) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *MsgRegisterPool) GetValidators() []string { + if m != nil { + return m.Validators + } + return nil +} + +func (m *MsgRegisterPool) GetDrawSchedule() DrawSchedule { + if m != nil { + return m.DrawSchedule + } + return DrawSchedule{} +} + +func (m *MsgRegisterPool) GetPrizeStrategy() PrizeStrategy { + if m != nil { + return m.PrizeStrategy + } + return PrizeStrategy{} +} + +func (m *MsgRegisterPool) GetBech32PrefixAccAddr() string { + if m != nil { + return m.Bech32PrefixAccAddr + } + return "" +} + +func (m *MsgRegisterPool) GetBech32PrefixValAddr() string { + if m != nil { + return m.Bech32PrefixValAddr + } + return "" +} + +func (m *MsgRegisterPool) GetCreatorAddress() string { + if m != nil { + return m.CreatorAddress + } + return "" +} + +type MsgRegisterPoolResponse struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` +} + +func (m *MsgRegisterPoolResponse) Reset() { *m = MsgRegisterPoolResponse{} } +func (m *MsgRegisterPoolResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterPoolResponse) ProtoMessage() {} +func (*MsgRegisterPoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{3} +} +func (m *MsgRegisterPoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterPoolResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRegisterPoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterPoolResponse.Merge(m, src) +} +func (m *MsgRegisterPoolResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterPoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterPoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterPoolResponse proto.InternalMessageInfo + +func (m *MsgRegisterPoolResponse) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +type MsgUpdatePool struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Validators []string `protobuf:"bytes,2,rep,name=validators,proto3" json:"validators,omitempty"` + MinDepositAmount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=min_deposit_amount,json=minDepositAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit_amount,omitempty"` + DrawSchedule *DrawSchedule `protobuf:"bytes,4,opt,name=draw_schedule,json=drawSchedule,proto3" json:"draw_schedule,omitempty"` + PrizeStrategy *PrizeStrategy `protobuf:"bytes,5,opt,name=prize_strategy,json=prizeStrategy,proto3" json:"prize_strategy,omitempty"` + UpdaterAddress string `protobuf:"bytes,6,opt,name=updater_address,json=updaterAddress,proto3" json:"updater_address,omitempty"` +} + +func (m *MsgUpdatePool) Reset() { *m = MsgUpdatePool{} } +func (m *MsgUpdatePool) String() string { return proto.CompactTextString(m) } +func (*MsgUpdatePool) ProtoMessage() {} +func (*MsgUpdatePool) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{4} +} +func (m *MsgUpdatePool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdatePool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdatePool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdatePool) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdatePool.Merge(m, src) +} +func (m *MsgUpdatePool) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdatePool) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdatePool.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdatePool proto.InternalMessageInfo + +func (m *MsgUpdatePool) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgUpdatePool) GetValidators() []string { + if m != nil { + return m.Validators + } + return nil +} + +func (m *MsgUpdatePool) GetDrawSchedule() *DrawSchedule { + if m != nil { + return m.DrawSchedule + } + return nil +} + +func (m *MsgUpdatePool) GetPrizeStrategy() *PrizeStrategy { + if m != nil { + return m.PrizeStrategy + } + return nil +} + +func (m *MsgUpdatePool) GetUpdaterAddress() string { + if m != nil { + return m.UpdaterAddress + } + return "" +} + +type MsgUpdatePoolResponse struct { +} + +func (m *MsgUpdatePoolResponse) Reset() { *m = MsgUpdatePoolResponse{} } +func (m *MsgUpdatePoolResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdatePoolResponse) ProtoMessage() {} +func (*MsgUpdatePoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{5} +} +func (m *MsgUpdatePoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdatePoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdatePoolResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdatePoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdatePoolResponse.Merge(m, src) +} +func (m *MsgUpdatePoolResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdatePoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdatePoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdatePoolResponse proto.InternalMessageInfo + +type MsgDeposit struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Amount types.Coin `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount"` + DepositorAddress string `protobuf:"bytes,3,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + WinnerAddress string `protobuf:"bytes,4,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` + IsSponsor bool `protobuf:"varint,5,opt,name=is_sponsor,json=isSponsor,proto3" json:"is_sponsor,omitempty"` +} + +func (m *MsgDeposit) Reset() { *m = MsgDeposit{} } +func (m *MsgDeposit) String() string { return proto.CompactTextString(m) } +func (*MsgDeposit) ProtoMessage() {} +func (*MsgDeposit) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{6} +} +func (m *MsgDeposit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDeposit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDeposit.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDeposit) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDeposit.Merge(m, src) +} +func (m *MsgDeposit) XXX_Size() int { + return m.Size() +} +func (m *MsgDeposit) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDeposit.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDeposit proto.InternalMessageInfo + +func (m *MsgDeposit) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgDeposit) GetAmount() types.Coin { + if m != nil { + return m.Amount + } + return types.Coin{} +} + +func (m *MsgDeposit) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *MsgDeposit) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +func (m *MsgDeposit) GetIsSponsor() bool { + if m != nil { + return m.IsSponsor + } + return false +} + +type MsgDepositResponse struct { + DepositId uint64 `protobuf:"varint,1,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` +} + +func (m *MsgDepositResponse) Reset() { *m = MsgDepositResponse{} } +func (m *MsgDepositResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDepositResponse) ProtoMessage() {} +func (*MsgDepositResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{7} +} +func (m *MsgDepositResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDepositResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDepositResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDepositResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDepositResponse.Merge(m, src) +} +func (m *MsgDepositResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDepositResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDepositResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDepositResponse proto.InternalMessageInfo + +func (m *MsgDepositResponse) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +type MsgDepositRetry struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` + DepositorAddress string `protobuf:"bytes,3,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` +} + +func (m *MsgDepositRetry) Reset() { *m = MsgDepositRetry{} } +func (m *MsgDepositRetry) String() string { return proto.CompactTextString(m) } +func (*MsgDepositRetry) ProtoMessage() {} +func (*MsgDepositRetry) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{8} +} +func (m *MsgDepositRetry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDepositRetry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDepositRetry.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDepositRetry) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDepositRetry.Merge(m, src) +} +func (m *MsgDepositRetry) XXX_Size() int { + return m.Size() +} +func (m *MsgDepositRetry) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDepositRetry.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDepositRetry proto.InternalMessageInfo + +func (m *MsgDepositRetry) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgDepositRetry) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +func (m *MsgDepositRetry) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +type MsgDepositRetryResponse struct { +} + +func (m *MsgDepositRetryResponse) Reset() { *m = MsgDepositRetryResponse{} } +func (m *MsgDepositRetryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDepositRetryResponse) ProtoMessage() {} +func (*MsgDepositRetryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{9} +} +func (m *MsgDepositRetryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDepositRetryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDepositRetryResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDepositRetryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDepositRetryResponse.Merge(m, src) +} +func (m *MsgDepositRetryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDepositRetryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDepositRetryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDepositRetryResponse proto.InternalMessageInfo + +type MsgClaimPrize struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + PrizeId uint64 `protobuf:"varint,3,opt,name=prize_id,json=prizeId,proto3" json:"prize_id,omitempty"` + WinnerAddress string `protobuf:"bytes,4,opt,name=winner_address,json=winnerAddress,proto3" json:"winner_address,omitempty"` +} + +func (m *MsgClaimPrize) Reset() { *m = MsgClaimPrize{} } +func (m *MsgClaimPrize) String() string { return proto.CompactTextString(m) } +func (*MsgClaimPrize) ProtoMessage() {} +func (*MsgClaimPrize) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{10} +} +func (m *MsgClaimPrize) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgClaimPrize) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgClaimPrize.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgClaimPrize) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgClaimPrize.Merge(m, src) +} +func (m *MsgClaimPrize) XXX_Size() int { + return m.Size() +} +func (m *MsgClaimPrize) XXX_DiscardUnknown() { + xxx_messageInfo_MsgClaimPrize.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgClaimPrize proto.InternalMessageInfo + +func (m *MsgClaimPrize) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgClaimPrize) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *MsgClaimPrize) GetPrizeId() uint64 { + if m != nil { + return m.PrizeId + } + return 0 +} + +func (m *MsgClaimPrize) GetWinnerAddress() string { + if m != nil { + return m.WinnerAddress + } + return "" +} + +type MsgClaimPrizeResponse struct { +} + +func (m *MsgClaimPrizeResponse) Reset() { *m = MsgClaimPrizeResponse{} } +func (m *MsgClaimPrizeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgClaimPrizeResponse) ProtoMessage() {} +func (*MsgClaimPrizeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{11} +} +func (m *MsgClaimPrizeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgClaimPrizeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgClaimPrizeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgClaimPrizeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgClaimPrizeResponse.Merge(m, src) +} +func (m *MsgClaimPrizeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgClaimPrizeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgClaimPrizeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgClaimPrizeResponse proto.InternalMessageInfo + +type MsgWithdrawDeposit struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` + DepositorAddress string `protobuf:"bytes,3,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + ToAddress string `protobuf:"bytes,4,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty"` +} + +func (m *MsgWithdrawDeposit) Reset() { *m = MsgWithdrawDeposit{} } +func (m *MsgWithdrawDeposit) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawDeposit) ProtoMessage() {} +func (*MsgWithdrawDeposit) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{12} +} +func (m *MsgWithdrawDeposit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawDeposit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawDeposit.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawDeposit) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawDeposit.Merge(m, src) +} +func (m *MsgWithdrawDeposit) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawDeposit) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawDeposit.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawDeposit proto.InternalMessageInfo + +func (m *MsgWithdrawDeposit) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgWithdrawDeposit) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +func (m *MsgWithdrawDeposit) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *MsgWithdrawDeposit) GetToAddress() string { + if m != nil { + return m.ToAddress + } + return "" +} + +type MsgWithdrawDepositResponse struct { + WithdrawalId uint64 `protobuf:"varint,1,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` +} + +func (m *MsgWithdrawDepositResponse) Reset() { *m = MsgWithdrawDepositResponse{} } +func (m *MsgWithdrawDepositResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawDepositResponse) ProtoMessage() {} +func (*MsgWithdrawDepositResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{13} +} +func (m *MsgWithdrawDepositResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawDepositResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawDepositResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawDepositResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawDepositResponse.Merge(m, src) +} +func (m *MsgWithdrawDepositResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawDepositResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawDepositResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawDepositResponse proto.InternalMessageInfo + +func (m *MsgWithdrawDepositResponse) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +type MsgWithdrawDepositRetry struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + WithdrawalId uint64 `protobuf:"varint,2,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` + DepositorAddress string `protobuf:"bytes,3,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` +} + +func (m *MsgWithdrawDepositRetry) Reset() { *m = MsgWithdrawDepositRetry{} } +func (m *MsgWithdrawDepositRetry) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawDepositRetry) ProtoMessage() {} +func (*MsgWithdrawDepositRetry) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{14} +} +func (m *MsgWithdrawDepositRetry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawDepositRetry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawDepositRetry.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawDepositRetry) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawDepositRetry.Merge(m, src) +} +func (m *MsgWithdrawDepositRetry) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawDepositRetry) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawDepositRetry.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawDepositRetry proto.InternalMessageInfo + +func (m *MsgWithdrawDepositRetry) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgWithdrawDepositRetry) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +func (m *MsgWithdrawDepositRetry) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +type MsgWithdrawDepositRetryResponse struct { +} + +func (m *MsgWithdrawDepositRetryResponse) Reset() { *m = MsgWithdrawDepositRetryResponse{} } +func (m *MsgWithdrawDepositRetryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawDepositRetryResponse) ProtoMessage() {} +func (*MsgWithdrawDepositRetryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{15} +} +func (m *MsgWithdrawDepositRetryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawDepositRetryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawDepositRetryResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawDepositRetryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawDepositRetryResponse.Merge(m, src) +} +func (m *MsgWithdrawDepositRetryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawDepositRetryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawDepositRetryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawDepositRetryResponse proto.InternalMessageInfo + +type MsgDrawRetry struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DrawId uint64 `protobuf:"varint,2,opt,name=draw_id,json=drawId,proto3" json:"draw_id,omitempty"` + DrawRetryAddress string `protobuf:"bytes,3,opt,name=draw_retry_address,json=drawRetryAddress,proto3" json:"draw_retry_address,omitempty"` +} + +func (m *MsgDrawRetry) Reset() { *m = MsgDrawRetry{} } +func (m *MsgDrawRetry) String() string { return proto.CompactTextString(m) } +func (*MsgDrawRetry) ProtoMessage() {} +func (*MsgDrawRetry) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{16} +} +func (m *MsgDrawRetry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDrawRetry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDrawRetry.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDrawRetry) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDrawRetry.Merge(m, src) +} +func (m *MsgDrawRetry) XXX_Size() int { + return m.Size() +} +func (m *MsgDrawRetry) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDrawRetry.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDrawRetry proto.InternalMessageInfo + +func (m *MsgDrawRetry) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgDrawRetry) GetDrawId() uint64 { + if m != nil { + return m.DrawId + } + return 0 +} + +func (m *MsgDrawRetry) GetDrawRetryAddress() string { + if m != nil { + return m.DrawRetryAddress + } + return "" +} + +type MsgDrawRetryResponse struct { +} + +func (m *MsgDrawRetryResponse) Reset() { *m = MsgDrawRetryResponse{} } +func (m *MsgDrawRetryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDrawRetryResponse) ProtoMessage() {} +func (*MsgDrawRetryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{17} +} +func (m *MsgDrawRetryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDrawRetryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDrawRetryResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDrawRetryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDrawRetryResponse.Merge(m, src) +} +func (m *MsgDrawRetryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDrawRetryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDrawRetryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDrawRetryResponse proto.InternalMessageInfo + +type MsgRestoreInterchainAccounts struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + RestorerAddress string `protobuf:"bytes,2,opt,name=restorer_address,json=restorerAddress,proto3" json:"restorer_address,omitempty"` +} + +func (m *MsgRestoreInterchainAccounts) Reset() { *m = MsgRestoreInterchainAccounts{} } +func (m *MsgRestoreInterchainAccounts) String() string { return proto.CompactTextString(m) } +func (*MsgRestoreInterchainAccounts) ProtoMessage() {} +func (*MsgRestoreInterchainAccounts) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{18} +} +func (m *MsgRestoreInterchainAccounts) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRestoreInterchainAccounts) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRestoreInterchainAccounts.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRestoreInterchainAccounts) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRestoreInterchainAccounts.Merge(m, src) +} +func (m *MsgRestoreInterchainAccounts) XXX_Size() int { + return m.Size() +} +func (m *MsgRestoreInterchainAccounts) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRestoreInterchainAccounts.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRestoreInterchainAccounts proto.InternalMessageInfo + +func (m *MsgRestoreInterchainAccounts) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *MsgRestoreInterchainAccounts) GetRestorerAddress() string { + if m != nil { + return m.RestorerAddress + } + return "" +} + +type MsgRestoreInterchainAccountsResponse struct { +} + +func (m *MsgRestoreInterchainAccountsResponse) Reset() { *m = MsgRestoreInterchainAccountsResponse{} } +func (m *MsgRestoreInterchainAccountsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRestoreInterchainAccountsResponse) ProtoMessage() {} +func (*MsgRestoreInterchainAccountsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1261f7cafc5ae2ec, []int{19} +} +func (m *MsgRestoreInterchainAccountsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRestoreInterchainAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRestoreInterchainAccountsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRestoreInterchainAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRestoreInterchainAccountsResponse.Merge(m, src) +} +func (m *MsgRestoreInterchainAccountsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRestoreInterchainAccountsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRestoreInterchainAccountsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRestoreInterchainAccountsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "lum.network.millions.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "lum.network.millions.MsgUpdateParamsResponse") + proto.RegisterType((*MsgRegisterPool)(nil), "lum.network.millions.MsgRegisterPool") + proto.RegisterType((*MsgRegisterPoolResponse)(nil), "lum.network.millions.MsgRegisterPoolResponse") + proto.RegisterType((*MsgUpdatePool)(nil), "lum.network.millions.MsgUpdatePool") + proto.RegisterType((*MsgUpdatePoolResponse)(nil), "lum.network.millions.MsgUpdatePoolResponse") + proto.RegisterType((*MsgDeposit)(nil), "lum.network.millions.MsgDeposit") + proto.RegisterType((*MsgDepositResponse)(nil), "lum.network.millions.MsgDepositResponse") + proto.RegisterType((*MsgDepositRetry)(nil), "lum.network.millions.MsgDepositRetry") + proto.RegisterType((*MsgDepositRetryResponse)(nil), "lum.network.millions.MsgDepositRetryResponse") + proto.RegisterType((*MsgClaimPrize)(nil), "lum.network.millions.MsgClaimPrize") + proto.RegisterType((*MsgClaimPrizeResponse)(nil), "lum.network.millions.MsgClaimPrizeResponse") + proto.RegisterType((*MsgWithdrawDeposit)(nil), "lum.network.millions.MsgWithdrawDeposit") + proto.RegisterType((*MsgWithdrawDepositResponse)(nil), "lum.network.millions.MsgWithdrawDepositResponse") + proto.RegisterType((*MsgWithdrawDepositRetry)(nil), "lum.network.millions.MsgWithdrawDepositRetry") + proto.RegisterType((*MsgWithdrawDepositRetryResponse)(nil), "lum.network.millions.MsgWithdrawDepositRetryResponse") + proto.RegisterType((*MsgDrawRetry)(nil), "lum.network.millions.MsgDrawRetry") + proto.RegisterType((*MsgDrawRetryResponse)(nil), "lum.network.millions.MsgDrawRetryResponse") + proto.RegisterType((*MsgRestoreInterchainAccounts)(nil), "lum.network.millions.MsgRestoreInterchainAccounts") + proto.RegisterType((*MsgRestoreInterchainAccountsResponse)(nil), "lum.network.millions.MsgRestoreInterchainAccountsResponse") +} + +func init() { proto.RegisterFile("lum-network/millions/tx.proto", fileDescriptor_1261f7cafc5ae2ec) } + +var fileDescriptor_1261f7cafc5ae2ec = []byte{ + // 1327 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x58, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xcf, 0x3a, 0x8e, 0x13, 0xbf, 0x38, 0x4d, 0xd9, 0xba, 0x89, 0x63, 0x51, 0x27, 0x75, 0x4a, + 0x15, 0x40, 0xb1, 0x69, 0x22, 0x54, 0x89, 0x0b, 0x72, 0x9a, 0x82, 0x7c, 0x88, 0x94, 0x6e, 0x54, + 0xfe, 0x14, 0xc4, 0x6a, 0xbc, 0x3b, 0x75, 0x46, 0xd9, 0xdd, 0x31, 0x3b, 0xe3, 0xc4, 0x41, 0xbd, + 0x22, 0x21, 0x71, 0xe9, 0x91, 0x0b, 0x7c, 0x0a, 0x3e, 0x44, 0x0f, 0x1c, 0x2a, 0x0e, 0x08, 0x71, + 0x28, 0xa8, 0xfd, 0x16, 0x9c, 0xd0, 0xfc, 0xd9, 0xf5, 0x3a, 0xf6, 0xd6, 0x76, 0x5b, 0x71, 0x6a, + 0x67, 0xe6, 0xbd, 0xdf, 0xfb, 0xcd, 0x7b, 0xbf, 0xf7, 0x66, 0x63, 0xb8, 0xe6, 0x75, 0xfd, 0xed, + 0x00, 0xf3, 0x33, 0x1a, 0x9e, 0xd4, 0x7d, 0xe2, 0x79, 0x84, 0x06, 0xac, 0xce, 0x7b, 0xb5, 0x4e, + 0x48, 0x39, 0x35, 0x8b, 0x5e, 0xd7, 0xaf, 0xe9, 0xe3, 0x5a, 0x74, 0x5c, 0x2e, 0xb6, 0x69, 0x9b, + 0x4a, 0x83, 0xba, 0xf8, 0x9f, 0xb2, 0x2d, 0x57, 0xda, 0x94, 0xb6, 0x3d, 0x5c, 0x97, 0xab, 0x56, + 0xf7, 0x61, 0xdd, 0xed, 0x86, 0x88, 0x13, 0x1a, 0x44, 0xe7, 0x0e, 0x65, 0x3e, 0x65, 0xf5, 0x16, + 0x62, 0xb8, 0x7e, 0x7a, 0xab, 0x85, 0x39, 0xba, 0x55, 0x77, 0x28, 0x89, 0xce, 0xd7, 0xd4, 0xb9, + 0xad, 0x80, 0xd5, 0x42, 0x1f, 0x6d, 0x8d, 0x64, 0xe9, 0x86, 0xe8, 0xcc, 0x66, 0xce, 0x31, 0x76, + 0xbb, 0x1e, 0xd6, 0x96, 0xeb, 0x23, 0x2d, 0x3b, 0x94, 0x7a, 0xda, 0xe0, 0xdd, 0xd1, 0x06, 0x21, + 0xf9, 0x0e, 0xdb, 0x8c, 0x87, 0x88, 0xe3, 0xf6, 0xb9, 0x32, 0xad, 0x3e, 0xc9, 0xc1, 0xf2, 0x01, + 0x6b, 0xdf, 0xef, 0xb8, 0x88, 0xe3, 0x43, 0x14, 0x22, 0x9f, 0x99, 0x5f, 0x83, 0xe9, 0x93, 0xc0, + 0x76, 0x71, 0x87, 0x32, 0xc2, 0x6d, 0xe4, 0xd3, 0x6e, 0xc0, 0x4b, 0xc6, 0x86, 0xb1, 0x95, 0xdf, + 0xab, 0x3d, 0x79, 0xb6, 0x6e, 0xfc, 0xf5, 0x6c, 0xfd, 0x66, 0x9b, 0xf0, 0xe3, 0x6e, 0xab, 0xe6, + 0x50, 0x5f, 0x5f, 0x43, 0xff, 0xb3, 0xcd, 0xdc, 0x93, 0x3a, 0x3f, 0xef, 0x60, 0x56, 0x6b, 0x06, + 0xdc, 0xba, 0xec, 0x93, 0x60, 0x5f, 0x01, 0x35, 0x24, 0x8e, 0x79, 0x02, 0x65, 0x1f, 0xf5, 0xec, + 0x41, 0x36, 0x76, 0x0b, 0x71, 0xe7, 0x18, 0xb3, 0x52, 0xe6, 0x95, 0xa2, 0xac, 0xfa, 0xa8, 0x77, + 0x28, 0x00, 0x8f, 0x34, 0xde, 0x9e, 0x82, 0x33, 0xdb, 0x50, 0xea, 0x07, 0x93, 0x31, 0xec, 0x6f, + 0xbb, 0x28, 0xe0, 0x84, 0x9f, 0x97, 0x66, 0x5f, 0x29, 0xd4, 0xd5, 0x28, 0x94, 0x0c, 0x71, 0x4f, + 0x83, 0x99, 0x0f, 0x60, 0x55, 0xe6, 0x2c, 0x59, 0x2e, 0xdb, 0xc5, 0x1e, 0x47, 0xa5, 0xec, 0x86, + 0xb1, 0xb5, 0xb8, 0xb3, 0x56, 0x53, 0xd2, 0xa9, 0x45, 0xd2, 0xa9, 0xed, 0x6b, 0xe9, 0xec, 0x2d, + 0x08, 0x0a, 0x3f, 0xfd, 0xbd, 0x6e, 0x58, 0x45, 0x91, 0xad, 0x10, 0x9d, 0x1d, 0x69, 0x84, 0x7d, + 0x01, 0x20, 0xb1, 0x51, 0x6f, 0x24, 0xf6, 0xdc, 0x34, 0xd8, 0xa8, 0x37, 0x8c, 0xfd, 0x25, 0xac, + 0xa8, 0xe4, 0xe0, 0x5e, 0x87, 0x28, 0x1f, 0x0d, 0x9d, 0x9b, 0x02, 0x5a, 0x42, 0xdc, 0x8d, 0x11, + 0x14, 0xf4, 0x3d, 0x28, 0x3c, 0xc4, 0x98, 0xd9, 0x8c, 0xa3, 0x13, 0x1c, 0xb2, 0xd2, 0xfc, 0xd4, + 0xf9, 0xde, 0xc7, 0x8e, 0xb5, 0x28, 0x30, 0x8e, 0x14, 0x84, 0xf9, 0x05, 0xac, 0x24, 0x95, 0x29, + 0x33, 0xa2, 0xd8, 0x2e, 0x4c, 0xce, 0xf6, 0x4a, 0x5f, 0x92, 0x22, 0x1f, 0x8a, 0x6c, 0x03, 0x96, + 0xbb, 0xb2, 0x07, 0x42, 0x1b, 0xb9, 0x6e, 0x88, 0x19, 0x2b, 0xe5, 0x25, 0xdf, 0xd2, 0xef, 0xbf, + 0x6e, 0x17, 0x75, 0xa3, 0x36, 0xd4, 0xc9, 0x11, 0x0f, 0x49, 0xd0, 0xb6, 0x2e, 0x69, 0x07, 0xbd, + 0x5b, 0x5d, 0x83, 0xd5, 0x0b, 0x9d, 0x64, 0x61, 0xd6, 0xa1, 0x01, 0xc3, 0xd5, 0x3f, 0xb2, 0xb2, + 0xcb, 0x2c, 0xdc, 0x26, 0x8c, 0xe3, 0xf0, 0x90, 0x52, 0xcf, 0x5c, 0x83, 0x05, 0xe7, 0x18, 0x91, + 0xc0, 0x26, 0xae, 0xea, 0x2d, 0x6b, 0x5e, 0xae, 0x9b, 0xae, 0x59, 0x84, 0x39, 0x17, 0x07, 0xd4, + 0x57, 0xdd, 0x60, 0xa9, 0x85, 0x79, 0x1d, 0x0a, 0x01, 0xe2, 0xe4, 0x54, 0xd4, 0x5e, 0x1c, 0x4a, + 0xfd, 0x5a, 0x8b, 0x6a, 0x6f, 0x5f, 0x9a, 0x6c, 0xc2, 0x92, 0x43, 0x83, 0x00, 0x3b, 0xb2, 0x8e, + 0xc4, 0x95, 0xda, 0xcb, 0x5b, 0x85, 0xfe, 0x66, 0xd3, 0x35, 0x2b, 0x00, 0xa7, 0xc8, 0x23, 0x2e, + 0xe2, 0x34, 0x64, 0xa5, 0xb9, 0x8d, 0xd9, 0xad, 0xbc, 0x95, 0xd8, 0x49, 0x69, 0xff, 0x5c, 0x5c, + 0xbd, 0x99, 0xd7, 0x6a, 0xff, 0x03, 0x58, 0x1a, 0x10, 0xb2, 0x94, 0xc5, 0xe2, 0x4e, 0xb5, 0x36, + 0x6a, 0x0a, 0xd7, 0x92, 0x82, 0xdd, 0xcb, 0x8a, 0xe0, 0x56, 0xc1, 0x4d, 0xec, 0x99, 0x87, 0x70, + 0x69, 0x70, 0x92, 0x68, 0x25, 0x6c, 0x8e, 0xc6, 0x1b, 0x1c, 0x12, 0x0a, 0x70, 0xa9, 0x93, 0xdc, + 0x34, 0x77, 0x61, 0xa5, 0x85, 0x9d, 0xe3, 0xdd, 0x1d, 0xbb, 0x13, 0xe2, 0x87, 0xa4, 0x67, 0x23, + 0xc7, 0x91, 0x9a, 0x50, 0x82, 0xb0, 0xae, 0xa8, 0xd3, 0x43, 0x79, 0xd8, 0x70, 0x1c, 0x51, 0xfe, + 0x61, 0xa7, 0x53, 0xe4, 0x29, 0x27, 0x18, 0x76, 0xfa, 0x0c, 0x79, 0xd2, 0xa9, 0x01, 0xcb, 0x4e, + 0x88, 0x45, 0xd2, 0x63, 0xcd, 0x2d, 0x8e, 0xd3, 0x9c, 0x76, 0x88, 0x34, 0xb7, 0x23, 0x35, 0x97, + 0xd4, 0x55, 0xa4, 0x39, 0x73, 0x15, 0xe6, 0xc5, 0x93, 0x10, 0xc9, 0x2b, 0x6b, 0xe5, 0xc4, 0xb2, + 0xe9, 0x56, 0x1f, 0xcf, 0xc2, 0x52, 0x5f, 0xa8, 0x42, 0x8a, 0x69, 0xa6, 0xe6, 0x8d, 0x01, 0xa9, + 0x64, 0x84, 0x54, 0x64, 0xd2, 0x8c, 0x09, 0x04, 0x33, 0xfb, 0x86, 0xde, 0x8b, 0x21, 0xc1, 0x64, + 0xa7, 0x12, 0x8c, 0x31, 0x56, 0x30, 0x73, 0xd3, 0x09, 0xc6, 0xb8, 0x28, 0x98, 0x11, 0xa3, 0x23, + 0x37, 0xe5, 0xe8, 0x58, 0x85, 0xab, 0x03, 0x15, 0x89, 0x07, 0xc7, 0xf7, 0x19, 0x80, 0x03, 0xd6, + 0xd6, 0x19, 0x49, 0x2f, 0xd4, 0x6d, 0xc8, 0xe9, 0xb4, 0x67, 0xf4, 0x20, 0xd4, 0x71, 0xc5, 0x87, + 0x48, 0x4d, 0x7f, 0x88, 0xd4, 0xee, 0x50, 0x12, 0x68, 0xd1, 0x6b, 0x73, 0xf3, 0x2e, 0xbc, 0xa5, + 0xeb, 0x96, 0x50, 0xe1, 0xec, 0x18, 0xfa, 0x97, 0x63, 0x17, 0xbd, 0x6f, 0x7e, 0x0c, 0x97, 0xce, + 0x48, 0x10, 0x24, 0x52, 0x90, 0x1d, 0x83, 0xb1, 0xa4, 0xec, 0x23, 0x80, 0x6b, 0x00, 0x84, 0xd9, + 0xf2, 0xd6, 0x34, 0x94, 0x25, 0x59, 0xb0, 0xf2, 0x84, 0x1d, 0xa9, 0x8d, 0xea, 0x2e, 0x98, 0xfd, + 0x34, 0xc4, 0x12, 0xbf, 0x06, 0x10, 0x89, 0x2e, 0xce, 0x48, 0x5e, 0xef, 0x08, 0xa1, 0x1b, 0x72, + 0xea, 0xc6, 0x5e, 0x3c, 0x3c, 0x4f, 0xcf, 0xe0, 0x20, 0x56, 0xe6, 0x02, 0xd6, 0x1b, 0xca, 0x93, + 0x7e, 0x23, 0x92, 0x8c, 0xe2, 0x52, 0xff, 0x6c, 0xc8, 0xb6, 0xbc, 0xe3, 0x21, 0xe2, 0x4b, 0xd5, + 0xa5, 0x73, 0x5d, 0x85, 0x79, 0xd9, 0x12, 0x31, 0xd1, 0x9c, 0x58, 0x36, 0x5d, 0xf1, 0xa6, 0x28, + 0x71, 0x13, 0x57, 0x92, 0xcb, 0x5a, 0xf3, 0x72, 0xdd, 0x74, 0x5f, 0xbb, 0x42, 0x5a, 0xa3, 0x7d, + 0x7a, 0x31, 0xf1, 0xdf, 0x0c, 0x59, 0x9c, 0xcf, 0x09, 0x3f, 0x76, 0xe5, 0x7b, 0x3a, 0x46, 0xab, + 0xff, 0x4b, 0xa6, 0xcd, 0xdb, 0x00, 0x9c, 0x4e, 0x7c, 0xd7, 0x3c, 0xa7, 0xd1, 0x3d, 0x1b, 0x50, + 0x1e, 0xbe, 0x4d, 0x2c, 0xb9, 0x4d, 0x58, 0x3a, 0xd3, 0x47, 0x28, 0x71, 0xb7, 0x42, 0x7f, 0xb3, + 0xe9, 0x56, 0x7f, 0x31, 0x64, 0x99, 0x87, 0x30, 0x5e, 0x2a, 0xc0, 0x21, 0xe4, 0xcc, 0x30, 0xf2, + 0x9b, 0x92, 0xe1, 0x75, 0x58, 0x4f, 0xe1, 0x17, 0x57, 0xf5, 0x07, 0x03, 0x0a, 0x42, 0xaa, 0x21, + 0x3a, 0x1b, 0x43, 0x3c, 0x55, 0x8d, 0x9f, 0x80, 0x29, 0x0f, 0x42, 0xe1, 0x3f, 0x05, 0xdb, 0x28, + 0x64, 0xc4, 0x76, 0x05, 0x8a, 0x49, 0x26, 0x31, 0xc5, 0x47, 0xf0, 0xb6, 0x7c, 0xfc, 0x18, 0xa7, + 0x21, 0x6e, 0x06, 0x1c, 0x87, 0xf2, 0x03, 0xaa, 0xe1, 0x38, 0x62, 0xb4, 0xb1, 0x74, 0xc6, 0x77, + 0xe0, 0x72, 0xa8, 0xbc, 0xfa, 0x49, 0xcc, 0x8c, 0xa1, 0xb5, 0x1c, 0x79, 0x44, 0xac, 0x6e, 0xc2, + 0x8d, 0x97, 0x45, 0x8f, 0x58, 0xee, 0xfc, 0x3b, 0x07, 0xb3, 0x07, 0xac, 0x6d, 0xde, 0x87, 0xf9, + 0xa8, 0x35, 0x36, 0x46, 0xbf, 0x35, 0xfd, 0xc9, 0x50, 0xde, 0x1a, 0x67, 0x11, 0x0b, 0xd2, 0x85, + 0xc2, 0x80, 0xbe, 0xde, 0x19, 0xef, 0xc9, 0xc3, 0xf3, 0xf2, 0xf6, 0x44, 0x66, 0x71, 0x94, 0x6f, + 0x00, 0x12, 0x83, 0x69, 0x33, 0xd5, 0xb9, 0x6f, 0x54, 0x7e, 0x7f, 0x02, 0xa3, 0x18, 0xdf, 0x87, + 0xe5, 0x8b, 0xf3, 0x23, 0x3d, 0x05, 0x17, 0x2c, 0xcb, 0x1f, 0x4c, 0x6a, 0x19, 0x87, 0x7b, 0x04, + 0xc5, 0x91, 0xcd, 0xb9, 0x3d, 0x39, 0x92, 0x48, 0xe2, 0x87, 0x53, 0x99, 0xc7, 0xd1, 0xbf, 0x82, + 0x7c, 0xbf, 0xad, 0xaa, 0xe9, 0x85, 0x88, 0x6c, 0xca, 0xef, 0x8d, 0xb7, 0x89, 0xc1, 0x7f, 0x34, + 0x60, 0x2d, 0xbd, 0x25, 0x76, 0x52, 0x91, 0x52, 0x7d, 0xca, 0x1f, 0x4d, 0xef, 0x13, 0xb1, 0xd9, + 0xfb, 0xf4, 0xc9, 0xf3, 0x8a, 0xf1, 0xf4, 0x79, 0xc5, 0xf8, 0xe7, 0x79, 0xc5, 0x78, 0xfc, 0xa2, + 0x32, 0xf3, 0xf4, 0x45, 0x65, 0xe6, 0xcf, 0x17, 0x95, 0x99, 0x07, 0xdb, 0x89, 0x0f, 0xc2, 0xe4, + 0xcf, 0x15, 0x12, 0xa7, 0xde, 0x4b, 0xfc, 0x4e, 0x23, 0xbe, 0x0d, 0x5b, 0x39, 0xf9, 0x17, 0xdd, + 0xee, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x7f, 0xb5, 0xa8, 0xcc, 0x11, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + Deposit(ctx context.Context, in *MsgDeposit, opts ...grpc.CallOption) (*MsgDepositResponse, error) + DepositRetry(ctx context.Context, in *MsgDepositRetry, opts ...grpc.CallOption) (*MsgDepositRetryResponse, error) + ClaimPrize(ctx context.Context, in *MsgClaimPrize, opts ...grpc.CallOption) (*MsgClaimPrizeResponse, error) + WithdrawDeposit(ctx context.Context, in *MsgWithdrawDeposit, opts ...grpc.CallOption) (*MsgWithdrawDepositResponse, error) + WithdrawDepositRetry(ctx context.Context, in *MsgWithdrawDepositRetry, opts ...grpc.CallOption) (*MsgWithdrawDepositRetryResponse, error) + DrawRetry(ctx context.Context, in *MsgDrawRetry, opts ...grpc.CallOption) (*MsgDrawRetryResponse, error) + RestoreInterchainAccounts(ctx context.Context, in *MsgRestoreInterchainAccounts, opts ...grpc.CallOption) (*MsgRestoreInterchainAccountsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Deposit(ctx context.Context, in *MsgDeposit, opts ...grpc.CallOption) (*MsgDepositResponse, error) { + out := new(MsgDepositResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/Deposit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) DepositRetry(ctx context.Context, in *MsgDepositRetry, opts ...grpc.CallOption) (*MsgDepositRetryResponse, error) { + out := new(MsgDepositRetryResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/DepositRetry", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) ClaimPrize(ctx context.Context, in *MsgClaimPrize, opts ...grpc.CallOption) (*MsgClaimPrizeResponse, error) { + out := new(MsgClaimPrizeResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/ClaimPrize", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) WithdrawDeposit(ctx context.Context, in *MsgWithdrawDeposit, opts ...grpc.CallOption) (*MsgWithdrawDepositResponse, error) { + out := new(MsgWithdrawDepositResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/WithdrawDeposit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) WithdrawDepositRetry(ctx context.Context, in *MsgWithdrawDepositRetry, opts ...grpc.CallOption) (*MsgWithdrawDepositRetryResponse, error) { + out := new(MsgWithdrawDepositRetryResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/WithdrawDepositRetry", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) DrawRetry(ctx context.Context, in *MsgDrawRetry, opts ...grpc.CallOption) (*MsgDrawRetryResponse, error) { + out := new(MsgDrawRetryResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/DrawRetry", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RestoreInterchainAccounts(ctx context.Context, in *MsgRestoreInterchainAccounts, opts ...grpc.CallOption) (*MsgRestoreInterchainAccountsResponse, error) { + out := new(MsgRestoreInterchainAccountsResponse) + err := c.cc.Invoke(ctx, "/lum.network.millions.Msg/RestoreInterchainAccounts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + Deposit(context.Context, *MsgDeposit) (*MsgDepositResponse, error) + DepositRetry(context.Context, *MsgDepositRetry) (*MsgDepositRetryResponse, error) + ClaimPrize(context.Context, *MsgClaimPrize) (*MsgClaimPrizeResponse, error) + WithdrawDeposit(context.Context, *MsgWithdrawDeposit) (*MsgWithdrawDepositResponse, error) + WithdrawDepositRetry(context.Context, *MsgWithdrawDepositRetry) (*MsgWithdrawDepositRetryResponse, error) + DrawRetry(context.Context, *MsgDrawRetry) (*MsgDrawRetryResponse, error) + RestoreInterchainAccounts(context.Context, *MsgRestoreInterchainAccounts) (*MsgRestoreInterchainAccountsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Deposit(ctx context.Context, req *MsgDeposit) (*MsgDepositResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Deposit not implemented") +} +func (*UnimplementedMsgServer) DepositRetry(ctx context.Context, req *MsgDepositRetry) (*MsgDepositRetryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DepositRetry not implemented") +} +func (*UnimplementedMsgServer) ClaimPrize(ctx context.Context, req *MsgClaimPrize) (*MsgClaimPrizeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ClaimPrize not implemented") +} +func (*UnimplementedMsgServer) WithdrawDeposit(ctx context.Context, req *MsgWithdrawDeposit) (*MsgWithdrawDepositResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WithdrawDeposit not implemented") +} +func (*UnimplementedMsgServer) WithdrawDepositRetry(ctx context.Context, req *MsgWithdrawDepositRetry) (*MsgWithdrawDepositRetryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WithdrawDepositRetry not implemented") +} +func (*UnimplementedMsgServer) DrawRetry(ctx context.Context, req *MsgDrawRetry) (*MsgDrawRetryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DrawRetry not implemented") +} +func (*UnimplementedMsgServer) RestoreInterchainAccounts(ctx context.Context, req *MsgRestoreInterchainAccounts) (*MsgRestoreInterchainAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RestoreInterchainAccounts not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Deposit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDeposit) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Deposit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/Deposit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Deposit(ctx, req.(*MsgDeposit)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_DepositRetry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDepositRetry) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).DepositRetry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/DepositRetry", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).DepositRetry(ctx, req.(*MsgDepositRetry)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_ClaimPrize_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgClaimPrize) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ClaimPrize(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/ClaimPrize", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ClaimPrize(ctx, req.(*MsgClaimPrize)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_WithdrawDeposit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawDeposit) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WithdrawDeposit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/WithdrawDeposit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WithdrawDeposit(ctx, req.(*MsgWithdrawDeposit)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_WithdrawDepositRetry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawDepositRetry) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WithdrawDepositRetry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/WithdrawDepositRetry", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WithdrawDepositRetry(ctx, req.(*MsgWithdrawDepositRetry)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_DrawRetry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDrawRetry) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).DrawRetry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/DrawRetry", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).DrawRetry(ctx, req.(*MsgDrawRetry)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RestoreInterchainAccounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRestoreInterchainAccounts) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RestoreInterchainAccounts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lum.network.millions.Msg/RestoreInterchainAccounts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RestoreInterchainAccounts(ctx, req.(*MsgRestoreInterchainAccounts)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "lum.network.millions.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Deposit", + Handler: _Msg_Deposit_Handler, + }, + { + MethodName: "DepositRetry", + Handler: _Msg_DepositRetry_Handler, + }, + { + MethodName: "ClaimPrize", + Handler: _Msg_ClaimPrize_Handler, + }, + { + MethodName: "WithdrawDeposit", + Handler: _Msg_WithdrawDeposit_Handler, + }, + { + MethodName: "WithdrawDepositRetry", + Handler: _Msg_WithdrawDepositRetry_Handler, + }, + { + MethodName: "DrawRetry", + Handler: _Msg_DrawRetry_Handler, + }, + { + MethodName: "RestoreInterchainAccounts", + Handler: _Msg_RestoreInterchainAccounts_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lum-network/millions/tx.proto", +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UpdaterAddress) > 0 { + i -= len(m.UpdaterAddress) + copy(dAtA[i:], m.UpdaterAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.UpdaterAddress))) + i-- + dAtA[i] = 0x4a + } + if m.MinDepositDrawDelta != nil { + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.MinDepositDrawDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDepositDrawDelta):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTx(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x42 + } + if m.FeesStakers != nil { + { + size := m.FeesStakers.Size() + i -= size + if _, err := m.FeesStakers.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + if m.PrizeExpirationDelta != nil { + n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.PrizeExpirationDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.PrizeExpirationDelta):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintTx(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x32 + } + if m.MaxDrawScheduleDelta != nil { + n3, err3 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.MaxDrawScheduleDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MaxDrawScheduleDelta):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintTx(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x2a + } + if m.MinDrawScheduleDelta != nil { + n4, err4 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.MinDrawScheduleDelta, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDrawScheduleDelta):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintTx(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x22 + } + if m.MaxPrizeBatchQuantity != nil { + { + size := m.MaxPrizeBatchQuantity.Size() + i -= size + if _, err := m.MaxPrizeBatchQuantity.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.MaxPrizeStrategyBatches != nil { + { + size := m.MaxPrizeStrategyBatches.Size() + i -= size + if _, err := m.MaxPrizeStrategyBatches.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.MinDepositAmount != nil { + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgRegisterPool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRegisterPool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CreatorAddress) > 0 { + i -= len(m.CreatorAddress) + copy(dAtA[i:], m.CreatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.CreatorAddress))) + i-- + dAtA[i] = 0x5a + } + if len(m.Bech32PrefixValAddr) > 0 { + i -= len(m.Bech32PrefixValAddr) + copy(dAtA[i:], m.Bech32PrefixValAddr) + i = encodeVarintTx(dAtA, i, uint64(len(m.Bech32PrefixValAddr))) + i-- + dAtA[i] = 0x52 + } + if len(m.Bech32PrefixAccAddr) > 0 { + i -= len(m.Bech32PrefixAccAddr) + copy(dAtA[i:], m.Bech32PrefixAccAddr) + i = encodeVarintTx(dAtA, i, uint64(len(m.Bech32PrefixAccAddr))) + i-- + dAtA[i] = 0x4a + } + { + size, err := m.PrizeStrategy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + { + size, err := m.DrawSchedule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.Validators) > 0 { + for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Validators[iNdEx]) + copy(dAtA[i:], m.Validators[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validators[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x22 + } + if len(m.NativeDenom) > 0 { + i -= len(m.NativeDenom) + copy(dAtA[i:], m.NativeDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.NativeDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTx(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterPoolResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRegisterPoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdatePool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdatePool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdatePool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UpdaterAddress) > 0 { + i -= len(m.UpdaterAddress) + copy(dAtA[i:], m.UpdaterAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.UpdaterAddress))) + i-- + dAtA[i] = 0x32 + } + if m.PrizeStrategy != nil { + { + size, err := m.PrizeStrategy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.DrawSchedule != nil { + { + size, err := m.DrawSchedule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.MinDepositAmount != nil { + { + size := m.MinDepositAmount.Size() + i -= size + if _, err := m.MinDepositAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.Validators) > 0 { + for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Validators[iNdEx]) + copy(dAtA[i:], m.Validators[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validators[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdatePoolResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdatePoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdatePoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgDeposit) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDeposit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.IsSponsor { + i-- + if m.IsSponsor { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0x22 + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0x1a + } + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgDepositResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDepositResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDepositResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DepositId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgDepositRetry) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDepositRetry) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDepositRetry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0x1a + } + if m.DepositId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgDepositRetryResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDepositRetryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDepositRetryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgClaimPrize) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgClaimPrize) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgClaimPrize) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.WinnerAddress) > 0 { + i -= len(m.WinnerAddress) + copy(dAtA[i:], m.WinnerAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.WinnerAddress))) + i-- + dAtA[i] = 0x22 + } + if m.PrizeId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PrizeId)) + i-- + dAtA[i] = 0x18 + } + if m.DrawId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgClaimPrizeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgClaimPrizeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgClaimPrizeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawDeposit) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawDeposit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ToAddress) > 0 { + i -= len(m.ToAddress) + copy(dAtA[i:], m.ToAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ToAddress))) + i-- + dAtA[i] = 0x22 + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0x1a + } + if m.DepositId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawDepositResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawDepositResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawDepositResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.WithdrawalId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawDepositRetry) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawDepositRetry) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawDepositRetry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0x1a + } + if m.WithdrawalId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawDepositRetryResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawDepositRetryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawDepositRetryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgDrawRetry) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDrawRetry) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDrawRetry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DrawRetryAddress) > 0 { + i -= len(m.DrawRetryAddress) + copy(dAtA[i:], m.DrawRetryAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DrawRetryAddress))) + i-- + dAtA[i] = 0x1a + } + if m.DrawId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.DrawId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgDrawRetryResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDrawRetryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDrawRetryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgRestoreInterchainAccounts) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRestoreInterchainAccounts) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRestoreInterchainAccounts) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.RestorerAddress) > 0 { + i -= len(m.RestorerAddress) + copy(dAtA[i:], m.RestorerAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.RestorerAddress))) + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgRestoreInterchainAccountsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRestoreInterchainAccountsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRestoreInterchainAccountsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MinDepositAmount != nil { + l = m.MinDepositAmount.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.MaxPrizeStrategyBatches != nil { + l = m.MaxPrizeStrategyBatches.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.MaxPrizeBatchQuantity != nil { + l = m.MaxPrizeBatchQuantity.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.MinDrawScheduleDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDrawScheduleDelta) + n += 1 + l + sovTx(uint64(l)) + } + if m.MaxDrawScheduleDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MaxDrawScheduleDelta) + n += 1 + l + sovTx(uint64(l)) + } + if m.PrizeExpirationDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.PrizeExpirationDelta) + n += 1 + l + sovTx(uint64(l)) + } + if m.FeesStakers != nil { + l = m.FeesStakers.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.MinDepositDrawDelta != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.MinDepositDrawDelta) + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.UpdaterAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRegisterPool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.NativeDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Validators) > 0 { + for _, s := range m.Validators { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + l = m.MinDepositAmount.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.DrawSchedule.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.PrizeStrategy.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Bech32PrefixAccAddr) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Bech32PrefixValAddr) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CreatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterPoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + return n +} + +func (m *MsgUpdatePool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + if len(m.Validators) > 0 { + for _, s := range m.Validators { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if m.MinDepositAmount != nil { + l = m.MinDepositAmount.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.DrawSchedule != nil { + l = m.DrawSchedule.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.PrizeStrategy != nil { + l = m.PrizeStrategy.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.UpdaterAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdatePoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgDeposit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + l = m.Amount.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.IsSponsor { + n += 2 + } + return n +} + +func (m *MsgDepositResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.DepositId != 0 { + n += 1 + sovTx(uint64(m.DepositId)) + } + return n +} + +func (m *MsgDepositRetry) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovTx(uint64(m.DepositId)) + } + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgDepositRetryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgClaimPrize) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovTx(uint64(m.DrawId)) + } + if m.PrizeId != 0 { + n += 1 + sovTx(uint64(m.PrizeId)) + } + l = len(m.WinnerAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgClaimPrizeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgWithdrawDeposit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovTx(uint64(m.DepositId)) + } + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ToAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWithdrawDepositResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.WithdrawalId != 0 { + n += 1 + sovTx(uint64(m.WithdrawalId)) + } + return n +} + +func (m *MsgWithdrawDepositRetry) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + if m.WithdrawalId != 0 { + n += 1 + sovTx(uint64(m.WithdrawalId)) + } + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWithdrawDepositRetryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgDrawRetry) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + if m.DrawId != 0 { + n += 1 + sovTx(uint64(m.DrawId)) + } + l = len(m.DrawRetryAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgDrawRetryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRestoreInterchainAccounts) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovTx(uint64(m.PoolId)) + } + l = len(m.RestorerAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRestoreInterchainAccountsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MinDepositAmount = &v + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPrizeStrategyBatches", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MaxPrizeStrategyBatches = &v + if err := m.MaxPrizeStrategyBatches.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPrizeBatchQuantity", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MaxPrizeBatchQuantity = &v + if err := m.MaxPrizeBatchQuantity.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDrawScheduleDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MinDrawScheduleDelta == nil { + m.MinDrawScheduleDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.MinDrawScheduleDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxDrawScheduleDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MaxDrawScheduleDelta == nil { + m.MaxDrawScheduleDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.MaxDrawScheduleDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeExpirationDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PrizeExpirationDelta == nil { + m.PrizeExpirationDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.PrizeExpirationDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeesStakers", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Dec + m.FeesStakers = &v + if err := m.FeesStakers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositDrawDelta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MinDepositDrawDelta == nil { + m.MinDepositDrawDelta = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.MinDepositDrawDelta, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdaterAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UpdaterAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRegisterPool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRegisterPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NativeDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NativeDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validators = append(m.Validators, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawSchedule", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DrawSchedule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeStrategy", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PrizeStrategy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32PrefixAccAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32PrefixAccAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32PrefixValAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32PrefixValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CreatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRegisterPoolResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRegisterPoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterPoolResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdatePool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdatePool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdatePool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validators = append(m.Validators, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinDepositAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_cosmos_cosmos_sdk_types.Int + m.MinDepositAmount = &v + if err := m.MinDepositAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawSchedule", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.DrawSchedule == nil { + m.DrawSchedule = &DrawSchedule{} + } + if err := m.DrawSchedule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeStrategy", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PrizeStrategy == nil { + m.PrizeStrategy = &PrizeStrategy{} + } + if err := m.PrizeStrategy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdaterAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UpdaterAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdatePoolResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdatePoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdatePoolResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDeposit) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDeposit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDeposit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsSponsor", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsSponsor = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDepositResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDepositResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDepositResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDepositRetry) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDepositRetry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDepositRetry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDepositRetryResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDepositRetryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDepositRetryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgClaimPrize) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgClaimPrize: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgClaimPrize: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PrizeId", wireType) + } + m.PrizeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PrizeId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WinnerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WinnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgClaimPrizeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgClaimPrizeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgClaimPrizeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawDeposit) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawDeposit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawDeposit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ToAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawDepositResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawDepositResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawDepositResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawDepositRetry) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawDepositRetry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawDepositRetry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawDepositRetryResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawDepositRetryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawDepositRetryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDrawRetry) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDrawRetry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDrawRetry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawId", wireType) + } + m.DrawId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrawId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrawRetryAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DrawRetryAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDrawRetryResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDrawRetryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDrawRetryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRestoreInterchainAccounts) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRestoreInterchainAccounts: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRestoreInterchainAccounts: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RestorerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RestorerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRestoreInterchainAccountsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRestoreInterchainAccountsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRestoreInterchainAccountsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/millions/types/withdrawal.go b/x/millions/types/withdrawal.go new file mode 100644 index 00000000..4d53809f --- /dev/null +++ b/x/millions/types/withdrawal.go @@ -0,0 +1,39 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ValidateBasic validates if a withdrawal is complete and valid +func (withdrawal *Withdrawal) ValidateBasic() error { + if withdrawal.PoolId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "pool ID") + } + if withdrawal.WithdrawalId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "withdrawal ID") + } + if withdrawal.State == WithdrawalState_Unspecified { + return errorsmod.Wrapf(ErrInvalidWithdrawalState, "no state specified") + } + if _, err := sdk.AccAddressFromBech32(withdrawal.DepositorAddress); err != nil { + return errorsmod.Wrapf(ErrInvalidWithdrawalDepositorAddress, err.Error()) + } + if withdrawal.Amount.Amount.LTE(sdk.ZeroInt()) { + return ErrDepositAlreadyWithdrawn + } + + return nil +} + +// ValidateWithdrawDepositRetryBasic validates the incoming message for a withdraw deposit retry +func (msg *MsgWithdrawDepositRetry) ValidateWithdrawDepositRetryBasic() error { + if msg.PoolId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "pool ID") + } + if msg.WithdrawalId == UnknownID { + return errorsmod.Wrapf(ErrInvalidID, "withdrawal ID") + } + + return nil +} diff --git a/x/millions/types/withdrawal.pb.go b/x/millions/types/withdrawal.pb.go new file mode 100644 index 00000000..889abc3d --- /dev/null +++ b/x/millions/types/withdrawal.pb.go @@ -0,0 +1,1284 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lum-network/millions/withdrawal.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type WithdrawalState int32 + +const ( + WithdrawalState_Unspecified WithdrawalState = 0 + WithdrawalState_IcaUndelegate WithdrawalState = 1 + WithdrawalState_IcaUnbonding WithdrawalState = 2 + WithdrawalState_IbcTransfer WithdrawalState = 3 + WithdrawalState_Failure WithdrawalState = 4 +) + +var WithdrawalState_name = map[int32]string{ + 0: "WITHDRAWAL_STATE_UNSPECIFIED", + 1: "WITHDRAWAL_STATE_ICA_UNDELEGATE", + 2: "WITHDRAWAL_STATE_ICA_UNBONDING", + 3: "WITHDRAWAL_STATE_IBC_TRANSFER", + 4: "WITHDRAWAL_STATE_FAILURE", +} + +var WithdrawalState_value = map[string]int32{ + "WITHDRAWAL_STATE_UNSPECIFIED": 0, + "WITHDRAWAL_STATE_ICA_UNDELEGATE": 1, + "WITHDRAWAL_STATE_ICA_UNBONDING": 2, + "WITHDRAWAL_STATE_IBC_TRANSFER": 3, + "WITHDRAWAL_STATE_FAILURE": 4, +} + +func (x WithdrawalState) String() string { + return proto.EnumName(WithdrawalState_name, int32(x)) +} + +func (WithdrawalState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_3be8b608427654c2, []int{0} +} + +type Withdrawal struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + DepositId uint64 `protobuf:"varint,2,opt,name=deposit_id,json=depositId,proto3" json:"deposit_id,omitempty"` + WithdrawalId uint64 `protobuf:"varint,3,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` + State WithdrawalState `protobuf:"varint,4,opt,name=state,proto3,enum=lum.network.millions.WithdrawalState" json:"state,omitempty"` + ErrorState WithdrawalState `protobuf:"varint,5,opt,name=error_state,json=errorState,proto3,enum=lum.network.millions.WithdrawalState" json:"error_state,omitempty"` + DepositorAddress string `protobuf:"bytes,6,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"` + ToAddress string `protobuf:"bytes,7,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty"` + Amount types.Coin `protobuf:"bytes,8,opt,name=amount,proto3" json:"amount"` + CreatedAtHeight int64 `protobuf:"varint,9,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` + UpdatedAtHeight int64 `protobuf:"varint,10,opt,name=updated_at_height,json=updatedAtHeight,proto3" json:"updated_at_height,omitempty"` + UnbondingEndsAt *time.Time `protobuf:"bytes,11,opt,name=unbonding_ends_at,json=unbondingEndsAt,proto3,stdtime" json:"unbonding_ends_at,omitempty"` + CreatedAt time.Time `protobuf:"bytes,12,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` + UpdatedAt time.Time `protobuf:"bytes,13,opt,name=updated_at,json=updatedAt,proto3,stdtime" json:"updated_at"` +} + +func (m *Withdrawal) Reset() { *m = Withdrawal{} } +func (m *Withdrawal) String() string { return proto.CompactTextString(m) } +func (*Withdrawal) ProtoMessage() {} +func (*Withdrawal) Descriptor() ([]byte, []int) { + return fileDescriptor_3be8b608427654c2, []int{0} +} +func (m *Withdrawal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Withdrawal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Withdrawal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Withdrawal) XXX_Merge(src proto.Message) { + xxx_messageInfo_Withdrawal.Merge(m, src) +} +func (m *Withdrawal) XXX_Size() int { + return m.Size() +} +func (m *Withdrawal) XXX_DiscardUnknown() { + xxx_messageInfo_Withdrawal.DiscardUnknown(m) +} + +var xxx_messageInfo_Withdrawal proto.InternalMessageInfo + +func (m *Withdrawal) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *Withdrawal) GetDepositId() uint64 { + if m != nil { + return m.DepositId + } + return 0 +} + +func (m *Withdrawal) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +func (m *Withdrawal) GetState() WithdrawalState { + if m != nil { + return m.State + } + return WithdrawalState_Unspecified +} + +func (m *Withdrawal) GetErrorState() WithdrawalState { + if m != nil { + return m.ErrorState + } + return WithdrawalState_Unspecified +} + +func (m *Withdrawal) GetDepositorAddress() string { + if m != nil { + return m.DepositorAddress + } + return "" +} + +func (m *Withdrawal) GetToAddress() string { + if m != nil { + return m.ToAddress + } + return "" +} + +func (m *Withdrawal) GetAmount() types.Coin { + if m != nil { + return m.Amount + } + return types.Coin{} +} + +func (m *Withdrawal) GetCreatedAtHeight() int64 { + if m != nil { + return m.CreatedAtHeight + } + return 0 +} + +func (m *Withdrawal) GetUpdatedAtHeight() int64 { + if m != nil { + return m.UpdatedAtHeight + } + return 0 +} + +func (m *Withdrawal) GetUnbondingEndsAt() *time.Time { + if m != nil { + return m.UnbondingEndsAt + } + return nil +} + +func (m *Withdrawal) GetCreatedAt() time.Time { + if m != nil { + return m.CreatedAt + } + return time.Time{} +} + +func (m *Withdrawal) GetUpdatedAt() time.Time { + if m != nil { + return m.UpdatedAt + } + return time.Time{} +} + +type WithdrawalIDs struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + WithdrawalId uint64 `protobuf:"varint,2,opt,name=withdrawal_id,json=withdrawalId,proto3" json:"withdrawal_id,omitempty"` +} + +func (m *WithdrawalIDs) Reset() { *m = WithdrawalIDs{} } +func (m *WithdrawalIDs) String() string { return proto.CompactTextString(m) } +func (*WithdrawalIDs) ProtoMessage() {} +func (*WithdrawalIDs) Descriptor() ([]byte, []int) { + return fileDescriptor_3be8b608427654c2, []int{1} +} +func (m *WithdrawalIDs) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *WithdrawalIDs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_WithdrawalIDs.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *WithdrawalIDs) XXX_Merge(src proto.Message) { + xxx_messageInfo_WithdrawalIDs.Merge(m, src) +} +func (m *WithdrawalIDs) XXX_Size() int { + return m.Size() +} +func (m *WithdrawalIDs) XXX_DiscardUnknown() { + xxx_messageInfo_WithdrawalIDs.DiscardUnknown(m) +} + +var xxx_messageInfo_WithdrawalIDs proto.InternalMessageInfo + +func (m *WithdrawalIDs) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *WithdrawalIDs) GetWithdrawalId() uint64 { + if m != nil { + return m.WithdrawalId + } + return 0 +} + +type WithdrawalIDsCollection struct { + WithdrawalsIds []WithdrawalIDs `protobuf:"bytes,1,rep,name=withdrawals_ids,json=withdrawalsIds,proto3" json:"withdrawals_ids"` +} + +func (m *WithdrawalIDsCollection) Reset() { *m = WithdrawalIDsCollection{} } +func (m *WithdrawalIDsCollection) String() string { return proto.CompactTextString(m) } +func (*WithdrawalIDsCollection) ProtoMessage() {} +func (*WithdrawalIDsCollection) Descriptor() ([]byte, []int) { + return fileDescriptor_3be8b608427654c2, []int{2} +} +func (m *WithdrawalIDsCollection) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *WithdrawalIDsCollection) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_WithdrawalIDsCollection.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *WithdrawalIDsCollection) XXX_Merge(src proto.Message) { + xxx_messageInfo_WithdrawalIDsCollection.Merge(m, src) +} +func (m *WithdrawalIDsCollection) XXX_Size() int { + return m.Size() +} +func (m *WithdrawalIDsCollection) XXX_DiscardUnknown() { + xxx_messageInfo_WithdrawalIDsCollection.DiscardUnknown(m) +} + +var xxx_messageInfo_WithdrawalIDsCollection proto.InternalMessageInfo + +func (m *WithdrawalIDsCollection) GetWithdrawalsIds() []WithdrawalIDs { + if m != nil { + return m.WithdrawalsIds + } + return nil +} + +func init() { + proto.RegisterEnum("lum.network.millions.WithdrawalState", WithdrawalState_name, WithdrawalState_value) + proto.RegisterType((*Withdrawal)(nil), "lum.network.millions.Withdrawal") + proto.RegisterType((*WithdrawalIDs)(nil), "lum.network.millions.WithdrawalIDs") + proto.RegisterType((*WithdrawalIDsCollection)(nil), "lum.network.millions.WithdrawalIDsCollection") +} + +func init() { + proto.RegisterFile("lum-network/millions/withdrawal.proto", fileDescriptor_3be8b608427654c2) +} + +var fileDescriptor_3be8b608427654c2 = []byte{ + // 764 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6a, 0xe3, 0x46, + 0x18, 0xb7, 0x6c, 0xc7, 0x59, 0x8f, 0xe3, 0xb5, 0x2d, 0x02, 0xab, 0x15, 0x5d, 0x59, 0x64, 0x59, + 0x70, 0x17, 0x22, 0x11, 0xb7, 0xb4, 0x87, 0x9e, 0x64, 0x5b, 0xce, 0x0a, 0x52, 0x77, 0x91, 0x6d, + 0x02, 0xbd, 0x08, 0x59, 0x33, 0x91, 0x87, 0x4a, 0x33, 0x46, 0x33, 0x6a, 0xda, 0x37, 0x28, 0x3e, + 0xed, 0xad, 0x27, 0x9f, 0xfa, 0x0a, 0x7d, 0x88, 0x1c, 0x97, 0x9e, 0x0a, 0x85, 0x6d, 0x49, 0x5e, + 0xa4, 0xe8, 0x4f, 0xac, 0x6d, 0xdc, 0x90, 0xcd, 0x4d, 0xf3, 0xfd, 0xfe, 0xe8, 0xfb, 0xe6, 0xfb, + 0x31, 0xe0, 0x55, 0x10, 0x87, 0xc7, 0x04, 0xf1, 0x4b, 0x1a, 0xfd, 0xa0, 0x87, 0x38, 0x08, 0x30, + 0x25, 0x4c, 0xbf, 0xc4, 0x7c, 0x09, 0x23, 0xf7, 0xd2, 0x0d, 0xb4, 0x55, 0x44, 0x39, 0x15, 0x0f, + 0x83, 0x38, 0xd4, 0x72, 0x9a, 0x76, 0x4b, 0x93, 0x0f, 0x7d, 0xea, 0xd3, 0x94, 0xa0, 0x27, 0x5f, + 0x19, 0x57, 0xee, 0xfa, 0x94, 0xfa, 0x01, 0xd2, 0xd3, 0xd3, 0x22, 0xbe, 0xd0, 0x39, 0x0e, 0x11, + 0xe3, 0x6e, 0xb8, 0xca, 0x09, 0x8a, 0x47, 0x59, 0x48, 0x99, 0xbe, 0x70, 0x19, 0xd2, 0x7f, 0x3c, + 0x59, 0x20, 0xee, 0x9e, 0xe8, 0x1e, 0xc5, 0x24, 0xc7, 0x9f, 0x67, 0xb8, 0x93, 0x39, 0x67, 0x87, + 0x0c, 0x3a, 0xfa, 0x6b, 0x0f, 0x80, 0xf3, 0x6d, 0x73, 0xe2, 0x33, 0xb0, 0xbf, 0xa2, 0x34, 0x70, + 0x30, 0x94, 0x04, 0x55, 0xe8, 0x55, 0xed, 0x5a, 0x72, 0xb4, 0xa0, 0xf8, 0x02, 0x00, 0x88, 0x56, + 0x94, 0x61, 0x9e, 0x60, 0xe5, 0x14, 0xab, 0xe7, 0x15, 0x0b, 0x8a, 0x2f, 0x41, 0xb3, 0x18, 0x31, + 0x61, 0x54, 0x52, 0xc6, 0x41, 0x51, 0xb4, 0xa0, 0xf8, 0x0d, 0xd8, 0x63, 0xdc, 0xe5, 0x48, 0xaa, + 0xaa, 0x42, 0xef, 0x69, 0xff, 0x95, 0xf6, 0x7f, 0x77, 0xa0, 0x15, 0xdd, 0x4c, 0x13, 0xb2, 0x9d, + 0x69, 0xc4, 0x31, 0x68, 0xa0, 0x28, 0xa2, 0x91, 0x93, 0x59, 0xec, 0x3d, 0xc6, 0x02, 0xa4, 0xca, + 0xf4, 0x5b, 0x34, 0x41, 0x27, 0x6f, 0x9b, 0x46, 0x8e, 0x0b, 0x61, 0x84, 0x18, 0x93, 0x6a, 0xaa, + 0xd0, 0xab, 0x0f, 0xa4, 0x3f, 0x7e, 0x3f, 0x3e, 0xcc, 0x6f, 0xc7, 0xc8, 0x90, 0x29, 0x8f, 0x30, + 0xf1, 0xed, 0xf6, 0x56, 0x92, 0xd7, 0xc5, 0xaf, 0x01, 0xe0, 0x74, 0xab, 0xdf, 0x7f, 0x40, 0x5f, + 0xe7, 0xb4, 0x10, 0xd6, 0xdc, 0x90, 0xc6, 0x84, 0x4b, 0x4f, 0x54, 0xa1, 0xd7, 0xe8, 0x3f, 0xd7, + 0x72, 0x45, 0xb2, 0x3c, 0x2d, 0x5f, 0x9e, 0x36, 0xa4, 0x98, 0x0c, 0xaa, 0x57, 0x1f, 0xba, 0x25, + 0x3b, 0xa7, 0x8b, 0xaf, 0x41, 0xc7, 0x8b, 0x90, 0xcb, 0x11, 0x74, 0x5c, 0xee, 0x2c, 0x11, 0xf6, + 0x97, 0x5c, 0xaa, 0xab, 0x42, 0xaf, 0x62, 0xb7, 0x72, 0xc0, 0xe0, 0x6f, 0xd2, 0x72, 0xc2, 0x8d, + 0x57, 0xf0, 0x0e, 0x17, 0x64, 0xdc, 0x1c, 0xd8, 0x72, 0xdf, 0x82, 0x4e, 0x4c, 0x16, 0x94, 0x40, + 0x4c, 0x7c, 0x07, 0x11, 0xc8, 0x1c, 0x97, 0x4b, 0x8d, 0xb4, 0x37, 0x59, 0xcb, 0x92, 0xa7, 0xdd, + 0x26, 0x4f, 0x9b, 0xdd, 0x26, 0x6f, 0xf0, 0xe4, 0xea, 0x43, 0x57, 0x78, 0xf7, 0x77, 0x57, 0xb0, + 0x5b, 0x5b, 0xb9, 0x49, 0x20, 0x33, 0xb8, 0x38, 0x04, 0xa0, 0xe8, 0x54, 0x3a, 0xf8, 0x24, 0xab, + 0x52, 0x6a, 0x55, 0xdf, 0x0e, 0x92, 0x98, 0x14, 0x23, 0x48, 0xcd, 0xc7, 0x98, 0x6c, 0x27, 0x3c, + 0xfa, 0x16, 0x34, 0x8b, 0x2c, 0x58, 0x23, 0x76, 0x7f, 0xbe, 0x77, 0x02, 0x5c, 0xde, 0x0d, 0xf0, + 0x51, 0x08, 0x9e, 0xfd, 0xc7, 0x6e, 0x48, 0x83, 0x00, 0x79, 0x1c, 0x53, 0x22, 0xda, 0xa0, 0x55, + 0x50, 0x99, 0x83, 0x21, 0x93, 0x04, 0xb5, 0xd2, 0x6b, 0xf4, 0x5f, 0x3e, 0x14, 0x51, 0x6b, 0xc4, + 0xf2, 0x4d, 0x3f, 0xfd, 0xc8, 0xc1, 0x82, 0xec, 0xf5, 0xaf, 0x65, 0xd0, 0xba, 0x13, 0x65, 0xf1, + 0x04, 0x7c, 0x76, 0x6e, 0xcd, 0xde, 0x8c, 0x6c, 0xe3, 0xdc, 0x38, 0x73, 0xa6, 0x33, 0x63, 0x66, + 0x3a, 0xf3, 0xc9, 0xf4, 0xad, 0x39, 0xb4, 0xc6, 0x96, 0x39, 0x6a, 0x97, 0xe4, 0xd6, 0x7a, 0xa3, + 0x36, 0xe6, 0x84, 0xad, 0x90, 0x87, 0x2f, 0x30, 0x82, 0xe2, 0x57, 0xa0, 0xbb, 0x23, 0xb1, 0x86, + 0x86, 0x33, 0x9f, 0x8c, 0xcc, 0x33, 0xf3, 0xd4, 0x98, 0x99, 0x6d, 0x41, 0xee, 0xac, 0x37, 0x6a, + 0xd3, 0xf2, 0xdc, 0x39, 0x81, 0x28, 0x40, 0x7e, 0xf2, 0xab, 0x2f, 0x81, 0x72, 0x8f, 0x6e, 0xf0, + 0xdd, 0x64, 0x64, 0x4d, 0x4e, 0xdb, 0x65, 0xb9, 0xbd, 0xde, 0xa8, 0x07, 0xa9, 0x2c, 0x8f, 0x80, + 0xd8, 0x07, 0x2f, 0x76, 0x55, 0x83, 0xa1, 0x33, 0xb3, 0x8d, 0xc9, 0x74, 0x6c, 0xda, 0xed, 0x4a, + 0xd6, 0xa1, 0xb5, 0xf0, 0x66, 0x91, 0x4b, 0xd8, 0x05, 0x8a, 0xc4, 0xcf, 0x81, 0xb4, 0xa3, 0x19, + 0x1b, 0xd6, 0xd9, 0xdc, 0x36, 0xdb, 0x55, 0xb9, 0xb1, 0xde, 0xa8, 0xfb, 0x63, 0x17, 0x07, 0x71, + 0x84, 0xe4, 0xea, 0x2f, 0xbf, 0x29, 0xc2, 0xe0, 0xf4, 0xea, 0x5a, 0x11, 0xde, 0x5f, 0x2b, 0xc2, + 0x3f, 0xd7, 0x8a, 0xf0, 0xee, 0x46, 0x29, 0xbd, 0xbf, 0x51, 0x4a, 0x7f, 0xde, 0x28, 0xa5, 0xef, + 0x8f, 0x7d, 0xcc, 0x97, 0xf1, 0x42, 0xf3, 0x68, 0xa8, 0x7f, 0xfc, 0x12, 0x7b, 0x4b, 0x17, 0x13, + 0xfd, 0xa7, 0xe2, 0x45, 0xe6, 0x3f, 0xaf, 0x10, 0x5b, 0xd4, 0xd2, 0x24, 0x7d, 0xf1, 0x6f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xd6, 0x41, 0x9b, 0xbc, 0xb6, 0x05, 0x00, 0x00, +} + +func (m *Withdrawal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Withdrawal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Withdrawal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpdatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintWithdrawal(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x6a + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintWithdrawal(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x62 + if m.UnbondingEndsAt != nil { + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.UnbondingEndsAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(*m.UnbondingEndsAt):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintWithdrawal(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x5a + } + if m.UpdatedAtHeight != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.UpdatedAtHeight)) + i-- + dAtA[i] = 0x50 + } + if m.CreatedAtHeight != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.CreatedAtHeight)) + i-- + dAtA[i] = 0x48 + } + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintWithdrawal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + if len(m.ToAddress) > 0 { + i -= len(m.ToAddress) + copy(dAtA[i:], m.ToAddress) + i = encodeVarintWithdrawal(dAtA, i, uint64(len(m.ToAddress))) + i-- + dAtA[i] = 0x3a + } + if len(m.DepositorAddress) > 0 { + i -= len(m.DepositorAddress) + copy(dAtA[i:], m.DepositorAddress) + i = encodeVarintWithdrawal(dAtA, i, uint64(len(m.DepositorAddress))) + i-- + dAtA[i] = 0x32 + } + if m.ErrorState != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.ErrorState)) + i-- + dAtA[i] = 0x28 + } + if m.State != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.State)) + i-- + dAtA[i] = 0x20 + } + if m.WithdrawalId != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x18 + } + if m.DepositId != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.DepositId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *WithdrawalIDs) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *WithdrawalIDs) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *WithdrawalIDs) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.WithdrawalId != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.WithdrawalId)) + i-- + dAtA[i] = 0x10 + } + if m.PoolId != 0 { + i = encodeVarintWithdrawal(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *WithdrawalIDsCollection) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *WithdrawalIDsCollection) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *WithdrawalIDsCollection) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.WithdrawalsIds) > 0 { + for iNdEx := len(m.WithdrawalsIds) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.WithdrawalsIds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintWithdrawal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintWithdrawal(dAtA []byte, offset int, v uint64) int { + offset -= sovWithdrawal(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Withdrawal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovWithdrawal(uint64(m.PoolId)) + } + if m.DepositId != 0 { + n += 1 + sovWithdrawal(uint64(m.DepositId)) + } + if m.WithdrawalId != 0 { + n += 1 + sovWithdrawal(uint64(m.WithdrawalId)) + } + if m.State != 0 { + n += 1 + sovWithdrawal(uint64(m.State)) + } + if m.ErrorState != 0 { + n += 1 + sovWithdrawal(uint64(m.ErrorState)) + } + l = len(m.DepositorAddress) + if l > 0 { + n += 1 + l + sovWithdrawal(uint64(l)) + } + l = len(m.ToAddress) + if l > 0 { + n += 1 + l + sovWithdrawal(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovWithdrawal(uint64(l)) + if m.CreatedAtHeight != 0 { + n += 1 + sovWithdrawal(uint64(m.CreatedAtHeight)) + } + if m.UpdatedAtHeight != 0 { + n += 1 + sovWithdrawal(uint64(m.UpdatedAtHeight)) + } + if m.UnbondingEndsAt != nil { + l = github_com_gogo_protobuf_types.SizeOfStdTime(*m.UnbondingEndsAt) + n += 1 + l + sovWithdrawal(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) + n += 1 + l + sovWithdrawal(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt) + n += 1 + l + sovWithdrawal(uint64(l)) + return n +} + +func (m *WithdrawalIDs) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovWithdrawal(uint64(m.PoolId)) + } + if m.WithdrawalId != 0 { + n += 1 + sovWithdrawal(uint64(m.WithdrawalId)) + } + return n +} + +func (m *WithdrawalIDsCollection) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.WithdrawalsIds) > 0 { + for _, e := range m.WithdrawalsIds { + l = e.Size() + n += 1 + l + sovWithdrawal(uint64(l)) + } + } + return n +} + +func sovWithdrawal(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozWithdrawal(x uint64) (n int) { + return sovWithdrawal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Withdrawal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Withdrawal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Withdrawal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositId", wireType) + } + m.DepositId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DepositId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + m.State = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.State |= WithdrawalState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ErrorState", wireType) + } + m.ErrorState = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ErrorState |= WithdrawalState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DepositorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ToAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) + } + m.CreatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAtHeight", wireType) + } + m.UpdatedAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatedAtHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UnbondingEndsAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.UnbondingEndsAt == nil { + m.UnbondingEndsAt = new(time.Time) + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(m.UnbondingEndsAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.UpdatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWithdrawal(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthWithdrawal + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthWithdrawal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *WithdrawalIDs) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: WithdrawalIDs: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: WithdrawalIDs: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalId", wireType) + } + m.WithdrawalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipWithdrawal(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthWithdrawal + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthWithdrawal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *WithdrawalIDsCollection) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: WithdrawalIDsCollection: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: WithdrawalIDsCollection: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalsIds", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWithdrawal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWithdrawal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WithdrawalsIds = append(m.WithdrawalsIds, WithdrawalIDs{}) + if err := m.WithdrawalsIds[len(m.WithdrawalsIds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWithdrawal(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthWithdrawal + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthWithdrawal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipWithdrawal(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWithdrawal + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthWithdrawal + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupWithdrawal + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthWithdrawal + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthWithdrawal = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowWithdrawal = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupWithdrawal = fmt.Errorf("proto: unexpected end of group") +)