Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
281559d4
Commit
281559d4
authored
May 22, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Canonical contract creation
parent
cc8464ce
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
17 deletions
+28
-17
state_manager.go
ethchain/state_manager.go
+15
-7
state_object.go
ethchain/state_object.go
+1
-2
transaction.go
ethchain/transaction.go
+2
-7
types.go
ethchain/types.go
+7
-0
pub.go
ethpub/pub.go
+3
-1
No files found.
ethchain/state_manager.go
View file @
281559d4
...
@@ -84,7 +84,7 @@ func (sm *StateManager) BlockChain() *BlockChain {
...
@@ -84,7 +84,7 @@ func (sm *StateManager) BlockChain() *BlockChain {
return
sm
.
bc
return
sm
.
bc
}
}
func
(
sm
*
StateManager
)
Make
Contra
ct
(
state
*
State
,
tx
*
Transaction
)
*
StateObject
{
func
(
sm
*
StateManager
)
Make
StateObje
ct
(
state
*
State
,
tx
*
Transaction
)
*
StateObject
{
contract
:=
MakeContract
(
tx
,
state
)
contract
:=
MakeContract
(
tx
,
state
)
if
contract
!=
nil
{
if
contract
!=
nil
{
state
.
states
[
string
(
tx
.
CreationAddress
())]
=
contract
.
state
state
.
states
[
string
(
tx
.
CreationAddress
())]
=
contract
.
state
...
@@ -123,18 +123,24 @@ func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transac
...
@@ -123,18 +123,24 @@ func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transac
// If there's no recipient, it's a contract
// If there's no recipient, it's a contract
// Check if this is a contract creation traction and if so
// Check if this is a contract creation traction and if so
// create a contract of this tx.
// create a contract of this tx.
// TODO COMMENT THIS SECTION
totalGasUsed
:=
big
.
NewInt
(
0
)
totalGasUsed
:=
big
.
NewInt
(
0
)
if
tx
.
IsContract
()
{
if
tx
.
IsContract
()
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
state
,
false
)
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
state
,
false
)
if
err
==
nil
{
if
err
==
nil
{
contract
:=
sm
.
Make
Contra
ct
(
state
,
tx
)
contract
:=
sm
.
Make
StateObje
ct
(
state
,
tx
)
if
contract
!=
nil
{
if
contract
!=
nil
{
sm
.
EvalScript
(
state
,
contract
.
Init
(),
contract
,
tx
,
block
)
script
,
err
:=
sm
.
EvalScript
(
state
,
contract
.
Init
(),
contract
,
tx
,
block
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"[STATE] Error during init script run %v"
,
err
)
}
contract
.
script
=
script
state
.
UpdateStateObject
(
contract
)
}
else
{
}
else
{
return
nil
,
fmt
.
Errorf
(
"[STATE] Unable to create contract"
)
return
nil
,
fmt
.
Errorf
(
"[STATE] Unable to create contract"
)
}
}
}
else
{
}
else
{
return
nil
,
fmt
.
Errorf
(
"[STATE] contract creat
e
:"
,
err
)
return
nil
,
fmt
.
Errorf
(
"[STATE] contract creat
ion tx
:"
,
err
)
}
}
}
else
{
}
else
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
state
,
false
)
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
state
,
false
)
...
@@ -331,10 +337,10 @@ func (sm *StateManager) Stop() {
...
@@ -331,10 +337,10 @@ func (sm *StateManager) Stop() {
sm
.
bc
.
Stop
()
sm
.
bc
.
Stop
()
}
}
func
(
sm
*
StateManager
)
EvalScript
(
state
*
State
,
script
[]
byte
,
object
*
StateObject
,
tx
*
Transaction
,
block
*
Block
)
{
func
(
sm
*
StateManager
)
EvalScript
(
state
*
State
,
script
[]
byte
,
object
*
StateObject
,
tx
*
Transaction
,
block
*
Block
)
(
ret
[]
byte
,
err
error
)
{
account
:=
state
.
GetAccount
(
tx
.
Sender
())
account
:=
state
.
GetAccount
(
tx
.
Sender
())
err
:
=
account
.
ConvertGas
(
tx
.
Gas
,
tx
.
GasPrice
)
err
=
account
.
ConvertGas
(
tx
.
Gas
,
tx
.
GasPrice
)
if
err
!=
nil
{
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Debugln
(
err
)
ethutil
.
Config
.
Log
.
Debugln
(
err
)
return
return
...
@@ -351,11 +357,13 @@ func (sm *StateManager) EvalScript(state *State, script []byte, object *StateObj
...
@@ -351,11 +357,13 @@ func (sm *StateManager) EvalScript(state *State, script []byte, object *StateObj
Value
:
tx
.
Value
,
Value
:
tx
.
Value
,
//Price: tx.GasPrice,
//Price: tx.GasPrice,
})
})
closure
.
Call
(
vm
,
tx
.
Data
,
nil
)
ret
,
err
=
closure
.
Call
(
vm
,
tx
.
Data
,
nil
)
// Update the account (refunds)
// Update the account (refunds)
state
.
UpdateStateObject
(
account
)
state
.
UpdateStateObject
(
account
)
state
.
UpdateStateObject
(
object
)
state
.
UpdateStateObject
(
object
)
return
}
}
func
(
sm
*
StateManager
)
notifyChanges
(
state
*
State
)
{
func
(
sm
*
StateManager
)
notifyChanges
(
state
*
State
)
{
...
...
ethchain/state_object.go
View file @
281559d4
...
@@ -28,8 +28,7 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
...
@@ -28,8 +28,7 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
value
:=
tx
.
Value
value
:=
tx
.
Value
contract
:=
NewContract
(
addr
,
value
,
ZeroHash256
)
contract
:=
NewContract
(
addr
,
value
,
ZeroHash256
)
contract
.
script
=
tx
.
Data
contract
.
initScript
=
tx
.
Data
contract
.
initScript
=
tx
.
Init
state
.
UpdateStateObject
(
contract
)
state
.
UpdateStateObject
(
contract
)
...
...
ethchain/transaction.go
View file @
281559d4
...
@@ -16,7 +16,6 @@ type Transaction struct {
...
@@ -16,7 +16,6 @@ type Transaction struct {
Gas
*
big
.
Int
Gas
*
big
.
Int
GasPrice
*
big
.
Int
GasPrice
*
big
.
Int
Data
[]
byte
Data
[]
byte
Init
[]
byte
v
byte
v
byte
r
,
s
[]
byte
r
,
s
[]
byte
...
@@ -24,8 +23,8 @@ type Transaction struct {
...
@@ -24,8 +23,8 @@ type Transaction struct {
contractCreation
bool
contractCreation
bool
}
}
func
NewContractCreationTx
(
value
,
gas
,
gasPrice
*
big
.
Int
,
script
[]
byte
,
init
[]
byte
)
*
Transaction
{
func
NewContractCreationTx
(
value
,
gas
,
gasPrice
*
big
.
Int
,
script
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Value
:
value
,
Gas
:
gas
,
GasPrice
:
gasPrice
,
Data
:
script
,
Init
:
init
,
contractCreation
:
true
}
return
&
Transaction
{
Value
:
value
,
Gas
:
gas
,
GasPrice
:
gasPrice
,
Data
:
script
,
contractCreation
:
true
}
}
}
func
NewTransactionMessage
(
to
[]
byte
,
value
,
gas
,
gasPrice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
func
NewTransactionMessage
(
to
[]
byte
,
value
,
gas
,
gasPrice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
...
@@ -115,10 +114,6 @@ func (tx *Transaction) Sign(privk []byte) error {
...
@@ -115,10 +114,6 @@ func (tx *Transaction) Sign(privk []byte) error {
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
GasPrice
,
tx
.
Gas
,
tx
.
Recipient
,
tx
.
Value
,
tx
.
Data
}
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
GasPrice
,
tx
.
Gas
,
tx
.
Recipient
,
tx
.
Value
,
tx
.
Data
}
if
tx
.
contractCreation
{
data
=
append
(
data
,
tx
.
Init
)
}
return
append
(
data
,
tx
.
v
,
tx
.
r
,
tx
.
s
)
return
append
(
data
,
tx
.
v
,
tx
.
r
,
tx
.
s
)
}
}
...
...
ethchain/types.go
View file @
281559d4
...
@@ -322,3 +322,10 @@ func IsOpCode(s string) bool {
...
@@ -322,3 +322,10 @@ func IsOpCode(s string) bool {
}
}
return
false
return
false
}
}
func
AppendScript
(
init
,
script
[]
byte
)
[]
byte
{
s
:=
append
(
init
,
byte
(
oRETURN
))
s
=
append
(
s
,
script
...
)
return
s
}
ethpub/pub.go
View file @
281559d4
...
@@ -141,7 +141,9 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
...
@@ -141,7 +141,9 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
}
}
}
}
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
mainScript
,
initScript
)
script
:=
ethchain
.
AppendScript
(
initScript
,
mainScript
)
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
script
)
}
else
{
}
else
{
// Just in case it was submitted as a 0x prefixed string
// Just in case it was submitted as a 0x prefixed string
if
len
(
initStr
)
>
0
&&
initStr
[
0
:
2
]
==
"0x"
{
if
len
(
initStr
)
>
0
&&
initStr
[
0
:
2
]
==
"0x"
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment