From 740081e2f7f3f76f7522753fd3c714e57ea22f3f Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 21 Aug 2014 21:06:42 +0200 Subject: Storage at changed to return bytes --- ethpipe/js_pipe.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index b32e94a10..eeece5179 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -99,7 +99,8 @@ func (self *JSPipe) NumberToHuman(balance string) string { func (self *JSPipe) StorageAt(addr, storageAddr string) string { storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) - return storage.BigInt().String() + + return ethutil.Bytes2Hex(storage.Bytes()) } func (self *JSPipe) TxCountAt(address string) int { -- cgit v1.2.3 From 6afc16399f9624663579ad72950b4ea3b887db57 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 25 Aug 2014 12:53:06 +0200 Subject: Block size --- ethpipe/js_types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index 0fb3a3876..d9cbef12d 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -14,6 +14,7 @@ import ( // Block interface exposed to QML type JSBlock struct { ref *ethchain.Block + Size string `json:"size"` Number int `json:"number"` Hash string `json:"hash"` Transactions string `json:"transactions"` @@ -40,7 +41,7 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { return nil } - return &JSBlock{ref: block, Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} } func (self *JSBlock) ToString() string { -- cgit v1.2.3 From 0fea62ec6d33a83e602c804ee4b5b0a7896fd9c6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 8 Sep 2014 00:49:47 +0200 Subject: Make use of new list type for transactions instead of json --- ethpipe/js_types.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index d9cbef12d..8d2805f3d 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -1,7 +1,6 @@ package ethpipe import ( - "encoding/json" "strconv" "strings" @@ -13,16 +12,17 @@ import ( // Block interface exposed to QML type JSBlock struct { + //Transactions string `json:"transactions"` ref *ethchain.Block - Size string `json:"size"` - Number int `json:"number"` - Hash string `json:"hash"` - Transactions string `json:"transactions"` - Time int64 `json:"time"` - Coinbase string `json:"coinbase"` - Name string `json:"name"` - GasLimit string `json:"gasLimit"` - GasUsed string `json:"gasUsed"` + Size string `json:"size"` + Number int `json:"number"` + Hash string `json:"hash"` + Transactions *ethutil.List `json:"transactions"` + Time int64 `json:"time"` + Coinbase string `json:"coinbase"` + Name string `json:"name"` + GasLimit string `json:"gasLimit"` + GasUsed string `json:"gasUsed"` } // Creates a new QML Block from a chain block @@ -36,12 +36,16 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { ptxs = append(ptxs, *NewJSTx(tx)) } - txJson, err := json.Marshal(ptxs) - if err != nil { - return nil - } + /* + txJson, err := json.Marshal(ptxs) + if err != nil { + return nil + } + return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + */ + list := ethutil.NewList(ptxs) - return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: list, Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} } func (self *JSBlock) ToString() string { -- cgit v1.2.3 From 7dacd7eb7818a336b3be99aea834093cf40a1b08 Mon Sep 17 00:00:00 2001 From: Cayman Nava Date: Sat, 6 Sep 2014 13:51:13 -0700 Subject: add pushtx to api Previously the software assumed use of an internal private key for use in all broadcasted transactions. This addition lets nodes relay pre-signed transactions originating from sources other than the node itself. --- ethpipe/js_pipe.go | 6 ++++++ ethpipe/pipe.go | 9 +++++++++ 2 files changed, 15 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index eeece5179..47cac2ca2 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -225,6 +225,12 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil } +func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) { + tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) + self.obj.TxPool().QueueTransaction(tx) + return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil +} + func (self *JSPipe) CompileMutan(code string) string { data, err := self.Pipe.CompileMutan(code) if err != nil { diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 800a71139..b7d3be041 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -149,6 +149,15 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price return tx.Hash(), nil } +func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) { + self.obj.TxPool().QueueTransaction(tx) + if tx.Recipient == nil { + logger.Infof("Contract addr %x", tx.CreationAddress()) + return tx.CreationAddress(), nil + } + return tx.Hash(), nil +} + func (self *Pipe) CompileMutan(code string) ([]byte, error) { data, err := ethutil.Compile(code, false) if err != nil { -- cgit v1.2.3 From 2fb57b2ea7b7f697ddc4811c471d87116eae07cc Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 14 Sep 2014 00:13:23 +0200 Subject: Reworked filters --- ethpipe/js_pipe.go | 97 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 95 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index eeece5179..7ee183c84 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -3,12 +3,10 @@ package ethpipe import ( "bytes" "encoding/json" - "fmt" "sync/atomic" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethcrypto" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethutil" ) @@ -234,102 +232,11 @@ func (self *JSPipe) CompileMutan(code string) string { return ethutil.Bytes2Hex(data) } -func (self *JSPipe) Watch(object map[string]interface{}) *JSFilter { - return NewJSFilterFromMap(object, self.Pipe.obj) - /*} else if str, ok := object.(string); ok { - println("str") - return NewJSFilterFromString(str, self.Pipe.obj) - */ -} - -func (self *JSPipe) Messages(object map[string]interface{}) string { - filter := self.Watch(object) - filter.Uninstall() - - return filter.Messages() - -} - -type JSFilter struct { - eth ethchain.EthManager - *ethchain.Filter - quit chan bool - - BlockCallback func(*ethchain.Block) - MessageCallback func(ethstate.Messages) -} - -func NewJSFilterFromMap(object map[string]interface{}, eth ethchain.EthManager) *JSFilter { - filter := &JSFilter{eth, ethchain.NewFilterFromMap(object, eth), make(chan bool), nil, nil} - - go filter.mainLoop() - - return filter -} - -func NewJSFilterFromString(str string, eth ethchain.EthManager) *JSFilter { - return nil -} - -func (self *JSFilter) MessagesToJson(messages ethstate.Messages) string { +func ToJSMessages(messages ethstate.Messages) *ethutil.List { var msgs []JSMessage for _, m := range messages { msgs = append(msgs, NewJSMessage(m)) } - // Return an empty array instead of "null" - if len(msgs) == 0 { - return "[]" - } - - b, err := json.Marshal(msgs) - if err != nil { - return "{\"error\":" + err.Error() + "}" - } - - return string(b) -} - -func (self *JSFilter) Messages() string { - return self.MessagesToJson(self.Find()) -} - -func (self *JSFilter) mainLoop() { - blockChan := make(chan ethreact.Event, 5) - messageChan := make(chan ethreact.Event, 5) - // Subscribe to events - reactor := self.eth.Reactor() - reactor.Subscribe("newBlock", blockChan) - reactor.Subscribe("messages", messageChan) -out: - for { - select { - case <-self.quit: - break out - case block := <-blockChan: - if block, ok := block.Resource.(*ethchain.Block); ok { - if self.BlockCallback != nil { - self.BlockCallback(block) - } - } - case msg := <-messageChan: - if messages, ok := msg.Resource.(ethstate.Messages); ok { - if self.MessageCallback != nil { - println("messages!") - msgs := self.FilterMessages(messages) - if len(msgs) > 0 { - self.MessageCallback(msgs) - } - } - } - } - } -} - -func (self *JSFilter) Changed(object interface{}) { - fmt.Printf("%T\n", object) -} - -func (self *JSFilter) Uninstall() { - self.quit <- true + return ethutil.NewList(msgs) } -- cgit v1.2.3 From 65a802c6787184951753ba2f79fdf60dce526721 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 22 Sep 2014 14:51:21 +0200 Subject: Re-wrote Call and Execute to use the new vm messages --- ethpipe/js_pipe.go | 30 +++++++++++++++++++++++------- ethpipe/pipe.go | 30 ++++++++++++++++-------------- 2 files changed, 39 insertions(+), 21 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 32212b26a..96990b671 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -85,10 +85,6 @@ func (self *JSPipe) CoinBase() string { 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 { b := ethutil.Big(balance) @@ -101,10 +97,18 @@ func (self *JSPipe) StorageAt(addr, storageAddr string) string { 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 { 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 { 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()) } +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 { Key string `json:"key"` Value string `json:"value"` @@ -224,9 +240,9 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr } func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) { - tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) - self.obj.TxPool().QueueTransaction(tx) - return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil + tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) + self.obj.TxPool().QueueTransaction(tx) + return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil } func (self *JSPipe) CompileMutan(code string) string { diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index b7d3be041..7c3f491d3 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -1,6 +1,7 @@ package ethpipe import ( + "fmt" "strings" "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) { var ( - initiator = ethstate.NewStateObject([]byte{0}) - block = self.blockChain.CurrentBlock - stateObject = object.StateObject + initiator = ethstate.NewStateObject(self.obj.KeyManager().KeyPair().Address()) + block = self.blockChain.CurrentBlock ) - 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.Verbose = true - closure := ethvm.NewClosure(ðstate.Message{}, initiator, stateObject, object.Code, gas.BigInt(), price.BigInt()) - ret, _, err := closure.Call(vm, data) + msg := ethvm.NewMessage(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) + ret, err := msg.Exec(object.Address(), initiator) + + fmt.Println("returned from call", ret, err) return ret, err } @@ -150,12 +152,12 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price } func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) { - self.obj.TxPool().QueueTransaction(tx) - if tx.Recipient == nil { - logger.Infof("Contract addr %x", tx.CreationAddress()) - return tx.CreationAddress(), nil - } - return tx.Hash(), nil + self.obj.TxPool().QueueTransaction(tx) + if tx.Recipient == nil { + logger.Infof("Contract addr %x", tx.CreationAddress()) + return tx.CreationAddress(), nil + } + return tx.Hash(), nil } func (self *Pipe) CompileMutan(code string) ([]byte, error) { -- cgit v1.2.3