Skip to content

Commit c4c8574

Browse files
authored
Merge pull request #397 from blinklabs-io/feat/ledger-determine-tx-type
feat: ledger function to determine transaction type
2 parents 99167a2 + dee107b commit c4c8574

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

ledger/tx.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ func NewTransactionBodyFromCbor(txType uint, data []byte) (TransactionBody, erro
8484
return nil, fmt.Errorf("unknown transaction type: %d", txType)
8585
}
8686

87+
func DetermineTransactionType(data []byte) (uint, error) {
88+
// TODO: uncomment this once the following issue is resolved:
89+
// https://github.com/blinklabs-io/gouroboros/issues/206
90+
/*
91+
if _, err := NewByronTransactionFromCbor(data); err == nil {
92+
return TxTypeByron, nil
93+
}
94+
*/
95+
if _, err := NewShelleyTransactionFromCbor(data); err == nil {
96+
return TxTypeShelley, nil
97+
}
98+
if _, err := NewAllegraTransactionFromCbor(data); err == nil {
99+
return TxTypeAllegra, nil
100+
}
101+
if _, err := NewMaryTransactionFromCbor(data); err == nil {
102+
return TxTypeMary, nil
103+
}
104+
if _, err := NewAlonzoTransactionFromCbor(data); err == nil {
105+
return TxTypeAlonzo, nil
106+
}
107+
if _, err := NewBabbageTransactionFromCbor(data); err == nil {
108+
return TxTypeBabbage, nil
109+
}
110+
return 0, fmt.Errorf("unknown transaction type")
111+
}
112+
87113
func generateTransactionHash(data []byte, prefix []byte) string {
88114
// We can ignore the error return here because our fixed size/key arguments will
89115
// never trigger an error

0 commit comments

Comments
 (0)