rename struct field from .Instructions to .Sequences

This commit is contained in:
fiatjaf
2023-09-30 14:31:11 -03:00
parent 212b1c85b1
commit bbc37a4a1d
2 changed files with 10 additions and 10 deletions

18
ots.go
View File

@@ -56,8 +56,8 @@ var tags = map[byte]*Operation{
// a series of sequences of instructions. Each sequence must be evaluated separately, applying the operations // a series of sequences of instructions. Each sequence must be evaluated separately, applying the operations
// on top of each other, starting with the .Digest until they end on an attestation. // on top of each other, starting with the .Digest until they end on an attestation.
type File struct { type File struct {
Digest []byte Digest []byte
Instructions []Sequence Sequences []Sequence
} }
// a Instruction can be an operation like "append" or "prepend" (this will be the case when .Operation != nil) // a Instruction can be an operation like "append" or "prepend" (this will be the case when .Operation != nil)
@@ -85,8 +85,8 @@ func (seq Sequence) Compute(initial []byte) []byte {
func (ts File) GetPendingSequences() []Sequence { func (ts File) GetPendingSequences() []Sequence {
bitcoin := ts.GetBitcoinAttestedSequences() bitcoin := ts.GetBitcoinAttestedSequences()
results := make([]Sequence, 0, len(ts.Instructions)) results := make([]Sequence, 0, len(ts.Sequences))
for _, seq := range ts.Instructions { for _, seq := range ts.Sequences {
if len(seq) > 0 && seq[len(seq)-1].Attestation != nil && seq[len(seq)-1].Attestation.CalendarServerURL != "" { if len(seq) > 0 && seq[len(seq)-1].Attestation != nil && seq[len(seq)-1].Attestation.CalendarServerURL != "" {
// this is a calendar sequence, fine // this is a calendar sequence, fine
// now we check if this same sequence isn't contained in a bigger one that contains a bitcoin attestation // now we check if this same sequence isn't contained in a bigger one that contains a bitcoin attestation
@@ -113,8 +113,8 @@ func (ts File) GetPendingSequences() []Sequence {
} }
func (ts File) GetBitcoinAttestedSequences() []Sequence { func (ts File) GetBitcoinAttestedSequences() []Sequence {
results := make([]Sequence, 0, len(ts.Instructions)) results := make([]Sequence, 0, len(ts.Sequences))
for _, seq := range ts.Instructions { for _, seq := range ts.Sequences {
if len(seq) > 0 && seq[len(seq)-1].Attestation != nil && seq[len(seq)-1].Attestation.BitcoinBlockHeight > 0 { if len(seq) > 0 && seq[len(seq)-1].Attestation != nil && seq[len(seq)-1].Attestation.BitcoinBlockHeight > 0 {
results = append(results, seq) results = append(results, seq)
} }
@@ -127,7 +127,7 @@ func (ts File) Human() string {
strs = append(strs, fmt.Sprintf("file digest: %x", ts.Digest)) strs = append(strs, fmt.Sprintf("file digest: %x", ts.Digest))
strs = append(strs, fmt.Sprintf("hashed with: sha256")) strs = append(strs, fmt.Sprintf("hashed with: sha256"))
strs = append(strs, "instruction sequences:") strs = append(strs, "instruction sequences:")
for _, seq := range ts.Instructions { for _, seq := range ts.Sequences {
strs = append(strs, "~>") strs = append(strs, "~>")
for _, inst := range seq { for _, inst := range seq {
line := " " line := " "
@@ -158,8 +158,8 @@ func (ts File) SerializeToFile() []byte {
} }
func (ts File) SerializeInstructionSequences() []byte { func (ts File) SerializeInstructionSequences() []byte {
sequences := make([]Sequence, len(ts.Instructions)) sequences := make([]Sequence, len(ts.Sequences))
copy(sequences, ts.Instructions) copy(sequences, ts.Sequences)
// first we sort everything so the checkpoint stuff makes sense // first we sort everything so the checkpoint stuff makes sense
slices.SortFunc(sequences, func(a, b Sequence) int { return slices.CompareFunc(a, b, CompareInstructions) }) slices.SortFunc(sequences, func(a, b Sequence) int { return slices.CompareFunc(a, b, CompareInstructions) })

View File

@@ -54,7 +54,7 @@ func parseOTSFile(buf Buffer) (*File, error) {
if seqs, err := parseTimestamp(buf); err != nil { if seqs, err := parseTimestamp(buf); err != nil {
return nil, err return nil, err
} else { } else {
ts.Instructions = seqs ts.Sequences = seqs
} }
return ts, nil return ts, nil