Documentation ¶
Overview ¶
Package common holds the common functions to be used by other packages.
Index ¶
- func DeleteQuietly(filename string)
- func EvaluateErrorCodeResponse(code *api.ErrorCode) error
- func FileExists(path string) bool
- func FindNextIndex(s []uint32, id uint32, index int) (int, error)
- func GetAllButOne(s []uint32, e uint32) []uint32
- func MockViper(args ...interface{}) *viper.Viper
- func ReadFile(filename string) ([]byte, error)
- func Remove(s []uint32, e uint32) ([]uint32, error)
- func SaveStringToDisk(str, filename string) error
- func SaveToDisk(bytes []byte, filename string) error
- func SubViper(args ...string) *viper.Viper
- func UnmarshalDFSSFile(data []byte) (*contract.JSON, error)
- type RecoverDataJSON
- type SequenceCoordinate
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteQuietly ¶
func DeleteQuietly(filename string)
DeleteQuietly try to delete a file, do not fail if an error is raised
func EvaluateErrorCodeResponse ¶
EvaluateErrorCodeResponse converts an ErrorCode to human-friendly error
func FindNextIndex ¶
FindNextIndex analyses the specified sequence and tries to find the next occurence of id after the specified index (excluded) Therefore to find the first occurence of the id in the sequence, use -1 as the index
If there is no occurence of id, then -1 is returned ¶
The sequence is supposed to be correct (in regards to its mathematical definition), and id is supposed to be a valid id for the sequence
Example ¶
s := []uint32{0, 1, 2, 0, 1, 2} id := uint32(2) index, _ := FindNextIndex(s, id, -1) fmt.Println("First index:", index) pSet, _ := GetPendingSet(s, id, index) fmt.Println("Pending Set:", pSet) sSet, _ := GetSendSet(s, id, index) fmt.Println("Send Set:", sSet)
Output: First index: 2 Pending Set: [{1 1} {0 0}] Send Set: [{0 3} {1 4}]
func GetAllButOne ¶
GetAllButOne creates the slice of all sequence ids, except the one specified
TODO This is O(n^2) and need a rework with a map
func MockViper ¶ added in v0.2.0
MockViper : Creates a dummy viper object to use in tests instead of the real one, the expected args are key1, val1, key2, val2, etc...
func SaveStringToDisk ¶
SaveStringToDisk saves the given string to disk with the given filename
func SaveToDisk ¶
SaveToDisk saves the given array of bytes to disk with the given filename
Types ¶
type RecoverDataJSON ¶ added in v0.3.0
RecoverDataJSON : contains all the necessary information to try and recover a previously signed contract from the ttp
func UnmarshalRecoverDataFile ¶ added in v0.3.0
func UnmarshalRecoverDataFile(data []byte) (*RecoverDataJSON, error)
UnmarshalRecoverDataFile decodes a json-encoded Recover dara file
type SequenceCoordinate ¶ added in v0.3.0
type SequenceCoordinate struct {
Signer, Index uint32
}
SequenceCoordinate : contains both the sequence id of a signer, and the index of the occurence in the sequence
func GetPendingSet ¶
func GetPendingSet(s []uint32, id uint32, index int) ([]SequenceCoordinate, error)
GetPendingSet analyses the specified sequence and computes the set of ids occuring between index (excluded) and the previous occurence of id
The sequence is supposed to be correct (in regards to its mathematical definition), and id is supposed to be a valid id for the sequence ¶
If the index is not the one of the specified id in the sequence, the result still holds, but may be incomplete for your needs If the id is not valid for the specified sequence, the result will be the set of ids of the sequence
func GetSendSet ¶
func GetSendSet(s []uint32, id uint32, index int) ([]SequenceCoordinate, error)
GetSendSet analyses the specified sequence and computes the set of ids occuring between index (excluded) and the next occurence of id
The sequence is supposed to be correct (in regards to its mathematical definition), and id is supposed to be a valid id for the sequence ¶
If the index is not the one of the specified id in the sequence, the result still holds, but may be incomplete for your needs If the id is not valid for the specified sequence, the result will be the set of ids of the sequence
func RemoveCoordinate ¶ added in v0.3.0
func RemoveCoordinate(s []SequenceCoordinate, e uint32) ([]SequenceCoordinate, error)
RemoveCoordinate : removes the first occurence of an ID from the coordinates array