diff --git a/.golangci.yaml b/.golangci.yaml index d71a776..2374a5c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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 diff --git a/util/determine_block_proposer.go b/util/determine_block_proposer.go index a24a200..bb79ec5 100644 --- a/util/determine_block_proposer.go +++ b/util/determine_block_proposer.go @@ -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 } diff --git a/util/elementsd_connector.go b/util/elementsd_connector.go index 9c30f8e..0c2f482 100644 --- a/util/elementsd_connector.go +++ b/util/elementsd_connector.go @@ -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 diff --git a/util/issue_commands.go b/util/issue_commands.go index 6ff4aae..f4c41fa 100644 --- a/util/issue_commands.go +++ b/util/issue_commands.go @@ -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 diff --git a/util/validate_signature.go b/util/validate_signature.go index 91f0ad8..bcf955f 100644 --- a/util/validate_signature.go +++ b/util/validate_signature.go @@ -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 } diff --git a/x/asset/keeper/asset.go b/x/asset/keeper/asset.go index 1ba7bb9..4d92349 100644 --- a/x/asset/keeper/asset.go +++ b/x/asset/keeper/asset.go @@ -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 diff --git a/x/asset/keeper/msg_server_test.go b/x/asset/keeper/msg_server_test.go index a50846a..c002df1 100644 --- a/x/asset/keeper/msg_server_test.go +++ b/x/asset/keeper/msg_server_test.go @@ -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) diff --git a/x/dao/abci.go b/x/dao/abci.go index 90f3117..414601b 100644 --- a/x/dao/abci.go +++ b/x/dao/abci.go @@ -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) } diff --git a/x/dao/keeper/msg_server_reissue_rddl_proposal.go b/x/dao/keeper/msg_server_reissue_rddl_proposal.go index 4f2c8a2..2e6aaf0 100644 --- a/x/dao/keeper/msg_server_reissue_rddl_proposal.go +++ b/x/dao/keeper/msg_server_reissue_rddl_proposal.go @@ -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") diff --git a/x/dao/keeper/reissuance.go b/x/dao/keeper/reissuance.go index 42a234d..d690679 100644 --- a/x/dao/keeper/reissuance.go +++ b/x/dao/keeper/reissuance.go @@ -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 } diff --git a/x/dao/util.go b/x/dao/util.go index 77b9166..1f17fd7 100644 --- a/x/dao/util.go +++ b/x/dao/util.go @@ -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 } diff --git a/x/machine/keeper/msg_server_attest_machine.go b/x/machine/keeper/msg_server_attest_machine.go index 71599d3..44f19a8 100644 --- a/x/machine/keeper/msg_server_attest_machine.go +++ b/x/machine/keeper/msg_server_attest_machine.go @@ -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) } diff --git a/x/machine/keeper/trust_anchor.go b/x/machine/keeper/trust_anchor.go index 691088a..993df7b 100644 --- a/x/machine/keeper/trust_anchor.go +++ b/x/machine/keeper/trust_anchor.go @@ -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