Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cli submit block #4

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7faf296
Can call the latest block from an instance of ethereum
maxrobot Jun 18, 2018
294747f
Adding in a testing framework
maxrobot Jun 19, 2018
4061564
got the CLI working and RPC stuff off in a different file.
maxrobot Jun 19, 2018
facb261
added the rlp encoding testing which was surprisingly painful and tes…
maxrobot Jun 19, 2018
c10346b
Ok we now can pull RLP encoded blocks :)
maxrobot Jun 19, 2018
957c3ee
Cleaned up the generation of RLP encoded blocks
maxrobot Jun 20, 2018
52fba22
Started creating the contract to actually verify signatures legitimately
maxrobot Jun 20, 2018
529efca
Merge pull request #2 from maxrobot/feature/rpc-calls
Jun 20, 2018
fa71842
Understand how to ecrecover stuff signed in the javascript modules pi…
maxrobot Jun 20, 2018
b474ad0
Initial inauthenticate block is there
maxrobot Jun 21, 2018
2c6be71
Another painful thing to figure out even though it was quite simple, …
maxrobot Jun 21, 2018
665779c
So everything is working as expected would be nice to handle the cont…
maxrobot Jun 21, 2018
62a8d2c
Not sure
maxrobot Jun 22, 2018
5a12e59
have funcitonality to query smart contracts from golang cli
maxrobot Jun 22, 2018
bf1469e
Have added the functionality to query the validators contract
maxrobot Jun 22, 2018
23b2e1e
Improved the CLI help and also the readme
maxrobot Jun 23, 2018
7a86b03
Just didnt want to see the bad link in the README
maxrobot Jun 24, 2018
5fe2666
Improved the readme and added the user accounts to the setup.json
maxrobot Jun 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Not sure
  • Loading branch information
maxrobot committed Jun 22, 2018

Unverified

This user has not yet uploaded their public signing key.
commit 62a8d2c0cb73080051bca73c9bb8dbc555fd7b05
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ coverage:
tail -n +2 coverage.out >> coverage-all.out;)
go tool cover -html=coverage-all.out

run:
build:
@go build -o cli-tool .

check:
34 changes: 17 additions & 17 deletions src/cli/cli.go
Original file line number Diff line number Diff line change
@@ -103,23 +103,23 @@ func Launch(setup config.Setup) {
},
})

// shell.AddCmd(&ishell.Cmd{
// Name: "submitSignedBlock",
// Help: "Request block [N] from chain [from], calculates the prefixes required for submission to chain [to]",
// Func: func(c *ishell.Context) {
// c.Println("===============================================================")
// if len(c.Args) == 0 {
// c.Println("Choose a block.")
// } else if len(c.Args) > 1 {
// c.Println("Too many arguments entered.")
// } else {
// block := strToHex(c.Args[0])
// c.Println("RLP encode block: " + c.Args[0])
// calculateRlpEncoding(client, block)
// }
// c.Println("===============================================================")
// },
// })
shell.AddCmd(&ishell.Cmd{
Name: "submitSignedBlock",
Help: "Request block [N] from chain [from], calculates the prefixes required for submission to chain [to]",
Func: func(c *ishell.Context) {
c.Println("===============================================================")
if len(c.Args) == 0 {
c.Println("Choose a block.")
} else if len(c.Args) > 1 {
c.Println("Too many arguments entered.")
} else {
block := strToHex(c.Args[0])
c.Println("RLP encode block: " + c.Args[0])
calculateRlpEncoding(client, block)
}
c.Println("===============================================================")
},
})

// run shell
shell.Run()
82 changes: 40 additions & 42 deletions src/cli/rpc.go
Original file line number Diff line number Diff line change
@@ -13,21 +13,21 @@ import (
)

type Header struct {
ParentHash string `json:"parentHash" gencodec:"required"`
UncleHash string `json:"sha3Uncles" gencodec:"required"`
Coinbase string `json:"miner" gencodec:"required"`
Root string `json:"stateRoot" gencodec:"required"`
TxHash string `json:"transactionsRoot" gencodec:"required"`
ReceiptHash string `json:"receiptsRoot" gencodec:"required"`
Bloom string `json:"logsBloom" gencodec:"required"`
Difficulty string `json:"difficulty" gencodec:"required"`
Number string `json:"number" gencodec:"required"`
GasLimit string `json:"gasLimit" gencodec:"required"`
GasUsed string `json:"gasUsed" gencodec:"required"`
Time string `json:"timestamp" gencodec:"required"`
Extra string `json:"extraData" gencodec:"required"`
MixDigest string `json:"mixHash" gencodec:"required"`
Nonce string `json:"nonce" gencodec:"required"`
ParentHash string `json:"parentHash"`
UncleHash string `json:"sha3Uncles"`
Coinbase string `json:"miner"`
Root string `json:"stateRoot"`
TxHash string `json:"transactionsRoot"`
ReceiptHash string `json:"receiptsRoot"`
Bloom string `json:"logsBloom"`
Difficulty string `json:"difficulty"`
Number string `json:"number"`
GasLimit string `json:"gasLimit"`
GasUsed string `json:"gasUsed"`
Time string `json:"timestamp"`
Extra string `json:"extraData"`
MixDigest string `json:"mixHash"`
Nonce string `json:"nonce"`
}

