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
|
-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
|
||||||
|
@ -13,7 +13,7 @@ type BlockChain struct {
|
|||||||
|
|
||||||
func NewBlockChain() *BlockChain {
|
func NewBlockChain() *BlockChain {
|
||||||
bc := &BlockChain{}
|
bc := &BlockChain{}
|
||||||
bc.genesisBlock = ethutil.NewBlock( ethutil.Encode(ethutil.Genesis) )
|
bc.genesisBlock = ethutil.NewBlock(ethutil.Encode(ethutil.Genesis))
|
||||||
|
|
||||||
return bc
|
return bc
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ func (bm *BlockManager) ProcessBlock(block *ethutil.Block) error {
|
|||||||
|
|
||||||
// Wait for all Tx to finish processing
|
// Wait for all Tx to finish processing
|
||||||
for i := 0; i < txCount; i++ {
|
for i := 0; i < txCount; i++ {
|
||||||
<- lockChan
|
<-lockChan
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
15
dagger.go
15
dagger.go
@ -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
|
||||||
@ -55,7 +58,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
|
|||||||
// Wait for each go routine to finish
|
// Wait for each go routine to finish
|
||||||
for k := 0; k < amountOfRoutines; k++ {
|
for k := 0; k < amountOfRoutines; k++ {
|
||||||
// Get the result from the channel. 0 = quit
|
// Get the result from the channel. 0 = quit
|
||||||
if r := <- resChan; r != 0 {
|
if r := <-resChan; r != 0 {
|
||||||
res = r
|
res = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +104,7 @@ func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
|
|||||||
|
|
||||||
b.SetBytes(Sum(d))
|
b.SetBytes(Sum(d))
|
||||||
pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
|
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))
|
ret.SetBytes(Sum(sha))
|
||||||
|
@ -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 {
|
||||||
@ -80,19 +82,19 @@ func (i *Console) ParseInput(input string) bool {
|
|||||||
case "print":
|
case "print":
|
||||||
i.db.Print()
|
i.db.Print()
|
||||||
case "dag":
|
case "dag":
|
||||||
fmt.Println(DaggerVerify( ethutil.Big(tokens[1]), // hash
|
fmt.Println(DaggerVerify(ethutil.Big(tokens[1]), // hash
|
||||||
ethutil.BigPow(2, 36), // diff
|
ethutil.BigPow(2, 36), // diff
|
||||||
ethutil.Big(tokens[2])))// nonce
|
ethutil.Big(tokens[2]))) // nonce
|
||||||
case "exit", "quit", "q":
|
case "exit", "quit", "q":
|
||||||
return false
|
return false
|
||||||
case "help":
|
case "help":
|
||||||
fmt.Printf( "COMMANDS:\n"+
|
fmt.Printf("COMMANDS:\n" +
|
||||||
"\033[1m= DB =\033[0m\n"+
|
"\033[1m= DB =\033[0m\n" +
|
||||||
"update KEY VALUE - Updates/Creates a new value for the given key\n"+
|
"update KEY VALUE - Updates/Creates a new value for the given key\n" +
|
||||||
"get KEY - Retrieves the given key\n"+
|
"get KEY - Retrieves the given key\n" +
|
||||||
"root - Prints the hex encoded merkle root\n"+
|
"root - Prints the hex encoded merkle root\n" +
|
||||||
"rawroot - Prints the raw merkle root\n"+
|
"rawroot - Prints the raw merkle root\n" +
|
||||||
"\033[1m= Dagger =\033[0m\n"+
|
"\033[1m= Dagger =\033[0m\n" +
|
||||||
"dag HASH NONCE - Verifies a nonce with the given hash with dagger\n")
|
"dag HASH NONCE - Verifies a nonce with the given hash with dagger\n")
|
||||||
default:
|
default:
|
||||||
fmt.Println("Unknown command:", tokens[0])
|
fmt.Println("Unknown command:", tokens[0])
|
||||||
|
10
ethereum.go
10
ethereum.go
@ -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")
|
||||||
@ -46,7 +47,7 @@ func main() {
|
|||||||
if StartConsole {
|
if StartConsole {
|
||||||
console := NewConsole()
|
console := NewConsole()
|
||||||
console.Start()
|
console.Start()
|
||||||
} else{
|
} else {
|
||||||
log.Println("Starting Ethereum")
|
log.Println("Starting Ethereum")
|
||||||
server, err := NewServer()
|
server, err := NewServer()
|
||||||
|
|
||||||
@ -78,7 +79,6 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Wait for shutdown
|
// Wait for shutdown
|
||||||
server.WaitForShutdown()
|
server.WaitForShutdown()
|
||||||
}
|
}
|
||||||
|
6
peer.go
6
peer.go
@ -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 {
|
||||||
@ -49,7 +49,7 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Break out of the for loop if a quit message is posted
|
// Break out of the for loop if a quit message is posted
|
||||||
case <- p.quit:
|
case <-p.quit:
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
rlp.go
44
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,10 +96,11 @@ 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
|
||||||
data, _ := Decode(rlpData,0)
|
data, _ := Decode(rlpData, 0)
|
||||||
decoder.rlpData = data
|
decoder.rlpData = data
|
||||||
|
|
||||||
return decoder
|
return decoder
|
||||||
@ -110,9 +112,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToBinarySlice(n uint64, length uint64) []uint64 {
|
func ToBinarySlice(n uint64, length uint64) []uint64 {
|
||||||
@ -120,10 +124,12 @@ 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)
|
||||||
|
|
||||||
return slice
|
return slice
|
||||||
}
|
}
|
||||||
@ -138,9 +144,11 @@ 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])
|
||||||
}
|
}
|
||||||
|
|
||||||
func Decode(data []byte, pos int) (interface{}, int) {
|
func Decode(data []byte, pos int) (interface{}, int) {
|
||||||
@ -161,16 +169,16 @@ func Decode(data []byte, pos int) (interface{}, int) {
|
|||||||
case char < 64:
|
case char < 64:
|
||||||
b := int(data[pos]) - 55
|
b := int(data[pos]) - 55
|
||||||
b2 := int(FromBin(data[pos+1 : pos+1+b]))
|
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:
|
case char < 120:
|
||||||
b := int(data[pos]) - 64
|
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:
|
case char < 128:
|
||||||
b := int(data[pos]) - 119
|
b := int(data[pos]) - 119
|
||||||
b2 := int(FromBin(data[pos+1 : pos+1+b]))
|
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:
|
case char < 184:
|
||||||
b := int(data[pos]) - 128
|
b := int(data[pos]) - 128
|
||||||
@ -186,7 +194,7 @@ func Decode(data []byte, pos int) (interface{}, int) {
|
|||||||
case char < 192:
|
case char < 192:
|
||||||
b := int(data[pos]) - 183
|
b := int(data[pos]) - 183
|
||||||
//b2 := int(FromBin(data[pos+1 : pos+1+b])) (ref implementation has an unused variable)
|
//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++ {
|
for i := 0; i < b; i++ {
|
||||||
var obj interface{}
|
var obj interface{}
|
||||||
|
|
||||||
@ -218,11 +226,11 @@ func Encode(object interface{}) []byte {
|
|||||||
buff.WriteString(string(num))
|
buff.WriteString(string(num))
|
||||||
} else if num <= uint64(math.Pow(2, 256)) {
|
} else if num <= uint64(math.Pow(2, 256)) {
|
||||||
b := ToBin(num, 0)
|
b := ToBin(num, 0)
|
||||||
buff.WriteString(string(len(b) + 23) + b)
|
buff.WriteString(string(len(b)+23) + b)
|
||||||
} else {
|
} else {
|
||||||
b := ToBin(num, 0)
|
b := ToBin(num, 0)
|
||||||
b2 := ToBin(uint64(len(b)), 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:
|
case *big.Int:
|
||||||
@ -230,10 +238,10 @@ func Encode(object interface{}) []byte {
|
|||||||
|
|
||||||
case string:
|
case string:
|
||||||
if len(t) < 56 {
|
if len(t) < 56 {
|
||||||
buff.WriteString(string(len(t) + 64) + t)
|
buff.WriteString(string(len(t)+64) + t)
|
||||||
} else {
|
} else {
|
||||||
b2 := ToBin(uint64(len(t)), 0)
|
b2 := ToBin(uint64(len(t)), 0)
|
||||||
buff.WriteString(string(len(b2) + 119) + b2 + t)
|
buff.WriteString(string(len(b2)+119) + b2 + t)
|
||||||
}
|
}
|
||||||
|
|
||||||
case []byte:
|
case []byte:
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEncode(t *testing.T) {
|
func TestEncode(t *testing.T) {
|
||||||
@ -30,7 +30,7 @@ func TestEncode(t *testing.T) {
|
|||||||
func TestMultiEncode(t *testing.T) {
|
func TestMultiEncode(t *testing.T) {
|
||||||
inter := []interface{}{
|
inter := []interface{}{
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
"1","2","3",
|
"1", "2", "3",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
"string",
|
"string",
|
||||||
|
17
server.go
17
server.go
@ -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
|
||||||
@ -95,10 +94,10 @@ func (s *Server) Start() {
|
|||||||
//go func() {
|
//go func() {
|
||||||
// for {
|
// for {
|
||||||
// s.Broadcast("block", Encode("blockdata"))
|
// s.Broadcast("block", Encode("blockdata"))
|
||||||
//
|
//
|
||||||
// time.Sleep(100 * time.Millisecond)
|
// time.Sleep(100 * time.Millisecond)
|
||||||
// }
|
// }
|
||||||
// }()
|
// }()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Stop() {
|
func (s *Server) Stop() {
|
||||||
@ -117,5 +116,5 @@ func (s *Server) Stop() {
|
|||||||
|
|
||||||
// This function will wait for a shutdown and resumes main thread execution
|
// This function will wait for a shutdown and resumes main thread execution
|
||||||
func (s *Server) WaitForShutdown() {
|
func (s *Server) WaitForShutdown() {
|
||||||
<- s.shutdownChan
|
<-s.shutdownChan
|
||||||
}
|
}
|
||||||
|
@ -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 (
|
||||||
_"fmt"
|
|
||||||
"testing"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
_ "fmt"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testsource = `{"Inputs":{
|
var testsource = `{"Inputs":{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
37
vm.go
37
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{}
|
||||||
}
|
}
|
||||||
@ -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) {
|
block *ethutil.Block, cb TxCallback) {
|
||||||
// Instruction pointer
|
// Instruction pointer
|
||||||
pc := 0
|
pc := 0
|
||||||
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user