Permalink
Browse files

Fix compatibility with go-ethereum/common package

  • Loading branch information...
sammy007 committed Mar 4, 2017
1 parent ab812d5 commit 3d797622322c690b94a40342a16818d540d29012
Showing with 23 additions and 15 deletions.
  1. +3 −4 payouts/payer.go
  2. +5 −5 payouts/unlocker.go
  3. +1 −1 rpc/rpc.go
  4. +1 −2 storage/redis.go
  5. +13 −3 util/util.go
View
@@ -8,7 +8,6 @@ import (
"strconv"
"time"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/sammy007/open-ethereum-pool/rpc"
@@ -34,12 +33,12 @@ type PayoutsConfig struct {
}
func (self PayoutsConfig) GasHex() string {
- x := common.String2Big(self.Gas)
+ x := util.String2Big(self.Gas)
return hexutil.EncodeBig(x)
}
func (self PayoutsConfig) GasPriceHex() string {
- x := common.String2Big(self.GasPrice)
+ x := util.String2Big(self.GasPrice)
return hexutil.EncodeBig(x)
}
@@ -122,7 +121,7 @@ func (u *PayoutsProcessor) process() {
amountInShannon := big.NewInt(amount)
// Shannon^2 = Wei
- amountInWei := new(big.Int).Mul(amountInShannon, common.Shannon)
+ amountInWei := new(big.Int).Mul(amountInShannon, util.Shannon)
if !u.reachedThreshold(amountInShannon) {
continue
View
@@ -8,7 +8,7 @@ import (
"strings"
"time"
- "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/math"
"github.com/sammy007/open-ethereum-pool/rpc"
"github.com/sammy007/open-ethereum-pool/storage"
@@ -30,7 +30,7 @@ type UnlockerConfig struct {
const minDepth = 16
-var constReward = common.Big("5000000000000000000")
+var constReward = math.MustParseBig256("5000000000000000000")
var uncleReward = new(big.Int).Div(constReward, new(big.Int).SetInt64(32))
// Donate 10% from pool fees to developers
@@ -490,7 +490,7 @@ func chargeFee(value *big.Rat, fee float64) (*big.Rat, *big.Rat) {
}
func weiToShannonInt64(wei *big.Rat) int64 {
- shannon := new(big.Rat).SetInt(common.Shannon)
+ shannon := new(big.Rat).SetInt(util.Shannon)
inShannon := new(big.Rat).Quo(wei, shannon)
value, _ := strconv.ParseInt(inShannon.FloatString(0), 10, 64)
return value
@@ -512,8 +512,8 @@ func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int,
return nil, err
}
if receipt != nil {
- gasUsed := common.String2Big(receipt.GasUsed)
- gasPrice := common.String2Big(tx.GasPrice)
+ gasUsed := util.String2Big(receipt.GasUsed)
+ gasPrice := util.String2Big(tx.GasPrice)
fee := new(big.Int).Mul(gasUsed, gasPrice)
amount.Add(amount, fee)
}
View
@@ -161,7 +161,7 @@ func (r *RPCClient) GetBalance(address string) (*big.Int, error) {
if err != nil {
return nil, err
}
- return common.String2Big(reply), err
+ return util.String2Big(reply), err
}
func (r *RPCClient) Sign(from string, s string) (string, error) {
View
@@ -7,7 +7,6 @@ import (
"strings"
"time"
- "github.com/ethereum/go-ethereum/common"
"gopkg.in/redis.v3"
"github.com/sammy007/open-ethereum-pool/util"
@@ -47,7 +46,7 @@ type BlockData struct {
}
func (b *BlockData) RewardInShannon() int64 {
- reward := new(big.Int).Div(b.Reward, common.Shannon)
+ reward := new(big.Int).Div(b.Reward, util.Shannon)
return reward.Int64()
}
View
@@ -7,9 +7,13 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/math"
)
-var pow256 = common.BigPow(2, 256)
+var Ether = math.BigPow(10, 18)
+var Shannon = math.BigPow(10, 9)
+
+var pow256 = math.BigPow(2, 256)
var addressPattern = regexp.MustCompile("^0x[0-9a-fA-F]{40}$")
var zeroHash = regexp.MustCompile("^0?x?0+$")
@@ -36,7 +40,7 @@ func GetTargetHex(diff int64) string {
func TargetHexToDiff(targetHex string) *big.Int {
targetBytes := common.FromHex(targetHex)
- return new(big.Int).Div(pow256, common.BytesToBig(targetBytes))
+ return new(big.Int).Div(pow256, new(big.Int).SetBytes(targetBytes))
}
func ToHex(n int64) string {
@@ -48,7 +52,7 @@ func FormatReward(reward *big.Int) string {
}
func FormatRatReward(reward *big.Rat) string {
- wei := new(big.Rat).SetInt(common.Ether)
+ wei := new(big.Rat).SetInt(Ether)
reward = reward.Quo(reward, wei)
return reward.FloatString(8)
}
@@ -69,3 +73,9 @@ func MustParseDuration(s string) time.Duration {
}
return value
}
+
+func String2Big(num string) *big.Int {
+ n := new(big.Int)
+ n.SetString(num, 0)
+ return n
+}

2 comments on commit 3d79762

@netzulo

This comment has been minimized.

Show comment
Hide comment
@netzulo

netzulo May 31, 2017

really i didn't know how i can talk with you @sammy007

  1. can pool be functional for CPUmining , works now with CPU mining? ( yes or not it's enought )
  2. im mining alone on my pool, wanted to be added here, but i can't contact with you. my pool forked yours ! :) http://ntz-crypto.tk

really i didn't know how i can talk with you @sammy007

  1. can pool be functional for CPUmining , works now with CPU mining? ( yes or not it's enought )
  2. im mining alone on my pool, wanted to be added here, but i can't contact with you. my pool forked yours ! :) http://ntz-crypto.tk
@sammy007

This comment has been minimized.

Show comment
Hide comment
@sammy007

sammy007 Jun 3, 2017

Owner

Hi. CPU mining is inefficient for ethereum.

Owner

sammy007 replied Jun 3, 2017

Hi. CPU mining is inefficient for ethereum.

Please sign in to comment.