Merge pull request #2505 from filecoin-project/expose-ComputeStateHTMLTempl

expose ComputeStateHTMLTempl
This commit is contained in:
Łukasz Magiera 2020-07-21 20:45:45 +02:00 committed by GitHub
commit d55a49a9b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"io"
"os" "os"
"reflect" "reflect"
"sort" "sort"
@ -874,7 +875,7 @@ var stateComputeStateCmd = &cli.Command{
return c.Code, nil return c.Code, nil
} }
return computeStateHTMLTempl(ts, stout, getCode) return ComputeStateHTMLTempl(os.Stdout, ts, stout, getCode)
} }
fmt.Println("computed state cid: ", stout.Root) fmt.Println("computed state cid: ", stout.Root)
@ -1081,7 +1082,7 @@ type compStateHTMLIn struct {
Comp *api.ComputeStateOutput Comp *api.ComputeStateOutput
} }
func computeStateHTMLTempl(ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error { func ComputeStateHTMLTempl(w io.Writer, ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error {
t, err := template.New("compute_state").Funcs(map[string]interface{}{ t, err := template.New("compute_state").Funcs(map[string]interface{}{
"GetCode": getCode, "GetCode": getCode,
"GetMethod": getMethod, "GetMethod": getMethod,
@ -1114,7 +1115,7 @@ func computeStateHTMLTempl(ts *types.TipSet, o *api.ComputeStateOutput, getCode
return err return err
} }
return t.ExecuteTemplate(os.Stdout, "compute_state", &compStateHTMLIn{ return t.ExecuteTemplate(w, "compute_state", &compStateHTMLIn{
TipSet: ts, TipSet: ts,
Comp: o, Comp: o,
}) })