Skip to content

Commit

Permalink
feat: ledger function to determine transaction type
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 committed Oct 12, 2023
1 parent 99167a2 commit dee107b
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 dee107b

Please sign in to comment.