Skip to content

Commit

Permalink
Added: Basic implementation of w3up service (Filecoin layer)
Browse files Browse the repository at this point in the history
Wrapper functions for the w3cli have been added. They require that the w3cli is installed on the target machine.
  • Loading branch information
regcs authored Sep 4, 2023
2 parents f5a2a2a + a1fdb6f commit 5971f82
Show file tree
Hide file tree
Showing 5 changed files with 1,042 additions and 62 deletions.
2 changes: 0 additions & 2 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ require github.com/ipfs/kubo v0.18.1

// General
require (
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86
github.com/dop251/goja_nodejs v0.0.0-20230222172725-12ac04f8c000
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-libipfs v0.2.0
Expand Down
10 changes: 0 additions & 10 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,14 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/docker/docker v1.6.2/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86 h1:E2wycakfddWJ26v+ZyEY91Lb/HEZyaiZhbMX+KQcdmc=
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/dop251/goja_nodejs v0.0.0-20230222172725-12ac04f8c000 h1:eJhYaEWVw87/LT0i/0cNvKyBlJ1U6qZ2SEoLEqCFzEs=
github.com/dop251/goja_nodejs v0.0.0-20230222172725-12ac04f8c000/go.mod h1:0tlktQL7yHfYEtjcRGi/eiOkbDR5XF7gyFFvbC5//E0=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -392,7 +384,6 @@ github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
Expand Down Expand Up @@ -2026,7 +2017,6 @@ golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfS
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
41 changes: 40 additions & 1 deletion src/ipfs/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ type PackageManager struct {
IpfsNode *core.IpfsNode
IpfsAPI icore.CoreAPI

// w3up service
W3Agent w3cliAgent

// Command line interface
Command *cobra.Command
CommandFlags struct {
Expand All @@ -110,6 +113,39 @@ func (ipfsm *PackageManager) Init() error {
logger.Manager.Package["ipfs"].Error().Msg(err.Error())
}

// Initialize w3 CLI command
ipfsm.W3Agent.Path = "w3"

// Authorize this agent
_, err = ipfsm.W3Agent.Whoami()
if err != nil {
logger.Manager.Package["ipfs"].Error().Msg(err.Error())
return err
}

// log did key of the w3up agent
logger.Manager.Package["ipfs"].Info().Msg(fmt.Sprintf(" [#] w3up identity: %v", ipfsm.W3Agent.DIDkey))

// Get list of spaces this agent has access to
err = ipfsm.W3Agent.SpaceList()
if err != nil {
logger.Manager.Package["ipfs"].Error().Msg(err.Error())
return err
}

// log number of known w3up spaces
logger.Manager.Package["ipfs"].Info().Msg(fmt.Sprintf(" [#] w3up spaces: %v", len(ipfsm.W3Agent.Spaces)))

// Get list of uploads in the active space
err = ipfsm.W3Agent.UploadList()
if err != nil {
logger.Manager.Package["ipfs"].Error().Msg(err.Error())
return err
}

// log currently used w3up spaces
logger.Manager.Package["ipfs"].Info().Msg(fmt.Sprintf(" [#] w3up current space: %v (%v)", ipfsm.W3Agent.ActiveSpace, ipfsm.W3Agent.Spaces[ipfsm.W3Agent.ActiveSpace].Name))

return err

}
Expand Down Expand Up @@ -566,13 +602,16 @@ func (ipfsm *PackageManager) CreateCommand() *cobra.Command {
},
}

// add the subcommands
// add the subcommands (IPFS)
ipfsm.Command.AddCommand(ipfsm.CreateCommandInfo())
ipfsm.Command.AddCommand(ipfsm.CreateCommandSwarm())
ipfsm.Command.AddCommand(ipfsm.CreateCommandAdd())
ipfsm.Command.AddCommand(ipfsm.CreateCommandGet())
ipfsm.Command.AddCommand(ipfsm.CreateCommandPin())

// add the subcommands (Filecoin / w3up service)
ipfsm.Command.AddCommand(ipfsm.CreateCommandW3())

return ipfsm.Command

}
Expand Down
Loading

0 comments on commit 5971f82

Please sign in to comment.