aboutsummaryrefslogtreecommitdiffstats
path: root/xeth
diff options
context:
space:
mode:
Diffstat (limited to 'xeth')
-rw-r--r--xeth/hexface.go118
-rw-r--r--xeth/pipe.go64
2 files changed, 112 insertions, 70 deletions
diff --git a/xeth/hexface.go b/xeth/hexface.go
index 5ef3eaf1a..31685403d 100644
--- a/xeth/hexface.go
+++ b/xeth/hexface.go
@@ -177,19 +177,25 @@ func (self *JSXEth) FromNumber(str string) string {
return ethutil.BigD(ethutil.Hex2Bytes(str)).String()
}
-func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) {
- var hash []byte
- var contractCreation bool
- if len(toStr) == 0 {
- contractCreation = true
+func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
+ var (
+ to []byte
+ value = ethutil.NewValue(valueStr)
+ gas = ethutil.NewValue(gasStr)
+ gasPrice = ethutil.NewValue(gasPriceStr)
+ data []byte
+ )
+
+ if ethutil.IsHex(codeStr) {
+ data = ethutil.Hex2Bytes(codeStr[2:])
} else {
- // Check if an address is stored by this address
- addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes()
- if len(addr) > 0 {
- hash = addr
- } else {
- hash = ethutil.Hex2Bytes(toStr)
- }
+ data = ethutil.Hex2Bytes(codeStr)
+ }
+
+ if ethutil.IsHex(toStr) {
+ to = ethutil.Hex2Bytes(toStr[2:])
+ } else {
+ to = ethutil.Hex2Bytes(toStr)
}
var keyPair *crypto.KeyPair
@@ -201,47 +207,77 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
}
if err != nil {
- return nil, err
+ return "", err
}
- var (
- value = ethutil.Big(valueStr)
- gas = ethutil.Big(gasStr)
- gasPrice = ethutil.Big(gasPriceStr)
- data []byte
- tx *chain.Transaction
- )
-
- if ethutil.IsHex(codeStr) {
- data = ethutil.Hex2Bytes(codeStr[2:])
- } else {
- data = ethutil.Hex2Bytes(codeStr)
+ tx, err := self.XEth.Transact(keyPair, to, value, gas, gasPrice, data)
+ if err != nil {
+ return "", err
}
-
- if contractCreation {
- tx = chain.NewContractCreationTx(value, gas, gasPrice, data)
- } else {
- tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data)
+ if chain.IsContractAddr(to) {
+ return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil
}
- acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address())
- tx.Nonce = acc.Nonce
- acc.Nonce += 1
- self.obj.BlockManager().TransState().UpdateStateObject(acc)
+ return ethutil.Bytes2Hex(tx.Hash()), nil
+
+ /*
+ var hash []byte
+ var contractCreation bool
+ if len(toStr) == 0 {
+ contractCreation = true
+ } else {
+ // Check if an address is stored by this address
+ addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes()
+ if len(addr) > 0 {
+ hash = addr
+ } else {
+ hash = ethutil.Hex2Bytes(toStr)
+ }
+ }
+
- tx.Sign(keyPair.PrivateKey)
- self.obj.TxPool().QueueTransaction(tx)
+ var (
+ value = ethutil.Big(valueStr)
+ gas = ethutil.Big(gasStr)
+ gasPrice = ethutil.Big(gasPriceStr)
+ data []byte
+ tx *chain.Transaction
+ )
- if contractCreation {
- pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
- }
+ if ethutil.IsHex(codeStr) {
+ data = ethutil.Hex2Bytes(codeStr[2:])
+ } else {
+ data = ethutil.Hex2Bytes(codeStr)
+ }
- return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
+ if contractCreation {
+ tx = chain.NewContractCreationTx(value, gas, gasPrice, data)
+ } else {
+ tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data)
+ }
+
+ acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address())
+ tx.Nonce = acc.Nonce
+ acc.Nonce += 1
+ self.obj.BlockManager().TransState().UpdateStateObject(acc)
+
+ tx.Sign(keyPair.PrivateKey)
+ self.obj.TxPool().QueueTransaction(tx)
+
+ if contractCreation {
+ pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
+ }
+
+ return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
+ */
}
func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
tx := chain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
- self.obj.TxPool().QueueTransaction(tx)
+ err := self.obj.TxPool().Add(tx)
+ if err != nil {
+ return nil, err
+ }
return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil
}
diff --git a/xeth/pipe.go b/xeth/pipe.go
index abed8ef9a..6e2f325c5 100644
--- a/xeth/pipe.go
+++ b/xeth/pipe.go
@@ -6,7 +6,6 @@ package xeth
import (
"fmt"
- "strings"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/crypto"
@@ -93,7 +92,7 @@ func (self *XEth) Exists(addr []byte) bool {
return self.World().Get(addr) != nil
}
-func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) ([]byte, error) {
+func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*chain.Transaction, error) {
// Check if an address is stored by this address
var hash []byte
addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes()
@@ -108,55 +107,62 @@ func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, pr
return self.Transact(key, hash, value, gas, price, data)
}
-func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *ethutil.Value, data []byte) ([]byte, error) {
+func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*chain.Transaction, error) {
var hash []byte
var contractCreation bool
- if rec == nil {
+ if chain.IsContractAddr(to) {
contractCreation = true
+ } else {
+ // Check if an address is stored by this address
+ addr := self.World().Config().Get("NameReg").Storage(to).Bytes()
+ if len(addr) > 0 {
+ hash = addr
+ } else {
+ hash = to
+ }
}
var tx *chain.Transaction
- // Compile and assemble the given data
if contractCreation {
- script, err := ethutil.Compile(string(data), false)
- if err != nil {
- return nil, err
- }
-
- tx = chain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), script)
+ tx = chain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data)
} else {
- data := ethutil.StringToByteFunc(string(data), func(s string) (ret []byte) {
- slice := strings.Split(s, "\n")
- for _, dataItem := range slice {
- d := ethutil.FormatData(dataItem)
- ret = append(ret, d...)
- }
- return
- })
-
tx = chain.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data)
}
- acc := self.blockManager.TransState().GetOrNewStateObject(key.Address())
- tx.Nonce = acc.Nonce
- acc.Nonce += 1
- self.blockManager.TransState().UpdateStateObject(acc)
+ state := self.blockManager.TransState()
+ nonce := state.GetNonce(key.Address())
+ tx.Nonce = nonce
tx.Sign(key.PrivateKey)
- self.obj.TxPool().QueueTransaction(tx)
+ err := self.obj.TxPool().Add(tx)
+ if err != nil {
+ return nil, err
+ }
+
+ state.SetNonce(key.Address(), nonce+1)
if contractCreation {
addr := tx.CreationAddress(self.World().State())
pipelogger.Infof("Contract addr %x\n", addr)
-
- return addr, nil
}
- return tx.Hash(), nil
+ return tx, nil
+
+ //acc := self.blockManager.TransState().GetOrNewStateObject(key.Address())
+ //self.obj.TxPool().QueueTransaction(tx)
+
+ //acc.Nonce += 1
+ //self.blockManager.TransState().UpdateStateObject(acc)
+
}
func (self *XEth) PushTx(tx *chain.Transaction) ([]byte, error) {
- self.obj.TxPool().QueueTransaction(tx)
+ err := self.obj.TxPool().Add(tx)
+ if err != nil {
+ return nil, err
+ }
+
+ //self.obj.TxPool().QueueTransaction(tx)
if tx.Recipient == nil {
addr := tx.CreationAddress(self.World().State())
pipelogger.Infof("Contract addr %x\n", addr)