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
c66cf95b
Commit
c66cf95b
authored
Feb 23, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added address states for storing a session based address
parent
73b9ae95
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
7 deletions
+97
-7
address.go
ethchain/address.go
+60
-0
address_test.go
ethchain/address_test.go
+8
-0
block_manager.go
ethchain/block_manager.go
+29
-7
No files found.
ethchain/address.go
0 → 100644
View file @
c66cf95b
package
ethchain
import
(
"github.com/ethereum/eth-go/ethutil"
"math/big"
)
type
Address
struct
{
Amount
*
big
.
Int
Nonce
uint64
}
func
NewAddress
(
amount
*
big
.
Int
)
*
Address
{
return
&
Address
{
Amount
:
amount
,
Nonce
:
0
}
}
func
NewAddressFromData
(
data
[]
byte
)
*
Address
{
address
:=
&
Address
{}
address
.
RlpDecode
(
data
)
return
address
}
func
(
a
*
Address
)
AddFee
(
fee
*
big
.
Int
)
{
a
.
Amount
.
Add
(
a
.
Amount
,
fee
)
}
func
(
a
*
Address
)
RlpEncode
()
[]
byte
{
return
ethutil
.
Encode
([]
interface
{}{
a
.
Amount
,
a
.
Nonce
})
}
func
(
a
*
Address
)
RlpDecode
(
data
[]
byte
)
{
decoder
:=
ethutil
.
NewValueFromBytes
(
data
)
a
.
Amount
=
decoder
.
Get
(
0
)
.
BigInt
()
a
.
Nonce
=
decoder
.
Get
(
1
)
.
Uint
()
}
type
AddrStateStore
struct
{
states
map
[
string
]
*
AddressState
}
func
NewAddrStateStore
()
*
AddrStateStore
{
return
&
AddrStateStore
{
states
:
make
(
map
[
string
]
*
AddressState
)}
}
func
(
s
*
AddrStateStore
)
Add
(
addr
[]
byte
,
account
*
Address
)
*
AddressState
{
state
:=
&
AddressState
{
Nonce
:
account
.
Nonce
,
Account
:
account
}
s
.
states
[
string
(
addr
)]
=
state
return
state
}
func
(
s
*
AddrStateStore
)
Get
(
addr
[]
byte
)
*
AddressState
{
return
s
.
states
[
string
(
addr
)]
}
type
AddressState
struct
{
Nonce
uint64
Account
*
Address
}
ethchain/address_test.go
0 → 100644
View file @
c66cf95b
package
ethchain
import
(
"testing"
)
func
TestAddressState
(
t
*
testing
.
T
)
{
}
ethchain/block_manager.go
View file @
c66cf95b
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"encoding/hex"
"encoding/hex"
"fmt"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
_
"github.com/ethereum/eth-go/ethwire"
"github.com/obscuren/secp256k1-go"
"github.com/obscuren/secp256k1-go"
"log"
"log"
"math"
"math"
...
@@ -19,6 +19,7 @@ type BlockProcessor interface {
...
@@ -19,6 +19,7 @@ type BlockProcessor interface {
ProcessBlock
(
block
*
Block
)
ProcessBlock
(
block
*
Block
)
}
}
// TODO rename to state manager
type
BlockManager
struct
{
type
BlockManager
struct
{
// Mutex for locking the block processor. Blocks can only be handled one at a time
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex
sync
.
Mutex
mutex
sync
.
Mutex
...
@@ -26,6 +27,10 @@ type BlockManager struct {
...
@@ -26,6 +27,10 @@ type BlockManager struct {
// The block chain :)
// The block chain :)
bc
*
BlockChain
bc
*
BlockChain
// States for addresses. You can watch any address
// at any given time
addrStateStore
*
AddrStateStore
// Stack for processing contracts
// Stack for processing contracts
stack
*
Stack
stack
*
Stack
// non-persistent key/value memory storage
// non-persistent key/value memory storage
...
@@ -63,6 +68,7 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
...
@@ -63,6 +68,7 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
mem
:
make
(
map
[
string
]
*
big
.
Int
),
mem
:
make
(
map
[
string
]
*
big
.
Int
),
Pow
:
&
EasyPow
{},
Pow
:
&
EasyPow
{},
Speaker
:
speaker
,
Speaker
:
speaker
,
addrStateStore
:
NewAddrStateStore
(),
}
}
if
bm
.
bc
.
CurrentBlock
==
nil
{
if
bm
.
bc
.
CurrentBlock
==
nil
{
...
@@ -81,6 +87,22 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
...
@@ -81,6 +87,22 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
return
bm
return
bm
}
}
// Watches any given address and puts it in the address state store
func
(
bm
*
BlockManager
)
WatchAddr
(
addr
[]
byte
)
*
AddressState
{
account
:=
bm
.
bc
.
CurrentBlock
.
GetAddr
(
addr
)
return
bm
.
addrStateStore
.
Add
(
addr
,
account
)
}
func
(
bm
*
BlockManager
)
GetAddrState
(
addr
[]
byte
)
*
AddressState
{
addrState
:=
bm
.
addrStateStore
.
Get
(
addr
)
if
addrState
==
nil
{
addrState
=
bm
.
WatchAddr
(
addr
)
}
return
addrState
}
func
(
bm
*
BlockManager
)
BlockChain
()
*
BlockChain
{
func
(
bm
*
BlockManager
)
BlockChain
()
*
BlockChain
{
return
bm
.
bc
return
bm
.
bc
}
}
...
@@ -165,7 +187,7 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
...
@@ -165,7 +187,7 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
*/
*/
// Broadcast the valid block back to the wire
// Broadcast the valid block back to the wire
bm
.
Speaker
.
Broadcast
(
ethwire
.
MsgBlockTy
,
[]
interface
{}{
block
.
Value
()
.
Val
})
//
bm.Speaker.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val})
// If there's a block processor present, pass in the block for further
// If there's a block processor present, pass in the block for further
// processing
// processing
...
...
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