[ci] Add nosnakecase to golangci-lint (#161)

Golang uses:

- Camel Case for variable names, e.g. `firstName`
- Camel Case for private function names, e.g. `getFirstName`
- Pascal Case for public function names, e.g. `GetFirstName`

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-10-20 14:09:07 +02:00 committed by GitHub
parent 7d65bff35f
commit 6472d7693f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 65 additions and 52 deletions

View File

@ -8,5 +8,17 @@ linters:
- gosimple
- govet
- ineffassign
- nosnakecase
- staticcheck
- unused
issues:
exclude-rules:
- path: codec\.go
linters:
- nosnakecase
- path: app\/simulation_test\.go
linters:
- nosnakecase
- path: testutil\/rest\.go
linters:
- nosnakecase

View File

@ -52,10 +52,10 @@ func GetValidatorCometBFTIdentity(ctx sdk.Context) (string, bool) {
}
func IsValidatorBlockProposer(ctx sdk.Context, proposerAddress []byte) bool {
validator_identity, valid_result := GetValidatorCometBFTIdentity(ctx)
if !valid_result {
validatorIdentity, validResult := GetValidatorCometBFTIdentity(ctx)
if !validResult {
return false
}
hexProposerAddress := hex.EncodeToString(proposerAddress)
return hexProposerAddress == validator_identity
return hexProposerAddress == validatorIdentity
}

View File

@ -16,12 +16,12 @@ type ReissueResult struct {
Vin int `json:"vin"`
}
func ReissueAsset(reissue_tx string) (txid string, err error) {
func ReissueAsset(reissueTx string) (txid string, err error) {
conf := config.GetConfig()
cmd_args := strings.Split(reissue_tx, " ")
cmdArgs := strings.Split(reissueTx, " ")
cmd := exec.Command("/usr/local/bin/elements-cli", "-rpcpassword="+conf.RPCPassword,
"-rpcuser="+conf.RPCUser, "-rpcport="+strconv.Itoa(conf.RPCPort), "-rpcconnect="+conf.RPCHost,
cmd_args[0], cmd_args[1], cmd_args[2])
cmdArgs[0], cmdArgs[1], cmdArgs[2])
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout

View File

@ -10,15 +10,15 @@ import (
"github.com/planetmint/planetmint-go/config"
)
func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsigned string, blk_height int64) error {
func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, txUnsigned string, blockHeight int64) error {
//get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
logger := ctx.Logger()
// Construct the command
sending_validator_address := config.GetConfig().ValidatorAddress
sendingValidatorAddress := config.GetConfig().ValidatorAddress
logger.Debug("REISSUE: create Proposal")
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal",
"--from", sending_validator_address, "-y",
proposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10))
"--from", sendingValidatorAddress, "-y",
proposerAddress, txUnsigned, strconv.FormatInt(blockHeight, 10))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
@ -35,14 +35,14 @@ func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsig
return err
}
func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blk_height int64) error {
func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blockHeight int64) error {
logger := ctx.Logger()
// Construct the command
sending_validator_address := config.GetConfig().ValidatorAddress
sendingValidatorAddress := config.GetConfig().ValidatorAddress
logger.Debug("REISSUE: create Result")
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result",
"--from", sending_validator_address, "-y",
proposerAddress, txID, strconv.FormatInt(blk_height, 10))
"--from", sendingValidatorAddress, "-y",
proposerAddress, txID, strconv.FormatInt(blockHeight, 10))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout

View File

