Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
c62d5422
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(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c62d5422
编写于
6月 21, 2017
作者:
B
Bas van Kervel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
whisper: use hexutil.UnmarshalFixedText for topic parsing
上级
a4e4c76c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
34 deletion
+27
-34
cmd/geth/consolecmd.go
cmd/geth/consolecmd.go
+1
-1
whisper/whisperv5/topic.go
whisper/whisperv5/topic.go
+6
-16
whisper/whisperv5/topic_test.go
whisper/whisperv5/topic_test.go
+20
-17
未找到文件。
cmd/geth/consolecmd.go
浏览文件 @
c62d5422
...
...
@@ -35,7 +35,7 @@ var (
Action
:
utils
.
MigrateFlags
(
localConsole
),
Name
:
"console"
,
Usage
:
"Start an interactive JavaScript environment"
,
Flags
:
append
(
append
(
nodeFlags
,
rpcFlags
...
),
console
Flags
...
),
Flags
:
append
(
append
(
append
(
nodeFlags
,
rpcFlags
...
),
consoleFlags
...
),
whisper
Flags
...
),
Category
:
"CONSOLE COMMANDS"
,
Description
:
`
The Geth console is an interactive shell for the JavaScript runtime environment
...
...
whisper/whisperv5/topic.go
浏览文件 @
c62d5422
...
...
@@ -19,9 +19,6 @@
package
whisperv5
import
(
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
...
...
@@ -47,19 +44,12 @@ func (topic *TopicType) String() string {
return
string
(
common
.
ToHex
(
topic
[
:
]))
}
func
(
t
*
TopicType
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
hexutil
.
Bytes
(
t
[
:
]))
// MarshalText returns the hex representation of t.
func
(
t
TopicType
)
MarshalText
()
([]
byte
,
error
)
{
return
hexutil
.
Bytes
(
t
[
:
])
.
MarshalText
()
}
// UnmarshalJSON parses a hex representation to a topic.
func
(
t
*
TopicType
)
UnmarshalJSON
(
input
[]
byte
)
error
{
var
data
hexutil
.
Bytes
if
err
:=
json
.
Unmarshal
(
input
,
&
data
);
err
!=
nil
{
return
err
}
if
len
(
data
)
!=
TopicLength
{
return
fmt
.
Errorf
(
"unmarshalJSON failed: topic must be exactly %d bytes(%d)"
,
TopicLength
,
len
(
input
))
}
*
t
=
BytesToTopic
(
data
)
return
nil
// UnmarshalText parses a hex representation to a topic.
func
(
t
*
TopicType
)
UnmarshalText
(
input
[]
byte
)
error
{
return
hexutil
.
UnmarshalFixedText
(
"Topic"
,
input
,
t
[
:
])
}
whisper/whisperv5/topic_test.go
浏览文件 @
c62d5422
...
...
@@ -16,7 +16,10 @@
package
whisperv5
import
"testing"
import
(
"encoding/json"
"testing"
)
var
topicStringTests
=
[]
struct
{
topic
TopicType
...
...
@@ -53,15 +56,6 @@ var bytesToTopicTests = []struct {
{
topic
:
TopicType
{
0x00
,
0x00
,
0x00
,
0x00
},
data
:
nil
},
}
func
TestBytesToTopic
(
t
*
testing
.
T
)
{
for
i
,
tst
:=
range
bytesToTopicTests
{
top
:=
BytesToTopic
(
tst
.
data
)
if
top
!=
tst
.
topic
{
t
.
Fatalf
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
}
}
}
var
unmarshalTestsGood
=
[]
struct
{
topic
TopicType
data
[]
byte
...
...
@@ -94,14 +88,23 @@ var unmarshalTestsUgly = []struct {
{
topic
:
TopicType
{
0x01
,
0x00
,
0x00
,
0x00
},
data
:
[]
byte
(
`"0x00000001"`
)},
}
func
TestBytesToTopic
(
t
*
testing
.
T
)
{
for
i
,
tst
:=
range
bytesToTopicTests
{
top
:=
BytesToTopic
(
tst
.
data
)
if
top
!=
tst
.
topic
{
t
.
Fatalf
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
}
}
}
func
TestUnmarshalTestsGood
(
t
*
testing
.
T
)
{
for
i
,
tst
:=
range
unmarshalTestsGood
{
var
top
TopicType
err
:=
top
.
UnmarshalJSON
(
tst
.
data
)
err
:=
json
.
Unmarshal
(
tst
.
data
,
&
top
)
if
err
!=
nil
{
t
.
Fatal
f
(
"failed test %d. input: %v. err: %v"
,
i
,
tst
.
data
,
err
)
t
.
Error
f
(
"failed test %d. input: %v. err: %v"
,
i
,
tst
.
data
,
err
)
}
else
if
top
!=
tst
.
topic
{
t
.
Fatal
f
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
t
.
Error
f
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
}
}
}
...
...
@@ -110,7 +113,7 @@ func TestUnmarshalTestsBad(t *testing.T) {
// in this test UnmarshalJSON() is supposed to fail
for
i
,
tst
:=
range
unmarshalTestsBad
{
var
top
TopicType
err
:=
top
.
UnmarshalJSON
(
tst
.
data
)
err
:=
json
.
Unmarshal
(
tst
.
data
,
&
top
)
if
err
==
nil
{
t
.
Fatalf
(
"failed test %d. input: %v."
,
i
,
tst
.
data
)
}
...
...
@@ -121,11 +124,11 @@ func TestUnmarshalTestsUgly(t *testing.T) {
// in this test UnmarshalJSON() is NOT supposed to fail, but result should be wrong
for
i
,
tst
:=
range
unmarshalTestsUgly
{
var
top
TopicType
err
:=
top
.
UnmarshalJSON
(
tst
.
data
)
err
:=
json
.
Unmarshal
(
tst
.
data
,
&
top
)
if
err
!=
nil
{
t
.
Fatal
f
(
"failed test %d. input: %v."
,
i
,
tst
.
data
)
t
.
Error
f
(
"failed test %d. input: %v."
,
i
,
tst
.
data
)
}
else
if
top
==
tst
.
topic
{
t
.
Fatal
f
(
"failed test %d: have %v, want %v."
,
i
,
top
,
tst
.
topic
)
t
.
Error
f
(
"failed test %d: have %v, want %v."
,
i
,
top
,
tst
.
topic
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录