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