From 6ea05f5a54c2db009e4379ce917590568b950f42 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 15 Aug 2015 23:51:31 +0200 Subject: rpc/api, xeth: added signTransaction method SignTransaction creates a transaction but does submit it to the network. SignTransaction returns a structure which includes the transaction object details as well as the RLP encoded transaction that could possibly be submitted by the SendRawTransaction method. --- xeth/xeth.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 35e6dd52d..04fdea1d2 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -912,6 +912,60 @@ func (self *XEth) Frontend() Frontend { return self.frontend } +func (self *XEth) SignTransaction(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (*types.Transaction, error) { + if len(toStr) > 0 && toStr != "0x" && !isAddress(toStr) { + return nil, errors.New("Invalid address") + } + + var ( + from = common.HexToAddress(fromStr) + to = common.HexToAddress(toStr) + value = common.Big(valueStr) + gas *big.Int + price *big.Int + data []byte + contractCreation bool + ) + + if len(gasStr) == 0 { + gas = DefaultGas() + } else { + gas = common.Big(gasStr) + } + + if len(gasPriceStr) == 0 { + price = self.DefaultGasPrice() + } else { + price = common.Big(gasPriceStr) + } + + data = common.FromHex(codeStr) + if len(toStr) == 0 { + contractCreation = true + } + + var nonce uint64 + if len(nonceStr) != 0 { + nonce = common.Big(nonceStr).Uint64() + } else { + state := self.backend.TxPool().State() + nonce = state.GetNonce(from) + } + var tx *types.Transaction + if contractCreation { + tx = types.NewContractCreation(nonce, value, gas, price, data) + } else { + tx = types.NewTransaction(nonce, to, value, gas, price, data) + } + + signed, err := self.sign(tx, from, false) + if err != nil { + return nil, err + } + + return signed, nil +} + func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { // this minimalistic recoding is enough (works for natspec.js) -- cgit v1.2.3 From a1d9ef48c505ab4314ca8e3ee1fc272032da3034 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 19 Oct 2015 16:08:17 +0200 Subject: core, eth, rpc: split out block validator and state processor This removes the burden on a single object to take care of all validation and state processing. Now instead the validation is done by the `core.BlockValidator` (`types.Validator`) that takes care of both header and uncle validation through the `ValidateBlock` method and state validation through the `ValidateState` method. The state processing is done by a new object `core.StateProcessor` (`types.Processor`) and accepts a new state as input and uses that to process the given block's transactions (and uncles for rewords) to calculate the state root for the next block (P_n + 1). --- xeth/xeth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 35e6dd52d..243bef0b8 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -379,7 +379,7 @@ func (self *XEth) CurrentBlock() *types.Block { } func (self *XEth) GetBlockReceipts(bhash common.Hash) types.Receipts { - return self.backend.BlockProcessor().GetBlockReceipts(bhash) + return core.GetBlockReceipts(self.backend.ChainDb(), bhash) } func (self *XEth) GetTxReceipt(txhash common.Hash) *types.Receipt { -- cgit v1.2.3 From e86e0ecdc8a977db2ff5df60dca3cad8355ace6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 22 Oct 2015 15:43:21 +0300 Subject: core, eth, miner, xeth: clean up tx/receipt db accessors --- xeth/xeth.go | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 243bef0b8..ae9f1fe47 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -322,44 +322,11 @@ func (self *XEth) EthBlockByHash(strHash string) *types.Block { return block } -func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blhash common.Hash, blnum *big.Int, txi uint64) { - // Due to increasing return params and need to determine if this is from transaction pool or - // some chain, this probably needs to be refactored for more expressiveness - data, _ := self.backend.ChainDb().Get(common.FromHex(hash)) - if len(data) != 0 { - dtx := new(types.Transaction) - if err := rlp.DecodeBytes(data, dtx); err != nil { - glog.V(logger.Error).Infoln(err) - return - } - tx = dtx - } else { // check pending transactions - tx = self.backend.TxPool().GetTransaction(common.HexToHash(hash)) - } - - // meta - var txExtra struct { - BlockHash common.Hash - BlockIndex uint64 - Index uint64 - } - - v, dberr := self.backend.ChainDb().Get(append(common.FromHex(hash), 0x0001)) - // TODO check specifically for ErrNotFound - if dberr != nil { - return +func (self *XEth) EthTransactionByHash(hash string) (*types.Transaction, common.Hash, uint64, uint64) { + if tx, hash, number, index := core.GetTransaction(self.backend.ChainDb(), common.HexToHash(hash)); tx != nil { + return tx, hash, number, index } - r := bytes.NewReader(v) - err := rlp.Decode(r, &txExtra) - if err == nil { - blhash = txExtra.BlockHash - blnum = big.NewInt(int64(txExtra.BlockIndex)) - txi = txExtra.Index - } else { - glog.V(logger.Error).Infoln(err) - } - - return + return self.backend.TxPool().GetTransaction(common.HexToHash(hash)), common.Hash{}, 0, 0 } func (self *XEth) BlockByNumber(num int64) *Block { -- cgit v1.2.3