Skip to content

Commit 2943ce8

Browse files
authored
Git workflow && Tron proto updates (#145)
* update go version * update dependencies * add GitHub Actions workflow for running tests * fix tests * enhance gen-proto script && update tron proto * fix grpc insecure deprecated Dial * refactor command help handling and improve error handling in config saving * refactor error handling and replace ioutil with os package functions * refactor tests to remove unnecessary gRPC connection setup and improve error assertions * remove unused writeKeyFile function and delete plain keystore implementation * update go.mod, crypto.UnmarshalPubkey, add signature length validation * add CI targets for testing and linting in Makefile * add GitHub Actions workflows for build, format, and test processes * ci: add Git hooks for commit message validation and pre-commit checks * chore: add issue and pull requests templates * fix: install goimport in workflow * ci: update golangci-lint installation method in format workflow * feat: add methods to retrieve energy, bandwidth, and memo fee #134 - Tron TIP-586 * fix: remove unused parameter from UnDelegateResource method #109
1 parent 5b98b16 commit 2943ce8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+7030
-11950
lines changed

.githooks/commit-msg

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[0;33m'
8+
NC='\033[0m' # No Color
9+
10+
COMMIT_MSG_FILE=$1
11+
COMMIT_MSG=$(cat $COMMIT_MSG_FILE)
12+
13+
# Define regex patterns for commit message
14+
CONVENTIONAL_PATTERN='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .{1,100}'
15+
TICKET_PATTERN='(TRON-[0-9]+)'
16+
17+
# Check if commit message follows conventional commits pattern
18+
if ! [[ $COMMIT_MSG =~ $CONVENTIONAL_PATTERN ]]; then
19+
echo -e "${RED}Error:${NC} Commit message does not follow conventional commits format."
20+
echo -e "${YELLOW}Format:${NC} type(scope): description"
21+
echo -e "${YELLOW}Example:${NC} feat(cli): add new transaction command"
22+
echo -e "${YELLOW}Types:${NC} feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
23+
exit 1
24+
fi
25+
26+
# Warn if no ticket number is found (but don't block commit)
27+
if ! [[ $COMMIT_MSG =~ $TICKET_PATTERN ]]; then
28+
echo -e "${YELLOW}Warning:${NC} No TRON-XXX ticket number found in commit message."
29+
echo -e "${YELLOW}Consider:${NC} Including ticket number like TRON-123 in description or scope"
30+
fi
31+
32+
echo -e "${GREEN}${NC} Commit message format is valid"
33+
exit 0

.githooks/install.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
set -e
3+
4+
HOOK_DIR=$(git rev-parse --git-path hooks)
5+
REPO_ROOT=$(git rev-parse --show-toplevel)
6+
HOOKS_DIR="$REPO_ROOT/.githooks"
7+
8+
# Make sure hooks are executable
9+
chmod +x "$HOOKS_DIR/pre-commit"
10+
chmod +x "$HOOKS_DIR/commit-msg"
11+
chmod +x "$HOOKS_DIR/prepare-commit-msg"
12+
13+
# Create symlinks to hooks
14+
ln -sf "$HOOKS_DIR/pre-commit" "$HOOK_DIR/pre-commit"
15+
ln -sf "$HOOKS_DIR/commit-msg" "$HOOK_DIR/commit-msg"
16+
ln -sf "$HOOKS_DIR/prepare-commit-msg" "$HOOK_DIR/prepare-commit-msg"
17+
18+
echo "✅ Git hooks installed successfully!"
19+
echo "Pre-commit hook will run: format, lint and test on staged files"
20+
echo "Commit-msg hook will enforce conventional commit format"
21+
echo "Prepare-commit-msg hook will provide a commit message template"
22+
23+
# Check for required tools
24+
echo "Checking required tools..."
25+
26+
if ! command -v goimports &> /dev/null; then
27+
echo "⚠️ goimports not found. Please install with:"
28+
echo " go install golang.org/x/tools/cmd/goimports@latest"
29+
fi
30+
31+
if ! command -v golangci-lint &> /dev/null; then
32+
echo "⚠️ golangci-lint not found. Please install with:"
33+
echo " curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin"
34+
fi

.githooks/pre-commit

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "==> Running pre-commit checks..."
5+
6+
# Get staged Go files
7+
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' | grep -v '\.pb\.go$' || true)
8+
9+
# Skip if no Go files are staged
10+
if [ -z "$STAGED_GO_FILES" ]; then
11+
echo "No Go files staged. Skipping pre-commit checks."
12+
exit 0
13+
fi
14+
15+
# Check for goimports
16+
if ! command -v goimports &> /dev/null; then
17+
echo "goimports not found! Please install with:"
18+
echo "go install golang.org/x/tools/cmd/goimports@latest"
19+
exit 1
20+
fi
21+
22+
# Check for golangci-lint
23+
if ! command -v golangci-lint &> /dev/null; then
24+
echo "golangci-lint not found! Please install with:"
25+
echo "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin"
26+
exit 1
27+
fi
28+
29+
# Format imports
30+
echo "Running goimports..."
31+
make goimports
32+
33+
# Run go mod tidy
34+
echo "Checking go.mod and go.sum..."
35+
go mod tidy
36+
if [ -n "$(git status --porcelain go.mod go.sum)" ]; then
37+
echo "go.mod or go.sum was modified. Please stage the changes."
38+
git status --porcelain go.mod go.sum
39+
exit 1
40+
fi
41+
42+
# Run linter on staged files
43+
echo "Running linter on staged files..."
44+
STAGED_FILES_ARGS=$(echo "$STAGED_GO_FILES" | tr '\n' ' ')
45+
golangci-lint run --fast $STAGED_FILES_ARGS
46+
47+
# Run tests affected by staged files
48+
echo "Running relevant tests..."
49+
# Parse package names from staged files
50+
STAGED_PACKAGES=$(echo "$STAGED_GO_FILES" | xargs -I{} dirname {} | sort -u)
51+
52+
# Run tests only for affected packages
53+
for pkg in $STAGED_PACKAGES; do
54+
if [ -n "$(find $pkg -name '*_test.go' -type f | head -1)" ]; then
55+
echo "Testing package: $pkg"
56+
go test -race ./$pkg
57+
fi
58+
done
59+
60+
echo "✅ Pre-commit checks passed"
61+
exit 0

.githooks/prepare-commit-msg

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
COMMIT_MSG_FILE=$1
4+
COMMIT_SOURCE=$2
5+
SHA1=$3
6+
7+
# Only add template if this is not from a merge, amend, etc.
8+
if [ -z "$COMMIT_SOURCE" ]; then
9+
# Check if the commit message already has content (non-commented lines)
10+
if ! grep -q '^[^#]' "$COMMIT_MSG_FILE"; then
11+
# Get the current branch name
12+
BRANCH_NAME=$(git symbolic-ref --short HEAD 2>/dev/null)
13+
14+
# Extract ticket number from branch name if it follows pattern like feature/TRON-123-description
15+
TICKET=""
16+
if [[ $BRANCH_NAME =~ (TRON-[0-9]+) ]]; then
17+
TICKET=${BASH_REMATCH[1]}
18+
fi
19+
20+
# Add commit message template
21+
cat > "$COMMIT_MSG_FILE" << EOF
22+
# Select commit type and add optional scope and description
23+
# Format: type(scope): description
24+
# Example: feat(cli): add new transaction feature
25+
# Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
26+
#
27+
# If applicable, include the TRON ticket number in scope or description
28+
# Current branch: $BRANCH_NAME
29+
EOF
30+
31+
# If we found a ticket number in the branch name, add it to the template
32+
if [ -n "$TICKET" ]; then
33+
echo "feat($TICKET): " > "$COMMIT_MSG_FILE.tmp"
34+
cat "$COMMIT_MSG_FILE" >> "$COMMIT_MSG_FILE.tmp"
35+
mv "$COMMIT_MSG_FILE.tmp" "$COMMIT_MSG_FILE"
36+
fi
37+
fi
38+
fi

.github/ISSUE_TEMPLATE/SECURITY.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
The following versions of gotron-sdk are currently being supported with security updates:
6+
7+
| Version | Supported |
8+
| ------- | ------------------ |
9+
| 2.3.x | :white_check_mark: |
10+
| 2.2.x | :white_check_mark: |
11+
| 2.1.x | :x: |
12+
| < 2.0 | :x: |
13+
14+
## Reporting a Vulnerability
15+
16+
We take the security of gotron-sdk seriously. If you believe you've found a security vulnerability, please follow these steps:
17+
18+
1. **Do not disclose the vulnerability publicly**
19+
2. **Email us directly** at security@cryptochain.network
20+
3. **Include the following information**:
21+
- A description of the vulnerability
22+
- Steps to reproduce the issue
23+
- Potential impact of the vulnerability
24+
- If possible, a suggested fix or mitigation
25+
26+
## What to expect
27+
28+
- We will acknowledge receipt of your vulnerability report within 3 business days
29+
- We will provide an initial assessment of the report within 10 business days
30+
- We will keep you informed about our progress throughout the process
31+
- We will notify you when the issue is fixed
32+
33+
Thank you for helping keep gotron-sdk and its users safe!

.github/ISSUE_TEMPLATE/bug_report.md

Whitespace-only changes.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: TRON SDK Documentation
4+
url: https://github.com/fbsobreira/gotron-sdk/wiki
5+
about: Check if your question is answered in the documentation.
6+
- name: TRON Network Documentation
7+
url: https://developers.tron.network/
8+
about: Learn more about TRON network specifications and APIs.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: '[FEATURE] '
5+
labels: enhancement
6+
assignees: ''
7+
---
8+
9+
## Is your feature request related to a problem? Please describe.
10+
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
11+
12+
## Describe the solution you'd like
13+
<!-- A clear and concise description of what you want to happen. -->
14+
15+
## Describe alternatives you've considered
16+
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
17+
18+
## API Design (if applicable)
19+
<!-- If this feature involves new API methods, please describe the proposed function signatures. -->
20+
```go
21+
// Example API design
22+
func NewFeature(param1 string, param2 int) (Result, error) {
23+
// Description of what this would do
24+
}
25+
```
26+
27+
## Ticket
28+
<!-- If there's a related ticket, please reference it here -->
29+
TRON-
30+
31+
## Additional context
32+
<!-- Add any other context or screenshots about the feature request here. -->

.github/ISSUE_TEMPLATE/question.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Question
3+
about: Ask a question about using this SDK
4+
title: '[QUESTION] '
5+
labels: question
6+
assignees: ''
7+
---
8+
9+
## Question
10+
<!-- Ask your question clearly and provide as much context as possible -->
11+
12+
## Context
13+
<!-- Describe what you're trying to accomplish and what you've tried so far -->
14+
15+
## Environment
16+
- OS: [e.g. Ubuntu 22.04, macOS 13.0, Windows 11]
17+
- Go version: [e.g. 1.20.4]
18+
- TRON node version:
19+
- SDK version: [e.g. v2.3.0]
20+
21+
## Code Example
22+
<!-- If applicable, provide code samples related to your question -->
23+
```go
24+
// Your code here
25+
```
26+
27+
## Additional Information
28+
<!-- Add any other context about your question here -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Description
2+
3+
<!-- Please include a summary of the changes and which issue is fixed. -->
4+
<!-- Also include relevant motivation and context. -->
5+
6+
Fixes # (issue)
7+
8+
## Type of change
9+
10+
<!-- Please delete options that are not relevant. -->
11+
12+
- [ ] Bug fix (non-breaking change which fixes an issue)
13+
- [ ] New feature (non-breaking change which adds functionality)
14+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
15+
- [ ] This change requires a documentation update
16+
- [ ] Refactoring (no functional changes, no API changes)
17+
- [ ] Performance improvement
18+
19+
## Ticket
20+
21+
<!-- Please add the ticket number (if any) related to this PR (e.g., TRON-123) -->
22+
TRON-
23+
24+
## How Has This Been Tested?
25+
26+
<!-- Please describe the tests that you ran to verify your changes. -->
27+
<!-- Provide instructions so we can reproduce. -->
28+
29+
- [ ] Unit tests
30+
- [ ] Integration tests
31+
- [ ] Manual tests (please describe below)
32+
33+
## Checklist:
34+
35+
- [ ] My code follows the style guidelines of this project
36+
- [ ] I have performed a self-review of my code
37+
- [ ] I have commented my code, particularly in hard-to-understand areas
38+
- [ ] I have made corresponding changes to the documentation
39+
- [ ] My changes generate no new warnings
40+
- [ ] I have added tests that prove my fix is effective or that my feature works
41+
- [ ] New and existing unit tests pass locally with my changes
42+
- [ ] Any dependent changes have been merged and published

0 commit comments

Comments
 (0)