forked from cerc-io/plugeth
gofmt no coding standards
This commit is contained in:
parent
8bbf879cb3
commit
9571a51286
@ -21,3 +21,8 @@ Command line options
|
||||
|
||||
-c launch the developer console
|
||||
-m start mining fake blocks and broadcast fake messages to the net
|
||||
|
||||
Contribution
|
||||
============
|
||||
|
||||
See CONTRIB.md
|
||||
|
@ -13,7 +13,7 @@ type BlockChain struct {
|
||||
|
||||
func NewBlockChain() *BlockChain {
|
||||
bc := &BlockChain{}
|
||||
bc.genesisBlock = ethutil.NewBlock( ethutil.Encode(ethutil.Genesis) )
|
||||
bc.genesisBlock = ethutil.NewBlock(ethutil.Encode(ethutil.Genesis))
|
||||
|
||||
return bc
|
||||
}
|
||||
@ -55,7 +55,7 @@ func (bm *BlockManager) ProcessBlock(block *ethutil.Block) error {
|
||||
|
||||
// Wait for all Tx to finish processing
|
||||
for i := 0; i < txCount; i++ {
|
||||
<- lockChan
|
||||
<-lockChan
|
||||
}
|
||||
|
||||
return nil
|
||||
|
15
dagger.go
15
dagger.go
@ -1,12 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/ethereum/ethutil-go"
|
||||
"github.com/obscuren/sha3"
|
||||
"hash"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"time"
|
||||
"github.com/obscuren/sha3"
|
||||
"hash"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
)
|
||||
|
||||
type Dagger struct {
|
||||
@ -15,6 +15,7 @@ type Dagger struct {
|
||||
}
|
||||
|
||||
var Found bool
|
||||
|
||||
func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
|
||||
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
|
||||
if Found { break }
|
||||
if Found {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
resChan <- 0
|
||||
@ -55,7 +58,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
|
||||
// Wait for each go routine to finish
|
||||
for k := 0; k < amountOfRoutines; k++ {
|
||||
// Get the result from the channel. 0 = quit
|
||||
if r := <- resChan; r != 0 {
|
||||
if r := <-resChan; r != 0 {
|
||||
res = r
|
||||
}
|
||||
}
|
||||
@ -101,7 +104,7 @@ func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
|
||||
|
||||
b.SetBytes(Sum(d))
|
||||
pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
|
||||
sha.Write(dag.Node(L - 1, pk).Bytes())
|
||||
sha.Write(dag.Node(L-1, pk).Bytes())
|
||||
}
|
||||
|
||||
ret.SetBytes(Sum(sha))
|
||||
|
@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkDaggerSearch(b *testing.B) {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bufio"
|
||||
"strings"
|
||||
"os"
|
||||
"errors"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ethereum/ethdb-go"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Console struct {
|
||||
@ -60,7 +60,9 @@ func (i *Console) ParseInput(input string) bool {
|
||||
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)
|
||||
if err != nil {
|
||||
@ -80,19 +82,19 @@ func (i *Console) ParseInput(input string) bool {
|
||||
case "print":
|
||||
i.db.Print()
|
||||
case "dag":
|
||||
fmt.Println(DaggerVerify( ethutil.Big(tokens[1]), // hash
|
||||
fmt.Println(DaggerVerify(ethutil.Big(tokens[1]), // hash
|
||||
ethutil.BigPow(2, 36), // diff
|
||||
ethutil.Big(tokens[2])))// nonce
|
||||
ethutil.Big(tokens[2]))) // nonce
|
||||
case "exit", "quit", "q":
|
||||
return false
|
||||
case "help":
|
||||
fmt.Printf( "COMMANDS:\n"+
|
||||
"\033[1m= DB =\033[0m\n"+
|
||||
"update KEY VALUE - Updates/Creates a new value for the given key\n"+
|
||||
"get KEY - Retrieves the given key\n"+
|
||||
"root - Prints the hex encoded merkle root\n"+
|
||||
"rawroot - Prints the raw merkle root\n"+
|
||||
"\033[1m= Dagger =\033[0m\n"+
|
||||
fmt.Printf("COMMANDS:\n" +
|
||||
"\033[1m= DB =\033[0m\n" +
|
||||
"update KEY VALUE - Updates/Creates a new value for the given key\n" +
|
||||
"get KEY - Retrieves the given key\n" +
|
||||
"root - Prints the hex encoded merkle root\n" +
|
||||
"rawroot - Prints the raw merkle root\n" +
|
||||
"\033[1m= Dagger =\033[0m\n" +
|
||||
"dag HASH NONCE - Verifies a nonce with the given hash with dagger\n")
|
||||
default:
|
||||
fmt.Println("Unknown command:", tokens[0])
|
||||
|
10
ethereum.go
10
ethereum.go
@ -1,19 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"flag"
|
||||
"runtime"
|
||||
"log"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
)
|
||||
|
||||
const Debug = true
|
||||
|
||||
var StartConsole bool
|
||||
var StartMining bool
|
||||
|
||||
func Init() {
|
||||
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
|
||||
flag.BoolVar(&StartMining, "m", false, "start dagger mining")
|
||||
@ -46,7 +47,7 @@ func main() {
|
||||
if StartConsole {
|
||||
console := NewConsole()
|
||||
console.Start()
|
||||
} else{
|
||||
} else {
|
||||
log.Println("Starting Ethereum")
|
||||
server, err := NewServer()
|
||||
|
||||
@ -78,7 +79,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Wait for shutdown
|
||||
server.WaitForShutdown()
|
||||
}
|
||||
|
6
peer.go
6
peer.go
@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"log"
|
||||
"github.com/ethereum/ethwire-go"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
type Peer struct {
|
||||
@ -49,7 +49,7 @@ out:
|
||||
}
|
||||
|
||||
// Break out of the for loop if a quit message is posted
|
||||
case <- p.quit:
|
||||
case <-p.quit:
|
||||
break out
|
||||
}
|
||||
}
|
||||
|
44
rlp.go
44
rlp.go
@ -1,16 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
"math"
|
||||
"math/big"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
)
|
||||
|
||||
type RlpEncoder struct {
|
||||
rlpData []byte
|
||||
}
|
||||
|
||||
func NewRlpEncoder() *RlpEncoder {
|
||||
encoder := &RlpEncoder{}
|
||||
|
||||
@ -95,10 +96,11 @@ func (attr *RlpDataAttribute) Get(idx int) *RlpDataAttribute {
|
||||
type RlpDecoder struct {
|
||||
rlpData interface{}
|
||||
}
|
||||
|
||||
func NewRlpDecoder(rlpData []byte) *RlpDecoder {
|
||||
decoder := &RlpDecoder{}
|
||||
// Decode the data
|
||||
data, _ := Decode(rlpData,0)
|
||||
data, _ := Decode(rlpData, 0)
|
||||
decoder.rlpData = data
|
||||
|
||||
return decoder
|
||||
@ -110,9 +112,11 @@ func (dec *RlpDecoder) Get(idx int) *RlpDataAttribute {
|
||||
|
||||
/// Raw methods
|
||||
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)
|
||||
}
|
||||
|
||||
func ToBinarySlice(n uint64, length uint64) []uint64 {
|
||||
@ -120,10 +124,12 @@ func ToBinarySlice(n uint64, length uint64) []uint64 {
|
||||
length = BinaryLength(n)
|
||||
}
|
||||
|
||||
if n == 0 { return make([]uint64, 1) }
|
||||
if n == 0 {
|
||||
return make([]uint64, 1)
|
||||
}
|
||||
|
||||
slice := ToBinarySlice(n / 256, 0)
|
||||
slice = append(slice, n % 256)
|
||||
slice := ToBinarySlice(n/256, 0)
|
||||
slice = append(slice, n%256)
|
||||
|
||||
return slice
|
||||
}
|
||||
@ -138,9 +144,11 @@ func ToBin(n uint64, length uint64) string {
|
||||
}
|
||||
|
||||
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])
|
||||
}
|
||||
|
||||
func Decode(data []byte, pos int) (interface{}, int) {
|
||||
@ -161,16 +169,16 @@ func Decode(data []byte, pos int) (interface{}, int) {
|
||||
case char < 64:
|
||||
b := int(data[pos]) - 55
|
||||
b2 := int(FromBin(data[pos+1 : pos+1+b]))
|
||||
return FromBin(data[pos+1+b : pos+1+b+b2]), pos+1+b+b2
|
||||
return FromBin(data[pos+1+b : pos+1+b+b2]), pos + 1 + b + b2
|
||||
|
||||
case char < 120:
|
||||
b := int(data[pos]) - 64
|
||||
return data[pos+1:pos+1+b], pos+1+b
|
||||
return data[pos+1 : pos+1+b], pos + 1 + b
|
||||
|
||||
case char < 128:
|
||||
b := int(data[pos]) - 119
|
||||
b2 := int(FromBin(data[pos+1 : pos+1+b]))
|
||||
return data[pos+1+b : pos+1+b+b2], pos+1+b+b2
|
||||
return data[pos+1+b : pos+1+b+b2], pos + 1 + b + b2
|
||||
|
||||
case char < 184:
|
||||
b := int(data[pos]) - 128
|
||||
@ -186,7 +194,7 @@ func Decode(data []byte, pos int) (interface{}, int) {
|
||||
case char < 192:
|
||||
b := int(data[pos]) - 183
|
||||
//b2 := int(FromBin(data[pos+1 : pos+1+b])) (ref implementation has an unused variable)
|
||||
pos = pos+1+b
|
||||
pos = pos + 1 + b
|
||||
for i := 0; i < b; i++ {
|
||||
var obj interface{}
|
||||
|
||||
@ -218,11 +226,11 @@ func Encode(object interface{}) []byte {
|
||||
buff.WriteString(string(num))
|
||||
} else if num <= uint64(math.Pow(2, 256)) {
|
||||
b := ToBin(num, 0)
|
||||
buff.WriteString(string(len(b) + 23) + b)
|
||||
buff.WriteString(string(len(b)+23) + b)
|
||||
} else {
|
||||
b := ToBin(num, 0)
|
||||
b2 := ToBin(uint64(len(b)), 0)
|
||||
buff.WriteString(string(len(b2) + 55) + b2 + b)
|
||||
buff.WriteString(string(len(b2)+55) + b2 + b)
|
||||
}
|
||||
|
||||
case *big.Int:
|
||||
@ -230,10 +238,10 @@ func Encode(object interface{}) []byte {
|
||||
|
||||
case string:
|
||||
if len(t) < 56 {
|
||||
buff.WriteString(string(len(t) + 64) + t)
|
||||
buff.WriteString(string(len(t)+64) + t)
|
||||
} else {
|
||||
b2 := ToBin(uint64(len(t)), 0)
|
||||
buff.WriteString(string(len(b2) + 119) + b2 + t)
|
||||
buff.WriteString(string(len(b2)+119) + b2 + t)
|
||||
}
|
||||
|
||||
case []byte:
|
||||
|
@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncode(t *testing.T) {
|
||||
@ -30,7 +30,7 @@ func TestEncode(t *testing.T) {
|
||||
func TestMultiEncode(t *testing.T) {
|
||||
inter := []interface{}{
|
||||
[]interface{}{
|
||||
"1","2","3",
|
||||
"1", "2", "3",
|
||||
},
|
||||
[]string{
|
||||
"string",
|
||||
|
17
server.go
17
server.go
@ -2,11 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"net"
|
||||
"log"
|
||||
_"time"
|
||||
"github.com/ethereum/ethdb-go"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
"log"
|
||||
"net"
|
||||
_ "time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@ -57,7 +57,6 @@ func (s *Server) ConnectToPeer(addr string) error {
|
||||
s.peers.PushBack(peer)
|
||||
peer.Start()
|
||||
|
||||
|
||||
log.Println("Connected to peer ::", conn.RemoteAddr())
|
||||
|
||||
return nil
|
||||
@ -95,10 +94,10 @@ func (s *Server) Start() {
|
||||
//go func() {
|
||||
// for {
|
||||
// s.Broadcast("block", Encode("blockdata"))
|
||||
//
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
// }
|
||||
// }()
|
||||
//
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
// }
|
||||
// }()
|
||||
}
|
||||
|
||||
func (s *Server) Stop() {
|
||||
@ -117,5 +116,5 @@ func (s *Server) Stop() {
|
||||
|
||||
// This function will wait for a shutdown and resumes main thread execution
|
||||
func (s *Server) WaitForShutdown() {
|
||||
<- s.shutdownChan
|
||||
<-s.shutdownChan
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type TestSource struct {
|
||||
|
@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_"fmt"
|
||||
"testing"
|
||||
"encoding/hex"
|
||||
_ "fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testsource = `{"Inputs":{
|
||||
|
@ -1,4 +1,5 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
|
||||
import (
|
||||
|
37
vm.go
37
vm.go
@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"github.com/ethereum/ethutil-go"
|
||||
"math/big"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Op codes
|
||||
@ -61,18 +61,21 @@ const (
|
||||
)
|
||||
|
||||
type OpType int
|
||||
|
||||
const (
|
||||
tNorm = iota
|
||||
tData
|
||||
tExtro
|
||||
tCrypto
|
||||
)
|
||||
|
||||
type TxCallback func(opType OpType) bool
|
||||
|
||||
// Simple push/pop stack mechanism
|
||||
type Stack struct {
|
||||
data []string
|
||||
}
|
||||
|
||||
func NewStack() *Stack {
|
||||
return &Stack{}
|
||||
}
|
||||
@ -112,7 +115,7 @@ func NewVm() *Vm {
|
||||
}
|
||||
}
|
||||
|
||||
func (vm *Vm) ProcContract( tx *ethutil.Transaction,
|
||||
func (vm *Vm) ProcContract(tx *ethutil.Transaction,
|
||||
block *ethutil.Block, cb TxCallback) {
|
||||
// Instruction pointer
|
||||
pc := 0
|
||||
@ -136,7 +139,9 @@ out:
|
||||
nb := ethutil.NumberToBytes(uint64(pc), 32)
|
||||
op, _, _ := ethutil.Instr(contract.State().Get(string(nb)))
|
||||
|
||||
if !cb(0) { break }
|
||||
if !cb(0) {
|
||||
break
|
||||
}
|
||||
|
||||
if Debug {
|
||||
//fmt.Printf("%-3d %-4d\n", pc, op)
|
||||
@ -173,11 +178,17 @@ out:
|
||||
case oSDIV:
|
||||
x, y := vm.stack.Popn()
|
||||
// n > 2**255
|
||||
if x.Cmp(Pow256) > 0 { x.Sub(Pow256, x) }
|
||||
if y.Cmp(Pow256) > 0 { y.Sub(Pow256, y) }
|
||||
if x.Cmp(Pow256) > 0 {
|
||||
x.Sub(Pow256, x)
|
||||
}
|
||||
if y.Cmp(Pow256) > 0 {
|
||||
y.Sub(Pow256, y)
|
||||
}
|
||||
z := new(big.Int)
|
||||
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
|
||||
vm.stack.Push(z.String())
|
||||
case oMOD:
|
||||
@ -187,11 +198,17 @@ out:
|
||||
case oSMOD:
|
||||
x, y := vm.stack.Popn()
|
||||
// n > 2**255
|
||||
if x.Cmp(Pow256) > 0 { x.Sub(Pow256, x) }
|
||||
if y.Cmp(Pow256) > 0 { y.Sub(Pow256, y) }
|
||||
if x.Cmp(Pow256) > 0 {
|
||||
x.Sub(Pow256, x)
|
||||
}
|
||||
if y.Cmp(Pow256) > 0 {
|
||||
y.Sub(Pow256, y)
|
||||
}
|
||||
z := new(big.Int)
|
||||
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
|
||||
vm.stack.Push(z.String())
|
||||
case oEXP:
|
||||
|
Loading…
Reference in New Issue
Block a user