Skip to content

Commit 4113563

Browse files
committed
support fee grant
1 parent ee1253b commit 4113563

File tree

11 files changed

+182
-103
lines changed

11 files changed

+182
-103
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
All notable changes will be documented here.
44

5-
## [v1.5.0] - UNRELEASED
5+
## [v1.5.0] - 2023-05-17
66

77
- git credential helper for git lfs
88
- Use git cli instead of go-git for fetch/push
99
- Common http basic auth for both git push and lfs
1010
- Refactor wallets
11+
- Support fee grant
12+
- Upgrade gitopia version to v2.0.1
1113

1214
## [v1.4.0] - 2023-02-22
1315

cmd/git-remote-gitopia/gitopia.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"github.com/gitopia/git-remote-gitopia/config"
2020
core "github.com/gitopia/git-remote-gitopia/core"
2121
"github.com/gitopia/git-remote-gitopia/core/wallet"
22-
gitopiaTypes "github.com/gitopia/gitopia/x/gitopia/types"
23-
"github.com/gitopia/gitopia/x/gitopia/utils"
22+
gitopiaTypes "github.com/gitopia/gitopia/v2/x/gitopia/types"
23+
"github.com/gitopia/gitopia/v2/x/gitopia/utils"
2424
"github.com/go-git/go-git/v5/plumbing"
2525
"github.com/pkg/errors"
2626
"google.golang.org/grpc"
@@ -237,16 +237,16 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
237237
force = true
238238
}
239239

240+
if h.wallet.Type() == wallet.LEDGER {
241+
remote.Logger.Println("Please sign the git server request on your ledger device.")
242+
}
243+
240244
data := []byte("test")
241245
signature, err := h.wallet.SignData(data)
242246
if err != nil {
243247
return nil, errors.Wrap(err, "error signing data")
244248
}
245249

246-
if h.wallet.Type() == wallet.LEDGER {
247-
remote.Logger.Println("Please sign the git server request on your ledger device.")
248-
}
249-
250250
credential := fmt.Sprintf("%s:%s", h.wallet.Address(), signature)
251251
args := []string{
252252
"-c",
@@ -332,21 +332,8 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
332332
}, deleteTags))
333333
}
334334

335-
switch v := h.wallet.(type) {
336-
case wallet.OSKeyring:
337-
if err := v.SignAndBroadcast(msg); err != nil {
338-
return nil, err
339-
}
340-
case wallet.GitopiaWallet:
341-
if err := v.SignAndBroadcast(h.grpcConn, msg); err != nil {
342-
return nil, err
343-
}
344-
case wallet.Ledger:
345-
if err := v.SignAndBroadcast(h.grpcConn, msg); err != nil {
346-
return nil, err
347-
}
348-
default:
349-
return nil, errors.New("unknown wallet type")
335+
if err := h.wallet.SignAndBroadcast(h.grpcConn, msg); err != nil {
336+
return nil, err
350337
}
351338

352339
return &res, nil

config/config_dev.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
package config
44

55
const (
6-
GRPCHost = "grpc.devnet.gitopia.com:9090"
7-
GitServerHost = "https://server.devnet.gitopia.com"
8-
TmAddr = "https://rpc.devnet.gitopia.com:443"
9-
GasPrices = "0.001ulore"
6+
GRPCHost = "grpc.devnet.gitopia.com:9090"
7+
GitServerHost = "https://server.devnet.gitopia.com"
8+
TmAddr = "https://rpc.devnet.gitopia.com:443"
9+
GasPrices = "0.001ulore"
10+
FeeGranterAddr = ""
1011
)

config/config_prod.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
package config
44

55
const (
6-
GRPCHost = "grpc.gitopia.com:9090"
7-
GitServerHost = "https://server.gitopia.com"
8-
TmAddr = "https://rpc.gitopia.com:443"
9-
GasPrices = "0.001ulore"
6+
GRPCHost = "grpc.gitopia.com:9090"
7+
GitServerHost = "https://server.gitopia.com"
8+
TmAddr = "https://rpc.gitopia.com:443"
9+
GasPrices = "0.001ulore"
10+
FeeGranterAddr = "gitopia13ashgc6j5xle4m47kqyn5psavq0u3klmscfxql"
1011
)

config/config_testing.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
package config
44

55
const (
6-
GRPCHost = "localhost:9090"
7-
GitServerHost = "http://localhost:5001"
8-
TmAddr = "http://localhost:26657"
9-
GasPrices = "0.001ulore"
6+
GRPCHost = "localhost:9090"
7+
GitServerHost = "http://localhost:5001"
8+
TmAddr = "http://localhost:26657"
9+
GasPrices = "0.001ulore"
10+
FeeGranterAddr = ""
1011
)

core/wallet/gitopia_wallet.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
2222
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
2323
authtype "github.com/cosmos/cosmos-sdk/x/auth/types"
24-
gitopia "github.com/gitopia/gitopia/app"
25-
offchaintypes "github.com/gitopia/gitopia/x/offchain/types"
24+
"github.com/cosmos/cosmos-sdk/x/feegrant"
25+
"github.com/gitopia/git-remote-gitopia/config"
26+
gitopia "github.com/gitopia/gitopia/v2/app"
27+
offchaintypes "github.com/gitopia/gitopia/v2/x/offchain/types"
2628
"github.com/pkg/errors"
2729
"google.golang.org/grpc"
2830
)
@@ -168,6 +170,30 @@ func (gw GitopiaWallet) SignAndBroadcast(grpcConn *grpc.ClientConn, msgs []sdk.M
168170
}
169171
txBuilder.SetFeeAmount(fee)
170172

