[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 - gosimple
- govet - govet
- ineffassign - ineffassign
- nosnakecase
- staticcheck - staticcheck
- unused - 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 { func IsValidatorBlockProposer(ctx sdk.Context, proposerAddress []byte) bool {
validator_identity, valid_result := GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := GetValidatorCometBFTIdentity(ctx)
if !valid_result { if !validResult {
return false return false
} }
hexProposerAddress := hex.EncodeToString(proposerAddress) hexProposerAddress := hex.EncodeToString(proposerAddress)
return hexProposerAddress == validator_identity return hexProposerAddress == validatorIdentity
} }

View File

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

View File

@ -10,15 +10,15 @@ import (
"github.com/planetmint/planetmint-go/config" "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 //get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
logger := ctx.Logger() logger := ctx.Logger()
// Construct the command // Construct the command
sending_validator_address := config.GetConfig().ValidatorAddress sendingValidatorAddress := config.GetConfig().ValidatorAddress
logger.Debug("REISSUE: create Proposal") logger.Debug("REISSUE: create Proposal")
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal", cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal",
"--from", sending_validator_address, "-y", "--from", sendingValidatorAddress, "-y",
proposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10)) proposerAddress, txUnsigned, strconv.FormatInt(blockHeight, 10))
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout cmd.Stdout = &stdout
@ -35,14 +35,14 @@ func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsig
return err 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() logger := ctx.Logger()
// Construct the command // Construct the command
sending_validator_address := config.GetConfig().ValidatorAddress sendingValidatorAddress := config.GetConfig().ValidatorAddress
logger.Debug("REISSUE: create Result") logger.Debug("REISSUE: create Result")
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result", cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result",
"--from", sending_validator_address, "-y", "--from", sendingValidatorAddress, "-y",
proposerAddress, txID, strconv.FormatInt(blk_height, 10)) proposerAddress, txID, strconv.FormatInt(blockHeight, 10))
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout 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) { func GetHexPubKey(extPubKey string) (string, error) {
xpubKey, err := hdkeychain.NewKeyFromString(ext_pub_key) xpubKey, err := hdkeychain.NewKeyFromString(extPubKey)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -49,6 +49,6 @@ func GetHexPubKey(ext_pub_key string) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
byte_key := pubKey.SerializeCompressed() byteKey := pubKey.SerializeCompressed()
return hex.EncodeToString(byte_key), nil 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) { 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)) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
creator_bytes := store.Get(GetAssetCIDBytes(cid)) creatorBytes := store.Get(GetAssetCIDBytes(cid))
if creator_bytes == nil { if creatorBytes == nil {
return msg, false return msg, false
} }
msg.Cid = cid msg.Cid = cid
msg.Creator = string(creator_bytes) msg.Creator = string(creatorBytes)
return msg, true return msg, true
} }
@ -29,11 +29,11 @@ func (k Keeper) GetCidsByAddress(ctx sdk.Context, address string) (cids []string
reverseIterator := store.ReverseIterator(nil, nil) reverseIterator := store.ReverseIterator(nil, nil)
defer reverseIterator.Close() defer reverseIterator.Close()
for ; reverseIterator.Valid(); reverseIterator.Next() { for ; reverseIterator.Valid(); reverseIterator.Next() {
address_bytes := reverseIterator.Value() addressBytes := reverseIterator.Value()
cid_bytes := reverseIterator.Key() cidBytes := reverseIterator.Key()
if string(address_bytes) == address { if string(addressBytes) == address {
cids = append(cids, string(cid_bytes)) cids = append(cids, string(cidBytes))
} }
} }
return cids, len(cids) > 0 return cids, len(cids) > 0

View File

@ -29,11 +29,11 @@ func TestMsgServer(t *testing.T) {
} }
func TestMsgServerNotarizeAsset(t *testing.T) { func TestMsgServerNotarizeAsset(t *testing.T) {
ext_sk, _ := sample.ExtendedKeyPair(config.PlmntNetParams) extSk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
xskKey, _ := hdkeychain.NewKeyFromString(ext_sk) xskKey, _ := hdkeychain.NewKeyFromString(extSk)
privKey, _ := xskKey.ECPrivKey() privKey, _ := xskKey.ECPrivKey()
byte_key := privKey.Serialize() byteKey := privKey.Serialize()
sk := hex.EncodeToString(byte_key) sk := hex.EncodeToString(byteKey)
cid := sample.Asset() cid := sample.Asset()
msg := types.NewMsgNotarizeAsset(sk, cid) 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") logger.Info("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress) hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig() conf := config.GetConfig()
tx_unsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight) txUnsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, tx_unsigned, blockHeight) err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil { if err != nil {
logger.Error("error while initializing RDDL issuance", err) 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) ctx := sdk.UnwrapSDKContext(goCtx)
logger := ctx.Logger() logger := ctx.Logger()
validator_identity, valid_result := util.GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
if valid_result && msg.Proposer == validator_identity { if validResult && msg.Proposer == validatorIdentity {
// 1. sign tx // 1. sign tx
// 2. broadcast tx // 2. broadcast tx
logger.Debug("REISSUE: Asset") 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 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)) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
iterator := store.Iterator(nil, nil) 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() { for ; iterator.Valid(); iterator.Next() {
reissuance := iterator.Value() reissuance := iterator.Value()
var reissuance_org types.Reissuance var reissuanceOrg types.Reissuance
k.cdc.MustUnmarshal(reissuance, &reissuance_org) k.cdc.MustUnmarshal(reissuance, &reissuanceOrg)
reissuances = append(reissuances, reissuance_org) reissuances = append(reissuances, reissuanceOrg)
} }
return reissuances return reissuances
} }

View File

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

View File

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

View File

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