repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
brankas/sentinel
sentinel.go
Shutdown
func (s *Sentinel) Shutdown() error { var firstErr error for i, f := range s.shutdownFuncs { ctxt, cancel := context.WithTimeout(context.Background(), s.shutdownDuration) defer cancel() if err := f(ctxt); err != nil { s.errf("could not shutdown %d: %v", i, err) if firstErr == nil { firstErr = err } } } return firstErr }
go
func (s *Sentinel) Shutdown() error { var firstErr error for i, f := range s.shutdownFuncs { ctxt, cancel := context.WithTimeout(context.Background(), s.shutdownDuration) defer cancel() if err := f(ctxt); err != nil { s.errf("could not shutdown %d: %v", i, err) if firstErr == nil { firstErr = err } } } return firstErr }
[ "func", "(", "s", "*", "Sentinel", ")", "Shutdown", "(", ")", "error", "{", "var", "firstErr", "error", "\n", "for", "i", ",", "f", ":=", "range", "s", ".", "shutdownFuncs", "{", "ctxt", ",", "cancel", ":=", "context", ".", "WithTimeout", "(", "context", ".", "Background", "(", ")", ",", "s", ".", "shutdownDuration", ")", "\n", "defer", "cancel", "(", ")", "\n", "if", "err", ":=", "f", "(", "ctxt", ")", ";", "err", "!=", "nil", "{", "s", ".", "errf", "(", "\"could not shutdown %d: %v\"", ",", "i", ",", "err", ")", "\n", "if", "firstErr", "==", "nil", "{", "firstErr", "=", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "firstErr", "\n", "}" ]
// Shutdown calls all registered shutdown funcs.
[ "Shutdown", "calls", "all", "registered", "shutdown", "funcs", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L108-L121
test
brankas/sentinel
sentinel.go
ShutdownIgnore
func (s *Sentinel) ShutdownIgnore(err error) bool { if err == nil { return true } for _, f := range s.ignoreErrors { if z := f(err); z { return true } } return false }
go
func (s *Sentinel) ShutdownIgnore(err error) bool { if err == nil { return true } for _, f := range s.ignoreErrors { if z := f(err); z { return true } } return false }
[ "func", "(", "s", "*", "Sentinel", ")", "ShutdownIgnore", "(", "err", "error", ")", "bool", "{", "if", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "f", ":=", "range", "s", ".", "ignoreErrors", "{", "if", "z", ":=", "f", "(", "err", ")", ";", "z", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ShutdownIgnore returns if any of the registered ignore funcs reported true.
[ "ShutdownIgnore", "returns", "if", "any", "of", "the", "registered", "ignore", "funcs", "reported", "true", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L124-L134
test
brankas/sentinel
sentinel.go
Register
func (s *Sentinel) Register(server, shutdown interface{}, ignore ...func(error) bool) error { // add server and shutdown funcs var err error s.serverFuncs, err = convertAndAppendContextFuncs(s.serverFuncs, server) if err != nil { return err } s.shutdownFuncs, err = convertAndAppendContextFuncs(s.shutdownFuncs, shutdown) if err != nil { return err } s.ignoreErrors = append(s.ignoreErrors, ignore...) return nil }
go
func (s *Sentinel) Register(server, shutdown interface{}, ignore ...func(error) bool) error { // add server and shutdown funcs var err error s.serverFuncs, err = convertAndAppendContextFuncs(s.serverFuncs, server) if err != nil { return err } s.shutdownFuncs, err = convertAndAppendContextFuncs(s.shutdownFuncs, shutdown) if err != nil { return err } s.ignoreErrors = append(s.ignoreErrors, ignore...) return nil }
[ "func", "(", "s", "*", "Sentinel", ")", "Register", "(", "server", ",", "shutdown", "interface", "{", "}", ",", "ignore", "...", "func", "(", "error", ")", "bool", ")", "error", "{", "var", "err", "error", "\n", "s", ".", "serverFuncs", ",", "err", "=", "convertAndAppendContextFuncs", "(", "s", ".", "serverFuncs", ",", "server", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "s", ".", "shutdownFuncs", ",", "err", "=", "convertAndAppendContextFuncs", "(", "s", ".", "shutdownFuncs", ",", "shutdown", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "s", ".", "ignoreErrors", "=", "append", "(", "s", ".", "ignoreErrors", ",", "ignore", "...", ")", "\n", "return", "nil", "\n", "}" ]
// Register registers a server, its shutdown func, and ignore error funcs.
[ "Register", "registers", "a", "server", "its", "shutdown", "func", "and", "ignore", "error", "funcs", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L137-L151
test
brankas/sentinel
sentinel.go
Mux
func (s *Sentinel) Mux(listener net.Listener, opts ...netmux.Option) (*netmux.Netmux, error) { s.Lock() defer s.Unlock() if s.started { return nil, ErrAlreadyStarted } // create connection mux mux, err := netmux.New(listener, opts...) if err != nil { return nil, err } // register server + shutdown if err = s.Register(mux, mux, IgnoreListenerClosed, IgnoreNetOpError); err != nil { return nil, err } return mux, nil }
go
func (s *Sentinel) Mux(listener net.Listener, opts ...netmux.Option) (*netmux.Netmux, error) { s.Lock() defer s.Unlock() if s.started { return nil, ErrAlreadyStarted } // create connection mux mux, err := netmux.New(listener, opts...) if err != nil { return nil, err } // register server + shutdown if err = s.Register(mux, mux, IgnoreListenerClosed, IgnoreNetOpError); err != nil { return nil, err } return mux, nil }
[ "func", "(", "s", "*", "Sentinel", ")", "Mux", "(", "listener", "net", ".", "Listener", ",", "opts", "...", "netmux", ".", "Option", ")", "(", "*", "netmux", ".", "Netmux", ",", "error", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "started", "{", "return", "nil", ",", "ErrAlreadyStarted", "\n", "}", "\n", "mux", ",", "err", ":=", "netmux", ".", "New", "(", "listener", ",", "opts", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "s", ".", "Register", "(", "mux", ",", "mux", ",", "IgnoreListenerClosed", ",", "IgnoreNetOpError", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "mux", ",", "nil", "\n", "}" ]
// Mux creates a new network connection muxer and registers its server, // shutdown, and ignore error funcs.
[ "Mux", "creates", "a", "new", "network", "connection", "muxer", "and", "registers", "its", "server", "shutdown", "and", "ignore", "error", "funcs", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L155-L175
test
brankas/sentinel
sentinel.go
HTTP
func (s *Sentinel) HTTP(listener net.Listener, handler http.Handler, opts ...ServerOption) error { s.Lock() defer s.Unlock() if s.started { return ErrAlreadyStarted } var err error // create server and apply options server := &http.Server{ Handler: handler, } for _, o := range opts { if err = o(server); err != nil { return err } } // register server return s.Register(func() error { return server.Serve(listener) }, server.Shutdown, IgnoreServerClosed, IgnoreNetOpError) }
go
func (s *Sentinel) HTTP(listener net.Listener, handler http.Handler, opts ...ServerOption) error { s.Lock() defer s.Unlock() if s.started { return ErrAlreadyStarted } var err error // create server and apply options server := &http.Server{ Handler: handler, } for _, o := range opts { if err = o(server); err != nil { return err } } // register server return s.Register(func() error { return server.Serve(listener) }, server.Shutdown, IgnoreServerClosed, IgnoreNetOpError) }
[ "func", "(", "s", "*", "Sentinel", ")", "HTTP", "(", "listener", "net", ".", "Listener", ",", "handler", "http", ".", "Handler", ",", "opts", "...", "ServerOption", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "started", "{", "return", "ErrAlreadyStarted", "\n", "}", "\n", "var", "err", "error", "\n", "server", ":=", "&", "http", ".", "Server", "{", "Handler", ":", "handler", ",", "}", "\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "if", "err", "=", "o", "(", "server", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "s", ".", "Register", "(", "func", "(", ")", "error", "{", "return", "server", ".", "Serve", "(", "listener", ")", "\n", "}", ",", "server", ".", "Shutdown", ",", "IgnoreServerClosed", ",", "IgnoreNetOpError", ")", "\n", "}" ]
// HTTP creates a HTTP server and registers it with the sentinel.
[ "HTTP", "creates", "a", "HTTP", "server", "and", "registers", "it", "with", "the", "sentinel", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L178-L202
test
brankas/sentinel
sentinel.go
IgnoreError
func IgnoreError(err error) func(error) bool { return func(e error) bool { return err == e } }
go
func IgnoreError(err error) func(error) bool { return func(e error) bool { return err == e } }
[ "func", "IgnoreError", "(", "err", "error", ")", "func", "(", "error", ")", "bool", "{", "return", "func", "(", "e", "error", ")", "bool", "{", "return", "err", "==", "e", "\n", "}", "\n", "}" ]
// IgnoreError returns a func that will return true when the passed errors // match.
[ "IgnoreError", "returns", "a", "func", "that", "will", "return", "true", "when", "the", "passed", "errors", "match", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L206-L210
test
brankas/sentinel
sentinel.go
IgnoreNetOpError
func IgnoreNetOpError(err error) bool { if opErr, ok := err.(*net.OpError); ok { return opErr.Err.Error() == "use of closed network connection" } return false }
go
func IgnoreNetOpError(err error) bool { if opErr, ok := err.(*net.OpError); ok { return opErr.Err.Error() == "use of closed network connection" } return false }
[ "func", "IgnoreNetOpError", "(", "err", "error", ")", "bool", "{", "if", "opErr", ",", "ok", ":=", "err", ".", "(", "*", "net", ".", "OpError", ")", ";", "ok", "{", "return", "opErr", ".", "Err", ".", "Error", "(", ")", "==", "\"use of closed network connection\"", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IgnoreNetOpError returns true when the passed error is a net.OpError with // error "use of closed network connection".
[ "IgnoreNetOpError", "returns", "true", "when", "the", "passed", "error", "is", "a", "net", ".", "OpError", "with", "error", "use", "of", "closed", "network", "connection", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/sentinel.go#L226-L231
test
brankas/sentinel
util.go
convertAndAppendContextFuncs
func convertAndAppendContextFuncs(o []func(context.Context) error, v ...interface{}) ([]func(context.Context) error, error) { for _, z := range v { var t func(context.Context) error switch f := z.(type) { case func(context.Context) error: t = f case func(): t = func(context.Context) error { f() return nil } case func() error: t = func(context.Context) error { return f() } } if t == nil { return nil, ErrInvalidType } o = append(o, t) } return o, nil }
go
func convertAndAppendContextFuncs(o []func(context.Context) error, v ...interface{}) ([]func(context.Context) error, error) { for _, z := range v { var t func(context.Context) error switch f := z.(type) { case func(context.Context) error: t = f case func(): t = func(context.Context) error { f() return nil } case func() error: t = func(context.Context) error { return f() } } if t == nil { return nil, ErrInvalidType } o = append(o, t) } return o, nil }
[ "func", "convertAndAppendContextFuncs", "(", "o", "[", "]", "func", "(", "context", ".", "Context", ")", "error", ",", "v", "...", "interface", "{", "}", ")", "(", "[", "]", "func", "(", "context", ".", "Context", ")", "error", ",", "error", ")", "{", "for", "_", ",", "z", ":=", "range", "v", "{", "var", "t", "func", "(", "context", ".", "Context", ")", "error", "\n", "switch", "f", ":=", "z", ".", "(", "type", ")", "{", "case", "func", "(", "context", ".", "Context", ")", "error", ":", "t", "=", "f", "\n", "case", "func", "(", ")", ":", "t", "=", "func", "(", "context", ".", "Context", ")", "error", "{", "f", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "case", "func", "(", ")", "error", ":", "t", "=", "func", "(", "context", ".", "Context", ")", "error", "{", "return", "f", "(", ")", "\n", "}", "\n", "}", "\n", "if", "t", "==", "nil", "{", "return", "nil", ",", "ErrInvalidType", "\n", "}", "\n", "o", "=", "append", "(", "o", ",", "t", ")", "\n", "}", "\n", "return", "o", ",", "nil", "\n", "}" ]
// convertAndAppendContextFuncs converts and appends funcs in v to o.
[ "convertAndAppendContextFuncs", "converts", "and", "appends", "funcs", "in", "v", "to", "o", "." ]
0ff081867c31a45cb71f5976ea6144fd06a557b5
https://github.com/brankas/sentinel/blob/0ff081867c31a45cb71f5976ea6144fd06a557b5/util.go#L25-L51
test
Financial-Times/base-ft-rw-app-go
baseftrwapp/baseftapp.go
router
func router(apiData []byte, services map[string]Service, healthHandler func(http.ResponseWriter, *http.Request)) *mux.Router { m := mux.NewRouter() gtgChecker := make([]gtg.StatusChecker, 0) for path, service := range services { handlers := httpHandlers{service} m.HandleFunc(fmt.Sprintf("/%s/__count", path), handlers.countHandler).Methods("GET") m.HandleFunc(fmt.Sprintf("/%s/__ids", path), handlers.idsHandler).Methods("GET") m.HandleFunc(fmt.Sprintf("/%s/{uuid}", path), handlers.getHandler).Methods("GET") m.HandleFunc(fmt.Sprintf("/%s/{uuid}", path), handlers.putHandler).Methods("PUT") m.HandleFunc(fmt.Sprintf("/%s/{uuid}", path), handlers.deleteHandler).Methods("DELETE") gtgChecker = append(gtgChecker, func() gtg.Status { if err := service.Check(); err != nil { return gtg.Status{GoodToGo: false, Message: err.Error()} } return gtg.Status{GoodToGo: true} }) } if apiData != nil && len(apiData) != 0 { endpoint, err := api.NewAPIEndpointForYAML(apiData) if err != nil { log.Warn("Failed to serve API endpoint, please check whether the OpenAPI file is valid") } else { m.HandleFunc(api.DefaultPath, endpoint.ServeHTTP) } } m.HandleFunc("/__health", healthHandler) // The top one of these feels more correct, but the lower one matches what we have in Dropwizard, // so it's what apps expect currently m.HandleFunc(status.PingPath, status.PingHandler) m.HandleFunc(status.PingPathDW, status.PingHandler) // The top one of these feels more correct, but the lower one matches what we have in Dropwizard, // so it's what apps expect currently same as ping, the content of build-info needs more definition m.HandleFunc(status.BuildInfoPath, status.BuildInfoHandler) m.HandleFunc(status.BuildInfoPathDW, status.BuildInfoHandler) m.HandleFunc(status.GTGPath, status.NewGoodToGoHandler(gtg.FailFastParallelCheck(gtgChecker))) return m }
go
func router(apiData []byte, services map[string]Service, healthHandler func(http.ResponseWriter, *http.Request)) *mux.Router { m := mux.NewRouter() gtgChecker := make([]gtg.StatusChecker, 0) for path, service := range services { handlers := httpHandlers{service} m.HandleFunc(fmt.Sprintf("/%s/__count", path), handlers.countHandler).Methods("GET") m.HandleFunc(fmt.Sprintf("/%s/__ids", path), handlers.idsHandler).Methods("GET") m.HandleFunc(fmt.Sprintf("/%s/{uuid}", path), handlers.getHandler).Methods("GET") m.HandleFunc(fmt.Sprintf("/%s/{uuid}", path), handlers.putHandler).Methods("PUT") m.HandleFunc(fmt.Sprintf("/%s/{uuid}", path), handlers.deleteHandler).Methods("DELETE") gtgChecker = append(gtgChecker, func() gtg.Status { if err := service.Check(); err != nil { return gtg.Status{GoodToGo: false, Message: err.Error()} } return gtg.Status{GoodToGo: true} }) } if apiData != nil && len(apiData) != 0 { endpoint, err := api.NewAPIEndpointForYAML(apiData) if err != nil { log.Warn("Failed to serve API endpoint, please check whether the OpenAPI file is valid") } else { m.HandleFunc(api.DefaultPath, endpoint.ServeHTTP) } } m.HandleFunc("/__health", healthHandler) // The top one of these feels more correct, but the lower one matches what we have in Dropwizard, // so it's what apps expect currently m.HandleFunc(status.PingPath, status.PingHandler) m.HandleFunc(status.PingPathDW, status.PingHandler) // The top one of these feels more correct, but the lower one matches what we have in Dropwizard, // so it's what apps expect currently same as ping, the content of build-info needs more definition m.HandleFunc(status.BuildInfoPath, status.BuildInfoHandler) m.HandleFunc(status.BuildInfoPathDW, status.BuildInfoHandler) m.HandleFunc(status.GTGPath, status.NewGoodToGoHandler(gtg.FailFastParallelCheck(gtgChecker))) return m }
[ "func", "router", "(", "apiData", "[", "]", "byte", ",", "services", "map", "[", "string", "]", "Service", ",", "healthHandler", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", ")", "*", "mux", ".", "Router", "{", "m", ":=", "mux", ".", "NewRouter", "(", ")", "\n", "gtgChecker", ":=", "make", "(", "[", "]", "gtg", ".", "StatusChecker", ",", "0", ")", "\n", "for", "path", ",", "service", ":=", "range", "services", "{", "handlers", ":=", "httpHandlers", "{", "service", "}", "\n", "m", ".", "HandleFunc", "(", "fmt", ".", "Sprintf", "(", "\"/%s/__count\"", ",", "path", ")", ",", "handlers", ".", "countHandler", ")", ".", "Methods", "(", "\"GET\"", ")", "\n", "m", ".", "HandleFunc", "(", "fmt", ".", "Sprintf", "(", "\"/%s/__ids\"", ",", "path", ")", ",", "handlers", ".", "idsHandler", ")", ".", "Methods", "(", "\"GET\"", ")", "\n", "m", ".", "HandleFunc", "(", "fmt", ".", "Sprintf", "(", "\"/%s/{uuid}\"", ",", "path", ")", ",", "handlers", ".", "getHandler", ")", ".", "Methods", "(", "\"GET\"", ")", "\n", "m", ".", "HandleFunc", "(", "fmt", ".", "Sprintf", "(", "\"/%s/{uuid}\"", ",", "path", ")", ",", "handlers", ".", "putHandler", ")", ".", "Methods", "(", "\"PUT\"", ")", "\n", "m", ".", "HandleFunc", "(", "fmt", ".", "Sprintf", "(", "\"/%s/{uuid}\"", ",", "path", ")", ",", "handlers", ".", "deleteHandler", ")", ".", "Methods", "(", "\"DELETE\"", ")", "\n", "gtgChecker", "=", "append", "(", "gtgChecker", ",", "func", "(", ")", "gtg", ".", "Status", "{", "if", "err", ":=", "service", ".", "Check", "(", ")", ";", "err", "!=", "nil", "{", "return", "gtg", ".", "Status", "{", "GoodToGo", ":", "false", ",", "Message", ":", "err", ".", "Error", "(", ")", "}", "\n", "}", "\n", "return", "gtg", ".", "Status", "{", "GoodToGo", ":", "true", "}", "\n", "}", ")", "\n", "}", "\n", "if", "apiData", "!=", "nil", "&&", "len", "(", "apiData", ")", "!=", "0", "{", "endpoint", ",", "err", ":=", "api", ".", "NewAPIEndpointForYAML", "(", "apiData", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warn", "(", "\"Failed to serve API endpoint, please check whether the OpenAPI file is valid\"", ")", "\n", "}", "else", "{", "m", ".", "HandleFunc", "(", "api", ".", "DefaultPath", ",", "endpoint", ".", "ServeHTTP", ")", "\n", "}", "\n", "}", "\n", "m", ".", "HandleFunc", "(", "\"/__health\"", ",", "healthHandler", ")", "\n", "m", ".", "HandleFunc", "(", "status", ".", "PingPath", ",", "status", ".", "PingHandler", ")", "\n", "m", ".", "HandleFunc", "(", "status", ".", "PingPathDW", ",", "status", ".", "PingHandler", ")", "\n", "m", ".", "HandleFunc", "(", "status", ".", "BuildInfoPath", ",", "status", ".", "BuildInfoHandler", ")", "\n", "m", ".", "HandleFunc", "(", "status", ".", "BuildInfoPathDW", ",", "status", ".", "BuildInfoHandler", ")", "\n", "m", ".", "HandleFunc", "(", "status", ".", "GTGPath", ",", "status", ".", "NewGoodToGoHandler", "(", "gtg", ".", "FailFastParallelCheck", "(", "gtgChecker", ")", ")", ")", "\n", "return", "m", "\n", "}" ]
//Router sets up the Router - extracted for testability
[ "Router", "sets", "up", "the", "Router", "-", "extracted", "for", "testability" ]
1ea8a13e1f37b95318cd965796558d932750f407
https://github.com/Financial-Times/base-ft-rw-app-go/blob/1ea8a13e1f37b95318cd965796558d932750f407/baseftrwapp/baseftapp.go#L84-L128
test
Financial-Times/base-ft-rw-app-go
baseftrwapp/http_handlers.go
buildInfoHandler
func buildInfoHandler(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "build-info") }
go
func buildInfoHandler(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "build-info") }
[ "func", "buildInfoHandler", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "fmt", ".", "Fprintf", "(", "w", ",", "\"build-info\"", ")", "\n", "}" ]
// buildInfoHandler - This is a stop gap and will be added to when we can define what we should display here
[ "buildInfoHandler", "-", "This", "is", "a", "stop", "gap", "and", "will", "be", "added", "to", "when", "we", "can", "define", "what", "we", "should", "display", "here" ]
1ea8a13e1f37b95318cd965796558d932750f407
https://github.com/Financial-Times/base-ft-rw-app-go/blob/1ea8a13e1f37b95318cd965796558d932750f407/baseftrwapp/http_handlers.go#L192-L194
test
codegangsta/martini-contrib
encoder/encoder.go
Encode
func (_ JsonEncoder) Encode(v ...interface{}) ([]byte, error) { var data interface{} = v var result interface{} if v == nil { // So that empty results produces `[]` and not `null` data = []interface{}{} } else if len(v) == 1 { data = v[0] } t := reflect.TypeOf(data) if t.Kind() == reflect.Ptr { t = t.Elem() } if t.Kind() == reflect.Struct { result = copyStruct(reflect.ValueOf(data), t).Interface() } else { result = data } b, err := json.Marshal(result) return b, err }
go
func (_ JsonEncoder) Encode(v ...interface{}) ([]byte, error) { var data interface{} = v var result interface{} if v == nil { // So that empty results produces `[]` and not `null` data = []interface{}{} } else if len(v) == 1 { data = v[0] } t := reflect.TypeOf(data) if t.Kind() == reflect.Ptr { t = t.Elem() } if t.Kind() == reflect.Struct { result = copyStruct(reflect.ValueOf(data), t).Interface() } else { result = data } b, err := json.Marshal(result) return b, err }
[ "func", "(", "_", "JsonEncoder", ")", "Encode", "(", "v", "...", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "data", "interface", "{", "}", "=", "v", "\n", "var", "result", "interface", "{", "}", "\n", "if", "v", "==", "nil", "{", "data", "=", "[", "]", "interface", "{", "}", "{", "}", "\n", "}", "else", "if", "len", "(", "v", ")", "==", "1", "{", "data", "=", "v", "[", "0", "]", "\n", "}", "\n", "t", ":=", "reflect", ".", "TypeOf", "(", "data", ")", "\n", "if", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "t", "=", "t", ".", "Elem", "(", ")", "\n", "}", "\n", "if", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Struct", "{", "result", "=", "copyStruct", "(", "reflect", ".", "ValueOf", "(", "data", ")", ",", "t", ")", ".", "Interface", "(", ")", "\n", "}", "else", "{", "result", "=", "data", "\n", "}", "\n", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "result", ")", "\n", "return", "b", ",", "err", "\n", "}" ]
// jsonEncoder is an Encoder that produces JSON-formatted responses.
[ "jsonEncoder", "is", "an", "Encoder", "that", "produces", "JSON", "-", "formatted", "responses", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/encoder/encoder.go#L32-L58
test
codegangsta/martini-contrib
binding/binding.go
Json
func Json(jsonStruct interface{}, ifacePtr ...interface{}) martini.Handler { return func(context martini.Context, req *http.Request) { ensureNotPointer(jsonStruct) jsonStruct := reflect.New(reflect.TypeOf(jsonStruct)) errors := newErrors() if req.Body != nil { defer req.Body.Close() } if err := json.NewDecoder(req.Body).Decode(jsonStruct.Interface()); err != nil { errors.Overall[DeserializationError] = err.Error() } validateAndMap(jsonStruct, context, errors, ifacePtr...) } }
go
func Json(jsonStruct interface{}, ifacePtr ...interface{}) martini.Handler { return func(context martini.Context, req *http.Request) { ensureNotPointer(jsonStruct) jsonStruct := reflect.New(reflect.TypeOf(jsonStruct)) errors := newErrors() if req.Body != nil { defer req.Body.Close() } if err := json.NewDecoder(req.Body).Decode(jsonStruct.Interface()); err != nil { errors.Overall[DeserializationError] = err.Error() } validateAndMap(jsonStruct, context, errors, ifacePtr...) } }
[ "func", "Json", "(", "jsonStruct", "interface", "{", "}", ",", "ifacePtr", "...", "interface", "{", "}", ")", "martini", ".", "Handler", "{", "return", "func", "(", "context", "martini", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "{", "ensureNotPointer", "(", "jsonStruct", ")", "\n", "jsonStruct", ":=", "reflect", ".", "New", "(", "reflect", ".", "TypeOf", "(", "jsonStruct", ")", ")", "\n", "errors", ":=", "newErrors", "(", ")", "\n", "if", "req", ".", "Body", "!=", "nil", "{", "defer", "req", ".", "Body", ".", "Close", "(", ")", "\n", "}", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "req", ".", "Body", ")", ".", "Decode", "(", "jsonStruct", ".", "Interface", "(", ")", ")", ";", "err", "!=", "nil", "{", "errors", ".", "Overall", "[", "DeserializationError", "]", "=", "err", ".", "Error", "(", ")", "\n", "}", "\n", "validateAndMap", "(", "jsonStruct", ",", "context", ",", "errors", ",", "ifacePtr", "...", ")", "\n", "}", "\n", "}" ]
// Json is middleware to deserialize a JSON payload from the request // into the struct that is passed in. The resulting struct is then // validated, but no error handling is actually performed here. // An interface pointer can be added as a second argument in order // to map the struct to a specific interface.
[ "Json", "is", "middleware", "to", "deserialize", "a", "JSON", "payload", "from", "the", "request", "into", "the", "struct", "that", "is", "passed", "in", ".", "The", "resulting", "struct", "is", "then", "validated", "but", "no", "error", "handling", "is", "actually", "performed", "here", ".", "An", "interface", "pointer", "can", "be", "added", "as", "a", "second", "argument", "in", "order", "to", "map", "the", "struct", "to", "a", "specific", "interface", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/binding/binding.go#L116-L132
test
codegangsta/martini-contrib
binding/binding.go
validateAndMap
func validateAndMap(obj reflect.Value, context martini.Context, errors *Errors, ifacePtr ...interface{}) { context.Invoke(Validate(obj.Interface())) errors.combine(getErrors(context)) context.Map(*errors) context.Map(obj.Elem().Interface()) if len(ifacePtr) > 0 { context.MapTo(obj.Elem().Interface(), ifacePtr[0]) } }
go
func validateAndMap(obj reflect.Value, context martini.Context, errors *Errors, ifacePtr ...interface{}) { context.Invoke(Validate(obj.Interface())) errors.combine(getErrors(context)) context.Map(*errors) context.Map(obj.Elem().Interface()) if len(ifacePtr) > 0 { context.MapTo(obj.Elem().Interface(), ifacePtr[0]) } }
[ "func", "validateAndMap", "(", "obj", "reflect", ".", "Value", ",", "context", "martini", ".", "Context", ",", "errors", "*", "Errors", ",", "ifacePtr", "...", "interface", "{", "}", ")", "{", "context", ".", "Invoke", "(", "Validate", "(", "obj", ".", "Interface", "(", ")", ")", ")", "\n", "errors", ".", "combine", "(", "getErrors", "(", "context", ")", ")", "\n", "context", ".", "Map", "(", "*", "errors", ")", "\n", "context", ".", "Map", "(", "obj", ".", "Elem", "(", ")", ".", "Interface", "(", ")", ")", "\n", "if", "len", "(", "ifacePtr", ")", ">", "0", "{", "context", ".", "MapTo", "(", "obj", ".", "Elem", "(", ")", ".", "Interface", "(", ")", ",", "ifacePtr", "[", "0", "]", ")", "\n", "}", "\n", "}" ]
// Performs validation and combines errors from validation // with errors from deserialization, then maps both the // resulting struct and the errors to the context.
[ "Performs", "validation", "and", "combines", "errors", "from", "validation", "with", "errors", "from", "deserialization", "then", "maps", "both", "the", "resulting", "struct", "and", "the", "errors", "to", "the", "context", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/binding/binding.go#L299-L307
test
codegangsta/martini-contrib
binding/binding.go
Count
func (self Errors) Count() int { return len(self.Overall) + len(self.Fields) }
go
func (self Errors) Count() int { return len(self.Overall) + len(self.Fields) }
[ "func", "(", "self", "Errors", ")", "Count", "(", ")", "int", "{", "return", "len", "(", "self", ".", "Overall", ")", "+", "len", "(", "self", ".", "Fields", ")", "\n", "}" ]
// Total errors is the sum of errors with the request overall // and errors on individual fields.
[ "Total", "errors", "is", "the", "sum", "of", "errors", "with", "the", "request", "overall", "and", "errors", "on", "individual", "fields", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/binding/binding.go#L332-L334
test
codegangsta/martini-contrib
cors/cors.go
Header
func (o *Options) Header(origin string) (headers map[string]string) { headers = make(map[string]string) // if origin is not alowed, don't extend the headers // with CORS headers. if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) { return } // add allow origin if o.AllowAllOrigins { headers[headerAllowOrigin] = "*" } else { headers[headerAllowOrigin] = origin } // add allow credentials headers[headerAllowCredentials] = strconv.FormatBool(o.AllowCredentials) // add allow methods if len(o.AllowMethods) > 0 { headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",") } // add allow headers if len(o.AllowHeaders) > 0 { // TODO: Add default headers headers[headerAllowHeaders] = strings.Join(o.AllowHeaders, ",") } // add exposed header if len(o.ExposeHeaders) > 0 { headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",") } // add a max age header if o.MaxAge > time.Duration(0) { headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10) } return }
go
func (o *Options) Header(origin string) (headers map[string]string) { headers = make(map[string]string) // if origin is not alowed, don't extend the headers // with CORS headers. if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) { return } // add allow origin if o.AllowAllOrigins { headers[headerAllowOrigin] = "*" } else { headers[headerAllowOrigin] = origin } // add allow credentials headers[headerAllowCredentials] = strconv.FormatBool(o.AllowCredentials) // add allow methods if len(o.AllowMethods) > 0 { headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",") } // add allow headers if len(o.AllowHeaders) > 0 { // TODO: Add default headers headers[headerAllowHeaders] = strings.Join(o.AllowHeaders, ",") } // add exposed header if len(o.ExposeHeaders) > 0 { headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",") } // add a max age header if o.MaxAge > time.Duration(0) { headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10) } return }
[ "func", "(", "o", "*", "Options", ")", "Header", "(", "origin", "string", ")", "(", "headers", "map", "[", "string", "]", "string", ")", "{", "headers", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "if", "!", "o", ".", "AllowAllOrigins", "&&", "!", "o", ".", "IsOriginAllowed", "(", "origin", ")", "{", "return", "\n", "}", "\n", "if", "o", ".", "AllowAllOrigins", "{", "headers", "[", "headerAllowOrigin", "]", "=", "\"*\"", "\n", "}", "else", "{", "headers", "[", "headerAllowOrigin", "]", "=", "origin", "\n", "}", "\n", "headers", "[", "headerAllowCredentials", "]", "=", "strconv", ".", "FormatBool", "(", "o", ".", "AllowCredentials", ")", "\n", "if", "len", "(", "o", ".", "AllowMethods", ")", ">", "0", "{", "headers", "[", "headerAllowMethods", "]", "=", "strings", ".", "Join", "(", "o", ".", "AllowMethods", ",", "\",\"", ")", "\n", "}", "\n", "if", "len", "(", "o", ".", "AllowHeaders", ")", ">", "0", "{", "headers", "[", "headerAllowHeaders", "]", "=", "strings", ".", "Join", "(", "o", ".", "AllowHeaders", ",", "\",\"", ")", "\n", "}", "\n", "if", "len", "(", "o", ".", "ExposeHeaders", ")", ">", "0", "{", "headers", "[", "headerExposeHeaders", "]", "=", "strings", ".", "Join", "(", "o", ".", "ExposeHeaders", ",", "\",\"", ")", "\n", "}", "\n", "if", "o", ".", "MaxAge", ">", "time", ".", "Duration", "(", "0", ")", "{", "headers", "[", "headerMaxAge", "]", "=", "strconv", ".", "FormatInt", "(", "int64", "(", "o", ".", "MaxAge", "/", "time", ".", "Second", ")", ",", "10", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Converts options into CORS headers.
[ "Converts", "options", "into", "CORS", "headers", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/cors/cors.go#L44-L82
test
codegangsta/martini-contrib
cors/cors.go
PreflightHeader
func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map[string]string) { headers = make(map[string]string) if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) { return } // verify if requested method is allowed // TODO: Too many for loops for _, method := range o.AllowMethods { if method == rMethod { headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",") break } } // verify if requested headers are allowed var allowed []string for _, rHeader := range strings.Split(rHeaders, ",") { lookupLoop: for _, allowedHeader := range o.AllowHeaders { if rHeader == allowedHeader { allowed = append(allowed, rHeader) break lookupLoop } } } // add allowed headers if len(allowed) > 0 { headers[headerAllowHeaders] = strings.Join(allowed, ",") } // add exposed headers if len(o.ExposeHeaders) > 0 { headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",") } // add a max age header if o.MaxAge > time.Duration(0) { headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10) } return }
go
func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map[string]string) { headers = make(map[string]string) if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) { return } // verify if requested method is allowed // TODO: Too many for loops for _, method := range o.AllowMethods { if method == rMethod { headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",") break } } // verify if requested headers are allowed var allowed []string for _, rHeader := range strings.Split(rHeaders, ",") { lookupLoop: for _, allowedHeader := range o.AllowHeaders { if rHeader == allowedHeader { allowed = append(allowed, rHeader) break lookupLoop } } } // add allowed headers if len(allowed) > 0 { headers[headerAllowHeaders] = strings.Join(allowed, ",") } // add exposed headers if len(o.ExposeHeaders) > 0 { headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",") } // add a max age header if o.MaxAge > time.Duration(0) { headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10) } return }
[ "func", "(", "o", "*", "Options", ")", "PreflightHeader", "(", "origin", ",", "rMethod", ",", "rHeaders", "string", ")", "(", "headers", "map", "[", "string", "]", "string", ")", "{", "headers", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "if", "!", "o", ".", "AllowAllOrigins", "&&", "!", "o", ".", "IsOriginAllowed", "(", "origin", ")", "{", "return", "\n", "}", "\n", "for", "_", ",", "method", ":=", "range", "o", ".", "AllowMethods", "{", "if", "method", "==", "rMethod", "{", "headers", "[", "headerAllowMethods", "]", "=", "strings", ".", "Join", "(", "o", ".", "AllowMethods", ",", "\",\"", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "var", "allowed", "[", "]", "string", "\n", "for", "_", ",", "rHeader", ":=", "range", "strings", ".", "Split", "(", "rHeaders", ",", "\",\"", ")", "{", "lookupLoop", ":", "for", "_", ",", "allowedHeader", ":=", "range", "o", ".", "AllowHeaders", "{", "if", "rHeader", "==", "allowedHeader", "{", "allowed", "=", "append", "(", "allowed", ",", "rHeader", ")", "\n", "break", "lookupLoop", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "allowed", ")", ">", "0", "{", "headers", "[", "headerAllowHeaders", "]", "=", "strings", ".", "Join", "(", "allowed", ",", "\",\"", ")", "\n", "}", "\n", "if", "len", "(", "o", ".", "ExposeHeaders", ")", ">", "0", "{", "headers", "[", "headerExposeHeaders", "]", "=", "strings", ".", "Join", "(", "o", ".", "ExposeHeaders", ",", "\",\"", ")", "\n", "}", "\n", "if", "o", ".", "MaxAge", ">", "time", ".", "Duration", "(", "0", ")", "{", "headers", "[", "headerMaxAge", "]", "=", "strconv", ".", "FormatInt", "(", "int64", "(", "o", ".", "MaxAge", "/", "time", ".", "Second", ")", ",", "10", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Converts options into CORS headers for a preflight response.
[ "Converts", "options", "into", "CORS", "headers", "for", "a", "preflight", "response", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/cors/cors.go#L85-L125
test
codegangsta/martini-contrib
cors/cors.go
IsOriginAllowed
func (o *Options) IsOriginAllowed(origin string) (allowed bool) { for _, pattern := range o.AllowOrigins { allowed, _ = regexp.MatchString(pattern, origin) if allowed { return } } return }
go
func (o *Options) IsOriginAllowed(origin string) (allowed bool) { for _, pattern := range o.AllowOrigins { allowed, _ = regexp.MatchString(pattern, origin) if allowed { return } } return }
[ "func", "(", "o", "*", "Options", ")", "IsOriginAllowed", "(", "origin", "string", ")", "(", "allowed", "bool", ")", "{", "for", "_", ",", "pattern", ":=", "range", "o", ".", "AllowOrigins", "{", "allowed", ",", "_", "=", "regexp", ".", "MatchString", "(", "pattern", ",", "origin", ")", "\n", "if", "allowed", "{", "return", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Looks up if the origin matches one of the patterns // provided in Options.AllowOrigins patterns.
[ "Looks", "up", "if", "the", "origin", "matches", "one", "of", "the", "patterns", "provided", "in", "Options", ".", "AllowOrigins", "patterns", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/cors/cors.go#L129-L137
test
codegangsta/martini-contrib
cors/cors.go
Allow
func Allow(opts *Options) http.HandlerFunc { return func(res http.ResponseWriter, req *http.Request) { var ( origin = req.Header.Get(headerOrigin) requestedMethod = req.Header.Get(headerRequestMethod) requestedHeaders = req.Header.Get(headerRequestHeaders) // additional headers to be added // to the response. headers map[string]string ) if req.Method == "OPTIONS" && (requestedMethod != "" || requestedHeaders != "") { // TODO: if preflight, respond with exact headers if allowed headers = opts.PreflightHeader(origin, requestedMethod, requestedHeaders) } else { headers = opts.Header(origin) } for key, value := range headers { res.Header().Set(key, value) } } }
go
func Allow(opts *Options) http.HandlerFunc { return func(res http.ResponseWriter, req *http.Request) { var ( origin = req.Header.Get(headerOrigin) requestedMethod = req.Header.Get(headerRequestMethod) requestedHeaders = req.Header.Get(headerRequestHeaders) // additional headers to be added // to the response. headers map[string]string ) if req.Method == "OPTIONS" && (requestedMethod != "" || requestedHeaders != "") { // TODO: if preflight, respond with exact headers if allowed headers = opts.PreflightHeader(origin, requestedMethod, requestedHeaders) } else { headers = opts.Header(origin) } for key, value := range headers { res.Header().Set(key, value) } } }
[ "func", "Allow", "(", "opts", "*", "Options", ")", "http", ".", "HandlerFunc", "{", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "var", "(", "origin", "=", "req", ".", "Header", ".", "Get", "(", "headerOrigin", ")", "\n", "requestedMethod", "=", "req", ".", "Header", ".", "Get", "(", "headerRequestMethod", ")", "\n", "requestedHeaders", "=", "req", ".", "Header", ".", "Get", "(", "headerRequestHeaders", ")", "\n", "headers", "map", "[", "string", "]", "string", "\n", ")", "\n", "if", "req", ".", "Method", "==", "\"OPTIONS\"", "&&", "(", "requestedMethod", "!=", "\"\"", "||", "requestedHeaders", "!=", "\"\"", ")", "{", "headers", "=", "opts", ".", "PreflightHeader", "(", "origin", ",", "requestedMethod", ",", "requestedHeaders", ")", "\n", "}", "else", "{", "headers", "=", "opts", ".", "Header", "(", "origin", ")", "\n", "}", "\n", "for", "key", ",", "value", ":=", "range", "headers", "{", "res", ".", "Header", "(", ")", ".", "Set", "(", "key", ",", "value", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Allows CORS for requests those match the provided options.
[ "Allows", "CORS", "for", "requests", "those", "match", "the", "provided", "options", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/cors/cors.go#L140-L163
test
codegangsta/martini-contrib
render/render.go
Renderer
func Renderer(options ...Options) martini.Handler { opt := prepareOptions(options) cs := prepareCharset(opt.Charset) t := compile(opt) return func(res http.ResponseWriter, req *http.Request, c martini.Context) { // recompile for easy development if martini.Env == martini.Dev { t = compile(opt) } tc, _ := t.Clone() c.MapTo(&renderer{res, req, tc, opt, cs}, (*Render)(nil)) } }
go
func Renderer(options ...Options) martini.Handler { opt := prepareOptions(options) cs := prepareCharset(opt.Charset) t := compile(opt) return func(res http.ResponseWriter, req *http.Request, c martini.Context) { // recompile for easy development if martini.Env == martini.Dev { t = compile(opt) } tc, _ := t.Clone() c.MapTo(&renderer{res, req, tc, opt, cs}, (*Render)(nil)) } }
[ "func", "Renderer", "(", "options", "...", "Options", ")", "martini", ".", "Handler", "{", "opt", ":=", "prepareOptions", "(", "options", ")", "\n", "cs", ":=", "prepareCharset", "(", "opt", ".", "Charset", ")", "\n", "t", ":=", "compile", "(", "opt", ")", "\n", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "c", "martini", ".", "Context", ")", "{", "if", "martini", ".", "Env", "==", "martini", ".", "Dev", "{", "t", "=", "compile", "(", "opt", ")", "\n", "}", "\n", "tc", ",", "_", ":=", "t", ".", "Clone", "(", ")", "\n", "c", ".", "MapTo", "(", "&", "renderer", "{", "res", ",", "req", ",", "tc", ",", "opt", ",", "cs", "}", ",", "(", "*", "Render", ")", "(", "nil", ")", ")", "\n", "}", "\n", "}" ]
// Renderer is a Middleware that maps a render.Render service into the Martini handler chain. An single variadic render.Options // struct can be optionally provided to configure HTML rendering. The default directory for templates is "templates" and the default // file extension is ".tmpl". // // If MARTINI_ENV is set to "" or "development" then templates will be recompiled on every request. For more performance, set the // MARTINI_ENV environment variable to "production"
[ "Renderer", "is", "a", "Middleware", "that", "maps", "a", "render", ".", "Render", "service", "into", "the", "Martini", "handler", "chain", ".", "An", "single", "variadic", "render", ".", "Options", "struct", "can", "be", "optionally", "provided", "to", "configure", "HTML", "rendering", ".", "The", "default", "directory", "for", "templates", "is", "templates", "and", "the", "default", "file", "extension", "is", ".", "tmpl", ".", "If", "MARTINI_ENV", "is", "set", "to", "or", "development", "then", "templates", "will", "be", "recompiled", "on", "every", "request", ".", "For", "more", "performance", "set", "the", "MARTINI_ENV", "environment", "variable", "to", "production" ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/render/render.go#L107-L119
test
codegangsta/martini-contrib
acceptlang/handler.go
String
func (al AcceptLanguages) String() string { output := bytes.NewBufferString("") for i, language := range al { output.WriteString(fmt.Sprintf("%s (%1.1f)", language.Language, language.Quality)) if i != len(al)-1 { output.WriteString(", ") } } if output.Len() == 0 { output.WriteString("[]") } return output.String() }
go
func (al AcceptLanguages) String() string { output := bytes.NewBufferString("") for i, language := range al { output.WriteString(fmt.Sprintf("%s (%1.1f)", language.Language, language.Quality)) if i != len(al)-1 { output.WriteString(", ") } } if output.Len() == 0 { output.WriteString("[]") } return output.String() }
[ "func", "(", "al", "AcceptLanguages", ")", "String", "(", ")", "string", "{", "output", ":=", "bytes", ".", "NewBufferString", "(", "\"\"", ")", "\n", "for", "i", ",", "language", ":=", "range", "al", "{", "output", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"%s (%1.1f)\"", ",", "language", ".", "Language", ",", "language", ".", "Quality", ")", ")", "\n", "if", "i", "!=", "len", "(", "al", ")", "-", "1", "{", "output", ".", "WriteString", "(", "\", \"", ")", "\n", "}", "\n", "}", "\n", "if", "output", ".", "Len", "(", ")", "==", "0", "{", "output", ".", "WriteString", "(", "\"[]\"", ")", "\n", "}", "\n", "return", "output", ".", "String", "(", ")", "\n", "}" ]
// Returns the parsed languages in a human readable fashion.
[ "Returns", "the", "parsed", "languages", "in", "a", "human", "readable", "fashion", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/acceptlang/handler.go#L52-L66
test
codegangsta/martini-contrib
acceptlang/handler.go
Languages
func Languages() martini.Handler { return func(context martini.Context, request *http.Request) { header := request.Header.Get(acceptLanguageHeader) if header != "" { acceptLanguageHeaderValues := strings.Split(header, ",") acceptLanguages := make(AcceptLanguages, len(acceptLanguageHeaderValues)) for i, languageRange := range acceptLanguageHeaderValues { // Check if a given range is qualified or not if qualifiedRange := strings.Split(languageRange, ";q="); len(qualifiedRange) == 2 { quality, error := strconv.ParseFloat(qualifiedRange[1], 32) if error != nil { // When the quality is unparseable, assume it's 1 acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), 1} } else { acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), float32(quality)} } } else { acceptLanguages[i] = AcceptLanguage{trimLanguage(languageRange), 1} } } sort.Sort(acceptLanguages) context.Map(acceptLanguages) } else { // If we have no Accept-Language header just map an empty slice context.Map(make(AcceptLanguages, 0)) } } }
go
func Languages() martini.Handler { return func(context martini.Context, request *http.Request) { header := request.Header.Get(acceptLanguageHeader) if header != "" { acceptLanguageHeaderValues := strings.Split(header, ",") acceptLanguages := make(AcceptLanguages, len(acceptLanguageHeaderValues)) for i, languageRange := range acceptLanguageHeaderValues { // Check if a given range is qualified or not if qualifiedRange := strings.Split(languageRange, ";q="); len(qualifiedRange) == 2 { quality, error := strconv.ParseFloat(qualifiedRange[1], 32) if error != nil { // When the quality is unparseable, assume it's 1 acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), 1} } else { acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), float32(quality)} } } else { acceptLanguages[i] = AcceptLanguage{trimLanguage(languageRange), 1} } } sort.Sort(acceptLanguages) context.Map(acceptLanguages) } else { // If we have no Accept-Language header just map an empty slice context.Map(make(AcceptLanguages, 0)) } } }
[ "func", "Languages", "(", ")", "martini", ".", "Handler", "{", "return", "func", "(", "context", "martini", ".", "Context", ",", "request", "*", "http", ".", "Request", ")", "{", "header", ":=", "request", ".", "Header", ".", "Get", "(", "acceptLanguageHeader", ")", "\n", "if", "header", "!=", "\"\"", "{", "acceptLanguageHeaderValues", ":=", "strings", ".", "Split", "(", "header", ",", "\",\"", ")", "\n", "acceptLanguages", ":=", "make", "(", "AcceptLanguages", ",", "len", "(", "acceptLanguageHeaderValues", ")", ")", "\n", "for", "i", ",", "languageRange", ":=", "range", "acceptLanguageHeaderValues", "{", "if", "qualifiedRange", ":=", "strings", ".", "Split", "(", "languageRange", ",", "\";q=\"", ")", ";", "len", "(", "qualifiedRange", ")", "==", "2", "{", "quality", ",", "error", ":=", "strconv", ".", "ParseFloat", "(", "qualifiedRange", "[", "1", "]", ",", "32", ")", "\n", "if", "error", "!=", "nil", "{", "acceptLanguages", "[", "i", "]", "=", "AcceptLanguage", "{", "trimLanguage", "(", "qualifiedRange", "[", "0", "]", ")", ",", "1", "}", "\n", "}", "else", "{", "acceptLanguages", "[", "i", "]", "=", "AcceptLanguage", "{", "trimLanguage", "(", "qualifiedRange", "[", "0", "]", ")", ",", "float32", "(", "quality", ")", "}", "\n", "}", "\n", "}", "else", "{", "acceptLanguages", "[", "i", "]", "=", "AcceptLanguage", "{", "trimLanguage", "(", "languageRange", ")", ",", "1", "}", "\n", "}", "\n", "}", "\n", "sort", ".", "Sort", "(", "acceptLanguages", ")", "\n", "context", ".", "Map", "(", "acceptLanguages", ")", "\n", "}", "else", "{", "context", ".", "Map", "(", "make", "(", "AcceptLanguages", ",", "0", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Creates a new handler that parses the Accept-Language HTTP header. // // The parsed structure is a slice of Accept-Language values stored in an // AcceptLanguages instance, sorted based on the language qualifier.
[ "Creates", "a", "new", "handler", "that", "parses", "the", "Accept", "-", "Language", "HTTP", "header", ".", "The", "parsed", "structure", "is", "a", "slice", "of", "Accept", "-", "Language", "values", "stored", "in", "an", "AcceptLanguages", "instance", "sorted", "based", "on", "the", "language", "qualifier", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/acceptlang/handler.go#L72-L101
test
codegangsta/martini-contrib
strip/prefix.go
Prefix
func Prefix(prefix string) martini.Handler { return func(w http.ResponseWriter, r *http.Request) { if prefix == "" { return } if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { r.URL.Path = p } else { http.NotFound(w, r) } } }
go
func Prefix(prefix string) martini.Handler { return func(w http.ResponseWriter, r *http.Request) { if prefix == "" { return } if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { r.URL.Path = p } else { http.NotFound(w, r) } } }
[ "func", "Prefix", "(", "prefix", "string", ")", "martini", ".", "Handler", "{", "return", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "prefix", "==", "\"\"", "{", "return", "\n", "}", "\n", "if", "p", ":=", "strings", ".", "TrimPrefix", "(", "r", ".", "URL", ".", "Path", ",", "prefix", ")", ";", "len", "(", "p", ")", "<", "len", "(", "r", ".", "URL", ".", "Path", ")", "{", "r", ".", "URL", ".", "Path", "=", "p", "\n", "}", "else", "{", "http", ".", "NotFound", "(", "w", ",", "r", ")", "\n", "}", "\n", "}", "\n", "}" ]
// strip Prefix for every incoming http request
[ "strip", "Prefix", "for", "every", "incoming", "http", "request" ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/strip/prefix.go#L12-L23
test
codegangsta/martini-contrib
auth/basic.go
Basic
func Basic(username string, password string) http.HandlerFunc { var siteAuth = base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) return func(res http.ResponseWriter, req *http.Request) { auth := req.Header.Get("Authorization") if !SecureCompare(auth, "Basic "+siteAuth) { res.Header().Set("WWW-Authenticate", "Basic realm=\"Authorization Required\"") http.Error(res, "Not Authorized", http.StatusUnauthorized) } } }
go
func Basic(username string, password string) http.HandlerFunc { var siteAuth = base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) return func(res http.ResponseWriter, req *http.Request) { auth := req.Header.Get("Authorization") if !SecureCompare(auth, "Basic "+siteAuth) { res.Header().Set("WWW-Authenticate", "Basic realm=\"Authorization Required\"") http.Error(res, "Not Authorized", http.StatusUnauthorized) } } }
[ "func", "Basic", "(", "username", "string", ",", "password", "string", ")", "http", ".", "HandlerFunc", "{", "var", "siteAuth", "=", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "[", "]", "byte", "(", "username", "+", "\":\"", "+", "password", ")", ")", "\n", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "auth", ":=", "req", ".", "Header", ".", "Get", "(", "\"Authorization\"", ")", "\n", "if", "!", "SecureCompare", "(", "auth", ",", "\"Basic \"", "+", "siteAuth", ")", "{", "res", ".", "Header", "(", ")", ".", "Set", "(", "\"WWW-Authenticate\"", ",", "\"Basic realm=\\\"Authorization Required\\\"\"", ")", "\n", "\\\"", "\n", "}", "\n", "}", "\n", "}" ]
// Basic returns a Handler that authenticates via Basic Auth. Writes a http.StatusUnauthorized // if authentication fails
[ "Basic", "returns", "a", "Handler", "that", "authenticates", "via", "Basic", "Auth", ".", "Writes", "a", "http", ".", "StatusUnauthorized", "if", "authentication", "fails" ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/auth/basic.go#L10-L19
test
codegangsta/martini-contrib
sessionauth/login.go
UpdateUser
func UpdateUser(s sessions.Session, user User) error { s.Set(SessionKey, user.UniqueId()) return nil }
go
func UpdateUser(s sessions.Session, user User) error { s.Set(SessionKey, user.UniqueId()) return nil }
[ "func", "UpdateUser", "(", "s", "sessions", ".", "Session", ",", "user", "User", ")", "error", "{", "s", ".", "Set", "(", "SessionKey", ",", "user", ".", "UniqueId", "(", ")", ")", "\n", "return", "nil", "\n", "}" ]
// UpdateUser updates the User object stored in the session. This is useful incase a change // is made to the user model that needs to persist across requests.
[ "UpdateUser", "updates", "the", "User", "object", "stored", "in", "the", "session", ".", "This", "is", "useful", "incase", "a", "change", "is", "made", "to", "the", "user", "model", "that", "needs", "to", "persist", "across", "requests", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/sessionauth/login.go#L101-L104
test
codegangsta/martini-contrib
sessionauth/example/user.go
GetById
func (u *MyUserModel) GetById(id interface{}) error { err := dbmap.SelectOne(u, "SELECT * FROM users WHERE id = $1", id) if err != nil { return err } return nil }
go
func (u *MyUserModel) GetById(id interface{}) error { err := dbmap.SelectOne(u, "SELECT * FROM users WHERE id = $1", id) if err != nil { return err } return nil }
[ "func", "(", "u", "*", "MyUserModel", ")", "GetById", "(", "id", "interface", "{", "}", ")", "error", "{", "err", ":=", "dbmap", ".", "SelectOne", "(", "u", ",", "\"SELECT * FROM users WHERE id = $1\"", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetById will populate a user object from a database model with // a matching id.
[ "GetById", "will", "populate", "a", "user", "object", "from", "a", "database", "model", "with", "a", "matching", "id", "." ]
8ce6181c2609699e4c7cd30994b76a850a9cdadc
https://github.com/codegangsta/martini-contrib/blob/8ce6181c2609699e4c7cd30994b76a850a9cdadc/sessionauth/example/user.go#L48-L55
test
stellar/go-stellar-base
main.go
AddressToAccountId
func AddressToAccountId(address string) (result xdr.AccountId, err error) { bytes, err := strkey.Decode(strkey.VersionByteAccountID, address) if err != nil { return } var raw xdr.Uint256 copy(raw[:], bytes) pk, err := xdr.NewPublicKey(xdr.CryptoKeyTypeKeyTypeEd25519, raw) if err != nil { return } result = xdr.AccountId(pk) return }
go
func AddressToAccountId(address string) (result xdr.AccountId, err error) { bytes, err := strkey.Decode(strkey.VersionByteAccountID, address) if err != nil { return } var raw xdr.Uint256 copy(raw[:], bytes) pk, err := xdr.NewPublicKey(xdr.CryptoKeyTypeKeyTypeEd25519, raw) if err != nil { return } result = xdr.AccountId(pk) return }
[ "func", "AddressToAccountId", "(", "address", "string", ")", "(", "result", "xdr", ".", "AccountId", ",", "err", "error", ")", "{", "bytes", ",", "err", ":=", "strkey", ".", "Decode", "(", "strkey", ".", "VersionByteAccountID", ",", "address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "raw", "xdr", ".", "Uint256", "\n", "copy", "(", "raw", "[", ":", "]", ",", "bytes", ")", "\n", "pk", ",", "err", ":=", "xdr", ".", "NewPublicKey", "(", "xdr", ".", "CryptoKeyTypeKeyTypeEd25519", ",", "raw", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "result", "=", "xdr", ".", "AccountId", "(", "pk", ")", "\n", "return", "\n", "}" ]
// AddressToAccountId converts the provided address into a xdr.AccountId
[ "AddressToAccountId", "converts", "the", "provided", "address", "into", "a", "xdr", ".", "AccountId" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/main.go#L16-L34
test
stellar/go-stellar-base
build/change_trust.go
MutateChangeTrust
func (m Asset) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) { if m.Native { return errors.New("Native asset not allowed") } o.Line, err = m.ToXdrObject() return }
go
func (m Asset) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) { if m.Native { return errors.New("Native asset not allowed") } o.Line, err = m.ToXdrObject() return }
[ "func", "(", "m", "Asset", ")", "MutateChangeTrust", "(", "o", "*", "xdr", ".", "ChangeTrustOp", ")", "(", "err", "error", ")", "{", "if", "m", ".", "Native", "{", "return", "errors", ".", "New", "(", "\"Native asset not allowed\"", ")", "\n", "}", "\n", "o", ".", "Line", ",", "err", "=", "m", ".", "ToXdrObject", "(", ")", "\n", "return", "\n", "}" ]
// MutateChangeTrust for Asset sets the ChangeTrustOp's Line field
[ "MutateChangeTrust", "for", "Asset", "sets", "the", "ChangeTrustOp", "s", "Line", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/change_trust.go#L51-L58
test
stellar/go-stellar-base
build/change_trust.go
MutateChangeTrust
func (m Limit) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) { o.Limit, err = amount.Parse(string(m)) return }
go
func (m Limit) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) { o.Limit, err = amount.Parse(string(m)) return }
[ "func", "(", "m", "Limit", ")", "MutateChangeTrust", "(", "o", "*", "xdr", ".", "ChangeTrustOp", ")", "(", "err", "error", ")", "{", "o", ".", "Limit", ",", "err", "=", "amount", ".", "Parse", "(", "string", "(", "m", ")", ")", "\n", "return", "\n", "}" ]
// MutateChangeTrust for Limit sets the ChangeTrustOp's Limit field
[ "MutateChangeTrust", "for", "Limit", "sets", "the", "ChangeTrustOp", "s", "Limit", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/change_trust.go#L61-L64
test
stellar/go-stellar-base
build/change_trust.go
Trust
func Trust(code, issuer string, args ...interface{}) (result ChangeTrustBuilder) { mutators := []interface{}{ CreditAsset(code, issuer), } limitSet := false for _, mut := range args { mutators = append(mutators, mut) _, isLimit := mut.(Limit) if isLimit { limitSet = true } } if !limitSet { mutators = append(mutators, MaxLimit) } return ChangeTrust(mutators...) }
go
func Trust(code, issuer string, args ...interface{}) (result ChangeTrustBuilder) { mutators := []interface{}{ CreditAsset(code, issuer), } limitSet := false for _, mut := range args { mutators = append(mutators, mut) _, isLimit := mut.(Limit) if isLimit { limitSet = true } } if !limitSet { mutators = append(mutators, MaxLimit) } return ChangeTrust(mutators...) }
[ "func", "Trust", "(", "code", ",", "issuer", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "result", "ChangeTrustBuilder", ")", "{", "mutators", ":=", "[", "]", "interface", "{", "}", "{", "CreditAsset", "(", "code", ",", "issuer", ")", ",", "}", "\n", "limitSet", ":=", "false", "\n", "for", "_", ",", "mut", ":=", "range", "args", "{", "mutators", "=", "append", "(", "mutators", ",", "mut", ")", "\n", "_", ",", "isLimit", ":=", "mut", ".", "(", "Limit", ")", "\n", "if", "isLimit", "{", "limitSet", "=", "true", "\n", "}", "\n", "}", "\n", "if", "!", "limitSet", "{", "mutators", "=", "append", "(", "mutators", ",", "MaxLimit", ")", "\n", "}", "\n", "return", "ChangeTrust", "(", "mutators", "...", ")", "\n", "}" ]
// Trust is a helper that creates ChangeTrustBuilder
[ "Trust", "is", "a", "helper", "that", "creates", "ChangeTrustBuilder" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/change_trust.go#L67-L87
test
stellar/go-stellar-base
build/change_trust.go
RemoveTrust
func RemoveTrust(code, issuer string, args ...interface{}) (result ChangeTrustBuilder) { mutators := []interface{}{ CreditAsset(code, issuer), Limit("0"), } for _, mut := range args { mutators = append(mutators, mut) } return ChangeTrust(mutators...) }
go
func RemoveTrust(code, issuer string, args ...interface{}) (result ChangeTrustBuilder) { mutators := []interface{}{ CreditAsset(code, issuer), Limit("0"), } for _, mut := range args { mutators = append(mutators, mut) } return ChangeTrust(mutators...) }
[ "func", "RemoveTrust", "(", "code", ",", "issuer", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "result", "ChangeTrustBuilder", ")", "{", "mutators", ":=", "[", "]", "interface", "{", "}", "{", "CreditAsset", "(", "code", ",", "issuer", ")", ",", "Limit", "(", "\"0\"", ")", ",", "}", "\n", "for", "_", ",", "mut", ":=", "range", "args", "{", "mutators", "=", "append", "(", "mutators", ",", "mut", ")", "\n", "}", "\n", "return", "ChangeTrust", "(", "mutators", "...", ")", "\n", "}" ]
// RemoveTrust is a helper that creates ChangeTrustBuilder
[ "RemoveTrust", "is", "a", "helper", "that", "creates", "ChangeTrustBuilder" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/change_trust.go#L90-L101
test
stellar/go-stellar-base
build/payment.go
MutatePayment
func (m CreditAmount) MutatePayment(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.PaymentOp: o.Amount, err = amount.Parse(m.Amount) if err != nil { return } o.Asset, err = createAlphaNumAsset(m.Code, m.Issuer) case *xdr.PathPaymentOp: o.DestAmount, err = amount.Parse(m.Amount) if err != nil { return } o.DestAsset, err = createAlphaNumAsset(m.Code, m.Issuer) } return }
go
func (m CreditAmount) MutatePayment(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.PaymentOp: o.Amount, err = amount.Parse(m.Amount) if err != nil { return } o.Asset, err = createAlphaNumAsset(m.Code, m.Issuer) case *xdr.PathPaymentOp: o.DestAmount, err = amount.Parse(m.Amount) if err != nil { return } o.DestAsset, err = createAlphaNumAsset(m.Code, m.Issuer) } return }
[ "func", "(", "m", "CreditAmount", ")", "MutatePayment", "(", "o", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "switch", "o", ":=", "o", ".", "(", "type", ")", "{", "default", ":", "err", "=", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "case", "*", "xdr", ".", "PaymentOp", ":", "o", ".", "Amount", ",", "err", "=", "amount", ".", "Parse", "(", "m", ".", "Amount", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "Asset", ",", "err", "=", "createAlphaNumAsset", "(", "m", ".", "Code", ",", "m", ".", "Issuer", ")", "\n", "case", "*", "xdr", ".", "PathPaymentOp", ":", "o", ".", "DestAmount", ",", "err", "=", "amount", ".", "Parse", "(", "m", ".", "Amount", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "DestAsset", ",", "err", "=", "createAlphaNumAsset", "(", "m", ".", "Code", ",", "m", ".", "Issuer", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MutatePayment for Asset sets the PaymentOp's Asset field
[ "MutatePayment", "for", "Asset", "sets", "the", "PaymentOp", "s", "Asset", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/payment.go#L64-L84
test
stellar/go-stellar-base
build/payment.go
MutatePayment
func (m Destination) MutatePayment(o interface{}) error { switch o := o.(type) { default: return errors.New("Unexpected operation type") case *xdr.PaymentOp: return setAccountId(m.AddressOrSeed, &o.Destination) case *xdr.PathPaymentOp: return setAccountId(m.AddressOrSeed, &o.Destination) } return nil }
go
func (m Destination) MutatePayment(o interface{}) error { switch o := o.(type) { default: return errors.New("Unexpected operation type") case *xdr.PaymentOp: return setAccountId(m.AddressOrSeed, &o.Destination) case *xdr.PathPaymentOp: return setAccountId(m.AddressOrSeed, &o.Destination) } return nil }
[ "func", "(", "m", "Destination", ")", "MutatePayment", "(", "o", "interface", "{", "}", ")", "error", "{", "switch", "o", ":=", "o", ".", "(", "type", ")", "{", "default", ":", "return", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "case", "*", "xdr", ".", "PaymentOp", ":", "return", "setAccountId", "(", "m", ".", "AddressOrSeed", ",", "&", "o", ".", "Destination", ")", "\n", "case", "*", "xdr", ".", "PathPaymentOp", ":", "return", "setAccountId", "(", "m", ".", "AddressOrSeed", ",", "&", "o", ".", "Destination", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MutatePayment for Destination sets the PaymentOp's Destination field
[ "MutatePayment", "for", "Destination", "sets", "the", "PaymentOp", "s", "Destination", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/payment.go#L87-L97
test
stellar/go-stellar-base
build/payment.go
MutatePayment
func (m NativeAmount) MutatePayment(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.PaymentOp: o.Amount, err = amount.Parse(m.Amount) if err != nil { return } o.Asset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) case *xdr.PathPaymentOp: o.DestAmount, err = amount.Parse(m.Amount) if err != nil { return } o.DestAsset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) } return }
go
func (m NativeAmount) MutatePayment(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.PaymentOp: o.Amount, err = amount.Parse(m.Amount) if err != nil { return } o.Asset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) case *xdr.PathPaymentOp: o.DestAmount, err = amount.Parse(m.Amount) if err != nil { return } o.DestAsset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) } return }
[ "func", "(", "m", "NativeAmount", ")", "MutatePayment", "(", "o", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "switch", "o", ":=", "o", ".", "(", "type", ")", "{", "default", ":", "err", "=", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "case", "*", "xdr", ".", "PaymentOp", ":", "o", ".", "Amount", ",", "err", "=", "amount", ".", "Parse", "(", "m", ".", "Amount", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "Asset", ",", "err", "=", "xdr", ".", "NewAsset", "(", "xdr", ".", "AssetTypeAssetTypeNative", ",", "nil", ")", "\n", "case", "*", "xdr", ".", "PathPaymentOp", ":", "o", ".", "DestAmount", ",", "err", "=", "amount", ".", "Parse", "(", "m", ".", "Amount", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "DestAsset", ",", "err", "=", "xdr", ".", "NewAsset", "(", "xdr", ".", "AssetTypeAssetTypeNative", ",", "nil", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MutatePayment for NativeAmount sets the PaymentOp's currency field to // native and sets its amount to the provided integer
[ "MutatePayment", "for", "NativeAmount", "sets", "the", "PaymentOp", "s", "currency", "field", "to", "native", "and", "sets", "its", "amount", "to", "the", "provided", "integer" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/payment.go#L101-L121
test
stellar/go-stellar-base
build/payment.go
MutatePayment
func (m PayWithPath) MutatePayment(o interface{}) (err error) { var pathPaymentOp *xdr.PathPaymentOp var ok bool if pathPaymentOp, ok = o.(*xdr.PathPaymentOp); !ok { return errors.New("Unexpected operation type") } // MaxAmount pathPaymentOp.SendMax, err = amount.Parse(m.MaxAmount) if err != nil { return } // Path var path []xdr.Asset var xdrAsset xdr.Asset for _, asset := range m.Path { xdrAsset, err = asset.ToXdrObject() if err != nil { return err } path = append(path, xdrAsset) } pathPaymentOp.Path = path // Asset pathPaymentOp.SendAsset, err = m.Asset.ToXdrObject() return }
go
func (m PayWithPath) MutatePayment(o interface{}) (err error) { var pathPaymentOp *xdr.PathPaymentOp var ok bool if pathPaymentOp, ok = o.(*xdr.PathPaymentOp); !ok { return errors.New("Unexpected operation type") } // MaxAmount pathPaymentOp.SendMax, err = amount.Parse(m.MaxAmount) if err != nil { return } // Path var path []xdr.Asset var xdrAsset xdr.Asset for _, asset := range m.Path { xdrAsset, err = asset.ToXdrObject() if err != nil { return err } path = append(path, xdrAsset) } pathPaymentOp.Path = path // Asset pathPaymentOp.SendAsset, err = m.Asset.ToXdrObject() return }
[ "func", "(", "m", "PayWithPath", ")", "MutatePayment", "(", "o", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "var", "pathPaymentOp", "*", "xdr", ".", "PathPaymentOp", "\n", "var", "ok", "bool", "\n", "if", "pathPaymentOp", ",", "ok", "=", "o", ".", "(", "*", "xdr", ".", "PathPaymentOp", ")", ";", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "}", "\n", "pathPaymentOp", ".", "SendMax", ",", "err", "=", "amount", ".", "Parse", "(", "m", ".", "MaxAmount", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "path", "[", "]", "xdr", ".", "Asset", "\n", "var", "xdrAsset", "xdr", ".", "Asset", "\n", "for", "_", ",", "asset", ":=", "range", "m", ".", "Path", "{", "xdrAsset", ",", "err", "=", "asset", ".", "ToXdrObject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "path", "=", "append", "(", "path", ",", "xdrAsset", ")", "\n", "}", "\n", "pathPaymentOp", ".", "Path", "=", "path", "\n", "pathPaymentOp", ".", "SendAsset", ",", "err", "=", "m", ".", "Asset", ".", "ToXdrObject", "(", ")", "\n", "return", "\n", "}" ]
// MutatePayment for PayWithPath sets the PathPaymentOp's SendAsset, // SendMax and Path fields
[ "MutatePayment", "for", "PayWithPath", "sets", "the", "PathPaymentOp", "s", "SendAsset", "SendMax", "and", "Path", "fields" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/payment.go#L125-L156
test
stellar/go-stellar-base
build/account_merge.go
MutateAccountMerge
func (m Destination) MutateAccountMerge(o *AccountMergeBuilder) error { return setAccountId(m.AddressOrSeed, &o.Destination) }
go
func (m Destination) MutateAccountMerge(o *AccountMergeBuilder) error { return setAccountId(m.AddressOrSeed, &o.Destination) }
[ "func", "(", "m", "Destination", ")", "MutateAccountMerge", "(", "o", "*", "AccountMergeBuilder", ")", "error", "{", "return", "setAccountId", "(", "m", ".", "AddressOrSeed", ",", "&", "o", ".", "Destination", ")", "\n", "}" ]
// MutateAccountMerge for Destination sets the AccountMergeBuilder's Destination field
[ "MutateAccountMerge", "for", "Destination", "sets", "the", "AccountMergeBuilder", "s", "Destination", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/account_merge.go#L50-L52
test
stellar/go-stellar-base
amount/main.go
MustParse
func MustParse(v string) xdr.Int64 { ret, err := Parse(v) if err != nil { panic(err) } return ret }
go
func MustParse(v string) xdr.Int64 { ret, err := Parse(v) if err != nil { panic(err) } return ret }
[ "func", "MustParse", "(", "v", "string", ")", "xdr", ".", "Int64", "{", "ret", ",", "err", ":=", "Parse", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "ret", "\n", "}" ]
// MustParse is the panicking version of Parse
[ "MustParse", "is", "the", "panicking", "version", "of", "Parse" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/amount/main.go#L25-L31
test
stellar/go-stellar-base
amount/main.go
Parse
func Parse(v string) (xdr.Int64, error) { var f, o, r big.Rat _, ok := f.SetString(v) if !ok { return xdr.Int64(0), fmt.Errorf("cannot parse amount: %s", v) } o.SetInt64(One) r.Mul(&f, &o) is := r.FloatString(0) i, err := strconv.ParseInt(is, 10, 64) if err != nil { return xdr.Int64(0), err } return xdr.Int64(i), nil }
go
func Parse(v string) (xdr.Int64, error) { var f, o, r big.Rat _, ok := f.SetString(v) if !ok { return xdr.Int64(0), fmt.Errorf("cannot parse amount: %s", v) } o.SetInt64(One) r.Mul(&f, &o) is := r.FloatString(0) i, err := strconv.ParseInt(is, 10, 64) if err != nil { return xdr.Int64(0), err } return xdr.Int64(i), nil }
[ "func", "Parse", "(", "v", "string", ")", "(", "xdr", ".", "Int64", ",", "error", ")", "{", "var", "f", ",", "o", ",", "r", "big", ".", "Rat", "\n", "_", ",", "ok", ":=", "f", ".", "SetString", "(", "v", ")", "\n", "if", "!", "ok", "{", "return", "xdr", ".", "Int64", "(", "0", ")", ",", "fmt", ".", "Errorf", "(", "\"cannot parse amount: %s\"", ",", "v", ")", "\n", "}", "\n", "o", ".", "SetInt64", "(", "One", ")", "\n", "r", ".", "Mul", "(", "&", "f", ",", "&", "o", ")", "\n", "is", ":=", "r", ".", "FloatString", "(", "0", ")", "\n", "i", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "is", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "xdr", ".", "Int64", "(", "0", ")", ",", "err", "\n", "}", "\n", "return", "xdr", ".", "Int64", "(", "i", ")", ",", "nil", "\n", "}" ]
// Parse parses the provided as a stellar "amount", i.e. A 64-bit signed integer // that represents a decimal number with 7 digits of significance in the // fractional portion of the number.
[ "Parse", "parses", "the", "provided", "as", "a", "stellar", "amount", "i", ".", "e", ".", "A", "64", "-", "bit", "signed", "integer", "that", "represents", "a", "decimal", "number", "with", "7", "digits", "of", "significance", "in", "the", "fractional", "portion", "of", "the", "number", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/amount/main.go#L36-L53
test
stellar/go-stellar-base
amount/main.go
String
func String(v xdr.Int64) string { var f, o, r big.Rat f.SetInt64(int64(v)) o.SetInt64(One) r.Quo(&f, &o) return r.FloatString(7) }
go
func String(v xdr.Int64) string { var f, o, r big.Rat f.SetInt64(int64(v)) o.SetInt64(One) r.Quo(&f, &o) return r.FloatString(7) }
[ "func", "String", "(", "v", "xdr", ".", "Int64", ")", "string", "{", "var", "f", ",", "o", ",", "r", "big", ".", "Rat", "\n", "f", ".", "SetInt64", "(", "int64", "(", "v", ")", ")", "\n", "o", ".", "SetInt64", "(", "One", ")", "\n", "r", ".", "Quo", "(", "&", "f", ",", "&", "o", ")", "\n", "return", "r", ".", "FloatString", "(", "7", ")", "\n", "}" ]
// String returns an "amount string" from the provided raw value `v`.
[ "String", "returns", "an", "amount", "string", "from", "the", "provided", "raw", "value", "v", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/amount/main.go#L56-L64
test
stellar/go-stellar-base
build/manage_offer.go
CreateOffer
func CreateOffer(rate Rate, amount Amount) (result ManageOfferBuilder) { return ManageOffer(false, rate, amount) }
go
func CreateOffer(rate Rate, amount Amount) (result ManageOfferBuilder) { return ManageOffer(false, rate, amount) }
[ "func", "CreateOffer", "(", "rate", "Rate", ",", "amount", "Amount", ")", "(", "result", "ManageOfferBuilder", ")", "{", "return", "ManageOffer", "(", "false", ",", "rate", ",", "amount", ")", "\n", "}" ]
// CreateOffer creates a new offer
[ "CreateOffer", "creates", "a", "new", "offer" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L12-L14
test
stellar/go-stellar-base
build/manage_offer.go
CreatePassiveOffer
func CreatePassiveOffer(rate Rate, amount Amount) (result ManageOfferBuilder) { return ManageOffer(true, rate, amount) }
go
func CreatePassiveOffer(rate Rate, amount Amount) (result ManageOfferBuilder) { return ManageOffer(true, rate, amount) }
[ "func", "CreatePassiveOffer", "(", "rate", "Rate", ",", "amount", "Amount", ")", "(", "result", "ManageOfferBuilder", ")", "{", "return", "ManageOffer", "(", "true", ",", "rate", ",", "amount", ")", "\n", "}" ]
// CreatePassiveOffer creates a new passive offer
[ "CreatePassiveOffer", "creates", "a", "new", "passive", "offer" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L17-L19
test
stellar/go-stellar-base
build/manage_offer.go
UpdateOffer
func UpdateOffer(rate Rate, amount Amount, offerID OfferID) (result ManageOfferBuilder) { return ManageOffer(false, rate, amount, offerID) }
go
func UpdateOffer(rate Rate, amount Amount, offerID OfferID) (result ManageOfferBuilder) { return ManageOffer(false, rate, amount, offerID) }
[ "func", "UpdateOffer", "(", "rate", "Rate", ",", "amount", "Amount", ",", "offerID", "OfferID", ")", "(", "result", "ManageOfferBuilder", ")", "{", "return", "ManageOffer", "(", "false", ",", "rate", ",", "amount", ",", "offerID", ")", "\n", "}" ]
// UpdateOffer updates an existing offer
[ "UpdateOffer", "updates", "an", "existing", "offer" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L22-L24
test
stellar/go-stellar-base
build/manage_offer.go
DeleteOffer
func DeleteOffer(rate Rate, offerID OfferID) (result ManageOfferBuilder) { return ManageOffer(false, rate, Amount("0"), offerID) }
go
func DeleteOffer(rate Rate, offerID OfferID) (result ManageOfferBuilder) { return ManageOffer(false, rate, Amount("0"), offerID) }
[ "func", "DeleteOffer", "(", "rate", "Rate", ",", "offerID", "OfferID", ")", "(", "result", "ManageOfferBuilder", ")", "{", "return", "ManageOffer", "(", "false", ",", "rate", ",", "Amount", "(", "\"0\"", ")", ",", "offerID", ")", "\n", "}" ]
// DeleteOffer deletes an existing offer
[ "DeleteOffer", "deletes", "an", "existing", "offer" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L27-L29
test
stellar/go-stellar-base
build/manage_offer.go
ManageOffer
func ManageOffer(passiveOffer bool, muts ...interface{}) (result ManageOfferBuilder) { result.PassiveOffer = passiveOffer result.Mutate(muts...) return }
go
func ManageOffer(passiveOffer bool, muts ...interface{}) (result ManageOfferBuilder) { result.PassiveOffer = passiveOffer result.Mutate(muts...) return }
[ "func", "ManageOffer", "(", "passiveOffer", "bool", ",", "muts", "...", "interface", "{", "}", ")", "(", "result", "ManageOfferBuilder", ")", "{", "result", ".", "PassiveOffer", "=", "passiveOffer", "\n", "result", ".", "Mutate", "(", "muts", "...", ")", "\n", "return", "\n", "}" ]
// ManageOffer groups the creation of a new ManageOfferBuilder with a call to Mutate.
[ "ManageOffer", "groups", "the", "creation", "of", "a", "new", "ManageOfferBuilder", "with", "a", "call", "to", "Mutate", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L32-L36
test
stellar/go-stellar-base
build/manage_offer.go
Mutate
func (b *ManageOfferBuilder) Mutate(muts ...interface{}) { for _, m := range muts { var err error switch mut := m.(type) { case ManageOfferMutator: if b.PassiveOffer { err = mut.MutateManageOffer(&b.PO) } else { err = mut.MutateManageOffer(&b.MO) } case OperationMutator: err = mut.MutateOperation(&b.O) default: err = errors.New("Mutator type not allowed") } if err != nil { b.Err = err return } } }
go
func (b *ManageOfferBuilder) Mutate(muts ...interface{}) { for _, m := range muts { var err error switch mut := m.(type) { case ManageOfferMutator: if b.PassiveOffer { err = mut.MutateManageOffer(&b.PO) } else { err = mut.MutateManageOffer(&b.MO) } case OperationMutator: err = mut.MutateOperation(&b.O) default: err = errors.New("Mutator type not allowed") } if err != nil { b.Err = err return } } }
[ "func", "(", "b", "*", "ManageOfferBuilder", ")", "Mutate", "(", "muts", "...", "interface", "{", "}", ")", "{", "for", "_", ",", "m", ":=", "range", "muts", "{", "var", "err", "error", "\n", "switch", "mut", ":=", "m", ".", "(", "type", ")", "{", "case", "ManageOfferMutator", ":", "if", "b", ".", "PassiveOffer", "{", "err", "=", "mut", ".", "MutateManageOffer", "(", "&", "b", ".", "PO", ")", "\n", "}", "else", "{", "err", "=", "mut", ".", "MutateManageOffer", "(", "&", "b", ".", "MO", ")", "\n", "}", "\n", "case", "OperationMutator", ":", "err", "=", "mut", ".", "MutateOperation", "(", "&", "b", ".", "O", ")", "\n", "default", ":", "err", "=", "errors", ".", "New", "(", "\"Mutator type not allowed\"", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "b", ".", "Err", "=", "err", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Mutate applies the provided mutators to this builder's offer or operation.
[ "Mutate", "applies", "the", "provided", "mutators", "to", "this", "builder", "s", "offer", "or", "operation", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L55-L76
test
stellar/go-stellar-base
build/manage_offer.go
MutateManageOffer
func (m Amount) MutateManageOffer(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.ManageOfferOp: o.Amount, err = amount.Parse(string(m)) case *xdr.CreatePassiveOfferOp: o.Amount, err = amount.Parse(string(m)) } return }
go
func (m Amount) MutateManageOffer(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.ManageOfferOp: o.Amount, err = amount.Parse(string(m)) case *xdr.CreatePassiveOfferOp: o.Amount, err = amount.Parse(string(m)) } return }
[ "func", "(", "m", "Amount", ")", "MutateManageOffer", "(", "o", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "switch", "o", ":=", "o", ".", "(", "type", ")", "{", "default", ":", "err", "=", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "case", "*", "xdr", ".", "ManageOfferOp", ":", "o", ".", "Amount", ",", "err", "=", "amount", ".", "Parse", "(", "string", "(", "m", ")", ")", "\n", "case", "*", "xdr", ".", "CreatePassiveOfferOp", ":", "o", ".", "Amount", ",", "err", "=", "amount", ".", "Parse", "(", "string", "(", "m", ")", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MutateManageOffer for Amount sets the ManageOfferOp's Amount field
[ "MutateManageOffer", "for", "Amount", "sets", "the", "ManageOfferOp", "s", "Amount", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L79-L89
test
stellar/go-stellar-base
build/manage_offer.go
MutateManageOffer
func (m OfferID) MutateManageOffer(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.ManageOfferOp: o.OfferId = xdr.Uint64(m) } return }
go
func (m OfferID) MutateManageOffer(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.ManageOfferOp: o.OfferId = xdr.Uint64(m) } return }
[ "func", "(", "m", "OfferID", ")", "MutateManageOffer", "(", "o", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "switch", "o", ":=", "o", ".", "(", "type", ")", "{", "default", ":", "err", "=", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "case", "*", "xdr", ".", "ManageOfferOp", ":", "o", ".", "OfferId", "=", "xdr", ".", "Uint64", "(", "m", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MutateManageOffer for OfferID sets the ManageOfferOp's OfferID field
[ "MutateManageOffer", "for", "OfferID", "sets", "the", "ManageOfferOp", "s", "OfferID", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L92-L100
test
stellar/go-stellar-base
build/manage_offer.go
MutateManageOffer
func (m Rate) MutateManageOffer(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.ManageOfferOp: o.Selling, err = m.Selling.ToXdrObject() if err != nil { return } o.Buying, err = m.Buying.ToXdrObject() if err != nil { return } o.Price, err = price.Parse(string(m.Price)) case *xdr.CreatePassiveOfferOp: o.Selling, err = m.Selling.ToXdrObject() if err != nil { return } o.Buying, err = m.Buying.ToXdrObject() if err != nil { return } o.Price, err = price.Parse(string(m.Price)) } return }
go
func (m Rate) MutateManageOffer(o interface{}) (err error) { switch o := o.(type) { default: err = errors.New("Unexpected operation type") case *xdr.ManageOfferOp: o.Selling, err = m.Selling.ToXdrObject() if err != nil { return } o.Buying, err = m.Buying.ToXdrObject() if err != nil { return } o.Price, err = price.Parse(string(m.Price)) case *xdr.CreatePassiveOfferOp: o.Selling, err = m.Selling.ToXdrObject() if err != nil { return } o.Buying, err = m.Buying.ToXdrObject() if err != nil { return } o.Price, err = price.Parse(string(m.Price)) } return }
[ "func", "(", "m", "Rate", ")", "MutateManageOffer", "(", "o", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "switch", "o", ":=", "o", ".", "(", "type", ")", "{", "default", ":", "err", "=", "errors", ".", "New", "(", "\"Unexpected operation type\"", ")", "\n", "case", "*", "xdr", ".", "ManageOfferOp", ":", "o", ".", "Selling", ",", "err", "=", "m", ".", "Selling", ".", "ToXdrObject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "Buying", ",", "err", "=", "m", ".", "Buying", ".", "ToXdrObject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "Price", ",", "err", "=", "price", ".", "Parse", "(", "string", "(", "m", ".", "Price", ")", ")", "\n", "case", "*", "xdr", ".", "CreatePassiveOfferOp", ":", "o", ".", "Selling", ",", "err", "=", "m", ".", "Selling", ".", "ToXdrObject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "Buying", ",", "err", "=", "m", ".", "Buying", ".", "ToXdrObject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "o", ".", "Price", ",", "err", "=", "price", ".", "Parse", "(", "string", "(", "m", ".", "Price", ")", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MutateManageOffer for Rate sets the ManageOfferOp's selling, buying and price fields
[ "MutateManageOffer", "for", "Rate", "sets", "the", "ManageOfferOp", "s", "selling", "buying", "and", "price", "fields" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/manage_offer.go#L103-L133
test
stellar/go-stellar-base
build/operation.go
MutateOperation
func (m SourceAccount) MutateOperation(o *xdr.Operation) error { o.SourceAccount = &xdr.AccountId{} return setAccountId(m.AddressOrSeed, o.SourceAccount) }
go
func (m SourceAccount) MutateOperation(o *xdr.Operation) error { o.SourceAccount = &xdr.AccountId{} return setAccountId(m.AddressOrSeed, o.SourceAccount) }
[ "func", "(", "m", "SourceAccount", ")", "MutateOperation", "(", "o", "*", "xdr", ".", "Operation", ")", "error", "{", "o", ".", "SourceAccount", "=", "&", "xdr", ".", "AccountId", "{", "}", "\n", "return", "setAccountId", "(", "m", ".", "AddressOrSeed", ",", "o", ".", "SourceAccount", ")", "\n", "}" ]
// MutateOperation for SourceAccount sets the operation's SourceAccount // to the pubilic key for the address provided
[ "MutateOperation", "for", "SourceAccount", "sets", "the", "operation", "s", "SourceAccount", "to", "the", "pubilic", "key", "for", "the", "address", "provided" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/operation.go#L16-L19
test
stellar/go-stellar-base
xdr/price.go
String
func (p *Price) String() string { return big.NewRat(int64(p.N), int64(p.D)).FloatString(7) }
go
func (p *Price) String() string { return big.NewRat(int64(p.N), int64(p.D)).FloatString(7) }
[ "func", "(", "p", "*", "Price", ")", "String", "(", ")", "string", "{", "return", "big", ".", "NewRat", "(", "int64", "(", "p", ".", "N", ")", ",", "int64", "(", "p", ".", "D", ")", ")", ".", "FloatString", "(", "7", ")", "\n", "}" ]
// String returns a string represenation of `p`
[ "String", "returns", "a", "string", "represenation", "of", "p" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/price.go#L8-L10
test
stellar/go-stellar-base
build/transaction.go
Transaction
func Transaction(muts ...TransactionMutator) (result *TransactionBuilder) { result = &TransactionBuilder{} result.Mutate(muts...) result.Mutate(Defaults{}) return }
go
func Transaction(muts ...TransactionMutator) (result *TransactionBuilder) { result = &TransactionBuilder{} result.Mutate(muts...) result.Mutate(Defaults{}) return }
[ "func", "Transaction", "(", "muts", "...", "TransactionMutator", ")", "(", "result", "*", "TransactionBuilder", ")", "{", "result", "=", "&", "TransactionBuilder", "{", "}", "\n", "result", ".", "Mutate", "(", "muts", "...", ")", "\n", "result", ".", "Mutate", "(", "Defaults", "{", "}", ")", "\n", "return", "\n", "}" ]
// Transaction groups the creation of a new TransactionBuilder with a call // to Mutate.
[ "Transaction", "groups", "the", "creation", "of", "a", "new", "TransactionBuilder", "with", "a", "call", "to", "Mutate", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L15-L20
test
stellar/go-stellar-base
build/transaction.go
Mutate
func (b *TransactionBuilder) Mutate(muts ...TransactionMutator) { if b.TX == nil { b.TX = &xdr.Transaction{} } for _, m := range muts { err := m.MutateTransaction(b) if err != nil { b.Err = err return } } }
go
func (b *TransactionBuilder) Mutate(muts ...TransactionMutator) { if b.TX == nil { b.TX = &xdr.Transaction{} } for _, m := range muts { err := m.MutateTransaction(b) if err != nil { b.Err = err return } } }
[ "func", "(", "b", "*", "TransactionBuilder", ")", "Mutate", "(", "muts", "...", "TransactionMutator", ")", "{", "if", "b", ".", "TX", "==", "nil", "{", "b", ".", "TX", "=", "&", "xdr", ".", "Transaction", "{", "}", "\n", "}", "\n", "for", "_", ",", "m", ":=", "range", "muts", "{", "err", ":=", "m", ".", "MutateTransaction", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "b", ".", "Err", "=", "err", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Mutate applies the provided TransactionMutators to this builder's transaction
[ "Mutate", "applies", "the", "provided", "TransactionMutators", "to", "this", "builder", "s", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L37-L49
test
stellar/go-stellar-base
build/transaction.go
Hash
func (b *TransactionBuilder) Hash() ([32]byte, error) { var txBytes bytes.Buffer _, err := fmt.Fprintf(&txBytes, "%s", b.NetworkID) if err != nil { return [32]byte{}, err } _, err = xdr.Marshal(&txBytes, xdr.EnvelopeTypeEnvelopeTypeTx) if err != nil { return [32]byte{}, err } _, err = xdr.Marshal(&txBytes, b.TX) if err != nil { return [32]byte{}, err } return hash.Hash(txBytes.Bytes()), nil }
go
func (b *TransactionBuilder) Hash() ([32]byte, error) { var txBytes bytes.Buffer _, err := fmt.Fprintf(&txBytes, "%s", b.NetworkID) if err != nil { return [32]byte{}, err } _, err = xdr.Marshal(&txBytes, xdr.EnvelopeTypeEnvelopeTypeTx) if err != nil { return [32]byte{}, err } _, err = xdr.Marshal(&txBytes, b.TX) if err != nil { return [32]byte{}, err } return hash.Hash(txBytes.Bytes()), nil }
[ "func", "(", "b", "*", "TransactionBuilder", ")", "Hash", "(", ")", "(", "[", "32", "]", "byte", ",", "error", ")", "{", "var", "txBytes", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "fmt", ".", "Fprintf", "(", "&", "txBytes", ",", "\"%s\"", ",", "b", ".", "NetworkID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "32", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "_", ",", "err", "=", "xdr", ".", "Marshal", "(", "&", "txBytes", ",", "xdr", ".", "EnvelopeTypeEnvelopeTypeTx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "32", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "_", ",", "err", "=", "xdr", ".", "Marshal", "(", "&", "txBytes", ",", "b", ".", "TX", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "32", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "return", "hash", ".", "Hash", "(", "txBytes", ".", "Bytes", "(", ")", ")", ",", "nil", "\n", "}" ]
// Hash returns the hash of this builder's transaction.
[ "Hash", "returns", "the", "hash", "of", "this", "builder", "s", "transaction", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L52-L71
test
stellar/go-stellar-base
build/transaction.go
HashHex
func (b *TransactionBuilder) HashHex() (string, error) { hash, err := b.Hash() if err != nil { return "", err } return hex.EncodeToString(hash[:]), nil }
go
func (b *TransactionBuilder) HashHex() (string, error) { hash, err := b.Hash() if err != nil { return "", err } return hex.EncodeToString(hash[:]), nil }
[ "func", "(", "b", "*", "TransactionBuilder", ")", "HashHex", "(", ")", "(", "string", ",", "error", ")", "{", "hash", ",", "err", ":=", "b", ".", "Hash", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "hex", ".", "EncodeToString", "(", "hash", "[", ":", "]", ")", ",", "nil", "\n", "}" ]
// HashHex returns the hex-encoded hash of this builder's transaction
[ "HashHex", "returns", "the", "hex", "-", "encoded", "hash", "of", "this", "builder", "s", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L74-L81
test
stellar/go-stellar-base
build/transaction.go
Sign
func (b *TransactionBuilder) Sign(signers ...string) (result TransactionEnvelopeBuilder) { result.Mutate(b) for _, s := range signers { result.Mutate(Sign{s}) } return }
go
func (b *TransactionBuilder) Sign(signers ...string) (result TransactionEnvelopeBuilder) { result.Mutate(b) for _, s := range signers { result.Mutate(Sign{s}) } return }
[ "func", "(", "b", "*", "TransactionBuilder", ")", "Sign", "(", "signers", "...", "string", ")", "(", "result", "TransactionEnvelopeBuilder", ")", "{", "result", ".", "Mutate", "(", "b", ")", "\n", "for", "_", ",", "s", ":=", "range", "signers", "{", "result", ".", "Mutate", "(", "Sign", "{", "s", "}", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Sign returns an new TransactionEnvelopeBuilder using this builder's // transaction as the basis and with signatures of that transaction from the // provided Signers.
[ "Sign", "returns", "an", "new", "TransactionEnvelopeBuilder", "using", "this", "builder", "s", "transaction", "as", "the", "basis", "and", "with", "signatures", "of", "that", "transaction", "from", "the", "provided", "Signers", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L86-L94
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m AllowTrustBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeAllowTrust, m.AT) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m AllowTrustBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeAllowTrust, m.AT) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "AllowTrustBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeAllowTrust", ",", "m", ".", "AT", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for AllowTrustBuilder causes the underylying AllowTrustOp // to be added to the operation list for the provided transaction
[ "MutateTransaction", "for", "AllowTrustBuilder", "causes", "the", "underylying", "AllowTrustOp", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L116-L124
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m ChangeTrustBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeChangeTrust, m.CT) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m ChangeTrustBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeChangeTrust, m.CT) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "ChangeTrustBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeChangeTrust", ",", "m", ".", "CT", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for ChangeTrustBuilder causes the underylying // CreateAccountOp to be added to the operation list for the provided // transaction
[ "MutateTransaction", "for", "ChangeTrustBuilder", "causes", "the", "underylying", "CreateAccountOp", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L148-L156
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m CreateAccountBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreateAccount, m.CA) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m CreateAccountBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreateAccount, m.CA) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "CreateAccountBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeCreateAccount", ",", "m", ".", "CA", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for CreateAccountBuilder causes the underylying // CreateAccountOp to be added to the operation list for the provided // transaction
[ "MutateTransaction", "for", "CreateAccountBuilder", "causes", "the", "underylying", "CreateAccountOp", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L161-L169
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m Defaults) MutateTransaction(o *TransactionBuilder) error { if o.TX.Fee == 0 { o.TX.Fee = xdr.Uint32(100 * len(o.TX.Operations)) } if o.NetworkID == [32]byte{} { o.NetworkID = DefaultNetwork.ID() } return nil }
go
func (m Defaults) MutateTransaction(o *TransactionBuilder) error { if o.TX.Fee == 0 { o.TX.Fee = xdr.Uint32(100 * len(o.TX.Operations)) } if o.NetworkID == [32]byte{} { o.NetworkID = DefaultNetwork.ID() } return nil }
[ "func", "(", "m", "Defaults", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "o", ".", "TX", ".", "Fee", "==", "0", "{", "o", ".", "TX", ".", "Fee", "=", "xdr", ".", "Uint32", "(", "100", "*", "len", "(", "o", ".", "TX", ".", "Operations", ")", ")", "\n", "}", "\n", "if", "o", ".", "NetworkID", "==", "[", "32", "]", "byte", "{", "}", "{", "o", ".", "NetworkID", "=", "DefaultNetwork", ".", "ID", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MutateTransaction for Defaults sets reasonable defaults on the transaction being built
[ "MutateTransaction", "for", "Defaults", "sets", "reasonable", "defaults", "on", "the", "transaction", "being", "built" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L172-L182
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m InflationBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeInflation, nil) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m InflationBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeInflation, nil) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "InflationBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeInflation", ",", "nil", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for InflationBuilder causes the underylying // InflationOp to be added to the operation list for the provided // transaction
[ "MutateTransaction", "for", "InflationBuilder", "causes", "the", "underylying", "InflationOp", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L187-L195
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m ManageDataBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageData, m.MD) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m ManageDataBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageData, m.MD) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "ManageDataBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeManageData", ",", "m", ".", "MD", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for ManageDataBuilder causes the underylying // ManageData to be added to the operation list for the provided // transaction
[ "MutateTransaction", "for", "ManageDataBuilder", "causes", "the", "underylying", "ManageData", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L200-L208
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m ManageOfferBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } if m.PassiveOffer { m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreatePassiveOffer, m.PO) o.TX.Operations = append(o.TX.Operations, m.O) } else { m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageOffer, m.MO) o.TX.Operations = append(o.TX.Operations, m.O) } return m.Err }
go
func (m ManageOfferBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } if m.PassiveOffer { m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreatePassiveOffer, m.PO) o.TX.Operations = append(o.TX.Operations, m.O) } else { m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageOffer, m.MO) o.TX.Operations = append(o.TX.Operations, m.O) } return m.Err }
[ "func", "(", "m", "ManageOfferBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "if", "m", ".", "PassiveOffer", "{", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeCreatePassiveOffer", ",", "m", ".", "PO", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "}", "else", "{", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeManageOffer", ",", "m", ".", "MO", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "}", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for ManageOfferBuilder causes the underylying // ManageData to be added to the operation list for the provided // transaction
[ "MutateTransaction", "for", "ManageOfferBuilder", "causes", "the", "underylying", "ManageData", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L213-L226
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m MemoHash) MutateTransaction(o *TransactionBuilder) (err error) { o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoHash, m.Value) return }
go
func (m MemoHash) MutateTransaction(o *TransactionBuilder) (err error) { o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoHash, m.Value) return }
[ "func", "(", "m", "MemoHash", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "(", "err", "error", ")", "{", "o", ".", "TX", ".", "Memo", ",", "err", "=", "xdr", ".", "NewMemo", "(", "xdr", ".", "MemoTypeMemoHash", ",", "m", ".", "Value", ")", "\n", "return", "\n", "}" ]
// MutateTransaction for MemoHash sets the memo.
[ "MutateTransaction", "for", "MemoHash", "sets", "the", "memo", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L229-L232
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m MemoID) MutateTransaction(o *TransactionBuilder) (err error) { o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoId, xdr.Uint64(m.Value)) return }
go
func (m MemoID) MutateTransaction(o *TransactionBuilder) (err error) { o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoId, xdr.Uint64(m.Value)) return }
[ "func", "(", "m", "MemoID", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "(", "err", "error", ")", "{", "o", ".", "TX", ".", "Memo", ",", "err", "=", "xdr", ".", "NewMemo", "(", "xdr", ".", "MemoTypeMemoId", ",", "xdr", ".", "Uint64", "(", "m", ".", "Value", ")", ")", "\n", "return", "\n", "}" ]
// MutateTransaction for MemoID sets the memo.
[ "MutateTransaction", "for", "MemoID", "sets", "the", "memo", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L235-L238
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m MemoReturn) MutateTransaction(o *TransactionBuilder) (err error) { o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoReturn, m.Value) return }
go
func (m MemoReturn) MutateTransaction(o *TransactionBuilder) (err error) { o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoReturn, m.Value) return }
[ "func", "(", "m", "MemoReturn", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "(", "err", "error", ")", "{", "o", ".", "TX", ".", "Memo", ",", "err", "=", "xdr", ".", "NewMemo", "(", "xdr", ".", "MemoTypeMemoReturn", ",", "m", ".", "Value", ")", "\n", "return", "\n", "}" ]
// MutateTransaction for MemoReturn sets the memo.
[ "MutateTransaction", "for", "MemoReturn", "sets", "the", "memo", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L241-L244
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) { if len([]byte(m.Value)) > MemoTextMaxLength { err = errors.New("Memo too long; over 28 bytes") return } o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoText, m.Value) return }
go
func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) { if len([]byte(m.Value)) > MemoTextMaxLength { err = errors.New("Memo too long; over 28 bytes") return } o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoText, m.Value) return }
[ "func", "(", "m", "MemoText", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "(", "err", "error", ")", "{", "if", "len", "(", "[", "]", "byte", "(", "m", ".", "Value", ")", ")", ">", "MemoTextMaxLength", "{", "err", "=", "errors", ".", "New", "(", "\"Memo too long; over 28 bytes\"", ")", "\n", "return", "\n", "}", "\n", "o", ".", "TX", ".", "Memo", ",", "err", "=", "xdr", ".", "NewMemo", "(", "xdr", ".", "MemoTypeMemoText", ",", "m", ".", "Value", ")", "\n", "return", "\n", "}" ]
// MutateTransaction for MemoText sets the memo.
[ "MutateTransaction", "for", "MemoText", "sets", "the", "memo", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L247-L256
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m Network) MutateTransaction(o *TransactionBuilder) error { o.NetworkID = m.ID() return nil }
go
func (m Network) MutateTransaction(o *TransactionBuilder) error { o.NetworkID = m.ID() return nil }
[ "func", "(", "m", "Network", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "o", ".", "NetworkID", "=", "m", ".", "ID", "(", ")", "\n", "return", "nil", "\n", "}" ]
// MutateTransaction for Network sets the Network ID to use when signing this transaction
[ "MutateTransaction", "for", "Network", "sets", "the", "Network", "ID", "to", "use", "when", "signing", "this", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L259-L262
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m PaymentBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } if m.PathPayment { m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypePathPayment, m.PP) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypePayment, m.P) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m PaymentBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } if m.PathPayment { m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypePathPayment, m.PP) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypePayment, m.P) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "PaymentBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "if", "m", ".", "PathPayment", "{", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypePathPayment", ",", "m", ".", "PP", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypePayment", ",", "m", ".", "P", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for PaymentBuilder causes the underylying PaymentOp // or PathPaymentOp to be added to the operation list for the provided transaction
[ "MutateTransaction", "for", "PaymentBuilder", "causes", "the", "underylying", "PaymentOp", "or", "PathPaymentOp", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L266-L280
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m SetOptionsBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeSetOptions, m.SO) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
go
func (m SetOptionsBuilder) MutateTransaction(o *TransactionBuilder) error { if m.Err != nil { return m.Err } m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeSetOptions, m.SO) o.TX.Operations = append(o.TX.Operations, m.O) return m.Err }
[ "func", "(", "m", "SetOptionsBuilder", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "m", ".", "O", ".", "Body", ",", "m", ".", "Err", "=", "xdr", ".", "NewOperationBody", "(", "xdr", ".", "OperationTypeSetOptions", ",", "m", ".", "SO", ")", "\n", "o", ".", "TX", ".", "Operations", "=", "append", "(", "o", ".", "TX", ".", "Operations", ",", "m", ".", "O", ")", "\n", "return", "m", ".", "Err", "\n", "}" ]
// MutateTransaction for SetOptionsBuilder causes the underylying // SetOptionsOp to be added to the operation list for the provided // transaction
[ "MutateTransaction", "for", "SetOptionsBuilder", "causes", "the", "underylying", "SetOptionsOp", "to", "be", "added", "to", "the", "operation", "list", "for", "the", "provided", "transaction" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L285-L293
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m Sequence) MutateTransaction(o *TransactionBuilder) error { o.TX.SeqNum = xdr.SequenceNumber(m.Sequence) return nil }
go
func (m Sequence) MutateTransaction(o *TransactionBuilder) error { o.TX.SeqNum = xdr.SequenceNumber(m.Sequence) return nil }
[ "func", "(", "m", "Sequence", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "o", ".", "TX", ".", "SeqNum", "=", "xdr", ".", "SequenceNumber", "(", "m", ".", "Sequence", ")", "\n", "return", "nil", "\n", "}" ]
// MutateTransaction for Sequence sets the SeqNum on the transaction.
[ "MutateTransaction", "for", "Sequence", "sets", "the", "SeqNum", "on", "the", "transaction", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L296-L299
test
stellar/go-stellar-base
build/transaction.go
MutateTransaction
func (m SourceAccount) MutateTransaction(o *TransactionBuilder) error { return setAccountId(m.AddressOrSeed, &o.TX.SourceAccount) }
go
func (m SourceAccount) MutateTransaction(o *TransactionBuilder) error { return setAccountId(m.AddressOrSeed, &o.TX.SourceAccount) }
[ "func", "(", "m", "SourceAccount", ")", "MutateTransaction", "(", "o", "*", "TransactionBuilder", ")", "error", "{", "return", "setAccountId", "(", "m", ".", "AddressOrSeed", ",", "&", "o", ".", "TX", ".", "SourceAccount", ")", "\n", "}" ]
// MutateTransaction for SourceAccount sets the transaction's SourceAccount // to the pubilic key for the address provided
[ "MutateTransaction", "for", "SourceAccount", "sets", "the", "transaction", "s", "SourceAccount", "to", "the", "pubilic", "key", "for", "the", "address", "provided" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction.go#L303-L305
test
stellar/go-stellar-base
xdr/db.go
Scan
func (t *Int64) Scan(src interface{}) error { val, ok := src.(int64) if !ok { return errors.New("Invalid value for xdr.Int64") } *t = Int64(val) return nil }
go
func (t *Int64) Scan(src interface{}) error { val, ok := src.(int64) if !ok { return errors.New("Invalid value for xdr.Int64") } *t = Int64(val) return nil }
[ "func", "(", "t", "*", "Int64", ")", "Scan", "(", "src", "interface", "{", "}", ")", "error", "{", "val", ",", "ok", ":=", "src", ".", "(", "int64", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"Invalid value for xdr.Int64\"", ")", "\n", "}", "\n", "*", "t", "=", "Int64", "(", "val", ")", "\n", "return", "nil", "\n", "}" ]
// Scan reads from src into an Int64
[ "Scan", "reads", "from", "src", "into", "an", "Int64" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/db.go#L33-L41
test
stellar/go-stellar-base
meta/bundle.go
InitialState
func (b *Bundle) InitialState(key xdr.LedgerKey) (*xdr.LedgerEntry, error) { all := b.Changes(key) if len(all) == 0 { return nil, ErrMetaNotFound } first := all[0] if first.Type != xdr.LedgerEntryChangeTypeLedgerEntryState { return nil, nil } result := first.MustState() return &result, nil }
go
func (b *Bundle) InitialState(key xdr.LedgerKey) (*xdr.LedgerEntry, error) { all := b.Changes(key) if len(all) == 0 { return nil, ErrMetaNotFound } first := all[0] if first.Type != xdr.LedgerEntryChangeTypeLedgerEntryState { return nil, nil } result := first.MustState() return &result, nil }
[ "func", "(", "b", "*", "Bundle", ")", "InitialState", "(", "key", "xdr", ".", "LedgerKey", ")", "(", "*", "xdr", ".", "LedgerEntry", ",", "error", ")", "{", "all", ":=", "b", ".", "Changes", "(", "key", ")", "\n", "if", "len", "(", "all", ")", "==", "0", "{", "return", "nil", ",", "ErrMetaNotFound", "\n", "}", "\n", "first", ":=", "all", "[", "0", "]", "\n", "if", "first", ".", "Type", "!=", "xdr", ".", "LedgerEntryChangeTypeLedgerEntryState", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "result", ":=", "first", ".", "MustState", "(", ")", "\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// InitialState returns the initial state of the LedgerEntry identified by `key` // just prior to the application of the transaction the produced `b`. Returns // nil if the ledger entry did not exist prior to the bundle.
[ "InitialState", "returns", "the", "initial", "state", "of", "the", "LedgerEntry", "identified", "by", "key", "just", "prior", "to", "the", "application", "of", "the", "transaction", "the", "produced", "b", ".", "Returns", "nil", "if", "the", "ledger", "entry", "did", "not", "exist", "prior", "to", "the", "bundle", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/meta/bundle.go#L18-L34
test
stellar/go-stellar-base
meta/bundle.go
Changes
func (b *Bundle) Changes(target xdr.LedgerKey) (ret []xdr.LedgerEntryChange) { return b.changes(target, math.MaxInt32) }
go
func (b *Bundle) Changes(target xdr.LedgerKey) (ret []xdr.LedgerEntryChange) { return b.changes(target, math.MaxInt32) }
[ "func", "(", "b", "*", "Bundle", ")", "Changes", "(", "target", "xdr", ".", "LedgerKey", ")", "(", "ret", "[", "]", "xdr", ".", "LedgerEntryChange", ")", "{", "return", "b", ".", "changes", "(", "target", ",", "math", ".", "MaxInt32", ")", "\n", "}" ]
// Changes returns any changes within the bundle that apply to the entry // identified by `key`.
[ "Changes", "returns", "any", "changes", "within", "the", "bundle", "that", "apply", "to", "the", "entry", "identified", "by", "key", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/meta/bundle.go#L38-L40
test
stellar/go-stellar-base
meta/bundle.go
StateAfter
func (b *Bundle) StateAfter(key xdr.LedgerKey, opidx int) (*xdr.LedgerEntry, error) { all := b.changes(key, opidx) if len(all) == 0 { return nil, ErrMetaNotFound } change := all[len(all)-1] switch change.Type { case xdr.LedgerEntryChangeTypeLedgerEntryCreated: entry := change.MustCreated() return &entry, nil case xdr.LedgerEntryChangeTypeLedgerEntryRemoved: return nil, nil case xdr.LedgerEntryChangeTypeLedgerEntryUpdated: entry := change.MustUpdated() return &entry, nil case xdr.LedgerEntryChangeTypeLedgerEntryState: // scott: stellar-core should not emit a lone state entry, and we are // retrieving changes from the end of the collection. If this situation // occurs, it means that I didn't understand something correctly or there is // a bug in stellar-core. panic(fmt.Errorf("Unexpected 'state' entry")) default: panic(fmt.Errorf("Unknown change type: %v", change.Type)) } }
go
func (b *Bundle) StateAfter(key xdr.LedgerKey, opidx int) (*xdr.LedgerEntry, error) { all := b.changes(key, opidx) if len(all) == 0 { return nil, ErrMetaNotFound } change := all[len(all)-1] switch change.Type { case xdr.LedgerEntryChangeTypeLedgerEntryCreated: entry := change.MustCreated() return &entry, nil case xdr.LedgerEntryChangeTypeLedgerEntryRemoved: return nil, nil case xdr.LedgerEntryChangeTypeLedgerEntryUpdated: entry := change.MustUpdated() return &entry, nil case xdr.LedgerEntryChangeTypeLedgerEntryState: // scott: stellar-core should not emit a lone state entry, and we are // retrieving changes from the end of the collection. If this situation // occurs, it means that I didn't understand something correctly or there is // a bug in stellar-core. panic(fmt.Errorf("Unexpected 'state' entry")) default: panic(fmt.Errorf("Unknown change type: %v", change.Type)) } }
[ "func", "(", "b", "*", "Bundle", ")", "StateAfter", "(", "key", "xdr", ".", "LedgerKey", ",", "opidx", "int", ")", "(", "*", "xdr", ".", "LedgerEntry", ",", "error", ")", "{", "all", ":=", "b", ".", "changes", "(", "key", ",", "opidx", ")", "\n", "if", "len", "(", "all", ")", "==", "0", "{", "return", "nil", ",", "ErrMetaNotFound", "\n", "}", "\n", "change", ":=", "all", "[", "len", "(", "all", ")", "-", "1", "]", "\n", "switch", "change", ".", "Type", "{", "case", "xdr", ".", "LedgerEntryChangeTypeLedgerEntryCreated", ":", "entry", ":=", "change", ".", "MustCreated", "(", ")", "\n", "return", "&", "entry", ",", "nil", "\n", "case", "xdr", ".", "LedgerEntryChangeTypeLedgerEntryRemoved", ":", "return", "nil", ",", "nil", "\n", "case", "xdr", ".", "LedgerEntryChangeTypeLedgerEntryUpdated", ":", "entry", ":=", "change", ".", "MustUpdated", "(", ")", "\n", "return", "&", "entry", ",", "nil", "\n", "case", "xdr", ".", "LedgerEntryChangeTypeLedgerEntryState", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"Unexpected 'state' entry\"", ")", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"Unknown change type: %v\"", ",", "change", ".", "Type", ")", ")", "\n", "}", "\n", "}" ]
// StateAfter returns the state of entry `key` after the application of the // operation at `opidx`
[ "StateAfter", "returns", "the", "state", "of", "entry", "key", "after", "the", "application", "of", "the", "operation", "at", "opidx" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/meta/bundle.go#L44-L71
test
stellar/go-stellar-base
meta/bundle.go
changes
func (b *Bundle) changes(target xdr.LedgerKey, maxOp int) (ret []xdr.LedgerEntryChange) { for _, change := range b.FeeMeta { key := change.LedgerKey() if !key.Equals(target) { continue } ret = append(ret, change) } for i, op := range b.TransactionMeta.MustOperations() { if i > maxOp { break } for _, change := range op.Changes { key := change.LedgerKey() if !key.Equals(target) { continue } ret = append(ret, change) } } return }
go
func (b *Bundle) changes(target xdr.LedgerKey, maxOp int) (ret []xdr.LedgerEntryChange) { for _, change := range b.FeeMeta { key := change.LedgerKey() if !key.Equals(target) { continue } ret = append(ret, change) } for i, op := range b.TransactionMeta.MustOperations() { if i > maxOp { break } for _, change := range op.Changes { key := change.LedgerKey() if !key.Equals(target) { continue } ret = append(ret, change) } } return }
[ "func", "(", "b", "*", "Bundle", ")", "changes", "(", "target", "xdr", ".", "LedgerKey", ",", "maxOp", "int", ")", "(", "ret", "[", "]", "xdr", ".", "LedgerEntryChange", ")", "{", "for", "_", ",", "change", ":=", "range", "b", ".", "FeeMeta", "{", "key", ":=", "change", ".", "LedgerKey", "(", ")", "\n", "if", "!", "key", ".", "Equals", "(", "target", ")", "{", "continue", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "change", ")", "\n", "}", "\n", "for", "i", ",", "op", ":=", "range", "b", ".", "TransactionMeta", ".", "MustOperations", "(", ")", "{", "if", "i", ">", "maxOp", "{", "break", "\n", "}", "\n", "for", "_", ",", "change", ":=", "range", "op", ".", "Changes", "{", "key", ":=", "change", ".", "LedgerKey", "(", ")", "\n", "if", "!", "key", ".", "Equals", "(", "target", ")", "{", "continue", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "change", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// changes returns any changes within the bundle that apply to the entry // identified by `key` that occurred at or before `maxOp`.
[ "changes", "returns", "any", "changes", "within", "the", "bundle", "that", "apply", "to", "the", "entry", "identified", "by", "key", "that", "occurred", "at", "or", "before", "maxOp", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/meta/bundle.go#L109-L137
test
stellar/go-stellar-base
strkey/main.go
MustDecode
func MustDecode(expected VersionByte, src string) []byte { d, err := Decode(expected, src) if err != nil { panic(err) } return d }
go
func MustDecode(expected VersionByte, src string) []byte { d, err := Decode(expected, src) if err != nil { panic(err) } return d }
[ "func", "MustDecode", "(", "expected", "VersionByte", ",", "src", "string", ")", "[", "]", "byte", "{", "d", ",", "err", ":=", "Decode", "(", "expected", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "d", "\n", "}" ]
// MustDecode is like Decode, but panics on error
[ "MustDecode", "is", "like", "Decode", "but", "panics", "on", "error" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/strkey/main.go#L64-L70
test
stellar/go-stellar-base
strkey/main.go
Encode
func Encode(version VersionByte, src []byte) (string, error) { if err := checkValidVersionByte(version); err != nil { return "", err } var raw bytes.Buffer // write version byte if err := binary.Write(&raw, binary.LittleEndian, version); err != nil { return "", err } // write payload if _, err := raw.Write(src); err != nil { return "", err } // calculate and write checksum checksum := crc16.Checksum(raw.Bytes()) if _, err := raw.Write(checksum); err != nil { return "", err } result := base32.StdEncoding.EncodeToString(raw.Bytes()) return result, nil }
go
func Encode(version VersionByte, src []byte) (string, error) { if err := checkValidVersionByte(version); err != nil { return "", err } var raw bytes.Buffer // write version byte if err := binary.Write(&raw, binary.LittleEndian, version); err != nil { return "", err } // write payload if _, err := raw.Write(src); err != nil { return "", err } // calculate and write checksum checksum := crc16.Checksum(raw.Bytes()) if _, err := raw.Write(checksum); err != nil { return "", err } result := base32.StdEncoding.EncodeToString(raw.Bytes()) return result, nil }
[ "func", "Encode", "(", "version", "VersionByte", ",", "src", "[", "]", "byte", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "checkValidVersionByte", "(", "version", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "var", "raw", "bytes", ".", "Buffer", "\n", "if", "err", ":=", "binary", ".", "Write", "(", "&", "raw", ",", "binary", ".", "LittleEndian", ",", "version", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "raw", ".", "Write", "(", "src", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "checksum", ":=", "crc16", ".", "Checksum", "(", "raw", ".", "Bytes", "(", ")", ")", "\n", "if", "_", ",", "err", ":=", "raw", ".", "Write", "(", "checksum", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "result", ":=", "base32", ".", "StdEncoding", ".", "EncodeToString", "(", "raw", ".", "Bytes", "(", ")", ")", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Encode encodes the provided data to a StrKey, using the provided version // byte.
[ "Encode", "encodes", "the", "provided", "data", "to", "a", "StrKey", "using", "the", "provided", "version", "byte", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/strkey/main.go#L74-L99
test
stellar/go-stellar-base
strkey/main.go
MustEncode
func MustEncode(version VersionByte, src []byte) string { e, err := Encode(version, src) if err != nil { panic(err) } return e }
go
func MustEncode(version VersionByte, src []byte) string { e, err := Encode(version, src) if err != nil { panic(err) } return e }
[ "func", "MustEncode", "(", "version", "VersionByte", ",", "src", "[", "]", "byte", ")", "string", "{", "e", ",", "err", ":=", "Encode", "(", "version", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "e", "\n", "}" ]
// MustEncode is like Encode, but panics on error
[ "MustEncode", "is", "like", "Encode", "but", "panics", "on", "error" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/strkey/main.go#L102-L108
test
stellar/go-stellar-base
strkey/main.go
checkValidVersionByte
func checkValidVersionByte(version VersionByte) error { if version == VersionByteAccountID { return nil } if version == VersionByteSeed { return nil } return ErrInvalidVersionByte }
go
func checkValidVersionByte(version VersionByte) error { if version == VersionByteAccountID { return nil } if version == VersionByteSeed { return nil } return ErrInvalidVersionByte }
[ "func", "checkValidVersionByte", "(", "version", "VersionByte", ")", "error", "{", "if", "version", "==", "VersionByteAccountID", "{", "return", "nil", "\n", "}", "\n", "if", "version", "==", "VersionByteSeed", "{", "return", "nil", "\n", "}", "\n", "return", "ErrInvalidVersionByte", "\n", "}" ]
// checkValidVersionByte returns an error if the provided value // is not one of the defined valid version byte constants.
[ "checkValidVersionByte", "returns", "an", "error", "if", "the", "provided", "value", "is", "not", "one", "of", "the", "defined", "valid", "version", "byte", "constants", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/strkey/main.go#L112-L121
test
stellar/go-stellar-base
crc16/main.go
Checksum
func Checksum(data []byte) []byte { var crc uint16 var out bytes.Buffer for _, b := range data { crc = ((crc << 8) & 0xffff) ^ crc16tab[((crc>>8)^uint16(b))&0x00FF] } err := binary.Write(&out, binary.LittleEndian, crc) if err != nil { panic(err) } return out.Bytes() }
go
func Checksum(data []byte) []byte { var crc uint16 var out bytes.Buffer for _, b := range data { crc = ((crc << 8) & 0xffff) ^ crc16tab[((crc>>8)^uint16(b))&0x00FF] } err := binary.Write(&out, binary.LittleEndian, crc) if err != nil { panic(err) } return out.Bytes() }
[ "func", "Checksum", "(", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "var", "crc", "uint16", "\n", "var", "out", "bytes", ".", "Buffer", "\n", "for", "_", ",", "b", ":=", "range", "data", "{", "crc", "=", "(", "(", "crc", "<<", "8", ")", "&", "0xffff", ")", "^", "crc16tab", "[", "(", "(", "crc", ">>", "8", ")", "^", "uint16", "(", "b", ")", ")", "&", "0x00FF", "]", "\n", "}", "\n", "err", ":=", "binary", ".", "Write", "(", "&", "out", ",", "binary", ".", "LittleEndian", ",", "crc", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "out", ".", "Bytes", "(", ")", "\n", "}" ]
// Checksum returns the 2-byte checksum for the provided data
[ "Checksum", "returns", "the", "2", "-", "byte", "checksum", "for", "the", "provided", "data" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/crc16/main.go#L95-L108
test
stellar/go-stellar-base
crc16/main.go
Validate
func Validate(data []byte, expected []byte) error { actual := Checksum(data) // validate the provided checksum against the calculated if !bytes.Equal(actual, expected) { return ErrInvalidChecksum } return nil }
go
func Validate(data []byte, expected []byte) error { actual := Checksum(data) // validate the provided checksum against the calculated if !bytes.Equal(actual, expected) { return ErrInvalidChecksum } return nil }
[ "func", "Validate", "(", "data", "[", "]", "byte", ",", "expected", "[", "]", "byte", ")", "error", "{", "actual", ":=", "Checksum", "(", "data", ")", "\n", "if", "!", "bytes", ".", "Equal", "(", "actual", ",", "expected", ")", "{", "return", "ErrInvalidChecksum", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate returns an error if the provided checksum does not match // the calculated checksum of the provided data
[ "Validate", "returns", "an", "error", "if", "the", "provided", "checksum", "does", "not", "match", "the", "calculated", "checksum", "of", "the", "provided", "data" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/crc16/main.go#L112-L122
test
stellar/go-stellar-base
xdr/ledger_entry_change.go
LedgerKey
func (change *LedgerEntryChange) LedgerKey() LedgerKey { switch change.Type { case LedgerEntryChangeTypeLedgerEntryCreated: change := change.MustCreated() return change.LedgerKey() case LedgerEntryChangeTypeLedgerEntryRemoved: return change.MustRemoved() case LedgerEntryChangeTypeLedgerEntryUpdated: change := change.MustUpdated() return change.LedgerKey() case LedgerEntryChangeTypeLedgerEntryState: change := change.MustState() return change.LedgerKey() default: panic(fmt.Errorf("Unknown change type: %v", change.Type)) } }
go
func (change *LedgerEntryChange) LedgerKey() LedgerKey { switch change.Type { case LedgerEntryChangeTypeLedgerEntryCreated: change := change.MustCreated() return change.LedgerKey() case LedgerEntryChangeTypeLedgerEntryRemoved: return change.MustRemoved() case LedgerEntryChangeTypeLedgerEntryUpdated: change := change.MustUpdated() return change.LedgerKey() case LedgerEntryChangeTypeLedgerEntryState: change := change.MustState() return change.LedgerKey() default: panic(fmt.Errorf("Unknown change type: %v", change.Type)) } }
[ "func", "(", "change", "*", "LedgerEntryChange", ")", "LedgerKey", "(", ")", "LedgerKey", "{", "switch", "change", ".", "Type", "{", "case", "LedgerEntryChangeTypeLedgerEntryCreated", ":", "change", ":=", "change", ".", "MustCreated", "(", ")", "\n", "return", "change", ".", "LedgerKey", "(", ")", "\n", "case", "LedgerEntryChangeTypeLedgerEntryRemoved", ":", "return", "change", ".", "MustRemoved", "(", ")", "\n", "case", "LedgerEntryChangeTypeLedgerEntryUpdated", ":", "change", ":=", "change", ".", "MustUpdated", "(", ")", "\n", "return", "change", ".", "LedgerKey", "(", ")", "\n", "case", "LedgerEntryChangeTypeLedgerEntryState", ":", "change", ":=", "change", ".", "MustState", "(", ")", "\n", "return", "change", ".", "LedgerKey", "(", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"Unknown change type: %v\"", ",", "change", ".", "Type", ")", ")", "\n", "}", "\n", "}" ]
// LedgerKey returns the key for the ledger entry that was changed // in `change`.
[ "LedgerKey", "returns", "the", "key", "for", "the", "ledger", "entry", "that", "was", "changed", "in", "change", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/ledger_entry_change.go#L12-L28
test
stellar/go-stellar-base
cmd/stellar-vanity-gen/main.go
checkPlausible
func checkPlausible() { for _, r := range prefix { if !strings.ContainsRune(alphabet, r) { fmt.Printf("Invalid prefix: %s is not in the base32 alphabet\n", strconv.QuoteRune(r)) os.Exit(1) } } }
go
func checkPlausible() { for _, r := range prefix { if !strings.ContainsRune(alphabet, r) { fmt.Printf("Invalid prefix: %s is not in the base32 alphabet\n", strconv.QuoteRune(r)) os.Exit(1) } } }
[ "func", "checkPlausible", "(", ")", "{", "for", "_", ",", "r", ":=", "range", "prefix", "{", "if", "!", "strings", ".", "ContainsRune", "(", "alphabet", ",", "r", ")", "{", "fmt", ".", "Printf", "(", "\"Invalid prefix: %s is not in the base32 alphabet\\n\"", ",", "\\n", ")", "\n", "strconv", ".", "QuoteRune", "(", "r", ")", "\n", "}", "\n", "}", "\n", "}" ]
// aborts the attempt if a desired character is not a valid base32 digit
[ "aborts", "the", "attempt", "if", "a", "desired", "character", "is", "not", "a", "valid", "base32", "digit" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/cmd/stellar-vanity-gen/main.go#L50-L57
test
stellar/go-stellar-base
xdr/account_id.go
Address
func (aid *AccountId) Address() string { if aid == nil { return "" } switch aid.Type { case CryptoKeyTypeKeyTypeEd25519: ed := aid.MustEd25519() raw := make([]byte, 32) copy(raw, ed[:]) return strkey.MustEncode(strkey.VersionByteAccountID, raw) default: panic(fmt.Errorf("Unknown account id type: %v", aid.Type)) } }
go
func (aid *AccountId) Address() string { if aid == nil { return "" } switch aid.Type { case CryptoKeyTypeKeyTypeEd25519: ed := aid.MustEd25519() raw := make([]byte, 32) copy(raw, ed[:]) return strkey.MustEncode(strkey.VersionByteAccountID, raw) default: panic(fmt.Errorf("Unknown account id type: %v", aid.Type)) } }
[ "func", "(", "aid", "*", "AccountId", ")", "Address", "(", ")", "string", "{", "if", "aid", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "switch", "aid", ".", "Type", "{", "case", "CryptoKeyTypeKeyTypeEd25519", ":", "ed", ":=", "aid", ".", "MustEd25519", "(", ")", "\n", "raw", ":=", "make", "(", "[", "]", "byte", ",", "32", ")", "\n", "copy", "(", "raw", ",", "ed", "[", ":", "]", ")", "\n", "return", "strkey", ".", "MustEncode", "(", "strkey", ".", "VersionByteAccountID", ",", "raw", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"Unknown account id type: %v\"", ",", "aid", ".", "Type", ")", ")", "\n", "}", "\n", "}" ]
// Address returns the strkey encoded form of this AccountId. This method will // panic if the accountid is backed by a public key of an unknown type.
[ "Address", "returns", "the", "strkey", "encoded", "form", "of", "this", "AccountId", ".", "This", "method", "will", "panic", "if", "the", "accountid", "is", "backed", "by", "a", "public", "key", "of", "an", "unknown", "type", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/account_id.go#L12-L26
test
stellar/go-stellar-base
xdr/account_id.go
Equals
func (aid *AccountId) Equals(other AccountId) bool { if aid.Type != other.Type { return false } switch aid.Type { case CryptoKeyTypeKeyTypeEd25519: l := aid.MustEd25519() r := other.MustEd25519() return l == r default: panic(fmt.Errorf("Unknown account id type: %v", aid.Type)) } }
go
func (aid *AccountId) Equals(other AccountId) bool { if aid.Type != other.Type { return false } switch aid.Type { case CryptoKeyTypeKeyTypeEd25519: l := aid.MustEd25519() r := other.MustEd25519() return l == r default: panic(fmt.Errorf("Unknown account id type: %v", aid.Type)) } }
[ "func", "(", "aid", "*", "AccountId", ")", "Equals", "(", "other", "AccountId", ")", "bool", "{", "if", "aid", ".", "Type", "!=", "other", ".", "Type", "{", "return", "false", "\n", "}", "\n", "switch", "aid", ".", "Type", "{", "case", "CryptoKeyTypeKeyTypeEd25519", ":", "l", ":=", "aid", ".", "MustEd25519", "(", ")", "\n", "r", ":=", "other", ".", "MustEd25519", "(", ")", "\n", "return", "l", "==", "r", "\n", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"Unknown account id type: %v\"", ",", "aid", ".", "Type", ")", ")", "\n", "}", "\n", "}" ]
// Equals returns true if `other` is equivalent to `aid`
[ "Equals", "returns", "true", "if", "other", "is", "equivalent", "to", "aid" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/account_id.go#L29-L42
test
stellar/go-stellar-base
xdr/account_id.go
SetAddress
func (aid *AccountId) SetAddress(address string) error { if aid == nil { return nil } raw, err := strkey.Decode(strkey.VersionByteAccountID, address) if err != nil { return err } if len(raw) != 32 { return errors.New("invalid address") } var ui Uint256 copy(ui[:], raw) *aid, err = NewAccountId(CryptoKeyTypeKeyTypeEd25519, ui) return err }
go
func (aid *AccountId) SetAddress(address string) error { if aid == nil { return nil } raw, err := strkey.Decode(strkey.VersionByteAccountID, address) if err != nil { return err } if len(raw) != 32 { return errors.New("invalid address") } var ui Uint256 copy(ui[:], raw) *aid, err = NewAccountId(CryptoKeyTypeKeyTypeEd25519, ui) return err }
[ "func", "(", "aid", "*", "AccountId", ")", "SetAddress", "(", "address", "string", ")", "error", "{", "if", "aid", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "raw", ",", "err", ":=", "strkey", ".", "Decode", "(", "strkey", ".", "VersionByteAccountID", ",", "address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "raw", ")", "!=", "32", "{", "return", "errors", ".", "New", "(", "\"invalid address\"", ")", "\n", "}", "\n", "var", "ui", "Uint256", "\n", "copy", "(", "ui", "[", ":", "]", ",", "raw", ")", "\n", "*", "aid", ",", "err", "=", "NewAccountId", "(", "CryptoKeyTypeKeyTypeEd25519", ",", "ui", ")", "\n", "return", "err", "\n", "}" ]
// SetAddress modifies the receiver, setting it's value to the AccountId form // of the provided address.
[ "SetAddress", "modifies", "the", "receiver", "setting", "it", "s", "value", "to", "the", "AccountId", "form", "of", "the", "provided", "address", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/account_id.go#L56-L76
test
stellar/go-stellar-base
build/main.go
ToXdrObject
func (a Asset) ToXdrObject() (xdr.Asset, error) { if a.Native { return xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) } var issuer xdr.AccountId err := setAccountId(a.Issuer, &issuer) if err != nil { return xdr.Asset{}, err } length := len(a.Code) switch { case length >= 1 && length <= 4: var codeArray [4]byte byteArray := []byte(a.Code) copy(codeArray[:], byteArray[0:length]) asset := xdr.AssetAlphaNum4{codeArray, issuer} return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, asset) case length >= 5 && length <= 12: var codeArray [12]byte byteArray := []byte(a.Code) copy(codeArray[:], byteArray[0:length]) asset := xdr.AssetAlphaNum12{codeArray, issuer} return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, asset) default: return xdr.Asset{}, errors.New("Asset code length is invalid") } }
go
func (a Asset) ToXdrObject() (xdr.Asset, error) { if a.Native { return xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) } var issuer xdr.AccountId err := setAccountId(a.Issuer, &issuer) if err != nil { return xdr.Asset{}, err } length := len(a.Code) switch { case length >= 1 && length <= 4: var codeArray [4]byte byteArray := []byte(a.Code) copy(codeArray[:], byteArray[0:length]) asset := xdr.AssetAlphaNum4{codeArray, issuer} return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, asset) case length >= 5 && length <= 12: var codeArray [12]byte byteArray := []byte(a.Code) copy(codeArray[:], byteArray[0:length]) asset := xdr.AssetAlphaNum12{codeArray, issuer} return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, asset) default: return xdr.Asset{}, errors.New("Asset code length is invalid") } }
[ "func", "(", "a", "Asset", ")", "ToXdrObject", "(", ")", "(", "xdr", ".", "Asset", ",", "error", ")", "{", "if", "a", ".", "Native", "{", "return", "xdr", ".", "NewAsset", "(", "xdr", ".", "AssetTypeAssetTypeNative", ",", "nil", ")", "\n", "}", "\n", "var", "issuer", "xdr", ".", "AccountId", "\n", "err", ":=", "setAccountId", "(", "a", ".", "Issuer", ",", "&", "issuer", ")", "\n", "if", "err", "!=", "nil", "{", "return", "xdr", ".", "Asset", "{", "}", ",", "err", "\n", "}", "\n", "length", ":=", "len", "(", "a", ".", "Code", ")", "\n", "switch", "{", "case", "length", ">=", "1", "&&", "length", "<=", "4", ":", "var", "codeArray", "[", "4", "]", "byte", "\n", "byteArray", ":=", "[", "]", "byte", "(", "a", ".", "Code", ")", "\n", "copy", "(", "codeArray", "[", ":", "]", ",", "byteArray", "[", "0", ":", "length", "]", ")", "\n", "asset", ":=", "xdr", ".", "AssetAlphaNum4", "{", "codeArray", ",", "issuer", "}", "\n", "return", "xdr", ".", "NewAsset", "(", "xdr", ".", "AssetTypeAssetTypeCreditAlphanum4", ",", "asset", ")", "\n", "case", "length", ">=", "5", "&&", "length", "<=", "12", ":", "var", "codeArray", "[", "12", "]", "byte", "\n", "byteArray", ":=", "[", "]", "byte", "(", "a", ".", "Code", ")", "\n", "copy", "(", "codeArray", "[", ":", "]", ",", "byteArray", "[", "0", ":", "length", "]", ")", "\n", "asset", ":=", "xdr", ".", "AssetAlphaNum12", "{", "codeArray", ",", "issuer", "}", "\n", "return", "xdr", ".", "NewAsset", "(", "xdr", ".", "AssetTypeAssetTypeCreditAlphanum12", ",", "asset", ")", "\n", "default", ":", "return", "xdr", ".", "Asset", "{", "}", ",", "errors", ".", "New", "(", "\"Asset code length is invalid\"", ")", "\n", "}", "\n", "}" ]
// ToXdrObject creates xdr.Asset object from build.Asset object
[ "ToXdrObject", "creates", "xdr", ".", "Asset", "object", "from", "build", ".", "Asset", "object" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/main.go#L52-L80
test
stellar/go-stellar-base
build/main.go
Through
func (pathSend PayWithPath) Through(asset Asset) PayWithPath { pathSend.Path = append(pathSend.Path, asset) return pathSend }
go
func (pathSend PayWithPath) Through(asset Asset) PayWithPath { pathSend.Path = append(pathSend.Path, asset) return pathSend }
[ "func", "(", "pathSend", "PayWithPath", ")", "Through", "(", "asset", "Asset", ")", "PayWithPath", "{", "pathSend", ".", "Path", "=", "append", "(", "pathSend", ".", "Path", ",", "asset", ")", "\n", "return", "pathSend", "\n", "}" ]
// Through appends a new asset to the path
[ "Through", "appends", "a", "new", "asset", "to", "the", "path" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/main.go#L182-L185
test
stellar/go-stellar-base
build/main.go
PayWith
func PayWith(sendAsset Asset, maxAmount string) PayWithPath { return PayWithPath{ Asset: sendAsset, MaxAmount: maxAmount, } }
go
func PayWith(sendAsset Asset, maxAmount string) PayWithPath { return PayWithPath{ Asset: sendAsset, MaxAmount: maxAmount, } }
[ "func", "PayWith", "(", "sendAsset", "Asset", ",", "maxAmount", "string", ")", "PayWithPath", "{", "return", "PayWithPath", "{", "Asset", ":", "sendAsset", ",", "MaxAmount", ":", "maxAmount", ",", "}", "\n", "}" ]
// PayWith is a helper to create PayWithPath struct
[ "PayWith", "is", "a", "helper", "to", "create", "PayWithPath", "struct" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/main.go#L188-L193
test
stellar/go-stellar-base
price/main.go
continuedFraction
func continuedFraction(price string) (xdrPrice xdr.Price, err error) { number := &big.Rat{} maxInt32 := &big.Rat{} zero := &big.Rat{} one := &big.Rat{} _, ok := number.SetString(price) if !ok { return xdrPrice, fmt.Errorf("cannot parse price: %s", price) } maxInt32.SetInt64(int64(math.MaxInt32)) zero.SetInt64(int64(0)) one.SetInt64(int64(1)) fractions := [][2]*big.Rat{ {zero, one}, {one, zero}, } i := 2 for { if number.Cmp(maxInt32) == 1 { break } f := &big.Rat{} h := &big.Rat{} k := &big.Rat{} a := floor(number) f.Sub(number, a) h.Mul(a, fractions[i-1][0]) h.Add(h, fractions[i-2][0]) k.Mul(a, fractions[i-1][1]) k.Add(k, fractions[i-2][1]) if h.Cmp(maxInt32) == 1 || k.Cmp(maxInt32) == 1 { break } fractions = append(fractions, [2]*big.Rat{h, k}) if f.Cmp(zero) == 0 { break } number.Quo(one, f) i++ } n, d := fractions[len(fractions)-1][0], fractions[len(fractions)-1][1] if n.Cmp(zero) == 0 || d.Cmp(zero) == 0 { return xdrPrice, errors.New("Couldn't find approximation") } return xdr.Price{ N: xdr.Int32(n.Num().Int64()), D: xdr.Int32(d.Num().Int64()), }, nil }
go
func continuedFraction(price string) (xdrPrice xdr.Price, err error) { number := &big.Rat{} maxInt32 := &big.Rat{} zero := &big.Rat{} one := &big.Rat{} _, ok := number.SetString(price) if !ok { return xdrPrice, fmt.Errorf("cannot parse price: %s", price) } maxInt32.SetInt64(int64(math.MaxInt32)) zero.SetInt64(int64(0)) one.SetInt64(int64(1)) fractions := [][2]*big.Rat{ {zero, one}, {one, zero}, } i := 2 for { if number.Cmp(maxInt32) == 1 { break } f := &big.Rat{} h := &big.Rat{} k := &big.Rat{} a := floor(number) f.Sub(number, a) h.Mul(a, fractions[i-1][0]) h.Add(h, fractions[i-2][0]) k.Mul(a, fractions[i-1][1]) k.Add(k, fractions[i-2][1]) if h.Cmp(maxInt32) == 1 || k.Cmp(maxInt32) == 1 { break } fractions = append(fractions, [2]*big.Rat{h, k}) if f.Cmp(zero) == 0 { break } number.Quo(one, f) i++ } n, d := fractions[len(fractions)-1][0], fractions[len(fractions)-1][1] if n.Cmp(zero) == 0 || d.Cmp(zero) == 0 { return xdrPrice, errors.New("Couldn't find approximation") } return xdr.Price{ N: xdr.Int32(n.Num().Int64()), D: xdr.Int32(d.Num().Int64()), }, nil }
[ "func", "continuedFraction", "(", "price", "string", ")", "(", "xdrPrice", "xdr", ".", "Price", ",", "err", "error", ")", "{", "number", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "maxInt32", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "zero", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "one", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "_", ",", "ok", ":=", "number", ".", "SetString", "(", "price", ")", "\n", "if", "!", "ok", "{", "return", "xdrPrice", ",", "fmt", ".", "Errorf", "(", "\"cannot parse price: %s\"", ",", "price", ")", "\n", "}", "\n", "maxInt32", ".", "SetInt64", "(", "int64", "(", "math", ".", "MaxInt32", ")", ")", "\n", "zero", ".", "SetInt64", "(", "int64", "(", "0", ")", ")", "\n", "one", ".", "SetInt64", "(", "int64", "(", "1", ")", ")", "\n", "fractions", ":=", "[", "]", "[", "2", "]", "*", "big", ".", "Rat", "{", "{", "zero", ",", "one", "}", ",", "{", "one", ",", "zero", "}", ",", "}", "\n", "i", ":=", "2", "\n", "for", "{", "if", "number", ".", "Cmp", "(", "maxInt32", ")", "==", "1", "{", "break", "\n", "}", "\n", "f", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "h", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "k", ":=", "&", "big", ".", "Rat", "{", "}", "\n", "a", ":=", "floor", "(", "number", ")", "\n", "f", ".", "Sub", "(", "number", ",", "a", ")", "\n", "h", ".", "Mul", "(", "a", ",", "fractions", "[", "i", "-", "1", "]", "[", "0", "]", ")", "\n", "h", ".", "Add", "(", "h", ",", "fractions", "[", "i", "-", "2", "]", "[", "0", "]", ")", "\n", "k", ".", "Mul", "(", "a", ",", "fractions", "[", "i", "-", "1", "]", "[", "1", "]", ")", "\n", "k", ".", "Add", "(", "k", ",", "fractions", "[", "i", "-", "2", "]", "[", "1", "]", ")", "\n", "if", "h", ".", "Cmp", "(", "maxInt32", ")", "==", "1", "||", "k", ".", "Cmp", "(", "maxInt32", ")", "==", "1", "{", "break", "\n", "}", "\n", "fractions", "=", "append", "(", "fractions", ",", "[", "2", "]", "*", "big", ".", "Rat", "{", "h", ",", "k", "}", ")", "\n", "if", "f", ".", "Cmp", "(", "zero", ")", "==", "0", "{", "break", "\n", "}", "\n", "number", ".", "Quo", "(", "one", ",", "f", ")", "\n", "i", "++", "\n", "}", "\n", "n", ",", "d", ":=", "fractions", "[", "len", "(", "fractions", ")", "-", "1", "]", "[", "0", "]", ",", "fractions", "[", "len", "(", "fractions", ")", "-", "1", "]", "[", "1", "]", "\n", "if", "n", ".", "Cmp", "(", "zero", ")", "==", "0", "||", "d", ".", "Cmp", "(", "zero", ")", "==", "0", "{", "return", "xdrPrice", ",", "errors", ".", "New", "(", "\"Couldn't find approximation\"", ")", "\n", "}", "\n", "return", "xdr", ".", "Price", "{", "N", ":", "xdr", ".", "Int32", "(", "n", ".", "Num", "(", ")", ".", "Int64", "(", ")", ")", ",", "D", ":", "xdr", ".", "Int32", "(", "d", ".", "Num", "(", ")", ".", "Int64", "(", ")", ")", ",", "}", ",", "nil", "\n", "}" ]
// continuedFraction calculates and returns the best rational approximation of the given real number.
[ "continuedFraction", "calculates", "and", "returns", "the", "best", "rational", "approximation", "of", "the", "given", "real", "number", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/price/main.go#L18-L77
test
stellar/go-stellar-base
build/transaction_envelope.go
Mutate
func (b *TransactionEnvelopeBuilder) Mutate(muts ...TransactionEnvelopeMutator) { b.Init() for _, m := range muts { err := m.MutateTransactionEnvelope(b) if err != nil { b.Err = err return } } }
go
func (b *TransactionEnvelopeBuilder) Mutate(muts ...TransactionEnvelopeMutator) { b.Init() for _, m := range muts { err := m.MutateTransactionEnvelope(b) if err != nil { b.Err = err return } } }
[ "func", "(", "b", "*", "TransactionEnvelopeBuilder", ")", "Mutate", "(", "muts", "...", "TransactionEnvelopeMutator", ")", "{", "b", ".", "Init", "(", ")", "\n", "for", "_", ",", "m", ":=", "range", "muts", "{", "err", ":=", "m", ".", "MutateTransactionEnvelope", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "b", ".", "Err", "=", "err", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Mutate applies the provided TransactionEnvelopeMutators to this builder's // envelope
[ "Mutate", "applies", "the", "provided", "TransactionEnvelopeMutators", "to", "this", "builder", "s", "envelope" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction_envelope.go#L38-L48
test
stellar/go-stellar-base
build/transaction_envelope.go
MutateTX
func (b *TransactionEnvelopeBuilder) MutateTX(muts ...TransactionMutator) { b.Init() if b.Err != nil { return } b.child.Mutate(muts...) b.Err = b.child.Err }
go
func (b *TransactionEnvelopeBuilder) MutateTX(muts ...TransactionMutator) { b.Init() if b.Err != nil { return } b.child.Mutate(muts...) b.Err = b.child.Err }
[ "func", "(", "b", "*", "TransactionEnvelopeBuilder", ")", "MutateTX", "(", "muts", "...", "TransactionMutator", ")", "{", "b", ".", "Init", "(", ")", "\n", "if", "b", ".", "Err", "!=", "nil", "{", "return", "\n", "}", "\n", "b", ".", "child", ".", "Mutate", "(", "muts", "...", ")", "\n", "b", ".", "Err", "=", "b", ".", "child", ".", "Err", "\n", "}" ]
// MutateTX runs Mutate on the underlying transaction using the provided // mutators.
[ "MutateTX", "runs", "Mutate", "on", "the", "underlying", "transaction", "using", "the", "provided", "mutators", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction_envelope.go#L52-L61
test
stellar/go-stellar-base
build/transaction_envelope.go
Bytes
func (b *TransactionEnvelopeBuilder) Bytes() ([]byte, error) { if b.Err != nil { return nil, b.Err } var txBytes bytes.Buffer _, err := xdr.Marshal(&txBytes, b.E) if err != nil { return nil, err } return txBytes.Bytes(), nil }
go
func (b *TransactionEnvelopeBuilder) Bytes() ([]byte, error) { if b.Err != nil { return nil, b.Err } var txBytes bytes.Buffer _, err := xdr.Marshal(&txBytes, b.E) if err != nil { return nil, err } return txBytes.Bytes(), nil }
[ "func", "(", "b", "*", "TransactionEnvelopeBuilder", ")", "Bytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "b", ".", "Err", "!=", "nil", "{", "return", "nil", ",", "b", ".", "Err", "\n", "}", "\n", "var", "txBytes", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "xdr", ".", "Marshal", "(", "&", "txBytes", ",", "b", ".", "E", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "txBytes", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Bytes encodes the builder's underlying envelope to XDR
[ "Bytes", "encodes", "the", "builder", "s", "underlying", "envelope", "to", "XDR" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction_envelope.go#L64-L76
test
stellar/go-stellar-base
build/transaction_envelope.go
Base64
func (b *TransactionEnvelopeBuilder) Base64() (string, error) { bs, err := b.Bytes() return base64.StdEncoding.EncodeToString(bs), err }
go
func (b *TransactionEnvelopeBuilder) Base64() (string, error) { bs, err := b.Bytes() return base64.StdEncoding.EncodeToString(bs), err }
[ "func", "(", "b", "*", "TransactionEnvelopeBuilder", ")", "Base64", "(", ")", "(", "string", ",", "error", ")", "{", "bs", ",", "err", ":=", "b", ".", "Bytes", "(", ")", "\n", "return", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "bs", ")", ",", "err", "\n", "}" ]
// Base64 returns a string which is the xdr-then-base64-encoded form // of the builder's underlying transaction envelope
[ "Base64", "returns", "a", "string", "which", "is", "the", "xdr", "-", "then", "-", "base64", "-", "encoded", "form", "of", "the", "builder", "s", "underlying", "transaction", "envelope" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction_envelope.go#L80-L83
test
stellar/go-stellar-base
build/transaction_envelope.go
MutateTransactionEnvelope
func (m *TransactionBuilder) MutateTransactionEnvelope(txe *TransactionEnvelopeBuilder) error { if m.Err != nil { return m.Err } txe.E.Tx = *m.TX newChild := *m txe.child = &newChild m.TX = &txe.E.Tx return nil }
go
func (m *TransactionBuilder) MutateTransactionEnvelope(txe *TransactionEnvelopeBuilder) error { if m.Err != nil { return m.Err } txe.E.Tx = *m.TX newChild := *m txe.child = &newChild m.TX = &txe.E.Tx return nil }
[ "func", "(", "m", "*", "TransactionBuilder", ")", "MutateTransactionEnvelope", "(", "txe", "*", "TransactionEnvelopeBuilder", ")", "error", "{", "if", "m", ".", "Err", "!=", "nil", "{", "return", "m", ".", "Err", "\n", "}", "\n", "txe", ".", "E", ".", "Tx", "=", "*", "m", ".", "TX", "\n", "newChild", ":=", "*", "m", "\n", "txe", ".", "child", "=", "&", "newChild", "\n", "m", ".", "TX", "=", "&", "txe", ".", "E", ".", "Tx", "\n", "return", "nil", "\n", "}" ]
// MutateTransactionEnvelope for TransactionBuilder causes the underylying // transaction to be set as the provided envelope's Tx field
[ "MutateTransactionEnvelope", "for", "TransactionBuilder", "causes", "the", "underylying", "transaction", "to", "be", "set", "as", "the", "provided", "envelope", "s", "Tx", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/transaction_envelope.go#L115-L125
test
stellar/go-stellar-base
build/set_options.go
MutateSetOptions
func (m HomeDomain) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { if len(m) > 32 { return errors.New("HomeDomain is too long") } value := xdr.String32(m) o.HomeDomain = &value return }
go
func (m HomeDomain) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { if len(m) > 32 { return errors.New("HomeDomain is too long") } value := xdr.String32(m) o.HomeDomain = &value return }
[ "func", "(", "m", "HomeDomain", ")", "MutateSetOptions", "(", "o", "*", "xdr", ".", "SetOptionsOp", ")", "(", "err", "error", ")", "{", "if", "len", "(", "m", ")", ">", "32", "{", "return", "errors", ".", "New", "(", "\"HomeDomain is too long\"", ")", "\n", "}", "\n", "value", ":=", "xdr", ".", "String32", "(", "m", ")", "\n", "o", ".", "HomeDomain", "=", "&", "value", "\n", "return", "\n", "}" ]
// MutateSetOptions for HomeDomain sets the SetOptionsOp's HomeDomain field
[ "MutateSetOptions", "for", "HomeDomain", "sets", "the", "SetOptionsOp", "s", "HomeDomain", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/set_options.go#L50-L58
test
stellar/go-stellar-base
build/set_options.go
MutateSetOptions
func (m InflationDest) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { o.InflationDest = &xdr.AccountId{} err = setAccountId(string(m), o.InflationDest) return }
go
func (m InflationDest) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { o.InflationDest = &xdr.AccountId{} err = setAccountId(string(m), o.InflationDest) return }
[ "func", "(", "m", "InflationDest", ")", "MutateSetOptions", "(", "o", "*", "xdr", ".", "SetOptionsOp", ")", "(", "err", "error", ")", "{", "o", ".", "InflationDest", "=", "&", "xdr", ".", "AccountId", "{", "}", "\n", "err", "=", "setAccountId", "(", "string", "(", "m", ")", ",", "o", ".", "InflationDest", ")", "\n", "return", "\n", "}" ]
// MutateSetOptions for InflationDest sets the SetOptionsOp's InflationDest field
[ "MutateSetOptions", "for", "InflationDest", "sets", "the", "SetOptionsOp", "s", "InflationDest", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/set_options.go#L66-L70
test
stellar/go-stellar-base
build/set_options.go
MutateSetOptions
func (m MasterWeight) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { val := xdr.Uint32(m) o.MasterWeight = &val return }
go
func (m MasterWeight) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { val := xdr.Uint32(m) o.MasterWeight = &val return }
[ "func", "(", "m", "MasterWeight", ")", "MutateSetOptions", "(", "o", "*", "xdr", ".", "SetOptionsOp", ")", "(", "err", "error", ")", "{", "val", ":=", "xdr", ".", "Uint32", "(", "m", ")", "\n", "o", ".", "MasterWeight", "=", "&", "val", "\n", "return", "\n", "}" ]
// MutateSetOptions for MasterWeight sets the SetOptionsOp's MasterWeight field
[ "MutateSetOptions", "for", "MasterWeight", "sets", "the", "SetOptionsOp", "s", "MasterWeight", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/set_options.go#L78-L82
test
stellar/go-stellar-base
build/set_options.go
MutateSetOptions
func (m Signer) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { var signer xdr.Signer signer.Weight = xdr.Uint32(m.Weight) err = setAccountId(m.PublicKey, &signer.PubKey) o.Signer = &signer return }
go
func (m Signer) MutateSetOptions(o *xdr.SetOptionsOp) (err error) { var signer xdr.Signer signer.Weight = xdr.Uint32(m.Weight) err = setAccountId(m.PublicKey, &signer.PubKey) o.Signer = &signer return }
[ "func", "(", "m", "Signer", ")", "MutateSetOptions", "(", "o", "*", "xdr", ".", "SetOptionsOp", ")", "(", "err", "error", ")", "{", "var", "signer", "xdr", ".", "Signer", "\n", "signer", ".", "Weight", "=", "xdr", ".", "Uint32", "(", "m", ".", "Weight", ")", "\n", "err", "=", "setAccountId", "(", "m", ".", "PublicKey", ",", "&", "signer", ".", "PubKey", ")", "\n", "o", ".", "Signer", "=", "&", "signer", "\n", "return", "\n", "}" ]
// MutateSetOptions for Signer sets the SetOptionsOp's signer field
[ "MutateSetOptions", "for", "Signer", "sets", "the", "SetOptionsOp", "s", "signer", "field" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/set_options.go#L100-L106
test
stellar/go-stellar-base
build/set_options.go
SetThresholds
func SetThresholds(low, medium, high uint32) Thresholds { return Thresholds{ Low: &low, Medium: &medium, High: &high, } }
go
func SetThresholds(low, medium, high uint32) Thresholds { return Thresholds{ Low: &low, Medium: &medium, High: &high, } }
[ "func", "SetThresholds", "(", "low", ",", "medium", ",", "high", "uint32", ")", "Thresholds", "{", "return", "Thresholds", "{", "Low", ":", "&", "low", ",", "Medium", ":", "&", "medium", ",", "High", ":", "&", "high", ",", "}", "\n", "}" ]
// SetThresholds creates Thresholds mutator
[ "SetThresholds", "creates", "Thresholds", "mutator" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/build/set_options.go#L114-L120
test