id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
200
gocraft/web
router_setup.go
Post
func (r *Router) Post(path string, fn interface{}) *Router { return r.addRoute(httpMethodPost, path, fn) }
go
func (r *Router) Post(path string, fn interface{}) *Router { return r.addRoute(httpMethodPost, path, fn) }
[ "func", "(", "r", "*", "Router", ")", "Post", "(", "path", "string", ",", "fn", "interface", "{", "}", ")", "*", "Router", "{", "return", "r", ".", "addRoute", "(", "httpMethodPost", ",", "path", ",", "fn", ")", "\n", "}" ]
// Post will add a route to the router that matches on POST requests and the specified path.
[ "Post", "will", "add", "a", "route", "to", "the", "router", "that", "matches", "on", "POST", "requests", "and", "the", "specified", "path", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L192-L194
201
gocraft/web
router_setup.go
Put
func (r *Router) Put(path string, fn interface{}) *Router { return r.addRoute(httpMethodPut, path, fn) }
go
func (r *Router) Put(path string, fn interface{}) *Router { return r.addRoute(httpMethodPut, path, fn) }
[ "func", "(", "r", "*", "Router", ")", "Put", "(", "path", "string", ",", "fn", "interface", "{", "}", ")", "*", "Router", "{", "return", "r", ".", "addRoute", "(", "httpMethodPut", ",", "path", ",", "fn", ")", "\n", "}" ]
// Put will add a route to the router that matches on PUT requests and the specified path.
[ "Put", "will", "add", "a", "route", "to", "the", "router", "that", "matches", "on", "PUT", "requests", "and", "the", "specified", "path", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L197-L199
202
gocraft/web
router_setup.go
Delete
func (r *Router) Delete(path string, fn interface{}) *Router { return r.addRoute(httpMethodDelete, path, fn) }
go
func (r *Router) Delete(path string, fn interface{}) *Router { return r.addRoute(httpMethodDelete, path, fn) }
[ "func", "(", "r", "*", "Router", ")", "Delete", "(", "path", "string", ",", "fn", "interface", "{", "}", ")", "*", "Router", "{", "return", "r", ".", "addRoute", "(", "httpMethodDelete", ",", "path", ",", "fn", ")", "\n", "}" ]
// Delete will add a route to the router that matches on DELETE requests and the specified path.
[ "Delete", "will", "add", "a", "route", "to", "the", "router", "that", "matches", "on", "DELETE", "requests", "and", "the", "specified", "path", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L202-L204
203
gocraft/web
router_setup.go
Patch
func (r *Router) Patch(path string, fn interface{}) *Router { return r.addRoute(httpMethodPatch, path, fn) }
go
func (r *Router) Patch(path string, fn interface{}) *Router { return r.addRoute(httpMethodPatch, path, fn) }
[ "func", "(", "r", "*", "Router", ")", "Patch", "(", "path", "string", ",", "fn", "interface", "{", "}", ")", "*", "Router", "{", "return", "r", ".", "addRoute", "(", "httpMethodPatch", ",", "path", ",", "fn", ")", "\n", "}" ]
// Patch will add a route to the router that matches on PATCH requests and the specified path.
[ "Patch", "will", "add", "a", "route", "to", "the", "router", "that", "matches", "on", "PATCH", "requests", "and", "the", "specified", "path", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L207-L209
204
gocraft/web
router_setup.go
Head
func (r *Router) Head(path string, fn interface{}) *Router { return r.addRoute(httpMethodHead, path, fn) }
go
func (r *Router) Head(path string, fn interface{}) *Router { return r.addRoute(httpMethodHead, path, fn) }
[ "func", "(", "r", "*", "Router", ")", "Head", "(", "path", "string", ",", "fn", "interface", "{", "}", ")", "*", "Router", "{", "return", "r", ".", "addRoute", "(", "httpMethodHead", ",", "path", ",", "fn", ")", "\n", "}" ]
// Head will add a route to the router that matches on HEAD requests and the specified path.
[ "Head", "will", "add", "a", "route", "to", "the", "router", "that", "matches", "on", "HEAD", "requests", "and", "the", "specified", "path", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L212-L214
205
gocraft/web
router_setup.go
Options
func (r *Router) Options(path string, fn interface{}) *Router { return r.addRoute(httpMethodOptions, path, fn) }
go
func (r *Router) Options(path string, fn interface{}) *Router { return r.addRoute(httpMethodOptions, path, fn) }
[ "func", "(", "r", "*", "Router", ")", "Options", "(", "path", "string", ",", "fn", "interface", "{", "}", ")", "*", "Router", "{", "return", "r", ".", "addRoute", "(", "httpMethodOptions", ",", "path", ",", "fn", ")", "\n", "}" ]
// Options will add a route to the router that matches on OPTIONS requests and the specified path.
[ "Options", "will", "add", "a", "route", "to", "the", "router", "that", "matches", "on", "OPTIONS", "requests", "and", "the", "specified", "path", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L217-L219
206
gocraft/web
router_setup.go
depth
func (r *Router) depth() int { max := 0 for _, child := range r.children { childDepth := child.depth() if childDepth > max { max = childDepth } } return max + 1 }
go
func (r *Router) depth() int { max := 0 for _, child := range r.children { childDepth := child.depth() if childDepth > max { max = childDepth } } return max + 1 }
[ "func", "(", "r", "*", "Router", ")", "depth", "(", ")", "int", "{", "max", ":=", "0", "\n", "for", "_", ",", "child", ":=", "range", "r", ".", "children", "{", "childDepth", ":=", "child", ".", "depth", "(", ")", "\n", "if", "childDepth", ">", ...
// Calculates the max child depth of the node. Leaves return 1. For Parent->Child, Parent is 2.
[ "Calculates", "the", "max", "child", "depth", "of", "the", "node", ".", "Leaves", "return", "1", ".", "For", "Parent", "-", ">", "Child", "Parent", "is", "2", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L237-L246
207
gocraft/web
router_serve.go
ServeHTTP
func (rootRouter *Router) ServeHTTP(rw http.ResponseWriter, r *http.Request) { // Manually create a closure. These variables are needed in middlewareStack. // The reason we put these here instead of in the middleware stack, is Go (as of 1.2) // creates a heap variable for each varaiable in the closure. To minimize that, we'll // just have one (closure *middlewareClosure). var closure middlewareClosure closure.Request.Request = r closure.appResponseWriter.ResponseWriter = rw closure.Routers = make([]*Router, 1, rootRouter.maxChildrenDepth) closure.Routers[0] = rootRouter closure.Contexts = make([]reflect.Value, 1, rootRouter.maxChildrenDepth) closure.Contexts[0] = reflect.New(rootRouter.contextType) closure.currentMiddlewareLen = len(rootRouter.middleware) closure.RootRouter = rootRouter closure.Request.rootContext = closure.Contexts[0] // Handle errors defer func() { if recovered := recover(); recovered != nil { rootRouter.handlePanic(&closure.appResponseWriter, &closure.Request, recovered) } }() next := middlewareStack(&closure) next(&closure.appResponseWriter, &closure.Request) }
go
func (rootRouter *Router) ServeHTTP(rw http.ResponseWriter, r *http.Request) { // Manually create a closure. These variables are needed in middlewareStack. // The reason we put these here instead of in the middleware stack, is Go (as of 1.2) // creates a heap variable for each varaiable in the closure. To minimize that, we'll // just have one (closure *middlewareClosure). var closure middlewareClosure closure.Request.Request = r closure.appResponseWriter.ResponseWriter = rw closure.Routers = make([]*Router, 1, rootRouter.maxChildrenDepth) closure.Routers[0] = rootRouter closure.Contexts = make([]reflect.Value, 1, rootRouter.maxChildrenDepth) closure.Contexts[0] = reflect.New(rootRouter.contextType) closure.currentMiddlewareLen = len(rootRouter.middleware) closure.RootRouter = rootRouter closure.Request.rootContext = closure.Contexts[0] // Handle errors defer func() { if recovered := recover(); recovered != nil { rootRouter.handlePanic(&closure.appResponseWriter, &closure.Request, recovered) } }() next := middlewareStack(&closure) next(&closure.appResponseWriter, &closure.Request) }
[ "func", "(", "rootRouter", "*", "Router", ")", "ServeHTTP", "(", "rw", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "// Manually create a closure. These variables are needed in middlewareStack.", "// The reason we put these here instead of...
// This is the entry point for servering all requests.
[ "This", "is", "the", "entry", "point", "for", "servering", "all", "requests", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_serve.go#L23-L49
208
gocraft/web
show_errors_middleware.go
ShowErrorsMiddleware
func ShowErrorsMiddleware(rw ResponseWriter, req *Request, next NextMiddlewareFunc) { defer func() { if err := recover(); err != nil { const size = 4096 stack := make([]byte, size) stack = stack[:runtime.Stack(stack, false)] renderPrettyError(rw, req, err, stack) } }() next(rw, req) }
go
func ShowErrorsMiddleware(rw ResponseWriter, req *Request, next NextMiddlewareFunc) { defer func() { if err := recover(); err != nil { const size = 4096 stack := make([]byte, size) stack = stack[:runtime.Stack(stack, false)] renderPrettyError(rw, req, err, stack) } }() next(rw, req) }
[ "func", "ShowErrorsMiddleware", "(", "rw", "ResponseWriter", ",", "req", "*", "Request", ",", "next", "NextMiddlewareFunc", ")", "{", "defer", "func", "(", ")", "{", "if", "err", ":=", "recover", "(", ")", ";", "err", "!=", "nil", "{", "const", "size", ...
// ShowErrorsMiddleware will catch panics and render an HTML page with the stack trace. // This middleware should only be used in development.
[ "ShowErrorsMiddleware", "will", "catch", "panics", "and", "render", "an", "HTML", "page", "with", "the", "stack", "trace", ".", "This", "middleware", "should", "only", "be", "used", "in", "development", "." ]
9707327fb69b5b93fd722c6b4259a7b414bedac5
https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/show_errors_middleware.go#L14-L26
209
heroku/rollrus
rollrus.go
WithLevels
func WithLevels(levels ...logrus.Level) OptionFunc { return func(h *Hook) { h.triggers = levels } }
go
func WithLevels(levels ...logrus.Level) OptionFunc { return func(h *Hook) { h.triggers = levels } }
[ "func", "WithLevels", "(", "levels", "...", "logrus", ".", "Level", ")", "OptionFunc", "{", "return", "func", "(", "h", "*", "Hook", ")", "{", "h", ".", "triggers", "=", "levels", "\n", "}", "\n", "}" ]
// WithLevels is an OptionFunc that customizes the log.Levels the hook will // report on.
[ "WithLevels", "is", "an", "OptionFunc", "that", "customizes", "the", "log", ".", "Levels", "the", "hook", "will", "report", "on", "." ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L59-L63
210
heroku/rollrus
rollrus.go
WithMinLevel
func WithMinLevel(level logrus.Level) OptionFunc { var levels []logrus.Level for _, l := range logrus.AllLevels { if l <= level { levels = append(levels, l) } } return func(h *Hook) { h.triggers = levels } }
go
func WithMinLevel(level logrus.Level) OptionFunc { var levels []logrus.Level for _, l := range logrus.AllLevels { if l <= level { levels = append(levels, l) } } return func(h *Hook) { h.triggers = levels } }
[ "func", "WithMinLevel", "(", "level", "logrus", ".", "Level", ")", "OptionFunc", "{", "var", "levels", "[", "]", "logrus", ".", "Level", "\n", "for", "_", ",", "l", ":=", "range", "logrus", ".", "AllLevels", "{", "if", "l", "<=", "level", "{", "level...
// WithMinLevel is an OptionFunc that customizes the log.Levels the hook will // report on by selecting all levels more severe than the one provided.
[ "WithMinLevel", "is", "an", "OptionFunc", "that", "customizes", "the", "log", ".", "Levels", "the", "hook", "will", "report", "on", "by", "selecting", "all", "levels", "more", "severe", "than", "the", "one", "provided", "." ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L67-L78
211
heroku/rollrus
rollrus.go
NewHook
func NewHook(token string, env string, opts ...OptionFunc) *Hook { h := NewHookForLevels(token, env, defaultTriggerLevels) for _, o := range opts { o(h) } return h }
go
func NewHook(token string, env string, opts ...OptionFunc) *Hook { h := NewHookForLevels(token, env, defaultTriggerLevels) for _, o := range opts { o(h) } return h }
[ "func", "NewHook", "(", "token", "string", ",", "env", "string", ",", "opts", "...", "OptionFunc", ")", "*", "Hook", "{", "h", ":=", "NewHookForLevels", "(", "token", ",", "env", ",", "defaultTriggerLevels", ")", "\n\n", "for", "_", ",", "o", ":=", "ra...
// NewHook creates a hook that is intended for use with your own logrus.Logger // instance. Uses the defualt report levels defined in wellKnownErrorFields.
[ "NewHook", "creates", "a", "hook", "that", "is", "intended", "for", "use", "with", "your", "own", "logrus", ".", "Logger", "instance", ".", "Uses", "the", "defualt", "report", "levels", "defined", "in", "wellKnownErrorFields", "." ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L106-L114
212
heroku/rollrus
rollrus.go
NewHookForLevels
func NewHookForLevels(token string, env string, levels []logrus.Level) *Hook { return &Hook{ Client: roll.New(token, env), triggers: levels, ignoredErrors: make([]error, 0), ignoreErrorFunc: func(error) bool { return false }, ignoreFunc: func(error, map[string]string) bool { return false }, } }
go
func NewHookForLevels(token string, env string, levels []logrus.Level) *Hook { return &Hook{ Client: roll.New(token, env), triggers: levels, ignoredErrors: make([]error, 0), ignoreErrorFunc: func(error) bool { return false }, ignoreFunc: func(error, map[string]string) bool { return false }, } }
[ "func", "NewHookForLevels", "(", "token", "string", ",", "env", "string", ",", "levels", "[", "]", "logrus", ".", "Level", ")", "*", "Hook", "{", "return", "&", "Hook", "{", "Client", ":", "roll", ".", "New", "(", "token", ",", "env", ")", ",", "tr...
// NewHookForLevels provided by the caller. Otherwise works like NewHook.
[ "NewHookForLevels", "provided", "by", "the", "caller", ".", "Otherwise", "works", "like", "NewHook", "." ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L117-L125
213
heroku/rollrus
rollrus.go
SetupLoggingForLevels
func SetupLoggingForLevels(token, env string, levels []logrus.Level) { setupLogging(token, env, levels) }
go
func SetupLoggingForLevels(token, env string, levels []logrus.Level) { setupLogging(token, env, levels) }
[ "func", "SetupLoggingForLevels", "(", "token", ",", "env", "string", ",", "levels", "[", "]", "logrus", ".", "Level", ")", "{", "setupLogging", "(", "token", ",", "env", ",", "levels", ")", "\n", "}" ]
// SetupLoggingForLevels works like SetupLogging, but allows you to // set the levels on which to trigger this hook.
[ "SetupLoggingForLevels", "works", "like", "SetupLogging", "but", "allows", "you", "to", "set", "the", "levels", "on", "which", "to", "trigger", "this", "hook", "." ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L136-L138
214
heroku/rollrus
rollrus.go
ReportPanic
func (r *Hook) ReportPanic() { if p := recover(); p != nil { if _, err := r.Client.Critical(fmt.Errorf("panic: %q", p), nil); err != nil { fmt.Fprintf(os.Stderr, "reporting_panic=false err=%q\n", err) } panic(p) } }
go
func (r *Hook) ReportPanic() { if p := recover(); p != nil { if _, err := r.Client.Critical(fmt.Errorf("panic: %q", p), nil); err != nil { fmt.Fprintf(os.Stderr, "reporting_panic=false err=%q\n", err) } panic(p) } }
[ "func", "(", "r", "*", "Hook", ")", "ReportPanic", "(", ")", "{", "if", "p", ":=", "recover", "(", ")", ";", "p", "!=", "nil", "{", "if", "_", ",", "err", ":=", "r", ".", "Client", ".", "Critical", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ...
// ReportPanic attempts to report the panic to rollbar using the provided // client and then re-panic. If it can't report the panic it will print an // error to stderr.
[ "ReportPanic", "attempts", "to", "report", "the", "panic", "to", "rollbar", "using", "the", "provided", "client", "and", "then", "re", "-", "panic", ".", "If", "it", "can", "t", "report", "the", "panic", "it", "will", "print", "an", "error", "to", "stder...
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L151-L158
215
heroku/rollrus
rollrus.go
ReportPanic
func ReportPanic(token, env string) { if token != "" { h := &Hook{Client: roll.New(token, env)} h.ReportPanic() } }
go
func ReportPanic(token, env string) { if token != "" { h := &Hook{Client: roll.New(token, env)} h.ReportPanic() } }
[ "func", "ReportPanic", "(", "token", ",", "env", "string", ")", "{", "if", "token", "!=", "\"", "\"", "{", "h", ":=", "&", "Hook", "{", "Client", ":", "roll", ".", "New", "(", "token", ",", "env", ")", "}", "\n", "h", ".", "ReportPanic", "(", "...
// ReportPanic attempts to report the panic to rollbar if the token is set
[ "ReportPanic", "attempts", "to", "report", "the", "panic", "to", "rollbar", "if", "the", "token", "is", "set" ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L161-L166
216
heroku/rollrus
rollrus.go
Levels
func (r *Hook) Levels() []logrus.Level { if r.triggers == nil { return defaultTriggerLevels } return r.triggers }
go
func (r *Hook) Levels() []logrus.Level { if r.triggers == nil { return defaultTriggerLevels } return r.triggers }
[ "func", "(", "r", "*", "Hook", ")", "Levels", "(", ")", "[", "]", "logrus", ".", "Level", "{", "if", "r", ".", "triggers", "==", "nil", "{", "return", "defaultTriggerLevels", "\n", "}", "\n", "return", "r", ".", "triggers", "\n", "}" ]
// Levels returns the logrus log.Levels that this hook handles
[ "Levels", "returns", "the", "logrus", "log", ".", "Levels", "that", "this", "hook", "handles" ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L169-L174
217
heroku/rollrus
rollrus.go
extractError
func extractError(entry *logrus.Entry) ([]uintptr, error) { var trace []uintptr fields := entry.Data type stackTracer interface { StackTrace() errors.StackTrace } for _, f := range wellKnownErrorFields { e, ok := fields[f] if !ok { continue } err, ok := e.(error) if !ok { continue } cause := errors.Cause(err) tracer, ok := err.(stackTracer) if ok { return copyStackTrace(tracer.StackTrace()), cause } return trace, cause } // when no error found, default to the logged message. return trace, fmt.Errorf(entry.Message) }
go
func extractError(entry *logrus.Entry) ([]uintptr, error) { var trace []uintptr fields := entry.Data type stackTracer interface { StackTrace() errors.StackTrace } for _, f := range wellKnownErrorFields { e, ok := fields[f] if !ok { continue } err, ok := e.(error) if !ok { continue } cause := errors.Cause(err) tracer, ok := err.(stackTracer) if ok { return copyStackTrace(tracer.StackTrace()), cause } return trace, cause } // when no error found, default to the logged message. return trace, fmt.Errorf(entry.Message) }
[ "func", "extractError", "(", "entry", "*", "logrus", ".", "Entry", ")", "(", "[", "]", "uintptr", ",", "error", ")", "{", "var", "trace", "[", "]", "uintptr", "\n", "fields", ":=", "entry", ".", "Data", "\n\n", "type", "stackTracer", "interface", "{", ...
// extractError attempts to extract an error from a well known field, err or error
[ "extractError", "attempts", "to", "extract", "an", "error", "from", "a", "well", "known", "field", "err", "or", "error" ]
fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99
https://github.com/heroku/rollrus/blob/fde2a6b0b07d2ac4af3fec2ccbdf20f963291f99/rollrus.go#L252-L280
218
koyachi/go-nude
nude.go
merge
func (d *Detector) merge(detectedRegions Regions, mergeRegions [][]int) { var newDetectedRegions Regions // merging detected regions for index, region := range mergeRegions { if len(newDetectedRegions) >= index { newDetectedRegions = append(newDetectedRegions, Region{}) } for _, r := range region { newDetectedRegions[index] = append(newDetectedRegions[index], detectedRegions[r]...) detectedRegions[r] = Region{} } } // push the rest of the regions to the newDetectedRegions array // (regions without merging) for _, region := range detectedRegions { if len(region) > 0 { newDetectedRegions = append(newDetectedRegions, region) } } // clean up d.clearRegions(newDetectedRegions) }
go
func (d *Detector) merge(detectedRegions Regions, mergeRegions [][]int) { var newDetectedRegions Regions // merging detected regions for index, region := range mergeRegions { if len(newDetectedRegions) >= index { newDetectedRegions = append(newDetectedRegions, Region{}) } for _, r := range region { newDetectedRegions[index] = append(newDetectedRegions[index], detectedRegions[r]...) detectedRegions[r] = Region{} } } // push the rest of the regions to the newDetectedRegions array // (regions without merging) for _, region := range detectedRegions { if len(region) > 0 { newDetectedRegions = append(newDetectedRegions, region) } } // clean up d.clearRegions(newDetectedRegions) }
[ "func", "(", "d", "*", "Detector", ")", "merge", "(", "detectedRegions", "Regions", ",", "mergeRegions", "[", "]", "[", "]", "int", ")", "{", "var", "newDetectedRegions", "Regions", "\n\n", "// merging detected regions", "for", "index", ",", "region", ":=", ...
// function for merging detected regions
[ "function", "for", "merging", "detected", "regions" ]
699a88f33605865928ccd8cdd39bbce80fb1aaef
https://github.com/koyachi/go-nude/blob/699a88f33605865928ccd8cdd39bbce80fb1aaef/nude.go#L176-L200
219
koyachi/go-nude
nude.go
clearRegions
func (d *Detector) clearRegions(detectedRegions Regions) { for _, region := range detectedRegions { if len(region) > 30 { d.SkinRegions = append(d.SkinRegions, region) } } }
go
func (d *Detector) clearRegions(detectedRegions Regions) { for _, region := range detectedRegions { if len(region) > 30 { d.SkinRegions = append(d.SkinRegions, region) } } }
[ "func", "(", "d", "*", "Detector", ")", "clearRegions", "(", "detectedRegions", "Regions", ")", "{", "for", "_", ",", "region", ":=", "range", "detectedRegions", "{", "if", "len", "(", "region", ")", ">", "30", "{", "d", ".", "SkinRegions", "=", "appen...
// clean up function // only push regions which are bigger than a specific amount to the final resul
[ "clean", "up", "function", "only", "push", "regions", "which", "are", "bigger", "than", "a", "specific", "amount", "to", "the", "final", "resul" ]
699a88f33605865928ccd8cdd39bbce80fb1aaef
https://github.com/koyachi/go-nude/blob/699a88f33605865928ccd8cdd39bbce80fb1aaef/nude.go#L204-L210
220
koyachi/go-nude
nude.go
classifySkin
func classifySkin(r, g, b uint32) (bool, float64) { rgbClassifier := r > 95 && g > 40 && g < 100 && b > 20 && maxRgb(r, g, b)-minRgb(r, g, b) > 15 && math.Abs(float64(r-g)) > 15 && r > g && r > b nr, ng, _ := toNormalizedRgb(r, g, b) normalizedRgbClassifier := nr/ng > 1.185 && (float64(r*b))/math.Pow(float64(r+g+b), 2) > 0.107 && (float64(r*g))/math.Pow(float64(r+g+b), 2) > 0.112 h, s, v := toHsv(r, g, b) hsvClassifier := h > 0 && h < 35 && s > 0.23 && s < 0.68 // ycc doesnt work result := rgbClassifier || normalizedRgbClassifier || hsvClassifier return result, v }
go
func classifySkin(r, g, b uint32) (bool, float64) { rgbClassifier := r > 95 && g > 40 && g < 100 && b > 20 && maxRgb(r, g, b)-minRgb(r, g, b) > 15 && math.Abs(float64(r-g)) > 15 && r > g && r > b nr, ng, _ := toNormalizedRgb(r, g, b) normalizedRgbClassifier := nr/ng > 1.185 && (float64(r*b))/math.Pow(float64(r+g+b), 2) > 0.107 && (float64(r*g))/math.Pow(float64(r+g+b), 2) > 0.112 h, s, v := toHsv(r, g, b) hsvClassifier := h > 0 && h < 35 && s > 0.23 && s < 0.68 // ycc doesnt work result := rgbClassifier || normalizedRgbClassifier || hsvClassifier return result, v }
[ "func", "classifySkin", "(", "r", ",", "g", ",", "b", "uint32", ")", "(", "bool", ",", "float64", ")", "{", "rgbClassifier", ":=", "r", ">", "95", "&&", "g", ">", "40", "&&", "g", "<", "100", "&&", "b", ">", "20", "&&", "maxRgb", "(", "r", ",...
// A Survey on Pixel-Based Skin Color Detection Techniques
[ "A", "Survey", "on", "Pixel", "-", "Based", "Skin", "Color", "Detection", "Techniques" ]
699a88f33605865928ccd8cdd39bbce80fb1aaef
https://github.com/koyachi/go-nude/blob/699a88f33605865928ccd8cdd39bbce80fb1aaef/nude.go#L292-L316
221
iotaledger/iota.go
mam/v1/mask.go
Mask
func Mask(dest Trits, message Trits, length uint64, c *curl.Curl) { var chunkLength uint64 chunk := make(Trits, HashTrinarySize) for i := uint64(0); i < length; i += HashTrinarySize { if length-i < HashTrinarySize { chunkLength = length - i } else { chunkLength = HashTrinarySize } copy(chunk, message[i:i+chunkLength]) for j := uint64(0); j < chunkLength; j++ { dest[i+j] = Sum(chunk[j], c.State[j]) } c.Absorb(chunk[:chunkLength]) } }
go
func Mask(dest Trits, message Trits, length uint64, c *curl.Curl) { var chunkLength uint64 chunk := make(Trits, HashTrinarySize) for i := uint64(0); i < length; i += HashTrinarySize { if length-i < HashTrinarySize { chunkLength = length - i } else { chunkLength = HashTrinarySize } copy(chunk, message[i:i+chunkLength]) for j := uint64(0); j < chunkLength; j++ { dest[i+j] = Sum(chunk[j], c.State[j]) } c.Absorb(chunk[:chunkLength]) } }
[ "func", "Mask", "(", "dest", "Trits", ",", "message", "Trits", ",", "length", "uint64", ",", "c", "*", "curl", ".", "Curl", ")", "{", "var", "chunkLength", "uint64", "\n\n", "chunk", ":=", "make", "(", "Trits", ",", "HashTrinarySize", ")", "\n\n", "for...
// Masks a given message with a curl instance state. // dest is the destination of the masked message // message is the message to be masked // length is the length of the message // c is the curl instance used to mask the message
[ "Masks", "a", "given", "message", "with", "a", "curl", "instance", "state", ".", "dest", "is", "the", "destination", "of", "the", "masked", "message", "message", "is", "the", "message", "to", "be", "masked", "length", "is", "the", "length", "of", "the", ...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/mam/v1/mask.go#L16-L35
222
iotaledger/iota.go
mam/v1/mask.go
Unmask
func Unmask(cipher Trits, length uint64, c *curl.Curl) (dest Trits) { var chunkLength uint64 dest = make(Trits, length) for i := uint64(0); i < length; i += HashTrinarySize { if length-i < HashTrinarySize { chunkLength = length - i } else { chunkLength = HashTrinarySize } for j := uint64(0); j < chunkLength; j++ { dest[i+j] = Sum(cipher[i+j], -c.State[j]) } c.Absorb(dest[i : i+chunkLength]) } return dest }
go
func Unmask(cipher Trits, length uint64, c *curl.Curl) (dest Trits) { var chunkLength uint64 dest = make(Trits, length) for i := uint64(0); i < length; i += HashTrinarySize { if length-i < HashTrinarySize { chunkLength = length - i } else { chunkLength = HashTrinarySize } for j := uint64(0); j < chunkLength; j++ { dest[i+j] = Sum(cipher[i+j], -c.State[j]) } c.Absorb(dest[i : i+chunkLength]) } return dest }
[ "func", "Unmask", "(", "cipher", "Trits", ",", "length", "uint64", ",", "c", "*", "curl", ".", "Curl", ")", "(", "dest", "Trits", ")", "{", "var", "chunkLength", "uint64", "\n", "dest", "=", "make", "(", "Trits", ",", "length", ")", "\n\n", "for", ...
// Unmasks a given cipher with a curl instance state. // cipher is the cipher to be unmasked // length is the length of the cipher // c is the curl instance used to unmask the cipher // returns the unmasked cipher
[ "Unmasks", "a", "given", "cipher", "with", "a", "curl", "instance", "state", ".", "cipher", "is", "the", "cipher", "to", "be", "unmasked", "length", "is", "the", "length", "of", "the", "cipher", "c", "is", "the", "curl", "instance", "used", "to", "unmask...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/mam/v1/mask.go#L42-L59
223
iotaledger/iota.go
api/api.go
ComposeAPI
func ComposeAPI(settings Settings, createProvider ...CreateProviderFunc) (*API, error) { if settings == nil { return nil, ErrSettingsNil } var provider Provider var err error if len(createProvider) > 0 && createProvider[0] != nil { provider, err = createProvider[0](settings) } else { provider, err = NewHTTPClient(settings) } if err != nil { return nil, err } api := &API{provider: provider} if settings.ProofOfWorkFunc() != nil { api.localProofOfWorkFunc = settings.ProofOfWorkFunc() } return api, nil }
go
func ComposeAPI(settings Settings, createProvider ...CreateProviderFunc) (*API, error) { if settings == nil { return nil, ErrSettingsNil } var provider Provider var err error if len(createProvider) > 0 && createProvider[0] != nil { provider, err = createProvider[0](settings) } else { provider, err = NewHTTPClient(settings) } if err != nil { return nil, err } api := &API{provider: provider} if settings.ProofOfWorkFunc() != nil { api.localProofOfWorkFunc = settings.ProofOfWorkFunc() } return api, nil }
[ "func", "ComposeAPI", "(", "settings", "Settings", ",", "createProvider", "...", "CreateProviderFunc", ")", "(", "*", "API", ",", "error", ")", "{", "if", "settings", "==", "nil", "{", "return", "nil", ",", "ErrSettingsNil", "\n", "}", "\n", "var", "provid...
// ComposeAPI composes a new API from the given settings and provider. // If no provider function is supplied, then the default http provider is used. // Settings must not be nil.
[ "ComposeAPI", "composes", "a", "new", "API", "from", "the", "given", "settings", "and", "provider", ".", "If", "no", "provider", "function", "is", "supplied", "then", "the", "default", "http", "provider", "is", "used", ".", "Settings", "must", "not", "be", ...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/api.go#L34-L55
224
iotaledger/iota.go
guards/validators/validator.go
Validate
func Validate(validators ...Validatable) error { for i := range validators { if err := validators[i](); err != nil { return err } } return nil }
go
func Validate(validators ...Validatable) error { for i := range validators { if err := validators[i](); err != nil { return err } } return nil }
[ "func", "Validate", "(", "validators", "...", "Validatable", ")", "error", "{", "for", "i", ":=", "range", "validators", "{", "if", "err", ":=", "validators", "[", "i", "]", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", ...
// Validate calls all given validators or returns the first occurred error.
[ "Validate", "calls", "all", "given", "validators", "or", "returns", "the", "first", "occurred", "error", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L17-L24
225
iotaledger/iota.go
guards/validators/validator.go
ValidateNonEmptyStrings
func ValidateNonEmptyStrings(err error, slice ...string) Validatable { return func() error { if slice == nil || len(slice) == 0 { return err } return nil } }
go
func ValidateNonEmptyStrings(err error, slice ...string) Validatable { return func() error { if slice == nil || len(slice) == 0 { return err } return nil } }
[ "func", "ValidateNonEmptyStrings", "(", "err", "error", ",", "slice", "...", "string", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "if", "slice", "==", "nil", "||", "len", "(", "slice", ")", "==", "0", "{", "return", "err", "\n",...
// ValidateNonEmptyStrings checks for non empty string slices.
[ "ValidateNonEmptyStrings", "checks", "for", "non", "empty", "string", "slices", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L27-L34
226
iotaledger/iota.go
guards/validators/validator.go
ValidateTransactionHashes
func ValidateTransactionHashes(hashes ...Hash) Validatable { return func() error { for i := range hashes { if !IsTransactionHash(hashes[i]) { return errors.Wrapf(ErrInvalidTransactionHash, "%s at index %d", hashes[i], i) } } return nil } }
go
func ValidateTransactionHashes(hashes ...Hash) Validatable { return func() error { for i := range hashes { if !IsTransactionHash(hashes[i]) { return errors.Wrapf(ErrInvalidTransactionHash, "%s at index %d", hashes[i], i) } } return nil } }
[ "func", "ValidateTransactionHashes", "(", "hashes", "...", "Hash", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "hashes", "{", "if", "!", "IsTransactionHash", "(", "hashes", "[", "i", "]", ")", "{", "retur...
// ValidateTransactionHashes validates the given transaction hashes.
[ "ValidateTransactionHashes", "validates", "the", "given", "transaction", "hashes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L37-L46
227
iotaledger/iota.go
guards/validators/validator.go
ValidateHashes
func ValidateHashes(hashes ...Hash) Validatable { return func() error { for i := range hashes { if !IsHash(hashes[i]) { return errors.Wrapf(ErrInvalidHash, "%s at index %d", hashes[i], i) } } return nil } }
go
func ValidateHashes(hashes ...Hash) Validatable { return func() error { for i := range hashes { if !IsHash(hashes[i]) { return errors.Wrapf(ErrInvalidHash, "%s at index %d", hashes[i], i) } } return nil } }
[ "func", "ValidateHashes", "(", "hashes", "...", "Hash", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "hashes", "{", "if", "!", "IsHash", "(", "hashes", "[", "i", "]", ")", "{", "return", "errors", ".",...
// ValidateHashes validates the given hashes.
[ "ValidateHashes", "validates", "the", "given", "hashes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L49-L58
228
iotaledger/iota.go
guards/validators/validator.go
ValidateAddresses
func ValidateAddresses(checkLastTrit bool, addrs ...Hash) Validatable { return func() error { for i := range addrs { if !IsAddressWithChecksum(addrs[i]) { return errors.Wrapf(ErrInvalidHash, "%s at index %d (not length of 90 trytes)", addrs[i], i) } if checkLastTrit { lastTrits := MustTrytesToTrits(string(addrs[i][80])) if lastTrits[2] != 0 { return errors.Wrapf(ErrInvalidHash, "%s at index %d (last trit non 0)", addrs[i], i) } } } return nil } }
go
func ValidateAddresses(checkLastTrit bool, addrs ...Hash) Validatable { return func() error { for i := range addrs { if !IsAddressWithChecksum(addrs[i]) { return errors.Wrapf(ErrInvalidHash, "%s at index %d (not length of 90 trytes)", addrs[i], i) } if checkLastTrit { lastTrits := MustTrytesToTrits(string(addrs[i][80])) if lastTrits[2] != 0 { return errors.Wrapf(ErrInvalidHash, "%s at index %d (last trit non 0)", addrs[i], i) } } } return nil } }
[ "func", "ValidateAddresses", "(", "checkLastTrit", "bool", ",", "addrs", "...", "Hash", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "addrs", "{", "if", "!", "IsAddressWithChecksum", "(", "addrs", "[", "i", ...
// ValidateAddresses validates the given addresses which must include the checksum.
[ "ValidateAddresses", "validates", "the", "given", "addresses", "which", "must", "include", "the", "checksum", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L61-L76
229
iotaledger/iota.go
guards/validators/validator.go
ValidateTransactionTrytes
func ValidateTransactionTrytes(trytes ...Trytes) Validatable { return func() error { for i := range trytes { if !IsTransactionTrytes(trytes[i]) { return errors.Wrapf(ErrInvalidTransactionTrytes, "at index %d", i) } } return nil } }
go
func ValidateTransactionTrytes(trytes ...Trytes) Validatable { return func() error { for i := range trytes { if !IsTransactionTrytes(trytes[i]) { return errors.Wrapf(ErrInvalidTransactionTrytes, "at index %d", i) } } return nil } }
[ "func", "ValidateTransactionTrytes", "(", "trytes", "...", "Trytes", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "trytes", "{", "if", "!", "IsTransactionTrytes", "(", "trytes", "[", "i", "]", ")", "{", "r...
// ValidateTransactionTrytes validates the given transaction trytes.
[ "ValidateTransactionTrytes", "validates", "the", "given", "transaction", "trytes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L79-L88
230
iotaledger/iota.go
guards/validators/validator.go
ValidateAttachedTransactionTrytes
func ValidateAttachedTransactionTrytes(trytes ...Trytes) Validatable { return func() error { for i := range trytes { if !IsAttachedTrytes(trytes[i]) { return errors.Wrapf(ErrInvalidAttachedTrytes, "at index %d", i) } } return nil } }
go
func ValidateAttachedTransactionTrytes(trytes ...Trytes) Validatable { return func() error { for i := range trytes { if !IsAttachedTrytes(trytes[i]) { return errors.Wrapf(ErrInvalidAttachedTrytes, "at index %d", i) } } return nil } }
[ "func", "ValidateAttachedTransactionTrytes", "(", "trytes", "...", "Trytes", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "trytes", "{", "if", "!", "IsAttachedTrytes", "(", "trytes", "[", "i", "]", ")", "{",...
// ValidateAttachedTransactionTrytes validates the given attached transaction trytes.
[ "ValidateAttachedTransactionTrytes", "validates", "the", "given", "attached", "transaction", "trytes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L91-L100
231
iotaledger/iota.go
guards/validators/validator.go
ValidateTags
func ValidateTags(tags ...Trytes) Validatable { return func() error { for i := range tags { if !IsTag(tags[i]) { return errors.Wrapf(ErrInvalidTag, "%s at index %d", tags[i], i) } } return nil } }
go
func ValidateTags(tags ...Trytes) Validatable { return func() error { for i := range tags { if !IsTag(tags[i]) { return errors.Wrapf(ErrInvalidTag, "%s at index %d", tags[i], i) } } return nil } }
[ "func", "ValidateTags", "(", "tags", "...", "Trytes", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "tags", "{", "if", "!", "IsTag", "(", "tags", "[", "i", "]", ")", "{", "return", "errors", ".", "Wra...
// ValidateTags validates the given tags.
[ "ValidateTags", "validates", "the", "given", "tags", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L103-L112
232
iotaledger/iota.go
guards/validators/validator.go
ValidateSeed
func ValidateSeed(seed Trytes) Validatable { return func() error { if !IsTrytesOfExactLength(seed, HashTrytesSize) { return ErrInvalidSeed } return nil } }
go
func ValidateSeed(seed Trytes) Validatable { return func() error { if !IsTrytesOfExactLength(seed, HashTrytesSize) { return ErrInvalidSeed } return nil } }
[ "func", "ValidateSeed", "(", "seed", "Trytes", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "if", "!", "IsTrytesOfExactLength", "(", "seed", ",", "HashTrytesSize", ")", "{", "return", "ErrInvalidSeed", "\n", "}", "\n", "return", "nil", ...
// ValidateSeed validates the given seed.
[ "ValidateSeed", "validates", "the", "given", "seed", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L145-L152
233
iotaledger/iota.go
guards/validators/validator.go
ValidateStartEndOptions
func ValidateStartEndOptions(start uint64, end *uint64) Validatable { return func() error { if end == nil { return nil } e := *end if start > e || e > start+MaxIndexDiff { return ErrInvalidStartEndOptions } return nil } }
go
func ValidateStartEndOptions(start uint64, end *uint64) Validatable { return func() error { if end == nil { return nil } e := *end if start > e || e > start+MaxIndexDiff { return ErrInvalidStartEndOptions } return nil } }
[ "func", "ValidateStartEndOptions", "(", "start", "uint64", ",", "end", "*", "uint64", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "if", "end", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "e", ":=", "*", "end", "\n", "if...
// ValidateStartEndOptions validates the given start and optional end option.
[ "ValidateStartEndOptions", "validates", "the", "given", "start", "and", "optional", "end", "option", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L158-L169
234
iotaledger/iota.go
guards/validators/validator.go
ValidateTransfers
func ValidateTransfers(transfers ...bundle.Transfer) Validatable { return func() error { for i := range transfers { transfer := &transfers[i] if IsHash(transfer.Address) && (transfer.Message == "" || IsTrytes(transfer.Message)) || (transfer.Tag == "" || IsTag(transfer.Tag)) { continue } return ErrInvalidTransfer } return nil } }
go
func ValidateTransfers(transfers ...bundle.Transfer) Validatable { return func() error { for i := range transfers { transfer := &transfers[i] if IsHash(transfer.Address) && (transfer.Message == "" || IsTrytes(transfer.Message)) || (transfer.Tag == "" || IsTag(transfer.Tag)) { continue } return ErrInvalidTransfer } return nil } }
[ "func", "ValidateTransfers", "(", "transfers", "...", "bundle", ".", "Transfer", ")", "Validatable", "{", "return", "func", "(", ")", "error", "{", "for", "i", ":=", "range", "transfers", "{", "transfer", ":=", "&", "transfers", "[", "i", "]", "\n", "if"...
// ValidateTransfers validates the given transfers.
[ "ValidateTransfers", "validates", "the", "given", "transfers", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/validators/validator.go#L172-L185
235
iotaledger/iota.go
kerl/sha3/hashes.go
New224
func New224() hash.Hash { if h := new224Asm(); h != nil { return h } return &state{rate: 144, outputLen: 28, dsbyte: 0x01} }
go
func New224() hash.Hash { if h := new224Asm(); h != nil { return h } return &state{rate: 144, outputLen: 28, dsbyte: 0x01} }
[ "func", "New224", "(", ")", "hash", ".", "Hash", "{", "if", "h", ":=", "new224Asm", "(", ")", ";", "h", "!=", "nil", "{", "return", "h", "\n", "}", "\n", "return", "&", "state", "{", "rate", ":", "144", ",", "outputLen", ":", "28", ",", "dsbyte...
// New224 creates a new SHA3-224 hash. // Its generic security strength is 224 bits against preimage attacks, // and 112 bits against collision attacks.
[ "New224", "creates", "a", "new", "SHA3", "-", "224", "hash", ".", "Its", "generic", "security", "strength", "is", "224", "bits", "against", "preimage", "attacks", "and", "112", "bits", "against", "collision", "attacks", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L18-L23
236
iotaledger/iota.go
kerl/sha3/hashes.go
New256
func New256() hash.Hash { if h := new256Asm(); h != nil { return h } return &state{rate: 136, outputLen: 32, dsbyte: 0x01} }
go
func New256() hash.Hash { if h := new256Asm(); h != nil { return h } return &state{rate: 136, outputLen: 32, dsbyte: 0x01} }
[ "func", "New256", "(", ")", "hash", ".", "Hash", "{", "if", "h", ":=", "new256Asm", "(", ")", ";", "h", "!=", "nil", "{", "return", "h", "\n", "}", "\n", "return", "&", "state", "{", "rate", ":", "136", ",", "outputLen", ":", "32", ",", "dsbyte...
// New256 creates a new SHA3-256 hash. // Its generic security strength is 256 bits against preimage attacks, // and 128 bits against collision attacks.
[ "New256", "creates", "a", "new", "SHA3", "-", "256", "hash", ".", "Its", "generic", "security", "strength", "is", "256", "bits", "against", "preimage", "attacks", "and", "128", "bits", "against", "collision", "attacks", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L28-L33
237
iotaledger/iota.go
kerl/sha3/hashes.go
New384
func New384() hash.Hash { if h := new384Asm(); h != nil { return h } return &state{rate: 104, outputLen: 48, dsbyte: 0x01} }
go
func New384() hash.Hash { if h := new384Asm(); h != nil { return h } return &state{rate: 104, outputLen: 48, dsbyte: 0x01} }
[ "func", "New384", "(", ")", "hash", ".", "Hash", "{", "if", "h", ":=", "new384Asm", "(", ")", ";", "h", "!=", "nil", "{", "return", "h", "\n", "}", "\n", "return", "&", "state", "{", "rate", ":", "104", ",", "outputLen", ":", "48", ",", "dsbyte...
// New384 creates a new SHA3-384 hash. // Its generic security strength is 384 bits against preimage attacks, // and 192 bits against collision attacks.
[ "New384", "creates", "a", "new", "SHA3", "-", "384", "hash", ".", "Its", "generic", "security", "strength", "is", "384", "bits", "against", "preimage", "attacks", "and", "192", "bits", "against", "collision", "attacks", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L38-L43
238
iotaledger/iota.go
kerl/sha3/hashes.go
New512
func New512() hash.Hash { if h := new512Asm(); h != nil { return h } return &state{rate: 72, outputLen: 64, dsbyte: 0x01} }
go
func New512() hash.Hash { if h := new512Asm(); h != nil { return h } return &state{rate: 72, outputLen: 64, dsbyte: 0x01} }
[ "func", "New512", "(", ")", "hash", ".", "Hash", "{", "if", "h", ":=", "new512Asm", "(", ")", ";", "h", "!=", "nil", "{", "return", "h", "\n", "}", "\n", "return", "&", "state", "{", "rate", ":", "72", ",", "outputLen", ":", "64", ",", "dsbyte"...
// New512 creates a new SHA3-512 hash. // Its generic security strength is 512 bits against preimage attacks, // and 256 bits against collision attacks.
[ "New512", "creates", "a", "new", "SHA3", "-", "512", "hash", ".", "Its", "generic", "security", "strength", "is", "512", "bits", "against", "preimage", "attacks", "and", "256", "bits", "against", "collision", "attacks", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L48-L53
239
iotaledger/iota.go
kerl/sha3/hashes.go
Sum224
func Sum224(data []byte) (digest [28]byte) { h := New224() h.Write(data) h.Sum(digest[:0]) return }
go
func Sum224(data []byte) (digest [28]byte) { h := New224() h.Write(data) h.Sum(digest[:0]) return }
[ "func", "Sum224", "(", "data", "[", "]", "byte", ")", "(", "digest", "[", "28", "]", "byte", ")", "{", "h", ":=", "New224", "(", ")", "\n", "h", ".", "Write", "(", "data", ")", "\n", "h", ".", "Sum", "(", "digest", "[", ":", "0", "]", ")", ...
// Sum224 returns the SHA3-224 digest of the data.
[ "Sum224", "returns", "the", "SHA3", "-", "224", "digest", "of", "the", "data", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L62-L67
240
iotaledger/iota.go
kerl/sha3/hashes.go
Sum256
func Sum256(data []byte) (digest [32]byte) { h := New256() h.Write(data) h.Sum(digest[:0]) return }
go
func Sum256(data []byte) (digest [32]byte) { h := New256() h.Write(data) h.Sum(digest[:0]) return }
[ "func", "Sum256", "(", "data", "[", "]", "byte", ")", "(", "digest", "[", "32", "]", "byte", ")", "{", "h", ":=", "New256", "(", ")", "\n", "h", ".", "Write", "(", "data", ")", "\n", "h", ".", "Sum", "(", "digest", "[", ":", "0", "]", ")", ...
// Sum256 returns the SHA3-256 digest of the data.
[ "Sum256", "returns", "the", "SHA3", "-", "256", "digest", "of", "the", "data", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L70-L75
241
iotaledger/iota.go
kerl/sha3/hashes.go
Sum384
func Sum384(data []byte) (digest [48]byte) { h := New384() h.Write(data) h.Sum(digest[:0]) return }
go
func Sum384(data []byte) (digest [48]byte) { h := New384() h.Write(data) h.Sum(digest[:0]) return }
[ "func", "Sum384", "(", "data", "[", "]", "byte", ")", "(", "digest", "[", "48", "]", "byte", ")", "{", "h", ":=", "New384", "(", ")", "\n", "h", ".", "Write", "(", "data", ")", "\n", "h", ".", "Sum", "(", "digest", "[", ":", "0", "]", ")", ...
// Sum384 returns the SHA3-384 digest of the data.
[ "Sum384", "returns", "the", "SHA3", "-", "384", "digest", "of", "the", "data", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L78-L83
242
iotaledger/iota.go
kerl/sha3/hashes.go
Sum512
func Sum512(data []byte) (digest [64]byte) { h := New512() h.Write(data) h.Sum(digest[:0]) return }
go
func Sum512(data []byte) (digest [64]byte) { h := New512() h.Write(data) h.Sum(digest[:0]) return }
[ "func", "Sum512", "(", "data", "[", "]", "byte", ")", "(", "digest", "[", "64", "]", "byte", ")", "{", "h", ":=", "New512", "(", ")", "\n", "h", ".", "Write", "(", "data", ")", "\n", "h", ".", "Sum", "(", "digest", "[", ":", "0", "]", ")", ...
// Sum512 returns the SHA3-512 digest of the data.
[ "Sum512", "returns", "the", "SHA3", "-", "512", "digest", "of", "the", "data", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/hashes.go#L86-L91
243
iotaledger/iota.go
signing/legacy/signing.go
Subseed
func Subseed(seed Trytes, index uint64, spongeFunc ...SpongeFunction) (Trits, error) { if err := ValidTrytes(seed); err != nil { return nil, err } else if len(seed) != HashTrinarySize/TrinaryRadix { return nil, ErrInvalidSeed } trits, err := TrytesToTrits(seed) if err != nil { return nil, err } incrementedSeed := AddTrits(trits, IntToTrits(int64(index))) h := GetSpongeFunc(spongeFunc, kerl.NewKerl) defer h.Reset() err = h.Absorb(incrementedSeed) if err != nil { return nil, err } subseed, err := h.Squeeze(HashTrinarySize) if err != nil { return nil, err } return subseed, err }
go
func Subseed(seed Trytes, index uint64, spongeFunc ...SpongeFunction) (Trits, error) { if err := ValidTrytes(seed); err != nil { return nil, err } else if len(seed) != HashTrinarySize/TrinaryRadix { return nil, ErrInvalidSeed } trits, err := TrytesToTrits(seed) if err != nil { return nil, err } incrementedSeed := AddTrits(trits, IntToTrits(int64(index))) h := GetSpongeFunc(spongeFunc, kerl.NewKerl) defer h.Reset() err = h.Absorb(incrementedSeed) if err != nil { return nil, err } subseed, err := h.Squeeze(HashTrinarySize) if err != nil { return nil, err } return subseed, err }
[ "func", "Subseed", "(", "seed", "Trytes", ",", "index", "uint64", ",", "spongeFunc", "...", "SpongeFunction", ")", "(", "Trits", ",", "error", ")", "{", "if", "err", ":=", "ValidTrytes", "(", "seed", ")", ";", "err", "!=", "nil", "{", "return", "nil", ...
// Subseed takes a seed and an index and returns the given subseed. // Optionally takes the SpongeFunction to use. Default is Kerl.
[ "Subseed", "takes", "a", "seed", "and", "an", "index", "and", "returns", "the", "given", "subseed", ".", "Optionally", "takes", "the", "SpongeFunction", "to", "use", ".", "Default", "is", "Kerl", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/signing/legacy/signing.go#L17-L44
244
iotaledger/iota.go
signing/legacy/signing.go
Address
func Address(digests Trits, spongeFunc ...SpongeFunction) (Trits, error) { h := GetSpongeFunc(spongeFunc, kerl.NewKerl) defer h.Reset() if err := h.Absorb(digests); err != nil { return nil, err } return h.Squeeze(HashTrinarySize) }
go
func Address(digests Trits, spongeFunc ...SpongeFunction) (Trits, error) { h := GetSpongeFunc(spongeFunc, kerl.NewKerl) defer h.Reset() if err := h.Absorb(digests); err != nil { return nil, err } return h.Squeeze(HashTrinarySize) }
[ "func", "Address", "(", "digests", "Trits", ",", "spongeFunc", "...", "SpongeFunction", ")", "(", "Trits", ",", "error", ")", "{", "h", ":=", "GetSpongeFunc", "(", "spongeFunc", ",", "kerl", ".", "NewKerl", ")", "\n", "defer", "h", ".", "Reset", "(", "...
// Address generates the address trits from the given digests. // Optionally takes the SpongeFunction to use. Default is Kerl.
[ "Address", "generates", "the", "address", "trits", "from", "the", "given", "digests", ".", "Optionally", "takes", "the", "SpongeFunction", "to", "use", ".", "Default", "is", "Kerl", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/signing/legacy/signing.go#L138-L146
245
iotaledger/iota.go
signing/legacy/signing.go
Digest
func Digest(bundleHash []int8, signatureFragment Trits, startOffset int, spongeFunc ...SpongeFunction) (Trits, error) { sigLength := len(signatureFragment) secLvl, err := GetSecurityLevel(bundleHash) if err != nil { return nil, err } sigFrag := make(Trits, sigLength) copy(sigFrag, signatureFragment[:sigLength]) h := GetSpongeFunc(spongeFunc, kerl.NewKerl) defer h.Reset() dig := make(Trits, HashTrinarySize) sig := make(Trits, HashTrinarySize) i := startOffset % int(secLvl) for digLength := 0; digLength < sigLength; { for j := i * ISSChunkLength; j < (i+1)*ISSChunkLength && digLength < sigLength; j += TrinaryRadix { copy(sig, sigFrag[digLength:digLength+HashTrinarySize]) to := (bundleHash[j] + bundleHash[j+1]*3 + bundleHash[j+2]*9) - MinTryteValue for k := 0; k < int(to); k++ { err := h.Absorb(sig) if err != nil { return nil, err } sig, err = h.Squeeze(HashTrinarySize) if err != nil { return nil, err } h.Reset() } copy(sigFrag[digLength:], sig) digLength += HashTrinarySize } i = (i + 1) % int(secLvl) } err = h.Absorb(sigFrag) if err != nil { return nil, err } dig, err = h.Squeeze(HashTrinarySize) if err != nil { return nil, err } return dig, nil }
go
func Digest(bundleHash []int8, signatureFragment Trits, startOffset int, spongeFunc ...SpongeFunction) (Trits, error) { sigLength := len(signatureFragment) secLvl, err := GetSecurityLevel(bundleHash) if err != nil { return nil, err } sigFrag := make(Trits, sigLength) copy(sigFrag, signatureFragment[:sigLength]) h := GetSpongeFunc(spongeFunc, kerl.NewKerl) defer h.Reset() dig := make(Trits, HashTrinarySize) sig := make(Trits, HashTrinarySize) i := startOffset % int(secLvl) for digLength := 0; digLength < sigLength; { for j := i * ISSChunkLength; j < (i+1)*ISSChunkLength && digLength < sigLength; j += TrinaryRadix { copy(sig, sigFrag[digLength:digLength+HashTrinarySize]) to := (bundleHash[j] + bundleHash[j+1]*3 + bundleHash[j+2]*9) - MinTryteValue for k := 0; k < int(to); k++ { err := h.Absorb(sig) if err != nil { return nil, err } sig, err = h.Squeeze(HashTrinarySize) if err != nil { return nil, err } h.Reset() } copy(sigFrag[digLength:], sig) digLength += HashTrinarySize } i = (i + 1) % int(secLvl) } err = h.Absorb(sigFrag) if err != nil { return nil, err } dig, err = h.Squeeze(HashTrinarySize) if err != nil { return nil, err } return dig, nil }
[ "func", "Digest", "(", "bundleHash", "[", "]", "int8", ",", "signatureFragment", "Trits", ",", "startOffset", "int", ",", "spongeFunc", "...", "SpongeFunction", ")", "(", "Trits", ",", "error", ")", "{", "sigLength", ":=", "len", "(", "signatureFragment", ")...
// Digest computes the digest derived from the signature fragment and bundle hash. // Optionally takes the SpongeFunction to use. Default is Kerl.
[ "Digest", "computes", "the", "digest", "derived", "from", "the", "signature", "fragment", "and", "bundle", "hash", ".", "Optionally", "takes", "the", "SpongeFunction", "to", "use", ".", "Default", "is", "Kerl", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/signing/legacy/signing.go#L212-L266
246
iotaledger/iota.go
pow/pow_avx.go
AVXProofOfWork
func AVXProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) { return avxProofOfWork(trytes, mwm, nil, parallelism...) }
go
func AVXProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) { return avxProofOfWork(trytes, mwm, nil, parallelism...) }
[ "func", "AVXProofOfWork", "(", "trytes", "Trytes", ",", "mwm", "int", ",", "parallelism", "...", "int", ")", "(", "Trytes", ",", "error", ")", "{", "return", "avxProofOfWork", "(", "trytes", ",", "mwm", ",", "nil", ",", "parallelism", "...", ")", "\n", ...
// AVXProofOfWork does Proof-of-Work on the given trytes using AVX instructions.
[ "AVXProofOfWork", "does", "Proof", "-", "of", "-", "Work", "on", "the", "given", "trytes", "using", "AVX", "instructions", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_avx.go#L318-L320
247
iotaledger/iota.go
kerl/converter.go
KerlTritsToBytes
func KerlTritsToBytes(trits Trits) ([]byte, error) { if !CanBeHash(trits) { return nil, errors.Wrapf(ErrInvalidTritsLength, "must be %d in size", HashTrinarySize) } allNeg := true // last position should be always zero. for _, e := range trits[0 : HashTrinarySize-1] { if e != -1 { allNeg = false break } } // trit to BigInt b := make([]byte, 48) // 48 bytes/384 bits // 12 * 32 bits = 384 bits base := (*(*[]uint32)(unsafe.Pointer(&b)))[0:IntLength] if allNeg { // if all trits are -1 then we're half way through all the numbers, // since they're in two's complement notation. copy(base, halfThree) // compensate for setting the last position to zero. bigint.Not(base) bigint.AddSmall(base, 1) return bigint.Reverse(b), nil } revT := make([]int8, len(trits)) copy(revT, trits) size := 1 for _, e := range ReverseTrits(revT[0 : HashTrinarySize-1]) { sz := size var carry uint32 for j := 0; j < sz; j++ { v := uint64(base[j])*uint64(TrinaryRadix) + uint64(carry) carry = uint32(v >> 32) base[j] = uint32(v) } if carry > 0 { base[sz] = carry size = size + 1 } trit := uint32(e + 1) ns := bigint.AddSmall(base, trit) if ns > size { size = ns } } if !bigint.IsNull(base) { if bigint.MustCmp(halfThree, base) <= 0 { // base >= HALF_3 // just do base - HALF_3 bigint.MustSub(base, halfThree) } else { // we don'trits have a wrapping sub. // so let's use some bit magic to achieve it tmp := make([]uint32, IntLength) copy(tmp, halfThree) bigint.MustSub(tmp, base) bigint.Not(tmp) bigint.AddSmall(tmp, 1) copy(base, tmp) } } return bigint.Reverse(b), nil }
go
func KerlTritsToBytes(trits Trits) ([]byte, error) { if !CanBeHash(trits) { return nil, errors.Wrapf(ErrInvalidTritsLength, "must be %d in size", HashTrinarySize) } allNeg := true // last position should be always zero. for _, e := range trits[0 : HashTrinarySize-1] { if e != -1 { allNeg = false break } } // trit to BigInt b := make([]byte, 48) // 48 bytes/384 bits // 12 * 32 bits = 384 bits base := (*(*[]uint32)(unsafe.Pointer(&b)))[0:IntLength] if allNeg { // if all trits are -1 then we're half way through all the numbers, // since they're in two's complement notation. copy(base, halfThree) // compensate for setting the last position to zero. bigint.Not(base) bigint.AddSmall(base, 1) return bigint.Reverse(b), nil } revT := make([]int8, len(trits)) copy(revT, trits) size := 1 for _, e := range ReverseTrits(revT[0 : HashTrinarySize-1]) { sz := size var carry uint32 for j := 0; j < sz; j++ { v := uint64(base[j])*uint64(TrinaryRadix) + uint64(carry) carry = uint32(v >> 32) base[j] = uint32(v) } if carry > 0 { base[sz] = carry size = size + 1 } trit := uint32(e + 1) ns := bigint.AddSmall(base, trit) if ns > size { size = ns } } if !bigint.IsNull(base) { if bigint.MustCmp(halfThree, base) <= 0 { // base >= HALF_3 // just do base - HALF_3 bigint.MustSub(base, halfThree) } else { // we don'trits have a wrapping sub. // so let's use some bit magic to achieve it tmp := make([]uint32, IntLength) copy(tmp, halfThree) bigint.MustSub(tmp, base) bigint.Not(tmp) bigint.AddSmall(tmp, 1) copy(base, tmp) } } return bigint.Reverse(b), nil }
[ "func", "KerlTritsToBytes", "(", "trits", "Trits", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "!", "CanBeHash", "(", "trits", ")", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "ErrInvalidTritsLength", ",", "\"", "\"", ",", "...
// KerlTritsToBytes is only defined for hashes, i.e. slices of trits of length 243. It returns 48 bytes.
[ "KerlTritsToBytes", "is", "only", "defined", "for", "hashes", "i", ".", "e", ".", "slices", "of", "trits", "of", "length", "243", ".", "It", "returns", "48", "bytes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/converter.go#L32-L107
248
iotaledger/iota.go
kerl/converter.go
KerlBytesToTrits
func KerlBytesToTrits(b []byte) (Trits, error) { if len(b) != HashBytesSize { return nil, errors.Wrapf(ErrInvalidBytesLength, "must be %d in size", HashBytesSize) } rb := make([]byte, len(b)) copy(rb, b) bigint.Reverse(rb) t := Trits(make([]int8, HashTrinarySize)) t[HashTrinarySize-1] = 0 base := (*(*[]uint32)(unsafe.Pointer(&rb)))[0:IntLength] // 12 * 32 bits = 384 bits if bigint.IsNull(base) { return t, nil } var flipTrits bool // Check if the MSB is 0, i.e. we have a positive number msbM := (unsafe.Sizeof(base[IntLength-1]) * 8) - 1 switch { case base[IntLength-1]>>msbM == 0: bigint.MustAdd(base, halfThree) default: bigint.Not(base) if bigint.MustCmp(base, halfThree) == 1 { bigint.MustSub(base, halfThree) flipTrits = true } else { bigint.AddSmall(base, 1) tmp := make([]uint32, IntLength) copy(tmp, halfThree) bigint.MustSub(tmp, base) copy(base, tmp) } } var rem uint64 for i := range t[0 : HashTrinarySize-1] { rem = 0 for j := IntLength - 1; j >= 0; j-- { lhs := (rem << 32) | uint64(base[j]) rhs := uint64(TrinaryRadix) q := uint32(lhs / rhs) r := uint32(lhs % rhs) base[j] = q rem = uint64(r) } t[i] = int8(rem) - 1 } if flipTrits { for i := range t { t[i] = -t[i] } } return t, nil }
go
func KerlBytesToTrits(b []byte) (Trits, error) { if len(b) != HashBytesSize { return nil, errors.Wrapf(ErrInvalidBytesLength, "must be %d in size", HashBytesSize) } rb := make([]byte, len(b)) copy(rb, b) bigint.Reverse(rb) t := Trits(make([]int8, HashTrinarySize)) t[HashTrinarySize-1] = 0 base := (*(*[]uint32)(unsafe.Pointer(&rb)))[0:IntLength] // 12 * 32 bits = 384 bits if bigint.IsNull(base) { return t, nil } var flipTrits bool // Check if the MSB is 0, i.e. we have a positive number msbM := (unsafe.Sizeof(base[IntLength-1]) * 8) - 1 switch { case base[IntLength-1]>>msbM == 0: bigint.MustAdd(base, halfThree) default: bigint.Not(base) if bigint.MustCmp(base, halfThree) == 1 { bigint.MustSub(base, halfThree) flipTrits = true } else { bigint.AddSmall(base, 1) tmp := make([]uint32, IntLength) copy(tmp, halfThree) bigint.MustSub(tmp, base) copy(base, tmp) } } var rem uint64 for i := range t[0 : HashTrinarySize-1] { rem = 0 for j := IntLength - 1; j >= 0; j-- { lhs := (rem << 32) | uint64(base[j]) rhs := uint64(TrinaryRadix) q := uint32(lhs / rhs) r := uint32(lhs % rhs) base[j] = q rem = uint64(r) } t[i] = int8(rem) - 1 } if flipTrits { for i := range t { t[i] = -t[i] } } return t, nil }
[ "func", "KerlBytesToTrits", "(", "b", "[", "]", "byte", ")", "(", "Trits", ",", "error", ")", "{", "if", "len", "(", "b", ")", "!=", "HashBytesSize", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "ErrInvalidBytesLength", ",", "\"", "\"", ",...
// KerlBytesToTrits converts binary to trinary
[ "KerlBytesToTrits", "converts", "binary", "to", "trinary" ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/converter.go#L110-L171
249
iotaledger/iota.go
account/builder/builder.go
Build
func (b *Builder) Build(plugins ...account.Plugin) (account.Account, error) { if b.settings.AddrGen == nil { b.settings.AddrGen = account.DefaultAddrGen(b.settings.SeedProv, true) } if b.settings.PrepareTransfers == nil { b.settings.PrepareTransfers = account.DefaultPrepareTransfers(b.settings.API, b.settings.SeedProv) } for _, p := range plugins { b.settings.Plugins[p.Name()] = p } settsCopy := *b.settings return account.NewAccount(&settsCopy) }
go
func (b *Builder) Build(plugins ...account.Plugin) (account.Account, error) { if b.settings.AddrGen == nil { b.settings.AddrGen = account.DefaultAddrGen(b.settings.SeedProv, true) } if b.settings.PrepareTransfers == nil { b.settings.PrepareTransfers = account.DefaultPrepareTransfers(b.settings.API, b.settings.SeedProv) } for _, p := range plugins { b.settings.Plugins[p.Name()] = p } settsCopy := *b.settings return account.NewAccount(&settsCopy) }
[ "func", "(", "b", "*", "Builder", ")", "Build", "(", "plugins", "...", "account", ".", "Plugin", ")", "(", "account", ".", "Account", ",", "error", ")", "{", "if", "b", ".", "settings", ".", "AddrGen", "==", "nil", "{", "b", ".", "settings", ".", ...
// Build adds the given plugins and creates the account.
[ "Build", "adds", "the", "given", "plugins", "and", "creates", "the", "account", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L30-L42
250
iotaledger/iota.go
account/builder/builder.go
WithAPI
func (b *Builder) WithAPI(api *api.API) *Builder { b.settings.API = api return b }
go
func (b *Builder) WithAPI(api *api.API) *Builder { b.settings.API = api return b }
[ "func", "(", "b", "*", "Builder", ")", "WithAPI", "(", "api", "*", "api", ".", "API", ")", "*", "Builder", "{", "b", ".", "settings", ".", "API", "=", "api", "\n", "return", "b", "\n", "}" ]
// API sets the underlying API to use.
[ "API", "sets", "the", "underlying", "API", "to", "use", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L50-L53
251
iotaledger/iota.go
account/builder/builder.go
WithStore
func (b *Builder) WithStore(store store.Store) *Builder { b.settings.Store = store return b }
go
func (b *Builder) WithStore(store store.Store) *Builder { b.settings.Store = store return b }
[ "func", "(", "b", "*", "Builder", ")", "WithStore", "(", "store", "store", ".", "Store", ")", "*", "Builder", "{", "b", ".", "settings", ".", "Store", "=", "store", "\n", "return", "b", "\n", "}" ]
// Store sets the underlying store to use.
[ "Store", "sets", "the", "underlying", "store", "to", "use", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L56-L59
252
iotaledger/iota.go
account/builder/builder.go
WithSeedProvider
func (b *Builder) WithSeedProvider(seedProv account.SeedProvider) *Builder { b.settings.SeedProv = seedProv return b }
go
func (b *Builder) WithSeedProvider(seedProv account.SeedProvider) *Builder { b.settings.SeedProv = seedProv return b }
[ "func", "(", "b", "*", "Builder", ")", "WithSeedProvider", "(", "seedProv", "account", ".", "SeedProvider", ")", "*", "Builder", "{", "b", ".", "settings", ".", "SeedProv", "=", "seedProv", "\n", "return", "b", "\n", "}" ]
// SeedProvider sets the underlying SeedProvider to use.
[ "SeedProvider", "sets", "the", "underlying", "SeedProvider", "to", "use", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L62-L65
253
iotaledger/iota.go
account/builder/builder.go
WithAddrGenFunc
func (b *Builder) WithAddrGenFunc(f account.AddrGenFunc) *Builder { b.settings.AddrGen = f return b }
go
func (b *Builder) WithAddrGenFunc(f account.AddrGenFunc) *Builder { b.settings.AddrGen = f return b }
[ "func", "(", "b", "*", "Builder", ")", "WithAddrGenFunc", "(", "f", "account", ".", "AddrGenFunc", ")", "*", "Builder", "{", "b", ".", "settings", ".", "AddrGen", "=", "f", "\n", "return", "b", "\n", "}" ]
// WithAddrGenFunc sets the address generation function to use.
[ "WithAddrGenFunc", "sets", "the", "address", "generation", "function", "to", "use", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L68-L71
254
iotaledger/iota.go
account/builder/builder.go
WithPrepareTransfersFunc
func (b *Builder) WithPrepareTransfersFunc(f account.PrepareTransfersFunc) *Builder { b.settings.PrepareTransfers = f return b }
go
func (b *Builder) WithPrepareTransfersFunc(f account.PrepareTransfersFunc) *Builder { b.settings.PrepareTransfers = f return b }
[ "func", "(", "b", "*", "Builder", ")", "WithPrepareTransfersFunc", "(", "f", "account", ".", "PrepareTransfersFunc", ")", "*", "Builder", "{", "b", ".", "settings", ".", "PrepareTransfers", "=", "f", "\n", "return", "b", "\n", "}" ]
// WithPrepareTransfersFunc sets the prepare transfers function to use.
[ "WithPrepareTransfersFunc", "sets", "the", "prepare", "transfers", "function", "to", "use", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L74-L77
255
iotaledger/iota.go
account/builder/builder.go
WithSeed
func (b *Builder) WithSeed(seed Trytes) *Builder { b.settings.SeedProv = account.NewInMemorySeedProvider(seed) return b }
go
func (b *Builder) WithSeed(seed Trytes) *Builder { b.settings.SeedProv = account.NewInMemorySeedProvider(seed) return b }
[ "func", "(", "b", "*", "Builder", ")", "WithSeed", "(", "seed", "Trytes", ")", "*", "Builder", "{", "b", ".", "settings", ".", "SeedProv", "=", "account", ".", "NewInMemorySeedProvider", "(", "seed", ")", "\n", "return", "b", "\n", "}" ]
// Seed sets the underlying seed to use.
[ "Seed", "sets", "the", "underlying", "seed", "to", "use", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L80-L83
256
iotaledger/iota.go
account/builder/builder.go
WithMWM
func (b *Builder) WithMWM(mwm uint64) *Builder { b.settings.MWM = mwm return b }
go
func (b *Builder) WithMWM(mwm uint64) *Builder { b.settings.MWM = mwm return b }
[ "func", "(", "b", "*", "Builder", ")", "WithMWM", "(", "mwm", "uint64", ")", "*", "Builder", "{", "b", ".", "settings", ".", "MWM", "=", "mwm", "\n", "return", "b", "\n", "}" ]
// MWM sets the minimum weight magnitude used to send transactions.
[ "MWM", "sets", "the", "minimum", "weight", "magnitude", "used", "to", "send", "transactions", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L86-L89
257
iotaledger/iota.go
account/builder/builder.go
WithDepth
func (b *Builder) WithDepth(depth uint64) *Builder { b.settings.Depth = depth return b }
go
func (b *Builder) WithDepth(depth uint64) *Builder { b.settings.Depth = depth return b }
[ "func", "(", "b", "*", "Builder", ")", "WithDepth", "(", "depth", "uint64", ")", "*", "Builder", "{", "b", ".", "settings", ".", "Depth", "=", "depth", "\n", "return", "b", "\n", "}" ]
// Depth sets the depth used when searching for transactions to approve.
[ "Depth", "sets", "the", "depth", "used", "when", "searching", "for", "transactions", "to", "approve", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L92-L95
258
iotaledger/iota.go
account/builder/builder.go
WithSecurityLevel
func (b *Builder) WithSecurityLevel(level consts.SecurityLevel) *Builder { b.settings.SecurityLevel = level return b }
go
func (b *Builder) WithSecurityLevel(level consts.SecurityLevel) *Builder { b.settings.SecurityLevel = level return b }
[ "func", "(", "b", "*", "Builder", ")", "WithSecurityLevel", "(", "level", "consts", ".", "SecurityLevel", ")", "*", "Builder", "{", "b", ".", "settings", ".", "SecurityLevel", "=", "level", "\n", "return", "b", "\n", "}" ]
// The overall security level used by the account.
[ "The", "overall", "security", "level", "used", "by", "the", "account", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L98-L101
259
iotaledger/iota.go
account/builder/builder.go
WithTimeSource
func (b *Builder) WithTimeSource(timesource timesrc.TimeSource) *Builder { b.settings.TimeSource = timesource return b }
go
func (b *Builder) WithTimeSource(timesource timesrc.TimeSource) *Builder { b.settings.TimeSource = timesource return b }
[ "func", "(", "b", "*", "Builder", ")", "WithTimeSource", "(", "timesource", "timesrc", ".", "TimeSource", ")", "*", "Builder", "{", "b", ".", "settings", ".", "TimeSource", "=", "timesource", "\n", "return", "b", "\n", "}" ]
// TimeSource sets the TimeSource to use to get the current time.
[ "TimeSource", "sets", "the", "TimeSource", "to", "use", "to", "get", "the", "current", "time", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L104-L107
260
iotaledger/iota.go
account/builder/builder.go
WithInputSelectionStrategy
func (b *Builder) WithInputSelectionStrategy(strat account.InputSelectionFunc) *Builder { b.settings.InputSelectionStrat = strat return b }
go
func (b *Builder) WithInputSelectionStrategy(strat account.InputSelectionFunc) *Builder { b.settings.InputSelectionStrat = strat return b }
[ "func", "(", "b", "*", "Builder", ")", "WithInputSelectionStrategy", "(", "strat", "account", ".", "InputSelectionFunc", ")", "*", "Builder", "{", "b", ".", "settings", ".", "InputSelectionStrat", "=", "strat", "\n", "return", "b", "\n", "}" ]
// InputSelectionFunc sets the strategy to determine inputs and usable balance.
[ "InputSelectionFunc", "sets", "the", "strategy", "to", "determine", "inputs", "and", "usable", "balance", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L110-L113
261
iotaledger/iota.go
account/builder/builder.go
WithEvents
func (b *Builder) WithEvents(em event.EventMachine) *Builder { b.settings.EventMachine = em return b }
go
func (b *Builder) WithEvents(em event.EventMachine) *Builder { b.settings.EventMachine = em return b }
[ "func", "(", "b", "*", "Builder", ")", "WithEvents", "(", "em", "event", ".", "EventMachine", ")", "*", "Builder", "{", "b", ".", "settings", ".", "EventMachine", "=", "em", "\n", "return", "b", "\n", "}" ]
// WithEvents instructs the account to emit events using the given EventMachine.
[ "WithEvents", "instructs", "the", "account", "to", "emit", "events", "using", "the", "given", "EventMachine", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/builder/builder.go#L136-L139
262
iotaledger/iota.go
api/quorum.go
NewQuorumHTTPClient
func NewQuorumHTTPClient(settings interface{}) (Provider, error) { client := &quorumhttpclient{} if err := client.SetSettings(settings); err != nil { return nil, err } return client, nil }
go
func NewQuorumHTTPClient(settings interface{}) (Provider, error) { client := &quorumhttpclient{} if err := client.SetSettings(settings); err != nil { return nil, err } return client, nil }
[ "func", "NewQuorumHTTPClient", "(", "settings", "interface", "{", "}", ")", "(", "Provider", ",", "error", ")", "{", "client", ":=", "&", "quorumhttpclient", "{", "}", "\n", "if", "err", ":=", "client", ".", "SetSettings", "(", "settings", ")", ";", "err...
// NewQuorumHTTPClient creates a new quorum based Http Provider.
[ "NewQuorumHTTPClient", "creates", "a", "new", "quorum", "based", "Http", "Provider", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L46-L52
263
iotaledger/iota.go
api/quorum.go
extractSubTangleMilestoneHash
func extractSubTangleMilestoneHash(data []byte) (string, error) { firstColonIndex := bytes.Index(data, colonSep[:]) if firstColonIndex == -1 { return "", errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find hash") } leadingQuoteIndex := bytes.Index(data[firstColonIndex+1:], quoteSep[:]) if leadingQuoteIndex == -1 { return "", errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find leading quote in hash search") } leadingQuoteIndex = firstColonIndex + 1 + leadingQuoteIndex endingQuoteIndex := bytes.Index(data[leadingQuoteIndex+1:], quoteSep[:]) if endingQuoteIndex == -1 { return "", errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find ending quote in hash search") } endingQuoteIndex = leadingQuoteIndex + 1 + endingQuoteIndex return string(data[leadingQuoteIndex+1 : endingQuoteIndex]), nil }
go
func extractSubTangleMilestoneHash(data []byte) (string, error) { firstColonIndex := bytes.Index(data, colonSep[:]) if firstColonIndex == -1 { return "", errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find hash") } leadingQuoteIndex := bytes.Index(data[firstColonIndex+1:], quoteSep[:]) if leadingQuoteIndex == -1 { return "", errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find leading quote in hash search") } leadingQuoteIndex = firstColonIndex + 1 + leadingQuoteIndex endingQuoteIndex := bytes.Index(data[leadingQuoteIndex+1:], quoteSep[:]) if endingQuoteIndex == -1 { return "", errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find ending quote in hash search") } endingQuoteIndex = leadingQuoteIndex + 1 + endingQuoteIndex return string(data[leadingQuoteIndex+1 : endingQuoteIndex]), nil }
[ "func", "extractSubTangleMilestoneHash", "(", "data", "[", "]", "byte", ")", "(", "string", ",", "error", ")", "{", "firstColonIndex", ":=", "bytes", ".", "Index", "(", "data", ",", "colonSep", "[", ":", "]", ")", "\n", "if", "firstColonIndex", "==", "-"...
// extracts the latest solid subtangle milestone hash of a reduced getNodeInfo response
[ "extracts", "the", "latest", "solid", "subtangle", "milestone", "hash", "of", "a", "reduced", "getNodeInfo", "response" ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L254-L270
264
iotaledger/iota.go
api/quorum.go
extractSubTangleMilestoneIndex
func extractSubTangleMilestoneIndex(data []byte) (uint64, error) { lastColonIndex := bytes.LastIndex(data, colonSep[:]) if lastColonIndex == -1 { return 0, errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find index") } index := data[lastColonIndex+1 : len(data)-1] return strconv.ParseUint(string(index), 10, 64) }
go
func extractSubTangleMilestoneIndex(data []byte) (uint64, error) { lastColonIndex := bytes.LastIndex(data, colonSep[:]) if lastColonIndex == -1 { return 0, errors.Wrap(ErrNoLatestSolidSubtangleInfo, "unable to find index") } index := data[lastColonIndex+1 : len(data)-1] return strconv.ParseUint(string(index), 10, 64) }
[ "func", "extractSubTangleMilestoneIndex", "(", "data", "[", "]", "byte", ")", "(", "uint64", ",", "error", ")", "{", "lastColonIndex", ":=", "bytes", ".", "LastIndex", "(", "data", ",", "colonSep", "[", ":", "]", ")", "\n", "if", "lastColonIndex", "==", ...
// extracts the latest solid subtangle milestone index of a reduced getNodeInfo response
[ "extracts", "the", "latest", "solid", "subtangle", "milestone", "index", "of", "a", "reduced", "getNodeInfo", "response" ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L273-L280
265
iotaledger/iota.go
api/quorum.go
injectDefault
func (hc *quorumhttpclient) injectDefault(cmd interface{}, out interface{}) bool { // use defaults for non quorum results if hc.settings.Defaults == nil { return false } switch x := cmd.(type) { case *WereAddressesSpentFromCommand: if hc.settings.Defaults.WereAddressesSpentFrom != nil { states := make([]bool, len(x.Addresses)) for i := range states { states[i] = *hc.settings.Defaults.WereAddressesSpentFrom } out.(*WereAddressesSpentFromResponse).States = states return true } case *GetInclusionStatesCommand: if hc.settings.Defaults.GetInclusionStates != nil { states := make([]bool, len(x.Transactions)) for i := range states { states[i] = *hc.settings.Defaults.GetInclusionStates } out.(*GetInclusionStatesResponse).States = states return true } case *GetBalancesCommand: if hc.settings.Defaults.GetBalances != nil { balances := make([]string, len(x.Addresses)) for i := range balances { balances[i] = strconv.Itoa(int(*hc.settings.Defaults.GetBalances)) } out.(*GetBalancesResponse).Balances = balances return true } } return false }
go
func (hc *quorumhttpclient) injectDefault(cmd interface{}, out interface{}) bool { // use defaults for non quorum results if hc.settings.Defaults == nil { return false } switch x := cmd.(type) { case *WereAddressesSpentFromCommand: if hc.settings.Defaults.WereAddressesSpentFrom != nil { states := make([]bool, len(x.Addresses)) for i := range states { states[i] = *hc.settings.Defaults.WereAddressesSpentFrom } out.(*WereAddressesSpentFromResponse).States = states return true } case *GetInclusionStatesCommand: if hc.settings.Defaults.GetInclusionStates != nil { states := make([]bool, len(x.Transactions)) for i := range states { states[i] = *hc.settings.Defaults.GetInclusionStates } out.(*GetInclusionStatesResponse).States = states return true } case *GetBalancesCommand: if hc.settings.Defaults.GetBalances != nil { balances := make([]string, len(x.Addresses)) for i := range balances { balances[i] = strconv.Itoa(int(*hc.settings.Defaults.GetBalances)) } out.(*GetBalancesResponse).Balances = balances return true } } return false }
[ "func", "(", "hc", "*", "quorumhttpclient", ")", "injectDefault", "(", "cmd", "interface", "{", "}", ",", "out", "interface", "{", "}", ")", "bool", "{", "// use defaults for non quorum results", "if", "hc", ".", "settings", ".", "Defaults", "==", "nil", "{"...
// injects the optional default set data into the response
[ "injects", "the", "optional", "default", "set", "data", "into", "the", "response" ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L283-L318
266
iotaledger/iota.go
api/quorum.go
sliceOutDurationField
func sliceOutDurationField(data []byte) []byte { indexOfDurationField := bytes.LastIndex(data, durationKey[:]) if indexOfDurationField == -1 { return data } curlyBraceIndex := bytes.Index(data[indexOfDurationField:], []byte{closingCurlyBraceAscii}) return append(data[:indexOfDurationField-1], data[indexOfDurationField+curlyBraceIndex:]...) }
go
func sliceOutDurationField(data []byte) []byte { indexOfDurationField := bytes.LastIndex(data, durationKey[:]) if indexOfDurationField == -1 { return data } curlyBraceIndex := bytes.Index(data[indexOfDurationField:], []byte{closingCurlyBraceAscii}) return append(data[:indexOfDurationField-1], data[indexOfDurationField+curlyBraceIndex:]...) }
[ "func", "sliceOutDurationField", "(", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "indexOfDurationField", ":=", "bytes", ".", "LastIndex", "(", "data", ",", "durationKey", "[", ":", "]", ")", "\n", "if", "indexOfDurationField", "==", "-", "1", ...
// slices out a byte slice without the duration field. // querying multiple nodes will always lead to different durations // and hence must be removed when hasing the entire response.
[ "slices", "out", "a", "byte", "slice", "without", "the", "duration", "field", ".", "querying", "multiple", "nodes", "will", "always", "lead", "to", "different", "durations", "and", "hence", "must", "be", "removed", "when", "hasing", "the", "entire", "response"...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L323-L330
267
iotaledger/iota.go
api/quorum.go
sliceOutInfoField
func sliceOutInfoField(data []byte) []byte { infoIndex := bytes.LastIndex(data, infoKey[:]) if infoIndex == -1 { return data } // if the info field is empty, don't create a copy if i := bytes.LastIndex(data, emptyInfoKey[:]); i != -1 { return data } // create a copy as we want to keep the schematics // of the original slice c := make([]byte, len(data)) copy(c, data) return append(c[:infoIndex-1], closingCurlyBraceAscii) }
go
func sliceOutInfoField(data []byte) []byte { infoIndex := bytes.LastIndex(data, infoKey[:]) if infoIndex == -1 { return data } // if the info field is empty, don't create a copy if i := bytes.LastIndex(data, emptyInfoKey[:]); i != -1 { return data } // create a copy as we want to keep the schematics // of the original slice c := make([]byte, len(data)) copy(c, data) return append(c[:infoIndex-1], closingCurlyBraceAscii) }
[ "func", "sliceOutInfoField", "(", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "infoIndex", ":=", "bytes", ".", "LastIndex", "(", "data", ",", "infoKey", "[", ":", "]", ")", "\n", "if", "infoIndex", "==", "-", "1", "{", "return", "data", "...
// slices out a byte slice without the info field of check consistency calls. // querying multiple nodes will lead to different info messages when the state // is false of the responses.
[ "slices", "out", "a", "byte", "slice", "without", "the", "info", "field", "of", "check", "consistency", "calls", ".", "querying", "multiple", "nodes", "will", "lead", "to", "different", "info", "messages", "when", "the", "state", "is", "false", "of", "the", ...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L335-L349
268
iotaledger/iota.go
api/quorum.go
sliceOutMilestoneIndexField
func sliceOutMilestoneIndexField(data []byte) []byte { indexOfMilestoneIndex := bytes.LastIndex(data, milestoneIndexKey[:]) if indexOfMilestoneIndex == -1 { return data } c := make([]byte, len(data)) copy(c, data) return append(c[:indexOfMilestoneIndex-2], closingCurlyBraceAscii) }
go
func sliceOutMilestoneIndexField(data []byte) []byte { indexOfMilestoneIndex := bytes.LastIndex(data, milestoneIndexKey[:]) if indexOfMilestoneIndex == -1 { return data } c := make([]byte, len(data)) copy(c, data) return append(c[:indexOfMilestoneIndex-2], closingCurlyBraceAscii) }
[ "func", "sliceOutMilestoneIndexField", "(", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "indexOfMilestoneIndex", ":=", "bytes", ".", "LastIndex", "(", "data", ",", "milestoneIndexKey", "[", ":", "]", ")", "\n", "if", "indexOfMilestoneIndex", "==", ...
// slices out a byte slice without the milestone index field for get balances calls. // even when querying multiple nodes with the same reference, the IRI node's latest snapshot index // is returned in the response, which must thereby be filtered out.
[ "slices", "out", "a", "byte", "slice", "without", "the", "milestone", "index", "field", "for", "get", "balances", "calls", ".", "even", "when", "querying", "multiple", "nodes", "with", "the", "same", "reference", "the", "IRI", "node", "s", "latest", "snapsho...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/quorum.go#L354-L362
269
iotaledger/iota.go
kerl/bigint/bigint.go
MustAdd
func MustAdd(b []uint32, rh []uint32) { if len(b) != len(rh) { panic(ErrUnequallySizedSlices) } carry := false for i := range b { v, c := FullAdd(b[i], rh[i], carry) b[i] = uint32(v) carry = c } }
go
func MustAdd(b []uint32, rh []uint32) { if len(b) != len(rh) { panic(ErrUnequallySizedSlices) } carry := false for i := range b { v, c := FullAdd(b[i], rh[i], carry) b[i] = uint32(v) carry = c } }
[ "func", "MustAdd", "(", "b", "[", "]", "uint32", ",", "rh", "[", "]", "uint32", ")", "{", "if", "len", "(", "b", ")", "!=", "len", "(", "rh", ")", "{", "panic", "(", "ErrUnequallySizedSlices", ")", "\n", "}", "\n\n", "carry", ":=", "false", "\n\n...
// MustAdd adds the given big ints together.
[ "MustAdd", "adds", "the", "given", "big", "ints", "together", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L16-L28
270
iotaledger/iota.go
kerl/bigint/bigint.go
MustSub
func MustSub(b []uint32, rh []uint32) { if len(b) != len(rh) { panic(ErrUnequallySizedSlices) } noborrow := true for i := range b { v, c := FullAdd(b[i], ^rh[i], noborrow) b[i] = uint32(v) noborrow = c } if !noborrow { panic(ErrSubtractionWithLeftovers) } }
go
func MustSub(b []uint32, rh []uint32) { if len(b) != len(rh) { panic(ErrUnequallySizedSlices) } noborrow := true for i := range b { v, c := FullAdd(b[i], ^rh[i], noborrow) b[i] = uint32(v) noborrow = c } if !noborrow { panic(ErrSubtractionWithLeftovers) } }
[ "func", "MustSub", "(", "b", "[", "]", "uint32", ",", "rh", "[", "]", "uint32", ")", "{", "if", "len", "(", "b", ")", "!=", "len", "(", "rh", ")", "{", "panic", "(", "ErrUnequallySizedSlices", ")", "\n", "}", "\n\n", "noborrow", ":=", "true", "\n...
// MustSub subtracts rh from b.
[ "MustSub", "subtracts", "rh", "from", "b", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L31-L47
271
iotaledger/iota.go
kerl/bigint/bigint.go
IsNull
func IsNull(b []uint32) bool { for i := range b { if b[i] != 0 { return false } } return true }
go
func IsNull(b []uint32) bool { for i := range b { if b[i] != 0 { return false } } return true }
[ "func", "IsNull", "(", "b", "[", "]", "uint32", ")", "bool", "{", "for", "i", ":=", "range", "b", "{", "if", "b", "[", "i", "]", "!=", "0", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// IsNull checks whether the given big int value is null.
[ "IsNull", "checks", "whether", "the", "given", "big", "int", "value", "is", "null", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L57-L64
272
iotaledger/iota.go
kerl/bigint/bigint.go
MustCmp
func MustCmp(lh, rh []uint32) int { if len(lh) != len(rh) { panic(ErrUnequallySizedSlices) } // put LSB first rlh := make([]uint32, len(lh)) copy(rlh, lh) ReverseU(rlh) rrh := make([]uint32, len(rh)) copy(rrh, rh) ReverseU(rrh) for i := range rlh { switch { case rlh[i] < rrh[i]: return -1 case rlh[i] > rrh[i]: return 1 } } return 0 }
go
func MustCmp(lh, rh []uint32) int { if len(lh) != len(rh) { panic(ErrUnequallySizedSlices) } // put LSB first rlh := make([]uint32, len(lh)) copy(rlh, lh) ReverseU(rlh) rrh := make([]uint32, len(rh)) copy(rrh, rh) ReverseU(rrh) for i := range rlh { switch { case rlh[i] < rrh[i]: return -1 case rlh[i] > rrh[i]: return 1 } } return 0 }
[ "func", "MustCmp", "(", "lh", ",", "rh", "[", "]", "uint32", ")", "int", "{", "if", "len", "(", "lh", ")", "!=", "len", "(", "rh", ")", "{", "panic", "(", "ErrUnequallySizedSlices", ")", "\n", "}", "\n\n", "// put LSB first", "rlh", ":=", "make", "...
// MustCmp compares the given big ints with each other.
[ "MustCmp", "compares", "the", "given", "big", "ints", "with", "each", "other", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L67-L90
273
iotaledger/iota.go
kerl/bigint/bigint.go
AddSmall
func AddSmall(b []uint32, a uint32) int { v, carry := FullAdd(b[0], a, false) b[0] = uint32(v) // uint is at least 32 bit var i int for i = 1; carry; i++ { vi, c := FullAdd(b[i], 0, carry) b[i] = uint32(vi) carry = c } return i }
go
func AddSmall(b []uint32, a uint32) int { v, carry := FullAdd(b[0], a, false) b[0] = uint32(v) // uint is at least 32 bit var i int for i = 1; carry; i++ { vi, c := FullAdd(b[i], 0, carry) b[i] = uint32(vi) carry = c } return i }
[ "func", "AddSmall", "(", "b", "[", "]", "uint32", ",", "a", "uint32", ")", "int", "{", "v", ",", "carry", ":=", "FullAdd", "(", "b", "[", "0", "]", ",", "a", ",", "false", ")", "\n", "b", "[", "0", "]", "=", "uint32", "(", "v", ")", "// uin...
// AddSmall adds a small number to a big int and returns the index of the last carry over.
[ "AddSmall", "adds", "a", "small", "number", "to", "a", "big", "int", "and", "returns", "the", "index", "of", "the", "last", "carry", "over", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L93-L105
274
iotaledger/iota.go
kerl/bigint/bigint.go
FullAdd
func FullAdd(lh, rh uint32, carry bool) (uint, bool) { v, c1 := AddWithOverflow(lh, rh) var c2 bool if carry { v, c2 = AddWithOverflow(uint32(v), 1) } return v, c1 || c2 }
go
func FullAdd(lh, rh uint32, carry bool) (uint, bool) { v, c1 := AddWithOverflow(lh, rh) var c2 bool if carry { v, c2 = AddWithOverflow(uint32(v), 1) } return v, c1 || c2 }
[ "func", "FullAdd", "(", "lh", ",", "rh", "uint32", ",", "carry", "bool", ")", "(", "uint", ",", "bool", ")", "{", "v", ",", "c1", ":=", "AddWithOverflow", "(", "lh", ",", "rh", ")", "\n", "var", "c2", "bool", "\n", "if", "carry", "{", "v", ",",...
// FullAdd adds left and right together and whether it overflowed.
[ "FullAdd", "adds", "left", "and", "right", "together", "and", "whether", "it", "overflowed", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L108-L116
275
iotaledger/iota.go
kerl/bigint/bigint.go
AddWithOverflow
func AddWithOverflow(lh, rh uint32) (uint, bool) { return uint(lh + rh), lh > math.MaxUint32-rh }
go
func AddWithOverflow(lh, rh uint32) (uint, bool) { return uint(lh + rh), lh > math.MaxUint32-rh }
[ "func", "AddWithOverflow", "(", "lh", ",", "rh", "uint32", ")", "(", "uint", ",", "bool", ")", "{", "return", "uint", "(", "lh", "+", "rh", ")", ",", "lh", ">", "math", ".", "MaxUint32", "-", "rh", "\n", "}" ]
// AddWithOverflow returns left hand + right hand and whether it overflowed.
[ "AddWithOverflow", "returns", "left", "hand", "+", "right", "hand", "and", "whether", "it", "overflowed", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L119-L121
276
iotaledger/iota.go
kerl/bigint/bigint.go
Reverse
func Reverse(a []byte) []byte { for left, right := 0, len(a)-1; left < right; left, right = left+1, right-1 { a[left], a[right] = a[right], a[left] } return a }
go
func Reverse(a []byte) []byte { for left, right := 0, len(a)-1; left < right; left, right = left+1, right-1 { a[left], a[right] = a[right], a[left] } return a }
[ "func", "Reverse", "(", "a", "[", "]", "byte", ")", "[", "]", "byte", "{", "for", "left", ",", "right", ":=", "0", ",", "len", "(", "a", ")", "-", "1", ";", "left", "<", "right", ";", "left", ",", "right", "=", "left", "+", "1", ",", "right...
// Reverse reverses the given byte slice.
[ "Reverse", "reverses", "the", "given", "byte", "slice", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L124-L130
277
iotaledger/iota.go
kerl/bigint/bigint.go
ReverseU
func ReverseU(a []uint32) []uint32 { for left, right := 0, len(a)-1; left < right; left, right = left+1, right-1 { a[left], a[right] = a[right], a[left] } return a }
go
func ReverseU(a []uint32) []uint32 { for left, right := 0, len(a)-1; left < right; left, right = left+1, right-1 { a[left], a[right] = a[right], a[left] } return a }
[ "func", "ReverseU", "(", "a", "[", "]", "uint32", ")", "[", "]", "uint32", "{", "for", "left", ",", "right", ":=", "0", ",", "len", "(", "a", ")", "-", "1", ";", "left", "<", "right", ";", "left", ",", "right", "=", "left", "+", "1", ",", "...
// ReverseU reverses the given uint32 slice.
[ "ReverseU", "reverses", "the", "given", "uint32", "slice", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/bigint/bigint.go#L133-L139
278
iotaledger/iota.go
account/event/listener/channel_listener.go
NewChannelEventListener
func NewChannelEventListener(em event.EventMachine) *ChannelEventListener { return &ChannelEventListener{em: em, ids: []uint64{}} }
go
func NewChannelEventListener(em event.EventMachine) *ChannelEventListener { return &ChannelEventListener{em: em, ids: []uint64{}} }
[ "func", "NewChannelEventListener", "(", "em", "event", ".", "EventMachine", ")", "*", "ChannelEventListener", "{", "return", "&", "ChannelEventListener", "{", "em", ":", "em", ",", "ids", ":", "[", "]", "uint64", "{", "}", "}", "\n", "}" ]
// NewChannelEventListener creates a new ChannelEventListener using the given EventMachine.
[ "NewChannelEventListener", "creates", "a", "new", "ChannelEventListener", "using", "the", "given", "EventMachine", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L34-L36
279
iotaledger/iota.go
account/event/listener/channel_listener.go
Close
func (el *ChannelEventListener) Close() error { el.idsMu.Lock() defer el.idsMu.Unlock() for _, id := range el.ids { if err := el.em.UnregisterListener(id); err != nil { return err } } return nil }
go
func (el *ChannelEventListener) Close() error { el.idsMu.Lock() defer el.idsMu.Unlock() for _, id := range el.ids { if err := el.em.UnregisterListener(id); err != nil { return err } } return nil }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "Close", "(", ")", "error", "{", "el", ".", "idsMu", ".", "Lock", "(", ")", "\n", "defer", "el", ".", "idsMu", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "id", ":=", "range", "el", ".", ...
// Close frees up all underlying channels from the EventMachine.
[ "Close", "frees", "up", "all", "underlying", "channels", "from", "the", "EventMachine", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L39-L48
280
iotaledger/iota.go
account/event/listener/channel_listener.go
RegPromotions
func (el *ChannelEventListener) RegPromotions() *ChannelEventListener { el.Promoted = make(chan *promoter.PromotionReattachmentEvent) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.Promoted <- data.(*promoter.PromotionReattachmentEvent) }, promoter.EventPromotion)) return el }
go
func (el *ChannelEventListener) RegPromotions() *ChannelEventListener { el.Promoted = make(chan *promoter.PromotionReattachmentEvent) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.Promoted <- data.(*promoter.PromotionReattachmentEvent) }, promoter.EventPromotion)) return el }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "RegPromotions", "(", ")", "*", "ChannelEventListener", "{", "el", ".", "Promoted", "=", "make", "(", "chan", "*", "promoter", ".", "PromotionReattachmentEvent", ")", "\n", "el", ".", "ids", "=", "append",...
// RegPromotions registers this listener to listen for promotions.
[ "RegPromotions", "registers", "this", "listener", "to", "listen", "for", "promotions", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L51-L57
281
iotaledger/iota.go
account/event/listener/channel_listener.go
RegReattachments
func (el *ChannelEventListener) RegReattachments() *ChannelEventListener { el.Reattached = make(chan *promoter.PromotionReattachmentEvent) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.Reattached <- data.(*promoter.PromotionReattachmentEvent) }, promoter.EventReattachment)) return el }
go
func (el *ChannelEventListener) RegReattachments() *ChannelEventListener { el.Reattached = make(chan *promoter.PromotionReattachmentEvent) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.Reattached <- data.(*promoter.PromotionReattachmentEvent) }, promoter.EventReattachment)) return el }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "RegReattachments", "(", ")", "*", "ChannelEventListener", "{", "el", ".", "Reattached", "=", "make", "(", "chan", "*", "promoter", ".", "PromotionReattachmentEvent", ")", "\n", "el", ".", "ids", "=", "app...
// RegReattachments registers this listener to listen for reattachments.
[ "RegReattachments", "registers", "this", "listener", "to", "listen", "for", "reattachments", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L60-L66
282
iotaledger/iota.go
account/event/listener/channel_listener.go
RegSentTransfers
func (el *ChannelEventListener) RegSentTransfers() *ChannelEventListener { el.SentTransfer = make(chan bundle.Bundle) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.SentTransfer <- data.(bundle.Bundle) }, event.EventSentTransfer)) return el }
go
func (el *ChannelEventListener) RegSentTransfers() *ChannelEventListener { el.SentTransfer = make(chan bundle.Bundle) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.SentTransfer <- data.(bundle.Bundle) }, event.EventSentTransfer)) return el }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "RegSentTransfers", "(", ")", "*", "ChannelEventListener", "{", "el", ".", "SentTransfer", "=", "make", "(", "chan", "bundle", ".", "Bundle", ")", "\n", "el", ".", "ids", "=", "append", "(", "el", ".",...
// RegSentTransfers registers this listener to listen for sent off transfers.
[ "RegSentTransfers", "registers", "this", "listener", "to", "listen", "for", "sent", "off", "transfers", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L69-L75
283
iotaledger/iota.go
account/event/listener/channel_listener.go
RegConfirmedTransfers
func (el *ChannelEventListener) RegConfirmedTransfers() *ChannelEventListener { el.TransferConfirmed = make(chan bundle.Bundle) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.TransferConfirmed <- data.(bundle.Bundle) }, poller.EventTransferConfirmed)) return el }
go
func (el *ChannelEventListener) RegConfirmedTransfers() *ChannelEventListener { el.TransferConfirmed = make(chan bundle.Bundle) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.TransferConfirmed <- data.(bundle.Bundle) }, poller.EventTransferConfirmed)) return el }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "RegConfirmedTransfers", "(", ")", "*", "ChannelEventListener", "{", "el", ".", "TransferConfirmed", "=", "make", "(", "chan", "bundle", ".", "Bundle", ")", "\n", "el", ".", "ids", "=", "append", "(", "e...
// RegConfirmedTransfers registers this listener to listen for sent off confirmed transfers.
[ "RegConfirmedTransfers", "registers", "this", "listener", "to", "listen", "for", "sent", "off", "confirmed", "transfers", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L78-L84
284
iotaledger/iota.go
account/event/listener/channel_listener.go
RegReceivingDeposits
func (el *ChannelEventListener) RegReceivingDeposits() *ChannelEventListener { el.ReceivingDeposit = make(chan bundle.Bundle) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.ReceivingDeposit <- data.(bundle.Bundle) }, poller.EventReceivingDeposit)) return el }
go
func (el *ChannelEventListener) RegReceivingDeposits() *ChannelEventListener { el.ReceivingDeposit = make(chan bundle.Bundle) el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) { el.ReceivingDeposit <- data.(bundle.Bundle) }, poller.EventReceivingDeposit)) return el }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "RegReceivingDeposits", "(", ")", "*", "ChannelEventListener", "{", "el", ".", "ReceivingDeposit", "=", "make", "(", "chan", "bundle", ".", "Bundle", ")", "\n", "el", ".", "ids", "=", "append", "(", "el"...
// RegReceivingDeposits registers this listener to listen for incoming deposits which are not yet confirmed.
[ "RegReceivingDeposits", "registers", "this", "listener", "to", "listen", "for", "incoming", "deposits", "which", "are", "not", "yet", "confirmed", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L87-L93
285
iotaledger/iota.go
account/event/listener/channel_listener.go
All
func (el *ChannelEventListener) All() *ChannelEventListener { return el. RegAccountShutdown(). RegPromotions(). RegReattachments(). RegSentTransfers(). RegConfirmedTransfers(). RegReceivedDeposits(). RegReceivingDeposits(). RegReceivedMessages(). RegInputSelection(). RegPreparingTransfer(). RegGettingTransactionsToApprove(). RegAttachingToTangle(). RegInternalErrors() }
go
func (el *ChannelEventListener) All() *ChannelEventListener { return el. RegAccountShutdown(). RegPromotions(). RegReattachments(). RegSentTransfers(). RegConfirmedTransfers(). RegReceivedDeposits(). RegReceivingDeposits(). RegReceivedMessages(). RegInputSelection(). RegPreparingTransfer(). RegGettingTransactionsToApprove(). RegAttachingToTangle(). RegInternalErrors() }
[ "func", "(", "el", "*", "ChannelEventListener", ")", "All", "(", ")", "*", "ChannelEventListener", "{", "return", "el", ".", "RegAccountShutdown", "(", ")", ".", "RegPromotions", "(", ")", ".", "RegReattachments", "(", ")", ".", "RegSentTransfers", "(", ")",...
// All sets this listener up to listen to all account events.
[ "All", "sets", "this", "listener", "up", "to", "listen", "to", "all", "account", "events", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/channel_listener.go#L169-L184
286
iotaledger/iota.go
transaction/transaction.go
ParseTransaction
func ParseTransaction(trits Trits, noHash ...bool) (*Transaction, error) { var err error if len(trits) != TransactionTrinarySize { return nil, ErrInvalidTransaction } if err := ValidTrits(trits); err != nil { return nil, err } t := &Transaction{} t.SignatureMessageFragment = MustTritsToTrytes(trits[SignatureMessageFragmentTrinaryOffset:SignatureMessageFragmentTrinarySize]) t.Address, err = TritsToTrytes(trits[AddressTrinaryOffset : AddressTrinaryOffset+AddressTrinarySize]) if err != nil { return nil, err } t.Value = TritsToInt(trits[ValueOffsetTrinary : ValueOffsetTrinary+ValueSizeTrinary]) t.ObsoleteTag = MustTritsToTrytes(trits[ObsoleteTagTrinaryOffset : ObsoleteTagTrinaryOffset+ObsoleteTagTrinarySize]) t.Timestamp = uint64(TritsToInt(trits[TimestampTrinaryOffset : TimestampTrinaryOffset+TimestampTrinarySize])) t.CurrentIndex = uint64(TritsToInt(trits[CurrentIndexTrinaryOffset : CurrentIndexTrinaryOffset+CurrentIndexTrinarySize])) t.LastIndex = uint64(TritsToInt(trits[LastIndexTrinaryOffset : LastIndexTrinaryOffset+LastIndexTrinarySize])) if t.CurrentIndex > t.LastIndex { return nil, errors.Wrap(ErrInvalidIndex, "current index is bigger than last index") } t.Bundle = MustTritsToTrytes(trits[BundleTrinaryOffset : BundleTrinaryOffset+BundleTrinarySize]) t.TrunkTransaction = MustTritsToTrytes(trits[TrunkTransactionTrinaryOffset : TrunkTransactionTrinaryOffset+TrunkTransactionTrinarySize]) t.BranchTransaction = MustTritsToTrytes(trits[BranchTransactionTrinaryOffset : BranchTransactionTrinaryOffset+BranchTransactionTrinarySize]) t.Tag = MustTritsToTrytes(trits[TagTrinaryOffset : TagTrinaryOffset+TagTrinarySize]) t.AttachmentTimestamp = TritsToInt(trits[AttachmentTimestampTrinaryOffset : AttachmentTimestampTrinaryOffset+AttachmentTimestampTrinarySize]) t.AttachmentTimestampLowerBound = TritsToInt(trits[AttachmentTimestampLowerBoundTrinaryOffset : AttachmentTimestampLowerBoundTrinaryOffset+AttachmentTimestampLowerBoundTrinarySize]) t.AttachmentTimestampUpperBound = TritsToInt(trits[AttachmentTimestampUpperBoundTrinaryOffset : AttachmentTimestampUpperBoundTrinaryOffset+AttachmentTimestampUpperBoundTrinarySize]) t.Nonce = MustTritsToTrytes(trits[NonceTrinaryOffset : NonceTrinaryOffset+NonceTrinarySize]) if len(noHash) == 0 || noHash[0] == false { t.Hash = TransactionHash(t) } return t, nil }
go
func ParseTransaction(trits Trits, noHash ...bool) (*Transaction, error) { var err error if len(trits) != TransactionTrinarySize { return nil, ErrInvalidTransaction } if err := ValidTrits(trits); err != nil { return nil, err } t := &Transaction{} t.SignatureMessageFragment = MustTritsToTrytes(trits[SignatureMessageFragmentTrinaryOffset:SignatureMessageFragmentTrinarySize]) t.Address, err = TritsToTrytes(trits[AddressTrinaryOffset : AddressTrinaryOffset+AddressTrinarySize]) if err != nil { return nil, err } t.Value = TritsToInt(trits[ValueOffsetTrinary : ValueOffsetTrinary+ValueSizeTrinary]) t.ObsoleteTag = MustTritsToTrytes(trits[ObsoleteTagTrinaryOffset : ObsoleteTagTrinaryOffset+ObsoleteTagTrinarySize]) t.Timestamp = uint64(TritsToInt(trits[TimestampTrinaryOffset : TimestampTrinaryOffset+TimestampTrinarySize])) t.CurrentIndex = uint64(TritsToInt(trits[CurrentIndexTrinaryOffset : CurrentIndexTrinaryOffset+CurrentIndexTrinarySize])) t.LastIndex = uint64(TritsToInt(trits[LastIndexTrinaryOffset : LastIndexTrinaryOffset+LastIndexTrinarySize])) if t.CurrentIndex > t.LastIndex { return nil, errors.Wrap(ErrInvalidIndex, "current index is bigger than last index") } t.Bundle = MustTritsToTrytes(trits[BundleTrinaryOffset : BundleTrinaryOffset+BundleTrinarySize]) t.TrunkTransaction = MustTritsToTrytes(trits[TrunkTransactionTrinaryOffset : TrunkTransactionTrinaryOffset+TrunkTransactionTrinarySize]) t.BranchTransaction = MustTritsToTrytes(trits[BranchTransactionTrinaryOffset : BranchTransactionTrinaryOffset+BranchTransactionTrinarySize]) t.Tag = MustTritsToTrytes(trits[TagTrinaryOffset : TagTrinaryOffset+TagTrinarySize]) t.AttachmentTimestamp = TritsToInt(trits[AttachmentTimestampTrinaryOffset : AttachmentTimestampTrinaryOffset+AttachmentTimestampTrinarySize]) t.AttachmentTimestampLowerBound = TritsToInt(trits[AttachmentTimestampLowerBoundTrinaryOffset : AttachmentTimestampLowerBoundTrinaryOffset+AttachmentTimestampLowerBoundTrinarySize]) t.AttachmentTimestampUpperBound = TritsToInt(trits[AttachmentTimestampUpperBoundTrinaryOffset : AttachmentTimestampUpperBoundTrinaryOffset+AttachmentTimestampUpperBoundTrinarySize]) t.Nonce = MustTritsToTrytes(trits[NonceTrinaryOffset : NonceTrinaryOffset+NonceTrinarySize]) if len(noHash) == 0 || noHash[0] == false { t.Hash = TransactionHash(t) } return t, nil }
[ "func", "ParseTransaction", "(", "trits", "Trits", ",", "noHash", "...", "bool", ")", "(", "*", "Transaction", ",", "error", ")", "{", "var", "err", "error", "\n\n", "if", "len", "(", "trits", ")", "!=", "TransactionTrinarySize", "{", "return", "nil", ",...
// ParseTransaction parses the trits and returns a transaction object. // The trits slice must be TransactionTrinarySize in length. // If noHash is set to true, no transaction hash is calculated.
[ "ParseTransaction", "parses", "the", "trits", "and", "returns", "a", "transaction", "object", ".", "The", "trits", "slice", "must", "be", "TransactionTrinarySize", "in", "length", ".", "If", "noHash", "is", "set", "to", "true", "no", "transaction", "hash", "is...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L45-L83
287
iotaledger/iota.go
transaction/transaction.go
ValidTransactionTrytes
func ValidTransactionTrytes(trytes Trytes) error { // verifies length and trytes values if !guards.IsTrytesOfExactLength(trytes, TransactionTrytesSize) { return ErrInvalidTrytes } if trytes[2279:2295] != "9999999999999999" { return ErrInvalidTrytes } return nil }
go
func ValidTransactionTrytes(trytes Trytes) error { // verifies length and trytes values if !guards.IsTrytesOfExactLength(trytes, TransactionTrytesSize) { return ErrInvalidTrytes } if trytes[2279:2295] != "9999999999999999" { return ErrInvalidTrytes } return nil }
[ "func", "ValidTransactionTrytes", "(", "trytes", "Trytes", ")", "error", "{", "// verifies length and trytes values", "if", "!", "guards", ".", "IsTrytesOfExactLength", "(", "trytes", ",", "TransactionTrytesSize", ")", "{", "return", "ErrInvalidTrytes", "\n", "}", "\n...
// ValidTransactionTrytes checks whether the given trytes make up a valid transaction schematically.
[ "ValidTransactionTrytes", "checks", "whether", "the", "given", "trytes", "make", "up", "a", "valid", "transaction", "schematically", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L86-L97
288
iotaledger/iota.go
transaction/transaction.go
AsTransactionObject
func AsTransactionObject(trytes Trytes, hash ...Hash) (*Transaction, error) { var tx *Transaction var err error if err := ValidTransactionTrytes(trytes); err != nil { return nil, err } skipHashCalc := len(hash) > 0 if tx, err = ParseTransaction(MustTrytesToTrits(trytes), skipHashCalc); err != nil { return nil, err } if skipHashCalc { tx.Hash = hash[0] } return tx, nil }
go
func AsTransactionObject(trytes Trytes, hash ...Hash) (*Transaction, error) { var tx *Transaction var err error if err := ValidTransactionTrytes(trytes); err != nil { return nil, err } skipHashCalc := len(hash) > 0 if tx, err = ParseTransaction(MustTrytesToTrits(trytes), skipHashCalc); err != nil { return nil, err } if skipHashCalc { tx.Hash = hash[0] } return tx, nil }
[ "func", "AsTransactionObject", "(", "trytes", "Trytes", ",", "hash", "...", "Hash", ")", "(", "*", "Transaction", ",", "error", ")", "{", "var", "tx", "*", "Transaction", "\n", "var", "err", "error", "\n\n", "if", "err", ":=", "ValidTransactionTrytes", "("...
// AsTransactionObject makes a new transaction from the given trytes. // Optionally the computed transaction hash can be overwritten by supplying an own hash.
[ "AsTransactionObject", "makes", "a", "new", "transaction", "from", "the", "given", "trytes", ".", "Optionally", "the", "computed", "transaction", "hash", "can", "be", "overwritten", "by", "supplying", "an", "own", "hash", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L101-L119
289
iotaledger/iota.go
transaction/transaction.go
AsTransactionObjects
func AsTransactionObjects(rawTrytes []Trytes, hashes Hashes) (Transactions, error) { txs := make(Transactions, len(rawTrytes)) var tx *Transaction var err error for i := range rawTrytes { if hashes != nil && len(hashes) > 0 && len(hashes) > i { tx, err = AsTransactionObject(rawTrytes[i], hashes[i]) } else { tx, err = AsTransactionObject(rawTrytes[i]) } if err != nil { return nil, err } txs[i] = *tx } return txs, nil }
go
func AsTransactionObjects(rawTrytes []Trytes, hashes Hashes) (Transactions, error) { txs := make(Transactions, len(rawTrytes)) var tx *Transaction var err error for i := range rawTrytes { if hashes != nil && len(hashes) > 0 && len(hashes) > i { tx, err = AsTransactionObject(rawTrytes[i], hashes[i]) } else { tx, err = AsTransactionObject(rawTrytes[i]) } if err != nil { return nil, err } txs[i] = *tx } return txs, nil }
[ "func", "AsTransactionObjects", "(", "rawTrytes", "[", "]", "Trytes", ",", "hashes", "Hashes", ")", "(", "Transactions", ",", "error", ")", "{", "txs", ":=", "make", "(", "Transactions", ",", "len", "(", "rawTrytes", ")", ")", "\n", "var", "tx", "*", "...
// AsTransactionObjects constructs new transactions from the given raw trytes.
[ "AsTransactionObjects", "constructs", "new", "transactions", "from", "the", "given", "raw", "trytes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L122-L138
290
iotaledger/iota.go
transaction/transaction.go
MustTransactionToTrytes
func MustTransactionToTrytes(t *Transaction) Trytes { trytes, err := TransactionToTrytes(t) if err != nil { panic(err) } return trytes }
go
func MustTransactionToTrytes(t *Transaction) Trytes { trytes, err := TransactionToTrytes(t) if err != nil { panic(err) } return trytes }
[ "func", "MustTransactionToTrytes", "(", "t", "*", "Transaction", ")", "Trytes", "{", "trytes", ",", "err", ":=", "TransactionToTrytes", "(", "t", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "trytes", "...
// MustTransactionToTrytes converts the transaction to trytes.
[ "MustTransactionToTrytes", "converts", "the", "transaction", "to", "trytes", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L197-L203
291
iotaledger/iota.go
transaction/transaction.go
TransactionsToTrytes
func TransactionsToTrytes(txs Transactions) ([]Trytes, error) { trytes := make([]Trytes, len(txs)) var err error for i := range txs { trytes[i], err = TransactionToTrytes(&txs[i]) if err != nil { return nil, err } } return trytes, nil }
go
func TransactionsToTrytes(txs Transactions) ([]Trytes, error) { trytes := make([]Trytes, len(txs)) var err error for i := range txs { trytes[i], err = TransactionToTrytes(&txs[i]) if err != nil { return nil, err } } return trytes, nil }
[ "func", "TransactionsToTrytes", "(", "txs", "Transactions", ")", "(", "[", "]", "Trytes", ",", "error", ")", "{", "trytes", ":=", "make", "(", "[", "]", "Trytes", ",", "len", "(", "txs", ")", ")", "\n", "var", "err", "error", "\n", "for", "i", ":="...
// TransactionsToTrytes returns a slice of transaction trytes from the given transactions.
[ "TransactionsToTrytes", "returns", "a", "slice", "of", "transaction", "trytes", "from", "the", "given", "transactions", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L206-L216
292
iotaledger/iota.go
transaction/transaction.go
MustTransactionsToTrytes
func MustTransactionsToTrytes(txs Transactions) []Trytes { trytes := make([]Trytes, len(txs)) for i := range txs { trytes[i] = MustTransactionToTrytes(&txs[i]) } return trytes }
go
func MustTransactionsToTrytes(txs Transactions) []Trytes { trytes := make([]Trytes, len(txs)) for i := range txs { trytes[i] = MustTransactionToTrytes(&txs[i]) } return trytes }
[ "func", "MustTransactionsToTrytes", "(", "txs", "Transactions", ")", "[", "]", "Trytes", "{", "trytes", ":=", "make", "(", "[", "]", "Trytes", ",", "len", "(", "txs", ")", ")", "\n", "for", "i", ":=", "range", "txs", "{", "trytes", "[", "i", "]", "...
// MustTransactionsToTrytes returns a slice of transaction trytes from the given transactions.
[ "MustTransactionsToTrytes", "returns", "a", "slice", "of", "transaction", "trytes", "from", "the", "given", "transactions", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L219-L225
293
iotaledger/iota.go
transaction/transaction.go
FinalTransactionTrytes
func FinalTransactionTrytes(txs Transactions) ([]Trytes, error) { trytes, err := TransactionsToTrytes(txs) if err != nil { return nil, err } for i, j := 0, len(trytes)-1; i < j; i, j = i+1, j-1 { trytes[i], trytes[j] = trytes[j], trytes[i] } return trytes, nil }
go
func FinalTransactionTrytes(txs Transactions) ([]Trytes, error) { trytes, err := TransactionsToTrytes(txs) if err != nil { return nil, err } for i, j := 0, len(trytes)-1; i < j; i, j = i+1, j-1 { trytes[i], trytes[j] = trytes[j], trytes[i] } return trytes, nil }
[ "func", "FinalTransactionTrytes", "(", "txs", "Transactions", ")", "(", "[", "]", "Trytes", ",", "error", ")", "{", "trytes", ",", "err", ":=", "TransactionsToTrytes", "(", "txs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "...
// FinalTransactionTrytes returns a slice of transaction trytes from the given transactions. // The order of the transactions is reversed in the output slice.
[ "FinalTransactionTrytes", "returns", "a", "slice", "of", "transaction", "trytes", "from", "the", "given", "transactions", ".", "The", "order", "of", "the", "transactions", "is", "reversed", "in", "the", "output", "slice", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L229-L238
294
iotaledger/iota.go
transaction/transaction.go
MustFinalTransactionTrytes
func MustFinalTransactionTrytes(txs Transactions) []Trytes { trytes := MustTransactionsToTrytes(txs) for i, j := 0, len(trytes)-1; i < j; i, j = i+1, j-1 { trytes[i], trytes[j] = trytes[j], trytes[i] } return trytes }
go
func MustFinalTransactionTrytes(txs Transactions) []Trytes { trytes := MustTransactionsToTrytes(txs) for i, j := 0, len(trytes)-1; i < j; i, j = i+1, j-1 { trytes[i], trytes[j] = trytes[j], trytes[i] } return trytes }
[ "func", "MustFinalTransactionTrytes", "(", "txs", "Transactions", ")", "[", "]", "Trytes", "{", "trytes", ":=", "MustTransactionsToTrytes", "(", "txs", ")", "\n", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "trytes", ")", "-", "1", ";", "i", "<",...
// MustFinalTransactionTrytes returns a slice of transaction trytes from the given transactions. // The order of the transactions is reversed in the output slice.
[ "MustFinalTransactionTrytes", "returns", "a", "slice", "of", "transaction", "trytes", "from", "the", "given", "transactions", ".", "The", "order", "of", "the", "transactions", "is", "reversed", "in", "the", "output", "slice", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L242-L248
295
iotaledger/iota.go
transaction/transaction.go
HasValidNonce
func HasValidNonce(t *Transaction, mwm uint64) bool { return TrailingZeros(MustTrytesToTrits(TransactionHash(t))) >= int64(mwm) }
go
func HasValidNonce(t *Transaction, mwm uint64) bool { return TrailingZeros(MustTrytesToTrits(TransactionHash(t))) >= int64(mwm) }
[ "func", "HasValidNonce", "(", "t", "*", "Transaction", ",", "mwm", "uint64", ")", "bool", "{", "return", "TrailingZeros", "(", "MustTrytesToTrits", "(", "TransactionHash", "(", "t", ")", ")", ")", ">=", "int64", "(", "mwm", ")", "\n", "}" ]
// HasValidNonce checks if the transaction has the valid MinWeightMagnitude. // MWM corresponds to the amount of zero trits at the end of the transaction hash.
[ "HasValidNonce", "checks", "if", "the", "transaction", "has", "the", "valid", "MinWeightMagnitude", ".", "MWM", "corresponds", "to", "the", "amount", "of", "zero", "trits", "at", "the", "end", "of", "the", "transaction", "hash", "." ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/transaction/transaction.go#L257-L259
296
iotaledger/iota.go
merkle/merkle.go
MerkleDepth
func MerkleDepth(nodeCount uint64) (depth uint64) { depth = 0 for binaryTreeSize(0, depth) < nodeCount { depth++ } return depth + 1 }
go
func MerkleDepth(nodeCount uint64) (depth uint64) { depth = 0 for binaryTreeSize(0, depth) < nodeCount { depth++ } return depth + 1 }
[ "func", "MerkleDepth", "(", "nodeCount", "uint64", ")", "(", "depth", "uint64", ")", "{", "depth", "=", "0", "\n\n", "for", "binaryTreeSize", "(", "0", ",", "depth", ")", "<", "nodeCount", "{", "depth", "++", "\n", "}", "\n\n", "return", "depth", "+", ...
// MerkleDepth computes the depth of a merkle tree. // nodeCount is the number of nodes of the tree
[ "MerkleDepth", "computes", "the", "depth", "of", "a", "merkle", "tree", ".", "nodeCount", "is", "the", "number", "of", "nodes", "of", "the", "tree" ]
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/merkle/merkle.go#L40-L48
297
iotaledger/iota.go
merkle/merkle.go
merkleNodeIndexTraverse
func merkleNodeIndexTraverse(acc, depth, width, treeDepth uint64) uint64 { if treeDepth == 0 { return 0 } var depthCursor uint64 = 1 index := depth + acc widthCursor := width var widthOfLeaves uint64 = 1 << depth for depthCursor <= depth { if widthCursor >= (widthOfLeaves >> depthCursor) { // add whole binary tree size of the left side binary tree index += ((1 << (treeDepth - depthCursor + 1)) - 1) // counting the node index of the subtree in which the cursor currently stays in widthCursor = widthCursor - (widthOfLeaves >> depthCursor) } depthCursor++ } return index }
go
func merkleNodeIndexTraverse(acc, depth, width, treeDepth uint64) uint64 { if treeDepth == 0 { return 0 } var depthCursor uint64 = 1 index := depth + acc widthCursor := width var widthOfLeaves uint64 = 1 << depth for depthCursor <= depth { if widthCursor >= (widthOfLeaves >> depthCursor) { // add whole binary tree size of the left side binary tree index += ((1 << (treeDepth - depthCursor + 1)) - 1) // counting the node index of the subtree in which the cursor currently stays in widthCursor = widthCursor - (widthOfLeaves >> depthCursor) } depthCursor++ } return index }
[ "func", "merkleNodeIndexTraverse", "(", "acc", ",", "depth", ",", "width", ",", "treeDepth", "uint64", ")", "uint64", "{", "if", "treeDepth", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "var", "depthCursor", "uint64", "=", "1", "\n", "index", ":=",...
// merkleNodeIndexTraverse returns the node index of assign location in tree. // The order of nodes indexes follow depth-first rule. // acc is the number of nodes in the previous counting binary tree // depth is the depth of the node, counting from root // width is the width of the node, counting from left // treeDepth is the depth of whole tree
[ "merkleNodeIndexTraverse", "returns", "the", "node", "index", "of", "assign", "location", "in", "tree", ".", "The", "order", "of", "nodes", "indexes", "follow", "depth", "-", "first", "rule", ".", "acc", "is", "the", "number", "of", "nodes", "in", "the", "...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/merkle/merkle.go#L56-L77
298
iotaledger/iota.go
merkle/merkle.go
MerkleNodeIndex
func MerkleNodeIndex(depth, width, treeDepth uint64) uint64 { return merkleNodeIndexTraverse(0, depth, width, treeDepth) }
go
func MerkleNodeIndex(depth, width, treeDepth uint64) uint64 { return merkleNodeIndexTraverse(0, depth, width, treeDepth) }
[ "func", "MerkleNodeIndex", "(", "depth", ",", "width", ",", "treeDepth", "uint64", ")", "uint64", "{", "return", "merkleNodeIndexTraverse", "(", "0", ",", "depth", ",", "width", ",", "treeDepth", ")", "\n", "}" ]
// MerkleNodeIndex indexes a given node in the tree. // depth is the depth of the node, counting from root // width is the width of the node, counting from left // treeDepth is the depth of whole tree
[ "MerkleNodeIndex", "indexes", "a", "given", "node", "in", "the", "tree", ".", "depth", "is", "the", "depth", "of", "the", "node", "counting", "from", "root", "width", "is", "the", "width", "of", "the", "node", "counting", "from", "left", "treeDepth", "is",...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/merkle/merkle.go#L83-L85
299
iotaledger/iota.go
merkle/merkle.go
MerkleBranch
func MerkleBranch(tree Trits, siblings Trits, treeLength, treeDepth, leafIndex, leafCount uint64) (Trits, error) { if tree == nil { return nil, errors.New("Null tree") } if siblings == nil { return nil, errors.New("Null sibling") } if HashTrinarySize*MerkleNodeIndex(treeDepth-1, leafIndex, treeDepth-1) >= treeLength { return nil, errors.New("Leaf index out of bounds") } if treeDepth > MerkleDepth(treeLength/HashTrinarySize) { return nil, errors.New("Depth out of bounds") } var siblingIndex, siteIndex uint64 siblingIndex = MerkleLeafIndex(leafIndex, leafCount) var i int64 = 0 for depthIndex := treeDepth - 1; depthIndex > 0; depthIndex-- { if (siblingIndex & 1) != 0 { siblingIndex-- } else { siblingIndex++ } siteIndex = HashTrinarySize * MerkleNodeIndex(depthIndex, siblingIndex, treeDepth-1) if siteIndex >= treeLength { // if depth width is not even, copy a null hash copy(siblings[i*HashTrinarySize:(i+1)*HashTrinarySize], merkleNullHash) } else { // else copy a sibling copy(siblings[i*HashTrinarySize:(i+1)*HashTrinarySize], tree[siteIndex:siteIndex+HashTrinarySize]) } siblingIndex >>= 1 i++ } return siblings, nil }
go
func MerkleBranch(tree Trits, siblings Trits, treeLength, treeDepth, leafIndex, leafCount uint64) (Trits, error) { if tree == nil { return nil, errors.New("Null tree") } if siblings == nil { return nil, errors.New("Null sibling") } if HashTrinarySize*MerkleNodeIndex(treeDepth-1, leafIndex, treeDepth-1) >= treeLength { return nil, errors.New("Leaf index out of bounds") } if treeDepth > MerkleDepth(treeLength/HashTrinarySize) { return nil, errors.New("Depth out of bounds") } var siblingIndex, siteIndex uint64 siblingIndex = MerkleLeafIndex(leafIndex, leafCount) var i int64 = 0 for depthIndex := treeDepth - 1; depthIndex > 0; depthIndex-- { if (siblingIndex & 1) != 0 { siblingIndex-- } else { siblingIndex++ } siteIndex = HashTrinarySize * MerkleNodeIndex(depthIndex, siblingIndex, treeDepth-1) if siteIndex >= treeLength { // if depth width is not even, copy a null hash copy(siblings[i*HashTrinarySize:(i+1)*HashTrinarySize], merkleNullHash) } else { // else copy a sibling copy(siblings[i*HashTrinarySize:(i+1)*HashTrinarySize], tree[siteIndex:siteIndex+HashTrinarySize]) } siblingIndex >>= 1 i++ } return siblings, nil }
[ "func", "MerkleBranch", "(", "tree", "Trits", ",", "siblings", "Trits", ",", "treeLength", ",", "treeDepth", ",", "leafIndex", ",", "leafCount", "uint64", ")", "(", "Trits", ",", "error", ")", "{", "if", "tree", "==", "nil", "{", "return", "nil", ",", ...
// MerkleBranch creates the merkle branch to generate back root from index. // tree is the merkle tree - Must be allocated // siblings is the siblings of the indexed node - Must be allocated // treeLength is the length of the tree // treeDepth is the depth of the tree // leafIndex is the index of the leaf to start the branch from // leafCount is the number of leaves of the tree
[ "MerkleBranch", "creates", "the", "merkle", "branch", "to", "generate", "back", "root", "from", "index", ".", "tree", "is", "the", "merkle", "tree", "-", "Must", "be", "allocated", "siblings", "is", "the", "siblings", "of", "the", "indexed", "node", "-", "...
812d82f707314a82defbb5ef9d965fd2129dfa50
https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/merkle/merkle.go#L181-L225