aboutsummaryrefslogtreecommitdiffstats
path: root/xeth/hexface.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-02 18:52:56 +0800
committerobscuren <geffobscura@gmail.com>2014-12-02 18:52:56 +0800
commit64f35ba8d1f31d6821a0a1bf946c71396a996f30 (patch)
tree375a081536c7c0b329a3b0c2e812ff05f81dd64c /xeth/hexface.go
parent616066a598933df7ef126186eb9c647094f665ca (diff)
parent99481a245adc2c4814ab6b38d94d63114f7bbb15 (diff)
downloaddexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.tar
dexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.tar.gz
dexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.tar.bz2
dexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.tar.lz
dexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.tar.xz
dexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.tar.zst
dexon-64f35ba8d1f31d6821a0a1bf946c71396a996f30.zip
merge errors fixed
Diffstat (limited to 'xeth/hexface.go')
-rw-r--r--xeth/hexface.go119
1 files changed, 78 insertions, 41 deletions
diff --git a/xeth/hexface.go b/xeth/hexface.go
index 5bf9845d4..9b7aa6b9c 100644
--- a/xeth/hexface.go
+++ b/xeth/hexface.go
@@ -178,19 +178,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
@@ -202,47 +208,78 @@ 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 *types.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 = types.NewContractCreationTx(value, gas, gasPrice, data)
- } else {
- tx = types.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
- tx.Sign(keyPair.PrivateKey)
- self.obj.TxPool().QueueTransaction(tx)
+ /*
+ 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)
+ }
+ }
- 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
+ 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)
+ }
+
+ 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 := types.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
}