Skip to content

Commit

Permalink
Merge pull request #397 from blinklabs-io/feat/ledger-determine-tx-type
Browse files Browse the repository at this point in the history
feat: ledger function to determine transaction type
  • Loading branch information
wolf31o2 authored Oct 12, 2023
2 parents 99167a2 + dee107b commit c4c8574
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ func NewTransactionBodyFromCbor(txType uint, data []byte) (TransactionBody, erro
return nil, fmt.Errorf("unknown transaction type: %d", txType)
}

func DetermineTransactionType(data []byte) (uint, error) {
// TODO: uncomment this once the following issue is resolved:
// https://github.com/blinklabs-io/gouroboros/issues/206
/*
if _, err := NewByronTransactionFromCbor(data); err == nil {
return TxTypeByron, nil
}
*/
if _, err := NewShelleyTransactionFromCbor(data); err == nil {
return TxTypeShelley, nil
}
if _, err := NewAllegraTransactionFromCbor(data); err == nil {
return TxTypeAllegra, nil
}
if _, err := NewMaryTransactionFromCbor(data); err == nil {
return TxTypeMary, nil
}
if _, err := NewAlonzoTransactionFromCbor(data); err == nil {
return TxTypeAlonzo, nil
}
if _, err := NewBabbageTransactionFromCbor(data); err == nil {
return TxTypeBabbage, nil
}
return 0, fmt.Errorf("unknown transaction type")
}

func generateTransactionHash(data []byte, prefix []byte) string {
// We can ignore the error return here because our fixed size/key arguments will
// never trigger an error
Expand Down

0 comments on commit c4c8574

Please sign in to comment.