-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a server component to the library. Note that it does not yet validate incoming payloads. 1. It accepts an `AgentMessage` 2. Pulls out the invocations 3. Executes each invocation, using the capability name to identify the handler to run 4. Encodes receipts for each invocation 5. Constructs a response `AgentMessage` and returns it It also has methods for constructing a server and defining invocation handler functions. BREAKING CHANGE: referencing this package at web3-storage will no longer work after this commit due to the way go.mod works --------- Co-authored-by: hannahhoward <[email protected]>
- Loading branch information
1 parent
6fb87be
commit d7e26c4
Showing
59 changed files
with
2,275 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ran | ||
|
||
import ( | ||
"github.com/storacha-network/go-ucanto/core/dag/blockstore" | ||
"github.com/storacha-network/go-ucanto/core/invocation" | ||
"github.com/storacha-network/go-ucanto/core/ipld" | ||
"github.com/storacha-network/go-ucanto/ucan" | ||
) | ||
|
||
type Ran struct { | ||
invocation invocation.Invocation | ||
link ucan.Link | ||
} | ||
|
||
func (r Ran) Invocation() (invocation.Invocation, bool) { | ||
return r.invocation, r.invocation != nil | ||
} | ||
|
||
func (r Ran) Link() ucan.Link { | ||
if r.invocation != nil { | ||
return r.invocation.Link() | ||
} | ||
return r.link | ||
} | ||
|
||
func FromInvocation(invocation invocation.Invocation) Ran { | ||
return Ran{invocation, nil} | ||
} | ||
|
||
func FromLink(link ucan.Link) Ran { | ||
return Ran{nil, link} | ||
} | ||
|
||
func (r Ran) WriteInto(bs blockstore.BlockWriter) (ipld.Link, error) { | ||
if invocation, ok := r.Invocation(); ok { | ||
return r.Link(), blockstore.WriteInto(invocation, bs) | ||
} | ||
return r.Link(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
package ipld | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ipld/go-ipld-prime" | ||
"github.com/web3-storage/go-ucanto/core/ipld/block" | ||
"github.com/ipld/go-ipld-prime/node/bindnode" | ||
"github.com/ipld/go-ipld-prime/schema" | ||
"github.com/storacha-network/go-ucanto/core/ipld/block" | ||
) | ||
|
||
type Link = ipld.Link | ||
type Block = block.Block | ||
type Node = ipld.Node | ||
|
||
// Builder can be modeled as an IPLD data and provides a `Build“ method to | ||
// build itself into a `datamodel.Node`. | ||
type Builder interface { | ||
Build() (Node, error) | ||
} | ||
|
||
// WrapWithRecovery behaves like bindnode.Wrap but converts panics into errors | ||
func WrapWithRecovery(ptrVal interface{}, typ schema.Type) (nd Node, err error) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
if asStr, ok := r.(string); ok { | ||
err = errors.New(asStr) | ||
} else if asErr, ok := r.(error); ok { | ||
err = asErr | ||
} else { | ||
err = errors.New("unknown panic building node") | ||
} | ||
} | ||
}() | ||
nd = bindnode.Wrap(ptrVal, typ) | ||
return | ||
} |
Oops, something went wrong.