From 371cc9c946eb3e6e8bf9909785fdae7c71c74fad Mon Sep 17 00:00:00 2001 From: Michael Tsitrin Date: Wed, 15 Jan 2025 11:23:00 +0200 Subject: [PATCH] moved common code to utils --- go.mod | 2 - go.sum | 39 ++++++++-- utils/ukeys/keys.go | 46 ++++++++++++ .../keeper => utils/ukeys}/utils_test.go | 23 +++--- .../client/cli/tx_create_denommetadata.go | 6 +- .../client/cli/tx_update_denommetadata.go | 6 +- x/dymns/client/cli/tx_gov.go | 6 +- x/incentives/keeper/gauge.go | 17 ++--- x/incentives/keeper/gauge_rollapp.go | 3 +- x/incentives/keeper/iterator.go | 5 +- x/incentives/keeper/store.go | 5 +- x/incentives/keeper/utils.go | 62 ---------------- x/incentives/keeper/utils_test.go | 72 ------------------- x/rollapp/client/cli/tx_create_rollapp.go | 6 +- x/sequencer/client/cli/tx.go | 6 +- x/sequencer/client/cli/tx_punish_sequencer.go | 3 +- x/sequencer/types/keys.go | 3 +- x/streamer/client/cli/tx_create_stream.go | 4 +- .../client/cli/tx_replace_distribution.go | 4 +- x/streamer/client/cli/tx_terminate_stream.go | 4 +- .../client/cli/tx_update_distribution.go | 4 +- x/streamer/keeper/keeper.go | 3 +- x/streamer/keeper/store.go | 9 +-- x/streamer/keeper/stream.go | 9 +-- x/streamer/keeper/utils.go | 60 ---------------- 25 files changed, 146 insertions(+), 261 deletions(-) rename {x/streamer/keeper => utils/ukeys}/utils_test.go (76%) delete mode 100644 x/incentives/keeper/utils.go delete mode 100644 x/incentives/keeper/utils_test.go delete mode 100644 x/streamer/keeper/utils.go diff --git a/go.mod b/go.mod index 9f1c5f451..d8af1ebb6 100644 --- a/go.mod +++ b/go.mod @@ -228,7 +228,6 @@ require ( golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect - golang.org/x/tools v0.18.0 // indirect google.golang.org/api v0.169.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect @@ -252,5 +251,4 @@ replace ( // broken goleveldb github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 - golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb ) diff --git a/go.sum b/go.sum index 3254d4286..f777fc20d 100644 --- a/go.sum +++ b/go.sum @@ -206,6 +206,7 @@ cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d h1:E/8y0oG3u9hBR8l4F9MtC0 cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d/go.mod h1:xbjky3L3DJEylaho6gXplkrMvJ5sFgv+qNX+Nn47bzY= cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw= cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -221,6 +222,7 @@ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= @@ -566,6 +568,9 @@ github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1T github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= @@ -1363,12 +1368,27 @@ golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us= -golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1381,16 +1401,18 @@ golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1515,6 +1537,7 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1527,6 +1550,7 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1645,6 +1669,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -1653,7 +1678,9 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -1669,6 +1696,7 @@ golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -1696,7 +1724,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/utils/ukeys/keys.go b/utils/ukeys/keys.go index de2e722ae..265b9e663 100644 --- a/utils/ukeys/keys.go +++ b/utils/ukeys/keys.go @@ -1,9 +1,11 @@ package ukeys import ( + "bytes" "time" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dymensionxyz/dymension/v3/x/lockup/types" ) // EncodeTimeToKey combines a given byte slice (queueKey) with an encoded representation of a specified time (endTime). @@ -33,3 +35,47 @@ func EncodeTimeToKey(queueKey []byte, endTime time.Time) []byte { copy(bz[prefixL:], timeBz) return bz } + +// GetTimeKey returns the time key used when getting a set of streams. +func GetTimeKey(timestamp time.Time) []byte { + timeBz := sdk.FormatTimeBytes(timestamp) + timeBzL := len(timeBz) + prefixL := len(types.KeyPrefixTimestamp) + + bz := make([]byte, prefixL+8+timeBzL) + + // copy the prefix + copy(bz[:prefixL], types.KeyPrefixTimestamp) + + // copy the encoded time bytes length + copy(bz[prefixL:prefixL+8], sdk.Uint64ToBigEndian(uint64(timeBzL))) + + // copy the encoded time bytes + copy(bz[prefixL+8:prefixL+8+timeBzL], timeBz) + return bz +} + +// FindIndex takes an array of IDs. Then return the index of a specific ID. +func FindIndex(IDs []uint64, ID uint64) int { + for index, id := range IDs { + if id == ID { + return index + } + } + return -1 +} + +// RemoveValue takes an array of IDs. Then finds the index of the IDs and remove those IDs from the array. +func RemoveValue(IDs []uint64, ID uint64) ([]uint64, int) { + index := FindIndex(IDs, ID) + if index < 0 { + return IDs, index + } + IDs[index] = IDs[len(IDs)-1] // set last element to index + return IDs[:len(IDs)-1], index +} + +// CombineKeys combine bytes array into a single bytes. +func CombineKeys(keys ...[]byte) []byte { + return bytes.Join(keys, types.KeyIndexSeparator) +} diff --git a/x/streamer/keeper/utils_test.go b/utils/ukeys/utils_test.go similarity index 76% rename from x/streamer/keeper/utils_test.go rename to utils/ukeys/utils_test.go index 96376f0f4..3c4b713ae 100644 --- a/x/streamer/keeper/utils_test.go +++ b/utils/ukeys/utils_test.go @@ -1,4 +1,4 @@ -package keeper +package ukeys_test import ( "bytes" @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/streamer/types" ) @@ -18,7 +19,7 @@ func TestCombineKeys(t *testing.T) { key3 := []byte{0x13} // combine the three keys into a single key - key := combineKeys(key1, key2, key3) + key := ukeys.CombineKeys(key1, key2, key3) // three keys plus two separators is equal to a length of 5 require.Len(t, key, 3+2) @@ -37,10 +38,10 @@ func TestFindIndex(t *testing.T) { // use the findIndex function to find the index of the respective IDs // if it doesn't exist, return -1 - require.Equal(t, findIndex(IDs, 1), 0) - require.Equal(t, findIndex(IDs, 3), 2) - require.Equal(t, findIndex(IDs, 5), 4) - require.Equal(t, findIndex(IDs, 6), -1) + require.Equal(t, ukeys.FindIndex(IDs, 1), 0) + require.Equal(t, ukeys.FindIndex(IDs, 3), 2) + require.Equal(t, ukeys.FindIndex(IDs, 5), 4) + require.Equal(t, ukeys.FindIndex(IDs, 6), -1) } func TestRemoveValue(t *testing.T) { @@ -49,23 +50,23 @@ func TestRemoveValue(t *testing.T) { // remove an ID // ensure if ID exists, the length is reduced by one and the index of the removed ID is returned - IDs, index1 := removeValue(IDs, 5) + IDs, index1 := ukeys.RemoveValue(IDs, 5) require.Len(t, IDs, 4) require.Equal(t, index1, 4) - IDs, index2 := removeValue(IDs, 3) + IDs, index2 := ukeys.RemoveValue(IDs, 3) require.Len(t, IDs, 3) require.Equal(t, index2, 2) - IDs, index3 := removeValue(IDs, 1) + IDs, index3 := ukeys.RemoveValue(IDs, 1) require.Len(t, IDs, 2) require.Equal(t, index3, 0) - IDs, index4 := removeValue(IDs, 6) + IDs, index4 := ukeys.RemoveValue(IDs, 6) require.Len(t, IDs, 2) require.Equal(t, index4, -1) } func TestGetTimeKey(t *testing.T) { now := time.Now() - timeKey := getTimeKey(now) + timeKey := ukeys.GetTimeKey(now) require.True(t, bytes.HasPrefix(timeKey, types.KeyPrefixTimestamp)) require.True(t, bytes.HasSuffix(timeKey, sdk.FormatTimeBytes(now))) } diff --git a/x/denommetadata/client/cli/tx_create_denommetadata.go b/x/denommetadata/client/cli/tx_create_denommetadata.go index 4b3fe8969..47c53e39e 100644 --- a/x/denommetadata/client/cli/tx_create_denommetadata.go +++ b/x/denommetadata/client/cli/tx_create_denommetadata.go @@ -8,7 +8,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/spf13/cobra" - utils "github.com/dymensionxyz/dymension/v3/utils/ucli" + "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/denommetadata/types" ) @@ -25,7 +25,7 @@ func NewCmdSubmitCreateDenomMetadataProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } @@ -33,7 +33,7 @@ func NewCmdSubmitCreateDenomMetadataProposal() *cobra.Command { path := args[0] var metadatas []banktypes.Metadata - err = utils.ParseJsonFromFile(path, &metadatas) + err = ucli.ParseJsonFromFile(path, &metadatas) if err != nil { return err } diff --git a/x/denommetadata/client/cli/tx_update_denommetadata.go b/x/denommetadata/client/cli/tx_update_denommetadata.go index 322fbcc76..01ba12f7d 100644 --- a/x/denommetadata/client/cli/tx_update_denommetadata.go +++ b/x/denommetadata/client/cli/tx_update_denommetadata.go @@ -8,7 +8,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/spf13/cobra" - utils "github.com/dymensionxyz/dymension/v3/utils/ucli" + "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/denommetadata/types" ) @@ -25,7 +25,7 @@ func NewCmdSubmitUpdateDenomMetadataProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } @@ -33,7 +33,7 @@ func NewCmdSubmitUpdateDenomMetadataProposal() *cobra.Command { path := args[0] var metadatas []banktypes.Metadata - err = utils.ParseJsonFromFile(path, &metadatas) + err = ucli.ParseJsonFromFile(path, &metadatas) if err != nil { return err } diff --git a/x/dymns/client/cli/tx_gov.go b/x/dymns/client/cli/tx_gov.go index aab09fc62..1f81728a2 100644 --- a/x/dymns/client/cli/tx_gov.go +++ b/x/dymns/client/cli/tx_gov.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/dymensionxyz/dymension/v3/app/params" - utils "github.com/dymensionxyz/dymension/v3/utils/ucli" + "github.com/dymensionxyz/dymension/v3/utils/ucli" dymnstypes "github.com/dymensionxyz/dymension/v3/x/dymns/types" "github.com/spf13/cobra" ) @@ -196,7 +196,7 @@ Sample proposal file content: func parseMigrateChainIdsProposal(metadataFile string) (*dymnstypes.MigrateChainIdsProposal, error) { var proposal dymnstypes.MigrateChainIdsProposal - err := utils.ParseJsonFromFile(metadataFile, &proposal) + err := ucli.ParseJsonFromFile(metadataFile, &proposal) if err != nil { return nil, err } @@ -208,7 +208,7 @@ func parseMigrateChainIdsProposal(metadataFile string) (*dymnstypes.MigrateChain func parseUpdateAliasesProposal(metadataFile string) (*dymnstypes.UpdateAliasesProposal, error) { var proposal dymnstypes.UpdateAliasesProposal - err := utils.ParseJsonFromFile(metadataFile, &proposal) + err := ucli.ParseJsonFromFile(metadataFile, &proposal) if err != nil { return nil, err } diff --git a/x/incentives/keeper/gauge.go b/x/incentives/keeper/gauge.go index 967c8b4d9..792c7086b 100644 --- a/x/incentives/keeper/gauge.go +++ b/x/incentives/keeper/gauge.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/incentives/types" lockuptypes "github.com/dymensionxyz/dymension/v3/x/lockup/types" ) @@ -77,13 +78,13 @@ func (k Keeper) SetGaugeWithRefKey(ctx sdk.Context, gauge *types.Gauge) error { activeOrUpcomingGauge := gauge.IsActiveGauge(curTime) || gauge.IsUpcomingGauge(curTime) if gauge.IsUpcomingGauge(curTime) { - combinedKeys := combineKeys(types.KeyPrefixUpcomingGauges, timeKey) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixUpcomingGauges, timeKey) return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys, activeOrUpcomingGauge) } else if gauge.IsActiveGauge(curTime) { - combinedKeys := combineKeys(types.KeyPrefixActiveGauges, timeKey) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixActiveGauges, timeKey) return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys, activeOrUpcomingGauge) } else { - combinedKeys := combineKeys(types.KeyPrefixFinishedGauges, timeKey) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixFinishedGauges, timeKey) return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys, activeOrUpcomingGauge) } } @@ -122,7 +123,7 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr } k.SetLastGaugeID(ctx, gauge.Id) - combinedKeys := combineKeys(types.KeyPrefixUpcomingGauges, getTimeKey(gauge.StartTime)) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixUpcomingGauges, getTimeKey(gauge.StartTime)) activeOrUpcomingGauge := true err = k.CreateGaugeRefKeys(ctx, &gauge, combinedKeys, activeOrUpcomingGauge) @@ -224,10 +225,10 @@ func (k Keeper) moveUpcomingGaugeToActiveGauge(ctx sdk.Context, gauge types.Gaug } timeKey := getTimeKey(gauge.StartTime) - if err := k.deleteGaugeRefByKey(ctx, combineKeys(types.KeyPrefixUpcomingGauges, timeKey), gauge.Id); err != nil { + if err := k.deleteGaugeRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixUpcomingGauges, timeKey), gauge.Id); err != nil { return err } - if err := k.addGaugeRefByKey(ctx, combineKeys(types.KeyPrefixActiveGauges, timeKey), gauge.Id); err != nil { + if err := k.addGaugeRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixActiveGauges, timeKey), gauge.Id); err != nil { return err } return nil @@ -236,10 +237,10 @@ func (k Keeper) moveUpcomingGaugeToActiveGauge(ctx sdk.Context, gauge types.Gaug // moveActiveGaugeToFinishedGauge moves a gauge that has completed its distribution from an active to a finished status. func (k Keeper) moveActiveGaugeToFinishedGauge(ctx sdk.Context, gauge types.Gauge) error { timeKey := getTimeKey(gauge.StartTime) - if err := k.deleteGaugeRefByKey(ctx, combineKeys(types.KeyPrefixActiveGauges, timeKey), gauge.Id); err != nil { + if err := k.deleteGaugeRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixActiveGauges, timeKey), gauge.Id); err != nil { return err } - if err := k.addGaugeRefByKey(ctx, combineKeys(types.KeyPrefixFinishedGauges, timeKey), gauge.Id); err != nil { + if err := k.addGaugeRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixFinishedGauges, timeKey), gauge.Id); err != nil { return err } diff --git a/x/incentives/keeper/gauge_rollapp.go b/x/incentives/keeper/gauge_rollapp.go index aa9229c1e..73c95df00 100644 --- a/x/incentives/keeper/gauge_rollapp.go +++ b/x/incentives/keeper/gauge_rollapp.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/incentives/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,7 +25,7 @@ func (k Keeper) CreateRollappGauge(ctx sdk.Context, rollappId string) (uint64, e } k.SetLastGaugeID(ctx, gauge.Id) - combinedKeys := combineKeys(types.KeyPrefixUpcomingGauges, getTimeKey(gauge.StartTime)) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixUpcomingGauges, getTimeKey(gauge.StartTime)) err = k.CreateGaugeRefKeys(ctx, &gauge, combinedKeys, true) if err != nil { return 0, err diff --git a/x/incentives/keeper/iterator.go b/x/incentives/keeper/iterator.go index cfb1f4c2a..31d4e659d 100644 --- a/x/incentives/keeper/iterator.go +++ b/x/incentives/keeper/iterator.go @@ -6,6 +6,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/incentives/types" lockuptypes "github.com/dymensionxyz/dymension/v3/x/lockup/types" ) @@ -14,7 +15,7 @@ import ( func (k Keeper) iteratorAfterTime(ctx sdk.Context, prefix []byte, time time.Time) sdk.Iterator { store := ctx.KVStore(k.storeKey) timeKey := getTimeKey(time) - key := combineKeys(prefix, timeKey) + key := ukeys.CombineKeys(prefix, timeKey) return store.Iterator(storetypes.InclusiveEndBytes(key), storetypes.PrefixEndBytes(prefix)) } @@ -22,7 +23,7 @@ func (k Keeper) iteratorAfterTime(ctx sdk.Context, prefix []byte, time time.Time func (k Keeper) iteratorBeforeTime(ctx sdk.Context, prefix []byte, time time.Time) sdk.Iterator { store := ctx.KVStore(k.storeKey) timeKey := getTimeKey(time) - key := combineKeys(prefix, timeKey) + key := ukeys.CombineKeys(prefix, timeKey) return store.Iterator(prefix, storetypes.InclusiveEndBytes(key)) } diff --git a/x/incentives/keeper/store.go b/x/incentives/keeper/store.go index 402a59953..b8b3dd55f 100644 --- a/x/incentives/keeper/store.go +++ b/x/incentives/keeper/store.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/incentives/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,12 +30,12 @@ func (k Keeper) SetLastGaugeID(ctx sdk.Context, ID uint64) { // gaugeStoreKey returns the combined byte array (store key) of the provided gauge ID's key prefix and the ID itself. func gaugeStoreKey(ID uint64) []byte { - return combineKeys(types.KeyPrefixPeriodGauge, sdk.Uint64ToBigEndian(ID)) + return ukeys.CombineKeys(types.KeyPrefixPeriodGauge, sdk.Uint64ToBigEndian(ID)) } // gaugeDenomStoreKey returns the combined byte array (store key) of the provided gauge denom key prefix and the denom itself. func gaugeDenomStoreKey(denom string) []byte { - return combineKeys(types.KeyPrefixGaugesByDenom, []byte(denom)) + return ukeys.CombineKeys(types.KeyPrefixGaugesByDenom, []byte(denom)) } // getGaugeRefs returns the gauge IDs specified by the provided key. diff --git a/x/incentives/keeper/utils.go b/x/incentives/keeper/utils.go deleted file mode 100644 index 851bc8674..000000000 --- a/x/incentives/keeper/utils.go +++ /dev/null @@ -1,62 +0,0 @@ -package keeper - -import ( - "time" - - "github.com/dymensionxyz/dymension/v3/x/incentives/types" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// TODO: move to common utils package - -// findIndex takes an array of IDs. Then return the index of a specific ID. -func findIndex(IDs []uint64, ID uint64) int { - for index, id := range IDs { - if id == ID { - return index - } - } - return -1 -} - -// removeValue takes an array of IDs. Then finds the index of the IDs and remove those IDs from the array. -func removeValue(IDs []uint64, ID uint64) ([]uint64, int) { - index := findIndex(IDs, ID) - if index < 0 { - return IDs, index - } - IDs[index] = IDs[len(IDs)-1] // set last element to index - return IDs[:len(IDs)-1], index -} - -// getTimeKey returns the time key used when getting a set of gauges. -func getTimeKey(timestamp time.Time) []byte { - timeBz := sdk.FormatTimeBytes(timestamp) - timeBzL := len(timeBz) - prefixL := len(types.KeyPrefixTimestamp) - - bz := make([]byte, prefixL+8+timeBzL) - - // copy the prefix - copy(bz[:prefixL], types.KeyPrefixTimestamp) - - // copy the encoded time bytes length - copy(bz[prefixL:prefixL+8], sdk.Uint64ToBigEndian(uint64(timeBzL))) - - // copy the encoded time bytes - copy(bz[prefixL+8:prefixL+8+timeBzL], timeBz) - return bz -} - -// combineKeys combines the byte arrays of multiple keys into a single byte array. -func combineKeys(keys ...[]byte) []byte { - combined := []byte{} - for i, key := range keys { - combined = append(combined, key...) - if i < len(keys)-1 { // not last item - combined = append(combined, types.KeyIndexSeparator...) - } - } - return combined -} diff --git a/x/incentives/keeper/utils_test.go b/x/incentives/keeper/utils_test.go deleted file mode 100644 index eff0f2845..000000000 --- a/x/incentives/keeper/utils_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package keeper - -import ( - "bytes" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/dymensionxyz/dymension/v3/x/incentives/types" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestCombineKeys(t *testing.T) { - // create three keys, each different byte arrays - key1 := []byte{0x11} - key2 := []byte{0x12} - key3 := []byte{0x13} - - // combine the three keys into a single key - key := combineKeys(key1, key2, key3) - - // three keys plus two separators is equal to a length of 5 - require.Len(t, key, 3+2) - - // ensure the newly created key is made up of the three previous keys (and the two key index separators) - require.Equal(t, key[0], key1[0]) - require.Equal(t, key[1], types.KeyIndexSeparator[0]) - require.Equal(t, key[2], key2[0]) - require.Equal(t, key[3], types.KeyIndexSeparator[0]) - require.Equal(t, key[4], key3[0]) -} - -func TestFindIndex(t *testing.T) { - // create an array of 5 IDs - IDs := []uint64{1, 2, 3, 4, 5} - - // use the findIndex function to find the index of the respective IDs - // if it doesn't exist, return -1 - require.Equal(t, findIndex(IDs, 1), 0) - require.Equal(t, findIndex(IDs, 3), 2) - require.Equal(t, findIndex(IDs, 5), 4) - require.Equal(t, findIndex(IDs, 6), -1) -} - -func TestRemoveValue(t *testing.T) { - // create an array of 5 IDs - IDs := []uint64{1, 2, 3, 4, 5} - - // remove an ID - // ensure if ID exists, the length is reduced by one and the index of the removed ID is returned - IDs, index1 := removeValue(IDs, 5) - require.Len(t, IDs, 4) - require.Equal(t, index1, 4) - IDs, index2 := removeValue(IDs, 3) - require.Len(t, IDs, 3) - require.Equal(t, index2, 2) - IDs, index3 := removeValue(IDs, 1) - require.Len(t, IDs, 2) - require.Equal(t, index3, 0) - IDs, index4 := removeValue(IDs, 6) - require.Len(t, IDs, 2) - require.Equal(t, index4, -1) -} - -func TestGetTimeKey(t *testing.T) { - now := time.Now() - timeKey := getTimeKey(now) - require.True(t, bytes.HasPrefix(timeKey, types.KeyPrefixTimestamp)) - require.True(t, bytes.HasSuffix(timeKey, sdk.FormatTimeBytes(now))) -} diff --git a/x/rollapp/client/cli/tx_create_rollapp.go b/x/rollapp/client/cli/tx_create_rollapp.go index 232fde101..27de08a80 100644 --- a/x/rollapp/client/cli/tx_create_rollapp.go +++ b/x/rollapp/client/cli/tx_create_rollapp.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" - "utils "github.com/dymensionxyz/dymension/v3/utils/ucli"" + "github.com/dymensionxyz/dymension/v3/utils/ucli" commontypes "github.com/dymensionxyz/dymension/v3/x/common/types" "github.com/dymensionxyz/dymension/v3/x/rollapp/types" @@ -117,7 +117,7 @@ func parseGenesisInfo(cmd *cobra.Command) (*types.GenesisInfo, error) { } if nativeDenomFlag != "" { - if err = utils.ParseJsonFromFile(nativeDenomFlag, &genesisInfo.NativeDenom); err != nil { + if err = ucli.ParseJsonFromFile(nativeDenomFlag, &genesisInfo.NativeDenom); err != nil { return nil, err } } @@ -185,7 +185,7 @@ func parseMetadata(cmd *cobra.Command) (*types.RollappMetadata, error) { metadata := new(types.RollappMetadata) if metadataFlag != "" { - if err = utils.ParseJsonFromFile(metadataFlag, metadata); err != nil { + if err = ucli.ParseJsonFromFile(metadataFlag, metadata); err != nil { return nil, err } } diff --git a/x/sequencer/client/cli/tx.go b/x/sequencer/client/cli/tx.go index 5dd7c7430..fdf1482b8 100644 --- a/x/sequencer/client/cli/tx.go +++ b/x/sequencer/client/cli/tx.go @@ -9,11 +9,9 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "utils "github.com/dymensionxyz/dymension/v3/utils/ucli"" "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/spf13/cobra" - ucli "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/sequencer/types" ) @@ -61,7 +59,7 @@ Whitelisted relayers is an optional flag-arg. It expects a comma-separated list var metadata types.SequencerMetadata if len(args) == 4 { - if err = utils.ParseJsonFromFile(args[3], &metadata); err != nil { + if err = ucli.ParseJsonFromFile(args[3], &metadata); err != nil { return } } @@ -120,7 +118,7 @@ func CmdUpdateSequencer() *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { metadata := new(types.SequencerMetadata) - if err = utils.ParseJsonFromFile(args[0], metadata); err != nil { + if err = ucli.ParseJsonFromFile(args[0], metadata); err != nil { return } diff --git a/x/sequencer/client/cli/tx_punish_sequencer.go b/x/sequencer/client/cli/tx_punish_sequencer.go index 41c0eebe6..2d2a68fe2 100644 --- a/x/sequencer/client/cli/tx_punish_sequencer.go +++ b/x/sequencer/client/cli/tx_punish_sequencer.go @@ -7,6 +7,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/spf13/cobra" + "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/sequencer/types" ) @@ -22,7 +23,7 @@ func NewCmdSubmitPunishSequencerProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } diff --git a/x/sequencer/types/keys.go b/x/sequencer/types/keys.go index b80cc6b36..4e445504f 100644 --- a/x/sequencer/types/keys.go +++ b/x/sequencer/types/keys.go @@ -6,6 +6,7 @@ import ( "time" "cosmossdk.io/collections" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" ) var _ binary.ByteOrder @@ -101,7 +102,7 @@ func SequencersByRollappByStatusKey(rollappId string, status OperatingStatus) [] /* -------------------------- queues keys -------------------------- */ func NoticeQueueByTimeKey(endTime time.Time) []byte { - return utils.EncodeTimeToKey(NoticePeriodQueueKey, endTime) + return ukeys.EncodeTimeToKey(NoticePeriodQueueKey, endTime) } func NoticeQueueBySeqTimeKey(sequencerAddress string, endTime time.Time) []byte { diff --git a/x/streamer/client/cli/tx_create_stream.go b/x/streamer/client/cli/tx_create_stream.go index e63673040..1d949620a 100644 --- a/x/streamer/client/cli/tx_create_stream.go +++ b/x/streamer/client/cli/tx_create_stream.go @@ -12,7 +12,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/spf13/cobra" - utils ucli "github.com/dymensionxyz/dymension/v3/utils/ucli" + "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/streamer/types" ) @@ -30,7 +30,7 @@ func NewCmdSubmitCreateStreamProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } diff --git a/x/streamer/client/cli/tx_replace_distribution.go b/x/streamer/client/cli/tx_replace_distribution.go index a98f288ac..d0edbb6d6 100644 --- a/x/streamer/client/cli/tx_replace_distribution.go +++ b/x/streamer/client/cli/tx_replace_distribution.go @@ -11,7 +11,7 @@ import ( govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - utils ucli "github.com/dymensionxyz/dymension/v3/utils/ucli" + ucli "github.com/dymensionxyz/dymension/v3/utils/ucli" ) // NewCmdSubmitReplaceStreamDistributionProposal broadcasts a CreateStream message. @@ -26,7 +26,7 @@ func NewCmdSubmitReplaceStreamDistributionProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } diff --git a/x/streamer/client/cli/tx_terminate_stream.go b/x/streamer/client/cli/tx_terminate_stream.go index aed0f21cf..1489274f7 100644 --- a/x/streamer/client/cli/tx_terminate_stream.go +++ b/x/streamer/client/cli/tx_terminate_stream.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cobra" - utils utils "github.com/dymensionxyz/dymension/v3/utils/ucli" + ucli "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/streamer/types" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" @@ -31,7 +31,7 @@ func NewCmdSubmitTerminateStreamProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } diff --git a/x/streamer/client/cli/tx_update_distribution.go b/x/streamer/client/cli/tx_update_distribution.go index 7f9e95089..751543788 100644 --- a/x/streamer/client/cli/tx_update_distribution.go +++ b/x/streamer/client/cli/tx_update_distribution.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cobra" - utils utils "github.com/dymensionxyz/dymension/v3/utils/ucli" + ucli "github.com/dymensionxyz/dymension/v3/utils/ucli" "github.com/dymensionxyz/dymension/v3/x/streamer/types" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" @@ -26,7 +26,7 @@ func NewCmdSubmitUpdateStreamDistributionProposal() *cobra.Command { return err } - proposal, deposit, err := utils.ParseProposal(cmd) + proposal, deposit, err := ucli.ParseProposal(cmd) if err != nil { return err } diff --git a/x/streamer/keeper/keeper.go b/x/streamer/keeper/keeper.go index 539043683..e98530a02 100644 --- a/x/streamer/keeper/keeper.go +++ b/x/streamer/keeper/keeper.go @@ -15,6 +15,7 @@ import ( epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types" "github.com/dymensionxyz/dymension/v3/internal/collcompat" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/streamer/types" ) @@ -129,7 +130,7 @@ func (k Keeper) CreateStream(ctx sdk.Context, coins sdk.Coins, records []types.D } k.SetLastStreamID(ctx, stream.Id) - combinedKeys := combineKeys(types.KeyPrefixUpcomingStreams, getTimeKey(stream.StartTime)) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixUpcomingStreams, getTimeKey(stream.StartTime)) err = k.CreateStreamRefKeys(ctx, &stream, combinedKeys) if err != nil { return 0, err diff --git a/x/streamer/keeper/store.go b/x/streamer/keeper/store.go index c64f82885..804439047 100644 --- a/x/streamer/keeper/store.go +++ b/x/streamer/keeper/store.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/streamer/types" ) @@ -51,20 +52,20 @@ func (k Keeper) SetStreamWithRefKey(ctx sdk.Context, stream *types.Stream) error timeKey := getTimeKey(stream.StartTime) if stream.IsUpcomingStream(curTime) { - combinedKeys := combineKeys(types.KeyPrefixUpcomingStreams, timeKey) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixUpcomingStreams, timeKey) return k.CreateStreamRefKeys(ctx, stream, combinedKeys) } else if stream.IsActiveStream(curTime) { - combinedKeys := combineKeys(types.KeyPrefixActiveStreams, timeKey) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixActiveStreams, timeKey) return k.CreateStreamRefKeys(ctx, stream, combinedKeys) } else { - combinedKeys := combineKeys(types.KeyPrefixFinishedStreams, timeKey) + combinedKeys := ukeys.CombineKeys(types.KeyPrefixFinishedStreams, timeKey) return k.CreateStreamRefKeys(ctx, stream, combinedKeys) } } // streamStoreKey returns the combined byte array (store key) of the provided stream ID's key prefix and the ID itself. func streamStoreKey(ID uint64) []byte { - return combineKeys(types.KeyPrefixPeriodStream, sdk.Uint64ToBigEndian(ID)) + return ukeys.CombineKeys(types.KeyPrefixPeriodStream, sdk.Uint64ToBigEndian(ID)) } // SetStream set the stream inside store. diff --git a/x/streamer/keeper/stream.go b/x/streamer/keeper/stream.go index 7aacfe47c..37d4dce50 100644 --- a/x/streamer/keeper/stream.go +++ b/x/streamer/keeper/stream.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" + "github.com/dymensionxyz/dymension/v3/utils/ukeys" "github.com/dymensionxyz/dymension/v3/x/streamer/types" ) @@ -119,10 +120,10 @@ func (k Keeper) moveUpcomingStreamToActiveStream(ctx sdk.Context, stream types.S } timeKey := getTimeKey(stream.StartTime) - if err := k.deleteStreamRefByKey(ctx, combineKeys(types.KeyPrefixUpcomingStreams, timeKey), stream.Id); err != nil { + if err := k.deleteStreamRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixUpcomingStreams, timeKey), stream.Id); err != nil { return err } - if err := k.addStreamRefByKey(ctx, combineKeys(types.KeyPrefixActiveStreams, timeKey), stream.Id); err != nil { + if err := k.addStreamRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixActiveStreams, timeKey), stream.Id); err != nil { return err } return nil @@ -141,10 +142,10 @@ func (k Keeper) moveActiveStreamToFinishedStream(ctx sdk.Context, stream types.S // moveStreamToFinishedStream moves a stream that has completed its distribution from an active to a finished status. func (k Keeper) moveStreamToFinishedStream(ctx sdk.Context, stream types.Stream, prefixKey []byte) error { timeKey := getTimeKey(stream.StartTime) - if err := k.deleteStreamRefByKey(ctx, combineKeys(prefixKey, timeKey), stream.Id); err != nil { + if err := k.deleteStreamRefByKey(ctx, ukeys.CombineKeys(prefixKey, timeKey), stream.Id); err != nil { return err } - if err := k.addStreamRefByKey(ctx, combineKeys(types.KeyPrefixFinishedStreams, timeKey), stream.Id); err != nil { + if err := k.addStreamRefByKey(ctx, ukeys.CombineKeys(types.KeyPrefixFinishedStreams, timeKey), stream.Id); err != nil { return err } return nil diff --git a/x/streamer/keeper/utils.go b/x/streamer/keeper/utils.go deleted file mode 100644 index 85a677bdf..000000000 --- a/x/streamer/keeper/utils.go +++ /dev/null @@ -1,60 +0,0 @@ -package keeper - -import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/dymensionxyz/dymension/v3/x/streamer/types" -) - -// findIndex takes an array of IDs. Then return the index of a specific ID. -func findIndex(IDs []uint64, ID uint64) int { - for index, id := range IDs { - if id == ID { - return index - } - } - return -1 -} - -// removeValue takes an array of IDs. Then finds the index of the IDs and remove those IDs from the array. -func removeValue(IDs []uint64, ID uint64) ([]uint64, int) { - index := findIndex(IDs, ID) - if index < 0 { - return IDs, index - } - IDs[index] = IDs[len(IDs)-1] // set last element to index - return IDs[:len(IDs)-1], index -} - -// getTimeKey returns the time key used when getting a set of streams. -func getTimeKey(timestamp time.Time) []byte { - timeBz := sdk.FormatTimeBytes(timestamp) - timeBzL := len(timeBz) - prefixL := len(types.KeyPrefixTimestamp) - - bz := make([]byte, prefixL+8+timeBzL) - - // copy the prefix - copy(bz[:prefixL], types.KeyPrefixTimestamp) - - // copy the encoded time bytes length - copy(bz[prefixL:prefixL+8], sdk.Uint64ToBigEndian(uint64(timeBzL))) - - // copy the encoded time bytes - copy(bz[prefixL+8:prefixL+8+timeBzL], timeBz) - return bz -} - -// combineKeys combines the byte arrays of multiple keys into a single byte array. -func combineKeys(keys ...[]byte) []byte { - combined := []byte{} - for i, key := range keys { - combined = append(combined, key...) - if i < len(keys)-1 { // not last item - combined = append(combined, types.KeyIndexSeparator...) - } - } - return combined -}