{"action":"created","issue":{"url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/issues/217","repository_url":"https://api.github.com/repos/OpenBazaar/openbazaar-go","labels_url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/issues/217/labels{/name}","comments_url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/issues/217/comments","events_url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/issues/217/events","html_url":"https://github.com/OpenBazaar/openbazaar-go/issues/217","id":188788555,"number":217,"title":"Simplify IPFS interface","user":{"login":"JustinDrake","id":731743,"avatar_url":"https://avatars.githubusercontent.com/u/731743?v=3","gravatar_id":"","url":"https://api.github.com/users/JustinDrake","html_url":"https://github.com/JustinDrake","followers_url":"https://api.github.com/users/JustinDrake/followers","following_url":"https://api.github.com/users/JustinDrake/following{/other_user}","gists_url":"https://api.github.com/users/JustinDrake/gists{/gist_id}","starred_url":"https://api.github.com/users/JustinDrake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JustinDrake/subscriptions","organizations_url":"https://api.github.com/users/JustinDrake/orgs","repos_url":"https://api.github.com/users/JustinDrake/repos","events_url":"https://api.github.com/users/JustinDrake/events{/privacy}","received_events_url":"https://api.github.com/users/JustinDrake/received_events","type":"User","site_admin":false},"labels":[{"id":479814466,"url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/labels/refactoring","name":"refactoring","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-11T15:48:43Z","updated_at":"2016-11-14T17:12:35Z","closed_at":null,"body":"As I understand from talking to @cpacia, the IPFS interface code in the `ipfs` folder was written \"in the dark\" (no documentation) from the IPFS command line tool and ended up being a dirty hack. For example, inside `add.go` the function `AddFile` calls the functions `PreRun`, `Run` and `PostRun` which are not relevant to adding files. As explained in [this issue](https://github.com/ipfs/go-ipfs/issues/3060), there is a much neater way of doing things (see whyrusleeping's answer):\r\n\r\n```\r\nfunc AddFile(ipfs *core.IpfsNode, file string) (string, error) {\r\n    fi, err := os.Open(file)\r\n    if err != nil {\r\n        return \"\", err\r\n    }\r\n\r\n    return coreunix.Add(ipfs, fi)\r\n}\r\n```\r\n\r\ninstead of\r\n\r\n```\r\nfunc AddFile(ctx commands.Context, fpath string) (string, error) {\r\n\targs := []string{\"add\", fpath}\r\n\treq, cmd, err := NewRequest(ctx, args)\r\n\tif err != nil {\r\n\t\treturn \"\", err\r\n\t}\r\n\tres := commands.NewResponse(req)\r\n\tcmd.PreRun(req)\r\n\tcmd.Run(req, res)\r\n\tvar fileHash string\r\n\tfor r := range res.Output().(<-chan interface{}) {\r\n\t\tfileHash = r.(*coreunix.AddedObject).Hash\r\n\t}\r\n\tcmd.PostRun(req, res)\r\n\tif res.Error() != nil {\r\n\t\treturn \"\", res.Error()\r\n\t}\r\n\tif fileHash == \"\" {\r\n\t\treturn \"\", addErr\r\n\t}\r\n\treturn fileHash, nil\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/issues/comments/260397616","html_url":"https://github.com/OpenBazaar/openbazaar-go/issues/217#issuecomment-260397616","issue_url":"https://api.github.com/repos/OpenBazaar/openbazaar-go/issues/217","id":260397616,"user":{"login":"cpacia","id":4504708,"avatar_url":"https://avatars.githubusercontent.com/u/4504708?v=3","gravatar_id":"","url":"https://api.github.com/users/cpacia","html_url":"https://github.com/cpacia","followers_url":"https://api.github.com/users/cpacia/followers","following_url":"https://api.github.com/users/cpacia/following{/other_user}","gists_url":"https://api.github.com/users/cpacia/gists{/gist_id}","starred_url":"https://api.github.com/users/cpacia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpacia/subscriptions","organizations_url":"https://api.github.com/users/cpacia/orgs","repos_url":"https://api.github.com/users/cpacia/repos","events_url":"https://api.github.com/users/cpacia/events{/privacy}","received_events_url":"https://api.github.com/users/cpacia/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T17:12:35Z","updated_at":"2016-11-14T17:12:35Z","body":"Because as far as I know add is the only one where you have a function like coreunix.add. If you can find others in the IPFS code to do the same thing for the other functions then that works."}}
{"actor":{"display_login":"cpacia"}}