Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
c66cf95b
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c66cf95b
编写于
2月 23, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added address states for storing a session based address
上级
73b9ae95
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
97 addition
and
7 deletion
+97
-7
ethchain/address.go
ethchain/address.go
+60
-0
ethchain/address_test.go
ethchain/address_test.go
+8
-0
ethchain/block_manager.go
ethchain/block_manager.go
+29
-7
未找到文件。
ethchain/address.go
0 → 100644
浏览文件 @
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
浏览文件 @
c66cf95b
package
ethchain
import
(
"testing"
)
func
TestAddressState
(
t
*
testing
.
T
)
{
}
ethchain/block_manager.go
浏览文件 @
c66cf95b
...
...
@@ -5,7 +5,7 @@ import (
"encoding/hex"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
_
"github.com/ethereum/eth-go/ethwire"
"github.com/obscuren/secp256k1-go"
"log"
"math"
...
...
@@ -19,6 +19,7 @@ type BlockProcessor interface {
ProcessBlock
(
block
*
Block
)
}
// TODO rename to state manager
type
BlockManager
struct
{
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex
sync
.
Mutex
...
...
@@ -26,6 +27,10 @@ type BlockManager struct {
// The block chain :)
bc
*
BlockChain
// States for addresses. You can watch any address
// at any given time
addrStateStore
*
AddrStateStore
// Stack for processing contracts
stack
*
Stack
// non-persistent key/value memory storage
...
...
@@ -63,6 +68,7 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
mem
:
make
(
map
[
string
]
*
big
.
Int
),
Pow
:
&
EasyPow
{},
Speaker
:
speaker
,
addrStateStore
:
NewAddrStateStore
(),
}
if
bm
.
bc
.
CurrentBlock
==
nil
{
...
...
@@ -81,6 +87,22 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
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
{
return
bm
.
bc
}
...
...
@@ -165,7 +187,7 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
*/
// 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
// processing
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录