gofmt no coding standards

This commit is contained in:
obscuren 2014-01-11 15:27:08 +01:00
parent 8bbf879cb3
commit 9571a51286
14 changed files with 922 additions and 887 deletions

@ -21,3 +21,8 @@ Command line options
-c launch the developer console -c launch the developer console
-m start mining fake blocks and broadcast fake messages to the net -m start mining fake blocks and broadcast fake messages to the net
Contribution
============
See CONTRIB.md

@ -1,12 +1,12 @@
package main package main
import ( import (
"github.com/ethereum/ethutil-go"
"github.com/obscuren/sha3"
"hash"
"math/big" "math/big"
"math/rand" "math/rand"
"time" "time"
"github.com/obscuren/sha3"
"hash"
"github.com/ethereum/ethutil-go"
) )
type Dagger struct { type Dagger struct {
@ -15,6 +15,7 @@ type Dagger struct {
} }
var Found bool var Found bool
func (dag *Dagger) Find(obj *big.Int, resChan chan int64) { func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
@ -29,7 +30,9 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
} }
// Break out if found // Break out if found
if Found { break } if Found {
break
}
} }
resChan <- 0 resChan <- 0

@ -1,8 +1,8 @@
package main package main
import ( import (
"testing"
"math/big" "math/big"
"testing"
) )
func BenchmarkDaggerSearch(b *testing.B) { func BenchmarkDaggerSearch(b *testing.B) {

@ -1,14 +1,14 @@
package main package main
import ( import (
"fmt"
"bufio" "bufio"
"strings"
"os"
"errors"
"encoding/hex" "encoding/hex"
"errors"
"fmt"
"github.com/ethereum/ethdb-go" "github.com/ethereum/ethdb-go"
"github.com/ethereum/ethutil-go" "github.com/ethereum/ethutil-go"
"os"
"strings"
) )
type Console struct { type Console struct {
@ -60,7 +60,9 @@ func (i *Console) ParseInput(input string) bool {
fmt.Fprintln(os.Stderr, "reading input:", err) fmt.Fprintln(os.Stderr, "reading input:", err)
} }
if len(tokens) == 0 { return true } if len(tokens) == 0 {
return true
}
err := i.ValidateInput(tokens[0], count-1) err := i.ValidateInput(tokens[0], count-1)
if err != nil { if err != nil {

@ -1,19 +1,20 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"github.com/ethereum/ethutil-go"
"log"
"os" "os"
"os/signal" "os/signal"
"flag"
"runtime" "runtime"
"log"
"github.com/ethereum/ethutil-go"
) )
const Debug = true const Debug = true
var StartConsole bool var StartConsole bool
var StartMining bool var StartMining bool
func Init() { func Init() {
flag.BoolVar(&StartConsole, "c", false, "debug and testing console") flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
flag.BoolVar(&StartMining, "m", false, "start dagger mining") flag.BoolVar(&StartMining, "m", false, "start dagger mining")
@ -78,7 +79,6 @@ func main() {
return return
} }
// Wait for shutdown // Wait for shutdown
server.WaitForShutdown() server.WaitForShutdown()
} }

@ -1,9 +1,9 @@
package main package main
import ( import (
"net"
"log"
"github.com/ethereum/ethwire-go" "github.com/ethereum/ethwire-go"
"log"
"net"
) )
type Peer struct { type Peer struct {

18
rlp.go

@ -1,16 +1,17 @@
package main package main
import ( import (
"fmt"
"bytes" "bytes"
"fmt"
"github.com/ethereum/ethutil-go"
"math" "math"
"math/big" "math/big"
"github.com/ethereum/ethutil-go"
) )
type RlpEncoder struct { type RlpEncoder struct {
rlpData []byte rlpData []byte
} }
func NewRlpEncoder() *RlpEncoder { func NewRlpEncoder() *RlpEncoder {
encoder := &RlpEncoder{} encoder := &RlpEncoder{}
@ -95,6 +96,7 @@ func (attr *RlpDataAttribute) Get(idx int) *RlpDataAttribute {
type RlpDecoder struct { type RlpDecoder struct {
rlpData interface{} rlpData interface{}
} }
func NewRlpDecoder(rlpData []byte) *RlpDecoder { func NewRlpDecoder(rlpData []byte) *RlpDecoder {
decoder := &RlpDecoder{} decoder := &RlpDecoder{}
// Decode the data // Decode the data
@ -110,7 +112,9 @@ func (dec *RlpDecoder) Get(idx int) *RlpDataAttribute {
/// Raw methods /// Raw methods
func BinaryLength(n uint64) uint64 { func BinaryLength(n uint64) uint64 {
if n == 0 { return 0 } if n == 0 {
return 0
}
return 1 + BinaryLength(n/256) return 1 + BinaryLength(n/256)
} }
@ -120,7 +124,9 @@ func ToBinarySlice(n uint64, length uint64) []uint64 {
length = BinaryLength(n) length = BinaryLength(n)
} }
if n == 0 { return make([]uint64, 1) } if n == 0 {
return make([]uint64, 1)
}
slice := ToBinarySlice(n/256, 0) slice := ToBinarySlice(n/256, 0)
slice = append(slice, n%256) slice = append(slice, n%256)
@ -138,7 +144,9 @@ func ToBin(n uint64, length uint64) string {
} }
func FromBin(data []byte) uint64 { func FromBin(data []byte) uint64 {
if len(data) == 0 { return 0 } if len(data) == 0 {
return 0
}
return FromBin(data[:len(data)-1])*256 + uint64(data[len(data)-1]) return FromBin(data[:len(data)-1])*256 + uint64(data[len(data)-1])
} }

@ -1,8 +1,8 @@
package main package main
import ( import (
"testing"
"fmt" "fmt"
"testing"
) )
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {

@ -2,11 +2,11 @@ package main
import ( import (
"container/list" "container/list"
"net"
"log"
_"time"
"github.com/ethereum/ethdb-go" "github.com/ethereum/ethdb-go"
"github.com/ethereum/ethutil-go" "github.com/ethereum/ethutil-go"
"log"
"net"
_ "time"
) )
type Server struct { type Server struct {
@ -57,7 +57,6 @@ func (s *Server) ConnectToPeer(addr string) error {
s.peers.PushBack(peer) s.peers.PushBack(peer)
peer.Start() peer.Start()
log.Println("Connected to peer ::", conn.RemoteAddr()) log.Println("Connected to peer ::", conn.RemoteAddr())
return nil return nil

@ -1,9 +1,9 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"testing" "testing"
"encoding/json"
) )
type TestSource struct { type TestSource struct {

@ -1,9 +1,9 @@
package main package main
import ( import (
"encoding/hex"
_ "fmt" _ "fmt"
"testing" "testing"
"encoding/hex"
) )
var testsource = `{"Inputs":{ var testsource = `{"Inputs":{

@ -1,4 +1,5 @@
package main package main
/* /*
import ( import (

35
vm.go

@ -1,10 +1,10 @@
package main package main
import ( import (
"math/big"
"fmt" "fmt"
"strconv"
"github.com/ethereum/ethutil-go" "github.com/ethereum/ethutil-go"
"math/big"
"strconv"
) )
// Op codes // Op codes
@ -61,18 +61,21 @@ const (
) )
type OpType int type OpType int
const ( const (
tNorm = iota tNorm = iota
tData tData
tExtro tExtro
tCrypto tCrypto
) )
type TxCallback func(opType OpType) bool type TxCallback func(opType OpType) bool
// Simple push/pop stack mechanism // Simple push/pop stack mechanism
type Stack struct { type Stack struct {
data []string data []string
} }
func NewStack() *Stack { func NewStack() *Stack {
return &Stack{} return &Stack{}
} }
@ -136,7 +139,9 @@ out:
nb := ethutil.NumberToBytes(uint64(pc), 32) nb := ethutil.NumberToBytes(uint64(pc), 32)
op, _, _ := ethutil.Instr(contract.State().Get(string(nb))) op, _, _ := ethutil.Instr(contract.State().Get(string(nb)))
if !cb(0) { break } if !cb(0) {
break
}
if Debug { if Debug {
//fmt.Printf("%-3d %-4d\n", pc, op) //fmt.Printf("%-3d %-4d\n", pc, op)
@ -173,11 +178,17 @@ out:
case oSDIV: case oSDIV:
x, y := vm.stack.Popn() x, y := vm.stack.Popn()
// n > 2**255 // n > 2**255
if x.Cmp(Pow256) > 0 { x.Sub(Pow256, x) } if x.Cmp(Pow256) > 0 {
if y.Cmp(Pow256) > 0 { y.Sub(Pow256, y) } x.Sub(Pow256, x)
}
if y.Cmp(Pow256) > 0 {
y.Sub(Pow256, y)
}
z := new(big.Int) z := new(big.Int)
z.Div(x, y) z.Div(x, y)
if z.Cmp(Pow256) > 0 { z.Sub(Pow256, z) } if z.Cmp(Pow256) > 0 {
z.Sub(Pow256, z)
}
// Push result on to the stack // Push result on to the stack
vm.stack.Push(z.String()) vm.stack.Push(z.String())
case oMOD: case oMOD:
@ -187,11 +198,17 @@ out:
case oSMOD: case oSMOD:
x, y := vm.stack.Popn() x, y := vm.stack.Popn()
// n > 2**255 // n > 2**255
if x.Cmp(Pow256) > 0 { x.Sub(Pow256, x) } if x.Cmp(Pow256) > 0 {
if y.Cmp(Pow256) > 0 { y.Sub(Pow256, y) } x.Sub(Pow256, x)
}
if y.Cmp(Pow256) > 0 {
y.Sub(Pow256, y)
}
z := new(big.Int) z := new(big.Int)
z.Mod(x, y) z.Mod(x, y)
if z.Cmp(Pow256) > 0 { z.Sub(Pow256, z) } if z.Cmp(Pow256) > 0 {
z.Sub(Pow256, z)
}
// Push result on to the stack // Push result on to the stack
vm.stack.Push(z.String()) vm.stack.Push(z.String())
case oEXP: case oEXP: