common

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package common holds the common functions to be used by other packages.

Index

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

func EvaluateErrorCodeResponse(code *api.ErrorCode) error

EvaluateErrorCodeResponse converts an ErrorCode to human-friendly error

func FileExists

func FileExists(path string) bool

FileExists check if a file exists or not

func FindNextIndex

func FindNextIndex(s []uint32, id uint32, index int) (int, error)

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

func GetAllButOne(s []uint32, e uint32) []uint32

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

func MockViper(args ...interface{}) *viper.Viper

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 ReadFile

func ReadFile(filename string) ([]byte, error)

ReadFile try to Read a file on the disk

func Remove

func Remove(s []uint32, e uint32) ([]uint32, error)

Remove the first occurence of an ID from the ids array

func SaveStringToDisk

func SaveStringToDisk(str, filename string) error

SaveStringToDisk saves the given string to disk with the given filename

func SaveToDisk

func SaveToDisk(bytes []byte, filename string) error

SaveToDisk saves the given array of bytes to disk with the given filename

func SubViper added in v0.2.0

func SubViper(args ...string) *viper.Viper

SubViper : From the singleton viper, creates another config object which holds only a part of of the config

func UnmarshalDFSSFile

func UnmarshalDFSSFile(data []byte) (*contract.JSON, error)

UnmarshalDFSSFile decodes a json-encoded DFSS file

Types

type RecoverDataJSON added in v0.3.0

type RecoverDataJSON struct {
	SignatureUUID string
	TTPAddrport   string
	TTPHash       []byte
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL