From c7e73ba12d747186002433db54d002ab43bed171 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 25 Feb 2014 11:20:24 +0100 Subject: Added currency converting --- ethutil/common.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ethutil/common.go (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go new file mode 100644 index 000000000..07df6bb13 --- /dev/null +++ b/ethutil/common.go @@ -0,0 +1,35 @@ +package ethutil + +import ( + "fmt" + "math/big" +) + +var ( + Ether = BigPow(10, 18) + Finney = BigPow(10, 15) + Szabo = BigPow(10, 12) + Vito = BigPow(10, 9) + Turing = BigPow(10, 6) + Eins = BigPow(10, 3) + Wei = big.NewInt(1) +) + +func CurrencyToString(num *big.Int) string { + switch { + case num.Cmp(Ether) >= 0: + return fmt.Sprintf("%v Ether", new(big.Int).Div(num, Ether)) + case num.Cmp(Finney) >= 0: + return fmt.Sprintf("%v Finney", new(big.Int).Div(num, Finney)) + case num.Cmp(Szabo) >= 0: + return fmt.Sprintf("%v Szabo", new(big.Int).Div(num, Szabo)) + case num.Cmp(Vito) >= 0: + return fmt.Sprintf("%v Vito", new(big.Int).Div(num, Vito)) + case num.Cmp(Turing) >= 0: + return fmt.Sprintf("%v Turing", new(big.Int).Div(num, Turing)) + case num.Cmp(Eins) >= 0: + return fmt.Sprintf("%v Eins", new(big.Int).Div(num, Eins)) + } + + return fmt.Sprintf("%v Wei", num) +} -- cgit From 01c1bce9c5dfa2b2bcdf934afec3f206823f895f Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 21 Mar 2014 18:22:47 +0100 Subject: Removed regular ints from the virtual machine and closures --- ethutil/common.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index 07df6bb13..f15b10e6d 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -33,3 +33,9 @@ func CurrencyToString(num *big.Int) string { return fmt.Sprintf("%v Wei", num) } + +var ( + Big1 = big.NewInt(1) + Big0 = big.NewInt(0) + Big256 = big.NewInt(0xff) +) -- cgit From e0b6091d7ef709902f534c1a4b57151f0171e03c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 24 Mar 2014 13:20:34 +0100 Subject: Test fixes and removed old code. Added VM gas fees --- ethutil/common.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index f15b10e6d..c63af29a6 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -36,6 +36,7 @@ func CurrencyToString(num *big.Int) string { var ( Big1 = big.NewInt(1) + Big2 = big.NewInt(1) Big0 = big.NewInt(0) Big256 = big.NewInt(0xff) ) -- cgit From 16e52327a4baa5547c38965fce53b3ff40b98173 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 16:50:44 +0200 Subject: Upped version number --- ethutil/common.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index c63af29a6..d0ee7b538 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -38,5 +38,12 @@ var ( Big1 = big.NewInt(1) Big2 = big.NewInt(1) Big0 = big.NewInt(0) + Big32 = big.NewInt(32) Big256 = big.NewInt(0xff) ) + +func CreateAddress(b []byte, nonce *big.Int) []byte { + addrBytes := append(b, nonce.Bytes()...) + + return Sha3Bin(addrBytes)[12:] +} -- cgit From 338b6980915c990c6e6287a7249ddd98e6be20eb Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 17:15:44 +0200 Subject: Refactoring and added documentation comments --- ethutil/common.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index d0ee7b538..983ea5d1b 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -5,16 +5,20 @@ import ( "math/big" ) +// The different number of units var ( Ether = BigPow(10, 18) Finney = BigPow(10, 15) Szabo = BigPow(10, 12) - Vito = BigPow(10, 9) + Vita = BigPow(10, 9) Turing = BigPow(10, 6) Eins = BigPow(10, 3) Wei = big.NewInt(1) ) +// Currency to string +// +// Returns a string representing a human readable format func CurrencyToString(num *big.Int) string { switch { case num.Cmp(Ether) >= 0: @@ -23,8 +27,8 @@ func CurrencyToString(num *big.Int) string { return fmt.Sprintf("%v Finney", new(big.Int).Div(num, Finney)) case num.Cmp(Szabo) >= 0: return fmt.Sprintf("%v Szabo", new(big.Int).Div(num, Szabo)) - case num.Cmp(Vito) >= 0: - return fmt.Sprintf("%v Vito", new(big.Int).Div(num, Vito)) + case num.Cmp(Vita) >= 0: + return fmt.Sprintf("%v Vita", new(big.Int).Div(num, Vita)) case num.Cmp(Turing) >= 0: return fmt.Sprintf("%v Turing", new(big.Int).Div(num, Turing)) case num.Cmp(Eins) >= 0: @@ -34,6 +38,7 @@ func CurrencyToString(num *big.Int) string { return fmt.Sprintf("%v Wei", num) } +// Common big integers often used var ( Big1 = big.NewInt(1) Big2 = big.NewInt(1) @@ -42,6 +47,7 @@ var ( Big256 = big.NewInt(0xff) ) +// Creates an ethereum address given the bytes and the nonce func CreateAddress(b []byte, nonce *big.Int) []byte { addrBytes := append(b, nonce.Bytes()...) -- cgit From 31e44c2ab959124cbcf2de45385373b9898727bc Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 20 May 2014 14:53:34 +0200 Subject: Change shorthands --- ethutil/common.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index 983ea5d1b..771dfc723 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -7,13 +7,13 @@ import ( // The different number of units var ( - Ether = BigPow(10, 18) - Finney = BigPow(10, 15) - Szabo = BigPow(10, 12) - Vita = BigPow(10, 9) - Turing = BigPow(10, 6) - Eins = BigPow(10, 3) - Wei = big.NewInt(1) + Ether = BigPow(10, 18) + Finney = BigPow(10, 15) + Szabo = BigPow(10, 12) + Shannon = BigPow(10, 9) + Babbage = BigPow(10, 6) + Ada = BigPow(10, 3) + Wei = big.NewInt(1) ) // Currency to string @@ -27,12 +27,12 @@ func CurrencyToString(num *big.Int) string { return fmt.Sprintf("%v Finney", new(big.Int).Div(num, Finney)) case num.Cmp(Szabo) >= 0: return fmt.Sprintf("%v Szabo", new(big.Int).Div(num, Szabo)) - case num.Cmp(Vita) >= 0: - return fmt.Sprintf("%v Vita", new(big.Int).Div(num, Vita)) - case num.Cmp(Turing) >= 0: - return fmt.Sprintf("%v Turing", new(big.Int).Div(num, Turing)) - case num.Cmp(Eins) >= 0: - return fmt.Sprintf("%v Eins", new(big.Int).Div(num, Eins)) + case num.Cmp(Shannon) >= 0: + return fmt.Sprintf("%v Shannon", new(big.Int).Div(num, Shannon)) + case num.Cmp(Babbage) >= 0: + return fmt.Sprintf("%v Babbage", new(big.Int).Div(num, Babbage)) + case num.Cmp(Ada) >= 0: + return fmt.Sprintf("%v Ada", new(big.Int).Div(num, Ada)) } return fmt.Sprintf("%v Wei", num) -- cgit From 1153fd9a0c9310ab70f9b20914071e0184e8020a Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 6 Jun 2014 12:12:27 +0200 Subject: Added Douglas and Einstan --- ethutil/common.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index 771dfc723..c7973eb92 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -7,13 +7,15 @@ import ( // The different number of units var ( - Ether = BigPow(10, 18) - Finney = BigPow(10, 15) - Szabo = BigPow(10, 12) - Shannon = BigPow(10, 9) - Babbage = BigPow(10, 6) - Ada = BigPow(10, 3) - Wei = big.NewInt(1) + Douglas = BigPow(10, 42) + Einstein = BigPow(10, 21) + Ether = BigPow(10, 18) + Finney = BigPow(10, 15) + Szabo = BigPow(10, 12) + Shannon = BigPow(10, 9) + Babbage = BigPow(10, 6) + Ada = BigPow(10, 3) + Wei = big.NewInt(1) ) // Currency to string @@ -21,6 +23,10 @@ var ( // Returns a string representing a human readable format func CurrencyToString(num *big.Int) string { switch { + case num.Cmp(Douglas) >= 0: + return fmt.Sprintf("%v Douglas", new(big.Int).Div(num, Douglas)) + case num.Cmp(Einstein) >= 0: + return fmt.Sprintf("%v Einstein", new(big.Int).Div(num, Einstein)) case num.Cmp(Ether) >= 0: return fmt.Sprintf("%v Ether", new(big.Int).Div(num, Ether)) case num.Cmp(Finney) >= 0: -- cgit From 97cc76214350b3ef9b0c15f53d06c684e01ede37 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 11 Jun 2014 10:28:18 +0200 Subject: Expose GasLimit to ethPub --- ethutil/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index c7973eb92..ddaf78f88 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -18,8 +18,8 @@ var ( Wei = big.NewInt(1) ) -// Currency to string // +// Currency to string // Returns a string representing a human readable format func CurrencyToString(num *big.Int) string { switch { -- cgit From 81245473486dd680b7121d4b227ca8a57d07b4b1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 13 Jun 2014 16:06:27 +0200 Subject: Moving a head closer to interop --- ethutil/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index ddaf78f88..f63ba5d83 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -47,7 +47,7 @@ func CurrencyToString(num *big.Int) string { // Common big integers often used var ( Big1 = big.NewInt(1) - Big2 = big.NewInt(1) + Big2 = big.NewInt(2) Big0 = big.NewInt(0) Big32 = big.NewInt(32) Big256 = big.NewInt(0xff) -- cgit From e3b911652dfba1475001137ba8b3687b9fec5331 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 16:08:33 +0100 Subject: move CreateAddress from ethutil/common to ethcrypto --- ethutil/common.go | 7 ------- 1 file changed, 7 deletions(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index f63ba5d83..6d88a1ed2 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -52,10 +52,3 @@ var ( Big32 = big.NewInt(32) Big256 = big.NewInt(0xff) ) - -// Creates an ethereum address given the bytes and the nonce -func CreateAddress(b []byte, nonce *big.Int) []byte { - addrBytes := append(b, nonce.Bytes()...) - - return Sha3Bin(addrBytes)[12:] -} -- cgit From 8845fb7eae3e51fd3e55c47c377bf1a9e0cfe2a9 Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 14 Jul 2014 15:24:38 +0200 Subject: Add windows helper functions --- ethutil/common.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index 6d88a1ed2..2fd031a20 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -3,8 +3,20 @@ package ethutil import ( "fmt" "math/big" + "runtime" ) +func IsWindows() bool { + return runtime.GOOS == "windows" +} + +func WindonizePath(path string) string { + if string(path[0]) == "/" && IsWindows() { + path = path[1:] + } + return path +} + // The different number of units var ( Douglas = BigPow(10, 42) -- cgit From 20ee1ae65e57ef7d60404277162c84c572c6bb10 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 21 Jul 2014 20:38:43 +0200 Subject: Refactored CALLDATALOAD to use big int * Added BigMin --- ethutil/common.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index 2fd031a20..cbd94e7ad 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -58,9 +58,11 @@ func CurrencyToString(num *big.Int) string { // Common big integers often used var ( - Big1 = big.NewInt(1) - Big2 = big.NewInt(2) - Big0 = big.NewInt(0) - Big32 = big.NewInt(32) - Big256 = big.NewInt(0xff) + Big1 = big.NewInt(1) + Big2 = big.NewInt(2) + Big0 = big.NewInt(0) + BigTrue = Big1 + BigFalse = Big0 + Big32 = big.NewInt(32) + Big256 = big.NewInt(0xff) ) -- cgit From 793e666f36e512bceb0d92d0a8dfe1d7c508c0e2 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 17 Aug 2014 12:42:32 +0200 Subject: Dump bytes instead of strings --- ethutil/common.go | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index cbd94e7ad..8532d80f2 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -34,26 +34,43 @@ var ( // Currency to string // Returns a string representing a human readable format func CurrencyToString(num *big.Int) string { + var ( + fin *big.Int = num + denom string = "Wei" + ) + switch { case num.Cmp(Douglas) >= 0: - return fmt.Sprintf("%v Douglas", new(big.Int).Div(num, Douglas)) + fin = new(big.Int).Div(num, Douglas) + denom = "Douglas" case num.Cmp(Einstein) >= 0: - return fmt.Sprintf("%v Einstein", new(big.Int).Div(num, Einstein)) + fin = new(big.Int).Div(num, Einstein) + denom = "Einstein" case num.Cmp(Ether) >= 0: - return fmt.Sprintf("%v Ether", new(big.Int).Div(num, Ether)) + fin = new(big.Int).Div(num, Ether) + denom = "Ether" case num.Cmp(Finney) >= 0: - return fmt.Sprintf("%v Finney", new(big.Int).Div(num, Finney)) + fin = new(big.Int).Div(num, Finney) + denom = "Finney" case num.Cmp(Szabo) >= 0: - return fmt.Sprintf("%v Szabo", new(big.Int).Div(num, Szabo)) + fin = new(big.Int).Div(num, Szabo) + denom = "Szabo" case num.Cmp(Shannon) >= 0: - return fmt.Sprintf("%v Shannon", new(big.Int).Div(num, Shannon)) + fin = new(big.Int).Div(num, Shannon) + denom = "Shannon" case num.Cmp(Babbage) >= 0: - return fmt.Sprintf("%v Babbage", new(big.Int).Div(num, Babbage)) + fin = new(big.Int).Div(num, Babbage) + denom = "Babbage" case num.Cmp(Ada) >= 0: - return fmt.Sprintf("%v Ada", new(big.Int).Div(num, Ada)) + fin = new(big.Int).Div(num, Ada) + denom = "Ada" + } + + if len(fin.String()) > 5 { + return fmt.Sprintf("%sE%d %s", fin.String()[0:5], len(fin.String())-5, denom) } - return fmt.Sprintf("%v Wei", num) + return fmt.Sprintf("%v %s", fin, denom) } // Common big integers often used -- cgit From 272d58662c885ab1cef8930e96fb832ae5377d96 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 27 Oct 2014 11:44:16 +0100 Subject: Implemented LOG. Closes #159 --- ethutil/common.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index 8532d80f2..e60f237cf 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -77,6 +77,7 @@ func CurrencyToString(num *big.Int) string { var ( Big1 = big.NewInt(1) Big2 = big.NewInt(2) + Big3 = big.NewInt(3) Big0 = big.NewInt(0) BigTrue = Big1 BigFalse = Big0 -- cgit From 2a9fc7baa908d64ff1ddae44641024114d3ec88d Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 14 Nov 2014 15:01:52 -0600 Subject: Merge branch 'develop' of https://github.com/tgerring/go-ethereum --- ethutil/common.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/common.go') diff --git a/ethutil/common.go b/ethutil/common.go index e60f237cf..0a29cac6c 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -66,6 +66,7 @@ func CurrencyToString(num *big.Int) string { denom = "Ada" } + // TODO add comment clarifying expected behavior if len(fin.String()) > 5 { return fmt.Sprintf("%sE%d %s", fin.String()[0:5], len(fin.String())-5, denom) } -- cgit