Re-wrote Call and Execute to use the new vm messages
This commit is contained in:
parent
151f9c7f82
commit
65a802c678
@ -85,10 +85,6 @@ func (self *JSPipe) CoinBase() string {
|
|||||||
return ethutil.Bytes2Hex(self.obj.KeyManager().Address())
|
return ethutil.Bytes2Hex(self.obj.KeyManager().Address())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSPipe) BalanceAt(addr string) string {
|
|
||||||
return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSPipe) NumberToHuman(balance string) string {
|
func (self *JSPipe) NumberToHuman(balance string) string {
|
||||||
b := ethutil.Big(balance)
|
b := ethutil.Big(balance)
|
||||||
|
|
||||||
@ -101,10 +97,18 @@ func (self *JSPipe) StorageAt(addr, storageAddr string) string {
|
|||||||
return ethutil.Bytes2Hex(storage.Bytes())
|
return ethutil.Bytes2Hex(storage.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *JSPipe) BalanceAt(addr string) string {
|
||||||
|
return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *JSPipe) TxCountAt(address string) int {
|
func (self *JSPipe) TxCountAt(address string) int {
|
||||||
return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce)
|
return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *JSPipe) CodeAt(address string) string {
|
||||||
|
return ethutil.Bytes2Hex(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *JSPipe) IsContract(address string) bool {
|
func (self *JSPipe) IsContract(address string) bool {
|
||||||
return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0
|
return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0
|
||||||
}
|
}
|
||||||
@ -118,6 +122,18 @@ func (self *JSPipe) SecretToAddress(key string) string {
|
|||||||
return ethutil.Bytes2Hex(pair.Address())
|
return ethutil.Bytes2Hex(pair.Address())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *JSPipe) Execute(addr, value, gas, price, data string) (string, error) {
|
||||||
|
ret, err := self.ExecuteObject(&Object{
|
||||||
|
self.World().safeGet(ethutil.Hex2Bytes(addr))},
|
||||||
|
ethutil.Hex2Bytes(data),
|
||||||
|
ethutil.NewValue(value),
|
||||||
|
ethutil.NewValue(gas),
|
||||||
|
ethutil.NewValue(price),
|
||||||
|
)
|
||||||
|
|
||||||
|
return ethutil.Bytes2Hex(ret), err
|
||||||
|
}
|
||||||
|
|
||||||
type KeyVal struct {
|
type KeyVal struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ethpipe
|
package ethpipe
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
@ -51,18 +52,19 @@ func (self *Pipe) Execute(addr []byte, data []byte, value, gas, price *ethutil.V
|
|||||||
|
|
||||||
func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
|
func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
initiator = ethstate.NewStateObject([]byte{0})
|
initiator = ethstate.NewStateObject(self.obj.KeyManager().KeyPair().Address())
|
||||||
block = self.blockChain.CurrentBlock
|
block = self.blockChain.CurrentBlock
|
||||||
stateObject = object.StateObject
|
|
||||||
)
|
)
|
||||||
if self.Vm.State == nil {
|
|
||||||
self.Vm.State = self.World().State().Copy()
|
self.Vm.State = self.World().State().Copy()
|
||||||
}
|
|
||||||
|
|
||||||
vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()))
|
vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()))
|
||||||
|
vm.Verbose = true
|
||||||
|
|
||||||
closure := ethvm.NewClosure(ðstate.Message{}, initiator, stateObject, object.Code, gas.BigInt(), price.BigInt())
|
msg := ethvm.NewMessage(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt())
|
||||||
ret, _, err := closure.Call(vm, data)
|
ret, err := msg.Exec(object.Address(), initiator)
|
||||||
|
|
||||||
|
fmt.Println("returned from call", ret, err)
|
||||||
|
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user