| 272 | } |
| 273 | |
| 274 | func header(args []string) { |
| 275 | fs := flag.NewFlagSet("header", flag.PanicOnError) |
| 276 | pretty := fs.Bool("pretty", false, "show individual blockheader fields") |
| 277 | |
| 278 | err := fs.Parse(args) |
| 279 | must(err) |
| 280 | |
| 281 | inp, err := ioutil.ReadAll(os.Stdin) |
| 282 | must(err) |
| 283 | |
| 284 | var rb bc.RawBlock |
| 285 | err = proto.Unmarshal(inp, &rb) |
| 286 | must(err) |
| 287 | |
| 288 | if *pretty { |
| 289 | var ( |
| 290 | bh = rb.Header |
| 291 | pubkeys []string |
| 292 | ) |
| 293 | |
| 294 | for _, p := range bh.NextPredicate.Pubkeys { |
| 295 | pubkeys = append(pubkeys, hex.EncodeToString(p)) |
| 296 | } |
| 297 | |
| 298 | fmt.Printf("Version: %d\n", bh.Version) |
| 299 | fmt.Printf("Height: %d\n", bh.Height) |
| 300 | if bh.PreviousBlockId != nil { |
| 301 | fmt.Printf("PreviousBlockId: %x\n", bh.PreviousBlockId.Bytes()) |
| 302 | } else { |
| 303 | fmt.Printf("PreviousBlockId: nil\n") |
| 304 | } |
| 305 | fmt.Printf("TimestampMs: %d\n", bh.TimestampMs) |
| 306 | fmt.Printf("Runlimit: %d\n", bh.Runlimit) |
| 307 | fmt.Printf("RefsCount: %d\n", bh.RefsCount) |
| 308 | fmt.Printf("TransactionsRoot: %x\n", bh.TransactionsRoot.Bytes()) |
| 309 | fmt.Printf("ContractsRoot: %x\n", bh.ContractsRoot.Bytes()) |
| 310 | fmt.Printf("NoncesRoot: %x\n", bh.NoncesRoot.Bytes()) |
| 311 | fmt.Printf("NextPredicate.Version: %d\n", bh.NextPredicate.Version) |
| 312 | fmt.Printf("NextPredicate.Quorum: %d\n", bh.NextPredicate.Quorum) |
| 313 | fmt.Printf("NextPredicate.Pubkeys: %s\n", strings.Join(pubkeys, " ")) |
| 314 | fmt.Printf("Transactions: %d\n", len(rb.Transactions)) |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | headerBytes, err := proto.Marshal(rb.Header) |
| 319 | must(err) |
| 320 | |
| 321 | os.Stdout.Write(headerBytes) |
| 322 | } |
| 323 | |
| 324 | func tx(args []string) { |
| 325 | fs := flag.NewFlagSet("tx", flag.PanicOnError) |