mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
WeiToGwei copy input big.int (#12370)
This commit is contained in:
@@ -214,11 +214,13 @@ func AddInt(i ...int) (int, error) {
|
||||
}
|
||||
|
||||
// WeiToGwei converts big int wei to uint64 gwei.
|
||||
// The input `v` is copied before being modified.
|
||||
func WeiToGwei(v *big.Int) uint64 {
|
||||
if v == nil {
|
||||
return 0
|
||||
}
|
||||
gweiPerEth := big.NewInt(1e9)
|
||||
v.Div(v, gweiPerEth)
|
||||
return v.Uint64()
|
||||
copied := big.NewInt(0).Set(v)
|
||||
copied.Div(copied, gweiPerEth)
|
||||
return copied.Uint64()
|
||||
}
|
||||
|
||||
@@ -567,3 +567,11 @@ func TestWeiToGwei(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiToGwei_CopyOk(t *testing.T) {
|
||||
v := big.NewInt(1e9)
|
||||
got := math.WeiToGwei(v)
|
||||
|
||||
require.Equal(t, uint64(1), got)
|
||||
require.Equal(t, big.NewInt(1e9).Uint64(), v.Uint64())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user