func latestBlock(client *rpc.Client) {
@@ -36,11 +36,10 @@ func latestBlock(client *rpc.Client) {
if err != nil {
fmt.Println("can't get latest block:", err)
return
} else {
// Print events from the subscription as they arrive.
k, _ := strconv.ParseInt(lastBlock.Number, 0, 64)
fmt.Printf("latest block: %v\n", k)
}
// Print events from the subscription as they arrive.
k, _ := strconv.ParseInt(lastBlock.Number, 0, 64)
fmt.Printf("latest block: %v\n", k)
}

func getBlock(client *rpc.Client, block string) {
@@ -49,9 +48,8 @@ func getBlock(client *rpc.Client, block string) {
if err != nil {
fmt.Println("can't get requested block:", err)
return
} else {
fmt.Printf("%+v\n", blockHeader)
}
fmt.Printf("%+v\n", blockHeader)
}

func rlpEncodeBlock(client *rpc.Client, block string) {
@@ -60,11 +58,10 @@ func rlpEncodeBlock(client *rpc.Client, block string) {
if err != nil {
fmt.Println("can't get requested block:", err)
return
} else {
blockInterface := GenerateInterface(blockHeader)
encodedBlock := EncodeBlock(blockInterface)
fmt.Printf("%+x\n", encodedBlock)
}
blockInterface := GenerateInterface(blockHeader)
encodedBlock := EncodeBlock(blockInterface)
fmt.Printf("%+x\n", encodedBlock)
}

func calculateRlpEncoding(client *rpc.Client, block string) {
@@ -73,25 +70,26 @@ func calculateRlpEncoding(client *rpc.Client, block string) {
if err != nil {
fmt.Println("can't get requested block:", err)
return
} else {
// Generate an interface to encode the standard block header
blockInterface := GenerateInterface(blockHeader)
encodedBlock := EncodeBlock(blockInterface)
fmt.Printf("%+x\n", encodedBlock)

// Generate an interface to encode the blockheader without the signature in the extraData
blockHeader.Extra = blockHeader.Extra[:len(blockHeader.Extra)-130]
blockInterface = GenerateInterface(blockHeader)
encodedBlock = EncodeBlock(blockInterface)
fmt.Printf("\n%+x\n", encodedBlock[1:3])

// Generate an interface to encode the blockheader without the signature in the extraData
encExtra, _ := hex.DecodeString(blockHeader.Extra[2:])
encodedBlock = EncodeBlock(encExtra)
fmt.Printf("\n%+x\n", encodedBlock[0:1])
}
// Generate an interface to encode the standard block header
blockInterface := GenerateInterface(blockHeader)
encodedBlock := EncodeBlock(blockInterface)
fmt.Printf("%+x\n", encodedBlock)

// Generate an interface to encode the blockheader without the signature in the extraData
blockHeader.Extra = blockHeader.Extra[:len(blockHeader.Extra)-130]
blockInterface = GenerateInterface(blockHeader)
encodedBlock = EncodeBlock(blockInterface)
fmt.Printf("\n%+x\n", encodedBlock[1:3])

// Generate an interface to encode the blockheader without the signature in the extraData
encExtra, _ := hex.DecodeString(blockHeader.Extra[2:])
encodedBlock = EncodeBlock(encExtra)
fmt.Printf("\n%+x\n", encodedBlock[0:1])

}

// Creates an interface for a block
func GenerateInterface(blockHeader Header) (rest interface{}) {
blockInterface := []interface{}{}
s := reflect.ValueOf(&blockHeader).Elem()
@@ -106,8 +104,8 @@ func GenerateInterface(blockHeader Header) (rest interface{}) {
return blockInterface
}

// Encodes a block
func EncodeBlock(blockInterface interface{}) (h []byte) {
// Encode the block
h, _ = rlp.EncodeToBytes(blockInterface)

return h