-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (60 loc) · 1.8 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/wire"
"os"
)
func main() {
// Check if the user provided a raw transaction hex input
if len(os.Args) != 2 {
fmt.Println("Usage: go run main.go <raw_transaction_hex>")
return
}
// Parse the raw transaction hex
rawTxHex := os.Args[1]
rawTxBytes, err := hex.DecodeString(rawTxHex)
if err != nil {
fmt.Println("Error decoding raw transaction hex:", err)
return
}
// Deserialize the raw transaction bytes
var tx wire.MsgTx
err = tx.Deserialize(bytes.NewReader(rawTxBytes))
if err != nil {
fmt.Println("Error deserializing raw transaction:", err)
return
}
// Print transaction details
fmt.Println("Transaction Version:", tx.Version)
fmt.Println("Transaction Locktime:", tx.LockTime)
fmt.Println("Number of Inputs:", len(tx.TxIn))
fmt.Println("Number of Outputs:", len(tx.TxOut))
// Print input details
fmt.Println("\nInputs:")
for i, input := range tx.TxIn {
fmt.Printf("Input %d:\n", i)
fmt.Printf(" Previous Tx Hash: %s\n", input.PreviousOutPoint.Hash)
fmt.Printf(" Previous Tx Index: %d\n", input.PreviousOutPoint.Index)
fmt.Printf(" Script Length: %d\n", len(input.SignatureScript))
fmt.Printf(" ScriptSig: %s\n", hex.EncodeToString(input.SignatureScript))
fmt.Printf(" Sequence: %d\n", input.Sequence)
if input.Sequence < 4294967295 {
fmt.Printf(" RBF: TRUE")
}else {
fmt.Printf(" RBF: FALSE")
}
}
// Print output details
fmt.Println("\nOutputs:")
for i, output := range tx.TxOut {
fmt.Printf("Output %d:\n", i)
fmt.Printf(" Value: %d Satoshis\n", output.Value)
fmt.Printf(" Script Length: %d\n", len(output.PkScript))
fmt.Printf(" ScriptPubKey: %s\n", hex.EncodeToString(output.PkScript))
}
if tx.HasWitness() {
fmt.Printf("Witness: %s\n", tx.WitnessHash().String())
}
}