Skip to content

Commit

Permalink
commands/bitswap: use cmds.EmitOnce in single value
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
  • Loading branch information
overbool authored and Stebalien committed Nov 5, 2018
1 parent c5b44de commit 73fef48
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,18 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
}

pstr, found := req.Options[peerOptionName].(string)
if err != nil {
return err
}
if found {
pid, err := peer.IDB58Decode(pstr)
if err != nil {
return err
}
if pid == nd.Identity {
return res.Emit(&KeyList{bs.GetWantlist()})
return cmds.EmitOnce(res, &KeyList{bs.GetWantlist()})
}

return res.Emit(&KeyList{bs.WantlistForPeer(pid)})
return cmds.EmitOnce(res, &KeyList{bs.WantlistForPeer(pid)})
}
return res.Emit(&KeyList{bs.GetWantlist()})
return cmds.EmitOnce(res, &KeyList{bs.GetWantlist()})
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *KeyList) error {
Expand Down Expand Up @@ -175,7 +172,7 @@ prints the ledger associated with a given peer.
if err != nil {
return err
}
return res.Emit(bs.LedgerForPeer(partner))
return cmds.EmitOnce(res, bs.LedgerForPeer(partner))
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *decision.Receipt) error {
Expand Down

0 comments on commit 73fef48

Please sign in to comment.