Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
a9dfe410
Unverified
提交
a9dfe410
authored
3月 22, 2018
作者:
Whyrusleeping
提交者:
GitHub
3月 22, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4563 from ipfs/fix/block-mhtype
commands/block: use CIDv1 with custom mhtype
上级
5c6f8578
efb74199
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
12 行删除
+41
-12
block.go
core/commands/block.go
+29
-12
t0050-block.sh
test/sharness/t0050-block.sh
+12
-0
没有找到文件。
core/commands/block.go
浏览文件 @
a9dfe410
...
...
@@ -3,6 +3,7 @@ package commands
import
(
"bytes"
"context"
"errors"
"fmt"
"io"
"io/ioutil"
...
...
@@ -121,6 +122,9 @@ var blockPutCmd = &cmds.Command{
ShortDescription
:
`
'ipfs block put' is a plumbing command for storing raw IPFS blocks.
It reads from stdin, and <key> is a base58 encoded multihash.
By default CIDv0 is going to be generated. Setting 'mhtype' to anything other
than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
`
,
},
...
...
@@ -128,7 +132,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
cmdkit
.
FileArg
(
"data"
,
true
,
false
,
"The data to be stored as an IPFS block."
)
.
EnableStdin
(),
},
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
StringOption
(
"format"
,
"f"
,
"cid format for blocks to be created with."
)
.
WithDefault
(
"v0"
)
,
cmdkit
.
StringOption
(
"format"
,
"f"
,
"cid format for blocks to be created with."
),
cmdkit
.
StringOption
(
"mhtype"
,
"multihash hash function"
)
.
WithDefault
(
"sha2-256"
),
cmdkit
.
IntOption
(
"mhlen"
,
"multihash hash length"
)
.
WithDefault
(
-
1
),
},
...
...
@@ -157,27 +161,40 @@ It reads from stdin, and <key> is a base58 encoded multihash.
return
}
mhtype
,
_
:=
req
.
Options
[
"mhtype"
]
.
(
string
)
mhtval
,
ok
:=
mh
.
Names
[
mhtype
]
if
!
ok
{
err
:=
fmt
.
Errorf
(
"unrecognized multihash function: %s"
,
mhtype
)
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
var
pref
cid
.
Prefix
pref
.
Version
=
1
format
,
_
:=
req
.
Options
[
"format"
]
.
(
string
)
formatval
,
ok
:=
cid
.
Codecs
[
format
]
if
!
ok
{
res
.
SetError
(
fmt
.
Errorf
(
"unrecognized format: %s"
,
format
),
cmdkit
.
ErrNormal
)
return
format
,
formatSet
:=
req
.
Options
[
"format"
]
.
(
string
)
if
!
formatSet
{
if
mhtval
==
mh
.
SHA2_256
{
format
=
"v0"
}
else
{
format
=
"protobuf"
}
}
if
format
==
"v0"
{
pref
.
Version
=
0
}
pref
.
Codec
=
formatval
mhtype
,
_
:=
req
.
Options
[
"mhtype"
]
.
(
string
)
mhtval
,
ok
:=
mh
.
Names
[
mhtype
]
formatval
,
ok
:=
cid
.
Codecs
[
format
]
if
!
ok
{
err
:=
fmt
.
Errorf
(
"unrecognized multihash function: %s"
,
mhtype
)
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
res
.
SetError
(
fmt
.
Errorf
(
"unrecognized format: '%s'"
,
format
),
cmdkit
.
ErrNormal
)
return
}
if
mhtval
!=
mh
.
SHA2_256
&&
pref
.
Version
==
0
{
res
.
SetError
(
errors
.
New
(
"cannot generate CIDv0 with non-sha256 hash function"
),
cmdkit
.
ErrNormal
)
return
}
pref
.
Codec
=
formatval
pref
.
MhType
=
mhtval
mhlen
,
ok
:=
req
.
Options
[
"mhlen"
]
.
(
int
)
...
...
test/sharness/t0050-block.sh
浏览文件 @
a9dfe410
...
...
@@ -209,4 +209,16 @@ test_expect_success "no panic in output" '
test_expect_code 1 grep "panic" stat_out
'
test_expect_success
"can set multihash type and length on block put without format"
'
HASH=$(echo "foooo" | ipfs block put --mhtype=sha3 --mhlen=20)
'
test_expect_success
"output looks good"
'
test "z8bwYCvQPhyDY7VUTsUdGdE8Evm1ktSPV" = "$HASH"
'
test_expect_success
"put with sha3 and cidv0 fails"
'
echo "foooo" | test_must_fail ipfs block put --mhtype=sha3 --mhlen=20 --format=v0
'
test_done
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论