Skip to content

Commit 5ad473d

Browse files
committed
Moved methods to messages
1 parent db49417 commit 5ad473d

File tree

6 files changed

+14
-37
lines changed

6 files changed

+14
-37
lines changed

cmd/mist/gui.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
310310
s, r string
311311
)
312312

313-
if tx.CreatesContract() {
313+
if core.MessageCreatesContract(tx) {
314314
rec = nameReg.Storage(core.AddressFromMessage(tx))
315315
}
316316

@@ -322,7 +322,7 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
322322
if rec.Len() != 0 {
323323
r = strings.Trim(rec.Str(), "\x00")
324324
} else {
325-
if tx.CreatesContract() {
325+
if core.MessageCreatesContract(tx) {
326326
r = ethutil.Bytes2Hex(core.AddressFromMessage(tx))
327327
} else {
328328
r = ethutil.Bytes2Hex(tx.To())

core/state_transition.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ type StateTransition struct {
4444
type Message interface {
4545
Hash() []byte
4646

47-
CreatesContract() bool
48-
4947
From() []byte
5048
To() []byte
5149

@@ -63,6 +61,10 @@ func AddressFromMessage(msg Message) []byte {
6361
return crypto.Sha3(ethutil.NewValue([]interface{}{msg.From(), msg.Nonce()}).Encode())[12:]
6462
}
6563

64+
func MessageCreatesContract(msg Message) bool {
65+
return len(msg.To()) == 0
66+
}
67+
6668
func NewStateTransition(coinbase *state.StateObject, msg Message, state *state.StateDB, block *types.Block) *StateTransition {
6769
return &StateTransition{coinbase.Address(), msg.To(), msg, new(big.Int), new(big.Int).Set(msg.GasPrice()), msg.Value(), msg.Data(), state, block, coinbase, nil, nil, nil}
6870
}
@@ -93,7 +95,7 @@ func (self *StateTransition) From() *state.StateObject {
9395
return self.sen
9496
}
9597
func (self *StateTransition) To() *state.StateObject {
96-
if self.msg != nil && self.msg.CreatesContract() {
98+
if self.msg != nil && MessageCreatesContract(self.msg) {
9799
return nil
98100
}
99101

@@ -205,7 +207,7 @@ func (self *StateTransition) TransitionState() (err error) {
205207
var ret []byte
206208
vmenv := self.VmEnv()
207209
var ref vm.ClosureRef
208-
if msg.CreatesContract() {
210+
if MessageCreatesContract(msg) {
209211
self.rec = MakeContract(msg, self.state)
210212

211213
ret, err, ref = vmenv.Create(sender, self.rec.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)

core/transaction_pool.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
131131
return fmt.Errorf("Insufficient amount in sender's (%x) account", tx.From())
132132
}
133133

134-
if tx.IsContract() {
135-
if tx.GasPrice().Cmp(big.NewInt(minGasPrice)) < 0 {
136-
return fmt.Errorf("Gasprice too low, %s given should be at least %d.", tx.GasPrice, minGasPrice)
137-
}
138-
}
139-
140134
// Increment the nonce making each tx valid only once to prevent replay
141135
// attacks
142136

core/types/transaction.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import (
99
"github.com/obscuren/secp256k1-go"
1010
)
1111

12-
var ContractAddr = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
13-
1412
func IsContractAddr(addr []byte) bool {
1513
return len(addr) == 0
16-
//return bytes.Compare(addr, ContractAddr) == 0
1714
}
1815

1916
type Transaction struct {
@@ -25,17 +22,14 @@ type Transaction struct {
2522
data []byte
2623
v byte
2724
r, s []byte
28-
29-
// Indicates whether this tx is a contract creation transaction
30-
contractCreation bool
3125
}
3226

3327
func NewContractCreationTx(value, gas, gasPrice *big.Int, script []byte) *Transaction {
34-
return &Transaction{recipient: nil, value: value, gas: gas, gasPrice: gasPrice, data: script, contractCreation: true}
28+
return &Transaction{recipient: nil, value: value, gas: gas, gasPrice: gasPrice, data: script}
3529
}
3630

3731
func NewTransactionMessage(to []byte, value, gas, gasPrice *big.Int, data []byte) *Transaction {
38-
return &Transaction{recipient: to, value: value, gasPrice: gasPrice, gas: gas, data: data, contractCreation: IsContractAddr(to)}
32+
return &Transaction{recipient: to, value: value, gasPrice: gasPrice, gas: gas, data: data}
3933
}
4034

4135
func NewTransactionFromBytes(data []byte) *Transaction {
@@ -99,15 +93,6 @@ func (self *Transaction) To() []byte {
9993
return self.recipient
10094
}
10195

102-
func (tx *Transaction) CreatesContract() bool {
103-
return tx.contractCreation
104-
}
105-
106-
/* Deprecated */
107-
func (tx *Transaction) IsContract() bool {
108-
return tx.CreatesContract()
109-
}
110-
11196
func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
11297
v = tx.v
11398
r = ethutil.LeftPadBytes(tx.r, 32)
@@ -192,10 +177,6 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
192177

193178
tx.r = decoder.Get(7).Bytes()
194179
tx.s = decoder.Get(8).Bytes()
195-
196-
if IsContractAddr(tx.recipient) {
197-
tx.contractCreation = true
198-
}
199180
}
200181

201182
func (tx *Transaction) String() string {

xeth/hexface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
229229
return nil, err
230230
}
231231

232-
return NewJSReciept(tx.CreatesContract(), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil
232+
return NewJSReciept(core.MessageCreatesContract(tx), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil
233233
}
234234

235235
func (self *JSXEth) CompileMutan(code string) string {

xeth/js_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction {
102102
receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx))
103103
}
104104
sender := ethutil.Bytes2Hex(tx.Sender())
105-
createsContract := tx.CreatesContract()
105+
createsContract := core.MessageCreatesContract(tx)
106106

107107
var data string
108-
if tx.CreatesContract() {
108+
if createsContract {
109109
data = strings.Join(core.Disassemble(tx.Data()), "\n")
110110
} else {
111111
data = ethutil.Bytes2Hex(tx.Data())
112112
}
113113

114-
return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: tx.CreatesContract(), Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())}
114+
return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())}
115115
}
116116

117117
func (self *JSTransaction) ToString() string {

0 commit comments

Comments
 (0)