In the 'printchain' command, print transactions as well
This commit is contained in:
parent
2b0619e103
commit
6b400109e9
3
cli.go
3
cli.go
|
@ -64,6 +64,9 @@ func (cli *CLI) printChain() {
|
|||
fmt.Printf("Hash: %x\n", block.Hash)
|
||||
pow := NewProofOfWork(block)
|
||||
fmt.Printf("PoW: %s\n", strconv.FormatBool(pow.Validate()))
|
||||
for _, tx := range block.Transactions {
|
||||
fmt.Println(tx)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
if len(block.PrevBlockHash) == 0 {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const subsidy = 10
|
||||
|
@ -23,6 +24,28 @@ func (tx Transaction) IsCoinbase() bool {
|
|||
return len(tx.Vin) == 1 && len(tx.Vin[0].Txid) == 0 && tx.Vin[0].Vout == -1
|
||||
}
|
||||
|
||||
// String returns a human-readable representation of a transaction
|
||||
func (tx Transaction) String() string {
|
||||
var lines []string
|
||||
|
||||
lines = append(lines, fmt.Sprintf("Transaction %x:", tx.ID))
|
||||
|
||||
for i, input := range tx.Vin {
|
||||
lines = append(lines, fmt.Sprintf(" Input %d:", i))
|
||||
lines = append(lines, fmt.Sprintf(" TXID: %x", input.Txid))
|
||||
lines = append(lines, fmt.Sprintf(" Out: %d", input.Vout))
|
||||
lines = append(lines, fmt.Sprintf(" Script: %s", input.ScriptSig))
|
||||
}
|
||||
|
||||
for i, output := range tx.Vout {
|
||||
lines = append(lines, fmt.Sprintf(" Output %d:", i))
|
||||
lines = append(lines, fmt.Sprintf(" Value: %d", output.Value))
|
||||
lines = append(lines, fmt.Sprintf(" Script: %s", output.ScriptPubKey))
|
||||
}
|
||||
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// SetID sets ID of a transaction
|
||||
func (tx Transaction) SetID() {
|
||||
var encoded bytes.Buffer
|
||||
|
|
Loading…
Reference in New Issue