173+
// check fee grant exists
174+
fqc := feegrant.NewQueryClient(grpcConn)
175+
fr, err := fqc.Allowance(context.Background(), &feegrant.QueryAllowanceRequest{
176+
Granter: config.FeeGranterAddr,
177+
Grantee: gw.Address(),
178+
})
179+
if err != nil {
180+
return err
181+
}
182+
183+
if fr.Allowance != nil {
184+
feeGranterAddr, err := sdk.AccAddressFromBech32(config.FeeGranterAddr)
185+
if err != nil {
186+
return err
187+
}
188+
feePayerAddr, err := sdk.AccAddressFromBech32(gw.Address())
189+
if err != nil {
190+
return err
191+
}
192+
193+
txBuilder.SetFeeGranter(feeGranterAddr)
194+
txBuilder.SetFeePayer(feePayerAddr)
195+
}
196+
171197
// Get chain id for signing transaction
172198
serviceClient := tmservice.NewServiceClient(grpcConn)
173199
nodeInfoRes, err := serviceClient.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})

core/wallet/ledger.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
2222
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
2323
authtype "github.com/cosmos/cosmos-sdk/x/auth/types"
24-
gitopia "github.com/gitopia/gitopia/app"
25-
offchaintypes "github.com/gitopia/gitopia/x/offchain/types"
24+
"github.com/cosmos/cosmos-sdk/x/feegrant"
25+
"github.com/gitopia/git-remote-gitopia/config"
26+
gitopia "github.com/gitopia/gitopia/v2/app"
27+
offchaintypes "github.com/gitopia/gitopia/v2/x/offchain/types"
2628
"github.com/pkg/errors"
2729
"google.golang.org/grpc"
2830
)
@@ -145,6 +147,30 @@ func (l Ledger) SignAndBroadcast(grpcConn *grpc.ClientConn, msgs []sdk.Msg) erro
145147
}
146148
txBuilder.SetFeeAmount(fee)
147149

150+
// check fee grant exists
151+
fqc := feegrant.NewQueryClient(grpcConn)
152+
fr, err := fqc.Allowance(context.Background(), &feegrant.QueryAllowanceRequest{
153+
Granter: config.FeeGranterAddr,
154+
Grantee: l.Address(),
155+
})
156+
if err != nil {
157+
return err
158+
}
159+
160+
if fr.Allowance != nil {
161+
feeGranterAddr, err := sdk.AccAddressFromBech32(config.FeeGranterAddr)
162+
if err != nil {
163+
return err
164+
}
165+
feePayerAddr, err := sdk.AccAddressFromBech32(l.Address())
166+
if err != nil {
167+
return err
168+
}
169+
170+
txBuilder.SetFeeGranter(feeGranterAddr)
171+
txBuilder.SetFeePayer(feePayerAddr)
172+
}
173+
148174
// Get chain id for signing transaction
149175
serviceClient := tmservice.NewServiceClient(grpcConn)
150176
nodeInfoRes, err := serviceClient.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})

