aboutsummaryrefslogtreecommitdiffstats
path: root/xeth
diff options
context:
space:
mode:
Diffstat (limited to 'xeth')
-rw-r--r--xeth/types.go2
-rw-r--r--xeth/xeth.go35
2 files changed, 20 insertions, 17 deletions
diff --git a/xeth/types.go b/xeth/types.go
index a903fccbb..5b2d16018 100644
--- a/xeth/types.go
+++ b/xeth/types.go
@@ -150,7 +150,7 @@ type Transaction struct {
func NewTx(tx *types.Transaction) *Transaction {
hash := toHex(tx.Hash())
receiver := toHex(tx.To())
- if receiver == "0000000000000000000000000000000000000000" {
+ if len(receiver) == 0 {
receiver = toHex(core.AddressFromMessage(tx))
}
sender := toHex(tx.From())
diff --git a/xeth/xeth.go b/xeth/xeth.go
index 06915c5e0..f3569e454 100644
--- a/xeth/xeth.go
+++ b/xeth/xeth.go
@@ -7,6 +7,7 @@ package xeth
import (
"bytes"
"encoding/json"
+ "fmt"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
@@ -138,15 +139,15 @@ func (self *XEth) BalanceAt(addr string) string {
}
func (self *XEth) TxCountAt(address string) int {
- return int(self.State().SafeGet(address).Nonce)
+ return int(self.State().SafeGet(address).Nonce())
}
func (self *XEth) CodeAt(address string) string {
- return toHex(self.State().SafeGet(address).Code)
+ return toHex(self.State().SafeGet(address).Code())
}
func (self *XEth) IsContract(address string) bool {
- return len(self.State().SafeGet(address).Code) > 0
+ return len(self.State().SafeGet(address).Code()) > 0
}
func (self *XEth) SecretToAddress(key string) string {
@@ -252,7 +253,6 @@ func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (st
}
func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
-
var (
to []byte
value = ethutil.NewValue(valueStr)
@@ -276,29 +276,32 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string)
tx = types.NewTransactionMessage(to, value.BigInt(), gas.BigInt(), price.BigInt(), data)
}
- state := self.chainManager.TransState()
+ var err error
+ state := self.eth.ChainManager().TransState()
+ if balance := state.GetBalance(key.Address()); balance.Cmp(tx.Value()) < 0 {
+ return "", fmt.Errorf("insufficient balance. balance=%v tx=%v", balance, tx.Value())
+ }
nonce := state.GetNonce(key.Address())
tx.SetNonce(nonce)
tx.Sign(key.PrivateKey)
- // Do some pre processing for our "pre" events and hooks
- block := self.chainManager.NewBlock(key.Address())
- coinbase := state.GetOrNewStateObject(key.Address())
- coinbase.SetGasPool(block.GasLimit())
- self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
+ //fmt.Printf("create tx: %x %v\n", tx.Hash()[:4], tx.Nonce())
- err := self.eth.TxPool().Add(tx)
+ /*
+ // Do some pre processing for our "pre" events and hooks
+ block := self.chainManager.NewBlock(key.Address())
+ coinbase := state.GetOrNewStateObject(key.Address())
+ coinbase.SetGasPool(block.GasLimit())
+ self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
+ */
+
+ err = self.eth.TxPool().Add(tx)
if err != nil {
return "", err
}
state.SetNonce(key.Address(), nonce+1)
- if contractCreation {
- addr := core.AddressFromMessage(tx)
- pipelogger.Infof("Contract addr %x\n", addr)
- }
-
if types.IsContractAddr(to) {
return toHex(core.AddressFromMessage(tx)), nil
}