mirror of https://github.com/status-im/op-geth.git
Parsing for block and tx
This commit is contained in:
parent
055407c835
commit
9581faf5fd
2
block.go
2
block.go
|
@ -73,7 +73,7 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
|
||||||
contract := NewContract(tx.value, []byte(""))
|
contract := NewContract(tx.value, []byte(""))
|
||||||
block.state.Update(string(addr), string(contract.MarshalRlp()))
|
block.state.Update(string(addr), string(contract.MarshalRlp()))
|
||||||
for i, val := range tx.data {
|
for i, val := range tx.data {
|
||||||
contract.state.Update(string(Encode(i)), val)
|
contract.state.Update(string(Encode(uint32(i))), val)
|
||||||
}
|
}
|
||||||
block.UpdateContract(addr, contract)
|
block.UpdateContract(addr, contract)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,11 @@ import (
|
||||||
// Op codes
|
// Op codes
|
||||||
var OpCodes = map[string]string{
|
var OpCodes = map[string]string{
|
||||||
"STOP": "0",
|
"STOP": "0",
|
||||||
"PSH": "30", // 0x30
|
"PUSH": "48", // 0x30
|
||||||
/*
|
"POP": "49", // 0x31
|
||||||
|
"LOAD": "54", // 0x36
|
||||||
|
|
||||||
|
/* OLD VM OPCODES
|
||||||
"ADD": "16", // 0x10
|
"ADD": "16", // 0x10
|
||||||
"SUB": "17", // 0x11
|
"SUB": "17", // 0x11
|
||||||
"MUL": "18", // 0x12
|
"MUL": "18", // 0x12
|
||||||
|
@ -57,7 +60,7 @@ var OpCodes = map[string]string{
|
||||||
func CompileInstr(s string) (string, error) {
|
func CompileInstr(s string) (string, error) {
|
||||||
tokens := strings.Split(s, " ")
|
tokens := strings.Split(s, " ")
|
||||||
if OpCodes[tokens[0]] == "" {
|
if OpCodes[tokens[0]] == "" {
|
||||||
return "", errors.New(fmt.Sprintf("OP not found: %s", tokens[0]))
|
return s, errors.New(fmt.Sprintf("OP not found: %s", tokens[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
code := OpCodes[tokens[0]] // Replace op codes with the proper numerical equivalent
|
code := OpCodes[tokens[0]] // Replace op codes with the proper numerical equivalent
|
||||||
|
|
|
@ -57,7 +57,7 @@ func NewTransaction(to string, value uint32, data []string) *Transaction {
|
||||||
for i, val := range data {
|
for i, val := range data {
|
||||||
instr, err := CompileInstr(val)
|
instr, err := CompileInstr(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("compile error:%d %v", i+1, err)
|
fmt.Printf("compile error:%d %v\n", i+1, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.data[i] = instr
|
tx.data[i] = instr
|
||||||
|
|
Loading…
Reference in New Issue