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
@@ -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
@@ -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)
}
@@ -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) {
@@ -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()
}
@@ -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
}

0 comments on commit 3d79762

Please sign in to comment.