-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User-specified transaction expiration [#3462]
- Loading branch information
1 parent
301747e
commit be66895
Showing
22 changed files
with
629 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2023 The Accumulate Authors | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
package protocol | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"time" | ||
|
||
"github.com/robfig/cron/v3" | ||
"gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" | ||
) | ||
|
||
type CronSchedule struct { | ||
src string | ||
inner cron.Schedule | ||
} | ||
|
||
func ParseCron(spec string) (*CronSchedule, error) { | ||
schedule, err := cron.ParseStandard(spec) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &CronSchedule{spec, schedule}, nil | ||
} | ||
|
||
func MustParseCron(spec string) *CronSchedule { | ||
s, err := ParseCron(spec) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return s | ||
} | ||
|
||
func (s *CronSchedule) Next(t time.Time) time.Time { | ||
return s.inner.Next(t) | ||
} | ||
|
||
func (s *CronSchedule) Copy() *CronSchedule { | ||
return s // CronSchedule is immutable so there's no need to copy | ||
} | ||
|
||
func (s *CronSchedule) Equal(r *CronSchedule) bool { | ||
return s.src == r.src | ||
} | ||
|
||
func (s *CronSchedule) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(s.src) | ||
} | ||
|
||
func (s *CronSchedule) UnmarshalJSON(data []byte) error { | ||
err := json.Unmarshal(data, &s.src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s.inner, err = cron.ParseStandard(s.src) | ||
return err | ||
} | ||
|
||
func (s *CronSchedule) MarshalBinary() ([]byte, error) { | ||
return encoding.MarshalString(s.src), nil | ||
} | ||
|
||
func (s *CronSchedule) UnmarshalBinaryFrom(rd io.Reader) error { | ||
b, err := io.ReadAll(rd) | ||
if err != nil { | ||
return err | ||
} | ||
s.src, err = encoding.UnmarshalString(b) | ||
if err != nil { | ||
return err | ||
} | ||
s.inner, err = cron.ParseStandard(s.src) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.