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
fd19142c
Commit
fd19142c
authored
May 20, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No longer store script directly in the state tree
parent
a2fb2655
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
70 additions
and
52 deletions
+70
-52
block.go
ethchain/block.go
+1
-1
block_chain.go
ethchain/block_chain.go
+1
-1
state.go
ethchain/state.go
+15
-34
state_manager.go
ethchain/state_manager.go
+3
-2
state_object.go
ethchain/state_object.go
+12
-9
state_object_test.go
ethchain/state_object_test.go
+25
-0
transaction.go
ethchain/transaction.go
+1
-1
vm.go
ethchain/vm.go
+1
-1
pub.go
ethpub/pub.go
+1
-2
types.go
ethpub/types.go
+9
-0
peer.go
peer.go
+1
-1
No files found.
ethchain/block.go
View file @
fd19142c
...
...
@@ -122,7 +122,7 @@ func (block *Block) Transactions() []*Transaction {
}
func
(
block
*
Block
)
PayFee
(
addr
[]
byte
,
fee
*
big
.
Int
)
bool
{
contract
:=
block
.
state
.
Get
Contra
ct
(
addr
)
contract
:=
block
.
state
.
Get
StateObje
ct
(
addr
)
// If we can't pay the fee return
if
contract
==
nil
||
contract
.
Amount
.
Cmp
(
fee
)
<
0
/* amount < fee */
{
fmt
.
Println
(
"Contract has insufficient funds"
,
contract
.
Amount
,
fee
)
...
...
ethchain/block_chain.go
View file @
fd19142c
...
...
@@ -260,7 +260,7 @@ func AddTestNetFunds(block *Block) {
"e6716f9544a56c530d868e4bfbacb172315bdead"
,
// Jeffrey
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"
,
// Vit
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4"
,
// Alex
"2ef47100e0787b915105fd5e3f4ff6752079d5cb"
,
// Maran
//
"2ef47100e0787b915105fd5e3f4ff6752079d5cb", // Maran
}
{
//log.Println("2^200 Wei to", addr)
codedAddr
:=
ethutil
.
FromHex
(
addr
)
...
...
ethchain/state.go
View file @
fd19142c
...
...
@@ -49,28 +49,6 @@ func (s *State) Purge() int {
return
s
.
trie
.
NewIterator
()
.
Purge
()
}
// XXX Deprecated
func
(
s
*
State
)
GetContract
(
addr
[]
byte
)
*
StateObject
{
data
:=
s
.
trie
.
Get
(
string
(
addr
))
if
data
==
""
{
return
nil
}
// build contract
contract
:=
NewStateObjectFromBytes
(
addr
,
[]
byte
(
data
))
// Check if there's a cached state for this contract
cachedState
:=
s
.
states
[
string
(
addr
)]
if
cachedState
!=
nil
{
contract
.
state
=
cachedState
}
else
{
// If it isn't cached, cache the state
s
.
states
[
string
(
addr
)]
=
contract
.
state
}
return
contract
}
func
(
s
*
State
)
GetStateObject
(
addr
[]
byte
)
*
StateObject
{
data
:=
s
.
trie
.
Get
(
string
(
addr
))
if
data
==
""
{
...
...
@@ -91,6 +69,21 @@ func (s *State) GetStateObject(addr []byte) *StateObject {
return
stateObject
}
// Updates any given state object
func
(
s
*
State
)
UpdateStateObject
(
object
*
StateObject
)
{
addr
:=
object
.
Address
()
if
object
.
state
!=
nil
{
s
.
states
[
string
(
addr
)]
=
object
.
state
}
ethutil
.
Config
.
Db
.
Put
(
ethutil
.
Sha3Bin
(
object
.
Script
()),
object
.
Script
())
s
.
trie
.
Update
(
string
(
addr
),
string
(
object
.
RlpEncode
()))
s
.
manifest
.
AddObjectChange
(
object
)
}
func
(
s
*
State
)
SetStateObject
(
stateObject
*
StateObject
)
{
s
.
states
[
string
(
stateObject
.
address
)]
=
stateObject
.
state
...
...
@@ -116,18 +109,6 @@ func (s *State) Copy() *State {
return
NewState
(
s
.
trie
.
Copy
())
}
// Updates any given state object
func
(
s
*
State
)
UpdateStateObject
(
object
*
StateObject
)
{
addr
:=
object
.
Address
()
if
object
.
state
!=
nil
{
s
.
states
[
string
(
addr
)]
=
object
.
state
}
s
.
trie
.
Update
(
string
(
addr
),
string
(
object
.
RlpEncode
()))
s
.
manifest
.
AddObjectChange
(
object
)
}
func
(
s
*
State
)
Put
(
key
,
object
[]
byte
)
{
s
.
trie
.
Update
(
string
(
key
),
string
(
object
))
}
...
...
ethchain/state_manager.go
View file @
fd19142c
...
...
@@ -87,7 +87,7 @@ func (sm *StateManager) BlockChain() *BlockChain {
func
(
sm
*
StateManager
)
MakeContract
(
state
*
State
,
tx
*
Transaction
)
*
StateObject
{
contract
:=
MakeContract
(
tx
,
state
)
if
contract
!=
nil
{
state
.
states
[
string
(
tx
.
Hash
()[
12
:
]
)]
=
contract
.
state
state
.
states
[
string
(
tx
.
CreationAddress
()
)]
=
contract
.
state
return
contract
}
...
...
@@ -117,7 +117,8 @@ func (sm *StateManager) ApplyTransactions(state *State, block *Block, txs []*Tra
}
}
else
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
,
false
)
contract
:=
state
.
GetContract
(
tx
.
Recipient
)
contract
:=
state
.
GetStateObject
(
tx
.
Recipient
)
ethutil
.
Config
.
Log
.
Debugf
(
"contract recip %x
\n
"
,
tx
.
Recipient
)
if
err
==
nil
&&
len
(
contract
.
Script
())
>
0
{
sm
.
EvalScript
(
state
,
contract
.
Script
(),
contract
,
tx
,
block
)
}
else
if
err
!=
nil
{
...
...
ethchain/state_object.go
View file @
fd19142c
...
...
@@ -10,8 +10,9 @@ type StateObject struct {
// Address of the object
address
[]
byte
// Shared attributes
Amount
*
big
.
Int
Nonce
uint64
Amount
*
big
.
Int
ScriptHash
[]
byte
Nonce
uint64
// Contract related attributes
state
*
State
script
[]
byte
...
...
@@ -22,12 +23,10 @@ type StateObject struct {
func
MakeContract
(
tx
*
Transaction
,
state
*
State
)
*
StateObject
{
// Create contract if there's no recipient
if
tx
.
IsContract
()
{
// FIXME
addr
:=
tx
.
Hash
()[
12
:
]
addr
:=
tx
.
CreationAddress
()
value
:=
tx
.
Value
contract
:=
NewContract
(
addr
,
value
,
[]
byte
(
""
))
state
.
UpdateStateObject
(
contract
)
contract
:=
NewContract
(
addr
,
value
,
ZeroHash256
)
contract
.
script
=
tx
.
Data
contract
.
initScript
=
tx
.
Init
...
...
@@ -146,9 +145,10 @@ func (c *StateObject) RlpEncode() []byte {
if
c
.
state
!=
nil
{
root
=
c
.
state
.
trie
.
Root
}
else
{
root
=
nil
root
=
ZeroHash256
}
return
ethutil
.
Encode
([]
interface
{}{
c
.
Amount
,
c
.
Nonce
,
root
,
c
.
script
})
return
ethutil
.
Encode
([]
interface
{}{
c
.
Amount
,
c
.
Nonce
,
root
,
ethutil
.
Sha3Bin
(
c
.
script
)})
}
func
(
c
*
StateObject
)
RlpDecode
(
data
[]
byte
)
{
...
...
@@ -157,7 +157,10 @@ func (c *StateObject) RlpDecode(data []byte) {
c
.
Amount
=
decoder
.
Get
(
0
)
.
BigInt
()
c
.
Nonce
=
decoder
.
Get
(
1
)
.
Uint
()
c
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
script
=
decoder
.
Get
(
3
)
.
Bytes
()
c
.
ScriptHash
=
decoder
.
Get
(
3
)
.
Bytes
()
c
.
script
,
_
=
ethutil
.
Config
.
Db
.
Get
(
c
.
ScriptHash
)
}
// Storage change object. Used by the manifest for notifying changes to
...
...
ethchain/state_object_test.go
0 → 100644
View file @
fd19142c
package
ethchain
import
(
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"testing"
)
func
TestSync
(
t
*
testing
.
T
)
{
ethutil
.
ReadConfig
(
""
,
ethutil
.
LogStd
)
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
contract
:=
NewContract
([]
byte
(
"aa"
),
ethutil
.
Big1
,
ZeroHash256
)
contract
.
script
=
[]
byte
{
42
}
state
.
UpdateStateObject
(
contract
)
state
.
Sync
()
object
:=
state
.
GetStateObject
([]
byte
(
"aa"
))
fmt
.
Printf
(
"%x
\n
"
,
object
.
Script
())
}
ethchain/transaction.go
View file @
fd19142c
...
...
@@ -60,7 +60,7 @@ func (tx *Transaction) IsContract() bool {
}
func
(
tx
*
Transaction
)
CreationAddress
()
[]
byte
{
return
tx
.
Hash
(
)[
12
:
]
return
ethutil
.
Sha3Bin
(
ethutil
.
NewValue
([]
interface
{}{
tx
.
Sender
(),
tx
.
Nonce
})
.
Encode
()
)[
12
:
]
}
func
(
tx
*
Transaction
)
Signature
(
key
[]
byte
)
[]
byte
{
...
...
ethchain/vm.go
View file @
fd19142c
...
...
@@ -471,7 +471,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
args
:=
mem
.
Get
(
inOffset
.
Int64
(),
inSize
.
Int64
())
// Fetch the contract which will serve as the closure body
contract
:=
vm
.
state
.
Get
Contra
ct
(
addr
.
Bytes
())
contract
:=
vm
.
state
.
Get
StateObje
ct
(
addr
.
Bytes
())
if
contract
!=
nil
{
// Prepay for the gas
...
...
ethpub/pub.go
View file @
fd19142c
...
...
@@ -45,7 +45,7 @@ func (lib *PEthereum) GetKey() *PKey {
}
func
(
lib
*
PEthereum
)
GetStateObject
(
address
string
)
*
PStateObject
{
stateObject
:=
lib
.
stateManager
.
CurrentState
()
.
Get
Contra
ct
(
ethutil
.
FromHex
(
address
))
stateObject
:=
lib
.
stateManager
.
CurrentState
()
.
Get
StateObje
ct
(
ethutil
.
FromHex
(
address
))
if
stateObject
!=
nil
{
return
NewPStateObject
(
stateObject
)
}
...
...
@@ -160,7 +160,6 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
}
acc
:=
lib
.
stateManager
.
TransState
()
.
GetStateObject
(
keyPair
.
Address
())
//acc := lib.stateManager.GetAddrState(keyPair.Address())
tx
.
Nonce
=
acc
.
Nonce
acc
.
Nonce
+=
1
lib
.
stateManager
.
TransState
()
.
SetStateObject
(
acc
)
...
...
ethpub/types.go
View file @
fd19142c
...
...
@@ -2,6 +2,7 @@ package ethpub
import
(
"encoding/hex"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
)
...
...
@@ -112,6 +113,14 @@ func (c *PStateObject) IsContract() bool {
return
false
}
func
(
c
*
PStateObject
)
Script
()
string
{
if
c
.
object
!=
nil
{
return
ethutil
.
Hex
(
c
.
object
.
Script
())
}
return
""
}
type
PStorageState
struct
{
StateAddress
string
Address
string
...
...
peer.go
View file @
fd19142c
...
...
@@ -18,7 +18,7 @@ const (
// The size of the output buffer for writing messages
outputBufferSize
=
50
// Current protocol version
ProtocolVersion
=
8
ProtocolVersion
=
9
)
type
DiscReason
byte
...
...
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