Skip to content

Commit

Permalink
Add index to transaction, stating its position inside the block.
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Jun 26, 2023
1 parent b55f477 commit cf83745
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ipld/ipldbindcode/ledger.ipldsch
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Transaction struct {
metadata DataFrame
# The slot number where this transaction was created.
slot Int
# The index of this transaction in the the block (0-indexed).
index nullable optional Int
} representation tuple

type Hash bytes
Expand Down
14 changes: 14 additions & 0 deletions ipld/ipldbindcode/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,17 @@ func VerifyHash(data []byte, hash int) error {
}
return nil
}

// Transaction.HasIndex returns whether the 'Index' field is present.
func (n Transaction) HasIndex() bool {
return n.Index != nil && *n.Index != nil
}

// GetIndex returns the value of the 'Index' field and
// a flag indicating whether the field has a value.
func (n Transaction) GetIndex() (int, bool) {
if n.Index == nil || *n.Index == nil {
return 0, false
}
return **n.Index, true
}
1 change: 1 addition & 0 deletions ipld/ipldbindcode/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Transaction struct {
Data DataFrame
Metadata DataFrame
Slot int
Index **int
}
type DataFrame struct {
Kind int
Expand Down
128 changes: 119 additions & 9 deletions ipld/ipldsch/ipldsch_satisfaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ipld/ipldsch/ipldsch_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ledger.ipldsch
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Transaction struct {
metadata DataFrame
# The slot number where this transaction was created.
slot Int
# The index of this transaction in the the block (0-indexed).
index nullable optional Int
} representation tuple

type Hash bytes
Expand Down

0 comments on commit cf83745

Please sign in to comment.