core/wallet/os_keyring.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
1313
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1414
sdk "github.com/cosmos/cosmos-sdk/types"
15+
"github.com/cosmos/cosmos-sdk/x/feegrant"
1516
"github.com/gitopia/git-remote-gitopia/config"
16-
gitopia "github.com/gitopia/gitopia/app"
17-
offchaintypes "github.com/gitopia/gitopia/x/offchain/types"
17+
gitopia "github.com/gitopia/gitopia/v2/app"
18+
offchaintypes "github.com/gitopia/gitopia/v2/x/offchain/types"
1819
goGitConfig "github.com/go-git/go-git/v5/config"
1920
"github.com/ignite/cli/ignite/pkg/cosmosaccount"
2021
"github.com/ignite/cli/ignite/pkg/cosmosclient"
2122
"github.com/pkg/errors"
23+
"google.golang.org/grpc"
2224
)
2325

2426
const (
@@ -37,20 +39,20 @@ var (
3739
type keyringBackend struct {
3840
key string
3941
backend string
40-
cc cosmosclient.Client
42+
CC cosmosclient.Client
4143
}
4244

4345
func newKeyringBackend(k string, b string, c cosmosclient.Client) keyringBackend {
4446
c.TxFactory = c.TxFactory.WithGasPrices(config.GasPrices)
4547
return keyringBackend{
4648
key: k,
4749
backend: b,
48-
cc: c,
50+
CC: c,
4951
}
5052
}
5153

5254
func (k keyringBackend) address() (string, error) {
53-
address, err := k.cc.Address(k.key)
55+
address, err := k.CC.Address(k.key)
5456
return address, err
5557
}
5658

@@ -157,12 +159,37 @@ func (o OSKeyring) SignData(data []byte) (string, error) {
157159
return string(txBz), nil
158160
}
159161

160-
func (o OSKeyring) SignAndBroadcast(msgs []sdk.Msg) error {
161-
account, err := o.kb.cc.Account(o.kb.key)
162+
func (o OSKeyring) SignAndBroadcast(grpcConn *grpc.ClientConn, msgs []sdk.Msg) error {
163+
account, err := o.kb.CC.Account(o.kb.key)
162164
if err != nil {
163165
return err
164166
}
165-
txResp, err := o.kb.cc.BroadcastTx(account, msgs...)
167+
168+
// check fee grant exists
169+
fqc := feegrant.NewQueryClient(grpcConn)
170+
fr, err := fqc.Allowance(context.Background(), &feegrant.QueryAllowanceRequest{
171+
Granter: config.FeeGranterAddr,
172+
Grantee: o.Address(),
173+
})
174+
if err != nil {
175+
return err
176+
}
177+
178+
if fr.Allowance != nil {
179+
feeGranterAddr, err := sdk.AccAddressFromBech32(config.FeeGranterAddr)
180+
if err != nil {
181+
return err
182+
}
183+
feePayerAddr, err := sdk.AccAddressFromBech32(o.Address())
184+
if err != nil {
185+
return err
186+
}
187+
188+
o.kb.CC.TxFactory.WithFeeGranter(feeGranterAddr)
189+
o.kb.CC.TxFactory.WithFeePayer(feePayerAddr)
190+
}
191+
192+
txResp, err := o.kb.CC.BroadcastTx(account, msgs...)
166193
if err != nil {
167194
return err
168195
}

core/wallet/wallet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package wallet
33
import (
44
"errors"
55
"fmt"
6+
7+
sdk "github.com/cosmos/cosmos-sdk/types"
8+
"google.golang.org/grpc"
69
)
710

811
type secretType int
@@ -17,6 +20,7 @@ const (
1720

1821
type Wallet interface {
1922
SignData(data []byte) (string, error)
23+
SignAndBroadcast(grpcConn *grpc.ClientConn, msgs []sdk.Msg) error
2024
Type() secretType
2125
Address() string
2226
}

go.mod

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module github.com/gitopia/git-remote-gitopia
22

3-
go 1.18
3+
go 1.19
44

55
require (
6-
github.com/cosmos/cosmos-sdk v0.46.10
7-
github.com/gitopia/gitopia v1.3.0
6+
github.com/cosmos/cosmos-sdk v0.46.12
7+
github.com/gitopia/gitopia/v2 v2.0.1
88
github.com/go-git/go-git/v5 v5.5.1
99
github.com/ignite/cli v0.24.0
1010
github.com/pkg/errors v0.9.1
1111
github.com/sirupsen/logrus v1.9.0
1212
github.com/spf13/cobra v1.6.1
13-
google.golang.org/grpc v1.51.0
13+
google.golang.org/grpc v1.53.0
1414
)
1515

1616
require (
17-
cloud.google.com/go v0.105.0 // indirect
18-
cloud.google.com/go/compute v1.13.0 // indirect
19-
cloud.google.com/go/compute/metadata v0.2.1 // indirect
20-
cloud.google.com/go/iam v0.8.0 // indirect
17+
cloud.google.com/go v0.107.0 // indirect
18+
cloud.google.com/go/compute v1.18.0 // indirect
19+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
20+
cloud.google.com/go/iam v0.11.0 // indirect
2121
cloud.google.com/go/storage v1.27.0 // indirect
2222
cosmossdk.io/errors v1.0.0-beta.7 // indirect
2323
cosmossdk.io/math v1.0.0-beta.3 // indirect
@@ -37,7 +37,7 @@ require (
3737
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
3838
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
3939
github.com/cespare/xxhash v1.1.0 // indirect
40-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
40+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
4141
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
4242
github.com/cloudflare/circl v1.3.1 // indirect
4343
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
@@ -71,12 +71,12 @@ require (
7171
github.com/gogo/protobuf v1.3.3 // indirect
7272
github.com/golang/glog v1.0.0 // indirect
7373
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
74-
github.com/golang/protobuf v1.5.2 // indirect
74+
github.com/golang/protobuf v1.5.3 // indirect
7575
github.com/golang/snappy v0.0.4 // indirect
76-
github.com/google/btree v1.0.1 // indirect
76+
github.com/google/btree v1.1.2 // indirect
7777
github.com/google/go-cmp v0.5.9 // indirect
7878
github.com/google/uuid v1.3.0 // indirect
79-
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
79+
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
8080
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
8181
github.com/gorilla/handlers v1.5.1 // indirect
8282
github.com/gorilla/mux v1.8.0 // indirect
@@ -147,7 +147,7 @@ require (
147147
github.com/subosito/gotenv v1.4.1 // indirect
148148
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
149149
github.com/tendermint/go-amino v0.16.0 // indirect
150-
github.com/tendermint/tendermint v0.34.26 // indirect
150+
github.com/tendermint/tendermint v0.34.27 // indirect
151151
github.com/tendermint/tm-db v0.6.7 // indirect
152152
github.com/tidwall/btree v1.5.0 // indirect
153153
github.com/ulikunitz/xz v0.5.8 // indirect
@@ -159,17 +159,17 @@ require (
159159
golang.org/x/crypto v0.5.0 // indirect
160160
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
161161
golang.org/x/mod v0.7.0 // indirect
162-
golang.org/x/net v0.5.0 // indirect
163-
golang.org/x/oauth2 v0.3.0 // indirect
162+
golang.org/x/net v0.7.0 // indirect
163+
golang.org/x/oauth2 v0.5.0 // indirect
164164
golang.org/x/sync v0.1.0 // indirect
165-
golang.org/x/sys v0.4.0 // indirect
166-
golang.org/x/term v0.4.0 // indirect
167-
golang.org/x/text v0.6.0 // indirect
165+
golang.org/x/sys v0.5.0 // indirect
166+
golang.org/x/term v0.5.0 // indirect
167+
golang.org/x/text v0.7.0 // indirect
168168
golang.org/x/tools v0.4.0 // indirect
169169
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
170-
google.golang.org/api v0.103.0 // indirect
170+
google.golang.org/api v0.110.0 // indirect
171171
google.golang.org/appengine v1.6.7 // indirect
172-
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
172+
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 // indirect
173173
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 // indirect
174174
gopkg.in/ini.v1 v1.67.0 // indirect
175175
gopkg.in/warnings.v0 v0.1.2 // indirect
@@ -180,4 +180,4 @@ require (
180180

181181
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
182182

183-
replace github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.26
183+
replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27

0 commit comments

Comments
 (0)