deals: More correct response in handler
This commit is contained in:
parent
5811f18b5e
commit
5a865177e6
@ -1,15 +1,22 @@
|
||||
package deals
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-lotus/chain/wallet"
|
||||
"github.com/filecoin-project/go-lotus/lib/cborrpc"
|
||||
"math"
|
||||
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
inet "github.com/libp2p/go-libp2p-core/network"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
w *wallet.Wallet
|
||||
}
|
||||
|
||||
func NewHandler() *Handler {
|
||||
return &Handler{}
|
||||
func NewHandler(w *wallet.Wallet) *Handler {
|
||||
return &Handler{
|
||||
w: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) HandleStream(s inet.Stream) {
|
||||
@ -26,14 +33,32 @@ func (h *Handler) HandleStream(s inet.Stream) {
|
||||
// TODO: Validate proposal maybe
|
||||
// (and signature, obviously)
|
||||
|
||||
// TODO: Review: Not signed?
|
||||
proposalNd, err := cbor.WrapObject(proposal.Proposal, math.MaxUint64, -1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
response := StorageDealResponse{
|
||||
State: Accepted,
|
||||
Message: "",
|
||||
//Proposal: , // TODO
|
||||
Proposal: proposalNd.Cid(),
|
||||
}
|
||||
|
||||
msg, err := cbor.DumpObject(response)
|
||||
if err != nil {
|
||||
log.Errorw("failed to serialize response message", "error", err)
|
||||
return
|
||||
}
|
||||
sig, err := h.w.Sign(proposal.Proposal.MinerAddress, msg)
|
||||
if err != nil {
|
||||
log.Errorw("failed to sign response message", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
signedResponse := &SignedStorageDealResponse{
|
||||
Response: response,
|
||||
//Signature: sig, // TODO
|
||||
Signature: sig,
|
||||
}
|
||||
if err := cborrpc.WriteCborRPC(s, signedResponse); err != nil {
|
||||
log.Errorw("failed to write deal response", "error", err)
|
||||
|
Loading…
Reference in New Issue
Block a user