MCPcopy Create free account
hub / github.com/chain/txvm / tx

Function tx

cmd/block/block.go:324–375  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

322}
323
324func tx(args []string) {
325 fs := flag.NewFlagSet("tx", flag.PanicOnError)
326
327 var (
328 raw = fs.Bool("raw", false, "emit raw tx")
329 pretty = fs.Bool("pretty", false, "show individual tx fields")
330 )
331
332 err := fs.Parse(args)
333 must(err)
334
335 args = fs.Args()
336 if len(args) < 1 {
337 usage()
338 }
339
340 idx, err := strconv.Atoi(args[0])
341 must(err)
342
343 if idx < 0 {
344 panic("index out of range")
345 }
346
347 inp, err := ioutil.ReadAll(os.Stdin)
348 must(err)
349
350 var rb bc.RawBlock
351 err = proto.Unmarshal(inp, &rb)
352 must(err)
353
354 if idx >= len(rb.Transactions) {
355 panic("index out of range")
356 }
357
358 tx := rb.Transactions[idx]
359
360 if *raw {
361 txBytes, err := proto.Marshal(tx)
362 must(err)
363 os.Stdout.Write(txBytes)
364 return
365 }
366
367 if *pretty {
368 fmt.Printf("Version: %d\n", tx.Version)
369 fmt.Printf("Runlimit: %d\n", tx.Runlimit)
370 fmt.Printf("Program: %x\n", tx.Program)
371 return
372 }
373
374 os.Stdout.Write(tx.Program)
375}
376
377func must(err error) {
378 if err != nil {

Callers

nothing calls this directly

Calls 3

mustFunction · 0.70
usageFunction · 0.70
WriteMethod · 0.45

Tested by

no test coverage detected