📢 Steem Go SDK Updates: Reputation Calculation Support
We're excited to announce updates to both steemutil (v0.0.16) and steemgosdk (v0.0.14) with new reputation calculation functionality!
📦 What's New
steemutil v0.0.16
Added RepLog10 function to the protocol package for converting raw Steem reputation values into a human-readable log10 format. This function implements the standard Steem reputation calculation algorithm used throughout the Steem ecosystem.
steemgosdk
Updated to use steemutil v0.0.16 and added comprehensive documentation and examples for reputation calculation.
✨ Features
- RepLog10 Function: Convert raw reputation integers to log10 format
- Edge Case Handling: Properly handles negative values and MinInt64 overflow
- Comprehensive Tests: Full test coverage including boundary conditions
- Easy Integration: Simple API that works seamlessly with existing code
🚀 Usage
Basic Example
package main
import (
"fmt"
"github.com/steemit/steemutil/protocol"
)
func main() {
// Raw reputation value from Steem blockchain
rawReputation := int64(10000000000)
// Convert to log10 format
repLog10 := protocol.RepLog10(rawReputation)
fmt.Printf("Raw Reputation: %d\n", rawReputation)
fmt.Printf("Reputation Score: %d\n", repLog10)
// Output:
// Raw Reputation: 10000000000
// Reputation Score: 1
}
With steemgosdk
package main
import (
"fmt"
"log"
"github.com/steemit/steemgosdk"
"github.com/steemit/steemutil/protocol"
)
func main() {
// Create client
client := steemgosdk.GetClient("https://api.steemit.com")
api := client.GetAPI()
// Get account information
result, err := api.Call("condenser_api", "get_accounts", []interface{}{
[]interface{}{"steemit"},
})
if err != nil {
log.Fatal(err)
}
// Extract reputation from result
// (Assuming you have parsed the account data)
// For demonstration, using a sample reputation value
rawReputation := int64(10000000000)
// Calculate reputation score
repLog10 := protocol.RepLog10(rawReputation)
fmt.Printf("Account: steemit\n")
fmt.Printf("Raw Reputation: %d\n", rawReputation)
fmt.Printf("Reputation Score (log10): %d\n", repLog10)
}
Handling Different Reputation Values
package main
import (
"fmt"
"github.com/steemit/steemutil/protocol"
)
func main() {
testCases := []struct {
name string
reputation int64
}{
{"New Account", 0},
{"Low Reputation", 1000000000}, // 1e9
{"Medium Reputation", 10000000000}, // 1e10
{"High Reputation", 100000000000}, // 1e11
{"Negative Reputation", -1000000000},
}
for _, tc := range testCases {
repLog10 := protocol.RepLog10(tc.reputation)
fmt.Printf("%s: Raw=%d, Score=%d\n", tc.name, tc.reputation, repLog10)
}
// Output:
// New Account: Raw=0, Score=0
// Low Reputation: Raw=1000000000, Score=0
// Medium Reputation: Raw=10000000000, Score=1
// High Reputation: Raw=100000000000, Score=2
// Negative Reputation: Raw=-1000000000, Score=0
}
📊 How It Works
The RepLog10 function converts raw reputation values using the formula:
repLog10 = log10(abs(reputation)) - 9
For negative reputation values, the result is negated. This matches the standard Steem reputation calculation used by steem-js and other Steem libraries.
Examples
| Raw Reputation | RepLog10 Score | Description |
|---|---|---|
| 0 | 0 | New account |
| 1,000,000,000 (1e9) | 0 | Baseline |
| 10,000,000,000 (1e10) | 1 | 10x baseline |
| 100,000,000,000 (1e11) | 2 | 100x baseline |
| -1,000,000,000 | 0 | Negative (handled correctly) |
🔧 Installation
Update steemutil
go get -u github.com/steemit/steemutil@v0.0.16
Update steemgosdk
go get -u github.com/steemit/steemgosdk@v0.0.14
Or update your go.mod:
require (
github.com/steemit/steemutil v0.0.16
github.com/steemit/steemgosdk v0.0.14
)
Then run:
go mod tidy
📝 API Reference
protocol.RepLog10(reputation int64) int64
Converts a raw Steem reputation value to log10 format.
Parameters:
reputation(int64): The raw reputation value from the Steem blockchain
Returns:
int64: The reputation score in log10 format
Special Cases:
- Returns
0for reputation value0 - Handles negative values correctly
- Safely handles
MinInt64overflow edge case
🧪 Testing
The implementation includes comprehensive test coverage:
- Zero reputation handling
- Positive reputation values
- Negative reputation values
- Edge cases (MinInt64, MaxInt64)
- Various magnitude values
All tests pass and the function is production-ready.
🔗 Links
- steemutil: https://github.com/steemit/steemutil
- steemgosdk: https://github.com/steemit/steemgosdk
🙏 Acknowledgments
This implementation is based on the standard Steem reputation calculation algorithm used throughout the Steem ecosystem, ensuring compatibility with other Steem libraries and tools.
Happy coding! 🚀
If you have any questions or feedback, please open an issue on GitHub.
Quality post, your effort really showed. Thanks for creating this👍
Upvoted! Thank you for supporting witness @jswit.