Skip to content

Commit

Permalink
refactor opb module
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer committed Jul 28, 2023
1 parent e6b5224 commit c2eb079
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 21 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/gogoproto v1.4.10
github.com/ethereum/go-ethereum v1.10.26
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
Expand Down Expand Up @@ -81,12 +82,13 @@ require (
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/orderedcode v0.0.1 // indirect
Expand All @@ -107,6 +109,7 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand Down
19 changes: 18 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
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 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o=
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=
github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I=
Expand Down Expand Up @@ -389,6 +391,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s=
github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
Expand Down Expand Up @@ -425,6 +429,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
Expand All @@ -434,6 +439,8 @@ github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
Expand Down Expand Up @@ -496,8 +503,9 @@ 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=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
Expand Down Expand Up @@ -634,6 +642,9 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU=
github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
Expand Down Expand Up @@ -715,6 +726,7 @@ github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp9
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand Down Expand Up @@ -763,6 +775,7 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
Expand Down Expand Up @@ -846,6 +859,7 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA=
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
Expand All @@ -872,6 +886,7 @@ github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZj
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down Expand Up @@ -937,6 +952,8 @@ github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tjfoc/gmsm v1.4.0 h1:8nbaiZG+iVdh+fXVw0DZoZZa7a4TGm3Qab+xdrdzj8s=
github.com/tjfoc/gmsm v1.4.0/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4=
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
Expand Down
21 changes: 8 additions & 13 deletions modules/opb/keeper/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@ type ValidateFn func(ctx sdk.Context, msg sdk.Msg) error

// ValidateTokenTransferDecorator checks if the token transfer satisfies the underlying constraint
type ValidateTokenTransferDecorator struct {
keeper Keeper
tokenKeeper types.TokenKeeper
permKeeper types.PermKeeper
validators map[string]ValidateFn
keeper Keeper
validators map[string]ValidateFn
}

// NewValidateTokenTransferDecorator constructs a new ValidateTokenTransferDecorator instance
func NewValidateTokenTransferDecorator(
keeper Keeper,
tokenKeeper types.TokenKeeper,
permKeeper types.PermKeeper,
) *ValidateTokenTransferDecorator {
return &ValidateTokenTransferDecorator{
keeper: keeper,
tokenKeeper: tokenKeeper,
permKeeper: permKeeper,
validators: make(map[string]ValidateFn),
keeper: keeper,
validators: make(map[string]ValidateFn),
}
}

Expand Down Expand Up @@ -152,7 +146,7 @@ func (vtd ValidateTokenTransferDecorator) getOwner(
if denom == baseTokenDenom {
owner = vtd.keeper.BaseTokenManager(ctx)
} else {
ownerAddr, err := vtd.tokenKeeper.GetOwner(ctx, denom)
ownerAddr, err := vtd.keeper.tokenKeeper.GetOwner(ctx, denom)
if err == nil {
owner = ownerAddr.String()
}
Expand Down Expand Up @@ -184,8 +178,9 @@ func (vtd ValidateTokenTransferDecorator) hasPlatformUserPerm(
ctx sdk.Context,
address sdk.AccAddress,
) bool {
return vtd.permKeeper.IsRootAdmin(ctx, address) || vtd.permKeeper.IsBaseM1Admin(ctx, address) ||
vtd.permKeeper.IsPlatformUser(ctx, address)
return vtd.keeper.permKeeper.IsRootAdmin(ctx, address) ||
vtd.keeper.permKeeper.IsBaseM1Admin(ctx, address) ||
vtd.keeper.permKeeper.IsPlatformUser(ctx, address)
}

// owned returns false if any address is not the owner of the denom among the given non-empty addresses
Expand Down
133 changes: 133 additions & 0 deletions modules/opb/keeper/evm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package keeper

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/bianjieai/iritamod/modules/opb/types"
)

type EVMTransferCreator struct {
opbKeeper Keeper
tokenKeeper types.TokenKeeper
evmKeeper types.EVMKeeper
permKeeper types.PermKeeper
}

func (k Keeper) NewEVMTransferCreator(
evmKeeper types.EVMKeeper,
permKeeper types.PermKeeper,
) *EVMTransferCreator {
return &EVMTransferCreator{
opbKeeper: k,
tokenKeeper: k.tokenKeeper,
evmKeeper: evmKeeper,
permKeeper: permKeeper,
}
}

func (ov *EVMTransferCreator) CanTransfer(ctx sdk.Context) vm.CanTransferFunc {
return func(db vm.StateDB, userAddr common.Address, amount *big.Int) bool {
userCosmosAddr := sdk.AccAddress(userAddr.Bytes())

// get opb params
evmDenom := ov.evmKeeper.GetBaseDenom(ctx)
restrictionEnabled := !ov.opbKeeper.UnrestrictedTokenTransfer(ctx)

// check only if the transfer restriction is enabled
if restrictionEnabled {
owner, err := ov.getOwner(ctx, evmDenom)
if err != nil {
return false
}
if ov.hasPlatformUserPerm(ctx, userCosmosAddr) {
return false
}
if userCosmosAddr.String() != owner {
return false
}
}

return db.GetBalance(userAddr).Cmp(amount) >= 0
}
}

func (ov *EVMTransferCreator) Transfer(ctx sdk.Context) vm.TransferFunc {
return func(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {
senderCosmosAddr := sdk.AccAddress(sender.Bytes())
recipientCosmosAddr := sdk.AccAddress(recipient.Bytes())

evmDenom := ov.evmKeeper.GetBaseDenom(ctx)
restrictionEnabled := !ov.opbKeeper.UnrestrictedTokenTransfer(ctx)
// check only if the transfer restriction is enabled
if restrictionEnabled {
owner, err := ov.getOwner(ctx, evmDenom)
if err != nil {
//ov.logger.Error("unauthorized operation", "err_msg", err.Error())
ov.opbKeeper.Logger(ctx).Error(
"unauthorized operation",
"err_msg", err.Error(),
"amount", amount.Int64(),
)
return
}
if senderCosmosAddr.String() != owner && recipientCosmosAddr.String() != owner {
errMsg := fmt.Sprintf(
"either the sender or recipient must be the owner %s for token %s",
owner,
evmDenom,
)
//ov.logger.Error("unauthorized operation", "err_msg", errMsg)
ov.opbKeeper.Logger(ctx).Error(
"unauthorized operation",
"err_msg", errMsg,
"amount", amount.Int64(),
)
return
}
}
// go-ethereum
db.SubBalance(sender, amount)
db.AddBalance(recipient, amount)
}
}

func (ov *EVMTransferCreator) getOwner(ctx sdk.Context, denom string) (owner string, err error) {
baseTokenDenom := ov.opbKeeper.BaseTokenDenom(ctx)

if denom == baseTokenDenom {
owner = ov.opbKeeper.BaseTokenManager(ctx)
} else {
ownerAddr, err := ov.tokenKeeper.GetOwner(ctx, denom)
if err == nil {
owner = ownerAddr.String()
}
}
return
}

// hasPlatformUserPermFromArr determine whether the account is a platform user from addresses
func (ov *EVMTransferCreator) hasPlatformUserPermFromArr(ctx sdk.Context, addresses []string) bool {
for _, addr := range addresses {
fromAddress, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return false
}
if !ov.hasPlatformUserPerm(ctx, fromAddress) {
return false
}
}

return true
}

// hasPlatformUserPerm determine whether the account is a platform user
func (ov *EVMTransferCreator) hasPlatformUserPerm(ctx sdk.Context, address sdk.AccAddress) bool {
return ov.permKeeper.IsRootAdmin(ctx, address) || ov.permKeeper.IsBaseM1Admin(ctx, address) ||
ov.permKeeper.IsPlatformUser(ctx, address)
}
6 changes: 3 additions & 3 deletions modules/opb/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func (k Keeper) Mint(ctx sdk.Context, amount uint64, recipient, operator sdk.Acc
}

// get the base token
baseToken, err := k.tokenKeeper.GetToken(ctx, baseTokenDenom)
symbol, err := k.tokenKeeper.GetSymbol(ctx, baseTokenDenom)
if err != nil {
return sdkerrors.Wrapf(types.ErrInvalidDenom, "token for %s does not exist", baseTokenDenom)
}

// NOTE: empty owner
owner := sdk.AccAddress{}

return k.tokenKeeper.MintToken(ctx, baseToken.GetSymbol(), amount, recipient, owner)
return k.tokenKeeper.MintToken(ctx, symbol, amount, recipient, owner)
}

// Reclaim reclaims the native token of the specified denom from the corresponding escrow account
Expand Down Expand Up @@ -150,7 +150,7 @@ func (k Keeper) Reclaim(ctx sdk.Context, denom string, recipient, operator sdk.A

// HasToken checks if the given token exists
func (k Keeper) HasToken(ctx sdk.Context, denom string) bool {
if _, err := k.tokenKeeper.GetToken(ctx, denom); err != nil {
if _, err := k.tokenKeeper.GetSymbol(ctx, denom); err != nil {
return false
}

Expand Down
6 changes: 3 additions & 3 deletions modules/opb/types/expected_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// TokenKeeper defines the expected token keeper (noalias)
type TokenKeeper interface {
GetOwner(ctx sdk.Context, denom string) (sdk.AccAddress, error)
GetToken(ctx sdk.Context, denom string) (Token, error)
GetSymbol(ctx sdk.Context, denom string) (string, error)
MintToken(
ctx sdk.Context,
symbol string,
Expand Down Expand Up @@ -40,6 +40,6 @@ type PermKeeper interface {
IsPlatformUser(ctx sdk.Context, address sdk.AccAddress) bool
}

type Token interface {
GetSymbol() string
type EVMKeeper interface {
GetBaseDenom(ctx sdk.Context) string
}

0 comments on commit c2eb079

Please sign in to comment.