Updated to use new state object

This commit is contained in:
obscuren 2014-04-16 04:08:25 +02:00
parent 6b644c17a7
commit 1cd7d4456b
4 changed files with 25 additions and 40 deletions

@ -170,7 +170,7 @@ func (ui *Gui) update() {
txChan := make(chan ethchain.TxMsg, 1) txChan := make(chan ethchain.TxMsg, 1)
ui.eth.TxPool().Subscribe(txChan) ui.eth.TxPool().Subscribe(txChan)
account := ui.eth.StateManager().GetAddrState(ui.addr).Account account := ui.eth.StateManager().GetAddrState(ui.addr).Object
unconfirmedFunds := new(big.Int) unconfirmedFunds := new(big.Int)
ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount))) ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount)))
for { for {

@ -6,7 +6,6 @@ import (
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils" "github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/mutan"
"github.com/obscuren/secp256k1-go" "github.com/obscuren/secp256k1-go"
"strings" "strings"
) )
@ -44,22 +43,6 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) {
return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub)
} }
// General compiler and preprocessor function
func compile(script string) ([]byte, error) {
asm, errors := mutan.Compile(strings.NewReader(script), false)
if len(errors) > 0 {
var errs string
for _, er := range errors {
if er != nil {
errs += er.Error()
}
}
return nil, fmt.Errorf("%v", errs)
}
return ethutil.Assemble(asm...), nil
}
func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) {
var hash []byte var hash []byte
var contractCreation bool var contractCreation bool
@ -81,18 +64,16 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin
// Compile and assemble the given data // Compile and assemble the given data
if contractCreation { if contractCreation {
mainInput, initInput := ethutil.PreProcess(data) mainInput, initInput := ethutil.PreProcess(data)
mainScript, err := compile(mainInput) mainScript, err := utils.Compile(mainInput)
if err != nil { if err != nil {
return "", err return "", err
} }
initScript, err := compile(initInput) initScript, err := utils.Compile(initInput)
if err != nil { if err != nil {
return "", err return "", err
} }
// TODO tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript, initScript)
fmt.Println(initScript)
tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript)
} else { } else {
tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil) tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil)
} }

@ -6,14 +6,13 @@ import (
"github.com/ethereum/eth-go" "github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/niemeyer/qml" "github.com/niemeyer/qml"
"github.com/obscuren/mutan"
"math/big" "math/big"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
) )
type memAddr struct { type memAddr struct {
@ -99,25 +98,24 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string)
state := ui.eth.BlockChain().CurrentBlock.State() state := ui.eth.BlockChain().CurrentBlock.State()
mainInput, _ := ethutil.PreProcess(data) mainInput, _ := ethutil.PreProcess(data)
asm, err := mutan.Compile(strings.NewReader(mainInput), false) callerScript, err := utils.Compile(mainInput)
if err != nil { if err != nil {
fmt.Println(err) ethutil.Config.Log.Debugln(err)
for _, e := range err {
ui.win.Root().Call("addDebugMessage", e.Error()) return
}
} }
callerScript := ethutil.Assemble(asm...)
dis := ethchain.Disassemble(callerScript) dis := ethchain.Disassemble(callerScript)
ui.win.Root().Call("clearAsm") ui.win.Root().Call("clearAsm")
for _, str := range dis { for _, str := range dis {
ui.win.Root().Call("setAsm", str) ui.win.Root().Call("setAsm", str)
} }
callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasPriceStr), callerScript) callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasPriceStr), callerScript, nil)
// Contract addr as test address // Contract addr as test address
keyPair := ethutil.Config.Db.GetKeys()[0] keyPair := ethutil.Config.Db.GetKeys()[0]
account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Account account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Object
c := ethchain.MakeContract(callerTx, state) c := ethchain.MakeContract(callerTx, state)
callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), new(big.Int)) callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), new(big.Int))

@ -11,8 +11,7 @@ import (
"github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire" "github.com/ethereum/eth-go/ethwire"
"github.com/obscuren/mutan" "github.com/ethereum/go-ethereum/utils"
_ "math/big"
"os" "os"
"strings" "strings"
) )
@ -171,7 +170,7 @@ func (i *Console) ParseInput(input string) bool {
if err != nil { if err != nil {
fmt.Println("recipient err:", err) fmt.Println("recipient err:", err)
} else { } else {
tx := ethchain.NewTransactionMessage(recipient, ethutil.Big(tokens[2]), ethutil.Big(tokens[3]), ethutil.Big(tokens[4]), []string{""}) tx := ethchain.NewTransactionMessage(recipient, ethutil.Big(tokens[2]), ethutil.Big(tokens[3]), ethutil.Big(tokens[4]), nil)
key := ethutil.Config.Db.GetKeys()[0] key := ethutil.Config.Db.GetKeys()[0]
tx.Sign(key.PrivateKey) tx.Sign(key.PrivateKey)
@ -190,15 +189,22 @@ func (i *Console) ParseInput(input string) bool {
} }
case "contract": case "contract":
fmt.Println("Contract editor (Ctrl-D = done)") fmt.Println("Contract editor (Ctrl-D = done)")
asm, err := mutan.Compile(strings.NewReader(i.Editor()), false)
mainInput, initInput := ethutil.PreProcess(i.Editor())
mainScript, err := utils.Compile(mainInput)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
break
}
initScript, err := utils.Compile(initInput)
if err != nil {
fmt.Println(err)
break break
} }
code := ethutil.Assemble(asm) contract := ethchain.NewContractCreationTx(ethutil.Big(tokens[0]), ethutil.Big(tokens[1]), mainScript, initScript)
contract := ethchain.NewContractCreationTx(ethutil.Big(tokens[0]), ethutil.Big(tokens[1]), code)
key := ethutil.Config.Db.GetKeys()[0] key := ethutil.Config.Db.GetKeys()[0]
contract.Sign(key.PrivateKey) contract.Sign(key.PrivateKey)