@ -40,8 +40,8 @@ func ValidateSignatureByteMsg(message []byte, signature string, publicKey string
}
}
func GetHexPubKey(ext_pub_key string) (string, error) {
xpubKey, err := hdkeychain.NewKeyFromString(ext_pub_key)
func GetHexPubKey(extPubKey string) (string, error) {
xpubKey, err := hdkeychain.NewKeyFromString(extPubKey)
if err != nil {
return "", err
}
@ -49,6 +49,6 @@ func GetHexPubKey(ext_pub_key string) (string, error) {
if err != nil {
return "", err
}
byte_key := pubKey.SerializeCompressed()
return hex.EncodeToString(byte_key), nil
byteKey := pubKey.SerializeCompressed()
return hex.EncodeToString(byteKey), nil
}

View File

@ -14,12 +14,12 @@ func (k Keeper) StoreAsset(ctx sdk.Context, msg types.MsgNotarizeAsset) {
func (k Keeper) GetAsset(ctx sdk.Context, cid string) (msg types.MsgNotarizeAsset, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
creator_bytes := store.Get(GetAssetCIDBytes(cid))
if creator_bytes == nil {
creatorBytes := store.Get(GetAssetCIDBytes(cid))
if creatorBytes == nil {
return msg, false
}
msg.Cid = cid
msg.Creator = string(creator_bytes)
msg.Creator = string(creatorBytes)
return msg, true
}
@ -29,11 +29,11 @@ func (k Keeper) GetCidsByAddress(ctx sdk.Context, address string) (cids []string
reverseIterator := store.ReverseIterator(nil, nil)
defer reverseIterator.Close()
for ; reverseIterator.Valid(); reverseIterator.Next() {
address_bytes := reverseIterator.Value()
cid_bytes := reverseIterator.Key()
addressBytes := reverseIterator.Value()
cidBytes := reverseIterator.Key()
if string(address_bytes) == address {
cids = append(cids, string(cid_bytes))
if string(addressBytes) == address {
cids = append(cids, string(cidBytes))
}
}
return cids, len(cids) > 0

View File

@ -29,11 +29,11 @@ func TestMsgServer(t *testing.T) {
}
func TestMsgServerNotarizeAsset(t *testing.T) {
ext_sk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
xskKey, _ := hdkeychain.NewKeyFromString(ext_sk)
extSk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
xskKey, _ := hdkeychain.NewKeyFromString(extSk)
privKey, _ := xskKey.ECPrivKey()
byte_key := privKey.Serialize()
sk := hex.EncodeToString(byte_key)
byteKey := privKey.Serialize()
sk := hex.EncodeToString(byteKey)
cid := sample.Asset()
msg := types.NewMsgNotarizeAsset(sk, cid)

View File

@ -23,8 +23,8 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
logger.Info("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig()
tx_unsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, tx_unsigned, blockHeight)
txUnsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil {
logger.Error("error while initializing RDDL issuance", err)
}

View File

@ -12,8 +12,8 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
ctx := sdk.UnwrapSDKContext(goCtx)
logger := ctx.Logger()
validator_identity, valid_result := util.GetValidatorCometBFTIdentity(ctx)
if valid_result && msg.Proposer == validator_identity {
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
if validResult && msg.Proposer == validatorIdentity {
// 1. sign tx
// 2. broadcast tx
logger.Debug("REISSUE: Asset")

View File

@ -24,7 +24,7 @@ func (k Keeper) LookupReissuance(ctx sdk.Context, height int64) (val types.Reiss
return val, true
}
func (k Keeper) getReissuancesPage(ctx sdk.Context, key []byte, offset uint64, page_size uint64, all bool, reverse bool) (reissuances []types.Reissuance) {
func (k Keeper) getReissuancesPage(ctx sdk.Context, key []byte, offset uint64, pageSize uint64, all bool, reverse bool) (reissuances []types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
iterator := store.Iterator(nil, nil)
@ -36,9 +36,9 @@ func (k Keeper) getReissuancesPage(ctx sdk.Context, key []byte, offset uint64, p
for ; iterator.Valid(); iterator.Next() {
reissuance := iterator.Value()
var reissuance_org types.Reissuance
k.cdc.MustUnmarshal(reissuance, &reissuance_org)
reissuances = append(reissuances, reissuance_org)
var reissuanceOrg types.Reissuance
k.cdc.MustUnmarshal(reissuance, &reissuanceOrg)
reissuances = append(reissuances, reissuanceOrg)
}
return reissuances
}

View File

@ -1,10 +1,10 @@
package dao
func GetReissuanceCommand(asset_id string, BlockHeight int64) string {
return "reissueasset " + asset_id + " 99869000000"
func GetReissuanceCommand(assetID string, BlockHeight int64) string {
return "reissueasset " + assetID + " 99869000000"
}
func IsValidReissuanceCommand(reissuance_str string, asset_id string, BlockHeight int64) bool {
expected := "reissueasset " + asset_id + " 99869000000"
return reissuance_str == expected
func IsValidReissuanceCommand(reissuanceStr string, assetID string, BlockHeight int64) bool {
expected := "reissueasset " + assetID + " 99869000000"
return reissuanceStr == expected
}

View File

@ -74,12 +74,12 @@ func validateExtendedPublicKey(issuer string, cfg chaincfg.Params) bool {
return isValidExtendedPublicKey
}
func (k msgServer) issueNFTAsset(ctx sdk.Context, name string, machine_address string) (asset_id string, contract string, err error) {
func (k msgServer) issueNFTAsset(ctx sdk.Context, name string, machineAddress string) (assetID string, contract string, err error) {
conf := config.GetConfig()
logger := ctx.Logger()
cmdName := "poetry"
cmdArgs := []string{"run", "python", "issuer_service/issue2liquid.py", name, machine_address}
cmdArgs := []string{"run", "python", "issuer_service/issue2liquid.py", name, machineAddress}
// Create a new command
cmd := exec.Command(cmdName, cmdArgs...)
@ -100,22 +100,22 @@ func (k msgServer) issueNFTAsset(ctx sdk.Context, name string, machine_address s
} else {
lines := strings.Split(stdout.String(), "\n")
if len(lines) == 3 {
asset_id = lines[0]
assetID = lines[0]
contract = lines[1]
} else {
err = errorsmod.Wrap(types.ErrMachineNFTIssuanceNoOutput, stderr.String())
}
}
return asset_id, contract, err
return assetID, contract, err
}
func (k msgServer) issueMachineNFT(ctx sdk.Context, machine *types.Machine) error {
_, _, err := k.issueNFTAsset(ctx, machine.Name, machine.Address)
return err
// asset registration is not performed in case of NFT issuance for machines
//asset_id, contract, err := k.issueNFTAsset(machine.Name, machine.Address)
//assetID, contract, err := k.issueNFTAsset(machine.Name, machine.Address)
// if err != nil {
// return err
// }
//return k.registerAsset(asset_id, contract)
//return k.registerAsset(assetID, contract)
}

View File

@ -3,6 +3,7 @@ package keeper
import (
"encoding/hex"
"errors"
"github.com/planetmint/planetmint-go/x/machine/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
@ -18,21 +19,21 @@ func (k Keeper) StoreTrustAnchor(ctx sdk.Context, ta types.TrustAnchor, activate
} else {
appendValue = []byte{0}
}
pubKey_bytes, err := getTrustAnchorBytes(ta.Pubkey)
pubKeyBytes, err := getTrustAnchorBytes(ta.Pubkey)
if err != nil {
return errors.New("the given public key could not be decoded (malformed string)")
}
store.Set(pubKey_bytes, appendValue)
store.Set(pubKeyBytes, appendValue)
return nil
}
func (k Keeper) GetTrustAnchor(ctx sdk.Context, pubKey string) (val types.TrustAnchor, activated bool, found bool) {
store := prefix.NewStore(ctx.KVStore(k.taStoreKey), types.KeyPrefix(types.TrustAnchorKey))
pubKey_bytes, err := getTrustAnchorBytes(pubKey)
pubKeyBytes, err := getTrustAnchorBytes(pubKey)
if err != nil {
return val, false, false
}
trustAnchorActivated := store.Get(pubKey_bytes)
trustAnchorActivated := store.Get(pubKeyBytes)
if trustAnchorActivated == nil {
return val, false, false