Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jun 22, 2024
1 parent edf298b commit 300e875
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
8 changes: 4 additions & 4 deletions x/btcbridge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ func CmdQueryUTXOs() *cobra.Command {
}

if len(args) == 0 {
return queryUTXOs(&clientCtx, cmd.Context())
return queryUTXOs(cmd.Context(), &clientCtx)
}

return queryUTXOsByAddr(&clientCtx, cmd.Context(), args[0])
return queryUTXOsByAddr(cmd.Context(), &clientCtx, args[0])
},
}

Expand All @@ -186,7 +186,7 @@ func CmdQueryUTXOs() *cobra.Command {
return cmd
}

func queryUTXOs(clientCtx *client.Context, cmdCtx context.Context) error {
func queryUTXOs(cmdCtx context.Context, clientCtx *client.Context) error {
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryUTXOs(cmdCtx, &types.QueryUTXOsRequest{})
Expand All @@ -197,7 +197,7 @@ func queryUTXOs(clientCtx *client.Context, cmdCtx context.Context) error {
return clientCtx.PrintProto(res)
}

func queryUTXOsByAddr(clientCtx *client.Context, cmdCtx context.Context, addr string) error {
func queryUTXOsByAddr(cmdCtx context.Context, clientCtx *client.Context, addr string) error {
queryClient := types.NewQueryClient(clientCtx)

_, err := sdk.AccAddressFromBech32(addr)
Expand Down
5 changes: 4 additions & 1 deletion x/btcbridge/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
k.SetParams(ctx, genState.Params)
k.SetBestBlockHeader(ctx, genState.BestBlockHeader)
if len(genState.BlockHeaders) > 0 {
k.SetBlockHeaders(ctx, genState.BlockHeaders)
err := k.SetBlockHeaders(ctx, genState.BlockHeaders)
if err != nil {
panic(err)
}
}
// import utxos
for _, utxo := range genState.Utxos {
Expand Down
4 changes: 2 additions & 2 deletions x/btcbridge/keeper/keeper_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (k Keeper) NewSigningRequest(ctx sdk.Context, sender string, coin sdk.Coin,
}

// lock the selected utxos
k.LockUTXOs(ctx, selectedUTXOs)
_ = k.LockUTXOs(ctx, selectedUTXOs)

// save the change utxo and mark minted
if changeUTXO != nil {
Expand Down Expand Up @@ -230,7 +230,7 @@ func (k Keeper) spendUTXOs(ctx sdk.Context, uTx *btcutil.Tx) {
vout := in.PreviousOutPoint.Index

if k.IsUTXOLocked(ctx, hash, uint64(vout)) {
k.SpendUTXO(ctx, hash, uint64(vout))
_ = k.SpendUTXO(ctx, hash, uint64(vout))
}
}
}
3 changes: 1 addition & 2 deletions x/btcbridge/keeper/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ func (bvk *BaseUTXOViewKeeper) IterateAllUTXOs(ctx sdk.Context, cb func(utxo *ty
func (bvk *BaseUTXOViewKeeper) IterateUTXOsByAddr(ctx sdk.Context, addr string, cb func(addr string, utxo *types.UTXO) (stop bool)) {
store := ctx.KVStore(bvk.storeKey)

keyPrefix := append(types.BtcOwnerUtxoKeyPrefix, []byte(addr)...)
iterator := sdk.KVStorePrefixIterator(store, keyPrefix)
iterator := sdk.KVStorePrefixIterator(store, append(types.BtcOwnerUtxoKeyPrefix, []byte(addr)...))
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
Expand Down
20 changes: 10 additions & 10 deletions x/btcbridge/types/bitcoin_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ func AddUTXOsToTx(tx *wire.MsgTx, utxos []*UTXO, outAmount int64, changeOut *wir
}

return selectedUTXOs, nil
} else {
tx.TxOut = tx.TxOut[0 : len(tx.TxOut)-1]
}

if changeValue == 0 {
return selectedUTXOs, nil
}
tx.TxOut = tx.TxOut[0 : len(tx.TxOut)-1]

if changeValue < 0 {
feeWithoutChange := GetTxVirtualSize(tx, selectedUTXOs) * feeRate
if inputAmount-outAmount-feeWithoutChange >= 0 {
return selectedUTXOs, nil
}
if changeValue == 0 {
return selectedUTXOs, nil
}

if changeValue < 0 {
feeWithoutChange := GetTxVirtualSize(tx, selectedUTXOs) * feeRate
if inputAmount-outAmount-feeWithoutChange >= 0 {
return selectedUTXOs, nil
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion x/btcbridge/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func BtcUtxoKey(hash string, vout uint64) []byte {
func BtcOwnerUtxoKey(owner string, hash string, vout uint64) []byte {
key := append(BtcOwnerUtxoKeyPrefix, []byte(owner)...)
key = append(key, []byte(hash)...)
key = append(key, Int64ToBytes(vout)...)

return append(key, Int64ToBytes(vout)...)
return key
}

func BtcBlockHeaderHashKey(hash string) []byte {
Expand Down
2 changes: 1 addition & 1 deletion x/gmm/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *Pool) DecreaseShare(amt sdkmath.Int) {
// IncreaseLiquidity adds xx amount liquidity to assets in pool
func (p *Pool) IncreaseLiquidity(coins []sdk.Coin) error {
for _, coin := range coins {
asset, index, exists := p.GetAssetByDenom(coin.Denom) //Assets[coin.Denom]
asset, index, exists := p.GetAssetByDenom(coin.Denom) // Assets[coin.Denom]
if !exists {
return ErrNotFoundAssetInPool
}
Expand Down
2 changes: 1 addition & 1 deletion x/gmm/types/poolI.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func (p *PoolI) ToPool() Pool {
assets := []PoolAsset{} //make(map[PoolAsset])
assets := []PoolAsset{} // make(map[PoolAsset])
for _, asset := range p.Assets {
weight := sdkmath.NewIntFromUint64(uint64(asset.Weight))
assets = append(assets, PoolAsset{
Expand Down
6 changes: 3 additions & 3 deletions x/gmm/types/pool_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func (p *Pool) estimateShareWithSingleLiquidityInWeightPool(coin sdk.Coin) (sdk.
decAsset := sdk.NewDecCoinFromCoin(asset.Token)
weight := sdk.NewDecFromInt(*asset.Weight).Quo(sdk.NewDec(100)) // divide by 100
ratio := decToken.Amount.Quo(decAsset.Amount).Add(sdk.NewDec(1))
precision := big.NewInt(1) //sdk.MustNewDecFromStr("0.00000001")
precision := big.NewInt(1) // sdk.MustNewDecFromStr("0.00000001")
_ = weight
_ = ratio
_ = precision
factor := sdk.NewInt(1)
//factor := (ApproximatePow(ratio.BigInt(), weight.BigInt(), precision).Sub(sdk.OneDec()))
// factor := (ApproximatePow(ratio.BigInt(), weight.BigInt(), precision).Sub(sdk.OneDec()))
issueAmount := p.TotalShares.Amount.Mul(factor).Quo(sdk.NewInt(1e10))
outputToken := sdk.Coin{
Amount: issueAmount,
Expand Down Expand Up @@ -105,7 +105,7 @@ func (p *Pool) estimateSwapInWeightPool(amountIn sdk.Coin, denomOut string) (sdk
ratio := balanceIn.Quo(balanceInPlusAmount)
oneMinusRatio := sdk.NewDec(1).Sub(ratio)
power := weightIn.Quo(weightOut)
precision := "0.00000001" //sdk.MustNewDecFromStr("0.00000001")
precision := "0.00000001" // sdk.MustNewDecFromStr("0.00000001")
factor, err := ApproximatePow(oneMinusRatio.String(), power.String(), precision) // 100 iterations for example
if err != nil {
return sdk.Coin{}, err
Expand Down

0 comments on commit 300e875

Please sign in to comment.